[compiler-rt] [clang] [libcxx] [libc] [flang] [llvm] [clang-tools-extra] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 15 11:07:03 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)) {
----------------
bwendling wrote:

Do you mean perform something like this:

```
Transform this:

ArraySubscriptExpr ...
|- ImplicitCastExpr
| `-MemberExpr ... ->arr
...
|
`- <index expr>

Into this (pseudo code):

CastExpr ... <'count' type>
`- BinaryOp ... <subtraction>
  |- MemberExpr ... ->arr
 ...
  |
  `- ConstantExpr ... <offset of 'count' relative to 'arr'
```

Quite possibly.... That would certainly solve a lot of headaches.

https://github.com/llvm/llvm-project/pull/73730


More information about the cfe-commits mailing list