Browse Source

Fix anonymous struct cbuffer (#1134)

Anonymous structures were not added to $Globals because they are
not externally visible.

Fixes #1075: dxcompiler drops anonymous struct cbuffer
Helena Kotas 7 years ago
parent
commit
20353da208

+ 1 - 1
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -1901,7 +1901,7 @@ void CGMSHLSLRuntime::addResource(Decl *D) {
     if (VD->hasInit() && resClass != DXIL::ResourceClass::Invalid)
     if (VD->hasInit() && resClass != DXIL::ResourceClass::Invalid)
       return;
       return;
     // skip static global.
     // skip static global.
-    if (!VD->isExternallyVisible()) {
+    if (!VD->hasExternalFormalLinkage()) {
       if (VD->hasInit() && VD->getType().isConstQualified()) {
       if (VD->hasInit() && VD->getType().isConstQualified()) {
         Expr* InitExp = VD->getInit();
         Expr* InitExp = VD->getInit();
         GlobalVariable *GV = cast<GlobalVariable>(CGM.GetAddrOfGlobalVar(VD));
         GlobalVariable *GV = cast<GlobalVariable>(CGM.GetAddrOfGlobalVar(VD));

+ 12 - 0
tools/clang/test/CodeGenHLSL/quick-test/anon_struct.hlsl

@@ -0,0 +1,12 @@
+// RUN: %dxc -T ps_6_0 -E main %s | FileCheck %s
+
+// CHECK: %"$Globals" = type { %struct.anon }
+// CHECK: @dx.op.cbufferLoadLegacy
+
+struct {
+    int X;
+} CB;
+
+float main(int N : A, int C : B) : SV_TARGET {
+    return CB.X;
+}