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

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 14:34:18 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;
+  }
----------------
bogner wrote:

This looks nearly identical to the logic for erroring in an anonymous namespace for C++ modules below - can we share the code?

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


More information about the cfe-commits mailing list