]> granicus.if.org Git - clang/commitdiff
[ExprConstant] Look through ExprWithCleanups for `allocsize`
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 6 Mar 2018 07:42:36 +0000 (07:42 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 6 Mar 2018 07:42:36 +0000 (07:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326766 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/CodeGenCXX/alloc-size.cpp

index bac2356cc43fd3dbd935de417324705138584b43..135e70e96ad6cb3d14ea44a73a35a9ee9dd4a0bb 100644 (file)
@@ -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();
 
index 137d4543ddcdc86a5782dd51291904c8ff0669d3..275ffe6dca9aa8e5d9ababafdf3f3b86aada3f99 100644 (file)
@@ -88,3 +88,15 @@ int callMemberCalloc() {
   // CHECK: ret i32 32
   return __builtin_object_size(C().my_calloc(16, 2), 0);
 }
+
+struct D {
+  ~D();
+  void *my_malloc(int N) __attribute__((alloc_size(2)));
+};
+
+// CHECK-LABEL: define i32 @_Z20callExprWithCleanupsv
+int callExprWithCleanups() {
+  int *const p = (int *)D().my_malloc(3);
+  // CHECK: ret i32 3
+  return __builtin_object_size(p, 0);
+}