[clang] [clang][HLSL] Fix assertion crash on forward-declared record in hasConstantBufferLayout (#198349) (PR #209692)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 06:54:30 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
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 && "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
More information about the cfe-commits
mailing list