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

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 14:39:50 PDT 2024


================
@@ -924,6 +939,23 @@ static bool checkExportedDeclContext(Sema &S, DeclContext *DC,
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
 
+  // HLSL: export declaration is valid only on functions
+  if (S.getLangOpts().HLSL) {
+    auto *FD = dyn_cast<FunctionDecl>(D);
+    if (!FD) {
+      if (auto *ED2 = dyn_cast<ExportDecl>(D)) {
+        S.Diag(ED2->getBeginLoc(), diag::err_export_within_export);
+        if (auto *ED1 = dyn_cast<ExportDecl>(D->getDeclContext()))
+          S.Diag(ED1->getBeginLoc(), diag::note_export);
+      }
----------------
bogner wrote:

On this note, we should also add a test like so:
```hlsl
export {
  export { // expected-error {{export declaration appears within another export declaration}}
    void f();
  }
}
```
    

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


More information about the cfe-commits mailing list