From 03345bef10089fcf1780b4180b18ce19373ec718 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 16 Sep 2023 22:25:03 +0200 Subject: [PATCH] Stricter checking of compare_exchange builtin. --- src/compiler/sema_builtins.c | 11 +++++++++-- src/compiler/target.c | 2 +- src/version.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/compiler/sema_builtins.c b/src/compiler/sema_builtins.c index 0def5c4a9..b4adea753 100644 --- a/src/compiler/sema_builtins.c +++ b/src/compiler/sema_builtins.c @@ -215,14 +215,21 @@ static bool sema_expr_analyse_compare_exchange(SemaContext *context, Expr *expr) Expr *pointer = args[0]; if (!sema_analyse_expr(context, pointer)) return false; + bool optional = IS_OPTIONAL(pointer); Type *comp_type = type_flatten(pointer->type); if (!type_is_pointer(comp_type)) RETURN_SEMA_ERROR(pointer, "Expected a pointer here."); - Type *pointee = comp_type->pointer; for (int i = 1; i < 3; i++) { - if (!sema_analyse_expr_rhs(context, pointee, args[i], true)) return false; + Expr *arg = args[i]; + if (!sema_analyse_expr_rhs(context, pointee == type_void ? NULL : pointee, arg, true)) return false; + if (pointee == type_void) pointee = arg->type->canonical; + if (!type_is_atomic(type_flatten(arg->type))) + { + RETURN_SEMA_ERROR(arg, "%s may not be used with atomics.", type_quoted_error_string(arg->type)); + } + optional = optional || IS_OPTIONAL(args[i]); } for (int i = 3; i < 5; i++) diff --git a/src/compiler/target.c b/src/compiler/target.c index d5af3e636..938d4ce6f 100644 --- a/src/compiler/target.c +++ b/src/compiler/target.c @@ -459,7 +459,7 @@ static void x86features_as_diff_to_scratch(X86Features *cpu_features, X86CpuSet x86_features_add_feature(&diff, X86_FEAT_CMPXCHG8B); break; } - for (int i = 0; i <= X86_FEATURE_LAST; i++) + for (X86Feature i = 0; i <= X86_FEATURE_LAST; i++) { if (i == X86_FEAT_AVX5124FMAPS || i == X86_FEAT_AVX5124VNNIW) continue; bool diff_has = x64features_contains(&diff, (X86Feature)i); diff --git a/src/version.h b/src/version.h index 6c85acc93..53c647863 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.648" \ No newline at end of file +#define COMPILER_VERSION "0.4.649" \ No newline at end of file