rnk added inline comments.

================
Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2263
   if (DebugKind == codegenoptions::DebugInfoConstructor &&
-      !CXXDecl->isLambda() && !isClassOrMethodDLLImport(CXXDecl)) {
-    for (const auto *Ctor : CXXDecl->ctors()) {
+      !CXXDecl->isLambda() && !CXXDecl->isLiteral() &&
+      !isClassOrMethodDLLImport(CXXDecl))
----------------
I'm not sure `isLiteral` is quite the right check. I think there are some ways 
to:
- have a type that is not literal
- construct it at compile time with the constexpr constructor
- skip object destruction

I came up with this example:
```
struct ConstexprCtor {
  constexpr ConstexprCtor(int a, int b) : a(a + 1), b(b + 1) {}
  ~ConstexprCtor();
  int a, b;
};

[[clang::no_destroy]] ConstexprCtor static_gv{1, 2};
```

I tried to find other ways to construct a class in a constexpr context without 
running the destructor, but wasn't able to.

It would also be interesting to know if StringRef and ArrayRef are literal or 
not. Those seem like types that we would want to apply this optimization to, 
and they have constexpr constructors. Maybe we can find a way to apply the 
optimization by figuring out if a constexpr constructor has been evaluated. You 
could look at who calls `Sema::MarkFunctionReferenced` and see if there are any 
callbacks into the ASTConsumer around there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77432



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to