[PATCH] D18438: Calculate __builtin_object_size when pointer depends on a condition

George Burgess IV via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 12:42:39 PDT 2016


george.burgess.iv added inline comments.

================
Comment at: lib/Analysis/MemoryBuiltins.cpp:574
@@ +573,3 @@
+        FalseSide.second.sgt(FalseSide.first)) {
+      return unknown();
+    }
----------------
spetrovic wrote:
> What do you think if we return unknown value if one of sides (true or false) has offset out of bounds, or you have some advice to return something else? Second proposal is to return some invalid value in SizeOffsetType object?
> What do you think if we return unknown value if one of sides (true or false) has offset out of bounds

I think that the goal of this code is to basically turn:

```
__builtin_object_size(a ? b : c, N);
```

into

```
max(__builtin_object_size(b, N), __builtin_object_size(c, N));
```

(or `min`, if N is 2 or 3).

If this is correct, I would expect `foo` below to return 3 if it isn't inlined:

```
int foo(int i) {
  char c[3];
  return __builtin_object_size(i ? c : c + 5, 0);
}
```

...because `__bos(c, 0)` should hand back 3, `__bos(c + 5, 0)` should hand back 0, and `max(3, 0)` is 3. So, I don't see how returning `unknown` makes sense.


Repository:
  rL LLVM

http://reviews.llvm.org/D18438





More information about the llvm-commits mailing list