[clang] [clang][bytecode] Fix ignoring comparisons in C (PR #156180)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 30 06:31:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Our comparison ops always return bool, and we do the pop before the conversion to in in C.
Fixes #<!-- -->156178
---
Full diff: https://github.com/llvm/llvm-project/pull/156180.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+1-1)
- (modified) clang/test/AST/ByteCode/c.c (+6)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index c314f0a132196..56552f3969216 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -942,7 +942,7 @@ bool Compiler<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
if (!Result)
return false;
if (DiscardResult)
- return this->emitPop(*T, BO);
+ return this->emitPopBool(BO);
if (T != PT_Bool)
return this->emitCast(PT_Bool, *T, BO);
return true;
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 05af00c040f45..b6d2a69271afb 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -362,3 +362,9 @@ void bar() { // pedantic-warning {{a function declaration without a prototype}}
int x;
x = foo(); // all-warning {{too few arguments}}
}
+
+int *_b = &a;
+void discardedCmp(void)
+{
+ (*_b) = ((&a == &a) , a); // all-warning {{left operand of comma operator has no effect}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/156180
More information about the cfe-commits
mailing list