Source: ldc
Version: 1:1.42.0-2.1
Severity: important
Tags: ftbfs
User: [email protected]
Usertags: llvm-23-default
Control: affects -1 + src:llvm-defaults
Control: block 1154024 by -1

Hello,

We are going to switch the default LLVM version to 23 (transition bug
#1154024). llvm-defaults 0.75~exp1, in experimental, already points to
23.

ldc fails to build in unstable with it, and builds without it:

driver/cl_helpers.h:43:52: error: 'BOU_TRUE' is not a member of
'opts::cl'; did you mean 'llvm::cl::boolOrDefault::BOU_TRUE'?

In LLVM 23, llvm::cl::boolOrDefault is an enum class, so the BOU_*
constants in driver/cl_helpers.h need to be qualified
(cl::boolOrDefault::BOU_TRUE, ...).

The attached debdiff is only a start: it fixes the two first API changes
(boolOrDefault, and Module::appendModuleInlineAsm() which takes a
GlobalAsmFragment since LLVM 23). The build then fails on a third one:
TargetMachine::getMCSubtargetInfo() and getMCAsmInfo() return
references instead of pointers (gen/ldctraits.cpp:27,
gen/llvmhelpers.cpp:1375). ldc 1.42 only knows LLVM up to 21, a newer
upstream release is probably the way to go.

To reproduce, with sbuild:

  sbuild -d unstable \
    --extra-repository='deb http://deb.debian.org/debian experimental main' \
    --build-dep-resolver=aptitude \
    --add-depends='clang (>= 1:23~), llvm-dev (>= 1:23~), libclang-dev (>= 
1:23~)' \
    <package>

The --add-depends forces the llvm-defaults packages from experimental
(the default apt resolver won't pick them, aptitude does), everything
else comes from unstable.

The severity will be raised to serious once llvm-defaults 23 is in
unstable.

Cheers,
Sylvestre
diff --git a/debian/patches/llvm-23.patch b/debian/patches/llvm-23.patch
new file mode 100644
index 0000000..bf90f1d
--- /dev/null
+++ b/debian/patches/llvm-23.patch
@@ -0,0 +1,115 @@
+Description: Fix the build with LLVM 23
+ * llvm::cl::boolOrDefault is an enum class since LLVM 23. Qualifying the
+   enumerators also works with the older versions.
+ * Module::appendModuleInlineAsm() takes a GlobalAsmFragment since LLVM
+   23, which can't be built from a brace list. Pass a StringRef, which
+   works with both.
+Author: Sylvestre Ledru <[email protected]>
+Forwarded: no
+Last-Update: 2026-11-15
+---
+Index: ldc-1.42.0/driver/cl_helpers.h
+===================================================================
+--- ldc-1.42.0.orig/driver/cl_helpers.h
++++ ldc-1.42.0/driver/cl_helpers.h
+@@ -40,12 +40,12 @@ template <> struct FlagParserDataType<bo
+ };
+ 
+ template <> struct FlagParserDataType<cl::boolOrDefault> {
+-  static cl::boolOrDefault true_val() { return cl::BOU_TRUE; }
+-  static cl::boolOrDefault false_val() { return cl::BOU_FALSE; }
++  static cl::boolOrDefault true_val() { return cl::boolOrDefault::BOU_TRUE; }
++  static cl::boolOrDefault false_val() { return cl::boolOrDefault::BOU_FALSE; }
+ };
+ 
+ inline bool getFlagOrDefault(cl::boolOrDefault value, bool defaultValue) {
+-  return value == cl::BOU_UNSET ? defaultValue : value == cl::BOU_TRUE;
++  return value == cl::boolOrDefault::BOU_UNSET ? defaultValue : value == cl::boolOrDefault::BOU_TRUE;
+ }
+ 
+ template <> struct FlagParserDataType<CHECKENABLE> {
+Index: ldc-1.42.0/driver/linker-gcc.cpp
+===================================================================
+--- ldc-1.42.0.orig/driver/linker-gcc.cpp
++++ ldc-1.42.0/driver/linker-gcc.cpp
+@@ -561,7 +561,7 @@ void ArgsBuilder::build(llvm::StringRef
+     args.push_back("-shared");
+   }
+ 
+-  if (linkFullyStatic() == llvm::cl::BOU_TRUE) {
++  if (linkFullyStatic() == llvm::cl::boolOrDefault::BOU_TRUE) {
+     args.push_back("-static");
+   }
+ 
+Index: ldc-1.42.0/driver/linker.cpp
+===================================================================
+--- ldc-1.42.0.orig/driver/linker.cpp
++++ ldc-1.42.0/driver/linker.cpp
+@@ -222,9 +222,9 @@ cl::boolOrDefault linkFullyStatic() { re
+ bool linkAgainstSharedDefaultLibs() {
+   // -static enforces static default libs.
+   // Default to shared default libs for DLLs.
+-  return staticFlag != cl::BOU_TRUE &&
+-         (linkDefaultLibShared == cl::BOU_TRUE ||
+-          (linkDefaultLibShared == cl::BOU_UNSET && global.params.dll));
++  return staticFlag != cl::boolOrDefault::BOU_TRUE &&
++         (linkDefaultLibShared == cl::boolOrDefault::BOU_TRUE ||
++          (linkDefaultLibShared == cl::boolOrDefault::BOU_UNSET && global.params.dll));
+ }
+ 
+ //////////////////////////////////////////////////////////////////////////////
+Index: ldc-1.42.0/driver/main.cpp
+===================================================================
+--- ldc-1.42.0.orig/driver/main.cpp
++++ ldc-1.42.0/driver/main.cpp
+@@ -470,11 +470,11 @@ void parseCommandLine(Strings &sourceFil
+   }
+ 
+   global.params.output_o =
+-      (opts::output_o == cl::BOU_UNSET &&
++      (opts::output_o == cl::boolOrDefault::BOU_UNSET &&
+        !(opts::output_bc || opts::output_ll || opts::output_s ||
+          opts::output_mlir))
+           ? OUTPUTFLAGdefault
+-          : opts::output_o == cl::BOU_TRUE ? OUTPUTFLAGset : OUTPUTFLAGno;
++          : opts::output_o == cl::boolOrDefault::BOU_TRUE ? OUTPUTFLAGset : OUTPUTFLAGno;
+   global.params.output_bc = opts::output_bc ? OUTPUTFLAGset : OUTPUTFLAGno;
+   global.params.output_ll = opts::output_ll ? OUTPUTFLAGset : OUTPUTFLAGno;
+   global.params.output_mlir = opts::output_mlir ? OUTPUTFLAGset : OUTPUTFLAGno;
+Index: ldc-1.42.0/gen/optimizer.cpp
+===================================================================
+--- ldc-1.42.0.orig/gen/optimizer.cpp
++++ ldc-1.42.0/gen/optimizer.cpp
+@@ -159,8 +159,8 @@ bool willInline() {
+ #ifdef IN_JITRT
+   return false;
+ #else
+-  return enableInlining == cl::BOU_TRUE ||
+-         (enableInlining == cl::BOU_UNSET && optLevel() > 1);
++  return enableInlining == cl::boolOrDefault::BOU_TRUE ||
++         (enableInlining == cl::boolOrDefault::BOU_UNSET && optLevel() > 1);
+ #endif
+ }
+ 
+@@ -168,7 +168,7 @@ bool willCrossModuleInline() {
+ #ifdef IN_JITRT
+   return false;
+ #else
+-  return enableCrossModuleInlining == llvm::cl::BOU_TRUE && willInline();
++  return enableCrossModuleInlining == llvm::cl::boolOrDefault::BOU_TRUE && willInline();
+ #endif
+ }
+ 
+Index: ldc-1.42.0/gen/declarations.cpp
+===================================================================
+--- ldc-1.42.0.orig/gen/declarations.cpp
++++ ldc-1.42.0/gen/declarations.cpp
+@@ -511,7 +511,7 @@ public:
+ 
+     DString str = se->peekString();
+     if (str.length)
+-      irs->module.appendModuleInlineAsm({str.ptr, str.length});
++      irs->module.appendModuleInlineAsm(llvm::StringRef(str.ptr, str.length));
+   }
+ };
+ 
diff --git a/debian/patches/series b/debian/patches/series
index b72ff8e..5460566 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
 i386_int128_alignment.patch
 Don-t-emit-install-time-rpath-in-50-target-default.conf.patch
 0001-Link-with-curl-when-building-ldc-profdata-5165.patch
+llvm-23.patch

Reply via email to