aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-07-13 20:48:52 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-07-13 20:48:52 +0000
commitf195f2cacf149286232d66578fad3370efa5f567 (patch)
tree0d3eb52e1a7281be1d85c0af80b461137c1a1858
parent916ea6522a200c4a3a4f5eecd29ee7bea315be5f (diff)
add support for conditional expressions in Expr::HasSideEffects()
This fixes a bug in __builtin_object_size() codegen git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160191 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ExprConstant.cpp3
-rw-r--r--test/CodeGen/object-size.c11
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index ad5aa54e48..eb34fc5fca 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -2323,6 +2323,9 @@ public:
{ return Visit(E->getLHS()) || Visit(E->getRHS()); }
bool VisitChooseExpr(const ChooseExpr *E)
{ return Visit(E->getChosenSubExpr(Ctx)); }
+ bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
+ { return Visit(E->getCond()) || Visit(E->getTrueExpr())
+ || Visit(E->getFalseExpr()); }
bool VisitCastExpr(const CastExpr *E) { return Visit(E->getSubExpr()); }
bool VisitBinAssign(const BinaryOperator *E) { return true; }
bool VisitCompoundAssignOperator(const BinaryOperator *E) { return true; }
diff --git a/test/CodeGen/object-size.c b/test/CodeGen/object-size.c
index df6189ef10..f6c7db835b 100644
--- a/test/CodeGen/object-size.c
+++ b/test/CodeGen/object-size.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - 2>&1 | FileCheck %s
#define strcpy(dest, src) \
((__builtin_object_size(dest, 0) != -1ULL) \
@@ -127,6 +127,7 @@ void test16() {
strcpy(gp += 1, "Hi there");
}
+// CHECK: @test17
void test17() {
// CHECK: store i32 -1
gi = __builtin_object_size(gp++, 0);
@@ -137,3 +138,11 @@ void test17() {
// CHECK: store i32 0
gi = __builtin_object_size(gp++, 3);
}
+
+// CHECK: @test18
+unsigned test18(int cond) {
+ int a[4], b[4];
+ // CHECK: phi i32*
+ // CHECK: call i64 @llvm.objectsize.i64
+ return __builtin_object_size(cond ? a : b, 0);
+}