llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-hlsl

Author: Macro Terra (hongtaihu)

<details>
<summary>Changes</summary>

hasConstantBufferLayout iterates fields and accesses base class info of 
CXXRecordDecl
without checking hasDefinition(), causing an assertion:

  Assertion `DD &amp;&amp; "queried property of class with no definition"' 
failed.

This is triggered when clangd opens HLSL files whose compile_commands.json has
`-x hlsl` without a DXIL/SPIR-V target triple. In this state, HLSL builtin
types like SamplerState exist as forward-declared CXXRecordDecls without
HLSLResourceAttr, bypassing the isHLSLResourceRecord() early return.

Fix: add hasDefinition() guard before accessing record fields and bases.

Fixes #<!-- -->198349.
Assisted by: claude code.

---
Full diff: https://github.com/llvm/llvm-project/pull/209692.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaHLSL.cpp (+2) 


``````````diff
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index ae6cbce2f890c..3bd1f06355205 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -5187,6 +5187,8 @@ static bool hasConstantBufferLayout(QualType QT) {
     return false;
 
   if (const auto *RD = Ty->getAsCXXRecordDecl()) {
+    if (!RD->hasDefinition())
+      return false;
     for (const auto *FD : RD->fields()) {
       if (hasConstantBufferLayout(FD->getType()))
         return true;

``````````

</details>


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

Reply via email to