[clang] 6ff6191 - [Driver] Reject -fptrauth-intrinsics on non-AArch64 targets

2024-03-26 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-03-26T00:04:19-07:00
New Revision: 6ff61914a1ef2c05702ba73cf31ffdeed59c1740

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

LOG: [Driver] Reject -fptrauth-intrinsics on non-AArch64 targets

And add a driver test missing from the original patch #65996.

Added: 
clang/test/Driver/aarch64-ptrauth.c

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b0d90c776b58a9..29066ea14280c2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4105,12 +4105,8 @@ defm strict_return : BoolFOption<"strict-return",
 " of a non-void function as unreachable">,
   PosFlag>;
 
-let Group = f_Group in {
-  let Visibility = [ClangOption,CC1Option] in {
-def fptrauth_intrinsics : Flag<["-"], "fptrauth-intrinsics">,
-  HelpText<"Enable pointer authentication intrinsics">;
-  }
-  def fno_ptrauth_intrinsics : Flag<["-"], "fno-ptrauth-intrinsics">;
+let Flags = [TargetSpecific] in {
+defm ptrauth_intrinsics : OptInCC1FFlag<"ptrauth-intrinsics", "Enable pointer 
authentication intrinsics">;
 }
 
 def fenable_matrix : Flag<["-"], "fenable-matrix">, Group,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 86a287db72a4eb..3bcacff7724c7d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1776,6 +1776,9 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
   }
 
   AddUnalignedAccessWarning(CmdArgs);
+
+  Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_intrinsics,
+options::OPT_fno_ptrauth_intrinsics);
 }
 
 void Clang::AddLoongArchTargetArgs(const ArgList &Args,
@@ -7258,10 +7261,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // -fno-common is the default, set -fcommon only when that flag is set.
   Args.addOptInFlag(CmdArgs, options::OPT_fcommon, options::OPT_fno_common);
 
-  if (Args.hasFlag(options::OPT_fptrauth_intrinsics,
-   options::OPT_fno_ptrauth_intrinsics, false))
-CmdArgs.push_back("-fptrauth-intrinsics");
-
   // -fsigned-bitfields is default, and clang doesn't yet support
   // -funsigned-bitfields.
   if (!Args.hasFlag(options::OPT_fsigned_bitfields,

diff  --git a/clang/test/Driver/aarch64-ptrauth.c 
b/clang/test/Driver/aarch64-ptrauth.c
new file mode 100644
index 00..1a69b2c6edfb17
--- /dev/null
+++ b/clang/test/Driver/aarch64-ptrauth.c
@@ -0,0 +1,5 @@
+// RUN: %clang -### -c --target=aarch64 -fno-ptrauth-intrinsics 
-fptrauth-intrinsics %s 2>&1 | FileCheck %s --check-prefix=INTRIN
+// INTRIN: "-cc1"{{.*}} "-fptrauth-intrinsics"
+
+// RUN: not %clang -### -c --target=x86_64 -fptrauth-intrinsics %s 2>&1 | 
FileCheck %s --check-prefix=ERR
+// ERR: error: unsupported option '-fptrauth-intrinsics' for target '{{.*}}'



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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI compatibility tag (PR #85235)

2024-03-26 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,32 @@
+// Check that we can manually enable specific ptrauth features.
+
+// RUN: %clang --target=aarch64 -c %s -### 2>&1 | FileCheck %s --check-prefix 
NONE
+// NONE: "-cc1"
+// NONE-NOT: "-fptrauth-intrinsics"

MaskRay wrote:

`// NONE-NOT: "-fptrauth-` to rule them all

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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI compatibility tag (PR #85235)

2024-03-26 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,32 @@
+// Check that we can manually enable specific ptrauth features.

MaskRay wrote:

aarch64-ptrauth.c is more conventional for such target-specific features

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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI compatibility tag (PR #85235)

2024-03-26 Thread Fangrui Song via cfe-commits


@@ -7203,6 +7203,33 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
options::OPT_fno_ptrauth_intrinsics, false))
 CmdArgs.push_back("-fptrauth-intrinsics");
 
+  if (Args.hasFlag(options::OPT_fptrauth_calls, options::OPT_fno_ptrauth_calls,

MaskRay wrote:

This should be added in Clang::AddAArch64TargetArgs and use addOptInFlag. See 
6ff61914a1ef2c05702ba73cf31ffdeed59c1740

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


[clang] [clang] Fix assertion failure when printing atomic apvalues (PR #85259)

2024-03-26 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Right, I was just hoping for an existing unittest for `APValue`.

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


[clang] 6a6f9bf - [clang] Fix assertion failure when printing atomic apvalues (#85259)

2024-03-26 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-03-26T08:35:03+01:00
New Revision: 6a6f9bf38e65ec45b32da4b578e2830341a9b364

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

LOG: [clang] Fix assertion failure when printing atomic apvalues (#85259)

When printing an `_Atomic(some struct type)`, we would later run into an
assertion because we do a `Ty->castAs()`, which doesn't work
with an `AtomicType`.

Added: 


Modified: 
clang/lib/AST/APValue.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 4eae308ef5b34c..d8042321319a67 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -704,6 +704,9 @@ void APValue::printPretty(raw_ostream &Out, const 
PrintingPolicy &Policy,
 return;
   }
 
+  if (const auto *AT = Ty->getAs())
+Ty = AT->getValueType();
+
   switch (getKind()) {
   case APValue::None:
 Out << "";



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


[clang] [clang] Fix assertion failure when printing atomic apvalues (PR #85259)

2024-03-26 Thread Timm Baeder via cfe-commits

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


[clang] [Clang][analyzer] add documentation for optin performance padding (padding checker) #73675 (PR #86411)

2024-03-26 Thread via cfe-commits


@@ -804,10 +804,38 @@ Check for performance anti-patterns when using Grand 
Central Dispatch.
 
 .. _optin-performance-Padding:
 
-optin.performance.Padding
-"
+optin.performance.Padding (C, C++, ObjC)
+
 Check for excessively padded structs.
 
+This checker detects structs with excessive padding, which can lead to wasted 
memory and decreased performance. Padding bytes are added by compilers to align 
data within the struct for performance optimization or memory alignment 
purposes. However, excessive padding can significantly increase the size of the 
struct without adding useful data, leading to inefficient memory usage, cache 
misses, and decreased performance.
+
+.. code-block:: c
+
+   #include 
+   // #pragma pack(1) // Uncomment it to disable structure padding
+   struct TestStruct {
+   char data1;  // 1 byte
+   char data2;  // 1 byte
+   int data3;   // 4 bytes
+   }; // Total size: 6 bytes
+   
+   int main () {
+   struct TestStruct struct1;
+   printf("Structure size: %d",sizeof(struct1)); // Structure size: 8
+   return 0;
+   }
+   
+Total memory used is 8 bytes due to structure padding. In this case, padding 
is of 2 bytes. Padding is done to decrease the number of CPU cycles needed to 
access data members of the structure, it increases the performance of the 
processor but at the penalty of memory.
+Padding can be disabled by using the pragma directive.
+Padding can also be decreased by putting data members of the structure in 
descending order of their size.
+
+Reports are only generated if the excessive padding exceeds ``AllowedPad`` in 
bytes. AllowedPad is the threshold value of padding.

komalverma04 wrote:

I will write everything in described form. 

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From aa9d6cd10ff32fdcdd3d1b2ef334aa70f56cccb1 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/9] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index e2232fb4a47153..41cd0443ca2ac7 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -275,6 +275,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4a954258ce40b6..1698c6c89e6e98 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -954,6 +954,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 0c80ad109ccbb2..bdd2f046113e7e 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -413,7 +413,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -423,44 +423,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> > With the current implementation `-Wformat-signedness` by itself actually 
> > turn on the signedness warnings. This is not compatible with how gcc do it. 
> > I guess I have thought that it was not that important to be compatible with 
> > gcc in this respect. However if it is I guess this could be implemented.
> 
> Personally, I find GCC's behavior a bit surprising, so I'm okay with a 
> divergence there.

Sorry, I'm confused. Ignore what I said above. What is not compatible with gcc 
is only that -Wformat is turned on default by clang and not by gcc. The 
handling of `-Wformat-signedness` is as far as I can tell compatible with gcc.

> But we should have tests for this just the same:
> 
> * `-Wformat-signedness`
> 
> * `-Wformat-signedness -Wno-format`
> 
> * `-Wno-format -Wformat-signedness`

I agree, it is good to have tests of those combinations. I have now added them 
to clang/test/Sema/format-strings-signedness.c


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


[clang] [Clang][analyzer] add documentation for optin performance padding (padding checker) #73675 (PR #86411)

2024-03-26 Thread via cfe-commits


@@ -804,10 +804,38 @@ Check for performance anti-patterns when using Grand 
Central Dispatch.
 
 .. _optin-performance-Padding:
 
-optin.performance.Padding
-"
+optin.performance.Padding (C, C++, ObjC)
+
 Check for excessively padded structs.
 
+This checker detects structs with excessive padding, which can lead to wasted 
memory and decreased performance. Padding bytes are added by compilers to align 
data within the struct for performance optimization or memory alignment 
purposes. However, excessive padding can significantly increase the size of the 
struct without adding useful data, leading to inefficient memory usage, cache 
misses, and decreased performance.
+
+.. code-block:: c
+
+   #include 
+   // #pragma pack(1) // Uncomment it to disable structure padding
+   struct TestStruct {
+   char data1;  // 1 byte
+   char data2;  // 1 byte
+   int data3;   // 4 bytes
+   }; // Total size: 6 bytes
+   
+   int main () {
+   struct TestStruct struct1;
+   printf("Structure size: %d",sizeof(struct1)); // Structure size: 8
+   return 0;
+   }
+   
+Total memory used is 8 bytes due to structure padding. In this case, padding 
is of 2 bytes. Padding is done to decrease the number of CPU cycles needed to 
access data members of the structure, it increases the performance of the 
processor but at the penalty of memory.
+Padding can be disabled by using the pragma directive.
+Padding can also be decreased by putting data members of the structure in 
descending order of their size.
+
+Reports are only generated if the excessive padding exceeds ``AllowedPad`` in 
bytes. AllowedPad is the threshold value of padding.

komalverma04 wrote:

@steakhal, if fields are in optimal order that is widest datatype first,still 
If the padding between two fields exceeds this value, the analyzer will issue a 
warning indicating that there's excessive padding within the structure.
Okay, so i will write it in the documentation in described form.
Please correct me if i am wrong


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


[clang] [Clang][analyzer] add documentation for optin performance padding (padding checker) #73675 (PR #86411)

2024-03-26 Thread via cfe-commits

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-26 Thread Petr Hosek via cfe-commits


@@ -49,3 +49,62 @@ if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)
   # despite potential dllexports.
   target_link_options(clangInterpreter PRIVATE LINKER:--export-all-symbols)
 endif()
+
+if(MSVC)
+  set_target_properties(clangInterpreter PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 
1)
+
+  # RTTI/C++ symbols
+  set(clangInterpreter_exports ${clangInterpreter_exports} ??_7type_info@@6B@
+?__type_info_root_node@@3U__type_info_node@@A
+?nothrow@std@@3Unothrow_t@1@B
+  )
+
+  # Compiler added symbols for static variables. NOT for VStudio < 2015
+  set(clangInterpreter_exports ${clangInterpreter_exports} _Init_thread_abort 
_Init_thread_epoch
+_Init_thread_footer _Init_thread_header _tls_index
+  )
+
+  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+# new/delete variants needed when linking to static msvc runtime (esp. 
Debug)
+set(clangInterpreter_exports ${clangInterpreter_exports}
+  ??2@YAPEAX_K@Z
+  ??3@YAXPEAX@Z
+  ??_U@YAPEAX_K@Z
+  ??_V@YAXPEAX@Z
+  ??3@YAXPEAX_K@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@H@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@M@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@PEBX@Z
+  
??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@P6AAEAV01@AEAV01@@Z@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@D@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z
+  ?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z
+)
+  else()
+set(clangInterpreter_exports ${clangInterpreter_exports}
+  ??2@YAPAXI@Z
+  ??3@YAXPAX@Z
+  ??3@YAXPAXI@Z
+  ??_U@YAPAXI@Z
+  ??_V@YAXPAX@Z
+  ??_V@YAXPAXI@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@M@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@PBX@Z
+  
??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@D@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z
+  ?_Facet_Register@std@@YAXPAV_Facet_base@1@@Z
+)
+  endif()
+
+  # List to '/EXPORT:sym0 /EXPORT:sym1 /EXPORT:sym2 ...'
+  foreach(sym ${clangInterpreter_exports})
+set(clangInterpreter_link_str "${clangInterpreter_link_str} 
/EXPORT:${sym}")
+  endforeach(sym ${clangInterpreter_exports})
+
+  set_property(TARGET clangInterpreter APPEND_STRING PROPERTY LINK_FLAGS 
${clangInterpreter_link_str})
+
+endif(MSVC)

petrhosek wrote:

Can you clarify what you mean by "`target_link_options` doesn't work", I'm not 
sure which part you're referring to?

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread via cfe-commits

https://github.com/ycdtosa updated 
https://github.com/llvm/llvm-project/pull/86486

>From 016152bc21c2625db77d3e31a7123bcf08114133 Mon Sep 17 00:00:00 2001
From: ycdtosa 
Date: Mon, 25 Mar 2024 10:28:02 +
Subject: [PATCH 1/5] add test for [[clang::always-destroy]] attribute

user wants the warning silenced by the attribute
so no warning should be issued
---
 clang/lib/Sema/SemaDeclCXX.cpp| 3 ++-
 clang/test/SemaCXX/warn-exit-time-destructors.cpp | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ee732679417e37..7070ea00cff275 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16202,7 +16202,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const 
RecordType *Record) {
 
   // Emit warning for non-trivial dtor in global scope (a real global,
   // class-static, function-static).
-  Diag(VD->getLocation(), diag::warn_exit_time_destructor);
+  if (!VD->hasAttr())
+Diag(VD->getLocation(), diag::warn_exit_time_destructor);
 
   // TODO: this should be re-enabled for static locals by !CXAAtExit
   if (!VD->isStaticLocal())
diff --git a/clang/test/SemaCXX/warn-exit-time-destructors.cpp 
b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
index 2f14243cb48c47..8bd798c036333e 100644
--- a/clang/test/SemaCXX/warn-exit-time-destructors.cpp
+++ b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
@@ -51,6 +51,11 @@ struct A { ~A(); };
 }
 
 namespace test5 {
+struct A { ~A(); };
+[[clang::always_destroy]] A a; // no warning
+}
+
+namespace test6 {
 #if __cplusplus >= 202002L
 #define CPP20_CONSTEXPR constexpr
 #else
@@ -68,3 +73,4 @@ namespace test5 {
   T t; // expected-warning {{exit-time destructor}}
 #undef CPP20_CONSTEXPR
 }
+

>From b9492928df4e9864b664dc99e34d372215e2fab9 Mon Sep 17 00:00:00 2001
From: ycdtosa 
Date: Mon, 25 Mar 2024 17:53:51 +
Subject: [PATCH 2/5] add test for static variable inside a function

---
 clang/test/SemaCXX/warn-exit-time-destructors.cpp | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaCXX/warn-exit-time-destructors.cpp 
b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
index 8bd798c036333e..55ae37d7368f88 100644
--- a/clang/test/SemaCXX/warn-exit-time-destructors.cpp
+++ b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
@@ -51,8 +51,12 @@ struct A { ~A(); };
 }
 
 namespace test5 {
-struct A { ~A(); };
-[[clang::always_destroy]] A a; // no warning
+  struct A { ~A(); };
+  [[clang::always_destroy]] A a; // no warning
+
+  void func() {
+[[clang::always_destroy]] static A a; // no warning
+  }
 }
 
 namespace test6 {

>From 127abc398d4ed059d761e4b70f0c9d14a8ac1c29 Mon Sep 17 00:00:00 2001
From: ycdtosa 
Date: Mon, 25 Mar 2024 18:05:26 +
Subject: [PATCH 3/5] update documentation

---
 clang/docs/ReleaseNotes.rst   | 4 
 clang/include/clang/Basic/AttrDocs.td | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8054d90fc70f93..46e135123aada9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -289,6 +289,10 @@ Improvements to Clang's diagnostics
 - Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
   Fixes #GH84495.
 
+- Clang no longer emits the ``exit-time destructor`` warning on static 
variables explicitly 
+  annotated with the ``clang::always_destroy`` attribute. 
+  Fixes #GH68686, #GH86486
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 9de14f608fd114..968f620dc3738c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6069,6 +6069,9 @@ def AlwaysDestroyDocs : Documentation {
 The ``always_destroy`` attribute specifies that a variable with static or 
thread
 storage duration should have its exit-time destructor run. This attribute is 
the
 default unless clang was invoked with -fno-c++-static-destructors.
+
+If a variable is explicity declared with this attribute clang will silence the
+exit-time destructor warning.
   }];
 }
 

>From 7f2ac7ddb89ea5eb05ff420b8570cfdd71192fe1 Mon Sep 17 00:00:00 2001
From: ycdtosa 
Date: Mon, 25 Mar 2024 18:10:42 +
Subject: [PATCH 4/5] fix typo

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

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 968f620dc3738c..cbd8610a9fc767 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6070,7 +6070,7 @@ The ``always_destroy`` attribute specifies that a 
variable with static or thread
 storage duration should have its exit-time destructor run. This attribute is 
the
 default unless clang was invoked with -fno-c++-static-destruc

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-03-26 Thread Mariya Podchishchaeva via cfe-commits


@@ -873,9 +873,14 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
 
   if (D->isPureVirtual())
 Out << " = 0";
-  else if (D->isDeletedAsWritten())
+  else if (D->isDeletedAsWritten()) {
 Out << " = delete";
-  else if (D->isExplicitlyDefaulted())
+if (const auto *M = D->getDeletedMessage()) {

Fznamznon wrote:

Could you please spell out the type?
```suggestion
if (const StringLiteral *M = D->getDeletedMessage()) {
```

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


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-03-26 Thread Mariya Podchishchaeva via cfe-commits


@@ -1936,6 +1936,9 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl 
*D) {
   if (D->isTrivial())
 OS << " trivial";
 
+  if (const auto *M = D->getDeletedMessage())

Fznamznon wrote:

Here too. 
```suggestion
  if (const StringLiteral *M = D->getDeletedMessage())
```

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-26 Thread Wang Pengcheng via cfe-commits


@@ -49,3 +49,62 @@ if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)
   # despite potential dllexports.
   target_link_options(clangInterpreter PRIVATE LINKER:--export-all-symbols)
 endif()
+
+if(MSVC)
+  set_target_properties(clangInterpreter PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 
1)
+
+  # RTTI/C++ symbols
+  set(clangInterpreter_exports ${clangInterpreter_exports} ??_7type_info@@6B@
+?__type_info_root_node@@3U__type_info_node@@A
+?nothrow@std@@3Unothrow_t@1@B
+  )
+
+  # Compiler added symbols for static variables. NOT for VStudio < 2015
+  set(clangInterpreter_exports ${clangInterpreter_exports} _Init_thread_abort 
_Init_thread_epoch
+_Init_thread_footer _Init_thread_header _tls_index
+  )
+
+  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+# new/delete variants needed when linking to static msvc runtime (esp. 
Debug)
+set(clangInterpreter_exports ${clangInterpreter_exports}
+  ??2@YAPEAX_K@Z
+  ??3@YAXPEAX@Z
+  ??_U@YAPEAX_K@Z
+  ??_V@YAXPEAX@Z
+  ??3@YAXPEAX_K@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@H@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@M@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@PEBX@Z
+  
??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@P6AAEAV01@AEAV01@@Z@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@D@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z
+  ?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z
+)
+  else()
+set(clangInterpreter_exports ${clangInterpreter_exports}
+  ??2@YAPAXI@Z
+  ??3@YAXPAX@Z
+  ??3@YAXPAXI@Z
+  ??_U@YAPAXI@Z
+  ??_V@YAXPAX@Z
+  ??_V@YAXPAXI@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@M@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@PBX@Z
+  
??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@D@Z
+  
??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z
+  ?_Facet_Register@std@@YAXPAV_Facet_base@1@@Z
+)
+  endif()
+
+  # List to '/EXPORT:sym0 /EXPORT:sym1 /EXPORT:sym2 ...'
+  foreach(sym ${clangInterpreter_exports})
+set(clangInterpreter_link_str "${clangInterpreter_link_str} 
/EXPORT:${sym}")
+  endforeach(sym ${clangInterpreter_exports})
+
+  set_property(TARGET clangInterpreter APPEND_STRING PROPERTY LINK_FLAGS 
${clangInterpreter_link_str})
+
+endif(MSVC)

wangpc-pp wrote:

See commit aae9c11511c6bd8b41cfc879cfe3197578d52068.
I tried to add these exports to `clangInterpreter` component and hoped these 
link options can be transitive to its users like `clang-repl` and 
`ClangReplInterpreterTests`. But it didn't work after 
aae9c11511c6bd8b41cfc879cfe3197578d52068 because the unit tests were still 
failed.
I am not a cmake expert, so I have to add exports to `clang-repl` and 
`ClangReplInterpreterTests` to make sure unit tests are passed, but the cmake 
code may be too duplicated in this way.

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


[clang] 4fa736b - [Clang] NFC Silence compiler warning spam (#86532)

2024-03-26 Thread via cfe-commits

Author: NagyDonat
Date: 2024-03-26T10:33:12+01:00
New Revision: 4fa736ba41fce885047bd5a242230b216ea85c70

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

LOG: [Clang] NFC Silence compiler warning spam (#86532)

This non-functional change eliminates the compiler warning
```
/repo/llvm-project/clang/include/clang/Basic/SyncScope.h: In member function 
‘virtual bool clang::AtomicScopeGenericModel::isValid(unsigned int) const’:
/repo/llvm-project/clang/include/clang/Basic/SyncScope.h:255:14: warning: 
comparison of unsigned expression >= 0 is always true [-Wtype-limits]
 return S >= static_cast(System) &&
~~^~~~
```
which was appearing repeatedly, as this header is included into very
many source files (through various chains of 6-7 header files).

Added: 


Modified: 
clang/include/clang/Basic/SyncScope.h

Removed: 




diff  --git a/clang/include/clang/Basic/SyncScope.h 
b/clang/include/clang/Basic/SyncScope.h
index bc7ec7b5cf777e..45beff41afa11d 100644
--- a/clang/include/clang/Basic/SyncScope.h
+++ b/clang/include/clang/Basic/SyncScope.h
@@ -252,8 +252,7 @@ class AtomicScopeGenericModel : public AtomicScopeModel {
   }
 
   bool isValid(unsigned S) const override {
-return S >= static_cast(System) &&
-   S <= static_cast(Last);
+return S <= static_cast(Last);
   }
 
   ArrayRef getRuntimeValues() const override {



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


[clang] [Clang] NFC Silence compiler warning spam (PR #86532)

2024-03-26 Thread via cfe-commits

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-03-26 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70307

From 17fb77d094018db20de0ac2a65861338006f9d68 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Thu, 26 Oct 2023 10:39:52 +0200
Subject: [PATCH] [clang] Emit bad shift warnings

---
 clang/lib/Sema/SemaExpr.cpp| 29 +++---
 clang/test/AST/Interp/shifts.cpp   |  7 ++
 clang/test/C/drs/dr0xx.c   |  2 +-
 clang/test/Sema/shift-count-negative.c |  8 ++
 clang/test/Sema/shift-count-overflow.c |  6 +
 clang/test/Sema/shift-negative-value.c |  8 ++
 clang/test/Sema/vla-2.c|  9 ---
 clang/test/SemaCXX/cxx2a-explicit-bool.cpp |  2 +-
 clang/test/SemaCXX/shift.cpp   |  1 -
 9 files changed, 52 insertions(+), 20 deletions(-)
 create mode 100644 clang/test/Sema/shift-count-negative.c
 create mode 100644 clang/test/Sema/shift-count-overflow.c
 create mode 100644 clang/test/Sema/shift-negative-value.c

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 94f52004cf6c27..4fef5163c657f8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11444,9 +11444,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   llvm::APSInt Right = RHSResult.Val.getInt();
 
   if (Right.isNegative()) {
-S.DiagRuntimeBehavior(Loc, RHS.get(),
-  S.PDiag(diag::warn_shift_negative)
-<< RHS.get()->getSourceRange());
+if (S.ExprEvalContexts.back().isConstantEvaluated())
+  S.Diag(Loc, diag::warn_shift_negative) << RHS.get()->getSourceRange();
+else
+  S.DiagRuntimeBehavior(Loc, RHS.get(),
+S.PDiag(diag::warn_shift_negative)
+  << RHS.get()->getSourceRange());
 return;
   }
 
@@ -11460,9 +11463,14 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   }
   llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
   if (Right.uge(LeftBits)) {
-S.DiagRuntimeBehavior(Loc, RHS.get(),
-  S.PDiag(diag::warn_shift_gt_typewidth)
-<< RHS.get()->getSourceRange());
+if (S.ExprEvalContexts.back().isConstantEvaluated()
+&& !S.getLangOpts().CPlusPlus11)
+  S.Diag(Loc, diag::warn_shift_gt_typewidth)
+<< RHS.get()->getSourceRange();
+else
+  S.DiagRuntimeBehavior(Loc, RHS.get(),
+S.PDiag(diag::warn_shift_gt_typewidth)
+  << RHS.get()->getSourceRange());
 return;
   }
 
@@ -11493,9 +11501,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   // If LHS does not have a non-negative value then, the
   // behavior is undefined before C++2a. Warn about it.
   if (Left.isNegative()) {
-S.DiagRuntimeBehavior(Loc, LHS.get(),
-  S.PDiag(diag::warn_shift_lhs_negative)
-<< LHS.get()->getSourceRange());
+if (S.ExprEvalContexts.back().isConstantEvaluated())
+  S.Diag(Loc, diag::warn_shift_lhs_negative) << 
LHS.get()->getSourceRange();
+else
+  S.DiagRuntimeBehavior(Loc, LHS.get(),
+S.PDiag(diag::warn_shift_lhs_negative)
+  << LHS.get()->getSourceRange());
 return;
   }
 
diff --git a/clang/test/AST/Interp/shifts.cpp b/clang/test/AST/Interp/shifts.cpp
index b1df7b85cc9f2b..c11ba0f6f3a19e 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -33,13 +33,10 @@ namespace shifts {
// FIXME: 'implicit conversion' warning missing in 
the new interpreter. \
// cxx17-warning {{shift count >= width of type}} \
// ref-warning {{shift count >= width of type}} \
-   // ref-warning {{implicit conversion}} \
-   // ref-cxx17-warning {{shift count >= width of 
type}} \
-   // ref-cxx17-warning {{implicit conversion}}
+   // ref-cxx17-warning {{shift count >= width of 
type}}
 c = 1 >> (unsigned)-1; // expected-warning {{shift count >= width of 
type}} \
// cxx17-warning {{shift count >= width of type}} \
-   // ref-warning {{shift count >= width of type}} \
-   // ref-cxx17-warning {{shift count >= width of 
type}}
+   // ref-warning {{shift count >= width of type}}
 c = 1 << c;
 c <<= 0;
 c >>= 0;
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index 6a3717f0729b60..6611b2b65264fa 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -426,7 +426,7 @@ void dr081(void) {
   /* Demonstrate that we don't crash when left shifting a signed value; that's
* implem

[clang] [clang] Emit bad shift warnings (PR #70307)

2024-03-26 Thread Budimir Aranđelović via cfe-commits


@@ -2805,7 +2805,7 @@ static bool handleIntIntBinOp(EvalInfo &Info, const Expr 
*E, const APSInt &LHS,
 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1);
 if (SA != RHS) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
-<< RHS << E->getType() << LHS.getBitWidth();
+  << RHS << E->getType() << LHS.getBitWidth();

budimirarandjelovicsyrmia wrote:

Reverted changes. Just to mention that 'git clang-format' proposed spaces in 
this comment and comments below.

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


[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-03-26 Thread via cfe-commits

https://github.com/NorthBlue333 updated 
https://github.com/llvm/llvm-project/pull/77456

>From a3ddae11b909a319d73fccff409fa5c0648a234f Mon Sep 17 00:00:00 2001
From: NorthBlue333 
Date: Tue, 9 Jan 2024 14:01:14 +0100
Subject: [PATCH 1/2] [clang-format] Do not update cursor pos if no includes
 replacement

---
 clang/lib/Format/Format.cpp | 13 +++--
 clang/unittests/Format/SortIncludesTest.cpp | 61 -
 2 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b..3d8cffaca1ded3 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3123,6 +3123,7 @@ static void sortCppIncludes(const FormatStyle &Style,
   }
 
   std::string result;
+  unsigned NewCursor = UINT_MAX;
   for (unsigned Index : Indices) {
 if (!result.empty()) {
   result += "\n";
@@ -3134,13 +3135,10 @@ static void sortCppIncludes(const FormatStyle &Style,
 }
 result += Includes[Index].Text;
 if (Cursor && CursorIndex == Index)
-  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
+  NewCursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
 CurrentCategory = Includes[Index].Category;
   }
 
-  if (Cursor && *Cursor >= IncludesEndOffset)
-*Cursor += result.size() - IncludesBlockSize;
-
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
@@ -3148,6 +3146,13 @@ static void sortCppIncludes(const FormatStyle &Style,
 return;
   }
 
+  if (Cursor) {
+if (NewCursor != UINT_MAX)
+  *Cursor = NewCursor;
+else if (*Cursor >= IncludesEndOffset)
+  *Cursor += result.size() - IncludesBlockSize;
+  }
+
   auto Err = Replaces.add(tooling::Replacement(
   FileName, Includes.front().Offset, IncludesBlockSize, result));
   // FIXME: better error handling. For now, just skip the replacement for the
diff --git a/clang/unittests/Format/SortIncludesTest.cpp 
b/clang/unittests/Format/SortIncludesTest.cpp
index ec142e03b12854..d180767b6ff9fa 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -6,19 +6,19 @@
 //
 
//===--===//
 
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "gtest/gtest.h"
 
-#define DEBUG_TYPE "format-test"
+#define DEBUG_TYPE "sort-includes-test"
 
 namespace clang {
 namespace format {
 namespace {
 
-class SortIncludesTest : public ::testing::Test {
+class SortIncludesTest : public test::FormatTestBase {
 protected:
   std::vector GetCodeRange(StringRef Code) {
 return std::vector(1, tooling::Range(0, Code.size()));
@@ -821,6 +821,61 @@ TEST_F(SortIncludesTest, 
CalculatesCorrectCursorPositionWithRegrouping) {
   EXPECT_EQ(27u, newCursor(Code, 28)); // Start of last line
 }
 
+TEST_F(SortIncludesTest,
+   CalculatesCorrectCursorPositionWhenNoReplacementsWithRegroupingAndCRLF) 
{
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {
+  {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  verifyNoChange(Code);
+  EXPECT_EQ(0u, newCursor(Code, 0));
+  EXPECT_EQ(14u, newCursor(Code, 14));
+  EXPECT_EQ(16u, newCursor(Code, 16));
+  EXPECT_EQ(30u, newCursor(Code, 30));
+  EXPECT_EQ(32u, newCursor(Code, 32));
+  EXPECT_EQ(46u, newCursor(Code, 46));
+  EXPECT_EQ(48u, newCursor(Code, 48));
+}
+
+TEST_F(
+SortIncludesTest,
+
CalculatesCorrectCursorPositionWhenRemoveLinesReplacementsWithRegroupingAndCRLF)
 {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {{".*", 0, 0, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  std::string Expected = "#include \"a\"\r\n" // Start of li

[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits


@@ -2303,11 +2303,6 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 } else {
   if (!FirstArg)
 OS << Comma;
-  if (!Policy.SuppressTagKeyword &&
-  Argument.getKind() == TemplateArgument::Type &&
-  isa(Argument.getAsType()))
-OS << Argument.getAsType().getAsString();
-  else

zahiraam wrote:

This code was wrongly added in 
https://github.com/intel/llvm/commit/6503b015d4a8 and was not reached by any 
tests. Some of our internal testing did hit this and realized the code was 
wrong. Created reproducers from internal tests to show that the code is wrong.

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


[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-03-26 Thread via cfe-commits

https://github.com/NorthBlue333 updated 
https://github.com/llvm/llvm-project/pull/77456

>From d4fd95374a82361e3dbfcd7a5d87c37da4542d2b Mon Sep 17 00:00:00 2001
From: NorthBlue333 
Date: Tue, 9 Jan 2024 14:01:14 +0100
Subject: [PATCH 1/2] [clang-format] Do not update cursor pos if no includes
 replacement

---
 clang/lib/Format/Format.cpp | 13 +++--
 clang/unittests/Format/SortIncludesTest.cpp | 61 -
 2 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 46ed5baaeacead..17a3e0c9cfd733 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3115,6 +3115,7 @@ static void sortCppIncludes(const FormatStyle &Style,
   }
 
   std::string result;
+  unsigned NewCursor = UINT_MAX;
   for (unsigned Index : Indices) {
 if (!result.empty()) {
   result += "\n";
@@ -3126,13 +3127,10 @@ static void sortCppIncludes(const FormatStyle &Style,
 }
 result += Includes[Index].Text;
 if (Cursor && CursorIndex == Index)
-  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
+  NewCursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
 CurrentCategory = Includes[Index].Category;
   }
 
-  if (Cursor && *Cursor >= IncludesEndOffset)
-*Cursor += result.size() - IncludesBlockSize;
-
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
@@ -3140,6 +3138,13 @@ static void sortCppIncludes(const FormatStyle &Style,
 return;
   }
 
+  if (Cursor) {
+if (NewCursor != UINT_MAX)
+  *Cursor = NewCursor;
+else if (*Cursor >= IncludesEndOffset)
+  *Cursor += result.size() - IncludesBlockSize;
+  }
+
   auto Err = Replaces.add(tooling::Replacement(
   FileName, Includes.front().Offset, IncludesBlockSize, result));
   // FIXME: better error handling. For now, just skip the replacement for the
diff --git a/clang/unittests/Format/SortIncludesTest.cpp 
b/clang/unittests/Format/SortIncludesTest.cpp
index 772eb53806b4b1..939ad181a9d707 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -6,19 +6,19 @@
 //
 
//===--===//
 
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "gtest/gtest.h"
 
-#define DEBUG_TYPE "format-test"
+#define DEBUG_TYPE "sort-includes-test"
 
 namespace clang {
 namespace format {
 namespace {
 
-class SortIncludesTest : public ::testing::Test {
+class SortIncludesTest : public test::FormatTestBase {
 protected:
   std::vector GetCodeRange(StringRef Code) {
 return std::vector(1, tooling::Range(0, Code.size()));
@@ -821,6 +821,61 @@ TEST_F(SortIncludesTest, 
CalculatesCorrectCursorPositionWithRegrouping) {
   EXPECT_EQ(27u, newCursor(Code, 28)); // Start of last line
 }
 
+TEST_F(SortIncludesTest,
+   CalculatesCorrectCursorPositionWhenNoReplacementsWithRegroupingAndCRLF) 
{
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {
+  {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  verifyNoChange(Code);
+  EXPECT_EQ(0u, newCursor(Code, 0));
+  EXPECT_EQ(14u, newCursor(Code, 14));
+  EXPECT_EQ(16u, newCursor(Code, 16));
+  EXPECT_EQ(30u, newCursor(Code, 30));
+  EXPECT_EQ(32u, newCursor(Code, 32));
+  EXPECT_EQ(46u, newCursor(Code, 46));
+  EXPECT_EQ(48u, newCursor(Code, 48));
+}
+
+TEST_F(
+SortIncludesTest,
+
CalculatesCorrectCursorPositionWhenRemoveLinesReplacementsWithRegroupingAndCRLF)
 {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {{".*", 0, 0, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  std::string Expected = "#include \"a\"\r\n" // Start of li

[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-26 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot updated 
https://github.com/llvm/llvm-project/pull/77732

>From 618762c79f5ec1ea9a945b81e182e3d8e1046baf Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Tue, 26 Mar 2024 16:21:10 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   6 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/Targets/PPC.cpp | 103 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   9 +
 clang/lib/Frontend/CompilerInvocation.cpp |   8 +
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 306 ++
 7 files changed, 430 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a33..f4845e9e424c67 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -225,6 +225,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi is specified on ppc32.
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_OnStack)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb0..1c9424f65623dd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_OnStack,
+CMPLX_InGPR, // If -fcomplex-ppc-gnu-abi is specified on ppc32
+CMPLX_InFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29066ea14280c2..4a5cfc988b8c18 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2577,6 +2577,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, pass Complex values in GPRs instead of the 
stack for PowerPC-32">,
+  HelpText<"Pass Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlaghttps://reviews.llvm.org/D146942 and the related LLVM pull
+  // request: #77732
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = TypeSize >> 5;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  if (!(getCodeGenOpts().getComplexInRegABI() == CodeGenOptions::CMPLX_InGPR) 
||
+  !ArgGPRsLeft)
+return DefaultABIInfo::classifyArgumentType(Ty);
+
+  assert(ArgGPRsLeft >= 0 && "Arg GPR must be large or equal than zero");
+  ASTContext &Context = getContext();
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (Ty->isAnyComplexType()) {
+if (TypeSize == 64 && ArgGPRsLeft % 2 == 1)
+  --ArgGPRsLeft;
+
+if (TypeSize <= RegLen * ArgGPRsLeft) {
+  ArgGPRsLeft -= TypeSize / RegLen;
+  return handleComplex(TypeSize);
+}
+  }
+
+  // Records with non-trivial destructors/copy-constructors should not be
+  // passed by value.
+  if (isAggregateTypeForABI(Ty))
+--ArgGPRsLeft;
+  else if (!Ty->isFloatingType()) {
+// For other primitive types.
+if (TypeSize == 64) {
+  if (ArgGPRsLeft % 2 == 1)
+--ArgGPRsLeft;
+  if (TypeSize <= 

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-03-26 Thread via cfe-commits

https://github.com/NorthBlue333 updated 
https://github.com/llvm/llvm-project/pull/77456

>From d4fd95374a82361e3dbfcd7a5d87c37da4542d2b Mon Sep 17 00:00:00 2001
From: NorthBlue333 
Date: Tue, 9 Jan 2024 14:01:14 +0100
Subject: [PATCH 1/2] [clang-format] Do not update cursor pos if no includes
 replacement

---
 clang/lib/Format/Format.cpp | 13 +++--
 clang/unittests/Format/SortIncludesTest.cpp | 61 -
 2 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 46ed5baaeacead..17a3e0c9cfd733 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3115,6 +3115,7 @@ static void sortCppIncludes(const FormatStyle &Style,
   }
 
   std::string result;
+  unsigned NewCursor = UINT_MAX;
   for (unsigned Index : Indices) {
 if (!result.empty()) {
   result += "\n";
@@ -3126,13 +3127,10 @@ static void sortCppIncludes(const FormatStyle &Style,
 }
 result += Includes[Index].Text;
 if (Cursor && CursorIndex == Index)
-  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
+  NewCursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
 CurrentCategory = Includes[Index].Category;
   }
 
-  if (Cursor && *Cursor >= IncludesEndOffset)
-*Cursor += result.size() - IncludesBlockSize;
-
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
@@ -3140,6 +3138,13 @@ static void sortCppIncludes(const FormatStyle &Style,
 return;
   }
 
+  if (Cursor) {
+if (NewCursor != UINT_MAX)
+  *Cursor = NewCursor;
+else if (*Cursor >= IncludesEndOffset)
+  *Cursor += result.size() - IncludesBlockSize;
+  }
+
   auto Err = Replaces.add(tooling::Replacement(
   FileName, Includes.front().Offset, IncludesBlockSize, result));
   // FIXME: better error handling. For now, just skip the replacement for the
diff --git a/clang/unittests/Format/SortIncludesTest.cpp 
b/clang/unittests/Format/SortIncludesTest.cpp
index 772eb53806b4b1..939ad181a9d707 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -6,19 +6,19 @@
 //
 
//===--===//
 
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "gtest/gtest.h"
 
-#define DEBUG_TYPE "format-test"
+#define DEBUG_TYPE "sort-includes-test"
 
 namespace clang {
 namespace format {
 namespace {
 
-class SortIncludesTest : public ::testing::Test {
+class SortIncludesTest : public test::FormatTestBase {
 protected:
   std::vector GetCodeRange(StringRef Code) {
 return std::vector(1, tooling::Range(0, Code.size()));
@@ -821,6 +821,61 @@ TEST_F(SortIncludesTest, 
CalculatesCorrectCursorPositionWithRegrouping) {
   EXPECT_EQ(27u, newCursor(Code, 28)); // Start of last line
 }
 
+TEST_F(SortIncludesTest,
+   CalculatesCorrectCursorPositionWhenNoReplacementsWithRegroupingAndCRLF) 
{
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {
+  {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  verifyNoChange(Code);
+  EXPECT_EQ(0u, newCursor(Code, 0));
+  EXPECT_EQ(14u, newCursor(Code, 14));
+  EXPECT_EQ(16u, newCursor(Code, 16));
+  EXPECT_EQ(30u, newCursor(Code, 30));
+  EXPECT_EQ(32u, newCursor(Code, 32));
+  EXPECT_EQ(46u, newCursor(Code, 46));
+  EXPECT_EQ(48u, newCursor(Code, 48));
+}
+
+TEST_F(
+SortIncludesTest,
+
CalculatesCorrectCursorPositionWhenRemoveLinesReplacementsWithRegroupingAndCRLF)
 {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {{".*", 0, 0, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  std::string Expected = "#include \"a\"\r\n" // Start of li

[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-26 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot updated 
https://github.com/llvm/llvm-project/pull/77732

>From 59bd85681c590a5b3e259bfa93d87a80e5362878 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Tue, 26 Mar 2024 16:40:32 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   6 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/Targets/PPC.cpp | 104 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   9 +
 clang/lib/Frontend/CompilerInvocation.cpp |   8 +
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 306 ++
 7 files changed, 431 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a33..f4845e9e424c67 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -225,6 +225,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi is specified on ppc32.
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_OnStack)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb0..1c9424f65623dd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_OnStack,
+CMPLX_InGPR, // If -fcomplex-ppc-gnu-abi is specified on ppc32
+CMPLX_InFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29066ea14280c2..4a5cfc988b8c18 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2577,6 +2577,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, pass Complex values in GPRs instead of the 
stack for PowerPC-32">,
+  HelpText<"Pass Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlaghttps://reviews.llvm.org/D146942 and the related LLVM pull
+  // request: #77732
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = TypeSize >> 5;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  if (!(getCodeGenOpts().getComplexInRegABI() == CodeGenOptions::CMPLX_InGPR) 
||
+  !ArgGPRsLeft)
+return DefaultABIInfo::classifyArgumentType(Ty);
+
+  assert(ArgGPRsLeft >= 0 && "Arg GPR must be large or equal than zero");
+  ASTContext &Context = getContext();
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (Ty->isAnyComplexType()) {
+// If gr is even set gr = gr + 1 for TypeSize=64.
+if (TypeSize == 64 && ArgGPRsLeft % 2 == 1)
+  --ArgGPRsLeft;
+
+if (TypeSize <= RegLen * ArgGPRsLeft) {
+  ArgGPRsLeft -= TypeSize / RegLen;
+  return handleComplex(TypeSize);
+}
+  }
+
+  // Records with non-trivial destructors/copy-constructors should not be
+  // passed by value.
+  if (isAggregateTypeForABI(Ty))
+--ArgGPRsLeft;
+  else if (!Ty->isFloatingType()) {
+// For other primitive types.
+if (TypeSize == 64) {
+  // If gr is even s

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-03-26 Thread via cfe-commits

NorthBlue333 wrote:

Woops, sorry, I missed the update here.

I've done all your changes in a second commit just to be able to keep track of 
my previous changes; but I am actually not sure how your suggested 
modifications are any different from mine? Well, I admit it looks a bit better, 
but it works the same? Or am I missing something? You are just storing the old 
value of Cursor and resetting it when no changes, while I was doing it the 
other way around: storing the new value and updating it only if no changes.

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-26 Thread Kishan Parmar via cfe-commits


@@ -337,12 +347,58 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const {
+  llvm::Type *ElemTy;
+  unsigned RegsNeeded; // Registers Needed for Complex.
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext &Context = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (IsComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RegLen * ArgGPRsLeft) {
+assert(Ty->isAnyComplexType() && "Ty must be Complex type.");
+ArgGPRsLeft -= TypeSize / RegLen;
+return handleComplex(TypeSize);
+  }
+
+  if (ArgGPRsLeft) {
+// Records with non-trivial destructors/copy-constructors should not be
+// passed by value.
+if (isAggregateTypeForABI(Ty))
+  ArgGPRsLeft -= 1;
+else if (!Ty->isFloatingType()) {
+  // For other premitive types.
+  if (TypeSize > RegLen && TypeSize <= 2 * RegLen)
+ArgGPRsLeft -= TypeSize / RegLen;

Long5hot wrote:

Yes, gcc  passes the last arg in stack
https://godbolt.org/z/EbPMK4jad

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/86652

Fixes #54705


>From 90f88bdac3dc40635c58f3f67e29354e6a32896e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 26 Mar 2024 12:23:24 +0100
Subject: [PATCH] [Clang] Fix __is_array returning true for zero-sized arrays

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaExprCXX.cpp | 4 
 clang/test/SemaCXX/type-traits.cpp | 4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..e6682028537101 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,8 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- ``__is_array`` no longer returns ``true`` for zero-sized arrays. Fixes 
(#GH54705).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c34a40fa7c81ac..93d2b4b259fbc3 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5143,6 +5143,10 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
   case UTT_IsFloatingPoint:
 return T->isFloatingType();
   case UTT_IsArray:
+// zero-sized arrays aren't considered arrays in partial specializations,
+// so __is_array shouldn't consider them arrays either.
+if (const auto* CAT = C.getAsConstantArrayType(T))
+  return CAT->getSize() != 0;
 return T->isArrayType();
   case UTT_IsBoundedArray:
 if (!T->isVariableArrayType()) {
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 14ec17989ec7c7..49df4b668513c0 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -25,6 +25,7 @@ typedef Empty EmptyArMB[1][2];
 typedef int Int;
 typedef Int IntAr[10];
 typedef Int IntArNB[];
+typedef Int IntArZero[0];
 class Statics { static int priv; static NonPOD np; };
 union EmptyUnion {};
 union IncompleteUnion; // expected-note {{forward declaration of 
'IncompleteUnion'}}
@@ -685,6 +686,7 @@ void is_array()
 {
   static_assert(__is_array(IntAr));
   static_assert(__is_array(IntArNB));
+  static_assert(!__is_array(IntArZero));
   static_assert(__is_array(UnionAr));
 
   static_assert(!__is_array(void));
@@ -1804,7 +1806,7 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(EnumForward, int));
   static_assert(!__is_layout_compatible(EnumClassForward, int));
   // FIXME: the following should be rejected (array of unknown bound and void 
are the only allowed incomplete types)
-  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); 
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete));
   static_assert(!__is_layout_compatible(CStruct, CStructIncomplete));
   static_assert(__is_layout_compatible(CStructIncomplete[2], 
CStructIncomplete[2]));
 }

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nikolas Klauser (philnik777)


Changes

Fixes #54705


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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+4) 
- (modified) clang/test/SemaCXX/type-traits.cpp (+3-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..e6682028537101 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,8 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- ``__is_array`` no longer returns ``true`` for zero-sized arrays. Fixes 
(#GH54705).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c34a40fa7c81ac..93d2b4b259fbc3 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5143,6 +5143,10 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
   case UTT_IsFloatingPoint:
 return T->isFloatingType();
   case UTT_IsArray:
+// zero-sized arrays aren't considered arrays in partial specializations,
+// so __is_array shouldn't consider them arrays either.
+if (const auto* CAT = C.getAsConstantArrayType(T))
+  return CAT->getSize() != 0;
 return T->isArrayType();
   case UTT_IsBoundedArray:
 if (!T->isVariableArrayType()) {
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 14ec17989ec7c7..49df4b668513c0 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -25,6 +25,7 @@ typedef Empty EmptyArMB[1][2];
 typedef int Int;
 typedef Int IntAr[10];
 typedef Int IntArNB[];
+typedef Int IntArZero[0];
 class Statics { static int priv; static NonPOD np; };
 union EmptyUnion {};
 union IncompleteUnion; // expected-note {{forward declaration of 
'IncompleteUnion'}}
@@ -685,6 +686,7 @@ void is_array()
 {
   static_assert(__is_array(IntAr));
   static_assert(__is_array(IntArNB));
+  static_assert(!__is_array(IntArZero));
   static_assert(__is_array(UnionAr));
 
   static_assert(!__is_array(void));
@@ -1804,7 +1806,7 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(EnumForward, int));
   static_assert(!__is_layout_compatible(EnumClassForward, int));
   // FIXME: the following should be rejected (array of unknown bound and void 
are the only allowed incomplete types)
-  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); 
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete));
   static_assert(!__is_layout_compatible(CStruct, CStructIncomplete));
   static_assert(__is_layout_compatible(CStructIncomplete[2], 
CStructIncomplete[2]));
 }

``




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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 5b544b511c7133fcb26a5c563b746a4baefb38d6 
90f88bdac3dc40635c58f3f67e29354e6a32896e -- clang/lib/Sema/SemaExprCXX.cpp 
clang/test/SemaCXX/type-traits.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 93d2b4b259..46dd14a871 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5145,7 +5145,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
   case UTT_IsArray:
 // zero-sized arrays aren't considered arrays in partial specializations,
 // so __is_array shouldn't consider them arrays either.
-if (const auto* CAT = C.getAsConstantArrayType(T))
+if (const auto *CAT = C.getAsConstantArrayType(T))
   return CAT->getSize() != 0;
 return T->isArrayType();
   case UTT_IsBoundedArray:

``




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


[clang] da9ac43 - [FMV] Allow mixing target_version with target_clones. (#86493)

2024-03-26 Thread via cfe-commits

Author: Alexandros Lamprineas
Date: 2024-03-26T11:36:34Z
New Revision: da9ac43433ace54b262cd8552a9fafac21186381

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

LOG: [FMV] Allow mixing target_version with target_clones. (#86493)

The latest ACLE allows it and further clarifies the following
in regards to the combination of the two attributes:

"If the `default` matches with another explicitly provided
 version in the same translation unit, then the compiler can
 emit only one function instead of the two. The explicitly
 provided version shall be preferred."

("default" refers to the default clone here)

https://github.com/ARM-software/acle/pull/310

Added: 
clang/test/CodeGen/aarch64-mixed-target-attributes.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGen/attr-target-clones-aarch64.c
clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp
clang/test/Sema/attr-target-clones-aarch64.c

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 3e03e55612645b..318d4e5ac5ba44 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3088,6 +3088,20 @@ def TargetClones : InheritableAttr {
 StringRef getFeatureStr(unsigned Index) const {
   return *(featuresStrs_begin() + Index);
 }
+bool isDefaultVersion(unsigned Index) const {
+  return getFeatureStr(Index) == "default";
+}
+void getFeatures(llvm::SmallVectorImpl &Out,
+ unsigned Index) const {
+  if (isDefaultVersion(Index)) return;
+  StringRef Features = getFeatureStr(Index);
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, "+");
+  for (auto &Feature : AttrFeatures) {
+Feature = Feature.trim();
+Out.push_back(Feature);
+  }
+}
 // Given an index into the 'featuresStrs' sequence, compute a unique
 // ID to be used with function name mangling for the associated variant.
 // This mapping is necessary due to a requirement that the mangling ID

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fcf801adeaf5ef..0b5f20a572a742 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13676,22 +13676,19 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
   } else if (const auto *TC = FD->getAttr()) {
 std::vector Features;
-StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
 if (Target->getTriple().isAArch64()) {
   // TargetClones for AArch64
-  if (VersionStr != "default") {
-SmallVector VersionFeatures;
-VersionStr.split(VersionFeatures, "+");
-for (auto &VFeature : VersionFeatures) {
-  VFeature = VFeature.trim();
+  llvm::SmallVector Feats;
+  TC->getFeatures(Feats, GD.getMultiVersionIndex());
+  for (StringRef Feat : Feats)
+if (Target->validateCpuSupports(Feat.str()))
   // Use '?' to mark features that came from AArch64 TargetClones.
-  Features.push_back((StringRef{"?"} + VFeature).str());
-}
-  }
+  Features.push_back("?" + Feat.str());
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
 } else {
+  StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
   if (VersionStr.starts_with("arch="))
 TargetCPU = VersionStr.drop_front(sizeof("arch=") - 1);
   else if (VersionStr != "default")

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index da411a9fa57994..3997da17bb2858 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3712,7 +3712,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 // Forward declarations are emitted lazily on first use.
 if (!FD->doesThisDeclarationHaveABody()) {
   if (!FD->doesDeclarationForceExternallyVisibleDefinition() &&
-  !FD->isTargetVersionMultiVersion())
+  (!FD->isMultiVersion() ||
+   !FD->getASTContext().getTargetInfo().getTriple().isAArch64()))
 return;
 
   StringRef MangledName = getMangledName(GD);
@@ -3994,10 +3995,11 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 auto *Spec = FD->getAttr();
 for (unsigned I = 0; I < Spec->cpus_size(); ++I)
   EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
-  } else if (FD->isTargetClonesMulti

[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-26 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [clang][ExtractAPI] improve template argument name deduction (PR #77716)

2024-03-26 Thread Daniel Grumberg via cfe-commits


@@ -1127,7 +1096,7 @@ 
DeclarationFragmentsBuilder::getFragmentsForVarTemplatePartialSpecialization(
   .append("<", DeclarationFragments::FragmentKind::Text)
   .append(getFragmentsForTemplateArguments(
   Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
-  Decl->getTemplateParameters()->asArray()))
+  Decl->getTemplateArgsAsWritten()->arguments()))

daniel-grumberg wrote:

Looks like the right thing to me!

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-26 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot updated 
https://github.com/llvm/llvm-project/pull/77732

>From 81d57b415738e4cea8fbbade990046271cb505a5 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Tue, 26 Mar 2024 17:08:25 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   6 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/Targets/PPC.cpp | 100 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   9 +
 clang/lib/Frontend/CompilerInvocation.cpp |   8 +
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 306 ++
 7 files changed, 429 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a33..f4845e9e424c67 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -225,6 +225,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi is specified on ppc32.
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_OnStack)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb0..1c9424f65623dd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_OnStack,
+CMPLX_InGPR, // If -fcomplex-ppc-gnu-abi is specified on ppc32
+CMPLX_InFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29066ea14280c2..4a5cfc988b8c18 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2577,6 +2577,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, pass Complex values in GPRs instead of the 
stack for PowerPC-32">,
+  HelpText<"Pass Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlaghttps://reviews.llvm.org/D146942 and the related LLVM pull
+  // request: #77732
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = TypeSize >> 5;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  if (!(getCodeGenOpts().getComplexInRegABI() == CodeGenOptions::CMPLX_InGPR) 
||
+  !ArgGPRsLeft)
+return DefaultABIInfo::classifyArgumentType(Ty);
+
+  assert(ArgGPRsLeft >= 0 && "Arg GPR must be large or equal than zero");
+  ASTContext &Context = getContext();
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (Ty->isAnyComplexType()) {
+// If gr is even set gr = gr + 1 for TypeSize=64.
+if (TypeSize == 64 && ArgGPRsLeft % 2 == 1)
+  --ArgGPRsLeft;
+
+if (TypeSize <= RegLen * ArgGPRsLeft) {
+  ArgGPRsLeft -= TypeSize / RegLen;
+  return handleComplex(TypeSize);
+}
+  }
+
+  // Records with non-trivial destructors/copy-constructors should not be
+  // passed by value.
+  if (isAggregateTypeForABI(Ty))
+--ArgGPRsLeft;
+  else if (!Ty->isFloatingType()) {
+// For other primitive types.
+if (TypeSize == 64) {
+  // If gr is even s

[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-03-26 Thread Jay Foad via cfe-commits


@@ -2326,6 +2326,20 @@ bool 
SIInsertWaitcnts::insertWaitcntInBlock(MachineFunction &MF,
 }
 #endif
 
+if (ST->isPreciseMemoryEnabled() && Inst.mayLoadOrStore()) {
+  AMDGPU::Waitcnt Wait;
+  if (ST->hasExtendedWaitCounts())
+Wait = AMDGPU::Waitcnt(0, 0, 0, 0, 0, 0, 0);
+  else
+Wait = AMDGPU::Waitcnt(0, 0, 0, 0);
+
+  if (!Inst.mayStore())
+Wait.StoreCnt = ~0u;

jayfoad wrote:

```suggestion
  AMDGPU::Waitcnt Wait = WCG->getAllZeroWaitcnt(Inst.mayStore());
```
However, as a general rule:
- loads and atomics-with-return update LOADcnt
- stores and atomics-without-return update STOREcnt

so it might be more accurate to use the condition `Inst.mayStore() && 
!SIInstrInfo::isAtomicRet(Inst)`.

Please make sure you have tests for atomics with and without return.

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


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

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


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Aaron Ballman via cfe-commits

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -1804,7 +1806,7 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(EnumForward, int));
   static_assert(!__is_layout_compatible(EnumClassForward, int));
   // FIXME: the following should be rejected (array of unknown bound and void 
are the only allowed incomplete types)
-  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); 
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete));

AaronBallman wrote:

Spurious whitespace change.

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Aaron Ballman via cfe-commits

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

My primary question is: then what is it?

We return true for `__is_aggregrate` (https://godbolt.org/z/67zjeo7Mj), and an 
aggregate is an array or class type (https://eel.is/c++draft/dcl.init.aggr#1). 
This isn't a class type... but it is an aggregate... so it must be an array? 
(We also don't claim it's a pointer or a reference currently... so this thing 
will be basically invisible to type traits.)

I would think it is an array given that it uses array syntax for declarations 
and array semantics for accesses, but it's also not an array that's usable so I 
can see why others say it's not an array. Personally, I think Clang's behavior 
here makes the most sense -- we claim it's an array, we also claim it's a 
bounded array, and we claim its extent is zero 
(https://godbolt.org/z/4GdYTh4GG), and that matches the declaration for the 
type. So with this change, I'm worried about how type traits can possibly 
reason about this type -- I'd like to understand better why other 
implementations decided this isn't an array and what it's classified as with 
their type traits. Assuming that logic is compelling, there's more work needed 
here to handle things like claiming it's a bounded array but not an array.

Also, do we need an ABI tag for folks to get the old behavior given that this 
change almost certainly will impact ABI through type traits?

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-03-26 Thread via cfe-commits


@@ -12,6 +12,7 @@
 #include 
 
 #include "config.h"
+#ifndef __wasm__

trcrsired wrote:

then it has to change cmake file, which is annoying for users.

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-03-26 Thread via cfe-commits


@@ -12,6 +12,7 @@
 #ifndef __LIBUNWIND_EXT__
 #define __LIBUNWIND_EXT__
 
+#ifndef __wasm__

trcrsired wrote:

The problem is that __WASM_EXCEPTIONS__ macro is not defined by clang, so using 
any other the header without __wasm__ will trigger ODR violation. Remote 
unwinding is not a thing for wasm, so i do not see what's wrong here

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-03-26 Thread via cfe-commits

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-03-26 Thread via cfe-commits

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> My primary question is: then what is it?
> 
> We return true for `__is_aggregrate` (https://godbolt.org/z/67zjeo7Mj), and 
> an aggregate is an array or class type 
> (https://eel.is/c++draft/dcl.init.aggr#1). This isn't a class type... but it 
> is an aggregate... so it must be an array? (We also don't claim it's a 
> pointer or a reference currently... so this thing will be basically invisible 
> to type traits.)

According to the spec it's ill-formed, so I'm not sure it falls under any 
sensible category.

> I would think it is an array given that it uses array syntax for declarations 
> and array semantics for accesses, but it's also not an array that's usable so 
> I can see why others say it's not an array. Personally, I think Clang's 
> behavior here makes the most sense -- we claim it's an array, we also claim 
> it's a bounded array, and we claim its extent is zero 
> (https://godbolt.org/z/4GdYTh4GG), and that matches the declaration for the 
> type. So with this change, I'm worried about how type traits can possibly 
> reason about this type -- I'd like to understand better why other 
> implementations decided this isn't an array and what it's classified as with 
> their type traits. Assuming that logic is compelling, there's more work 
> needed here to handle things like claiming it's a bounded array but not an 
> array.

For MSVC it's probably because they don't support `T[0]`. The main reason I 
don't think it should be considered an array for the type traits is that it 
doesn't behave like other arrays. e.g. the implementation that's used without 
the builtin is
```c++
template 
inline constexpr bool is_array_v = false;

template 
inline constexpr bool is_array_v = true;

template 
inline constexpr bool is_array_v = true;
```

For `T[0]` this returns false. 

Another example

> Also, do we need an ABI tag for folks to get the old behavior given that this 
> change almost certainly will impact ABI through type traits?

We don't use the trait currently in libc++ because of this bug and GCC only 
added it in trunk (and have the same bug), so probably not.


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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -6069,6 +6069,9 @@ def AlwaysDestroyDocs : Documentation {
 The ``always_destroy`` attribute specifies that a variable with static or 
thread
 storage duration should have its exit-time destructor run. This attribute is 
the
 default unless clang was invoked with -fno-c++-static-destructors.
+
+If a variable is explicitly declared with this attribute clang will silence the
+exit-time destructor warning.

AaronBallman wrote:

```suggestion
If a variable is explicitly declared with this attribute, Clang will silence
otherwise applicable ``-Wexit-time-destructor`` warnings.
```

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits

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

LGTM aside from a few minor nits, thank you for the improvement! I'm assuming 
you need me to land this on your behalf, so I'll go ahead and apply the fixes 
myself and then land the changes.

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -289,6 +289,10 @@ Improvements to Clang's diagnostics
 - Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
   Fixes #GH84495.
 
+- Clang no longer emits the ``exit-time destructor`` warning on static 
variables explicitly

AaronBallman wrote:

```suggestion
- Clang no longer emits a ``-Wexit-time destructor`` warning on static 
variables explicitly
```

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -289,6 +289,10 @@ Improvements to Clang's diagnostics
 - Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
   Fixes #GH84495.
 
+- Clang no longer emits a ``-Wexit-time destructor`` warning on static 
variables explicitly

AaronBallman wrote:

```suggestion
- Clang no longer emits a ``-Wexit-time destructors`` warning on static 
variables explicitly
```

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Suggesting a typo fix to my previous suggested edits

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -6069,6 +6069,9 @@ def AlwaysDestroyDocs : Documentation {
 The ``always_destroy`` attribute specifies that a variable with static or 
thread
 storage duration should have its exit-time destructor run. This attribute is 
the
 default unless clang was invoked with -fno-c++-static-destructors.
+
+If a variable is explicitly declared with this attribute, Clang will silence
+otherwise applicable ``-Wexit-time-destructor`` warnings.

AaronBallman wrote:

```suggestion
otherwise applicable ``-Wexit-time-destructors`` warnings.
```

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


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Ed Maste via cfe-commits

https://github.com/emaste created 
https://github.com/llvm/llvm-project/pull/86658

As discussed in #86320; opening this PR for CI.

It looks like (prior to this change) there are no C++26 jobs right now.

>From 6cf1345feee41ec3bad51ba853091e35723c85ab Mon Sep 17 00:00:00 2001
From: Dmitry Chagin 
Date: Thu, 12 Oct 2023 16:02:06 +0300
Subject: [PATCH 1/2] [libunwind] Unwind through aarch64/FreeBSD sigreturn
 frame

Similar to D90898 (Linux Aarch64).

Differential Revision: https://reviews.llvm.org/D155066
---
 libunwind/include/__libunwind_config.h |  5 ++
 libunwind/src/UnwindCursor.hpp | 85 --
 2 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..783a488d7de0fd 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -39,6 +39,9 @@
 # if defined(__HAIKU__)
 #  define _LIBUNWIND_TARGET_HAIKU 1
 # endif
+#if defined(__FreeBSD__)
+#define _LIBUNWIND_TARGET_FREEBSD 1
+#endif
 # if defined(__i386__)
 #  define _LIBUNWIND_TARGET_I386
 #  define _LIBUNWIND_CONTEXT_SIZE 8
@@ -73,6 +76,8 @@
 #  define _LIBUNWIND_CONTEXT_SIZE 66
 #  if defined(__SEH__)
 #define _LIBUNWIND_CURSOR_SIZE 164
+#elif defined(_LIBUNWIND_TARGET_FREEBSD)
+#define _LIBUNWIND_CURSOR_SIZE 80
 #  else
 #define _LIBUNWIND_CURSOR_SIZE 78
 #  endif
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 7753936a5894a3..96d82d6aac7c93 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -39,6 +39,17 @@
 #include 
 #include 
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
+#endif
+
+#if defined(_LIBUNWIND_TARGET_FREEBSD) && defined(_LIBUNWIND_TARGET_AARCH64)
+#include 
+#include 
+#include 
+#include 
+#include 
+#define _LIBUNWIND_CHECK_FREEBSD_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
 #endif
 
 #include "AddressSpace.hpp"
@@ -983,7 +994,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   }
 #endif
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool setInfoForSigReturn() {
 R dummy;
 return setInfoForSigReturn(dummy);
@@ -1011,7 +1022,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   template  int stepThroughSigReturn(Registers &) {
 return UNW_STEP_END;
   }
-#endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 
 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
   bool getInfoFromFdeCie(const typename CFI_Parser::FDE_Info &fdeInfo,
@@ -1314,9 +1325,14 @@ class UnwindCursor : public AbstractUnwindCursor{
   unw_proc_info_t  _info;
   bool _unwindInfoMissing;
   bool _isSignalFrame;
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool _isSigReturn = false;
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN)
+  bool _isSigTrampDetermined = false;
+  pint_t _sigTrampStart;
+  pint_t _sigTrampEnd;
 #endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 };
 
 
@@ -2558,7 +2574,7 @@ int UnwindCursor::stepWithTBTable(pint_t pc, 
tbtable *TBTable,
 
 template 
 void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) {
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   _isSigReturn = false;
 #endif
 
@@ -2673,7 +2689,7 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool 
isReturnAddress) {
   }
 #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   if (setInfoForSigReturn())
 return;
 #endif
@@ -2909,6 +2925,63 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN) && 
\
+defined(_LIBUNWIND_TARGET_AARCH64)
+template 
+bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) {
+  // Look for the sigreturn trampoline.
+  //
+  // https://cgit.freebsd.org/src/tree/sys/arm64/arm64/sigtramp.S
+  const pint_t pc = static_cast(this->getReg(UNW_REG_IP));
+
+  if (_isSigTrampDetermined == false) {
+struct kinfo_sigtramp kst = {0};
+size_t len = sizeof(kst);
+int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_SIGTRAMP, getpid()};
+if (sysctl(mib, 4, &kst, &len, NULL, 0) == 0) {
+  _isSigTrampDetermined = true;
+  _sigTrampStart = reinterpret_cast(kst.ksigtramp_start);
+  _sigTrampEnd = reinterpret_cast(kst.ksigtramp_end);
+}
+  }
+
+  if (_isSigTrampDetermined == false ||
+  (pc < _sigTrampStart || pc >= _sigTrampEnd))
+return false;
+
+  _info = {};
+  _info.start_ip = _sigTrampStart;
+  _info.end_ip = _sigTrampEnd;
+  _isSigReturn = true;
+  return true;
+}
+
+template 
+int UnwindCursor::stepThroughSigReturn(Registers_arm64 &) {
+  // In the signal trampoline 

[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Ed Maste (emaste)


Changes

As discussed in #86320; opening this PR for CI.

It looks like (prior to this change) there are no C++26 jobs right now.

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


3 Files Affected:

- (modified) libcxx/utils/ci/buildkite-pipeline.yml (+1-1) 
- (modified) libunwind/include/__libunwind_config.h (+5) 
- (modified) libunwind/src/UnwindCursor.hpp (+79-6) 


``diff
diff --git a/libcxx/utils/ci/buildkite-pipeline.yml 
b/libcxx/utils/ci/buildkite-pipeline.yml
index 31e794e67d330d..c43e414418729a 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -207,7 +207,7 @@ steps:
 - group: ':freebsd: FreeBSD'
   steps:
   - label: FreeBSD 13 amd64
-command: libcxx/utils/ci/run-buildbot generic-cxx23
+command: libcxx/utils/ci/run-buildbot generic-cxx26
 env:
   CC: clang17
   CXX: clang++17
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..783a488d7de0fd 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -39,6 +39,9 @@
 # if defined(__HAIKU__)
 #  define _LIBUNWIND_TARGET_HAIKU 1
 # endif
+#if defined(__FreeBSD__)
+#define _LIBUNWIND_TARGET_FREEBSD 1
+#endif
 # if defined(__i386__)
 #  define _LIBUNWIND_TARGET_I386
 #  define _LIBUNWIND_CONTEXT_SIZE 8
@@ -73,6 +76,8 @@
 #  define _LIBUNWIND_CONTEXT_SIZE 66
 #  if defined(__SEH__)
 #define _LIBUNWIND_CURSOR_SIZE 164
+#elif defined(_LIBUNWIND_TARGET_FREEBSD)
+#define _LIBUNWIND_CURSOR_SIZE 80
 #  else
 #define _LIBUNWIND_CURSOR_SIZE 78
 #  endif
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 7753936a5894a3..96d82d6aac7c93 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -39,6 +39,17 @@
 #include 
 #include 
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
+#endif
+
+#if defined(_LIBUNWIND_TARGET_FREEBSD) && defined(_LIBUNWIND_TARGET_AARCH64)
+#include 
+#include 
+#include 
+#include 
+#include 
+#define _LIBUNWIND_CHECK_FREEBSD_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
 #endif
 
 #include "AddressSpace.hpp"
@@ -983,7 +994,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   }
 #endif
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool setInfoForSigReturn() {
 R dummy;
 return setInfoForSigReturn(dummy);
@@ -1011,7 +1022,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   template  int stepThroughSigReturn(Registers &) {
 return UNW_STEP_END;
   }
-#endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 
 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
   bool getInfoFromFdeCie(const typename CFI_Parser::FDE_Info &fdeInfo,
@@ -1314,9 +1325,14 @@ class UnwindCursor : public AbstractUnwindCursor{
   unw_proc_info_t  _info;
   bool _unwindInfoMissing;
   bool _isSignalFrame;
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool _isSigReturn = false;
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN)
+  bool _isSigTrampDetermined = false;
+  pint_t _sigTrampStart;
+  pint_t _sigTrampEnd;
 #endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 };
 
 
@@ -2558,7 +2574,7 @@ int UnwindCursor::stepWithTBTable(pint_t pc, 
tbtable *TBTable,
 
 template 
 void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) {
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   _isSigReturn = false;
 #endif
 
@@ -2673,7 +2689,7 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool 
isReturnAddress) {
   }
 #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   if (setInfoForSigReturn())
 return;
 #endif
@@ -2909,6 +2925,63 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN) && 
\
+defined(_LIBUNWIND_TARGET_AARCH64)
+template 
+bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) {
+  // Look for the sigreturn trampoline.
+  //
+  // https://cgit.freebsd.org/src/tree/sys/arm64/arm64/sigtramp.S
+  const pint_t pc = static_cast(this->getReg(UNW_REG_IP));
+
+  if (_isSigTrampDetermined == false) {
+struct kinfo_sigtramp kst = {0};
+size_t len = sizeof(kst);
+int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_SIGTRAMP, getpid()};
+if (sysctl(mib, 4, &kst, &len, NULL, 0) == 0) {
+  _isSigTrampDetermined = true;
+  _sigTrampStart = reinterpret_cast(kst.ksigtramp_start);
+  _sigTrampEnd = reinterpret_cast(kst.ksigtramp_end);
+}
+  }
+
+  if (_isSigTrampDetermined == false ||
+  (pc < _s

[clang] 59e0525 - [[clang::always_destroy]] attribute silences warn-exit-time-destructor (#86486)

2024-03-26 Thread via cfe-commits

Author: ycdtosa
Date: 2024-03-26T08:38:31-04:00
New Revision: 59e052568e7d46cc0489269e3c76f53bb21941f5

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

LOG: [[clang::always_destroy]] attribute silences warn-exit-time-destructor 
(#86486)

This attribute tells the compiler that the variable must have its exit-time
destructor run, so it makes sense that it would silence the warning telling
users that an exit-time destructor is required.

Fixes https://github.com/llvm/llvm-project/issues/68686

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/warn-exit-time-destructors.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..af2295c43d7e22 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -295,6 +295,10 @@ Improvements to Clang's diagnostics
 - Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
   Fixes #GH84495.
 
+- Clang no longer emits a ``-Wexit-time destructors`` warning on static 
variables explicitly
+  annotated with the ``clang::always_destroy`` attribute.
+  Fixes #GH68686, #GH86486
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 9de14f608fd114..384aebbdf2e32a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6069,6 +6069,9 @@ def AlwaysDestroyDocs : Documentation {
 The ``always_destroy`` attribute specifies that a variable with static or 
thread
 storage duration should have its exit-time destructor run. This attribute is 
the
 default unless clang was invoked with -fno-c++-static-destructors.
+
+If a variable is explicitly declared with this attribute, Clang will silence
+otherwise applicable ``-Wexit-time-destructors`` warnings.
   }];
 }
 

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ee732679417e37..7070ea00cff275 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16202,7 +16202,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const 
RecordType *Record) {
 
   // Emit warning for non-trivial dtor in global scope (a real global,
   // class-static, function-static).
-  Diag(VD->getLocation(), diag::warn_exit_time_destructor);
+  if (!VD->hasAttr())
+Diag(VD->getLocation(), diag::warn_exit_time_destructor);
 
   // TODO: this should be re-enabled for static locals by !CXAAtExit
   if (!VD->isStaticLocal())

diff  --git a/clang/test/SemaCXX/warn-exit-time-destructors.cpp 
b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
index 2f14243cb48c47..55ae37d7368f88 100644
--- a/clang/test/SemaCXX/warn-exit-time-destructors.cpp
+++ b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
@@ -51,6 +51,15 @@ struct A { ~A(); };
 }
 
 namespace test5 {
+  struct A { ~A(); };
+  [[clang::always_destroy]] A a; // no warning
+
+  void func() {
+[[clang::always_destroy]] static A a; // no warning
+  }
+}
+
+namespace test6 {
 #if __cplusplus >= 202002L
 #define CPP20_CONSTEXPR constexpr
 #else
@@ -68,3 +77,4 @@ namespace test5 {
   T t; // expected-warning {{exit-time destructor}}
 #undef CPP20_CONSTEXPR
 }
+



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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread Aaron Ballman via cfe-commits

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


[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)

2024-03-26 Thread via cfe-commits

github-actions[bot] wrote:



@ycdtosa Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)

2024-03-26 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,25 @@
+.. title:: clang-tidy - readability-math-missing-parentheses
+
+readability-math-missing-parentheses
+
+
+Check for missing parentheses in mathematical expressions that involve 
operators
+of different priorities. Parentheses in mathematical expressions clarify the 
order
+of operations, especially with different-priority operators. Lengthy or 
multiline
+expressions can obscure this order, leading to coding errors. IDEs can aid 
clarity
+by highlighting parentheses. Explicitly using parentheses also clarify what 
the 

5chmidti wrote:

Maybe I didn't select the correct lines, given that GitHub shows 4 lines here, 
my bad. I only meant the second `clarify`, not both.
- `Parentheses in mathematical expressions clarify`
- `Explicitly using parentheses also clarifies`

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


[clang] feebcd6 - [clang] Fix -Wunused-variable in SemaDecl.cpp (NFC)

2024-03-26 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2024-03-26T20:41:46+08:00
New Revision: feebcd65fb7e0534f5219e05432a05e45aa8cd2a

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

LOG: [clang] Fix -Wunused-variable in SemaDecl.cpp (NFC)

llvm-project/clang/lib/Sema/SemaDecl.cpp:11653:20:
error: unused variable 'OldMVKind' [-Werror,-Wunused-variable]
  MultiVersionKind OldMVKind = OldFD->getMultiVersionKind();
   ^
1 error generated.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9a286e0b26a4c6..b907fee01d5f26 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11650,7 +11650,7 @@ static bool CheckMultiVersionAdditionalDecl(
   const auto *NewTA = NewFD->getAttr();
   const auto *NewTVA = NewFD->getAttr();
   MultiVersionKind NewMVKind = NewFD->getMultiVersionKind();
-  MultiVersionKind OldMVKind = OldFD->getMultiVersionKind();
+  [[maybe_unused]] MultiVersionKind OldMVKind = OldFD->getMultiVersionKind();
 
   ParsedTargetAttr NewParsed;
   if (NewTA) {



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


[clang-tools-extra] [clang-tidy] Fix fix-it overlaps in readability-static-definition-in-anonymous-namespace (PR #86599)

2024-03-26 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-03-26 Thread via cfe-commits


@@ -12,6 +12,7 @@
 #include 
 
 #include "config.h"
+#ifndef __wasm__

EricWF wrote:

I feel like we could detect `__wasm__` or similar in CMake. And it feels like 
the right tool, though maybe not the most trivial to implement.

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


[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)

2024-03-26 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/84481

>From 8fdf6306085ed4cf0f77b7e718e374e9f65fedf9 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 8 Mar 2024 19:02:47 +0530
Subject: [PATCH 1/8] add clang-tidy check readability-math-missing-parentheses

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../MathMissingParenthesesCheck.cpp   | 167 ++
 .../readability/MathMissingParenthesesCheck.h |  31 
 .../readability/ReadabilityTidyModule.cpp |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../readability/math-missing-parentheses.rst  |  19 ++
 .../readability/math-missing-parentheses.cpp  |  42 +
 8 files changed, 270 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index a6c8cbd8eb448a..0d4fa095501dfb 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangTidyReadabilityModule
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
   MakeMemberFunctionConstCheck.cpp
+  MathMissingParenthesesCheck.cpp
   MisleadingIndentationCheck.cpp
   MisplacedArrayIndexCheck.cpp
   NamedParameterCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
new file mode 100644
index 00..d9574a9fb7a476
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -0,0 +1,167 @@
+//===--- MathMissingParenthesesCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MathMissingParenthesesCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())),
+hasDescendant(binaryOperator()))
+ .bind("binOp"),
+ this);
+}
+static int precedenceCheck(const char op) {
+  if (op == '/' || op == '*' || op == '%')
+return 5;
+
+  else if (op == '+' || op == '-')
+return 4;
+
+  else if (op == '&')
+return 3;
+  else if (op == '^')
+return 2;
+
+  else if (op == '|')
+return 1;
+
+  else
+return 0;
+}
+static bool isOperand(const char c) {
+  if (c >= 'a' && c <= 'z')
+return true;
+  else if (c >= 'A' && c <= 'Z')
+return true;
+  else if (c >= '0' && c <= '9')
+return true;
+  else if (c == '$')
+return true;
+  else
+return false;
+}
+static bool conditionForNegative(const std::string s, int i,
+ const std::string CurStr) {
+  if (CurStr[0] == '-') {
+if (i == 0) {
+  return true;
+} else {
+  while (s[i - 1] == ' ') {
+i--;
+  }
+  if (!isOperand(s[i - 1])) {
+return true;
+  } else {
+return false;
+  }
+}
+  } else {
+return false;
+  }
+}
+static std::string getOperationOrder(std::string s, std::set &Operators) 
{
+  std::stack StackOne;
+  std::string TempStr = "";
+  for (int i = 0; i < s.length(); i++) {
+std::string CurStr = "";
+CurStr += s[i];
+if (CurStr == " ")
+  continue;
+else {
+  if (isOperand(CurStr[0]) || conditionForNegative(s, i, CurStr)) {
+while (i < s.length() && (isOperand(s[i]) || s[i] == '-')) {
+  if (s[i] == '-') {
+TempStr += "$";
+  } else {
+TempStr += CurStr;
+  }
+  i++;
+  CurStr = s[i];
+}
+TempStr += " ";
+  } else if (CurStr == "(") {
+StackOne.push("(");
+  } else if (CurStr == ")") {
+while (StackOne.top() != "(") {
+  TempStr += StackOne.top();
+  StackOne.pop();
+}
+StackOne.pop();
+  } else {
+while (!StackOne.empty() && precedenceCheck

[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)

2024-03-26 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,25 @@
+.. title:: clang-tidy - readability-math-missing-parentheses
+
+readability-math-missing-parentheses
+
+
+Check for missing parentheses in mathematical expressions that involve 
operators
+of different priorities. Parentheses in mathematical expressions clarify the 
order
+of operations, especially with different-priority operators. Lengthy or 
multiline
+expressions can obscure this order, leading to coding errors. IDEs can aid 
clarity
+by highlighting parentheses. Explicitly using parentheses also clarify what 
the 

11happy wrote:

done

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> According to the spec it's ill-formed, so I'm not sure it falls under any 
> sensible category.

It's an extension we support so it's up to us to decide what sensible is.

> For T[0] this returns false.

Understood, but why is this not the bug to be fixed? (It would also fix the 
`takes_an_array` case as well.)

> We don't use the trait currently in libc++ because of this bug and GCC only 
> added it in trunk (and have the same bug), so probably not.

For example, it seems to be used in Unreal Engine: 
https://github.com/windystrife/UnrealEngine_NVIDIAGameWorks/blob/b50e6338a7c5b26374d66306ebc7807541ff815e/Engine/Source/Runtime/Core/Public/Templates/UnrealTemplate.h#L128

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-26 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

@arsenm would you be fine with those codegen changes as-is? Given that the 
convergent/no-convergent switch will be done later, depending on when the 
required IR change is merged?

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,223 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+
+// Verify that -Wformat-signedness alone (without -Wformat) trigger the
+// warnings. Note in gcc this will not trigger the signedness warnings as
+// -Wformat is default off in gcc.
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+
+// Verify that -Wformat-signedness warnings are not reported with only -Wformat
+// (gcc compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-Werror %s
+
+// Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -Werror %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -Werror %s
+
+#include 
+
+int printf(const char *restrict format, ...);
+int scanf(const char * restrict, ...);
+
+void test_printf_bool(_Bool x)
+{
+printf("%d", x); // no-warning
+printf("%u", x); // no-warning
+printf("%x", x); // no-warning
+}
+
+void test_printf_char(char x)
+{
+printf("%c", x); // no-warning
+}
+
+void test_printf_unsigned_char(unsigned char x)
+{
+printf("%c", x); // no-warning
+}
+
+void test_printf_int(int x)
+{
+printf("%d", x); // no-warning
+printf("%u", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has type 'int'}}
+printf("%x", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has type 'int'}}
+}
+
+void test_printf_unsigned(unsigned x)
+{
+printf("%d", x); // expected-warning{{format specifies type 'int' but the 
argument has type 'unsigned int'}}
+printf("%u", x); // no-warning
+printf("%x", x); // no-warning
+}
+
+void test_printf_long(long x)
+{
+printf("%ld", x); // no-warning
+printf("%lu", x); // expected-warning{{format specifies type 'unsigned 
long' but the argument has type 'long'}}
+printf("%lx", x); // expected-warning{{format specifies type 'unsigned 
long' but the argument has type 'long'}}
+}
+
+void test_printf_unsigned_long(unsigned long x)
+{
+printf("%ld", x); // expected-warning{{format specifies type 'long' but 
the argument has type 'unsigned long'}}
+printf("%lu", x); // no-warning
+printf("%lx", x); // no-warning
+}
+
+void test_printf_long_long(long long x)
+{
+printf("%lld", x); // no-warning
+printf("%llu", x); // expected-warning{{format specifies type 'unsigned 
long long' but the argument has type 'long long'}}
+printf("%llx", x); // expected-warning{{format specifies type 'unsigned 
long long' but the argument has type 'long long'}}
+}
+
+void test_printf_unsigned_long_long(unsigned long long x)
+{
+printf("%lld", x); // expected-warning{{format specifies type 'long long' 
but the argument has type 'unsigned long long'}}
+printf("%llu", x); // no-warning
+printf("%llx", x); // no-warning
+}
+
+enum enum_int {
+minus_1 = -1
+};
+
+void test_printf_enum_int(enum enum_int x)
+{
+printf("%d", x); // no-warning
+printf("%u", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has underlying type 'int'}}
+printf("%x", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has underlying type 'int'}}
+}
+
+#ifndef _WIN32 // Disabled due to enums have different underlying type on 
_WIN32
+enum enum_unsigned {
+zero = 0
+};
+
+void test_printf_enum_unsigned(enum enum_unsigned x)
+{
+printf("%d", x); // expected-warning{{format specifies type 'int' but the 
argument has underlying type 'unsigned int'}}
+printf("%u", x); // no-warning
+printf("%x", x); // no-warning
+}
+
+enum enum_long {
+minus_one = -1,
+int_val = INT_MAX,
+unsigned_val = (unsigned)INT_MIN

AaronBallman wrote:

```suggestion
int_val = __INT_MAX__,
unsigned_val = (unsigned)(-__INT_MAX__ - 1)
```

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,223 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+
+// Verify that -Wformat-signedness alone (without -Wformat) trigger the
+// warnings. Note in gcc this will not trigger the signedness warnings as
+// -Wformat is default off in gcc.
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+
+// Verify that -Wformat-signedness warnings are not reported with only -Wformat
+// (gcc compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-Werror %s
+
+// Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -Werror %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -Werror %s
+
+#include 

AaronBallman wrote:

```suggestion
```
I think we should drop this include (avoids relying on finding the limits.h 
from Clang without passing `-ffreestanding` for the tests). Instead, we can use 
the predefined macros below.

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,223 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+
+// Verify that -Wformat-signedness alone (without -Wformat) trigger the
+// warnings. Note in gcc this will not trigger the signedness warnings as
+// -Wformat is default off in gcc.
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+
+// Verify that -Wformat-signedness warnings are not reported with only -Wformat
+// (gcc compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-Werror %s
+
+// Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -Werror %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -Werror %s

AaronBallman wrote:

```suggestion
// Verify that -Wformat-signedness warnings are not reported with only -Wformat
// (gcc compat).
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-Werror %s

// Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -verify=okay %s
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -verify=okay %s

// okay-no-diagnostics
```
These are all missing `-verify` lines so they're relying on `-Werror` to 
upgrade diagnostics from warnings to errors and that the return value from 
`clang -cc1` will be non-zero if a diagnostic was emitted. This works but is a 
bit subtle -- usually we'd have `-verify` in all of the `RUN` lines and we'd 
use a different prefix for these and we ensure there are no diagnostics with 
the diagnostics verifier, along these lines.

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,223 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+
+// Verify that -Wformat-signedness alone (without -Wformat) trigger the
+// warnings. Note in gcc this will not trigger the signedness warnings as
+// -Wformat is default off in gcc.
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+
+// Verify that -Wformat-signedness warnings are not reported with only -Wformat
+// (gcc compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-Werror %s
+
+// Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -Werror %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -Werror %s
+
+#include 
+
+int printf(const char *restrict format, ...);
+int scanf(const char * restrict, ...);
+
+void test_printf_bool(_Bool x)
+{
+printf("%d", x); // no-warning
+printf("%u", x); // no-warning
+printf("%x", x); // no-warning
+}
+
+void test_printf_char(char x)
+{
+printf("%c", x); // no-warning
+}
+
+void test_printf_unsigned_char(unsigned char x)
+{
+printf("%c", x); // no-warning
+}
+
+void test_printf_int(int x)
+{
+printf("%d", x); // no-warning
+printf("%u", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has type 'int'}}
+printf("%x", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has type 'int'}}
+}
+
+void test_printf_unsigned(unsigned x)
+{
+printf("%d", x); // expected-warning{{format specifies type 'int' but the 
argument has type 'unsigned int'}}
+printf("%u", x); // no-warning
+printf("%x", x); // no-warning
+}
+
+void test_printf_long(long x)
+{
+printf("%ld", x); // no-warning
+printf("%lu", x); // expected-warning{{format specifies type 'unsigned 
long' but the argument has type 'long'}}
+printf("%lx", x); // expected-warning{{format specifies type 'unsigned 
long' but the argument has type 'long'}}
+}
+
+void test_printf_unsigned_long(unsigned long x)
+{
+printf("%ld", x); // expected-warning{{format specifies type 'long' but 
the argument has type 'unsigned long'}}
+printf("%lu", x); // no-warning
+printf("%lx", x); // no-warning
+}
+
+void test_printf_long_long(long long x)
+{
+printf("%lld", x); // no-warning
+printf("%llu", x); // expected-warning{{format specifies type 'unsigned 
long long' but the argument has type 'long long'}}
+printf("%llx", x); // expected-warning{{format specifies type 'unsigned 
long long' but the argument has type 'long long'}}
+}
+
+void test_printf_unsigned_long_long(unsigned long long x)
+{
+printf("%lld", x); // expected-warning{{format specifies type 'long long' 
but the argument has type 'unsigned long long'}}
+printf("%llu", x); // no-warning
+printf("%llx", x); // no-warning
+}
+
+enum enum_int {
+minus_1 = -1
+};
+
+void test_printf_enum_int(enum enum_int x)
+{
+printf("%d", x); // no-warning
+printf("%u", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has underlying type 'int'}}
+printf("%x", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has underlying type 'int'}}
+}
+
+#ifndef _WIN32 // Disabled due to enums have different underlying type on 
_WIN32
+enum enum_unsigned {
+zero = 0
+};
+
+void test_printf_enum_unsigned(enum enum_unsigned x)
+{
+printf("%d", x); // expected-warning{{format specifies type 'int' but the 
argument has underlying type 'unsigned int'}}
+printf("%u", x); // no-warning
+printf("%x", x); // no-warning
+}
+
+enum enum_long {
+minus_one = -1,
+int_val = INT_MAX,
+unsigned_val = (unsigned)INT_MIN
+};
+
+void test_printf_enum_long(enum enum_long x)
+{
+printf("%ld", x); // no-warning
+printf("%lu", x); // expected-warning{{format specifies type 'unsigned 
long' but the argument has underlying type 'long'}}
+printf("%lx", x); // expected-warning{{format specifies type 'unsigned 
long' but the argument has underlying type 'long'}}
+}
+
+enum enum_unsigned_long {
+uint_max_plus = (unsigned long)UINT_MAX+1,

AaronBallman wrote:

```suggestion
uint_max_plus = (unsigned long)((__INT_MAX__  *2U +1U)+1),
```

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


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Aaron Ballman via cfe-commits

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

Good catch, LGTM!

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> > According to the spec it's ill-formed, so I'm not sure it falls under any 
> > sensible category.
> 
> It's an extension we support so it's up to us to decide what sensible is.

Sure. If we end up putting it in the array category we should probably 
coordinate with GCC.

> > For T[0] this returns false.
> 
> Understood, but why is this not the bug to be fixed? (It would also fix the 
> `takes_an_array` case as well.)

Because I don't think we can. AFAICT this is valid C++:
```c++
template 
int func() {
  return 1;
}

template 
int func() {
  return 0;
}
```
If clang accepted `int[0]` in this context the observable behaviour would 
change.

> > We don't use the trait currently in libc++ because of this bug and GCC only 
> > added it in trunk (and have the same bug), so probably not.
> 
> For example, it seems to be used in Unreal Engine: 
> https://github.com/windystrife/UnrealEngine_NVIDIAGameWorks/blob/b50e6338a7c5b26374d66306ebc7807541ff815e/Engine/Source/Runtime/Core/Public/Templates/UnrealTemplate.h#L128

If you think it's a significant enough change that we should add an ABI tag I 
can do that.


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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -2805,7 +2805,7 @@ static bool handleIntIntBinOp(EvalInfo &Info, const Expr 
*E, const APSInt &LHS,
 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1);
 if (SA != RHS) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
-<< RHS << E->getType() << LHS.getBitWidth();
+  << RHS << E->getType() << LHS.getBitWidth();

AaronBallman wrote:

FWIW, you should be using `clang-format-diff` so that you're only formatting 
the changes made in the PR: 
https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting

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


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

@AaronBallman Thanks!


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


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

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


[clang] 3a2c70b - Fix printing of templated records. (#86339)

2024-03-26 Thread via cfe-commits

Author: Zahira Ammarguellat
Date: 2024-03-26T09:06:46-04:00
New Revision: 3a2c70b3713a856ea416d92abdddb7893fca308b

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

LOG: Fix printing of templated records. (#86339)

Fixed the printing of templated argument list and added test case.

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp
clang/unittests/AST/DeclPrinterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 7032ff2f18468c..d9504f9dcb3899 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2303,11 +2303,6 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 } else {
   if (!FirstArg)
 OS << Comma;
-  if (!Policy.SuppressTagKeyword &&
-  Argument.getKind() == TemplateArgument::Type &&
-  isa(Argument.getAsType()))
-OS << Argument.getAsType().getAsString();
-  else
 // Tries to print the argument with location info if exists.
 printArgument(Arg, Policy, ArgOS,
   TemplateParameterList::shouldIncludeTypeForArgument(

diff  --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index e024c41e03b484..07fa02bd96e25d 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1386,6 +1386,75 @@ TEST(DeclPrinter, TestTemplateArgumentList16) {
   ASSERT_TRUE(PrintedDeclCXX11Matches(Code, "NT2", "int NT2 = 5"));
 }
 
+TEST(DeclPrinter, TestCXXRecordDecl17) {
+  ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
+  "struct X {};"
+  "Z A;",
+  "A", "Z A"));
+  [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; };
+}
+
+TEST(DeclPrinter, TestCXXRecordDecl18) {
+  ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
+  "struct X {};"
+  "Z A;"
+  "template "
+  "struct Y{};"
+  "Y, 2> B;",
+  "B", "Y, 2> B"));
+  [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; };
+}
+
+TEST(DeclPrinter, TestCXXRecordDecl19) {
+  ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
+  "struct X {};"
+  "Z A;"
+  "template "
+  "struct Y{};"
+  "Y, 2> B;",
+  "B", "Y, 2> B"));
+  [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = true; };
+}
+TEST(DeclPrinter, TestCXXRecordDecl20) {
+  ASSERT_TRUE(PrintedDeclCXX98Matches(
+  "template  class Inner;"
+  "template "
+  "class Inner{Inner(T val){}};"
+  "template  class Outer {"
+  "public:"
+  "struct NestedStruct {"
+  "int nestedValue;"
+  "NestedStruct(int val) : nestedValue(val) {}"
+  "};"
+  "InnerClass innerInstance;"
+  "Outer(const InnerClass &inner) : innerInstance(inner) {}"
+  "};"
+  "Outer, 5>::NestedStruct nestedInstance(100);",
+  "nestedInstance",
+  "Outer, 5>::NestedStruct nestedInstance(100)"));
+  [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; };
+}
+
+TEST(DeclPrinter, TestCXXRecordDecl21) {
+  ASSERT_TRUE(PrintedDeclCXX98Matches(
+  "template  class Inner;"
+  "template "
+  "class Inner{Inner(T val){}};"
+  "template  class Outer {"
+  "public:"
+  "struct NestedStruct {"
+  "int nestedValue;"
+  "NestedStruct(int val) : nestedValue(val) {}"
+  "};"
+  "InnerClass innerInstance;"
+  "Outer(const InnerClass &inner) : innerInstance(inner) {}"
+  "};"
+  "Outer, 5>::NestedStruct nestedInstance(100);",
+  "nestedInstance",
+  "Outer, 5>::NestedStruct nestedInstance(100)"));
+  [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = true; };
+}
+
 TEST(DeclPrinter, TestFunctionParamUglified) {
   llvm::StringLiteral Code = R"cpp(
 class __c;



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


[clang-tools-extra] [clang-tidy] Improve performance of google-runtime-int (PR #86596)

2024-03-26 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM. That's a very nice speedup :)

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-26 Thread Matt Arsenault via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 


arsenm wrote:

> @arsenm would you be fine with those codegen changes as-is? Given that the 
> convergent/no-convergent switch will be done later, depending on when the 
> required IR change is merged?

Yes 

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -11444,9 +11444,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   llvm::APSInt Right = RHSResult.Val.getInt();
 
   if (Right.isNegative()) {
-S.DiagRuntimeBehavior(Loc, RHS.get(),
-  S.PDiag(diag::warn_shift_negative)
-<< RHS.get()->getSourceRange());
+if (S.ExprEvalContexts.back().isConstantEvaluated())
+  S.Diag(Loc, diag::warn_shift_negative) << RHS.get()->getSourceRange();
+else
+  S.DiagRuntimeBehavior(Loc, RHS.get(),
+S.PDiag(diag::warn_shift_negative)
+  << RHS.get()->getSourceRange());

AaronBallman wrote:

I still don't think this is the correct fix -- I think the issue is that 
ExprConstant.cpp needs to be taught about these as undefined behaviors. Notice 
how GCC correctly emits the pedantic diagnostic but Clang does not: 
https://godbolt.org/z/arb8Y9G9q

When I step through in the debugger, it seems that we do catch the issue in 
`handleIntIntBinOp()` but we're suppressing diagnostics for it in C more 
broadly. That seems more likely to be the root cause of the issue. (Basically, 
we want the diagnostics to be split between SemaExpr.cpp for runtime reachable 
diagnostics and ExprConstant.cpp for constant expressions.)

CC @tbaederr for opinions on constant expression behavior here.

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-26 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

@ssahasra it is up to you then 😊

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-26 Thread Nathan Gauër via cfe-commits

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


[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86587

>From 9b25b0486d8f3c8409ee199a9f4695da7780e6cb Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 25 Mar 2024 17:12:14 -0400
Subject: [PATCH 1/2] [InstallAPI] Add *umbrella-header options

Umbrella headers are a concept for darwin based libraries. They allow
framework authors control the order of which their headers should be
parsed and allows clients to access available headers by including a
single header.

InstallAPI will attempt to find the umbrella based on the name of the
framework. Users can also specify this explicitly by using command line
options specifying the umbrella header by file path.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  1 +
 clang/include/clang/InstallAPI/HeaderFile.h   | 12 ++-
 clang/test/InstallAPI/umbrella-headers.test   | 59 +++
 .../tools/clang-installapi/InstallAPIOpts.td  | 12 +++
 clang/tools/clang-installapi/Options.cpp  | 74 +++
 clang/tools/clang-installapi/Options.h|  9 +++
 llvm/include/llvm/TextAPI/Utils.h |  3 +
 7 files changed, 167 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/InstallAPI/umbrella-headers.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 27df731fa28627..d710688fc1fe20 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -18,6 +18,7 @@ def err_no_output_file: Error<"no output file specified">;
 def err_no_such_header_file : Error<"no such %select{public|private|project}1 
header file: '%0'">;
 def warn_no_such_excluded_header_file : Warning<"no such excluded 
%select{public|private}0 header file: '%1'">, InGroup;
 def warn_glob_did_not_match: Warning<"glob '%0' did not match any header 
file">, InGroup;
+def err_no_such_umbrella_header_file : Error<"no such 
%select{public|private|project}1 umbrella header file: '%0'">;
 } // end of command line category.
 
 let CategoryName = "Verification" in {
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index 235b4da3add840..332cd415b39ae4 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/include/clang/InstallAPI/HeaderFile.h
@@ -62,6 +62,8 @@ class HeaderFile {
   bool Excluded{false};
   /// Add header file to processing.
   bool Extra{false};
+  /// Specify that header file is the umbrella header for library.
+  bool Umbrella{false};
 
 public:
   HeaderFile() = delete;
@@ -79,17 +81,21 @@ class HeaderFile {
 
   void setExtra(bool V = true) { Extra = V; }
   void setExcluded(bool V = true) { Excluded = V; }
+  void setUmbrellaHeader(bool V = true) { Umbrella = V; }
   bool isExtra() const { return Extra; }
   bool isExcluded() const { return Excluded; }
+  bool isUmbrellaHeader() const { return Umbrella; }
 
   bool useIncludeName() const {
 return Type != HeaderType::Project && !IncludeName.empty();
   }
 
   bool operator==(const HeaderFile &Other) const {
-return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra) ==
-   std::tie(Other.Type, Other.FullPath, Other.IncludeName,
-Other.Language, Other.Excluded, Other.Extra);
+return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
+Umbrella) == std::tie(Other.Type, Other.FullPath,
+  Other.IncludeName, Other.Language,
+  Other.Excluded, Other.Extra,
+  Other.Umbrella);
   }
 };
 
diff --git a/clang/test/InstallAPI/umbrella-headers.test 
b/clang/test/InstallAPI/umbrella-headers.test
new file mode 100644
index 00..b91d3df25b38ec
--- /dev/null
+++ b/clang/test/InstallAPI/umbrella-headers.test
@@ -0,0 +1,59 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
+
+// Try umbrella header flags with different spellings.
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN:  -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: 
--public-umbrella-header=%t/Frameworks/Umbrella2.framework/Headers/SpecialUmbrella.h
 \
+; RUN: -private-umbrella-header \
+; RUN: 
%t/Frameworks/Umbrella2.framework/PrivateHeaders/SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN: -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: --public-umbrella-header=SpecialUmbrella.h \
+; RUN: --private-umbrella-header=SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; CHECK-NOT: error
+; CHECK-N

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-03-26 Thread via cfe-commits


@@ -873,9 +873,14 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
 
   if (D->isPureVirtual())
 Out << " = 0";
-  else if (D->isDeletedAsWritten())
+  else if (D->isDeletedAsWritten()) {
 Out << " = delete";
-  else if (D->isExplicitlyDefaulted())
+if (const auto *M = D->getDeletedMessage()) {

Sirraide wrote:

Ah yeah, I have a habit of always writing `auto`, so I forget about this 
sometimes; will do.

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


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-03-26 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/86526

>From 98af47e8ccc633016c14b91c221f9f8fc620f068 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Mon, 25 Mar 2024 14:46:52 +0100
Subject: [PATCH 1/8] [Clang] Parse `= delete("message")`

---
 clang/include/clang/AST/Decl.h| 13 
 clang/include/clang/Parse/Parser.h|  1 +
 clang/include/clang/Sema/Sema.h   |  6 ++--
 clang/lib/AST/Decl.cpp|  4 +--
 clang/lib/AST/DeclPrinter.cpp |  9 +++--
 clang/lib/AST/TextNodeDumper.cpp  |  3 ++
 clang/lib/Parse/ParseCXXInlineMethods.cpp | 24 +-
 clang/lib/Parse/Parser.cpp|  4 ++-
 clang/lib/Sema/SemaDeclCXX.cpp| 10 +++---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  6 
 .../test/Parser/cxx2c-delete-with-message.cpp | 33 +++
 11 files changed, 100 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Parser/cxx2c-delete-with-message.cpp

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index a5879591f4c659..24f0394577e228 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2013,6 +2013,12 @@ class FunctionDecl : public DeclaratorDecl,
 DefaultedFunctionInfo *DefaultedInfo;
   };
 
+  /// Message that indicates why this function was deleted.
+  ///
+  /// FIXME: Figure out where to actually put this; maybe in the
+  /// 'DefaultedInfo' above?
+  StringLiteral *DeletedMessage;
+
   unsigned ODRHash;
 
   /// End part of this FunctionDecl's source range.
@@ -2483,6 +2489,10 @@ class FunctionDecl : public DeclaratorDecl,
   }
 
   void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
+  void setDeletedWithMessage(StringLiteral* Message) {
+FunctionDeclBits.IsDeleted = true;
+DeletedMessage = Message;
+  }
 
   /// Determines whether this function is "main", which is the
   /// entry point into an executable program.
@@ -2638,6 +2648,9 @@ class FunctionDecl : public DeclaratorDecl,
   AC.push_back(TRC);
   }
 
+  /// Get the message that indicates why this function was deleted.
+  StringLiteral *getDeletedMessage() const { return DeletedMessage; }
+
   void setPreviousDeclaration(FunctionDecl * PrevDecl);
 
   FunctionDecl *getCanonicalDecl() override;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 14df75180ef321..559e6416b7dfb3 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1600,6 +1600,7 @@ class Parser : public CodeCompletionHandler {
  const ParsedTemplateInfo &TemplateInfo,
  const VirtSpecifiers &VS,
  SourceLocation PureSpecLoc);
+  StringLiteral *ParseCXXDeletedFunctionMessage();
   void ParseCXXNonStaticMemberInitializer(Decl *VarD);
   void ParseLexedAttributes(ParsingClass &Class);
   void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 64de39acc72176..919f8f6b0a35a2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4926,10 +4926,12 @@ class Sema final {
SourceLocation EqualLoc);
 
   void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc);
-  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
+  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc,
+  StringLiteral *Message = nullptr);
   void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
 
-  void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind);
+  void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind,
+   StringLiteral *DeletedMessage = nullptr);
   void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D);
   ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr);
   ExprResult ActOnRequiresClause(ExprResult ConstraintExpr);
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 95900afdd2c5d8..b5e61f0eceb6e4 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3043,8 +3043,8 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, 
DeclContext *DC,
Expr *TrailingRequiresClause)
 : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
  StartLoc),
-  DeclContext(DK), redeclarable_base(C), Body(), ODRHash(0),
-  EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {
+  DeclContext(DK), redeclarable_base(C), Body(), DeletedMessage(nullptr),
+  ODRHash(0), EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) 
{
   assert(T.isNull() || T->isFunctionType());
   FunctionDeclBits.SClass = S;
   FunctionDeclBits.IsInline = isInlineSpecified;
diff --git a/c

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-03-26 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/86526

>From 98af47e8ccc633016c14b91c221f9f8fc620f068 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Mon, 25 Mar 2024 14:46:52 +0100
Subject: [PATCH 1/9] [Clang] Parse `= delete("message")`

---
 clang/include/clang/AST/Decl.h| 13 
 clang/include/clang/Parse/Parser.h|  1 +
 clang/include/clang/Sema/Sema.h   |  6 ++--
 clang/lib/AST/Decl.cpp|  4 +--
 clang/lib/AST/DeclPrinter.cpp |  9 +++--
 clang/lib/AST/TextNodeDumper.cpp  |  3 ++
 clang/lib/Parse/ParseCXXInlineMethods.cpp | 24 +-
 clang/lib/Parse/Parser.cpp|  4 ++-
 clang/lib/Sema/SemaDeclCXX.cpp| 10 +++---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  6 
 .../test/Parser/cxx2c-delete-with-message.cpp | 33 +++
 11 files changed, 100 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Parser/cxx2c-delete-with-message.cpp

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index a5879591f4c659..24f0394577e228 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2013,6 +2013,12 @@ class FunctionDecl : public DeclaratorDecl,
 DefaultedFunctionInfo *DefaultedInfo;
   };
 
+  /// Message that indicates why this function was deleted.
+  ///
+  /// FIXME: Figure out where to actually put this; maybe in the
+  /// 'DefaultedInfo' above?
+  StringLiteral *DeletedMessage;
+
   unsigned ODRHash;
 
   /// End part of this FunctionDecl's source range.
@@ -2483,6 +2489,10 @@ class FunctionDecl : public DeclaratorDecl,
   }
 
   void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
+  void setDeletedWithMessage(StringLiteral* Message) {
+FunctionDeclBits.IsDeleted = true;
+DeletedMessage = Message;
+  }
 
   /// Determines whether this function is "main", which is the
   /// entry point into an executable program.
@@ -2638,6 +2648,9 @@ class FunctionDecl : public DeclaratorDecl,
   AC.push_back(TRC);
   }
 
+  /// Get the message that indicates why this function was deleted.
+  StringLiteral *getDeletedMessage() const { return DeletedMessage; }
+
   void setPreviousDeclaration(FunctionDecl * PrevDecl);
 
   FunctionDecl *getCanonicalDecl() override;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 14df75180ef321..559e6416b7dfb3 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1600,6 +1600,7 @@ class Parser : public CodeCompletionHandler {
  const ParsedTemplateInfo &TemplateInfo,
  const VirtSpecifiers &VS,
  SourceLocation PureSpecLoc);
+  StringLiteral *ParseCXXDeletedFunctionMessage();
   void ParseCXXNonStaticMemberInitializer(Decl *VarD);
   void ParseLexedAttributes(ParsingClass &Class);
   void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 64de39acc72176..919f8f6b0a35a2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4926,10 +4926,12 @@ class Sema final {
SourceLocation EqualLoc);
 
   void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc);
-  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
+  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc,
+  StringLiteral *Message = nullptr);
   void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
 
-  void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind);
+  void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind,
+   StringLiteral *DeletedMessage = nullptr);
   void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D);
   ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr);
   ExprResult ActOnRequiresClause(ExprResult ConstraintExpr);
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 95900afdd2c5d8..b5e61f0eceb6e4 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3043,8 +3043,8 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, 
DeclContext *DC,
Expr *TrailingRequiresClause)
 : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
  StartLoc),
-  DeclContext(DK), redeclarable_base(C), Body(), ODRHash(0),
-  EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {
+  DeclContext(DK), redeclarable_base(C), Body(), DeletedMessage(nullptr),
+  ODRHash(0), EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) 
{
   assert(T.isNull() || T->isFunctionType());
   FunctionDeclBits.SClass = S;
   FunctionDeclBits.IsInline = isInlineSpecified;
diff --git a/c

[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits


@@ -424,6 +448,56 @@ InstallAPIContext Options::createContext() {
 if (!Glob->didMatch())
   Diags->Report(diag::warn_glob_did_not_match) << Glob->str();
 
+  // Mark any explicit or inferred umbrella headers. If one exists, move
+  // that to the beginning of the input headers.
+  auto MarkandMoveUmbrellaInHeaders = [&](Regex &Regex,
+  HeaderType Type) -> bool {
+auto It = find_if(Ctx.InputHeaders, [&Regex, Type](const HeaderFile &H) {
+  return (H.getType() == Type) && Regex.match(H.getPath());
+});
+
+if (It == Ctx.InputHeaders.end())
+  return false;
+It->setUmbrellaHeader();
+
+// Because there can be an umbrella header per header type,
+// find the first non umbrella header to swap position with.
+auto BeginPos = find_if(Ctx.InputHeaders, [](const HeaderFile &H) {
+  return !H.isUmbrellaHeader();
+});
+if (BeginPos != Ctx.InputHeaders.end() && BeginPos < It)
+  std::swap(*BeginPos, *It);
+return true;
+  };
+
+  auto FindUmbrellaHeader = [&](StringRef HeaderPath, HeaderType Type) -> bool 
{
+if (!HeaderPath.empty()) {
+  auto EscapedString = Regex::escape(HeaderPath);
+  Regex UmbrellaRegex(EscapedString);
+  if (!MarkandMoveUmbrellaInHeaders(UmbrellaRegex, Type)) {
+Diags->Report(diag::err_no_such_umbrella_header_file)
+<< HeaderPath << (unsigned)Type - 1;

cyndyishida wrote:

No, added asserts.

https://github.com/llvm/llvm-project/pull/86587
___
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 new check readability-enum-initial-value (PR #86129)

2024-03-26 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,82 @@
+//===--- EnumInitialValueCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "EnumInitialValueCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(EnumDecl, isNoneEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() == nullptr;
+  });
+}
+
+AST_MATCHER(EnumDecl, isOnlyFirstEnumeratorsInitialized) {
+  for (EnumConstantDecl const *ECD : Node.enumerators())
+if (ECD == *Node.enumerator_begin()) {
+  if (ECD->getInitExpr() == nullptr)
+return false;
+} else {
+  if (ECD->getInitExpr() != nullptr)
+return false;
+}
+  return true;
+}
+
+AST_MATCHER(EnumDecl, isAllEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() != nullptr;
+  });
+}
+
+} // namespace
+
+void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(enumDecl(unless(anyOf(isNoneEnumeratorsInitialized(),
+   isOnlyFirstEnumeratorsInitialized(),
+   isAllEnumeratorsInitialized(
+ .bind("enum"),
+ this);
+}
+
+void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Enum = Result.Nodes.getNodeAs("enum");
+  assert(Enum != nullptr);
+  SourceLocation Loc = Enum->getBeginLoc();
+  if (Loc.isInvalid() || Loc.isMacroID())
+return;
+  DiagnosticBuilder Diag =
+  diag(Loc, "inital value in enum %0 has readability issue, "
+"explicit initialization of all of enumerators")
+  << Enum->getName();
+  for (EnumConstantDecl const *ECD : Enum->enumerators())
+if (ECD->getInitExpr() == nullptr) {
+  SourceLocation ECDLoc = ECD->getEndLoc();
+  if (ECDLoc.isInvalid() || ECDLoc.isMacroID())
+continue;
+  std::optional Next = utils::lexer::findNextTokenSkippingComments(

HerrCai0907 wrote:

fix in the end location of enum constant will insert the string before enum 
constant.
`a3,` will be changed to `= 3a3,`.

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


[clang] ca594fe - Update documentation and release notes for llvm-profgen COFF support (#84864)

2024-03-26 Thread via cfe-commits

Author: Tim Creech
Date: 2024-03-26T21:52:36+08:00
New Revision: ca594fedeb3d6bb8ee0f80c92b0089147fb5e757

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

LOG: Update documentation and release notes for llvm-profgen COFF support 
(#84864)

This change:
- Updates the existing Clang User's Manual section on SPGO so that it
describes how to use llvm-profgen to perform SPGO on Windows. This is
new functionality implemented in #83972.
- Fixes a minor typo in the existing llvm-profgen invocation example.
- Adds an LLVM release note on this new functionality in llvm-profgen.

Added: 


Modified: 
clang/docs/UsersManual.rst
llvm/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 129e75fc9a785a..c464bc3a69adc5 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2441,20 +2441,39 @@ usual build cycle when using sample profilers for 
optimization:
 
 1. Build the code with source line table information. You can use all the
usual build flags that you always build your application with. The only
-   requirement is that you add ``-gline-tables-only`` or ``-g`` to the
-   command line. This is important for the profiler to be able to map
-   instructions back to source line locations.
+   requirement is that DWARF debug info including source line information is
+   generated. This DWARF information is important for the profiler to be able
+   to map instructions back to source line locations.
+
+   On Linux, ``-g`` or just ``-gline-tables-only`` is sufficient:
 
.. code-block:: console
 
  $ clang++ -O2 -gline-tables-only code.cc -o code
 
+   While MSVC-style targets default to CodeView debug information, DWARF debug
+   information is required to generate source-level LLVM profiles. Use
+   ``-gdwarf`` to include DWARF debug information:
+
+   .. code-block:: console
+
+ $ clang-cl -O2 -gdwarf -gline-tables-only coff-profile.cpp -fuse-ld=lld 
-link -debug:dwarf
+
 2. Run the executable under a sampling profiler. The specific profiler
you use does not really matter, as long as its output can be converted
-   into the format that the LLVM optimizer understands. Currently, there
-   exists a conversion tool for the Linux Perf profiler
-   (https://perf.wiki.kernel.org/), so these examples assume that you
-   are using Linux Perf to profile your code.
+   into the format that the LLVM optimizer understands.
+
+   Two such profilers are the the Linux Perf profiler
+   (https://perf.wiki.kernel.org/) and Intel's Sampling Enabling Product (SEP),
+   available as part of `Intel VTune
+   
`_.
+   While Perf is Linux-specific, SEP can be used on Linux, Windows, and 
FreeBSD.
+
+   The LLVM tool ``llvm-profgen`` can convert output of either Perf or SEP. An
+   external project, `AutoFDO `_, also
+   provides a ``create_llvm_prof`` tool which supports Linux Perf output.
+
+   When using Perf:
 
.. code-block:: console
 
@@ -2465,11 +2484,19 @@ usual build cycle when using sample profilers for 
optimization:
it provides better call information, which improves the accuracy of
the profile data.
 
-3. Convert the collected profile data to LLVM's sample profile format.
-   This is currently supported via the AutoFDO converter ``create_llvm_prof``.
-   It is available at https://github.com/google/autofdo. Once built and
-   installed, you can convert the ``perf.data`` file to LLVM using
-   the command:
+   When using SEP:
+
+   .. code-block:: console
+
+ $ sep -start -out code.tb7 -ec 
BR_INST_RETIRED.NEAR_TAKEN:precise=yes:pdir -lbr no_filter:usr -perf-script 
brstack -app ./code
+
+   This produces a ``code.perf.data.script`` output which can be used with
+   ``llvm-profgen``'s ``--perfscript`` input option.
+
+3. Convert the collected profile data to LLVM's sample profile format. This is
+   currently supported via the `AutoFDO `_
+   converter ``create_llvm_prof``. Once built and installed, you can convert
+   the ``perf.data`` file to LLVM using the command:
 
.. code-block:: console
 
@@ -2485,7 +2512,14 @@ usual build cycle when using sample profilers for 
optimization:
 
.. code-block:: console
 
- $ llvm-profgen --binary=./code --output=code.prof--perfdata=perf.data
+ $ llvm-profgen --binary=./code --output=code.prof --perfdata=perf.data
+
+   When using SEP the output is in the textual format corresponding to
+   ``llvm-profgen --perfscript``. For example:
+
+   .. code-block:: console
+
+ $ llvm-profgen --binary=./code --output=code.prof 
--perfscript=code.perf.data.script
 
 
 4. Buil

[clang] [llvm] Update documentation and release notes for llvm-profgen COFF support (PR #84864)

2024-03-26 Thread Wei Xiao via cfe-commits

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


[clang] [llvm] Update documentation and release notes for llvm-profgen COFF support (PR #84864)

2024-03-26 Thread via cfe-commits

github-actions[bot] wrote:



@tcreech-intel Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] Fix failure in buildbot, builds/25788. (PR #86661)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam created 
https://github.com/llvm/llvm-project/pull/86661

None

>From 5ef0aca43c2eefbb9967b98c70a58a29a9407e97 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Tue, 26 Mar 2024 06:53:31 -0700
Subject: [PATCH] Fix failure in buildbot, builds/25788.

---
 clang/lib/AST/TypePrinter.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index d9504f9dcb3899..d0ba6066fa0180 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2303,10 +2303,10 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 } else {
   if (!FirstArg)
 OS << Comma;
-// Tries to print the argument with location info if exists.
-printArgument(Arg, Policy, ArgOS,
-  TemplateParameterList::shouldIncludeTypeForArgument(
-  Policy, TPL, ParmIndex));
+  // Tries to print the argument with location info if exists.
+  printArgument(Arg, Policy, ArgOS,
+TemplateParameterList::shouldIncludeTypeForArgument(
+Policy, TPL, ParmIndex));
 }
 StringRef ArgString = ArgOS.str();
 

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


[clang] Fix failure in buildbot (PR #86661)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

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


[clang] Fix failure in buildbot (PR #86661)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [Clang] [Sema] Fix dependence of DREs in lambdas with an explicit object parameter (PR #84473)

2024-03-26 Thread via cfe-commits

Sirraide wrote:

@AaronBallman ping

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


[clang] 2e38c50 - [clang-repl] Fix remove invalidates iterators in CleanUpPTU() (#85378)

2024-03-26 Thread via cfe-commits

Author: Stefan Gränitz
Date: 2024-03-26T15:07:05+01:00
New Revision: 2e38c50e5c53d66d4968fbd47b78e71a220a28ca

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

LOG: [clang-repl] Fix remove invalidates iterators in CleanUpPTU() (#85378)

Using remove() on DeclContext::lookup_result list invalidates iterators.

This assertion failure was one (fortunate) symptom:
```
clang/include/clang/AST/DeclBase.h:1337: reference 
clang::DeclListNode::iterator::operator*() const: Assertion `Ptr && 
"dereferencing end() iterator"' failed.
```

Added: 


Modified: 
clang/include/clang/AST/DeclContextInternals.h
clang/lib/Interpreter/IncrementalParser.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclContextInternals.h 
b/clang/include/clang/AST/DeclContextInternals.h
index 903cdb7bfcc822..c4734ab5789538 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -205,7 +205,7 @@ class StoredDeclsList {
 Data.setPointer(Head);
   }
 
-  /// Return an array of all the decls that this list represents.
+  /// Return the list of all the decls.
   DeclContext::lookup_result getLookupResult() const {
 return DeclContext::lookup_result(Data.getPointer());
   }

diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 370bcbfee8b014..5eec2a2fd6d1a6 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -375,16 +375,22 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit 
&PTU) {
   TranslationUnitDecl *MostRecentTU = PTU.TUPart;
   TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();
   if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) {
-for (auto I = Map->begin(); I != Map->end(); ++I) {
-  StoredDeclsList &List = I->second;
+for (auto &&[Key, List] : *Map) {
   DeclContextLookupResult R = List.getLookupResult();
+  std::vector NamedDeclsToRemove;
+  bool RemoveAll = true;
   for (NamedDecl *D : R) {
-if (D->getTranslationUnitDecl() == MostRecentTU) {
+if (D->getTranslationUnitDecl() == MostRecentTU)
+  NamedDeclsToRemove.push_back(D);
+else
+  RemoveAll = false;
+  }
+  if (LLVM_LIKELY(RemoveAll)) {
+Map->erase(Key);
+  } else {
+for (NamedDecl *D : NamedDeclsToRemove)
   List.remove(D);
-}
   }
-  if (List.isNull())
-Map->erase(I);
 }
   }
 }



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


[clang] [clang-repl] Fix assertion failure in CleanUpPTU() (PR #85378)

2024-03-26 Thread Stefan Gränitz via cfe-commits

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


[clang] [clang][OpenMP] Add const-qualified `getIteratorModifier` to OMPMapClause (PR #86666)

2024-03-26 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/8

NFC

>From 3ffabe11eb01f42ceaeb92895a0eb0f251e6ef9a Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 21 Mar 2024 06:54:02 -0500
Subject: [PATCH] [clang][OpenMP] Add const-qualified `getIteratorModifier` to
 OMPMapClause

NFC
---
 clang/include/clang/AST/OpenMPClause.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 325a1baa446142..bf814c81665eb7 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6050,6 +6050,11 @@ class OMPMapClause final : public 
OMPMappableExprListClause,
 return getTrailingObjects()[2 * varlist_size()];
   }
 
+  /// Fetches Expr * of iterator modifier.
+  Expr *getIteratorModifier() const {
+return getTrailingObjects()[2 * varlist_size()];
+  }
+
   /// Fetches mapping kind for the clause.
   OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
 

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


[clang] [clang][OpenMP] Add const-qualified `getIteratorModifier` to OMPMapClause (PR #86666)

2024-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krzysztof Parzyszek (kparzysz)


Changes

NFC

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


1 Files Affected:

- (modified) clang/include/clang/AST/OpenMPClause.h (+5) 


``diff
diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 325a1baa446142..bf814c81665eb7 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6050,6 +6050,11 @@ class OMPMapClause final : public 
OMPMappableExprListClause,
 return getTrailingObjects()[2 * varlist_size()];
   }
 
+  /// Fetches Expr * of iterator modifier.
+  Expr *getIteratorModifier() const {
+return getTrailingObjects()[2 * varlist_size()];
+  }
+
   /// Fetches mapping kind for the clause.
   OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
 

``




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


  1   2   3   4   5   >