Skip to content

Commit b162099

Browse files
authored
[clang][bytecode] Fix discarding ImplitiValueInitExprs (llvm#170089)
They don't have side-effects, so this should be fine. Fixes llvm#170064
1 parent 2c9e9ff commit b162099

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,9 @@ bool Compiler<Emitter>::VisitFixedPointUnaryOperator(const UnaryOperator *E) {
17051705
template <class Emitter>
17061706
bool Compiler<Emitter>::VisitImplicitValueInitExpr(
17071707
const ImplicitValueInitExpr *E) {
1708+
if (DiscardResult)
1709+
return true;
1710+
17081711
QualType QT = E->getType();
17091712

17101713
if (OptPrimType T = classify(QT))

clang/test/AST/ByteCode/c.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,16 @@ void plainComplex(void) {
392392
_Complex cd; // all-warning {{_Complex double}}
393393
cd = *(_Complex *)&(struct { double r, i; }){0.0, 0.0}; // all-warning {{_Complex double}}
394394
}
395+
396+
/// This test results in an ImplicitValueInitExpr with DiscardResult set.
397+
struct M{
398+
char c;
399+
};
400+
typedef struct S64 {
401+
struct M m;
402+
char a[64];
403+
} I64;
404+
405+
_Static_assert((((I64){}, 1)), ""); // all-warning {{left operand of comma operator has no effect}} \
406+
// pedantic-warning {{use of an empty initializer is a C23 extension}} \
407+
// pedantic-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}

0 commit comments

Comments
 (0)