summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2018-03-07 04:52:34 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2018-03-07 04:52:34 +0000
commit4763876f4b417b9effb7d4737dc22007e44a9c19 (patch)
treeaafb3765618cb377739f9ee515587b53f52cff41 /clang
parentbec42c848ddc0eb525d1a3c63ba3f65961848f2f (diff)
downloadbcm5719-llvm-4763876f4b417b9effb7d4737dc22007e44a9c19.tar.gz
bcm5719-llvm-4763876f4b417b9effb7d4737dc22007e44a9c19.zip
Reland r326766 (with a slightly modified test)
The original revert was done in r326869, since reverting r326602 broke the test added by this. The new test should be less dependent on r326602. llvm-svn: 326872
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/ExprConstant.cpp6
-rw-r--r--clang/test/CodeGenCXX/alloc-size.cpp16
2 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 45df133ad57..c3e41658c29 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -133,7 +133,11 @@ namespace {
E = E->IgnoreParens();
// If we're doing a variable assignment from e.g. malloc(N), there will
- // probably be a cast of some kind. Ignore it.
+ // probably be a cast of some kind. In exotic cases, we might also see a
+ // top-level ExprWithCleanups. Ignore them either way.
+ if (const auto *EC = dyn_cast<ExprWithCleanups>(E))
+ E = EC->getSubExpr()->IgnoreParens();
+
if (const auto *Cast = dyn_cast<CastExpr>(E))
E = Cast->getSubExpr()->IgnoreParens();
diff --git a/clang/test/CodeGenCXX/alloc-size.cpp b/clang/test/CodeGenCXX/alloc-size.cpp
index ac53ea8f8ea..34892b8abc2 100644
--- a/clang/test/CodeGenCXX/alloc-size.cpp
+++ b/clang/test/CodeGenCXX/alloc-size.cpp
@@ -70,3 +70,19 @@ int testIt() {
__builtin_object_size(dependent_calloc2<int, 9>(), 0);
}
} // namespace templated_alloc_size
+
+// Be sure that an ExprWithCleanups doesn't deter us.
+namespace alloc_size_with_cleanups {
+struct Foo {
+ ~Foo();
+};
+
+void *my_malloc(const Foo &, int N) __attribute__((alloc_size(2)));
+
+// CHECK-LABEL: define i32 lalala
+int testIt() {
+ int *const p = (int *)my_malloc(Foo{}, 3);
+ // CHECK: ret i32 3
+ return __builtin_object_size(p, 0);
+}
+} // namespace alloc_size_with_cleanups
OpenPOWER on IntegriCloud