[clang] [HLSL] Rewrite semantics parsing (PR #152537)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 8 10:41:08 PDT 2025


Nathan =?utf-8?q?Gauër?= <brioche at google.com>,
Nathan =?utf-8?q?Gauër?= <brioche at google.com>,
Nathan =?utf-8?q?Gauër?= <brioche at google.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/152537 at github.com>


================
@@ -282,14 +327,17 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs,
       return;
     }
   } break;
-  case ParsedAttr::UnknownAttribute:
-    Diag(Loc, diag::err_unknown_hlsl_semantic) << II;
-    return;
-  case ParsedAttr::AT_HLSLSV_GroupThreadID:
-  case ParsedAttr::AT_HLSLSV_GroupID:
-  case ParsedAttr::AT_HLSLSV_GroupIndex:
-  case ParsedAttr::AT_HLSLSV_DispatchThreadID:
-  case ParsedAttr::AT_HLSLSV_Position:
+  case ParsedAttr::AT_HLSLUnparsedSemantic: {
+    ASTContext &Ctx = Actions.getASTContext();
+    ArgExprs.push_back(IntegerLiteral::Create(
+        Ctx, llvm::APInt(Ctx.getTypeSize(Ctx.IntTy), Semantic.Index), Ctx.IntTy,
+        SourceLocation()));
+    ArgExprs.push_back(IntegerLiteral::Create(
+        Ctx, llvm::APInt(1, Semantic.Explicit), Ctx.BoolTy, SourceLocation()));
+    II = PP.getIdentifierInfo(Semantic.Name.upper());
----------------
llvm-beanz wrote:

This has an unfortunate side effect of changing the diagnostic printing to all upper case. I'm not sure this is really what we want.

Because the preprocessor can be involved here (for example https://godbolt.org/z/n3fx8Kraf), the error message may not annotate clearly the line that has the semantic string. Keeping the semantic string preserved as it is in source is pretty important for enabling users to copy and then search the text.

The existing tests consciously preserved capitalization as the user spelled it for this reason.

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


More information about the cfe-commits mailing list