Skip to content

Commit ae434cd

Browse files
authored
[C] Fix issue with -Wimplicit-void-ptr-cast (#154351)
The changes from #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 #154157 co-authored-by: @ahatanak
1 parent 5cc8c92 commit ae434cd

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
@@ -9317,14 +9317,14 @@ AssignConvertType Sema::CheckAssignmentConstraints(QualType LHSType,
93179317
// If we have an atomic type, try a non-atomic assignment, then just add an
93189318
// atomic qualification step.
93199319
if (const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
9320-
AssignConvertType result =
9320+
AssignConvertType Result =
93219321
CheckAssignmentConstraints(AtomicTy->getValueType(), RHS, Kind);
9322-
if (result != AssignConvertType::Compatible)
9323-
return result;
9322+
if (!IsAssignConvertCompatible(Result))
9323+
return Result;
93249324
if (Kind != CK_NoOp && ConvertRHS)
93259325
RHS = ImpCastExprToType(RHS.get(), AtomicTy->getValueType(), Kind);
93269326
Kind = CK_NonAtomicToAtomic;
9327-
return AssignConvertType::Compatible;
9327+
return Result;
93289328
}
93299329

93309330
// 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)