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.
This commit is contained in:
parent
4a33b9ece0
commit
cf4a67bcbb
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user