aaron.ballman created this revision. aaron.ballman added reviewers: jyknight, erichkeane, clang-language-wg. Herald added a project: All. aaron.ballman requested review of this revision. Herald added a project: clang.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D122681 Files: clang/lib/Sema/SemaExprMember.cpp clang/test/Sema/atomic-expr.c Index: clang/test/Sema/atomic-expr.c =================================================================== --- clang/test/Sema/atomic-expr.c +++ clang/test/Sema/atomic-expr.c @@ -102,4 +102,10 @@ _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); } Index: clang/lib/Sema/SemaExprMember.cpp =================================================================== --- clang/lib/Sema/SemaExprMember.cpp +++ clang/lib/Sema/SemaExprMember.cpp @@ -1298,7 +1298,8 @@ // 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,
Index: clang/test/Sema/atomic-expr.c =================================================================== --- clang/test/Sema/atomic-expr.c +++ clang/test/Sema/atomic-expr.c @@ -102,4 +102,10 @@ _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); } Index: clang/lib/Sema/SemaExprMember.cpp =================================================================== --- clang/lib/Sema/SemaExprMember.cpp +++ clang/lib/Sema/SemaExprMember.cpp @@ -1298,7 +1298,8 @@ // 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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits