[llvm-branch-commits] [llvm] [DirectX] Improve error handling and validation in root signature parsing (PR #144577)
Chris B via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jul 11 11:42:12 PDT 2025
================
@@ -48,6 +48,71 @@ static bool reportValueError(LLVMContext *Ctx, Twine ParamName,
return true;
}
+// Template function to get formatted type string based on C++ type
+template <typename T> std::string getTypeFormatted() {
+ if constexpr (std::is_same_v<T, MDString>) {
+ return "string";
+ } else if constexpr (std::is_same_v<T, MDNode *> ||
+ std::is_same_v<T, const MDNode *>) {
+ return "metadata";
+ } else if constexpr (std::is_same_v<T, ConstantAsMetadata *> ||
+ std::is_same_v<T, const ConstantAsMetadata *>) {
+ return "constant";
+ } else if constexpr (std::is_same_v<T, ConstantAsMetadata>) {
+ return "constant";
+ } else if constexpr (std::is_same_v<T, ConstantInt *> ||
+ std::is_same_v<T, const ConstantInt *>) {
+ return "constant int";
+ } else if constexpr (std::is_same_v<T, ConstantInt>) {
+ return "constant int";
+ }
+ return "unknown";
+}
+
+// Helper function to get the actual type of a metadata operand
+std::string getActualMDType(const MDNode *Node, unsigned Index) {
+ if (!Node || Index >= Node->getNumOperands())
+ return "null";
+
+ Metadata *Op = Node->getOperand(Index);
+ if (!Op)
+ return "null";
+
+ if (isa<MDString>(Op))
+ return getTypeFormatted<MDString>();
+
+ if (isa<ConstantAsMetadata>(Op)) {
+ if (auto *CAM = dyn_cast<ConstantAsMetadata>(Op)) {
+ Type *T = CAM->getValue()->getType();
+ if (T->isIntegerTy())
+ return (Twine("i") + Twine(T->getIntegerBitWidth())).str();
+ if (T->isFloatingPointTy())
+ return T->isFloatTy() ? getTypeFormatted<float>()
+ : T->isDoubleTy() ? getTypeFormatted<double>()
+ : "fp";
+
+ return getTypeFormatted<ConstantAsMetadata>();
+ }
+ }
+ if (isa<MDNode>(Op))
+ return getTypeFormatted<MDNode *>();
+
+ return "unknown";
+}
+
+// Helper function to simplify error reporting for invalid metadata values
+template <typename ET>
+auto reportInvalidTypeError(LLVMContext *Ctx, Twine ParamName,
----------------
llvm-beanz wrote:
`auto` as a return type rarely meets LLVM's coding standards:
see: https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
https://github.com/llvm/llvm-project/pull/144577
More information about the llvm-branch-commits
mailing list