Browse Source

Take care ParenExpr when get concrete type for literal. (#91)

Xiang Li 8 years ago
parent
commit
dedba5e584

+ 3 - 0
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -4342,6 +4342,9 @@ static ArBasicKind LiteralToConcrete(Expr *litExpr) {
     ArBasicKind kind1 = LiteralToConcrete(BO->getRHS());
     CombineBasicTypes(kind, kind1, &kind);
     return kind;
+  } else if (ParenExpr *PE = dyn_cast<ParenExpr>(litExpr)) {
+    ArBasicKind kind = LiteralToConcrete(PE->getSubExpr());
+    return kind;
   } else {
     // Could only be function call.
     CallExpr *CE = cast<CallExpr>(litExpr);

+ 7 - 0
tools/clang/test/CodeGenHLSL/lit_in_paren.hlsl

@@ -0,0 +1,7 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: dx.op.evalSampleIndex.f32(i32 88, i32 0, i32 0, i8 0, i32 2)
+
+float4 main(float4 a : A) : SV_TARGET {
+  return EvaluateAttributeAtSample(a, (2));
+}

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

@@ -384,6 +384,7 @@ public:
   TEST_METHOD(CodeGenIntrinsic4_dbg)
   TEST_METHOD(CodeGenIntrinsic5)
   TEST_METHOD(CodeGenLegacyStruct)
+  TEST_METHOD(CodeGenLitInParen)
   TEST_METHOD(CodeGenLiteralShift)
   TEST_METHOD(CodeGenLiveness1)
   TEST_METHOD(CodeGenLoop1)
@@ -2180,6 +2181,10 @@ TEST_F(CompilerTest, CodeGenLegacyStruct) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\legacy_struct.hlsl");
 }
 
+TEST_F(CompilerTest, CodeGenLitInParen) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\lit_in_paren.hlsl");
+}
+
 TEST_F(CompilerTest, CodeGenLiteralShift) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\literalShift.hlsl");
 }