[lld] [libunwind] [compiler-rt] [libcxxabi] [flang] [lldb] [clang] [llvm] [clang-tools-extra] [libc] [libcxx] [mlir] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-19 Thread Shahid Iqbal via cfe-commits


@@ -83,10 +85,29 @@ struct DOTGraphTraitsViewer
   StringRef Name;
 };
 
+static void shortenFileName(std::string , unsigned char len = 250) {
+
+  FN = FN.substr(0, len);
+  if (nameObj.empty())
+nameObj.push_back(FN);
+
+  else {
+for (auto it = nameObj.begin(); it != nameObj.end(); it++) {
+  if (*it == FN) {
+FN = FN.substr(0, --len);

shahidiqbal13 wrote:

@DrTodd13 ,
Yes I do agree with the 3 filenames example but the chances would be highly 
rare that's what y I didn't go for keep searching mechanism

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-11-19 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@sam-mccall ping

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


[clang] [AArch64][SME2] Enable bfm builtins for sme2 (PR #71927)

2023-11-19 Thread Sander de Smalen via cfe-commits


@@ -1992,3 +1986,12 @@ let TargetGuard = "sme2" in {
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;
   def SVADD_SINGLE_X4 : SInst<"svadd[_single_{d}_x4]", "44d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x4", [IsStreaming], []>;
 }
+
+let TargetGuard = "sve2p1|sme2" in {
+// == BFloat16 multiply-subtract ==
+  def SVBFMLSLB : SInst<"svbfmlslb[_{d}]", "dd$$", "f", MergeNone, 
"aarch64_sve_bfmlslb", [IsOverloadNone, IsStreaming], []>;
+  def SVBFMLSLT : SInst<"svbfmlslt[_{d}]", "dd$$", "f", MergeNone, 
"aarch64_sve_bfmlslt", [IsOverloadNone, IsStreaming], []>;
+
+  def SVBFMLSLB_LANE : SInst<"svbfmlslb_lane[_{d}]", "dd$$i", "f", MergeNone, 
"aarch64_sve_bfmlslb_lane", [IsOverloadNone, IsStreaming], [ImmCheck<3, 
ImmCheck0_7>]>;

sdesmalen-arm wrote:

I suspect having `IsStreaming` here this is not going to work, because with 
SVE2p1 the function works in a non-streaming mode. The fact that the test 
passes suggests we're missing a diagnostic when the intrinsic has 
`IsStreaming`, but the caller is not a streaming function.

For the purpose of these intrinsics, we also need to add a new attribute 
instead of `IsStreaming` which adds logic that emits a diagnostic only when the 
function is not in streaming mode or the function is not compiled with +sve2p1.

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


[clang] [PowerPC] Disable float128 on AIX in Clang (PR #67298)

2023-11-19 Thread Qiu Chaofan via cfe-commits

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


[clang] d572c4c - [PowerPC] Disable float128 on AIX in Clang (#67298)

2023-11-19 Thread via cfe-commits

Author: Qiu Chaofan
Date: 2023-11-20T15:20:57+08:00
New Revision: d572c4cdef4b3a2b1f57769233f33a1788f5172e

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

LOG: [PowerPC] Disable float128 on AIX in Clang (#67298)

PowerPC AIX backend does not support float128 at all. Diagnose even when
specifying -mfloat128 to avoid backend crash.

-

Co-authored-by: Kai Luo 

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.cpp
clang/test/Sema/128bitfloat.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 5ce276e1af9ef64..045c273f03c7a0c 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -53,7 +53,7 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector ,
 } else if (Feature == "+htm") {
   HasHTM = true;
 } else if (Feature == "+float128") {
-  HasFloat128 = true;
+  HasFloat128 = !getTriple().isOSAIX();
 } else if (Feature == "+power9-vector") {
   HasP9Vector = true;
 } else if (Feature == "+power10-vector") {

diff  --git a/clang/test/Sema/128bitfloat.cpp b/clang/test/Sema/128bitfloat.cpp
index b98b42496e8db27..bd9f2889c98f6aa 100644
--- a/clang/test/Sema/128bitfloat.cpp
+++ b/clang/test/Sema/128bitfloat.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -std=gnu++11 %s
 // RUN: %clang_cc1 -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple powerpc64-linux -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -target-feature +float128 -verify 
-std=c++11 %s
 // RUN: %clang_cc1 -triple i686-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -verify -std=c++11 %s



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


[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dinar Temirbulatov (dtemirbulatov)


Changes

This change enables PEXT, PSEL builtins for SME2 target.

---

Patch is 25.95 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/72827.diff


3 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+17-13) 
- (modified) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c 
(+196-11) 
- (modified) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c 
(+5) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 40e474d5f0a8f4e..96c5ac366574bf2 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1859,19 +1859,28 @@ def SVBGRP   : SInst<"svbgrp[_{d}]",   "ddd", 
"UcUsUiUl", MergeNone, "aarch64_sv
 def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", MergeNone, 
"aarch64_sve_bgrp_x">;
 }
 
+let TargetGuard = "sve2p1|sme" in {
+def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", 
[IsStreamingCompatible], []>;
+}
+
+let TargetGuard = "sve2p1|sme2" in {
+def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [IsStreamingCompatible], []>;
+
+def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
+def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck0_1>]>;
+}
+
 let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
 def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;
 
-def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;
-def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [], [ImmCheck<1, ImmCheck0_1>]>;
-
-def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [], []>;
-
 def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
 def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
 def SVWHILELE_COUNT  : SInst<"svwhilele_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
@@ -1971,11 +1980,6 @@ let TargetGuard = "sve2p1" in {
 def SVSCLAMP : SInst<"svclamp[_{d}]", "", "csil", MergeNone, 
"aarch64_sve_sclamp", [], []>;
 def SVUCLAMP : SInst<"svclamp[_{d}]", "", "UcUsUiUl", MergeNone, 
"aarch64_sve_uclamp", [], []>;
 
-def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", [], []>;
-def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", [], []>;
-def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", [], []>;
-def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", [], []>;
-
 def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
 
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
index fe15d5a9db81f2f..76603e384b99ca3 100644
--- a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
@@ -1,10 +1,17 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: aarch64-registered-target
-// RUN: %clang_cc1 -triple 

[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-19 Thread Dinar Temirbulatov via cfe-commits

https://github.com/dtemirbulatov created 
https://github.com/llvm/llvm-project/pull/72827

This change enables PEXT, PSEL builtins for SME2 target.

>From 7aa69c9cb936b3883de7922f72ed9417be5a16f5 Mon Sep 17 00:00:00 2001
From: Dinar Temirbulatov 
Date: Mon, 20 Nov 2023 07:04:18 +
Subject: [PATCH] [AArch64][SME2] Add PEXT, PSEL builtins for SME2

This change enables PEXT, PSEL builtins for SME2 target.
---
 clang/include/clang/Basic/arm_sve.td  |  30 +--
 .../acle_sve2p1_pext.c| 207 +-
 .../acle_sve2p1_psel.c|   5 +
 3 files changed, 218 insertions(+), 24 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 40e474d5f0a8f4e..96c5ac366574bf2 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1859,19 +1859,28 @@ def SVBGRP   : SInst<"svbgrp[_{d}]",   "ddd", 
"UcUsUiUl", MergeNone, "aarch64_sv
 def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", MergeNone, 
"aarch64_sve_bgrp_x">;
 }
 
+let TargetGuard = "sve2p1|sme" in {
+def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", 
[IsStreamingCompatible], []>;
+}
+
+let TargetGuard = "sve2p1|sme2" in {
+def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [IsStreamingCompatible], []>;
+
+def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
+def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck0_1>]>;
+}
+
 let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
 def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;
 
-def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;
-def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [], [ImmCheck<1, ImmCheck0_1>]>;
-
-def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [], []>;
-
 def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
 def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
 def SVWHILELE_COUNT  : SInst<"svwhilele_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
@@ -1971,11 +1980,6 @@ let TargetGuard = "sve2p1" in {
 def SVSCLAMP : SInst<"svclamp[_{d}]", "", "csil", MergeNone, 
"aarch64_sve_sclamp", [], []>;
 def SVUCLAMP : SInst<"svclamp[_{d}]", "", "UcUsUiUl", MergeNone, 
"aarch64_sve_uclamp", [], []>;
 
-def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", [], []>;
-def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", [], []>;
-def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", [], []>;
-def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", [], []>;
-
 def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
 
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
index fe15d5a9db81f2f..76603e384b99ca3 100644
--- a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
@@ -1,10 +1,17 @@
 // NOTE: Assertions have been autogenerated by 

[clang] [AMDGPU] Treat printf as builtin for OpenCL (PR #72554)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -406,5 +410,9 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", 
"nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", "fp8-insts")
 
+// OpenCL
+LANGBUILTIN(printf, "icC*4.", "fp:0:", ALL_OCL_LANGUAGES)

ssahasra wrote:

I still don't see why this is necessary. A target-defined language-specific 
builtin is a whole new beast. What is missing in the current parsing of OpenCL 
printf?

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


[llvm] [clang] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -1,12 +1,68 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -cl-std=CL1.2 -triple amdgcn-amd-amdhsa 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL1.2 -triple amdgcn-amd-amdhsa 
-mprintf-kind=buffered -disable-llvm-passes -emit-llvm -o - %s | FileCheck 
--check-prefix=CHECK_BUFFERED %s
+// RUN: %clang_cc1 -cl-std=CL1.2 -triple amdgcn-amd-amdhsa 
-mprintf-kind=hostcall -disable-llvm-passes -emit-llvm -o - %s | FileCheck 
--check-prefix=CHECK_HOSTCALL %s
 
 int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 
2)));

ssahasra wrote:

There should be tests that use the "v" modifier inside a format specifier such 
as "%v2d" and also tests that use outside it, such as "%dv".

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


[llvm] [clang] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -170,20 +173,49 @@ static Value *appendString(IRBuilder<> , Value 
*Desc, Value *Arg,
   return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
 }
 
+static Value *appendVectorArg(IRBuilder<> , Value *Desc, Value *Arg,
+  bool IsLast, bool IsBuffered) {
+  assert(Arg->getType()->isVectorTy() && "incorrent append* function");
+  auto VectorTy = dyn_cast(Arg->getType());
+  auto Zero = Builder.getInt64(0);
+  if (VectorTy) {
+for (unsigned int i = 0; i < VectorTy->getNumElements() - 1; i++) {
+  auto Val = Builder.CreateExtractElement(Arg, i);
+  Desc = callAppendArgs(Builder, Desc, 1,
+fitArgInto64Bits(Builder, Val, IsBuffered), Zero,
+Zero, Zero, Zero, Zero, Zero, false);
+}
+
+Value* Val =
+Builder.CreateExtractElement(Arg, VectorTy->getNumElements() - 1);
+return callAppendArgs(Builder, Desc, 1,
+  fitArgInto64Bits(Builder, Val, IsBuffered), Zero,
+  Zero, Zero, Zero, Zero, Zero, IsLast);
+  }
+  return nullptr;
+}
+
 static Value *processArg(IRBuilder<> , Value *Desc, Value *Arg,
- bool SpecIsCString, bool IsLast) {
+ bool SpecIsCString, bool IsVector, bool IsLast,
+ bool IsBuffered) {
   if (SpecIsCString && isa(Arg->getType())) {
 return appendString(Builder, Desc, Arg, IsLast);
   }
-  // If the format specifies a string but the argument is not, the frontend 
will
-  // have printed a warning. We just rely on undefined behaviour and send the
-  // argument anyway.
-  return appendArg(Builder, Desc, Arg, IsLast);
+
+  if (IsVector) {
+return appendVectorArg(Builder, Desc, Arg, IsLast, IsBuffered);
+  } 
+
+  // If the format specifies a string but the argument is not, the frontend
+  // will have printed a warning. We just rely on undefined behaviour and send
+  // the argument anyway.
+  return appendArg(Builder, Desc, Arg, IsLast, IsBuffered);
 }
 
 // Scan the format string to locate all specifiers, and mark the ones that
 // specify a string, i.e, the "%s" specifier with optional '*' characters.
-static void locateCStrings(SparseBitVector<8> , StringRef Str) {
+static void locateCStringsAndVectors(SparseBitVector<8> ,

ssahasra wrote:

update the comment above the function

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -194,6 +226,8 @@ static void locateCStrings(SparseBitVector<8> , 
StringRef Str) {
   SpecPos += 2;
   continue;
 }
+if (Str.find_first_of("v", SpecPos) != StringRef::npos)

ssahasra wrote:

I don't think this will work as expected. It can clearly match a "v" that 
occurs after the data type. For example, it is supposed to match "%v2d", but it 
will also match "%d v". The match should be performed inside the "Spec" 
substring created below. 

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -170,20 +173,49 @@ static Value *appendString(IRBuilder<> , Value 
*Desc, Value *Arg,
   return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
 }
 
+static Value *appendVectorArg(IRBuilder<> , Value *Desc, Value *Arg,
+  bool IsLast, bool IsBuffered) {
+  assert(Arg->getType()->isVectorTy() && "incorrent append* function");
+  auto VectorTy = dyn_cast(Arg->getType());
+  auto Zero = Builder.getInt64(0);
+  if (VectorTy) {
+for (unsigned int i = 0; i < VectorTy->getNumElements() - 1; i++) {
+  auto Val = Builder.CreateExtractElement(Arg, i);
+  Desc = callAppendArgs(Builder, Desc, 1,
+fitArgInto64Bits(Builder, Val, IsBuffered), Zero,
+Zero, Zero, Zero, Zero, Zero, false);
+}
+
+Value* Val =
+Builder.CreateExtractElement(Arg, VectorTy->getNumElements() - 1);
+return callAppendArgs(Builder, Desc, 1,
+  fitArgInto64Bits(Builder, Val, IsBuffered), Zero,
+  Zero, Zero, Zero, Zero, Zero, IsLast);
+  }
+  return nullptr;
+}
+
 static Value *processArg(IRBuilder<> , Value *Desc, Value *Arg,
- bool SpecIsCString, bool IsLast) {
+ bool SpecIsCString, bool IsVector, bool IsLast,
+ bool IsBuffered) {
   if (SpecIsCString && isa(Arg->getType())) {
 return appendString(Builder, Desc, Arg, IsLast);
   }
-  // If the format specifies a string but the argument is not, the frontend 
will
-  // have printed a warning. We just rely on undefined behaviour and send the
-  // argument anyway.
-  return appendArg(Builder, Desc, Arg, IsLast);
+
+  if (IsVector) {
+return appendVectorArg(Builder, Desc, Arg, IsLast, IsBuffered);
+  } 
+
+  // If the format specifies a string but the argument is not, the frontend
+  // will have printed a warning. We just rely on undefined behaviour and send
+  // the argument anyway.

ssahasra wrote:

This is a pure whitespace change. Keeping the original formatting of the 
comment helps simplify the diff.

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -170,20 +173,49 @@ static Value *appendString(IRBuilder<> , Value 
*Desc, Value *Arg,
   return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
 }
 
+static Value *appendVectorArg(IRBuilder<> , Value *Desc, Value *Arg,
+  bool IsLast, bool IsBuffered) {
+  assert(Arg->getType()->isVectorTy() && "incorrent append* function");
+  auto VectorTy = dyn_cast(Arg->getType());
+  auto Zero = Builder.getInt64(0);
+  if (VectorTy) {

ssahasra wrote:

So the argument is ignored if it is not a FixedVectorType?

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -26,28 +26,31 @@ using namespace llvm;
 
 #define DEBUG_TYPE "amdgpu-emit-printf"
 
-static Value *fitArgInto64Bits(IRBuilder<> , Value *Arg) {
+static Value *fitArgInto64Bits(IRBuilder<> , Value *Arg,
+   bool IsBuffered) {
+  const DataLayout  = 
Builder.GetInsertBlock()->getModule()->getDataLayout();
   auto Int64Ty = Builder.getInt64Ty();
   auto Ty = Arg->getType();
 
   if (auto IntTy = dyn_cast(Ty)) {
-switch (IntTy->getBitWidth()) {
-case 32:
-  return Builder.CreateZExt(Arg, Int64Ty);
-case 64:
-  return Arg;
+if (IntTy->getBitWidth() < 64) {
+  return Builder.CreateZExt(Arg, Builder.getInt64Ty());
 }
   }
 
-  if (Ty->getTypeID() == Type::DoubleTyID) {
+  if (Ty->isFloatingPointTy()) {
+if (DL.getTypeAllocSize(Ty) < 8)
+  Arg = Builder.CreateFPExt(Arg, Builder.getDoubleTy());

ssahasra wrote:

This typecast should not be necessary. Default argument promotions in C++ for 
variadic functions ensure that all floating point arguments are promoted to 
double. If that is not happening, can you demonstrate with a test?

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -4742,6 +4742,16 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 Args.ClaimAllArgs(options::OPT_gen_cdb_fragment_path);
   }
 
+  if (TC.getTriple().isAMDGPU() && types::isOpenCL(Input.getType())) {
+if (Args.getLastArg(options::OPT_mprintf_kind_EQ)) {
+  CmdArgs.push_back(Args.MakeArgString(
+  "-mprintf-kind=" +
+  Args.getLastArgValue(options::OPT_mprintf_kind_EQ)));
+  // Force compiler error on invalid conversion specifiers
+  
CmdArgs.push_back(Args.MakeArgString("-Werror=format-invalid-specifier"));

ssahasra wrote:

Why is this necessary here?

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


[llvm] [clang] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -406,5 +410,9 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", 
"nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", "fp8-insts")
 
+// OpenCL
+LANGBUILTIN(printf, "icC*4.", "fp:0:", ALL_OCL_LANGUAGES)

ssahasra wrote:

I don't understand why this is necessary for the current task. What does it fix 
in the parsing OpenCL builtins?

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


[llvm] [clang] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -26,28 +26,31 @@ using namespace llvm;
 
 #define DEBUG_TYPE "amdgpu-emit-printf"
 
-static Value *fitArgInto64Bits(IRBuilder<> , Value *Arg) {
+static Value *fitArgInto64Bits(IRBuilder<> , Value *Arg,
+   bool IsBuffered) {
+  const DataLayout  = 
Builder.GetInsertBlock()->getModule()->getDataLayout();
   auto Int64Ty = Builder.getInt64Ty();
   auto Ty = Arg->getType();
 
   if (auto IntTy = dyn_cast(Ty)) {
-switch (IntTy->getBitWidth()) {
-case 32:
-  return Builder.CreateZExt(Arg, Int64Ty);
-case 64:
-  return Arg;
+if (IntTy->getBitWidth() < 64) {
+  return Builder.CreateZExt(Arg, Builder.getInt64Ty());
 }
   }
 
-  if (Ty->getTypeID() == Type::DoubleTyID) {
+  if (Ty->isFloatingPointTy()) {
+if (DL.getTypeAllocSize(Ty) < 8)
+  Arg = Builder.CreateFPExt(Arg, Builder.getDoubleTy());
+if (IsBuffered)
+  return Arg;
 return Builder.CreateBitCast(Arg, Int64Ty);
   }
 
-  if (isa(Ty)) {
+  if (!IsBuffered && isa(Ty)) {
 return Builder.CreatePtrToInt(Arg, Int64Ty);

ssahasra wrote:

How are pointers handled in the buffered case? 

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


[clang-tools-extra] [llvm] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-11-19 Thread Justin Fargnoli via cfe-commits

justinfargnoli wrote:

> I would recommend trying to run this pass (with all options enabled) over all 
> existing tests to make sure that it doesn't cause any crashes/verifier 
> failures. You're moving instructions around, and it's easy to get that wrong 
> when invoke, callbr or catchswitch are involved.

Thanks for this suggestion! It helped iron out a lot of bugs in the 
implementation. 

> I would also try to add this pass at the end of the clang pipeline and run 
> llvm-test-suite to verify that the normalization this does is indeed 
> semantics-preserving.

I'm running into some linking errors when trying to build 
[`llvm-test-suite`](https://github.com/llvm/llvm-test-suite/tree/main). Pinging 
for another round of review in the meantime. 

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


[clang-tools-extra] [llvm] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-11-19 Thread Justin Fargnoli via cfe-commits

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


[clang-tools-extra] [llvm] [clang] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-11-19 Thread via cfe-commits

goldsteinn wrote:

For my money this was merged prematurely. There are still outstanding concerns 
about whether this transform is desirable, as well there is an outstanding 
comment about the implementation itself.
I'm fairly agnostic about this code getting in, but I think it should be 
reverted until some degree of consensus is reached.
It's painful to have comments/a PR languish without replies, but don't think 
the answer is to just push.

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


[clang] [clang] Enhance handling of Apple-specific '-arch'/'-target' option values (PR #72821)

2023-11-19 Thread Daniil Kovalev via cfe-commits

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


[clang] [clang] Enhance handling of Apple-specific '-arch'/'-target' option values (PR #72821)

2023-11-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Daniil Kovalev (kovdan01)


Changes

The '-arch' option itself is Apple-specific, so, if '-target' is not passed 
explicitely, we try to construct an Apple triple. If the default triple is 
Apple-specific, we just update it's arch so it matches the one passed via 
'-arch' option, otherwise, we construct a 'arch-apple-darwin10' triple 
"from scratch".

The arm64e arch value is also Apple-specific, so, if we have 'arm64e' or 
'arm64e-apple' triple, append missing parts to it so it becomes 
'arm64e-apple-darwin10'.

See tests in Driver/apple-specific-options.c for detailed description of how 
different cases are handled.

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


2 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+28) 
- (added) clang/test/Driver/apple-specific-options.c (+60) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 6f5ff8141032677..4663189933cc1c2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -521,6 +521,34 @@ static llvm::Triple computeTargetTriple(const Driver ,
   if (TargetTriple.contains("-unknown-gnu") || 
TargetTriple.contains("-pc-gnu"))
 Target.setOSName("hurd");
 
+  auto SetDefaultAppleTarget = []() {
+if (Target.getVendorName().empty())
+  Target.setVendor(llvm::Triple::Apple);
+if (Target.getVendor() == llvm::Triple::Apple &&
+Target.getOSAndEnvironmentName().empty())
+  Target.setOSName("darwin10");
+  };
+
+  // Since '-arch' is an Apple-specific option, construct a default Apple 
triple
+  // when '-target' is not explicitely passed.
+  if (Args.hasArg(options::OPT_arch) && !Args.hasArg(options::OPT_target)) {
+StringRef ArchName = Args.getLastArg(options::OPT_arch)->getValue();
+if (Target.isOSBinFormatMachO()) {
+  // The default triple is already Apple-specific - just update the arch.
+  tools::darwin::setTripleTypeForMachOArchName(Target, ArchName, Args);
+} else {
+  // The default triple is not Apple-specific - construct a new one to 
avoid
+  // handling unrelated info from the default one (e.g. environment).
+  Target = llvm::Triple(ArchName);
+  SetDefaultAppleTarget();
+}
+  }
+
+  // Since arm64e arch is Apple-specific, set VendorName and OS correspondingly
+  // if not set already.
+  if (Target.getArchName() == "arm64e")
+SetDefaultAppleTarget();
+
   // Handle Apple-specific options available here.
   if (Target.isOSBinFormatMachO()) {
 // If an explicit Darwin arch name is given, that trumps all.
diff --git a/clang/test/Driver/apple-specific-options.c 
b/clang/test/Driver/apple-specific-options.c
new file mode 100644
index 000..b683bf5a3de3a8f
--- /dev/null
+++ b/clang/test/Driver/apple-specific-options.c
@@ -0,0 +1,60 @@
+// Without '-target' explicitly passed, construct the default triple.
+// If the LLVM_DEFAULT_TARGET_TRIPLE is a Darwin triple, change it's 
architecture
+// to a one passed via '-arch'. Otherwise, use '-apple-darwin10'.
+
+// RUN: %clang -arch x86_64 -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH
+
+// ARCH: "-triple" "x86_64-apple-
+
+// For non-Darwin explicitly passed '-target', ignore '-arch'.
+
+// RUN: %clang -arch arm64 -target x86_64-unknown-linux -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH_NON_DARWIN1
+
+// ARCH_NON_DARWIN1: "-triple" "x86_64-unknown-linux"
+
+// RUN: %clang -arch arm64 -target x86_64-apple -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH_NON_DARWIN2
+
+// ARCH_NON_DARWIN2: "-triple" "x86_64-apple"
+
+
+// For Darwin explicitly passed '-target', the '-arch' option overrides the 
architecture
+
+// RUN: %clang -arch arm64 -target x86_64-apple-ios7.0.0 -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH_DARWIN
+
+// ARCH_DARWIN: "-triple" "arm64-apple-ios7.0.0"
+
+
+// For 'arm64e' and 'arm64e-apple' explicitly passed as '-target',
+// construct the default 'arm64e-apple-darwin10' triple.
+
+// RUN: %clang -target arm64e -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARM64E
+// RUN: %clang -target arm64e-apple -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARM64E
+// ARM64E: "-triple" "arm64e-apple-macosx10.6.0"
+
+
+// For non-Darwin explicitly passed '-target', keep it unchanged if not 
'arm64e' and
+// 'arm64e-apple', which we implicitly narrow to the default 
'arm64e-apple-darwin10'.
+
+// RUN: %clang -target arm64e-pc -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARM64E_NON_DARWIN1
+
+// ARM64E_NON_DARWIN1: "-triple" "arm64e-pc"
+
+// RUN: %clang -target arm64e-unknown-linux -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARM64E_NON_DARWIN2
+
+// ARM64E_NON_DARWIN2: "-triple" "arm64e-unknown-linux"
+
+
+// For Darwin explicitly passed '-target', keep it unchanged
+
+// RUN: %clang -target arm64e-apple-ios7.0.0 -c %s -### 2>&1 | \
+// RUN:   FileCheck %s 

[clang] [clang] Enhance handling of Apple-specific '-arch'/'-target' option values (PR #72821)

2023-11-19 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 created 
https://github.com/llvm/llvm-project/pull/72821

The '-arch' option itself is Apple-specific, so, if '-target' is not passed 
explicitely, we try to construct an Apple triple. If the default triple is 
Apple-specific, we just update it's arch so it matches the one passed via 
'-arch' option, otherwise, we construct a '-apple-darwin10' triple "from 
scratch".

The arm64e arch value is also Apple-specific, so, if we have 'arm64e' or 
'arm64e-apple' triple, append missing parts to it so it becomes 
'arm64e-apple-darwin10'.

See tests in Driver/apple-specific-options.c for detailed description of how 
different cases are handled.

>From a1ad61f5194c1ba577222e9381d01f836432db32 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Fri, 17 Nov 2023 06:33:33 +0300
Subject: [PATCH] [clang] Enhance handling of Apple-specific '-arch'/'-target'
 option values

The '-arch' option itself is Apple-specific, so, if '-target' is not passed
explicitely, we try to construct an Apple triple. If the default triple
is Apple-specific, we just update it's arch so it matches the one passed
via '-arch' option, otherwise, we construct a '-apple-darwin10' triple
"from scratch". Passing just '-arch' without '-target' seems as a common
practice in Apple's tests, and it previously led to undesireable triple
values deduced if a person had, say, linux-specific
LLVM_DEFAULT_TARGET_TRIPLE set.

The arm64e arch value is also Apple-specific, so, if we have 'arm64e' or
'arm64e-apple' triple, append missing parts to it so it becomes
'arm64e-apple-darwin10'.

See tests in Driver/apple-specific-options.c for detailed description of how
different cases are handled.
---
 clang/lib/Driver/Driver.cpp| 28 ++
 clang/test/Driver/apple-specific-options.c | 60 ++
 2 files changed, 88 insertions(+)
 create mode 100644 clang/test/Driver/apple-specific-options.c

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 6f5ff8141032677..4663189933cc1c2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -521,6 +521,34 @@ static llvm::Triple computeTargetTriple(const Driver ,
   if (TargetTriple.contains("-unknown-gnu") || 
TargetTriple.contains("-pc-gnu"))
 Target.setOSName("hurd");
 
+  auto SetDefaultAppleTarget = []() {
+if (Target.getVendorName().empty())
+  Target.setVendor(llvm::Triple::Apple);
+if (Target.getVendor() == llvm::Triple::Apple &&
+Target.getOSAndEnvironmentName().empty())
+  Target.setOSName("darwin10");
+  };
+
+  // Since '-arch' is an Apple-specific option, construct a default Apple 
triple
+  // when '-target' is not explicitely passed.
+  if (Args.hasArg(options::OPT_arch) && !Args.hasArg(options::OPT_target)) {
+StringRef ArchName = Args.getLastArg(options::OPT_arch)->getValue();
+if (Target.isOSBinFormatMachO()) {
+  // The default triple is already Apple-specific - just update the arch.
+  tools::darwin::setTripleTypeForMachOArchName(Target, ArchName, Args);
+} else {
+  // The default triple is not Apple-specific - construct a new one to 
avoid
+  // handling unrelated info from the default one (e.g. environment).
+  Target = llvm::Triple(ArchName);
+  SetDefaultAppleTarget();
+}
+  }
+
+  // Since arm64e arch is Apple-specific, set VendorName and OS correspondingly
+  // if not set already.
+  if (Target.getArchName() == "arm64e")
+SetDefaultAppleTarget();
+
   // Handle Apple-specific options available here.
   if (Target.isOSBinFormatMachO()) {
 // If an explicit Darwin arch name is given, that trumps all.
diff --git a/clang/test/Driver/apple-specific-options.c 
b/clang/test/Driver/apple-specific-options.c
new file mode 100644
index 000..b683bf5a3de3a8f
--- /dev/null
+++ b/clang/test/Driver/apple-specific-options.c
@@ -0,0 +1,60 @@
+// Without '-target' explicitly passed, construct the default triple.
+// If the LLVM_DEFAULT_TARGET_TRIPLE is a Darwin triple, change it's 
architecture
+// to a one passed via '-arch'. Otherwise, use '-apple-darwin10'.
+
+// RUN: %clang -arch x86_64 -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH
+
+// ARCH: "-triple" "x86_64-apple-
+
+// For non-Darwin explicitly passed '-target', ignore '-arch'.
+
+// RUN: %clang -arch arm64 -target x86_64-unknown-linux -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH_NON_DARWIN1
+
+// ARCH_NON_DARWIN1: "-triple" "x86_64-unknown-linux"
+
+// RUN: %clang -arch arm64 -target x86_64-apple -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH_NON_DARWIN2
+
+// ARCH_NON_DARWIN2: "-triple" "x86_64-apple"
+
+
+// For Darwin explicitly passed '-target', the '-arch' option overrides the 
architecture
+
+// RUN: %clang -arch arm64 -target x86_64-apple-ios7.0.0 -c %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefix ARCH_DARWIN
+
+// ARCH_DARWIN: "-triple" "arm64-apple-ios7.0.0"
+
+
+// For 'arm64e' and 

[llvm] [clang] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Vikram Hegde via cfe-commits


@@ -278,7 +310,13 @@ static Value *callBufferedPrintfStart(
 StringData(StringRef(), LenWithNull, LenWithNullAligned, false));
   }
 } else {
-  int AllocSize = M->getDataLayout().getTypeAllocSize(Args[i]->getType());
+  int AllocSize = 0;
+  if (OCLVectors.test(i)) {
+auto VecArg = dyn_cast(Args[i]->getType());
+assert(VecArg && "invalid vector specifier");
+AllocSize = VecArg->getNumElements() * 8;
+  } else
+AllocSize = M->getDataLayout().getTypeAllocSize(Args[i]->getType());

vikramRH wrote:

I extract individual vector elements, expand them to 8 bytes and store them 
onto the buffer. The "getTypeAllocSize" would not give me the actual occupied 
size in the buffer in this case.

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Vikram Hegde via cfe-commits


@@ -278,7 +310,13 @@ static Value *callBufferedPrintfStart(
 StringData(StringRef(), LenWithNull, LenWithNullAligned, false));
   }
 } else {
-  int AllocSize = M->getDataLayout().getTypeAllocSize(Args[i]->getType());
+  int AllocSize = 0;
+  if (OCLVectors.test(i)) {
+auto VecArg = dyn_cast(Args[i]->getType());
+assert(VecArg && "invalid vector specifier");

vikramRH wrote:

Done

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Vikram Hegde via cfe-commits


@@ -170,20 +173,46 @@ static Value *appendString(IRBuilder<> , Value 
*Desc, Value *Arg,
   return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
 }
 
+static Value *appendVectorArg(IRBuilder<> , Value *Desc, Value *Arg,

vikramRH wrote:

Done

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Vikram Hegde via cfe-commits


@@ -170,20 +173,46 @@ static Value *appendString(IRBuilder<> , Value 
*Desc, Value *Arg,
   return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
 }
 
+static Value *appendVectorArg(IRBuilder<> , Value *Desc, Value *Arg,
+  bool IsLast, bool IsBuffered) {
+  assert(Arg->getType()->isVectorTy() && "incorrent append* function");
+  auto VectorTy = dyn_cast(Arg->getType());
+  auto Zero = Builder.getInt64(0);
+  if (VectorTy) {
+for (unsigned int i = 0; i < VectorTy->getNumElements() - 1; i++) {
+  auto Val = Builder.CreateExtractElement(Arg, i);
+  Desc = callAppendArgs(Builder, Desc, 1,
+fitArgInto64Bits(Builder, Val, IsBuffered), Zero,
+Zero, Zero, Zero, Zero, Zero, false);
+}
+
+auto Val =
+Builder.CreateExtractElement(Arg, VectorTy->getNumElements() - 1);
+return callAppendArgs(Builder, Desc, 1,
+  fitArgInto64Bits(Builder, Val, IsBuffered), Zero,
+  Zero, Zero, Zero, Zero, Zero, IsLast);
+  }
+  return nullptr;
+}
+
 static Value *processArg(IRBuilder<> , Value *Desc, Value *Arg,
- bool SpecIsCString, bool IsLast) {
+ bool SpecIsCString, bool IsVector, bool IsLast,
+ bool IsBuffered) {
   if (SpecIsCString && isa(Arg->getType())) {
 return appendString(Builder, Desc, Arg, IsLast);
-  }
-  // If the format specifies a string but the argument is not, the frontend 
will
-  // have printed a warning. We just rely on undefined behaviour and send the
-  // argument anyway.
-  return appendArg(Builder, Desc, Arg, IsLast);
+  } else if (IsVector) {

vikramRH wrote:

Done

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Vikram Hegde via cfe-commits


@@ -170,20 +173,46 @@ static Value *appendString(IRBuilder<> , Value 
*Desc, Value *Arg,
   return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
 }
 
+static Value *appendVectorArg(IRBuilder<> , Value *Desc, Value *Arg,
+  bool IsLast, bool IsBuffered) {
+  assert(Arg->getType()->isVectorTy() && "incorrent append* function");
+  auto VectorTy = dyn_cast(Arg->getType());
+  auto Zero = Builder.getInt64(0);
+  if (VectorTy) {
+for (unsigned int i = 0; i < VectorTy->getNumElements() - 1; i++) {
+  auto Val = Builder.CreateExtractElement(Arg, i);
+  Desc = callAppendArgs(Builder, Desc, 1,
+fitArgInto64Bits(Builder, Val, IsBuffered), Zero,
+Zero, Zero, Zero, Zero, Zero, false);
+}
+
+auto Val =

vikramRH wrote:

Done

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


[clang] [llvm] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-19 Thread Vikram Hegde via cfe-commits

https://github.com/vikramRH updated 
https://github.com/llvm/llvm-project/pull/72556

>From 6ace9d0a51064be189093ca3bb42416aafadb7f6 Mon Sep 17 00:00:00 2001
From: Vikram 
Date: Fri, 10 Nov 2023 09:39:41 +
Subject: [PATCH 1/3] [AMDGPU] Treat printf as builtin for OpenCL

---
 clang/include/clang/Basic/BuiltinsAMDGPU.def | 8 
 clang/lib/AST/Decl.cpp   | 7 +++
 clang/lib/Basic/Targets/AMDGPU.cpp   | 2 ++
 clang/lib/CodeGen/CGBuiltin.cpp  | 5 +
 4 files changed, 22 insertions(+)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index a19c8bd5f219ec6..1799c72806bfdd4 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -21,6 +21,10 @@
 #if defined(BUILTIN) && !defined(TARGET_BUILTIN)
 #   define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
 #endif
+
+#if defined(BUILTIN) && !defined(LANGBUILTIN)
+#define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
+#endif
 
//===--===//
 // SI+ only builtins.
 
//===--===//
@@ -406,5 +410,9 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", 
"nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", "fp8-insts")
 
+// OpenCL
+LANGBUILTIN(printf, "icC*4.", "fp:0:", ALL_OCL_LANGUAGES)
+
 #undef BUILTIN
 #undef TARGET_BUILTIN
+#undef LANGBUILTIN
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..2597422bdd521a0 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -49,6 +49,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetCXXABI.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Visibility.h"
@@ -3598,6 +3599,12 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
   if (!ConsiderWrapperFunctions && getStorageClass() == SC_Static)
 return 0;
 
+  // AMDGCN implementation supports printf as a builtin
+  // for OpenCL
+  if (Context.getTargetInfo().getTriple().isAMDGCN() &&
+  Context.getLangOpts().OpenCL && BuiltinID == AMDGPU::BIprintf)
+return BuiltinID;
+
   // OpenCL v1.2 s6.9.f - The library functions defined in
   // the C99 standard headers are not available.
   if (Context.getLangOpts().OpenCL &&
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 409ae32ab424215..307cfa49f54e926 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -91,6 +91,8 @@ static constexpr Builtin::Info BuiltinInfo[] = {
   {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
 #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   
\
   {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) 
\
+  {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, LANG},
 #include "clang/Basic/BuiltinsAMDGPU.def"
 };
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 09309a3937fb613..987909b5a62e11b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2458,6 +2458,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   ().getLongDoubleFormat() == ::APFloat::IEEEquad())
 BuiltinID = mutateLongDoubleBuiltin(BuiltinID);
 
+   // Mutate the printf builtin ID so that we use the same CodeGen path for
+   // HIP and OpenCL with AMDGPU targets.
+   if (getTarget().getTriple().isAMDGCN() && BuiltinID == AMDGPU::BIprintf)
+ BuiltinID = Builtin::BIprintf;
+
   // If the builtin has been declared explicitly with an assembler label,
   // disable the specialized emitting below. Ideally we should communicate the
   // rename in IR, or at least avoid generating the intrinsic calls that are

>From 040a28deef5fe7a5d9e357a898b50335992e708d Mon Sep 17 00:00:00 2001
From: Vikram 
Date: Mon, 20 Nov 2023 05:26:27 +
Subject: [PATCH 2/3] [AMDGPU] Enable OpenCL printf expansion at clang CodeGen

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 ++-
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 25 +++--
 clang/lib/Driver/ToolChains/Clang.cpp | 10 ++
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 987909b5a62e11b..8d51df24c7872b7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5622,7 +5622,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,

[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-19 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/72815

>From 27f1873abd9707107c714eb3432b31ffa56235e3 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Sun, 19 Nov 2023 19:34:35 -0500
Subject: [PATCH] [CUDA][HIP] ignore implicit host/device attr for override

When deciding whether a previous function declaration is an
overload or override, implicit host/device attrs should
not be considered.

This fixes the failure for the following code:

`template 
class C {
explicit C() {};
};

template <> C::C() {};
`

The issue was introduced by https://github.com/llvm/llvm-project/pull/72394

sine the template specialization is treated as overload
due to implicit host/device attrs are considered for
overload/override differentiation.
---
 clang/lib/Sema/SemaCUDA.cpp  |  8 ++--
 clang/lib/Sema/SemaOverload.cpp  |  6 --
 .../SemaCUDA/implicit-member-target-inherited.cu |  1 +
 clang/test/SemaCUDA/trivial-ctor-dtor.cu | 16 
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index b94f448dabe7517..9dc63ff315a3926 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -1000,13 +1000,9 @@ void Sema::checkCUDATargetOverload(FunctionDecl *NewFD,
 // should have the same implementation on both sides.
 if (NewTarget != OldTarget &&
 ((NewTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(NewFD) &&
-OldTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(NewFD)) ||
  (OldTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(OldFD) &&
-NewTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(OldFD)) ||
  (NewTarget == CFT_Global) || (OldTarget == CFT_Global)) &&
 !IsOverload(NewFD, OldFD, /* UseMemberUsingDeclRules = */ false,
 /* ConsiderCudaAttrs = */ false)) {
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9800d7f1c9cfee9..64607e28b8b35e6 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1491,8 +1491,10 @@ static bool IsOverloadOrOverrideImpl(Sema , 
FunctionDecl *New,
 // Don't allow overloading of destructors.  (In theory we could, but it
 // would be a giant change to clang.)
 if (!isa(New)) {
-  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(New),
-   OldTarget = SemaRef.IdentifyCUDATarget(Old);
+  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(
+   New, isa(New)),
+   OldTarget = SemaRef.IdentifyCUDATarget(
+   Old, isa(New));
   if (NewTarget != Sema::CFT_InvalidTarget) {
 assert((OldTarget != Sema::CFT_InvalidTarget) &&
"Unexpected invalid target.");
diff --git a/clang/test/SemaCUDA/implicit-member-target-inherited.cu 
b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
index 781199bba6b5a11..ceca0891fc9b03c 100644
--- a/clang/test/SemaCUDA/implicit-member-target-inherited.cu
+++ b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
@@ -39,6 +39,7 @@ struct A2_with_device_ctor {
 };
 // expected-note@-3 {{candidate constructor (the implicit copy constructor) 
not viable}}
 // expected-note@-4 {{candidate constructor (the implicit move constructor) 
not viable}}
+// expected-note@-4 {{candidate inherited constructor not viable: call to 
__device__ function from __host__ function}}
 
 struct B2_with_implicit_default_ctor : A2_with_device_ctor {
   using A2_with_device_ctor::A2_with_device_ctor;
diff --git a/clang/test/SemaCUDA/trivial-ctor-dtor.cu 
b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
index 1df8adc62bab590..21d698d28492ac3 100644
--- a/clang/test/SemaCUDA/trivial-ctor-dtor.cu
+++ b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
@@ -38,3 +38,19 @@ struct TC : TB {
 };
 
 __device__ TC tc; //expected-error {{dynamic initialization is not 
supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+// Check trivial ctor specialization
+template 
+struct C { //expected-note {{candidate constructor (the implicit copy 
constructor) not viable}}
+   //expected-note@-1 {{candidate constructor (the implicit move 
constructor) not viable}}
+explicit C() {};
+};
+
+template <> C::C() {};
+__device__ C ci_d;
+C ci_h;
+
+// Check non-trivial ctor specialization
+template <> C::C() { static int nontrivial_ctor = 1; } //expected-note 
{{candidate constructor not viable: call to __host__ function from __device__ 
function}}
+__device__ C cf_d; //expected-error {{no matching constructor for 
initialization of 'C'}}
+C cf_h;


[clang] [clang][Interp] IndirectMember initializers (PR #69900)

2023-11-19 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Add an EvaluationResult class (PR #71315)

2023-11-19 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

2023-11-19 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang-tools-extra] [llvm] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-11-19 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

2023-11-19 Thread Nathan Ridge via cfe-commits


@@ -1724,6 +1724,33 @@ TEST(InlayHints, RestrictRange) {
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, PseudoObjectExpr) {
+  Annotations Code(R"cpp(
+struct S {
+  __declspec(property(get=GetX, put=PutX)) int x[];
+  int GetX(int y, int z) { return 42 + y; }
+  void PutX(int y) { x = $one[[y]]; } // FIXME: Undesired `x = y: y` for 
this ill-formed expression.

HighCommander4 wrote:

This is a bit confusing, since the fact that the expression is ill-formed is 
not related to the FIXME.

I would suggest moving the `x = y;` to some other function (where it's not 
ill-formed).

(Also mention in a comment that this builds a PseudoObjectExpr here too.)

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


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

2023-11-19 Thread Nathan Ridge via cfe-commits


@@ -1724,6 +1724,33 @@ TEST(InlayHints, RestrictRange) {
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, PseudoObjectExpr) {
+  Annotations Code(R"cpp(
+struct S {
+  __declspec(property(get=GetX, put=PutX)) int x[];
+  int GetX(int y, int z) { return 42 + y; }
+  void PutX(int y) { x = $one[[y]]; } // FIXME: Undesired `x = y: y` for 
this ill-formed expression.
+};
+
+int printf(const char *Format, ...);
+
+int main() {
+  S s;
+  __builtin_dump_struct(, printf); // Not `Format: 
__builtin_dump_struct()`
+  printf($Param[["Hello, %d"]], 42); // Normal calls are not affected.
+  return s.x[ $two[[1]] ][ $three[[2]] ]; // `x[y: 1][z: 2]`

HighCommander4 wrote:

Thanks, this is an interesting use case for not just skipping the semantic 
forms of all PseudoObjectExprs (which was my initial thought)

Since it's not obvious that this builds a PseudoObjectExpr, can you please add 
a comment:

```
// This builds a PseudoObjectExpr, but here it's useful for show the
// arguments from the semantic form.
```

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


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

2023-11-19 Thread Nathan Ridge via cfe-commits


@@ -589,6 +589,24 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
+// Do not show inlay hints for the __builtin_dump_struct, which would
+// expand to a PseudoObjectExpr that includes a couple of calls to a
+// printf function. Printing parameter names for that anyway would end up
+// with duplicate parameter names (which, however, got de-duplicated after
+// visiting) for the printf function.
+if (auto *CE = dyn_cast(E->getSyntacticForm());
+CE && CE->getBuiltinCallee() == Builtin::BI__builtin_dump_struct)
+  // Only traverse the syntactic forms. This leaves the door open in case
+  // the arguments in the syntactic form for __builtin_dump_struct could
+  // possibly get parameter names.
+  return RecursiveASTVisitor::TraverseStmt(
+  E->getSyntacticForm());
+// FIXME: Shall we ignore semantic forms for other pseudo object

HighCommander4 wrote:

Maybe all PseudoObjectExprs where the syntactic form is a CallExpr with a 
builtin callee would be reasonable?

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


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

2023-11-19 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 requested changes to this pull request.


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


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

2023-11-19 Thread Nathan Ridge via cfe-commits

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


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-19 Thread John McCall via cfe-commits

rjmccall wrote:

This is less about the implementation weeds of LLVM and more about the actual 
details of your calling convention — the decisions about how arguments and 
results are passed that are ultimately downstream of the choices made here.  
Mostly, I'm encouraging you as a platform maintainer who's adding Swift CC 
support for your platform to take a few moments to make sure you're happy with 
the CC.  It's likely that everything will *work* regardless — Swift will 
generate both declarations and calls according to the rules of the CC you 
specify here, which should be enough to make things functional — but you might 
find yourself looking at generated code in two years and realize you've been 
doing something ridiculous for that entire time, and maybe it'll be too awkward 
to change.

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


[llvm] [clang-tools-extra] [clang] [Clang] Correct handling of negative and out-of-bounds indices (PR #71877)

2023-11-19 Thread Bill Wendling via cfe-commits


@@ -827,6 +827,165 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const 
Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
+llvm::Value *
+CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type,
+ llvm::IntegerType *ResType) {

bwendling wrote:

This has been rebased with the NFC refactor. PTAL.

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


[llvm] [clang-tools-extra] [clang] [Clang] Correct handling of negative and out-of-bounds indices (PR #71877)

2023-11-19 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/71877

>From 721415856f1e89d8fbe48e63751a9275b25e0fb8 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Thu, 9 Nov 2023 14:15:22 -0800
Subject: [PATCH] [Clang] Correct handling of negative and out-of-bounds
 indices

GCC returns 0 for a negative index on an array in a structure. It also
returns 0 for an array index that goes beyond the extent of the array.
In addition. a pointer to a struct field returns that field's size, not
the size of it plus the rest of the struct, unless it's the first field
in the struct.

  struct s {
int count;
char dummy;
int array[] __attribute((counted_by(count)));
  };

  struct s *p = malloc(...);

  p->count = 10;

A __bdos on the elements of p return:

  __bdos(p, 0) == 30
  __bdos(p->array, 0) == 10
  __bdos(>array[0], 0) == 10
  __bdos(>array[-1], 0) == 0
  __bdos(>array[42], 0) == 0

Also perform some refactoring, putting the "counted_by" calculations in
their own function.
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 309 ++-
 clang/lib/CodeGen/CodeGenFunction.h  |   3 +
 clang/test/CodeGen/attr-counted-by.c | 188 
 3 files changed, 268 insertions(+), 232 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 03ea7ad187e53dc..ebbd5016160b22f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -827,6 +827,165 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const 
Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
+llvm::Value *
+CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type,
+ llvm::IntegerType *ResType) {
+  // The code generated here calculates the size of a struct with a flexible
+  // array member that uses the counted_by attribute. There are two instances
+  // we handle:
+  //
+  //   struct s {
+  // unsigned long flags;
+  // int count;
+  // int array[] __attribute__((counted_by(count)));
+  //   }
+  //
+  //   1) bdos of the flexible array itself:
+  //
+  // __builtin_dynamic_object_size(p->array, 1) ==
+  // p->count * sizeof(*p->array)
+  //
+  //   2) bdos of a pointer into the flexible array:
+  //
+  // __builtin_dynamic_object_size(>array[42], 1) ==
+  // (p->count - 42) * sizeof(*p->array)
+  //
+  //   2) bdos of the whole struct, including the flexible array:
+  //
+  // __builtin_dynamic_object_size(p, 1) ==
+  //max(sizeof(struct s),
+  //offsetof(struct s, array) + p->count * sizeof(*p->array))
+  //
+  ASTContext  = getContext();
+  const Expr *Base = E->IgnoreParenImpCasts();
+  const Expr *Idx = nullptr;
+
+  if (const auto *UO = dyn_cast(Base);
+  UO && UO->getOpcode() == UO_AddrOf) {
+Expr *SubExpr = UO->getSubExpr()->IgnoreParenImpCasts();
+if (const auto *ASE = dyn_cast(SubExpr)) {
+  Base = ASE->getBase()->IgnoreParenImpCasts();
+  Idx = ASE->getIdx()->IgnoreParenImpCasts();
+
+  if (const auto *IL = dyn_cast(Idx)) {
+int64_t Val = IL->getValue().getSExtValue();
+if (Val < 0)
+  // __bdos returns 0 for negative indexes into an array in a struct.
+  return getDefaultBuiltinObjectSizeResult(Type, ResType);
+
+if (Val == 0)
+  // The index is 0, so we don't need to take it into account.
+  Idx = nullptr;
+  }
+} else {
+  // Potential pointer to another element in the struct.
+  Base = SubExpr;
+}
+  }
+
+  // Get the flexible array member Decl.
+  const ValueDecl *FAMDecl = nullptr;
+  if (const auto *ME = dyn_cast(Base)) {
+// Check if \p Base is referencing the FAM itself.
+if (const ValueDecl *MD = ME->getMemberDecl()) {
+  const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
+  getLangOpts().getStrictFlexArraysLevel();
+  if (!Decl::isFlexibleArrayMemberLike(
+  Ctx, MD, MD->getType(), StrictFlexArraysLevel,
+  /*IgnoreTemplateOrMacroSubstitution=*/true))
+return nullptr;
+
+  FAMDecl = MD;
+}
+  } else if (const auto *DRE = dyn_cast(Base)) {
+// Check if we're pointing to the whole struct.
+QualType Ty = DRE->getDecl()->getType();
+if (Ty->isPointerType())
+  Ty = Ty->getPointeeType();
+
+if (const auto *RD = Ty->getAsRecordDecl())
+  // Don't use the outer lexical record because the FAM might be in a
+  // different RecordDecl.
+  FAMDecl = FindFlexibleArrayMemberField(Ctx, RD);
+  }
+
+  if (!FAMDecl || !FAMDecl->hasAttr())
+// No flexible array member found or it doesn't have the "counted_by"
+// attribute.
+return nullptr;
+
+  const ValueDecl *CountedByFD = FindCountedByField(Base);
+  if (!CountedByFD)
+// Can't find the field referenced by the "counted_by" attribute.
+return nullptr;
+
+  // 

[clang] [NFC][Clang] Refactor code to calculate flexible array member size (PR #72790)

2023-11-19 Thread Bill Wendling via cfe-commits

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


[clang] a76adfb - [NFC][Clang] Refactor code to calculate flexible array member size (#72790)

2023-11-19 Thread via cfe-commits

Author: Bill Wendling
Date: 2023-11-19T19:25:10-08:00
New Revision: a76adfb992c6f5a9b05fbcc2de5889d2531607db

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

LOG: [NFC][Clang] Refactor code to calculate flexible array member size (#72790)

The code that calculates the flexible array member size is big enough to
warrant its own method.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 09309a3937fb613..570675b590eae6c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -822,6 +822,158 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const 
Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
+llvm::Value *
+CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type,
+ llvm::IntegerType *ResType) {
+  // The code generated here calculates the size of a struct with a flexible
+  // array member that uses the counted_by attribute. There are two instances
+  // we handle:
+  //
+  //   struct s {
+  // unsigned long flags;
+  // int count;
+  // int array[] __attribute__((counted_by(count)));
+  //   }
+  //
+  //   1) bdos of the flexible array itself:
+  //
+  // __builtin_dynamic_object_size(p->array, 1) ==
+  // p->count * sizeof(*p->array)
+  //
+  //   2) bdos of a pointer into the flexible array:
+  //
+  // __builtin_dynamic_object_size(>array[42], 1) ==
+  // (p->count - 42) * sizeof(*p->array)
+  //
+  //   2) bdos of the whole struct, including the flexible array:
+  //
+  // __builtin_dynamic_object_size(p, 1) ==
+  //max(sizeof(struct s),
+  //offsetof(struct s, array) + p->count * sizeof(*p->array))
+  //
+  const Expr *Base = E->IgnoreParenImpCasts();
+  const Expr *Idx = nullptr;
+
+  if (const auto *UO = dyn_cast(Base);
+  UO && UO->getOpcode() == UO_AddrOf) {
+if (const auto *ASE =
+dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+  Base = ASE->getBase();
+  Idx = ASE->getIdx()->IgnoreParenImpCasts();
+
+  if (const auto *IL = dyn_cast(Idx);
+  IL && !IL->getValue().getSExtValue())
+Idx = nullptr;
+}
+  }
+
+  const ValueDecl *CountedByFD = FindCountedByField(Base);
+  if (!CountedByFD)
+// Can't find the field referenced by the "counted_by" attribute.
+return nullptr;
+
+  // Build a load of the counted_by field.
+  bool IsSigned = CountedByFD->getType()->isSignedIntegerType();
+  const RecordDecl *OuterRD =
+  CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
+  ASTContext  = getContext();
+
+  // Load the counted_by field.
+  const Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
+  Value *CountedByInst = EmitAnyExprToTemp(CountedByExpr).getScalarVal();
+  llvm::Type *CountedByTy = CountedByInst->getType();
+
+  if (Idx) {
+// There's an index into the array. Remove it from the count.
+bool IdxSigned = Idx->getType()->isSignedIntegerType();
+Value *IdxInst = EmitAnyExprToTemp(Idx).getScalarVal();
+IdxInst = IdxSigned ? Builder.CreateSExtOrTrunc(IdxInst, CountedByTy)
+: Builder.CreateZExtOrTrunc(IdxInst, CountedByTy);
+
+// If the index is negative, don't subtract it from the counted_by
+// value. The pointer is pointing to something before the FAM.
+IdxInst = Builder.CreateNeg(IdxInst, "", !IdxSigned, IdxSigned);
+CountedByInst =
+Builder.CreateAdd(CountedByInst, IdxInst, "", !IsSigned, IsSigned);
+  }
+
+  // Get the size of the flexible array member's base type.
+  const ValueDecl *FAMDecl = nullptr;
+  if (const auto *ME = dyn_cast(Base)) {
+const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
+getLangOpts().getStrictFlexArraysLevel();
+if (const ValueDecl *MD = ME->getMemberDecl()) {
+  if (!Decl::isFlexibleArrayMemberLike(
+  Ctx, MD, MD->getType(), StrictFlexArraysLevel,
+  /*IgnoreTemplateOrMacroSubstitution=*/true))
+return nullptr;
+  // Base is referencing the FAM itself.
+  FAMDecl = MD;
+}
+  }
+
+  if (!FAMDecl)
+FAMDecl = FindFlexibleArrayMemberField(Ctx, OuterRD);
+
+  assert(FAMDecl && "Can't find the flexible array member field");
+
+  const ArrayType *ArrayTy = Ctx.getAsArrayType(FAMDecl->getType());
+  CharUnits Size = Ctx.getTypeSizeInChars(ArrayTy->getElementType());
+  llvm::Constant *ElemSize =
+  llvm::ConstantInt::get(CountedByTy, Size.getQuantity(), IsSigned);
+
+  // Calculate how large the flexible array member is in bytes.
+  Value 

[PATCH] D151730: [RISCV] Support target attribute for function

2023-11-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:229
+collectNonISAExtFeature(const std::vector , int XLen) 
{
+  auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  auto FeatureNeedOveride = std::vector(FeaturesVec.begin(), I);

Do we need to call find again? We already did it in the caller, can we pass 
that information somehow?



Comment at: clang/lib/Basic/Targets/RISCV.cpp:230
+  auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  auto FeatureNeedOveride = std::vector(FeaturesVec.begin(), I);
+  auto ParseResult =

`std::vector FeaturesNeedOverride(FeaturesVec.begin(), I);`



Comment at: clang/lib/Basic/Targets/RISCV.cpp:243
+
+  for (auto Feat : FeatureNeedOveride) {
+if (!llvm::is_contained(ImpliedFeatures, Feat))

`llvm::copy_if(FeatureNeedOveride, std::back_inserter(NonISAExtFeatureVec), 
[&](const std::string ) { return !llvm::is_contained(ImpliedFeatures, 
Feat); });`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151730/new/

https://reviews.llvm.org/D151730

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


[PATCH] D151730: [RISCV] Support target attribute for function

2023-11-19 Thread Piyou Chen via Phabricator via cfe-commits
BeMg added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151730/new/

https://reviews.llvm.org/D151730

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


[clang] [llvm] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-11-19 Thread via cfe-commits

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


[clang] [llvm] [clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)

2023-11-19 Thread Justin Fargnoli via cfe-commits

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


[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-19 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B approved this pull request.

LGTM, with one question.

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


[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-19 Thread Artem Belevich via cfe-commits


@@ -1000,13 +1000,9 @@ void Sema::checkCUDATargetOverload(FunctionDecl *NewFD,
 // should have the same implementation on both sides.
 if (NewTarget != OldTarget &&
 ((NewTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(NewFD) &&
-OldTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(NewFD)) ||

Artem-B wrote:

This change was previously excluding device functions. Do we want/need to keep 
that check in place?
If it does need to be gone, then the comment above may need to be updated.

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


[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-19 Thread Artem Belevich via cfe-commits

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


[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2023-11-19 Thread dong jianqiang via cfe-commits

dongjianqiang2 wrote:

@MaskRay the reason for adding this option is that gcc supports it. please 
refer to https://godbolt.org/z/54sE6zTa1

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


[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2023-11-19 Thread dong jianqiang via cfe-commits

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


[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2023-11-19 Thread dong jianqiang via cfe-commits

dongjianqiang2 wrote:

> GCC's default spec file for Linux does not say how `-export-dynamic` 
> translates to ld `-export-dynamic`.
> 
> I think ld `--export-dynamic` is exclusively caused by `-Wl,--export-dynamic` 
> or `-rdynamic`. Do you have any example of `gcc -export-dynamic` uses?
> 
> > clang splits -export-dynamic into "-e" and "xport-dynamic"
> 
> This behavior simulates GCC but the uses seem extremely rare or not used at 
> all. We probably should just reject `-exxx`: #72804



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


[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2023-11-19 Thread dong jianqiang via cfe-commits

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


[PATCH] D135171: FreeBSD: enable __float128 on x86 and powerpc64le

2023-11-19 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

In D135171#4657080 , @brad wrote:

> You can close this.

The submitted patch 
https://github.com/llvm/llvm-project/commit/23c47eba879769a29772c999be2991201c2fe399
 was not the same since it omitted ppc64. So I guess this should remain open


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135171/new/

https://reviews.llvm.org/D135171

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


[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yaxun (Sam) Liu (yxsamliu)


Changes

When deciding whether a previous function declaration is an overload or 
override, implicit host/device attrs should not be considered.

This fixes the failure for the following code:

`template typename T
class C {
explicit C() {};
};

template  Cint::C() {};
`

The issue was introduced by https://github.com/llvm/llvm-project/pull/72394

sine the template specialization is treated as overload due to implicit 
host/device attrs are considered for overload/override differentiation.

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


4 Files Affected:

- (modified) clang/lib/Sema/SemaCUDA.cpp (+2-6) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+4-2) 
- (modified) clang/test/SemaCUDA/implicit-member-target-inherited.cu (+1) 
- (modified) clang/test/SemaCUDA/trivial-ctor-dtor.cu (+16) 


``diff
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index b94f448dabe7517..9dc63ff315a3926 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -1000,13 +1000,9 @@ void Sema::checkCUDATargetOverload(FunctionDecl *NewFD,
 // should have the same implementation on both sides.
 if (NewTarget != OldTarget &&
 ((NewTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(NewFD) &&
-OldTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(NewFD)) ||
  (OldTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(OldFD) &&
-NewTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(OldFD)) ||
  (NewTarget == CFT_Global) || (OldTarget == CFT_Global)) &&
 !IsOverload(NewFD, OldFD, /* UseMemberUsingDeclRules = */ false,
 /* ConsiderCudaAttrs = */ false)) {
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9800d7f1c9cfee9..a33acc184b75274 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1491,8 +1491,10 @@ static bool IsOverloadOrOverrideImpl(Sema , 
FunctionDecl *New,
 // Don't allow overloading of destructors.  (In theory we could, but it
 // would be a giant change to clang.)
 if (!isa(New)) {
-  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(New),
-   OldTarget = SemaRef.IdentifyCUDATarget(Old);
+  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(
+   New, /*IgnoreImplicitHDAttr=*/true),
+   OldTarget = SemaRef.IdentifyCUDATarget(
+   Old, /*IgnoreImplicitHDAttr=*/true);
   if (NewTarget != Sema::CFT_InvalidTarget) {
 assert((OldTarget != Sema::CFT_InvalidTarget) &&
"Unexpected invalid target.");
diff --git a/clang/test/SemaCUDA/implicit-member-target-inherited.cu 
b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
index 781199bba6b5a11..ceca0891fc9b03c 100644
--- a/clang/test/SemaCUDA/implicit-member-target-inherited.cu
+++ b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
@@ -39,6 +39,7 @@ struct A2_with_device_ctor {
 };
 // expected-note@-3 {{candidate constructor (the implicit copy constructor) 
not viable}}
 // expected-note@-4 {{candidate constructor (the implicit move constructor) 
not viable}}
+// expected-note@-4 {{candidate inherited constructor not viable: call to 
__device__ function from __host__ function}}
 
 struct B2_with_implicit_default_ctor : A2_with_device_ctor {
   using A2_with_device_ctor::A2_with_device_ctor;
diff --git a/clang/test/SemaCUDA/trivial-ctor-dtor.cu 
b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
index 1df8adc62bab590..21d698d28492ac3 100644
--- a/clang/test/SemaCUDA/trivial-ctor-dtor.cu
+++ b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
@@ -38,3 +38,19 @@ struct TC : TB {
 };
 
 __device__ TC tc; //expected-error {{dynamic initialization is not 
supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+// Check trivial ctor specialization
+template 
+struct C { //expected-note {{candidate constructor (the implicit copy 
constructor) not viable}}
+   //expected-note@-1 {{candidate constructor (the implicit move 
constructor) not viable}}
+explicit C() {};
+};
+
+template <> C::C() {};
+__device__ C ci_d;
+C ci_h;
+
+// Check non-trivial ctor specialization
+template <> C::C() { static int nontrivial_ctor = 1; } //expected-note 
{{candidate constructor not viable: call to __host__ function from __device__ 
function}}
+__device__ C cf_d; //expected-error {{no matching constructor for 
initialization of 'C'}}
+C cf_h;

``




https://github.com/llvm/llvm-project/pull/72815
___
cfe-commits mailing 

[clang] [CUDA][HIP] make trivial ctor/dtor host device (PR #72394)

2023-11-19 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

> > We've found a problem with the patch. https://godbolt.org/z/jcKo34vzG
> > ```
> > template 
> > class C {
> > explicit C() {};
> > };
> > 
> > template <> C::C() {};
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > ```
> > :6:21: error: __host__ function 'C' cannot overload __host__ 
> > __device__ function 'C'
> > 6 | template <> C::C() {};
> >   | ^
> > :3:14: note: previous declaration is here
> > 3 | explicit C() {};
> > ```
> 

fix by https://github.com/llvm/llvm-project/pull/72815



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


[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-19 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu created 
https://github.com/llvm/llvm-project/pull/72815

When deciding whether a previous function declaration is an overload or 
override, implicit host/device attrs should not be considered.

This fixes the failure for the following code:

`template 
class C {
explicit C() {};
};

template <> C::C() {};
`

The issue was introduced by https://github.com/llvm/llvm-project/pull/72394

sine the template specialization is treated as overload due to implicit 
host/device attrs are considered for overload/override differentiation.

>From 427b878d9196f85be5a1fd9d578b73c88dc2c185 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Sun, 19 Nov 2023 19:34:35 -0500
Subject: [PATCH] [CUDA][HIP] ignore implicit host/device attr for override

When deciding whether a previous function declaration is an
overload or override, implicit host/device attrs should
not be considered.

This fixes the failure for the following code:

`template 
class C {
explicit C() {};
};

template <> C::C() {};
`

The issue was introduced by https://github.com/llvm/llvm-project/pull/72394

sine the template specialization is treated as overload
due to implicit host/device attrs are considered for
overload/override differentiation.
---
 clang/lib/Sema/SemaCUDA.cpp  |  8 ++--
 clang/lib/Sema/SemaOverload.cpp  |  6 --
 .../SemaCUDA/implicit-member-target-inherited.cu |  1 +
 clang/test/SemaCUDA/trivial-ctor-dtor.cu | 16 
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index b94f448dabe7517..9dc63ff315a3926 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -1000,13 +1000,9 @@ void Sema::checkCUDATargetOverload(FunctionDecl *NewFD,
 // should have the same implementation on both sides.
 if (NewTarget != OldTarget &&
 ((NewTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(NewFD) &&
-OldTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(NewFD)) ||
  (OldTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(OldFD) &&
-NewTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(OldFD)) ||
  (NewTarget == CFT_Global) || (OldTarget == CFT_Global)) &&
 !IsOverload(NewFD, OldFD, /* UseMemberUsingDeclRules = */ false,
 /* ConsiderCudaAttrs = */ false)) {
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9800d7f1c9cfee9..a33acc184b75274 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1491,8 +1491,10 @@ static bool IsOverloadOrOverrideImpl(Sema , 
FunctionDecl *New,
 // Don't allow overloading of destructors.  (In theory we could, but it
 // would be a giant change to clang.)
 if (!isa(New)) {
-  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(New),
-   OldTarget = SemaRef.IdentifyCUDATarget(Old);
+  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(
+   New, /*IgnoreImplicitHDAttr=*/true),
+   OldTarget = SemaRef.IdentifyCUDATarget(
+   Old, /*IgnoreImplicitHDAttr=*/true);
   if (NewTarget != Sema::CFT_InvalidTarget) {
 assert((OldTarget != Sema::CFT_InvalidTarget) &&
"Unexpected invalid target.");
diff --git a/clang/test/SemaCUDA/implicit-member-target-inherited.cu 
b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
index 781199bba6b5a11..ceca0891fc9b03c 100644
--- a/clang/test/SemaCUDA/implicit-member-target-inherited.cu
+++ b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
@@ -39,6 +39,7 @@ struct A2_with_device_ctor {
 };
 // expected-note@-3 {{candidate constructor (the implicit copy constructor) 
not viable}}
 // expected-note@-4 {{candidate constructor (the implicit move constructor) 
not viable}}
+// expected-note@-4 {{candidate inherited constructor not viable: call to 
__device__ function from __host__ function}}
 
 struct B2_with_implicit_default_ctor : A2_with_device_ctor {
   using A2_with_device_ctor::A2_with_device_ctor;
diff --git a/clang/test/SemaCUDA/trivial-ctor-dtor.cu 
b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
index 1df8adc62bab590..21d698d28492ac3 100644
--- a/clang/test/SemaCUDA/trivial-ctor-dtor.cu
+++ b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
@@ -38,3 +38,19 @@ struct TC : TB {
 };
 
 __device__ TC tc; //expected-error {{dynamic initialization is not 
supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+// Check trivial ctor specialization
+template 
+struct C { //expected-note {{candidate constructor (the implicit copy 
constructor) 

[clang] [clang-format] Correctly annotate braces of empty functions (PR #72733)

2023-11-19 Thread Owen Pan via cfe-commits

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


[clang] edad025 - [clang-format] Correctly annotate braces of empty functions (#72733)

2023-11-19 Thread via cfe-commits

Author: Owen Pan
Date: 2023-11-19T15:10:27-08:00
New Revision: edad025d1e1f8043637c65fed91060b327e85313

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

LOG: [clang-format] Correctly annotate braces of empty functions (#72733)

Also fixed some existing test cases.

Fixed #57305.
Fixed #58251.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 06775b6df945887..cfca7c00312aab3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3477,6 +3477,19 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
 }
   }
 
+  if (IsCpp && LineIsFunctionDeclaration &&
+  Line.endsWith(tok::semi, tok::r_brace)) {
+auto *Tok = Line.Last->Previous;
+while (Tok->isNot(tok::r_brace))
+  Tok = Tok->Previous;
+if (auto *LBrace = Tok->MatchingParen; LBrace) {
+  assert(LBrace->is(tok::l_brace));
+  Tok->setBlockKind(BK_Block);
+  LBrace->setBlockKind(BK_Block);
+  LBrace->setFinalizedType(TT_FunctionLBrace);
+}
+  }
+
   if (IsCpp && SeenName && AfterLastAttribute &&
   mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
 AfterLastAttribute->MustBreakBefore = true;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 45f12d158089a36..67423f9b06fbc37 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3415,7 +3415,7 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) {
   verifyFormat("myFunc(public);");
   verifyFormat("std::vector testVec = {private};");
   verifyFormat("private.p = 1;");
-  verifyFormat("void function(private...){};");
+  verifyFormat("void function(private...) {};");
   verifyFormat("if (private && public)");
   verifyFormat("private &= true;");
   verifyFormat("int x = private * public;");
@@ -16093,16 +16093,16 @@ TEST_F(FormatTest, ZeroTabWidth) {
   Tab.IndentWidth = 8;
   Tab.UseTab = FormatStyle::UT_Never;
   Tab.TabWidth = 0;
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line starts with '\t'\n"
"};",
"void a(){\n"
"\t// line starts with '\t'\n"
"};",
Tab);
 
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line starts with '\t'\n"
"};",
"void a(){\n"
"\t\t// line starts with '\t'\n"
@@ -16110,16 +16110,16 @@ TEST_F(FormatTest, ZeroTabWidth) {
Tab);
 
   Tab.UseTab = FormatStyle::UT_ForIndentation;
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line starts with '\t'\n"
"};",
"void a(){\n"
"\t// line starts with '\t'\n"
"};",
Tab);
 
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line starts with '\t'\n"
"};",
"void a(){\n"
"\t\t// line starts with '\t'\n"
@@ -16127,16 +16127,16 @@ TEST_F(FormatTest, ZeroTabWidth) {
Tab);
 
   Tab.UseTab = FormatStyle::UT_ForContinuationAndIndentation;
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line starts with '\t'\n"
"};",
"void a(){\n"
"\t// line starts with '\t'\n"
"};",
Tab);
 
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line starts with '\t'\n"
"};",
"void a(){\n"
"\t\t// line starts with '\t'\n"
@@ -16144,16 +16144,16 @@ TEST_F(FormatTest, ZeroTabWidth) {
Tab);
 
   Tab.UseTab = FormatStyle::UT_AlignWithSpaces;
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line starts with '\t'\n"
"};",
"void a(){\n"
"\t// line starts with '\t'\n"
"};",
Tab);
 
-  verifyFormat("void a(){\n"
-   "// line starts with '\t'\n"
+  verifyFormat("void a() {\n"
+   "// line 

[clang] [clang-format] Fix a bug in isStartOfName() on macro definitions (PR #72768)

2023-11-19 Thread Owen Pan via cfe-commits

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


[clang] cb3a605 - [clang-format] Fix a bug in isStartOfName() on macro definitions (#72768)

2023-11-19 Thread via cfe-commits

Author: Owen Pan
Date: 2023-11-19T15:08:54-08:00
New Revision: cb3a605c5d453f9c6af8c44f84a11815aed7fe85

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

LOG: [clang-format] Fix a bug in isStartOfName() on macro definitions (#72768)

Fixed #72751.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1cc198ceec708d7..06775b6df945887 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2206,8 +2206,10 @@ class AnnotatingParser {
   return false;
 
 if (const auto *NextNonComment = Tok.getNextNonComment();
-!NextNonComment || NextNonComment->isPointerOrReference() ||
-NextNonComment->isOneOf(tok::identifier, tok::string_literal)) {
+(!NextNonComment && !Line.InMacroBody) ||
+(NextNonComment &&
+ (NextNonComment->isPointerOrReference() ||
+  NextNonComment->isOneOf(tok::identifier, tok::string_literal {
   return false;
 }
 

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a986806b7a44069..b6abf34c589b146 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2390,7 +2390,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsDoWhile) {
   EXPECT_TOKEN(Tokens[4], tok::kw_while, TT_DoWhile);
 }
 
-TEST_F(TokenAnnotatorTest, NotStartOfName) {
+TEST_F(TokenAnnotatorTest, StartOfName) {
   auto Tokens = annotate("#pragma clang diagnostic push");
   ASSERT_EQ(Tokens.size(), 6u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
@@ -2402,6 +2402,12 @@ TEST_F(TokenAnnotatorTest, NotStartOfName) {
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
   EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+
+  Tokens = annotate("#define FOO Foo foo");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName);
 }
 
 } // namespace



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


[clang] [clang-format] Fix a bug in aligning comments above PPDirective (PR #72791)

2023-11-19 Thread Owen Pan via cfe-commits

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


[clang] 5860d24 - [clang-format] Fix a bug in aligning comments above PPDirective (#72791)

2023-11-19 Thread via cfe-commits

Author: Owen Pan
Date: 2023-11-19T14:59:53-08:00
New Revision: 5860d248a780aaef860db3d54184b49fc758c3c1

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

LOG: [clang-format] Fix a bug in aligning comments above PPDirective (#72791)

Fixed #72785.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a6cd3c68e30bcaf..1cc198ceec708d7 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3123,8 +3123,8 @@ void TokenAnnotator::setCommentLineLevels(
 
 // If the comment is currently aligned with the line immediately following
 // it, that's probably intentional and we should keep it.
-if (NextNonCommentLine && !NextNonCommentLine->First->Finalized &&
-Line->isComment() && NextNonCommentLine->First->NewlinesBefore <= 1 &&
+if (NextNonCommentLine && NextNonCommentLine->First->NewlinesBefore < 2 &&
+Line->isComment() && !isClangFormatOff(Line->First->TokenText) &&
 NextNonCommentLine->First->OriginalColumn ==
 Line->First->OriginalColumn) {
   const bool PPDirectiveOrImportStmt =

diff  --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 967ffa32db79c75..9770d5090703c77 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -1069,6 +1069,17 @@ TEST_F(FormatTestComments, 
KeepsLevelOfCommentBeforePPDirective) {
"  // clang-format on\n"
"}");
   verifyNoChange(Code);
+
+  auto Style = getLLVMStyle();
+  Style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash;
+  verifyFormat("#ifdef FOO\n"
+   "  // Foo\n"
+   "  #define Foo foo\n"
+   "#else\n"
+   "  // Bar\n"
+   "  #define Bar bar\n"
+   "#endif",
+   Style);
 }
 
 TEST_F(FormatTestComments, SplitsLongLinesInComments) {



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


[clang] [clang-format][NFC] Skip alignArrayInitializers() for 1-row matrices (PR #72166)

2023-11-19 Thread Owen Pan via cfe-commits

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


[clang] e16a834 - [clang-format][NFC] Skip alignArrayInitializers() for 1-row matrices (#72166)

2023-11-19 Thread via cfe-commits

Author: Owen Pan
Date: 2023-11-19T14:58:44-08:00
New Revision: e16a8344d0efa33caddc147f9b316ba4734c99ff

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

LOG: [clang-format][NFC] Skip alignArrayInitializers() for 1-row matrices 
(#72166)

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.h
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index 69398fe411502f1..24fe492dcb0269b 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -202,7 +202,7 @@ class WhitespaceManager {
 // Determine if every row in the array
 // has the same number of columns.
 bool isRectangular() const {
-  if (CellCounts.empty())
+  if (CellCounts.size() < 2)
 return false;
 
   for (auto NumberOfColumns : CellCounts)

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b5021f924a80904..45f12d158089a36 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20884,13 +20884,15 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
"};",
Style);
   // TODO: Fix the indentations below when this option is fully functional.
+#if 0
   verifyFormat("int a[][] = {\n"
"{\n"
" {0, 2}, //\n"
-   " {1, 2}  //\n"
+   " {1, 2}  //\n"
"}\n"
"};",
Style);
+#endif
   Style.ColumnLimit = 100;
   verifyFormat(
   "test demo[] = {\n"



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


[clang] [NFC][Clang] Refactor code to calculate flexible array member size (PR #72790)

2023-11-19 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/72790

>From fcea607665cdbae3e98f08288b165c2c1af24f95 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Sun, 19 Nov 2023 02:28:28 -0800
Subject: [PATCH 1/2] [NFC][Clang] Refactor code to calculate flexible array
 member size

The code that calculates the flexible array member size is big enough to
warrant its own method.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 296 +++-
 clang/lib/CodeGen/CodeGenFunction.h |   3 +
 2 files changed, 159 insertions(+), 140 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 09309a3937fb613..b869bca7f07b85a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -822,6 +822,158 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const 
Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
+llvm::Value *
+CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type,
+ llvm::IntegerType *ResType) {
+  // The code generated here calculates the size of a struct with a flexible
+  // array member that uses the counted_by attribute. There are two instances
+  // we handle:
+  //
+  //   struct s {
+  // unsigned long flags;
+  // int count;
+  // int array[] __attribute__((counted_by(count)));
+  //   }
+  //
+  //   1) bdos of the flexible array itself:
+  //
+  // __builtin_dynamic_object_size(p->array, 1) ==
+  // p->count * sizeof(*p->array)
+  //
+  //   2) bdos of a pointer into the flexible array:
+  //
+  // __builtin_dynamic_object_size(>array[42], 1) ==
+  // (p->count - 42) * sizeof(*p->array)
+  //
+  //   2) bdos of the whole struct, including the flexible array:
+  //
+  // __builtin_dynamic_object_size(p, 1) ==
+  //max(sizeof(struct s),
+  //offsetof(struct s, array) + p->count * sizeof(*p->array))
+  //
+  const Expr *Base = E->IgnoreParenImpCasts();
+  const Expr *Idx = nullptr;
+
+  if (const auto *UO = dyn_cast(Base);
+  UO && UO->getOpcode() == UO_AddrOf) {
+if (const auto *ASE =
+dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+  Base = ASE->getBase();
+  Idx = ASE->getIdx()->IgnoreParenImpCasts();
+
+  if (const auto *IL = dyn_cast(Idx);
+  IL && !IL->getValue().getSExtValue())
+Idx = nullptr;
+}
+  }
+
+  const ValueDecl *CountedByFD = FindCountedByField(Base);
+  if (!CountedByFD)
+// Can't find the field referenced by the "counted_by" attribute.
+return nullptr;
+
+  // Build a load of the counted_by field.
+  bool IsSigned = CountedByFD->getType()->isSignedIntegerType();
+  const RecordDecl *OuterRD =
+  CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
+  ASTContext  = getContext();
+
+  // Load the counted_by field.
+  const Expr *CountedByExpr = BuildCountedByFieldExpr(Base, CountedByFD);
+  Value *CountedByInst = EmitAnyExprToTemp(CountedByExpr).getScalarVal();
+  llvm::Type *CountedByTy = CountedByInst->getType();
+
+  if (Idx) {
+// There's an index into the array. Remove it from the count.
+bool IdxSigned = Idx->getType()->isSignedIntegerType();
+Value *IdxInst = EmitAnyExprToTemp(Idx).getScalarVal();
+IdxInst = IdxSigned ? Builder.CreateSExtOrTrunc(IdxInst, CountedByTy)
+: Builder.CreateZExtOrTrunc(IdxInst, CountedByTy);
+
+// If the index is negative, don't subtract it from the counted_by
+// value. The pointer is pointing to something before the FAM.
+IdxInst = Builder.CreateNeg(IdxInst, "", !IdxSigned, IdxSigned);
+CountedByInst =
+Builder.CreateAdd(CountedByInst, IdxInst, "", !IsSigned, IsSigned);
+  }
+
+  // Get the size of the flexible array member's base type.
+  const ValueDecl *FAMDecl = nullptr;
+  if (const auto *ME = dyn_cast(Base)) {
+const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
+getLangOpts().getStrictFlexArraysLevel();
+if (const ValueDecl *MD = ME->getMemberDecl()) {
+  if (!Decl::isFlexibleArrayMemberLike(
+  Ctx, MD, MD->getType(), StrictFlexArraysLevel,
+  /*IgnoreTemplateOrMacroSubstitution=*/true))
+return nullptr;
+  // Base is referencing the FAM itself.
+  FAMDecl = MD;
+}
+  }
+
+  if (!FAMDecl)
+FAMDecl = FindFlexibleArrayMemberField(Ctx, OuterRD);
+
+  assert(FAMDecl && "Can't find the flexible array member field");
+
+  const ArrayType *ArrayTy = Ctx.getAsArrayType(FAMDecl->getType());
+  CharUnits Size = Ctx.getTypeSizeInChars(ArrayTy->getElementType());
+  llvm::Constant *ElemSize =
+  llvm::ConstantInt::get(CountedByTy, Size.getQuantity(), IsSigned);
+
+  // Calculate how large the flexible array member is in bytes.
+  Value *FAMSize =
+  Builder.CreateMul(CountedByInst, ElemSize, "", !IsSigned, IsSigned);
+  FAMSize = 

[llvm] [clang] Fix python escapes (PR #71170)

2023-11-19 Thread Nathan Sidwell via cfe-commits

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


[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2023-11-19 Thread Fangrui Song via cfe-commits

MaskRay wrote:

GCC's default spec file for Linux does not say how `-export-dynamic` translates 
to ld `-export-dynamic`.

I think ld `--export-dynamic` is exclusively caused by `-Wl,--export-dynamic` 
or `-rdynamic`.
Do you have any example of `gcc -export-dynamic` uses?

We probably should just reject `-exxx`: 
https://github.com/llvm/llvm-project/pull/72804


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


[clang] [Driver] Allow -e entry but reject -eentry (PR #72804)

2023-11-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

This short option taking an argument is unfortunate.

* If a cc1-only option starts with `-e`, using it for driver will not be
  reported as an error (e.g. commit
  6cd9886c88d16d288c74846495d89f2fe84ff827).
* If another `-e` driver option is intended but a typo is made, the
  option will be recognized as a `-e`.

`gcc -export-dynamic` passes `-export-dynamic` to ld. It's not clear
whether some options behave this way.

It seems `-Wl,-eentry` and `-Wl,--entry=entry` are primarily used. There
may also be a few `gcc -e entry`, but `gcc -eentry` is extremely rare or
not used at all. Therefore, we probably should reject the Joined form of
`-e`.


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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (added) clang/test/Driver/entry.s (+5) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296a..83b09a892049bb6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1452,7 +1452,7 @@ def extract_api_ignores_EQ: CommaJoined<["--"], 
"extract-api-ignores=">,
   Visibility<[ClangOption, CC1Option]>,
 HelpText<"Comma separated list of files containing a new line separated 
list of API symbols to ignore when extracting API information.">,
 MarshallingInfoStringVector>;
-def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
+def e : Separate<["-"], "e">, Flags<[LinkerInput]>, Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
diff --git a/clang/test/Driver/entry.s b/clang/test/Driver/entry.s
new file mode 100644
index 000..60ab89704c35462
--- /dev/null
+++ b/clang/test/Driver/entry.s
@@ -0,0 +1,5 @@
+/// To prevent mistaking -exxx as --entry=xxx, we allow -e xxx but reject 
-exxx.
+/// GCC -export-dynamic is rejected as well.
+// RUN: not %clang -### --target=x86_64-linux-gnu -export-dynamic %s 2>&1 | 
FileCheck %s
+
+// CHECK: error: unknown argument: '-export-dynamic'

``




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


[clang] [Driver] Allow -e entry but reject -eentry (PR #72804)

2023-11-19 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/72804

This short option taking an argument is unfortunate.

* If a cc1-only option starts with `-e`, using it for driver will not be
  reported as an error (e.g. commit
  6cd9886c88d16d288c74846495d89f2fe84ff827).
* If another `-e` driver option is intended but a typo is made, the
  option will be recognized as a `-e`.

`gcc -export-dynamic` passes `-export-dynamic` to ld. It's not clear
whether some options behave this way.

It seems `-Wl,-eentry` and `-Wl,--entry=entry` are primarily used. There
may also be a few `gcc -e entry`, but `gcc -eentry` is extremely rare or
not used at all. Therefore, we probably should reject the Joined form of
`-e`.


>From 31da211e0566e7254c9cff615eb9ca17106b5923 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sun, 19 Nov 2023 10:32:54 -0800
Subject: [PATCH] [Driver] Allow -e entry but reject -eentry

This short option taking an argument is unfortunate.

* If a cc1-only option starts with `-e`, using it for driver will not be
  reported as an error (e.g. commit
  6cd9886c88d16d288c74846495d89f2fe84ff827).
* If another `-e` driver option is intended but a typo is made, the
  option will be recognized as a `-e`.

`gcc -export-dynamic` passes `-export-dynamic` to ld. It's not clear
whether some options behave this way.

It seems `-Wl,-eentry` and `-Wl,--entry=entry` are primarily used. There
may also be a few `gcc -e entry`, but `gcc -eentry` is extremely rare or
not used at all. Therefore, we probably should reject the Joined form of
`-e`.
---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/Driver/entry.s | 5 +
 2 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/entry.s

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296a..83b09a892049bb6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1452,7 +1452,7 @@ def extract_api_ignores_EQ: CommaJoined<["--"], 
"extract-api-ignores=">,
   Visibility<[ClangOption, CC1Option]>,
 HelpText<"Comma separated list of files containing a new line separated 
list of API symbols to ignore when extracting API information.">,
 MarshallingInfoStringVector>;
-def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
+def e : Separate<["-"], "e">, Flags<[LinkerInput]>, Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
diff --git a/clang/test/Driver/entry.s b/clang/test/Driver/entry.s
new file mode 100644
index 000..60ab89704c35462
--- /dev/null
+++ b/clang/test/Driver/entry.s
@@ -0,0 +1,5 @@
+/// To prevent mistaking -exxx as --entry=xxx, we allow -e xxx but reject 
-exxx.
+/// GCC -export-dynamic is rejected as well.
+// RUN: not %clang -### --target=x86_64-linux-gnu -export-dynamic %s 2>&1 | 
FileCheck %s
+
+// CHECK: error: unknown argument: '-export-dynamic'

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


[clang] 5603bb5 - [test] Fix misused Joined -e options

2023-11-19 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-11-19T10:38:49-08:00
New Revision: 5603bb5f5001e88a490b8f9c11c6e8969037183b

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

LOG: [test] Fix misused Joined -e options

Some tests for the obsoleted NaCl misuse the -e for linking.

Added: 


Modified: 
clang/test/Driver/lanai-unknown-unknown.cpp
clang/test/Driver/wasm32-unknown-unknown.cpp
clang/test/Driver/wasm64-unknown-unknown.cpp
clang/test/Driver/x86_64-nacl-defines.cpp

Removed: 
clang/test/Driver/mipsel-nacl-defines.cpp



diff  --git a/clang/test/Driver/lanai-unknown-unknown.cpp 
b/clang/test/Driver/lanai-unknown-unknown.cpp
index 220a84f9eb2de03..103ccabab0d306f 100644
--- a/clang/test/Driver/lanai-unknown-unknown.cpp
+++ b/clang/test/Driver/lanai-unknown-unknown.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang -target lanai-unknown-unknown -### %s -emit-llvm-only -c 2>&1 \
+// RUN: %clang --target=lanai-unknown-unknown -### %s -c 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=ECHO
-// RUN: %clang -target lanai-unknown-unknown %s -emit-llvm -S -o - \
+// RUN: %clang --target=lanai-unknown-unknown %s -emit-llvm -S -o - \
 // RUN:   | FileCheck %s
 
 // ECHO: {{.*}} "-cc1" {{.*}}lanai-unknown-unknown.c

diff  --git a/clang/test/Driver/mipsel-nacl-defines.cpp 
b/clang/test/Driver/mipsel-nacl-defines.cpp
deleted file mode 100644
index 0f63d7659e518f7..000
--- a/clang/test/Driver/mipsel-nacl-defines.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// RUN: %clang -target mipsel-unknown-nacl -### %s -emit-llvm-only -c -o %t.o 
2>&1 | FileCheck %s -check-prefix=ECHO
-// RUN: %clang -target mipsel-unknown-nacl %s -emit-llvm -S -c -o - | 
FileCheck %s
-// RUN: %clang -target mipsel-unknown-nacl %s -emit-llvm -S -c -pthread -o - | 
FileCheck %s -check-prefix=THREADS
-
-// ECHO: {{.*}} "-cc1" {{.*}}mipsel-nacl-defines.c
-
-// Check platform defines
-
-// CHECK: _MIPSELdefined
-#ifdef _MIPSEL
-void _MIPSELdefined() {}
-#endif
-
-// CHECK: _mipsdefined
-#ifdef _mips
-void _mipsdefined() {}
-#endif
-
-// CHECK: __native_client__defined
-#ifdef __native_client__
-void __native_client__defined() {}
-#endif
-
-// CHECK: unixdefined
-#ifdef unix
-void unixdefined() {}
-#endif
-
-// CHECK: __ELF__defined
-#ifdef __ELF__
-void __ELF__defined() {}
-#endif
-
-// CHECK: _GNU_SOURCEdefined
-#ifdef _GNU_SOURCE
-void _GNU_SOURCEdefined() {}
-#endif
-
-// THREADS: _REENTRANTdefined
-// CHECK: _REENTRANTundefined
-#ifdef _REENTRANT
-void _REENTRANTdefined() {}
-#else
-void _REENTRANTundefined() {}
-#endif

diff  --git a/clang/test/Driver/wasm32-unknown-unknown.cpp 
b/clang/test/Driver/wasm32-unknown-unknown.cpp
index 90b58503faf9a06..73b015c39f4af1a 100644
--- a/clang/test/Driver/wasm32-unknown-unknown.cpp
+++ b/clang/test/Driver/wasm32-unknown-unknown.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang -target wasm32-unknown-unknown -### %s -emit-llvm-only -c 2>&1 \
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -c 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=ECHO
 // RUN: %clang -target wasm32-unknown-unknown %s -emit-llvm -S -o - \
 // RUN:   | FileCheck %s

diff  --git a/clang/test/Driver/wasm64-unknown-unknown.cpp 
b/clang/test/Driver/wasm64-unknown-unknown.cpp
index 9ee4a1b566d028a..25d382cb64d1e6e 100644
--- a/clang/test/Driver/wasm64-unknown-unknown.cpp
+++ b/clang/test/Driver/wasm64-unknown-unknown.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang -target wasm64-unknown-unknown -### %s -emit-llvm-only -c 2>&1 \
+// RUN: %clang --target=wasm64-unknown-unknown -### %s -c 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=ECHO
 // RUN: %clang -target wasm64-unknown-unknown %s -emit-llvm -S -o - \
 // RUN:   | FileCheck %s

diff  --git a/clang/test/Driver/x86_64-nacl-defines.cpp 
b/clang/test/Driver/x86_64-nacl-defines.cpp
index 87d02d7e10f7d6a..1b29fc7922419b9 100644
--- a/clang/test/Driver/x86_64-nacl-defines.cpp
+++ b/clang/test/Driver/x86_64-nacl-defines.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang -target x86_64-unknown-nacl -### %s -emit-llvm-only -c -o %t.o 
2>&1 | FileCheck %s -check-prefix=ECHO
+// RUN: %clang --target=x86_64-unknown-nacl -### %s -c -o %t.o 2>&1 | 
FileCheck %s -check-prefix=ECHO
 // RUN: %clang -target x86_64-unknown-nacl %s -emit-llvm -S -c -o - | 
FileCheck %s
 // RUN: %clang -target x86_64-unknown-nacl %s -emit-llvm -S -c -pthread -o - | 
FileCheck %s -check-prefix=THREADS
 



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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-19 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

> @PiotrZSL I have implemented the changes you have requested, but because of 
> #72536, I am not going to push those changes yet, unless you prefer it if I 
> do. I might take a look into fixing this issue. I came across this when I 
> checked what would happen when the big templated function was instantiated, 
> just to be sure the test would pass.

TK_IgnoreUnlessSpelledInSource should do a trick. I will re-check this review 
in some near free time.

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


[clang] [clang-format] Correctly annotate braces of empty functions (PR #72733)

2023-11-19 Thread Emilia Kond via cfe-commits

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

wow!

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-19 Thread Björn Schäpers via cfe-commits


@@ -1308,6 +1308,13 @@ class OptimizingLineFormatter : public LineFormatter {
 
 } // anonymous namespace
 
+static bool lineContainsPPDefinition(const AnnotatedLine ) {

HazardyKnusperkeks wrote:

```suggestion
static bool LineContainsPPDefinition(const AnnotatedLine ) {
```
Code style.

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-19 Thread Björn Schäpers via cfe-commits


@@ -24153,6 +24153,113 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   verifyNoChange("FOO(String-ized+But: :Still=Intentional);", Style);
 }
 
+TEST_F(FormatTest, IgnorePPDefinitions) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IgnorePPDefinitions = true;
+
+  verifyNoChange("#define  A", Style);
+  verifyNoChange("#define A   b", Style);
+  verifyNoChange("#define A  (  args   )", Style);
+  verifyNoChange("#define A  (  args   )  =  func  (  args  )", Style);
+
+  verifyNoChange("#define A x:", Style);
+  verifyNoChange("#define A a. b", Style);
+
+  // Surrounded with formatted code.
+  verifyFormat("int a;\n"
+   "#define  A  a\n"
+   "int a;",
+   "int  a ;\n"

HazardyKnusperkeks wrote:

It's often hard to see that comma. That's what probably happened here.

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-19 Thread Björn Schäpers via cfe-commits


@@ -1355,6 +1362,10 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+
+if (Style.IgnorePPDefinitions && lineContainsPPDefinition(TheLine))
+  ShouldFormat = false;

HazardyKnusperkeks wrote:

```suggestion
bool ShouldFormat = (TheLine.Affected || FixIndentation) && 
(!Style.IgnorePPDefinitions || lineContainsPPDefinition(TheLine));
```
Maybe? Don't know which is better.

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-19 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

@PiotrZSL I have implemented the changes you have requested, but because of 
#72536, I am not going to push those changes yet, unless you prefer it if I do. 
I might take a look into fixing this issue.
I came across this when I checked what would happen when the big templated 
function was instantiated, just to be sure the test would pass.

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


[clang] [clang-format] Fix a bug in aligning comments above PPDirective (PR #72791)

2023-11-19 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Fix a bug in isStartOfName() on macro definitions (PR #72768)

2023-11-19 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Correctly annotate braces of empty functions (PR #72733)

2023-11-19 Thread Björn Schäpers via cfe-commits

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


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


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

2023-11-19 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Since the other PR turned out to be infeasible, I'm overriding 
`TraversePseudoObjectExpr` now.

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


[clang-tools-extra] [clangd] Don't show inlay hints for __builtin_dump_struct (PR #71366)

2023-11-19 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/71366

>From 808c141c34218dd542b00149216adc061567dd31 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 6 Nov 2023 16:50:02 +0800
Subject: [PATCH 1/4] [clangd] Don't show inlay hints for PseudoObjectExprs in
 C++

This closes https://github.com/clangd/clangd/issues/1813.

PseudoObjectExprs in C++ are currently not very interesting but probably
mess up inlay hints.
---
 clang-tools-extra/clangd/InlayHints.cpp   | 13 ++
 .../clangd/unittests/InlayHintTests.cpp   | 24 +++
 2 files changed, 37 insertions(+)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 3da047f954213856..867c70e5dbc80c65 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -589,6 +589,19 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool dataTraverseStmtPre(Stmt *S) {
+// Do not show inlay hints for PseudoObjectExprs. They're never
+// genuine user codes in C++.
+//
+// For example, __builtin_dump_struct would expand to a PseudoObjectExpr
+// that includes a couple of calls to a printf function. Printing parameter
+// names for that anyway would end up with duplicate parameter names 
(which,
+// however, got de-duplicated after visiting) for the printf function.
+if (AST.getLangOpts().CPlusPlus && isa(S))
+  return false;
+return true;
+  }
+
   bool VisitCallExpr(CallExpr *E) {
 if (!Cfg.InlayHints.Parameters)
   return true;
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 20c1cdd985dbc017..2b6c27b17b537a96 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1724,6 +1724,30 @@ TEST(InlayHints, RestrictRange) {
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, PseudoObjectExpr) {
+  Annotations Code(R"cpp(
+struct S {
+  __declspec(property(get=GetX, put=PutX)) int x[];
+  int GetX(int y, int z) { return 42 + y; }
+  void PutX(int y) { x = y; } // Not `x = y: y`
+};
+
+int printf(const char *Format, ...);
+
+int main() {
+  S s;
+  __builtin_dump_struct(, printf); // Not `Format: 
__builtin_dump_struct()`
+  printf($Param[["Hello, %d"]], 42); // Normal calls are not affected.
+  return s.x[1][2]; // Not `x[y: 1][z: 2]`
+}
+  )cpp");
+  auto TU = TestTU::withCode(Code.code());
+  TU.ExtraArgs.push_back("-fms-extensions");
+  auto AST = TU.build();
+  EXPECT_THAT(inlayHints(AST, std::nullopt),
+  ElementsAre(HintMatcher(ExpectedHint{"Format: ", "Param"}, 
Code)));
+}
+
 TEST(ParameterHints, ArgPacksAndConstructors) {
   assertParameterHints(
   R"cpp(

>From f15e35f67e23e742536ca2fe7229f5b6cba8f6b8 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 6 Nov 2023 17:32:50 +0800
Subject: [PATCH 2/4] Don't make the patch C++-specific

---
 clang-tools-extra/clangd/InlayHints.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 867c70e5dbc80c65..1b54b570c1c5d4fc 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -591,13 +591,13 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 
   bool dataTraverseStmtPre(Stmt *S) {
 // Do not show inlay hints for PseudoObjectExprs. They're never
-// genuine user codes in C++.
+// genuine user codes.
 //
 // For example, __builtin_dump_struct would expand to a PseudoObjectExpr
 // that includes a couple of calls to a printf function. Printing parameter
 // names for that anyway would end up with duplicate parameter names 
(which,
 // however, got de-duplicated after visiting) for the printf function.
-if (AST.getLangOpts().CPlusPlus && isa(S))
+if (isa(S))
   return false;
 return true;
   }

>From 8813a4f11254f89feb72e435888d896911a5dc78 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 7 Nov 2023 14:22:07 +0800
Subject: [PATCH 3/4] Only apply the restriction to __builtin_dump_struct

---
 clang-tools-extra/clangd/InlayHints.cpp| 18 +-
 .../clangd/unittests/InlayHintTests.cpp|  9 ++---
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 1b54b570c1c5d4fc..9897d1c1e6da209e 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -590,15 +590,15 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   }
 
   bool dataTraverseStmtPre(Stmt *S) {
-// Do not show inlay hints for PseudoObjectExprs. They're never
-// genuine user codes.
-   

[clang] [clang] Reject incomplete type arguments for __builtin_dump_struct (PR #72749)

2023-11-19 Thread Younan Zhang via cfe-commits


@@ -713,6 +713,11 @@ static ExprResult SemaBuiltinDumpStruct(Sema , CallExpr 
*TheCall) {
 return ExprError();
   }
   const RecordDecl *RD = PtrArgType->getPointeeType()->getAsRecordDecl();
+  if (!RD->isCompleteDefinition()) {

zyn0217 wrote:

Thank you! Added the template case to the test.

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


[clang] [clang] Reject incomplete type arguments for __builtin_dump_struct (PR #72749)

2023-11-19 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/72749

>From d23305db7faba1ed1464aeee6d9e0f2ee1994226 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 6 Nov 2023 16:50:02 +0800
Subject: [PATCH 1/2] [clang] Reject incomplete type arguments for
 __builtin_dump_struct

We used to assume that the CXXRecordDecl passed to the 1st argument
always had a definition. This is not true since a pointer to an
incomplete type was not excluded.
---
 clang/docs/LanguageExtensions.rst  | 2 +-
 clang/docs/ReleaseNotes.rst| 3 +++
 clang/lib/Sema/SemaChecking.cpp| 5 +
 clang/test/SemaCXX/builtin-dump-struct.cpp | 4 
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 30e288f986782fd..e80a096357b1deb 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2809,7 +2809,7 @@ Example output:
 
 The ``__builtin_dump_struct`` function is used to print the fields of a simple
 structure and their values for debugging purposes. The first argument of the
-builtin should be a pointer to the struct to dump. The second argument ``f``
+builtin should be a pointer to a complete record type to dump. The second 
argument ``f``
 should be some callable expression, and can be a function object or an overload
 set. The builtin calls ``f``, passing any further arguments ``args...``
 followed by a ``printf``-compatible format string and the corresponding
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 74358219ba9fb22..f2903c1684dcb60 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -691,6 +691,9 @@ Bug Fixes to C++ Support
   Fixes:
   (`#68769 `_)
 
+- Clang now rejects incomplete types for ``__builtin_dump_struct``. Fixes:
+  (`#63506 `_)
+
 - Clang now defers the instantiation of explicit specifier until constraint 
checking
   completes (except deduction guides). Fixes:
   (`#59827 `_)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ae588db02bbe722..20ff3ce722da80a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -713,6 +713,11 @@ static ExprResult SemaBuiltinDumpStruct(Sema , CallExpr 
*TheCall) {
 return ExprError();
   }
   const RecordDecl *RD = PtrArgType->getPointeeType()->getAsRecordDecl();
+  if (!RD->isCompleteDefinition()) {
+S.Diag(PtrArgResult.get()->getBeginLoc(), diag::err_incomplete_type)
+<< PtrArgType->getPointeeType();
+return ExprError();
+  }
 
   // Second argument is a callable, but we can't fully validate it until we try
   // calling it.
diff --git a/clang/test/SemaCXX/builtin-dump-struct.cpp 
b/clang/test/SemaCXX/builtin-dump-struct.cpp
index b3d2a2d808ce267..477bbcf07a41fa4 100644
--- a/clang/test/SemaCXX/builtin-dump-struct.cpp
+++ b/clang/test/SemaCXX/builtin-dump-struct.cpp
@@ -149,7 +149,10 @@ B {
 }
 )"[1]);
 
+class Incomplete;
+
 void errors(B b) {
+  ConstexprString cs;
   __builtin_dump_struct(); // expected-error {{too few arguments to function 
call, expected 2, have 0}}
   __builtin_dump_struct(1); // expected-error {{too few arguments to function 
call, expected 2, have 1}}
   __builtin_dump_struct(1, 2); // expected-error {{expected pointer to struct 
as 1st argument to '__builtin_dump_struct', found 'int'}}
@@ -157,6 +160,7 @@ void errors(B b) {
   __builtin_dump_struct(, Format, 0); // expected-error {{no matching 
function for call to 'Format'}}
 // expected-note@-1 {{in call to 
printing function with arguments '(0, "%s", "B")' while dumping struct}}
 // expected-note@#Format {{no known 
conversion from 'int' to 'ConstexprString &' for 1st argument}}
+  __builtin_dump_struct((Incomplete *)nullptr, Format, cs); // expected-error 
{{incomplete type 'Incomplete' where a complete type is required}}
 }
 #endif
 

>From e0bbbd2e5518a98936e1b6f51e8fff66018a7183 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 19 Nov 2023 23:38:50 +0800
Subject: [PATCH 2/2] Use Sema::RequireCompleteType.

---
 clang/lib/Sema/SemaChecking.cpp| 12 ++--
 clang/test/SemaCXX/builtin-dump-struct.cpp | 10 +-
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 20ff3ce722da80a..9f90585b3b7d8cb 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -712,13 +712,13 @@ static ExprResult SemaBuiltinDumpStruct(Sema , CallExpr 
*TheCall) {
 << 1 << TheCall->getDirectCallee() << PtrArgType;
 return ExprError();
   }
-  const RecordDecl *RD = PtrArgType->getPointeeType()->getAsRecordDecl();
-  if 

[clang] [CUDA][HIP] make trivial ctor/dtor host device (PR #72394)

2023-11-19 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

> We've found a problem with the patch. https://godbolt.org/z/jcKo34vzG
> 
> ```
> template 
> class C {
> explicit C() {};
> };
> 
> template <> C::C() {};
> ```
> 
> ```
> :6:21: error: __host__ function 'C' cannot overload __host__ 
> __device__ function 'C'
> 6 | template <> C::C() {};
>   | ^
> :3:14: note: previous declaration is here
> 3 | explicit C() {};
> ```

I will take a look. Thanks.

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-19 Thread Kiran Chandramohan via cfe-commits


@@ -85,6 +85,19 @@ class CodeGenOptions : public CodeGenOptionsBase {
 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
   };
 
+  /// \brief Enumeration value for AMDGPU code object version, which is the
+  /// code object version times 100.
+  enum class CodeObjectVersionKind {
+COV_None,
+COV_2 = 200, // Unsupported.
+COV_3 = 300, // Unsupported.
+COV_4 = 400,
+COV_5 = 500,
+  };

kiranchandramohan wrote:

If possible move this to `llvm/include/llvm/Frontend/Driver/TargetOptions.h`.

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


[clang-tools-extra] [clang] [clang] Turn invented Exprs' source locations in __builtin_dump_struct to empty (PR #72750)

2023-11-19 Thread Younan Zhang via cfe-commits

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


[clang] [clang-tools-extra] [clang] Turn invented Exprs' source locations in __builtin_dump_struct to empty (PR #72750)

2023-11-19 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> The CI run shows the test 
> [Sema/builtin-dump-struct.c](https://searchfox.org/llvm/source/clang/test/Sema/builtin-dump-struct.c)
>  is failing.

Oops, I didn't even realize there's such a test for C. I had only run the 
Sema/builtin-dump-struct.cpp locally and it passed. :(

> I guess this means the approach of using an invalid SourceLocation doesn't 
> work after all?
 
The answer seems no to me. At least we have to preserve these source locations 
at the Sema level to produce the diagnoses. As to the other approach involving 
"virtual buffers", I think that requires a more drastic change. I.e. moving the 
printf function generation to the tokenization level.

Closing this PR now and sorry for the churn!

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


[PATCH] D153701: [Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-11-19 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

In D153701#4656920 , @Endill wrote:

> @yronglin We are sorry it takes so much time to get feedback. Richard and 
> Hubert have little bandwidth for reviews. Others, including me, don't feel 
> qualified to provide good feedback.

@Endill Thanks for your reply, let's wait for them have time. You are clang 
experts, please feel free to comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153701/new/

https://reviews.llvm.org/D153701

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


[libcxx] [clang-tools-extra] [flang] [libc] [llvm] [compiler-rt] [clang] [C23] Complete support for WG14 N2508 (PR #71398)

2023-11-19 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/71398

>From 1d54a5cc6b34aca0e34ab57d7ee62815707d9153 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 6 Nov 2023 08:54:40 -0500
Subject: [PATCH 1/4] [C23] Complete support for WG14 N2508

In Clang 16, we implemented the ability to add a label at the end of
a compound statement. These changes complete the implementation by
allowing a label to be followed by a declaration in C.

Note, this seems to have fixed an issue with some OpenMP stand-alone
directives not being properly diagnosed as per:
https://www.openmp.org/spec-html/5.1/openmpsu19.html#x34-330002.1.3
(The same requirement exists in OpenMP 5.2 as well.)
---
 clang/docs/ReleaseNotes.rst   | 22 
 .../clang/Basic/DiagnosticParseKinds.td   |  6 
 clang/include/clang/Parse/Parser.h|  9 ++---
 clang/lib/Parse/ParseOpenMP.cpp   |  4 +--
 clang/lib/Parse/ParseStmt.cpp | 34 ---
 clang/test/C/C2x/n2508.c  | 11 ++
 clang/test/OpenMP/barrier_ast_print.cpp   | 24 -
 clang/test/OpenMP/barrier_messages.cpp|  8 ++---
 clang/test/OpenMP/cancel_messages.cpp |  6 ++--
 .../OpenMP/cancellation_point_messages.cpp|  6 ++--
 clang/test/OpenMP/depobj_messages.cpp |  8 ++---
 clang/test/OpenMP/error_message.cpp   | 10 +++---
 clang/test/OpenMP/flush_messages.cpp  |  8 ++---
 clang/test/OpenMP/scan_messages.cpp   | 10 +++---
 clang/test/OpenMP/taskwait_messages.cpp   |  8 ++---
 clang/test/OpenMP/taskyield_messages.cpp  |  8 ++---
 clang/www/c_status.html   |  2 +-
 17 files changed, 121 insertions(+), 63 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index afe7e2e79c2d087..91f4c90fc9b0e24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -209,6 +209,12 @@ C23 Feature Support
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
 
+- Completed the implementation of
+  `N2508 `_. We
+  previously implemented allowing a label at the end of a compound statement,
+  and now we've implemented allowing a label to be followed by a declaration
+  instead of a statement.
+
 Non-comprehensive list of changes in this release
 -
 
@@ -541,6 +547,22 @@ Bug Fixes in This Version
   Fixes (`#67687 `_)
 - Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
   Fixes (`#67317 `_)
+- Clang now properly diagnoses use of stand-alone OpenMP directives after a
+  label (including ``case`` or ``default`` labels).
+
+  Before:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // ok
+
+  After:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // error: '#pragma omp barrier' cannot be an immediate 
substatement
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index de180344fcc5c74..2bc72acc1375143 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;
 def ext_c_label_end_of_compound_statement : ExtWarn<
   "label at end of compound statement is a C23 extension">,
InGroup;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 30e0352c868637b..22e8c4ceea39cd6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -410,18 +410,15 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
-/// This context permits declarations in language modes where declarations
-/// are not statements.
-AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x2,
+AllowStandaloneOpenMPDirectives = 0x1,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x4,
+InStmtExpr = 0x2,
 
 /// The context of a regular 

[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-19 Thread Andrzej Warzyński via cfe-commits




banach-space wrote:

All test files in this PR use hyphen (`-`) rather than underscore (`_`) ;-)

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-19 Thread Andrzej Warzyński via cfe-commits


@@ -264,6 +263,37 @@ static void addDepdendentLibs(mlir::ModuleOp ,
   }
 }
 
+// Add to MLIR code target specific items which are dependent on target
+// configuration specified by the user
+static void addTargetSpecificMLIRItems(mlir::ModuleOp ,
+   CompilerInstance ) {
+  const TargetOptions  = ci.getInvocation().getTargetOpts();
+  const llvm::Triple triple(targetOpts.triple);
+  if (triple.isAMDGPU()) {
+unsigned oclcABIVERsion;
+const unsigned defaultOclcABIVERsion = 400;
+mlir::OpBuilder builder(mlirModule.getContext());
+const CodeGenOptions  = ci.getInvocation().getCodeGenOpts();
+if (codeGenOpts.CodeObjectVersion ==
+CodeGenOptions::CodeObjectVersionKind::COV_None)
+  oclcABIVERsion = defaultOclcABIVERsion;
+else
+  oclcABIVERsion = static_cast(codeGenOpts.CodeObjectVersion);
+
+auto int32Type = builder.getI32Type();
+auto covInfo = builder.create(
+mlirModule.getLoc(), int32Type, true, mlir::LLVM::Linkage::WeakODR,
+"__oclc_ABI_version",
+builder.getIntegerAttr(int32Type, oclcABIVERsion));
+covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
+covInfo.setAddrSpace(4);
+covInfo.setVisibility_(mlir::LLVM::Visibility::Hidden);
+builder.setInsertionPointToStart(mlirModule.getBody());
+builder.insert(covInfo);
+  }
+  addDependentLibs(mlirModule, ci);

banach-space wrote:

My terminology might be off, but:
* most of this function adds some specific to a particular hardware _target_ 
(i.e. AMDGPU),
* `addDependentLibs` is something linked to specific to a particular _platform_ 
(i.e. MSVC/Windows).

My suggestion:
* keep `addDependentLibs` as an independent hook,
* rename `addTargetSpecificMLIRItems` as `addAMDGPUSpecificMLIRItems` (we can 
rename this later if people want to add support for other targets).

@jsjodin - is that consistent with what you had in mind?

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-19 Thread Andrzej Warzyński via cfe-commits


@@ -85,6 +85,19 @@ class CodeGenOptions : public CodeGenOptionsBase {
 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
   };
 
+  /// \brief Enumeration value for AMDGPU code object version, which is the
+  /// code object version times 100.
+  enum class CodeObjectVersionKind {
+COV_None,
+COV_2 = 200, // Unsupported.
+COV_3 = 300, // Unsupported.

banach-space wrote:

What does `COV` stand for and what does `unsupported` mean in this context? Why 
list any unsupported versions? Isn't it a bit like:
*  `400` and `500` _are supported_, and
* everything else is _not supported_?

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


[clang] [flang] [Flang] Add code-object-version option (PR #72638)

2023-11-19 Thread Andrzej Warzyński via cfe-commits


@@ -264,6 +263,37 @@ static void addDepdendentLibs(mlir::ModuleOp ,
   }
 }
 
+// Add to MLIR code target specific items which are dependent on target
+// configuration specified by the user
+static void addTargetSpecificMLIRItems(mlir::ModuleOp ,
+   CompilerInstance ) {
+  const TargetOptions  = ci.getInvocation().getTargetOpts();
+  const llvm::Triple triple(targetOpts.triple);
+  if (triple.isAMDGPU()) {

banach-space wrote:

Please avoid indentation where possible 
(https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code):

```suggestion
  if (! triple.isAMDGPU())
return
```

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


[flang] [clang] [Flang][Clang] Add support for frame pointers in Flang Driver (PR #72146)

2023-11-19 Thread Andrzej Warzyński via cfe-commits


@@ -960,7 +1099,7 @@ bool tools::addOpenMPRuntime(ArgStringList , const 
ToolChain ,
 CmdArgs.push_back("-Bdynamic");
 
   if (RTKind == Driver::OMPRT_GOMP && GompNeedsRT)
-  CmdArgs.push_back("-lrt");
+CmdArgs.push_back("-lrt");

banach-space wrote:

This and the following changes in this file are unrelated and merely formatting 
fixes. Please, could you reduce the noise and revert these? I am happy for you 
to submit them as a separate PR.

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


[flang] [clang] [Flang][Clang] Add support for frame pointers in Flang Driver (PR #72146)

2023-11-19 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

> Could you add some tests? In e.g. "driver-help.f90" we merely test that a 
> flag is visible.

I see that you added 
[frame-pointer-codegen.f90](https://github.com/llvm/llvm-project/pull/72146/files#diff-76ca50365c8a0eb4797ce10b121021e7da52cc86523d806e1ade530a897de7e8),
 but that does not test how flags added in this patch impact code-gen. Please 
add a test that will demonstrate how this flag impacts the generated code.

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


[clang] [flang] [flang] Add runtimes using --dependent-lib on MSVC targets (PR #72519)

2023-11-19 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,36 @@
+! RUN: %flang -### --target=aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 
-v 2>&1 | FileCheck %s --check-prefixes=MSVC

banach-space wrote:

Could you remind the rationale behind an empty `-fuse-ld=`?

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


[flang] [clang] [flang] Add runtimes using --dependent-lib on MSVC targets (PR #72519)

2023-11-19 Thread Andrzej Warzyński via cfe-commits


@@ -977,47 +977,10 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
+void tools::addFortranRuntimeLibs(const ToolChain ,
   llvm::opt::ArgStringList ) {
-  if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-CmdArgs.push_back(Args.MakeArgString(
-"/DEFAULTLIB:" + TC.getCompilerRTBasename(Args, "builtins")));
-unsigned RTOptionID = options::OPT__SLASH_MT;
-if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
-  RTOptionID = llvm::StringSwitch(rtl->getValue())
-   .Case("static", options::OPT__SLASH_MT)
-   .Case("static_dbg", options::OPT__SLASH_MTd)
-   .Case("dll", options::OPT__SLASH_MD)
-   .Case("dll_dbg", options::OPT__SLASH_MDd)
-   .Default(options::OPT__SLASH_MT);
-}
-switch (RTOptionID) {
-case options::OPT__SLASH_MT:
-  CmdArgs.push_back("/DEFAULTLIB:libcmt");
-  CmdArgs.push_back("Fortran_main.static.lib");
-  CmdArgs.push_back("FortranRuntime.static.lib");
-  CmdArgs.push_back("FortranDecimal.static.lib");
-  break;
-case options::OPT__SLASH_MTd:
-  CmdArgs.push_back("/DEFAULTLIB:libcmtd");
-  CmdArgs.push_back("Fortran_main.static_dbg.lib");
-  CmdArgs.push_back("FortranRuntime.static_dbg.lib");
-  CmdArgs.push_back("FortranDecimal.static_dbg.lib");
-  break;
-case options::OPT__SLASH_MD:
-  CmdArgs.push_back("/DEFAULTLIB:msvcrt");
-  CmdArgs.push_back("Fortran_main.dynamic.lib");
-  CmdArgs.push_back("FortranRuntime.dynamic.lib");
-  CmdArgs.push_back("FortranDecimal.dynamic.lib");
-  break;
-case options::OPT__SLASH_MDd:
-  CmdArgs.push_back("/DEFAULTLIB:msvcrtd");
-  CmdArgs.push_back("Fortran_main.dynamic_dbg.lib");
-  CmdArgs.push_back("FortranRuntime.dynamic_dbg.lib");
-  CmdArgs.push_back("FortranDecimal.dynamic_dbg.lib");
-  break;
-}
-  } else {
+  // These are handled by adding link options to the object file on Windows
+  if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {

banach-space wrote:

Does this mean it's user's responsibility to add these? Why can't these be 
added auto-magically like on other platforms?

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


  1   2   >