Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TBAA] Add verifier for tbaa.struct metadata #86709

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

juliannagele
Copy link
Contributor

Adds logic to the IR verifier that checks whether !tbaa.struct nodes are well-formed. That is, it checks that the operands of !tbaa.struct nodes are in groups of three, that each group of three operands consists of two integers and a valid tbaa node, and that the regions described by the offset and size operands are non-overlapping.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 26, 2024

@llvm/pr-subscribers-backend-amdgpu
@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-llvm-ir

Author: Julian Nagele (juliannagele)

Changes

Adds logic to the IR verifier that checks whether !tbaa.struct nodes are well-formed. That is, it checks that the operands of !tbaa.struct nodes are in groups of three, that each group of three operands consists of two integers and a valid tbaa node, and that the regions described by the offset and size operands are non-overlapping.


Full diff: https://github.com/llvm/llvm-project/pull/86709.diff

9 Files Affected:

  • (modified) llvm/include/llvm/IR/Verifier.h (+1)
  • (modified) llvm/lib/IR/Verifier.cpp (+32)
  • (modified) llvm/test/CodeGen/AArch64/arm64-abi_align.ll (+3-1)
  • (modified) llvm/test/Transforms/InferAddressSpaces/AMDGPU/mem-intrinsics.ll (+1-1)
  • (modified) llvm/test/Transforms/InstCombine/struct-assign-tbaa.ll (+1-1)
  • (modified) llvm/test/Transforms/SROA/tbaa-struct3.ll (+1-1)
  • (modified) llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll (+2-1)
  • (modified) llvm/test/Transforms/Scalarizer/basic.ll (+2-1)
  • (modified) llvm/test/Verifier/tbaa-struct.ll (+11-3)
diff --git a/llvm/include/llvm/IR/Verifier.h b/llvm/include/llvm/IR/Verifier.h
index b25f8eb77ee38b..b7db6e0bbfb71c 100644
--- a/llvm/include/llvm/IR/Verifier.h
+++ b/llvm/include/llvm/IR/Verifier.h
@@ -77,6 +77,7 @@ class TBAAVerifier {
   /// Visit an instruction and return true if it is valid, return false if an
   /// invalid TBAA is attached.
   bool visitTBAAMetadata(Instruction &I, const MDNode *MD);
+  bool visitTBAAStructMetadata(Instruction &I, const MDNode *MD);
 };
 
 /// Check a function for errors, useful for use when debugging a
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 33f358440a312d..3035c6f53ad0d4 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5096,6 +5096,9 @@ void Verifier::visitInstruction(Instruction &I) {
   if (MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa))
     TBAAVerifyHelper.visitTBAAMetadata(I, TBAA);
 
+  if (MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa_struct))
+    TBAAVerifyHelper.visitTBAAStructMetadata(I, TBAA);
+
   if (MDNode *MD = I.getMetadata(LLVMContext::MD_noalias))
     visitAliasScopeListMetadata(MD);
   if (MDNode *MD = I.getMetadata(LLVMContext::MD_alias_scope))
@@ -7419,6 +7422,35 @@ bool TBAAVerifier::visitTBAAMetadata(Instruction &I, const MDNode *MD) {
   return true;
 }
 
+bool TBAAVerifier::visitTBAAStructMetadata(Instruction &I, const MDNode *MD) {
+  CheckTBAA(MD->getNumOperands() % 3 == 0,
+            "tbaa.struct operands must occur in groups of three", &I, MD);
+
+  // Each group of three operands must consist of two integers and a
+  // tbaa node. Moreover, the regions described by the offset and size
+  // operands must be non-overlapping.
+  std::optional<APInt> NextFree;
+  for (unsigned int Idx = 0; Idx < MD->getNumOperands(); Idx += 3) {
+    auto *OffsetCI =
+        mdconst::dyn_extract_or_null<ConstantInt>(MD->getOperand(Idx));
+    CheckTBAA(OffsetCI, "Offset must be a constant integer", &I, MD);
+
+    auto *SizeCI =
+        mdconst::dyn_extract_or_null<ConstantInt>(MD->getOperand(Idx + 1));
+    CheckTBAA(SizeCI, "Size must be a constant integer", &I, MD);
+
+    MDNode *TBAA = dyn_cast_or_null<MDNode>(MD->getOperand(Idx + 2));
+    CheckTBAA(TBAA, "TBAA tag missing", &I, MD);
+    visitTBAAMetadata(I, TBAA);
+
+    bool NonOverlapping = !NextFree || NextFree->ule(OffsetCI->getValue());
+    CheckTBAA(NonOverlapping, "Overlapping tbaa.struct regions", &I, MD);
+
+    NextFree = OffsetCI->getValue() + SizeCI->getValue();;
+  }
+  return true;
+}
+
 char VerifierLegacyPass::ID = 0;
 INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false)
 
diff --git a/llvm/test/CodeGen/AArch64/arm64-abi_align.ll b/llvm/test/CodeGen/AArch64/arm64-abi_align.ll
index 089e171e5a4a79..c9fd2d38e27acd 100644
--- a/llvm/test/CodeGen/AArch64/arm64-abi_align.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-abi_align.ll
@@ -518,4 +518,6 @@ attributes #5 = { nobuiltin }
 !1 = !{!"omnipotent char", !2}
 !2 = !{!"Simple C/C++ TBAA"}
 !3 = !{!"short", !1}
-!4 = !{i64 0, i64 4, !0, i64 4, i64 2, !3, i64 8, i64 4, !0, i64 12, i64 2, !3, i64 16, i64 4, !0, i64 20, i64 2, !3}
+!4 = !{i64 0, i64 4, !5, i64 4, i64 2, !6, i64 8, i64 4, !5, i64 12, i64 2, !6, i64 16, i64 4, !5, i64 20, i64 2, !6}
+!5 = !{!0, !0, i64 0}
+!6 = !{!3, !3, i64 0}
diff --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/mem-intrinsics.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/mem-intrinsics.ll
index 50b0e7a0f5471b..2f264a2432fc3d 100644
--- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/mem-intrinsics.ll
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/mem-intrinsics.ll
@@ -141,4 +141,4 @@ attributes #1 = { argmemonly nounwind }
 !5 = distinct !{!5, !"some domain"}
 !6 = !{!7}
 !7 = distinct !{!7, !5, !"some scope 2"}
-!8 = !{i64 0, i64 8, null}
+!8 = !{i64 0, i64 8, !0}
diff --git a/llvm/test/Transforms/InstCombine/struct-assign-tbaa.ll b/llvm/test/Transforms/InstCombine/struct-assign-tbaa.ll
index 996d2c0e67e165..d079c03f1dcb93 100644
--- a/llvm/test/Transforms/InstCombine/struct-assign-tbaa.ll
+++ b/llvm/test/Transforms/InstCombine/struct-assign-tbaa.ll
@@ -75,7 +75,7 @@ entry:
 !1 = !{!"omnipotent char", !0}
 !2 = !{!5, !5, i64 0}
 !3 = !{i64 0, i64 4, !2}
-!4 = !{i64 0, i64 8, null}
+!4 = !{i64 0, i64 8, !2}
 !5 = !{!"float", !0}
 !6 = !{i64 0, i64 4, !2, i64 4, i64 4, !2}
 !7 = !{i64 0, i64 2, !2, i64 4, i64 6, !2}
diff --git a/llvm/test/Transforms/SROA/tbaa-struct3.ll b/llvm/test/Transforms/SROA/tbaa-struct3.ll
index 0fcd787fef9769..61034de81e4b27 100644
--- a/llvm/test/Transforms/SROA/tbaa-struct3.ll
+++ b/llvm/test/Transforms/SROA/tbaa-struct3.ll
@@ -539,7 +539,7 @@ declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias
 !6 = !{!5, !5, i64 0}
 !7 = !{i64 0, i64 8, !6, i64 8, i64 4, !1}
 !8 = !{i64 0, i64 4, !1, i64 4, i64 8, !6}
-!9 = !{i64 0, i64 8, !6, i64 4, i64 8, !1}
+!9 = !{i64 0, i64 8, !6, i64 8, i64 8, !1}
 !10 = !{i64 0, i64 2, !1, i64 2, i64 2, !1}
 !11 = !{i64 0, i64 1, !1, i64 1, i64 3, !1}
 !12 = !{i64 0, i64 2, !1, i64 2, i64 6, !1}
diff --git a/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll b/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll
index bbcdcb6f586742..73ae66dd76c66e 100644
--- a/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll
+++ b/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll
@@ -836,5 +836,6 @@ define <2 x i32> @f23_crash(<2 x i32> %srcvec, i32 %v1) {
 !2 = !{ !"set2", !0 }
 !3 = !{ !3, !{!"llvm.loop.parallel_accesses", !13} }
 !4 = !{ float 4.0 }
-!5 = !{ i64 0, i64 8, null }
+!5 = !{ i64 0, i64 8, !6 }
+!6 = !{ !1, !1, i64 0 }
 !13 = distinct !{}
diff --git a/llvm/test/Transforms/Scalarizer/basic.ll b/llvm/test/Transforms/Scalarizer/basic.ll
index db7c5f535f7e9d..87a70ccd3fc7c5 100644
--- a/llvm/test/Transforms/Scalarizer/basic.ll
+++ b/llvm/test/Transforms/Scalarizer/basic.ll
@@ -870,5 +870,6 @@ define <2 x float> @f25(<2 x float> %src) {
 !2 = !{ !"set2", !0 }
 !3 = !{ !3, !{!"llvm.loop.parallel_accesses", !13} }
 !4 = !{ float 4.0 }
-!5 = !{ i64 0, i64 8, null }
+!5 = !{ i64 0, i64 8, !6 }
+!6 = !{ !1, !1, i64 0 }
 !13 = distinct !{}
diff --git a/llvm/test/Verifier/tbaa-struct.ll b/llvm/test/Verifier/tbaa-struct.ll
index b8ddc7cee496a9..14c19a19d5ae89 100644
--- a/llvm/test/Verifier/tbaa-struct.ll
+++ b/llvm/test/Verifier/tbaa-struct.ll
@@ -1,28 +1,36 @@
-; RUN: llvm-as < %s 2>&1
-
-; FIXME: The verifer should reject the invalid !tbaa.struct nodes below.
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
 
 define void @test_overlapping_regions(ptr %a1) {
+; CHECK: Overlapping tbaa.struct regions
+; CHECK-NEXT:  %ld = load i8, ptr %a1, align 1, !tbaa.struct !0
   %ld = load i8, ptr %a1, align 1, !tbaa.struct !0
   ret void
 }
 
 define void @test_size_not_integer(ptr %a1) {
+; CHECK: Size must be a constant integer
+; CHECK-NEXT:  store i8 1, ptr %a1, align 1, !tbaa.struct !5
   store i8 1, ptr %a1, align 1, !tbaa.struct !5
   ret void
 }
 
 define void @test_offset_not_integer(ptr %a1, ptr %a2) {
+; CHECK: Offset must be a constant integer
+; CHECK-NEXT:  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %a1, ptr align 8 %a2, i64 16, i1 false), !tbaa.struct !6
   tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %a1, ptr align 8 %a2, i64 16, i1 false), !tbaa.struct !6
   ret void
 }
 
 define void @test_tbaa_missing(ptr %a1, ptr %a2) {
+; CHECK: TBAA tag missing
+; CHECK-NEXT:  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %a1, ptr align 8 %a2, i64 16, i1 false), !tbaa.struct !7
   tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %a1, ptr align 8 %a2, i64 16, i1 false), !tbaa.struct !7
   ret void
 }
 
 define void @test_tbaa_invalid(ptr %a1) {
+; CHECK: Old-style TBAA is no longer allowed, use struct-path TBAA instead
+; CHECK-NEXT:  store i8 1, ptr %a1, align 1, !tbaa.struct !8
   store i8 1, ptr %a1, align 1, !tbaa.struct !8
   ret void
 }

Copy link

github-actions bot commented Mar 26, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@fhahn fhahn merged commit df75183 into llvm:main Mar 27, 2024
4 checks passed
@uweigand
Copy link
Member

This is breaking the openmp-s390x-linux build bot. I was able to reduce the problem to the following test case:

typedef struct kmp_affinity_attrs_t {
  int core_type : 8;
  int core_eff : 8;
  unsigned valid : 1;
  unsigned reserved : 15;
} kmp_affinity_attrs_t;

typedef struct kmp_affinity_t {
  kmp_affinity_attrs_t core_attr_gran;
  int compact;
} kmp_affinity_t;

void test(kmp_affinity_t *affinity) {
  *affinity = (kmp_affinity_t) { { 0 }, 0 };
}

Building this with clang --target=s390x-ibm-linux -O results in

Overlapping tbaa.struct regions
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 4 %.compoundliteral, i64 8, i1 false), !tbaa.struct !12
!12 = !{i64 2, i64 4, !13, i64 4, i64 4, !14}
fatal error: error in backend: Broken module found, compilation aborted!

The first offset of 2 seems wrong to me - not sure where this came from. This seems to be an actual bug uncovered by this test?

@amy-kwan
Copy link
Contributor

I believe this patch is still causing failures on the PPC64BE bots in the recent builds: https://lab.llvm.org/buildbot/#/builders/93/builds/19428/steps/10/logs/stdio

The errors are similar to what @uweigand reported.

@uweigand
Copy link
Member

Hmm, if it fails on big-endian platforms, maybe that indicates an endian bug in (bit)field offset computation somewhere?

fhahn added a commit that referenced this pull request Mar 27, 2024
This reverts commit df75183.

Revert for now as this appears to cause failures on some buildbots,
e.g.:
https://lab.llvm.org/buildbot/#/builders/93/builds/19428/steps/10/logs/stdio
@fhahn
Copy link
Contributor

fhahn commented Mar 27, 2024

Thanks for the report, reverted for now

fhahn pushed a commit that referenced this pull request Apr 4, 2024
…out (#87617)

This test exposes what I think is invalid tbaa.struct metadata currently
generated for bitfields when using big endian layout. The regions given
by `!{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 4 ...` are
overlapping. This issue was originally observed in
#86709.
fhahn pushed a commit that referenced this pull request Apr 15, 2024
This reverts commit b9cd48f.

-------------------------------------------------------------
Original commit message:

Adds logic to the IR verifier that checks whether !tbaa.struct nodes are
well-formed. That is, it checks that the operands of !tbaa.struct nodes
are in groups of three, that each group of three operands consists of
two integers and a valid tbaa node, and that the regions described by
the offset and size operands are non-overlapping.

PR: #86709
@juliannagele juliannagele deleted the verify-tbaa.struct branch April 15, 2024 15:12
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
This reverts commit b9cd48f.

-------------------------------------------------------------
Original commit message:

Adds logic to the IR verifier that checks whether !tbaa.struct nodes are
well-formed. That is, it checks that the operands of !tbaa.struct nodes
are in groups of three, that each group of three operands consists of
two integers and a valid tbaa node, and that the regions described by
the offset and size operands are non-overlapping.

PR: llvm#86709
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 15, 2024
This reverts commit b9cd48f.

-------------------------------------------------------------
Original commit message:

Adds logic to the IR verifier that checks whether !tbaa.struct nodes are
well-formed. That is, it checks that the operands of !tbaa.struct nodes
are in groups of three, that each group of three operands consists of
two integers and a valid tbaa node, and that the regions described by
the offset and size operands are non-overlapping.

PR: llvm#86709
@alexey-bataev
Copy link
Member

Looks like it fails clang/llvm compiler build with ThinLTO with openmp

Overlapping tbaa.struct regions
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %17, ptr noundef nonnull align 8 dereferenceable(40) %18, i64 40, i1 false), !tbaa.struct !232
!232 = !{i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 8, i64 8, !139, i64 0, i64 8, !138, i64 0, i64 1, !124, i64 0, i64 4, !233, i64 0, i64 4, !233, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 24, i64 8, !139, i64 16, i64 8, !138, i64 16, i64 1, !124, i64 16, i64 4, !233, i64 16, i64 4, !233, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 32, i64 1, !234, i64 33, i64 1, !234}
Overlapping tbaa.struct regions
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %22, ptr noundef nonnull align 8 dereferenceable(40) %23, i64 40, i1 false), !tbaa.struct !232
!232 = !{i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 8, i64 8, !139, i64 0, i64 8, !138, i64 0, i64 1, !124, i64 0, i64 4, !233, i64 0, i64 4, !233, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 0, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 24, i64 8, !139, i64 16, i64 8, !138, i64 16, i64 1, !124, i64 16, i64 4, !233, i64 16, i64 4, !233, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 16, i64 8, !138, i64 32, i64 1, !234, i64 33, i64 1, !234}
Overlapping tbaa.struct regions
  store ptrclang++: error: unable to execute command: Aborted
clang++: error: linker command failed due to signal (use -v to see invocation)
[8/13] Building CXX object openmp/libomptarget/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/JIT.cpp.o

@juliannagele
Copy link
Contributor Author

Thanks for the report, do you have the full clang invocation? If possible can you check if the IR coming out of clang is already invalid?

@alexey-bataev
Copy link
Member

Looks like it happens at linking stage, not at compile time:

clang++ --target=x86_64-unknown-linux-gnu -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -fcolor-diagnostics -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -fno-semantic-interposition -fdata-sections -O3 -DNDEBUG  -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=lld -Wl,--color-diagnostics   -Wl,--gc-sections  -flto=thin -shared -Wl,-soname,libomptarget.so.19.0git -o lib/libomptarget.so.19.0git openmp/libomptarget/src/CMakeFiles/omptarget.dir/device.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/interface.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/omptarget.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/OffloadRTL.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/LegacyAPI.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/PluginManager.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/DeviceImage.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/OpenMP/API.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/OpenMP/Mapping.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/OpenMP/InteropAPI.cpp.o openmp/libomptarget/src/CMakeFiles/omptarget.dir/OpenMP/OMPT/Callback.cpp.o  -Wl,-rpath,"\$ORIGIN:runtimes/runtimes-bins/openmp/libomptarget/src/..:runtimes/runtimes-bins/openmp/runtime/src:"  openmp/runtime/src/libomp.so  lib/libLLVMSupport.a  lib/libLLVMObject.a  -Wl,--version-script=llvm-project/openmp/libomptarget/src/exports  -lrt  -lm  lib/libLLVMIRReader.a  lib/libLLVMBitReader.a  lib/libLLVMAsmParser.a  lib/libLLVMCore.a  lib/libLLVMRemarks.a  lib/libLLVMBitstreamReader.a  lib/libLLVMMCParser.a  lib/libLLVMMC.a  lib/libLLVMDebugInfoCodeView.a  lib/libLLVMTextAPI.a  lib/libLLVMBinaryFormat.a  lib/libLLVMTargetParser.a  lib/libLLVMSupport.a  -lrt  -lpthread  -ldl  -lm  /usr/lib64/libz.so  /usr/lib64/libtinfo.so lib/libLLVMDemangle.a

@juliannagele
Copy link
Contributor Author

hmm, struggling to reproduce this one I'm afraid, any chance you could share the bitcode input for ThinLTO (--save-temps), and maybe the full cmake invocation

@alexey-bataev
Copy link
Member

hmm, struggling to reproduce this one I'm afraid, any chance you could share the bitcode input for ThinLTO (--save-temps), and maybe the full cmake invocation

Here is the config of clang/LLVM building:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release $HOME/clang_tools/llvm-project/llvm -DCMAKE_C_COMPILER=clang  -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;clang-tools-extra;lld" -DLLVM_ENABLE_RUNTIMES="openmp" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_USE_LINKER=lld -DLLVM_CCACHE_BUILD=true -DLLVM_PARALLEL_COMPILE_JOBS=12 -DLLVM_PARALLEL_LINK_JOBS=2 -DOPENMP_ENABLE_LIBOMPTARGET_PROFILING=OFF -DCMAKE_INSTALL_PREFIX=$HOME/clang_tools -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=all -DLIBOMPTARGET_BUILD_DEVICERTL_BCLIB=false -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_EH=ON -DLIBOMPTARGET_BUILD_CUDA_PLUGIN=false -DLIBOMPTARGET_BUILD_AMDGPU_PLUGIN=false -DCMAKE_C_FLAGS="-Wformat -Wno-conversion" -DCMAKE_CXX_FLAGS="-Wformat -Wno-conversion" -DCMAKE_ASM_FLAGS="-Wformat -Wno-conversion" -DCMAKE_C_FLAGS=-march=native -DCMAKE_CXX_FLAGS=-march=native -DLLVM_ENABLE_LTO=Thin
ninja -j12

@Dinistro
Copy link
Contributor

Can confirm that this also breaks on our end on a multitude of cases (all of them involving LTO).

@juliannagele
Copy link
Contributor Author

Ok thanks, still trying to get this to happen on my end, if you have any more info on how to reproduce that'd be great

@Dinistro
Copy link
Contributor

Ok thanks, still trying to get this to happen on my end, if you have any more info on how to reproduce that'd be great

I can sadly only reproduce this on a very large codebase that mostly consists of internal source code that I'm not allowed to share. @alexey-bataev do you have anything you can share that allows reproducing this issue?

@alexey-bataev
Copy link
Member

Ok thanks, still trying to get this to happen on my end, if you have any more info on how to reproduce that'd be great

I can sadly only reproduce this on a very large codebase that mostly consists of internal source code that I'm not allowed to share. @alexey-bataev do you have anything you can share that allows reproducing this issue?

I shared already, for me it crashes on on clang/LLVM (+ openmp runtime) build with ThinLTO, shared the options how to build it

@Dinistro
Copy link
Contributor

Note: In my case some of the broken memcpy intrinsics seem to stem from IR produced from libc++'s basic_string files.

@tstellar
Copy link
Collaborator

tstellar commented Apr 20, 2024

This change is causing our builds of LLVM to fail in Fedora. Here is how you can reproduce:


export CXXFLAGS='-O2 -flto=thin -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_DEFAULT_SOURCE -Dasm=__asm__ '
export FFLAGS='-O2 -flto=thin -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_DEFAULT_SOURCE -Dasm=__asm__ -I/usr/lib64/gfortran/modules '
export FCFLAGS='-O2 -flto=thin -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS-fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_DEFAULT_SOURCE -Dasm=__asm__ -I/usr/lib64/gfortran/modules '
export LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now    -Wl,--build-id=sha1  '
export CC=clang
export CXX=clang++
rm -Rf redhat-linux-build
/usr/bin/cmake -S llvm -B redhat-linux-build -DCMAKE_C_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_Fortran_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr -DINCLUDE_INSTALL_DIR:PATH=/usr/include -DLIB_INSTALL_DIR:PATH=/usr/lib64 -DSYSCONF_INSTALL_DIR:PATH=/etc -DSHARE_INSTALL_PREFIX:PATH=/usr/share -DLIB_SUFFIX=64 -DBUILD_SHARED_LIBS:BOOL=ON -G Ninja '-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra' -DCLANG_DEFAULT_PIE_ON_LINUX=OFF -DPPC_LINUX_DEFAULT_IEEELONGDOUBLE=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 -DLLVM_INCLUDE_TESTS:BOOL=ON -DCLANG_INCLUDE_TESTS:BOOL=ON -DLLVM_BUILD_UTILS:BOOL=ON -DCLANG_ENABLE_ARCMT:BOOL=ON -DCLANG_ENABLE_STATIC_ANALYZER:BOOL=ON  -DCLANG_PLUGIN_SUPPORT:BOOL=ON -DENABLE_LINKER_BUILD_ID:BOOL=ON -DLLVM_ENABLE_EH=ON -DCLANG_LINK_CLANG_DYLIB=ON -DCLANG_BUILD_EXAMPLES:BOOL=OFF '-DCLANG_REPOSITORY_STRING=Fedora 19.0.0~pre20240419.gb566810add5b7c-1.fc39' -DCLANG_RESOURCE_DIR=../lib/clang/19 -DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=../clang-tools-extra -DCLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang/ -DCLANG_DEFAULT_UNWINDLIB=libgcc '-DLLVM_ENABLE_RUNTIMES=compiler-rt;openmp' -DCOMPILER_RT_INSTALL_PATH=/usr/lib/clang/19 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DCOMPILER_RT_INCLUDE_TESTS:BOOL=OFF -DLIBOMP_HAVE_VERSION_SCRIPT_FLAG:BOOL=ON -DLIBOMP_INSTALL_ALIASES=OFF -DOPENMP_LIBDIR_SUFFIX=64 -DOPENMP_INSTALL_LIBDIR=lib64 -DBUILD_SHARED_LIBS:BOOL=OFF -DLLVM_PARALLEL_LINK_JOBS=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_SKIP_RPATH:BOOL=ON -DLLVM_LIBDIR_SUFFIX=64 -DLLVM_TARGETS_TO_BUILD=all -DLLVM_ENABLE_LIBCXX:BOOL=OFF -DLLVM_ENABLE_ZLIB:BOOL=ON -DLLVM_ENABLE_FFI:BOOL=ON -DLLVM_ENABLE_RTTI:BOOL=ON -DLLVM_USE_PERF:BOOL=ON -DLLVM_BINUTILS_INCDIR=/usr/include -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR -DLLVM_BUILD_RUNTIME:BOOL=ON -DLLVM_INCLUDE_TOOLS:BOOL=ON -DLLVM_BUILD_TOOLS:BOOL=ON -DLLVM_BUILD_TESTS:BOOL=ON -DLLVM_INSTALL_GTEST:BOOL=ON -DLLVM_LIT_ARGS=-vv -DLLVM_INCLUDE_EXAMPLES:BOOL=ON -DLLVM_BUILD_EXAMPLES:BOOL=OFF -DLLVM_INCLUDE_UTILS:BOOL=ON -DLLVM_INSTALL_UTILS:BOOL=ON -DLLVM_UTILS_INSTALL_DIR:PATH=/usr/bin -DLLVM_TOOLS_INSTALL_DIR:PATH=bin  -DLLVM_ENABLE_SPHINX:BOOL=ON -DLLVM_ENABLE_DOXYGEN:BOOL=OFF -DLLVM_VERSION_SUFFIX=pre20240419.gb566810add5b7c -DLLVM_UNREACHABLE_OPTIMIZE:BOOL=ON -DLLVM_BUILD_LLVM_DYLIB:BOOL=ON -DLLVM_LINK_LLVM_DYLIB:BOOL=ON -DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=OFF -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-redhat-linux-gnu -DSPHINX_WARNINGS_AS_ERRORS=OFF -DCMAKE_INSTALL_PREFIX=/usr -DLLVM_INSTALL_SPHINX_HTML_DIR=/usr/share/doc/llvm/html -DSPHINX_EXECUTABLE=/usr/bin/sphinx-build-3 -DLLVM_INCLUDE_BENCHMARKS=OFF '-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now    -Wl,--build-id=sha1'

ninja -v -C redhat-linux-build

@tstellar
Copy link
Collaborator

Given the number of issues reported with this change, can we revert it while it is investigated?

@juliannagele
Copy link
Contributor Author

Sure, I've finally managed to reproduce it, but will probably need a bit of time to figure out what's going wrong

@Dinistro
Copy link
Contributor

Sure, I've finally managed to reproduce it, but will probably need a bit of time to figure out what's going wrong

Will you open a PR for this? If you need an approve/merge, let me know

fhahn added a commit that referenced this pull request Apr 22, 2024
This reverts commit 7dbba39.

Revert as there are reports this triggers during ThinLTO in some
configurations.
@fhahn
Copy link
Contributor

fhahn commented Apr 22, 2024

Reverted again for now c8e5ad4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants