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] Test for tbaa.struct metadata with bitfields in big endian layout #87617

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

juliannagele
Copy link
Member

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.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 4, 2024

@llvm/pr-subscribers-clang

Author: Julian Nagele (juliannagele)

Changes

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.


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

1 Files Affected:

  • (added) clang/test/CodeGen/tbaa-struct-be.cpp (+37)
diff --git a/clang/test/CodeGen/tbaa-struct-be.cpp b/clang/test/CodeGen/tbaa-struct-be.cpp
new file mode 100644
index 00000000000000..537e6e9ce31779
--- /dev/null
+++ b/clang/test/CodeGen/tbaa-struct-be.cpp
@@ -0,0 +1,37 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
+// RUN:     FileCheck -check-prefixes=CHECK %s
+//
+// Check TBAA metadata for struct copies for big endian architecture.
+// FIXME: The tbaa.struct metadata generated below is invalid: it
+// contains overlapping regions.
+
+struct NamedBitfields {
+  int f1 : 8;
+  int f2 : 8;
+  unsigned f3 : 1;
+  unsigned f4 : 15;
+  int f5;
+  double f6;
+};
+
+// CHECK-LABEL: define dso_local void @_Z4copyP14NamedBitfieldsS0_(
+// CHECK-SAME: ptr nocapture noundef writeonly [[A1:%.*]], ptr nocapture noundef readonly [[A2:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) [[A1]], ptr noundef nonnull align 8 dereferenceable(16) [[A2]], i64 16, i1 false), !tbaa.struct [[TBAA_STRUCT2:![0-9]+]]
+// CHECK-NEXT:    ret void
+//
+void copy(NamedBitfields *a1, NamedBitfields *a2) {
+  *a1 = *a2;
+}
+
+//.
+// CHECK: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[META3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
+// CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
+// CHECK: [[META5]] = !{!"Simple C++ TBAA"}
+// CHECK: [[META6]] = !{[[META7:![0-9]+]], [[META7]], i64 0}
+// CHECK: [[META7]] = !{!"int", [[META4]], i64 0}
+// CHECK: [[META8]] = !{[[META9:![0-9]+]], [[META9]], i64 0}
+// CHECK: [[META9]] = !{!"double", [[META4]], i64 0}
+//.

@fhahn fhahn requested review from fhahn and dobbelaj-snps April 4, 2024 14:13
@fhahn fhahn changed the title Test for tbaa.struct metadata for bitfields in big endian layout [TBAA] Test for tbaa.struct metadata with bitfields in big endian layout Apr 4, 2024
Copy link
Contributor

@dobbelaj-snps dobbelaj-snps left a comment

Choose a reason for hiding this comment

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

lgtm

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 dcab42a into llvm:main Apr 4, 2024
3 of 4 checks passed
@juliannagele juliannagele deleted the tbaa-struct-bitfields-big-endian-test branch April 4, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants