[flang-commits] [libc] [libcxx] [compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
John McCall via flang-commits
flang-commits at lists.llvm.org
Fri Dec 15 11:35:34 PST 2023
================
@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
else
ArrayLV = EmitLValue(Array);
+
auto *Idx = EmitIdxAfterBase(/*Promote*/true);
+ if (SanOpts.has(SanitizerKind::ArrayBounds)) {
----------------
rjmccall wrote:
Yeah. Specifically, I was thinking that you already have the address of this flexible array member, and if the immediately containing struct is uniquely allocated directly within the root type of the `__counted_by` path, you can just find that offset statically and subtract to get a pointer to the root type. But of course that only works if it *is* uniquely allocated directly within the root type, which it isn't going to be in the general case if the root type is just some lexically-enclosing struct, which ties this back to the other conversation.
Stepping back for a second, I'm surprised you need to do so much from scratch for flexible arrays. Don't the other `-fbounds-safety` features already have some logic where they recognize e.g. a load from a `__counted_by` field of pointer type and then emit the count expression? How do those code paths solve this problem?
https://github.com/llvm/llvm-project/pull/73730
More information about the flang-commits
mailing list