From c83472e0ff4c30e19a7f0fb2b53203a2ea733dde Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 11 Mar 2014 11:35:10 +0000 Subject: [PATCH] Sema: demote invalid atomic ordering message to warning. Someone could write: if (0) { __c11_atomic_load(ptr, memory_order_release); } or the equivalent, which is perfectly valid, so we shouldn't outright reject invalid orderings on purely static grounds. rdar://problem/16242991 llvm-svn: 203564 --- .../clang/Basic/DiagnosticSemaKinds.td | 5 +-- clang/lib/Sema/SemaChecking.cpp | 6 ++-- clang/test/Sema/atomic-ops.c | 34 +++++++++---------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8ec965bd6ca9..c9bdcf12cb6a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5689,8 +5689,9 @@ def err_atomic_op_needs_atomic_int_or_ptr : Error< def err_atomic_op_bitwise_needs_atomic_int : Error< "address argument to bitwise atomic operation must be a pointer to " "%select{|atomic }0integer (%1 invalid)">; -def err_atomic_op_has_invalid_memory_order : Error< - "memory order argument to atomic operation is invalid">; +def warn_atomic_op_has_invalid_memory_order : Warning< + "memory order argument to atomic operation is invalid">, + InGroup>; def err_atomic_load_store_uses_lib : Error< "atomic %select{load|store}0 requires runtime support that is not " diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 19e61b2e8197..30a872fcab59 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1231,9 +1231,9 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult, llvm::APSInt Result(32); if (SubExprs[1]->isIntegerConstantExpr(Result, Context) && !isValidOrderingForOp(Result.getSExtValue(), Op)) - return ExprError(Diag(SubExprs[1]->getLocStart(), - diag::err_atomic_op_has_invalid_memory_order) - << SubExprs[1]->getSourceRange()); + Diag(SubExprs[1]->getLocStart(), + diag::warn_atomic_op_has_invalid_memory_order) + << SubExprs[1]->getSourceRange(); } AtomicExpr *AE = new (Context) AtomicExpr(TheCall->getCallee()->getLocStart(), diff --git a/clang/test/Sema/atomic-ops.c b/clang/test/Sema/atomic-ops.c index ec0a2bfe64cd..6f9f568503ce 100644 --- a/clang/test/Sema/atomic-ops.c +++ b/clang/test/Sema/atomic-ops.c @@ -187,18 +187,18 @@ void memory_checks(_Atomic(int) *Ap, int *p, int val) { (void)__c11_atomic_load(Ap, memory_order_relaxed); (void)__c11_atomic_load(Ap, memory_order_acquire); (void)__c11_atomic_load(Ap, memory_order_consume); - (void)__c11_atomic_load(Ap, memory_order_release); // expected-error {{memory order argument to atomic operation is invalid}} - (void)__c11_atomic_load(Ap, memory_order_acq_rel); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__c11_atomic_load(Ap, memory_order_release); // expected-warning {{memory order argument to atomic operation is invalid}} + (void)__c11_atomic_load(Ap, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__c11_atomic_load(Ap, memory_order_seq_cst); (void)__c11_atomic_load(Ap, val); - (void)__c11_atomic_load(Ap, -1); // expected-error {{memory order argument to atomic operation is invalid}} - (void)__c11_atomic_load(Ap, 42); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__c11_atomic_load(Ap, -1); // expected-warning {{memory order argument to atomic operation is invalid}} + (void)__c11_atomic_load(Ap, 42); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__c11_atomic_store(Ap, val, memory_order_relaxed); - (void)__c11_atomic_store(Ap, val, memory_order_acquire); // expected-error {{memory order argument to atomic operation is invalid}} - (void)__c11_atomic_store(Ap, val, memory_order_consume); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__c11_atomic_store(Ap, val, memory_order_acquire); // expected-warning {{memory order argument to atomic operation is invalid}} + (void)__c11_atomic_store(Ap, val, memory_order_consume); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__c11_atomic_store(Ap, val, memory_order_release); - (void)__c11_atomic_store(Ap, val, memory_order_acq_rel); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__c11_atomic_store(Ap, val, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__c11_atomic_store(Ap, val, memory_order_seq_cst); (void)__c11_atomic_fetch_add(Ap, 1, memory_order_relaxed); @@ -267,29 +267,29 @@ void memory_checks(_Atomic(int) *Ap, int *p, int val) { (void)__atomic_load_n(p, memory_order_relaxed); (void)__atomic_load_n(p, memory_order_acquire); (void)__atomic_load_n(p, memory_order_consume); - (void)__atomic_load_n(p, memory_order_release); // expected-error {{memory order argument to atomic operation is invalid}} - (void)__atomic_load_n(p, memory_order_acq_rel); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__atomic_load_n(p, memory_order_release); // expected-warning {{memory order argument to atomic operation is invalid}} + (void)__atomic_load_n(p, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__atomic_load_n(p, memory_order_seq_cst); (void)__atomic_load(p, p, memory_order_relaxed); (void)__atomic_load(p, p, memory_order_acquire); (void)__atomic_load(p, p, memory_order_consume); - (void)__atomic_load(p, p, memory_order_release); // expected-error {{memory order argument to atomic operation is invalid}} - (void)__atomic_load(p, p, memory_order_acq_rel); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__atomic_load(p, p, memory_order_release); // expected-warning {{memory order argument to atomic operation is invalid}} + (void)__atomic_load(p, p, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__atomic_load(p, p, memory_order_seq_cst); (void)__atomic_store(p, p, memory_order_relaxed); - (void)__atomic_store(p, p, memory_order_acquire); // expected-error {{memory order argument to atomic operation is invalid}} - (void)__atomic_store(p, p, memory_order_consume); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__atomic_store(p, p, memory_order_acquire); // expected-warning {{memory order argument to atomic operation is invalid}} + (void)__atomic_store(p, p, memory_order_consume); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__atomic_store(p, p, memory_order_release); - (void)__atomic_store(p, p, memory_order_acq_rel); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__atomic_store(p, p, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__atomic_store(p, p, memory_order_seq_cst); (void)__atomic_store_n(p, val, memory_order_relaxed); - (void)__atomic_store_n(p, val, memory_order_acquire); // expected-error {{memory order argument to atomic operation is invalid}} - (void)__atomic_store_n(p, val, memory_order_consume); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__atomic_store_n(p, val, memory_order_acquire); // expected-warning {{memory order argument to atomic operation is invalid}} + (void)__atomic_store_n(p, val, memory_order_consume); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__atomic_store_n(p, val, memory_order_release); - (void)__atomic_store_n(p, val, memory_order_acq_rel); // expected-error {{memory order argument to atomic operation is invalid}} + (void)__atomic_store_n(p, val, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} (void)__atomic_store_n(p, val, memory_order_seq_cst); (void)__atomic_fetch_add(p, val, memory_order_relaxed);