Skip to content

Commit

Permalink
Stricter checking of compare_exchange builtin.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Sep 16, 2023
1 parent ff05128 commit 03345be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/compiler/sema_builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define COMPILER_VERSION "0.4.648"
#define COMPILER_VERSION "0.4.649"

0 comments on commit 03345be

Please sign in to comment.