[clang] [clang][AArch64] Enable fp128 for aarch64 linux target (PR #85070)

2024-03-18 Thread Pranav Kant via cfe-commits

pranavk wrote:

I have same opinion as @lntue and Nick.

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


[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-06 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/83918

>From c28121199d5e16efb908a3058a52c6b5b2016848 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 4 Mar 2024 22:19:04 +
Subject: [PATCH 1/3] [clang][CUDA] Disable float128 diagnostics for device
 compilation

---
 clang/lib/Sema/SemaDeclAttr.cpp | 4 +++-
 clang/lib/Sema/SemaType.cpp | 1 +
 clang/test/SemaCUDA/float128.cu | 9 +
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCUDA/float128.cu

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 397b5db0dc0669..e6943efb345ce0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if (NewElemTy.isNull()) {
-Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
+// Only emit diagnostic on host for 128-bit mode attribute
+if (!(DestWidth == 128 && getLangOpts().CUDAIsDevice))
+  Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1e43e36016a66f..4a4e6f80d0d049 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1562,6 +1562,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
 !S.getLangOpts().SYCLIsDevice &&
+!S.getLangOpts().CUDAIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";
diff --git a/clang/test/SemaCUDA/float128.cu b/clang/test/SemaCUDA/float128.cu
new file mode 100644
index 00..a59e1b2f8a741a
--- /dev/null
+++ b/clang/test/SemaCUDA/float128.cu
@@ -0,0 +1,9 @@
+// CPU-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x 
cuda -fsyntax-only -verify %s
+
+// GPU-side compilation on x86 (no errors expected)
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fcuda-is-device -x cuda -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
+typedef __float128 _Float128;

>From bcc8d6ea5e7922712017ecb1941a53cf769577b3 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 4 Mar 2024 22:31:24 +
Subject: [PATCH 2/3] formatting

---
 clang/lib/Sema/SemaType.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 4a4e6f80d0d049..3148299f6467af 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1561,8 +1561,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
 break;
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
-!S.getLangOpts().SYCLIsDevice &&
-!S.getLangOpts().CUDAIsDevice &&
+!S.getLangOpts().SYCLIsDevice && !S.getLangOpts().CUDAIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";

>From 422af59d7aa7c0095606e0a9bf6ce091ea84b925 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Wed, 6 Mar 2024 22:33:33 +
Subject: [PATCH 3/3] extend test to compile a device function

---
 clang/test/SemaCUDA/float128.cu | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCUDA/float128.cu b/clang/test/SemaCUDA/float128.cu
index a59e1b2f8a741a..f8f20cb1588d76 100644
--- a/clang/test/SemaCUDA/float128.cu
+++ b/clang/test/SemaCUDA/float128.cu
@@ -1,9 +1,18 @@
 // CPU-side compilation on x86 (no errors expected).
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x 
cuda -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x 
cuda -fsyntax-only -verify=cpu %s
 
 // GPU-side compilation on x86 (no errors expected)
-// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fcuda-is-device -x cuda -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fcuda-is-device -x cuda -fsyntax-only -verify=gpu %s
 
-// expected-no-diagnostics
+// cpu-no-diagnostics
 typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
 typedef __float128 _Float128;
+
+// gpu-note@+1 {{'a' defined here}}
+__attribute__((device)) __float128 f(__float128 a, float b) {
+// gpu-note@+1 {{'c' defined here}}
+  __float128 c = b + 1.0;
+  // gpu-error@+2 {{'a' requires 128 bit size '__float128' type support, but 
target 'nvptx64' does not s

[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-04 Thread Pranav Kant via cfe-commits

https://github.com/pranavk created 
https://github.com/llvm/llvm-project/pull/83918

None

>From 39fa380fc3df9775e59b1957dca4a7f927702360 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 4 Mar 2024 22:19:04 +
Subject: [PATCH] [clang][CUDA] Disable float128 diagnostics for device
 compilation

---
 clang/lib/Sema/SemaDeclAttr.cpp | 4 +++-
 clang/lib/Sema/SemaType.cpp | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 397b5db0dc0669..e6943efb345ce0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if (NewElemTy.isNull()) {
-Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
+// Only emit diagnostic on host for 128-bit mode attribute
+if (!(DestWidth == 128 && getLangOpts().CUDAIsDevice))
+  Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1e43e36016a66f..4a4e6f80d0d049 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1562,6 +1562,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
 !S.getLangOpts().SYCLIsDevice &&
+!S.getLangOpts().CUDAIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";

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


[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-04 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/83918

>From c28121199d5e16efb908a3058a52c6b5b2016848 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 4 Mar 2024 22:19:04 +
Subject: [PATCH] [clang][CUDA] Disable float128 diagnostics for device
 compilation

---
 clang/lib/Sema/SemaDeclAttr.cpp | 4 +++-
 clang/lib/Sema/SemaType.cpp | 1 +
 clang/test/SemaCUDA/float128.cu | 9 +
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCUDA/float128.cu

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 397b5db0dc0669..e6943efb345ce0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if (NewElemTy.isNull()) {
-Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
+// Only emit diagnostic on host for 128-bit mode attribute
+if (!(DestWidth == 128 && getLangOpts().CUDAIsDevice))
+  Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1e43e36016a66f..4a4e6f80d0d049 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1562,6 +1562,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
 !S.getLangOpts().SYCLIsDevice &&
+!S.getLangOpts().CUDAIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";
diff --git a/clang/test/SemaCUDA/float128.cu b/clang/test/SemaCUDA/float128.cu
new file mode 100644
index 00..a59e1b2f8a741a
--- /dev/null
+++ b/clang/test/SemaCUDA/float128.cu
@@ -0,0 +1,9 @@
+// CPU-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x 
cuda -fsyntax-only -verify %s
+
+// GPU-side compilation on x86 (no errors expected)
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fcuda-is-device -x cuda -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
+typedef __float128 _Float128;

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


[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-04 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/83918

>From c28121199d5e16efb908a3058a52c6b5b2016848 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 4 Mar 2024 22:19:04 +
Subject: [PATCH 1/2] [clang][CUDA] Disable float128 diagnostics for device
 compilation

---
 clang/lib/Sema/SemaDeclAttr.cpp | 4 +++-
 clang/lib/Sema/SemaType.cpp | 1 +
 clang/test/SemaCUDA/float128.cu | 9 +
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCUDA/float128.cu

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 397b5db0dc0669..e6943efb345ce0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if (NewElemTy.isNull()) {
-Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
+// Only emit diagnostic on host for 128-bit mode attribute
+if (!(DestWidth == 128 && getLangOpts().CUDAIsDevice))
+  Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1e43e36016a66f..4a4e6f80d0d049 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1562,6 +1562,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
 !S.getLangOpts().SYCLIsDevice &&
+!S.getLangOpts().CUDAIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";
diff --git a/clang/test/SemaCUDA/float128.cu b/clang/test/SemaCUDA/float128.cu
new file mode 100644
index 00..a59e1b2f8a741a
--- /dev/null
+++ b/clang/test/SemaCUDA/float128.cu
@@ -0,0 +1,9 @@
+// CPU-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x 
cuda -fsyntax-only -verify %s
+
+// GPU-side compilation on x86 (no errors expected)
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fcuda-is-device -x cuda -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
+typedef __float128 _Float128;

>From bcc8d6ea5e7922712017ecb1941a53cf769577b3 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 4 Mar 2024 22:31:24 +
Subject: [PATCH 2/2] formatting

---
 clang/lib/Sema/SemaType.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 4a4e6f80d0d049..3148299f6467af 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1561,8 +1561,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
 break;
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
-!S.getLangOpts().SYCLIsDevice &&
-!S.getLangOpts().CUDAIsDevice &&
+!S.getLangOpts().SYCLIsDevice && !S.getLangOpts().CUDAIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";

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


[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-04 Thread Pranav Kant via cfe-commits


@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if (NewElemTy.isNull()) {
-Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
+// Only emit diagnostic on host for 128-bit mode attribute

pranavk wrote:

This is going to error out like this:

```
error: 'a' requires 128 bit size '__float128' type support, but target 
'nvptx64-nvidia-cuda' does not support it
```

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


[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-04 Thread Pranav Kant via cfe-commits


@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if (NewElemTy.isNull()) {
-Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
+// Only emit diagnostic on host for 128-bit mode attribute

pranavk wrote:

On second thought, it may be a good idea to add that in the diagnostic test.

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


[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-04 Thread Pranav Kant via cfe-commits


@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if (NewElemTy.isNull()) {
-Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
+// Only emit diagnostic on host for 128-bit mode attribute

pranavk wrote:

There are two diags that I disabled as part of this PR:
1. "%0 is not supported on this target"
2. unsupported machine mode __TC__

The diag that got emitted as part of building sample snippet that you pasted in 
this comment thread is neither 1 nor 2. This diag comes from part of clang/LLVM 
when it starts to generate code for nvptx specifically.

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


[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)

2024-03-04 Thread Pranav Kant via cfe-commits

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-22 Thread Pranav Kant via cfe-commits

https://github.com/pranavk created 
https://github.com/llvm/llvm-project/pull/67196

None

>From 8c07729b195fa78133258b03a31e8668d70a922d Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 20:50:32 +
Subject: [PATCH] [clang] Predefined macros for float128 support

---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e5db8a654e6707d..9e4d4d398a21da5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-22 Thread Pranav Kant via cfe-commits

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-22 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/67196

>From 8c07729b195fa78133258b03a31e8668d70a922d Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 20:50:32 +
Subject: [PATCH 1/2] [clang] Predefined macros for float128 support

---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e5db8a654e6707d..9e4d4d398a21da5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

>From 0978352c91562f82229daeb1fb65f27f04f93d97 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 21:23:51 +
Subject: [PATCH 2/2] Fix test

---
 clang/test/Preprocessor/init.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 59c5122afe1e4c3..395c4cebfa5be76 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1576,6 +1576,20 @@
 // EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
 // WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
 // WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_DECIMAL_DIG__ 36
+// WEBASSEMBLY-NEXT:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
+// WEBASSEMBLY-NEXT:#define __FLT128_DIG__ 33
+// WEBASSEMBLY-NEXT:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_DENORM__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_INFINITY__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_MANT_DIG__ 113
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_10_EXP__ 4932
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_EXP__ 16384
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_10_EXP__ (-4931)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_EXP__ (-16381)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
 // WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
 // WEBASSEMBLY-NOT:#define __FLT16_DIG__

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-25 Thread Pranav Kant via cfe-commits


@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");

pranavk wrote:

I am not adding any new float type or any literal suffix (unlike other revision 
you pointed by Ray). This is only adding float macros for which I modified the 
test that was expecting it.

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-26 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/67196

>From 8c07729b195fa78133258b03a31e8668d70a922d Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 20:50:32 +
Subject: [PATCH 1/3] [clang] Predefined macros for float128 support

---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e5db8a654e6707d..9e4d4d398a21da5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

>From 0978352c91562f82229daeb1fb65f27f04f93d97 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 21:23:51 +
Subject: [PATCH 2/3] Fix test

---
 clang/test/Preprocessor/init.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 59c5122afe1e4c3..395c4cebfa5be76 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1576,6 +1576,20 @@
 // EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
 // WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
 // WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_DECIMAL_DIG__ 36
+// WEBASSEMBLY-NEXT:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
+// WEBASSEMBLY-NEXT:#define __FLT128_DIG__ 33
+// WEBASSEMBLY-NEXT:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_DENORM__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_INFINITY__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_MANT_DIG__ 113
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_10_EXP__ 4932
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_EXP__ 16384
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_10_EXP__ (-4931)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_EXP__ (-16381)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
 // WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
 // WEBASSEMBLY-NOT:#define __FLT16_DIG__

>From 98b9a38df6ae039aae014929e26939e38d8d7f55 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Tue, 26 Sep 2023 18:22:12 +
Subject: [PATCH 3/3] Add FLOAT128 macros to NETBSD tests

---
 clang/test/Preprocessor/init-x86.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/clang/test/Preprocessor/init-x86.c 
b/clang/test/Preprocessor/init-x86.c
index 58be9b716571747..8984fcbd02c4f13 100644
--- a/clang/test/Preprocessor/init-x86.c
+++ b/clang/test/Preprocessor/init-x86.c
@@ -1235,6 +1235,21 @@
 // X86_64-NETBSD:#define __DBL_MIN_EXP__ (-1021)
 // X86_64-NETBSD:#define __DBL_MIN__ 2.2250738585072014e-308
 // X86_64-NETBSD:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
+// X86_64-NETBSD:#define __FLOAT128__ 1
+// X86_64-NETBSD:#define __FLT128_DECIMAL_DIG__ 36
+// X86_64-NETBSD:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
+// X86_64-NETBSD:#define __FLT128_DIG__ 33
+// X86_64-NETBSD:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
+// X86_64-NETBSD:#define __FLT128_HAS_DENORM__ 1
+// X86_64-NETBSD:#define __FLT128_HAS_INFINITY__ 1
+// X86_64-NETBSD:#define __FLT128_HAS_QUIET_NAN__ 1
+// X86_64-NETBSD:#define __FLT128_MANT_DIG__ 113
+// X86_64-NETBSD:#define __FLT128_MAX_10_EXP__ 4932
+// X86_64-NETBSD:#define __FLT128_MAX_EXP__ 16384
+// X86_64-NETBSD:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
+// X86_64-NETBSD:#define __FLT128_MIN_10_EXP__ (-4931)
+// X86_64-NETBSD:#define __FLT128_MIN_EXP__ (-16381)
+// X86_64-NETBSD:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // X86_64-NETBSD:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // X86_64-NETBSD:#define __FLT_DIG__ 6
 // X86_64-NETBSD:#define __FLT_EPSILON__ 1.19209290e-7F

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-26 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/67196

>From 8c07729b195fa78133258b03a31e8668d70a922d Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 20:50:32 +
Subject: [PATCH 1/3] [clang] Predefined macros for float128 support

---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e5db8a654e6707d..9e4d4d398a21da5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

>From 0978352c91562f82229daeb1fb65f27f04f93d97 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 21:23:51 +
Subject: [PATCH 2/3] Fix test

---
 clang/test/Preprocessor/init.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 59c5122afe1e4c3..395c4cebfa5be76 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1576,6 +1576,20 @@
 // EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
 // WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
 // WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_DECIMAL_DIG__ 36
+// WEBASSEMBLY-NEXT:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
+// WEBASSEMBLY-NEXT:#define __FLT128_DIG__ 33
+// WEBASSEMBLY-NEXT:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_DENORM__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_INFINITY__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_MANT_DIG__ 113
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_10_EXP__ 4932
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_EXP__ 16384
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_10_EXP__ (-4931)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_EXP__ (-16381)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
 // WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
 // WEBASSEMBLY-NOT:#define __FLT16_DIG__

>From 7882a56d4b9d610cfda5aa141478746c378dbcfb Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Tue, 26 Sep 2023 20:15:43 +
Subject: [PATCH 3/3] Fix test for x86_64

---
 clang/test/Preprocessor/init-x86.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/clang/test/Preprocessor/init-x86.c 
b/clang/test/Preprocessor/init-x86.c
index 58be9b716571747..1ee770df0c4a303 100644
--- a/clang/test/Preprocessor/init-x86.c
+++ b/clang/test/Preprocessor/init-x86.c
@@ -1023,6 +1023,21 @@
 // X86_64-LINUX:#define __DBL_MIN_EXP__ (-1021)
 // X86_64-LINUX:#define __DBL_MIN__ 2.2250738585072014e-308
 // X86_64-LINUX:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
+// X86_64-LINUX:#define __FLOAT128__ 1
+// X86_64-LINUX:#define __FLT128_DECIMAL_DIG__ 36
+// X86_64-LINUX:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
+// X86_64-LINUX:#define __FLT128_DIG__ 33
+// X86_64-LINUX:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
+// X86_64-LINUX:#define __FLT128_HAS_DENORM__ 1
+// X86_64-LINUX:#define __FLT128_HAS_INFINITY__ 1
+// X86_64-LINUX:#define __FLT128_HAS_QUIET_NAN__ 1
+// X86_64-LINUX:#define __FLT128_MANT_DIG__ 113
+// X86_64-LINUX:#define __FLT128_MAX_10_EXP__ 4932
+// X86_64-LINUX:#define __FLT128_MAX_EXP__ 16384
+// X86_64-LINUX:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
+// X86_64-LINUX:#define __FLT128_MIN_10_EXP__ (-4931)
+// X86_64-LINUX:#define __FLT128_MIN_EXP__ (-16381)
+// X86_64-LINUX:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // X86_64-LINUX:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // X86_64-LINUX:#define __FLT_DIG__ 6
 // X86_64-LINUX:#define __FLT_EPSILON__ 1.19209290e-7F

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-10-02 Thread Pranav Kant via cfe-commits

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


[clang] 7d21086 - Revert "[clang] Predefined macros for float128 support (#67196)"

2023-10-04 Thread Pranav Kant via cfe-commits

Author: Pranav Kant
Date: 2023-10-04T18:19:24Z
New Revision: 7d21086d0ca4a680e96e0f4cd3e2597ebe027a48

URL: 
https://github.com/llvm/llvm-project/commit/7d21086d0ca4a680e96e0f4cd3e2597ebe027a48
DIFF: 
https://github.com/llvm/llvm-project/commit/7d21086d0ca4a680e96e0f4cd3e2597ebe027a48.diff

LOG: Revert "[clang] Predefined macros for float128 support (#67196)"

This reverts commit 457f582ffe23e951380bc345c4c96ec053c09681.

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Preprocessor/init-x86.c
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 9e1e02e04ca7a00..846e5fce6de7b2c 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1081,8 +1081,6 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
-  if (TI.hasFloat128Type())
-DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

diff  --git a/clang/test/Preprocessor/init-x86.c 
b/clang/test/Preprocessor/init-x86.c
index 1ee770df0c4a303..58be9b716571747 100644
--- a/clang/test/Preprocessor/init-x86.c
+++ b/clang/test/Preprocessor/init-x86.c
@@ -1023,21 +1023,6 @@
 // X86_64-LINUX:#define __DBL_MIN_EXP__ (-1021)
 // X86_64-LINUX:#define __DBL_MIN__ 2.2250738585072014e-308
 // X86_64-LINUX:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
-// X86_64-LINUX:#define __FLOAT128__ 1
-// X86_64-LINUX:#define __FLT128_DECIMAL_DIG__ 36
-// X86_64-LINUX:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
-// X86_64-LINUX:#define __FLT128_DIG__ 33
-// X86_64-LINUX:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
-// X86_64-LINUX:#define __FLT128_HAS_DENORM__ 1
-// X86_64-LINUX:#define __FLT128_HAS_INFINITY__ 1
-// X86_64-LINUX:#define __FLT128_HAS_QUIET_NAN__ 1
-// X86_64-LINUX:#define __FLT128_MANT_DIG__ 113
-// X86_64-LINUX:#define __FLT128_MAX_10_EXP__ 4932
-// X86_64-LINUX:#define __FLT128_MAX_EXP__ 16384
-// X86_64-LINUX:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
-// X86_64-LINUX:#define __FLT128_MIN_10_EXP__ (-4931)
-// X86_64-LINUX:#define __FLT128_MIN_EXP__ (-16381)
-// X86_64-LINUX:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // X86_64-LINUX:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // X86_64-LINUX:#define __FLT_DIG__ 6
 // X86_64-LINUX:#define __FLT_EPSILON__ 1.19209290e-7F

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 395c4cebfa5be76..59c5122afe1e4c3 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1576,20 +1576,6 @@
 // EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
 // WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
 // WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
-// WEBASSEMBLY-NEXT:#define __FLT128_DECIMAL_DIG__ 36
-// WEBASSEMBLY-NEXT:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
-// WEBASSEMBLY-NEXT:#define __FLT128_DIG__ 33
-// WEBASSEMBLY-NEXT:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
-// WEBASSEMBLY-NEXT:#define __FLT128_HAS_DENORM__ 1
-// WEBASSEMBLY-NEXT:#define __FLT128_HAS_INFINITY__ 1
-// WEBASSEMBLY-NEXT:#define __FLT128_HAS_QUIET_NAN__ 1
-// WEBASSEMBLY-NEXT:#define __FLT128_MANT_DIG__ 113
-// WEBASSEMBLY-NEXT:#define __FLT128_MAX_10_EXP__ 4932
-// WEBASSEMBLY-NEXT:#define __FLT128_MAX_EXP__ 16384
-// WEBASSEMBLY-NEXT:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
-// WEBASSEMBLY-NEXT:#define __FLT128_MIN_10_EXP__ (-4931)
-// WEBASSEMBLY-NEXT:#define __FLT128_MIN_EXP__ (-16381)
-// WEBASSEMBLY-NEXT:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
 // WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
 // WEBASSEMBLY-NOT:#define __FLT16_DIG__



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


[clang] [Clang][Sema] placement new initializes typedef array with correct size (PR #83124)

2024-04-23 Thread Pranav Kant via cfe-commits

pranavk wrote:

This commit is still problematic. Minimal reproducer 
(https://godbolt.org/z/hE7M8EfT1).

We should get this reverted again.

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


[clang] [Clang][Sema] placement new initializes typedef array with correct size (PR #83124)

2024-04-23 Thread Pranav Kant via cfe-commits

pranavk wrote:

```
In file included from /usr/local/foo/home/prka/wip/unique/test.cpp:1:
In file included from 
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/memory:78:
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:1085:14:
 error: no matching conversion for functional-style cast from 'unsigned short 
*' to 'unique_ptr'
 1085 | { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }
  |  ^~
/usr/local/foo/home/prka/wip/unique/test.cpp:10:47: note: in instantiation of 
function template specialization 'std::make_unique' 
requested here
   10 |   const std::unique_ptr nodes_ = 
std::make_unique(max_nodes_);
  |   ^
/usr/local/foo/home/prka/wip/unique/test.cpp:15:38: note: in instantiation of 
member function 'Base<256>::Base' requested here
   15 |   explicit Child(size_t max_bytes) : Base<256>(max_bytes) {
  |  ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:648:7:
 note: candidate constructor not viable: no known conversion from 'unsigned 
short *' to 'unique_ptr' for 1st argument
  648 |   unique_ptr(unique_ptr&&) = default;
  |   ^  
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:652:12:
 note: candidate constructor template not viable: no known conversion from 
'unsigned short *' to 'nullptr_t' (aka 'std::nullptr_t') for 1st argument
  652 | constexpr unique_ptr(nullptr_t) noexcept
  |   ^  ~
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:796:7:
 note: candidate constructor not viable: no known conversion from 'unsigned 
short *' to 'const unique_ptr' for 1st argument
  796 |   unique_ptr(const unique_ptr&) = delete;
  |   ^  ~
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:603:2:
 note: candidate template ignored: requirement 
'__and_, std::is_same>, 
std::__and_, std::is_same, std::is_convertible>>>::value' was not satisfied [with _Up = unsigned 
short *, _Vp = std::default_delete, $2 = 
_DeleterConstraint>]
  603 | unique_ptr(_Up __p) noexcept
  | ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:662:2:
 note: candidate template ignored: could not match 'unique_ptr<_Up, _Ep>' 
against 'unsigned short *'
  662 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
```

We get error messages like above with this commit. This compiles fine without 
this commit or with gcc.

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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)

2024-04-23 Thread Pranav Kant via cfe-commits

pranavk wrote:

@mahtohappy can we please revert this in the meantime while you look for a fix 
here. Feel free to land it again with the fix. 

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


[clang] e1321fa - Revert "Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (#89036)"

2024-04-23 Thread Pranav Kant via cfe-commits

Author: Pranav Kant
Date: 2024-04-23T22:08:50Z
New Revision: e1321fafbc024007023ce5d9b88d987a920c3bca

URL: 
https://github.com/llvm/llvm-project/commit/e1321fafbc024007023ce5d9b88d987a920c3bca
DIFF: 
https://github.com/llvm/llvm-project/commit/e1321fafbc024007023ce5d9b88d987a920c3bca.diff

LOG: Revert "Reapply "[Clang][Sema] placement new initializes typedef array 
with correct size (#83124)" (#89036)"

This reverts commit 74cab546825b32f24e44d69942cdbdd129160471.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriter.cpp

Removed: 
clang/test/SemaCXX/PR41441.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d1f7293a842bb6..3db558a1c11a3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -557,7 +557,6 @@ Bug Fixes to C++ Support
 - Fix a crash in requires expression with templated base class member 
function. Fixes (#GH84020).
 - Fix a crash caused by defined struct in a type alias template when the 
structure
   has fields with dependent type. Fixes (#GH75221).
-- Fix placement new initializes typedef array with correct size. Fixes 
(#GH41441).
 - Fix the Itanium mangling of lambdas defined in a member of a local class 
(#GH88906)
 - Fixed a crash when trying to evaluate a user-defined ``static_assert`` 
message whose ``size()``
   function returns a large or negative value. Fixes (#GH89407).

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 539a18eb92a7ce..9404be5a46f3f7 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12943,19 +12943,6 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
-  // Per C++0x [expr.new]p5, the type being constructed may be a
-  // typedef of an array type.
-  QualType AllocType = AllocTypeInfo->getType();
-  if (ArraySize && E->isTypeDependent()) {
-if (const ConstantArrayType *Array =
-SemaRef.Context.getAsConstantArrayType(AllocType)) {
-  ArraySize = IntegerLiteral::Create(SemaRef.Context, Array->getSize(),
- SemaRef.Context.getSizeType(),
- E->getBeginLoc());
-  AllocType = Array->getElementType();
-}
-  }
-
   // Transform the placement arguments (if any).
   bool ArgumentChanged = false;
   SmallVector PlacementArgs;
@@ -13017,6 +13004,7 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 return E;
   }
 
+  QualType AllocType = AllocTypeInfo->getType();
   if (!ArraySize) {
 // If no array size was specified, but the new expression was
 // instantiated with an array type (e.g., "new T" where T is

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 21cf72ab0f9121..a1b340b252fb08 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5097,7 +5097,7 @@ void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) {
   DeclsToCheckForDeferredDiags.push_back(getDeclID(D));
   if (!DeclsToCheckForDeferredDiags.empty())
 Stream.EmitRecord(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS,
-  DeclsToCheckForDeferredDiags);
+DeclsToCheckForDeferredDiags);
 
   // Write the record containing CUDA-specific declaration references.
   RecordData CUDASpecialDeclRefs;

diff  --git a/clang/test/SemaCXX/PR41441.cpp b/clang/test/SemaCXX/PR41441.cpp
deleted file mode 100644
index 3f60b6e209207a..00
--- a/clang/test/SemaCXX/PR41441.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm 
-o - %s | FileCheck %s
-
-namespace std {
-  using size_t = decltype(sizeof(int));
-};
-void* operator new[](std::size_t, void*) noexcept;
-
-// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
-// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 
false)
-template 
-void f()
-{
-typedef TYPE TArray[8];
-
-TArray x;
-new(&x) TArray();
-}
-
-template 
-void f1() {
-  int (*x)[1] = new int[1][1];
-}
-template void f1();
-void f2() {
-  int (*x)[1] = new int[1][1];
-}
-
-int main()
-{
-f();
-f();
-}



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


[clang] [clang-tools-extra] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base clas

2024-04-25 Thread Pranav Kant via cfe-commits

pranavk wrote:

This makes clang crash in some cases. Here's a sample: 
https://godbolt.org/z/4sbvna4WY



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


[clang] [clang-tools-extra] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base clas

2024-04-25 Thread Pranav Kant via cfe-commits

pranavk wrote:

Yes, I also think that this should be reverted. This commit seems to 
erroneously fail on cases like this:

https://github.com/tink-crypto/tink-cc/blob/4501627fe9ee312ad5d413600f050827b5f725ed/tink/util/secret_proto.h#L62

Note that ParseFromArray is being on an instance of T. So code is correct but 
this commit breaks such use cases.

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


[clang] 45fc0e6 - Revert "[Clang][Sema] Fix warnings after #84050 (#90104)"

2024-04-25 Thread Pranav Kant via cfe-commits

Author: Pranav Kant
Date: 2024-04-26T00:17:28Z
New Revision: 45fc0e6b38b62a61b0ddcda2e7fe9b4fee7e3e58

URL: 
https://github.com/llvm/llvm-project/commit/45fc0e6b38b62a61b0ddcda2e7fe9b4fee7e3e58
DIFF: 
https://github.com/llvm/llvm-project/commit/45fc0e6b38b62a61b0ddcda2e7fe9b4fee7e3e58.diff

LOG: Revert "[Clang][Sema] Fix warnings after #84050 (#90104)"

This reverts commit 6dd2617c80d5133b92fdff679364f2d8fcd93b47.

Added: 


Modified: 
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 14dde1bff8fbc6..0eeb7b1faa0a22 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1793,6 +1793,7 @@ ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr 
*Base,
   DecomposeUnqualifiedId(Id, TemplateArgsBuffer,
  NameInfo, TemplateArgs);
 
+  DeclarationName Name = NameInfo.getName();
   bool IsArrow = (OpKind == tok::arrow);
 
   if (getLangOpts().HLSL && IsArrow)

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 2f6ad49fc08b61..a537eccc2ebaf0 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -2791,7 +2791,7 @@ bool Sema::LookupParsedName(LookupResult &R, Scope *S, 
CXXScopeSpec *SS,
   return LookupInSuper(R, NNS->getAsRecordDecl());
 // This nested-name-specifier occurs after another nested-name-specifier,
 // so long into the context associated with the prior 
nested-name-specifier.
-if ((DC = computeDeclContext(*SS, EnteringContext))) {
+if (DC = computeDeclContext(*SS, EnteringContext)) {
   // The declaration context must be complete.
   if (!DC->isDependentContext() && RequireCompleteDeclContext(*SS, DC))
 return false;



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


[clang] 0c6e1ca - Revert "[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classe

2024-04-25 Thread Pranav Kant via cfe-commits

Author: Pranav Kant
Date: 2024-04-26T00:18:08Z
New Revision: 0c6e1ca1c704a3a0fb53ae54f7e3723736f477c7

URL: 
https://github.com/llvm/llvm-project/commit/0c6e1ca1c704a3a0fb53ae54f7e3723736f477c7
DIFF: 
https://github.com/llvm/llvm-project/commit/0c6e1ca1c704a3a0fb53ae54f7e3723736f477c7.diff

LOG: Revert "[Clang][Sema] Diagnose class member access expressions naming 
non-existent members of the current instantiation prior to instantiation in the 
absence of dependent base classes (#84050)"

This reverts commit a8fd0d029dca7d17eee72d0445223c2fe1ee7758.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Lookup.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Expr.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/HLSL/this-reference-template.hlsl
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/temp/temp.res/temp.local/p3.cpp
clang/test/CodeGenCXX/mangle.cpp
clang/test/Index/annotate-nested-name-specifier.cpp
clang/test/SemaCXX/member-expr.cpp
clang/test/SemaTemplate/instantiate-function-1.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 
clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp



diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 94437857cecca6..799a549ff0816e 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -854,7 +854,7 @@ TEST_F(TargetDeclTest, DependentExprs) {
   }
 };
   )cpp";
-  EXPECT_DECLS("MemberExpr", "void foo()");
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void foo()");
 
   // Similar to above but base expression involves a function call.
   Code = R"cpp(
@@ -872,7 +872,7 @@ TEST_F(TargetDeclTest, DependentExprs) {
   }
 };
   )cpp";
-  EXPECT_DECLS("MemberExpr", "void foo()");
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void foo()");
 
   // Similar to above but uses a function pointer.
   Code = R"cpp(
@@ -891,7 +891,7 @@ TEST_F(TargetDeclTest, DependentExprs) {
   }
 };
   )cpp";
-  EXPECT_DECLS("MemberExpr", "void foo()");
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void foo()");
 
   // Base expression involves a member access into this.
   Code = R"cpp(
@@ -962,7 +962,7 @@ TEST_F(TargetDeclTest, DependentExprs) {
   void Foo() { this->[[find]](); }
 };
   )cpp";
-  EXPECT_DECLS("MemberExpr", "void find()");
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void find()");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 30b9b1902aa9c7..4156921d83edf8 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -621,7 +621,7 @@ sizeof...($TemplateParameter[[Elements]]);
   struct $Class_def[[Foo]] {
 int $Field_decl[[Waldo]];
 void $Method_def[[bar]]() {
-  $Class[[Foo]]().$Field[[Waldo]];
+  $Class[[Foo]]().$Field_dependentName[[Waldo]];
 }
 template $Bracket[[<]]typename $TemplateParameter_def[[U]]$Bracket[[>]]
 void $Method_def[[bar1]]() {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
index ae61b17ca14d20..574efe7bd91478 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
@@ -309,8 +309,6 @@ struct HeapArray {  
// Ok, since destruc
 
   HeapArray(HeapArray &&other) : _data(other._data), size(other.size) { // Ok
 other._data = nullptr;  // Ok
-// CHECK-NOTES: [[@LINE-1]]:5: warning: expected assignment source to be 
of type 'gsl::owner<>'; got 'std::nullptr_t'
-// FIXME: This warning is emitted 

[clang] [clang-tools-extra] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base clas

2024-04-25 Thread Pranav Kant via cfe-commits

pranavk wrote:

Sorry, I just pushed the reverts. I reverted the commits for now. Feel free to 
re-land with fixes.

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


[clang] [libcxx] [llvm] Reapply "[Clang] Implement resolution for CWG1835 (#92957)" (PR #98547)

2024-07-12 Thread Pranav Kant via cfe-commits

pranavk wrote:

Could we perhaps put this behind a flag to help with the transition?

Some cases can already be silenced with -Wno-missing-dependent-template-keyword 
but cases like above in absl are hard errors and there are no workarounds. 

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


[clang] [clang] Add option to opt out of the missing_dependent_template_keyword diagnostic (PR #98613)

2024-07-12 Thread Pranav Kant via cfe-commits

pranavk wrote:

This doesn't seem to handle all the cases? See 
https://github.com/abseil/abseil-cpp/pull/1711 for absl build failures that are 
not silenced by using this option.

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


[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-09-11 Thread Pranav Kant via cfe-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Kyungwoo Lee 
,Dmitry
 Polukhin ,Dmitry Polukhin
 
Message-ID:
In-Reply-To: 


pranavk wrote:

I am seeing internal crashes due to this as well. I am reverting this as it's 
causing issues in chromium open-source project as well as @aeubanks mentioned 
above. Feel free to reland. 

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


[clang] Revert "[RFC][C++20][Modules] Fix crash when function and lambda insi… (PR #108311)

2024-09-11 Thread Pranav Kant via cfe-commits

https://github.com/pranavk created 
https://github.com/llvm/llvm-project/pull/108311

…de loaded from different modules (#104512)"

This reverts commit d778689fdc812033e7142ed87e4ee13c4997b3f9.

>From 2bce8ffa0ede2e21c590768f0b533c7e793b Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Thu, 12 Sep 2024 00:18:28 +
Subject: [PATCH] Revert "[RFC][C++20][Modules] Fix crash when function and
 lambda inside loaded from different modules (#104512)"

This reverts commit d778689fdc812033e7142ed87e4ee13c4997b3f9.
---
 clang/include/clang/Serialization/ASTReader.h |  9 ---
 clang/lib/Serialization/ASTReader.cpp |  8 +-
 clang/lib/Serialization/ASTReaderDecl.cpp | 10 ---
 clang/lib/Serialization/ASTWriterDecl.cpp | 42 --
 ...rash-instantiated-in-scope-cxx-modules.cpp | 76 ---
 ...ash-instantiated-in-scope-cxx-modules2.cpp | 30 
 6 files changed, 1 insertion(+), 174 deletions(-)
 delete mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
 delete mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules2.cpp

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 7331bcf249266d..898f4392465fdf 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1188,15 +1188,6 @@ class ASTReader
   /// once recursing loading has been completed.
   llvm::SmallVector PendingOdrMergeChecks;
 
-  /// Lambdas that need to be loaded right after the function they belong to.
-  /// It is required to have canonical declaration for lambda class from the
-  /// same module as enclosing function. This is required to correctly resolve
-  /// captured variables in the lambda. Without this, due to lazy
-  /// deserialization canonical declarations for the function and lambdas can
-  /// be from different modules and DeclRefExprs may refer to the AST nodes
-  /// that don't exist in the function.
-  SmallVector PendingLambdas;
-
   using DataPointers =
   std::pair;
   using ObjCInterfaceDataPointers =
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0ee53e43dff39c..e5a1e20a265616 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9782,8 +9782,7 @@ void ASTReader::finishPendingActions() {
   !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
   !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
   !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty() ||
-  !PendingLambdas.empty()) {
+  !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -9928,11 +9927,6 @@ void ASTReader::finishPendingActions() {
   }
   PendingObjCExtensionIvarRedeclarations.pop_back();
 }
-
-// Load any pendiong lambdas.
-for (auto ID : PendingLambdas)
-  GetDecl(ID);
-PendingLambdas.clear();
   }
 
   // At this point, all update records for loaded decls are in place, so any
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 20e577404d997d..9272e23c7da3fc 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1155,16 +1155,6 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
   for (unsigned I = 0; I != NumParams; ++I)
 Params.push_back(readDeclAs());
   FD->setParams(Reader.getContext(), Params);
-
-  // For the first decl add all lambdas inside for loading them later,
-  // otherwise skip them.
-  unsigned NumLambdas = Record.readInt();
-  if (FD->isFirstDecl()) {
-for (unsigned I = 0; I != NumLambdas; ++I)
-  Reader.PendingLambdas.push_back(Record.readDeclID());
-  } else {
-Record.skipInts(NumLambdas);
-  }
 }
 
 void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 732a6e21f340d6..555f6325da646b 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -18,7 +18,6 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/OpenMPClause.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
-#include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTRecordWriter.h"
@@ -626,33 +625,6 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) 
{
: QualType());
 }
 
-static llvm::SmallVector collectLambdas(FunctionDecl *D) {
-  struct LambdaCollector : public ConstStmtVisitor {
-llvm::SmallVectorImpl &Lambdas;
-
-LambdaCollector(llvm::SmallVectorI

[clang] Revert "[RFC][C++20][Modules] Fix crash when function and lambda insi… (PR #108311)

2024-09-11 Thread Pranav Kant via cfe-commits

pranavk wrote:

Breaks multiple of our internal workloads and chromium open-source project 
(https://issues.chromium.org/issues/366045258)

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


[clang] Revert "[RFC][C++20][Modules] Fix crash when function and lambda insi… (PR #108311)

2024-09-11 Thread Pranav Kant via cfe-commits

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


[clang] [PAC] Re-sign a pointer to a noexcept member function when it is converted to a pointer to a member function without noexcept (PR #109056)

2024-10-09 Thread Pranav Kant via cfe-commits


@@ -924,17 +924,20 @@ 
ItaniumCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
   if (isa(src))
 return EmitMemberPointerConversion(E, cast(src));
 
+  QualType DstType = E->getType(), SrcType = E->getSubExpr()->getType();

pranavk wrote:

`SrcType` is unused in non-assert builds.

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


[clang] [llvm] Revert "[X86][AMX] Support AMX-AVX512" (PR #115570)

2024-11-08 Thread Pranav Kant via cfe-commits

https://github.com/pranavk approved this pull request.


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


[clang] [llvm] [X86][AMX] Support AMX-AVX512 (PR #114070)

2024-11-08 Thread Pranav Kant via cfe-commits

pranavk wrote:

This is causing similar errors for us as well.

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


[clang] [X86] Return illegal vectors in memory (PR #121944)

2025-01-07 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/121944

>From 2347ae937659988e54bc6b9f47b6edb0fdaa8c13 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Tue, 7 Jan 2025 14:48:00 +
Subject: [PATCH] [X86] Return illegal vectors in memory

When vector size doesn't fit in native machine vector size, we should
return vector via a hidden reference.
---
 clang/include/clang/Basic/LangOptions.h |  2 ++
 clang/lib/CodeGen/Targets/X86.cpp   | 38 +++--
 clang/test/CodeGen/X86/x86-illegal-vector.c | 22 
 clang/test/CodeGen/X86/x86-vec-i128.c   | 38 +++--
 4 files changed, 79 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/CodeGen/X86/x86-illegal-vector.c

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..7dd8251c9da5c2 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,8 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return illegal vectors (size greater than native
+/// vector size) to be returned in illegal registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..a40dbf9160ba6e 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1298,8 +1298,12 @@ class X86_64ABIInfo : public ABIInfo {
unsigned &NeededSSE,
unsigned &MaxVectorWidth) const;
 
+  // Checks whether vector types for function arguments are illegal
   bool IsIllegalVectorType(QualType Ty) const;
 
+  // Checks whether vector types for returns are illegal
+  bool IsIllegalReturnVectorType(QualType Ty) const;
+
   /// The 0.98 ABI revision clarified a lot of ambiguities,
   /// unfortunately in ways that were not always consistent with
   /// certain previous compilers.  In particular, platforms which
@@ -1334,6 +1338,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnIllegalVectorsInMem() const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2156,9 +2170,12 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 }
 
 ABIArgInfo X86_64ABIInfo::getIndirectReturnResult(QualType Ty) const {
+  const bool returnIllegalVectorsIndirectly =
+  (returnIllegalVectorsInMem() && IsIllegalReturnVectorType(Ty));
+
   // If this is a scalar LLVM value then assume LLVM will pass it in the right
   // place naturally.
-  if (!isAggregateTypeForABI(Ty)) {
+  if (!isAggregateTypeForABI(Ty) && !returnIllegalVectorsIndirectly) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = Ty->getAs())
   Ty = EnumTy->getDecl()->getIntegerType();
@@ -2173,12 +2190,23 @@ ABIArgInfo 
X86_64ABIInfo::getIndirectReturnResult(QualType Ty) const {
   return getNaturalAlignIndirect(Ty);
 }
 
-bool X86_64ABIInfo::IsIllegalVectorType(QualType Ty) const {
+static bool IsIllegalVector(QualType Ty, uint64_t Size,
+X86AVXABILevel AVXLevel) {
   if (const VectorType *VecTy = Ty->getAs()) {
-uint64_t Size = getContext().getTypeSize(VecTy);
 unsigned LargestVector = getNativeVectorSizeForAVXABI(AVXLevel);
 if (Size <= 64 || Size > LargestVector)
   return true;
+  }
+
+  return false;
+}
+
+bool X86_64ABIInfo::IsIllegalVectorType(QualType Ty) const {
+  if (IsIllegalVector(Ty, getContext().getTypeSize(Ty), AVXLevel))
+return true;
+
+  // Maintain backward compatibility
+  if (const VectorType *VecTy = Ty->getAs()) {
 QualType EltTy = VecTy->getElementType();
 if (passInt128VectorsInMem() &&
 (EltTy->isSpecificBuiltinType(BuiltinType::Int128) ||
@@ -2189,6 +2217,10 @@ bool X86_64ABIInfo::IsIllegalVectorType(QualType Ty) 
const {
   return false;
 }
 
+bool X86_64ABIInfo::IsIllegalReturnVectorType(QualType Ty) const {
+  return IsIllegalVector(Ty, getContext().getTypeSize(Ty), AVXLevel);
+}
+
 ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty,
 unsigned freeIntRegs) const {
   // If this is a scalar LLVM value then assume LLVM will pass it in the right
diff --git a/clang/test/CodeGen/X86/x86-illegal-vector.c 
b/clang/tes

[clang] [X86] Return illegal vectors in memory (PR #121944)

2025-01-07 Thread Pranav Kant via cfe-commits

pranavk wrote:

Took a look at failing tests -- they need to be modified to conform to the new 
ABI. Should be easy to do.

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2024-12-30 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 4b6839317bcd2a014011cb91b5a3e58d4a47b0b1 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH 1/2] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h |  1 +
 clang/lib/CodeGen/Targets/X86.cpp   | 18 ++
 2 files changed, 19 insertions(+)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..0dd644eba559b9 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..70d812057d0b01 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,20 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem(unsigned Size, unsigned TypeSize,
+  unsigned NativeSize) const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+// The only case a 256(or 512)-bit wide vector could be used to return
+// is when CXX record contains a single 256(or 512)-bit element.
+if (Size > 128 && (Size != TypeSize || Size > NativeSize))
+  return true;
+return false;
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2081,10 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem(
+Size, getContext().getTypeSize(I.getType()),
+getNativeVectorSizeForAVXABI(AVXLevel)))
+  Lo = Memory;
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;

>From 6e62d019db05601bb6d4046785b9a219f92cebe8 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 30 Dec 2024 14:57:31 +
Subject: [PATCH 2/2] add a regression test

---
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..0d5f070b7754fb
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -c -S -emit-llvm -O2 -march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2024-12-30 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 4b6839317bcd2a014011cb91b5a3e58d4a47b0b1 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH 1/3] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h |  1 +
 clang/lib/CodeGen/Targets/X86.cpp   | 18 ++
 2 files changed, 19 insertions(+)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..0dd644eba559b9 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..70d812057d0b01 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,20 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem(unsigned Size, unsigned TypeSize,
+  unsigned NativeSize) const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+// The only case a 256(or 512)-bit wide vector could be used to return
+// is when CXX record contains a single 256(or 512)-bit element.
+if (Size > 128 && (Size != TypeSize || Size > NativeSize))
+  return true;
+return false;
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2081,10 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem(
+Size, getContext().getTypeSize(I.getType()),
+getNativeVectorSizeForAVXABI(AVXLevel)))
+  Lo = Memory;
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;

>From 6e62d019db05601bb6d4046785b9a219f92cebe8 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 30 Dec 2024 14:57:31 +
Subject: [PATCH 2/3] add a regression test

---
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..0d5f070b7754fb
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -c -S -emit-llvm -O2 -march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

>From 1f01309c237c8daf15be4ac1708e22e841935662 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 30 Dec 2024 14:59:04 +
Subject: [PATCH 3/3] comment

---
 clang/include/clang/Basic/LangOptions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 0dd644eba559b9..6df2fa414f4df8 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,7 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
-///   - Incorrectly return C++ records in AVX registers.
+///   - Incorrectly return C++ records in AVX registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

_

[clang] [clang] Return larger CXX records in memory (PR #120670)

2024-12-30 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 4b6839317bcd2a014011cb91b5a3e58d4a47b0b1 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH 1/4] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h |  1 +
 clang/lib/CodeGen/Targets/X86.cpp   | 18 ++
 2 files changed, 19 insertions(+)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..0dd644eba559b9 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..70d812057d0b01 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,20 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem(unsigned Size, unsigned TypeSize,
+  unsigned NativeSize) const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+// The only case a 256(or 512)-bit wide vector could be used to return
+// is when CXX record contains a single 256(or 512)-bit element.
+if (Size > 128 && (Size != TypeSize || Size > NativeSize))
+  return true;
+return false;
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2081,10 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem(
+Size, getContext().getTypeSize(I.getType()),
+getNativeVectorSizeForAVXABI(AVXLevel)))
+  Lo = Memory;
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;

>From 6e62d019db05601bb6d4046785b9a219f92cebe8 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 30 Dec 2024 14:57:31 +
Subject: [PATCH 2/4] add a regression test

---
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..0d5f070b7754fb
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -c -S -emit-llvm -O2 -march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

>From 1f01309c237c8daf15be4ac1708e22e841935662 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 30 Dec 2024 14:59:04 +
Subject: [PATCH 3/4] comment

---
 clang/include/clang/Basic/LangOptions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 0dd644eba559b9..6df2fa414f4df8 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,7 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
-///   - Incorrectly return C++ records in AVX registers.
+///   - Incorrectly return C++ records in AVX registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

>From 0bcdcc4

[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-02-03 Thread Pranav Kant via cfe-commits


@@ -1334,6 +1334,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem() const {
+// Clang <= 20.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver20)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();

pranavk wrote:

Done. 

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-02-03 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 2c049c1a377e0b9142d4dcb8682ea27837750810 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH 1/2] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/LangOptions.h   |  5 +
 clang/lib/CodeGen/Targets/X86.cpp | 17 +
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 4 files changed, 47 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fafe2807bd3883..d5469d96d615c41 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,8 @@ C++ Specific Potentially Breaking Changes
 ABI Changes in This Version
 ---
 
+- Return larger CXX records in memory instead of using AVX registers. Code 
compiled with older clang will be incompatible with newer version of the clang 
unless -fclang-abi-compat=20 is provided. (#GH120670)
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 114a5d34a008bd7..d8311dbdfdb43c6 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -248,6 +248,11 @@ class LangOptionsBase {
 ///   function templates.
 Ver19,
 
+/// Attempt to be ABI-compatible with code generated by Clang 20.0.x.
+/// This causes clang to:
+///   - Incorrectly return C++ records in AVX registers on x86_64.
+Ver20,
+
 /// Conform to the underlying platform's C and C++ ABIs as closely
 /// as we can.
 Latest
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 5ee5179dd0f3e8f..3224362169bc418 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem() const {
+// Clang <= 20.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver20)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2077,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem() &&
+(Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
+Size > getNativeVectorSizeForAVXABI(AVXLevel {
+  // The only case a 256(or 512)-bit wide vector could be used to 
return
+  // is when CXX record contains a single 256(or 512)-bit element.
+  Lo = Memory;
+}
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;
diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 000..d8863ca4e45f9e5
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

>From 4fe3dda872bb6dca0599b979c1561fc92aac32f8 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 3 Feb 2025 22:34:39 +
Subject: [PATCH 2/2] ABI change for all targets

---
 clang/lib/CodeGen/Targets/X86.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 3224362169bc418..7e470abe078f595 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1340,8 +1

[clang] Fix broken clang codegen test (avx-cxx-record.cpp) (PR #125787)

2025-02-04 Thread Pranav Kant via cfe-commits

https://github.com/pranavk created 
https://github.com/llvm/llvm-project/pull/125787

Fixes e8a486ea97895a18e1bba75431d37d9758886084

>From eaa2581b6b81aa616296f09b859024b3d22fe3c8 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Tue, 4 Feb 2025 23:35:44 +
Subject: [PATCH] Fix broken clang codegen test

Fixes e8a486ea97895a18e1bba75431d37d9758886084
---
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
index d8863ca4e45f9e..bcd9c361fda901 100644
--- a/clang/test/CodeGen/X86/avx-cxx-record.cpp
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -O2 
-target-cpu x86-64-v3 -o - | FileCheck %s
 
 using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
 
@@ -11,7 +11,7 @@ struct XMM2 : XMM1<0>, XMM1<1> {
 };
 
 // CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
-// CHECK-NEXT: entry:
+// CHECK: entry:
 // CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
 // CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
 // CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-02-04 Thread Pranav Kant via cfe-commits

pranavk wrote:

I fixed this in #125787

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


[clang] Fix broken clang codegen test (avx-cxx-record.cpp) (PR #125787)

2025-02-04 Thread Pranav Kant via cfe-commits

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-02-04 Thread Pranav Kant via cfe-commits

pranavk wrote:

Checking ...

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-02-04 Thread Pranav Kant via cfe-commits

pranavk wrote:

Thank you

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2024-12-19 Thread Pranav Kant via cfe-commits

https://github.com/pranavk created 
https://github.com/llvm/llvm-project/pull/120670

We incorrectly return CXX records in AVX registers when they should be returned 
in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ

>From 573cb2685f5ea060eff3d374f58ff04426c1f3d4 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h |  1 +
 clang/lib/CodeGen/Targets/X86.cpp   | 18 ++
 2 files changed, 19 insertions(+)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..0dd644eba559b9 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..70d812057d0b01 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,20 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem(unsigned Size, unsigned TypeSize,
+  unsigned NativeSize) const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+// The only case a 256(or 512)-bit wide vector could be used to return
+// is when CXX record contains a single 256(or 512)-bit element.
+if (Size > 128 && (Size != TypeSize || Size > NativeSize))
+  return true;
+return false;
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2081,10 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem(
+Size, getContext().getTypeSize(I.getType()),
+getNativeVectorSizeForAVXABI(AVXLevel)))
+  Lo = Memory;
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-24 Thread Pranav Kant via cfe-commits

pranavk wrote:

> Shouldn't this have some sort of Release not maybe under the X86 section?

you mean mention this in release section? I plan to add a note in 
clang/docs/ReleaseNotes.rst. Next week.

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


[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)

2025-01-28 Thread Pranav Kant via cfe-commits


@@ -2949,6 +2950,13 @@ static void handleSectionAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   }
 }
 
+static bool isValidCodeModelAttr(Sema &S, StringRef Str) {
+  bool IsX8664Target =
+  S.Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86_64;
+  bool IsX8664Spelling = Str == "small" || Str == "large";
+  return IsX8664Target == IsX8664Spelling;
+}

pranavk wrote:

This is correct but slightly harder to read, I feel. I think just simple 
if/else wrapping which attributes are valid would be easier to read.


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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-28 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 3f7f567dde22f7501822b83c33eeff8dd596 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH 1/2] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h   |  1 +
 clang/lib/CodeGen/Targets/X86.cpp | 17 +
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 3 files changed, 41 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 114a5d34a008bd..31afe808fa1411 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -246,6 +246,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 5ee5179dd0f3e8..ebd4291cfb49e5 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem() const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2077,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem() &&
+(Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
+Size > getNativeVectorSizeForAVXABI(AVXLevel {
+  // The only case a 256(or 512)-bit wide vector could be used to 
return
+  // is when CXX record contains a single 256(or 512)-bit element.
+  Lo = Memory;
+}
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;
diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..d8863ca4e45f9e
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

>From 403bcdd97211e200dba39d0ab51909d1e4b59d96 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Tue, 28 Jan 2025 22:48:01 +
Subject: [PATCH 2/2] Add entry to release notes

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d8a94703bd9c57..f44175f294204b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -253,6 +253,7 @@ ABI Changes in This Version
 - Fixed Microsoft name mangling of placeholder, auto and decltype(auto), 
return types for MSVC 1920+. This change resolves incompatibilities with code 
compiled by MSVC 1920+ but will introduce incompatibilities with code compiled 
by earlier versions of Clang unless such code is built with the compiler option 
-fms-compatibility-version=19.14 to imitate the MSVC 1914 mangling behavior.
 - Fixed the Itanium mangling of the construction vtable name. This change will 
introduce incompatibilities with code compiled by Clang 19 and earlier 
versions, unless the -fclang-abi-compat=19 option is used. (#GH108015)
 - Mangle member-like friend function templates as members of

[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-28 Thread Pranav Kant via cfe-commits

pranavk wrote:

> Shouldn't this have some sort of Release not maybe under the X86 section?

there's no x86 section in the release notes. So I added it in ABI section. 

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-29 Thread Pranav Kant via cfe-commits

pranavk wrote:

We don't need this urgently. I am fine just keeping it like this.

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-29 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 2c049c1a377e0b9142d4dcb8682ea27837750810 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/LangOptions.h   |  5 +
 clang/lib/CodeGen/Targets/X86.cpp | 17 +
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 4 files changed, 47 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fafe2807bd388..d5469d96d615c4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,8 @@ C++ Specific Potentially Breaking Changes
 ABI Changes in This Version
 ---
 
+- Return larger CXX records in memory instead of using AVX registers. Code 
compiled with older clang will be incompatible with newer version of the clang 
unless -fclang-abi-compat=20 is provided. (#GH120670)
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 114a5d34a008bd..d8311dbdfdb43c 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -248,6 +248,11 @@ class LangOptionsBase {
 ///   function templates.
 Ver19,
 
+/// Attempt to be ABI-compatible with code generated by Clang 20.0.x.
+/// This causes clang to:
+///   - Incorrectly return C++ records in AVX registers on x86_64.
+Ver20,
+
 /// Conform to the underlying platform's C and C++ ABIs as closely
 /// as we can.
 Latest
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 5ee5179dd0f3e8..3224362169bc41 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem() const {
+// Clang <= 20.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver20)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2077,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem() &&
+(Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
+Size > getNativeVectorSizeForAVXABI(AVXLevel {
+  // The only case a 256(or 512)-bit wide vector could be used to 
return
+  // is when CXX record contains a single 256(or 512)-bit element.
+  Lo = Memory;
+}
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;
diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..d8863ca4e45f9e
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-29 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 2fc0a12eaef09e26143a78c2071009394e5a4f3b Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH 1/2] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h   |  1 +
 clang/lib/CodeGen/Targets/X86.cpp | 17 +
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 3 files changed, 41 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 114a5d34a008bd..31afe808fa1411 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -246,6 +246,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 5ee5179dd0f3e8..ebd4291cfb49e5 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem() const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2077,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem() &&
+(Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
+Size > getNativeVectorSizeForAVXABI(AVXLevel {
+  // The only case a 256(or 512)-bit wide vector could be used to 
return
+  // is when CXX record contains a single 256(or 512)-bit element.
+  Lo = Memory;
+}
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;
diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..d8863ca4e45f9e
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

>From b729ea269664b02d4640131375584d3d10bcd7df Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Tue, 28 Jan 2025 22:48:01 +
Subject: [PATCH 2/2] Add entry to release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fafe2807bd388..96455ebc37271a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,8 @@ C++ Specific Potentially Breaking Changes
 ABI Changes in This Version
 ---
 
+- Return larger CXX records in memory instead of using AVX registers. Code 
compiled with older clang will be incompatible with newer version of the clang 
unless -fclang-abi-compat=19 is provided. (#GH120670)
+
 AST Dumping Potentially Breaking Changes
 
 

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-29 Thread Pranav Kant via cfe-commits

pranavk wrote:

Oops. Too bad. I didn't realize we branched off release/20.x 

Anyhow, I made necessary tweaks to now make it a LLVM 21 feature.

> There is a X86 Support section

It feels more appropriate to put this in "ABI changes section" than "X86 
support" since it's not a "support". But I am happy to move that over if that's 
the precedence for these kind of changes. Let me know. 

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-02 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 852907ee0d0806f2c48c07a7c0d5746ad0a48367 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h   |  1 +
 clang/lib/CodeGen/Targets/X86.cpp | 17 +
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 3 files changed, 41 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..6df2fa414f4df8 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..147fc7f7389faa 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem() const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2077,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem() &&
+(Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
+Size > getNativeVectorSizeForAVXABI(AVXLevel {
+  // The only case a 256(or 512)-bit wide vector could be used to 
return
+  // is when CXX record contains a single 256(or 512)-bit element.
+  Lo = Memory;
+}
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;
diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..d8863ca4e45f9e
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-02 Thread Pranav Kant via cfe-commits


@@ -2067,6 +2081,10 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem(
+Size, getContext().getTypeSize(I.getType()),
+getNativeVectorSizeForAVXABI(AVXLevel)))
+  Lo = Memory;

pranavk wrote:

This seemed like the most appropriate location for such a check as I only want 
to do it for CXXRecords (`if dyn_cast` ...) which is already 
being checked here.

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-02 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 4b6839317bcd2a014011cb91b5a3e58d4a47b0b1 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH 1/5] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h |  1 +
 clang/lib/CodeGen/Targets/X86.cpp   | 18 ++
 2 files changed, 19 insertions(+)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..0dd644eba559b9 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..70d812057d0b01 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,20 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem(unsigned Size, unsigned TypeSize,
+  unsigned NativeSize) const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+// The only case a 256(or 512)-bit wide vector could be used to return
+// is when CXX record contains a single 256(or 512)-bit element.
+if (Size > 128 && (Size != TypeSize || Size > NativeSize))
+  return true;
+return false;
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2081,10 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem(
+Size, getContext().getTypeSize(I.getType()),
+getNativeVectorSizeForAVXABI(AVXLevel)))
+  Lo = Memory;
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;

>From 6e62d019db05601bb6d4046785b9a219f92cebe8 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 30 Dec 2024 14:57:31 +
Subject: [PATCH 2/5] add a regression test

---
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..0d5f070b7754fb
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -c -S -emit-llvm -O2 -march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

>From 1f01309c237c8daf15be4ac1708e22e841935662 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Mon, 30 Dec 2024 14:59:04 +
Subject: [PATCH 3/5] comment

---
 clang/include/clang/Basic/LangOptions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 0dd644eba559b9..6df2fa414f4df8 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,7 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
-///   - Incorrectly return C++ records in AVX registers.
+///   - Incorrectly return C++ records in AVX registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

>From 0bcdcc4

[clang] [clang] Track final substitution for Subst* AST nodes (PR #132748)

2025-04-09 Thread Pranav Kant via cfe-commits

pranavk wrote:

This causes another mangling issue similar to 
[this](https://github.com/llvm/llvm-project/pull/133610#issuecomment-2787332042).

Here's the repro:

```
namespace {
template  struct enable_if {
  typedef int type;
};
template  using enable_if_t = enable_if<_Bp>::type;
template  struct integral_constant {
  static const int value = __v;
};
template  using _BoolConstant = integral_constant<_Val>;
template 
using _IsNotSame = _BoolConstant<__is_same(_Tp, _Up)>;
template  using __expand_to_true = integral_constant;
template  __expand_to_true<> __and_helper(int);
template  using _And = decltype(__and_helper<_Pred...>(0));
template  struct _OrImpl {
  template  using _Result = _OrImpl<_First::value>;
};
template 
using _Or =
_OrImpl::template _Result,
_Args...>;
struct optional {
  template ,
_Or<_IsNotSame<_Up, int>, int>>::value,
   int> = 0>
  void operator=(_Up);
};
} // namespace
optional f_opt;
void f() { f_opt = int{}; }
```

`clang -c -std=gnu++20 -x c++ /tmp/reduced.i`
`llvm-readelf -s -W reduced.o | grep -P 'optional.*aS.*srNS[0-9]_I'`

The subexpression srNS5_I...E violates the grammar at 
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#expressions. The srN must be 
followed by an , which is allowed to be a  such 
as S5_, but not a substitution followed by I...E template arguments. LLVM, GNU, 
and Abseil demanglers correctly reject this name.



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


[clang] [clang] Track final substitution for Subst* AST nodes (PR #132748)

2025-04-09 Thread Pranav Kant via cfe-commits

pranavk wrote:

With this commit, I get:
```
llvm-readelf -s -W reduced.o | grep -P 'optional.*aS.*srNS[0-9]_I'
 6:  0 NOTYPE  GLOBAL DEFAULT   UND 
_ZN12_GLOBAL__N_18optionalaSIiTnNS_9enable_ifIXsr4_AndINS_17integral_constantIXu9__is_sameT_S0_NS_7_OrImplIXsrNS3_IXu9__is_sameS4_i5valueE5valueEE4typeELi0EEEvS4_
 ```
 
Before this, the same symbol was:
```
 6:  0 NOTYPE  GLOBAL DEFAULT   UND 
_ZN12_GLOBAL__N_18optionalaSIiTnNS_9enable_ifIXsr4_AndINS_17integral_constantIXu9__is_sameT_S0_NS_7_OrImplIXsr10_IsNotSameIS4_iEE5valueE5valueEE4typeELi0EEEvS4_
```

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


[clang] Move CodeGen cuda.h to Inputs from include (PR #134706)

2025-04-07 Thread Pranav Kant via cfe-commits

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


[clang] [clang] Track final substitution for Subst* AST nodes (PR #132748)

2025-04-10 Thread Pranav Kant via cfe-commits

pranavk wrote:

> @pranavk this test case is fixed by the same fix as for the first mangling 
> issue: https://github.com/llvm/llvm-project/pull/135111

I could still repro this issue after #135111 

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


[clang] [clang] Make tests write to /dev/null if output is not needed (PR #135242)

2025-04-10 Thread Pranav Kant via cfe-commits

https://github.com/pranavk created 
https://github.com/llvm/llvm-project/pull/135242

We execute tests in read only environment which leads to test failure when 
tests try to write to the current directory. Either they should write to a 
temporary directory or not write if output is not needed.

Fallback from #134717

>From df9b0c4966674f17550c515bae22dbbcfe41a95c Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Thu, 10 Apr 2025 19:36:52 +
Subject: [PATCH] [clang] Make tests write to /dev/null if output is not needed

We execute tests in read only environment which leads to test failure
when tests try to write to the current directory. Either they should
write to a temporary directory or not write if output is not needed.
---
 clang/test/Driver/openacc-no-cir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/openacc-no-cir.c 
b/clang/test/Driver/openacc-no-cir.c
index 7b67df2b6b886..891f175a001bb 100644
--- a/clang/test/Driver/openacc-no-cir.c
+++ b/clang/test/Driver/openacc-no-cir.c
@@ -1,6 +1,6 @@
-// RUN: %clang -fopenacc -S %s 2>&1 | FileCheck %s -check-prefix=ERROR
-// RUN: %clang -fclangir -fopenacc -S %s 2>&1 | FileCheck %s --allow-empty 
-check-prefix=NOERROR
-// RUN: %clang -fopenacc -fclangir -S %s 2>&1 | FileCheck %s --allow-empty 
-check-prefix=NOERROR
+// RUN: %clang -fopenacc -S %s -o /dev/null 2>&1 | FileCheck %s 
-check-prefix=ERROR
+// RUN: %clang -fclangir -fopenacc -S %s -o /dev/null 2>&1 | FileCheck %s 
--allow-empty -check-prefix=NOERROR
+// RUN: %clang -fopenacc -fclangir -S %s -o /dev/null 2>&1 | FileCheck %s 
--allow-empty -check-prefix=NOERROR
 
 // ERROR: OpenACC directives will result in no runtime behavior; use -fclangir 
to enable runtime effect
 // NOERROR-NOT: OpenACC directives

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


[clang] [clang] Make tests write to /dev/null if output is not needed (PR #135242)

2025-04-10 Thread Pranav Kant via cfe-commits

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


[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)

2025-02-12 Thread Pranav Kant via cfe-commits


@@ -2964,20 +2963,36 @@ static bool isValidCodeModelAttr(Sema &S, StringRef 
Str) {
 static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   StringRef Str;
   SourceLocation LiteralLoc;
+  auto IsTripleSupported = [](const llvm::Triple Triple) {
+return Triple.getArch() == llvm::Triple::ArchType::x86_64 ||
+   Triple.isLoongArch();
+  };
+
   // Check that it is a string.
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
 return;
 
-  // Ignore the attribute for GPU device compiles since it only applies to host
-  // globals.
-  if (S.Context.getTargetInfo().getTriple().isNVPTX() ||
-  S.Context.getTargetInfo().getTriple().isAMDGPU() ||
-  S.Context.getTargetInfo().getTriple().isSPIRV())
+  SmallVector Triples = {
+  S.Context.getTargetInfo().getTriple()};
+  if (auto *aux = S.Context.getAuxTargetInfo()) {
+Triples.push_back(aux->getTriple());
+  } else if (S.Context.getTargetInfo().getTriple().isNVPTX() ||
+ S.Context.getTargetInfo().getTriple().isAMDGPU() ||
+ S.Context.getTargetInfo().getTriple().isSPIRV()) {
+// Ignore the attribute for pure GPU device compiles since it only applies
+// to host globals.
+return;
+  }
+
+  auto SupportedTripleIt = llvm::find_if(Triples, IsTripleSupported);
+  if (SupportedTripleIt == Triples.end()) {

pranavk wrote:

this was done this way because we also need the `SupportedTripleIt` later in 
line 2995

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


[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)

2025-02-12 Thread Pranav Kant via cfe-commits


@@ -2950,12 +2950,11 @@ static void handleSectionAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   }
 }
 
-static bool isValidCodeModelAttr(Sema &S, StringRef Str) {
-  if (S.Context.getTargetInfo().getTriple().isLoongArch()) {
+static bool isValidCodeModelAttr(llvm::Triple Triple, StringRef Str) {

pranavk wrote:

Right. This should be fixed.

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


[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)

2025-02-12 Thread Pranav Kant via cfe-commits


@@ -2964,20 +2963,36 @@ static bool isValidCodeModelAttr(Sema &S, StringRef 
Str) {
 static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   StringRef Str;
   SourceLocation LiteralLoc;
+  auto IsTripleSupported = [](const llvm::Triple Triple) {
+return Triple.getArch() == llvm::Triple::ArchType::x86_64 ||
+   Triple.isLoongArch();
+  };
+
   // Check that it is a string.
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
 return;
 
-  // Ignore the attribute for GPU device compiles since it only applies to host
-  // globals.
-  if (S.Context.getTargetInfo().getTriple().isNVPTX() ||
-  S.Context.getTargetInfo().getTriple().isAMDGPU() ||
-  S.Context.getTargetInfo().getTriple().isSPIRV())
+  SmallVector Triples = {
+  S.Context.getTargetInfo().getTriple()};
+  if (auto *aux = S.Context.getAuxTargetInfo()) {
+Triples.push_back(aux->getTriple());
+  } else if (S.Context.getTargetInfo().getTriple().isNVPTX() ||

pranavk wrote:

i agree. 

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