bwendling 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.
Right. That's what I want to add to the front-end. > 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); > } > ``` Yup! I've been forbidden from doing this in the back-end, so I have to jump through hoops now and do partial solutions and hope that it works for most people and that when we get it wrong it doesn't hurt security (spoilers: it will). 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