aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Compiler.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-05-01 07:35:33 +0200
committerGitHub <noreply@github.com>2025-05-01 07:35:33 +0200
commitc51be1be3ac9c66fc0c598298edd1fd224c1da07 (patch)
tree778c7149fd066431a475788dc99b4a913dbffcb5 /clang/lib/AST/ByteCode/Compiler.cpp
parentd0a97271a4ea2b0fe392afe498af20f8499260d2 (diff)
downloadllvm-c51be1be3ac9c66fc0c598298edd1fd224c1da07.zip
llvm-c51be1be3ac9c66fc0c598298edd1fd224c1da07.tar.gz
llvm-c51be1be3ac9c66fc0c598298edd1fd224c1da07.tar.bz2
[clang][bytecode] Fix checking for integer overflow (#137962)
We need to evaluate both the True/False expressions of a conditional operator as well as the LHS/RHS of a binary operator in more cases.
Diffstat (limited to 'clang/lib/AST/ByteCode/Compiler.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Compiler.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index fe8d05c..ae6574c 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -866,12 +866,14 @@ bool Compiler<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
// Assignments require us to evalute the RHS first.
if (BO->getOpcode() == BO_Assign) {
- // We don't support assignments in C.
- if (!Ctx.getLangOpts().CPlusPlus)
- return this->emitInvalid(BO);
if (!visit(RHS) || !visit(LHS))
return false;
+
+ // We don't support assignments in C.
+ if (!Ctx.getLangOpts().CPlusPlus && !this->emitInvalid(BO))
+ return false;
+
if (!this->emitFlip(*LT, *RT, BO))
return false;
} else {
@@ -2367,8 +2369,19 @@ bool Compiler<Emitter>::VisitAbstractConditionalOperator(
return false;
}
- if (!this->visitBool(Condition))
+ if (!this->visitBool(Condition)) {
+ // If the condition failed and we're checking for undefined behavior
+ // (which only happens with EvalEmitter) check the TrueExpr and FalseExpr
+ // as well.
+ if (this->checkingForUndefinedBehavior()) {
+ if (!this->discard(TrueExpr))
+ return false;
+ if (!this->discard(FalseExpr))
+ return false;
+ }
return false;
+ }
+
if (!this->jumpFalse(LabelFalse))
return false;
if (!visitChildExpr(TrueExpr))