[clang] cf4a67b - Don't diagnostic atomic object access as UB in an unevaluated context
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 30 04:13:08 PDT 2022
Author: Aaron Ballman
Date: 2022-03-30T07:12:49-04:00
New Revision: cf4a67bcbbb109347b1e2d6cedf69bae142a182f
URL: https://github.com/llvm/llvm-project/commit/cf4a67bcbbb109347b1e2d6cedf69bae142a182f
DIFF: https://github.com/llvm/llvm-project/commit/cf4a67bcbbb109347b1e2d6cedf69bae142a182f.diff
LOG: Don't diagnostic atomic object access as UB in an unevaluated context
We started diagnosing this situation with a more clear diagnostic
message, but it was pointed out that unevaluated contexts don't really
have the undefined behavior property as there is no runtime access
involved.
This augments the changes in https://reviews.llvm.org/D122656 to not
diagnose in an unevaluated context.
Added:
Modified:
clang/lib/Sema/SemaExprMember.cpp
clang/test/Sema/atomic-expr.c
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 152b39dabe361..cb95f70f445b6 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1298,7 +1298,8 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
// lvalue. Because this is inherently unsafe as an atomic operation, the
// warning defaults to an error.
if (const auto *ATy = BaseType->getAs<AtomicType>()) {
- S.Diag(OpLoc, diag::warn_atomic_member_access);
+ S.DiagRuntimeBehavior(OpLoc, nullptr,
+ S.PDiag(diag::warn_atomic_member_access));
BaseType = ATy->getValueType().getUnqualifiedType();
BaseExpr = ImplicitCastExpr::Create(
S.Context, IsArrow ? S.Context.getPointerType(BaseType) : BaseType,
diff --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index 86cd32ce338c8..6c6823c848722 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -102,4 +102,10 @@ void func_16(void) {
_Atomic(struct { int val; }) z;
z.val = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
int zval = z.val; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
+
+ // Don't diagnose in an unevaluated context, however.
+ (void)sizeof(x.val);
+ (void)sizeof(xp->val);
+ (void)sizeof(y.ival);
+ (void)sizeof(yp->ival);
}
More information about the cfe-commits
mailing list