================
@@ -155,6 +155,29 @@ RValue 
CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const CallExpr *E) {
       E, this, GetVprintfDeclaration(CGM.getModule()), false);
 }
 
+// Collects the constant global variables that \p S refers to.
+static void
+collectReferencedGlobalVars(const ASTContext &Ctx, const Stmt *S,
+                            SmallVectorImpl<const VarDecl *> &Vars) {
+  if (!S)
+    return;
+  const ValueDecl *D = nullptr;
+  if (const auto *DRE = dyn_cast<DeclRefExpr>(S)) {
+    if (DRE->isNonOdrUse() == NOUR_None)
+      D = DRE->getDecl();
+  } else if (const auto *ME = dyn_cast<MemberExpr>(S)) {
+    if (ME->isNonOdrUse() == NOUR_None)
+      D = ME->getMemberDecl();
+  }
+  if (const auto *VD = dyn_cast_if_present<VarDecl>(D))
+    if (VD->hasGlobalStorage() && !VD->isStaticLocal() &&
+        VD->getType().isConstantStorage(Ctx, /*ExcludeCtor=*/true,
+                                        /*ExcludeDtor=*/true))
+      Vars.push_back(VD);
+  for (const Stmt *Child : S->children())
+    collectReferencedGlobalVars(Ctx, Child, Vars);
----------------
steffenlarsen wrote:

We definitely can! It has been done in the newest commit.

https://github.com/llvm/llvm-project/pull/231967
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to