https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/220891
>From bb2bb587d304987c58787b5f7833b070ca822569 Mon Sep 17 00:00:00 2001 From: Henrich Lauko <[email protected]> Date: Thu, 3 Sep 2026 12:44:31 +0000 Subject: [PATCH] [CIR] Derive lowering attr names from cppClassName, not the def name CIRLoweringEmitter built its CXX_ABI_ALWAYS_LEGAL_ATTRS entries with GetOpCppClassName, which splits the TableGen def name at the first underscore. That works only while every def is named CIR_<CppClassName>Attr. When one is not, the emitter writes an `isa<>` for a class that does not exist, and the failure lands as a compile error in generated code. Attributes carry the authoritative name in cppClassName, which GenerateAttrToValueVisitor was already reading. Factor that out as GetAttrCppClassRef and use it for both attribute paths. GetOpCppClassName stays for operations. The def name is now free, so CIREnumAttr.td drops the paragraph warning that it is not. NFC, and checkable. No CIR attribute overrides cppClassName, so the generated CIRLowering.inc is byte-identical. --- .../clang/CIR/Dialect/IR/CIREnumAttr.td | 4 --- clang/utils/TableGen/CIRLoweringEmitter.cpp | 26 ++++++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td b/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td index 3659eb71257f8..26bccc6090b37 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td +++ b/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td @@ -46,10 +46,6 @@ class CIR_I32BitEnumAttr<string name, string summary, // must therefore wrap the argument in the `enum` assembly format directive, // as in `enum($cleanupKind)`. Referring to the argument directly would print // the stripped attribute body, i.e. `<all>` including the delimiters. -// -// The def name is not free: `CIRLoweringEmitter` derives an `isa<cir::...>` -// entry for `CXXABILowering.cpp` by dropping the prefix up to the first -// underscore, so a def must be named `CIR_<CppClassName>`. class CIR_EnumAttr<EnumAttrInfo info, string name = "", list<Trait> traits = []> : EnumAttr<CIR_Dialect, info, name, traits> { let assemblyFormat = "`<` $value `>`"; diff --git a/clang/utils/TableGen/CIRLoweringEmitter.cpp b/clang/utils/TableGen/CIRLoweringEmitter.cpp index f67c37b9e1870..39be43a337c74 100644 --- a/clang/utils/TableGen/CIRLoweringEmitter.cpp +++ b/clang/utils/TableGen/CIRLoweringEmitter.cpp @@ -62,6 +62,19 @@ std::string GetOpCppClassName(const Record *OpRecord) { return CppClassName.str(); } +// Returns the namespace-qualified C++ class name of an attribute. Unlike +// operations, attributes carry the authoritative name in cppClassName, so the +// def name is free to differ from it. +std::string GetAttrCppClassRef(const Record *AttrRecord) { + StringRef Ns = + AttrRecord->getValueAsDef("dialect")->getValueAsString("cppNamespace"); + Ns.consume_front("::"); + std::string CppClassRef = Ns.str(); + CppClassRef += "::"; + CppClassRef += AttrRecord->getValueAsString("cppClassName"); + return CppClassRef; +} + std::string GetOpABILoweringPatternName(llvm::StringRef OpName) { std::string Name = "CIR"; Name += OpName; @@ -286,19 +299,13 @@ void Generate(const Record *OpRecord) { } void GenerateCIREnumAttrs(const Record *Record) { - std::string OpName = GetOpCppClassName(Record); // EnumAttr is in a separate hierarchy, so we have to set these separately, as // they never have an 'illegal' CXXABI type in them. - CXXABILoweringAttrAlwaysLegal.push_back("cir::" + OpName); + CXXABILoweringAttrAlwaysLegal.push_back(GetAttrCppClassRef(Record)); } void GenerateAttrToValueVisitor(const Record *Rec) { - const Record *DialectRec = Rec->getValueAsDef("dialect"); - llvm::StringRef Ns = DialectRec->getValueAsString("cppNamespace"); - Ns.consume_front("::"); - std::string CppClassRef = Ns.str(); - CppClassRef += "::"; - CppClassRef += Rec->getValueAsString("cppClassName"); + std::string CppClassRef = GetAttrCppClassRef(Rec); std::string CodeBuffer; llvm::raw_string_ostream Code(CodeBuffer); @@ -327,9 +334,8 @@ void GenerateAttrToValueVisitFunc() { } void GenerateCIRAttrs(const Record *Record) { - std::string OpName = GetOpCppClassName(Record); if (!Record->getValueAsBit("canHaveIllegalCXXABIType")) - CXXABILoweringAttrAlwaysLegal.push_back("cir::" + OpName); + CXXABILoweringAttrAlwaysLegal.push_back(GetAttrCppClassRef(Record)); if (Record->getValueAsBit("hasAttrToValueLowering")) GenerateAttrToValueVisitor(Record); } _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
