[PATCH] D152109: Update clang-repl documentation

2023-06-09 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/docs/ClangRepl.rst:119
+   clang-repl> int c = sum(9,10);
+   clang-repl> std::cout << c;
+   19clang-repl>





Comment at: clang/docs/ClangRepl.rst:120
+   clang-repl> std::cout << c;
+   19clang-repl>
+





Comment at: clang/docs/ClangRepl.rst:145
+
+   clang-repl> #include
+   clang-repl> class Rectangle {int width, height; public: void set_values 
(int,int);int area() {return width*height;}};





Comment at: clang/docs/ClangRepl.rst:146
+   clang-repl> #include
+   clang-repl> class Rectangle {int width, height; public: void set_values 
(int,int);int area() {return width*height;}};
+   clang-repl>  void Rectangle::set_values (int x, int y) { width = x;height = 
y;}

We can use `\` to break lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152109

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


[PATCH] D150843: [clang][Diagnostics] Refactor printableTextForNextCharacter

2023-06-09 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6669dc09a441: [clang][NFC] Refactor 
printableTextForNextCharacter (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D150843?vs=529170&id=530160#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150843

Files:
  clang/lib/Frontend/TextDiagnostic.cpp

Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -91,73 +91,78 @@
 ///printableTextForNextCharacter.
 ///
 /// \param SourceLine The line of source
-/// \param i Pointer to byte index,
+/// \param I Pointer to byte index,
 /// \param TabStop used to expand tabs
 /// \return pair(printable text, 'true' iff original text was printable)
 ///
 static std::pair, bool>
-printableTextForNextCharacter(StringRef SourceLine, size_t *i,
+printableTextForNextCharacter(StringRef SourceLine, size_t *I,
   unsigned TabStop) {
-  assert(i && "i must not be null");
-  assert(*i expandedTab;
-expandedTab.assign(NumSpaces, ' ');
-return std::make_pair(expandedTab, true);
+SmallString<16> ExpandedTab;
+ExpandedTab.assign(NumSpaces, ' ');
+return std::make_pair(ExpandedTab, true);
   }
 
-  unsigned char const *begin, *end;
-  begin = reinterpret_cast(&*(SourceLine.begin() + *i));
-  end = begin + (SourceLine.size() - *i);
-
-  if (llvm::isLegalUTF8Sequence(begin, end)) {
-llvm::UTF32 c;
-llvm::UTF32 *cptr = &c;
-unsigned char const *original_begin = begin;
-unsigned char const *cp_end =
-begin + llvm::getNumBytesForUTF8(SourceLine[*i]);
-
-llvm::ConversionResult res = llvm::ConvertUTF8toUTF32(
-&begin, cp_end, &cptr, cptr + 1, llvm::strictConversion);
-(void)res;
-assert(llvm::conversionOK == res);
-assert(0 < begin-original_begin
-   && "we must be further along in the string now");
-*i += begin-original_begin;
-
-if (!llvm::sys::locale::isPrint(c)) {
-  // If next character is valid UTF-8, but not printable
-  SmallString<16> expandedCP("");
-  while (c) {
-expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(c%16));
-c/=16;
-  }
-  while (expandedCP.size() < 8)
-expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(0));
-  return std::make_pair(expandedCP, false);
-}
-
-// If next character is valid UTF-8, and printable
-return std::make_pair(SmallString<16>(original_begin, cp_end), true);
+  const unsigned char *Begin = SourceLine.bytes_begin() + *I;
 
+  // Fast path for the common ASCII case.
+  if (*Begin < 0x80 && llvm::sys::locale::isPrint(*Begin)) {
+++(*I);
+return std::make_pair(SmallString<16>(Begin, Begin + 1), true);
+  }
+  unsigned CharSize = llvm::getNumBytesForUTF8(*Begin);
+  const unsigned char *End = Begin + CharSize;
+
+  // Convert it to UTF32 and check if it's printable.
+  if (End <= SourceLine.bytes_end() && llvm::isLegalUTF8Sequence(Begin, End)) {
+llvm::UTF32 C;
+llvm::UTF32 *CPtr = &C;
+
+// Begin and end before conversion.
+unsigned char const *OriginalBegin = Begin;
+llvm::ConversionResult Res = llvm::ConvertUTF8toUTF32(
+&Begin, End, &CPtr, CPtr + 1, llvm::strictConversion);
+(void)Res;
+assert(Res == llvm::conversionOK);
+assert(OriginalBegin < Begin);
+assert((Begin - OriginalBegin) == CharSize);
+
+(*I) += (Begin - OriginalBegin);
+
+// Valid, multi-byte, printable UTF8 character.
+if (llvm::sys::locale::isPrint(C))
+  return std::make_pair(SmallString<16>(OriginalBegin, End), true);
+
+// Valid but not printable.
+SmallString<16> Str("");
+while (C) {
+  Str.insert(Str.begin() + 3, llvm::hexdigit(C % 16));
+  C /= 16;
+}
+while (Str.size() < 8)
+  Str.insert(Str.begin() + 3, llvm::hexdigit(0));
+return std::make_pair(Str, false);
   }
 
-  // If next byte is not valid UTF-8 (and therefore not printable)
-  SmallString<16> expandedByte("");
-  unsigned char byte = SourceLine[*i];
-  expandedByte[1] = llvm::hexdigit(byte / 16);
-  expandedByte[2] = llvm::hexdigit(byte % 16);
-  ++(*i);
-  return std::make_pair(expandedByte, false);
+  // Otherwise, not printable since it's not valid UTF8.
+  SmallString<16> ExpandedByte("");
+  unsigned char Byte = SourceLine[*I];
+  ExpandedByte[1] = llvm::hexdigit(Byte / 16);
+  ExpandedByte[2] = llvm::hexdigit(Byte % 16);
+  ++(*I);
+  return std::make_pair(ExpandedByte, false);
 }
 
 static void expandTabs(std::string &SourceLine, unsigned TabStop) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6669dc0 - [clang][NFC] Refactor printableTextForNextCharacter

2023-06-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-10T07:51:36+02:00
New Revision: 6669dc09a441f27f3b5e18805a1a59fbe93a4cd6

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

LOG: [clang][NFC] Refactor printableTextForNextCharacter

Differential Revision: https://reviews.llvm.org/D150843

Added: 


Modified: 
clang/lib/Frontend/TextDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 3cdf86f5c8a6e..48082d7273e51 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -91,73 +91,78 @@ static int bytesSincePreviousTabOrLineBegin(StringRef 
SourceLine, size_t i) {
 ///printableTextForNextCharacter.
 ///
 /// \param SourceLine The line of source
-/// \param i Pointer to byte index,
+/// \param I Pointer to byte index,
 /// \param TabStop used to expand tabs
 /// \return pair(printable text, 'true' iff original text was printable)
 ///
 static std::pair, bool>
-printableTextForNextCharacter(StringRef SourceLine, size_t *i,
+printableTextForNextCharacter(StringRef SourceLine, size_t *I,
   unsigned TabStop) {
-  assert(i && "i must not be null");
-  assert(*i expandedTab;
-expandedTab.assign(NumSpaces, ' ');
-return std::make_pair(expandedTab, true);
+SmallString<16> ExpandedTab;
+ExpandedTab.assign(NumSpaces, ' ');
+return std::make_pair(ExpandedTab, true);
   }
 
-  unsigned char const *begin, *end;
-  begin = reinterpret_cast(&*(SourceLine.begin() + *i));
-  end = begin + (SourceLine.size() - *i);
-
-  if (llvm::isLegalUTF8Sequence(begin, end)) {
-llvm::UTF32 c;
-llvm::UTF32 *cptr = &c;
-unsigned char const *original_begin = begin;
-unsigned char const *cp_end =
-begin + llvm::getNumBytesForUTF8(SourceLine[*i]);
-
-llvm::ConversionResult res = llvm::ConvertUTF8toUTF32(
-&begin, cp_end, &cptr, cptr + 1, llvm::strictConversion);
-(void)res;
-assert(llvm::conversionOK == res);
-assert(0 < begin-original_begin
-   && "we must be further along in the string now");
-*i += begin-original_begin;
-
-if (!llvm::sys::locale::isPrint(c)) {
-  // If next character is valid UTF-8, but not printable
-  SmallString<16> expandedCP("");
-  while (c) {
-expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(c%16));
-c/=16;
-  }
-  while (expandedCP.size() < 8)
-expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(0));
-  return std::make_pair(expandedCP, false);
-}
-
-// If next character is valid UTF-8, and printable
-return std::make_pair(SmallString<16>(original_begin, cp_end), true);
+  const unsigned char *Begin = SourceLine.bytes_begin() + *I;
 
+  // Fast path for the common ASCII case.
+  if (*Begin < 0x80 && llvm::sys::locale::isPrint(*Begin)) {
+++(*I);
+return std::make_pair(SmallString<16>(Begin, Begin + 1), true);
+  }
+  unsigned CharSize = llvm::getNumBytesForUTF8(*Begin);
+  const unsigned char *End = Begin + CharSize;
+
+  // Convert it to UTF32 and check if it's printable.
+  if (End <= SourceLine.bytes_end() && llvm::isLegalUTF8Sequence(Begin, End)) {
+llvm::UTF32 C;
+llvm::UTF32 *CPtr = &C;
+
+// Begin and end before conversion.
+unsigned char const *OriginalBegin = Begin;
+llvm::ConversionResult Res = llvm::ConvertUTF8toUTF32(
+&Begin, End, &CPtr, CPtr + 1, llvm::strictConversion);
+(void)Res;
+assert(Res == llvm::conversionOK);
+assert(OriginalBegin < Begin);
+assert((Begin - OriginalBegin) == CharSize);
+
+(*I) += (Begin - OriginalBegin);
+
+// Valid, multi-byte, printable UTF8 character.
+if (llvm::sys::locale::isPrint(C))
+  return std::make_pair(SmallString<16>(OriginalBegin, End), true);
+
+// Valid but not printable.
+SmallString<16> Str("");
+while (C) {
+  Str.insert(Str.begin() + 3, llvm::hexdigit(C % 16));
+  C /= 16;
+}
+while (Str.size() < 8)
+  Str.insert(Str.begin() + 3, llvm::hexdigit(0));
+return std::make_pair(Str, false);
   }
 
-  // If next byte is not valid UTF-8 (and therefore not printable)
-  SmallString<16> expandedByte("");
-  unsigned char byte = SourceLine[*i];
-  expandedByte[1] = llvm::hexdigit(byte / 16);
-  expandedByte[2] = llvm::hexdigit(byte % 16);
-  ++(*i);
-  return std::make_pair(expandedByte, false);
+  // Otherwise, not printable since it's not valid UTF8.
+  SmallString<16> ExpandedByte("");
+  unsigned char Byte = SourceLine[*I];
+  ExpandedByte[1] = llvm::hexdigit(Byte / 16);
+  ExpandedByte[2] = llvm::hexdigit(Byte % 16);
+  ++(*I);
+  return std::make_pair(ExpandedByte, false);
 }
 
 static void expandTabs(std::string &SourceLine, unsigned TabStop) {


  

[clang] 0e9843b - [clang][parse][NFC] Fix grammar in a comment

2023-06-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-10T07:51:36+02:00
New Revision: 0e9843bf35d94100a843baf660700011227a6cc4

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

LOG: [clang][parse][NFC] Fix grammar in a comment

Added: 


Modified: 
clang/lib/Parse/ParseStmt.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 224df67b47f8f..43ff808e296b5 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -1625,7 +1625,7 @@ StmtResult Parser::ParseIfStatement(SourceLocation 
*TrailingElseLoc) {
   IfScope.Exit();
 
   // If the then or else stmt is invalid and the other is valid (and present),
-  // make turn the invalid one into a null stmt to avoid dropping the other
+  // turn the invalid one into a null stmt to avoid dropping the other
   // part.  If both are invalid, return error.
   if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
   (ThenStmt.isInvalid() && ElseStmt.get() == nullptr) ||
@@ -1636,7 +1636,7 @@ StmtResult Parser::ParseIfStatement(SourceLocation 
*TrailingElseLoc) {
 
   if (IsConsteval) {
 auto IsCompoundStatement = [](const Stmt *S) {
-  if (const auto *Outer = dyn_cast_or_null(S))
+  if (const auto *Outer = dyn_cast_if_present(S))
 S = Outer->getSubStmt();
   return isa_and_nonnull(S);
 };



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


[PATCH] D152604: [Driver] Default -fsanitize-address-globals-dead-stripping to true for ELF

2023-06-09 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152604

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


[PATCH] D152604: [Driver] Default -fsanitize-address-globals-dead-stripping to true for ELF

2023-06-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: Sanitizers, aeubanks, rnk, eugenis, phosek, probinson.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

-fsanitize-address-globals-dead-stripping is the default for non-ELF
platforms. For ELF, we disabled it to work around an ancient gold 2.26
bug. However, some platforms (Fuchsia and PS) default the option to
true.

This patch changes -fsanitize-address-globals-dead-stripping to true for all ELF
platforms. Without specifying -fdata-sections (non-default for most ELF
platforms), `asan_globals` can only be GCed if the monolithic .data/.bss section
is GCed, which makes it less effective.
However, I think this simplified rule is better than making the
-fsanitize-address-globals-dead-stripping default dependent on another option.

Close https://github.com/llvm/llvm-project/issues/63127


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152604

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -240,7 +240,7 @@
 // CHECK-ASAN-WITHOUT-POISON-CUSTOM-ARRAY-NEW-COOKIE-NOT: 
-cc1{{.*}}address-poison-custom-array-cookie
 
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=address 
-fsanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-GLOBALS
-// RUN: %clang --target=x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
+// RUN: %clang --target=x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=address 
-fsanitize-address-globals-dead-stripping 
-fno-sanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-NO-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address 
-fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 
2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -928,14 +928,9 @@
  options::OPT_fno_sanitize_address_outline_instrumentation,
  AsanOutlineInstrumentation);
 
-// As a workaround for a bug in gold 2.26 and earlier, dead stripping of
-// globals in ASan is disabled by default on most ELF targets.
-// See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
 AsanGlobalsDeadStripping = Args.hasFlag(
 options::OPT_fsanitize_address_globals_dead_stripping,
-options::OPT_fno_sanitize_address_globals_dead_stripping,
-!TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
-TC.getTriple().isPS());
+options::OPT_fno_sanitize_address_globals_dead_stripping, true);
 
 // Enable ODR indicators which allow better handling of mixed instrumented
 // and uninstrumented globals. Disable them for Windows where weak odr


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -240,7 +240,7 @@
 // CHECK-ASAN-WITHOUT-POISON-CUSTOM-ARRAY-NEW-COOKIE-NOT: -cc1{{.*}}address-poison-custom-array-cookie
 
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=address -fsanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
-// RUN: %clang --target=x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
+// RUN: %clang --target=x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-sanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -928,14 +928,9 @@
  options::OPT_fno_sanitize_address_outline_instrumentation,
  AsanOutlineInstrumentation);
 
- 

[PATCH] D147732: [AMDGPU] Add type mangling for {read, write, readfirst, perm}lane intrinsics

2023-06-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

D84639  is an old version of this. It has some 
additional tests not covered here, can you copy them?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147732

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


[PATCH] D84068: AMDGPU/clang: Search resource directory for device libraries

2023-06-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm abandoned this revision.
arsenm added a comment.
Herald added a subscriber: MaskRay.
Herald added a project: All.

This was already done


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

https://reviews.llvm.org/D84068

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


[PATCH] D137524: clang/AMDGPU: Emit atomicrmw for atomic_inc/dec builtins

2023-06-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.
Herald added a subscriber: arichardson.

ping


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

https://reviews.llvm.org/D137524

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


[PATCH] D145767: [Verifier][NFC] Refactor check for associated metadata to allow multiple operands on AIX

2023-06-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGen/PowerPC/aix-init-ref-null.cpp:1
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -emit-llvm -O3 -x c++ < %s 
| FileCheck %s
+

Don't use -O3, maybe -O1 -disable-llvm-passes



Comment at: clang/test/CodeGen/PowerPC/aix-init-ref-null.cpp:1
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -emit-llvm -O3 -x c++ < %s 
| FileCheck %s
+

arsenm wrote:
> Don't use -O3, maybe -O1 -disable-llvm-passes
Use generated checks with --check-globals?



Comment at: clang/test/CodeGen/PowerPC/aix-init-ref-null.cpp:22
+// CHECK: @base_rview = local_unnamed_addr global %struct.ext zeroinitializer, 
align [[ALIGN:[0-9]+]]
+// XFAIL-CHECK: @base_rview = local_unnamed_addr global %struct.ext 
zeroinitializer, align [[ALIGN:[0-9]+]], !associated ![[ASSOC0:[0-9]+]]
+// CHECK: @llvm.global_ctors = appending global [0 x { i32, ptr, ptr }] 
zeroinitializer

XFAIL-CHECK doesn't do anything



Comment at: clang/test/CodeGen/PowerPC/aix-ref-static-var.cpp:11
+// CHECK: @_ZZ1fvE1s = internal global %struct.S zeroinitializer, align 
[[ALIGN:[0-9]+]]
+// XFAIL-CHECK: @_ZZ1fvE1s = internal global %struct.S zeroinitializer, align 
[[ALIGN:[0-9]+]], !associated ![[ASSOC0:[0-9]+]]
+// CHECK: define internal void @__dtor__ZZ1fvE1s() [[ATTR:#[0-9]+]] {

XFAIL-CHECK doesn't do anything


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145767

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1279
+  if (isa(E))
+return nullptr;
+

nickdesaulniers wrote:
> efriedma wrote:
> > efriedma wrote:
> > > This needs a comment explaining why we're bailing out here.
> > We might need to do a recursive visit still, to handle the cases noted at 
> > https://en.cppreference.com/w/cpp/language/reference_initialization#Lifetime_of_a_temporary
> >  .  Not constructors, but other things.  I think we don't have existing 
> > testcases, but for example `typedef int x[2]; struct Z { int &&x, y; }; Z z 
> > = { x{1,2}[0], z.x=10 };`
> The AST for that test case:
> ```
> `-VarDecl 0x55809e1c6110  col:47 used z 'Z':'Z' cinit
>   `-ExprWithCleanups 0x55809e1c6658  'Z':'Z'
> `-InitListExpr 0x55809e1c64c8  'Z':'Z'
>   |-ArraySubscriptExpr 0x55809e1c63b8  'int' xvalue
>   | |-ImplicitCastExpr 0x55809e1c63a0  'int *' 
> 
>   | | `-MaterializeTemporaryExpr 0x55809e1c6388  
> 'x':'int[2]' xvalue extended by Var 0x55809e1c6110 'z' 'Z':'Z'
>   | |   `-CXXFunctionalCastExpr 0x55809e1c6310  
> 'x':'int[2]' functional cast to x 
>   | | `-InitListExpr 0x55809e1c62c0  'x':'int[2]'
>   | |   |-IntegerLiteral 0x55809e1c6230  'int' 1
>   | |   `-IntegerLiteral 0x55809e1c6250  'int' 2
>   | `-IntegerLiteral 0x55809e1c6338  'int' 0
>   `-ImplicitCastExpr 0x55809e1c6560  'int' 
> 
> `-BinaryOperator 0x55809e1c6448  'int' lvalue '='
>   |-MemberExpr 0x55809e1c63f8  'int' lvalue .x 
> 0x55809e1c5fe0
>   | `-DeclRefExpr 0x55809e1c63d8  'Z':'Z' lvalue Var 
> 0x55809e1c6110 'z' 'Z':'Z'
>   `-IntegerLiteral 0x55809e1c6428  'int' 10
> ```
> my code at this revision `Diff 529732` (without recursive visitation) 
> produces:
> ```
> @_ZGR1z_ = internal global [2 x i32] [i32 1, i32 2], align 4
> @z = dso_local global { ptr, i32 } { ptr @_ZGR1z_, i32 10 }, align 8
> ```
> so yeah, it looks wrong and differs from the slow path (or behavior before 
> this patch).  I'm tempted to add an expensive check to calculate both the 
> slow and fast path and fail when they differ, though the subtle test changes 
> here show there are slight differences already.
> 
> So I guess we will need something like `HasAnyMaterializeTemporaryExpr` from 
> previous revisions of this patch.  One thing I don't like about that 
> approach; IIRC if I accidentally omit methods of the Visitor, I think it 
> produces the wrong answers.  Is there a better way to design such a visitor?  
> I'm assuming that if you don't define the method, then the visitor stops 
> descending further into the AST. Is that correct?
Ideally, I think we fix LValueExprEvaluator::VisitMaterializeTemporaryExpr in 
ExprConstant so it only calls getOrCreateValue() and resets the value when 
we're actually evaluating the initializer of the corresponding variable.  If 
we're not, we should bail out or treat it as a temporary. But when I looked 
briefly, I couldn't figure out how to check that condition correctly.  If we do 
that, we don't need this workaround.

It's possible to, instead of using a visitor pattern, use a switch statement 
that lists out all the possible kinds of expressions. Some places do that, I 
think, but I'm not sure how much it helps in this context; even if all the 
possible expressions are listed out, that doesn't mean you managed to classify 
them correctly.

> though the subtle test changes here show there are slight differences already

That's probably fixable?  The tests only show two kinds of difference; there 
can't be that many more.  Not sure how much work it is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D144911: adding bf16 support to NVPTX

2023-06-09 Thread Kushan Ahmadian via Phabricator via cfe-commits
kushanam updated this revision to Diff 530123.
kushanam added a comment.

Adding new bf16 tests and refactoring the code with new conversion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144911

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
  llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
  llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/lib/Target/NVPTX/NVPTXMCExpr.cpp
  llvm/lib/Target/NVPTX/NVPTXMCExpr.h
  llvm/lib/Target/NVPTX/NVPTXSubtarget.cpp
  llvm/lib/Target/NVPTX/NVPTXSubtarget.h
  llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
  llvm/test/CodeGen/NVPTX/bf16-instructions.ll

Index: llvm/test/CodeGen/NVPTX/bf16-instructions.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/bf16-instructions.ll
@@ -0,0 +1,131 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | FileCheck %s
+; RUN: %if ptxas-11.0 %{ llc < %s -march=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | %ptxas-verify -arch=sm_80 %}
+
+; LDST: .b8 bfloat_array[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+@"bfloat_array" = addrspace(1) constant [4 x bfloat]
+[bfloat 0xR0201, bfloat 0xR0403, bfloat 0xR0605, bfloat 0xR0807]
+  
+; CHECK-LABEL: test_fadd(
+; CHECK-DAG:  ld.param.b16[[A:%h[0-9]+]], [test_fadd_param_0];
+; CHECK-DAG:  ld.param.b16[[B:%h[0-9]+]], [test_fadd_param_1];
+; CHECK-NEXT: add.rn.bf16 [[R:%f[0-9]+]], [[A]], [[B]];
+; CHECK-NEXT: st.param.b16[func_retval0+0], [[R]];
+; CHECK-NEXT: ret;
+
+define bfloat @test_fadd(bfloat %0, bfloat %1) {
+  %3 = fadd bfloat %0, %1
+  ret bfloat %3
+}
+
+; CHECK-LABEL: test_fsub(
+; CHECK-DAG:  ld.param.b16[[A:%h[0-9]+]], [test_fsub_param_0];
+; CHECK-DAG:  ld.param.b16[[B:%h[0-9]+]], [test_fsub_param_1];
+; CHECK-NEXT: sub.rn.bf16 [[R:%f[0-9]+]], [[A]], [[B]];
+; CHECK-NEXT: st.param.b16[func_retval0+0], [[R]];
+; CHECK-NEXT: ret;
+
+define bfloat @test_fsub(bfloat %0, bfloat %1) {
+  %3 = fsub bfloat %0, %1
+  ret bfloat %3
+}
+
+; CHECK-LABEL: test_faddx2(
+; CHECK-DAG:  ld.param.b32[[A:%hh[0-9]+]], [test_faddx2_param_0];
+; CHECK-DAG:  ld.param.b32[[B:%hh[0-9]+]], [test_faddx2_param_1];
+; CHECK-NEXT: add.rn.bf16x2   [[R:%f[0-9]+]], [[A]], [[B]];
+
+; CHECK:  st.param.b32[func_retval0+0], [[R]];
+; CHECK:  ret;
+
+define <2 x bfloat> @test_faddx2(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
+  %r = fadd <2 x bfloat> %a, %b
+  ret <2 x bfloat> %r
+}
+
+; CHECK-LABEL: test_fsubx2(
+; CHECK-DAG:  ld.param.b32[[A:%hh[0-9]+]], [test_fsubx2_param_0];
+; CHECK-DAG:  ld.param.b32[[B:%hh[0-9]+]], [test_fsubx2_param_1];
+; CHECK-NEXT: sub.rn.bf16x2   [[R:%f[0-9]+]], [[A]], [[B]];
+
+; CHECK:  st.param.b32[func_retval0+0], [[R]];
+; CHECK:  ret;
+
+define <2 x bfloat> @test_fsubx2(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
+  %r = fsub <2 x bfloat> %a, %b
+  ret <2 x bfloat> %r
+}
+
+; CHECK-LABEL: test_fmulx2(
+; CHECK-DAG:  ld.param.b32[[A:%hh[0-9]+]], [test_fmulx2_param_0];
+; CHECK-DAG:  ld.param.b32[[B:%hh[0-9]+]], [test_fmulx2_param_1];
+; CHECK-NEXT: mul.rn.bf16x2   [[R:%f[0-9]+]], [[A]], [[B]];
+
+; CHECK:  st.param.b32[func_retval0+0], [[R]];
+; CHECK:  ret;
+
+define <2 x bfloat> @test_fmul(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
+  %r = fmul <2 x bfloat> %a, %b
+  ret <2 x bfloat> %r
+}
+
+; CHECK-LABEL: test_fdiv(
+; CHECK-DAG:  ld.param.b32[[A:%hh[0-9]+]], [test_fdiv_param_0];
+; CHECK-DAG:  ld.param.b32[[B:%hh[0-9]+]], [test_fdiv_param_1];
+; CHECK-DAG:  mov.b32 {[[A0:%h[0-9]+]], [[A1:%h[0-9]+]]}, [[A]]
+; CHECK-DAG:  mov.b32 {[[B0:%h[0-9]+]], [[B1:%h[0-9]+]]}, [[B]]
+; CHECK-DAG:  cvt.f32.bf16 [[FA0:%f[0-9]+]], [[A0]];
+; CHECK-DAG:  cvt.f32.bf16 [[FA1:%f[0-9]+]], [[A1]];
+; CHECK-DAG:  cvt.f32.bf16 [[FB0:%f[0-9]+]], [[B0]];
+; CHECK-DAG:  cvt.f32.bf16 [[FB1:%f[0-9]+]], [[B1]];
+; CHECK-DAG:  div.rn.f32  [[FR0:%f[0-9]+]], [[FA0]], [[FB0]];
+; CHECK-DAG:  div.rn.f32  [[FR1:%f[0-9]+]], [[FA1]], [[FB1]];
+; CHECK-DAG:  cvt.rn.bf16.f32  [[R0:%h[0-9]+]], [[FR0]];
+; CHECK-DAG:  cvt.rn.bf16.f32  [[R1:%h[0-9]+]], [[FR1]];
+; CHECK-NEXT: mov.b32 [[R:%hh[0-9]+]], {[[R0]], [[R1]]}
+; CHECK-NEXT: st.param.b32[func_retval0+0], [[R]];
+; CHECK-NEXT: ret;
+
+define <2 x bfloat> @test_fdiv(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
+  %r = fdiv <2 x bfloat> %a, %b
+  ret <2 x bfloat> %r
+}
+
+; CHECK-LABEL: test_extract_0(
+; CHECK:  ld.param.b16[[A:%rs[0-9]+]], [test_extract_0_param_0];
+; CHECK:  st.param.b16[func_retval0+0], [[A]];
+; CHECK:  ret;
+
+define bfloat @test_extract_0(<2 x bfloat> %a) #0 {
+  %e = extra

[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-06-09 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/include/clang/AST/DeclBase.h:1686
 
-/// [C++17] Only used by CXXDeductionGuideDecl. Indicates that
-/// the Deduction Guide is the implicitly generated 'copy
-/// deduction candidate' (is used during overload resolution).
-uint64_t IsCopyDeductionCandidate : 1;
+/// Only used by CXXDeductionGuideDecl. Indicates the kind
+/// of the Deduction Guide that is the implicitly generated

Why remove `[C++17]` ?



Comment at: clang/include/clang/AST/DeclCXX.h:1987
+  void setDeductionCandidateKind(DeductionCandidateKind K) {
+FunctionDeclBits.DeductionCandidateKind = static_cast(K);
   }

aaron.ballman wrote:
> Er, seems a bit odd to cast an 8-bit type to a 64-bit type only to shove it 
> into a 2-bit bit-field. I think `DeductionCandidateKind` should be an enum 
> class whose underlying type is `int` and we cast to/from `int` as needed.
It feels a bit weird that we are taking an enum w/ an underlying type of 
`unsigned char` casting it to `int` and then placing it in an unsigned 
bit-field. I don't have a better suggestion ATM but I wish we had something 
better. 



Comment at: clang/lib/Sema/SemaDecl.cpp:12647
 // FIXME: Initialization should not be taking a mutable list of inits.
-SmallVector InitsCopy(DeduceInits.begin(), DeduceInits.end());
+SmallVector InitsCopy(DeduceInits.begin(), DeduceInits.end());
 return DeduceTemplateSpecializationFromInitializer(TSI, Entity, Kind,

nitpick but we seem to use `Expr*` everywhere else.



Comment at: clang/lib/Sema/SemaInit.cpp:15
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"

I saw your adding headers. How did you figure out which ones were missing?



Comment at: clang/lib/Sema/SemaInit.cpp:513
+  SmallVectorImpl &AggrDeductionCandidateParamTypes)
+  : InitListChecker(S, Entity, IL, T, true, false, false,
+&AggrDeductionCandidateParamTypes){};

nit



Comment at: clang/lib/Sema/SemaInit.cpp:10680
+   /*PartialOverloading=*/false, AllowExplicit,
+   ADLCallKind::NotADL, {}, true);
+} else {

nit,

note: PO` is not a very descriptive name.



Comment at: clang/lib/Sema/SemaInit.cpp:10736
+addDeductionCandidate(TD, GD, DeclAccessPair::make(TD, AS_public),
+  OnlyListConstructors, true);
+  }





Comment at: clang/lib/Sema/SemaInit.cpp:10743
+  addDeductionCandidate(TD, GD, DeclAccessPair::make(TD, AS_public),
+OnlyListConstructors, true);
+}





Comment at: clang/lib/Sema/SemaInit.cpp:10763
 
-  // C++ [over.match.ctor]p1: (non-list copy-initialization from non-class)
-  //   For copy-initialization, the candidate functions are all the
-  //   converting constructors (12.3.1) of that class.
-  // C++ [over.match.copy]p1: (non-list copy-initialization from class)
-  //   The converting constructors of T are candidate functions.
-  if (!AllowExplicit) {
-// Overload resolution checks whether the deduction guide is declared
-// explicit for us.
-
-// When looking for a converting constructor, deduction guides that
-// could never be called with one argument are not interesting to
-// check or note.
-if (GD->getMinRequiredArguments() > 1 ||
-(GD->getNumParams() == 0 && !GD->isVariadic()))
-  continue;
+  addDeductionCandidate(TD, GD, I.getPair(), OnlyListConstructors, false);
+}

> Quoted Text




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D151523: [ASTStructuralEquivalence] Fix crash when ObjCCategoryDecl doesn't have corresponding ObjCInterfaceDecl.

2023-06-09 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

If anybody has further comments about the condition style, I'm happy to change 
the code post-commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151523

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


[PATCH] D151523: [ASTStructuralEquivalence] Fix crash when ObjCCategoryDecl doesn't have corresponding ObjCInterfaceDecl.

2023-06-09 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e16df352c7a: [ASTStructuralEquivalence] Fix crash when 
ObjCCategoryDecl doesn't have… (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151523

Files:
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp


Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1143,6 +1143,18 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceObjCCategoryTest, CategoriesWithoutInterfaces) {
+  auto t = makeDecls("  @interface A(X) 
@end",
+   "@interface A @end @interface A(X) 
@end",
+   Lang_OBJC, objcCategoryDecl());
+  EXPECT_FALSE(testStructuralMatch(t));
+
+  auto t2 = makeDecls("@interface A(X) @end",
+"@interface A(X) @end",
+Lang_OBJC, objcCategoryDecl());
+  EXPECT_TRUE(testStructuralMatch(t2));
+}
+
 TEST_F(StructuralEquivalenceObjCCategoryTest, CategoryAndExtension) {
   auto t = makeDecls("@interface A @end @interface A(X) 
@end",
"@interface A @end @interface A() @end",
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2057,8 +2057,13 @@
   if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
 return false;
 
-  if (!IsStructurallyEquivalent(D1->getClassInterface()->getIdentifier(),
-D2->getClassInterface()->getIdentifier()))
+  const ObjCInterfaceDecl *Intf1 = D1->getClassInterface(),
+  *Intf2 = D2->getClassInterface();
+  if ((!Intf1 || !Intf2) && (Intf1 != Intf2))
+return false;
+
+  if (Intf1 &&
+  !IsStructurallyEquivalent(Intf1->getIdentifier(), 
Intf2->getIdentifier()))
 return false;
 
   // Compare protocols.
@@ -2077,7 +2082,8 @@
 return false;
 
   // Compare ivars.
-  QualType D2Type = 
Context.ToCtx.getObjCInterfaceType(D2->getClassInterface());
+  QualType D2Type =
+  Intf2 ? Context.ToCtx.getObjCInterfaceType(Intf2) : QualType();
   ObjCCategoryDecl::ivar_iterator Ivar2 = D2->ivar_begin(),
   Ivar2End = D2->ivar_end();
   for (ObjCCategoryDecl::ivar_iterator Ivar1 = D1->ivar_begin(),


Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1143,6 +1143,18 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceObjCCategoryTest, CategoriesWithoutInterfaces) {
+  auto t = makeDecls("  @interface A(X) @end",
+   "@interface A @end @interface A(X) @end",
+   Lang_OBJC, objcCategoryDecl());
+  EXPECT_FALSE(testStructuralMatch(t));
+
+  auto t2 = makeDecls("@interface A(X) @end",
+"@interface A(X) @end",
+Lang_OBJC, objcCategoryDecl());
+  EXPECT_TRUE(testStructuralMatch(t2));
+}
+
 TEST_F(StructuralEquivalenceObjCCategoryTest, CategoryAndExtension) {
   auto t = makeDecls("@interface A @end @interface A(X) @end",
"@interface A @end @interface A() @end",
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2057,8 +2057,13 @@
   if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
 return false;
 
-  if (!IsStructurallyEquivalent(D1->getClassInterface()->getIdentifier(),
-D2->getClassInterface()->getIdentifier()))
+  const ObjCInterfaceDecl *Intf1 = D1->getClassInterface(),
+  *Intf2 = D2->getClassInterface();
+  if ((!Intf1 || !Intf2) && (Intf1 != Intf2))
+return false;
+
+  if (Intf1 &&
+  !IsStructurallyEquivalent(Intf1->getIdentifier(), Intf2->getIdentifier()))
 return false;
 
   // Compare protocols.
@@ -2077,7 +2082,8 @@
 return false;
 
   // Compare ivars.
-  QualType D2Type = Context.ToCtx.getObjCInterfaceType(D2->getClassInterface());
+  QualType D2Type =
+  Intf2 ? Context.ToCtx.getObjCInterfaceType(Intf2) : QualType();
   ObjCCat

[clang] 2e16df3 - [ASTStructuralEquivalence] Fix crash when ObjCCategoryDecl doesn't have corresponding ObjCInterfaceDecl.

2023-06-09 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2023-06-09T17:09:28-07:00
New Revision: 2e16df352c7acb910313c80ac90b650ad9c14a3d

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

LOG: [ASTStructuralEquivalence] Fix crash when ObjCCategoryDecl doesn't have 
corresponding ObjCInterfaceDecl.

When this happens, it is invalid code and there is diagnostic
```
error: cannot find interface declaration for '...'
```

But clang shouldn't crash even if code is invalid. Though subsequent
diagnostic can be imperfect because without ObjCInterfaceDecl we don't have
a type for error messages.

rdar://108818430

Differential Revision: https://reviews.llvm.org/D151523

Added: 


Modified: 
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index a9470782c634e..f867b6bf84beb 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2057,8 +2057,13 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
 return false;
 
-  if (!IsStructurallyEquivalent(D1->getClassInterface()->getIdentifier(),
-D2->getClassInterface()->getIdentifier()))
+  const ObjCInterfaceDecl *Intf1 = D1->getClassInterface(),
+  *Intf2 = D2->getClassInterface();
+  if ((!Intf1 || !Intf2) && (Intf1 != Intf2))
+return false;
+
+  if (Intf1 &&
+  !IsStructurallyEquivalent(Intf1->getIdentifier(), 
Intf2->getIdentifier()))
 return false;
 
   // Compare protocols.
@@ -2077,7 +2082,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 return false;
 
   // Compare ivars.
-  QualType D2Type = 
Context.ToCtx.getObjCInterfaceType(D2->getClassInterface());
+  QualType D2Type =
+  Intf2 ? Context.ToCtx.getObjCInterfaceType(Intf2) : QualType();
   ObjCCategoryDecl::ivar_iterator Ivar2 = D2->ivar_begin(),
   Ivar2End = D2->ivar_end();
   for (ObjCCategoryDecl::ivar_iterator Ivar1 = D1->ivar_begin(),

diff  --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 8efb9a905c2f1..319eefe1e6ba3 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1143,6 +1143,18 @@ TEST_F(StructuralEquivalenceObjCCategoryTest, 
CategoriesWithDifferentNames) {
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceObjCCategoryTest, CategoriesWithoutInterfaces) {
+  auto t = makeDecls("  @interface A(X) 
@end",
+   "@interface A @end @interface A(X) 
@end",
+   Lang_OBJC, objcCategoryDecl());
+  EXPECT_FALSE(testStructuralMatch(t));
+
+  auto t2 = makeDecls("@interface A(X) @end",
+"@interface A(X) @end",
+Lang_OBJC, objcCategoryDecl());
+  EXPECT_TRUE(testStructuralMatch(t2));
+}
+
 TEST_F(StructuralEquivalenceObjCCategoryTest, CategoryAndExtension) {
   auto t = makeDecls("@interface A @end @interface A(X) 
@end",
"@interface A @end @interface A() @end",



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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth marked an inline comment as done.
paulkirth added a comment.

In D152473#4410331 , @MyDeveloperDay 
wrote:

> My additional concern is, is the original patch is the root cause of the 
> regression?, so I’m struggling to understand why this in particular is being 
> reverted or are we just going backwards through all commits?

I'm not sure I follow, can you elaborate on what you mean here?  Reverting only 
4b9764959dc4b8783e18747c1742ab164e4bc4ee 
 will 
allow the new test added here to pass, but tests added in 
d2627cf88d2553a4c2e850430bdb908a4b7d2e52 
 will 
fail, since they require the behavior added in 
4b9764959dc4b8783e18747c1742ab164e4bc4ee 
.  
Reverting them both is required to keep tests passing.




Comment at: clang/test/Format/overlapping-lines.cpp:1
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | 
FileCheck %s 
+// CHECK-NOT: The new replacement overlaps with an existing replacement.

MyDeveloperDay wrote:
> please remove this.
removed in https://reviews.llvm.org/rGa28a46665529992cefb78049da79f2125f6b6c2d


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[clang] 10e8300 - [-Wunsafe-buffer-usage] Remove the unnecessary `const` qualifier in safe buffer analysis

2023-06-09 Thread via cfe-commits

Author: ziqingluo-90
Date: 2023-06-09T16:41:49-07:00
New Revision: 10e83005367c595821749896e5938ff4f374601b

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

LOG: [-Wunsafe-buffer-usage] Remove the unnecessary `const` qualifier in safe 
buffer analysis

Casting away the qualifier raises a warning in 
1e270be0886c3a770e7a967679552a02dfc1dca9

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2133cbaa9be8d..999b94a070368 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1563,7 +1563,7 @@ std::optional 
UPCPreIncrementGadget::getFixits(const Strategy &S) con
 //   `Init` a pointer to the initializer expression
 //   `Ctx` a reference to the ASTContext
 static FixItList
-populateInitializerFixItWithSpan(const Expr *Init, const ASTContext &Ctx,
+populateInitializerFixItWithSpan(const Expr *Init, ASTContext &Ctx,
  const StringRef UserFillPlaceHolder) {
   const SourceManager &SM = Ctx.getSourceManager();
   const LangOptions &LangOpts = Ctx.getLangOpts();
@@ -1572,8 +1572,7 @@ populateInitializerFixItWithSpan(const Expr *Init, const 
ASTContext &Ctx,
   // NULL pointer, we use the default constructor to initialize the span
   // object, i.e., a `std:span` variable declaration with no initializer.
   // So the fix-it is just to remove the initializer.
-  if (Init->isNullPointerConstant(
-  std::remove_const_t(Ctx),
+  if (Init->isNullPointerConstant(Ctx,
   // FIXME: Why does this function not ask for `const ASTContext
   // &`? It should. Maybe worth an NFC patch later.
   Expr::NullPointerConstantValueDependence::
@@ -1654,7 +1653,7 @@ populateInitializerFixItWithSpan(const Expr *Init, const 
ASTContext &Ctx,
 //   `Ctx` a reference to the ASTContext
 // Returns:
 //the generated fix-it
-static FixItList fixVarDeclWithSpan(const VarDecl *D, const ASTContext &Ctx,
+static FixItList fixVarDeclWithSpan(const VarDecl *D, ASTContext &Ctx,
 const StringRef UserFillPlaceHolder) {
   const QualType &SpanEltT = D->getType()->getPointeeType();
   assert(!SpanEltT.isNull() && "Trying to fix a non-pointer type variable!");
@@ -1940,7 +1939,7 @@ static FixItList fixParamWithSpan(const ParmVarDecl *PVD, 
const ASTContext &Ctx,
 
 static FixItList fixVariableWithSpan(const VarDecl *VD,
  const DeclUseTracker &Tracker,
- const ASTContext &Ctx,
+ ASTContext &Ctx,
  UnsafeBufferUsageHandler &Handler) {
   const DeclStmt *DS = Tracker.lookupDecl(VD);
   assert(DS && "Fixing non-local variables not implemented yet!");
@@ -1962,7 +1961,7 @@ static FixItList fixVariableWithSpan(const VarDecl *VD,
 static FixItList
 fixVariable(const VarDecl *VD, Strategy::Kind K,
 /* The function decl under analysis */ const Decl *D,
-const DeclUseTracker &Tracker, const ASTContext &Ctx,
+const DeclUseTracker &Tracker, ASTContext &Ctx,
 UnsafeBufferUsageHandler &Handler) {
   if (const auto *PVD = dyn_cast(VD)) {
 auto *FD = dyn_cast(PVD->getDeclContext());
@@ -2035,7 +2034,7 @@ static bool impossibleToFixForVar(const FixableGadgetSets 
&FixablesForUnsafeVars
 
 static std::map
 getFixIts(FixableGadgetSets &FixablesForUnsafeVars, const Strategy &S,
- const ASTContext &Ctx,
+ ASTContext &Ctx,
   /* The function decl under analysis */ const Decl *D,
 const DeclUseTracker &Tracker, UnsafeBufferUsageHandler &Handler,
  const DefMapTy &VarGrpMap) {



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


[PATCH] D152584: [clang-format] Remove redundant test case

2023-06-09 Thread Paul Kirth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa28a46665529: [clang-format] Remove redundant test case 
(authored by paulkirth).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152584

Files:
  clang/test/Format/overlapping-lines.cpp


Index: clang/test/Format/overlapping-lines.cpp
===
--- clang/test/Format/overlapping-lines.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | 
FileCheck %s 
-// CHECK-NOT: The new replacement overlaps with an existing replacement.
-
-#ifdef 
-
-
-#else 
-#endif 


Index: clang/test/Format/overlapping-lines.cpp
===
--- clang/test/Format/overlapping-lines.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | FileCheck %s 
-// CHECK-NOT: The new replacement overlaps with an existing replacement.
-
-#ifdef 
-
-
-#else 
-#endif 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a28a466 - [clang-format] Remove redundant test case

2023-06-09 Thread Paul Kirth via cfe-commits

Author: Paul Kirth
Date: 2023-06-09T23:41:32Z
New Revision: a28a46665529992cefb78049da79f2125f6b6c2d

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

LOG: [clang-format] Remove redundant test case

The test is now properly covered in unit tests, and shouldn't have been
added in the initial commit of D152473.

Reviewed By: owenpan

Differential Revision: https://reviews.llvm.org/D152584

Added: 


Modified: 


Removed: 
clang/test/Format/overlapping-lines.cpp



diff  --git a/clang/test/Format/overlapping-lines.cpp 
b/clang/test/Format/overlapping-lines.cpp
deleted file mode 100644
index 1a8b4785a506b..0
--- a/clang/test/Format/overlapping-lines.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | 
FileCheck %s 
-// CHECK-NOT: The new replacement overlaps with an existing replacement.
-
-#ifdef 
-
-
-#else 
-#endif 



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


[PATCH] D152589: Add readability test for not allowing relative includes

2023-06-09 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/AbsoluteIncludesOnlyCheck.cpp:16
+
+
+namespace clang::tidy::readability {

Excessive newline.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:187
+
+Finds relative includes in your code and warn about them. for example
+don't use "readability/absolute-includes-only", use 


Please make it as first statement in documentation.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst:8
+
+Meaning this check disallow the use of quote includes (""), and allow only 
angular brackets includes (<>).
+

Please highlight `""` and `<>` with double back-ticks. Please follow 
80-characters limit.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst:17
+
+  // #include "utility.hpp"   // Wrong.
+  // #include// Wrong.

Please split example on right and wrong blocks.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp:14
+
+
+#include 

Excessive newline.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp:18
+#include 
+

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152589

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-09 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 530110.
nickdesaulniers added a comment.

- move added test case CHECK lines closer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
@@ -76,6 +76,13 @@
   S *p = &s<1, 2, 3, 4>;
 }
 
+
+// CHECK: @_ZGR1z_ = internal global [2 x i32] [i32 10, i32 2], align 4
+// CHECK: @z = global { ptr, i32 } { ptr @_ZGR1z_, i32 10 }, align 8
+typedef int v[2];
+struct Z { int &&x, y; };
+Z z = { v{1,2}[0], z.x = 10 };
+
 // CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev, {{.*}} @b
 
 // CHECK: define
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -910,6 +910,25 @@
   .Build(Updater, /*AllowOverwrite*/ true);
 }
 
+class HasAnyMaterializeTemporaryExpr :
+  public ConstStmtVisitor {
+public:
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr *A) {
+return Visit(A->getBase()) || Visit(A->getIdx());
+  }
+  bool VisitCastExpr(const CastExpr *C) {
+return Visit(C->getSubExpr());
+  }
+  bool VisitInitListExpr(const InitListExpr *I) {
+return llvm::any_of(I->inits(), [this](const Expr *II) {
+  return Visit(II);
+});
+  }
+  bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *) {
+return true;
+  }
+};
+
 //===--===//
 // ConstExprEmitter
 //===--===//
@@ -1215,11 +1234,6 @@
 return Visit(E->getSubExpr(), T);
   }
 
-  llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(E->getSubExpr(), T);
-  }
-
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
@@ -1279,6 +1293,13 @@
 if (ILE->isTransparent())
   return Visit(ILE->getInit(0), T);
 
+// If we have any MaterializeTemporaryExpr's in the InitListExpr, bail so
+// that EmitArrayInitialization or EmitRecordInitialization don't corrupt
+// the generated object.
+HasAnyMaterializeTemporaryExpr H;
+if (H.Visit(ILE))
+  return nullptr;
+
 if (ILE->getType()->isArrayType())
   return EmitArrayInitialization(ILE, T);
 
@@ -1322,7 +1343,12 @@
   assert(CGM.getContext().hasSameUnqualifiedType(Ty, Arg->getType(

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-09 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 530109.
nickdesaulniers marked 2 inline comments as done.
nickdesaulniers added a comment.

- remove fixme, restore isReferenceType


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
@@ -64,6 +64,8 @@
 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi46_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi47_ }
 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4_ = linkonce_odr global %"struct.VariableTemplateWithPack::S" { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi40_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi42_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi44_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi46_ }
 // CHECK: @_ZN24VariableTemplateWithPack1pE ={{.*}} global {{.*}} @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4_
+// CHECK: @_ZGR1z_ = internal global [2 x i32] [i32 10, i32 2], align 4
+// CHECK: @z = global { ptr, i32 } { ptr @_ZGR1z_, i32 10 }, align 8
 namespace VariableTemplateWithPack {
   struct A {
 const int &r;
@@ -85,3 +87,7 @@
 // CHECK: store
 // CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
 // CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE
+
+typedef int v[2];
+struct Z { int &&x, y; };
+Z z = { v{1,2}[0], z.x = 10 };
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -910,6 +910,25 @@
   .Build(Updater, /*AllowOverwrite*/ true);
 }
 
+class HasAnyMaterializeTemporaryExpr :
+  public ConstStmtVisitor {
+public:
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr *A) {
+return Visit(A->getBase()) || Visit(A->getIdx());
+  }
+  bool VisitCastExpr(const CastExpr *C) {
+return Visit(C->getSubExpr());
+  }
+  bool VisitInitListExpr(const InitListExpr *I) {
+return llvm::any_of(I->inits(), [this](const Expr *II) {
+  return Visit(II);
+});
+  }
+  bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *) {
+return true;
+  }
+};
+
 //===--===//
 // ConstExprEmitter
 //===--===//
@@ -1215,11 +1234,6 @@
 return Visit(E->getSubExpr(), T);
   }
 
-  llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) 

[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

My additional concern is, is the original patch is the root cause of the 
regression?, so I’m struggling to understand why this in particular is being 
reverted or are we just going backwards through all commits?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-09 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 530107.
nickdesaulniers added a comment.

- resurrect HasAnyMaterializeTemporaryExpr, add @efriedma's test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
@@ -64,6 +64,8 @@
 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi46_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi47_ }
 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4_ = linkonce_odr global %"struct.VariableTemplateWithPack::S" { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi40_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi42_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi44_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi46_ }
 // CHECK: @_ZN24VariableTemplateWithPack1pE ={{.*}} global {{.*}} @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4_
+// CHECK: @_ZGR1z_ = internal global [2 x i32] [i32 10, i32 2], align 4
+// CHECK: @z = global { ptr, i32 } { ptr @_ZGR1z_, i32 10 }, align 8
 namespace VariableTemplateWithPack {
   struct A {
 const int &r;
@@ -85,3 +87,7 @@
 // CHECK: store
 // CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
 // CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE
+
+typedef int v[2];
+struct Z { int &&x, y; };
+Z z = { v{1,2}[0], z.x = 10 };
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -910,6 +910,25 @@
   .Build(Updater, /*AllowOverwrite*/ true);
 }
 
+class HasAnyMaterializeTemporaryExpr :
+  public ConstStmtVisitor {
+public:
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr *A) {
+return Visit(A->getBase()) || Visit(A->getIdx());
+  }
+  bool VisitCastExpr(const CastExpr *C) {
+return Visit(C->getSubExpr());
+  }
+  bool VisitInitListExpr(const InitListExpr *I) {
+return llvm::any_of(I->inits(), [this](const Expr *II) {
+  return Visit(II);
+});
+  }
+  bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *) {
+return true;
+  }
+};
+
 //===--===//
 // ConstExprEmitter
 //===--===//
@@ -1215,11 +1234,6 @@
 return Visit(E->getSubExpr(), T);
   }
 
-  llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(

[PATCH] D143048: [-Wunsafe-buffer-usage] Add T* -> span Fix-Its for function parameters

2023-06-09 Thread Ziqing Luo via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e270be0886c: [-Wunsafe-buffer-usage] Add fix-its for 
function parameters using the `span`… (authored by ziqingluo-90).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D143048?vs=528028&id=530106#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143048

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-main.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-overload.cpp
  
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-qualified-names.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -36,7 +36,7 @@
 void * voidPtrCall(void);
 char * charPtrCall(void);
 
-void testArraySubscripts(int *p, int **pp) {
+void testArraySubscripts(int *p, int **pp) { // expected-note{{change type of 'pp' to 'std::span' to preserve bounds information}}
 // expected-warning@-1{{'p' is an unsafe pointer used for buffer access}}
 // expected-warning@-2{{'pp' is an unsafe pointer used for buffer access}}
   foo(p[1], // expected-note{{used in buffer access here}}
@@ -104,6 +104,12 @@
   foo(ap4[1]);// expected-note{{used in buffer access here}}
 }
 
+void testUnevaluatedContext(int * p) {// no-warning
+  foo(sizeof(p[1]), // no-warning
+  sizeof(decltype(p[1])));  // no-warning
+}
+
+// expected-note@+1{{change type of 'a' to 'std::span' to preserve bounds information}}
 void testQualifiedParameters(const int * p, const int * const q, const int a[10], const int b[10][10]) {
   // expected-warning@-1{{'p' is an unsafe pointer used for buffer access}}
   // expected-warning@-2{{'q' is an unsafe pointer used for buffer access}}
@@ -319,7 +325,7 @@
 
 template void fArr(int t[]); // FIXME: expected note {{in instantiation of}}
 
-int testReturn(int t[]) {
+int testReturn(int t[]) {// expected-note{{change type of 't' to 'std::span' to preserve bounds information}}
   // expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
   return t[1]; // expected-note{{used in buffer access here}}
 }
Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp
@@ -0,0 +1,131 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage -fcxx-exceptions -fsafe-buffer-usage-suggestions -verify %s
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fcxx-exceptions -fdiagnostics-parseable-fixits -fsafe-buffer-usage-suggestions %s 2>&1 | FileCheck %s
+
+void const_ptr(int * const x) { // expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
+  // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:16-[[@LINE-1]]:29}:"std::span const x"
+  int tmp = x[5]; // expected-note{{used in buffer access here}}
+}
+// CHECK-DAG: fix-it:{{.*}}:{[[@LINE-1]]:2-[[@LINE-1]]:2}:"\n{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}}\nvoid const_ptr(int * const x) {return const_ptr(std::span(x, <# size #>));}\n"
+
+void const_ptr_to_const(const int * const x) {// expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
+  // CHECK-DAG: fix-it:{{.*}}:{[[@LINE-1]]:25-[[@LINE-1]]:44}:"std::span const x"
+  int tmp = x[5]; // expected-note{{used in buffer access here}}
+}
+// CHECK-DAG: fix-it:{{.*}}:{[[@LINE-1]]:2-[[@LINE-1]]:2}:"\n{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}}\nvoid const_ptr_to_const(const int * const x) {return const_ptr_to_const(std::span(x, <# size #>));}\n"
+
+typedef struct {int x;} NAMED_UNNAMED_STRUCT; // an unnamed struct type named by a typedef
+typedef struct {int x;} * PTR_TO_ANON;// pointer to an unnamed struct
+typedef NAMED_UNNAMED_STRUCT * PTR_TO_NAMED;  // pointer to a named type
+
+// We can fix a pointer to a named type
+void namedPointeeType(NAMED_UNNAMED_STRUCT * p) {  // expected-warning{{'p' is an unsafe pointer used for buffer access}}\ expected-note{{change type of 'p' to 'std::span' to preserve bounds information}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:23-[[@LINE-1]]:47}:"std::span p"
+  if (++p) {  // expected-note{{used in pointer arithmetic here}}
+// CHECK:

[clang] 1e270be - [-Wunsafe-buffer-usage] Add fix-its for function parameters using the `span` strategy

2023-06-09 Thread via cfe-commits

Author: ziqingluo-90
Date: 2023-06-09T15:44:38-07:00
New Revision: 1e270be0886c3a770e7a967679552a02dfc1dca9

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

LOG: [-Wunsafe-buffer-usage] Add fix-its for function parameters using the 
`span` strategy

Generate fix-its for function parameters that are raw pointers used
unsafely.  Currently, the analyzer fixes one parameter at a time.

Fix-its for a function parameter includes:

- Fix the parameter declaration of the definition, result in a new
  overload of the function. We call the function with the original
  signature the old overload.
- For any other existing declaration of the old overload, mark it with
  the [[unsafe_buffer_usage]] attribute and generate a new overload
  declaration next to it.
- Creates a new definition for the old overload, which is simply
  defined by a call to the new overload.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru), and
 jkorous (Jan Korous)

Differential revision: https://reviews.llvm.org/D143048

Added: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-main.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-overload.cpp

clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-qualified-names.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp

Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index c9cc4ccbfb5d5..2133cbaa9be8d 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1224,6 +1224,12 @@ UPCAddressofArraySubscriptGadget::getFixits(const 
Strategy &S) const {
   return std::nullopt; // something went wrong, no fix-it
 }
 
+// FIXME: this function should be customizable through format
+static StringRef getEndOfLine() {
+  static const char *const EOL = "\n";
+  return EOL;
+}
+
 // Return the text representation of the given `APInt Val`:
 static std::string getAPIntText(APInt Val) {
   SmallVector Txt;
@@ -1275,6 +1281,83 @@ static std::optional getExprText(const Expr 
*E,
   return std::nullopt;
 }
 
+// Returns the literal text in `SourceRange SR`, if `SR` is a valid range.
+static std::optional getRangeText(SourceRange SR,
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+  bool Invalid = false;
+  CharSourceRange CSR = CharSourceRange::getCharRange(SR.getBegin(), 
SR.getEnd());
+  StringRef Text = Lexer::getSourceText(CSR, SM, LangOpts, &Invalid);
+
+  if (!Invalid)
+return Text;
+  return std::nullopt;
+}
+
+// Returns the text of the pointee type of `T` from a `VarDecl` of a pointer
+// type. The text is obtained through from `TypeLoc`s.  Since `TypeLoc` does 
not
+// have source ranges of qualifiers ( The `QualifiedTypeLoc` looks hacky too me
+// :( ), `Qualifiers` of the pointee type is returned separately through the
+// output parameter `QualifiersToAppend`.
+static std::optional
+getPointeeTypeText(const ParmVarDecl *VD, const SourceManager &SM,
+   const LangOptions &LangOpts,
+   std::optional *QualifiersToAppend) {
+  QualType Ty = VD->getType();
+  QualType PteTy;
+
+  assert(Ty->isPointerType() && !Ty->isFunctionPointerType() &&
+ "Expecting a VarDecl of type of pointer to object type");
+  PteTy = Ty->getPointeeType();
+  if (PteTy->hasUnnamedOrLocalType())
+// If the pointee type is unnamed, we can't refer to it
+return std::nullopt;
+
+  TypeLoc TyLoc = VD->getTypeSourceInfo()->getTypeLoc();
+  TypeLoc PteTyLoc = TyLoc.getUnqualifiedLoc().getNextTypeLoc();
+  SourceLocation VDNameStartLoc = VD->getLocation();
+
+  if (!SM.isBeforeInTranslationUnit(PteTyLoc.getSourceRange().getEnd(),
+VDNameStartLoc)) {
+// We only deal with the cases where the source text of the pointee type
+// appears on the left-hand side of the variable identifier completely,
+// including the following forms:
+// `T ident`,
+// `T ident[]`, where `T` is any type.
+// Examples of excluded cases are `T (*ident)[]` or `T ident[][n]`.
+return std::nullopt;
+  }
+  if (PteTy.hasQualifiers()) {
+// TypeLoc does not provide source ranges for qualifiers (it says it's
+// intentional but seems fishy to me), so we cannot get the full text
+// `PteTy` via source ranges.
+*QualifiersToAppend = PteTy.getQualifiers();
+  }
+
+  // Note that TypeLoc.getEndLoc() returns the begin location of the last 
token:
+

[PATCH] D152589: Add readability test for not allowing relative includes

2023-06-09 Thread Erez Amihud via Phabricator via cfe-commits
ErezAmihud updated this revision to Diff 530102.
ErezAmihud added a comment.

Remove a line in absolute-includes-only.cpp (fix formatting)


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

https://reviews.llvm.org/D152589

Files:
  clang-tools-extra/clang-tidy/readability/AbsoluteIncludesOnlyCheck.cpp
  clang-tools-extra/clang-tidy/readability/AbsoluteIncludesOnlyCheck.h
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp
@@ -0,0 +1,18 @@
+// RUN: %check_clang_tidy %s readability-absolute-includes-only %t -- -- -isystem %clang_tidy_headers -fmodules
+
+// clang-format off
+
+// CHECK-MESSAGES: [[@LINE+1]]:10: warning: relative include found, use only absolute includes
+#include "j.h"
+
+// CHECK-MESSAGES: [[@LINE+1]]:10: warning: relative include found, use only absolute includes
+#include "llvm/a.h"
+
+// CHECK-MESSAGES: [[@LINE+1]]:10: warning: relative include found, use only absolute includes
+#include "clang/../b.h"
+
+
+#include 
+
+#include 
+
Index: clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - readability-absolute-includes-only
+
+readability-absolute-includes-only
+==
+
+Finds relative includes inside of the code and warn about them.
+
+Meaning this check disallow the use of quote includes (""), and allow only angular brackets includes (<>).
+
+This is relevant for the canonical project structure specified in paper p1204r0.
+The relevant part is the src-dir where relative includes are discussed: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1204r0.html#src-dir
+
+Example (taken from the paper):
+
+.. code-block:: c++
+
+  // #include "utility.hpp"   // Wrong.
+  // #include// Wrong.
+  // #include "../hello/utility.hpp"  // Wrong.
+
+  #include 
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -337,6 +337,7 @@
`portability-restrict-system-includes `_, "Yes"
`portability-simd-intrinsics `_,
`portability-std-allocator-const `_,
+   `readability-absolute-includes-only `_,
`readability-avoid-const-params-in-decls `_, "Yes"
`readability-avoid-unconditional-preprocessor-if `_,
`readability-braces-around-statements `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -181,6 +181,12 @@
 
   Finds uses of ``std::endl`` on streams and replaces them with ``'\n'``.
 
+- New :doc:`readability-absolute-includes-only
+  ` check.
+
+Finds relative includes in your code and warn about them. for example
+don't use "readability/absolute-includes-only", use 
+
 - New :doc:`readability-avoid-unconditional-preprocessor-if
   ` check.
 
Index: clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AbsoluteIncludesOnlyCheck.h"
 #include "AvoidConstParamsInDecls.h"
 #include "AvoidUnconditionalPreprocessorIfCheck.h"
 #include "BracesAroundStatementsCheck.h"
@@ -60,6 +61,8 @@
 class ReadabilityModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"readability-absolute-includes-only");
 CheckFactories.registerCheck(
 "readability-avoid-const-params-in-decls");
 CheckFactories.registerCheck(
Index: clang-tools-extra/clang-tidy/readability/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -4,6 +4,7 @@
   )
 
 add_clang_library(clangTid

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-09 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1279
+  if (isa(E))
+return nullptr;
+

efriedma wrote:
> efriedma wrote:
> > This needs a comment explaining why we're bailing out here.
> We might need to do a recursive visit still, to handle the cases noted at 
> https://en.cppreference.com/w/cpp/language/reference_initialization#Lifetime_of_a_temporary
>  .  Not constructors, but other things.  I think we don't have existing 
> testcases, but for example `typedef int x[2]; struct Z { int &&x, y; }; Z z = 
> { x{1,2}[0], z.x=10 };`
The AST for that test case:
```
`-VarDecl 0x55809e1c6110  col:47 used z 'Z':'Z' cinit
  `-ExprWithCleanups 0x55809e1c6658  'Z':'Z'
`-InitListExpr 0x55809e1c64c8  'Z':'Z'
  |-ArraySubscriptExpr 0x55809e1c63b8  'int' xvalue
  | |-ImplicitCastExpr 0x55809e1c63a0  'int *' 

  | | `-MaterializeTemporaryExpr 0x55809e1c6388  
'x':'int[2]' xvalue extended by Var 0x55809e1c6110 'z' 'Z':'Z'
  | |   `-CXXFunctionalCastExpr 0x55809e1c6310  
'x':'int[2]' functional cast to x 
  | | `-InitListExpr 0x55809e1c62c0  'x':'int[2]'
  | |   |-IntegerLiteral 0x55809e1c6230  'int' 1
  | |   `-IntegerLiteral 0x55809e1c6250  'int' 2
  | `-IntegerLiteral 0x55809e1c6338  'int' 0
  `-ImplicitCastExpr 0x55809e1c6560  'int' 
`-BinaryOperator 0x55809e1c6448  'int' lvalue '='
  |-MemberExpr 0x55809e1c63f8  'int' lvalue .x 
0x55809e1c5fe0
  | `-DeclRefExpr 0x55809e1c63d8  'Z':'Z' lvalue Var 
0x55809e1c6110 'z' 'Z':'Z'
  `-IntegerLiteral 0x55809e1c6428  'int' 10
```
my code at this revision `Diff 529732` (without recursive visitation) produces:
```
@_ZGR1z_ = internal global [2 x i32] [i32 1, i32 2], align 4
@z = dso_local global { ptr, i32 } { ptr @_ZGR1z_, i32 10 }, align 8
```
so yeah, it looks wrong and differs from the slow path (or behavior before this 
patch).  I'm tempted to add an expensive check to calculate both the slow and 
fast path and fail when they differ, though the subtle test changes here show 
there are slight differences already.

So I guess we will need something like `HasAnyMaterializeTemporaryExpr` from 
previous revisions of this patch.  One thing I don't like about that approach; 
IIRC if I accidentally omit methods of the Visitor, I think it produces the 
wrong answers.  Is there a better way to design such a visitor?  I'm assuming 
that if you don't define the method, then the visitor stops descending further 
into the AST. Is that correct?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D152504: [clang][ThreadSafety] Analyze cleanup functions

2023-06-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I think this is the right solution and I'm happy to see it!

We have a few "direct" CFG tests in `test/Analysis/cfg.c` etc.; your patch 
doesn't seem to be specific to thread safety analysis so it's probably a good 
idea to add a few direct tests.




Comment at: clang/lib/Analysis/CFG.cpp:1945
+  auto DRE =
+  DeclRefExpr::Create(*Context, {}, {}, VD, false, SourceLocation(),
+  VD->getType(), VK_PRValue);

Is there a way to attach some valid source locations here, like the source 
location of the attribute's identifier argument?

I'm worried that the static analyzer may be unable to consume the CFG without 
them, it typically requires source locations for almost arbitrary statements. 
I'm still not sure how it'll react to synthetic statements, maybe turning them 
into a custom `CFGElement` subclass (like destructors) would be safer as it'll 
let all clients of the CFG to treat these in a custom manner. Otherwise it 
makes it look like a completely normal call-expression to the clients, which is 
not necessarily a good thing.



Comment at: clang/lib/Analysis/CFG.cpp:1951-1952
+
+  SmallVector Args;
+  Args.push_back(DRE);
+  auto A = CallExpr::Create(*Context, F, Args, FD->getType(), VK_PRValue,

Shouldn't there be a unary operator `&` here somewhere? In your example the 
variable is `int` but the function accepts `int *`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152504

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


[PATCH] D152589: Add readability test for not allowing relative includes

2023-06-09 Thread Erez Amihud via Phabricator via cfe-commits
ErezAmihud created this revision.
ErezAmihud added reviewers: clang-tools-extra, njames93.
ErezAmihud created this object with edit policy "Administrators".
ErezAmihud added a project: clang-tools-extra.
Herald added subscribers: PiotrZSL, carlosgalvezp.
Herald added a project: All.
ErezAmihud requested review of this revision.
Herald added a subscriber: cfe-commits.

Hi, it would be nice to add a check that warn if it finds a relative include. 
This is to allow people to easily conform to the canonical project structure - 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1204r0.html

The check issue a warning for every relative include (e.g. any include that 
uses regular quotes).

Github issue:
https://github.com/llvm/llvm-project/issues/63226


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152589

Files:
  clang-tools-extra/clang-tidy/readability/AbsoluteIncludesOnlyCheck.cpp
  clang-tools-extra/clang-tidy/readability/AbsoluteIncludesOnlyCheck.h
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/absolute-includes-only.cpp
@@ -0,0 +1,18 @@
+// RUN: %check_clang_tidy %s readability-absolute-includes-only %t -- -- -isystem %clang_tidy_headers -fmodules
+
+// clang-format off
+
+// CHECK-MESSAGES: [[@LINE+1]]:10: warning: relative include found, use only absolute includes
+#include "j.h"
+
+// CHECK-MESSAGES: [[@LINE+1]]:10: warning: relative include found, use only absolute includes
+#include "llvm/a.h"
+
+// CHECK-MESSAGES: [[@LINE+1]]:10: warning: relative include found, use only absolute includes
+#include "clang/../b.h"
+
+
+#include 
+
+#include 
+
Index: clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/absolute-includes-only.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - readability-absolute-includes-only
+
+readability-absolute-includes-only
+==
+
+Finds relative includes inside of the code and warn about them.
+
+Meaning this check disallow the use of quote includes (""), and allow only angular brackets includes (<>).
+
+This is relevant for the canonical project structure specified in paper p1204r0.
+The relevant part is the src-dir where relative includes are discussed: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1204r0.html#src-dir
+
+Example (taken from the paper):
+
+.. code-block:: c++
+
+  // #include "utility.hpp"   // Wrong.
+  // #include// Wrong.
+  // #include "../hello/utility.hpp"  // Wrong.
+
+  #include 
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -337,6 +337,7 @@
`portability-restrict-system-includes `_, "Yes"
`portability-simd-intrinsics `_,
`portability-std-allocator-const `_,
+   `readability-absolute-includes-only `_,
`readability-avoid-const-params-in-decls `_, "Yes"
`readability-avoid-unconditional-preprocessor-if `_,
`readability-braces-around-statements `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -181,6 +181,12 @@
 
   Finds uses of ``std::endl`` on streams and replaces them with ``'\n'``.
 
+- New :doc:`readability-absolute-includes-only
+  ` check.
+
+Finds relative includes in your code and warn about them. for example
+don't use "readability/absolute-includes-only", use 
+
 - New :doc:`readability-avoid-unconditional-preprocessor-if
   ` check.
 
Index: clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AbsoluteIncludesOnlyCheck.h"
 #include "AvoidConstParamsInDecls.h"
 #include "AvoidUnconditionalPreprocessorIfCheck.h"
 #include "BracesAroundStatementsCheck.h"
@@ -60,6 +61,8 @@
 class ReadabilityModule : public ClangTidyModul

[PATCH] D151683: [clang] Enable C++11-style attributes in all language modes

2023-06-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D151683#4409633 , @aaron.ballman 
wrote:

> In D151683#4384017 , @erichkeane 
> wrote:
>
>> In D151683#4382408 , @philnik 
>> wrote:
>>
>>> No. I guess, since you are asking I should write one for this? Only for the 
>>> removal of `-fdouble-square-bracket-attributes`, or also for back porting 
>>> this?
>>
>> The RFC I would expect for "allow C/C++ style attributes as an extension in 
>> previous modes".  This is a pretty significant feature to allow as an 
>> extension, particularly since our two main alternative compilers (G++/MSVC) 
>> don't have this as an extension. I'd be curious how the other C compilers do 
>> this as well.
>
> I think this does warrant an RFC because it impacts both C++ and C, but I'm 
> hoping the RFC is uncontroversial. It's mostly to establish what the use 
> cases are for needing the extension. The feature is conforming as an 
> extension to both languages, and I don't know of any breakage that would come 
> from enabling it by default. I'm not certain whether we want to remove the 
> feature flag immediately or whether we'd like to give one release of warning 
> about it being removed (I'll defer to whatever @MaskRay thinks is reasonable) 
> -- that search is compelling for why it's safe to remove the option, but 
> there's plenty of proprietary code which we don't know about, so it's 
> possible the option is still used. I'd be especially curious to know if 
> anyone is using `-fno-double-square-bracket-attributes` to disable the 
> feature in a mode where it would otherwise be enabled. I'm adding the 
> `clang-vendors` group as a subscriber as an early warning that removing the 
> command line option could be a potentially breaking change.
>
> In terms of implementation work, there's still some minor stuff to address. 
> Also, please be sure to also add a release note about the changes, and a 
> potentially breaking entry for removing the command line option (assuming we 
> elect to go that route).

If allowing the extension in older language modes deems good, removing 
`-fno-double-square-bracket-attributes` seems fine if (and thanks for CCing the 
`clang-vendors` group).
If we want to play safely, we can default `-fdouble-square-bracket-attributes` 
to true in this patch and remove the option in a follow-up change possibly 
after some time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151683

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


[PATCH] D149867: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-06-09 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu marked 3 inline comments as done.
myhsu added inline comments.



Comment at: clang/test/CodeGen/mrtd.c:4
 
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the 
stdcall calling convention
+// CHECK: mrtd.c:13:3: warning: function with no prototype cannot use the 
stdcall calling convention
 

jrtc27 wrote:
> Ew... this should be using -verify and `// expected-warning {{...}}`, then 
> the line number is relative to the comment's location. Or, really, it should 
> be in the Sema test...
> 
> Plus is it correct to call this stdcall on m68k? The GCC manpage only 
> mentions it in the x86 option description, not the m68k one.
Now this check is moved to `test/Sema/m68k-mrtd.c`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-06-09 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 530089.
myhsu retitled this revision from "[M68k] Add Clang support for the new 
M68k_RTD CC" to "[Clang][M68k] Add Clang support for the new M68k_RTD CC".
myhsu edited the summary of this revision.
myhsu set the repository for this revision to rG LLVM Github Monorepo.
myhsu added a comment.
Herald added a subscriber: arphaman.
Herald added a reviewer: aaron.ballman.

Use a new CC, `CC_M68kRTD`, to model `llvm::CallingConv::M68k_RTD` instead of 
using X86StdCall


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149867

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Specifiers.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/Sema/m68k-mrtd.c
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/Sema/m68k-mrtd.c
===
--- /dev/null
+++ clang/test/Sema/m68k-mrtd.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -DMRTD -mrtd -triple m68k-unknown-unknown -std=c89 -verify %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify %s
+
+#ifdef MRTD
+// expected-error@+3 {{function with no prototype cannot use the m68k_rtd calling convention}}
+#endif
+void foo(int arg) {
+  bar(arg);
+}
+
+#ifndef MRTD
+// expected-note@+5 {{previous declaration is here}}
+// expected-error@+5 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// expected-note@+5 {{previous declaration is here}}
+// expected-error@+5 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+#endif
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-warning@+2 {{m68k_rtd calling convention is not supported on variadic function}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+#ifdef MRTD
+// expected-note@+3 {{previous declaration is here}}
+// expected-error@+3 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+#endif
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+#ifndef MRTD
+// expected-note@+3 {{previous declaration is here}}
+// expected-error@+3 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+#endif
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-warning@+2 {{m68k_rtd calling convention is not supported on variadic function}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
Index: clang/test/CodeGen/mrtd.c
===
--- clang/test/CodeGen/mrtd.c
+++ clang/test/CodeGen/mrtd.c
@@ -1,20 +1,26 @@
-// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,X86 %s
+// RUN: %clang_cc1 -mrtd -triple m68k-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,M68k %s
 
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the stdcall calling convention
+// X86: mrtd.c:13:3: warning: function with no prototype cannot use the stdcall calling convention
 
 void baz(int arg);
 
-// CHECK: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} m68k_rtdcc void @foo(i32 noundef %arg)
 void foo(int arg) {
-// CHECK: call x86_stdcallcc i32 @bar(
+// X86: call x86_stdcallcc i32 @bar(
+#ifndef mc68000
 

[PATCH] D151761: clang-format: Add AlignConsecutiveShortCaseStatements

2023-06-09 Thread Galen Elias via Phabricator via cfe-commits
galenelias added a comment.

In D151761#4404179 , 
@HazardyKnusperkeks wrote:

> In D151761#4403828 , @galenelias 
> wrote:
>
>> In D151761#4400693 , 
>> @HazardyKnusperkeks wrote:
>>
>>> I'd say: align it.
>>
>> If it was straightforward, I would definitely agree to just align across 
>> empty case labels, but unfortunately there is no way to do that while using 
>> the generic AlignTokens (since the line with just a case has no token which 
>> matches the pattern, but needs to not break the alignment streak).  I guess 
>> the way to do it generically would be to add some sort of ExcludeLine lambda 
>> to allow filtering out lines.  Given that I don't think this is a common 
>> pattern with these 'Short Case Labels', and it's fairly easy to work around 
>> with `[[fallthrough]];` my plan is just to leave this as is (and add a test 
>> to make the behavior explicit).
>
> Leaving it open (and documenting that) I could get behind, but making it 
> explicit as desired behavior will not get my approval. On the other hand I 
> will not stand in the way, if the others approve.

Yah, I think leaving it open would be my preference at this point.  Not sure 
how to properly document that though?  Just be explicit in the tests?  Mention 
it in `alignConsecutiveShortCaseStatements`?  Should it be documented in the 
generated documentation (that feels a bit heavy)?


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

https://reviews.llvm.org/D151761

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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

I understand the concerns and I apologize if my LGTM came out as disrespectful, 
but there has been an issue  
reported with the original change over two days ago, including a reproducer, 
and given given that this issue is affecting `clang-format` users, I think it's 
entirely reasonable to go ahead and revert the change in accordance with the 
Patch reversion policy 
, and then 
take as much time as needed to address issue rather than trying to rush a fix 
forward. In fact, I'd argue that both 4b9764959dc4b8783e18747c1742ab164e4bc4ee 
 and 
d2627cf88d2553a4c2e850430bdb908a4b7d2e52 
 should 
have been reverted right away immediately after the issue was reported without 
any need for code review as is customary in LLVM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[PATCH] D16559: [CUDA] Add -fcuda-allow-variadic-functions.

2023-06-09 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D16559#4410067 , @garymm wrote:

> Could you please add this to the documentation?
> Could this be made the default? It seems like nvcc does this by default.

Clang already does that, though we only allow variadic functions that don't 
actually use the vararg arguments: https://reviews.llvm.org/D151359
It's sufficient to compile recent CUDA/libcu++ headers w/o errors.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D16559

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


[PATCH] D16559: [CUDA] Add -fcuda-allow-variadic-functions.

2023-06-09 Thread Gary Miguel via Phabricator via cfe-commits
garymm added a comment.
Herald added subscribers: mattd, carlosgalvezp, yaxunl.
Herald added a project: All.

Could you please add this to the documentation?
Could this be made the default? It seems like nvcc does this by default.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D16559

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


[PATCH] D144911: adding bf16 support to NVPTX

2023-06-09 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp:615
   // need to deal with.
   if (Vector.getSimpleValueType() != MVT::v2f16)
 return false;

This needs to be updated to include v2bf16


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144911

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


[PATCH] D152485: Fix regex in test case so that it doesn't match "coverage" in directory names

2023-06-09 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde3c01b06fe5: Fix regex in test case so that it doesn't 
match "coverage" in directory (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152485

Files:
  clang/test/Driver/cuda-no-pgo-or-coverage.cu


Index: clang/test/Driver/cuda-no-pgo-or-coverage.cu
===
--- clang/test/Driver/cuda-no-pgo-or-coverage.cu
+++ clang/test/Driver/cuda-no-pgo-or-coverage.cu
@@ -26,7 +26,7 @@
 // CHECK-NOT: error: unsupported option '-fprofile
 // CHECK-NOT: error: invalid argument
 // CHECK-DAG: "-fcuda-is-device"
-// CHECK-NOT: "-f{{[^"]*coverage.*}}"
+// CHECK-NOT: "-f{{[^"/]*coverage.*}}"
 // CHECK-NOT: "-fprofile{{[^"]*}}"
 // CHECK: "-triple" "x86_64-unknown-linux-gnu"
 // PROF:  "-fprofile{{.*}}"


Index: clang/test/Driver/cuda-no-pgo-or-coverage.cu
===
--- clang/test/Driver/cuda-no-pgo-or-coverage.cu
+++ clang/test/Driver/cuda-no-pgo-or-coverage.cu
@@ -26,7 +26,7 @@
 // CHECK-NOT: error: unsupported option '-fprofile
 // CHECK-NOT: error: invalid argument
 // CHECK-DAG: "-fcuda-is-device"
-// CHECK-NOT: "-f{{[^"]*coverage.*}}"
+// CHECK-NOT: "-f{{[^"/]*coverage.*}}"
 // CHECK-NOT: "-fprofile{{[^"]*}}"
 // CHECK: "-triple" "x86_64-unknown-linux-gnu"
 // PROF:  "-fprofile{{.*}}"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] de3c01b - Fix regex in test case so that it doesn't match "coverage" in directory

2023-06-09 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2023-06-09T14:20:17-07:00
New Revision: de3c01b06fe5854d2bf72c516e63eaa294e75fd2

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

LOG: Fix regex in test case so that it doesn't match "coverage" in directory
names

The test case was failing because "-f{{[^"]*coverage.*}}" was matching
the following string:

"-fdebug-compilation-dir=/Users/buildslave/jenkins/workspace/coverage/"

Differential Revision: https://reviews.llvm.org/D152485

Added: 


Modified: 
clang/test/Driver/cuda-no-pgo-or-coverage.cu

Removed: 




diff  --git a/clang/test/Driver/cuda-no-pgo-or-coverage.cu 
b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
index 01449fe7ae833..cd89f0f2e969c 100644
--- a/clang/test/Driver/cuda-no-pgo-or-coverage.cu
+++ b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
@@ -26,7 +26,7 @@
 // CHECK-NOT: error: unsupported option '-fprofile
 // CHECK-NOT: error: invalid argument
 // CHECK-DAG: "-fcuda-is-device"
-// CHECK-NOT: "-f{{[^"]*coverage.*}}"
+// CHECK-NOT: "-f{{[^"/]*coverage.*}}"
 // CHECK-NOT: "-fprofile{{[^"]*}}"
 // CHECK: "-triple" "x86_64-unknown-linux-gnu"
 // PROF:  "-fprofile{{.*}}"



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


[PATCH] D141907: [CMake] Ensure `CLANG_RESOURCE_DIR` is respected

2023-06-09 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D141907#4409973 , @MaskRay wrote:

> In D141907#4094748 , @MaskRay wrote:
>
>> [...]
>> edeaf16f2c2f02d6e43312d48d26d354d87913f3 (2011) added the CMake variable 
>> `CLANG_RESOURCE_DIR` but did not explain why. 
>> In the long term, the CMake variable `CLANG_RESOURCE_DIR` probably should be 
>> removed.
>
> My feeling stays the same. In the long term, we should try removing the CMake 
> variable `CLANG_RESOURCE_DIR`.
> Customizing the variable in a special way will make some `clang/test/Driver` 
> tests fail, I don't know it's healthy for contributors to be aware of this 
> yet-another configure variable for `clang/test/Driver` tests. The 
> `CLANG_RESOURCE_DIR` users should be served by specifying `-resource-dir=` in 
> a configuration file 
> (https://clang.llvm.org/docs/UsersManual.html#configuration-files)

I agree with this

In D141907#4409973 , @MaskRay wrote:

> In D141907#4094748 , @MaskRay wrote:
>
>> [...]
>> edeaf16f2c2f02d6e43312d48d26d354d87913f3 (2011) added the CMake variable 
>> `CLANG_RESOURCE_DIR` but did not explain why. 
>> In the long term, the CMake variable `CLANG_RESOURCE_DIR` probably should be 
>> removed.
>
> My feeling stays the same. In the long term, we should try removing the CMake 
> variable `CLANG_RESOURCE_DIR`.
> Customizing the variable in a special way will make some `clang/test/Driver` 
> tests fail, I don't know it's healthy for contributors to be aware of this 
> yet-another configure variable for `clang/test/Driver` tests. The 
> `CLANG_RESOURCE_DIR` users should be served by specifying `-resource-dir=` in 
> a configuration file 
> (https://clang.llvm.org/docs/UsersManual.html#configuration-files)

I think I agree with you here.  The other problem I see with CLANG_RESOURCE_DIR 
is that it depends on the value of LLVM_LIBDIR_SUFFIX, so it's still 
configurable even without the CLANG_RESOURCE_DIR variable.  I think it would 
make sense to standardize it to /usr/lib/clang rather than 
/usr/lib${LLVM_LBDIR_SUFFIX}/clang.  This is how gcc works and it also ensures 
that clang can find the 32-bit compiler-rt libraries.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141907

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


[PATCH] D152584: [clang-format] Remove redundant test case

2023-06-09 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth created this revision.
paulkirth added reviewers: owenpan, MyDeveloperDay.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks.
paulkirth requested review of this revision.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


The test is now properly covered in unit tests, and shouldn't have been
added in the initial commit of D152473 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152584

Files:
  clang/test/Format/overlapping-lines.cpp


Index: clang/test/Format/overlapping-lines.cpp
===
--- clang/test/Format/overlapping-lines.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | 
FileCheck %s 
-// CHECK-NOT: The new replacement overlaps with an existing replacement.
-
-#ifdef 
-
-
-#else 
-#endif 


Index: clang/test/Format/overlapping-lines.cpp
===
--- clang/test/Format/overlapping-lines.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | FileCheck %s 
-// CHECK-NOT: The new replacement overlaps with an existing replacement.
-
-#ifdef 
-
-
-#else 
-#endif 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

In D152473#4409975 , @MyDeveloperDay 
wrote:

> In D152473#4409146 , @paulkirth 
> wrote:
>
>> The point of this patch was to show a regression. I'm not trying to fix 
>> anything per se. I'd like https://reviews.llvm.org/D151954  and anything 
>> that depends on it reverted, since it breaks `clang-format`.
>
> I think its respectful to wait a little for the code owners to give you a LG 
> unless the patch is breaking the unit tests.

So first, no one here is trying to be disrespectful, we're all here to make the 
compiler and surrounding tools better for everyone. That said, it's also 
normally respectful to revert changes when others report that your patch has a 
serious regression.  
https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy

I'm not sure how common this is, but in this case we found a test case that was 
missing from the unit tests, otherwise the patches that were reverted would 
never have landed. So, while I understand your point, reverting here is in line 
w/ the communities policies. If there is a different interpretation I should 
have on the policy, I'm happy to hear it, but as I read it, our response here 
is in line w/ our typical developer expectations. My apologies if any of this 
comes off as rude (being nuanced in text is hard) but I'm trying to be very 
clear about my interpretation and rationale.

As a last point we've had our CI broken by this since the initial patch landed, 
and it's been several days since we first reported the issue. We're certainly 
not trying to be discourteous w/ our actions, but it I also don't think it's 
reasonable to expect that when community members report a serious regression, 
file an issue, and provide a reproducer that they be expected to wait days for 
a revert or forward fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[PATCH] D152433: [ARM,AArch64] Add a full set of -mtp= options.

2023-06-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/clang-translation.c:132
+// ARMv7_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
+
+// RUN: %clang -target armv7-linux -mtp=tpidruro -### -S %s 2>&1 | \

`clang-translation.c`'s job is shifting, but I think it is mainly for testing 
common options. For Arm-specific testing, I think using a `arm-*.c` file will 
be more appropriate. Ideally we can find an existing file where new RUN lines 
seem appropriate, as a fallback we can introduce a new test file:)

Also, use `--target=` for new tests. `-target ` has been deprecated (without a 
warning) since Clang 3.x era.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152433

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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D152473#4409652 , @phosek wrote:

> LGTM

@phosek can I ask you review https://llvm.org/docs/CodeReview.html

  When providing an unqualified LGTM (approval to commit), it is the 
responsibility of the reviewer to have reviewed all of the discussion and 
feedback from all reviewers ensuring that all feedback has been addressed and 
that all other reviewers will almost surely be satisfied with the patch being 
approved. If unsure, the reviewer should provide a qualified approval, (e.g., 
“LGTM, but please wait for @someone, @someone_else”). You may also do this if 
you are fairly certain that a particular community member will wish to review, 
even if that person hasn’t done so yet.

Whilst I understand you migth "like" the revert, I would ask that the when you 
do this, you say  `LGTM but please wait for the code owners".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D152473#4409146 , @paulkirth wrote:

> The point of this patch was to show a regression. I'm not trying to fix 
> anything per se. I'd like https://reviews.llvm.org/D151954  and anything that 
> depends on it reverted, since it breaks `clang-format`.

I think its respectful to wait a little for the code owners to give you a LG 
unless the patch is breaking the unit tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[clang-tools-extra] 2adf9c9 - [clang-tidy] Fix error in documentation of bugprone-unchecked-optional-access.

2023-06-09 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2023-06-09T20:42:09Z
New Revision: 2adf9c9f502acacf3b846cbf64d8a4739c803de6

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

LOG: [clang-tidy] Fix error in documentation of 
bugprone-unchecked-optional-access.

The documentation claims that the check recognizes `ASSERT_THAT`, but it doesn't
recognize any googletest macros at the moment. This patch removes the reference.

Added: 


Modified: 

clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst
index ddb43a3dac98b..47365185e42b0 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst
@@ -146,9 +146,8 @@ have a value. For example:
 Ensure that a value exists using common macros
 --
 
-The check is aware of common macros like ``CHECK``, ``DCHECK``, and
-``ASSERT_THAT``. Those can be used to ensure that an optional object has
-a value. For example:
+The check is aware of common macros like ``CHECK`` and ``DCHECK``. Those can be
+used to ensure that an optional object has a value. For example:
 
 .. code-block:: c++
 



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


[PATCH] D141907: [CMake] Ensure `CLANG_RESOURCE_DIR` is respected

2023-06-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D141907#4094748 , @MaskRay wrote:

> [...]
> edeaf16f2c2f02d6e43312d48d26d354d87913f3 (2011) added the CMake variable 
> `CLANG_RESOURCE_DIR` but did not explain why. 
> In the long term, the CMake variable `CLANG_RESOURCE_DIR` probably should be 
> removed.

My feeling stays the same. In the long term, we should try removing the CMake 
variable `CLANG_RESOURCE_DIR`.
Customizing the variable in a special way will make some `clang/test/Driver` 
tests fail, I don't know it's healthy for contributors to be aware of this 
yet-another configure variable for `clang/test/Driver` tests. The 
`CLANG_RESOURCE_DIR` users should be served by specifying `-resource-dir=` in a 
configuration file 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141907

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


[PATCH] D152433: [ARM,AArch64] Add a full set of -mtp= options.

2023-06-09 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp:4941-4943
   if (LoadImmOpc == ARM::MRC || LoadImmOpc == ARM::t2MRC) {
-assert(Subtarget.isReadTPHard() &&
+assert(!Subtarget.isReadTPSoft() &&
"TLS stack protector requires hardware TLS register");

From the buildbot presubmit failure:

```
/var/lib/buildkite-agent/builds/llvm-project/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp:4942:23:
 error: no member named 'isReadTPSoft' in 'llvm::ARMSubtarget'
assert(!Subtarget.isReadTPSoft() &&
~ ^
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
 (static_cast  (expr) \
  ^~~~
```
PTAL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152433

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


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 530070.
dankm added a comment.

Fix typo in release notes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/file-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s 
-emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions &LO) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions &LO;
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = &PrettyCB;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions &LO) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions &LO;
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = &PrettyCB;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 530069.
dankm added a comment.

Added unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/file-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s 
-emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions &LO) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions &LO;
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = &PrettyCB;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions &LO) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions &LO;
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = &PrettyCB;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay reopened this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

Did this need an immediate revert? was the unit tests failing?




Comment at: clang/test/Format/overlapping-lines.cpp:1
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | 
FileCheck %s 
+// CHECK-NOT: The new replacement overlaps with an existing replacement.

please remove this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread Paul Kirth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb6a718016c0f: [clang-format] Add test case for issue 63170 
(authored by paulkirth).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/test/Format/overlapping-lines.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12856,22 +12856,6 @@
"  void f() {}\n"
"};\n",
Style);
-  verifyFormat("struct foo {\n"
-   "#ifdef FOO\n"
-   "#else\n"
-   "private:\n"
-   "\n"
-   "#endif\n"
-   "};",
-   "struct foo {\n"
-   "#ifdef FOO\n"
-   "#else\n"
-   "private:\n"
-   "\n"
-   "\n"
-   "#endif\n"
-   "};",
-   Style);
 
   Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
   verifyFormat("struct foo {\n"
@@ -25744,15 +25728,6 @@
   verifyFormat("int i;\n", "int i;", Style);
 }
 
-TEST_F(FormatTest, KeepEmptyLinesAtEOF) {
-  FormatStyle Style = getLLVMStyle();
-  Style.KeepEmptyLinesAtEOF = true;
-
-  const StringRef Code{"int i;\n\n"};
-  verifyFormat(Code, Code, Style);
-  verifyFormat(Code, "int i;\n\n\n", Style);
-}
-
 TEST_F(FormatTest, SpaceAfterUDL) {
   verifyFormat("auto c = (4s).count();");
   verifyFormat("auto x = 5s .count() == 5;");
@@ -25765,6 +25740,18 @@
"}");
 }
 
+TEST_F(FormatTest, PreprocessorOverlappingRegions) {
+  verifyFormat("#ifdef\n\n"
+   "#else\n"
+   "#endif\n",
+   "#ifdef \n"
+   "\n"
+   "\n"
+   "#else \n"
+   "#endif \n",
+   getGoogleStyle());
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -167,7 +167,6 @@
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
   CHECK_PARSE_BOOL(InsertBraces);
   CHECK_PARSE_BOOL(InsertNewlineAtEOF);
-  CHECK_PARSE_BOOL(KeepEmptyLinesAtEOF);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
Index: clang/test/Format/overlapping-lines.cpp
===
--- /dev/null
+++ clang/test/Format/overlapping-lines.cpp
@@ -0,0 +1,8 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | FileCheck %s 
+// CHECK-NOT: The new replacement overlaps with an existing replacement.
+
+#ifdef 
+
+
+#else 
+#endif 
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,12 +1418,19 @@
   return Penalty;
 }
 
-static auto newlinesBeforeLine(const AnnotatedLine &Line,
-   const AnnotatedLine *PreviousLine,
-   const AnnotatedLine *PrevPrevLine,
-   const SmallVectorImpl &Lines,
-   const FormatStyle &Style) {
-  const auto &RootToken = *Line.First;
+void UnwrappedLineFormatter::formatFirstToken(
+const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
+const SmallVectorImpl &Lines, unsigned Indent,
+unsigned NewlineIndent) {
+  FormatToken &RootToken = *Line.First;
+  if (RootToken.is(tok::eof)) {
+unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u);
+unsigned TokenIndent = Newlines ? NewlineIndent : 0;
+Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
+   TokenIndent);
+return;
+  }
   unsigned Newlines =
   std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
   // Remove empty lines before "}" where applicable.
@@ -1503,29 +1510,6 @@
 }
   }
 
-  return Newlines;
-}
-
-void UnwrappedLineFormatter::formatFirstToken(
-const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
-const AnnotatedLine *PrevPrevLine,
-const SmallVectorImpl &Lines, unsigned Indent,
-unsigned NewlineIndent) {
-  FormatToken &RootToken = 

[clang] b6a7180 - [clang-format] Add test case for issue 63170

2023-06-09 Thread Paul Kirth via cfe-commits

Author: Paul Kirth
Date: 2023-06-09T20:10:19Z
New Revision: b6a718016c0fd7a0d883214ba19d88b6f96e3ae1

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

LOG: [clang-format] Add test case for issue 63170

After https://reviews.llvm.org/D151954 we've noticed some issues w/
clang-format behavior, as outlined in
https://github.com/llvm/llvm-project/issues/63170.

Valid C/C++ files, that were previously accepted, are now rejected by
clang-format, emitting the message:

"The new replacement overlaps with an existing replacement."

This reverts commit 4b9764959dc4b8783e18747c1742ab164e4bc4ee and
d2627cf88d2553a4c2e850430bdb908a4b7d2e52, which depends on it.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D152473

Added: 
clang/test/Format/overlapping-lines.cpp

Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index fa552d65e208a..8f23a4aa27a92 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3555,11 +3555,6 @@ the configuration (without a prefix: ``Auto``).
  false:
  import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, 
VeryLongImportsAreAnnoying,} from "some/module.js"
 
-.. _KeepEmptyLinesAtEOF:
-
-**KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ 
`
-  Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
-
 .. _KeepEmptyLinesAtTheStartOfBlocks:
 
 **KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index acd8c4d622a89..58e1039c4f133 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -707,7 +707,6 @@ clang-format
 - Fix all known issues associated with ``LambdaBodyIndentation: OuterScope``.
 - Add ``BracedInitializerIndentWidth`` which can be used to configure
   the indentation level of the contents of braced init lists.
-- Add ``KeepEmptyLinesAtEOF`` to keep empty lines at end of file.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 74b3e15918184..6a9d435174cdd 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2675,10 +2675,6 @@ struct FormatStyle {
   bool JavaScriptWrapImports;
   // clang-format on
 
-  /// Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
-  /// \version 17
-  bool KeepEmptyLinesAtEOF;
-
   /// If true, the empty line at the start of blocks is kept.
   /// \code
   ///true:  false:
@@ -4368,7 +4364,6 @@ struct FormatStyle {
JavaImportGroups == R.JavaImportGroups &&
JavaScriptQuotes == R.JavaScriptQuotes &&
JavaScriptWrapImports == R.JavaScriptWrapImports &&
-   KeepEmptyLinesAtEOF == R.KeepEmptyLinesAtEOF &&
KeepEmptyLinesAtTheStartOfBlocks ==
R.KeepEmptyLinesAtTheStartOfBlocks &&
Language == R.Language &&

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 5fee5e6c261a9..6e2b6a662e7e1 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -942,7 +942,6 @@ template <> struct MappingTraits {
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
-IO.mapOptional("KeepEmptyLinesAtEOF", Style.KeepEmptyLinesAtEOF);
 IO.mapOptional("LambdaBodyIndentation", Style.LambdaBodyIndentation);
 IO.mapOptional("LineEnding", Style.LineEnding);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -1411,7 +1410,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   /*Hex=*/0, /*HexMinDigits=*/0};
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
-  LLVMStyle.KeepEmptyLinesAtEOF = false;
   LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
   LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
   LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;

diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index f229742b19d97..33be74dfe1b9f 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,12 +1418,19 @@ unsigned Unwrap

[PATCH] D152090: [clang][Driver] Add -fcaret-diagnostics-max-lines as a driver option

2023-06-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D152090#4407632 , @dyung wrote:

> If we do not accept the form "`-fcaret-diagnostics-max-lines n`", can we add 
> a negative for that? Or if we do a positive test for it as well?

I think this is not very useful. This is a new option. Separate-form driver 
options are unusual and typically legacy GCC options (before 2000 or early 
2000s).
If we have tested `-fcaret-diagnostics-max-lines=N`, it is unnecessary to test 
`-fcaret-diagnostics-max-lines N`.




Comment at: clang/test/Driver/caret-diagnostics-max-lines.cpp:1
+//RUN: not %clang++ -fsyntax-only -fcaret-diagnostics-max-lines=2 %s 2>&1 | 
FileCheck %s -strict-whitespace
+

tbaeder wrote:
> MaskRay wrote:
> > The `test/Driver` test just tests that `-fcaret-diagnostics-max-lines=2` is 
> > forwarded to CC1. The semantic tests are performed in other test 
> > directories, `Misc/caret-diags-multiline.cpp` in this case.
> Do you want me to remove the semantic part in this file or add a `RUN` line 
> to `caret-diags-multiline.cpp` using `%clang`?
`clang/test/Driver/caret-diagnostics-max-lines.cpp` should just check that the 
driver option `-fcaret-diagnostics-max-lines=N` is translated to `-cc1 
{{.*}}"-fcaret-diagnostics-max-lines=N"`.

The functionality feature is tested in other test directories, and should not 
be duplicated in `test/Driver/`.


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

https://reviews.llvm.org/D152090

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


Re: [PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2023-06-09 Thread Corentin via cfe-commits
I'll be unavailable the next 2 weeks, feel free to do it if you want!

On Fri, Jun 9, 2023, 21:10 Tom Honermann via Phabricator <
revi...@reviews.llvm.org> wrote:

> tahonermann added a comment.
>
> @cor3ntin, sorry for failing to keep up with reviews; I know this has
> already been committed. I did spot a couple of typos should you feel
> inclined to address them.
>
>
>
> 
> Comment at: clang/lib/Lex/Lexer.cpp:2695
> +  // diagnostic only once per entire ill-formed subsequence to avoid
> +  // emiting to many diagnostics (see
> http://unicode.org/review/pr-121.html).
> +  bool UnicodeDecodingAlreadyDiagnosed = false;
> 
>
>
>
> 
> Comment at: clang/lib/Lex/Lexer.cpp:2398
> +  // diagnostic only once per entire ill-formed subsequence to avoid
> +  // emiting to many diagnostics (see
> http://unicode.org/review/pr-121.html).
> +  bool UnicodeDecodingAlreadyDiagnosed = false;
> 
>
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D128059/new/
>
> https://reviews.llvm.org/D128059
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-06-09 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen marked an inline comment as done.
ychen added inline comments.



Comment at: clang/test/SemaTemplate/aggregate-deduction-candidate.cpp:101
+
+  template  struct E {
+T t;

shafik wrote:
> I would also like to see this test:
> 
> ```
> template 
> struct I {
>   using type = T;
> };
> 
> template 
> struct E {
>   typename I::type i;
>   T t;
> };
> 
> E e1 = {1, 2}; // OK, E deduced
> ```
> 
> Since it is in the paper, this should cover it but it can't hurt.
Yep, just added this test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-06-09 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 530057.
ychen added a comment.

- add one extra test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1246,7 +1246,7 @@
 
   Class template argument deduction for aggregates
   https://wg21.link/p1816r0";>P1816R0
-  No
+  Clang 17
 

 https://wg21.link/p2082r1";>P2082R1
Index: clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -0,0 +1,364 @@
+// RUN: %clang_cc1 -std=c++20 -verify -ast-dump -ast-dump-decl-types -ast-dump-filter "deduction guide" %s | FileCheck %s --strict-whitespace
+
+namespace Basic {
+  template struct A {
+T x;
+T y;
+  };
+
+  A a1 = {3.0, 4.0};
+  A a2 = {.x = 3.0, .y = 4.0};
+
+  A a3(3.0, 4.0);
+
+  // CHECK-LABEL: Dumping Basic:::
+  // CHECK: FunctionTemplateDecl {{.*}} implicit 
+  // CHECK: |-TemplateTypeParmDecl {{.*}} referenced class depth 0 index 0 T
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (T, T) -> A'
+  // CHECK: | |-ParmVarDecl {{.*}} 'T'
+  // CHECK: | `-ParmVarDecl {{.*}} 'T'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (double, double) -> Basic::A'
+  // CHECK:   |-TemplateArgument type 'double'
+  // CHECK:   | `-BuiltinType {{.*}} 'double'
+  // CHECK:   |-ParmVarDecl {{.*}} 'double':'double'
+  // CHECK:   `-ParmVarDecl {{.*}} 'double':'double'
+  // CHECK: FunctionProtoType {{.*}} 'auto (T, T) -> A' dependent trailing_return cdecl
+  // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
+  // CHECK: | `-CXXRecord {{.*}} 'A'
+  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK: `-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   `-TemplateTypeParm {{.*}} 'T'
+
+  template  struct S { // expected-note 2 {{candidate}}
+T x;
+T y;
+  };
+
+  template  struct C { // expected-note 10 {{candidate}}
+S s;
+T t;
+  };
+
+  template  struct D { // expected-note 6 {{candidate}}
+S s;
+T t;
+  };
+
+  C c1 = {1, 2}; // expected-error {{no viable}}
+  C c2 = {1, 2, 3}; // expected-error {{no viable}}
+  C c3 = {{1u, 2u}, 3};
+
+  C c4(1, 2);// expected-error {{no viable}}
+  C c5(1, 2, 3); // expected-error {{no viable}}
+  C c6({1u, 2u}, 3);
+
+  D d1 = {1, 2}; // expected-error {{no viable}}
+  D d2 = {1, 2, 3};
+
+  D d3(1, 2); // expected-error {{no viable}}
+  // CTAD succeed but brace elision is not allowed for parenthesized aggregate init. 
+  D d4(1, 2, 3); // expected-error {{no viable}}
+
+  // CHECK-LABEL: Dumping Basic:::
+  // CHECK: FunctionTemplateDecl {{.*}} implicit 
+  // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (S, T) -> C'
+  // CHECK: | |-ParmVarDecl {{.*}} 'S':'S'
+  // CHECK: | `-ParmVarDecl {{.*}} 'T'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (S, int) -> Basic::C'
+  // CHECK:   |-TemplateArgument type 'int'
+  // CHECK:   | `-BuiltinType {{.*}} 'int'
+  // CHECK:   |-ParmVarDecl {{.*}} 'S':'Basic::S'
+  // CHECK:   `-ParmVarDecl {{.*}} 'int':'int'
+  // CHECK: FunctionProtoType {{.*}} 'auto (S, T) -> C' dependent trailing_return cdecl
+  // CHECK: |-InjectedClassNameType {{.*}} 'C' dependent
+  // CHECK: | `-CXXRecord {{.*}} 'C'
+  // CHECK: |-ElaboratedType {{.*}} 'S' sugar dependent
+  // CHECK: | `-TemplateSpecializationType {{.*}} 'S' dependent S
+  // CHECK: |   `-TemplateArgument type 'T'
+  // CHECK: | `-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK: |   `-TemplateTypeParm {{.*}} 'T'
+  // CHECK: `-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   `-TemplateTypeParm {{.*}} 'T'
+
+  // CHECK-LABEL: Dumping Basic:::
+  // CHECK: FunctionTemplateDecl {{.*}} implicit 
+  // CHECK: |-TemplateTypeParmDecl {{.*}} re

[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/lib/AST/Expr.cpp:791
+public:
+  PrettyCallbacks(const LangOptions &L) : LO(L) {}
+  std::string remapPath(StringRef Path) const override {

shafik wrote:
> This may not be a well known idiom but is widely used within llvm.
Makes sense, I was going for unambiguity between the class's member name and 
the constructor argument name, but if it's widely used that's fine. I'll add 
that change when I add unit tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152570

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


[PATCH] D152547: [clang][NFC] Drop alignment in builtin-nondeterministic-value test

2023-06-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/CodeGen/builtins-nondeterministic-value.c:8
 // CHECK-LABEL: entry
-// CHECK: [[A:%.*]] = alloca i32, align 4
-// CHECK: store i32 [[X:%.*]], ptr [[A]], align 4
+// CHECK: [[A:%.*]] = alloca i32, align
+// CHECK: store i32 [[X:%.*]], ptr [[A]], align

this test doesn't seem to be testing for alignment at all, so just take out 
everything after the type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152547

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


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Expr.cpp:789
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:

This looks consistent with how other places that set `CallBacks` but I am not 
familiar with this area. 



Comment at: clang/lib/AST/Expr.cpp:791
+public:
+  PrettyCallbacks(const LangOptions &L) : LO(L) {}
+  std::string remapPath(StringRef Path) const override {

This may not be a well known idiom but is widely used within llvm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152570

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


[PATCH] D151683: [clang] Enable C++11-style attributes in all language modes

2023-06-09 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/ParserHLSL/group_shared.hlsl:14
-// expected-error@+1 {{expected expression}}
 float groupshared [[]] i = 12;
 

philnik wrote:
> beanz wrote:
> > aaron.ballman wrote:
> > > philnik wrote:
> > > > Should this also get an extension warning/should attributes be disabled 
> > > > for HLSL?
> > > CC @beanz 
> > > 
> > > I was wondering the same thing. :-)
> > By bug rather than design DXC allows C++ attribute syntax in some places 
> > for HLSL.
> > 
> > I'm totally fine with (and prefer) following the rest of the languages here 
> > and having HLSL in Clang always allow C++ attributes regardless of language 
> > version.
> Would you like some sort of warning?
Since DXC accepts the syntax without a warning/error I think we're fine without 
one here. There won't be any portability issues with code that use C++ 
attributes in HLSL unless they go back to the _extremely_ old compiler that we 
don't really support anyways.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151683

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


[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-09 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Could Clang offer a builtin.h file? It is always included. You place named 
constants and enums inside.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

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


[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-06-09 Thread David Sawatzke via Phabricator via cfe-commits
david-sawatzke added a comment.

Hey I've tried using this patch (roughly following 
https://noxim.xyz/blog/rust-ch32v003/).

It uses the older version of this patch for the rust llvm version (here the 
llvm tree https://github.com/Noxime/llvm-project/tree/rv32e) and I use rust 
commit 0939ec13 (together with the small patch for the RVE).

I've experience some issues that results in corruption of $sp, the following is 
the smallest reproduction (hopefully small enough):
Code:

  rust
  #![no_std]
  
  pub fn test()  {
  }

which, with the following .ll for release builds:

  source_filename = "miscomp_repro.8b6a426d3b54bd13-cgu.0"
  target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
  target triple = "riscv32"
  
  define dso_local void @_ZN13miscomp_repro4test17h065760f827b95d43E() 
unnamed_addr #0 {
  start:
ret void
  }
  
  attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone 
willreturn "target-cpu"="generic-rv32" "target-features"="+e,+c" }

results in this assembly:

.text
.attribute  4, 4
.attribute  5, "rv32e1p9_c2p0"
.file   "miscomp_repro.8b6a426d3b54bd13-cgu.0"
.section
.text._ZN13miscomp_repro4test17h065760f827b95d43E,"ax",@progbits
.globl  _ZN13miscomp_repro4test17h065760f827b95d43E
.p2align1
.type   _ZN13miscomp_repro4test17h065760f827b95d43E,@function
  _ZN13miscomp_repro4test17h065760f827b95d43E:
mv  sp, s0
ret
  .Lfunc_end0:
.size   _ZN13miscomp_repro4test17h065760f827b95d43E, 
.Lfunc_end0-_ZN13miscomp_repro4test17h065760f827b95d43E
  
.section".note.GNU-stack","",@progbits

Since s0 isn't required to have any specific contents (and in the larger 
project this was extracted from doesn't), this corrupts the stack pointer. 
Large functions using the stack first save sp to  0, so not all functions have 
this issue. This also happens (but more verbose) in debug builds, but works 
fine with the exact same toolchain using the riscv32i target.

Here is the repro with some further output, I hope this patch and not something 
else is to blame (if so, sorry in advance).

F27877626: miscomp_repro.zip 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[PATCH] D152443: Add SpaceAfterOperatorKeyword & SpaceAfterOperatorKeywordInCall style options for clang-format

2023-06-09 Thread Alexander Hinze via Phabricator via cfe-commits
KitsuneAlex added a comment.

In D152443#4408991 , @MyDeveloperDay 
wrote:

> In D152443#4407438 , @KitsuneAlex 
> wrote:
>
>> I had some issues with Git there because i messed up a merge, so the diff 
>> was bad. Here's the proper diff.
>
>
>
>> NOTE: Clang-Format Team Automated Review Comment
>
> keeps you honest right!

Yes, i was referring to the fact that the previous diff was only 30% of my 
intended changes if you look at the changed files, which was caused by an 
unsmart local merge on my end.
That's why my following diff corrected the formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

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


[PATCH] D150843: [clang][Diagnostics] Refactor printableTextForNextCharacter

2023-06-09 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.
This revision is now accepted and ready to land.

> They are NFC, it's just not 100% only a refactoring, since it adds the new 
> ASCII-only case.

Ok, thanks. Changes look good. I noticed one comment that appears to be 
incorrect; please just remove it when committing the changes.




Comment at: clang/lib/Frontend/TextDiagnostic.cpp:128
+
+  // We now know that the next character is a multi-byte character.
+  // Convert it to UTF32 and check if it's printable.

This comment is not correct; `Begin` might still point to a non-printable 
character with a code point value less than 0x80. I suggest just removing the 
comment.


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

https://reviews.llvm.org/D150843

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


[PATCH] D151683: [clang] Enable C++11-style attributes in all language modes

2023-06-09 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added inline comments.



Comment at: clang/test/Parser/cxx-decl.cpp:316
 #if __cplusplus >= 201103L
-// expected-error@+3 {{expected}}
+// expected-error@+2 {{expected}}
 // expected-error@-3 {{expected ';' after top level declarator}}

aaron.ballman wrote:
> Huh... I wasn't expecting to see a change here because there's no attribute 
> nearby. Probably fine, but still a bit curious.
This is probably because of the whitespace trim below.



Comment at: clang/test/ParserHLSL/group_shared.hlsl:14
-// expected-error@+1 {{expected expression}}
 float groupshared [[]] i = 12;
 

beanz wrote:
> aaron.ballman wrote:
> > philnik wrote:
> > > Should this also get an extension warning/should attributes be disabled 
> > > for HLSL?
> > CC @beanz 
> > 
> > I was wondering the same thing. :-)
> By bug rather than design DXC allows C++ attribute syntax in some places for 
> HLSL.
> 
> I'm totally fine with (and prefer) following the rest of the languages here 
> and having HLSL in Clang always allow C++ attributes regardless of language 
> version.
Would you like some sort of warning?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151683

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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2023-06-09 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

@cor3ntin, sorry for failing to keep up with reviews; I know this has already 
been committed. I did spot a couple of typos should you feel inclined to 
address them.




Comment at: clang/lib/Lex/Lexer.cpp:2695
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;





Comment at: clang/lib/Lex/Lexer.cpp:2398
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

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


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm created this revision.
Herald added a project: All.
dankm added a comment.
dankm updated this revision to Diff 530046.
dankm published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I still need to make a unit test for this. Should be more-or-less a cleaned up 
version of the testcase in https://github.com/llvm/llvm-project/issues/63219.


dankm added a comment.

Add release notes.


dankm added a comment.

Despite needing unit tests, I'd like some eyes on this change.


When expanding template arguments for pretty function printing,
such as for __PRETTY_FUNCTION__, apply macro-prefix-map remapping
for lambda names.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions &L) : LO(L) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions &LO;
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = &PrettyCB;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions &L) : LO(L) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions &LO;
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = &PrettyCB;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGen/isfpclass.c:2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -O1 -emit-llvm %s -o - | 
FileCheck %s
+
+_Bool check_isfpclass_finite(float x) {

sepavloff wrote:
> arsenm wrote:
> >  Can you also add a half test, also vectors
> Half is added. But vectors cannot, because in this case result is also a 
> vector.
Could copy what __builtin_elementwise does. Should that be in this builtin, or 
should there be a separate __builtin_elementwise_isfpclass?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

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


[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D152351#4409725 , @sepavloff wrote:

> In D152351#4403904 , @aaron.ballman 
> wrote:
>
>> In D152351#4402785 , @arsenm wrote:
>>
>>> Also should get mentioned in the builtin docs and release notes
>>
>> +1, also, should there be named constants for the mask values?
>
> I don't know where these constants could be placed.

The preprocessor predefines a bunch of macros, so I was thinking along those 
same lines. e.g., 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/InitPreprocessor.cpp#L737


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

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


[PATCH] D152561: [AST] Always set dependent-type for the CallExpr for error-recovery in C.

2023-06-09 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.

Thank you for the quick fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152561

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


[PATCH] D151683: [clang] Enable C++11-style attributes in all language modes

2023-06-09 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/ParserHLSL/group_shared.hlsl:14
-// expected-error@+1 {{expected expression}}
 float groupshared [[]] i = 12;
 

aaron.ballman wrote:
> philnik wrote:
> > Should this also get an extension warning/should attributes be disabled for 
> > HLSL?
> CC @beanz 
> 
> I was wondering the same thing. :-)
By bug rather than design DXC allows C++ attribute syntax in some places for 
HLSL.

I'm totally fine with (and prefer) following the rest of the languages here and 
having HLSL in Clang always allow C++ attributes regardless of language version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151683

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


[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-09 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff marked 8 inline comments as done.
sepavloff added a comment.

In D152351#4403904 , @aaron.ballman 
wrote:

> In D152351#4402785 , @arsenm wrote:
>
>> Also should get mentioned in the builtin docs and release notes
>
> +1, also, should there be named constants for the mask values?

I don't know where these constants could be placed.




Comment at: clang/test/CodeGen/isfpclass.c:2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -O1 -emit-llvm %s -o - | 
FileCheck %s
+
+_Bool check_isfpclass_finite(float x) {

arsenm wrote:
>  Can you also add a half test, also vectors
Half is added. But vectors cannot, because in this case result is also a vector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

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


[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Typo builting in commit message




Comment at: clang/docs/LanguageExtensions.rst:3418
+
+This function never raises floating-point exceptions.
+

Maybe also mention it doesn't canonicalize its input



Comment at: clang/test/CodeGen/isfpclass.c:54
+_Bool check_isfpclass_nan_f16(_Float16 x) {
+#pragma STDC FENV_ACCESS ON
+  return __builtin_isfpclass(x, 3 /*NaN*/);

Also tests without fenv access



Comment at: clang/test/CodeGen/isfpclass.c:56
+  return __builtin_isfpclass(x, 3 /*NaN*/);
+}

Test some vectors?



Comment at: clang/test/Sema/builtins.c:384
+  int x1 = __builtin_isfpclass(x, 1024); // expected-error {{argument value 
1024 is outside the valid range [0, 1023]}}
+  int x2 = __builtin_isfpclass(3, 3); // expected-error{{floating point 
classification requires argument of floating point type (passed in 'int')}}
+  int x3 = __builtin_isfpclass(x, 3, x); // expected-error{{too many arguments 
to function call, expected 2, have 3}}

For any other float argument, 3 would accept implicit conversion. Do we just 
not do that for these type inferring intrinsics?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

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


[PATCH] D151834: Include math-errno with fast-math

2023-06-09 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/include/clang/Basic/FPOptions.def:30
 OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
FPEvalMethod)
+OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision)
 #undef OPTION

andrew.w.kaylor wrote:
> Does this mean MathErrno is tracked in both LangOpts and FPOptions?
Yes. So that we can check that if it's overridden by a pragma or an attribute. 
I don't see another way.



Comment at: clang/test/CodeGen/math-errno.c:33
+
+__attribute__((optnone))
+float f4(float x) { 

andrew.w.kaylor wrote:
> Can you add a runline with -O0. That should prevent all instances of the 
> intrinsics, right?
Yes.



Comment at: clang/test/CodeGen/math-errno.c:49
+// FAST-LABEL: define dso_local nofpclass(nan inf) float @f4(float noundef 
nofpclass(nan inf) {{.*}})
+// FAST: call reassoc nnan ninf nsz arcp afn nofpclass(nan inf) float 
@sqrtf(float noundef nofpclass(nan inf) %0) #[[ATTR0:[0-9]+]]
+

andrew.w.kaylor wrote:
> I think the 'afn' flag here is a problem. The backend has no concept of 
> errno, so 'afn' will be treated as allowing the function to be replaced.
Added all the commands that are triggered by fast-math in the RUN line command. 


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

https://reviews.llvm.org/D151834

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


[PATCH] D151834: Include math-errno with fast-math

2023-06-09 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 530040.
zahiraam marked 5 inline comments as done.

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

https://reviews.llvm.org/D151834

Files:
  clang/include/clang/Basic/FPOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/math-errno.c

Index: clang/test/CodeGen/math-errno.c
===
--- /dev/null
+++ clang/test/CodeGen/math-errno.c
@@ -0,0 +1,66 @@
+// -O2
+// RUN: %clang_cc1 -Wno-implicit-function-declaration  \
+// RUN: -ffp-contract=on -fno-rounding-math -O2 -emit-llvm -o - %s \
+// RUN: | FileCheck %s
+
+// -ffast-math
+// RUN: %clang_cc1 -Wno-implicit-function-declaration  \
+// RUN: -menable-no-infs -menable-no-nans -fapprox-func \
+// RUN: -funsafe-math-optimizations -fno-signed-zeros -mreassociate \
+// RUN: -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math \
+// RUN: -ffinite-math-only -ffast-math -emit-llvm -o - %s \
+// RUN: | FileCheck %s -check-prefix=FAST
+
+// -O0
+// RUN: %clang_cc1 -Wno-implicit-function-declaration  \
+// RUN: -ffp-contract=on -fno-rounding-math -O2 -emit-llvm -o - %s \
+// RUN: | FileCheck %s -check-prefix=NOOPT
+
+#pragma float_control(precise,on)
+float f1(float x) {
+  return sqrtf(x);
+}
+
+// CHECK-LABEL: define dso_local float @f1
+// CHECK: tail call float @sqrtf(float noundef {{.*}}) #[[ATTR4_O2:[0-9]+]]
+
+// FAST-LABEL: define dso_local nofpclass(nan inf) float @f1
+// FAST: call fast nofpclass(nan inf) float @sqrtf(float noundef nofpclass(nan inf) {{.*}}) #[[ATTR3_FAST:[0-9]+]]
+//
+// NOOPT-LABEL: define dso_local float @f1
+// NOOPT: tail call float @sqrtf(float noundef {{.*}}) #[[ATTR4_NOOPT:[0-9]+]]
+
+
+#pragma float_control(precise,off)
+float f2(float x) {
+  return sqrtf(x);
+}
+
+// CHECK-LABEL: define dso_local float @f2
+// CHECK: tail call float @llvm.sqrt.f32(float {{.*}})
+
+// FAST-LABEL: define dso_local nofpclass(nan inf) float @f2
+// FAST: call fast nofpclass(nan inf) float @sqrtf(float noundef nofpclass(nan inf) {{.*}}) #[[ATTR3_FAST]]
+
+// NOOPT-LABEL: define dso_local float @f2
+// NOOPT: tail call float @llvm.sqrt.f32(float {{.*}})
+
+
+__attribute__((optnone))
+float f3(float x) {
+  x = sqrtf(x);
+  return x;
+}
+
+// CHECK-LABEL: define dso_local float @f3
+// CHECK: call float @llvm.sqrt.f32(float {{.*}})
+
+// FAST-LABEL: define dso_local nofpclass(nan inf) float @f3
+// FAST: call fast nofpclass(nan inf) float @sqrtf(float noundef nofpclass(nan inf) {{.*}}) #[[ATTR4_FAST:[0-9]+]]
+
+// NOOPT-LABEL: define dso_local float @f3
+// NOOPT: call float @llvm.sqrt.f32(float {{.*}})
+
+// CHECK: [[ATTR4_O2]] = { nounwind willreturn memory(none) }
+// FAST: [[ATTR3_FAST]] =  { nounwind willreturn memory(none) }
+// NOOPT: [[ATTR4_NOOPT]] = { nounwind willreturn memory(none) }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1254,6 +1254,12 @@
   llvm::AttributeList &Attrs, unsigned &CallingConv,
   bool AttrOnCallSite, bool IsThunk);
 
+  /// Adjust Memory attribute to ensure that the BE gets the right attribute
+  // in order to generate the library call or the intrinsic for the function
+  // name 'Name'.
+  void AdjustMemoryAttribute(StringRef Name,
+ CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs);
+
   /// Adds attributes to F according to our CodeGenOptions and LangOptions, as
   /// though we had emitted it ourselves.  We remove any attributes on F that
   /// conflict with the attributes we add here.
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2216,6 +2216,17 @@
   return Mask;
 }
 
+void CodeGenModule::AdjustMemoryAttribute(StringRef Name,
+  CGCalleeInfo CalleeInfo,
+  llvm::AttributeList &Attrs) {
+  if (Attrs.getMemoryEffects().getModRef() == llvm::ModRefInfo::NoModRef) {
+Attrs = Attrs.removeFnAttribute(getLLVMContext(), llvm::Attribute::Memory);
+llvm::Attribute MemoryAttr = llvm::Attribute::getWithMemoryEffects(
+getLLVMContext(), llvm::MemoryEffects::writeOnly());
+Attrs = Attrs.addFnAttribute(getLLVMContext(), MemoryAttr);
+  }
+}
+
 /// Construct the IR attribute list of a function or call.
 ///
 /// When adding an attribute, please consider where it should be handled:
@@ -5463,11 +5474,17 @@
  /*AttrOnCallSite=*/true,
  /*IsThunk=*/false);
 
-  if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl))
+  if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDe

[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-09 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 530041.
sepavloff added a comment.

Updated patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins.c
  clang/test/CodeGen/isfpclass.c
  clang/test/Sema/builtins.c
  clang/test/Sema/constant-builtins-2.c
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/IR/IRBuilder.cpp

Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -1375,6 +1375,14 @@
   return Fn;
 }
 
+Value *IRBuilderBase::createIsFPClass(Value *FPNum, unsigned Test) {
+  ConstantInt *TestV = getInt32(Test);
+  Module *M = BB->getParent()->getParent();
+  Function *FnIsFPClass =
+  Intrinsic::getDeclaration(M, Intrinsic::is_fpclass, {FPNum->getType()});
+  return CreateCall(FnIsFPClass, {FPNum, TestV});
+}
+
 CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
  Value *PtrValue,
  Value *AlignValue,
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -2518,6 +2518,8 @@
  unsigned Index, unsigned FieldIndex,
  MDNode *DbgInfo);
 
+  Value *createIsFPClass(Value *FPNum, unsigned Test);
+
 private:
   /// Helper function that creates an assume intrinsic call that
   /// represents an alignment assumption on the provided pointer \p PtrValue
Index: clang/test/Sema/constant-builtins-2.c
===
--- clang/test/Sema/constant-builtins-2.c
+++ clang/test/Sema/constant-builtins-2.c
@@ -124,6 +124,47 @@
 char isnormal_nan[!__builtin_isnormal(__builtin_nan("")) ? 1 : -1];
 char isnormal_snan   [!__builtin_isnormal(__builtin_nans("")) ? 1 : -1];
 
+char isfpclass_inf_pos_0[__builtin_isfpclass(__builtin_inf(), 0x0200) ? 1 : -1]; // fcPosInf
+char isfpclass_inf_pos_1[!__builtin_isfpclass(__builtin_inff(), 0x0004) ? 1 : -1]; // fcNegInf
+char isfpclass_inf_pos_2[__builtin_isfpclass(__builtin_infl(), 0x0207) ? 1 : -1]; // fcSNan|fcQNan|fcNegInf|fcPosInf
+char isfpclass_inf_pos_3[!__builtin_isfpclass(__builtin_inf(), 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pos_0[__builtin_isfpclass(1.0, 0x0100) ? 1 : -1]; // fcPosNormal
+char isfpclass_pos_1[!__builtin_isfpclass(1.0f, 0x0008) ? 1 : -1]; // fcNegNormal
+char isfpclass_pos_2[__builtin_isfpclass(1.0L, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pos_3[!__builtin_isfpclass(1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan
+char isfpclass_pdenorm_0[__builtin_isfpclass(1.0e-40f, 0x0080) ? 1 : -1]; // fcPosSubnormal
+char isfpclass_pdenorm_1[__builtin_isfpclass(1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pdenorm_2[!__builtin_isfpclass(1.0e-40f, 0x003C) ? 1 : -1]; // fcNegative
+char isfpclass_pdenorm_3[!__builtin_isfpclass(1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+char isfpclass_pzero_0  [__builtin_isfpclass(0.0f, 0x0060) ? 1 : -1]; // fcZero
+char isfpclass_pzero_1  [__builtin_isfpclass(0.0, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pzero_2  [!__builtin_isfpclass(0.0L, 0x0020) ? 1 : -1]; // fcNegZero
+char isfpclass_pzero_3  [!__builtin_isfpclass(0.0, 0x0003) ? 1 : -1]; // fcNan
+char isfpclass_nzero_0  [__builtin_isfpclass(-0.0f, 0x0060) ? 1 : -1]; // fcZero
+char isfpclass_nzero_1  [__builtin_isfpclass(-0.0, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_nzero_2  [!__builtin_isfpclass(-0.0L, 0x0040) ? 1 : -1]; // fcPosZero
+char isfpclass_nzero_3  [!__builtin_isfpclass(-0.0, 0x0003) ? 1 : -1]; // fcNan
+char isfpclass_ndenorm_0[__builtin_isfpclass(-1.0e-40f, 0x0010) ? 1 : -1]; // fcNegSubnormal
+char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_ndenorm_2[!__builtin_isfpclass(-1.0e-40f, 0x03C0) ? 1 : -1]; // fcPositive
+char isfpclass_ndenorm_3[!__builtin_isfpclass(-1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+char isfpclass_neg_0[__builtin_isfpclass(-1.0, 0x0008) ? 1 : -1]; // fcNegNormal
+char isfpclass_neg_1[!__builtin_isfpclass(-1.0f, 0x00100) ? 1 : -1]; // fcPosNormal
+char isfpclass_neg_2[__builtin_isfpclass(-1.0L, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_neg_3[!__builtin_isfpclass(-1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan
+char isfpclass_inf_neg_0[__builtin_isfpclass(-__builtin_inf(), 0x0004) ? 1 : -1]; // fcNegInf
+char isfpclass_inf_neg_1[!__builtin_isfpclass(-__builtin_inff(), 0x0200) ? 1 : -1]; // fcPosInf
+char isf

[PATCH] D144999: [Clang][MC][MachO]Only emits compact-unwind format for "canonical" personality symbols. For the rest, use DWARFs.

2023-06-09 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo added a comment.

P.S This might have the same root-cause with the previous comment and could be 
fixed by D152540  as well.
(not able to repro the failures yet - don't have arm64 readily available, will 
test it later this evening. but on linux x86-64 and macos x86-64, ninja 
check-debuginfo passed for me)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144999

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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

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


[PATCH] D151683: [clang] Enable C++11-style attributes in all language modes

2023-06-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: beanz, clang-vendors.
aaron.ballman added a comment.

In D151683#4384017 , @erichkeane 
wrote:

> In D151683#4382408 , @philnik wrote:
>
>> No. I guess, since you are asking I should write one for this? Only for the 
>> removal of `-fdouble-square-bracket-attributes`, or also for back porting 
>> this?
>
> The RFC I would expect for "allow C/C++ style attributes as an extension in 
> previous modes".  This is a pretty significant feature to allow as an 
> extension, particularly since our two main alternative compilers (G++/MSVC) 
> don't have this as an extension. I'd be curious how the other C compilers do 
> this as well.

I think this does warrant an RFC because it impacts both C++ and C, but I'm 
hoping the RFC is uncontroversial. It's mostly to establish what the use cases 
are for needing the extension. The feature is conforming as an extension to 
both languages, and I don't know of any breakage that would come from enabling 
it by default. I'm not certain whether we want to remove the feature flag 
immediately or whether we'd like to give one release of warning about it being 
removed (I'll defer to whatever @MaskRay thinks is reasonable) -- that search 
is compelling for why it's safe to remove the option, but there's plenty of 
proprietary code which we don't know about, so it's possible the option is 
still used. I'd be especially curious to know if anyone is using 
`-fno-double-square-bracket-attributes` to disable the feature in a mode where 
it would otherwise be enabled. I'm adding the `clang-vendors` group as a 
subscriber as an early warning that removing the command line option could be a 
potentially breaking change.

In terms of implementation work, there's still some minor stuff to address. 
Also, please be sure to also add a release note about the changes, and a 
potentially breaking entry for removing the command line option (assuming we 
elect to go that route).




Comment at: clang/docs/LanguageExtensions.rst:1434
 Designated initializers (N494)  C99
   C89
 Array & element qualification (N2607)   C2x
   C89
+==  
= =

You need to add an entry here as well, as this also extends C.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:553
 def err_while_loop_outside_of_a_function : Error<
-  "while loop outside of a function">; 
+  "while loop outside of a function">;
 def err_brackets_go_after_unqualified_id : Error<

Spurious whitespace change.



Comment at: clang/include/clang/Driver/Options.td:3530
   Values<"none,cf,cf-nochecks">;
-def mcpu_EQ : Joined<["-"], "mcpu=">, Group, 
+def mcpu_EQ : Joined<["-"], "mcpu=">, Group,
   HelpText<"For a list of available CPUs for the target use '-mcpu=help'">;

Spurious whitespace change.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:1196
   // Add include/gpu-none-libc/* to our system include path. This lets us 
use
-  // GPU-specific system headers first. 
+  // GPU-specific system headers first.
   // TODO: We need to find a way to make these headers compatible with the

Spurious whitespace change.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:4477
   SourceLocation OpenLoc = Tok.getLocation();
-  Diag(OpenLoc, diag::warn_cxx98_compat_attribute);
+  Diag(OpenLoc, getLangOpts().CPlusPlus11 ? diag::warn_cxx98_compat_attribute
+: getLangOpts().CPlusPlus ? diag::warn_ext_cxx11_attributes

Missing the same "not compatible with standards before C2x" warning as for C++ 
(might want to reword the C++ warning at the same time to fit the newer style)



Comment at: clang/test/OpenMP/assumes_messages_attr.c:57
 [[omp::directive(begin assumes ext_abc)]];
-

Spurious removal.



Comment at: clang/test/Parser/asm.c:14
   asm("foo" : "=r" (a)); // expected-error {{use of undeclared identifier 'a'}}
-  asm("foo" : : "r" (b)); // expected-error {{use of undeclared identifier 
'b'}} 
+  asm("foo" : : "r" (b)); // expected-error {{use of undeclared identifier 
'b'}}
 

Spurious whitespace change



Comment at: clang/test/Parser/cxx-decl.cpp:316
 #if __cplusplus >= 201103L
-// expected-error@+3 {{expected}}
+// expected-error@+2 {{expected}}
 // expected-error@-3 {{expected ';' after top level declarator}}

Huh... I wasn't expecting to see a change here because there's no attribute 
nearby. Probably fine, but still a bit curious.



Comment at: clang/test/Parser/cxx-decl.cpp:322
 #endif
-

Spurious change.



Comm

[PATCH] D152412: [clang/test/CodeGen] Add test coverage for VarBypassDetector handling init statements and condition variables in switch clauses

2023-06-09 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb03abbb537e5: [clang/test/CodeGen] Add test coverage for 
VarBypassDetector handling init… (authored by dwang, committed by vitalybuka).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152412

Files:
  clang/test/CodeGen/lifetime3.cpp


Index: clang/test/CodeGen/lifetime3.cpp
===
--- /dev/null
+++ clang/test/CodeGen/lifetime3.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -S -emit-llvm -o - -O2 -disable-llvm-passes %s  | 
FileCheck %s --implicit-check-not="call void @llvm.lifetime" 
--check-prefixes=CHECK,O2
+// RUN: %clang_cc1 -S -emit-llvm -o - -O2 -disable-lifetime-markers %s | 
FileCheck %s --implicit-check-not="call void @llvm.lifetime" 
--check-prefixes=CHECK
+// RUN: %clang_cc1 -S -emit-llvm -o - -O0 %s   | 
FileCheck %s --implicit-check-not="call void @llvm.lifetime" 
--check-prefixes=CHECK 
+
+extern int bar(char *A, int n);
+
+// CHECK-LABEL: @no_switch_bypass
+extern "C" void no_switch_bypass(int n) {
+  // O2: call void @llvm.lifetime.start.p0(i64 4,
+  switch (n += 1; int b=n) {
+  case 1: {
+// O2: call void @llvm.lifetime.start.p0(i64 1,
+// O2: call void @llvm.lifetime.end.p0(i64 1,
+char x;
+bar(&x, 1);
+break;
+  }
+  case 2:
+n = n;
+// O2: call void @llvm.lifetime.start.p0(i64 5,
+// O2: call void @llvm.lifetime.end.p0(i64 5,
+char y[5];
+bar(y, 5);
+break;
+  }
+  // O2: call void @llvm.lifetime.end.p0(i64 4,
+}
+
+// CHECK-LABEL: @switch_bypass
+extern "C" void switch_bypass(int n) {
+  // O2: call void @llvm.lifetime.start.p0(i64 4,
+  // O2: call void @llvm.lifetime.end.p0(i64 4,
+  switch (n += 1; int b=n) {
+  case 1:
+n = n;
+char x;
+bar(&x, 1);
+break;
+  case 2:
+bar(&x, 1);
+break;
+  }
+}


Index: clang/test/CodeGen/lifetime3.cpp
===
--- /dev/null
+++ clang/test/CodeGen/lifetime3.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -S -emit-llvm -o - -O2 -disable-llvm-passes %s  | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK,O2
+// RUN: %clang_cc1 -S -emit-llvm -o - -O2 -disable-lifetime-markers %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK
+// RUN: %clang_cc1 -S -emit-llvm -o - -O0 %s   | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK 
+
+extern int bar(char *A, int n);
+
+// CHECK-LABEL: @no_switch_bypass
+extern "C" void no_switch_bypass(int n) {
+  // O2: call void @llvm.lifetime.start.p0(i64 4,
+  switch (n += 1; int b=n) {
+  case 1: {
+// O2: call void @llvm.lifetime.start.p0(i64 1,
+// O2: call void @llvm.lifetime.end.p0(i64 1,
+char x;
+bar(&x, 1);
+break;
+  }
+  case 2:
+n = n;
+// O2: call void @llvm.lifetime.start.p0(i64 5,
+// O2: call void @llvm.lifetime.end.p0(i64 5,
+char y[5];
+bar(y, 5);
+break;
+  }
+  // O2: call void @llvm.lifetime.end.p0(i64 4,
+}
+
+// CHECK-LABEL: @switch_bypass
+extern "C" void switch_bypass(int n) {
+  // O2: call void @llvm.lifetime.start.p0(i64 4,
+  // O2: call void @llvm.lifetime.end.p0(i64 4,
+  switch (n += 1; int b=n) {
+  case 1:
+n = n;
+char x;
+bar(&x, 1);
+break;
+  case 2:
+bar(&x, 1);
+break;
+  }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b03abbb - [clang/test/CodeGen] Add test coverage for VarBypassDetector handling init statements and condition variables in switch clauses

2023-06-09 Thread Vitaly Buka via cfe-commits

Author: Wang
Date: 2023-06-09T11:28:14-07:00
New Revision: b03abbb537e5403ab32f97e2ffcebafe4a92720d

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

LOG: [clang/test/CodeGen] Add test coverage for VarBypassDetector handling init 
statements and condition variables in switch clauses

[VarBypassDetector.cpp](https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/VarBypassDetector.cpp)
 lacks test coverage for handling init statements and condition variables in 
switch clauses, as is shown in:
https://lab.llvm.org/coverage/coverage-reports/coverage/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/VarBypassDetector.cpp.html#L70
This patch adds test coverage for uncovered lines.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D152412

Added: 
clang/test/CodeGen/lifetime3.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/lifetime3.cpp 
b/clang/test/CodeGen/lifetime3.cpp
new file mode 100644
index 0..37ed5f1938111
--- /dev/null
+++ b/clang/test/CodeGen/lifetime3.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -S -emit-llvm -o - -O2 -disable-llvm-passes %s  | 
FileCheck %s --implicit-check-not="call void @llvm.lifetime" 
--check-prefixes=CHECK,O2
+// RUN: %clang_cc1 -S -emit-llvm -o - -O2 -disable-lifetime-markers %s | 
FileCheck %s --implicit-check-not="call void @llvm.lifetime" 
--check-prefixes=CHECK
+// RUN: %clang_cc1 -S -emit-llvm -o - -O0 %s   | 
FileCheck %s --implicit-check-not="call void @llvm.lifetime" 
--check-prefixes=CHECK 
+
+extern int bar(char *A, int n);
+
+// CHECK-LABEL: @no_switch_bypass
+extern "C" void no_switch_bypass(int n) {
+  // O2: call void @llvm.lifetime.start.p0(i64 4,
+  switch (n += 1; int b=n) {
+  case 1: {
+// O2: call void @llvm.lifetime.start.p0(i64 1,
+// O2: call void @llvm.lifetime.end.p0(i64 1,
+char x;
+bar(&x, 1);
+break;
+  }
+  case 2:
+n = n;
+// O2: call void @llvm.lifetime.start.p0(i64 5,
+// O2: call void @llvm.lifetime.end.p0(i64 5,
+char y[5];
+bar(y, 5);
+break;
+  }
+  // O2: call void @llvm.lifetime.end.p0(i64 4,
+}
+
+// CHECK-LABEL: @switch_bypass
+extern "C" void switch_bypass(int n) {
+  // O2: call void @llvm.lifetime.start.p0(i64 4,
+  // O2: call void @llvm.lifetime.end.p0(i64 4,
+  switch (n += 1; int b=n) {
+  case 1:
+n = n;
+char x;
+bar(&x, 1);
+break;
+  case 2:
+bar(&x, 1);
+break;
+  }
+}



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


[PATCH] D152443: Add SpaceAfterOperatorKeyword & SpaceAfterOperatorKeywordInCall style options for clang-format

2023-06-09 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D152443#4407331 , @KitsuneAlex 
wrote:

> Applied all suggested changes and added a suiting option for aformentioned 
> edge-case for call expressions.
> Also added the missing release notes to the apropriate section.

Please mark comments as done, if you think they are done.




Comment at: clang/docs/ClangFormatStyleOptions.rst:4709
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 17` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the 'operator' keyword.

MyDeveloperDay wrote:
> could we use something like `SpaceAfterOperatorDeclaration` to differentiate
But it also applies to the definition?

Keyword seems to be wrong too, if we have a second option for the calls...

I currently have no recommendations for the naming.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4206
+  if (Left.Previous &&
+  Left.Previous->isOneOf(tok::coloncolon, tok::period)) {
+return Style.SpaceAfterOperatorKeywordInCall ||

`bool Foo::operator==() = default;`?

Please add a test. :)



Comment at: clang/unittests/Format/FormatTest.cpp:22915
+  verifyFormat("foo.Foo::operator==();", Style);
+  Style.SpaceAfterOperatorKeywordInCall = true;
+  verifyFormat("foo.operator ==();", Style);

Can you add an empty line, so that the 2 blocks are visually separated?



Comment at: clang/unittests/Format/FormatTest.cpp:22916
+  Style.SpaceAfterOperatorKeywordInCall = true;
+  verifyFormat("foo.operator ==();", Style);
+  verifyFormat("foo.Foo::operator ==();", Style);

MyDeveloperDay wrote:
> I assume I could have `foo->operator ==();`
Of course you can. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

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


[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-06-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/Interp.h:1560
+  // is the furthest we might go up in the hierarchy.
+  ThisPtr = ThisPtr.getDeclPtr();
+}

tbaeder wrote:
> I think this test case was from the function pointer review, but this fixes:
> ```
> struct S {
>   virtual constexpr int func() const { return 1; }
> };
> 
> struct Middle : S {
>   constexpr Middle(int i) : i(i) {}
>   int i;
> };
> 
> struct Other {
>   constexpr Other(int k) : k(k) {}
>   int k;
> };
> 
> struct S2 : Middle, Other {
>   int j;
>   constexpr S2(int i, int j, int k) : Middle(i), Other(k), j(j) {}
>   virtual constexpr int func() const { return i + j + k  + S::func(); }
> };
> 
> 
> constexpr S s;
> constexpr decltype(&S::func) foo = &S::func;
> constexpr S2 s2(1, 2, 3);
> constexpr int value3 = (s2.*foo)();
> ```
> 
> even I am confused by all of this now, so the comment might not be the 
> clearest :)
> 
> (I did not add that test case since it needs other changes in`classify()` and 
> `VisitBinaryOperator()`, but can do that in a follow-up commit.)
Please do add the example in a follow-up.



Comment at: clang/test/AST/Interp/records.cpp:650
+};
+#endif

We should also have test cases for calling virtual functions from within a 
constructor and a destructor, as that has special semantics. e.g., 
https://godbolt.org/z/snaj1zfM5


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

https://reviews.llvm.org/D142630

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


[PATCH] D152412: [clang/test/CodeGen] Add test coverage for VarBypassDetector handling init statements and condition variables in switch clauses

2023-06-09 Thread Duo Wang via Phabricator via cfe-commits
dwang added a comment.

@vitalybuka Thanks for the quick review!

I need help landing this since I do not have commit permission.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152412

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


[PATCH] D152561: [AST] Always set dependent-type for the CallExpr for error-recovery in C.

2023-06-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, though please add a release note about the fix. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152561

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


[PATCH] D149548: [IR] Update to use new shufflevector semantics

2023-06-09 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito added a comment.

In D149548#4405173 , @qiucf wrote:

> Why this changes IR output of following case?
>
>   // RUN: clang vecpromote.c -S -o - -O0 -target s390x-linux-gnu -fzvector 
> -emit-llvm
>   #include 
>   
>   vector int si;
>   int g;
>   int i;
>   
>   void foo() {
> si = vec_promote(g, i);
>   }
>   
>   // store <4 x i32> undef, ptr %__vec.i, align 16, !noalias !6  ; this undef 
> becomes poison after this patch
>   // %2 = load i32, ptr %__scalar.addr.i, align 4, !noalias !6
>   // %3 = load i32, ptr %__index.addr.i, align 4, !noalias !6
>   // %4 = load <4 x i32>, ptr %__vec.i, align 16, !noalias !6
>   // %vecins.i = insertelement <4 x i32> %4, i32 %2, i32 %and.i

I think it's because vec_promote is implemented in clang using a shufflevector 
with an undefined mask (-1). 
ConstantFold sees that we have a fully undefined mask and it folds the 
shufflevector to poison.(previously undef)
My concern : is it Ok to have the undefined values of the vector be poison or 
was the undef used to abide to some specific semantics?
Hope this makes sense.

> I see no PowerPC related case changes. Maybe adding SystemZ folks for 
> comments @uweigand @jonpa

My bad I pinged the wrong people, thanks for adding SystemZ folks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149548

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring createTargetData in OMPIRBuilder

2023-06-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1365
+  // possible, or else at the end of the function.
+  void EmitBlock(BasicBlock *BB, Function *CurFn, bool IsFinished = false);
+

why are these capitalized?



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4085
+omp::RuntimeFunction *MapperFunc,
+function_ref
+BodyGenCB) {

Can we not use an `int` for some "type". The 1 and 2 below are magic, use an 
enum and descriptive words.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4105
+// Emit the number of elements in the offloading arrays.
+llvm::Value *PointerNum = Builder.getInt32(Info.NumberOfPtrs);
 

No llvm::. Also elsewhere.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4727
+  Builder.ClearInsertionPoint();
+}
+

This function doesn't make sense to me. For one, I don't know what a "unreal 
block" is. Nor would I have expected a block with terminator to be silently not 
touched. It might just be a documentation issue (in the header). I would avoid 
duplicating the comment here again.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4785
+  EmitBlock(ContBlock, CurFn, /*IsFinished=*/true);
+}
+

CFG Utils have helpers for these things. Do we not use them on purpose?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D149872: [OpenMP][OMPIRBuilder] Migrate emitOffloadingArrays and EmitNonContiguousDescriptor from Clang

2023-06-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

If this passes all our tests, it looks fine. A few nits below, try to address 
if possible.




Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4427
+  M.getContext(), ArrayRef({Int64Ty, Int64Ty, Int64Ty}),
+  "struct.descriptor_dim");
+

If it helps, you can define the struct type in OMPKind.td, I think that's the 
name.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4487
+
+  if (Info.NumberOfPtrs) {
+Builder.restoreIP(AllocaIP);

Can we do an early exit here?



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4562
+Info.RTArgs.SizesArray = SizesArrayGbl;
+  }
+  Builder.restoreIP(CodeGenIP);

Generally try to have the "short" branch first, especially one liners.
People have forgotten the condition when they get here.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4618
+  if (Info.requiresDevicePointerInfo()) {
+assert(DeviceAddrCB);
+DeviceAddrCB(I, BP, BPVal);

Add a message to all asserts, please.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149872

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


[PATCH] D152561: [AST] Always set dependent-type for the CallExpr for error-recovery in C.

2023-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: aaron.ballman, sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

When build CallExpr for error-recovery where we have any dependent
child nodes), we should set a dependent type for CallExpr to avoid
running into some unexpected following semantic analysis.

This also aligns with the C++ behavior.

This fixes the symptom crashes: 
https://github.com/llvm/llvm-project/issues/50244


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152561

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.c


Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -93,7 +93,7 @@
   (*__builtin_classify_type)(1);
 
   extern void ext();
-  // CHECK: CallExpr {{.*}} 'void' contains-errors
+  // CHECK: CallExpr {{.*}} '' contains-errors
   // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext'
   // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
   ext(undef_var);
@@ -117,3 +117,12 @@
   // CHECK-NEXT: |   `-RecoveryExpr {{.*}} '' contains-errors
   if (__builtin_va_arg(undef, int) << 1);
 }
+
+void test6_GH50244() {
+  double array[16];
+  // CHECK:  UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' 
contains-errors sizeof
+  // CHECK-NEXT: `-CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT:   |-DeclRefExpr {{.*}} 'int ()'
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
+  sizeof array / sizeof foo(undef);
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7201,13 +7201,8 @@
 llvm::any_of(ArgExprs,
  [](clang::Expr *E) { return E->containsErrors(); })) 
&&
"should only occur in error-recovery path.");
-QualType ReturnType =
-llvm::isa_and_nonnull(NDecl)
-? cast(NDecl)->getCallResultType()
-: Context.DependentTy;
-return CallExpr::Create(Context, Fn, ArgExprs, ReturnType,
-Expr::getValueKindForType(ReturnType), RParenLoc,
-CurFPFeatureOverrides());
+return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
+VK_PRValue, RParenLoc, CurFPFeatureOverrides());
   }
   return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
ExecConfig, IsExecConfig);


Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -93,7 +93,7 @@
   (*__builtin_classify_type)(1);
 
   extern void ext();
-  // CHECK: CallExpr {{.*}} 'void' contains-errors
+  // CHECK: CallExpr {{.*}} '' contains-errors
   // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext'
   // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
   ext(undef_var);
@@ -117,3 +117,12 @@
   // CHECK-NEXT: |   `-RecoveryExpr {{.*}} '' contains-errors
   if (__builtin_va_arg(undef, int) << 1);
 }
+
+void test6_GH50244() {
+  double array[16];
+  // CHECK:  UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' contains-errors sizeof
+  // CHECK-NEXT: `-CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT:   |-DeclRefExpr {{.*}} 'int ()'
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
+  sizeof array / sizeof foo(undef);
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7201,13 +7201,8 @@
 llvm::any_of(ArgExprs,
  [](clang::Expr *E) { return E->containsErrors(); })) &&
"should only occur in error-recovery path.");
-QualType ReturnType =
-llvm::isa_and_nonnull(NDecl)
-? cast(NDecl)->getCallResultType()
-: Context.DependentTy;
-return CallExpr::Create(Context, Fn, ArgExprs, ReturnType,
-Expr::getValueKindForType(ReturnType), RParenLoc,
-CurFPFeatureOverrides());
+return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
+VK_PRValue, RParenLoc, CurFPFeatureOverrides());
   }
   return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
ExecConfig, IsExecConfig);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 530004.
paulkirth edited the summary of this revision.
paulkirth added reverted changes: rGd2627cf88d25: [clang-format] Add the 
KeepEmptyLinesAtEOF option, rG4b9764959dc4: [clang-format] Fix overlapping 
replacements before PPDirectives, D152305: [clang-format] Add the 
KeepEmptyLinesAtEOF option, D151954: [clang-format] Fix overlapping whitespace 
replacements before PPDirective.
paulkirth added a comment.

Rebase and update summary


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/test/Format/overlapping-lines.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12856,22 +12856,6 @@
"  void f() {}\n"
"};\n",
Style);
-  verifyFormat("struct foo {\n"
-   "#ifdef FOO\n"
-   "#else\n"
-   "private:\n"
-   "\n"
-   "#endif\n"
-   "};",
-   "struct foo {\n"
-   "#ifdef FOO\n"
-   "#else\n"
-   "private:\n"
-   "\n"
-   "\n"
-   "#endif\n"
-   "};",
-   Style);
 
   Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
   verifyFormat("struct foo {\n"
@@ -25744,15 +25728,6 @@
   verifyFormat("int i;\n", "int i;", Style);
 }
 
-TEST_F(FormatTest, KeepEmptyLinesAtEOF) {
-  FormatStyle Style = getLLVMStyle();
-  Style.KeepEmptyLinesAtEOF = true;
-
-  const StringRef Code{"int i;\n\n"};
-  verifyFormat(Code, Code, Style);
-  verifyFormat(Code, "int i;\n\n\n", Style);
-}
-
 TEST_F(FormatTest, SpaceAfterUDL) {
   verifyFormat("auto c = (4s).count();");
   verifyFormat("auto x = 5s .count() == 5;");
@@ -25765,6 +25740,18 @@
"}");
 }
 
+TEST_F(FormatTest, PreprocessorOverlappingRegions) {
+  verifyFormat("#ifdef\n\n"
+   "#else\n"
+   "#endif\n",
+   "#ifdef \n"
+   "\n"
+   "\n"
+   "#else \n"
+   "#endif \n",
+   getGoogleStyle());
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -167,7 +167,6 @@
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
   CHECK_PARSE_BOOL(InsertBraces);
   CHECK_PARSE_BOOL(InsertNewlineAtEOF);
-  CHECK_PARSE_BOOL(KeepEmptyLinesAtEOF);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
Index: clang/test/Format/overlapping-lines.cpp
===
--- /dev/null
+++ clang/test/Format/overlapping-lines.cpp
@@ -0,0 +1,8 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | FileCheck %s 
+// CHECK-NOT: The new replacement overlaps with an existing replacement.
+
+#ifdef 
+
+
+#else 
+#endif 
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,12 +1418,19 @@
   return Penalty;
 }
 
-static auto newlinesBeforeLine(const AnnotatedLine &Line,
-   const AnnotatedLine *PreviousLine,
-   const AnnotatedLine *PrevPrevLine,
-   const SmallVectorImpl &Lines,
-   const FormatStyle &Style) {
-  const auto &RootToken = *Line.First;
+void UnwrappedLineFormatter::formatFirstToken(
+const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
+const SmallVectorImpl &Lines, unsigned Indent,
+unsigned NewlineIndent) {
+  FormatToken &RootToken = *Line.First;
+  if (RootToken.is(tok::eof)) {
+unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u);
+unsigned TokenIndent = Newlines ? NewlineIndent : 0;
+Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
+   TokenIndent);
+return;
+  }
   unsigned Newlines =
   std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
   // Remove empty lines before "}" where applicable.
@@ -1503,29 +1510,6 @@
 }
   }
 
-  return Newlines;
-}
-
-void UnwrappedLineF

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1279
+  if (isa(E))
+return nullptr;
+

efriedma wrote:
> This needs a comment explaining why we're bailing out here.
We might need to do a recursive visit still, to handle the cases noted at 
https://en.cppreference.com/w/cpp/language/reference_initialization#Lifetime_of_a_temporary
 .  Not constructors, but other things.  I think we don't have existing 
testcases, but for example `typedef int x[2]; struct Z { int &&x, y; }; Z z = { 
x{1,2}[0], z.x=10 };`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-09 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 52.
paulkirth added a comment.

Revert patches introducing regression & add unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152473

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/test/Format/overlapping-lines.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12856,22 +12856,6 @@
"  void f() {}\n"
"};\n",
Style);
-  verifyFormat("struct foo {\n"
-   "#ifdef FOO\n"
-   "#else\n"
-   "private:\n"
-   "\n"
-   "#endif\n"
-   "};",
-   "struct foo {\n"
-   "#ifdef FOO\n"
-   "#else\n"
-   "private:\n"
-   "\n"
-   "\n"
-   "#endif\n"
-   "};",
-   Style);
 
   Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
   verifyFormat("struct foo {\n"
@@ -25744,15 +25728,6 @@
   verifyFormat("int i;\n", "int i;", Style);
 }
 
-TEST_F(FormatTest, KeepEmptyLinesAtEOF) {
-  FormatStyle Style = getLLVMStyle();
-  Style.KeepEmptyLinesAtEOF = true;
-
-  const StringRef Code{"int i;\n\n"};
-  verifyFormat(Code, Code, Style);
-  verifyFormat(Code, "int i;\n\n\n", Style);
-}
-
 TEST_F(FormatTest, SpaceAfterUDL) {
   verifyFormat("auto c = (4s).count();");
   verifyFormat("auto x = 5s .count() == 5;");
@@ -25765,6 +25740,18 @@
"}");
 }
 
+TEST_F(FormatTest, PreprocessorOverlappingRegions) {
+  verifyFormat("#ifdef\n\n"
+   "#else\n"
+   "#endif\n",
+   "#ifdef \n"
+   "\n"
+   "\n"
+   "#else \n"
+   "#endif \n",
+   getGoogleStyle());
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -167,7 +167,6 @@
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
   CHECK_PARSE_BOOL(InsertBraces);
   CHECK_PARSE_BOOL(InsertNewlineAtEOF);
-  CHECK_PARSE_BOOL(KeepEmptyLinesAtEOF);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
Index: clang/test/Format/overlapping-lines.cpp
===
--- /dev/null
+++ clang/test/Format/overlapping-lines.cpp
@@ -0,0 +1,8 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format --style=Google 2>&1 | FileCheck %s 
+// CHECK-NOT: The new replacement overlaps with an existing replacement.
+
+#ifdef 
+
+
+#else 
+#endif 
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,12 +1418,19 @@
   return Penalty;
 }
 
-static auto newlinesBeforeLine(const AnnotatedLine &Line,
-   const AnnotatedLine *PreviousLine,
-   const AnnotatedLine *PrevPrevLine,
-   const SmallVectorImpl &Lines,
-   const FormatStyle &Style) {
-  const auto &RootToken = *Line.First;
+void UnwrappedLineFormatter::formatFirstToken(
+const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
+const SmallVectorImpl &Lines, unsigned Indent,
+unsigned NewlineIndent) {
+  FormatToken &RootToken = *Line.First;
+  if (RootToken.is(tok::eof)) {
+unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u);
+unsigned TokenIndent = Newlines ? NewlineIndent : 0;
+Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
+   TokenIndent);
+return;
+  }
   unsigned Newlines =
   std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
   // Remove empty lines before "}" where applicable.
@@ -1503,29 +1510,6 @@
 }
   }
 
-  return Newlines;
-}
-
-void UnwrappedLineFormatter::formatFirstToken(
-const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
-const AnnotatedLine *PrevPrevLine,
-const SmallVectorImpl &Lines, unsigned Indent,
-unsigned NewlineIndent) {
-  FormatToken &RootToken = *Line.First;
-  if (RootToken.is(tok::eof)) {
-unsigned Newlines =
-std::min(RootToken.Newl

[PATCH] D152554: [OpenMP] Migrate deviice code privatization from Clang CodeGen to OMPIRBuilder

2023-06-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:7170-7234
+const llvm::Value *DevPtr = nullptr;
 
 // In order to identify the right initializer we need to match the
 // declaration used by the mapping logic. In some cases we may get
 // OMPCapturedExprDecl that refers to the original declaration.
-const ValueDecl *MatchingVD = OrigVD;
-if (const auto *OED = dyn_cast(MatchingVD)) {
+if (const auto *OED = dyn_cast(OrigVD)) {
   // OMPCapturedExprDecl are used to privative fields of the current

Currently clang maintains a map between Clang::ValueDecl and corresponding 
address in Info.CaptureDeviceAddrMap.

Please see the EmitOMPUseDeviceAddrClause function just below this to see how 
it does so.

I would however like to get rid of this map as it allows us to then get rid of 
another map in the MapInfosTy and a clang specific callback for maintaining 
these maps..

This map is only used to retain the mapping between a ValueDecl inside a map 
clause to its corresponding llvm address.

The highlighted code here tries to retrieve this llvm address back from the 
ValueDecl without using the map, but as you can it is a very hacky way of doing 
so. But my intuition says that there must be a much simpler method of 
retrieving this address as Clang must be storing it in some way in order for it 
to generate code.

It would be great if someone with more experience in Clang codegen could help 
me achieve this. 

Also I am aware that I am probably doing a very poor job at explaining this. 
Please let me know if you have any questions or would like me to try and 
explain it with more clarity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152554

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


[PATCH] D144999: [Clang][MC][MachO]Only emits compact-unwind format for "canonical" personality symbols. For the rest, use DWARFs.

2023-06-09 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo added a comment.

In D144999#4409149 , @Michael137 
wrote:

> In D144999#4408248 , @Michael137 
> wrote:
>
>> Looks like the latest reland of this patch 
>> (`e60b30d5e3878e7d91f8872ec4c4dca00d4a2dfc`) broke some debug-info 
>> `cross-project-tests` on the Arm64 macOS buildbots: 
>> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-as/263/execution/node/54/log/
>>
>>   Failed Tests (2):
>> cross-project-tests :: debuginfo-tests/dexter-tests/optnone-fastmath.cpp
>> cross-project-tests :: 
>> debuginfo-tests/dexter-tests/optnone-struct-and-methods.cpp
>>
>> You can run those tests by adding `cross-project-tests` to 
>> `LLVM_ENABLE_PROJECTS` and running `ninja check-debuginfo`.
>>
>> AFAICT, it also broke following LLDB test 
>> (https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-as/263/execution/node/65/log/):
>>
>>   Failed Tests (1):
>> lldb-api :: functionalities/step-avoids-no-debug/TestStepNoDebug.py
>>
>> Let me know if you need help reproducing this
>
> Mind taking a look or reverting the patch until the tests pass?

Yes - having a look now - wasn't able to repro the test failure before because 
the build broke at HEAD:

  /mnt/ssd/repo/llvm-project/llvm/include/llvm/CodeGen/RDFRegisters.h: In 
member function ‘constexpr size_t llvm::rdf::RegisterRef::hash() const’:
  /mnt/ssd/repo/llvm-project/llvm/include/llvm/CodeGen/RDFRegisters.h:92:35: 
error: call to non-‘constexpr’ function ‘std::size_t std::hash::operator()(unsigned int) const’
 92 | return std::hash{}(Reg) ^
|~~~^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144999

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


[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

Please use clang-format on the modified lines.




Comment at: clang/lib/CodeGen/CGBuilder.h:170
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,
const llvm::Twine &Name = "") {
+return Address(Addr.getPointer(), Ty,

The argument can be removed.

Idea for a follow-up: I would also consider removing this method because it 
does not do what its name says.
Maybe replace it with `Address::withElementType` analagous to 
`Address::withPointer` / `Address::withAlignment`?




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:9351
   // Implement the index operand if not omitted.
   if (Ops.size() > 3) {
 BasePtr = Builder.CreateGEP(MemoryTy, BasePtr, Ops[2]);

Braces are now redundant.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:238-240
   CharPtrTy = llvm::PointerType::getUnqual(Types.ConvertType(Ctx.CharTy));
   VoidPtrTy = cast(Types.ConvertType(Ctx.VoidPtrTy));
+  VoidPtrPtrTy = llvm::PointerType::get(CGM.getLLVMContext(), 0);

These are all the same types. Replace the variables with single `PtrTy`?




Comment at: clang/lib/CodeGen/CGCUDANV.cpp:272
   auto *RegisterGlobalsFnTy = getRegisterGlobalsFnTy();
-  llvm::Type *Params[] = {RegisterGlobalsFnTy->getPointerTo(), VoidPtrTy,
-  VoidPtrTy, CallbackFnTy->getPointerTo()};
+  llvm::Type *Params[] = {llvm::PointerType::getUnqual(RegisterGlobalsFnTy), 
VoidPtrTy,
+  VoidPtrTy, llvm::PointerType::get(Context, 0)};

Pass Context



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:540
   VoidPtrPtrTy, CharPtrTy, CharPtrTy, CharPtrTy, IntTy,
-  VoidPtrTy,VoidPtrTy, VoidPtrTy, VoidPtrTy, IntTy->getPointerTo()};
+  VoidPtrTy,VoidPtrTy, VoidPtrTy, VoidPtrTy, 
llvm::PointerType::getUnqual(IntTy)};
   llvm::FunctionCallee RegisterFunc = CGM.CreateRuntimeFunction(

Pass Context



Comment at: clang/lib/CodeGen/CGCXX.cpp:175
   // Create the alias with no name.
+  llvm::Type *AliasValueType = getTypes().GetFunctionType(AliasDecl);
   auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",

This looks wrong. It used to be `GetFunctionType(TargetDecl)`.




Comment at: clang/lib/CodeGen/CGCXX.cpp:184
   if (Entry) {
-assert(Entry->getType() == AliasType &&
+assert(Entry->getValueType() == AliasValueType &&
+   Entry->getAddressSpace() == Alias->getAddressSpace() &&

What's the reason for this change?



Comment at: clang/lib/CodeGen/CGException.cpp:2117
+  llvm::Type *PtrTy = llvm::PointerType::get(getLLVMContext(), 0);
+  llvm::Type *PtrsTy = llvm::StructType::get(PtrTy, CGM.VoidPtrTy);
+  llvm::Value *Rec = Builder.CreateStructGEP(PtrsTy, SEHInfo, 0);

I guess this was intended to be named `RecordTy`.




Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1945-1949
   if (TypeInfoLValue TI = base.dyn_cast()) {
-llvm::Type *StdTypeInfoPtrTy =
-CGM.getTypes().ConvertType(base.getTypeInfoType())->getPointerTo();
 llvm::Constant *TypeInfo =
 CGM.GetAddrOfRTTIDescriptor(QualType(TI.getType(), 0));
-if (TypeInfo->getType() != StdTypeInfoPtrTy)
-  TypeInfo = llvm::ConstantExpr::getBitCast(TypeInfo, StdTypeInfoPtrTy);
 return TypeInfo;
   }





Comment at: clang/lib/CodeGen/CGObjCRuntime.cpp:373
 llvm::PointerType *signatureType =
-  CGM.getTypes().GetFunctionType(signature)->getPointerTo(ProgramAS);
+  llvm::PointerType::get(CGM.getTypes().GetFunctionType(signature),
+ ProgramAS);

Pass context here



Comment at: clang/lib/CodeGen/CGObjCRuntime.cpp:388
   llvm::PointerType *signatureType =
-CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo(ProgramAS);
+llvm::PointerType::get(CGM.getTypes().GetFunctionType(argsInfo),
+   ProgramAS);

Pass context here.
Can also be moved above `if`.




Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:816-818
   llvm::Value *Addr = Builder.CreateInBoundsGEP(
   Base.getElementType(), Base.getPointer(), MemPtr, "memptr.offset");
+  return Addr;





Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1924-1927
   llvm::Value *Load = CGF.Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
   {VTable, llvm::ConstantInt::get(CGM.Int32Ty, 4 * VTableIndex)});
+  VFuncLoad = Load;





Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2552-2554
   auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
-  auto AddrInt8PtrTy =
-  AddrAS ? CGF.Int8Ty->getPointerTo(AddrAS) : CGF.

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1279
+  if (isa(E))
+return nullptr;
+

This needs a comment explaining why we're bailing out here.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1664
 
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a 
temporary,

You can probably delete this FIXME comment.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1670
   // desired value of the referee.
-  if (destType->isReferenceType())
-return nullptr;
+  if (!destType->isLValueReferenceType()) {
+QualType nonMemoryDestType = getNonMemoryType(CGM, destType);

Why are you changing this to "isLValueReferenceType"?  I think rvalue 
references need to be handled basically the same way as lvalue references.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D152554: [OpenMP] Migrate deviice code privatization from Clang CodeGen to OMPIRBuilder

2023-06-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added reviewers: jsjodin, jdoerfert, kiranktp.
Herald added subscribers: sunshaoce, guansong, hiraditya, yaxunl.
Herald added a project: All.
TIFitis requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

This patch migrats the UseDevicePtr and UseDeviceAddr clause related code for 
handling privatization from Clang codegen to the OMPIRBuilder

Depends on D150860 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152554

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4086,7 +4086,7 @@
 omp::RuntimeFunction *MapperFunc,
 function_ref
 BodyGenCB,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
@@ -4129,6 +4129,14 @@
 
   Builder.CreateCall(beginMapperFunc, OffloadingArgs);
 
+  for (auto DeviceMap : Info.DevicePtrInfoMap) {
+if (isa(DeviceMap.second.second)) {
+  auto *LI =
+  Builder.CreateLoad(Builder.getPtrTy(), DeviceMap.second.first);
+  Builder.CreateStore(LI, DeviceMap.second.second);
+}
+  }
+
   // If device pointer privatization is required, emit the body of the
   // region here. It will have to be duplicated: with and without
   // privatization.
@@ -4541,7 +4549,7 @@
 void OpenMPIRBuilder::emitOffloadingArrays(
 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
 TargetDataInfo &Info, bool IsNonContiguous,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB) {
 
   // Reset the array information.
@@ -4679,8 +4687,19 @@
   M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
 
   if (Info.requiresDevicePointerInfo()) {
-assert(DeviceAddrCB);
-DeviceAddrCB(I, BP, BPVal);
+if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Pointer) {
+  CodeGenIP = Builder.saveIP();
+  Builder.restoreIP(AllocaIP);
+  Info.DevicePtrInfoMap[BPVal] = {
+  BP, Builder.CreateAlloca(Builder.getPtrTy())};
+  Builder.restoreIP(CodeGenIP);
+  assert(DeviceAddrCB);
+  DeviceAddrCB(I, Info.DevicePtrInfoMap[BPVal].second);
+} else if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Address) {
+  Info.DevicePtrInfoMap[BPVal] = {BP, BP};
+  assert(DeviceAddrCB);
+  DeviceAddrCB(I, BP);
+}
   }
 
   Value *PVal = CombinedInfo.Pointers[I];
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1564,6 +1564,9 @@
   public:
 TargetDataRTArgs RTArgs;
 
+SmallMapVector, 4>
+DevicePtrInfoMap;
+
 /// Indicate whether any user-defined mapper exists.
 bool HasMapper = false;
 /// The total number of pointers passed to the runtime library.
@@ -1590,7 +1593,9 @@
 bool separateBeginEndCalls() { return SeparateBeginEndCalls; }
   };
 
+  enum class DeviceInfoTy { None, Pointer, Address };
   using MapValuesArrayTy = SmallVector;
+  using MapDeviceInfoArrayTy = SmallVector;
   using MapFlagsArrayTy = SmallVector;
   using MapNamesArrayTy = SmallVector;
   using MapDimArrayTy = SmallVector;
@@ -1609,6 +1614,7 @@
 };
 MapValuesArrayTy BasePointers;
 MapValuesArrayTy Pointers;
+MapDeviceInfoArrayTy DevicePointers;
 MapValuesArrayTy Sizes;
 MapFlagsArrayTy Types;
 MapNamesArrayTy Names;
@@ -1619,6 +1625,8 @@
   BasePointers.append(CurInfo.BasePointers.begin(),
   CurInfo.BasePointers.end());
   Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
+  DevicePointers.append(CurInfo.DevicePointers.begin(),
+CurInfo.DevicePointers.end());
   Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
   Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
   Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
@@ -1655,7 +1663,7 @@
   void emitOffloadingArrays(
   InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
   TargetDataInfo &Info, bool IsNonContiguous = false,
-  function_ref DeviceAddrCB = nullptr,
+  function

  1   2   >