Skip to content

Commit 09f8b35

Browse files
mattgodboltclaude
andcommitted
🐛 Add dedicated debug patch for released clang 22
Released clang 22.x is an intermediate state: it rewrote setCurrentDebugTypes() and added a blank line before the closing "} // namespace llvm" (breaking ce-debug-clang-13.patch) but, unlike LLVM trunk, does not yet have printDebugLog()/printDebugLogImpl() (breaking ce-debug-clang-trunk.patch). The version routing previously sent everything >= 22 to the trunk patch, so 22.1.6 / assertions-22.1.6 builds failed to apply the --debug-to-stdout patch. Add ce-debug-clang-22.patch with context matching release/22.x and route MAJOR == 22 to it; trunk now covers 23+, which already contains printDebugLog on main. Verified each of release/21.x, release/22.x and main applies exactly one of the three patches. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ccafe80 commit 09f8b35

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

build/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ mlir-*)
431431
elif [[ $MAJOR -le 21 ]]; then
432432
PATCHES_TO_APPLY+=("${ROOT}/patches/ce-debug-clang-13.patch")
433433
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD="M68k;WebAssembly"
434+
elif [[ $MAJOR -eq 22 ]]; then
435+
# 22 rewrote setCurrentDebugTypes() but, unlike trunk, has no
436+
# printDebugLog() yet, so it needs its own debug patch context.
437+
PATCHES_TO_APPLY+=("${ROOT}/patches/ce-debug-clang-22.patch")
438+
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD="M68k;WebAssembly"
434439
else
435440
PATCHES_TO_APPLY+=("${ROOT}/patches/ce-debug-clang-trunk.patch")
436441
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD="M68k;WebAssembly"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
commit 445c6dd4845daf2fbc5e8e8b9bac6a39cd90a470
2+
Author: partouf <partouf@gmail.com>
3+
Date: Sat Dec 10 14:07:08 2022 +0100
4+
5+
change dbgs() in case of --debug-to-stdout
6+
7+
LLVM 22 rewrote setCurrentDebugTypes() and added a blank line before the
8+
closing "} // namespace llvm" but, unlike trunk, does not yet have
9+
printDebugLog()/printDebugLogImpl(). It therefore needs its own context,
10+
distinct from both ce-debug-clang-13.patch and ce-debug-clang-trunk.patch.
11+
12+
diff --git a/llvm/lib/Support/Debug.cpp b/llvm/lib/Support/Debug.cpp
13+
--- a/llvm/lib/Support/Debug.cpp
14+
+++ b/llvm/lib/Support/Debug.cpp
15+
@@ -117,6 +117,11 @@ void setCurrentDebugTypes(const char **Types, unsigned Count) {
16+
17+
} // namespace llvm
18+
19+
+cl::opt<bool> LogDebugToStdOut(
20+
+ "debug-to-stdout",
21+
+ llvm::cl::desc("Log debugging to stdout instead of stderr"),
22+
+ cl::init(false), cl::Hidden);
23+
+
24+
// All Debug.h functionality is a no-op in NDEBUG mode.
25+
#ifndef NDEBUG
26+
27+
@@ -205,23 +210,27 @@ static void debug_user_sig_handler(void *Cookie) {
28+
29+
/// dbgs - Return a circular-buffered debug stream.
30+
raw_ostream &llvm::dbgs() {
31+
- // Do one-time initialization in a thread-safe way.
32+
- static struct dbgstream {
33+
- circular_raw_ostream strm;
34+
-
35+
- dbgstream()
36+
- : strm(errs(), "*** Debug Log Output ***\n",
37+
- (!EnableDebugBuffering || !DebugFlag) ? 0 : *DebugBufferSize) {
38+
- if (EnableDebugBuffering && DebugFlag && *DebugBufferSize != 0)
39+
- // TODO: Add a handler for SIGUSER1-type signals so the user can
40+
- // force a debug dump.
41+
- sys::AddSignalHandler(&debug_user_sig_handler, nullptr);
42+
- // Otherwise we've already set the debug stream buffer size to
43+
- // zero, disabling buffering so it will output directly to errs().
44+
- }
45+
- } thestrm;
46+
-
47+
- return thestrm.strm;
48+
+ if (LogDebugToStdOut) {
49+
+ return outs();
50+
+ } else {
51+
+ // Do one-time initialization in a thread-safe way.
52+
+ static struct dbgstream {
53+
+ circular_raw_ostream strm;
54+
+
55+
+ dbgstream()
56+
+ : strm(errs(), "*** Debug Log Output ***\n",
57+
+ (!EnableDebugBuffering || !DebugFlag) ? 0 : *DebugBufferSize) {
58+
+ if (EnableDebugBuffering && DebugFlag && *DebugBufferSize != 0)
59+
+ // TODO: Add a handler for SIGUSER1-type signals so the user can
60+
+ // force a debug dump.
61+
+ sys::AddSignalHandler(&debug_user_sig_handler, nullptr);
62+
+ // Otherwise we've already set the debug stream buffer size to
63+
+ // zero, disabling buffering so it will output directly to errs().
64+
+ }
65+
+ } thestrm;
66+
+
67+
+ return thestrm.strm;
68+
+ }
69+
}
70+
71+
#else
72+
@@ -229,7 +238,11 @@ raw_ostream &llvm::dbgs() {
73+
namespace llvm {
74+
/// dbgs - Return errs().
75+
raw_ostream &dbgs() {
76+
- return errs();
77+
+ if (LogDebugToStdOut) {
78+
+ return outs();
79+
+ } else {
80+
+ return errs();
81+
+ }
82+
}
83+
}
84+
void llvm::initDebugOptions() {}

0 commit comments

Comments
 (0)