[clang] [clang][bytecode] Fix discarding ImplitiValueInitExprs (PR #170089)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 1 01:08:42 PST 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/170089
They don't have side-effects, so this should be fine.
Fixes https://github.com/llvm/llvm-project/issues/170064
>From cdae33192a41233427caa7d5a4eebd5ab63a5348 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 1 Dec 2025 09:58:56 +0100
Subject: [PATCH] [clang][bytecode] Fix discarding ImplitiValueInitExprs
---
clang/lib/AST/ByteCode/Compiler.cpp | 3 +++
clang/test/AST/ByteCode/c.c | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index dd0b8e790d444..58e84ef70abb7 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1705,6 +1705,9 @@ bool Compiler<Emitter>::VisitFixedPointUnaryOperator(const UnaryOperator *E) {
template <class Emitter>
bool Compiler<Emitter>::VisitImplicitValueInitExpr(
const ImplicitValueInitExpr *E) {
+ if (DiscardResult)
+ return true;
+
QualType QT = E->getType();
if (OptPrimType T = classify(QT))
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index bffd557ff77a6..794181499cde9 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -392,3 +392,12 @@ void plainComplex(void) {
_Complex cd; // all-warning {{_Complex double}}
cd = *(_Complex *)&(struct { double r, i; }){0.0, 0.0}; // all-warning {{_Complex double}}
}
+
+/// This test results in an ImplicitValueInitExpr with DiscardResult set.
+struct M{};
+typedef struct S64 {
+ struct M m;
+ char a[64];
+} I64;
+
+_Static_assert((((I64){}, 1)), ""); // all-warning {{left operand of comma operator has no effect}}
More information about the cfe-commits
mailing list