efriedma-quic wrote:

> ```c
> struct x {
>     int a;
>     char foo[2][40];
>     int b;
>     int c;
> };
> 
> size_t f(struct x *p, int idx) {
>     return __builtin_dynamic_object_size(&p->foo[idx], 1);
> }
> ```

If I'm following correctly, the return here is 0, 40, or 80, depending on the 
value of idx?  That's not a constant, but the computation is entirely 
syntactic; it doesn't matter what "p" actually points to.  So clang can lower 
the builtin itself.  Currently it doesn't, I think, because all the relevant 
code is in ExprConstant, but the code could be adapted.

The problem, really, is that we can't easily extend that approach to stuff like 
the following:

```c
size_t f(struct x *p, int idx) {
    char *c = &p->foo[idx];
    return __builtin_dynamic_object_size(c, 1);
}
```

https://github.com/llvm/llvm-project/pull/78526
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to