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

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 12 17:02:36 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:

So just to be clear, you want me to bypass this code:

```
    LValue ArrayLV;
    // For simple multidimensional array indexing, set the 'accessed' flag for
    // better bounds-checking of the base expression.
    if (const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
      ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
    else
      ArrayLV = EmitLValue(Array);
    auto *Idx = EmitIdxAfterBase(/*Promote*/true);
```

and instead calculate the base pointer from the `Array` that will point to both `count` and `array`. Then emit that pointer, and then append to that GEPs to access `count` and `array` that I calculate by hand?

That sounds incredibly fragile, given the complexity of both of the above `Emit*Expr` methods. But if that will finally get some approval, I'll cobble it together. It'll almost certainly fail for some side case, but I'm stupid, so what do I know.

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


More information about the cfe-commits mailing list