Author: gbiv Date: Tue Mar 6 20:52:34 2018 New Revision: 326872 URL: http://llvm.org/viewvc/llvm-project?rev=326872&view=rev Log: 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. Modified: cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/CodeGenCXX/alloc-size.cpp Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=326872&r1=326871&r2=326872&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Mar 6 20:52:34 2018 @@ -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(); Modified: cfe/trunk/test/CodeGenCXX/alloc-size.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alloc-size.cpp?rev=326872&r1=326871&r2=326872&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/alloc-size.cpp (original) +++ cfe/trunk/test/CodeGenCXX/alloc-size.cpp Tue Mar 6 20:52:34 2018 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits