[PATCH] D12000: Bugfix - Clang handles __builtin_object_size in wrong way

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 14 17:11:43 PDT 2015


rsmith added a subscriber: rsmith.

================
Comment at: lib/AST/ExprConstant.cpp:6221-6223
@@ +6220,5 @@
+  //
+  //   extern struct X { char buff[32]; int a, b, c; } *p;
+  //   int a = __builtin_object_size(p->buff + 4, 3); // returns 28
+  //   int b = __builtin_object_size(p->buff + 4, 2); // returns 0, not 40
+  //
----------------
Please add a testcase like this (where the base object is unknown but the designator is known, and thus we can compute the Type == 1 and Type == 3 forms but not the Type == 0 and Type == 2 forms).

================
Comment at: lib/AST/ExprConstant.cpp:6243-6245
@@ +6242,5 @@
+  } else if (End.Designator.IsOnePastTheEnd) {
+    // We're already pointing at the end of the object.
+    AmountToAdd = 0;
+  }
+
----------------
Please add testcases for the pointer-to-the-end case:

  int n;
  static_assert(__builtin_object_size(&n + 1, 1) == 0);

  struct X { int a, b, c; } x;
  static_assert(__builtin_object_size(&x.a + 1, 1) == 0);



http://reviews.llvm.org/D12000





More information about the cfe-commits mailing list