[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits

https://github.com/juliannagele created 
https://github.com/llvm/llvm-project/pull/87753

When generating tbaa.struct metadata we treat multiple adjacent bitfields as a 
single "field", with one corresponding entry in the metadata. At the moment 
this is achieved by adding an entry for the first bitfield in the run using its 
StorageSize and skipping the remaining bitfields. The problem is that "first" 
is determined by checking that the Offset of the field in the run is 0, which 
breaks for big endian.

>From cd73a85e55d683f9aa18e1099302202d663e5e7d Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Thu, 4 Apr 2024 11:48:19 +0100
Subject: [PATCH] Fix tbaa.struct metadata for bitfields using big endian.

When generating tbaa.struct metadata we treat multiple adjacent
bitfields as a single "field", with one corresponding entry in the
metadata.
At the moment this is achieved by adding an entry for the first
bitfield in the run using its StorageSize (and skipping the remaining
bitfields). The problem is that "first" is determined by checking that
the Offset of the field in the run is 0. This breaks for big endian.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp  |  6 +-
 clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp | 10 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..0ddefc4751b08c 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =
diff --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, 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"}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits

https://github.com/juliannagele updated 
https://github.com/llvm/llvm-project/pull/87753

>From db1ee85ca26d7ddbaa163f4e9b1038c28e3d4a57 Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Thu, 4 Apr 2024 11:48:19 +0100
Subject: [PATCH] Fix tbaa.struct metadata for bitfields using big endian.

When generating tbaa.struct metadata we treat multiple adjacent
bitfields as a single "field", with one corresponding entry in the
metadata.
At the moment this is achieved by adding an entry for the first
bitfield in the run using its StorageSize (and skipping the remaining
bitfields). The problem is that "first" is determined by checking that
the Offset of the field in the run is 0. This breaks for big endian.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp  |  6 +-
 clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp | 10 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..0ddefc4751b08c 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =
diff --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, 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"}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits


@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0

juliannagele wrote:

Agreed, and that's what I had originally, but then saw 
https://github.com/llvm/llvm-project/blob/0b7362c257ff7b656c31266b4f9b8485a7ba4033/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp#L759
 so thought I'd go with the same structure, but no strong feelings either way.

https://github.com/llvm/llvm-project/pull/87753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits

https://github.com/juliannagele updated 
https://github.com/llvm/llvm-project/pull/87753

>From db1ee85ca26d7ddbaa163f4e9b1038c28e3d4a57 Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Thu, 4 Apr 2024 11:48:19 +0100
Subject: [PATCH 1/2] Fix tbaa.struct metadata for bitfields using big endian.

When generating tbaa.struct metadata we treat multiple adjacent
bitfields as a single "field", with one corresponding entry in the
metadata.
At the moment this is achieved by adding an entry for the first
bitfield in the run using its StorageSize (and skipping the remaining
bitfields). The problem is that "first" is determined by checking that
the Offset of the field in the run is 0. This breaks for big endian.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp  |  6 +-
 clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp | 10 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..0ddefc4751b08c 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =
diff --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, 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"}

>From bdfc7dd785d50d4bf41428afb314a4c89d22c100 Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Fri, 5 Apr 2024 14:58:29 +0100
Subject: [PATCH 2/2] fixup! Fix tbaa.struct metadata for bitfields using big
 endian.

---
 clang/lib/CodeGen/CodeGenTBAA.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 0ddefc4751b08c..837bf725da388a 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -320,6 +320,9 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
+// For big endian targets the first bitfield in the consecutive run is
+// at the most-significant end; see CGRecordLowering::setBitFieldInfo
+// for more information.
 bool IsBE = Context.getTargetInfo().isBigEndian();
 bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
 : Info.Offset == 0;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits


@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0

juliannagele wrote:

Added a comment, thanks!

https://github.com/llvm/llvm-project/pull/87753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [XRay][AArch64] Support -fxray-shared (PR #114431)

2024-11-05 Thread Julian Nagele via cfe-commits

juliannagele wrote:

Unfortunately it looks like this has broken building compiler-rt on green 
dragon:
https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/2606/console
```
:1:1: error: unrecognized instruction mnemonic
pushfq
^
/Users/ec2-user/jenkins/workspace/llvm.org/clang-stage1-RA/llvm-project/compiler-rt/lib/xray/xray_trampoline_x86_64.S:129:2:
 note: while in macro instantiation
 SAVE_REGISTERS
 ^
...
```

https://github.com/llvm/llvm-project/pull/114431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits