[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-09 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/84599

>From 43238d58ff490073c13ff621faddceb89b05b22e Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 8 Mar 2024 19:47:54 -0800
Subject: [PATCH 1/2] [clang-format][NFC] Eliminate the IsCpp parameter in all
 functions

---
 clang/include/clang/Format/Format.h  |  3 ++
 clang/lib/Format/ContinuationIndenter.cpp| 12 +++--
 clang/lib/Format/Format.cpp  |  2 +
 clang/lib/Format/FormatToken.cpp |  6 +--
 clang/lib/Format/FormatToken.h   |  6 +--
 clang/lib/Format/FormatTokenLexer.cpp|  5 +-
 clang/lib/Format/QualifierAlignmentFixer.cpp | 29 ++--
 clang/lib/Format/QualifierAlignmentFixer.h   |  5 +-
 clang/lib/Format/TokenAnnotator.cpp  | 48 ++--
 clang/lib/Format/TokenAnnotator.h|  6 +--
 clang/lib/Format/UnwrappedLineParser.cpp | 22 +
 clang/lib/Format/UnwrappedLineParser.h   |  1 -
 12 files changed, 74 insertions(+), 71 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 590297fd89a398..a72c1b171c3e18 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5228,6 +5228,9 @@ extern const char *DefaultFormatStyle;
 /// Different builds can modify the value to the preferred styles.
 extern const char *DefaultFallbackStyle;
 
+/// Whether the language is C/C++/Objective-C/Objective-C++.
+extern bool IsCpp;
+
 /// Construct a FormatStyle based on ``StyleName``.
 ///
 /// ``StyleName`` can take several forms:
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index df44e6994c4784..506e21725ba9f7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -241,7 +241,9 @@ ContinuationIndenter::ContinuationIndenter(const 
FormatStyle ,
 : Style(Style), Keywords(Keywords), SourceMgr(SourceMgr),
   Whitespaces(Whitespaces), Encoding(Encoding),
   BinPackInconclusiveFunctions(BinPackInconclusiveFunctions),
-  CommentPragmasRegex(Style.CommentPragmas), RawStringFormats(Style) {}
+  CommentPragmasRegex(Style.CommentPragmas), RawStringFormats(Style) {
+  IsCpp = Style.isCpp();
+}
 
 LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
 unsigned FirstStartColumn,
@@ -406,7 +408,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
   }
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
-State.Line->First->isNot(TT_AttributeSquare) && Style.isCpp() &&
+State.Line->First->isNot(TT_AttributeSquare) && IsCpp &&
 // FIXME: This is a temporary workaround for the case where 
clang-format
 // sets BreakBeforeParameter to avoid bin packing and this creates a
 // completely unnecessary line break after a template type that isn't
@@ -677,8 +679,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   auto  = State.Stack.back();
 
   bool DisallowLineBreaksOnThisLine =
-  Style.LambdaBodyIndentation == FormatStyle::LBI_Signature &&
-  Style.isCpp() && [] {
+  Style.LambdaBodyIndentation == FormatStyle::LBI_Signature && IsCpp &&
+  [] {
 // Deal with lambda arguments in C++. The aim here is to ensure that we
 // don't over-indent lambda function bodies when lambdas are passed as
 // arguments to function calls. We do this by ensuring that either all
@@ -1091,7 +1093,7 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState ,
   // Any break on this level means that the parent level has been broken
   // and we need to avoid bin packing there.
   bool NestedBlockSpecialCase =
-  (!Style.isCpp() && Current.is(tok::r_brace) && State.Stack.size() > 1 &&
+  (!IsCpp && Current.is(tok::r_brace) && State.Stack.size() > 1 &&
State.Stack[State.Stack.size() - 2].NestedBlockInlined) ||
   (Style.Language == FormatStyle::LK_ObjC && Current.is(tok::r_brace) &&
State.Stack.size() > 1 && !Style.ObjCBreakBeforeNestedBlockParam);
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e64ba7eebc1ce8..00182f75560a2c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3943,6 +3943,8 @@ const char *DefaultFormatStyle = "file";
 
 const char *DefaultFallbackStyle = "LLVM";
 
+bool IsCpp = false;
+
 llvm::ErrorOr>
 loadAndParseConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS,
FormatStyle *Style, bool AllowUnknownOptions) {
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 4fb70ffac706d0..665b2e43259b21 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -78,15 +78,15 @@ static SmallVector 

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-09 Thread Owen Pan via cfe-commits

owenca wrote:

> That's okay for clang-format, but you couldn't use libFormat with different 
> languages at once anymore.

I believe we still could because `IsCpp` is set to `Style.isCpp()` every time 
new instances of the classes are constructed. I'll add a couple of test cases 
to demonstrate this.

> I dislike global state in libraries.

So do I, but I prefer this to keeping the `IsCpp` parameter. See also 
https://github.com/llvm/llvm-project/pull/83709#discussion_r1512657115.

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


[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2024-03-09 Thread Owen Pan via cfe-commits

owenca wrote:

> Thanks for doing this. Does it mean we would have to add every type we use to 
> our config? It would be much more convenient if clang-format treated the 
> argument list the same way that it treats in definitions. For example
> 
> ```shell
> printf "int\niso_time(time_t) { return 1; }\n" | clang-format -style='{ 
> AlwaysBreakAfterReturnType: All }'
> ```
> 
> gives
> 
> ```c
> int
> iso_time(time_t) {
>   return 1;
> }
> ```
> 
> whereas
> 
> ```shell
> printf "int\niso_time(time_t);\n" | clang-format -style='{ 
> AlwaysBreakAfterReturnType: All }'
> ```
> 
> will need a config edit to work.

@mattmundell you don't need to add `time_t` and other common C/C++ types to 
`TypeNames` after 0baef3b18cdb.

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


[clang] [clang][Interp] Implement __builtin_popcountg (PR #84500)

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

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


[clang] e95040f - [clang][Interp] Implement __builtin_popcountg (#84500)

2024-03-09 Thread via cfe-commits

Author: OverMighty
Date: 2024-03-10T06:54:03+01:00
New Revision: e95040f0f05b74406e9d7ee02b110470588cc5f0

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

LOG: [clang][Interp] Implement __builtin_popcountg (#84500)

The previous code would truncate IntegerAPs wider than 64 bits.

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 5250d02be85a61..c500b9d502d707 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -53,11 +53,7 @@ static APSInt peekToAPSInt(InterpStack , PrimType T, 
size_t Offset = 0) {
 Offset = align(primSize(T));
 
   APSInt R;
-  INT_TYPE_SWITCH(T, {
-T Val = Stk.peek(Offset);
-R = APSInt(APInt(Val.bitWidth(), static_cast(Val), 
T::isSigned()),
-   !T::isSigned());
-  });
+  INT_TYPE_SWITCH(T, R = Stk.peek(Offset).toAPSInt());
 
   return R;
 }
@@ -1052,6 +1048,7 @@ bool InterpretBuiltin(InterpState , CodePtr OpPC, const 
Function *F,
   case Builtin::BI__builtin_popcount:
   case Builtin::BI__builtin_popcountl:
   case Builtin::BI__builtin_popcountll:
+  case Builtin::BI__builtin_popcountg:
   case Builtin::BI__popcnt16: // Microsoft variants of popcount
   case Builtin::BI__popcnt:
   case Builtin::BI__popcnt64:

diff  --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index ab8abac4b36e34..08fca8428cf5e8 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -268,6 +268,24 @@ namespace popcount {
   static_assert(__builtin_popcountl(0) == 0, "");
   static_assert(__builtin_popcountll(~0ull) == __CHAR_BIT__ * sizeof(unsigned 
long long), "");
   static_assert(__builtin_popcountll(0) == 0, "");
+  static_assert(__builtin_popcountg((unsigned char)~0) == __CHAR_BIT__ * 
sizeof(unsigned char), "");
+  static_assert(__builtin_popcountg((unsigned char)0) == 0, "");
+  static_assert(__builtin_popcountg((unsigned short)~0) == __CHAR_BIT__ * 
sizeof(unsigned short), "");
+  static_assert(__builtin_popcountg((unsigned short)0) == 0, "");
+  static_assert(__builtin_popcountg(~0u) == __CHAR_BIT__ * sizeof(unsigned 
int), "");
+  static_assert(__builtin_popcountg(0u) == 0, "");
+  static_assert(__builtin_popcountg(~0ul) == __CHAR_BIT__ * sizeof(unsigned 
long), "");
+  static_assert(__builtin_popcountg(0ul) == 0, "");
+  static_assert(__builtin_popcountg(~0ull) == __CHAR_BIT__ * sizeof(unsigned 
long long), "");
+  static_assert(__builtin_popcountg(0ull) == 0, "");
+#ifdef __SIZEOF_INT128__
+  static_assert(__builtin_popcountg(~(unsigned __int128)0) == __CHAR_BIT__ * 
sizeof(unsigned __int128), "");
+  static_assert(__builtin_popcountg((unsigned __int128)0) == 0, "");
+#endif
+#ifndef __AVR__
+  static_assert(__builtin_popcountg(~(unsigned _BitInt(128))0) == __CHAR_BIT__ 
* sizeof(unsigned _BitInt(128)), "");
+  static_assert(__builtin_popcountg((unsigned _BitInt(128))0) == 0, "");
+#endif
 
   /// From test/Sema/constant-builtins-2.c
   char popcount1[__builtin_popcount(0) == 0 ? 1 : -1];
@@ -280,6 +298,17 @@ namespace popcount {
   char popcount8[__builtin_popcountll(0LL) == 0 ? 1 : -1];
   char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
   char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
+  char popcount11[__builtin_popcountg(0U) == 0 ? 1 : -1];
+  char popcount12[__builtin_popcountg(0xF0F0U) == 8 ? 1 : -1];
+  char popcount13[__builtin_popcountg(~0U) == BITSIZE(int) ? 1 : -1];
+  char popcount14[__builtin_popcountg(~0UL) == BITSIZE(long) ? 1 : -1];
+  char popcount15[__builtin_popcountg(~0ULL) == BITSIZE(long long) ? 1 : -1];
+#ifdef __SIZEOF_INT128__
+  char popcount16[__builtin_popcountg(~(unsigned __int128)0) == 
BITSIZE(__int128) ? 1 : -1];
+#endif
+#ifndef __AVR__
+  char popcount17[__builtin_popcountg(~(unsigned _BitInt(128))0) == 
BITSIZE(_BitInt(128)) ? 1 : -1];
+#endif
 }
 
 namespace parity {



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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-09 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-09 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -342,3 +342,21 @@ typedef int InExternCPP;
 // CHECK-FIXES: using InExternCPP = int;
 
 }
+
+namespace ISSUE_72179
+{  
+  void foo()
+  {
+typedef int a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using a = int;
+
+  }
+
+  void foo2()
+  {
+typedef struct { int a; union { int b; }; } c;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using c = struct { int a; union { int b; }; };
+  }
+}

PiotrZSL wrote:

add test with lambda, template function, normal function in template class.

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-09 Thread Piotr Zegar via cfe-commits
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


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

Overall fine.

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-09 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -183,6 +183,9 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`modernize-use-using `
+  check by fixing false-negative in functions.

PiotrZSL wrote:

maybe: `by adding support for detection of typedefs declared on function level.`

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2024-03-09 Thread via cfe-commits


@@ -123,6 +123,15 @@
 // CHECK-CHAR8_T_: "-fno-char8_t"
 
 
+// RUN: %clang_cl /TC /dev/null /E -Xclang -dM 2> /dev/null | FileCheck 
-match-full-lines %s --check-prefix=NOSTDC

xbjfk wrote:

Moved to clang/test/Preprocessor, thanks!

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2024-03-09 Thread via cfe-commits

https://github.com/xbjfk updated https://github.com/llvm/llvm-project/pull/68690

>From 391eb28dbf4d2e912d072893ff7c57077c718bca Mon Sep 17 00:00:00 2001
From: Reagan Bohan 
Date: Sun, 10 Mar 2024 01:49:37 +
Subject: [PATCH] [clang] Add /Zc:__STDC__ flag to clang-cl

This commit adds the /Zc:__STDC__ argument from MSVC, which defines __STDC__.
This means, alongside stronger feature parity with MSVC,
that things that rely on __STDC__, such as autoconf, can work.
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  7 +++
 clang/lib/Driver/ToolChains/Clang.cpp |  9 -
 clang/lib/Frontend/InitPreprocessor.cpp   |  3 ++-
 clang/test/Driver/ms-define-stdc.c| 11 +++
 clang/test/Preprocessor/stdc-ms-extension.cpp |  9 +
 7 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/ms-define-stdc.c
 create mode 100644 clang/test/Preprocessor/stdc-ms-extension.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..fde603a6245247 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,6 +177,9 @@ New Compiler Flags
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
   like it did before Clang 18.x. Fixes (`#56628 
`_)
+- ``-fms-define-stdc`` and its clang-cl counterpart ``/Zc:__STDC__``.
+  Matches MSVC behaviour by defining ``__STDC__`` to ``1`` when
+  MSVC compatibility mode is used. It has no effect for C++ code.
 
 Deprecated Compiler Flags
 -
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 472fd9f093a718..121db13277b474 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -291,6 +291,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations 
/ deallocations with
 
 LANGOPT(OpenACC   , 1, 0, "OpenACC Enabled")
 
+LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with 
'-fms-compatability'")
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aca8c9b0d5487a..7a24f26530c60f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2934,6 +2934,10 @@ def fms_compatibility : Flag<["-"], 
"fms-compatibility">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Enable full Microsoft Visual C++ compatibility">,
   MarshallingInfoFlag>;
+def fms_define_stdc : Flag<["-"], "fms-define-stdc">, Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Define '__STDC__' to '1' in MSVC Compatibility mode">,
+  MarshallingInfoFlag>;
 def fms_extensions : Flag<["-"], "fms-extensions">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
@@ -8172,6 +8176,9 @@ def _SLASH_vd : CLJoined<"vd">, HelpText<"Control 
vtordisp placement">,
   Alias;
 def _SLASH_X : CLFlag<"X">,
   HelpText<"Do not add %INCLUDE% to include search path">, Alias;
+def _SLASH_Zc___STDC__ : CLFlag<"Zc:__STDC__">,
+  HelpText<"Define __STDC__">,
+  Alias;
 def _SLASH_Zc_sizedDealloc : CLFlag<"Zc:sizedDealloc">,
   HelpText<"Enable C++14 sized global deallocation functions">,
   Alias;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index cc568b9a715bbe..f9e2cb043f7b5d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6888,8 +6888,12 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
   (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
  options::OPT_fno_ms_extensions, true)));
-  if (IsMSVCCompat)
+  if (IsMSVCCompat) {
 CmdArgs.push_back("-fms-compatibility");
+if (!types::isCXX(Input.getType()) &&
+Args.hasArg(options::OPT_fms_define_stdc))
+  CmdArgs.push_back("-fms-define-stdc");
+  }
 
   if (Triple.isWindowsMSVCEnvironment() && !D.IsCLMode() &&
   Args.hasArg(options::OPT_fms_runtime_lib_EQ))
@@ -8065,6 +8069,9 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,
CmdArgs.push_back("-fno-wchar");
  }
 
+ if (!types::isCXX(InputType) && Args.hasArg(options::OPT_fms_define_stdc))
+   CmdArgs.push_back("-fms-define-stdc");
+
  if (Args.hasArg(options::OPT__SLASH_kernel)) {
llvm::Triple::ArchType 

[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-09 Thread Kees Cook via cfe-commits

kees wrote:

> Left my comment on the main list, but I don't see this as a well motivated 
> change, and even if GCC supported it, it would still be a very difficult to 
> motivate extension without massive historical workloads already using it.

This is needed by the Linux kernel, and is in active use. Directly converting 
from [0] to [] isn't possible due to all the places flex arrays are used in 
unions. Linux is working around this by tricking the syntax checker currently, 
which needlessly complicates things. There are currently over 200 separate 
unions using the work-around.

So, this fixes the accidental lack of the existing [0] extensions not being 
directly applied to [], and doesn't cause problems for any other users. What 
solution should Linux use if not fixing this directly nor providing something 
like -fflex-array-extensions?



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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-09 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/82947

From d1cbed0e2e83bd3544067fd25d7e811f1ab3f095 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 20:20:59 -0500
Subject: [PATCH 1/3] [clang-tidy] Improved modernize-use-using by fixing a
 false-negative

The check needs a parent decl to match but if the typedef is in a function,
the parent is a declStmt which is not a decl by itself.
Improved the matcher to match on either a decl or a declstmt and extract
the decl from the stmt in the latter case.

fixes #72179
---
 .../clang-tidy/modernize/UseUsingCheck.cpp | 16 +---
 clang-tools-extra/docs/ReleaseNotes.rst|  3 +++
 .../checkers/modernize/use-using.cpp   | 18 ++
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index bb05f206c717ce..50a07fc02e31b4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -24,6 +24,7 @@ static constexpr llvm::StringLiteral ExternCDeclName = 
"extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
+static constexpr llvm::StringLiteral DeclStmtName = "decl-stmt";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -41,7 +42,8 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   unless(isInstantiated()),
   optionally(hasAncestor(
   linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
-  hasParent(decl().bind(ParentDeclName)))
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName
   .bind(TypedefName),
   this);
 
@@ -51,17 +53,25 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   tagDecl(
   anyOf(allOf(unless(anyOf(isImplicit(),
classTemplateSpecializationDecl())),
-  hasParent(decl().bind(ParentDeclName))),
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName,
 // We want the parent of the ClassTemplateDecl, not the parent
 // of the specialization.
 classTemplateSpecializationDecl(hasAncestor(classTemplateDecl(
-hasParent(decl().bind(ParentDeclName)))
+anyOf(hasParent(decl().bind(ParentDeclName)),
+  hasParent(declStmt().bind(DeclStmtName
   .bind(TagDeclName),
   this);
 }
 
 void UseUsingCheck::check(const MatchFinder::MatchResult ) {
   const auto *ParentDecl = Result.Nodes.getNodeAs(ParentDeclName);
+
+  if (!ParentDecl) {
+const auto *ParentDeclStmt = 
Result.Nodes.getNodeAs(DeclStmtName);
+ParentDecl = ParentDeclStmt->getSingleDecl();
+  }
+
   if (!ParentDecl)
 return;
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6fd01ed9d471c5..2b36ae4acb9f1d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`modernize-use-using `
+  check by fixing false-negative in functions.
+
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 462bc984fd3ad5..230c7c94cda1cf 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -342,3 +342,21 @@ typedef int InExternCPP;
 // CHECK-FIXES: using InExternCPP = int;
 
 }
+
+namespace ISSUE_72179
+{  
+  void foo()
+  {
+typedef int a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using a = int;
+
+  }
+
+  void foo2()
+  {
+typedef struct { int a; union { int b; }; } c;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 
'typedef' [modernize-use-using]
+// CHECK-FIXES: using c = struct { int a; union { int b; }; };
+  }
+}

From 0b5c78508fbf49229d576171d7af6c6bb16b4367 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 22:14:22 -0500
Subject: [PATCH 2/3] fixup! [clang-tidy] 

[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2024-03-09 Thread via cfe-commits

https://github.com/xbjfk updated https://github.com/llvm/llvm-project/pull/68690

>From adfced08cd4c150b02345629e1bd9c5bc4681f09 Mon Sep 17 00:00:00 2001
From: Reagan Bohan 
Date: Sun, 10 Mar 2024 01:49:37 +
Subject: [PATCH] [clang] Add /Zc:__STDC__ flag to clang-cl

This commit adds the /Zc:__STDC__ argument from MSVC, which defines __STDC__.
This means, alongside stronger feature parity with MSVC,
that things that rely on __STDC__, such as autoconf, can work.
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  7 +++
 clang/lib/Driver/ToolChains/Clang.cpp |  9 -
 clang/lib/Frontend/InitPreprocessor.cpp   |  3 ++-
 clang/test/Driver/cl-zc.cpp   |  9 +
 clang/test/Driver/ms-define-stdc.c| 11 +++
 7 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/ms-define-stdc.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..fde603a6245247 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,6 +177,9 @@ New Compiler Flags
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
   like it did before Clang 18.x. Fixes (`#56628 
`_)
+- ``-fms-define-stdc`` and its clang-cl counterpart ``/Zc:__STDC__``.
+  Matches MSVC behaviour by defining ``__STDC__`` to ``1`` when
+  MSVC compatibility mode is used. It has no effect for C++ code.
 
 Deprecated Compiler Flags
 -
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 472fd9f093a718..121db13277b474 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -291,6 +291,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations 
/ deallocations with
 
 LANGOPT(OpenACC   , 1, 0, "OpenACC Enabled")
 
+LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with 
'-fms-compatability'")
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aca8c9b0d5487a..7a24f26530c60f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2934,6 +2934,10 @@ def fms_compatibility : Flag<["-"], 
"fms-compatibility">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Enable full Microsoft Visual C++ compatibility">,
   MarshallingInfoFlag>;
+def fms_define_stdc : Flag<["-"], "fms-define-stdc">, Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Define '__STDC__' to '1' in MSVC Compatibility mode">,
+  MarshallingInfoFlag>;
 def fms_extensions : Flag<["-"], "fms-extensions">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
@@ -8172,6 +8176,9 @@ def _SLASH_vd : CLJoined<"vd">, HelpText<"Control 
vtordisp placement">,
   Alias;
 def _SLASH_X : CLFlag<"X">,
   HelpText<"Do not add %INCLUDE% to include search path">, Alias;
+def _SLASH_Zc___STDC__ : CLFlag<"Zc:__STDC__">,
+  HelpText<"Define __STDC__">,
+  Alias;
 def _SLASH_Zc_sizedDealloc : CLFlag<"Zc:sizedDealloc">,
   HelpText<"Enable C++14 sized global deallocation functions">,
   Alias;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index cc568b9a715bbe..f9e2cb043f7b5d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6888,8 +6888,12 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
   (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
  options::OPT_fno_ms_extensions, true)));
-  if (IsMSVCCompat)
+  if (IsMSVCCompat) {
 CmdArgs.push_back("-fms-compatibility");
+if (!types::isCXX(Input.getType()) &&
+Args.hasArg(options::OPT_fms_define_stdc))
+  CmdArgs.push_back("-fms-define-stdc");
+  }
 
   if (Triple.isWindowsMSVCEnvironment() && !D.IsCLMode() &&
   Args.hasArg(options::OPT_fms_runtime_lib_EQ))
@@ -8065,6 +8069,9 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,
CmdArgs.push_back("-fno-wchar");
  }
 
+ if (!types::isCXX(InputType) && Args.hasArg(options::OPT_fms_define_stdc))
+   CmdArgs.push_back("-fms-define-stdc");
+
  if (Args.hasArg(options::OPT__SLASH_kernel)) {
llvm::Triple::ArchType Arch = getToolChain().getArch();
std::vector Values =
diff --git 

[clang] Document runtime config directory options (PR #66593)

2024-03-09 Thread via cfe-commits

https://github.com/xbjfk updated https://github.com/llvm/llvm-project/pull/66593

>From 0d50e2892bd055053e0e61615911928371106e17 Mon Sep 17 00:00:00 2001
From: Reagan Bohan 
Date: Sun, 17 Sep 2023 21:19:33 +1200
Subject: [PATCH] Document runtime config directory options

---
 clang/docs/UsersManual.rst | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 7391e4cf3a9aeb..9d8af41ac0d0d0 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -944,10 +944,13 @@ treated as a file name and is searched for sequentially 
in the directories:
 - system directory,
 - the directory where Clang executable resides.
 
-Both user and system directories for configuration files are specified during
-clang build using CMake parameters, ``CLANG_CONFIG_FILE_USER_DIR`` and
-``CLANG_CONFIG_FILE_SYSTEM_DIR`` respectively. The first file found is used.
-It is an error if the required file cannot be found.
+Both user and system directories for configuration files can be specified
+either during build or during runtime. At build time, use
+``CLANG_CONFIG_FILE_USER_DIR`` and ``CLANG_CONFIG_FILE_SYSTEM_DIR``. At run
+time use the ``--config-user-dir=`` and ``--config-system-dir=`` command line
+options. Specifying config directories at runtime overrides the config
+directories set at build time The first file found is used. It is an error if
+the required file cannot be found.
 
 The default configuration files are searched for in the same directories
 following the rules described in the next paragraphs. Loading default

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


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-09 Thread Erich Keane via cfe-commits

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

Left my comment on the main list, but I don't see this as a well motivated 
change, and even if GCC supported it, it would still be a very difficult to 
motivate extension without massive historical workloads already using it.

In general, I don't think this is something we'd want to do either.

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


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-09 Thread Erich Keane via cfe-commits

erichkeane wrote:

I'm pretty unmotivated here, I don't think it is worth allowing this all the 
time thanks to it not really being a conforming extension, and I don't think it 
is sufficiently worth creating a dialect over with the flag. 

>From what I can see, the GCC folks are equally as unmotivated, so unless that 
>changes and they wish to do it, I don't think we'd want to do it here either.

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


[clang] [Clang][Sema] Fix crash when using name of UnresolvedUsingValueDecl with template arguments (PR #83842)

2024-03-09 Thread Lei Wang via cfe-commits

wlei-llvm wrote:

```
clang++ -std=gnu++20  test.cpp

clang-18: /../llvm-project/llvm/include/llvm/Support/Casting.h:578: 
decltype(auto) llvm::cast(From *) [To = clang::CXXRecordDecl, From = 
clang::DeclContext]: Assertion `isa(Val) && "cast() argument of 
incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.

1.  test.bk.10.cpp:90:15: current parser token ')'
2.  test.bk.10.cpp:81:1: parsing struct/union/class body '(unnamed class at 
test.bk.10.cpp:81:1)'
3.  test.bk.10.cpp:87:18: parsing function body '(anonymous class)::get'
4.  test.bk.10.cpp:87:18: in compound statement ('{}')
 #0 0x7fb54bdf9588 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/home/wlei/local/upstream/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x7fb54bdf7630 llvm::sys::RunSignalHandlers() 
/home/wlei/local/upstream/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x7fb54bdf9c5d SignalHandler(int) 
/home/wlei/local/upstream/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x7fb550812d20 __restore_rt (/lib64/libpthread.so.0+0x12d20)
 #4 0x7fb54ac4e52f raise (/lib64/libc.so.6+0x4e52f)
 #5 0x7fb54ac21e65 abort (/lib64/libc.so.6+0x21e65)
 #6 0x7fb54ac21d39 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d39)
 #7 0x7fb54ac46e86 (/lib64/libc.so.6+0x46e86)
 #8 0x7fb5485a934c FindDeclaringClass(clang::NamedDecl*) 
/home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:0:0
 #9 0x7fb5485a9265 (anonymous namespace)::AccessTarget::initialize() 
/home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:267:24
#10 0x7fb5485a686c clang::sema::AccessedEntity::isQuiet() const 
/home/wlei/local/upstream/llvm-project/clang/include/clang/Sema/DelayedDiagnostic.h:75:50
#11 0x7fb5485a686c clang::sema::AccessedEntity::setDiag(unsigned int) 
/home/wlei/local/upstream/llvm-project/clang/include/clang/Sema/DelayedDiagnostic.h:104:5
#12 0x7fb5485a686c 
clang::Sema::CheckUnresolvedLookupAccess(clang::UnresolvedLookupExpr*, 
clang::DeclAccessPair) 
/home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:1567:10
#13 0x7fb548c98e83 clang::DeclarationNameInfo::getLoc() const 
/home/wlei/local/upstream/llvm-project/clang/include/clang/AST/DeclarationName.h:797:42
#14 0x7fb548c98e83 clang::OverloadExpr::getNameLoc() const 
/home/wlei/local/upstream/llvm-project/clang/include/clang/AST/ExprCXX.h:3078:55
#15 0x7fb548c98e83 FinishOverloadedCallExpr(clang::Sema&, clang::Scope*, 
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, 
llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, 
clang::OverloadCandidateSet*, clang::OverloadCandidate**, 
clang::OverloadingResult, bool) 
/home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaOverload.cpp:14062:47
#16 0x7fb548c98c8f clang::Sema::BuildOverloadedCallExpr(clang::Scope*, 
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, 
llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, bool, 
bool) 
/home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaOverload.cpp:14200:10
#17 0x7fb54890511d clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, 
clang::SourceLocation, llvm::MutableArrayRef, 
clang::SourceLocation, clang::Expr*, bool, bool) 
/home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaExpr.cpp:7276:16
#18 0x7fb548920e6b clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, 
clang::SourceLocation, llvm::MutableArrayRef, 
clang::SourceLocation, clang::Expr*) 
/home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaExpr.cpp:7167:7
#19 0x7fb54bf59dca 
clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult) 
/home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:2181:23
#20 0x7fb54bf5af8a 
clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, 
clang::Parser::TypeCastState, bool, bool*) 
/home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:1890:7
#21 0x7fb54bf56e2b 
clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, 
clang::Parser::TypeCastState, bool, bool*) 
/home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:693:20
#22 0x7fb54bf56e2b clang::Parser:
```


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


[clang] [Clang][CodeGen] Fix `CanSkipVTablePointerInitialization` for dynamic classes with a trivial anonymous union (PR #84651)

2024-03-09 Thread Max Winkler via cfe-commits

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


[clang] [Clang][Sema] Fix crash when using name of UnresolvedUsingValueDecl with template arguments (PR #83842)

2024-03-09 Thread Lei Wang via cfe-commits

wlei-llvm wrote:

Here is the repro from our side. It's reduced by creduce, there are some 
unrelated error, the assertion is the real issue. 

```
typedef a;
template < typename b, b c > struct d {
  static constexpr b e = c;
};
typedef d< bool, true > f;
typedef d< bool, false > g;
template < bool, typename, typename > struct aa;
template < typename... > struct h;
template < typename i, typename j, typename ab, typename... k >
struct h< i, j, ab, k... >
: aa< i::e, i, h<> >::l {};
template < typename > struct ad : g {};
template < typename b >
struct ae : ad<  b  >{};
template < typename ai, typename aj,
   bool = h< ae< ai >,  aj ,
  aj  >::e >
class ak {
  template < typename >
  static f al(int);
public:
  typedef decltype(al< aj >(0)) l;
};
template < typename ai, typename aj >
struct am : ak< ai, aj >::l {};
template < bool , typename az, typename >
struct aa {
  typedef az l;
}template < typename ai, typename aj >
constexpr bool bj = am< ai, aj >::e;
template < typename bx, typename by >
concept bz =
bj< bx , by >;
  template < typename... > class cy
template < typename m >
concept n =
bz<  m , m > 
 template < typename b >
concept o =
n<  b  >
template < a , typename > struct tuple_element;
template < typename p, typename r >
class cy< p, r > {};
template < a q, typename... t >
__tuple_element_t< q, cy<> > get( cy< t... > ) ;
class s ;
template < class w > class u {
  w begin() ;
};
template < typename x > class v {
  using y = x
   ;
  using dp = decltype(static_cast< y (*)() >(
  nullptr)()[{}])
  ;
  dp operator*()
}
template < typename x >
struct dr {
  using ds = x::dt;
  using dp = u< ds >;
}template < o x > class du {
  using   dr< x >
  ::dp;
}
enum class dy
class dz 
template < typename eb > struct ec : eb ;
template < typename... ed >
struct ee
 :ec< cy< ed... > > {};
template < o... ej > class ek {
public:
  using el = a;
  using dw =
  ee<  ej ... >;
  using dt = v< ek >
   ;
  dw operator[](el ) ;
};
class  {
  using eo =
   s ;
  using ep =
  ek< eo,  dz  >;
  using eq = du< ep >::dp;
  eq get(dy cat) {
  auto es = get(cat)
  auto et = es.begin();
  get< 0 >(*et)
```

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


[clang] [clang] Add optional pass to remove UBSAN traps using PGO (PR #84214)

2024-03-09 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84214

>From feb5bfa786d1660a7fe0b6c48ec9048cdd315800 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:03:46 -0800
Subject: [PATCH 1/7] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp   | 17 +
 clang/test/CodeGen/remote-traps.cpp | 15 +++
 2 files changed, 32 insertions(+)
 create mode 100644 clang/test/CodeGen/remote-traps.cpp

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7310e3817c79a1..d89e53f69c4a51 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Instrumentation/MemProfiler.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -83,6 +84,7 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
+#include "llvm/Transforms/Scalar/SimplifyCFG.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,6 +100,10 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
+
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
@@ -744,6 +750,17 @@ static void addSanitizers(const Triple ,
 // LastEP does not need GlobalsAA.
 PB.registerOptimizerLastEPCallback(SanitizersCallback);
   }
+
+  if (ClRemoveTraps) {
+PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
+OptimizationLevel Level) {
+  FunctionPassManager FPM;
+  FPM.addPass(RemoveTrapsPass());
+  FPM.addPass(
+  
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+});
+  }
 }
 
 void EmitAssemblyHelper::RunOptimizationPipeline(
diff --git a/clang/test/CodeGen/remote-traps.cpp 
b/clang/test/CodeGen/remote-traps.cpp
new file mode 100644
index 00..7d4eb76a7d81e9
--- /dev/null
+++ b/clang/test/CodeGen/remote-traps.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
+
+int f(int x) {
+  return x + 123;
+}
+
+// CHECK-LABEL: define dso_local noundef i32 @_Z1fi(
+// CHECK: call { i32, i1 } @llvm.sadd.with.overflow.i32(
+// CHECK: trap:
+// CHECK-NEXT: call void @llvm.ubsantrap(i8 0)
+// CHECK-NEXT: unreachable, !nosanitize !2 
+
+// REMOVE-LABEL: define dso_local noundef i32 @_Z1fi(
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(

>From 0b2b44e04b8c900c29f52e340ebdfc6824607773 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:08:47 -0800
Subject: [PATCH 2/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d89e53f69c4a51..fa49a364cf5600 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -752,6 +752,9 @@ static void addSanitizers(const Triple ,
   }
 
   if (ClRemoveTraps) {
+// We can optimize after inliner, and PGO profile matching, which are part
+// of `buildModuleSimplificationPipeline`. The hook below is called after
+// that, from `buildModuleOptimizationPipeline`.
 PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
 OptimizationLevel Level) {
   FunctionPassManager FPM;

>From 000854eb9d18cd9cfd6eaf7d29e5954fb18d454c Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:22:16 -0800
Subject: [PATCH 3/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git 

[clang] [Clang][CodeGen] Fix `CanSkipVTablePointerInitialization` for dynamic classes with a trivial anonymous union (PR #84651)

2024-03-09 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo.
  Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account.
  See [LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.


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


[clang] [Clang][CodeGen] Fix `CanSkipVTablePointerInitialization` for dynamic classes with a trivial anonymous union (PR #84651)

2024-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Max Winkler (MaxEW707)


Changes

Hit this when trying upgrade an old project of mine. I couldn't find a 
corresponding existing issue for this when spelunking the open issues here on 
github.
Thankfully I can work-around it today with the `[[clang::no_destroy]]` 
attribute for my use case. However it should still be properly fixed.

### Issue and History ###

https://godbolt.org/z/EYnhce8MK for reference.
All subsequent text below refers to the example in the godbolt above.

Anonymous unions never have their destructor invoked automatically. Therefore 
we can skip vtable initialization of the destructor of a dynamic class if that 
destructor effectively does no work.

This worked previously as the following check would be hit and return true for 
the trivial anonymous union, 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGClass.cpp#L1348,
 resulting in the code skipping vtable initialization.

This was broken here 
https://github.com/llvm/llvm-project/commit/982bbf404eba2d968afda5c674d4821652159c53
 in relation to comments made on this review here 
https://reviews.llvm.org/D10508.

### Fixes ###

The check the code is doing is correct however the return value is inverted. We 
want to return true here since a field with anonymous union never has its 
destructor invoked and thus effectively has a trivial destructor body from the 
perspective of requiring vtable init in the parent dynamic class.

Also added some extra missing unit tests to test for this use case.


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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp (+63) 


``diff
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index d18f186ce5b415..ca3ac7142af9c0 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1395,7 +1395,7 @@ FieldHasTrivialDestructorBody(ASTContext ,
 
   // The destructor for an implicit anonymous union member is never invoked.
   if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
-return false;
+return true;
 
   return HasTrivialDestructorBody(Context, FieldClassDecl, FieldClassDecl);
 }
diff --git a/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp 
b/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
index eb8f21b57aa7b6..d99a45869fdb54 100644
--- a/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
+++ b/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -emit-llvm -o - | FileCheck 
%s
 
 // See Test9 for test description.
 // CHECK: @_ZTTN5Test91BE = linkonce_odr unnamed_addr constant
@@ -198,3 +199,65 @@ struct C : virtual B {
 C::~C() {}
 
 }
+
+namespace Test10 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), since the 
class has an anonymous union which
+// never has its destructor invoked.
+struct A {
+virtual void f();
+~A();
+
+union
+{
+int i;
+unsigned u;
+};
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test101AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test101AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}
+
+namespace Test11 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), even if the 
base class has a non trivial destructor.
+struct Field {
+~Field();
+};
+
+struct A : public Field {
+virtual void f();
+~A();
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test111AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test111AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}
+
+namespace Test12 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), since the 
class has an anonymous struct with trivial fields.
+struct A {
+virtual void f();
+~A();
+
+struct
+{
+int i;
+unsigned u;
+};
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test121AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test121AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}

``




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


[clang] [Clang][CodeGen] Fix `CanSkipVTablePointerInitialization` for dynamic classes with a trivial anonymous union (PR #84651)

2024-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Max Winkler (MaxEW707)


Changes

Hit this when trying upgrade an old project of mine. I couldn't find a 
corresponding existing issue for this when spelunking the open issues here on 
github.
Thankfully I can work-around it today with the `[[clang::no_destroy]]` 
attribute for my use case. However it should still be properly fixed.

### Issue and History ###

https://godbolt.org/z/EYnhce8MK for reference.
All subsequent text below refers to the example in the godbolt above.

Anonymous unions never have their destructor invoked automatically. Therefore 
we can skip vtable initialization of the destructor of a dynamic class if that 
destructor effectively does no work.

This worked previously as the following check would be hit and return true for 
the trivial anonymous union, 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGClass.cpp#L1348,
 resulting in the code skipping vtable initialization.

This was broken here 
https://github.com/llvm/llvm-project/commit/982bbf404eba2d968afda5c674d4821652159c53
 in relation to comments made on this review here 
https://reviews.llvm.org/D10508.

### Fixes ###

The check the code is doing is correct however the return value is inverted. We 
want to return true here since a field with anonymous union never has its 
destructor invoked and thus effectively has a trivial destructor body from the 
perspective of requiring vtable init in the parent dynamic class.

Also added some extra missing unit tests to test for this use case.


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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp (+63) 


``diff
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index d18f186ce5b415..ca3ac7142af9c0 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1395,7 +1395,7 @@ FieldHasTrivialDestructorBody(ASTContext ,
 
   // The destructor for an implicit anonymous union member is never invoked.
   if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
-return false;
+return true;
 
   return HasTrivialDestructorBody(Context, FieldClassDecl, FieldClassDecl);
 }
diff --git a/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp 
b/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
index eb8f21b57aa7b6..d99a45869fdb54 100644
--- a/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
+++ b/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -emit-llvm -o - | FileCheck 
%s
 
 // See Test9 for test description.
 // CHECK: @_ZTTN5Test91BE = linkonce_odr unnamed_addr constant
@@ -198,3 +199,65 @@ struct C : virtual B {
 C::~C() {}
 
 }
+
+namespace Test10 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), since the 
class has an anonymous union which
+// never has its destructor invoked.
+struct A {
+virtual void f();
+~A();
+
+union
+{
+int i;
+unsigned u;
+};
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test101AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test101AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}
+
+namespace Test11 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), even if the 
base class has a non trivial destructor.
+struct Field {
+~Field();
+};
+
+struct A : public Field {
+virtual void f();
+~A();
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test111AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test111AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}
+
+namespace Test12 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), since the 
class has an anonymous struct with trivial fields.
+struct A {
+virtual void f();
+~A();
+
+struct
+{
+int i;
+unsigned u;
+};
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test121AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test121AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}

``




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


[clang] [Clang][CodeGen] Fix `CanSkipVTablePointerInitialization` for dynamic classes with a trivial anonymous union (PR #84651)

2024-03-09 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 created 
https://github.com/llvm/llvm-project/pull/84651

Hit this when trying upgrade an old project of mine. I couldn't find a 
corresponding existing issue for this when spelunking the open issues here on 
github.
Thankfully I can work-around it today with the `[[clang::no_destroy]]` 
attribute for my use case. However it should still be properly fixed.

### Issue and History ###

https://godbolt.org/z/EYnhce8MK for reference.
All subsequent text below refers to the example in the godbolt above.

Anonymous unions never have their destructor invoked automatically. Therefore 
we can skip vtable initialization of the destructor of a dynamic class if that 
destructor effectively does no work.

This worked previously as the following check would be hit and return true for 
the trivial anonymous union, 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGClass.cpp#L1348,
 resulting in the code skipping vtable initialization.

This was broken here 
https://github.com/llvm/llvm-project/commit/982bbf404eba2d968afda5c674d4821652159c53
 in relation to comments made on this review here 
https://reviews.llvm.org/D10508.

### Fixes ###

The check the code is doing is correct however the return value is inverted. We 
want to return true here since a field with anonymous union never has its 
destructor invoked and thus effectively has a trivial destructor body from the 
perspective of requiring vtable init in the parent dynamic class.

Also added some extra missing unit tests to test for this use case.


>From 28cbaad3c16e985306c7b977cb7d9e8e89c39a07 Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sat, 9 Mar 2024 15:40:52 -0500
Subject: [PATCH] Fix `CanSkipVTablePointerInitialization` for dynamic classes
 with an anonymous union

---
 clang/lib/CodeGen/CGClass.cpp |  2 +-
 .../skip-vtable-pointer-initialization.cpp| 63 +++
 2 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index d18f186ce5b415..ca3ac7142af9c0 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1395,7 +1395,7 @@ FieldHasTrivialDestructorBody(ASTContext ,
 
   // The destructor for an implicit anonymous union member is never invoked.
   if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
-return false;
+return true;
 
   return HasTrivialDestructorBody(Context, FieldClassDecl, FieldClassDecl);
 }
diff --git a/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp 
b/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
index eb8f21b57aa7b6..d99a45869fdb54 100644
--- a/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
+++ b/clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -emit-llvm -o - | FileCheck 
%s
 
 // See Test9 for test description.
 // CHECK: @_ZTTN5Test91BE = linkonce_odr unnamed_addr constant
@@ -198,3 +199,65 @@ struct C : virtual B {
 C::~C() {}
 
 }
+
+namespace Test10 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), since the 
class has an anonymous union which
+// never has its destructor invoked.
+struct A {
+virtual void f();
+~A();
+
+union
+{
+int i;
+unsigned u;
+};
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test101AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test101AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}
+
+namespace Test11 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), even if the 
base class has a non trivial destructor.
+struct Field {
+~Field();
+};
+
+struct A : public Field {
+virtual void f();
+~A();
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test111AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test111AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}
+
+namespace Test12 {
+
+// Check that we don't initialize the vtable pointer in A::~A(), since the 
class has an anonymous struct with trivial fields.
+struct A {
+virtual void f();
+~A();
+
+struct
+{
+int i;
+unsigned u;
+};
+};
+
+// CHECK-LABEL: define{{.*}} void @_ZN6Test121AD2Ev
+// CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr 
@_ZTVN6Test121AE, i32 0, inrange i32 0, i32 2), ptr
+A::~A() {
+}
+
+}

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


[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-09 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

That's okay for clang-format, but you couldn't use libFormat with different 
languages at once anymore.

I dislike global state in libraries.

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-09 Thread Heejin Ahn via cfe-commits

aheejin wrote:

> > > In terms of getting this landed and tested, I wonder which path we should 
> > > take:
> > > 
> > > 1. Land this now, without tests, then update emscripten then come back 
> > > and flip the default, at which point the existing tests will get updated.
> > > 2. Duplicate/update the the existing tests to tests both modes, then 
> > > delete those changes once we flip the default.
> > > 
> > > Personally I think I'd be happy with (1) since this is a behind and 
> > > experimental flag.
> > > What do others think? @aheejin ?
> > 
> > 
> > Come to think of it, should we even introduce this experimental option? 
> > Adding `if (NewOption) ... else ...` everywhere makes the code complicated. 
> > Can we just do
> > 
> > 1. Add library functions in emscripten
> 
> So you think it should be possible to have both old and new versions 
> supported in emscripten at the same time? If that works that would be great. 
> Do you want to send and emscripten PR? And link to it here? If we can confirm 
> that all tests pass then I agree it would be great to do this in a single 
> LLVM change.

No, 1 just adds new library functions to emscripten (with different names than 
the current ones) and at this point they will not be actually used. The reason 
we add them there first is otherwise 2 (replacing the current scheme with the 
new one) wouldn't pass in the emscripten CI. As long as we use different 
library function names I think it can be fine. (I actually want to reuse the 
name `__wasm_longjmp` (instead of `__wasm_sjlj_longjmp` this PR uses), but 
maybe we can change that after landing all these.)

@yamt, do you want to submit a PR to emscripten adding new library functions? I 
can do that too, but given that this is your code, if you want to do it it'd be 
good. About where to add them... to make the transition smooth, 
https://github.com/emscripten-core/emscripten/blob/main/system/lib/compiler-rt/emscripten_setjmp.c
 looks like a good place to start given that our current functions are here, 
but we can move them later to elsewhere. WDYT? @sbc100 

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 2603e170c127aa614d499e5d527db8503a55c651 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual() 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/2] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

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

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [NFC] Eliminate trailing white space causing CI build failure (PR #84632)

2024-03-09 Thread Yingwei Zheng via cfe-commits

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


[clang] b4001e3 - [NFC] Eliminate trailing white space causing CI build failure (#84632)

2024-03-09 Thread via cfe-commits

Author: Amirreza Ashouri
Date: 2024-03-10T01:17:29+08:00
New Revision: b4001e32b1aa4df07dc6babefba19f2b77f487c6

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

LOG: [NFC] Eliminate trailing white space causing CI build failure (#84632)

To resolve the following issue in the CI build:
```
*** Checking for trailing whitespace left in Clang source files ***
+ grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs
clang/docs/ReleaseNotes.rst:412:- PTX is no longer included by default when 
compiling for CUDA. Using
+ echo '*** Trailing whitespace has been found in Clang source files as 
described above ***'
*** Trailing whitespace has been found in Clang source files as described above 
***
+ exit 1
```

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f61dca9bbc8467..3b89d5a8720785 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -409,7 +409,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using 
+- PTX is no longer included by default when compiling for CUDA. Using
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support



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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-03-09 Thread via cfe-commits

hoyhoy wrote:

cmake is broken as well.  It includes zlib internally.

https://gitlab.kitware.com/cmake/cmake/-/issues/25755

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


[clang] [clang] Add optional pass to remove UBSAN traps using PGO (PR #84214)

2024-03-09 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84214

>From feb5bfa786d1660a7fe0b6c48ec9048cdd315800 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:03:46 -0800
Subject: [PATCH 1/7] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp   | 17 +
 clang/test/CodeGen/remote-traps.cpp | 15 +++
 2 files changed, 32 insertions(+)
 create mode 100644 clang/test/CodeGen/remote-traps.cpp

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7310e3817c79a1..d89e53f69c4a51 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Instrumentation/MemProfiler.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -83,6 +84,7 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
+#include "llvm/Transforms/Scalar/SimplifyCFG.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,6 +100,10 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
+
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
@@ -744,6 +750,17 @@ static void addSanitizers(const Triple ,
 // LastEP does not need GlobalsAA.
 PB.registerOptimizerLastEPCallback(SanitizersCallback);
   }
+
+  if (ClRemoveTraps) {
+PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
+OptimizationLevel Level) {
+  FunctionPassManager FPM;
+  FPM.addPass(RemoveTrapsPass());
+  FPM.addPass(
+  
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+});
+  }
 }
 
 void EmitAssemblyHelper::RunOptimizationPipeline(
diff --git a/clang/test/CodeGen/remote-traps.cpp 
b/clang/test/CodeGen/remote-traps.cpp
new file mode 100644
index 00..7d4eb76a7d81e9
--- /dev/null
+++ b/clang/test/CodeGen/remote-traps.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
+
+int f(int x) {
+  return x + 123;
+}
+
+// CHECK-LABEL: define dso_local noundef i32 @_Z1fi(
+// CHECK: call { i32, i1 } @llvm.sadd.with.overflow.i32(
+// CHECK: trap:
+// CHECK-NEXT: call void @llvm.ubsantrap(i8 0)
+// CHECK-NEXT: unreachable, !nosanitize !2 
+
+// REMOVE-LABEL: define dso_local noundef i32 @_Z1fi(
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(

>From 0b2b44e04b8c900c29f52e340ebdfc6824607773 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:08:47 -0800
Subject: [PATCH 2/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d89e53f69c4a51..fa49a364cf5600 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -752,6 +752,9 @@ static void addSanitizers(const Triple ,
   }
 
   if (ClRemoveTraps) {
+// We can optimize after inliner, and PGO profile matching, which are part
+// of `buildModuleSimplificationPipeline`. The hook below is called after
+// that, from `buildModuleOptimizationPipeline`.
 PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
 OptimizationLevel Level) {
   FunctionPassManager FPM;

>From 000854eb9d18cd9cfd6eaf7d29e5954fb18d454c Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:22:16 -0800
Subject: [PATCH 3/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git 

[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)

2024-03-09 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Diego A. Estrada Rivera (diego-est)


Changes

>From issue #73088. I changed `NodeBuilderContext` into a class. 
>Additionally, there were some other mentions of the former being a struct 
>which I also changed into a class. This is my first time working with an issue 
>so I will be open to hearing any advice or changes that need to be done.

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


1 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
(+3-2) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 8e392421fef9bb..24d4afc551355e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -59,7 +59,7 @@ class CoreEngine {
   friend class ExprEngine;
   friend class IndirectGotoNodeBuilder;
   friend class NodeBuilder;
-  friend struct NodeBuilderContext;
+  friend class NodeBuilderContext;
   friend class SwitchNodeBuilder;
 
 public:
@@ -194,7 +194,8 @@ class CoreEngine {
 };
 
 // TODO: Turn into a class.
-struct NodeBuilderContext {
+class NodeBuilderContext {
+public:
   const CoreEngine 
   const CFGBlock *Block;
   const LocationContext *LC;

``




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


[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)

2024-03-09 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)

2024-03-09 Thread Diego A. Estrada Rivera via cfe-commits

https://github.com/diego-est created 
https://github.com/llvm/llvm-project/pull/84638

>From issue #73088. I changed `NodeBuilderContext` into a class. Additionally, 
>there were some other mentions of the former being a struct which I also 
>changed into a class. This is my first time working with an issue so I will be 
>open to hearing any advice or changes that need to be done.

>From 114e22388508cd1ef5174bdda041564691b58032 Mon Sep 17 00:00:00 2001
From: Sunglas 
Date: Sat, 9 Mar 2024 12:23:43 -0400
Subject: [PATCH] [analyzer] Turn NodeBuilderContext into a class

---
 .../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 8e392421fef9bb..24d4afc551355e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -59,7 +59,7 @@ class CoreEngine {
   friend class ExprEngine;
   friend class IndirectGotoNodeBuilder;
   friend class NodeBuilder;
-  friend struct NodeBuilderContext;
+  friend class NodeBuilderContext;
   friend class SwitchNodeBuilder;
 
 public:
@@ -194,7 +194,8 @@ class CoreEngine {
 };
 
 // TODO: Turn into a class.
-struct NodeBuilderContext {
+class NodeBuilderContext {
+public:
   const CoreEngine 
   const CFGBlock *Block;
   const LocationContext *LC;

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-09 Thread Sam Clegg via cfe-commits

sbc100 wrote:

> > In terms of getting this landed and tested, I wonder which path we should 
> > take:
> > 
> > 1. Land this now, without tests, then update emscripten then come back and 
> > flip the default, at which point the existing tests will get updated.
> > 2. Duplicate/update the the existing tests to tests both modes, then delete 
> > those changes once we flip the default.
> > 
> > Personally I think I'd be happy with (1) since this is a behind and 
> > experimental flag.
> > What do others think? @aheejin ?
> 
> Come to think of it, should we even introduce this experimental option? 
> Adding `if (NewOption) ... else ...` everywhere makes the code complicated. 
> Can we just do
> 
> 1. Add library functions in emscripten

So you think it should be possible to have both old and new versions supported 
in emscripten at the same time?If that works that would be great.  Do you 
want to send and emscripten PR?  And link to it here?   If we can confirm that 
all tests pass then I agree it would be great to do this in a single LLVM 
change.

> 2. Replace the current logic in LLVM with new code. (Without `if`~`else`). 
> Tests can be updated with this.
> 3. Remove old library functions in emscripten.
>?



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


[clang] [Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type (PR #83847)

2024-03-09 Thread Qizhi Hu via cfe-commits

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


[clang] [Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type (PR #83847)

2024-03-09 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/83847

>From 8541506bdbe26b9f24e47e5a372fe89124eaff47 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Mon, 4 Mar 2024 21:51:07 +0800
Subject: [PATCH] [Clang][Sema] Allow access to a public template alias
 declaration that refers to friend's private nested type

---
 clang/docs/ReleaseNotes.rst |  6 +-
 clang/lib/Sema/SemaTemplate.cpp | 13 ++---
 clang/test/SemaTemplate/PR25708.cpp | 23 +++
 3 files changed, 38 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaTemplate/PR25708.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f61dca9bbc8467..b015367329194c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,10 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
+- Allow access to a public template alias declaration that refers to friend's
+  private nested type.
+  Fixes (#GH25708).
+
 Bug Fixes to Compiler Builtins
 ^^
 
@@ -409,7 +413,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using 
+- PTX is no longer included by default when compiling for CUDA. Using
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index d62095558d0ffb..4981aa7c5fc739 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4342,10 +4342,17 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 InstantiatingTemplate Inst(*this, TemplateLoc, Template);
 if (Inst.isInvalid())
   return QualType();
+if (!AliasTemplate->getDeclContext()->isFileContext()) {
+  ContextRAII SavedContext(*this, AliasTemplate->getDeclContext());
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+} else {
 
-CanonType = SubstType(Pattern->getUnderlyingType(),
-  TemplateArgLists, AliasTemplate->getLocation(),
-  AliasTemplate->getDeclName());
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+}
 if (CanonType.isNull()) {
   // If this was enable_if and we failed to find the nested type
   // within enable_if in a SFINAE context, dig out the specific
diff --git a/clang/test/SemaTemplate/PR25708.cpp 
b/clang/test/SemaTemplate/PR25708.cpp
new file mode 100644
index 00..cc2e7551a6abaa
--- /dev/null
+++ b/clang/test/SemaTemplate/PR25708.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+struct FooAccessor
+{
+template 
+using Foo = typename T::Foo;
+};
+
+class Type
+{
+friend struct FooAccessor;
+
+using Foo = int;
+};
+
+int main()
+{
+FooAccessor::Foo t;
+}

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


[clang] [Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type (PR #83847)

2024-03-09 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/83847

>From 76c7e3e19a1d5e3f35f1d3e9d9c99b76e973ff00 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Mon, 4 Mar 2024 21:51:07 +0800
Subject: [PATCH] [Clang][Sema] Allow access to a public template alias
 declaration that refers to friend's private nested type

---
 clang/docs/ReleaseNotes.rst |  6 +-
 clang/lib/Sema/SemaAccess.cpp   |  1 +
 clang/lib/Sema/SemaTemplate.cpp | 13 ++---
 clang/test/SemaTemplate/PR25708.cpp | 23 +++
 4 files changed, 39 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaTemplate/PR25708.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f61dca9bbc8467..b015367329194c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,10 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
+- Allow access to a public template alias declaration that refers to friend's
+  private nested type.
+  Fixes (#GH25708).
+
 Bug Fixes to Compiler Builtins
 ^^
 
@@ -409,7 +413,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using 
+- PTX is no longer included by default when compiling for CUDA. Using
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 4af3c0f30a8e8a..4c5da7ce75bec1 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -1481,6 +1481,7 @@ static Sema::AccessResult CheckAccess(Sema , 
SourceLocation Loc,
   }
 
   EffectiveContext EC(S.CurContext);
+
   switch (CheckEffectiveAccess(S, EC, Loc, Entity)) {
   case AR_accessible: return Sema::AR_accessible;
   case AR_inaccessible: return Sema::AR_inaccessible;
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index d62095558d0ffb..4981aa7c5fc739 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4342,10 +4342,17 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 InstantiatingTemplate Inst(*this, TemplateLoc, Template);
 if (Inst.isInvalid())
   return QualType();
+if (!AliasTemplate->getDeclContext()->isFileContext()) {
+  ContextRAII SavedContext(*this, AliasTemplate->getDeclContext());
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+} else {
 
-CanonType = SubstType(Pattern->getUnderlyingType(),
-  TemplateArgLists, AliasTemplate->getLocation(),
-  AliasTemplate->getDeclName());
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+}
 if (CanonType.isNull()) {
   // If this was enable_if and we failed to find the nested type
   // within enable_if in a SFINAE context, dig out the specific
diff --git a/clang/test/SemaTemplate/PR25708.cpp 
b/clang/test/SemaTemplate/PR25708.cpp
new file mode 100644
index 00..cc2e7551a6abaa
--- /dev/null
+++ b/clang/test/SemaTemplate/PR25708.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+struct FooAccessor
+{
+template 
+using Foo = typename T::Foo;
+};
+
+class Type
+{
+friend struct FooAccessor;
+
+using Foo = int;
+};
+
+int main()
+{
+FooAccessor::Foo t;
+}

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


[clang] [NFC] Eliminate trailing white space causing CI build failure (PR #84632)

2024-03-09 Thread via cfe-commits

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


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


[clang-tools-extra] [clang-tidy]avoid bugprone-unused-return-value false positive for assignment operator overloading (PR #84489)

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

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


[clang-tools-extra] 4fdf10f - [clang-tidy]avoid bugprone-unused-return-value false positive for assignment operator overloading (#84489)

2024-03-09 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-03-09T23:08:51+08:00
New Revision: 4fdf10faf2b45f4bbbd2ddfb07272d19a47cc531

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

LOG: [clang-tidy]avoid bugprone-unused-return-value false positive for 
assignment operator overloading (#84489)

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-avoid-assignment.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 1252b2f23805a1..243fe47c2036b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -11,6 +11,8 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/OperatorKinds.h"
 
 using namespace clang::ast_matchers;
 using namespace clang::ast_matchers::internal;
@@ -28,6 +30,11 @@ AST_MATCHER_P(FunctionDecl, isInstantiatedFrom, 
Matcher,
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
+
+AST_MATCHER_P(CXXMethodDecl, isOperatorOverloading,
+  llvm::SmallVector, Kinds) {
+  return llvm::is_contained(Kinds, Node.getOverloadedOperator());
+}
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -157,16 +164,22 @@ void 
UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 }
 
 void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
-  auto MatchedDirectCallExpr =
-  expr(callExpr(callee(functionDecl(
-// Don't match void overloads of checked functions.
-unless(returns(voidType())),
-
anyOf(isInstantiatedFrom(matchers::matchesAnyListedName(
-  CheckedFunctions)),
-  returns(hasCanonicalType(hasDeclaration(
-  namedDecl(matchers::matchesAnyListedName(
-  CheckedReturnTypes)
-   .bind("match"));
+  auto MatchedDirectCallExpr = expr(
+  callExpr(
+  callee(functionDecl(
+  // Don't match void overloads of checked functions.
+  unless(returns(voidType())),
+  // Don't match copy or move assignment operator.
+  unless(cxxMethodDecl(isOperatorOverloading(
+  {OO_Equal, OO_PlusEqual, OO_MinusEqual, OO_StarEqual,
+   OO_SlashEqual, OO_PercentEqual, OO_CaretEqual, OO_AmpEqual,
+   OO_PipeEqual, OO_LessLessEqual, OO_GreaterGreaterEqual}))),
+  anyOf(
+  isInstantiatedFrom(
+  matchers::matchesAnyListedName(CheckedFunctions)),
+  returns(hasCanonicalType(hasDeclaration(namedDecl(
+  
matchers::matchesAnyListedName(CheckedReturnTypes)
+  .bind("match"));
 
   auto CheckCastToVoid =
   AllowCastToVoid ? castExpr(unless(hasCastKind(CK_ToVoid))) : castExpr();

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a005adf76b8b5b..44680f79de6f54 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -152,9 +152,9 @@ Changes in existing checks
 
 - Improved :doc:`bugprone-unused-return-value
   ` check by updating the
-  parameter `CheckedFunctions` to support regexp and avoiding false postive for
+  parameter `CheckedFunctions` to support regexp, avoiding false positive for
   function with the same prefix as the default argument, e.g. 
``std::unique_ptr``
-  and ``std::unique``.
+  and ``std::unique``, avoiding false positive for assignment operator 
overloading.
 
 - Improved :doc:`bugprone-use-after-move
   ` check to also handle

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
index 9c01ef50b53814..9205ba98729c4b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -5,6 +5,8 @@ bugprone-unused-return-value
 
 Warns on unused function return values. The checked functions can be 
configured.
 
+Operator overloading with assignment semantics 

[clang] e733d7e - Fix test clang-offload-bundler-zstd.c

2024-03-09 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2024-03-09T10:07:57-05:00
New Revision: e733d7e23f6553c55c85edd55511b133d2064677

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

LOG: Fix test clang-offload-bundler-zstd.c

Added: 


Modified: 
clang/test/Driver/clang-offload-bundler-zstd.c

Removed: 




diff  --git a/clang/test/Driver/clang-offload-bundler-zstd.c 
b/clang/test/Driver/clang-offload-bundler-zstd.c
index c1eb3f6e7ebd07..4485e57309bbbc 100644
--- a/clang/test/Driver/clang-offload-bundler-zstd.c
+++ b/clang/test/Driver/clang-offload-bundler-zstd.c
@@ -32,7 +32,7 @@
 // RUN: 
diff  %t.tgt2 %t.res.tgt2
 //
 // COMPRESS: Compression method used: zstd
-// COMPRESS: Compression level: 20
+// COMPRESS: Compression level: 3 
 // DECOMPRESS: Decompression method: zstd
 // DECOMPRESS: Hashes match: Yes
 // NOHOST-NOT: host-



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


[clang] [NFC] Eliminate trailing white space causing CI build failure (PR #84632)

2024-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amirreza Ashouri (AMP999)


Changes

To resolve the following issue in the CI build:
```
*** Checking for trailing whitespace left in Clang source files ***
+ grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs
clang/docs/ReleaseNotes.rst:412:- PTX is no longer included by default when 
compiling for CUDA. Using
+ echo '*** Trailing whitespace has been found in Clang source files as 
described above ***'
*** Trailing whitespace has been found in Clang source files as described above 
***
+ exit 1
```

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


1 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f61dca9bbc8467..3b89d5a8720785 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -409,7 +409,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using 
+- PTX is no longer included by default when compiling for CUDA. Using
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support

``




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


[clang] [NFC] Eliminate trailing white space causing CI build failure (PR #84632)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/84632

To resolve the following issue in the CI build:
```
*** Checking for trailing whitespace left in Clang source files ***
+ grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs
clang/docs/ReleaseNotes.rst:412:- PTX is no longer included by default when 
compiling for CUDA. Using
+ echo '*** Trailing whitespace has been found in Clang source files as 
described above ***'
*** Trailing whitespace has been found in Clang source files as described above 
***
+ exit 1
```

>From c122cc4e95f1e07c922983b787f95edf187b304c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 9 Mar 2024 18:25:07 +0330
Subject: [PATCH] [NFC] Eliminate trailing white space causing CI build failure

To resolve the following issue in the CI build:
```
*** Checking for trailing whitespace left in Clang source files ***
+ grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs
clang/docs/ReleaseNotes.rst:412:- PTX is no longer included by default when 
compiling for CUDA. Using
+ echo '*** Trailing whitespace has been found in Clang source files as 
described above ***'
*** Trailing whitespace has been found in Clang source files as described above 
***
+ exit 1
```
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f61dca9bbc8467..3b89d5a8720785 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -409,7 +409,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using 
+- PTX is no longer included by default when compiling for CUDA. Using
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support

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


[clang] [llvm] [HIP] add --offload-compression-level= option (PR #83605)

2024-03-09 Thread Yaxun Liu via cfe-commits

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


[clang] 124d0b7 - [HIP] add --offload-compression-level= option (#83605)

2024-03-09 Thread via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2024-03-09T09:45:48-05:00
New Revision: 124d0b787b5d1ff4aa06bbd61a98d3fc344d0cc6

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

LOG: [HIP] add --offload-compression-level= option (#83605)

Added --offload-compression-level= option to clang and
-compression-level=
option to clang-offload-bundler for controlling compression level.

Added support of long distance matching (LDM) for llvm::zstd which is
off
by default. Enable it for clang-offload-bundler by default since it
improves compression rate in general.

Change default compression level to 3 for zstd for clang-offload-bundler
since it works well for bundle entry size from 1KB to 32MB, which should
cover most of the clang-offload-bundler usage. Users can still specify
compression level by -compression-level= option if necessary.

Added: 


Modified: 
clang/include/clang/Driver/OffloadBundler.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/OffloadBundler.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/HIPUtility.cpp
clang/test/Driver/clang-offload-bundler-zlib.c
clang/test/Driver/clang-offload-bundler-zstd.c
clang/test/Driver/hip-offload-compress-zlib.hip
clang/test/Driver/hip-offload-compress-zstd.hip
clang/test/Driver/linker-wrapper.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
llvm/include/llvm/Support/Compression.h
llvm/lib/Support/Compression.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/OffloadBundler.h 
b/clang/include/clang/Driver/OffloadBundler.h
index 84349abe185fa4..65d33bfbd2825f 100644
--- a/clang/include/clang/Driver/OffloadBundler.h
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
 #define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
 
+#include "llvm/Support/Compression.h"
 #include "llvm/Support/Error.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -36,6 +37,8 @@ class OffloadBundlerConfig {
   bool HipOpenmpCompatible = false;
   bool Compress = false;
   bool Verbose = false;
+  llvm::compression::Format CompressionFormat;
+  int CompressionLevel;
 
   unsigned BundleAlignment = 1;
   unsigned HostInputIndex = ~0u;
@@ -116,7 +119,8 @@ class CompressedOffloadBundle {
 
 public:
   static llvm::Expected>
-  compress(const llvm::MemoryBuffer , bool Verbose = false);
+  compress(llvm::compression::Params P, const llvm::MemoryBuffer ,
+   bool Verbose = false);
   static llvm::Expected>
   decompress(const llvm::MemoryBuffer , bool Verbose = false);
 };

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d5eed152d15061..aca8c9b0d5487a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1264,6 +1264,10 @@ def fno_gpu_sanitize : Flag<["-"], "fno-gpu-sanitize">, 
Group;
 def offload_compress : Flag<["--"], "offload-compress">,
   HelpText<"Compress offload device binaries (HIP only)">;
 def no_offload_compress : Flag<["--"], "no-offload-compress">;
+
+def offload_compression_level_EQ : Joined<["--"], 
"offload-compression-level=">,
+  Flags<[HelpHidden]>,
+  HelpText<"Compression level for offload device binaries (HIP only)">;
 }
 
 // CUDA options

diff  --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index f9eadfaec88dec..77c89356bc76bb 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -924,6 +924,17 @@ CreateFileHandler(MemoryBuffer ,
 }
 
 OffloadBundlerConfig::OffloadBundlerConfig() {
+  if (llvm::compression::zstd::isAvailable()) {
+CompressionFormat = llvm::compression::Format::Zstd;
+// Compression level 3 is usually sufficient for zstd since long distance
+// matching is enabled.
+CompressionLevel = 3;
+  } else if (llvm::compression::zlib::isAvailable()) {
+CompressionFormat = llvm::compression::Format::Zlib;
+// Use default level for zlib since higher level does not have significant
+// improvement.
+CompressionLevel = llvm::compression::zlib::DefaultCompression;
+  }
   auto IgnoreEnvVarOpt =
   llvm::sys::Process::GetEnv("OFFLOAD_BUNDLER_IGNORE_ENV_VAR");
   if (IgnoreEnvVarOpt.has_value() && IgnoreEnvVarOpt.value() == "1")
@@ -937,11 +948,41 @@ OffloadBundlerConfig::OffloadBundlerConfig() {
   llvm::sys::Process::GetEnv("OFFLOAD_BUNDLER_COMPRESS");
   if (CompressEnvVarOpt.has_value())
 Compress = CompressEnvVarOpt.value() == "1";
+
+  auto CompressionLevelEnvVarOpt =
+  

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 2603e170c127aa614d499e5d527db8503a55c651 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual() 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@mordante Thank you! I've resolved merge conflicts. I've also added an NFC 
commit to remove empty messages from `static_assert`s for consistency with the 
rest of the file.

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/77092

>From ed94371b8e2293642731b72948883c2ec20bd09d Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 3 Jan 2024 23:23:14 +0330
Subject: [PATCH 1/2] [clang] Fix behavior of
 __is_trivially_relocatable(volatile int)

Consistent with `__is_trivially_copyable(volatile int) == true`
and `__is_trivially_relocatable(volatile Trivial) == true`,
`__is_trivially_relocatable(volatile int)` should also be `true`.

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

[clang] [test] New tests for __is_trivially_relocatable(cv-qualified type)
---
 clang/docs/ReleaseNotes.rst|  5 +
 clang/lib/AST/Type.cpp |  2 ++
 clang/test/SemaCXX/type-traits.cpp | 31 ++
 3 files changed, 38 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..d1e0fec9862d8f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,11 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object 
types
+  such as references and functions, and no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (`#67498 `_) and
+  (`#77091 `_)
+
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78dcd3f4007a5a..22666184c56ccf 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2682,6 +2682,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
+  } else if (BaseElementType.isTriviallyCopyableType(Context)) {
+return true;
   } else {
 switch (isNonTrivialToPrimitiveDestructiveMove()) {
 case PCK_Trivial:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..d4f26adfc04147 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3104,6 +3104,8 @@ namespace is_trivially_relocatable {
 static_assert(!__is_trivially_relocatable(void), "");
 static_assert(__is_trivially_relocatable(int), "");
 static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int), "");
+static_assert(__is_trivially_relocatable(volatile int), "");
 
 enum Enum {};
 static_assert(__is_trivially_relocatable(Enum), "");
@@ -3115,7 +3117,28 @@ static_assert(__is_trivially_relocatable(Union[]), "");
 
 struct Trivial {};
 static_assert(__is_trivially_relocatable(Trivial), "");
+static_assert(__is_trivially_relocatable(const Trivial), "");
+static_assert(__is_trivially_relocatable(volatile Trivial), "");
+
 static_assert(__is_trivially_relocatable(Trivial[]), "");
+static_assert(__is_trivially_relocatable(const Trivial[]), "");
+static_assert(__is_trivially_relocatable(volatile Trivial[]), "");
+
+static_assert(__is_trivially_relocatable(int[10]), "");
+static_assert(__is_trivially_relocatable(const int[10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10]), "");
+
+static_assert(__is_trivially_relocatable(int[10][10]), "");
+static_assert(__is_trivially_relocatable(const int[10][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[10][10]), "");
+
+static_assert(__is_trivially_relocatable(int[]), "");
+static_assert(__is_trivially_relocatable(const int[]), "");
+static_assert(__is_trivially_relocatable(volatile int[]), "");
+
+static_assert(__is_trivially_relocatable(int[][10]), "");
+static_assert(__is_trivially_relocatable(const int[][10]), "");
+static_assert(__is_trivially_relocatable(volatile int[][10]), "");
 
 struct Incomplete; // expected-note {{forward declaration of 
'is_trivially_relocatable::Incomplete'}}
 bool unused = __is_trivially_relocatable(Incomplete); // expected-error 
{{incomplete type}}
@@ -3125,6 +3148,8 @@ struct NontrivialDtor {
 };
 static_assert(!__is_trivially_relocatable(NontrivialDtor), "");
 static_assert(!__is_trivially_relocatable(NontrivialDtor[]), "");
+static_assert(!__is_trivially_relocatable(const NontrivialDtor), "");
+static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), "");
 
 struct NontrivialCopyCtor {
   NontrivialCopyCtor(const NontrivialCopyCtor&) {}
@@ -3143,12 +3168,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor {
 };
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), "");
 static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), "");
+static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), "");

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-09 Thread Xiang Li via cfe-commits

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


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


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-09 Thread Xiang Li via cfe-commits


@@ -69,6 +69,21 @@ LangStandard::Kind LangStandard::getLangKind(StringRef Name) 
{
   .Default(lang_unspecified);
 }
 
+LangStandard::Kind LangStandard::getHLSLLangKind(StringRef Name) {
+  if (Name == "2016")

python3kgae wrote:

Maybe a StringSwitch here.



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


[clang] [Clang] [Parser] Support [[omp::assume]] (PR #84582)

2024-03-09 Thread via cfe-commits

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

>From d436f7fefb967f050220a8ede6d05c8e26f363b3 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 8 Mar 2024 23:54:14 +0100
Subject: [PATCH 1/2] [Clang] [Parser] Support [[omp::assume]]

---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/lib/Basic/Attributes.cpp|  8 ++--
 clang/lib/Parse/ParseDeclCXX.cpp  |  4 +++-
 clang/test/Sema/attr-assume.c | 17 +
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fa191c7378dba4..c6877b61fa7f1e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4144,7 +4144,7 @@ def OMPDeclareVariant : InheritableAttr {
 }
 
 def Assumption : InheritableAttr {
-  let Spellings = [Clang<"assume">];
+  let Spellings = [Clang<"assume">, CXX11<"omp", "assume">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let InheritEvenIfAlreadyPresent = 1;
   let Documentation = [AssumptionDocs];
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index 44a4f1890d39e1..867d241a2cf847 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -47,8 +47,12 @@ int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax,
   // attributes. We support those, but not through the typical attribute
   // machinery that goes through TableGen. We support this in all OpenMP modes
   // so long as double square brackets are enabled.
-  if (LangOpts.OpenMP && ScopeName == "omp")
-return (Name == "directive" || Name == "sequence") ? 1 : 0;
+  //
+  // Other OpenMP attributes (e.g. [[omp::assume]]) are handled via the
+  // regular attribute parsing machinery.
+  if (LangOpts.OpenMP && ScopeName == "omp" &&
+  (Name == "directive" || Name == "sequence"))
+return 1;
 
   int res = hasAttributeImpl(Syntax, Name, ScopeName, Target, LangOpts);
   if (res)
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 62632b2d79792e..64129d7eaface5 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4579,7 +4579,9 @@ bool Parser::ParseCXX11AttributeArgs(
 return true;
   }
 
-  if (ScopeName && ScopeName->isStr("omp")) {
+  // [[omp::directive]] and [[omp::sequence]] need special handling.
+  if (ScopeName && ScopeName->isStr("omp") &&
+  (AttrName->isStr("directive") || AttrName->isStr("sequence"))) {
 Diag(AttrNameLoc, getLangOpts().OpenMP >= 51
   ? diag::warn_omp51_compat_attributes
   : diag::ext_omp_attributes);
diff --git a/clang/test/Sema/attr-assume.c b/clang/test/Sema/attr-assume.c
index 98deffa3a74609..3b7721647dee60 100644
--- a/clang/test/Sema/attr-assume.c
+++ b/clang/test/Sema/attr-assume.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -fopenmp -DCXX -verify %s
 
+#ifndef CXX
 void f1(void) __attribute__((assume(3))); // expected-error {{expected string 
literal as argument of 'assume' attribute}}
 void f2(void) __attribute__((assume(int))); // expected-error {{expected 
string literal as argument of 'assume' attribute}}
 void f3(void) __attribute__((assume(for))); // expected-error {{expected 
string literal as argument of 'assume' attribute}}
@@ -12,3 +14,18 @@ void f9(void) __attribute__((assume("omp_no_openmp", 
"omp_no_openmp"))); // expe
 
 int g1 __attribute__((assume(0))); // expected-error {{expected string literal 
as argument of 'assume' attribute}}
 int g2 __attribute__((assume("omp_no_openmp"))); // expected-warning 
{{'assume' attribute only applies to functions and Objective-C methods}}
+
+#else
+[[omp::assume(3)]] void f1(); // expected-error {{expected string literal as 
argument of 'assume' attribute}}
+[[omp::assume(int)]] void f2(); // expected-error {{expected string literal as 
argument of 'assume' attribute}}
+[[omp::assume(for)]] void f3(); // expected-error {{expected string literal as 
argument of 'assume' attribute}}
+[[omp::assume("")]] void f4(); // expected-warning {{unknown assumption 
string ''; attribute is potentially ignored}}
+[[omp::assume("omp_no_openmp")]] void f5();
+[[omp::assume("omp_noopenmp")]] void f6(); // expected-warning {{unknown 
assumption string 'omp_noopenmp' may be misspelled; attribute is potentially 
ignored, did you mean 'omp_no_openmp'?}}
+[[omp::assume("omp_no_openmp_routine")]] void f7(); // expected-warning 
{{unknown assumption string 'omp_no_openmp_routine' may be misspelled; 
attribute is potentially ignored, did you mean 'omp_no_openmp_routines'?}}
+[[omp::assume("omp_no_openmp1")]] void f8(); // expected-warning {{unknown 
assumption string 'omp_no_openmp1' may be misspelled; attribute is potentially 
ignored, did you mean 'omp_no_openmp'?}}
+[[omp::assume("omp_no_openmp", "omp_no_openmp")]] void f9(); // 

[clang] [clang][Interp] Implement __builtin_popcountg (PR #84500)

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

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


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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-03-09 Thread Mark de Wever via cfe-commits

mordante wrote:

@AMP999 I wanted to merge this for you but there are merge conflicts. Can you 
resolve these?

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


[clang] 83fe0b1 - [clang] Fix -Wunused-lambda-capture in TokenAnnotator.cpp (NFC)

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

Author: Jie Fu
Date: 2024-03-09T20:26:10+08:00
New Revision: 83fe0b13824bc419092bad47727aa1c8ca69330a

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

LOG: [clang] Fix -Wunused-lambda-capture in TokenAnnotator.cpp (NFC)

llvm-project/clang/lib/Format/TokenAnnotator.cpp:2707:43:
error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
auto IsQualifiedPointerOrReference = [this](FormatToken *T) {
  ^~~~
1 error generated.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 3a5510661200e8..d7b84e309e0964 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2707,6 +2707,7 @@ class AnnotatingParser {
 auto IsQualifiedPointerOrReference = [this](FormatToken *T) {
   // This is used to handle cases such as x = (foo *const)
   assert(!T->isTypeName(IsCpp) && "Should have already been checked");
+  (void)IsCpp; // Avoid -Wunused-lambda-capture when assertion is disabled.
   // Strip trailing qualifiers such as const or volatile when checking
   // whether the parens could be a cast to a pointer/reference type.
   while (T) {



___
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-09 Thread Mark de Wever via cfe-commits

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

I have only reviewed the libc++ changes and they LGTM.

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][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-09 Thread via cfe-commits


@@ -1398,11 +1398,16 @@ void Sema::ActOnEndOfTranslationUnit() {
   if (FD->getDescribedFunctionTemplate())
 Diag(DiagD->getLocation(), diag::warn_unused_template)
 << /*function=*/0 << DiagD << DiagRange;
-  else
-Diag(DiagD->getLocation(), isa(DiagD)
-   ? diag::warn_unused_member_function
-   : diag::warn_unused_function)
-<< DiagD << DiagRange;
+  else {
+if (isa(DiagD))
+  Diag(DiagD->getLocation(), diag::warn_unused_member_function)
+  << (!isa(DiagD) ? /*member function=*/0
+  : /*constructor=*/1)
+  << DiagD << DiagRange;
+else
+  Diag(DiagD->getLocation(), diag::warn_unused_function)
+  << DiagD << DiagRange;
+  }

cor3ntin wrote:

```suggestion
  else {
Diag(DiagD->getLocation(), isa(DiagD)
   ? diag::warn_unused_member_function
   : diag::warn_unused_function)

<< DiagD 
<< (!isa(DiagD) ? /*member function=*/0

: /*constructor=*/1
<< DiagRange;
  }
```

I think you can simplify like that.
And then change ` warn_unused_member_function : Warning<"unused %select{member 
function|constructor}1 %0"`

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


[clang] [Clang] Only check for error in C++20 mode (PR #84624)

2024-03-09 Thread via cfe-commits

Sirraide wrote:

Merged this w/o review to fix the bots. Should be a trivial change.

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


[clang] [Clang] Only check for error in C++20 mode (PR #84624)

2024-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

Fix a test that was added in #81014 and which caused buildbots to fail. 
Only check for the ‘never produces a constant expression error’ in C++20 mode.

This fixes #84623.

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


1 Files Affected:

- (modified) clang/test/SemaCXX/cxx23-assume.cpp (+2-2) 


``diff
diff --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 2b99cbd3e788a1..2d7c9b174d9019 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -65,8 +65,8 @@ static_assert(h(4) == sizeof(int));
 static_assert(__has_cpp_attribute(assume) == 202207L);
 static_assert(__has_attribute(assume));
 
-constexpr bool i() { // expected-error {{never produces a constant expression}}
-  [[assume(false)]]; // expected-note {{assumption evaluated to false}} 
expected-note {{assumption evaluated to false}} ext-warning {{C++23 extension}}
+constexpr bool i() { // ext-error {{never produces a constant expression}}
+  [[assume(false)]]; // ext-note {{assumption evaluated to false}} 
expected-note {{assumption evaluated to false}} ext-warning {{C++23 extension}}
   return true;
 }
 

``




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


[clang] 5630dc6 - [Clang] Only check for error in C++20 mode (#84624)

2024-03-09 Thread via cfe-commits

Author: Sirraide
Date: 2024-03-09T12:39:55+01:00
New Revision: 5630dc66369ccec925f27151b495c9f9818638f1

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

LOG: [Clang] Only check for error in C++20 mode (#84624)

Fix a test that was added in #81014 and which caused buildbots to fail.
Only check for the ‘never produces a constant expression error’ in C++20
mode.

This fixes #84623.

Added: 


Modified: 
clang/test/SemaCXX/cxx23-assume.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 2b99cbd3e788a1..2d7c9b174d9019 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -65,8 +65,8 @@ static_assert(h(4) == sizeof(int));
 static_assert(__has_cpp_attribute(assume) == 202207L);
 static_assert(__has_attribute(assume));
 
-constexpr bool i() { // expected-error {{never produces a constant expression}}
-  [[assume(false)]]; // expected-note {{assumption evaluated to false}} 
expected-note {{assumption evaluated to false}} ext-warning {{C++23 extension}}
+constexpr bool i() { // ext-error {{never produces a constant expression}}
+  [[assume(false)]]; // ext-note {{assumption evaluated to false}} 
expected-note {{assumption evaluated to false}} ext-warning {{C++23 extension}}
   return true;
 }
 



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


[clang] [Clang] Only check for error in C++20 mode (PR #84624)

2024-03-09 Thread via cfe-commits

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


[clang] [Clang] Only check for error in C++20 mode (PR #84624)

2024-03-09 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/84624

Fix a test that was added in #81014 and which caused buildbots to fail. Only 
check for the ‘never produces a constant expression error’ in C++20 mode.

This fixes #84623.

>From c1c882866ba65626879e053682f9fdea72194ec2 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 9 Mar 2024 12:36:52 +0100
Subject: [PATCH] [Clang] Only check for error in C++20 mode

---
 clang/test/SemaCXX/cxx23-assume.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 2b99cbd3e788a1..2d7c9b174d9019 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -65,8 +65,8 @@ static_assert(h(4) == sizeof(int));
 static_assert(__has_cpp_attribute(assume) == 202207L);
 static_assert(__has_attribute(assume));
 
-constexpr bool i() { // expected-error {{never produces a constant expression}}
-  [[assume(false)]]; // expected-note {{assumption evaluated to false}} 
expected-note {{assumption evaluated to false}} ext-warning {{C++23 extension}}
+constexpr bool i() { // ext-error {{never produces a constant expression}}
+  [[assume(false)]]; // ext-note {{assumption evaluated to false}} 
expected-note {{assumption evaluated to false}} ext-warning {{C++23 extension}}
   return true;
 }
 

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


[clang] [C++20][Coroutines] lambda-coroutine with promise_type ctor. (PR #84519)

2024-03-09 Thread via cfe-commits

https://github.com/cor3ntin commented:

Can we add a changelog entry for that?

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


[clang] [C++20][Coroutines] lambda-coroutine with promise_type ctor. (PR #84519)

2024-03-09 Thread via cfe-commits


@@ -596,8 +596,21 @@ VarDecl *Sema::buildCoroutinePromise(SourceLocation Loc) {
 
   // Add implicit object parameter.
   if (auto *MD = dyn_cast(FD)) {
-if (MD->isImplicitObjectMemberFunction() && !isLambdaCallOperator(MD)) {
-  ExprResult ThisExpr = ActOnCXXThis(Loc);
+if (MD->isImplicitObjectMemberFunction()) {
+  ExprResult ThisExpr{};
+
+  if (isLambdaCallOperator(MD) && !MD->isStatic()) {

cor3ntin wrote:

`MD->isStatic()` can never be true (because `isImplicitObjectMemberFunction` is 
true)

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


[clang] [C++20][Coroutines] lambda-coroutine with promise_type ctor. (PR #84519)

2024-03-09 Thread via cfe-commits

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


[clang] ceaf4a0 - [Clang] Fix status of P1774 Portable assumptions

2024-03-09 Thread via cfe-commits

Author: cor3ntin
Date: 2024-03-09T12:22:40+01:00
New Revision: ceaf4a0aab86f10199e16a825c1bdabe59d07eb3

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

LOG: [Clang] Fix status of P1774 Portable assumptions

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 66a2b11ee34f1c..1e36b90356c3e1 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -381,7 +381,7 @@ C++23 implementation status
 
   Portable assumptions
   https://wg21.link/P1774R8;>P1774R8
-  Clang 19
+  Clang 19
 
 
   Support for UTF-8 as a portable source file encoding



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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 71502300d47f3d5492e6073a3959fe32b0c9cf65 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual() 

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-09 Thread via cfe-commits

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


[clang] 2b5f68a - [Clang][C++23] Implement P1774R8: Portable assumptions (#81014)

2024-03-09 Thread via cfe-commits

Author: Sirraide
Date: 2024-03-09T12:07:16+01:00
New Revision: 2b5f68a5f63d2342a056bf9f86bd116c100fd81a

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

LOG: [Clang][C++23] Implement P1774R8: Portable assumptions (#81014)

This implements the C++23 `[[assume]]` attribute.

Assumption information is lowered to a call to `@llvm.assume`, unless the 
expression has side-effects, in which case it is discarded and a warning is 
issued to tell the user that the assumption doesn’t do anything. A failed 
assumption at compile time is an error (unless we are in `MSVCCompat` mode, in 
which case we don’t check assumptions at compile time).

Due to performance regressions in LLVM, assumptions can be disabled with the 
`-fno-assumptions` flag. With it, assumptions will still be parsed and checked, 
but no calls to `@llvm.assume` will be emitted and assumptions will not be 
checked at compile time.

Added: 
clang/test/CodeGenCXX/cxx23-assume.cpp
clang/test/Parser/cxx23-assume.cpp
clang/test/SemaCXX/cxx23-assume-disabled.cpp
clang/test/SemaCXX/cxx23-assume-print.cpp
clang/test/SemaCXX/cxx23-assume.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmtAttr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 690fc7ed271a3d..f61dca9bbc8467 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -100,6 +100,7 @@ C++23 Feature Support
 
 - Implemented `P2718R0: Lifetime extension in range-based for loops 
`_. Also
   materialize temporary object which is a prvalue in discarded-value 
expression.
+- Implemented `P1774R8: Portable assumptions `_.
 
 - Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index ebb616fbe253fc..fd7970d0451acd 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1580,6 +1580,13 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def CXXAssume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202207>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [CXXAssumeDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
@@ -4151,11 +4158,11 @@ def OMPDeclareVariant : InheritableAttr {
   }];
 }
 
-def Assumption : InheritableAttr {
+def OMPAssume : InheritableAttr {
   let Spellings = [Clang<"assume">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let InheritEvenIfAlreadyPresent = 1;
-  let Documentation = [AssumptionDocs];
+  let Documentation = [OMPAssumeDocs];
   let Args = [StringArgument<"Assumption">];
 }
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b96fbddd51154c..2c07cd09b0d5b7 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1996,6 +1996,34 @@ Here is an example:
   }];
 }
 
+def CXXAssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition is assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is
+undefined. ``assume`` can only be applied to a null statement.
+
+Different optimisers are likely to react 
diff erently to the presence of
+this attribute; in some cases, adding ``assume`` may affect performance
+negatively. It should be used with parsimony and care.
+
+Note that `clang::assume` is a 
diff erent attribute. Always write ``assume``
+without a namespace if you intend to use the standard 

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amirreza Ashouri (AMP999)


Changes

To resolve llvm#69394, this patch separates trivial-relocatability's 
logic from `canPassInRegisters` to decide if a type is trivial-relocatable. A 
type passed in registers doesn't necessarily mean trivial-relocatability of 
that type(e.g. on Windows) i.e. it gives us an unintended false positive. This 
change would be beneficial for Abseil since they rely upon these semantics. By 
these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable. The `[[clang::trivial_abi]]` attribute always implies 
trivial-relocatability, even if it can't pass in registers. The trait has 
extensive tests for both old and new behaviors. Test aggregation of both kinds 
of types as data members; inheritance; virtual member functions and virtual 
bases; const and reference data members; and reference types.

Fixes llvm#69394

---

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


7 Files Affected:

- (modified) clang/include/clang/AST/CXXRecordDeclDefinitionBits.def (+5) 
- (modified) clang/include/clang/AST/DeclCXX.h (+3) 
- (modified) clang/lib/AST/DeclCXX.cpp (+42-3) 
- (modified) clang/lib/AST/Type.cpp (+4-2) 
- (modified) clang/test/SemaCXX/attr-trivial-abi.cpp (-35) 
- (added) clang/test/SemaCXX/is-trivially-relocatable.cpp (+106) 
- (modified) clang/test/SemaCXX/type-traits.cpp (+68) 


``diff
diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 117e802dae2d9d..ae9de533889f2c 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual() || !BaseClassDecl->isTriviallyRelocatable())
+  data().IsNaturallyTriviallyRelocatable = false;
+
 // Now go through all virtual bases of this base and add them.
 for (const 

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-09 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 created 
https://github.com/llvm/llvm-project/pull/84621

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics. By these changes 
now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable. The `[[clang::trivial_abi]]` attribute always implies 
trivial-relocatability, even if it can't pass in registers. The trait has 
extensive tests for both old and new behaviors. Test aggregation of both kinds 
of types as data members; inheritance; virtual member functions and virtual 
bases; const and reference data members; and reference types.

Fixes llvm#69394

>From 191a98edecdbe7451d75adc3a71ee2f94bb046cd Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH] [clang][Sema] Track trivial-relocatability as a type trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   6 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  68 +++
 7 files changed, 228 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 117e802dae2d9d..ae9de533889f2c 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ 

[clang] [Clang][Driver] Merge the different strategies of how libc++ is included (PR #83721)

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

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


[clang] [clang] Add optional pass to remove UBSAN traps using PGO (PR #84214)

2024-03-09 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84214

>From feb5bfa786d1660a7fe0b6c48ec9048cdd315800 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:03:46 -0800
Subject: [PATCH 1/7] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp   | 17 +
 clang/test/CodeGen/remote-traps.cpp | 15 +++
 2 files changed, 32 insertions(+)
 create mode 100644 clang/test/CodeGen/remote-traps.cpp

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7310e3817c79a1..d89e53f69c4a51 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Instrumentation/MemProfiler.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -83,6 +84,7 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
+#include "llvm/Transforms/Scalar/SimplifyCFG.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,6 +100,10 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
+
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
@@ -744,6 +750,17 @@ static void addSanitizers(const Triple ,
 // LastEP does not need GlobalsAA.
 PB.registerOptimizerLastEPCallback(SanitizersCallback);
   }
+
+  if (ClRemoveTraps) {
+PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
+OptimizationLevel Level) {
+  FunctionPassManager FPM;
+  FPM.addPass(RemoveTrapsPass());
+  FPM.addPass(
+  
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+});
+  }
 }
 
 void EmitAssemblyHelper::RunOptimizationPipeline(
diff --git a/clang/test/CodeGen/remote-traps.cpp 
b/clang/test/CodeGen/remote-traps.cpp
new file mode 100644
index 00..7d4eb76a7d81e9
--- /dev/null
+++ b/clang/test/CodeGen/remote-traps.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
+
+int f(int x) {
+  return x + 123;
+}
+
+// CHECK-LABEL: define dso_local noundef i32 @_Z1fi(
+// CHECK: call { i32, i1 } @llvm.sadd.with.overflow.i32(
+// CHECK: trap:
+// CHECK-NEXT: call void @llvm.ubsantrap(i8 0)
+// CHECK-NEXT: unreachable, !nosanitize !2 
+
+// REMOVE-LABEL: define dso_local noundef i32 @_Z1fi(
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(

>From 0b2b44e04b8c900c29f52e340ebdfc6824607773 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:08:47 -0800
Subject: [PATCH 2/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d89e53f69c4a51..fa49a364cf5600 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -752,6 +752,9 @@ static void addSanitizers(const Triple ,
   }
 
   if (ClRemoveTraps) {
+// We can optimize after inliner, and PGO profile matching, which are part
+// of `buildModuleSimplificationPipeline`. The hook below is called after
+// that, from `buildModuleOptimizationPipeline`.
 PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
 OptimizationLevel Level) {
   FunctionPassManager FPM;

>From 000854eb9d18cd9cfd6eaf7d29e5954fb18d454c Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:22:16 -0800
Subject: [PATCH 3/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git 

[clang] Revert "[clang] Fix crash when declaring invalid lambda member" (PR #84615)

2024-03-09 Thread Vitaly Buka via cfe-commits

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


[clang] def038b - Revert "[clang] Fix crash when declaring invalid lambda member" (#84615)

2024-03-09 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-03-09T00:33:21-08:00
New Revision: def038bc40fae7d6756dde9c41677d76ad0387d2

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

LOG: Revert "[clang] Fix crash when declaring invalid lambda member" (#84615)

Reverts llvm/llvm-project#74110

Fails on many bots:
https://lab.llvm.org/buildbot/#/builders/5/builds/41633

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/DeclCXX.cpp
clang/test/SemaCXX/lambda-expressions.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8935a610722a31..690fc7ed271a3d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,9 +258,6 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
-- Fixes an assertion failure on invalid code when trying to define member
-  functions in lambdas.
-
 Bug Fixes to Compiler Builtins
 ^^
 
@@ -411,7 +408,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using
+- PTX is no longer included by default when compiling for CUDA. Using 
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 645ec2f7563bca..1c3dcf63465c68 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1567,9 +1567,10 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  return llvm::all_of(R, [&](NamedDecl *D) {
-return D->isInvalidDecl() || declaresSameEntity(D, R.front());
-  });
+  for (auto *D : R)
+if (!declaresSameEntity(D, R.front()))
+  return false;
+  return true;
 }
 #endif
 

diff  --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 8907b08e1830e0..0516a5da31ae9a 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,4 +1,3 @@
-// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -559,8 +558,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
+  A d = [&](auto param) { int y = x; };
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
 };
 
 B b;
@@ -590,7 +589,6 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
-  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -606,7 +604,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto ) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
+  auto y = [](auto ) -> void { v.n = 0; };
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -626,22 +624,22 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
+friend auto T::operator()(int) const;
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
+  friend void U::operator()(T&) const;
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
+  friend U::operator ExpectedTypeU() const;
 #endif
 
   private:
 int n;
   };
 
-  // Should be OK in C++14 and later: lambda's call operator is a friend.
-  void use(X ) { y(x); } // cxx11-error {{no matching function for call to 
object}}

[clang] Revert "[clang] Fix crash when declaring invalid lambda member" (PR #84615)

2024-03-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vitaly Buka (vitalybuka)


Changes

Reverts llvm/llvm-project#74110

Fails on many bots: https://lab.llvm.org/buildbot/#/builders/5/builds/41633

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1-4) 
- (modified) clang/lib/AST/DeclCXX.cpp (+4-3) 
- (modified) clang/test/SemaCXX/lambda-expressions.cpp (+8-10) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8935a610722a31..690fc7ed271a3d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,9 +258,6 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
-- Fixes an assertion failure on invalid code when trying to define member
-  functions in lambdas.
-
 Bug Fixes to Compiler Builtins
 ^^
 
@@ -411,7 +408,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using
+- PTX is no longer included by default when compiling for CUDA. Using 
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 645ec2f7563bca..1c3dcf63465c68 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1567,9 +1567,10 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  return llvm::all_of(R, [&](NamedDecl *D) {
-return D->isInvalidDecl() || declaresSameEntity(D, R.front());
-  });
+  for (auto *D : R)
+if (!declaresSameEntity(D, R.front()))
+  return false;
+  return true;
 }
 #endif
 
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 8907b08e1830e0..0516a5da31ae9a 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,4 +1,3 @@
-// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -559,8 +558,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
+  A d = [&](auto param) { int y = x; };
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
 };
 
 B b;
@@ -590,7 +589,6 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
-  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -606,7 +604,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto ) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
+  auto y = [](auto ) -> void { v.n = 0; };
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -626,22 +624,22 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
+friend auto T::operator()(int) const;
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
+  friend void U::operator()(T&) const;
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
+  friend U::operator ExpectedTypeU() const;
 #endif
 
   private:
 int n;
   };
 
-  // Should be OK in C++14 and later: lambda's call operator is a friend.
-  void use(X ) { y(x); } // cxx11-error {{no matching function for call to 
object}}
+  // Should be OK: lambda's call operator is a friend.
+  void use(X ) { y(x); }
 
   // This used to crash in return type deduction for the conversion opreator.
   struct A { int n; void f() { +[](decltype(n)) {}; } };

``





[clang] Revert "[clang] Fix crash when declaring invalid lambda member" (PR #84615)

2024-03-09 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/84615

Reverts llvm/llvm-project#74110

Fails on many bots: https://lab.llvm.org/buildbot/#/builders/5/builds/41633

>From 780ee1d80aa1b8cf54bd642e7c2a7e59c2dc9e11 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Sat, 9 Mar 2024 00:30:10 -0800
Subject: [PATCH] Revert "[clang] Fix crash when declaring invalid lambda
 member (#74110)"

This reverts commit dc567a2ec61d07e89902f73c1bdd4106dc071f3f.
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/lib/AST/DeclCXX.cpp |  7 ---
 clang/test/SemaCXX/lambda-expressions.cpp | 18 --
 3 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8935a610722a31..690fc7ed271a3d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,9 +258,6 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
-- Fixes an assertion failure on invalid code when trying to define member
-  functions in lambdas.
-
 Bug Fixes to Compiler Builtins
 ^^
 
@@ -411,7 +408,7 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
-- PTX is no longer included by default when compiling for CUDA. Using
+- PTX is no longer included by default when compiling for CUDA. Using 
   ``--cuda-include-ptx=all`` will return the old behavior.
 
 CUDA Support
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 645ec2f7563bca..1c3dcf63465c68 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1567,9 +1567,10 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  return llvm::all_of(R, [&](NamedDecl *D) {
-return D->isInvalidDecl() || declaresSameEntity(D, R.front());
-  });
+  for (auto *D : R)
+if (!declaresSameEntity(D, R.front()))
+  return false;
+  return true;
 }
 #endif
 
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 8907b08e1830e0..0516a5da31ae9a 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,4 +1,3 @@
-// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -559,8 +558,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
+  A d = [&](auto param) { int y = x; };
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
 };
 
 B b;
@@ -590,7 +589,6 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
-  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -606,7 +604,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto ) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
+  auto y = [](auto ) -> void { v.n = 0; };
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -626,22 +624,22 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
+friend auto T::operator()(int) const;
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
+  friend void U::operator()(T&) const;
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
+  friend U::operator ExpectedTypeU() const;
 #endif
 
   private:
 int n;
   };
 
-  // Should be OK in C++14 and later: lambda's call operator is a friend.
-  void use(X ) { y(x); } // cxx11-error {{no matching function for call to 
object}}
+  // 

[clang] [clang] Add optional pass to remove UBSAN traps using PGO (PR #84214)

2024-03-09 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84214

>From feb5bfa786d1660a7fe0b6c48ec9048cdd315800 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:03:46 -0800
Subject: [PATCH 1/7] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp   | 17 +
 clang/test/CodeGen/remote-traps.cpp | 15 +++
 2 files changed, 32 insertions(+)
 create mode 100644 clang/test/CodeGen/remote-traps.cpp

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7310e3817c79a1..d89e53f69c4a51 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Instrumentation/MemProfiler.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -83,6 +84,7 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
+#include "llvm/Transforms/Scalar/SimplifyCFG.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,6 +100,10 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
+
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
@@ -744,6 +750,17 @@ static void addSanitizers(const Triple ,
 // LastEP does not need GlobalsAA.
 PB.registerOptimizerLastEPCallback(SanitizersCallback);
   }
+
+  if (ClRemoveTraps) {
+PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
+OptimizationLevel Level) {
+  FunctionPassManager FPM;
+  FPM.addPass(RemoveTrapsPass());
+  FPM.addPass(
+  
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+});
+  }
 }
 
 void EmitAssemblyHelper::RunOptimizationPipeline(
diff --git a/clang/test/CodeGen/remote-traps.cpp 
b/clang/test/CodeGen/remote-traps.cpp
new file mode 100644
index 00..7d4eb76a7d81e9
--- /dev/null
+++ b/clang/test/CodeGen/remote-traps.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
+
+int f(int x) {
+  return x + 123;
+}
+
+// CHECK-LABEL: define dso_local noundef i32 @_Z1fi(
+// CHECK: call { i32, i1 } @llvm.sadd.with.overflow.i32(
+// CHECK: trap:
+// CHECK-NEXT: call void @llvm.ubsantrap(i8 0)
+// CHECK-NEXT: unreachable, !nosanitize !2 
+
+// REMOVE-LABEL: define dso_local noundef i32 @_Z1fi(
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(

>From 0b2b44e04b8c900c29f52e340ebdfc6824607773 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:08:47 -0800
Subject: [PATCH 2/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d89e53f69c4a51..fa49a364cf5600 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -752,6 +752,9 @@ static void addSanitizers(const Triple ,
   }
 
   if (ClRemoveTraps) {
+// We can optimize after inliner, and PGO profile matching, which are part
+// of `buildModuleSimplificationPipeline`. The hook below is called after
+// that, from `buildModuleOptimizationPipeline`.
 PB.registerOptimizerEarlyEPCallback([&](ModulePassManager ,
 OptimizationLevel Level) {
   FunctionPassManager FPM;

>From 000854eb9d18cd9cfd6eaf7d29e5954fb18d454c Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 6 Mar 2024 10:22:16 -0800
Subject: [PATCH 3/7] comment

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git