[PATCH] D133361: [BPF] Attribute preserve_static_offset for structs

Eduard Zingerman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 2 07:33:41 PDT 2023


eddyz87 added inline comments.


================
Comment at: clang/lib/CodeGen/CGExpr.cpp:3700
+    return false;
+  if (auto *BaseDecl = E->getType()->getPointeeType()->getAsRecordDecl())
+    return hasBPFPreserveStaticOffset(BaseDecl);
----------------
erichkeane wrote:
> getPointeeType can also return nullptr, so unless you have a test elsewhere to ensure it isn't, you likely have to do a little more work here (and if so, I'd need an assert).
Is it? I actually double-checked this before pushing an update, clangd jumps to the following definition:

```
lang=cpp
QualType Type::getPointeeType() const {
  if (const auto *PT = getAs<PointerType>())
    return PT->getPointeeType();
  ...
  return {};
}
```

The `getAsRecordDecl()` can return null indeed, but that null is checked.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133361/new/

https://reviews.llvm.org/D133361



More information about the cfe-commits mailing list