[clang-tools-extra] [clangd] Use StringRef::consume_back_insensitive (NFC) (PR #139456)

2025-05-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clangd

@llvm/pr-subscribers-clang-tools-extra

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clangd/CompileCommands.cpp (+1-2) 


``diff
diff --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 207e4c3e6722c..808d8998db4a8 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -404,8 +404,7 @@ enum DriverMode : unsigned char {
 DriverMode getDriverMode(const std::vector &Args) {
   DriverMode Mode = DM_GCC;
   llvm::StringRef Argv0 = Args.front();
-  if (Argv0.ends_with_insensitive(".exe"))
-Argv0 = Argv0.drop_back(strlen(".exe"));
+  Argv0.consume_back_insensitive(".exe");
   if (Argv0.ends_with_insensitive("cl"))
 Mode = DM_CL;
   for (const llvm::StringRef Arg : Args) {

``




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


[clang-tools-extra] [clangd] Use StringRef::consume_back_insensitive (NFC) (PR #139456)

2025-05-11 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/139456

None



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] [Driver] Use StringRef::substr instead of StringRef::slice (NFC) (PR #139455)

2025-05-11 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/139455

StringRef::substr is shorter here because we can rely on its default
second parameter.


>From 4954a82909003f320866106a140efbc0757da707 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 11 May 2025 07:54:17 -0700
Subject: [PATCH] [Driver] Use StringRef::substr instead of StringRef::slice
 (NFC)

StringRef::substr is shorter here because we can rely on its default
second parameter.
---
 clang/lib/Driver/Job.cpp   | 2 +-
 clang/lib/Driver/ToolChain.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index f676b12c99a24..880e9e396c41e 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -184,7 +184,7 @@ rewriteIncludes(const llvm::ArrayRef &Args, 
size_t Idx,
 StringRef FlagRef(Args[Idx + NumArgs - 1]);
 assert((FlagRef.starts_with("-F") || FlagRef.starts_with("-I")) &&
"Expecting -I or -F");
-StringRef Inc = FlagRef.slice(2, StringRef::npos);
+StringRef Inc = FlagRef.substr(2);
 if (getAbsPath(Inc, NewInc)) {
   SmallString<128> NewArg(FlagRef.slice(0, 2));
   NewArg += NewInc;
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 3c52abb0ab78e..664aafad0f680 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1441,7 +1441,7 @@ std::string ToolChain::detectLibcxxVersion(StringRef 
IncludePath) const {
 StringRef VersionText = llvm::sys::path::filename(LI->path());
 int Version;
 if (VersionText[0] == 'v' &&
-!VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
+!VersionText.substr(1).getAsInteger(10, Version)) {
   if (Version > MaxVersion) {
 MaxVersion = Version;
 MaxVersionString = std::string(VersionText);

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


[clang] [Driver] Use StringRef::substr instead of StringRef::slice (NFC) (PR #139455)

2025-05-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

StringRef::substr is shorter here because we can rely on its default
second parameter.


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


2 Files Affected:

- (modified) clang/lib/Driver/Job.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChain.cpp (+1-1) 


``diff
diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index f676b12c99a24..880e9e396c41e 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -184,7 +184,7 @@ rewriteIncludes(const llvm::ArrayRef &Args, 
size_t Idx,
 StringRef FlagRef(Args[Idx + NumArgs - 1]);
 assert((FlagRef.starts_with("-F") || FlagRef.starts_with("-I")) &&
"Expecting -I or -F");
-StringRef Inc = FlagRef.slice(2, StringRef::npos);
+StringRef Inc = FlagRef.substr(2);
 if (getAbsPath(Inc, NewInc)) {
   SmallString<128> NewArg(FlagRef.slice(0, 2));
   NewArg += NewInc;
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 3c52abb0ab78e..664aafad0f680 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1441,7 +1441,7 @@ std::string ToolChain::detectLibcxxVersion(StringRef 
IncludePath) const {
 StringRef VersionText = llvm::sys::path::filename(LI->path());
 int Version;
 if (VersionText[0] == 'v' &&
-!VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
+!VersionText.substr(1).getAsInteger(10, Version)) {
   if (Version > MaxVersion) {
 MaxVersion = Version;
 MaxVersionString = std::string(VersionText);

``




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


[clang] [clang] Enforce 1-based indexing for command line source locations (PR #139457)

2025-05-11 Thread Naveen Seth Hanig via cfe-commits

https://github.com/naveen-seth created 
https://github.com/llvm/llvm-project/pull/139457

Fixes #139375

Clang expects command line source locations to be provided using 1-based 
indexing.
Currently, Clang does not reject zero as invalid argument for column or line 
number, which can cause Clang to crash.

This commit extends validation in `ParsedSourceLocation::FromString` to only 
accept (unsinged) non-zero integers.



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang-tools-extra] [clangd] Use StringRef::consume_back_insensitive (NFC) (PR #139456)

2025-05-11 Thread Nikita Popov via cfe-commits

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


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


[clang] [clang-cl] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--precompile` (PR #121046)

2025-05-11 Thread via cfe-commits


@@ -6097,10 +6097,29 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
   }
 
   llvm::PrettyStackTraceString CrashInfo("Computing output path");
+
   // Output to a user requested destination?
   if (AtTopLevel && !isa(JA) && !isa(JA)) {
-if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+bool IsCLNonPCH =
+IsCLMode() && !C.getArgs().hasArg(options::OPT__SLASH_Yc) &&
+(isa(JA) || isa(JA));
+bool HasAnyOutputArg = C.getArgs().hasArg(
+options::OPT_o, options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON);

cor3ntin wrote:

@sharadhr ping

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


[clang] [clang] Enforce 1-based indexing for command line source locations (PR #139457)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Naveen Seth Hanig (naveen-seth)


Changes

Fixes #139375

Clang expects command line source locations to be provided using 1-based 
indexing.
Currently, Clang does not reject zero as invalid argument for column or line 
number, which can cause Clang to crash.

This commit extends validation in `ParsedSourceLocation::FromString` to only 
accept (unsinged) non-zero integers.

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


2 Files Affected:

- (modified) clang/include/clang/Frontend/CommandLineSourceLoc.h (+4-1) 
- (added) clang/test/CodeCompletion/crash-if-zero-index.cpp (+6) 


``diff
diff --git a/clang/include/clang/Frontend/CommandLineSourceLoc.h 
b/clang/include/clang/Frontend/CommandLineSourceLoc.h
index 074800a881a89..a412d41dbb023 100644
--- a/clang/include/clang/Frontend/CommandLineSourceLoc.h
+++ b/clang/include/clang/Frontend/CommandLineSourceLoc.h
@@ -24,7 +24,9 @@ namespace clang {
 /// A source location that has been parsed on the command line.
 struct ParsedSourceLocation {
   std::string FileName;
+  // The 1-based line number
   unsigned Line;
+  // The 1-based column number
   unsigned Column;
 
 public:
@@ -38,7 +40,8 @@ struct ParsedSourceLocation {
 
 // If both tail splits were valid integers, return success.
 if (!ColSplit.second.getAsInteger(10, PSL.Column) &&
-!LineSplit.second.getAsInteger(10, PSL.Line)) {
+!LineSplit.second.getAsInteger(10, PSL.Line) &&
+!(PSL.Column == 0 || PSL.Line == 0)) {
   PSL.FileName = std::string(LineSplit.first);
 
   // On the command-line, stdin may be specified via "-". Inside the
diff --git a/clang/test/CodeCompletion/crash-if-zero-index.cpp 
b/clang/test/CodeCompletion/crash-if-zero-index.cpp
new file mode 100644
index 0..2f0eae35738e6
--- /dev/null
+++ b/clang/test/CodeCompletion/crash-if-zero-index.cpp
@@ -0,0 +1,6 @@
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:0:1 %s -o -
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:1:0 %s -o -
+
+// Related to #139375
+// Clang uses 1-based indexing for source locations given from the 
command-line.
+// Verify Clang doesn’t crash when 0 is given as line or column number.

``




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


[clang] [Driver] Use StringRef::substr instead of StringRef::slice (NFC) (PR #139455)

2025-05-11 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang] Enforce 1-based indexing for command line source locations (PR #139457)

2025-05-11 Thread via cfe-commits


@@ -0,0 +1,6 @@
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:0:1 %s -o -
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:1:0 %s -o -
+
+// Related to #139375
+// Clang uses 1-based indexing for source locations given from the 
command-line.
+// Verify Clang doesn’t crash when 0 is given as line or column number.

cor3ntin wrote:

Can you add a test using FileCheck that we produce a diagnostic?

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


[clang] 918cdae - [TableGen] Use StringRef::substr instead of StringRef::slice (NFC) (#139485)

2025-05-11 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-11T19:09:25-07:00
New Revision: 918cdaef52e73b3884cf380362199765bed4e566

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

LOG: [TableGen] Use StringRef::substr instead of StringRef::slice (NFC) 
(#139485)

StringRef::substr is shorter here because we can rely on its default
second parameter.

Added: 


Modified: 
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index e72288801a830..e347b89a85d46 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1089,7 +1089,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
 
 if (End) {
   Parsed.push_back(New(Text.slice(0, End), "diagtext"));
-  Text = Text.slice(End, StringRef::npos);
+  Text = Text.substr(End);
   if (Text.empty())
 break;
 }
@@ -1103,7 +1103,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
 // Extract the (optional) modifier.
 size_t ModLength = Text.find_first_of("0123456789<{");
 StringRef Modifier = Text.slice(0, ModLength);
-Text = Text.slice(ModLength, StringRef::npos);
+Text = Text.substr(ModLength);
 ModifierType ModType = StringSwitch{Modifier}
.Case("select", MT_Select)
.Case("enum_select", MT_EnumSelect)
@@ -1154,7 +1154,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
   Text = Text.drop_front(); // Drop '<'
   size_t EnumNameLen = Text.find_first_of('>');
   EnumSelect->EnumName = Text.slice(0, EnumNameLen);
-  Text = Text.slice(EnumNameLen, StringRef::npos);
+  Text = Text.substr(EnumNameLen);
   ExpectAndConsume(">");
 
   if (Text[0] != '{')
@@ -1169,7 +1169,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
   Text = Text.drop_front(); // '%'
   size_t OptionNameLen = Text.find_first_of("{");
   EnumSelect->OptionEnumNames.push_back(Text.slice(0, OptionNameLen));
-  Text = Text.slice(OptionNameLen, StringRef::npos);
+  Text = Text.substr(OptionNameLen);
 } else {
   EnumSelect->OptionEnumNames.push_back({});
 }
@@ -1206,7 +1206,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
 assert(!Text.empty());
 Plural->OptionPrefixes.push_back(
 New(Text.slice(0, End), "diagtext"));
-Text = Text.slice(End, StringRef::npos);
+Text = Text.substr(End);
 Plural->Options.push_back(
 parseDiagText(Text, StopAt::PipeOrCloseBrace));
 assert(!Text.empty() && "malformed %plural");



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


[clang] [TableGen] Use StringRef::substr instead of StringRef::slice (NFC) (PR #139485)

2025-05-11 Thread Kazu Hirata via cfe-commits

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


[clang] [clang] Include for size_t (PR #139496)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Takuto Ikuta (atetubou)


Changes

This is to fix Clang module build in chromium.

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


1 Files Affected:

- (modified) clang/lib/Headers/mm_malloc.h (+2) 


``diff
diff --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index d32fe59416277..dec91fc3f720a 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -15,6 +15,8 @@
 #ifdef _WIN32
 #include 
 #else
+#include 
+
 #ifndef __cplusplus
 extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
 #else

``




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


[clang] [clang] Include for size_t (PR #139496)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Takuto Ikuta (atetubou)


Changes

This is to fix Clang module build in chromium.

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


1 Files Affected:

- (modified) clang/lib/Headers/mm_malloc.h (+2) 


``diff
diff --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index d32fe59416277..dec91fc3f720a 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -15,6 +15,8 @@
 #ifdef _WIN32
 #include 
 #else
+#include 
+
 #ifndef __cplusplus
 extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
 #else

``




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


[clang] [clang] Include for size_t (PR #139496)

2025-05-11 Thread Takuto Ikuta via cfe-commits

https://github.com/atetubou created 
https://github.com/llvm/llvm-project/pull/139496

This is to fix Clang module build in chromium.

>From d0e83133ff408270adb1e477f1b32e2e39a469c4 Mon Sep 17 00:00:00 2001
From: Takuto Ikuta 
Date: Mon, 12 May 2025 14:36:35 +0900
Subject: [PATCH] [clang] Include  for size_t

This is to fix Clang module build in chromium.
---
 clang/lib/Headers/mm_malloc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index d32fe59416277..dec91fc3f720a 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -15,6 +15,8 @@
 #ifdef _WIN32
 #include 
 #else
+#include 
+
 #ifndef __cplusplus
 extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
 #else

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


[clang] [C] Handle comma operator for implicit int->enum conversions (PR #138752)

2025-05-11 Thread Mikael Holmén via cfe-commits

mikaelholmen wrote:

Hi @AaronBallman

I see that if I build clang with ASAN with this patch and run the testcase
```clang/test/C/C99/n590.c```
it crashes and I see this

```
AddressSanitizer:DEADLYSIGNAL
=
==2063954==ERROR: AddressSanitizer: SEGV on unknown address 0xb5c8001f7e52 (pc 
0x7fe2bd0e8baf bp 0x7fe2bd718370 sp 0x7fe2bd7181a0 T0)
==2063954==The signal is caused by a WRITE memory access.
#0 0x7fe2bd0e8baf in raise (/lib64/libpthread.so.0+0x12baf) (BuildId: 
1962602ac5dc3011b6d697b38b05ddc244197114)
#1 0x5610e162f93e in SignalHandler(int, siginfo_t*, void*) 
/repo/llvm/build-all-bbisdk-asan/../lib/Support/Unix/Signals.inc
#2 0x7fe2bd0e8d0f  (/lib64/libpthread.so.0+0x12d0f) (BuildId: 
1962602ac5dc3011b6d697b38b05ddc244197114)
#3 0x5610e888912a in AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, 
clang::SourceLocation, bool) 
/repo/llvm/build-all-bbisdk-asan/../../clang/lib/Sema/SemaChecking.cpp:12638
#4 0x5610e888a70b in CheckCommaOperand 
/repo/llvm/build-all-bbisdk-asan/../../clang/lib/Sema/SemaChecking.cpp:11653:3
#5 0x5610e888a70b in AnalyzeImplicitConversions 
/repo/llvm/build-all-bbisdk-asan/../../clang/lib/Sema/SemaChecking.cpp:12510:7
#6 0x5610e888a70b in AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, 
clang::SourceLocation, bool) 
/repo/llvm/build-all-bbisdk-asan/../../clang/lib/Sema/SemaChecking.cpp:12642:5
[...]
#730 0x5610e888a70b in CheckCommaOperand 
/repo/llvm/build-all-bbisdk-asan/../../clang/lib/Sema/SemaChecking.cpp:11653:3
#731 0x5610e888a70b in AnalyzeImplicitConversions 
/repo/llvm/build-all-bbisdk-asan/../../clang/lib/Sema/SemaChecking.cpp:12510:7
#732 0x5610e888a70b in AnalyzeImplicitConversions(clang::Sema&, 
clang::Expr*, clang::SourceLocation, bool) 
/repo/llvm/build-all-bbisdk-asan/../../clang/lib/Sema/SemaChecking.cpp:12642:5

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libpthread.so.0+0x12baf) (BuildId: 
1962602ac5dc3011b6d697b38b05ddc244197114) in raise
==2063954==ABORTING
```

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


[clang] Fix missing initializer for inline static template member with auto caused by delayed template instantiation. (PR #138122)

2025-05-11 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis commented:

LGTM

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


[clang] [NFC] Optimize file kind determination (PR #139492)

2025-05-11 Thread via cfe-commits

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


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


[clang] [NFC] Optimize file kind determination (PR #139492)

2025-05-11 Thread via cfe-commits


@@ -1529,6 +1529,15 @@ class SourceManager : public 
RefCountedBase {
 return Filename == "";
   }
 
+  /// Returns whether \p Loc is located in a built-ins or command line sources.

cor3ntin wrote:

```suggestion
  /// Returns whether \p Loc is located in a built-in or command line source.
```

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


[clang] [NFC] Optimize file kind determination (PR #139492)

2025-05-11 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/139492

>From 95522dc44fa7c807cf0278e0ce0a62bc0761ed04 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Fri, 9 May 2025 23:29:08 +0700
Subject: [PATCH 1/2] [NFC] Optimize File kind determination

There are checks in clang codebase that determine the type of source
file, associated with a given location - specifically, if it is an
ordonary file or comes from sources like command-line options or a
built-in definitions. These checks often rely on calls to
`getPresumedLoc`, which is relatively expensive.  In certain cases,
these checks are combined, leading to repeated calculations of the
costly function negatively affecting compile time.

This change tries to optimize such checks. It must fix compile time
regression introduced in https://github.com/llvm/llvm-project/pull/137306/.
---
 clang/include/clang/Basic/SourceManager.h  | 9 +
 clang/lib/ExtractAPI/ExtractAPIConsumer.cpp| 3 +--
 clang/lib/Frontend/PrintPreprocessedOutput.cpp | 3 +--
 clang/lib/Lex/PPDirectives.cpp | 8 +++-
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index e0f1ea435d54e..8859865a1ee7e 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1529,6 +1529,15 @@ class SourceManager : public 
RefCountedBase {
 return Filename == "";
   }
 
+  /// Returns whether \p Loc is located in a built-ins or command line sources.
+  bool isInPredefinedFile(SourceLocation Loc) const {
+PresumedLoc Presumed = getPresumedLoc(Loc);
+if (Presumed.isInvalid())
+  return false;
+StringRef Filename(Presumed.getFilename());
+return Filename == "" || Filename == "";
+  }
+
   /// Returns if a SourceLocation is in a system header.
   bool isInSystemHeader(SourceLocation Loc) const {
 if (Loc.isInvalid())
diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 6f42b36bd36a4..764c345a9db99 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -305,8 +305,7 @@ class MacroCallback : public PPCallbacks {
 
   auto DefLoc = MI->getDefinitionLoc();
 
-  if (SM.isWrittenInBuiltinFile(DefLoc) ||
-  SM.isWrittenInCommandLineFile(DefLoc))
+  if (SM.isInPredefinedFile(DefLoc))
 continue;
 
   auto AssociatedModuleMacros = MD.getModuleMacros();
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp 
b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 2ae355fb33885..22ba4cee182af 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -569,8 +569,7 @@ void PrintPPOutputPPCallbacks::MacroDefined(const Token 
&MacroNameTok,
   SourceLocation DefLoc = MI->getDefinitionLoc();
   if (DirectivesOnly && !MI->isUsed()) {
 SourceManager &SM = PP.getSourceManager();
-if (SM.isWrittenInBuiltinFile(DefLoc) ||
-SM.isWrittenInCommandLineFile(DefLoc))
+if (SM.isInPredefinedFile(DefLoc))
   return;
   }
   MoveToLine(DefLoc, /*RequireStartOfLine=*/true);
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 384d167cbcf88..c2bab9118234c 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -374,9 +374,8 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, 
MacroUse isDefineUndef,
   // Macro names with reserved identifiers are accepted if built-in or passed
   // through the command line (the later may be present if -dD was used to
   // generate the preprocessed file).
-  bool IsBuiltinOrCmd = SourceMgr.isWrittenInBuiltinFile(MacroNameLoc) ||
-SourceMgr.isWrittenInCommandLineFile(MacroNameLoc);
-  if (!IsBuiltinOrCmd && !SourceMgr.isInSystemHeader(MacroNameLoc)) {
+  if (!SourceMgr.isInPredefinedFile(MacroNameLoc) &&
+  !SourceMgr.isInSystemHeader(MacroNameLoc)) {
 MacroDiag D = MD_NoWarn;
 if (isDefineUndef == MU_Define) {
   D = shouldWarnOnMacroDef(*this, II);
@@ -1706,8 +1705,7 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) {
 // If a filename was present, read any flags that are present.
 if (ReadLineMarkerFlags(IsFileEntry, IsFileExit, FileKind, *this))
   return;
-if (!SourceMgr.isWrittenInBuiltinFile(DigitTok.getLocation()) &&
-!SourceMgr.isWrittenInCommandLineFile(DigitTok.getLocation()))
+if (!SourceMgr.isInPredefinedFile(DigitTok.getLocation()))
   Diag(StrTok, diag::ext_pp_gnu_line_directive);
 
 // Exiting to an empty string means pop to the including file, so leave

>From 841634a9cbb55483e7e4ee60a743c2a7e518f66c Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Mon, 12 May 2025 13:34:02 +0700
Subject: [PATCH 2/2] Update clang/include/clang/Basic/SourceManager.h

Co-authored-by: cor3ntin 
---
 clang/i

[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)

2025-05-11 Thread via cfe-commits


@@ -7220,6 +7220,17 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, 
TypeSourceInfo *TInfo,
 if (auto ILE = dyn_cast(LiteralExpr))
   for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
 Expr *Init = ILE->getInit(i);
+// C99 6.5.2.5
+//  "If the compound literal occurs outside the body of a function, the
+//  initializer list shall consist of constant expressions."
+if (!Init->isTypeDependent() && !Init->isValueDependent() &&
+!Init->getType()->isDependentType())

cor3ntin wrote:

This is not checking for "outside of the function".
Note that GCC errors on these cases too 
https://compiler-explorer.com/z/TaqzEdnbe
I think you need to update the comment to better describe the check

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


[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)

2025-05-11 Thread via cfe-commits

https://github.com/cor3ntin commented:

This change needs a release note.
Please add an entry to `clang/docs/ReleaseNotes.rst` in the section the most 
adapted to the change, and referencing any Github issue this change fixes. 
Thanks!

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


[clang] [clang][scandeps] Improve handling of rawstrings. (PR #139504)

2025-05-11 Thread Tobias Hieta via cfe-commits

https://github.com/tru created https://github.com/llvm/llvm-project/pull/139504

The current parser just checks one step back for a R before each string to know 
that it's a rawstring. But the preprocessor is much more advanced here and can 
have constructs like:

R\
"str"

And much more. This patch also adds more test coverage for Rawstrings in the 
dependencydirectivesscanner.

This was co-authored by Sylvain Audi  (@sylvain-audi)

Fixes #137648

>From b722c2e1702304de2bb962ba24868cf0912f27ee Mon Sep 17 00:00:00 2001
From: Tobias Hieta 
Date: Mon, 5 May 2025 11:40:17 +0200
Subject: [PATCH] [clang][scandeps] Improve handling of rawstrings.

The current parser just checks one step back for a R before each string
to know that it's a rawstring. But the preprocessor is much more
advanced here and can have constructs like:

R\
"str"

And much more. This patch also adds more test coverage for Rawstrings in
the dependencydirectivesscanner.

This was co-authored by Sylvain Audi 

Fixes #137648
---
 clang/lib/Lex/DependencyDirectivesScanner.cpp | 43 ---
 clang/test/ClangScanDeps/raw-strings.cpp  | 55 +++
 2 files changed, 91 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/ClangScanDeps/raw-strings.cpp

diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 088d1cc96e3a2..86e860abdbbdc 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -206,6 +206,24 @@ static void skipOverSpaces(const char *&First, const char 
*const End) {
 ++First;
 }
 
+// Move back by one character, skipping escaped newlines (backslash + \n)
+static char previousChar(const char *First, const char *&Current) {
+  assert(Current > First);
+  --Current;
+  while (Current > First + 1 && isVerticalWhitespace(*Current)) {
+const char PrevChar = *(Current - 1);
+if (PrevChar == '\\') {
+  Current -= 2; // backslash + (\n or \r)
+} else if (Current > First + 2 && isVerticalWhitespace(PrevChar) &&
+   PrevChar != *Current && *(Current - 2) == '\\') {
+  Current -= 3; // backslash + (\n\r or \r\n)
+} else {
+  break;
+}
+  }
+  return *Current;
+}
+
 [[nodiscard]] static bool isRawStringLiteral(const char *First,
  const char *Current) {
   assert(First <= Current);
@@ -215,25 +233,28 @@ static void skipOverSpaces(const char *&First, const char 
*const End) {
 return false;
 
   // Check for an "R".
-  --Current;
-  if (*Current != 'R')
+  if (previousChar(First, Current) != 'R')
 return false;
-  if (First == Current || !isAsciiIdentifierContinue(*--Current))
+  if (First == Current ||
+  !isAsciiIdentifierContinue(previousChar(First, Current)))
 return true;
 
   // Check for a prefix of "u", "U", or "L".
   if (*Current == 'u' || *Current == 'U' || *Current == 'L')
-return First == Current || !isAsciiIdentifierContinue(*--Current);
+return First == Current ||
+   !isAsciiIdentifierContinue(previousChar(First, Current));
 
   // Check for a prefix of "u8".
-  if (*Current != '8' || First == Current || *Current-- != 'u')
+  if (*Current != '8' || First == Current ||
+  previousChar(First, Current) != 'u')
 return false;
-  return First == Current || !isAsciiIdentifierContinue(*--Current);
+  return First == Current ||
+ !isAsciiIdentifierContinue(previousChar(First, Current));
 }
 
 static void skipRawString(const char *&First, const char *const End) {
   assert(First[0] == '"');
-  assert(First[-1] == 'R');
+  //assert(First[-1] == 'R');
 
   const char *Last = ++First;
   while (Last != End && *Last != '(')
@@ -416,6 +437,14 @@ void Scanner::skipLine(const char *&First, const char 
*const End) {
 continue;
   }
 
+  // Continue on the same line if an EOL is preceded with backslash
+  if (First + 1 < End && *First == '\\') {
+if (unsigned Len = isEOL(First + 1, End)) {
+  First += 1 + Len;
+  continue;
+}
+  }
+
   // Iterate over comments correctly.
   if (*First != '/' || End - First < 2) {
 LastTokenPtr = First;
diff --git a/clang/test/ClangScanDeps/raw-strings.cpp 
b/clang/test/ClangScanDeps/raw-strings.cpp
new file mode 100644
index 0..5fda4a559c9e3
--- /dev/null
+++ b/clang/test/ClangScanDeps/raw-strings.cpp
@@ -0,0 +1,55 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
+
+//--- cdb.json.in
+[{
+"directory": "DIR",
+"command": "clang -c DIR/tu.c -o DIR/tu.o -IDIR/include",
+"file": "DIR/tu.c"
+}]
+//--- include/header.h
+//--- include/header2.h
+//--- include/header3.h
+//--- include/header4.h
+//--- tu.c
+#if 0
+R"x()x"
+#endif
+
+#include "header.h"
+
+#if 0
+R"y(";
+#endif
+#include "header2.h"
+
+#if 0
+//")y"
+#endif
+
+#if 0
+R"y(";
+R"z()y";
+#endif
+#include "header3.h"
+#if 0
+//")z"

[clang] [clang][scandeps] Improve handling of rawstrings. (PR #139504)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Tobias Hieta (tru)


Changes

The current parser just checks one step back for a R before each string to know 
that it's a rawstring. But the preprocessor is much more advanced here and can 
have constructs like:

R\
"str"

And much more. This patch also adds more test coverage for Rawstrings in the 
dependencydirectivesscanner.

This was co-authored by Sylvain Audi  
(@sylvain-audi)

Fixes #137648

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


2 Files Affected:

- (modified) clang/lib/Lex/DependencyDirectivesScanner.cpp (+36-7) 
- (added) clang/test/ClangScanDeps/raw-strings.cpp (+55) 


``diff
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 088d1cc96e3a2..86e860abdbbdc 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -206,6 +206,24 @@ static void skipOverSpaces(const char *&First, const char 
*const End) {
 ++First;
 }
 
+// Move back by one character, skipping escaped newlines (backslash + \n)
+static char previousChar(const char *First, const char *&Current) {
+  assert(Current > First);
+  --Current;
+  while (Current > First + 1 && isVerticalWhitespace(*Current)) {
+const char PrevChar = *(Current - 1);
+if (PrevChar == '\\') {
+  Current -= 2; // backslash + (\n or \r)
+} else if (Current > First + 2 && isVerticalWhitespace(PrevChar) &&
+   PrevChar != *Current && *(Current - 2) == '\\') {
+  Current -= 3; // backslash + (\n\r or \r\n)
+} else {
+  break;
+}
+  }
+  return *Current;
+}
+
 [[nodiscard]] static bool isRawStringLiteral(const char *First,
  const char *Current) {
   assert(First <= Current);
@@ -215,25 +233,28 @@ static void skipOverSpaces(const char *&First, const char 
*const End) {
 return false;
 
   // Check for an "R".
-  --Current;
-  if (*Current != 'R')
+  if (previousChar(First, Current) != 'R')
 return false;
-  if (First == Current || !isAsciiIdentifierContinue(*--Current))
+  if (First == Current ||
+  !isAsciiIdentifierContinue(previousChar(First, Current)))
 return true;
 
   // Check for a prefix of "u", "U", or "L".
   if (*Current == 'u' || *Current == 'U' || *Current == 'L')
-return First == Current || !isAsciiIdentifierContinue(*--Current);
+return First == Current ||
+   !isAsciiIdentifierContinue(previousChar(First, Current));
 
   // Check for a prefix of "u8".
-  if (*Current != '8' || First == Current || *Current-- != 'u')
+  if (*Current != '8' || First == Current ||
+  previousChar(First, Current) != 'u')
 return false;
-  return First == Current || !isAsciiIdentifierContinue(*--Current);
+  return First == Current ||
+ !isAsciiIdentifierContinue(previousChar(First, Current));
 }
 
 static void skipRawString(const char *&First, const char *const End) {
   assert(First[0] == '"');
-  assert(First[-1] == 'R');
+  //assert(First[-1] == 'R');
 
   const char *Last = ++First;
   while (Last != End && *Last != '(')
@@ -416,6 +437,14 @@ void Scanner::skipLine(const char *&First, const char 
*const End) {
 continue;
   }
 
+  // Continue on the same line if an EOL is preceded with backslash
+  if (First + 1 < End && *First == '\\') {
+if (unsigned Len = isEOL(First + 1, End)) {
+  First += 1 + Len;
+  continue;
+}
+  }
+
   // Iterate over comments correctly.
   if (*First != '/' || End - First < 2) {
 LastTokenPtr = First;
diff --git a/clang/test/ClangScanDeps/raw-strings.cpp 
b/clang/test/ClangScanDeps/raw-strings.cpp
new file mode 100644
index 0..5fda4a559c9e3
--- /dev/null
+++ b/clang/test/ClangScanDeps/raw-strings.cpp
@@ -0,0 +1,55 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
+
+//--- cdb.json.in
+[{
+"directory": "DIR",
+"command": "clang -c DIR/tu.c -o DIR/tu.o -IDIR/include",
+"file": "DIR/tu.c"
+}]
+//--- include/header.h
+//--- include/header2.h
+//--- include/header3.h
+//--- include/header4.h
+//--- tu.c
+#if 0
+R"x()x"
+#endif
+
+#include "header.h"
+
+#if 0
+R"y(";
+#endif
+#include "header2.h"
+
+#if 0
+//")y"
+#endif
+
+#if 0
+R"y(";
+R"z()y";
+#endif
+#include "header3.h"
+#if 0
+//")z"
+#endif
+
+#if 0
+R\
+"y(";
+R"z()y";
+#endif
+#include "header4.h"
+#if 0
+//")z"
+#endif
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -mode preprocess | 
FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -mode 
preprocess-dependency-directives | FileCheck %s
+// CHECK: tu.c
+// CHECK-NEXT: header.h
+// CHECK-NEXT: header3.h
+// CHECK-NEXT: header4.h

``




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

[clang-tools-extra] [clangd] Add CodePatterns config option under Completion (PR #137613)

2025-05-11 Thread via cfe-commits

https://github.com/Noustaa updated 
https://github.com/llvm/llvm-project/pull/137613



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] [clang][scandeps] Improve handling of rawstrings. (PR #139504)

2025-05-11 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- 
clang/test/ClangScanDeps/raw-strings.cpp 
clang/lib/Lex/DependencyDirectivesScanner.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 86e860abd..6565e77af 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -254,7 +254,7 @@ static char previousChar(const char *First, const char 
*&Current) {
 
 static void skipRawString(const char *&First, const char *const End) {
   assert(First[0] == '"');
-  //assert(First[-1] == 'R');
+  // assert(First[-1] == 'R');
 
   const char *Last = ++First;
   while (Last != End && *Last != '(')

``




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


[clang-tools-extra] [clangd] Add CodePatterns config option under Completion (PR #137613)

2025-05-11 Thread via cfe-commits


@@ -950,6 +951,11 @@ struct CompletionRecorder : public CodeCompleteConsumer {
 // Retain the results we might want.
 for (unsigned I = 0; I < NumResults; ++I) {
   auto &Result = InResults[I];
+  if (Config::current().Completion.CodePatterns ==
+  Config::CodePatternsPolicy::None &&
+  Result.Kind == CodeCompletionResult::RK_Pattern &&
+  ContextKind != CodeCompletionContext::CCC_IncludedFile)

Noustaa wrote:

Done 
[1c5d401](https://github.com/llvm/llvm-project/pull/137613/commits/1c5d4019d56e9c023b777dbf8e335f4f13e037fa)

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


[clang-tools-extra] [clangd] Add CodePatterns config option under Completion (PR #137613)

2025-05-11 Thread via cfe-commits


@@ -267,6 +267,17 @@ opt HeaderInsertion{
 "Never insert #include directives as part of code completion")),
 };
 
+opt CodePatterns{

Noustaa wrote:

Done 
[1430d62](https://github.com/llvm/llvm-project/pull/137613/commits/1430d62625fe84ecea5ade72343031ffddbc7197)

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


[clang] [clang] Use StringRef::consume_front (NFC) (PR #139472)

2025-05-11 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/139472

None



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] [clang] Use StringRef::consume_front (NFC) (PR #139472)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


4 Files Affected:

- (modified) clang/lib/CodeGen/CGBlocks.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+2-4) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-5) 


``diff
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index ba0d87fdc5d43..40627d6ffd3c9 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -40,8 +40,7 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef 
name)
 
   // Skip asm prefix, if any.  'name' is usually taken directly from
   // the mangled name of the enclosing function.
-  if (!name.empty() && name[0] == '\01')
-name = name.substr(1);
+  name.consume_front("\01");
 }
 
 // Anchor the vtable to this translation unit.
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3513175b8b8ad..2a11eebf1b682 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4500,8 +4500,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
 
 Flags |= llvm::DINode::FlagPrototyped;
   }
-  if (Name.starts_with("\01"))
-Name = Name.substr(1);
+  Name.consume_front("\01");
 
   assert((!D || !isa(D) ||
   GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
@@ -4590,8 +4589,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, 
SourceLocation Loc,
   } else {
 llvm_unreachable("not a function or ObjC method");
   }
-  if (!Name.empty() && Name[0] == '\01')
-Name = Name.substr(1);
+  Name.consume_front("\01");
 
   if (D->isImplicit()) {
 Flags |= llvm::DINode::FlagArtificial;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 49c2bef20925a..0d03923951a16 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3388,8 +3388,7 @@ LValue CodeGenFunction::EmitPredefinedLValue(const 
PredefinedExpr *E) {
   auto SL = E->getFunctionName();
   assert(SL != nullptr && "No StringLiteral name in PredefinedExpr");
   StringRef FnName = CurFn->getName();
-  if (FnName.starts_with("\01"))
-FnName = FnName.substr(1);
+  FnName.consume_front("\01");
   StringRef NameItems[] = {
   PredefinedExpr::getIdentKindName(E->getIdentKind()), FnName};
   std::string GVName = llvm::join(NameItems, NameItems + 2, ".");
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 3469676b74bc8..428a4b8335524 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4061,11 +4061,7 @@ namespace {
 return false;
   std::string BuiltinNameStr = BI.getName(BuiltinID);
   StringRef BuiltinName = BuiltinNameStr;
-  if (BuiltinName.starts_with("__builtin_") &&
-  Name == BuiltinName.slice(strlen("__builtin_"), StringRef::npos)) {
-return true;
-  }
-  return false;
+  return BuiltinName.consume_front("__builtin_") && Name == BuiltinName;
 }
 
 bool VisitStmt(const Stmt *S) {

``




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


[clang] [clang] Use StringRef::consume_front (NFC) (PR #139472)

2025-05-11 Thread Matt Arsenault via cfe-commits

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


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


[clang] [clang] Use StringRef::consume_front (NFC) (PR #139472)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Kazu Hirata (kazutakahirata)


Changes



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


4 Files Affected:

- (modified) clang/lib/CodeGen/CGBlocks.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+2-4) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-5) 


``diff
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index ba0d87fdc5d43..40627d6ffd3c9 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -40,8 +40,7 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef 
name)
 
   // Skip asm prefix, if any.  'name' is usually taken directly from
   // the mangled name of the enclosing function.
-  if (!name.empty() && name[0] == '\01')
-name = name.substr(1);
+  name.consume_front("\01");
 }
 
 // Anchor the vtable to this translation unit.
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3513175b8b8ad..2a11eebf1b682 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4500,8 +4500,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
 
 Flags |= llvm::DINode::FlagPrototyped;
   }
-  if (Name.starts_with("\01"))
-Name = Name.substr(1);
+  Name.consume_front("\01");
 
   assert((!D || !isa(D) ||
   GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
@@ -4590,8 +4589,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, 
SourceLocation Loc,
   } else {
 llvm_unreachable("not a function or ObjC method");
   }
-  if (!Name.empty() && Name[0] == '\01')
-Name = Name.substr(1);
+  Name.consume_front("\01");
 
   if (D->isImplicit()) {
 Flags |= llvm::DINode::FlagArtificial;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 49c2bef20925a..0d03923951a16 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3388,8 +3388,7 @@ LValue CodeGenFunction::EmitPredefinedLValue(const 
PredefinedExpr *E) {
   auto SL = E->getFunctionName();
   assert(SL != nullptr && "No StringLiteral name in PredefinedExpr");
   StringRef FnName = CurFn->getName();
-  if (FnName.starts_with("\01"))
-FnName = FnName.substr(1);
+  FnName.consume_front("\01");
   StringRef NameItems[] = {
   PredefinedExpr::getIdentKindName(E->getIdentKind()), FnName};
   std::string GVName = llvm::join(NameItems, NameItems + 2, ".");
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 3469676b74bc8..428a4b8335524 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4061,11 +4061,7 @@ namespace {
 return false;
   std::string BuiltinNameStr = BI.getName(BuiltinID);
   StringRef BuiltinName = BuiltinNameStr;
-  if (BuiltinName.starts_with("__builtin_") &&
-  Name == BuiltinName.slice(strlen("__builtin_"), StringRef::npos)) {
-return true;
-  }
-  return false;
+  return BuiltinName.consume_front("__builtin_") && Name == BuiltinName;
 }
 
 bool VisitStmt(const Stmt *S) {

``




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


[clang-tools-extra] Fix the issue #139467 ([clang-tidy] false positive narrowing conversion) (PR #139474)

2025-05-11 Thread via cfe-commits

https://github.com/AndreyG created 
https://github.com/llvm/llvm-project/pull/139474

Let's consider the following code from the issue #139467:
```c
void test(int cond, char c) {
char ret = cond > 0 ? ':' : c;
}
```
Initializer of `ret` looks the following:
```
-ImplicitCastExpr 'char' 
 `-ConditionalOperator 'int'
   |-BinaryOperator 'int' '>'
   | |-ImplicitCastExpr 'int' 
   | | `-DeclRefExpr 'int' lvalue ParmVar 'cond' 'int'
   | `-IntegerLiteral 'int' 0
   |-CharacterLiteral 'int' 58
   `-ImplicitCastExpr 'int' 
 `-ImplicitCastExpr 'char' 
   `-DeclRefExpr 'char' lvalue ParmVar 'c' 'char'
```
So it could be seen that `RHS` of the conditional operator is `DeclRefExpr 'c'` 
which is casted to `int` and then the whole conditional expression is casted to 
'char'. But this last conversion is not narrowing, because `RHS` was `char` 
_initially_. We should just remove the cast from `char` to `int` before the 
narrowing conversion check.

>From 19c3713883e79220e6c30bf76c2d95cfaf4dcaa3 Mon Sep 17 00:00:00 2001
From: Andrey Davydov 
Date: Sun, 11 May 2025 22:23:38 +0200
Subject: [PATCH] [clang-tidy] false positive narrowing conversion

Let's consider the following code from the issue #139467:

void test(int cond, char c) {
char ret = cond > 0 ? ':' : c;
}

Initializer of 'ret' looks the following:

-ImplicitCastExpr 'char' 
 `-ConditionalOperator 'int'
   |-BinaryOperator 'int' '>'
   | |-ImplicitCastExpr 'int' 
   | | `-DeclRefExpr 'int' lvalue ParmVar 'cond' 'int'
   | `-IntegerLiteral 'int' 0
   |-CharacterLiteral 'int' 58
   `-ImplicitCastExpr 'int' 
 `-ImplicitCastExpr 'char' 
   `-DeclRefExpr 'char' lvalue ParmVar 'c' 'char'

So it could be seen that 'RHS' of the conditional operator is
DeclRefExpr 'c' which is casted to 'int' and then the whole conditional 
expression is casted to 'char'.
But this last conversion is not narrowing, because 'RHS' was 'char' _initially_.
We should just remove the cast from 'char' to 'int' before the narrowing 
conversion check.
---
 .../bugprone/NarrowingConversionsCheck.cpp   | 16 
 .../bugprone/NarrowingConversionsCheck.h |  2 ++
 ...rrowing-conversions-conditional-expressions.c |  6 ++
 3 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index bafcd402ca851..9e53bfe83e03e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -554,15 +554,23 @@ bool NarrowingConversionsCheck::handleConditionalOperator(
 // We have an expression like so: `output = cond ? lhs : rhs`
 // From the point of view of narrowing conversion we treat it as two
 // expressions `output = lhs` and `output = rhs`.
-handleBinaryOperator(Context, CO->getLHS()->getExprLoc(), Lhs,
- *CO->getLHS());
-handleBinaryOperator(Context, CO->getRHS()->getExprLoc(), Lhs,
- *CO->getRHS());
+handleConditionalOperatorArgument(Context, Lhs, CO->getLHS());
+handleConditionalOperatorArgument(Context, Lhs, CO->getRHS());
 return true;
   }
   return false;
 }
 
+void NarrowingConversionsCheck::handleConditionalOperatorArgument(
+const ASTContext &Context, const Expr &Lhs, const Expr *Arg) {
+  if (const auto *ICE = llvm::dyn_cast(Arg)) {
+if (!Arg->getIntegerConstantExpr(Context)) {
+  Arg = ICE->getSubExpr();
+}
+  }
+  handleBinaryOperator(Context, Arg->getExprLoc(), Lhs, *Arg);
+}
+
 void NarrowingConversionsCheck::handleImplicitCast(
 const ASTContext &Context, const ImplicitCastExpr &Cast) {
   if (Cast.getExprLoc().isMacroID())
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
index 20403f920b925..ebddbc2869675 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
@@ -85,6 +85,8 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
   bool handleConditionalOperator(const ASTContext &Context, const Expr &Lhs,
  const Expr &Rhs);
 
+  void handleConditionalOperatorArgument(const ASTContext &Context, const Expr 
&Lhs,
+ const Expr *Arg);
   void handleImplicitCast(const ASTContext &Context,
   const ImplicitCastExpr &Cast);
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
new file mode 100644
index 0..754d6425b07cd
--- /dev/n

[clang-tools-extra] Fix the issue #139467 ([clang-tidy] false positive narrowing conversion) (PR #139474)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Andrey (AndreyG)


Changes

Let's consider the following code from the issue #139467:
```c
void test(int cond, char c) {
char ret = cond > 0 ? ':' : c;
}
```
Initializer of `ret` looks the following:
```
-ImplicitCastExpr 'char' 
 `-ConditionalOperator 'int'
   |-BinaryOperator 'int' '>'
   | |-ImplicitCastExpr 'int' 
   | | `-DeclRefExpr 'int' lvalue ParmVar 'cond' 'int'
   | `-IntegerLiteral 'int' 0
   |-CharacterLiteral 'int' 58
   `-ImplicitCastExpr 'int' 
 `-ImplicitCastExpr 'char' 
   `-DeclRefExpr 'char' lvalue ParmVar 'c' 'char'
```
So it could be seen that `RHS` of the conditional operator is `DeclRefExpr 'c'` 
which is casted to `int` and then the whole conditional expression is casted to 
'char'. But this last conversion is not narrowing, because `RHS` was `char` 
_initially_. We should just remove the cast from `char` to `int` before the 
narrowing conversion check.

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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp (+12-4) 
- (modified) clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h 
(+2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
 (+6) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index bafcd402ca851..9e53bfe83e03e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -554,15 +554,23 @@ bool NarrowingConversionsCheck::handleConditionalOperator(
 // We have an expression like so: `output = cond ? lhs : rhs`
 // From the point of view of narrowing conversion we treat it as two
 // expressions `output = lhs` and `output = rhs`.
-handleBinaryOperator(Context, CO->getLHS()->getExprLoc(), Lhs,
- *CO->getLHS());
-handleBinaryOperator(Context, CO->getRHS()->getExprLoc(), Lhs,
- *CO->getRHS());
+handleConditionalOperatorArgument(Context, Lhs, CO->getLHS());
+handleConditionalOperatorArgument(Context, Lhs, CO->getRHS());
 return true;
   }
   return false;
 }
 
+void NarrowingConversionsCheck::handleConditionalOperatorArgument(
+const ASTContext &Context, const Expr &Lhs, const Expr *Arg) {
+  if (const auto *ICE = llvm::dyn_cast(Arg)) {
+if (!Arg->getIntegerConstantExpr(Context)) {
+  Arg = ICE->getSubExpr();
+}
+  }
+  handleBinaryOperator(Context, Arg->getExprLoc(), Lhs, *Arg);
+}
+
 void NarrowingConversionsCheck::handleImplicitCast(
 const ASTContext &Context, const ImplicitCastExpr &Cast) {
   if (Cast.getExprLoc().isMacroID())
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
index 20403f920b925..ebddbc2869675 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
@@ -85,6 +85,8 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
   bool handleConditionalOperator(const ASTContext &Context, const Expr &Lhs,
  const Expr &Rhs);
 
+  void handleConditionalOperatorArgument(const ASTContext &Context, const Expr 
&Lhs,
+ const Expr *Arg);
   void handleImplicitCast(const ASTContext &Context,
   const ImplicitCastExpr &Cast);
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
new file mode 100644
index 0..754d6425b07cd
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s bugprone-narrowing-conversions %t -- --
+
+char test(int cond, char c) {
+   char ret = cond > 0 ? ':' : c;
+   return ret;
+}

``




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


[clang-tools-extra] Fix the issue #139467 ([clang-tidy] false positive narrowing conversion) (PR #139474)

2025-05-11 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] 64f53db - [clang] Use StringRef::consume_front (NFC) (#139472)

2025-05-11 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-11T15:38:22-07:00
New Revision: 64f53db79ce69768aab2caa828e1e0157f3d23b6

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

LOG: [clang] Use StringRef::consume_front (NFC) (#139472)

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index ba0d87fdc5d43..40627d6ffd3c9 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -40,8 +40,7 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef 
name)
 
   // Skip asm prefix, if any.  'name' is usually taken directly from
   // the mangled name of the enclosing function.
-  if (!name.empty() && name[0] == '\01')
-name = name.substr(1);
+  name.consume_front("\01");
 }
 
 // Anchor the vtable to this translation unit.

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3513175b8b8ad..2a11eebf1b682 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4500,8 +4500,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
 
 Flags |= llvm::DINode::FlagPrototyped;
   }
-  if (Name.starts_with("\01"))
-Name = Name.substr(1);
+  Name.consume_front("\01");
 
   assert((!D || !isa(D) ||
   GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
@@ -4590,8 +4589,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, 
SourceLocation Loc,
   } else {
 llvm_unreachable("not a function or ObjC method");
   }
-  if (!Name.empty() && Name[0] == '\01')
-Name = Name.substr(1);
+  Name.consume_front("\01");
 
   if (D->isImplicit()) {
 Flags |= llvm::DINode::FlagArtificial;

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 49c2bef20925a..0d03923951a16 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3388,8 +3388,7 @@ LValue CodeGenFunction::EmitPredefinedLValue(const 
PredefinedExpr *E) {
   auto SL = E->getFunctionName();
   assert(SL != nullptr && "No StringLiteral name in PredefinedExpr");
   StringRef FnName = CurFn->getName();
-  if (FnName.starts_with("\01"))
-FnName = FnName.substr(1);
+  FnName.consume_front("\01");
   StringRef NameItems[] = {
   PredefinedExpr::getIdentKindName(E->getIdentKind()), FnName};
   std::string GVName = llvm::join(NameItems, NameItems + 2, ".");

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 3469676b74bc8..428a4b8335524 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4061,11 +4061,7 @@ namespace {
 return false;
   std::string BuiltinNameStr = BI.getName(BuiltinID);
   StringRef BuiltinName = BuiltinNameStr;
-  if (BuiltinName.starts_with("__builtin_") &&
-  Name == BuiltinName.slice(strlen("__builtin_"), StringRef::npos)) {
-return true;
-  }
-  return false;
+  return BuiltinName.consume_front("__builtin_") && Name == BuiltinName;
 }
 
 bool VisitStmt(const Stmt *S) {



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


[clang] [clang] Use StringRef::consume_front (NFC) (PR #139472)

2025-05-11 Thread Kazu Hirata via cfe-commits

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


[clang] [Driver] Use StringRef::consume_back (NFC) (PR #139478)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+2-2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fe3952ee76229..26e24ad0ab17c 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1411,8 +1411,8 @@ StringRef Darwin::getSDKName(StringRef isysroot) {
   auto EndSDK = llvm::sys::path::rend(isysroot);
   for (auto IT = BeginSDK; IT != EndSDK; ++IT) {
 StringRef SDK = *IT;
-if (SDK.ends_with(".sdk"))
-return SDK.slice(0, SDK.size() - 4);
+if (SDK.consume_back(".sdk"))
+  return SDK;
   }
   return "";
 }

``




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


[clang] [Driver] Use StringRef::consume_back (NFC) (PR #139478)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+2-2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fe3952ee76229..26e24ad0ab17c 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1411,8 +1411,8 @@ StringRef Darwin::getSDKName(StringRef isysroot) {
   auto EndSDK = llvm::sys::path::rend(isysroot);
   for (auto IT = BeginSDK; IT != EndSDK; ++IT) {
 StringRef SDK = *IT;
-if (SDK.ends_with(".sdk"))
-return SDK.slice(0, SDK.size() - 4);
+if (SDK.consume_back(".sdk"))
+  return SDK;
   }
   return "";
 }

``




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


[clang] [Driver] Use StringRef::consume_back (NFC) (PR #139478)

2025-05-11 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/139478

None

>From e74f12c1afc7bd492b9101040d49284200d12638 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 10 May 2025 23:49:14 -0700
Subject: [PATCH] [Driver] Use StringRef::consume_back (NFC)

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fe3952ee76229..26e24ad0ab17c 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1411,8 +1411,8 @@ StringRef Darwin::getSDKName(StringRef isysroot) {
   auto EndSDK = llvm::sys::path::rend(isysroot);
   for (auto IT = BeginSDK; IT != EndSDK; ++IT) {
 StringRef SDK = *IT;
-if (SDK.ends_with(".sdk"))
-return SDK.slice(0, SDK.size() - 4);
+if (SDK.consume_back(".sdk"))
+  return SDK;
   }
   return "";
 }

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


[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)

2025-05-11 Thread via cfe-commits

https://github.com/Mr-Anyone created 
https://github.com/llvm/llvm-project/pull/139479

Compound literals initializer-list should be a constant expression if it is 
defined outside the body of a function.

Emit error instead of falling through tripping assertion error.

fixes #139160

>From 43bb454e741e74fe164f1988b3056a377b080269 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Sun, 11 May 2025 19:01:34 -0400
Subject: [PATCH] [clang] Compound Literal Statement Constant Expression
 Assertion Fix

Compound literals initializer-list should be a constant expression if it is 
defined outside the body of a function.

Emit error instead of falling through tripping assertion error.

fixes #139160
---
 clang/lib/Sema/SemaExpr.cpp| 11 +++
 clang/test/SemaCXX/cxx2a-consteval.cpp | 22 ++
 2 files changed, 33 insertions(+)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index deb8d2edfc5c9..e06b6fc233fcc 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7220,6 +7220,17 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, 
TypeSourceInfo *TInfo,
 if (auto ILE = dyn_cast(LiteralExpr))
   for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
 Expr *Init = ILE->getInit(i);
+// C99 6.5.2.5
+//  "If the compound literal occurs outside the body of a function, the
+//  initializer list shall consist of constant expressions."
+if (!Init->isTypeDependent() && !Init->isValueDependent() &&
+!Init->getType()->isDependentType())
+  if (!Init->isConstantInitializer(Context, false)) {
+Diag(Init->getExprLoc(), diag::err_init_element_not_constant)
+<< Init->getSourceBitField();
+return ExprError();
+  }
+
 ILE->setInit(i, ConstantExpr::Create(Context, Init));
   }
 
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index d9d144cafdbcc..d9932e4dd8241 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1300,3 +1300,25 @@ void foo() {
 }
 
 }
+
+// https://github.com/llvm/llvm-project/issues/139160
+namespace GH139160{
+  // original test case taken from Github
+  struct A {int x[1]; }; 
+  A f(); // expected-note {{declared here}}
+  typedef int *t[];
+  consteval int* f(int* x) { return x; }
+
+  int ** x = (t){f(f().x)}; // expected-error{{call to consteval function 
'GH139160::f' is not a constant expression}}
+// expected-note@-1  {{non-constexpr function 'f' 
cannot be used in a constant expression}}
+// expected-error@-2 {{initializer element is not 
a compile-time constant}} 
+
+  struct B {int value, value_two;};
+  B make_struct() {return {10, 20};} // expected-note {{declared here}}
+  consteval int get_value(B container) {return container.value;}
+  B result = (B){10, get_value(make_struct())}; // expected-error 
{{initializer element is not a compile-time constant}} 
+// expected-error@-1 {{call to 
consteval function 'GH139160::get_value' is not a constant expression}}
+// expected-note@-2  
{{non-constexpr function 'make_struct' cannot be used in a constant expression}}
+};
+
+

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


[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vincent (Mr-Anyone)


Changes

Compound literals initializer-list should be a constant expression if it is 
defined outside the body of a function.

Emit error instead of falling through tripping assertion error.

fixes #139160

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+11) 
- (modified) clang/test/SemaCXX/cxx2a-consteval.cpp (+22) 


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index deb8d2edfc5c9..e06b6fc233fcc 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7220,6 +7220,17 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, 
TypeSourceInfo *TInfo,
 if (auto ILE = dyn_cast(LiteralExpr))
   for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
 Expr *Init = ILE->getInit(i);
+// C99 6.5.2.5
+//  "If the compound literal occurs outside the body of a function, the
+//  initializer list shall consist of constant expressions."
+if (!Init->isTypeDependent() && !Init->isValueDependent() &&
+!Init->getType()->isDependentType())
+  if (!Init->isConstantInitializer(Context, false)) {
+Diag(Init->getExprLoc(), diag::err_init_element_not_constant)
+<< Init->getSourceBitField();
+return ExprError();
+  }
+
 ILE->setInit(i, ConstantExpr::Create(Context, Init));
   }
 
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index d9d144cafdbcc..d9932e4dd8241 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1300,3 +1300,25 @@ void foo() {
 }
 
 }
+
+// https://github.com/llvm/llvm-project/issues/139160
+namespace GH139160{
+  // original test case taken from Github
+  struct A {int x[1]; }; 
+  A f(); // expected-note {{declared here}}
+  typedef int *t[];
+  consteval int* f(int* x) { return x; }
+
+  int ** x = (t){f(f().x)}; // expected-error{{call to consteval function 
'GH139160::f' is not a constant expression}}
+// expected-note@-1  {{non-constexpr function 'f' 
cannot be used in a constant expression}}
+// expected-error@-2 {{initializer element is not 
a compile-time constant}} 
+
+  struct B {int value, value_two;};
+  B make_struct() {return {10, 20};} // expected-note {{declared here}}
+  consteval int get_value(B container) {return container.value;}
+  B result = (B){10, get_value(make_struct())}; // expected-error 
{{initializer element is not a compile-time constant}} 
+// expected-error@-1 {{call to 
consteval function 'GH139160::get_value' is not a constant expression}}
+// expected-note@-2  
{{non-constexpr function 'make_struct' cannot be used in a constant expression}}
+};
+
+

``




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


[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)

2025-05-11 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang-tools-extra] [clangd] Add tweak to add pure virtual overrides (PR #139348)

2025-05-11 Thread Marco Maia via cfe-commits

https://github.com/marcogmaia updated 
https://github.com/llvm/llvm-project/pull/139348

>From 76503bd8f5618b710e2909d1303de5d34723 Mon Sep 17 00:00:00 2001
From: Marco Maia 
Date: Sat, 10 May 2025 00:48:39 -0300
Subject: [PATCH 1/9] [clangd] Add tweak to add pure virtual overrides

---
 .../clangd/refactor/tweaks/CMakeLists.txt |   3 +-
 .../refactor/tweaks/OverridePureVirtuals.cpp  | 366 
 .../clangd/unittests/CMakeLists.txt   |   1 +
 .../tweaks/OverridePureVirtualsTests.cpp  | 410 ++
 4 files changed, 779 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp
 create mode 100644 
clang-tools-extra/clangd/unittests/tweaks/OverridePureVirtualsTests.cpp

diff --git a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt 
b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
index 59475b0dfd3d2..1d6e38088ad67 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
+++ b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
@@ -14,9 +14,9 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangDaemonTweaks OBJECT
   AddUsing.cpp
   AnnotateHighlightings.cpp
-  DumpAST.cpp
   DefineInline.cpp
   DefineOutline.cpp
+  DumpAST.cpp
   ExpandDeducedType.cpp
   ExpandMacro.cpp
   ExtractFunction.cpp
@@ -24,6 +24,7 @@ add_clang_library(clangDaemonTweaks OBJECT
   MemberwiseConstructor.cpp
   ObjCLocalizeStringLiteral.cpp
   ObjCMemberwiseInitializer.cpp
+  OverridePureVirtuals.cpp
   PopulateSwitch.cpp
   RawStringLiteral.cpp
   RemoveUsingNamespace.cpp
diff --git a/clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp
new file mode 100644
index 0..b8880433fdd52
--- /dev/null
+++ b/clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp
@@ -0,0 +1,366 @@
+//===--- AddPureVirtualOverride.cpp --*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "refactor/Tweak.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+
+class OverridePureVirtuals : public Tweak {
+public:
+  const char *id() const final; // defined by REGISTER_TWEAK.
+  bool prepare(const Selection &Sel) override;
+  Expected apply(const Selection &Sel) override;
+  std::string title() const override { return "Override pure virtual methods"; 
}
+  llvm::StringLiteral kind() const override {
+return CodeAction::REFACTOR_KIND;
+  }
+
+private:
+  // Stores the CXXRecordDecl of the class being modified.
+  const CXXRecordDecl *CurrentDecl = nullptr;
+  // Stores pure virtual methods that need overriding, grouped by their 
original
+  // access specifier.
+  std::map>
+  MissingMethodsByAccess;
+  // Stores the source locations of existing access specifiers in CurrentDecl.
+  std::map AccessSpecifierLocations;
+
+  // Helper function to gather information before applying the tweak.
+  void collectMissingPureVirtuals(const Selection &Sel);
+};
+
+REGISTER_TWEAK(OverridePureVirtuals)
+
+// Collects all unique, canonical pure virtual methods from a class and its
+// entire inheritance hierarchy. This function aims to find methods that 
*could*
+// make a derived class abstract if not implemented.
+std::vector
+getAllUniquePureVirtualsFromHierarchy(const CXXRecordDecl *Decl) {
+  std::vector Result;
+  llvm::DenseSet VisitedCanonicalMethods;
+  // We declare it as a std::function because we are going to call it
+  // recursively.
+  std::function Collect;
+
+  Collect = [&](const CXXRecordDecl *CurrentClass) {
+if (!CurrentClass) {
+  return;
+}
+const CXXRecordDecl *Def = CurrentClass->getDefinition();
+if (!Def) {
+  return;
+}
+
+for (const CXXMethodDecl *M : Def->methods()) {
+  // Add if its canonical declaration hasn't been processed yet.
+  // This ensures each distinct pure virtual method signature is collected
+  // once.
+  if (M->isPureVirtual() &&
+  VisitedCanonicalMethods.insert(M->getCanonicalDecl()).second) {
+Result.emplace_back(M); // Store the specific declaration encountered.
+  }
+}
+
+for (const auto &BaseSpec : Def->bases()) {
+  if (const CXXRecordDecl *BaseDef =
+  BaseSpec.getType()->getAsCXXRecordDecl()) {
+Collect(BaseDef)

[clang-tools-extra] allow implicit completion inside empty template argument list (PR #138846)

2025-05-11 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] allow implicit completion inside empty template argument list (PR #138846)

2025-05-11 Thread Nathan Ridge via cfe-commits


@@ -2455,6 +2455,11 @@ bool isIncludeFile(llvm::StringRef Line) {
 }
 
 bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset) {
+  // Check if we're inside an empty template argument list

HighCommander4 wrote:

nit: for consistency with the other checks in this function, could you:

 * move this after the "Look at last line before completion only" check; and
 * formulate the check using `ends_with`?

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


[clang-tools-extra] allow implicit completion inside empty template argument list (PR #138846)

2025-05-11 Thread Nathan Ridge via cfe-commits

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

Looks reasonable to me, but the buildkite run is showing 
`AllowImplicitCompletions.All` is currently failing

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


[clang] [Clang][Sema] Disable checking invalid template id in primary variable template initializer (PR #139490)

2025-05-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

I think we would prefer a revert than adding dead blocks


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


[clang] [clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (PR #139489)

2025-05-11 Thread Younan Zhang via cfe-commits

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


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


[clang] [llvm] [RISCV] Add Andes XAndesVPackFPH (Andes Vector Packed FP16) extension. (PR #138827)

2025-05-11 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.


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


[clang] f7991aa - [clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (#139489)

2025-05-11 Thread via cfe-commits

Author: Nathan Ridge
Date: 2025-05-11T23:55:00-04:00
New Revision: f7991aae5e2a7be1d3118591bc41ec36b296fecc

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

LOG: [clang][AST] Pass ProfileArguments by value in 
findSpecialization{Impl,Locally} (#139489)

The arguments passed are lightweight (an ArrayRef and a pointer), and
findSpecializationImpl passes them to multiple functions, making it a
potential hazard to pass them by rvalue reference (even though no one
was in fact moving them).

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/DeclTemplate.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index a8100b642e04c..80c97681d9163 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -781,16 +781,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   bool loadLazySpecializationsImpl(llvm::ArrayRef Args,
TemplateParameterList *TPL = nullptr) const;
 
-  template 
-  typename SpecEntryTraits::DeclType*
+  template 
+  typename SpecEntryTraits::DeclType *
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
- void *&InsertPos, ProfileArguments &&...ProfileArgs);
+ void *&InsertPos, ProfileArguments... ProfileArgs);
 
   template 
   typename SpecEntryTraits::DeclType *
   findSpecializationLocally(llvm::FoldingSetVector &Specs,
-void *&InsertPos,
-ProfileArguments &&...ProfileArgs);
+void *&InsertPos, ProfileArguments... ProfileArgs);
 
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,

diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index d058831b9f6bf..6857eef87de38 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -382,12 +382,11 @@ template 
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationLocally(
 llvm::FoldingSetVector &Specs, void *&InsertPos,
-ProfileArguments &&...ProfileArgs) {
+ProfileArguments... ProfileArgs) {
   using SETraits = RedeclarableTemplateDecl::SpecEntryTraits;
 
   llvm::FoldingSetNodeID ID;
-  EntryType::Profile(ID, std::forward(ProfileArgs)...,
- getASTContext());
+  EntryType::Profile(ID, ProfileArgs..., getASTContext());
   EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
@@ -396,18 +395,15 @@ template 
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
 llvm::FoldingSetVector &Specs, void *&InsertPos,
-ProfileArguments &&...ProfileArgs) {
+ProfileArguments... ProfileArgs) {
 
-  if (auto *Found = findSpecializationLocally(
-  Specs, InsertPos, std::forward(ProfileArgs)...))
+  if (auto *Found = findSpecializationLocally(Specs, InsertPos, 
ProfileArgs...))
 return Found;
 
-  if (!loadLazySpecializationsImpl(
-  std::forward(ProfileArgs)...))
+  if (!loadLazySpecializationsImpl(ProfileArgs...))
 return nullptr;
 
-  return findSpecializationLocally(
-  Specs, InsertPos, std::forward(ProfileArgs)...);
+  return findSpecializationLocally(Specs, InsertPos, ProfileArgs...);
 }
 
 template



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


[clang] [clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (PR #139489)

2025-05-11 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] [clangd] Add tweak to add pure virtual overrides (PR #139348)

2025-05-11 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,296 @@
+//===--- OverridePureVirtuals.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "refactor/Tweak.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+
+class OverridePureVirtuals : public Tweak {
+public:
+  const char *id() const final; // defined by REGISTER_TWEAK.
+  bool prepare(const Selection &Sel) override;
+  Expected apply(const Selection &Sel) override;
+  std::string title() const override { return "Override pure virtual methods"; 
}
+  llvm::StringLiteral kind() const override {
+return CodeAction::QUICKFIX_KIND;
+  }
+
+private:
+  // Stores the CXXRecordDecl of the class being modified.
+  const CXXRecordDecl *CurrentDeclDef = nullptr;
+  // Stores pure virtual methods that need overriding, grouped by their 
original
+  // access specifier.
+  llvm::MapVector>
+  MissingMethodsByAccess;
+  // Stores the source locations of existing access specifiers in CurrentDecl.
+  llvm::MapVector AccessSpecifierLocations;
+
+  // Helper function to gather information before applying the tweak.
+  void collectMissingPureVirtuals(const Selection &Sel);
+};
+
+REGISTER_TWEAK(OverridePureVirtuals)
+
+// Function to get all unique pure virtual methods from the entire
+// base class hierarchy of CurrentDeclDef.
+llvm::SmallVector
+getAllUniquePureVirtualsFromBaseHierarchy(
+const clang::CXXRecordDecl *CurrentDeclDef) {
+  llvm::SmallVector AllPureVirtualsInHierarchy;
+  llvm::DenseSet CanonicalPureVirtualsSeen;
+
+  if (!CurrentDeclDef || !CurrentDeclDef->getDefinition())
+return AllPureVirtualsInHierarchy;
+
+  const clang::CXXRecordDecl *Def = CurrentDeclDef->getDefinition();
+
+  Def->forallBases([&](const clang::CXXRecordDecl *BaseDefinition) {
+for (const clang::CXXMethodDecl *Method : BaseDefinition->methods()) {
+  if (Method->isPureVirtual() &&
+  CanonicalPureVirtualsSeen.insert(Method->getCanonicalDecl()).second)
+AllPureVirtualsInHierarchy.emplace_back(Method);
+}
+// Continue iterating through all bases.
+return true;
+  });
+
+  return AllPureVirtualsInHierarchy;
+}
+
+// Gets canonical declarations of methods already overridden or implemented in
+// class D.
+llvm::SetVector
+getImplementedOrOverriddenCanonicals(const CXXRecordDecl *D) {
+  llvm::SetVector ImplementedSet;
+  for (const CXXMethodDecl *M : D->methods()) {
+// If M provides an implementation for any virtual method it overrides.
+// A method is an "implementation" if it's virtual and not pure.
+// Or if it directly overrides a base method.
+for (const CXXMethodDecl *OverriddenM : M->overridden_methods())
+  ImplementedSet.insert(OverriddenM->getCanonicalDecl());
+  }
+  return ImplementedSet;
+}
+
+// Get the location of every colon of the `AccessSpecifier`.
+llvm::MapVector
+getSpecifierLocations(const CXXRecordDecl *D) {
+  llvm::MapVector Locs;
+  for (auto *DeclNode : D->decls()) {
+if (const auto *ASD = llvm::dyn_cast(DeclNode))
+  Locs[ASD->getAccess()] = ASD->getColonLoc();
+  }
+  return Locs;
+}
+
+bool hasAbstractBaseAncestor(const clang::CXXRecordDecl *CurrentDecl) {
+  if (!CurrentDecl || !CurrentDecl->getDefinition())

zwuis wrote:

Is this condition always `false`? This function is called from `prepare` only. 
We can use `assert` instead.

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


[clang-tools-extra] [clangd] Add tweak to add pure virtual overrides (PR #139348)

2025-05-11 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,296 @@
+//===--- OverridePureVirtuals.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "refactor/Tweak.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+
+class OverridePureVirtuals : public Tweak {
+public:
+  const char *id() const final; // defined by REGISTER_TWEAK.
+  bool prepare(const Selection &Sel) override;
+  Expected apply(const Selection &Sel) override;
+  std::string title() const override { return "Override pure virtual methods"; 
}
+  llvm::StringLiteral kind() const override {
+return CodeAction::QUICKFIX_KIND;
+  }
+
+private:
+  // Stores the CXXRecordDecl of the class being modified.
+  const CXXRecordDecl *CurrentDeclDef = nullptr;
+  // Stores pure virtual methods that need overriding, grouped by their 
original
+  // access specifier.
+  llvm::MapVector>
+  MissingMethodsByAccess;
+  // Stores the source locations of existing access specifiers in CurrentDecl.
+  llvm::MapVector AccessSpecifierLocations;
+
+  // Helper function to gather information before applying the tweak.
+  void collectMissingPureVirtuals(const Selection &Sel);
+};
+
+REGISTER_TWEAK(OverridePureVirtuals)
+
+// Function to get all unique pure virtual methods from the entire
+// base class hierarchy of CurrentDeclDef.
+llvm::SmallVector
+getAllUniquePureVirtualsFromBaseHierarchy(
+const clang::CXXRecordDecl *CurrentDeclDef) {
+  llvm::SmallVector AllPureVirtualsInHierarchy;
+  llvm::DenseSet CanonicalPureVirtualsSeen;
+
+  if (!CurrentDeclDef || !CurrentDeclDef->getDefinition())
+return AllPureVirtualsInHierarchy;
+
+  const clang::CXXRecordDecl *Def = CurrentDeclDef->getDefinition();
+
+  Def->forallBases([&](const clang::CXXRecordDecl *BaseDefinition) {
+for (const clang::CXXMethodDecl *Method : BaseDefinition->methods()) {
+  if (Method->isPureVirtual() &&
+  CanonicalPureVirtualsSeen.insert(Method->getCanonicalDecl()).second)
+AllPureVirtualsInHierarchy.emplace_back(Method);
+}
+// Continue iterating through all bases.
+return true;
+  });
+
+  return AllPureVirtualsInHierarchy;
+}
+
+// Gets canonical declarations of methods already overridden or implemented in
+// class D.
+llvm::SetVector
+getImplementedOrOverriddenCanonicals(const CXXRecordDecl *D) {
+  llvm::SetVector ImplementedSet;
+  for (const CXXMethodDecl *M : D->methods()) {
+// If M provides an implementation for any virtual method it overrides.
+// A method is an "implementation" if it's virtual and not pure.
+// Or if it directly overrides a base method.
+for (const CXXMethodDecl *OverriddenM : M->overridden_methods())
+  ImplementedSet.insert(OverriddenM->getCanonicalDecl());
+  }
+  return ImplementedSet;
+}
+
+// Get the location of every colon of the `AccessSpecifier`.
+llvm::MapVector
+getSpecifierLocations(const CXXRecordDecl *D) {
+  llvm::MapVector Locs;
+  for (auto *DeclNode : D->decls()) {
+if (const auto *ASD = llvm::dyn_cast(DeclNode))
+  Locs[ASD->getAccess()] = ASD->getColonLoc();
+  }
+  return Locs;
+}
+
+bool hasAbstractBaseAncestor(const clang::CXXRecordDecl *CurrentDecl) {
+  if (!CurrentDecl || !CurrentDecl->getDefinition())
+return false;
+
+  return llvm::any_of(
+  CurrentDecl->getDefinition()->bases(), [](CXXBaseSpecifier BaseSpec) {
+const auto *D = BaseSpec.getType()->getAsCXXRecordDecl();
+const auto *Def = D ? D->getDefinition() : nullptr;
+return Def && Def->isAbstract();
+  });
+}
+
+// Check if the current class has any pure virtual method to be implemented.
+bool OverridePureVirtuals::prepare(const Selection &Sel) {
+  const SelectionTree::Node *Node = Sel.ASTSelection.commonAncestor();
+  if (!Node)
+return false;
+
+  // Make sure we have a definition.
+  CurrentDeclDef = Node->ASTNode.get();
+  if (!CurrentDeclDef || !CurrentDeclDef->getDefinition())
+return false;
+
+  // From now on, we should work with the definition.
+  CurrentDeclDef = CurrentDeclDef->getDefinition();
+
+  // Only offer for abstract classes with abstract bases.
+  return CurrentDeclDef->isAbstract() &&
+ hasAbstractBaseAncestor(CurrentDeclDef);
+}
+
+// Collects all pure virtual methods that are missing an override in
+// CurrentDecl, grouped by their original access specifier.
+void OverridePureVirtuals::collectMissingPureVirtuals(const Select

[clang-tools-extra] [clangd] Add tweak to add pure virtual overrides (PR #139348)

2025-05-11 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,296 @@
+//===--- OverridePureVirtuals.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "refactor/Tweak.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+
+class OverridePureVirtuals : public Tweak {
+public:
+  const char *id() const final; // defined by REGISTER_TWEAK.
+  bool prepare(const Selection &Sel) override;
+  Expected apply(const Selection &Sel) override;
+  std::string title() const override { return "Override pure virtual methods"; 
}
+  llvm::StringLiteral kind() const override {
+return CodeAction::QUICKFIX_KIND;
+  }
+
+private:
+  // Stores the CXXRecordDecl of the class being modified.
+  const CXXRecordDecl *CurrentDeclDef = nullptr;
+  // Stores pure virtual methods that need overriding, grouped by their 
original
+  // access specifier.
+  llvm::MapVector>
+  MissingMethodsByAccess;
+  // Stores the source locations of existing access specifiers in CurrentDecl.
+  llvm::MapVector AccessSpecifierLocations;
+
+  // Helper function to gather information before applying the tweak.
+  void collectMissingPureVirtuals(const Selection &Sel);
+};
+
+REGISTER_TWEAK(OverridePureVirtuals)
+
+// Function to get all unique pure virtual methods from the entire
+// base class hierarchy of CurrentDeclDef.
+llvm::SmallVector
+getAllUniquePureVirtualsFromBaseHierarchy(
+const clang::CXXRecordDecl *CurrentDeclDef) {
+  llvm::SmallVector AllPureVirtualsInHierarchy;
+  llvm::DenseSet CanonicalPureVirtualsSeen;
+
+  if (!CurrentDeclDef || !CurrentDeclDef->getDefinition())
+return AllPureVirtualsInHierarchy;
+
+  const clang::CXXRecordDecl *Def = CurrentDeclDef->getDefinition();
+
+  Def->forallBases([&](const clang::CXXRecordDecl *BaseDefinition) {
+for (const clang::CXXMethodDecl *Method : BaseDefinition->methods()) {
+  if (Method->isPureVirtual() &&
+  CanonicalPureVirtualsSeen.insert(Method->getCanonicalDecl()).second)
+AllPureVirtualsInHierarchy.emplace_back(Method);
+}
+// Continue iterating through all bases.
+return true;
+  });
+
+  return AllPureVirtualsInHierarchy;
+}
+
+// Gets canonical declarations of methods already overridden or implemented in
+// class D.
+llvm::SetVector
+getImplementedOrOverriddenCanonicals(const CXXRecordDecl *D) {
+  llvm::SetVector ImplementedSet;
+  for (const CXXMethodDecl *M : D->methods()) {
+// If M provides an implementation for any virtual method it overrides.
+// A method is an "implementation" if it's virtual and not pure.
+// Or if it directly overrides a base method.
+for (const CXXMethodDecl *OverriddenM : M->overridden_methods())
+  ImplementedSet.insert(OverriddenM->getCanonicalDecl());
+  }
+  return ImplementedSet;
+}
+
+// Get the location of every colon of the `AccessSpecifier`.
+llvm::MapVector
+getSpecifierLocations(const CXXRecordDecl *D) {
+  llvm::MapVector Locs;
+  for (auto *DeclNode : D->decls()) {
+if (const auto *ASD = llvm::dyn_cast(DeclNode))
+  Locs[ASD->getAccess()] = ASD->getColonLoc();
+  }
+  return Locs;
+}
+
+bool hasAbstractBaseAncestor(const clang::CXXRecordDecl *CurrentDecl) {
+  if (!CurrentDecl || !CurrentDecl->getDefinition())
+return false;
+
+  return llvm::any_of(
+  CurrentDecl->getDefinition()->bases(), [](CXXBaseSpecifier BaseSpec) {
+const auto *D = BaseSpec.getType()->getAsCXXRecordDecl();
+const auto *Def = D ? D->getDefinition() : nullptr;
+return Def && Def->isAbstract();
+  });
+}
+
+// Check if the current class has any pure virtual method to be implemented.
+bool OverridePureVirtuals::prepare(const Selection &Sel) {
+  const SelectionTree::Node *Node = Sel.ASTSelection.commonAncestor();
+  if (!Node)
+return false;
+
+  // Make sure we have a definition.
+  CurrentDeclDef = Node->ASTNode.get();
+  if (!CurrentDeclDef || !CurrentDeclDef->getDefinition())
+return false;
+
+  // From now on, we should work with the definition.
+  CurrentDeclDef = CurrentDeclDef->getDefinition();
+
+  // Only offer for abstract classes with abstract bases.
+  return CurrentDeclDef->isAbstract() &&
+ hasAbstractBaseAncestor(CurrentDeclDef);
+}
+
+// Collects all pure virtual methods that are missing an override in
+// CurrentDecl, grouped by their original access specifier.
+void OverridePureVirtuals::collectMissingPureVirtuals(const Select

[clang-tools-extra] [clangd] Add tweak to add pure virtual overrides (PR #139348)

2025-05-11 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,296 @@
+//===--- OverridePureVirtuals.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "refactor/Tweak.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+
+class OverridePureVirtuals : public Tweak {
+public:
+  const char *id() const final; // defined by REGISTER_TWEAK.
+  bool prepare(const Selection &Sel) override;
+  Expected apply(const Selection &Sel) override;
+  std::string title() const override { return "Override pure virtual methods"; 
}
+  llvm::StringLiteral kind() const override {
+return CodeAction::QUICKFIX_KIND;
+  }
+
+private:
+  // Stores the CXXRecordDecl of the class being modified.
+  const CXXRecordDecl *CurrentDeclDef = nullptr;
+  // Stores pure virtual methods that need overriding, grouped by their 
original
+  // access specifier.
+  llvm::MapVector>
+  MissingMethodsByAccess;
+  // Stores the source locations of existing access specifiers in CurrentDecl.
+  llvm::MapVector AccessSpecifierLocations;
+
+  // Helper function to gather information before applying the tweak.
+  void collectMissingPureVirtuals(const Selection &Sel);
+};
+
+REGISTER_TWEAK(OverridePureVirtuals)
+
+// Function to get all unique pure virtual methods from the entire
+// base class hierarchy of CurrentDeclDef.
+llvm::SmallVector
+getAllUniquePureVirtualsFromBaseHierarchy(
+const clang::CXXRecordDecl *CurrentDeclDef) {
+  llvm::SmallVector AllPureVirtualsInHierarchy;
+  llvm::DenseSet CanonicalPureVirtualsSeen;
+
+  if (!CurrentDeclDef || !CurrentDeclDef->getDefinition())
+return AllPureVirtualsInHierarchy;
+
+  const clang::CXXRecordDecl *Def = CurrentDeclDef->getDefinition();
+
+  Def->forallBases([&](const clang::CXXRecordDecl *BaseDefinition) {
+for (const clang::CXXMethodDecl *Method : BaseDefinition->methods()) {
+  if (Method->isPureVirtual() &&
+  CanonicalPureVirtualsSeen.insert(Method->getCanonicalDecl()).second)
+AllPureVirtualsInHierarchy.emplace_back(Method);
+}
+// Continue iterating through all bases.
+return true;
+  });
+
+  return AllPureVirtualsInHierarchy;
+}
+
+// Gets canonical declarations of methods already overridden or implemented in
+// class D.
+llvm::SetVector
+getImplementedOrOverriddenCanonicals(const CXXRecordDecl *D) {
+  llvm::SetVector ImplementedSet;
+  for (const CXXMethodDecl *M : D->methods()) {
+// If M provides an implementation for any virtual method it overrides.
+// A method is an "implementation" if it's virtual and not pure.
+// Or if it directly overrides a base method.
+for (const CXXMethodDecl *OverriddenM : M->overridden_methods())
+  ImplementedSet.insert(OverriddenM->getCanonicalDecl());
+  }
+  return ImplementedSet;
+}
+
+// Get the location of every colon of the `AccessSpecifier`.
+llvm::MapVector
+getSpecifierLocations(const CXXRecordDecl *D) {
+  llvm::MapVector Locs;
+  for (auto *DeclNode : D->decls()) {
+if (const auto *ASD = llvm::dyn_cast(DeclNode))
+  Locs[ASD->getAccess()] = ASD->getColonLoc();
+  }
+  return Locs;
+}
+
+bool hasAbstractBaseAncestor(const clang::CXXRecordDecl *CurrentDecl) {
+  if (!CurrentDecl || !CurrentDecl->getDefinition())
+return false;
+
+  return llvm::any_of(
+  CurrentDecl->getDefinition()->bases(), [](CXXBaseSpecifier BaseSpec) {
+const auto *D = BaseSpec.getType()->getAsCXXRecordDecl();
+const auto *Def = D ? D->getDefinition() : nullptr;
+return Def && Def->isAbstract();
+  });
+}
+
+// Check if the current class has any pure virtual method to be implemented.
+bool OverridePureVirtuals::prepare(const Selection &Sel) {
+  const SelectionTree::Node *Node = Sel.ASTSelection.commonAncestor();
+  if (!Node)
+return false;
+
+  // Make sure we have a definition.
+  CurrentDeclDef = Node->ASTNode.get();
+  if (!CurrentDeclDef || !CurrentDeclDef->getDefinition())
+return false;
+
+  // From now on, we should work with the definition.
+  CurrentDeclDef = CurrentDeclDef->getDefinition();
+
+  // Only offer for abstract classes with abstract bases.
+  return CurrentDeclDef->isAbstract() &&
+ hasAbstractBaseAncestor(CurrentDeclDef);
+}
+
+// Collects all pure virtual methods that are missing an override in
+// CurrentDecl, grouped by their original access specifier.
+void OverridePureVirtuals::collectMissingPureVirtuals(const Select

[clang] [llvm] [RISCV][MC] Add support for Q extension (PR #139369)

2025-05-11 Thread Pengcheng Wang via cfe-commits


@@ -43,34 +43,43 @@ def WriteAtomicSTD  : SchedWrite;// Atomic store double 
word
 def WriteFAdd16 : SchedWrite;// 16-bit floating point 
addition/subtraction
 def WriteFAdd32 : SchedWrite;// 32-bit floating point 
addition/subtraction
 def WriteFAdd64 : SchedWrite;// 64-bit floating point 
addition/subtraction
+def WriteFAdd128: SchedWrite;// 128-bit floating point 
addition/subtraction

wangpc-pp wrote:

I think we should put schedule things into another seperated PR to simplify 
this PR.

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


[clang] [llvm] [RISCV][MC] Add support for Q extension (PR #139369)

2025-05-11 Thread Pengcheng Wang via cfe-commits

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


[clang] [llvm] [RISCV][MC] Add support for Q extension (PR #139369)

2025-05-11 Thread Pengcheng Wang via cfe-commits


@@ -131,20 +131,22 @@ def FPR32INX : RegisterOperand {
 // The DAGOperand can be unset if the predicates are not enough to define it.
 class ExtInfo predicates,
   ValueType primaryvt, DAGOperand primaryty, DAGOperand f32ty,
-  DAGOperand f64ty, DAGOperand f16ty> {
+  DAGOperand f64ty, DAGOperand f16ty, DAGOperand f128ty> {
   list Predicates = predicates;
   string Suffix = suffix;
   string Space = space;
   DAGOperand PrimaryTy = primaryty;
   DAGOperand F16Ty = f16ty;
   DAGOperand F32Ty = f32ty;
   DAGOperand F64Ty = f64ty;
+  DAGOperand F128Ty = f128ty;

wangpc-pp wrote:

I think we don't have `Zqinx`?
> In the future, an RV64Zqinx quad-precision extension could be defined 
> analogously to RV32Zdinx. An RV32Zqinx extension could also be defined but 
> would require quad-register groups.

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


[clang] [llvm] [RISCV][MC] Add support for Q extension (PR #139369)

2025-05-11 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp commented:

We should support `Zfa+Q` as well (this can be a follow-up).

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


[clang] [clang] Enforce 1-based indexing for command line source locations (PR #139457)

2025-05-11 Thread via cfe-commits

cor3ntin wrote:

Thanks for working on that.
I think it might better to do that check where 
`ParsedSourceLocation::FromString` is called, so that we can have a proper
front-end diagnostics for it (search for `err_fe_invalid_code_complete_file` 
and `OPT_code_completion_at`)

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


[clang] [Clang] Suppress a ``-Wimplicit-int-conversion``warning introduced in #126846 (PR #139429)

2025-05-11 Thread via cfe-commits

cor3ntin wrote:

If that warning is disruptive, maybe we should consider making it a separate 
warning that people can disable independently? It is certainly a potential 
source of bugs, so I'm not sure removing it entirely is the right approach  
@AaronBallman 

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


[clang] [TableGen] Use StringRef::take_while (NFC) (PR #139461)

2025-05-11 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/139461

None



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] [TableGen] Use StringRef::take_while (NFC) (PR #139461)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/utils/TableGen/ClangOptionDocEmitter.cpp (+1-4) 


``diff
diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp 
b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index b6c1aad90b5cb..b651820bb4ab5 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -205,10 +205,7 @@ std::string escapeRST(StringRef Str) {
 }
 
 StringRef getSphinxOptionID(StringRef OptionName) {
-  for (auto I = OptionName.begin(), E = OptionName.end(); I != E; ++I)
-if (!isalnum(*I) && *I != '-')
-  return OptionName.substr(0, I - OptionName.begin());
-  return OptionName;
+  return OptionName.take_while([](char C) { return isalnum(C) || C == '-'; });
 }
 
 bool canSphinxCopeWithOption(const Record *Option) {

``




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


[clang-tools-extra] [clang-tidy] Switch misc-confusable-identifiers check to a faster algorithm. (PR #130369)

2025-05-11 Thread Richard Smith via cfe-commits

zygoloid wrote:

Ping x6

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


[clang] [clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (PR #139489)

2025-05-11 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

(This came up during https://github.com/llvm/llvm-project/issues/139019 as a 
potential diagnosis, but it does not fix the crash. As mentioned, no one was in 
fact moving from the arguments, so passing them by rvalue reference and 
forwarding them multiple times in the same function was just poor style rather 
than an actual bug.)

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


[clang] [Clang][Sema] Disable checking invalid template id in primary variable template initializer (PR #139490)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yanzuo Liu (zwuis)


Changes

Workaround for #139067

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplate.cpp (+3) 
- (modified) clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp (+2-2) 


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7940340064eda..365c61949379d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4382,6 +4382,8 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
   return Context.isSameTemplateArgument(Arg1, Arg2);
 };
 
+// Workaround for GH139067 / 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120190
+#if 0
 if (VarDecl *Var = Template->getTemplatedDecl();
 ParsingInitForAutoVars.count(Var) &&
 llvm::equal(
@@ -4393,6 +4395,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
   << diag::ParsingInitFor::VarTemplate << Var << Var->getType();
   return true;
 }
+#endif
 
 SmallVector PartialSpecs;
 Template->getPartialSpecializations(PartialSpecs);
diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp 
b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
index 1fe0ce9aabf29..a60d723e477c4 100644
--- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -495,12 +495,12 @@ static_assert(C::VALUEARRAY[0] == 0, "");
 
 namespace appear_in_its_own_init {
 template 
-auto GH51347 = GH51347; // expected-error {{variable template 'GH51347' 
declared with deduced type 'auto' cannot appear in its own initializer}}
+auto GH51347 = GH51347;
 
 template 
 auto a = [] {
   using U = T;
-  a; // expected-error {{variable template 'a' declared with deduced 
type 'auto' cannot appear in its own initializer}}
+  a;
 };
 
 template  int b;

``




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


[clang] [clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (PR #139489)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)


Changes

The arguments passed are lightweight (an ArrayRef and a pointer), and 
findSpecializationImpl passes them to multiple functions, making it a potential 
hazard to pass them by rvalue reference (even though no one was in fact moving 
them).

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


2 Files Affected:

- (modified) clang/include/clang/AST/DeclTemplate.h (+4-5) 
- (modified) clang/lib/AST/DeclTemplate.cpp (+6-10) 


``diff
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index a8100b642e04c..80c97681d9163 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -781,16 +781,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   bool loadLazySpecializationsImpl(llvm::ArrayRef Args,
TemplateParameterList *TPL = nullptr) const;
 
-  template 
-  typename SpecEntryTraits::DeclType*
+  template 
+  typename SpecEntryTraits::DeclType *
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
- void *&InsertPos, ProfileArguments &&...ProfileArgs);
+ void *&InsertPos, ProfileArguments... ProfileArgs);
 
   template 
   typename SpecEntryTraits::DeclType *
   findSpecializationLocally(llvm::FoldingSetVector &Specs,
-void *&InsertPos,
-ProfileArguments &&...ProfileArgs);
+void *&InsertPos, ProfileArguments... ProfileArgs);
 
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index d058831b9f6bf..6857eef87de38 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -382,12 +382,11 @@ template 
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationLocally(
 llvm::FoldingSetVector &Specs, void *&InsertPos,
-ProfileArguments &&...ProfileArgs) {
+ProfileArguments... ProfileArgs) {
   using SETraits = RedeclarableTemplateDecl::SpecEntryTraits;
 
   llvm::FoldingSetNodeID ID;
-  EntryType::Profile(ID, std::forward(ProfileArgs)...,
- getASTContext());
+  EntryType::Profile(ID, ProfileArgs..., getASTContext());
   EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
@@ -396,18 +395,15 @@ template 
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
 llvm::FoldingSetVector &Specs, void *&InsertPos,
-ProfileArguments &&...ProfileArgs) {
+ProfileArguments... ProfileArgs) {
 
-  if (auto *Found = findSpecializationLocally(
-  Specs, InsertPos, std::forward(ProfileArgs)...))
+  if (auto *Found = findSpecializationLocally(Specs, InsertPos, 
ProfileArgs...))
 return Found;
 
-  if (!loadLazySpecializationsImpl(
-  std::forward(ProfileArgs)...))
+  if (!loadLazySpecializationsImpl(ProfileArgs...))
 return nullptr;
 
-  return findSpecializationLocally(
-  Specs, InsertPos, std::forward(ProfileArgs)...);
+  return findSpecializationLocally(Specs, InsertPos, ProfileArgs...);
 }
 
 template

``




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


[clang] [clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (PR #139489)

2025-05-11 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/139489

The arguments passed are lightweight (an ArrayRef and a pointer), and 
findSpecializationImpl passes them to multiple functions, making it a potential 
hazard to pass them by rvalue reference (even though no one was in fact moving 
them).

>From 069edae907f41f127ac1f4010a7e01acbc494b40 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 11 May 2025 22:02:21 -0500
Subject: [PATCH] [clang][AST] Pass ProfileArguments by value in
 findSpecialization{Impl,Locally}

The arguments passed are lightweight (an ArrayRef and a pointer),
and findSpecializationImpl passes them to multiple functions,
making it a potential hazard to pass them by rvalue reference
(even though no one was in fact moving them).
---
 clang/include/clang/AST/DeclTemplate.h |  9 -
 clang/lib/AST/DeclTemplate.cpp | 16 ++--
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index a8100b642e04c..80c97681d9163 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -781,16 +781,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   bool loadLazySpecializationsImpl(llvm::ArrayRef Args,
TemplateParameterList *TPL = nullptr) const;
 
-  template 
-  typename SpecEntryTraits::DeclType*
+  template 
+  typename SpecEntryTraits::DeclType *
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
- void *&InsertPos, ProfileArguments &&...ProfileArgs);
+ void *&InsertPos, ProfileArguments... ProfileArgs);
 
   template 
   typename SpecEntryTraits::DeclType *
   findSpecializationLocally(llvm::FoldingSetVector &Specs,
-void *&InsertPos,
-ProfileArguments &&...ProfileArgs);
+void *&InsertPos, ProfileArguments... ProfileArgs);
 
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index d058831b9f6bf..6857eef87de38 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -382,12 +382,11 @@ template 
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationLocally(
 llvm::FoldingSetVector &Specs, void *&InsertPos,
-ProfileArguments &&...ProfileArgs) {
+ProfileArguments... ProfileArgs) {
   using SETraits = RedeclarableTemplateDecl::SpecEntryTraits;
 
   llvm::FoldingSetNodeID ID;
-  EntryType::Profile(ID, std::forward(ProfileArgs)...,
- getASTContext());
+  EntryType::Profile(ID, ProfileArgs..., getASTContext());
   EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
@@ -396,18 +395,15 @@ template 
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
 llvm::FoldingSetVector &Specs, void *&InsertPos,
-ProfileArguments &&...ProfileArgs) {
+ProfileArguments... ProfileArgs) {
 
-  if (auto *Found = findSpecializationLocally(
-  Specs, InsertPos, std::forward(ProfileArgs)...))
+  if (auto *Found = findSpecializationLocally(Specs, InsertPos, 
ProfileArgs...))
 return Found;
 
-  if (!loadLazySpecializationsImpl(
-  std::forward(ProfileArgs)...))
+  if (!loadLazySpecializationsImpl(ProfileArgs...))
 return nullptr;
 
-  return findSpecializationLocally(
-  Specs, InsertPos, std::forward(ProfileArgs)...);
+  return findSpecializationLocally(Specs, InsertPos, ProfileArgs...);
 }
 
 template

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


[clang] [Clang][Sema] Disable checking invalid template id in primary variable template initializer (PR #139490)

2025-05-11 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/139490

Workaround for #139067

>From c5a9cda3e5c3aa2b07281e373e9736045a01643b Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Mon, 12 May 2025 11:08:50 +0800
Subject: [PATCH] Disable checking invalid template id in primary variable
 template initializer

---
 clang/lib/Sema/SemaTemplate.cpp   | 3 +++
 clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7940340064eda..365c61949379d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4382,6 +4382,8 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
   return Context.isSameTemplateArgument(Arg1, Arg2);
 };
 
+// Workaround for GH139067 / 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120190
+#if 0
 if (VarDecl *Var = Template->getTemplatedDecl();
 ParsingInitForAutoVars.count(Var) &&
 llvm::equal(
@@ -4393,6 +4395,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
   << diag::ParsingInitFor::VarTemplate << Var << Var->getType();
   return true;
 }
+#endif
 
 SmallVector PartialSpecs;
 Template->getPartialSpecializations(PartialSpecs);
diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp 
b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
index 1fe0ce9aabf29..a60d723e477c4 100644
--- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -495,12 +495,12 @@ static_assert(C::VALUEARRAY[0] == 0, "");
 
 namespace appear_in_its_own_init {
 template 
-auto GH51347 = GH51347; // expected-error {{variable template 'GH51347' 
declared with deduced type 'auto' cannot appear in its own initializer}}
+auto GH51347 = GH51347;
 
 template 
 auto a = [] {
   using U = T;
-  a; // expected-error {{variable template 'a' declared with deduced 
type 'auto' cannot appear in its own initializer}}
+  a;
 };
 
 template  int b;

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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-11 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r HEAD~1...HEAD clang/tools/include-mapping/test.py
``





View the diff from darker here.


``diff
--- test.py 2025-05-11 19:36:59.00 +
+++ test.py 2025-05-11 19:39:49.979769 +
@@ -90,11 +90,13 @@
 
 this is matched
   
 
 """
-self.assertEqual(_ParseSymbolPage(html, "foo", "foo"), 
set(["", ""]))
+self.assertEqual(
+_ParseSymbolPage(html, "foo", "foo"), set(["", 
""])
+)
 
 def testParseSymbolPage_MulHeadersInSameDiv(self):
 # Multile  blocks in a Div.
 # Defined in header 
 # Defined in header 
@@ -141,10 +143,12 @@
   this is matched
 
 
 """
 self.assertEqual(_ParseSymbolPage(html, "int8_t", "int8_t"), 
set([""]))
-self.assertEqual(_ParseSymbolPage(html, "int16_t", "int16_t"), 
set([""]))
+self.assertEqual(
+_ParseSymbolPage(html, "int16_t", "int16_t"), set([""])
+)
 
 
 if __name__ == "__main__":
 unittest.main()

``




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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-11 Thread Robin Caloudis via cfe-commits

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


[clang] Provide qualified symbol as argument (PR #139463)

2025-05-11 Thread Robin Caloudis via cfe-commits

https://github.com/robincaloudis created 
https://github.com/llvm/llvm-project/pull/139463

None

>From 6b842dfb2e81a0438f380b86fc4392bf0316f31c Mon Sep 17 00:00:00 2001
From: Robin Caloudis 
Date: Sun, 11 May 2025 21:36:59 +0200
Subject: [PATCH] Provide qualified symbol as argument

---
 clang/tools/include-mapping/test.py | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/tools/include-mapping/test.py 
b/clang/tools/include-mapping/test.py
index eef328381f2bb..cff8862e6e026 100755
--- a/clang/tools/include-mapping/test.py
+++ b/clang/tools/include-mapping/test.py
@@ -52,7 +52,7 @@ def testParseSymbolPage_SingleHeader(self):
   
 
 """
-self.assertEqual(_ParseSymbolPage(html, "foo"), set([""]))
+self.assertEqual(_ParseSymbolPage(html, "foo", "foo"), 
set([""]))
 
 def testParseSymbolPage_MulHeaders(self):
 #  Defined in header 
@@ -92,7 +92,7 @@ def testParseSymbolPage_MulHeaders(self):
   
 
 """
-self.assertEqual(_ParseSymbolPage(html, "foo"), set(["", 
""]))
+self.assertEqual(_ParseSymbolPage(html, "foo", "foo"), 
set(["", ""]))
 
 def testParseSymbolPage_MulHeadersInSameDiv(self):
 # Multile  blocks in a Div.
@@ -118,7 +118,7 @@ def testParseSymbolPage_MulHeadersInSameDiv(self):
 
 """
 self.assertEqual(
-_ParseSymbolPage(html, "foo"), set(["", ""])
+_ParseSymbolPage(html, "foo", "foo"), set(["", 
""])
 )
 
 def testParseSymbolPage_MulSymbolsInSameTd(self):
@@ -142,8 +142,8 @@ def testParseSymbolPage_MulSymbolsInSameTd(self):
 
 
 """
-self.assertEqual(_ParseSymbolPage(html, "int8_t"), set([""]))
-self.assertEqual(_ParseSymbolPage(html, "int16_t"), set([""]))
+self.assertEqual(_ParseSymbolPage(html, "int8_t", "int8_t"), 
set([""]))
+self.assertEqual(_ParseSymbolPage(html, "int16_t", "int16_t"), 
set([""]))
 
 
 if __name__ == "__main__":

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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-11 Thread Robin Caloudis via cfe-commits

https://github.com/robincaloudis updated 
https://github.com/llvm/llvm-project/pull/139463



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-11 Thread Robin Caloudis via cfe-commits

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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-11 Thread Robin Caloudis via cfe-commits

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


[clang] [CIR] Upstream shift operators for VectorType (PR #139465)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds support for shift ops for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487

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


6 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+8-7) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td (+19) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+2-3) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+9-6) 
- (modified) clang/test/CIR/CodeGen/vector-ext.cpp (+65) 
- (modified) clang/test/CIR/CodeGen/vector.cpp (+65) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 7aff5edb88167..b0e593b011109 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -1401,18 +1401,19 @@ def ShiftOp : CIR_Op<"shift", [Pure]> {
 The `cir.shift` operation performs a bitwise shift, either to the left or 
to
 the right, based on the first operand. The second operand specifies the
 value to be shifted, and the third operand determines the number of
-positions by which the shift is applied. Both the second and third operands
-are required to be integers.
+positions by which the shift is applied, they must be either all vector of
+integer type, or all integer type. If they are vectors, each vector 
element of
+the shift target is shifted by the corresponding shift amount in
+the shift amount vector.
 
 ```mlir
-%7 = cir.shift(left, %1 : !u64i, %4 : !s32i) -> !u64i
+%res = cir.shift(left, %lhs : !u64i, %amount : !s32i) -> !u64i
+%new_vec = cir.shift(left, %lhs : !cir.vector<2 x !s32i>, %rhs : 
!cir.vector<2 x !s32i>) -> !cir.vector<2 x !s32i>
 ```
   }];
 
-  // TODO(cir): Support vectors. CIR_IntType -> CIR_AnyIntOrVecOfInt. Also
-  // update the description above.
-  let results = (outs CIR_IntType:$result);
-  let arguments = (ins CIR_IntType:$value, CIR_IntType:$amount,
+  let results = (outs CIR_AnyIntOrVecOfInt:$result);
+  let arguments = (ins CIR_AnyIntOrVecOfInt:$value, 
CIR_AnyIntOrVecOfInt:$amount,
UnitAttr:$isShiftleft);
 
   let assemblyFormat = [{
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
index 00f67e2a03a25..902d6535ff717 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
@@ -174,4 +174,23 @@ def CIR_PtrToVoidPtrType
 "$_builder.getType<" # cppType # ">("
 "cir::VoidType::get($_builder.getContext(">;
 
+//===--===//
+// Vector Type predicates
+//===--===//
+
+// Vector of integral type
+def IntegerVector : Type<
+And<[
+  CPred<"::mlir::isa<::cir::VectorType>($_self)">,
+  CPred<"::mlir::isa<::cir::IntType>("
+"::mlir::cast<::cir::VectorType>($_self).getElementType())">,
+  CPred<"::mlir::cast<::cir::IntType>("
+"::mlir::cast<::cir::VectorType>($_self).getElementType())"
+".isFundamental()">
+]>, "!cir.vector of !cir.int"> {
+}
+
+// Any Integer or Vector of Integer Constraints
+def CIR_AnyIntOrVecOfInt: AnyTypeOf<[CIR_AnyIntType, IntegerVector]>;
+
 #endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index b131edaf403ed..2f7e3496d55a5 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1297,9 +1297,8 @@ OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
 LogicalResult cir::ShiftOp::verify() {
   mlir::Operation *op = getOperation();
   mlir::Type resType = getResult().getType();
-  assert(!cir::MissingFeatures::vectorType());
-  bool isOp0Vec = false;
-  bool isOp1Vec = false;
+  const bool isOp0Vec = 
mlir::isa(op->getOperand(0).getType());
+  const bool isOp1Vec = 
mlir::isa(op->getOperand(1).getType());
   if (isOp0Vec != isOp1Vec)
 return emitOpError() << "input types cannot be one vector and one scalar";
   if (isOp1Vec && op->getOperand(1).getType() != resType) {
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 5986655ababe9..1951d2e3a3b79 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1376,16 +1376,17 @@ mlir::LogicalResult 
CIRToLLVMShiftOpLowering::matchAndRewrite(
   auto cirValTy = mlir::dyn_cast(op.getValue().getType());
 
   // Operands could also be vector type
-  assert(!cir::MissingFeatures::vectorType());
+  auto cirAmtVTy = mlir::dyn_cast(op.ge

[clang] [CIR] Upstream shift operators for VectorType (PR #139465)

2025-05-11 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/139465

This change adds support for shift ops for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Robin Caloudis (robincaloudis)


Changes

## Why
In 
https://github.com/llvm/llvm-project/pull/113612/files#diff-ada12e18f3e902b41b6989b46455c4e32656276e59907026e2464cf57d10d583,
 the parameter `qual_name` was introduced. However, the tests have not been 
adopted accordingly and hence cannot be executed.

## What
Fix the execution of tests by providing the missing argument.

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


1 Files Affected:

- (modified) clang/tools/include-mapping/test.py (+9-5) 


``diff
diff --git a/clang/tools/include-mapping/test.py 
b/clang/tools/include-mapping/test.py
index eef328381f2bb..81803855dac8f 100755
--- a/clang/tools/include-mapping/test.py
+++ b/clang/tools/include-mapping/test.py
@@ -52,7 +52,7 @@ def testParseSymbolPage_SingleHeader(self):
   
 
 """
-self.assertEqual(_ParseSymbolPage(html, "foo"), set([""]))
+self.assertEqual(_ParseSymbolPage(html, "foo", "foo"), 
set([""]))
 
 def testParseSymbolPage_MulHeaders(self):
 #  Defined in header 
@@ -92,7 +92,9 @@ def testParseSymbolPage_MulHeaders(self):
   
 
 """
-self.assertEqual(_ParseSymbolPage(html, "foo"), set(["", 
""]))
+self.assertEqual(
+_ParseSymbolPage(html, "foo", "foo"), set(["", 
""])
+)
 
 def testParseSymbolPage_MulHeadersInSameDiv(self):
 # Multile  blocks in a Div.
@@ -118,7 +120,7 @@ def testParseSymbolPage_MulHeadersInSameDiv(self):
 
 """
 self.assertEqual(
-_ParseSymbolPage(html, "foo"), set(["", ""])
+_ParseSymbolPage(html, "foo", "foo"), set(["", 
""])
 )
 
 def testParseSymbolPage_MulSymbolsInSameTd(self):
@@ -142,8 +144,10 @@ def testParseSymbolPage_MulSymbolsInSameTd(self):
 
 
 """
-self.assertEqual(_ParseSymbolPage(html, "int8_t"), set([""]))
-self.assertEqual(_ParseSymbolPage(html, "int16_t"), set([""]))
+self.assertEqual(_ParseSymbolPage(html, "int8_t", "int8_t"), 
set([""]))
+self.assertEqual(
+_ParseSymbolPage(html, "int16_t", "int16_t"), set([""])
+)
 
 
 if __name__ == "__main__":

``




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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-11 Thread Robin Caloudis via cfe-commits

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


[clang] [Clang] Stop changing DC when instantiating dependent friend specializations (PR #139436)

2025-05-11 Thread Matheus Izvekov via cfe-commits


@@ -5751,14 +5751,16 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 RebuildTypeSourceInfoForDefaultSpecialMembers();
 SetDeclDefaulted(Function, PatternDecl->getLocation());
   } else {
-NamedDecl *ND = Function;
-DeclContext *DC = ND->getLexicalDeclContext();
+DeclContext *DC = Function->getLexicalDeclContext();
 std::optional> Innermost;
-if (auto *Primary = Function->getPrimaryTemplate();
-Primary &&
+bool NeedDCFromPrimaryTemplate =
 !isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function) &&
 Function->getTemplateSpecializationKind() !=
-TSK_ExplicitSpecialization) {
+TSK_ExplicitSpecialization &&
+!PatternDecl->getDependentSpecializationInfo();

mizvekov wrote:

Aren't we simply returning the wrong info above in 
`Function->getTemplateSpecializationKind()`?
Did you look into fixing that?

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


[clang] [TableGen] Use StringRef::substr instead of StringRef::slice (NFC) (PR #139485)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

StringRef::substr is shorter here because we can rely on its default
second parameter.


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


1 Files Affected:

- (modified) clang/utils/TableGen/ClangDiagnosticsEmitter.cpp (+5-5) 


``diff
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index e72288801a830..e347b89a85d46 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1089,7 +1089,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
 
 if (End) {
   Parsed.push_back(New(Text.slice(0, End), "diagtext"));
-  Text = Text.slice(End, StringRef::npos);
+  Text = Text.substr(End);
   if (Text.empty())
 break;
 }
@@ -1103,7 +1103,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
 // Extract the (optional) modifier.
 size_t ModLength = Text.find_first_of("0123456789<{");
 StringRef Modifier = Text.slice(0, ModLength);
-Text = Text.slice(ModLength, StringRef::npos);
+Text = Text.substr(ModLength);
 ModifierType ModType = StringSwitch{Modifier}
.Case("select", MT_Select)
.Case("enum_select", MT_EnumSelect)
@@ -1154,7 +1154,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
   Text = Text.drop_front(); // Drop '<'
   size_t EnumNameLen = Text.find_first_of('>');
   EnumSelect->EnumName = Text.slice(0, EnumNameLen);
-  Text = Text.slice(EnumNameLen, StringRef::npos);
+  Text = Text.substr(EnumNameLen);
   ExpectAndConsume(">");
 
   if (Text[0] != '{')
@@ -1169,7 +1169,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
   Text = Text.drop_front(); // '%'
   size_t OptionNameLen = Text.find_first_of("{");
   EnumSelect->OptionEnumNames.push_back(Text.slice(0, OptionNameLen));
-  Text = Text.slice(OptionNameLen, StringRef::npos);
+  Text = Text.substr(OptionNameLen);
 } else {
   EnumSelect->OptionEnumNames.push_back({});
 }
@@ -1206,7 +1206,7 @@ Piece 
*DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
 assert(!Text.empty());
 Plural->OptionPrefixes.push_back(
 New(Text.slice(0, End), "diagtext"));
-Text = Text.slice(End, StringRef::npos);
+Text = Text.substr(End);
 Plural->Options.push_back(
 parseDiagText(Text, StopAt::PipeOrCloseBrace));
 assert(!Text.empty() && "malformed %plural");

``




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


[clang] [TableGen] Use StringRef::substr instead of StringRef::slice (NFC) (PR #139485)

2025-05-11 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/139485

StringRef::substr is shorter here because we can rely on its default
second parameter.




  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] [TableGen] Use StringRef::substr instead of StringRef::slice (NFC) (PR #139485)

2025-05-11 Thread Rahul Joshi via cfe-commits

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


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


[clang] [Clang] Fix handling of reference types in tryEvaluateBuiltinObjectSize (PR #138247)

2025-05-11 Thread via cfe-commits

zhscn wrote:

ping @cor3ntin @erichkeane 

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


[clang] [clang-cl] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--precompile` (PR #121046)

2025-05-11 Thread Chuanqi Xu via cfe-commits


@@ -14,3 +14,11 @@
 
 //--- test.pcm
 // CPP20WARNING-NOT: clang-cl: warning: argument unused during compilation: 
'/std:c++20' [-Wunused-command-line-argument]
+
+// test whether the following outputs %Hello.bmi
+// RUN: %clang_cl /std:c++20 --precompile -x c++-module 
-fmodule-output=%t/Hello.bmi -Fo"%t/Hello.bmi" -c %t/Hello.cppm -### 2>&1 | 
FileCheck %s

ChuanqiXu9 wrote:

Sorry for ignoring this. `--precompile` will be meaningless if it is followed 
by a `-c`. So the command line in cmake's thread actually use `-fmodule-output`.

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


[clang] [Clang] Suppress a ``-Wimplicit-int-conversion``warning introduced in #126846 (PR #139429)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yutong Zhu (YutongZhuu)


Changes

This PR reverts a change made in #126846. 

#126846 introduced an ``-Wimplicit-int-conversion`` diagnosis for 
```c++
int8_t x = something;
x = -x; // warning here
```

This is technically correct since -x could have a width of 9, but this pattern 
is common in codebases. 

Reverting this change would also introduce the false positive I fixed in #126846:
```c++
bool b(signed char c) {
  return -c >= 128; // -c can be 128
}
```

This false positive is uncommon, so I think it makes sense to revert the change.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-19) 
- (modified) clang/test/Sema/compare.c (+3-20) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..edbcbea7828b2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,9 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- The -Wimplicit-int-conversion warning no longer triggers for direct 
assignments between integer types narrower than int. 
+  However, -Wsign-compare can now incorrectly produce a warning when comparing 
a value to another with just one more bit of width.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index bffd0dd461d3d..084c3dbdecb20 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10626,25 +10626,7 @@ static std::optional 
TryGetExprRange(ASTContext &C, const Expr *E,
 case UO_AddrOf: // should be impossible
   return IntRange::forValueOfType(C, GetExprType(E));
 
-case UO_Minus: {
-  if (E->getType()->isUnsignedIntegerType()) {
-return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, 
InConstantContext,
-   Approximate);
-  }
-
-  std::optional SubRange = TryGetExprRange(
-  C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
-
-  if (!SubRange)
-return std::nullopt;
-
-  // If the range was previously non-negative, we need an extra bit for the
-  // sign bit. If the range was not non-negative, we need an extra bit
-  // because the negation of the most-negative value is one bit wider than
-  // that value.
-  return IntRange(SubRange->Width + 1, false);
-}
-
+case UO_Minus:
 case UO_Not: {
   if (E->getType()->isUnsignedIntegerType()) {
 return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, 
InConstantContext,
@@ -10659,6 +10641,10 @@ static std::optional 
TryGetExprRange(ASTContext &C, const Expr *E,
 
   // The width increments by 1 if the sub-expression cannot be negative
   // since it now can be.
+  // This isn't technically correct for UO_Minus since we need an extra bit
+  // because the negation of the most-negative value is one bit wider than
+  // the original value. However, the correct version triggers many 
unwanted
+  // warnings.
   return IntRange(SubRange->Width + (int)SubRange->NonNegative, false);
 }
 
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index fdae3bc19841e..f8c4694b8730e 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -454,16 +454,6 @@ int test20(int n) {
 }
 #endif
 
-int test21(short n) {
-  return -n == 32768; // no-warning
-}
-
-#if TEST == 1
-int test22(short n) {
-  return -n == 65536; // expected-warning {{result of comparison of 17-bit 
signed value == 65536 is always false}}
-}
-#endif
-
 int test23(unsigned short n) {
   return ~n == 32768; // no-warning
 }
@@ -471,13 +461,6 @@ int test23(unsigned short n) {
 int test24(short n) {
   return ~n == 32767; // no-warning
 }
-
-#if TEST == 1
-int test25(unsigned short n) {
-  return ~n == 65536; // expected-warning {{result of comparison of 17-bit 
signed value == 65536 is always false}}
-}
-
-int test26(short n) {
-  return ~n == 32768; // expected-warning {{result of comparison of 16-bit 
signed value == 32768 is always false}}
-}
-#endif
+unsigned char test25(unsigned char n) {
+  return -n; // no-warning
+}
\ No newline at end of file

``




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


[clang] [Clang] Suppress a ``-Wimplicit-int-conversion``warning introduced in #126846 (PR #139429)

2025-05-11 Thread Yutong Zhu via cfe-commits

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


[clang] [Clang] Suppress a ``-Wimplicit-int-conversion``warning introduced in #126846 (PR #139429)

2025-05-11 Thread Yutong Zhu via cfe-commits

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


[clang] [llvm] [RISCV][MC] Add support for Q extension (PR #139369)

2025-05-11 Thread Iris Shi via cfe-commits


@@ -462,6 +474,12 @@ def FPR64C : RISCVRegisterClass<[f64], 64, (add
   (sequence "F%u_D", 8, 9)
 )>;
 
+def FPR128 : RISCVRegisterClass<
+ [f128], 128,

el-ev wrote:

Sorry, they were messed up by clang-format

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


[clang] [CIR] Upstream enum support (PR #136807)

2025-05-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-fast` running on `sanitizer-buildbot4` while building 
`clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/169/builds/11316


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 89528 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: LLVM :: 
ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s (76718 of 
89528)
 TEST 'LLVM :: 
ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s' FAILED 

Exit Code: 1

Command Output (stderr):
--
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc 
-filetype=obj -triple=x86_64-windows-msvc 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
 -o 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
 # RUN: at line 1
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc 
-filetype=obj -triple=x86_64-windows-msvc 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
 -o 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
not 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink
 -noexec 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
 2>&1 | 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
 # RUN: at line 2
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
+ not 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink
 -noexec 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp

--


Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--
414.78s: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir
338.80s: Clang :: Driver/fsanitize.c
273.66s: Clang :: Preprocessor/riscv-target-features.c
204.63s: Clang :: OpenMP/target_update_codegen.cpp
202.62s: Clang :: Driver/arm-cortex-cpus-2.c
200.75s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
199.27s: Clang :: Driver/arm-cortex-cpus-1.c
189.41s: Clang :: Preprocessor/arm-target-features.c
187.89s: Clang :: Preprocessor/aarch64-target-features.c
166.92s: LLVM

[clang] [CIR] Upstream unary operators for VectorType (PR #139444)

2025-05-11 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/139444

This change adds support for unary ops for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487

>From 9fd2f92f9122c8c79c4977e00dab93bfaa468787 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 10 May 2025 20:37:05 +0200
Subject: [PATCH] [CIR] Upstream unary operators for VectorType

---
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 54 --
 clang/test/CIR/CodeGen/vector-ext.cpp | 56 +++
 clang/test/CIR/CodeGen/vector.cpp | 56 +++
 3 files changed, 149 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 5986655ababe9..fb55b2984daea 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -54,10 +54,10 @@ namespace direct {
 namespace {
 /// If the given type is a vector type, return the vector's element type.
 /// Otherwise return the given type unchanged.
-// TODO(cir): Return the vector element type once we have support for vectors
-// instead of the identity type.
 mlir::Type elementTypeIfVector(mlir::Type type) {
-  assert(!cir::MissingFeatures::vectorType());
+  if (const auto vecType = mlir::dyn_cast(type)) {
+return vecType.getElementType();
+  }
   return type;
 }
 } // namespace
@@ -1043,12 +1043,11 @@ mlir::LogicalResult 
CIRToLLVMUnaryOpLowering::matchAndRewrite(
 mlir::ConversionPatternRewriter &rewriter) const {
   assert(op.getType() == op.getInput().getType() &&
  "Unary operation's operand type and result type are different");
-  mlir::Type type = op.getType();
-  mlir::Type elementType = type;
-  bool isVector = false;
-  assert(!cir::MissingFeatures::vectorType());
-  mlir::Type llvmType = getTypeConverter()->convertType(type);
-  mlir::Location loc = op.getLoc();
+  const mlir::Type type = op.getType();
+  const mlir::Type elementType = elementTypeIfVector(type);
+  const bool isVector = mlir::isa(type);
+  const mlir::Type llvmType = getTypeConverter()->convertType(type);
+  const mlir::Location loc = op.getLoc();
 
   // Integer unary operations: + - ~ ++ --
   if (mlir::isa(elementType)) {
@@ -1076,20 +1075,41 @@ mlir::LogicalResult 
CIRToLLVMUnaryOpLowering::matchAndRewrite(
   rewriter.replaceOp(op, adaptor.getInput());
   return mlir::success();
 case cir::UnaryOpKind::Minus: {
-  assert(!isVector &&
- "Add vector handling when vector types are supported");
-  mlir::LLVM::ConstantOp zero = rewriter.create(
-  loc, llvmType, mlir::IntegerAttr::get(llvmType, 0));
+  mlir::Value zero;
+  if (isVector)
+zero = rewriter.create(loc, llvmType);
+  else
+zero = rewriter.create(
+loc, llvmType, mlir::IntegerAttr::get(llvmType, 0));
   rewriter.replaceOpWithNewOp(
   op, llvmType, zero, adaptor.getInput(), maybeNSW);
   return mlir::success();
 }
 case cir::UnaryOpKind::Not: {
   // bit-wise compliment operator, implemented as an XOR with -1.
-  assert(!isVector &&
- "Add vector handling when vector types are supported");
-  mlir::LLVM::ConstantOp minusOne = 
rewriter.create(
-  loc, llvmType, mlir::IntegerAttr::get(llvmType, -1));
+  mlir::Value minusOne;
+  if (isVector) {
+// Creating a vector object with all -1 values is easier said than
+// done. It requires a series of insertelement ops.
+const mlir::Type llvmElementType =
+getTypeConverter()->convertType(elementType);
+const mlir::Value minusOneInt = 
rewriter.create(
+loc, llvmElementType, mlir::IntegerAttr::get(llvmElementType, -1));
+minusOne = rewriter.create(loc, llvmType);
+
+const uint64_t numElements =
+mlir::dyn_cast(type).getSize();
+for (uint64_t i = 0; i < numElements; ++i) {
+  const mlir::Value indexValue =
+  rewriter.create(loc,
+  rewriter.getI64Type(), 
i);
+  minusOne = rewriter.create(
+  loc, minusOne, minusOneInt, indexValue);
+}
+  } else {
+minusOne = rewriter.create(
+loc, llvmType, mlir::IntegerAttr::get(llvmType, -1));
+  }
   rewriter.replaceOpWithNewOp(
   op, llvmType, adaptor.getInput(), minusOne);
   return mlir::success();
diff --git a/clang/test/CIR/CodeGen/vector-ext.cpp 
b/clang/test/CIR/CodeGen/vector-ext.cpp
index 0756497bf6b96..005f629b88143 100644
--- a/clang/test/CIR/CodeGen/vector-ext.cpp
+++ b/clang/test/CIR/CodeGen/vector-ext.cpp
@@ -213,3 +213,59 @@ void foo4() {
 // OGCG: %[[TMP2:.*]] = load i32, ptr %[[IDX]], align 4
 // OGCG: %[[ELE:.*]] = extractelement <4 x i32> %[[TMP1]], i32 %[[TMP2]]
 // OGCG: store i32 %[[ELE]], ptr %[[INIT]], align 4
+
+void

[clang] [CIR] Upstream unary operators for VectorType (PR #139444)

2025-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds support for unary ops for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487

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


3 Files Affected:

- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+37-17) 
- (modified) clang/test/CIR/CodeGen/vector-ext.cpp (+56) 
- (modified) clang/test/CIR/CodeGen/vector.cpp (+56) 


``diff
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 5986655ababe9..fb55b2984daea 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -54,10 +54,10 @@ namespace direct {
 namespace {
 /// If the given type is a vector type, return the vector's element type.
 /// Otherwise return the given type unchanged.
-// TODO(cir): Return the vector element type once we have support for vectors
-// instead of the identity type.
 mlir::Type elementTypeIfVector(mlir::Type type) {
-  assert(!cir::MissingFeatures::vectorType());
+  if (const auto vecType = mlir::dyn_cast(type)) {
+return vecType.getElementType();
+  }
   return type;
 }
 } // namespace
@@ -1043,12 +1043,11 @@ mlir::LogicalResult 
CIRToLLVMUnaryOpLowering::matchAndRewrite(
 mlir::ConversionPatternRewriter &rewriter) const {
   assert(op.getType() == op.getInput().getType() &&
  "Unary operation's operand type and result type are different");
-  mlir::Type type = op.getType();
-  mlir::Type elementType = type;
-  bool isVector = false;
-  assert(!cir::MissingFeatures::vectorType());
-  mlir::Type llvmType = getTypeConverter()->convertType(type);
-  mlir::Location loc = op.getLoc();
+  const mlir::Type type = op.getType();
+  const mlir::Type elementType = elementTypeIfVector(type);
+  const bool isVector = mlir::isa(type);
+  const mlir::Type llvmType = getTypeConverter()->convertType(type);
+  const mlir::Location loc = op.getLoc();
 
   // Integer unary operations: + - ~ ++ --
   if (mlir::isa(elementType)) {
@@ -1076,20 +1075,41 @@ mlir::LogicalResult 
CIRToLLVMUnaryOpLowering::matchAndRewrite(
   rewriter.replaceOp(op, adaptor.getInput());
   return mlir::success();
 case cir::UnaryOpKind::Minus: {
-  assert(!isVector &&
- "Add vector handling when vector types are supported");
-  mlir::LLVM::ConstantOp zero = rewriter.create(
-  loc, llvmType, mlir::IntegerAttr::get(llvmType, 0));
+  mlir::Value zero;
+  if (isVector)
+zero = rewriter.create(loc, llvmType);
+  else
+zero = rewriter.create(
+loc, llvmType, mlir::IntegerAttr::get(llvmType, 0));
   rewriter.replaceOpWithNewOp(
   op, llvmType, zero, adaptor.getInput(), maybeNSW);
   return mlir::success();
 }
 case cir::UnaryOpKind::Not: {
   // bit-wise compliment operator, implemented as an XOR with -1.
-  assert(!isVector &&
- "Add vector handling when vector types are supported");
-  mlir::LLVM::ConstantOp minusOne = 
rewriter.create(
-  loc, llvmType, mlir::IntegerAttr::get(llvmType, -1));
+  mlir::Value minusOne;
+  if (isVector) {
+// Creating a vector object with all -1 values is easier said than
+// done. It requires a series of insertelement ops.
+const mlir::Type llvmElementType =
+getTypeConverter()->convertType(elementType);
+const mlir::Value minusOneInt = 
rewriter.create(
+loc, llvmElementType, mlir::IntegerAttr::get(llvmElementType, -1));
+minusOne = rewriter.create(loc, llvmType);
+
+const uint64_t numElements =
+mlir::dyn_cast(type).getSize();
+for (uint64_t i = 0; i < numElements; ++i) {
+  const mlir::Value indexValue =
+  rewriter.create(loc,
+  rewriter.getI64Type(), 
i);
+  minusOne = rewriter.create(
+  loc, minusOne, minusOneInt, indexValue);
+}
+  } else {
+minusOne = rewriter.create(
+loc, llvmType, mlir::IntegerAttr::get(llvmType, -1));
+  }
   rewriter.replaceOpWithNewOp(
   op, llvmType, adaptor.getInput(), minusOne);
   return mlir::success();
diff --git a/clang/test/CIR/CodeGen/vector-ext.cpp 
b/clang/test/CIR/CodeGen/vector-ext.cpp
index 0756497bf6b96..005f629b88143 100644
--- a/clang/test/CIR/CodeGen/vector-ext.cpp
+++ b/clang/test/CIR/CodeGen/vector-ext.cpp
@@ -213,3 +213,59 @@ void foo4() {
 // OGCG: %[[TMP2:.*]] = load i32, ptr %[[IDX]], align 4
 // OGCG: %[[ELE:.*]] = extractelement <4 x i32> %[[TMP1]], i32 %[[TMP2]]
 // OGCG: store i32 %[[ELE]], ptr %[[INIT]], align 4
+
+void foo8() {
+  vi4 a = { 1, 2, 3, 4 };
+  vi4 plus_res = +a;
+  vi4 minus_res = -a;
+  vi4 not_res = ~a;
+}
+
+// CIR: %[[VEC:.*]] = cir.alloca !cir.vector<4 x !s32i>, 
!ci

[clang] [Clang] Stop changing DC when instantiating dependent friend specializations (PR #139436)

2025-05-11 Thread via cfe-commits

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

LGTM

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


[clang] [Clang] Stop changing DC when instantiating dependent friend specializations (PR #139436)

2025-05-11 Thread via cfe-commits

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


[clang] [Clang] Stop changing DC when instantiating dependent friend specializations (PR #139436)

2025-05-11 Thread via cfe-commits


@@ -5751,14 +5751,16 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 RebuildTypeSourceInfoForDefaultSpecialMembers();
 SetDeclDefaulted(Function, PatternDecl->getLocation());
   } else {
-NamedDecl *ND = Function;
-DeclContext *DC = ND->getLexicalDeclContext();
+DeclContext *DC = Function->getLexicalDeclContext();
 std::optional> Innermost;
-if (auto *Primary = Function->getPrimaryTemplate();
-Primary &&
+bool NeedDCFromPrimaryTemplate =
 !isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function) &&
 Function->getTemplateSpecializationKind() !=
-TSK_ExplicitSpecialization) {
+TSK_ExplicitSpecialization &&
+!PatternDecl->getDependentSpecializationInfo();
+
+if (auto *Primary = Function->getPrimaryTemplate();
+Primary && NeedDCFromPrimaryTemplate) {

cor3ntin wrote:

Can you add a comment? It is sufficiently subtle

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


[clang] [llvm] [Mips] Implement MipsInstrInfo::getNop() operation (PR #135524)

2025-05-11 Thread YunQiang Su via cfe-commits


@@ -87,6 +87,14 @@ MipsInstrInfo::GetMemOperand(MachineBasicBlock &MBB, int FI,
  MFI.getObjectAlign(FI));
 }
 
+MCInst MipsInstrInfo::getNop() const {
+  MCInst Nop;
+  // using Mips::NOP gives
+  // "fatal error: error in backend: Not supported instr: "

wzssyqa wrote:

I guess the reason is that NOP is defined as PseudoSE

  /// No operation.
  def NOP : PseudoSE<(outs), (ins), []>,
 PseudoInstExpansion<(SLL ZERO, ZERO, 0)>, ISA_MIPS1;

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-05-11 Thread JJ Marr via cfe-commits


@@ -5975,9 +5975,22 @@ static bool CheckConstexprFunction(EvalInfo &Info, 
SourceLocation CallLoc,
 
Definition->hasAttr(
 return true;
 
-  if (Info.getLangOpts().CPlusPlus11) {
-const FunctionDecl *DiagDecl = Definition ? Definition : Declaration;
+  const FunctionDecl *DiagDecl = Definition ? Definition : Declaration;
+  // Special note for the assert() macro, as the normal error message falsely
+  // implies we cannot use an assertion during constant evaluation.
+  if (CallLoc.isMacroID() && DiagDecl->getIdentifier()) {
+// FIXME: Instead of checking for an implementation-defined function,
+// check and evaluate the assert() macro.

jj-marr wrote:

I have no idea how to access the preprocessor from this method and I am too 
inexperienced to know where to start. 
If you can give me a hint on where to look I would appreciate that. Do I just 
do a big refactor and pass it in as a parameter to the function? Or is there 
some method on an object I already have? 

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-05-11 Thread via cfe-commits


@@ -5975,9 +5975,22 @@ static bool CheckConstexprFunction(EvalInfo &Info, 
SourceLocation CallLoc,
 
Definition->hasAttr(
 return true;
 
-  if (Info.getLangOpts().CPlusPlus11) {
-const FunctionDecl *DiagDecl = Definition ? Definition : Declaration;
+  const FunctionDecl *DiagDecl = Definition ? Definition : Declaration;
+  // Special note for the assert() macro, as the normal error message falsely
+  // implies we cannot use an assertion during constant evaluation.
+  if (CallLoc.isMacroID() && DiagDecl->getIdentifier()) {
+// FIXME: Instead of checking for an implementation-defined function,
+// check and evaluate the assert() macro.

cor3ntin wrote:

Oh, right, we would need access to Sema, which we currently don't. Good answer! 
(@Endilll !)
Given that, I am satisfied with the change as is, thanks

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-05-11 Thread via cfe-commits

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


  1   2   >