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

OP::GetTypeName - use struct name for UDT and return StringRef

Tex Riddell 7 жил өмнө
parent
commit
8beb970b51

+ 1 - 1
include/dxc/HLSL/DxilOperations.h

@@ -147,7 +147,7 @@ private:
   static const char *m_MatrixTypePrefix;
   static unsigned GetTypeSlot(llvm::Type *pType);
   static const char *GetOverloadTypeName(unsigned TypeSlot);
-  static const char *GetTypeName(llvm::Type *Ty, std::string &str);
+  static llvm::StringRef GetTypeName(llvm::Type *Ty, std::string &str);
 };
 
 } // namespace hlsl

+ 8 - 3
lib/HLSL/DxilOperations.cpp

@@ -356,18 +356,23 @@ const char *OP::GetOverloadTypeName(unsigned TypeSlot) {
   return m_OverloadTypeName[TypeSlot];
 }
 
-const char * OP::GetTypeName(Type *Ty, std::string &str) {
+llvm::StringRef OP::GetTypeName(Type *Ty, std::string &str) {
   unsigned TypeSlot = OP::GetTypeSlot(Ty);
   if (TypeSlot < kUserDefineTypeSlot) {
     return GetOverloadTypeName(TypeSlot);
+  } else if (TypeSlot == kUserDefineTypeSlot) {
+    if (Ty->isPointerTy())
+      Ty = Ty->getPointerElementType();
+    StructType *ST = cast<StructType>(Ty);
+    return ST->getStructName();
   } else if (TypeSlot == kObjectTypeSlot) {
     StructType *ST = cast<StructType>(Ty);
-    return ST->getStructName().data();
+    return ST->getStructName();
   } else {
     raw_string_ostream os(str);
     Ty->print(os);
     os.flush();
-    return str.c_str();
+    return str;
   }
 }