llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.88k stars 11.03k forks source link

ODR warning in Arch64GenAsmMatcher.in (SubtargetFeatureBits) #86986

Open efriedma-quic opened 3 months ago

efriedma-quic commented 3 months ago

When building with -flto -Werror=odr to find possible runtime issues w/ LTO:

/var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/AArch64/AArch64GenAsmMatcher.inc:272: error: type ‘SubtargetFeatureBits’ violates the C++ One Definition Rule [-Werror=odr]
  272 | enum SubtargetFeatureBits : uint8_t {
      | 
/var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/Hexagon/HexagonGenAsmMatcher.inc:49: note: an enum with different value name is defined in another translation unit
   49 | enum SubtargetFeatureBits : uint8_t {
      | 
/var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/AArch64/AArch64GenAsmMatcher.inc:273: note: name ‘Feature_HasV8_0aBit’ differs from name ‘Feature_HasV5Bit’ defined in another translation unit
  273 |   Feature_HasV8_0aBit = 103,
      | 
/var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/Hexagon/HexagonGenAsmMatcher.inc:50: note: mismatching definition
   50 |   Feature_HasV5Bit = 2,
      | 

Split from #84577 . Originally reported downstream in Gentoo at https://bugs.gentoo.org/926529.

efriedma-quic commented 3 months ago

It looks like this is harmless; these don't actually need to match. Probably TableGen can generate an anonymous namespace or something like that to avoid the warning.

llvmbot commented 3 months ago

@llvm/issue-subscribers-backend-aarch64

Author: Eli Friedman (efriedma-quic)

When building with -flto -Werror=odr to find possible runtime issues w/ LTO: ``` /var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/AArch64/AArch64GenAsmMatcher.inc:272: error: type ‘SubtargetFeatureBits’ violates the C++ One Definition Rule [-Werror=odr] 272 | enum SubtargetFeatureBits : uint8_t { | /var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/Hexagon/HexagonGenAsmMatcher.inc:49: note: an enum with different value name is defined in another translation unit 49 | enum SubtargetFeatureBits : uint8_t { | /var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/AArch64/AArch64GenAsmMatcher.inc:273: note: name ‘Feature_HasV8_0aBit’ differs from name ‘Feature_HasV5Bit’ defined in another translation unit 273 | Feature_HasV8_0aBit = 103, | /var/tmp/portage/sys-devel/llvm-18.1.0/work/llvm_build-abi_x86_32.x86/lib/Target/Hexagon/HexagonGenAsmMatcher.inc:50: note: mismatching definition 50 | Feature_HasV5Bit = 2, | ``` Split from #84577 . Originally reported downstream in Gentoo at https://bugs.gentoo.org/926529.
dwblaikie commented 3 months ago

I guess this & the other bug/warning came from a GCC LTO build? I don't think LLVM has these diagnostics, right?

But I can say that these sort of ODR violations can mess up LLVM's LTO DWARF - it assumes types with the same mangled name are identical, and will pick one at random. So you could have a rather confusing debugging experience from code like this.