Skip to content

Commit 34b34fa

Browse files
AaronBallmanahatanaka
authored andcommitted
[C] Fix issue with -Wimplicit-void-ptr-cast (llvm#154351)
The changes from llvm#136855 missed a change with atomic assignment constraints. This fixes a bug where we'd accidentally drop a non-atomic-to-atomic conversion step. Fixes llvm#154157 co-authored-by: @ahatanak
1 parent 0ee6fb9 commit 34b34fa

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11534,14 +11534,14 @@ AssignConvertType Sema::CheckAssignmentConstraints(QualType LHSType,
1153411534
// If we have an atomic type, try a non-atomic assignment, then just add an
1153511535
// atomic qualification step.
1153611536
if (const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
11537-
AssignConvertType result =
11537+
AssignConvertType Result =
1153811538
CheckAssignmentConstraints(AtomicTy->getValueType(), RHS, Kind);
11539-
if (result != AssignConvertType::Compatible)
11540-
return result;
11539+
if (!IsAssignConvertCompatible(Result))
11540+
return Result;
1154111541
if (Kind != CK_NoOp && ConvertRHS)
1154211542
RHS = ImpCastExprToType(RHS.get(), AtomicTy->getValueType(), Kind);
1154311543
Kind = CK_NonAtomicToAtomic;
11544-
return AssignConvertType::Compatible;
11544+
return Result;
1154511545
}
1154611546

1154711547
// If the left-hand side is a reference type, then we are in a

clang/test/Sema/implicit-void-ptr-cast.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ void more(void) {
8282
ptr3 = SOMETHING_THAT_IS_NOT_NULL; // c-warning {{implicit conversion when assigning to 'char *' from type 'void *' is not permitted in C++}} \
8383
cxx-error {{assigning to 'char *' from incompatible type 'void *'}}
8484
}
85+
86+
void gh154157(void) {
87+
#define ATOMIC_VAR_INIT(value) (value)
88+
89+
typedef const struct T * T_Ref;
90+
static T_Ref _Atomic x = ATOMIC_VAR_INIT((void*)NULL); // c-warning {{implicit conversion when initializing '_Atomic(T_Ref)' with an expression of type 'void *' is not permitted in C++}} \
91+
cxx-error {{cannot initialize a variable of type '_Atomic(T_Ref)' with an rvalue of type 'void *'}}
92+
static T_Ref const y = ATOMIC_VAR_INIT((void*)NULL); // c-warning {{implicit conversion when initializing 'const T_Ref' (aka 'const struct T *const') with an expression of type 'void *' is not permitted in C++}} \
93+
cxx-error {{cannot initialize a variable of type 'const T_Ref' (aka 'const struct T *const') with an rvalue of type 'void *'}}
94+
static T_Ref z = ATOMIC_VAR_INIT((void*)NULL); // c-warning {{implicit conversion when initializing 'T_Ref' (aka 'const struct T *') with an expression of type 'void *' is not permitted in C++}} \
95+
cxx-error {{cannot initialize a variable of type 'T_Ref' (aka 'const struct T *') with an rvalue of type 'void *'}}
96+
}

0 commit comments

Comments
 (0)