2
0
Эх сурвалжийг харах

Lookup attribute variable from CurScope instead of TUScope. (#214)

Xiang Li 8 жил өмнө
parent
commit
cf2cf6edf9

+ 4 - 1
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -9398,7 +9398,10 @@ static int ValidateAttributeIntArg(Sema& S, const AttributeList &Attr, unsigned
     if (!Attr.isArgExpr(index)) {
     if (!Attr.isArgExpr(index)) {
       // For case arg is constant variable.
       // For case arg is constant variable.
       IdentifierLoc *loc = Attr.getArgAsIdent(index);
       IdentifierLoc *loc = Attr.getArgAsIdent(index);
-      VarDecl *decl = dyn_cast<VarDecl>(S.LookupSingleName(S.TUScope, loc->Ident, loc->Loc, Sema::LookupNameKind::LookupOrdinaryName));
+
+      VarDecl *decl = dyn_cast_or_null<VarDecl>(
+          S.LookupSingleName(S.getCurScope(), loc->Ident, loc->Loc,
+                             Sema::LookupNameKind::LookupOrdinaryName));
       if (!decl) {
       if (!decl) {
         S.Diag(Attr.getLoc(), diag::warn_hlsl_attribute_expects_uint_literal) << Attr.getName();
         S.Diag(Attr.getLoc(), diag::warn_hlsl_attribute_expects_uint_literal) << Attr.getName();
         return value;
         return value;

+ 19 - 0
tools/clang/test/CodeGenHLSL/loop6.hlsl

@@ -0,0 +1,19 @@
+// RUN: %dxc -E main -O2 -T ps_6_0 %s | FileCheck %s
+
+// CHECK: !"llvm.loop.unroll.count", i32 8
+
+float main(float2 a : A, int3 b : B) : SV_Target
+{
+  float s = 0;
+  const uint l = 8;
+  if (b.y > 3) {
+    while (a.y > 1) {
+      [unroll(l)]
+      for(int i = 0; i < b.x; i++) {
+        s += a.x;
+      }
+      a.y--;
+    }
+  }
+  return s;
+}

+ 5 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -421,6 +421,7 @@ public:
   TEST_METHOD(CodeGenLoop3)
   TEST_METHOD(CodeGenLoop3)
   TEST_METHOD(CodeGenLoop4)
   TEST_METHOD(CodeGenLoop4)
   TEST_METHOD(CodeGenLoop5)
   TEST_METHOD(CodeGenLoop5)
+  TEST_METHOD(CodeGenLoop6)
   TEST_METHOD(CodeGenMatElt)
   TEST_METHOD(CodeGenMatElt)
   TEST_METHOD(CodeGenMatInit)
   TEST_METHOD(CodeGenMatInit)
   TEST_METHOD(CodeGenMatMulMat)
   TEST_METHOD(CodeGenMatMulMat)
@@ -2489,6 +2490,10 @@ TEST_F(CompilerTest, CodeGenLoop5) {
   CodeGenTest(L"..\\CodeGenHLSL\\loop5.hlsl");
   CodeGenTest(L"..\\CodeGenHLSL\\loop5.hlsl");
 }
 }
 
 
+TEST_F(CompilerTest, CodeGenLoop6) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\loop6.hlsl");
+}
+
 TEST_F(CompilerTest, CodeGenMatElt) {
 TEST_F(CompilerTest, CodeGenMatElt) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\matElt.hlsl");
   CodeGenTestCheck(L"..\\CodeGenHLSL\\matElt.hlsl");
 }
 }