https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/232299
These backends reported errors by calling SrcMgr.PrintMessage directly, which does not increment ErrorsPrinted, so clang-tblgen would print an error but still exit with status 0 and write its output file. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> >From f721b5bb0b91cd8ae5e0bb45af71c0df445b9621 Mon Sep 17 00:00:00 2001 From: Jay Foad <[email protected]> Date: Thu, 15 Oct 2026 13:27:39 +0100 Subject: [PATCH] [clang][TableGen] Use PrintError so that errors are counted These backends reported errors by calling SrcMgr.PrintMessage directly, which does not increment ErrorsPrinted, so clang-tblgen would print an error but still exit with status 0 and write its output file. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --- .../html-named-character-references-errors.td | 11 +++++++++++ clang/test/TableGen/redefined-group.td | 4 +++- ...ClangCommentHTMLNamedCharacterReferenceEmitter.cpp | 3 +-- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp | 10 ++++------ 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 clang/test/TableGen/html-named-character-references-errors.td diff --git a/clang/test/TableGen/html-named-character-references-errors.td b/clang/test/TableGen/html-named-character-references-errors.td new file mode 100644 index 00000000000000..138f9ffa521c36 --- /dev/null +++ b/clang/test/TableGen/html-named-character-references-errors.td @@ -0,0 +1,11 @@ +// RUN: not clang-tblgen -gen-clang-comment-html-named-character-references %s -o /dev/null 2>&1 | FileCheck %s + +class NCR<string spelling, int codePoint> { + string Spelling = spelling; + int CodePoint = codePoint; +} + +def : NCR<"valid", 0x41>; +def : NCR<"invalid", 0x110000>; +// CHECK: html-named-character-references-errors.td:[[@LINE-1]]:1: error: invalid code point +// CHECK: 1 errors. diff --git a/clang/test/TableGen/redefined-group.td b/clang/test/TableGen/redefined-group.td index 558c6775ef4bf4..093fbd6c398a3d 100644 --- a/clang/test/TableGen/redefined-group.td +++ b/clang/test/TableGen/redefined-group.td @@ -1,4 +1,4 @@ -// RUN: clang-tblgen -gen-clang-diag-groups -I%S %s -o /dev/null 2>&1 | FileCheck %s +// RUN: not clang-tblgen -gen-clang-diag-groups -I%S %s -o /dev/null 2>&1 | FileCheck %s include "DiagnosticBase.inc" def NamedGroup : DiagGroup<"a">; @@ -41,3 +41,5 @@ def InGroupF4 : Warning<"">, InGroup<DiagGroup<"f">>; // CHECK: redefined-group.td:[[@LINE-7]]:5: note: also implicitly defined here // CHECK: redefined-group.td:[[@LINE-6]]:5: note: also implicitly defined here // CHECK: redefined-group.td:[[@LINE-4]]:5: note: also implicitly defined here + +// CHECK: 6 errors. diff --git a/clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp b/clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp index e5eec5e7ca8d46..e0445929530d44 100644 --- a/clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp +++ b/clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp @@ -56,8 +56,7 @@ void clang::EmitClangCommentHTMLNamedCharacterReferences( CLiteral.clear(); CLiteral.append("return "); if (!translateCodePointToUTF8(CodePoint, CLiteral)) { - SrcMgr.PrintMessage(Tag->getLoc().front(), SourceMgr::DK_Error, - Twine("invalid code point")); + PrintError(Tag->getLoc().front(), "invalid code point"); continue; } CLiteral.append(";"); diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp index 2fe7dc64fbdc6d..dfd9463a435a86 100644 --- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -196,9 +196,8 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags, SMLoc Loc = Def->getLoc().front(); if (First) { - SrcMgr.PrintMessage(Loc, SourceMgr::DK_Error, - Twine("group '") + Group.first + - "' is defined more than once"); + PrintError(Loc, Twine("group '") + Group.first + + "' is defined more than once"); First = false; } else { SrcMgr.PrintMessage(Loc, SourceMgr::DK_Note, "also defined here"); @@ -211,9 +210,8 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags, SMLoc Loc = Diag->getLoc().front(); if (First) { - SrcMgr.PrintMessage(Loc, SourceMgr::DK_Error, - Twine("group '") + Group.first + - "' is implicitly defined more than once"); + PrintError(Loc, Twine("group '") + Group.first + + "' is implicitly defined more than once"); First = false; } else { SrcMgr.PrintMessage(Loc, SourceMgr::DK_Note, _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
