[clang] [HLSL] Implement `export` keyword (PR #96823)

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 15:49:01 PDT 2024


================
@@ -851,6 +851,21 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
   CurContext->addDecl(D);
   PushDeclContext(S, D);
 
+  if (getLangOpts().HLSL) {
+    // exported functions cannot be in an unnamed namespace
+    for (const DeclContext *DC = CurContext; DC; DC = DC->getLexicalParent()) {
+      if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
+        if (ND->isAnonymousNamespace()) {
+          Diag(ExportLoc, diag::err_export_within_anonymous_namespace);
+          Diag(ND->getLocation(), diag::note_anonymous_namespace);
+          D->setInvalidDecl();
+          return D;
+        }
+      }
+    }
+    return D;
+  }
----------------
hekota wrote:

Ok. I was debating whether to wrap all the other paths in `!getLangOpts().HLSL` or duplicate this one part and early exit.

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


More information about the cfe-commits mailing list