mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix of atomic checks. Renamed MONOTONIC -> RELAXED.
This commit is contained in:
@@ -119,6 +119,13 @@ endif()
|
||||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
|
||||
message(STATUS "Libraries located in: ${LLVM_LIBRARY_DIRS}")
|
||||
|
||||
if(LLVM_ENABLE_RTTI)
|
||||
message(STATUS "LLVM was built with RTTI")
|
||||
else()
|
||||
message(STATUS "LLVM was not built with RTTI")
|
||||
endif()
|
||||
|
||||
include_directories(${LLVM_INCLUDE_DIRS})
|
||||
link_directories(${LLVM_LIBRARY_DIRS})
|
||||
add_definitions(${LLVM_DEFINITIONS})
|
||||
|
||||
@@ -24,7 +24,7 @@ enum AtomicOrdering : int
|
||||
{
|
||||
NOT_ATOMIC, // Not atomic
|
||||
UNORDERED, // No lock
|
||||
MONOTONIC, // Consistent ordering
|
||||
RELAXED, // Consistent ordering
|
||||
ACQUIRE, // Barrier locking load/store
|
||||
RELEASE, // Barrier releasing load/store
|
||||
ACQUIRE_RELEASE, // Barrier fence to load/store
|
||||
|
||||
@@ -69,13 +69,13 @@ static LLVMAtomicOrdering ordering_to_llvm(int value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0: return LLVMAtomicOrderingNotAtomic;
|
||||
case 1: return LLVMAtomicOrderingUnordered;
|
||||
case 2: return LLVMAtomicOrderingMonotonic;
|
||||
case 3: return LLVMAtomicOrderingAcquire;
|
||||
case 4: return LLVMAtomicOrderingRelease;
|
||||
case 5: return LLVMAtomicOrderingAcquireRelease;
|
||||
case 6: return LLVMAtomicOrderingSequentiallyConsistent;
|
||||
case ATOMIC_NONE: return LLVMAtomicOrderingNotAtomic;
|
||||
case ATOMIC_UNORDERED: return LLVMAtomicOrderingUnordered;
|
||||
case ATOMIC_RELAXED: return LLVMAtomicOrderingMonotonic;
|
||||
case ATOMIC_ACQUIRE: return LLVMAtomicOrderingAcquire;
|
||||
case ATOMIC_RELEASE: return LLVMAtomicOrderingRelease;
|
||||
case ATOMIC_ACQUIRE_RELEASE: return LLVMAtomicOrderingAcquireRelease;
|
||||
case ATOMIC_SEQ_CONSISTENT: return LLVMAtomicOrderingSequentiallyConsistent;
|
||||
default: UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// a copy of which can be found in the LICENSE file.
|
||||
#include "sema_internal.h"
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BA_POINTER,
|
||||
@@ -164,7 +165,7 @@ static inline bool is_valid_atomicity(Expr* expr)
|
||||
{
|
||||
if (!expr_is_const_int(expr) || !int_fits(expr->const_expr.ixx, TYPE_U8) || expr->const_expr.ixx.i.low > 6)
|
||||
{
|
||||
RETURN_SEMA_ERROR(expr, "Expected a constant integer value < 8.");
|
||||
RETURN_SEMA_ERROR(expr, "Expected a constant integer value < 7.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -200,6 +201,14 @@ static bool sema_expr_analyse_compare_exchange(SemaContext *context, Expr *expr)
|
||||
if (!sema_analyse_expr_rhs(context, type_char, args[i], false)) return false;
|
||||
if (!is_valid_atomicity(args[i])) return false;
|
||||
}
|
||||
unsigned success = args[5]->const_expr.ixx.i.low;
|
||||
unsigned failure = args[6]->const_expr.ixx.i.low;
|
||||
if (success < ATOMIC_RELAXED) RETURN_SEMA_ERROR(args[5], "Success ordering must be at least RELAXED.");
|
||||
if (failure < ATOMIC_RELAXED) RETURN_SEMA_ERROR(args[6], "Failure ordering must be at least RELAXED.");
|
||||
if (failure == ATOMIC_ACQUIRE_RELEASE || failure == ATOMIC_RELEASE)
|
||||
{
|
||||
RETURN_SEMA_ERROR(args[6], "Failure ordering may not be RELEASE / ACQUIRE_RELEASE.");
|
||||
}
|
||||
Expr *align = args[7];
|
||||
if (!sema_analyse_expr_rhs(context, type_usz, align, false)) return false;
|
||||
if (!expr_is_const_int(align)
|
||||
@@ -563,7 +572,7 @@ bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr)
|
||||
if (!expr_is_const(args[1])) RETURN_SEMA_ERROR(args[1], "'is_volatile' must be a compile time constant.");
|
||||
if (!expr_is_const(args[2])) RETURN_SEMA_ERROR(args[2], "Ordering must be a compile time constant.");
|
||||
if (!is_valid_atomicity(args[2])) return false;
|
||||
switch (expr->const_expr.ixx.i.low)
|
||||
switch (args[2]->const_expr.ixx.i.low)
|
||||
{
|
||||
case ATOMIC_ACQUIRE_RELEASE:
|
||||
case ATOMIC_RELEASE:
|
||||
@@ -606,11 +615,11 @@ bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr)
|
||||
if (!expr_is_const(args[2])) RETURN_SEMA_ERROR(args[2], "'is_volatile' must be a compile time constant.");
|
||||
if (!expr_is_const(args[3])) RETURN_SEMA_ERROR(args[3], "Ordering must be a compile time constant.");
|
||||
if (!is_valid_atomicity(args[3])) return false;
|
||||
switch (expr->const_expr.ixx.i.low)
|
||||
switch (args[3]->const_expr.ixx.i.low)
|
||||
{
|
||||
case ATOMIC_ACQUIRE_RELEASE:
|
||||
case ATOMIC_ACQUIRE:
|
||||
RETURN_SEMA_ERROR(args[2], "'acquire' and 'acquire release' are not valid for atomic stores.");
|
||||
RETURN_SEMA_ERROR(args[3], "'acquire' and 'acquire release' are not valid for atomic stores.");
|
||||
}
|
||||
rtype = args[1]->type;
|
||||
break;
|
||||
|
||||
@@ -12,9 +12,9 @@ fn void main()
|
||||
{
|
||||
int a = 111;
|
||||
int x = @atomic_load(a);
|
||||
int y = @atomic_load(a, MONOTONIC, true);
|
||||
int y = @atomic_load(a, RELAXED, true);
|
||||
@atomic_store(a, 123 + x);
|
||||
@atomic_store(a, 33 + y, MONOTONIC, true);
|
||||
@atomic_store(a, 33 + y, RELAXED, true);
|
||||
io::printfn("%d", a);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ fn void main()
|
||||
{
|
||||
int a = 111;
|
||||
int x = @atomic_load(a);
|
||||
int y = @atomic_load(a, MONOTONIC, true);
|
||||
int y = @atomic_load(a, RELAXED, true);
|
||||
@atomic_store(a, 123 + x);
|
||||
@atomic_store(a, 33 + y, MONOTONIC, true);
|
||||
@atomic_store(a, 33 + y, RELAXED, true);
|
||||
io::printfn("%d", a);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user