Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0eb4bd2

Browse filesBrowse files
authored
[C] Silence unreachable -Watomic-access diagnostics (#140064)
Accessing the member of a structure or union which is _Atomic-qualified is undefined behavior in C. We currently diagnose that with a warning that defaults to an error. In turn, this means we reject a valid program if the access it not reachable because of the error. e.g., if (0) SomeAtomicStruct.Member = 12; // Was diagnosed This silences the diagnostic if the member access is not reachable.
1 parent 5defe49 commit 0eb4bd2
Copy full SHA for 0eb4bd2

File tree

3 files changed

+31
-1
lines changed
Filter options

3 files changed

+31
-1
lines changed

‎clang/docs/ReleaseNotes.rst

Copy file name to clipboardExpand all lines: clang/docs/ReleaseNotes.rst
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,19 @@ Improvements to Clang's diagnostics
533533
- A new off-by-default warning ``-Wms-bitfield-padding`` has been added to alert to cases where bit-field
534534
packing may differ under the MS struct ABI (#GH117428).
535535

536+
- ``-Watomic-access`` no longer fires on unreachable code. e.g.,
537+
538+
.. code-block:: c
539+
540+
_Atomic struct S { int a; } s;
541+
void func(void) {
542+
if (0)
543+
s.a = 12; // Previously diagnosed with -Watomic-access, now silenced
544+
s.a = 12; // Still diagnosed with -Watomic-access
545+
return;
546+
s.a = 12; // Previously diagnosed, now silenced
547+
}
548+
536549
537550
- A new ``-Wcharacter-conversion`` warns where comparing or implicitly converting
538551
between different Unicode character types (``char8_t``, ``char16_t``, ``char32_t``).

‎clang/lib/Sema/SemaExprMember.cpp

Copy file name to clipboardExpand all lines: clang/lib/Sema/SemaExprMember.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
13851385
// lvalue. Because this is inherently unsafe as an atomic operation, the
13861386
// warning defaults to an error.
13871387
if (const auto *ATy = BaseType->getAs<AtomicType>()) {
1388-
S.DiagRuntimeBehavior(OpLoc, nullptr,
1388+
S.DiagRuntimeBehavior(OpLoc, BaseExpr.get(),
13891389
S.PDiag(diag::warn_atomic_member_access));
13901390
BaseType = ATy->getValueType().getUnqualifiedType();
13911391
BaseExpr = ImplicitCastExpr::Create(

‎clang/test/Sema/atomic-expr.c

Copy file name to clipboardExpand all lines: clang/test/Sema/atomic-expr.c
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ void func_16(void) {
114114
(void)sizeof(xp->val);
115115
(void)sizeof(y.ival);
116116
(void)sizeof(yp->ival);
117+
118+
// Also, do not diagnose in unreachable code paths.
119+
{
120+
if (0) {
121+
x.val = 12;
122+
xp->val = 12;
123+
(void)y.ival;
124+
(void)yp->ival;
125+
}
126+
127+
return;
128+
129+
x.val = 12;
130+
xp->val = 12;
131+
(void)y.ival;
132+
(void)yp->ival;
133+
}
117134
}
118135

119136
// Ensure that we correctly implement assignment constraints from C2x 6.5.16.1.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.