[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-15 Thread via cfe-commits

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-15 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/90741

>From 1d6b0bb8479edce69e054ce461482bdbafb4eb4e Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 1 May 2024 15:20:05 +
Subject: [PATCH 1/2] [Clang] Fix incorrect passing of _BitInt args

---
 clang/lib/CodeGen/Targets/AArch64.cpp   |  2 +-
 clang/test/CodeGen/aarch64-bitint-argpass.c | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/aarch64-bitint-argpass.c

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 4c32f510101f0..7daf416b624fa 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -302,7 +302,7 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 
 if (const auto *EIT = Ty->getAs())
   if (EIT->getNumBits() > 128)
-return getNaturalAlignIndirect(Ty);
+return getNaturalAlignIndirect(Ty, false);
 
 return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
 ? ABIArgInfo::getExtend(Ty)
diff --git a/clang/test/CodeGen/aarch64-bitint-argpass.c 
b/clang/test/CodeGen/aarch64-bitint-argpass.c
new file mode 100644
index 0..c7333bac75c1a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-bitint-argpass.c
@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
+
+_BitInt(129) v = -1;
+int h(_BitInt(129));
+
+// CHECK: declare i32 @h(ptr noundef)
+int largerthan128() {
+   return h(v);
+}
+
+

>From f67d0d5a9a99b72a238189e5f6a41586b5b81d6e Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Tue, 14 May 2024 14:51:51 +
Subject: [PATCH 2/2] Fixed ext-int-cc.c test and removed the newly added one

---
 clang/test/CodeGen/aarch64-bitint-argpass.c | 14 --
 clang/test/CodeGen/ext-int-cc.c |  8 
 2 files changed, 4 insertions(+), 18 deletions(-)
 delete mode 100644 clang/test/CodeGen/aarch64-bitint-argpass.c

diff --git a/clang/test/CodeGen/aarch64-bitint-argpass.c 
b/clang/test/CodeGen/aarch64-bitint-argpass.c
deleted file mode 100644
index c7333bac75c1a..0
--- a/clang/test/CodeGen/aarch64-bitint-argpass.c
+++ /dev/null
@@ -1,14 +0,0 @@
-// REQUIRES: arm-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-elf \
-// RUN:   -O2 \
-// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
-
-_BitInt(129) v = -1;
-int h(_BitInt(129));
-
-// CHECK: declare i32 @h(ptr noundef)
-int largerthan128() {
-   return h(v);
-}
-
-
diff --git a/clang/test/CodeGen/ext-int-cc.c b/clang/test/CodeGen/ext-int-cc.c
index 001e866d34b45..508728172ab4a 100644
--- a/clang/test/CodeGen/ext-int-cc.c
+++ b/clang/test/CodeGen/ext-int-cc.c
@@ -22,9 +22,9 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple systemz -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=SYSTEMZ
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC32
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -target-abi 
darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=AARCH64DARWIN
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios 
-target-abi darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck 
%s --check-prefixes=AARCH64DARWIN
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=ARM
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA64
@@ -135,6 +135,7 @@ void ParamPassing4(_BitInt(129) a) {}
 // WIN64: define dso_local void @ParamPassing4(ptr %{{.+}})
 // LIN32: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // WIN32: define dso_local void @ParamPassing4(ptr %{{.+}})
+// AARCH64: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // 

[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-14 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-14 Thread via cfe-commits


@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s

Lukacma wrote:

Thank you for pointing me to this ! I didn't expect there would a general tests 
for all ABIs ! I have adjusted the test so it correctly checks for sizes >128. 
Probably better fix would be to correctly set __BITINT_MAXWIDTH__  in AArch64 
target, but that is story for separate patch.

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-14 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/90741

>From 1d6b0bb8479edce69e054ce461482bdbafb4eb4e Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 1 May 2024 15:20:05 +
Subject: [PATCH 1/2] [Clang] Fix incorrect passing of _BitInt args

---
 clang/lib/CodeGen/Targets/AArch64.cpp   |  2 +-
 clang/test/CodeGen/aarch64-bitint-argpass.c | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/aarch64-bitint-argpass.c

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 4c32f510101f0..7daf416b624fa 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -302,7 +302,7 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 
 if (const auto *EIT = Ty->getAs())
   if (EIT->getNumBits() > 128)
-return getNaturalAlignIndirect(Ty);
+return getNaturalAlignIndirect(Ty, false);
 
 return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
 ? ABIArgInfo::getExtend(Ty)
diff --git a/clang/test/CodeGen/aarch64-bitint-argpass.c 
b/clang/test/CodeGen/aarch64-bitint-argpass.c
new file mode 100644
index 0..c7333bac75c1a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-bitint-argpass.c
@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
+
+_BitInt(129) v = -1;
+int h(_BitInt(129));
+
+// CHECK: declare i32 @h(ptr noundef)
+int largerthan128() {
+   return h(v);
+}
+
+

>From f67d0d5a9a99b72a238189e5f6a41586b5b81d6e Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Tue, 14 May 2024 14:51:51 +
Subject: [PATCH 2/2] Fixed ext-int-cc.c test and removed the newly added one

---
 clang/test/CodeGen/aarch64-bitint-argpass.c | 14 --
 clang/test/CodeGen/ext-int-cc.c |  8 
 2 files changed, 4 insertions(+), 18 deletions(-)
 delete mode 100644 clang/test/CodeGen/aarch64-bitint-argpass.c

diff --git a/clang/test/CodeGen/aarch64-bitint-argpass.c 
b/clang/test/CodeGen/aarch64-bitint-argpass.c
deleted file mode 100644
index c7333bac75c1a..0
--- a/clang/test/CodeGen/aarch64-bitint-argpass.c
+++ /dev/null
@@ -1,14 +0,0 @@
-// REQUIRES: arm-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-elf \
-// RUN:   -O2 \
-// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
-
-_BitInt(129) v = -1;
-int h(_BitInt(129));
-
-// CHECK: declare i32 @h(ptr noundef)
-int largerthan128() {
-   return h(v);
-}
-
-
diff --git a/clang/test/CodeGen/ext-int-cc.c b/clang/test/CodeGen/ext-int-cc.c
index 001e866d34b45..508728172ab4a 100644
--- a/clang/test/CodeGen/ext-int-cc.c
+++ b/clang/test/CodeGen/ext-int-cc.c
@@ -22,9 +22,9 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple systemz -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=SYSTEMZ
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple ppc -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC32
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple aarch64 -target-abi 
darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=AARCH64DARWIN
-// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 
-disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | 
FileCheck %s --check-prefixes=AARCH64
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios 
-target-abi darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck 
%s --check-prefixes=AARCH64DARWIN
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=ARM
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch64 -O3 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA64
@@ -135,6 +135,7 @@ void ParamPassing4(_BitInt(129) a) {}
 // WIN64: define dso_local void @ParamPassing4(ptr %{{.+}})
 // LIN32: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // WIN32: define dso_local void @ParamPassing4(ptr %{{.+}})
+// AARCH64: define{{.*}} void @ParamPassing4(ptr %{{.+}})
 // 

[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-10 Thread Eli Friedman via cfe-commits


@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s

efriedma-quic wrote:

Digging a bit into the history, I found clang/test/CodeGen/ext-int-cc.c .  
Which apparently has broken CHECK-NOT lines.

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-10 Thread via cfe-commits


@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s

Lukacma wrote:

I don't think such test file exists for aarch64. I tried searching for smth 
like that in CodeGen, couldn't find any file which would be suitable for this 
test.

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-09 Thread Eli Friedman via cfe-commits


@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s

efriedma-quic wrote:

Can we integrate this into some existing test file for aarch64 calling 
conventions?

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-09 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/90741

>From 1d6b0bb8479edce69e054ce461482bdbafb4eb4e Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 1 May 2024 15:20:05 +
Subject: [PATCH] [Clang] Fix incorrect passing of _BitInt args

---
 clang/lib/CodeGen/Targets/AArch64.cpp   |  2 +-
 clang/test/CodeGen/aarch64-bitint-argpass.c | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/aarch64-bitint-argpass.c

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 4c32f510101f0..7daf416b624fa 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -302,7 +302,7 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 
 if (const auto *EIT = Ty->getAs())
   if (EIT->getNumBits() > 128)
-return getNaturalAlignIndirect(Ty);
+return getNaturalAlignIndirect(Ty, false);
 
 return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
 ? ABIArgInfo::getExtend(Ty)
diff --git a/clang/test/CodeGen/aarch64-bitint-argpass.c 
b/clang/test/CodeGen/aarch64-bitint-argpass.c
new file mode 100644
index 0..c7333bac75c1a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-bitint-argpass.c
@@ -0,0 +1,14 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-elf \
+// RUN:   -O2 \
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
+
+_BitInt(129) v = -1;
+int h(_BitInt(129));
+
+// CHECK: declare i32 @h(ptr noundef)
+int largerthan128() {
+   return h(v);
+}
+
+

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-09 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/90741

>From dfb8a9de874f233c9d3964569f3d5201fd717c16 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Tue, 30 Apr 2024 12:46:48 +
Subject: [PATCH 1/3] [Clang][AArch64] Fixed incorrect _BitInt alignment

---
 clang/include/clang/Basic/TargetInfo.h |  8 
 clang/lib/AST/ASTContext.cpp   |  5 +-
 clang/lib/Basic/Targets/AArch64.cpp|  6 ++-
 clang/lib/Basic/Targets/AArch64.h  |  3 ++
 clang/test/CodeGen/aapcs64-align.cpp   | 64 +-
 5 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3ced2e7397a75..1b5efa488b6de 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -518,6 +518,14 @@ class TargetInfo : public TransferrableTargetInfo,
   /// getInt128Align() - Returns the alignment of Int128.
   unsigned getInt128Align() const { return Int128Align; }
 
+  /// getBitIntAlign/Width - Return aligned size of '_BitInt' and 
+  /// 'unsigned _BitInt' for this target, in bits.
+  unsigned getBitIntWidth(unsigned NumBits) const {
+return llvm::alignTo(NumBits, getBitIntAlign(NumBits));}
+  virtual unsigned getBitIntAlign(unsigned NumBits) const {
+return std::clamp(llvm::PowerOf2Ceil(NumBits), getCharWidth(), 
+getLongLongAlign());}
+
   /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
   /// 'unsigned short _Accum' for this target, in bits.
   unsigned getShortAccumWidth() const { return ShortAccumWidth; }
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index cbf4932aff9a6..f440af50e08a4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2263,9 +2263,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
   }
   case Type::BitInt: {
 const auto *EIT = cast(T);
-Align = std::clamp(llvm::PowerOf2Ceil(EIT->getNumBits()),
- getCharWidth(), Target->getLongLongAlign());
-Width = llvm::alignTo(EIT->getNumBits(), Align);
+Align = Target->getBitIntAlign(EIT->getNumBits());
+Width = Target->getBitIntWidth(EIT->getNumBits());
 break;
   }
   case Type::Record:
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c8d243a8fb7ae..9a6c197ff77b5 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1473,6 +1473,10 @@ bool AArch64TargetInfo::validatePointerAuthKey(
 
 bool AArch64TargetInfo::hasInt128Type() const { return true; }
 
+unsigned AArch64TargetInfo::getBitIntAlign(unsigned NumBits) const{
+return std::clamp(llvm::PowerOf2Ceil(NumBits), 
getCharWidth(), 
+getInt128Align());}
+
 AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple ,
  const TargetOptions )
 : AArch64TargetInfo(Triple, Opts) {}
@@ -1674,4 +1678,4 @@ void RenderScript64TargetInfo::getTargetDefines(const 
LangOptions ,
 MacroBuilder ) const {
   Builder.defineMacro("__RENDERSCRIPT__");
   AArch64leTargetInfo::getTargetDefines(Opts, Builder);
-}
+}
\ No newline at end of file
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..d8cdc814b2a9a 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,9 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine ) const override;
+
+  unsigned getBitIntAlign(unsigned NumBits) const override;
+ 
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/test/CodeGen/aapcs64-align.cpp 
b/clang/test/CodeGen/aapcs64-align.cpp
index de231f2123b97..7a8151022852e 100644
--- a/clang/test/CodeGen/aapcs64-align.cpp
+++ b/clang/test/CodeGen/aapcs64-align.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: arm-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-elf \
 // RUN:   -O2 \
-// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
 
 extern "C" {
 
@@ -100,4 +100,66 @@ void f5m(int, int, int, int, int, P16);
 // CHECK: declare void @f5(i32 noundef, [2 x i64])
 // CHECK: declare void @f5m(i32 noundef, i32 noundef, i32 noundef, i32 
noundef, i32 noundef, [2 x i64])
 
+//BitInt alignment
+struct BITINT129 {
+char ch;
+unsigned _BitInt(129) v;
+};
+
+int test_bitint129(){
+  return __builtin_offsetof(struct BITINT129, v);
 }
+// CHECK:  ret i32 16 
+
+struct BITINT127 {
+char ch;
+_BitInt(127) v;
+};
+
+int test_bitint127(){
+  return __builtin_offsetof(struct BITINT127, v);
+}
+// CHECK:  ret i32 16 
+
+struct BITINT63 {
+  

[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-01 Thread via cfe-commits

Lukacma wrote:

This PR is dependent on #90602 to be merged.

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


[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (Lukacma)


Changes

This patch removes incorrect `byval` attribute from pointer argument passed 
with 128 bit long _BitInt types. 

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


7 Files Affected:

- (modified) clang/include/clang/Basic/TargetInfo.h (+10) 
- (modified) clang/lib/AST/ASTContext.cpp (+2-3) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+6-1) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+2) 
- (modified) clang/lib/CodeGen/Targets/AArch64.cpp (+1-1) 
- (modified) clang/test/CodeGen/aapcs64-align.cpp (+63-1) 
- (added) clang/test/CodeGen/aarch64-bitint-argpass.c (+14) 


``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3ced2e7397a754..488b166a95af7d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -518,6 +518,16 @@ class TargetInfo : public TransferrableTargetInfo,
   /// getInt128Align() - Returns the alignment of Int128.
   unsigned getInt128Align() const { return Int128Align; }
 
+  /// getBitIntAlign/Width - Return aligned size of '_BitInt' and
+  /// 'unsigned _BitInt' for this target, in bits.
+  unsigned getBitIntWidth(unsigned NumBits) const {
+return llvm::alignTo(NumBits, getBitIntAlign(NumBits));
+  }
+  virtual unsigned getBitIntAlign(unsigned NumBits) const {
+return std::clamp(llvm::PowerOf2Ceil(NumBits), getCharWidth(),
+getLongLongAlign());
+  }
+
   /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
   /// 'unsigned short _Accum' for this target, in bits.
   unsigned getShortAccumWidth() const { return ShortAccumWidth; }
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index cbf4932aff9a6b..f440af50e08a49 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2263,9 +2263,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
   }
   case Type::BitInt: {
 const auto *EIT = cast(T);
-Align = std::clamp(llvm::PowerOf2Ceil(EIT->getNumBits()),
- getCharWidth(), Target->getLongLongAlign());
-Width = llvm::alignTo(EIT->getNumBits(), Align);
+Align = Target->getBitIntAlign(EIT->getNumBits());
+Width = Target->getBitIntWidth(EIT->getNumBits());
 break;
   }
   case Type::Record:
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c8d243a8fb7aea..cc0ae0e2856fd0 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1473,6 +1473,11 @@ bool AArch64TargetInfo::validatePointerAuthKey(
 
 bool AArch64TargetInfo::hasInt128Type() const { return true; }
 
+unsigned AArch64TargetInfo::getBitIntAlign(unsigned NumBits) const {
+  return std::clamp(llvm::PowerOf2Ceil(NumBits), getCharWidth(),
+  getInt128Align());
+}
+
 AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple ,
  const TargetOptions )
 : AArch64TargetInfo(Triple, Opts) {}
@@ -1674,4 +1679,4 @@ void RenderScript64TargetInfo::getTargetDefines(const 
LangOptions ,
 MacroBuilder ) const {
   Builder.defineMacro("__RENDERSCRIPT__");
   AArch64leTargetInfo::getTargetDefines(Opts, Builder);
-}
+}
\ No newline at end of file
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f7511..be6435007a6009 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine ) const override;
+
+  unsigned getBitIntAlign(unsigned NumBits) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 4c32f510101f04..7daf416b624fa6 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -302,7 +302,7 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 
 if (const auto *EIT = Ty->getAs())
   if (EIT->getNumBits() > 128)
-return getNaturalAlignIndirect(Ty);
+return getNaturalAlignIndirect(Ty, false);
 
 return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
 ? ABIArgInfo::getExtend(Ty)
diff --git a/clang/test/CodeGen/aapcs64-align.cpp 
b/clang/test/CodeGen/aapcs64-align.cpp
index de231f2123b975..7a8151022852ea 100644
--- a/clang/test/CodeGen/aapcs64-align.cpp
+++ b/clang/test/CodeGen/aapcs64-align.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: arm-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-elf \
 // RUN:   -O2 \
-// RUN:   -emit-llvm -o - %s | FileCheck %s
+// 

[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: None (Lukacma)


Changes

This patch removes incorrect `byval` attribute from pointer argument passed 
with 128 bit long _BitInt types. 

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


7 Files Affected:

- (modified) clang/include/clang/Basic/TargetInfo.h (+10) 
- (modified) clang/lib/AST/ASTContext.cpp (+2-3) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+6-1) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+2) 
- (modified) clang/lib/CodeGen/Targets/AArch64.cpp (+1-1) 
- (modified) clang/test/CodeGen/aapcs64-align.cpp (+63-1) 
- (added) clang/test/CodeGen/aarch64-bitint-argpass.c (+14) 


``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3ced2e7397a754..488b166a95af7d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -518,6 +518,16 @@ class TargetInfo : public TransferrableTargetInfo,
   /// getInt128Align() - Returns the alignment of Int128.
   unsigned getInt128Align() const { return Int128Align; }
 
+  /// getBitIntAlign/Width - Return aligned size of '_BitInt' and
+  /// 'unsigned _BitInt' for this target, in bits.
+  unsigned getBitIntWidth(unsigned NumBits) const {
+return llvm::alignTo(NumBits, getBitIntAlign(NumBits));
+  }
+  virtual unsigned getBitIntAlign(unsigned NumBits) const {
+return std::clamp(llvm::PowerOf2Ceil(NumBits), getCharWidth(),
+getLongLongAlign());
+  }
+
   /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
   /// 'unsigned short _Accum' for this target, in bits.
   unsigned getShortAccumWidth() const { return ShortAccumWidth; }
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index cbf4932aff9a6b..f440af50e08a49 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2263,9 +2263,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
   }
   case Type::BitInt: {
 const auto *EIT = cast(T);
-Align = std::clamp(llvm::PowerOf2Ceil(EIT->getNumBits()),
- getCharWidth(), Target->getLongLongAlign());
-Width = llvm::alignTo(EIT->getNumBits(), Align);
+Align = Target->getBitIntAlign(EIT->getNumBits());
+Width = Target->getBitIntWidth(EIT->getNumBits());
 break;
   }
   case Type::Record:
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c8d243a8fb7aea..cc0ae0e2856fd0 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1473,6 +1473,11 @@ bool AArch64TargetInfo::validatePointerAuthKey(
 
 bool AArch64TargetInfo::hasInt128Type() const { return true; }
 
+unsigned AArch64TargetInfo::getBitIntAlign(unsigned NumBits) const {
+  return std::clamp(llvm::PowerOf2Ceil(NumBits), getCharWidth(),
+  getInt128Align());
+}
+
 AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple ,
  const TargetOptions )
 : AArch64TargetInfo(Triple, Opts) {}
@@ -1674,4 +1679,4 @@ void RenderScript64TargetInfo::getTargetDefines(const 
LangOptions ,
 MacroBuilder ) const {
   Builder.defineMacro("__RENDERSCRIPT__");
   AArch64leTargetInfo::getTargetDefines(Opts, Builder);
-}
+}
\ No newline at end of file
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f7511..be6435007a6009 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine ) const override;
+
+  unsigned getBitIntAlign(unsigned NumBits) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 4c32f510101f04..7daf416b624fa6 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -302,7 +302,7 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 
 if (const auto *EIT = Ty->getAs())
   if (EIT->getNumBits() > 128)
-return getNaturalAlignIndirect(Ty);
+return getNaturalAlignIndirect(Ty, false);
 
 return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
 ? ABIArgInfo::getExtend(Ty)
diff --git a/clang/test/CodeGen/aapcs64-align.cpp 
b/clang/test/CodeGen/aapcs64-align.cpp
index de231f2123b975..7a8151022852ea 100644
--- a/clang/test/CodeGen/aapcs64-align.cpp
+++ b/clang/test/CodeGen/aapcs64-align.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: arm-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-elf \
 // RUN:   -O2 \
-// RUN:   -emit-llvm -o - %s | FileCheck %s
+// 

[clang] [Clang] Fix incorrect passing of _BitInt args (PR #90741)

2024-05-01 Thread via cfe-commits

https://github.com/Lukacma created 
https://github.com/llvm/llvm-project/pull/90741

This patch removes incorrect `byval` attribute from pointer argument passed 
with >128 bit long _BitInt types. 

>From dfb8a9de874f233c9d3964569f3d5201fd717c16 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Tue, 30 Apr 2024 12:46:48 +
Subject: [PATCH 1/3] [Clang][AArch64] Fixed incorrect _BitInt alignment

---
 clang/include/clang/Basic/TargetInfo.h |  8 
 clang/lib/AST/ASTContext.cpp   |  5 +-
 clang/lib/Basic/Targets/AArch64.cpp|  6 ++-
 clang/lib/Basic/Targets/AArch64.h  |  3 ++
 clang/test/CodeGen/aapcs64-align.cpp   | 64 +-
 5 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3ced2e7397a754..1b5efa488b6ded 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -518,6 +518,14 @@ class TargetInfo : public TransferrableTargetInfo,
   /// getInt128Align() - Returns the alignment of Int128.
   unsigned getInt128Align() const { return Int128Align; }
 
+  /// getBitIntAlign/Width - Return aligned size of '_BitInt' and 
+  /// 'unsigned _BitInt' for this target, in bits.
+  unsigned getBitIntWidth(unsigned NumBits) const {
+return llvm::alignTo(NumBits, getBitIntAlign(NumBits));}
+  virtual unsigned getBitIntAlign(unsigned NumBits) const {
+return std::clamp(llvm::PowerOf2Ceil(NumBits), getCharWidth(), 
+getLongLongAlign());}
+
   /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
   /// 'unsigned short _Accum' for this target, in bits.
   unsigned getShortAccumWidth() const { return ShortAccumWidth; }
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index cbf4932aff9a6b..f440af50e08a49 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2263,9 +2263,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
   }
   case Type::BitInt: {
 const auto *EIT = cast(T);
-Align = std::clamp(llvm::PowerOf2Ceil(EIT->getNumBits()),
- getCharWidth(), Target->getLongLongAlign());
-Width = llvm::alignTo(EIT->getNumBits(), Align);
+Align = Target->getBitIntAlign(EIT->getNumBits());
+Width = Target->getBitIntWidth(EIT->getNumBits());
 break;
   }
   case Type::Record:
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c8d243a8fb7aea..9a6c197ff77b58 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1473,6 +1473,10 @@ bool AArch64TargetInfo::validatePointerAuthKey(
 
 bool AArch64TargetInfo::hasInt128Type() const { return true; }
 
+unsigned AArch64TargetInfo::getBitIntAlign(unsigned NumBits) const{
+return std::clamp(llvm::PowerOf2Ceil(NumBits), 
getCharWidth(), 
+getInt128Align());}
+
 AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple ,
  const TargetOptions )
 : AArch64TargetInfo(Triple, Opts) {}
@@ -1674,4 +1678,4 @@ void RenderScript64TargetInfo::getTargetDefines(const 
LangOptions ,
 MacroBuilder ) const {
   Builder.defineMacro("__RENDERSCRIPT__");
   AArch64leTargetInfo::getTargetDefines(Opts, Builder);
-}
+}
\ No newline at end of file
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f7511..d8cdc814b2a9ae 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,9 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool hasBitIntType() const override { return true; }
 
   bool validateTarget(DiagnosticsEngine ) const override;
+
+  unsigned getBitIntAlign(unsigned NumBits) const override;
+ 
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
diff --git a/clang/test/CodeGen/aapcs64-align.cpp 
b/clang/test/CodeGen/aapcs64-align.cpp
index de231f2123b975..7a8151022852ea 100644
--- a/clang/test/CodeGen/aapcs64-align.cpp
+++ b/clang/test/CodeGen/aapcs64-align.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: arm-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-elf \
 // RUN:   -O2 \
-// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN:   -emit-llvm -fexperimental-max-bitint-width=1024 -o - %s | FileCheck 
%s
 
 extern "C" {
 
@@ -100,4 +100,66 @@ void f5m(int, int, int, int, int, P16);
 // CHECK: declare void @f5(i32 noundef, [2 x i64])
 // CHECK: declare void @f5m(i32 noundef, i32 noundef, i32 noundef, i32 
noundef, i32 noundef, [2 x i64])
 
+//BitInt alignment
+struct BITINT129 {
+char ch;
+unsigned _BitInt(129) v;
+};
+
+int test_bitint129(){
+  return __builtin_offsetof(struct BITINT129, v);
 }
+// CHECK:  ret i32 16 
+
+struct BITINT127 {
+char ch;
+_BitInt(127) v;
+};
+