Переглянути джерело

Merged PR 91: CG: Fix matrix component type name by using printing policy

CG: Fix matrix component type name by using printing policy
Tex Riddell 7 роки тому
батько
коміт
103d33ef5d

+ 1 - 1
tools/clang/include/clang/Basic/LangOptions.fixed.def

@@ -88,7 +88,7 @@ LANGOPT(AppExt , 1, 0, "Objective-C App Extension")
 LANGOPT(Trigraphs         , 1, 0,"trigraphs")
 LANGOPT(LineComment       , 1, 1, "'//' comments")
 LANGOPT(Bool              , 1, 1, "bool, true, and false keywords")
-LANGOPT(Half              , 1, 0, "half keyword")
+LANGOPT(Half              , 1, 1, "half keyword")
 LANGOPT(WChar             , 1, CPlusPlus, "wchar_t keyword")
 BENIGN_LANGOPT(DollarIdents   , 1, 1, "'$' in identifiers")
 BENIGN_LANGOPT(AsmPreprocessor, 1, 0, "preprocessor in asm mode")

+ 7 - 6
tools/clang/lib/CodeGen/CodeGenTypes.cpp

@@ -78,7 +78,8 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
     OS << suffix;
 
   // HLSL Change Starts
-  
+
+  const clang::PrintingPolicy &policy = RD->getASTContext().getPrintingPolicy();
   // Note that this check, like the 'abs' check, shouldn't happen by simple
   // string comparison; instead we can map the types and functions we
   // inject and look them up by a simple pointer value check.
@@ -86,16 +87,16 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
   if (isMatrix) {
     // Encode additional information into the type.
     const ClassTemplateSpecializationDecl* templateDecl = dyn_cast<ClassTemplateSpecializationDecl>(RD);
-    OS
-      << "." << templateDecl->getTemplateArgs().get(0).getAsType().getAsString()
-      << "." << templateDecl->getTemplateArgs().get(1).getAsIntegral().toString(10)
-      << "." << templateDecl->getTemplateArgs().get(2).getAsIntegral().toString(10);
+    QualType CompType = templateDecl->getTemplateArgs().get(0).getAsType();
+    OS  << ".";   CompType.print(OS, policy);
+    OS  << "." << templateDecl->getTemplateArgs().get(1).getAsIntegral().toString(10)
+        << "." << templateDecl->getTemplateArgs().get(2).getAsIntegral().toString(10);
   } else if (const ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
     const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
     TemplateSpecializationType::PrintTemplateArgumentList(OS,
                                                           TemplateArgs.data(),
                                                           TemplateArgs.size(),
-                                                          RD->getASTContext().getPrintingPolicy());
+                                                          policy);
   }
 
   // HLSL Change Ends

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

@@ -0,0 +1,12 @@
+// RUN: %dxc -enable-16bit-types -T lib_6_3 %s | FileCheck %s
+
+// CHECK: %class.matrix.half.4.3 = type { [4 x <3 x half>] }
+
+cbuffer CB : register(b0)
+{
+  row_major float16_t4x3 mat;
+};
+
+float3 foo() {
+  return mat[0];
+}