From: George Burgess IV Date: Wed, 7 Mar 2018 04:52:34 +0000 (+0000) Subject: Reland r326766 (with a slightly modified test) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2ba96f62365d8da4d01949474f65578637defbf;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326872 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 45df133ad5..c3e41658c2 100644 --- a/lib/AST/ExprConstant.cpp +++ b/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(E)) + E = EC->getSubExpr()->IgnoreParens(); + if (const auto *Cast = dyn_cast(E)) E = Cast->getSubExpr()->IgnoreParens(); diff --git a/test/CodeGenCXX/alloc-size.cpp b/test/CodeGenCXX/alloc-size.cpp index ac53ea8f8e..34892b8abc 100644 --- a/test/CodeGenCXX/alloc-size.cpp +++ b/test/CodeGenCXX/alloc-size.cpp @@ -70,3 +70,19 @@ int testIt() { __builtin_object_size(dependent_calloc2(), 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