[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 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 e00d32afb9d33a1eca48e2b041c9688436706c5b 
a20790e9e87d2ede14605b277184d2b8c5b0979f -- clang/include/clang/Lex/Lexer.h 
clang/lib/Lex/DependencyDirectivesScanner.cpp clang/lib/Lex/Lexer.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 26c7755fb6fd..1c5399752773 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2092,7 +2092,8 @@ const char *Lexer::LexUDSuffix(Token &Result, const char 
*CurPtr,
   unsigned Consumed = Size;
   unsigned Chars = 1;
   while (true) {
-auto [Next, NextSize] = getCharAndSizeNoWarn(CurPtr + Consumed, 
LangOpts);
+auto [Next, NextSize] =
+getCharAndSizeNoWarn(CurPtr + Consumed, LangOpts);
 if (!isAsciiIdentifierContinue(Next)) {
   // End of suffix. Check whether this is on the allowed list.
   const StringRef CompleteSuffix(Buffer, Chars);

``




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


[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70543

>From 7bbcabd82edc1736cc22243e109dc0858036c6ac Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Fri, 27 Oct 2023 22:48:08 +0200
Subject: [PATCH 1/2] [clang] Change GetCharAndSizeSlow interface to by-value
 style

Instead of passing the Size by reference, assuming it is initialized,
return it alongside the expected char result as a POD.

This makes the interface less error prone: previous interface expected
the Size reference to be initialized, and it was often forgotten,
leading to uninitialized variable usage. This patch fixes the issue.

This also generates faster code, as the returned POD (a char and an
unsigned) fits in 64 bits. The speedup according to compile time tracker
reach -O.7%, with a good number of -0.4%. Details are available on


https://llvm-compile-time-tracker.com/compare.php?from=3fe63f81fcb999681daa11b2890c82fda3aaeef5&to=fc76a9202f737472ecad4d6e0b0bf87a013866f3&stat=instructions:u

And icing on the cake, on my setup it also shaves 2kB out of
libclang-cpp :-)
---
 clang/include/clang/Lex/Lexer.h   | 35 
 clang/lib/Lex/DependencyDirectivesScanner.cpp |  7 +-
 clang/lib/Lex/Lexer.cpp   | 79 +++
 3 files changed, 65 insertions(+), 56 deletions(-)

diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h
index ac0ef14c591bdd7..899e665e7454652 100644
--- a/clang/include/clang/Lex/Lexer.h
+++ b/clang/include/clang/Lex/Lexer.h
@@ -575,19 +575,23 @@ class Lexer : public PreprocessorLexer {
   /// sequence.
   static bool isNewLineEscaped(const char *BufferStart, const char *Str);
 
+  /// Represents a char and the number of bytes parsed to produce it.
+  struct SizedChar {
+char Char;
+unsigned Size;
+  };
+
   /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever
   /// emit a warning.
-  static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size,
-  const LangOptions &LangOpts) {
+  static inline SizedChar getCharAndSizeNoWarn(const char *Ptr,
+   const LangOptions &LangOpts) {
 // If this is not a trigraph and not a UCN or escaped newline, return
 // quickly.
 if (isObviouslySimpleCharacter(Ptr[0])) {
-  Size = 1;
-  return *Ptr;
+  return {*Ptr, 1u};
 }
 
-Size = 0;
-return getCharAndSizeSlowNoWarn(Ptr, Size, LangOpts);
+return getCharAndSizeSlowNoWarn(Ptr, LangOpts);
   }
 
   /// Returns the leading whitespace for line that corresponds to the given
@@ -665,8 +669,7 @@ class Lexer : public PreprocessorLexer {
 // quickly.
 if (isObviouslySimpleCharacter(Ptr[0])) return *Ptr++;
 
-unsigned Size = 0;
-char C = getCharAndSizeSlow(Ptr, Size, &Tok);
+auto [C, Size] = getCharAndSizeSlow(Ptr, &Tok);
 Ptr += Size;
 return C;
   }
@@ -682,9 +685,7 @@ class Lexer : public PreprocessorLexer {
 
 // Otherwise, re-lex the character with a current token, allowing
 // diagnostics to be emitted and flags to be set.
-Size = 0;
-getCharAndSizeSlow(Ptr, Size, &Tok);
-return Ptr+Size;
+return Ptr + getCharAndSizeSlow(Ptr, &Tok).Size;
   }
 
   /// getCharAndSize - Peek a single 'character' from the specified buffer,
@@ -699,14 +700,14 @@ class Lexer : public PreprocessorLexer {
   return *Ptr;
 }
 
-Size = 0;
-return getCharAndSizeSlow(Ptr, Size);
+auto CharAndSize = getCharAndSizeSlow(Ptr);
+Size = CharAndSize.Size;
+return CharAndSize.Char;
   }
 
   /// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize
   /// method.
-  char getCharAndSizeSlow(const char *Ptr, unsigned &Size,
-  Token *Tok = nullptr);
+  SizedChar getCharAndSizeSlow(const char *Ptr, Token *Tok = nullptr);
 
   /// getEscapedNewLineSize - Return the size of the specified escaped newline,
   /// or 0 if it is not an escaped newline. P[-1] is known to be a "\" on entry
@@ -720,8 +721,8 @@ class Lexer : public PreprocessorLexer {
 
   /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a
   /// diagnostic.
-  static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size,
-   const LangOptions &LangOpts);
+  static SizedChar getCharAndSizeSlowNoWarn(const char *Ptr,
+const LangOptions &LangOpts);
 
   
//======//
   // Other lexer functions.
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 2bd2c5f8388c0dd..42b89f98a24f3e1 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -565,10 +565,9 @@ Scanner::cleanStringIfNeeded(const 
dependency_directives_scan::Token &Tok) {
  

[clang] [clang][Interp] Fix variables refering to their own address (PR #70587)

2023-10-29 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/70587

This was a combination of issues:
  1) We can subtract pointers that don't point into arrays.
  2) In C, everything is possible.

>From 01d5cccfc4cd3813fb57e17af3c7b395bc0c9646 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 29 Oct 2023 09:12:00 +0100
Subject: [PATCH] [clang][Interp] Fix variables refering to their own address

This was a combination of issues:
  1) We can subtract pointers that don't point into arrays.
  2) In C, everything is possible.
---
 clang/lib/AST/Interp/Interp.h  |  4 ++--
 clang/test/AST/Interp/c.c  |  4 
 clang/test/AST/Interp/literals.cpp | 15 +++
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 7dd415d6e460536..c5ee720d5a29ddd 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1453,7 +1453,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
   DiagInvalidOffset();
   }
 
-  if (Invalid && !Ptr.isDummy())
+  if (Invalid && !Ptr.isDummy() && S.getLangOpts().CPlusPlus)
 return false;
 
   // Offset is valid - compute it on unsigned.
@@ -1531,7 +1531,7 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
   const Pointer &LHS = S.Stk.pop();
   const Pointer &RHS = S.Stk.pop();
 
-  if (!Pointer::hasSameArray(LHS, RHS)) {
+  if (!Pointer::hasSameBase(LHS, RHS) && S.getLangOpts().CPlusPlus) {
 // TODO: Diagnose.
 return false;
   }
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 6bfcded0a78646c..2bc3d906bcc5ef9 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -pedantic -verify=pedantic-ref -std=c11 %s
 
 typedef __INTPTR_TYPE__ intptr_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
 
 _Static_assert(1, "");
 _Static_assert(0 != 1, "");
@@ -81,3 +82,6 @@ const intptr_t L = (intptr_t)(&(yy->y)); // expected-error 
{{not a compile-time
  // pedantic-expected-error {{not a 
compile-time constant}} \
  // ref-error {{not a compile-time 
constant}} \
  // pedantic-ref-error {{not a 
compile-time constant}}
+const ptrdiff_t m = &m + 137 - &m;
+_Static_assert(m == 137, ""); // pedantic-ref-warning {{GNU extension}} \
+  // pedantic-expected-warning {{GNU extension}}
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index ba24955d14503be..92b467da3e8847b 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -7,6 +7,7 @@
 #define INT_MAX __INT_MAX__
 
 typedef __INTPTR_TYPE__ intptr_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
 
 
 static_assert(true, "");
@@ -198,6 +199,20 @@ namespace PointerComparison {
  // ref-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
   constexpr bool v7 = qv <= (void*)&s.b; // ok
+
+  constexpr ptrdiff_t m = &m - &m;
+  static_assert(m == 0, "");
+
+  constexpr ptrdiff_t m2 = (&m2 + 1) - (&m2 + 1);
+  static_assert(m2 == 0, "");
+
+  constexpr long m3 = (&m3 + 1) - (&m3);
+  static_assert(m3 == 1, "");
+
+  constexpr long m4 = &m4 + 2 - &m4; // ref-error {{must be initialized by a 
constant expression}} \
+ // ref-note {{cannot refer to element 2 
of non-array object}} \
+ // expected-error {{must be initialized 
by a constant expression}} \
+ // expected-note {{cannot refer to 
element 2 of non-array object}}
 }
 
 namespace SizeOf {

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


[clang] [clang][Interp] Fix variables refering to their own address (PR #70587)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

This was a combination of issues:
  1) We can subtract pointers that don't point into arrays.
  2) In C, everything is possible.

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


3 Files Affected:

- (modified) clang/lib/AST/Interp/Interp.h (+2-2) 
- (modified) clang/test/AST/Interp/c.c (+4) 
- (modified) clang/test/AST/Interp/literals.cpp (+15) 


``diff
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 7dd415d6e460536..c5ee720d5a29ddd 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1453,7 +1453,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
   DiagInvalidOffset();
   }
 
-  if (Invalid && !Ptr.isDummy())
+  if (Invalid && !Ptr.isDummy() && S.getLangOpts().CPlusPlus)
 return false;
 
   // Offset is valid - compute it on unsigned.
@@ -1531,7 +1531,7 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
   const Pointer &LHS = S.Stk.pop();
   const Pointer &RHS = S.Stk.pop();
 
-  if (!Pointer::hasSameArray(LHS, RHS)) {
+  if (!Pointer::hasSameBase(LHS, RHS) && S.getLangOpts().CPlusPlus) {
 // TODO: Diagnose.
 return false;
   }
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 6bfcded0a78646c..2bc3d906bcc5ef9 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -pedantic -verify=pedantic-ref -std=c11 %s
 
 typedef __INTPTR_TYPE__ intptr_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
 
 _Static_assert(1, "");
 _Static_assert(0 != 1, "");
@@ -81,3 +82,6 @@ const intptr_t L = (intptr_t)(&(yy->y)); // expected-error 
{{not a compile-time
  // pedantic-expected-error {{not a 
compile-time constant}} \
  // ref-error {{not a compile-time 
constant}} \
  // pedantic-ref-error {{not a 
compile-time constant}}
+const ptrdiff_t m = &m + 137 - &m;
+_Static_assert(m == 137, ""); // pedantic-ref-warning {{GNU extension}} \
+  // pedantic-expected-warning {{GNU extension}}
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index ba24955d14503be..92b467da3e8847b 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -7,6 +7,7 @@
 #define INT_MAX __INT_MAX__
 
 typedef __INTPTR_TYPE__ intptr_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
 
 
 static_assert(true, "");
@@ -198,6 +199,20 @@ namespace PointerComparison {
  // ref-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
   constexpr bool v7 = qv <= (void*)&s.b; // ok
+
+  constexpr ptrdiff_t m = &m - &m;
+  static_assert(m == 0, "");
+
+  constexpr ptrdiff_t m2 = (&m2 + 1) - (&m2 + 1);
+  static_assert(m2 == 0, "");
+
+  constexpr long m3 = (&m3 + 1) - (&m3);
+  static_assert(m3 == 1, "");
+
+  constexpr long m4 = &m4 + 2 - &m4; // ref-error {{must be initialized by a 
constant expression}} \
+ // ref-note {{cannot refer to element 2 
of non-array object}} \
+ // expected-error {{must be initialized 
by a constant expression}} \
+ // expected-note {{cannot refer to 
element 2 of non-array object}}
 }
 
 namespace SizeOf {

``




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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-29 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From 8e0d084529d159ee80dd3971f9a5bb112e24bb86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/21] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteva

[clang] [clang][Interp] Handle CXXTryStmts (PR #70584)

2023-10-29 Thread Timm Baeder via cfe-commits

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


[clang-tools-extra] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-10-29 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69102

>From 21156656433fb8d2dc5a805d97cbd20fa916fff9 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 15 Oct 2023 11:39:42 +0100
Subject: [PATCH 1/6] Fix #35272: Don't replace typedefs in extern c scope

---
 .../clang-tidy/modernize/UseUsingCheck.cpp   | 16 
 .../clang-tidy/checkers/modernize/use-using.cpp  | 14 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddbb..841ffb4c9bfe66e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,6 +11,12 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
@@ -27,10 +33,12 @@ void 
UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(unless(anyOf(isInstantiated(), hasAncestor(linkageSpecDecl(
+ isExternCLinkage(),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 422abee11a71962..0f8f14502d5ca3c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -325,3 +325,17 @@ typedef bool (*ISSUE_65055_2)(int);
 typedef class ISSUE_67529_1 *ISSUE_67529;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
+
+// Some Header
+extern "C" {
+
+typedef int InExternC;
+}
+
+extern "C++" {
+
+typedef int InExternCPP;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+// CHECK-FIXES: using InExternCPP = int;
+
+}

>From 521dec9325285d1e1819a8bee1bd20eadb7c4158 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Mon, 16 Oct 2023 23:26:25 +0100
Subject: [PATCH 2/6] Add: Update docs with the new changes. Update
 ReleaseNotes.rst with the changes made

---
 clang-tools-extra/docs/ReleaseNotes.rst  | 5 +
 .../docs/clang-tidy/checks/modernize/use-using.rst   | 9 +
 2 files changed, 14 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c1b926b296b055a..af6b20369c9dcff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -285,6 +285,10 @@ Changes in existing checks
   ` check to fix function pointer and
   forward declared ``typedef`` correctly.
 
+- Improved :doc:`modernize-use-using
+  ` by ignoring ``typedef`` declaration 
in
+  ``extern "C"`` scope.
+
 - Improved :doc:`performance-faster-string-find
   ` check to properly escape
   single quotes.
@@ -325,6 +329,7 @@ Changes in existing checks
   identify calls to static member functions with out-of-class inline 
definitions.
 
 
+
 Removed checks
 ^^
 
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
index eeddaf8d8d65abe..048fc26617b7b73 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
@@ -28,6 +28,15 @@ After:
   using R_t = struct { int a; };
   using R_p = R_t*;
 
+The checker ignores `typedef` within `extern "C" { ... }` blocks.
+
+.. code-block:: c++
+
+  extern "C" {
+
+typedef int InExternC; // Left intact.
+  }
+
 This check requires using C++11 or higher to run.
 
 Options

>From 3426e0a36606a7e3eeb38c0f436c25aa2fde2b36 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 22 Oct 2023 20:02:20 +0100
Subject: [PATCH 3/6] Update: commit with review requested changes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 6 +-
 .../docs/clang-tidy/checks/modernize/use-using.rst  | 2 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index

[clang-tools-extra] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-10-29 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69102

>From 21156656433fb8d2dc5a805d97cbd20fa916fff9 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 15 Oct 2023 11:39:42 +0100
Subject: [PATCH 1/7] Fix #35272: Don't replace typedefs in extern c scope

---
 .../clang-tidy/modernize/UseUsingCheck.cpp   | 16 
 .../clang-tidy/checkers/modernize/use-using.cpp  | 14 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddbb..841ffb4c9bfe66e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,6 +11,12 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
@@ -27,10 +33,12 @@ void 
UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(unless(anyOf(isInstantiated(), hasAncestor(linkageSpecDecl(
+ isExternCLinkage(),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 422abee11a71962..0f8f14502d5ca3c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -325,3 +325,17 @@ typedef bool (*ISSUE_65055_2)(int);
 typedef class ISSUE_67529_1 *ISSUE_67529;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
+
+// Some Header
+extern "C" {
+
+typedef int InExternC;
+}
+
+extern "C++" {
+
+typedef int InExternCPP;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+// CHECK-FIXES: using InExternCPP = int;
+
+}

>From 521dec9325285d1e1819a8bee1bd20eadb7c4158 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Mon, 16 Oct 2023 23:26:25 +0100
Subject: [PATCH 2/7] Add: Update docs with the new changes. Update
 ReleaseNotes.rst with the changes made

---
 clang-tools-extra/docs/ReleaseNotes.rst  | 5 +
 .../docs/clang-tidy/checks/modernize/use-using.rst   | 9 +
 2 files changed, 14 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c1b926b296b055a..af6b20369c9dcff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -285,6 +285,10 @@ Changes in existing checks
   ` check to fix function pointer and
   forward declared ``typedef`` correctly.
 
+- Improved :doc:`modernize-use-using
+  ` by ignoring ``typedef`` declaration 
in
+  ``extern "C"`` scope.
+
 - Improved :doc:`performance-faster-string-find
   ` check to properly escape
   single quotes.
@@ -325,6 +329,7 @@ Changes in existing checks
   identify calls to static member functions with out-of-class inline 
definitions.
 
 
+
 Removed checks
 ^^
 
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
index eeddaf8d8d65abe..048fc26617b7b73 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
@@ -28,6 +28,15 @@ After:
   using R_t = struct { int a; };
   using R_p = R_t*;
 
+The checker ignores `typedef` within `extern "C" { ... }` blocks.
+
+.. code-block:: c++
+
+  extern "C" {
+
+typedef int InExternC; // Left intact.
+  }
+
 This check requires using C++11 or higher to run.
 
 Options

>From 3426e0a36606a7e3eeb38c0f436c25aa2fde2b36 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 22 Oct 2023 20:02:20 +0100
Subject: [PATCH 3/7] Update: commit with review requested changes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 6 +-
 .../docs/clang-tidy/checks/modernize/use-using.rst  | 2 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index

[clang] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-10-29 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69102

>From 21156656433fb8d2dc5a805d97cbd20fa916fff9 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 15 Oct 2023 11:39:42 +0100
Subject: [PATCH 1/7] Fix #35272: Don't replace typedefs in extern c scope

---
 .../clang-tidy/modernize/UseUsingCheck.cpp   | 16 
 .../clang-tidy/checkers/modernize/use-using.cpp  | 14 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddbb..841ffb4c9bfe66e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,6 +11,12 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
@@ -27,10 +33,12 @@ void 
UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(unless(anyOf(isInstantiated(), hasAncestor(linkageSpecDecl(
+ isExternCLinkage(),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 422abee11a71962..0f8f14502d5ca3c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -325,3 +325,17 @@ typedef bool (*ISSUE_65055_2)(int);
 typedef class ISSUE_67529_1 *ISSUE_67529;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
+
+// Some Header
+extern "C" {
+
+typedef int InExternC;
+}
+
+extern "C++" {
+
+typedef int InExternCPP;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+// CHECK-FIXES: using InExternCPP = int;
+
+}

>From 521dec9325285d1e1819a8bee1bd20eadb7c4158 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Mon, 16 Oct 2023 23:26:25 +0100
Subject: [PATCH 2/7] Add: Update docs with the new changes. Update
 ReleaseNotes.rst with the changes made

---
 clang-tools-extra/docs/ReleaseNotes.rst  | 5 +
 .../docs/clang-tidy/checks/modernize/use-using.rst   | 9 +
 2 files changed, 14 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c1b926b296b055a..af6b20369c9dcff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -285,6 +285,10 @@ Changes in existing checks
   ` check to fix function pointer and
   forward declared ``typedef`` correctly.
 
+- Improved :doc:`modernize-use-using
+  ` by ignoring ``typedef`` declaration 
in
+  ``extern "C"`` scope.
+
 - Improved :doc:`performance-faster-string-find
   ` check to properly escape
   single quotes.
@@ -325,6 +329,7 @@ Changes in existing checks
   identify calls to static member functions with out-of-class inline 
definitions.
 
 
+
 Removed checks
 ^^
 
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
index eeddaf8d8d65abe..048fc26617b7b73 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
@@ -28,6 +28,15 @@ After:
   using R_t = struct { int a; };
   using R_p = R_t*;
 
+The checker ignores `typedef` within `extern "C" { ... }` blocks.
+
+.. code-block:: c++
+
+  extern "C" {
+
+typedef int InExternC; // Left intact.
+  }
+
 This check requires using C++11 or higher to run.
 
 Options

>From 3426e0a36606a7e3eeb38c0f436c25aa2fde2b36 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 22 Oct 2023 20:02:20 +0100
Subject: [PATCH 3/7] Update: commit with review requested changes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 6 +-
 .../docs/clang-tidy/checks/modernize/use-using.rst  | 2 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index

[clang] Fix #68492: point to the correct const location (PR #69103)

2023-10-29 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69103

>From 354a8e4034afd82e6ea854848a86b9011e26269b Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Fri, 13 Oct 2023 19:27:15 +0100
Subject: [PATCH 1/5] Fix #68492: point to the correct const location

---
 .../readability/AvoidConstParamsInDecls.cpp   | 43 ---
 .../avoid-const-params-in-decls.cpp   | 14 +++---
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
index 6476f1d7fdf2b81..24cbbd8bc60a2b5 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -21,6 +21,24 @@ SourceRange getTypeRange(const ParmVarDecl &Param) {
   return {Param.getBeginLoc(), Param.getLocation().getLocWithOffset(-1)};
 }
 
+// Finds the location of the qualifying `const` token in the `ParmValDecl`'s
+// return type. Returns `std::nullopt` when the parm type is not
+// `const`-qualified like when the type is an alias or a macro.
+static std::optional
+findConstToRemove(const ParmVarDecl &Param,
+  const MatchFinder::MatchResult &Result) {
+
+  CharSourceRange FileRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(getTypeRange(Param)),
+  *Result.SourceManager, Result.Context->getLangOpts());
+
+  if (FileRange.isInvalid())
+return std::nullopt;
+
+  return tidy::utils::lexer::getQualifyingToken(
+  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
+}
+
 } // namespace
 
 void AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
@@ -30,11 +48,10 @@ void 
AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
   const auto ConstParamDecl =
   parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
-  Finder->addMatcher(
-  functionDecl(unless(isDefinition()),
-   has(typeLoc(forEach(ConstParamDecl
-  .bind("func"),
-  this);
+  Finder->addMatcher(functionDecl(unless(isDefinition()),
+  has(typeLoc(forEach(ConstParamDecl
+ .bind("func"),
+ this);
 }
 
 void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) {
@@ -50,7 +67,10 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
-  auto Diag = diag(Param->getBeginLoc(),
+  const auto Tok = findConstToRemove(*Param, Result);
+  const auto ConstLocation = Tok ? Tok->getLocation() : Param->getBeginLoc();
+
+  auto Diag = diag(ConstLocation,
"parameter %0 is const-qualified in the function "
"declaration; const-qualification of parameters only has an 
"
"effect in function definitions");
@@ -70,18 +90,9 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 // from a macro.
 return;
   }
-
-  CharSourceRange FileRange = Lexer::makeFileCharRange(
-  CharSourceRange::getTokenRange(getTypeRange(*Param)),
-  *Result.SourceManager, getLangOpts());
-
-  if (!FileRange.isValid())
-return;
-
-  auto Tok = tidy::utils::lexer::getQualifyingToken(
-  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
   if (!Tok)
 return;
+
   Diag << FixItHint::CreateRemoval(
   CharSourceRange::getTokenRange(Tok->getLocation(), Tok->getLocation()));
 }
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
index d521fd238b7d521..bc098efe3044a5d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
@@ -9,15 +9,15 @@ void F1(const int i);
 // CHECK-FIXES: void F1(int i);
 
 void F2(const int *const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F2(const int *i);
 
 void F3(int const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F3(int i);
 
 void F4(alias_type const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F4(alias_type i);
 
 void F5(const int);
@@ -25,7 +25,7 @@ void F5(const int);
 // CHECK-FIXES: void F5(int);
 
 void F6(const int *const);
-// CHECK-MESSAGES: :[[@LIN

[clang-tools-extra] Fix #68492: point to the correct const location (PR #69103)

2023-10-29 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69103

>From 354a8e4034afd82e6ea854848a86b9011e26269b Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Fri, 13 Oct 2023 19:27:15 +0100
Subject: [PATCH 1/5] Fix #68492: point to the correct const location

---
 .../readability/AvoidConstParamsInDecls.cpp   | 43 ---
 .../avoid-const-params-in-decls.cpp   | 14 +++---
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
index 6476f1d7fdf2b81..24cbbd8bc60a2b5 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -21,6 +21,24 @@ SourceRange getTypeRange(const ParmVarDecl &Param) {
   return {Param.getBeginLoc(), Param.getLocation().getLocWithOffset(-1)};
 }
 
+// Finds the location of the qualifying `const` token in the `ParmValDecl`'s
+// return type. Returns `std::nullopt` when the parm type is not
+// `const`-qualified like when the type is an alias or a macro.
+static std::optional
+findConstToRemove(const ParmVarDecl &Param,
+  const MatchFinder::MatchResult &Result) {
+
+  CharSourceRange FileRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(getTypeRange(Param)),
+  *Result.SourceManager, Result.Context->getLangOpts());
+
+  if (FileRange.isInvalid())
+return std::nullopt;
+
+  return tidy::utils::lexer::getQualifyingToken(
+  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
+}
+
 } // namespace
 
 void AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
@@ -30,11 +48,10 @@ void 
AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
   const auto ConstParamDecl =
   parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
-  Finder->addMatcher(
-  functionDecl(unless(isDefinition()),
-   has(typeLoc(forEach(ConstParamDecl
-  .bind("func"),
-  this);
+  Finder->addMatcher(functionDecl(unless(isDefinition()),
+  has(typeLoc(forEach(ConstParamDecl
+ .bind("func"),
+ this);
 }
 
 void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) {
@@ -50,7 +67,10 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
-  auto Diag = diag(Param->getBeginLoc(),
+  const auto Tok = findConstToRemove(*Param, Result);
+  const auto ConstLocation = Tok ? Tok->getLocation() : Param->getBeginLoc();
+
+  auto Diag = diag(ConstLocation,
"parameter %0 is const-qualified in the function "
"declaration; const-qualification of parameters only has an 
"
"effect in function definitions");
@@ -70,18 +90,9 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 // from a macro.
 return;
   }
-
-  CharSourceRange FileRange = Lexer::makeFileCharRange(
-  CharSourceRange::getTokenRange(getTypeRange(*Param)),
-  *Result.SourceManager, getLangOpts());
-
-  if (!FileRange.isValid())
-return;
-
-  auto Tok = tidy::utils::lexer::getQualifyingToken(
-  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
   if (!Tok)
 return;
+
   Diag << FixItHint::CreateRemoval(
   CharSourceRange::getTokenRange(Tok->getLocation(), Tok->getLocation()));
 }
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
index d521fd238b7d521..bc098efe3044a5d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
@@ -9,15 +9,15 @@ void F1(const int i);
 // CHECK-FIXES: void F1(int i);
 
 void F2(const int *const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F2(const int *i);
 
 void F3(int const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F3(int i);
 
 void F4(alias_type const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F4(alias_type i);
 
 void F5(const int);
@@ -25,7 +25,7 @@ void F5(const int);
 // CHECK-FIXES: void F5(int);
 
 void F6(const int *const);
-// CHECK-MESSAGES: :[[@LIN

[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-10-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D86993#4655487 , @rsmith wrote:

> In D86993#4655474 , @RalfJung wrote:
>
>> With everything moving to github PRs, what are the next steps for this patch?
>
> I'm unlikely to have cycles to work on this in the near future. If someone 
> else wants to take over here, you would have my blessing :-)

Since I had strong opinions, I'll commandeer the patch and get it across the 
finish line before Phab gets put into read-only mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/70593

Tested on `amd64-pc-solaris2.11`.

>From 808764675f3cc37f9b2e0f3f31372be93ada6b84 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 29 Oct 2023 09:02:12 -0400
Subject: [PATCH] [OpenMP] Add support for Solaris

Tested on `amd64-pc-solaris2.11`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp |  5 +
 clang/test/Driver/fopenmp.c | 19 ++-
 openmp/runtime/src/kmp.h|  8 ++--
 openmp/runtime/src/kmp_ftn_entry.h  |  2 +-
 openmp/runtime/src/kmp_platform.h   | 11 +--
 openmp/runtime/src/kmp_runtime.cpp  |  8 +---
 openmp/runtime/src/z_Linux_util.cpp | 21 +++--
 7 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..958ed99c482ed22 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
+// Use the static OpenMP runtime with -static-openmp
+bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
+!Args.hasArg(options::OPT_static);
+addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index cf04340ebc06ac6..2003fdbafe02760 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -16,6 +16,9 @@
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
 //
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP 
--check-prefix=CHECK-LD-GOMP-NO-RT
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
+//
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp -static-openmp 
%s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP 
--check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -static-openmp 
%s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -static 
-static-openmp %s -o %t -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
+//
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libomp %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libgomp %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libiomp5 %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
+//
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LD-OMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --ch

[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Brad Smith (brad0)


Changes

Tested on `amd64-pc-solaris2.11`.

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


7 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+5) 
- (modified) clang/test/Driver/fopenmp.c (+18-1) 
- (modified) openmp/runtime/src/kmp.h (+6-2) 
- (modified) openmp/runtime/src/kmp_ftn_entry.h (+1-1) 
- (modified) openmp/runtime/src/kmp_platform.h (+9-2) 
- (modified) openmp/runtime/src/kmp_runtime.cpp (+5-3) 
- (modified) openmp/runtime/src/z_Linux_util.cpp (+15-6) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..958ed99c482ed22 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
+// Use the static OpenMP runtime with -static-openmp
+bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
+!Args.hasArg(options::OPT_static);
+addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index cf04340ebc06ac6..2003fdbafe02760 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -16,6 +16,9 @@
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
 //
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP 
--check-prefix=CHECK-LD-GOMP-NO-RT
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
+//
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp -static-openmp 
%s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP 
--check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -static-openmp 
%s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -static 
-static-openmp %s -o %t -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
+//
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libomp %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libgomp %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libiomp5 %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
+//
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LD-OMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-IOMP5MD
@@ -152,7 +168,7 @@
 // C

[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 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 640274ff1fe17852615564a80d9f8c69b67f1d59 
808764675f3cc37f9b2e0f3f31372be93ada6b84 -- 
clang/lib/Driver/ToolChains/Solaris.cpp clang/test/Driver/fopenmp.c 
openmp/runtime/src/kmp.h openmp/runtime/src/kmp_ftn_entry.h 
openmp/runtime/src/kmp_platform.h openmp/runtime/src/kmp_runtime.cpp 
openmp/runtime/src/z_Linux_util.cpp
``





View the diff from clang-format here.


``diff
diff --git a/openmp/runtime/src/z_Linux_util.cpp 
b/openmp/runtime/src/z_Linux_util.cpp
index c3c8f33b3..82e2ad5e5 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -73,10 +73,11 @@ struct kmp_sys_timer {
 };
 
 #ifdef KMP_OS_SOLARIS
-#define TIMEVAL_TO_TIMESPEC(tv, ts) do {\
-(ts)->tv_sec = (tv)->tv_sec;\
-(ts)->tv_nsec = (tv)->tv_usec * 1000;   \
-} while (0)
+#define TIMEVAL_TO_TIMESPEC(tv, ts)
\
+  do { 
\
+(ts)->tv_sec = (tv)->tv_sec;   
\
+(ts)->tv_nsec = (tv)->tv_usec * 1000;  
\
+  } while (0)
 #endif
 
 // Convert timespec to nanoseconds.

``




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


[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70593

>From 80c900b380de3b6b536084e680bcffbd2b94962d Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 29 Oct 2023 09:02:12 -0400
Subject: [PATCH] [OpenMP] Add support for Solaris

Tested on `amd64-pc-solaris2.11`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp |  5 +
 clang/test/Driver/fopenmp.c | 19 ++-
 openmp/runtime/src/kmp.h|  8 ++--
 openmp/runtime/src/kmp_ftn_entry.h  |  2 +-
 openmp/runtime/src/kmp_platform.h   | 11 +--
 openmp/runtime/src/kmp_runtime.cpp  |  8 +---
 openmp/runtime/src/z_Linux_util.cpp | 22 --
 7 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..958ed99c482ed22 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
+// Use the static OpenMP runtime with -static-openmp
+bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
+!Args.hasArg(options::OPT_static);
+addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index cf04340ebc06ac6..2003fdbafe02760 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -16,6 +16,9 @@
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
 //
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP 
--check-prefix=CHECK-LD-GOMP-NO-RT
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
+//
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libgomp -static-openmp 
%s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP 
--check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -static-openmp 
%s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
+// RUN: %clang -target sparc-sun-solaris2.11 -fopenmp=libiomp5 -static 
-static-openmp %s -o %t -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
+//
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libomp %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libgomp %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
+// RUN: %clang -nostdlib -target sparc-sun-solaris2.11 -fopenmp=libiomp5 %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
+//
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LD-OMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
 //

[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-10-29 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 created 
https://github.com/llvm/llvm-project/pull/70594

Resolves Issue #35603

This change makes the `assertion` less strict in `debug` builds by stripping 
qualifiers from the base class and ignoring them. I hope `weakened` assertions 
don't affect other cases where such `errors` are intended to be `caught` by the 
compiler. 

>From 6c5fda81d4d9c5cda677cb84fffaa8bf5c2bb6ac Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix clang++ crash on assertions when compiling source

Resolves Issue #35603
---
 clang/lib/AST/ExprConstant.cpp  |  2 +-
 clang/test/Sema/assertion-crash.cpp | 19 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/assertion-crash.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5947805f9576ff8..07f0a12385b46e9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue &This,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/assertion-crash.cpp 
b/clang/test/Sema/assertion-crash.cpp
new file mode 100644
index 000..853552108ec2b67
--- /dev/null
+++ b/clang/test/Sema/assertion-crash.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rajveer Singh Bharadwaj (Rajveer100)


Changes

Resolves Issue #35603

This change makes the `assertion` less strict in `debug` builds by stripping 
qualifiers from the base class and ignoring them. I hope `weakened` assertions 
don't affect other cases where such `errors` are intended to be `caught` by the 
compiler. 

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


2 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+1-1) 
- (added) clang/test/Sema/assertion-crash.cpp (+19) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5947805f9576ff8..07f0a12385b46e9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue &This,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/assertion-crash.cpp 
b/clang/test/Sema/assertion-crash.cpp
new file mode 100644
index 000..853552108ec2b67
--- /dev/null
+++ b/clang/test/Sema/assertion-crash.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

``




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


[clang] f8fe400 - [clang][Interp][NFC] Make IntegralAP::isSigned() constexpr

2023-10-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-29T14:15:44+01:00
New Revision: f8fe40090ab302921bc4b83969bfec8b31c902aa

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

LOG: [clang][Interp][NFC] Make IntegralAP::isSigned() constexpr

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 45e5b49546270aa..cfed9ca29336d2e 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -124,7 +124,7 @@ template  class IntegralAP final {
   bool isNegative() const { return !V.isNonNegative(); }
   bool isMin() const { return V.isMinValue(); }
   bool isMax() const { return V.isMaxValue(); }
-  static bool isSigned() { return Signed; }
+  static constexpr bool isSigned() { return Signed; }
   bool isMinusOne() const { return Signed && V == -1; }
 
   unsigned countLeadingZeros() const { return V.countl_zero(); }



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


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2023-10-29 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/70306

>From b7af057b1e8cd56ce1151d6232244c137d349ea9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 25 Oct 2023 08:33:30 +0200
Subject: [PATCH 1/5] [clang][Interp] Implement dynamic memory allocation
 handling

---
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  |  76 +++
 clang/lib/AST/Interp/ByteCodeExprGen.h|   2 +
 clang/lib/AST/Interp/Context.cpp  |   2 +-
 clang/lib/AST/Interp/DynamicAllocator.cpp |  91 
 clang/lib/AST/Interp/DynamicAllocator.h   |  90 
 clang/lib/AST/Interp/EvalEmitter.cpp  |   4 +-
 clang/lib/AST/Interp/Interp.cpp   |  37 
 clang/lib/AST/Interp/Interp.h |  94 
 clang/lib/AST/Interp/InterpState.cpp  |  15 ++
 clang/lib/AST/Interp/InterpState.h|  10 +
 clang/lib/AST/Interp/Opcodes.td   |  24 +++
 clang/test/AST/Interp/new-delete.cpp  | 247 ++
 13 files changed, 690 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.cpp
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.h
 create mode 100644 clang/test/AST/Interp/new-delete.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..1423623fb038cab 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/DynamicAllocator.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 195af664c13dafc..380ec8fc2dda661 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1629,6 +1629,82 @@ bool 
ByteCodeExprGen::VisitCXXScalarValueInitExpr(
   return this->visitZeroInitializer(classifyPrim(Ty), Ty, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNewExpr(const CXXNewExpr *E) {
+  assert(classifyPrim(E->getType()) == PT_Ptr);
+  const Expr *Init = E->getInitializer();
+  QualType ElementType = E->getAllocatedType();
+  std::optional ElemT = classify(ElementType);
+
+  const Descriptor *Desc;
+  if (ElemT) {
+if (E->isArray())
+  Desc = nullptr; // We're not going to use it in this case.
+else
+  Desc = P.createDescriptor(E, *ElemT, Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false,
+/*IsMutable=*/false);
+  } else {
+Desc = P.createDescriptor(
+E, ElementType.getTypePtr(),
+E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init);
+  }
+
+  if (E->isArray()) {
+assert(E->getArraySize());
+PrimType SizeT = classifyPrim((*E->getArraySize())->getType());
+
+if (!this->visit(*E->getArraySize()))
+  return false;
+
+if (ElemT) {
+  // N primitive elements.
+  if (!this->emitAllocN(SizeT, *ElemT, E, E))
+return false;
+} else {
+  // N Composite elements.
+  if (!this->emitAllocCN(SizeT, Desc, E))
+return false;
+}
+
+  } else {
+// Allocate just one element.
+if (!this->emitAlloc(Desc, E))
+  return false;
+
+if (Init) {
+  if (ElemT) {
+if (!this->visit(Init))
+  return false;
+
+if (!this->emitInit(*ElemT, E))
+  return false;
+  } else {
+// Composite.
+if (!this->visitInitializer(Init))
+  return false;
+  }
+}
+  }
+
+  if (DiscardResult)
+return this->emitPopPtr(E);
+
+  return true;
+}
+
+template 
+bool ByteCodeExprGen::VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+  const Expr *Arg = E->getArgument();
+
+  // Arg must be an lvalue.
+  if (!this->visit(Arg))
+return false;
+
+  return this->emitFree(E->isArrayForm(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 83986d3dd579ed6..f65dc9494db36ef 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -107,6 +107,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitSourceLocExpr(const SourceLocExpr *E);
   bool VisitOffsetOfExpr(const OffsetOfExpr *E);
   bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
+  bool VisitCXXNewExpr(const CXXNewExpr *E);
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AS

[clang-tools-extra] [clang-tidy] Add readability-redundant-casting check (PR #70595)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Detects explicit type casting operations that involve the same source and 
destination types, and subsequently recommend their removal. Covers a range of 
explicit casting operations. Its primary objective is to enhance code 
readability and maintainability by eliminating unnecessary type casting.

Closes #67534

---

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


10 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
(+3) 
- (added) clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp 
(+242) 
- (added) clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.h 
(+38) 
- (modified) clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp (+5) 
- (modified) clang-tools-extra/clang-tidy/utils/FixItHintUtils.h (+4) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-casting.rst 
(+37) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp 
(+200) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..52f873d2a14b700 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -33,6 +33,7 @@ add_clang_library(clangTidyReadabilityModule
   QualifiedAutoCheck.cpp
   ReadabilityTidyModule.cpp
   RedundantAccessSpecifiersCheck.cpp
+  RedundantCastingCheck.cpp
   RedundantControlFlowCheck.cpp
   RedundantDeclarationCheck.cpp
   RedundantFunctionPtrDereferenceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..d33d429f64c4421 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -36,6 +36,7 @@
 #include "OperatorsRepresentationCheck.h"
 #include "QualifiedAutoCheck.h"
 #include "RedundantAccessSpecifiersCheck.h"
+#include "RedundantCastingCheck.h"
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
@@ -111,6 +112,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-qualified-auto");
 CheckFactories.registerCheck(
 "readability-redundant-access-specifiers");
+CheckFactories.registerCheck(
+"readability-redundant-casting");
 CheckFactories.registerCheck(
 "readability-redundant-function-ptr-dereference");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
new file mode 100644
index 000..ab18b6b7dd886f7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
@@ -0,0 +1,242 @@
+//===--- RedundantCastingCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantCastingCheck.h"
+#include "../utils/FixItHintUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static bool areTypesEquals(QualType S, QualType D) {
+  if (S == D)
+return true;
+
+  const auto *TS = S->getAs();
+  const auto *TD = D->getAs();
+  if (TS != TD)
+return false;
+
+  QualType PtrS = S->getPointeeType();
+  QualType PtrD = D->getPointeeType();
+
+  if (!PtrS.isNull() && !PtrD.isNull())
+return areTypesEquals(PtrS, PtrD);
+
+  const DeducedType *DT = S->getContainedDeducedType();
+  if (DT && DT->isDeduced())
+return D == DT->getDeducedType();
+
+  return false;
+}
+
+static bool areTypesEquals(QualType TypeS, QualType TypeD,
+   bool IgnoreTypeAliases) {
+  const QualType CTypeS = TypeS.getCanonicalType();
+  const QualType CTypeD = TypeD.getCanonicalType();
+  if (CTypeS != CTypeD)
+return false;
+
+  return IgnoreTypeAliases || areTypesEquals(TypeS.getLocalUnqualifiedType(),
+ TypeD.getLocalUnqualifiedType());
+}
+
+static bool areBinaryOperatorOperandsTypesEqual(const Expr *E,
+ 

[clang-tools-extra] [clang-tidy] Add readability-redundant-casting check (PR #70595)

2023-10-29 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

431 issues found in llvm.

Example:
```
clang/lib/Sema/SemaAttr.cpp:332:21: warning: redundant explicit casting to the 
same type 'Expr *' as the sub-expression, remove this casting 
[readability-redundant-casting]
 332 |   Expr *Alignment = static_cast(alignment);
 | ^~~~ ~
clang/lib/Sema/SemaAttr.cpp:323:55: note: source type originates from 
referencing this parameter
 323 |StringRef SlotLabel, Expr *alignment) {
 | ~~^
```

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


[clang-tools-extra] [clang-tidy] Add readability-redundant-casting check (PR #70595)

2023-10-29 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/70595

Detects explicit type casting operations that involve the same source and 
destination types, and subsequently recommend their removal. Covers a range of 
explicit casting operations. Its primary objective is to enhance code 
readability and maintainability by eliminating unnecessary type casting.

Closes #67534

>From e17c6f3fcd14bade8295480f84ba1ce12ec27c13 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 10 Oct 2023 20:37:05 +
Subject: [PATCH] [clang-tidy] Add readability-redundant-casting check

Detects explicit type casting operations that involve the same source and
destination types, and subsequently recommend their removal. Covers a range
of explicit casting operations. Its primary objective is to enhance code
readability and maintainability by eliminating unnecessary type casting.
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../readability/RedundantCastingCheck.cpp | 242 ++
 .../readability/RedundantCastingCheck.h   |  38 +++
 .../clang-tidy/utils/FixItHintUtils.cpp   |   5 +
 .../clang-tidy/utils/FixItHintUtils.h |   4 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/readability/redundant-casting.rst  |  37 +++
 .../readability/redundant-casting.cpp | 200 +++
 10 files changed, 537 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-casting.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..52f873d2a14b700 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -33,6 +33,7 @@ add_clang_library(clangTidyReadabilityModule
   QualifiedAutoCheck.cpp
   ReadabilityTidyModule.cpp
   RedundantAccessSpecifiersCheck.cpp
+  RedundantCastingCheck.cpp
   RedundantControlFlowCheck.cpp
   RedundantDeclarationCheck.cpp
   RedundantFunctionPtrDereferenceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..d33d429f64c4421 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -36,6 +36,7 @@
 #include "OperatorsRepresentationCheck.h"
 #include "QualifiedAutoCheck.h"
 #include "RedundantAccessSpecifiersCheck.h"
+#include "RedundantCastingCheck.h"
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
@@ -111,6 +112,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-qualified-auto");
 CheckFactories.registerCheck(
 "readability-redundant-access-specifiers");
+CheckFactories.registerCheck(
+"readability-redundant-casting");
 CheckFactories.registerCheck(
 "readability-redundant-function-ptr-dereference");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
new file mode 100644
index 000..ab18b6b7dd886f7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
@@ -0,0 +1,242 @@
+//===--- RedundantCastingCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantCastingCheck.h"
+#include "../utils/FixItHintUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static bool areTypesEquals(QualType S, QualType D) {
+  if (S == D)
+return true;
+
+  const auto *TS = S->getAs();
+  const auto *TD = D->getAs();
+  if (TS != TD)
+return false;
+
+  QualType PtrS = S->getPointeeType();
+  QualType PtrD = D->getPointeeType();
+
+  if (!PtrS.isNull() && !PtrD.isNull())
+return areTypesEquals(PtrS, PtrD);
+
+  const DeducedType *DT = S->getContainedDeducedType();
+  if (DT && DT->isDeduced())
+return D == DT->getDeducedType();
+
+  return f

[clang-tools-extra] [clang-tidy] Fix #68492: point to the correct const location (PR #69103)

2023-10-29 Thread Piotr Zegar via cfe-commits

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


[clang] [clang-tidy] Fix #68492: point to the correct const location (PR #69103)

2023-10-29 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix #68492: point to the correct const location (PR #69103)

2023-10-29 Thread Piotr Zegar via cfe-commits

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


[clang] [clang-tidy] Fix readability-avoid-const-params-in-decls - point to the correct const location (PR #69103)

2023-10-29 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix readability-avoid-const-params-in-decls - point to the correct const location (PR #69103)

2023-10-29 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 3f64c0f - [clang-tidy] Fix readability-avoid-const-params-in-decls - point to the correct const location (#69103)

2023-10-29 Thread via cfe-commits

Author: Da-Viper
Date: 2023-10-29T15:17:32+01:00
New Revision: 3f64c0fc48c5b2efc5b9ba11351647d515f23418

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

LOG: [clang-tidy] Fix readability-avoid-const-params-in-decls - point to the 
correct const location (#69103)

Fixes the warning marker for redundant const from beginning of variable
to actual location of const. 

Fixes #68492

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
index 6476f1d7fdf2b81..24cbbd8bc60a2b5 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -21,6 +21,24 @@ SourceRange getTypeRange(const ParmVarDecl &Param) {
   return {Param.getBeginLoc(), Param.getLocation().getLocWithOffset(-1)};
 }
 
+// Finds the location of the qualifying `const` token in the `ParmValDecl`'s
+// return type. Returns `std::nullopt` when the parm type is not
+// `const`-qualified like when the type is an alias or a macro.
+static std::optional
+findConstToRemove(const ParmVarDecl &Param,
+  const MatchFinder::MatchResult &Result) {
+
+  CharSourceRange FileRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(getTypeRange(Param)),
+  *Result.SourceManager, Result.Context->getLangOpts());
+
+  if (FileRange.isInvalid())
+return std::nullopt;
+
+  return tidy::utils::lexer::getQualifyingToken(
+  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
+}
+
 } // namespace
 
 void AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
@@ -30,11 +48,10 @@ void 
AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
   const auto ConstParamDecl =
   parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
-  Finder->addMatcher(
-  functionDecl(unless(isDefinition()),
-   has(typeLoc(forEach(ConstParamDecl
-  .bind("func"),
-  this);
+  Finder->addMatcher(functionDecl(unless(isDefinition()),
+  has(typeLoc(forEach(ConstParamDecl
+ .bind("func"),
+ this);
 }
 
 void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) {
@@ -50,7 +67,10 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
-  auto Diag = diag(Param->getBeginLoc(),
+  const auto Tok = findConstToRemove(*Param, Result);
+  const auto ConstLocation = Tok ? Tok->getLocation() : Param->getBeginLoc();
+
+  auto Diag = diag(ConstLocation,
"parameter %0 is const-qualified in the function "
"declaration; const-qualification of parameters only has an 
"
"effect in function definitions");
@@ -70,18 +90,9 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 // from a macro.
 return;
   }
-
-  CharSourceRange FileRange = Lexer::makeFileCharRange(
-  CharSourceRange::getTokenRange(getTypeRange(*Param)),
-  *Result.SourceManager, getLangOpts());
-
-  if (!FileRange.isValid())
-return;
-
-  auto Tok = tidy::utils::lexer::getQualifyingToken(
-  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
   if (!Tok)
 return;
+
   Diag << FixItHint::CreateRemoval(
   CharSourceRange::getTokenRange(Tok->getLocation(), Tok->getLocation()));
 }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5ce38ab48bf295f..ecfb3aa9267f140 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -369,6 +369,10 @@ Changes in existing checks
   ` check to
   ignore false-positive for ``if constexpr`` in lambda expression.
 
+- Improved :doc:`readability-avoid-const-params-in-decls
+  ` diagnositics to
+  highlight the const location
+
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals and support

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
index d521fd238b7d521..bc098efe3044a5d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-para

[clang] [clang-tidy] Fix readability-avoid-const-params-in-decls - point to the correct const location (PR #69103)

2023-10-29 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix readability-avoid-const-params-in-decls - point to the correct const location (PR #69103)

2023-10-29 Thread Piotr Zegar via cfe-commits

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


[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 Thread Shilei Tian via cfe-commits

shiltian wrote:

I'm not familiar with Solaris but does it need dedicated implementation of the 
function invocation written in ASM?

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


[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread via cfe-commits


@@ -1964,11 +1969,14 @@ bool Lexer::LexIdentifierContinue(Token &Result, const 
char *CurPtr) {
 /// isHexaLiteral - Return true if Start points to a hex constant.
 /// in microsoft mode (where this is supposed to be several different tokens).
 bool Lexer::isHexaLiteral(const char *Start, const LangOptions &LangOpts) {
-  unsigned Size;
-  char C1 = Lexer::getCharAndSizeNoWarn(Start, Size, LangOpts);
+  auto CharAndSize1 = Lexer::getCharAndSizeNoWarn(Start, LangOpts);
+  char C1 = CharAndSize1.Char;
   if (C1 != '0')
 return false;
-  char C2 = Lexer::getCharAndSizeNoWarn(Start + Size, Size, LangOpts);
+
+  auto CharAndSize2 =

cor3ntin wrote:

I won't insist!

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


[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread via cfe-commits

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

LGTM, thanks

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


[clang] [clang][Interp] Handle CXXTryStmts (PR #70584)

2023-10-29 Thread via cfe-commits

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


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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-29 Thread via cfe-commits


@@ -817,7 +817,7 @@ For later versions of Visual Studio, no setup is required-->
  
{IncludeMacroStack._Mypair._Myval2._Mylast - 1,na}
 {CurLexer._Mypair._Myval2,na}
 Expanding 
Macro: {CurTokenLexer._Mypair._Myval2,na}
-

cor3ntin wrote:

@AaronBallman can you review this change?

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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-29 Thread via cfe-commits


@@ -1914,7 +1909,7 @@ class Preprocessor {
 
   /// Recompute the current lexer kind based on the CurLexer/
   /// CurTokenLexer pointers.
-  void recomputeCurLexerKind();
+  void recomputeCurLexerCallback();

cor3ntin wrote:

I think renaming this one is a bit too aggressive. Ideally that we use a 
callback is an implementation detail that should not leak more than it needs to

 ```suggestion
  void recomputeCurLexerKind();
```

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


[clang] [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (PR #70383)

2023-10-29 Thread Joseph Huber via cfe-commits


@@ -4078,8 +4092,20 @@ OpenMPIRBuilder::createTargetInit(const 
LocationDescription &Loc, bool IsSPMD) {
   Constant *DebugIndentionLevelVal = ConstantInt::getSigned(Int16, 0);
 
   Function *Kernel = Builder.GetInsertBlock()->getParent();
-  auto [MinThreadsVal, MaxThreadsVal] = readThreadBoundsForKernel(*Kernel);
-  auto [MinTeamsVal, MaxTeamsVal] = readTeamBoundsForKernel(*Kernel);
+
+  /// Manifest the launch configuration in the metadata matching the kernel
+  /// environment.

jhuber6 wrote:

Doxygen comments?

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


[clang] [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (PR #70383)

2023-10-29 Thread Joseph Huber via cfe-commits


@@ -339,9 +339,33 @@ Error GenericKernelTy::init(GenericDeviceTy &GenericDevice,
 
   ImagePtr = &Image;
 
-  PreferredNumThreads = GenericDevice.getDefaultNumThreads();
+  // Retrieve kernel environment object for the kernel.
+  GlobalTy KernelEnv(std::string(Name) + "_kernel_environment",
+ sizeof(KernelEnvironment), &KernelEnvironment);
+  GenericGlobalHandlerTy &GHandler = Plugin::get().getGlobalHandler();
+  if (auto Err =
+  GHandler.readGlobalFromImage(GenericDevice, *ImagePtr, KernelEnv)) {
+[[maybe_unused]] std::string ErrStr = toString(std::move(Err));
+DP("Failed to read kernel environment for '%s': %s\n"
+   "Using default SPMD (2) execution mode\n",
+   Name, ErrStr.data());
+KernelEnvironment.Configuration.ExecMode = OMP_TGT_EXEC_MODE_SPMD;
+KernelEnvironment.Configuration.MayUseNestedParallelism = /* Unknown */ 2;

jhuber6 wrote:

```suggestion
KernelEnvironment.Configuration.MayUseNestedParallelism = /*Unknown=*/2;
```

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


[clang] [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (PR #70383)

2023-10-29 Thread Joseph Huber via cfe-commits

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


[clang] [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (PR #70383)

2023-10-29 Thread Joseph Huber via cfe-commits

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

Lots of churn but looks straightforward enough. Few nits.

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


[clang] d8f5a18 - Perf/lexer faster slow get char and size (#70543)

2023-10-29 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-10-29T18:17:02Z
New Revision: d8f5a18b6e587aeaa8b99707e87b652f49b160cd

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

LOG: Perf/lexer faster slow get char and size (#70543)

Co-authored-by: serge-sans-paille 

Added: 


Modified: 
clang/include/clang/Lex/Lexer.h
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Lex/Lexer.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h
index ac0ef14c591bdd7..899e665e7454652 100644
--- a/clang/include/clang/Lex/Lexer.h
+++ b/clang/include/clang/Lex/Lexer.h
@@ -575,19 +575,23 @@ class Lexer : public PreprocessorLexer {
   /// sequence.
   static bool isNewLineEscaped(const char *BufferStart, const char *Str);
 
+  /// Represents a char and the number of bytes parsed to produce it.
+  struct SizedChar {
+char Char;
+unsigned Size;
+  };
+
   /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever
   /// emit a warning.
-  static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size,
-  const LangOptions &LangOpts) {
+  static inline SizedChar getCharAndSizeNoWarn(const char *Ptr,
+   const LangOptions &LangOpts) {
 // If this is not a trigraph and not a UCN or escaped newline, return
 // quickly.
 if (isObviouslySimpleCharacter(Ptr[0])) {
-  Size = 1;
-  return *Ptr;
+  return {*Ptr, 1u};
 }
 
-Size = 0;
-return getCharAndSizeSlowNoWarn(Ptr, Size, LangOpts);
+return getCharAndSizeSlowNoWarn(Ptr, LangOpts);
   }
 
   /// Returns the leading whitespace for line that corresponds to the given
@@ -665,8 +669,7 @@ class Lexer : public PreprocessorLexer {
 // quickly.
 if (isObviouslySimpleCharacter(Ptr[0])) return *Ptr++;
 
-unsigned Size = 0;
-char C = getCharAndSizeSlow(Ptr, Size, &Tok);
+auto [C, Size] = getCharAndSizeSlow(Ptr, &Tok);
 Ptr += Size;
 return C;
   }
@@ -682,9 +685,7 @@ class Lexer : public PreprocessorLexer {
 
 // Otherwise, re-lex the character with a current token, allowing
 // diagnostics to be emitted and flags to be set.
-Size = 0;
-getCharAndSizeSlow(Ptr, Size, &Tok);
-return Ptr+Size;
+return Ptr + getCharAndSizeSlow(Ptr, &Tok).Size;
   }
 
   /// getCharAndSize - Peek a single 'character' from the specified buffer,
@@ -699,14 +700,14 @@ class Lexer : public PreprocessorLexer {
   return *Ptr;
 }
 
-Size = 0;
-return getCharAndSizeSlow(Ptr, Size);
+auto CharAndSize = getCharAndSizeSlow(Ptr);
+Size = CharAndSize.Size;
+return CharAndSize.Char;
   }
 
   /// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize
   /// method.
-  char getCharAndSizeSlow(const char *Ptr, unsigned &Size,
-  Token *Tok = nullptr);
+  SizedChar getCharAndSizeSlow(const char *Ptr, Token *Tok = nullptr);
 
   /// getEscapedNewLineSize - Return the size of the specified escaped newline,
   /// or 0 if it is not an escaped newline. P[-1] is known to be a "\" on entry
@@ -720,8 +721,8 @@ class Lexer : public PreprocessorLexer {
 
   /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a
   /// diagnostic.
-  static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size,
-   const LangOptions &LangOpts);
+  static SizedChar getCharAndSizeSlowNoWarn(const char *Ptr,
+const LangOptions &LangOpts);
 
   
//======//
   // Other lexer functions.

diff  --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 2bd2c5f8388c0dd..980f865cf24c97e 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -565,9 +565,8 @@ Scanner::cleanStringIfNeeded(const 
dependency_directives_scan::Token &Tok) {
   const char *BufPtr = Input.begin() + Tok.Offset;
   const char *AfterIdent = Input.begin() + Tok.getEnd();
   while (BufPtr < AfterIdent) {
-unsigned Size;
-Spelling[SpellingLength++] =
-Lexer::getCharAndSizeNoWarn(BufPtr, Size, LangOpts);
+auto [Char, Size] = Lexer::getCharAndSizeNoWarn(BufPtr, LangOpts);
+Spelling[SpellingLength++] = Char;
 BufPtr += Size;
   }
 

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 675ec28e514797e..1c53997527732a9 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -287,9 +287,9 @@ static size_t getSpellingSlow(const Token &Tok, const char 
*BufPtr,
   if (tok::isStringLiteral(Tok.getKind())) {
 // Munch the

[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread via cfe-commits

https://github.com/serge-sans-paille closed 
https://github.com/llvm/llvm-project/pull/70543
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-29 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70381

>From 3fe63f81fcb999681daa11b2890c82fda3aaeef5 Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 26 Oct 2023 22:31:43 +0200
Subject: [PATCH 1/2] [clang] Change representation of CurLexerKind

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on
compile time tracker are consistent and range form -0.05% to -0.20%
for NewPM-O0-g, see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef&to=608c85ec1283638db949d73e062bcc3355001ce4&stat=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)
---
 clang/include/clang/Lex/Preprocessor.h| 46 +++-
 clang/lib/Lex/PPCaching.cpp   |  8 +--
 clang/lib/Lex/PPLexerChange.cpp   | 20 +++
 clang/lib/Lex/Preprocessor.cpp| 67 ++-
 clang/utils/ClangVisualizers/clang.natvis |  2 +-
 5 files changed, 62 insertions(+), 81 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 18d88407ae12c90..634d3924aa2248b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = &CLK_Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &&TheLexer,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &&TheTokenLexer,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -1914,7 +1909,7 @@ class Preprocessor {
 
   /// Recompute the current lexer kind based on the CurLexer/
   /// CurTokenLexer pointers.
-  void recomputeCurLexerKind();
+  void recomputeCurLexerCallback();
 
   /// Returns true if incremental processing is enabled
   bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+ 

[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-29 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70381

>From 3fe63f81fcb999681daa11b2890c82fda3aaeef5 Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 26 Oct 2023 22:31:43 +0200
Subject: [PATCH 1/2] [clang] Change representation of CurLexerKind

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on
compile time tracker are consistent and range form -0.05% to -0.20%
for NewPM-O0-g, see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef&to=608c85ec1283638db949d73e062bcc3355001ce4&stat=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)
---
 clang/include/clang/Lex/Preprocessor.h| 46 +++-
 clang/lib/Lex/PPCaching.cpp   |  8 +--
 clang/lib/Lex/PPLexerChange.cpp   | 20 +++
 clang/lib/Lex/Preprocessor.cpp| 67 ++-
 clang/utils/ClangVisualizers/clang.natvis |  2 +-
 5 files changed, 62 insertions(+), 81 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 18d88407ae12c90..634d3924aa2248b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = &CLK_Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &&TheLexer,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &&TheTokenLexer,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -1914,7 +1909,7 @@ class Preprocessor {
 
   /// Recompute the current lexer kind based on the CurLexer/
   /// CurTokenLexer pointers.
-  void recomputeCurLexerKind();
+  void recomputeCurLexerCallback();
 
   /// Returns true if incremental processing is enabled
   bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+ 

[clang] [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (PR #70383)

2023-10-29 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert updated 
https://github.com/llvm/llvm-project/pull/70383

>From fa6d6d9cf6398915f911e06eecc78c7ba83d3623 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert 
Date: Wed, 25 Oct 2023 16:46:01 -0700
Subject: [PATCH] [OpenMP] Associate the KernelEnvironment with the
 GenericKernelTy

By associating the kernel environment with the generic kernel we can
access middle-end information easily, including the launch bounds ranges
that are acceptable. By constraining the number of threads accordingly,
we now obey the user provided bounds that were passed via attributes.
---
 clang/test/OpenMP/bug57757.cpp| 15 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp |  4 +-
 .../plugins-nextgen/amdgpu/src/rtl.cpp|  8 +-
 .../PluginInterface/PluginInterface.cpp   | 74 +++
 .../common/PluginInterface/PluginInterface.h  | 39 +-
 .../plugins-nextgen/cuda/src/rtl.cpp  |  8 +-
 .../generic-elf-64bit/src/rtl.cpp | 20 ++---
 .../test/offloading/default_thread_limit.c|  3 +-
 .../test/offloading/thread_state_1.c  |  4 +-
 .../test/offloading/thread_state_2.c  |  4 +-
 10 files changed, 74 insertions(+), 105 deletions(-)

diff --git a/clang/test/OpenMP/bug57757.cpp b/clang/test/OpenMP/bug57757.cpp
index 7894796ac46284c..7acfe134ddd0baf 100644
--- a/clang/test/OpenMP/bug57757.cpp
+++ b/clang/test/OpenMP/bug57757.cpp
@@ -32,24 +32,23 @@ void foo() {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP2:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP1]], i64 0, i32 2
 // CHECK-NEXT:tail call void 
@llvm.experimental.noalias.scope.decl(metadata [[META13:![0-9]+]])
-// CHECK-NEXT:tail call void 
@llvm.experimental.noalias.scope.decl(metadata [[META16:![0-9]+]])
-// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4, !tbaa 
[[TBAA18:![0-9]+]], !alias.scope !13, !noalias !16
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4, !tbaa 
[[TBAA16:![0-9]+]], !alias.scope !13, !noalias !17
 // CHECK-NEXT:switch i32 [[TMP3]], label [[DOTOMP_OUTLINED__EXIT:%.*]] [
 // CHECK-NEXT:i32 0, label [[DOTUNTIED_JMP__I:%.*]]
 // CHECK-NEXT:i32 1, label [[DOTUNTIED_NEXT__I:%.*]]
 // CHECK-NEXT:]
 // CHECK:   .untied.jmp..i:
-// CHECK-NEXT:store i32 1, ptr [[TMP2]], align 4, !tbaa [[TBAA18]], 
!alias.scope !13, !noalias !16
-// CHECK-NEXT:[[TMP4:%.*]] = tail call i32 @__kmpc_omp_task(ptr nonnull 
@[[GLOB1]], i32 [[TMP0]], ptr [[TMP1]]), !noalias !19
+// CHECK-NEXT:store i32 1, ptr [[TMP2]], align 4, !tbaa [[TBAA16]], 
!alias.scope !13, !noalias !17
+// CHECK-NEXT:[[TMP4:%.*]] = tail call i32 @__kmpc_omp_task(ptr nonnull 
@[[GLOB1]], i32 [[TMP0]], ptr [[TMP1]]), !noalias !13
 // CHECK-NEXT:br label [[DOTOMP_OUTLINED__EXIT]]
 // CHECK:   .untied.next..i:
 // CHECK-NEXT:[[TMP5:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP1]], i64 0, i32 1
 // CHECK-NEXT:[[TMP6:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T_WITH_PRIVATES]], ptr [[TMP1]], i64 0, i32 1, i32 2
 // CHECK-NEXT:[[TMP7:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T_WITH_PRIVATES]], ptr [[TMP1]], i64 0, i32 1, i32 1
-// CHECK-NEXT:[[TMP8:%.*]] = load ptr, ptr [[TMP5]], align 8, !tbaa 
[[TBAA20:![0-9]+]], !alias.scope !16, !noalias !13
-// CHECK-NEXT:[[TMP9:%.*]] = load i32, ptr [[TMP7]], align 4, !tbaa 
[[TBAA18]], !alias.scope !16, !noalias !13
-// CHECK-NEXT:[[TMP10:%.*]] = load float, ptr [[TMP6]], align 4, !tbaa 
[[TBAA21:![0-9]+]], !alias.scope !16, !noalias !13
-// CHECK-NEXT:tail call void [[TMP8]](i32 noundef [[TMP9]], float noundef 
[[TMP10]]) #[[ATTR2:[0-9]+]], !noalias !19
+// CHECK-NEXT:[[TMP8:%.*]] = load ptr, ptr [[TMP5]], align 8, !tbaa 
[[TBAA19:![0-9]+]], !noalias !13
+// CHECK-NEXT:[[TMP9:%.*]] = load i32, ptr [[TMP7]], align 4, !tbaa 
[[TBAA16]], !noalias !13
+// CHECK-NEXT:[[TMP10:%.*]] = load float, ptr [[TMP6]], align 4, !tbaa 
[[TBAA20:![0-9]+]], !noalias !13
+// CHECK-NEXT:tail call void [[TMP8]](i32 noundef [[TMP9]], float noundef 
[[TMP10]]) #[[ATTR2:[0-9]+]], !noalias !13
 // CHECK-NEXT:br label [[DOTOMP_OUTLINED__EXIT]]
 // CHECK:   .omp_outlined..exit:
 // CHECK-NEXT:ret i32 0
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 3e4e030f44c7fe0..b320d77652e1cba 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4093,8 +4093,8 @@ OpenMPIRBuilder::createTargetInit(const 
LocationDescription &Loc, bool IsSPMD,
 
   Function *Kernel = Builder.GetInsertBlock()->getParent();
 
-  /// Manifest the launch configuration in the metadata matching the kernel
-  /// environment.
+  // Manifest the launch configuration in the metadata matching the kernel
+  // environment.
   if (MinTeamsVal > 1 || MaxTeamsVal > 0)
 writeTeamsForKernel(T, *Kernel, MinTeamsVal, MaxTeams

[clang] d346c82 - [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (#70383)

2023-10-29 Thread via cfe-commits

Author: Johannes Doerfert
Date: 2023-10-29T11:35:34-07:00
New Revision: d346c82435f377984c2ff3d7d4b5e3942c72bc17

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

LOG: [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (#70383)

By associating the kernel environment with the generic kernel we can
access middle-end information easily, including the launch bounds ranges
that are acceptable. By constraining the number of threads accordingly,
we now obey the user-provided bounds that were passed via attributes.

Added: 


Modified: 
clang/test/OpenMP/bug57757.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
openmp/libomptarget/test/offloading/default_thread_limit.c
openmp/libomptarget/test/offloading/thread_state_1.c
openmp/libomptarget/test/offloading/thread_state_2.c

Removed: 




diff  --git a/clang/test/OpenMP/bug57757.cpp b/clang/test/OpenMP/bug57757.cpp
index 7894796ac46284c..7acfe134ddd0baf 100644
--- a/clang/test/OpenMP/bug57757.cpp
+++ b/clang/test/OpenMP/bug57757.cpp
@@ -32,24 +32,23 @@ void foo() {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP2:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP1]], i64 0, i32 2
 // CHECK-NEXT:tail call void 
@llvm.experimental.noalias.scope.decl(metadata [[META13:![0-9]+]])
-// CHECK-NEXT:tail call void 
@llvm.experimental.noalias.scope.decl(metadata [[META16:![0-9]+]])
-// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4, !tbaa 
[[TBAA18:![0-9]+]], !alias.scope !13, !noalias !16
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4, !tbaa 
[[TBAA16:![0-9]+]], !alias.scope !13, !noalias !17
 // CHECK-NEXT:switch i32 [[TMP3]], label [[DOTOMP_OUTLINED__EXIT:%.*]] [
 // CHECK-NEXT:i32 0, label [[DOTUNTIED_JMP__I:%.*]]
 // CHECK-NEXT:i32 1, label [[DOTUNTIED_NEXT__I:%.*]]
 // CHECK-NEXT:]
 // CHECK:   .untied.jmp..i:
-// CHECK-NEXT:store i32 1, ptr [[TMP2]], align 4, !tbaa [[TBAA18]], 
!alias.scope !13, !noalias !16
-// CHECK-NEXT:[[TMP4:%.*]] = tail call i32 @__kmpc_omp_task(ptr nonnull 
@[[GLOB1]], i32 [[TMP0]], ptr [[TMP1]]), !noalias !19
+// CHECK-NEXT:store i32 1, ptr [[TMP2]], align 4, !tbaa [[TBAA16]], 
!alias.scope !13, !noalias !17
+// CHECK-NEXT:[[TMP4:%.*]] = tail call i32 @__kmpc_omp_task(ptr nonnull 
@[[GLOB1]], i32 [[TMP0]], ptr [[TMP1]]), !noalias !13
 // CHECK-NEXT:br label [[DOTOMP_OUTLINED__EXIT]]
 // CHECK:   .untied.next..i:
 // CHECK-NEXT:[[TMP5:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP1]], i64 0, i32 1
 // CHECK-NEXT:[[TMP6:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T_WITH_PRIVATES]], ptr [[TMP1]], i64 0, i32 1, i32 2
 // CHECK-NEXT:[[TMP7:%.*]] = getelementptr inbounds 
[[STRUCT_KMP_TASK_T_WITH_PRIVATES]], ptr [[TMP1]], i64 0, i32 1, i32 1
-// CHECK-NEXT:[[TMP8:%.*]] = load ptr, ptr [[TMP5]], align 8, !tbaa 
[[TBAA20:![0-9]+]], !alias.scope !16, !noalias !13
-// CHECK-NEXT:[[TMP9:%.*]] = load i32, ptr [[TMP7]], align 4, !tbaa 
[[TBAA18]], !alias.scope !16, !noalias !13
-// CHECK-NEXT:[[TMP10:%.*]] = load float, ptr [[TMP6]], align 4, !tbaa 
[[TBAA21:![0-9]+]], !alias.scope !16, !noalias !13
-// CHECK-NEXT:tail call void [[TMP8]](i32 noundef [[TMP9]], float noundef 
[[TMP10]]) #[[ATTR2:[0-9]+]], !noalias !19
+// CHECK-NEXT:[[TMP8:%.*]] = load ptr, ptr [[TMP5]], align 8, !tbaa 
[[TBAA19:![0-9]+]], !noalias !13
+// CHECK-NEXT:[[TMP9:%.*]] = load i32, ptr [[TMP7]], align 4, !tbaa 
[[TBAA16]], !noalias !13
+// CHECK-NEXT:[[TMP10:%.*]] = load float, ptr [[TMP6]], align 4, !tbaa 
[[TBAA20:![0-9]+]], !noalias !13
+// CHECK-NEXT:tail call void [[TMP8]](i32 noundef [[TMP9]], float noundef 
[[TMP10]]) #[[ATTR2:[0-9]+]], !noalias !13
 // CHECK-NEXT:br label [[DOTOMP_OUTLINED__EXIT]]
 // CHECK:   .omp_outlined..exit:
 // CHECK-NEXT:ret i32 0

diff  --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 3e4e030f44c7fe0..b320d77652e1cba 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4093,8 +4093,8 @@ OpenMPIRBuilder::createTargetInit(const 
LocationDescription &Loc, bool IsSPMD,
 
   Function *Kernel = Builder.GetInsertBlock()->getParent();
 
-  /// Manifest the launch configuration in the metadata matching the kernel
-  /// environment.
+  // Manifest the la

[clang] [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (PR #70383)

2023-10-29 Thread Johannes Doerfert via cfe-commits

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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-29 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70381

>From 3fe63f81fcb999681daa11b2890c82fda3aaeef5 Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 26 Oct 2023 22:31:43 +0200
Subject: [PATCH 1/3] [clang] Change representation of CurLexerKind

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on
compile time tracker are consistent and range form -0.05% to -0.20%
for NewPM-O0-g, see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef&to=608c85ec1283638db949d73e062bcc3355001ce4&stat=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)
---
 clang/include/clang/Lex/Preprocessor.h| 46 +++-
 clang/lib/Lex/PPCaching.cpp   |  8 +--
 clang/lib/Lex/PPLexerChange.cpp   | 20 +++
 clang/lib/Lex/Preprocessor.cpp| 67 ++-
 clang/utils/ClangVisualizers/clang.natvis |  2 +-
 5 files changed, 62 insertions(+), 81 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 18d88407ae12c90..634d3924aa2248b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = &CLK_Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &&TheLexer,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &&TheTokenLexer,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -1914,7 +1909,7 @@ class Preprocessor {
 
   /// Recompute the current lexer kind based on the CurLexer/
   /// CurTokenLexer pointers.
-  void recomputeCurLexerKind();
+  void recomputeCurLexerCallback();
 
   /// Returns true if incremental processing is enabled
   bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+ 

[clang-tools-extra] [clang-tidy] Improve modernize-make-shared check (PR #70600)

2023-10-29 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/70600

Improved modernize-make-shared check to support
std::shared_ptr implementations that inherit the
reset method from a base class.
In GCC that class is called __shared_ptr.

Fixes #64481

>From 79c01dbf330cd3489ee8ac1dd284c80eacebce85 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 29 Oct 2023 19:21:23 +
Subject: [PATCH] [clang-tidy] Improve modernize-make-shared check

Improved modernize-make-shared check to support
std::shared_ptr implementations that inherit the
reset method from a base class.
In GCC that class is called __shared_ptr.
---
 .../modernize/MakeSmartPtrCheck.cpp   | 20 --
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 
 .../modernize/Inputs/smart-ptr/shared_ptr.h   | 27 ---
 3 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 2f9f47d3f6c3e85..71fd8eca300c1b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -96,14 +96,18 @@ void 
MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
   this);
 
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxMemberCallExpr(
-   thisPointerType(getSmartPointerTypeMatcher()),
-   callee(cxxMethodDecl(hasName("reset"))),
-   hasArgument(0, cxxNewExpr(CanCallCtor, unless(IsPlacement))
-  .bind(NewExpression)),
-   unless(isInTemplateInstantiation()))
-   .bind(ResetCall)),
+  traverse(
+  TK_AsIs,
+  cxxMemberCallExpr(
+  unless(isInTemplateInstantiation()),
+  hasArgument(0, cxxNewExpr(CanCallCtor, unless(IsPlacement))
+ .bind(NewExpression)),
+  callee(cxxMethodDecl(hasName("reset"))),
+  anyOf(thisPointerType(getSmartPointerTypeMatcher()),
+on(ignoringImplicit(anyOf(
+hasType(getSmartPointerTypeMatcher()),
+hasType(pointsTo(getSmartPointerTypeMatcher(
+  .bind(ResetCall)),
   this);
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5ce38ab48bf295f..2a755e9b75aa739 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -331,6 +331,11 @@ Changes in existing checks
   iterators initialized by free functions like ``begin``, ``end``, or ``size``
   and avoid crash for array of dependent array.
 
+- Improved :doc:`modernize-make-shared
+  ` check to support
+  ``std::shared_ptr`` implementations that inherit the ``reset`` method from a
+  base class.
+
 - Improved :doc:`modernize-return-braced-init-list
   ` check to ignore
   false-positives when constructing the container with ``count`` copies of
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
index 0f4f2a97095b56f..337cb28228b09c4 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
@@ -1,24 +1,33 @@
 namespace std {
 
 template 
-class shared_ptr {
+class __shared_ptr {
+protected:
+  __shared_ptr();
+  __shared_ptr(type *ptr);
+  ~__shared_ptr();
 public:
-  shared_ptr();
-  shared_ptr(type *ptr);
-  shared_ptr(const shared_ptr &t) {}
-  shared_ptr(shared_ptr &&t) {}
-  ~shared_ptr();
   type &operator*() { return *ptr; }
   type *operator->() { return ptr; }
   type *release();
   void reset();
   void reset(type *pt);
-  shared_ptr &operator=(shared_ptr &&);
-  template 
-  shared_ptr &operator=(shared_ptr &&);
 
 private:
   type *ptr;
 };
 
+template 
+class shared_ptr : public __shared_ptr {
+public:
+  shared_ptr();
+  shared_ptr(type *ptr);
+  shared_ptr(const shared_ptr &t);
+  shared_ptr(shared_ptr &&t);
+  ~shared_ptr();
+  shared_ptr &operator=(shared_ptr &&);
+  template 
+  shared_ptr &operator=(shared_ptr &&);
+};
+
 }  // namespace std

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


[clang-tools-extra] [clang-tidy] Improve modernize-make-shared check (PR #70600)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Improved modernize-make-shared check to support
std::shared_ptr implementations that inherit the
reset method from a base class.
In GCC that class is called __shared_ptr.

Fixes #64481

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(+12-8) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
 (+18-9) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 2f9f47d3f6c3e85..71fd8eca300c1b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -96,14 +96,18 @@ void 
MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
   this);
 
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxMemberCallExpr(
-   thisPointerType(getSmartPointerTypeMatcher()),
-   callee(cxxMethodDecl(hasName("reset"))),
-   hasArgument(0, cxxNewExpr(CanCallCtor, unless(IsPlacement))
-  .bind(NewExpression)),
-   unless(isInTemplateInstantiation()))
-   .bind(ResetCall)),
+  traverse(
+  TK_AsIs,
+  cxxMemberCallExpr(
+  unless(isInTemplateInstantiation()),
+  hasArgument(0, cxxNewExpr(CanCallCtor, unless(IsPlacement))
+ .bind(NewExpression)),
+  callee(cxxMethodDecl(hasName("reset"))),
+  anyOf(thisPointerType(getSmartPointerTypeMatcher()),
+on(ignoringImplicit(anyOf(
+hasType(getSmartPointerTypeMatcher()),
+hasType(pointsTo(getSmartPointerTypeMatcher(
+  .bind(ResetCall)),
   this);
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5ce38ab48bf295f..2a755e9b75aa739 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -331,6 +331,11 @@ Changes in existing checks
   iterators initialized by free functions like ``begin``, ``end``, or ``size``
   and avoid crash for array of dependent array.
 
+- Improved :doc:`modernize-make-shared
+  ` check to support
+  ``std::shared_ptr`` implementations that inherit the ``reset`` method from a
+  base class.
+
 - Improved :doc:`modernize-return-braced-init-list
   ` check to ignore
   false-positives when constructing the container with ``count`` copies of
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
index 0f4f2a97095b56f..337cb28228b09c4 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
@@ -1,24 +1,33 @@
 namespace std {
 
 template 
-class shared_ptr {
+class __shared_ptr {
+protected:
+  __shared_ptr();
+  __shared_ptr(type *ptr);
+  ~__shared_ptr();
 public:
-  shared_ptr();
-  shared_ptr(type *ptr);
-  shared_ptr(const shared_ptr &t) {}
-  shared_ptr(shared_ptr &&t) {}
-  ~shared_ptr();
   type &operator*() { return *ptr; }
   type *operator->() { return ptr; }
   type *release();
   void reset();
   void reset(type *pt);
-  shared_ptr &operator=(shared_ptr &&);
-  template 
-  shared_ptr &operator=(shared_ptr &&);
 
 private:
   type *ptr;
 };
 
+template 
+class shared_ptr : public __shared_ptr {
+public:
+  shared_ptr();
+  shared_ptr(type *ptr);
+  shared_ptr(const shared_ptr &t);
+  shared_ptr(shared_ptr &&t);
+  ~shared_ptr();
+  shared_ptr &operator=(shared_ptr &&);
+  template 
+  shared_ptr &operator=(shared_ptr &&);
+};
+
 }  // namespace std

``




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


[clang] 91b9a66 - [clang-format][NFC] Reduce indent

2023-10-29 Thread via cfe-commits

Author: Björn Schäpers
Date: 2023-10-29T20:55:12+01:00
New Revision: 91b9a661c21891dc06e1721a26478d5bfe53e4ed

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

LOG: [clang-format][NFC] Reduce indent

By using if init statement.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 9ec8b93e39fd23a..aee966145b8e518 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2093,18 +2093,16 @@ class AnnotatingParser {
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
  tok::comma, tok::period, tok::arrow,
  tok::coloncolon, tok::kw_noexcept)) {
-if (FormatToken *AfterParen = Current.MatchingParen->Next) {
-  // Make sure this isn't the return type of an Obj-C block declaration
-  if (AfterParen->isNot(tok::caret)) {
-if (FormatToken *BeforeParen = Current.MatchingParen->Previous) {
-  if (BeforeParen->is(tok::identifier) &&
-  BeforeParen->isNot(TT_TypenameMacro) &&
-  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
-  (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration)) {
-Current.setType(TT_FunctionAnnotationRParen);
-  }
-}
+if (FormatToken *AfterParen = Current.MatchingParen->Next;
+AfterParen && AfterParen->isNot(tok::caret)) {
+  // Make sure this isn't the return type of an Obj-C block 
declaration.
+  if (FormatToken *BeforeParen = Current.MatchingParen->Previous;
+  BeforeParen && BeforeParen->is(tok::identifier) &&
+  BeforeParen->isNot(TT_TypenameMacro) &&
+  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
+  (!BeforeParen->Previous ||
+   BeforeParen->Previous->ClosesTemplateDeclaration)) {
+Current.setType(TT_FunctionAnnotationRParen);
   }
 }
   }



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


[clang] [clang-format][NFC] Reduce indent (PR #70583)

2023-10-29 Thread Björn Schäpers via cfe-commits

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


[clang] [clang-format] Fix annotating annotations after requires clause (PR #70602)

2023-10-29 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks created 
https://github.com/llvm/llvm-project/pull/70602

Fixes #69325.

From 9d3169cbd756f6c3ba9ac2a7e334677c330da3d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Sun, 29 Oct 2023 20:55:31 +0100
Subject: [PATCH] [clang-format] Fix annotating annotations after requires
 clause

Fixes #69325.
---
 clang/lib/Format/TokenAnnotator.cpp   |  3 ++-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index aee966145b8e518..729e7e370bf62ea 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2101,7 +2101,8 @@ class AnnotatingParser {
   BeforeParen->isNot(TT_TypenameMacro) &&
   BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
   (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration)) {
+   BeforeParen->Previous->ClosesTemplateDeclaration ||
+   BeforeParen->Previous->ClosesRequiresClause)) {
 Current.setType(TT_FunctionAnnotationRParen);
   }
 }
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index c16c7d64752458a..c9f1439e212b0ff 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1376,6 +1376,20 @@ TEST_F(TokenAnnotatorTest, 
RequiresDoesNotChangeParsingOfTheRest) {
 "}";
   RequiresTokenCount = 9;
   TestRequires(__LINE__);
+
+  BaseCode = "template\n"
+ "ANNOTATE(\"S\"\n"
+ " \"S\")\n"
+ "void foo();";
+  ConstrainedCode = "template\n"
+"  requires(true)\n"
+"ANNOTATE(\"S\"\n"
+" \"S\")\n"
+"void foo();";
+  BaseTokenCount = 16;
+  RequiresTokenCount = 4;
+  PrefixTokenCount = 5;
+  TestRequires(__LINE__);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsAsm) {

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


[clang] [clang-format] Fix annotating annotations after requires clause (PR #70602)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Björn Schäpers (HazardyKnusperkeks)


Changes

Fixes #69325.

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


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+2-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+14) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index aee966145b8e518..729e7e370bf62ea 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2101,7 +2101,8 @@ class AnnotatingParser {
   BeforeParen->isNot(TT_TypenameMacro) &&
   BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
   (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration)) {
+   BeforeParen->Previous->ClosesTemplateDeclaration ||
+   BeforeParen->Previous->ClosesRequiresClause)) {
 Current.setType(TT_FunctionAnnotationRParen);
   }
 }
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index c16c7d64752458a..c9f1439e212b0ff 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1376,6 +1376,20 @@ TEST_F(TokenAnnotatorTest, 
RequiresDoesNotChangeParsingOfTheRest) {
 "}";
   RequiresTokenCount = 9;
   TestRequires(__LINE__);
+
+  BaseCode = "template\n"
+ "ANNOTATE(\"S\"\n"
+ " \"S\")\n"
+ "void foo();";
+  ConstrainedCode = "template\n"
+"  requires(true)\n"
+"ANNOTATE(\"S\"\n"
+" \"S\")\n"
+"void foo();";
+  BaseTokenCount = 16;
+  RequiresTokenCount = 4;
+  PrefixTokenCount = 5;
+  TestRequires(__LINE__);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsAsm) {

``




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


[clang] [clang-format] Fix annotating annotations after requires clause (PR #70602)

2023-10-29 Thread Owen Pan via cfe-commits

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


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


[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke builders like 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/8/builds/761) that 
include `clang-tools-extra`.

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


[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread Nico Weber via cfe-commits

nico wrote:

This breaks building: http://45.33.8.238/linux/121901/step_4.txt

Please take a look and revert for now if it takes a while to fix.

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


[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-10-29 Thread Bill Wendling via cfe-commits

https://github.com/bwendling created 
https://github.com/llvm/llvm-project/pull/70606

Break down the counted_by calculations so that they correctly handle
anonymous structs, which are specified internally as IndirectFieldDecls.
Also simplify the code to use helper methods to get the field referenced
by counted_by and the flexible array member itself, which also had some
issues with FAMs in sub-structs.

>From 19dd7db8ab5f98a618c717944c96b34e604fbc30 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Sun, 29 Oct 2023 14:58:04 -0700
Subject: [PATCH] [CodeGen] Revamp counted_by calculations

Break down the counted_by calculations so that they correctly handle
anonymous structs, which are specified internally as IndirectFieldDecls.
Also simplify the code to use helper methods to get the field referenced
by counted_by and the flexible array member itself, which also had some
issues with FAMs in sub-structs.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 91 +++-
 clang/lib/CodeGen/CGExpr.cpp| 93 +++--
 clang/lib/CodeGen/CodeGenFunction.h | 12 +++-
 3 files changed, 134 insertions(+), 62 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index dce5ee5888c458e..acee2c1af1ab368 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,53 +859,60 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, 
unsigned Type,
   }
 
   if (IsDynamic) {
-LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-getLangOpts().getStrictFlexArraysLevel();
-const Expr *Base = E->IgnoreParenImpCasts();
-
-if (FieldDecl *FD = FindCountedByField(Base, StrictFlexArraysLevel)) {
-  const auto *ME = dyn_cast(Base);
-  llvm::Value *ObjectSize = nullptr;
-
-  if (!ME) {
-const auto *DRE = dyn_cast(Base);
-ValueDecl *VD = nullptr;
-
-ObjectSize = ConstantInt::get(
-ResType,
-getContext().getTypeSize(DRE->getType()->getPointeeType()) / 8,
-true);
-
-if (auto *RD = DRE->getType()->getPointeeType()->getAsRecordDecl())
-  VD = RD->getLastField();
-
-Expr *ICE = ImplicitCastExpr::Create(
-getContext(), DRE->getType(), CK_LValueToRValue,
-const_cast(cast(DRE)), nullptr, VK_PRValue,
-FPOptionsOverride());
-ME = MemberExpr::CreateImplicit(getContext(), ICE, true, VD,
-VD->getType(), VK_LValue, OK_Ordinary);
-  }
-
-  // At this point, we know that \p ME is a flexible array member.
-  const auto *ArrayTy = getContext().getAsArrayType(ME->getType());
+// The code generated here calculates the size of a struct with a flexible
+// array member that uses the counted_by attribute. There are two instances
+// we handle:
+//
+//   struct s {
+// unsigned long flags;
+// int count;
+// int array[] __attribute__((counted_by(count)));
+//   }
+//
+//   1) bdos of the flexible array itself:
+//
+// __builtin_dynamic_object_size(p->array, 1) ==
+// p->count * sizeof(*p->array)
+//
+//   2) bdos of the whole struct, including the flexible array:
+//
+// __builtin_dynamic_object_size(p, 1) ==
+//sizeof(*p) + p->count * sizeof(*p->array)
+//
+if (const ValueDecl *CountedByFD = FindCountedByField(E)) {
+  // Find the flexible array member.
+  const RecordDecl *OuterRD =
+CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
+  const ValueDecl *FAM = FindFlexibleArrayMemberField(getContext(),
+  OuterRD);
+
+  // Get the size of the flexible array member's base type.
+  const auto *ArrayTy = getContext().getAsArrayType(FAM->getType());
   unsigned Size = getContext().getTypeSize(ArrayTy->getElementType());
 
-  llvm::Value *CountField =
-  EmitAnyExprToTemp(MemberExpr::CreateImplicit(
-getContext(), const_cast(ME->getBase()),
-ME->isArrow(), FD, FD->getType(), VK_LValue,
-OK_Ordinary))
-  .getScalarVal();
+  // Find the outer struct expr (i.e. p in p->a.b.c.d).
+  Expr *CountedByExpr = BuildCountedByFieldExpr(const_cast(E),
+CountedByFD);
+
+  llvm::Value *CountedByInstr =
+EmitAnyExprToTemp(CountedByExpr).getScalarVal();
 
-  llvm::Value *Mul = Builder.CreateMul(
-  CountField, llvm::ConstantInt::get(CountField->getType(), Size / 8));
-  Mul = Builder.CreateZExtOrTrunc(Mul, ResType);
+  llvm::Constant *ArraySize =
+llvm::ConstantInt::get(CountedByInstr->getType(), Size / 8);
 
-  if (ObjectSize)
-return Builder.CreateAdd(ObjectSize, Mul);
+  llvm::Value *Ob

[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bill Wendling (bwendling)


Changes

Break down the counted_by calculations so that they correctly handle
anonymous structs, which are specified internally as IndirectFieldDecls.
Also simplify the code to use helper methods to get the field referenced
by counted_by and the flexible array member itself, which also had some
issues with FAMs in sub-structs.

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+49-42) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+76-17) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+9-3) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index dce5ee5888c458e..acee2c1af1ab368 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,53 +859,60 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, 
unsigned Type,
   }
 
   if (IsDynamic) {
-LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-getLangOpts().getStrictFlexArraysLevel();
-const Expr *Base = E->IgnoreParenImpCasts();
-
-if (FieldDecl *FD = FindCountedByField(Base, StrictFlexArraysLevel)) {
-  const auto *ME = dyn_cast(Base);
-  llvm::Value *ObjectSize = nullptr;
-
-  if (!ME) {
-const auto *DRE = dyn_cast(Base);
-ValueDecl *VD = nullptr;
-
-ObjectSize = ConstantInt::get(
-ResType,
-getContext().getTypeSize(DRE->getType()->getPointeeType()) / 8,
-true);
-
-if (auto *RD = DRE->getType()->getPointeeType()->getAsRecordDecl())
-  VD = RD->getLastField();
-
-Expr *ICE = ImplicitCastExpr::Create(
-getContext(), DRE->getType(), CK_LValueToRValue,
-const_cast(cast(DRE)), nullptr, VK_PRValue,
-FPOptionsOverride());
-ME = MemberExpr::CreateImplicit(getContext(), ICE, true, VD,
-VD->getType(), VK_LValue, OK_Ordinary);
-  }
-
-  // At this point, we know that \p ME is a flexible array member.
-  const auto *ArrayTy = getContext().getAsArrayType(ME->getType());
+// The code generated here calculates the size of a struct with a flexible
+// array member that uses the counted_by attribute. There are two instances
+// we handle:
+//
+//   struct s {
+// unsigned long flags;
+// int count;
+// int array[] __attribute__((counted_by(count)));
+//   }
+//
+//   1) bdos of the flexible array itself:
+//
+// __builtin_dynamic_object_size(p->array, 1) ==
+// p->count * sizeof(*p->array)
+//
+//   2) bdos of the whole struct, including the flexible array:
+//
+// __builtin_dynamic_object_size(p, 1) ==
+//sizeof(*p) + p->count * sizeof(*p->array)
+//
+if (const ValueDecl *CountedByFD = FindCountedByField(E)) {
+  // Find the flexible array member.
+  const RecordDecl *OuterRD =
+CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
+  const ValueDecl *FAM = FindFlexibleArrayMemberField(getContext(),
+  OuterRD);
+
+  // Get the size of the flexible array member's base type.
+  const auto *ArrayTy = getContext().getAsArrayType(FAM->getType());
   unsigned Size = getContext().getTypeSize(ArrayTy->getElementType());
 
-  llvm::Value *CountField =
-  EmitAnyExprToTemp(MemberExpr::CreateImplicit(
-getContext(), const_cast(ME->getBase()),
-ME->isArrow(), FD, FD->getType(), VK_LValue,
-OK_Ordinary))
-  .getScalarVal();
+  // Find the outer struct expr (i.e. p in p->a.b.c.d).
+  Expr *CountedByExpr = BuildCountedByFieldExpr(const_cast(E),
+CountedByFD);
+
+  llvm::Value *CountedByInstr =
+EmitAnyExprToTemp(CountedByExpr).getScalarVal();
 
-  llvm::Value *Mul = Builder.CreateMul(
-  CountField, llvm::ConstantInt::get(CountField->getType(), Size / 8));
-  Mul = Builder.CreateZExtOrTrunc(Mul, ResType);
+  llvm::Constant *ArraySize =
+llvm::ConstantInt::get(CountedByInstr->getType(), Size / 8);
 
-  if (ObjectSize)
-return Builder.CreateAdd(ObjectSize, Mul);
+  llvm::Value *ObjectSize = Builder.CreateMul(CountedByInstr, ArraySize);
+  ObjectSize = Builder.CreateZExtOrTrunc(ObjectSize, ResType);
+
+  if (const auto *DRE = dyn_cast(E->IgnoreImpCasts())) {
+// The whole struct is specificed in the __bdos.
+QualType StructTy = DRE->getType()->getPointeeType();
+llvm::Value *StructSize = ConstantInt::get(
+ResType, getContext().getTypeSize(StructTy) / 8, true);
+ObjectSize = Builder.CreateAdd(StructSize,

[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-10-29 Thread Bill Wendling via cfe-commits

bwendling wrote:

To answer @nickdesaulniers 's question, the testcases are in the works. :-)

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


[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-10-29 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 91b9a661c21891dc06e1721a26478d5bfe53e4ed 
19dd7db8ab5f98a618c717944c96b34e604fbc30 -- clang/lib/CodeGen/CGBuiltin.cpp 
clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CodeGenFunction.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index acee2c1af..26c73d07c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -882,23 +882,23 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, 
unsigned Type,
 if (const ValueDecl *CountedByFD = FindCountedByField(E)) {
   // Find the flexible array member.
   const RecordDecl *OuterRD =
-CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
-  const ValueDecl *FAM = FindFlexibleArrayMemberField(getContext(),
-  OuterRD);
+  CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
+  const ValueDecl *FAM =
+  FindFlexibleArrayMemberField(getContext(), OuterRD);
 
   // Get the size of the flexible array member's base type.
   const auto *ArrayTy = getContext().getAsArrayType(FAM->getType());
   unsigned Size = getContext().getTypeSize(ArrayTy->getElementType());
 
   // Find the outer struct expr (i.e. p in p->a.b.c.d).
-  Expr *CountedByExpr = BuildCountedByFieldExpr(const_cast(E),
-CountedByFD);
+  Expr *CountedByExpr =
+  BuildCountedByFieldExpr(const_cast(E), CountedByFD);
 
   llvm::Value *CountedByInstr =
-EmitAnyExprToTemp(CountedByExpr).getScalarVal();
+  EmitAnyExprToTemp(CountedByExpr).getScalarVal();
 
   llvm::Constant *ArraySize =
-llvm::ConstantInt::get(CountedByInstr->getType(), Size / 8);
+  llvm::ConstantInt::get(CountedByInstr->getType(), Size / 8);
 
   llvm::Value *ObjectSize = Builder.CreateMul(CountedByInstr, ArraySize);
   ObjectSize = Builder.CreateZExtOrTrunc(ObjectSize, ResType);
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 2b39194e1..b39cd8b45 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -976,9 +976,9 @@ Expr *CodeGenFunction::BuildCountedByFieldExpr(Expr *Base,
 }
 
   // Add back an implicit cast to create the required pr-value.
-  Base = ImplicitCastExpr::Create(
-  getContext(), Base->getType(), CK_LValueToRValue, Base,
-  nullptr, VK_PRValue, FPOptionsOverride());
+  Base =
+  ImplicitCastExpr::Create(getContext(), Base->getType(), 
CK_LValueToRValue,
+   Base, nullptr, VK_PRValue, FPOptionsOverride());
 
   Expr *CountedByExpr = Base;
 
@@ -988,24 +988,24 @@ Expr *CodeGenFunction::BuildCountedByFieldExpr(Expr *Base,
 // easily. (Yay!)
 for (NamedDecl *ND : IFD->chain()) {
   ValueDecl *VD = cast(ND);
-  CountedByExpr = MemberExpr::CreateImplicit(
-  getContext(), CountedByExpr,
-  CountedByExpr->getType()->isPointerType(), VD, VD->getType(),
-  VK_LValue, OK_Ordinary);
+  CountedByExpr =
+  MemberExpr::CreateImplicit(getContext(), CountedByExpr,
+ CountedByExpr->getType()->isPointerType(),
+ VD, VD->getType(), VK_LValue, 
OK_Ordinary);
 }
   } else {
 CountedByExpr = MemberExpr::CreateImplicit(
-getContext(), CountedByExpr,
-CountedByExpr->getType()->isPointerType(),
-const_cast(CountedByVD), CountedByVD->getType(),
-VK_LValue, OK_Ordinary);
+getContext(), CountedByExpr, CountedByExpr->getType()->isPointerType(),
+const_cast(CountedByVD), CountedByVD->getType(), 
VK_LValue,
+OK_Ordinary);
   }
 
   return CountedByExpr;
 }
 
-const ValueDecl *CodeGenFunction::FindFlexibleArrayMemberField(
-ASTContext &Ctx, const RecordDecl *RD) {
+const ValueDecl *
+CodeGenFunction::FindFlexibleArrayMemberField(ASTContext &Ctx,
+  const RecordDecl *RD) {
   LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
 

``




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


[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

2023-10-29 Thread Bill Wendling via cfe-commits

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

>From 19dd7db8ab5f98a618c717944c96b34e604fbc30 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Sun, 29 Oct 2023 14:58:04 -0700
Subject: [PATCH 1/2] [CodeGen] Revamp counted_by calculations

Break down the counted_by calculations so that they correctly handle
anonymous structs, which are specified internally as IndirectFieldDecls.
Also simplify the code to use helper methods to get the field referenced
by counted_by and the flexible array member itself, which also had some
issues with FAMs in sub-structs.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 91 +++-
 clang/lib/CodeGen/CGExpr.cpp| 93 +++--
 clang/lib/CodeGen/CodeGenFunction.h | 12 +++-
 3 files changed, 134 insertions(+), 62 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index dce5ee5888c458e..acee2c1af1ab368 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -859,53 +859,60 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, 
unsigned Type,
   }
 
   if (IsDynamic) {
-LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-getLangOpts().getStrictFlexArraysLevel();
-const Expr *Base = E->IgnoreParenImpCasts();
-
-if (FieldDecl *FD = FindCountedByField(Base, StrictFlexArraysLevel)) {
-  const auto *ME = dyn_cast(Base);
-  llvm::Value *ObjectSize = nullptr;
-
-  if (!ME) {
-const auto *DRE = dyn_cast(Base);
-ValueDecl *VD = nullptr;
-
-ObjectSize = ConstantInt::get(
-ResType,
-getContext().getTypeSize(DRE->getType()->getPointeeType()) / 8,
-true);
-
-if (auto *RD = DRE->getType()->getPointeeType()->getAsRecordDecl())
-  VD = RD->getLastField();
-
-Expr *ICE = ImplicitCastExpr::Create(
-getContext(), DRE->getType(), CK_LValueToRValue,
-const_cast(cast(DRE)), nullptr, VK_PRValue,
-FPOptionsOverride());
-ME = MemberExpr::CreateImplicit(getContext(), ICE, true, VD,
-VD->getType(), VK_LValue, OK_Ordinary);
-  }
-
-  // At this point, we know that \p ME is a flexible array member.
-  const auto *ArrayTy = getContext().getAsArrayType(ME->getType());
+// The code generated here calculates the size of a struct with a flexible
+// array member that uses the counted_by attribute. There are two instances
+// we handle:
+//
+//   struct s {
+// unsigned long flags;
+// int count;
+// int array[] __attribute__((counted_by(count)));
+//   }
+//
+//   1) bdos of the flexible array itself:
+//
+// __builtin_dynamic_object_size(p->array, 1) ==
+// p->count * sizeof(*p->array)
+//
+//   2) bdos of the whole struct, including the flexible array:
+//
+// __builtin_dynamic_object_size(p, 1) ==
+//sizeof(*p) + p->count * sizeof(*p->array)
+//
+if (const ValueDecl *CountedByFD = FindCountedByField(E)) {
+  // Find the flexible array member.
+  const RecordDecl *OuterRD =
+CountedByFD->getDeclContext()->getOuterLexicalRecordContext();
+  const ValueDecl *FAM = FindFlexibleArrayMemberField(getContext(),
+  OuterRD);
+
+  // Get the size of the flexible array member's base type.
+  const auto *ArrayTy = getContext().getAsArrayType(FAM->getType());
   unsigned Size = getContext().getTypeSize(ArrayTy->getElementType());
 
-  llvm::Value *CountField =
-  EmitAnyExprToTemp(MemberExpr::CreateImplicit(
-getContext(), const_cast(ME->getBase()),
-ME->isArrow(), FD, FD->getType(), VK_LValue,
-OK_Ordinary))
-  .getScalarVal();
+  // Find the outer struct expr (i.e. p in p->a.b.c.d).
+  Expr *CountedByExpr = BuildCountedByFieldExpr(const_cast(E),
+CountedByFD);
+
+  llvm::Value *CountedByInstr =
+EmitAnyExprToTemp(CountedByExpr).getScalarVal();
 
-  llvm::Value *Mul = Builder.CreateMul(
-  CountField, llvm::ConstantInt::get(CountField->getType(), Size / 8));
-  Mul = Builder.CreateZExtOrTrunc(Mul, ResType);
+  llvm::Constant *ArraySize =
+llvm::ConstantInt::get(CountedByInstr->getType(), Size / 8);
 
-  if (ObjectSize)
-return Builder.CreateAdd(ObjectSize, Mul);
+  llvm::Value *ObjectSize = Builder.CreateMul(CountedByInstr, ArraySize);
+  ObjectSize = Builder.CreateZExtOrTrunc(ObjectSize, ResType);
+
+  if (const auto *DRE = dyn_cast(E->IgnoreImpCasts())) {
+// The whole struct is specificed in the __bdos.
+QualType StructTy = DRE->getType()->getPointeeType();
+  

[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70593

>From 0933677259d446875c25898383c1c206b0c6efd8 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 29 Oct 2023 09:02:12 -0400
Subject: [PATCH] [OpenMP] Add support for Solaris

Tested on `amd64-pc-solaris2.11`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp |  5 +
 clang/test/Driver/fopenmp.c | 19 ++-
 openmp/runtime/src/kmp.h|  8 ++--
 openmp/runtime/src/kmp_ftn_entry.h  |  2 +-
 openmp/runtime/src/kmp_platform.h   | 11 +--
 openmp/runtime/src/kmp_runtime.cpp  |  8 +---
 openmp/runtime/src/z_Linux_util.cpp | 20 +++-
 7 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..958ed99c482ed22 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
+// Use the static OpenMP runtime with -static-openmp
+bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
+!Args.hasArg(options::OPT_static);
+addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index cf04340ebc06ac6..291946923b3ea3d 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -16,6 +16,9 @@
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
 //
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
+//
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP 
--check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static 
-static-openmp %s -o %t -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
+//
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
+//
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LD-OMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
 // RUN: %clang -target x86_64-w

[clang] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

2023-10-29 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/70567

>From ba6c43cc63e9ae3c8d174406ced4df839af3e0a7 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Fri, 27 Oct 2023 16:37:40 -0700
Subject: [PATCH 1/3] [Clang] Coroutines: warn against unused parameters in C++
 coroutines with -Wunused-parameters

---
 clang/include/clang/AST/DeclBase.h| 18 +++-
 clang/lib/Sema/SemaCoroutine.cpp  |  6 
 clang/lib/Sema/SemaDecl.cpp   |  5 +++-
 .../warn-unused-parameters-coroutine.cpp  | 28 +++
 4 files changed, 55 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 978e4255e877ec2..dc78ee37d16bea2 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -306,6 +306,11 @@ class alignas(8) Decl {
   /// are regarded as "referenced" but not "used".
   unsigned Referenced : 1;
 
+  /// Whether the last reference to this declaration happened in Coroutine
+  /// Parameter moves. Otherwise the reference caused by such moves would
+  /// prevent a warning against unused parameters in all coroutines.
+  unsigned LastReferenceInCoroutineParamMoves : 1;
+
   /// Whether this declaration is a top-level declaration (function,
   /// global variable, etc.) that is lexically inside an objc container
   /// definition.
@@ -609,11 +614,22 @@ class alignas(8) Decl {
   /// Whether any declaration of this entity was referenced.
   bool isReferenced() const;
 
+  bool isLastReferenceInCoroutineParamMoves() const {
+return LastReferenceInCoroutineParamMoves;
+  }
+
+  void setLastReferenceInCoroutineParamMoves(bool V = true) {
+LastReferenceInCoroutineParamMoves = true;
+  }
+
   /// Whether this declaration was referenced. This should not be relied
   /// upon for anything other than debugging.
   bool isThisDeclarationReferenced() const { return Referenced; }
 
-  void setReferenced(bool R = true) { Referenced = R; }
+  void setReferenced(bool R = true) {
+Referenced = R;
+LastReferenceInCoroutineParamMoves = false;
+  }
 
   /// Whether this declaration is a top-level declaration (function,
   /// global variable, etc.) that is lexically inside an objc container
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index cfaa93fbea4dd37..2936c39941e2922 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1964,9 +1964,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+bool PDRefBefore = PD->isReferenced();
+
 ExprResult PDRefExpr =
 BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(),
  ExprValueKind::VK_LValue, Loc); // FIXME: scope?
+
+if (!PDRefBefore)
+  PD->setLastReferenceInCoroutineParamMoves();
+
 if (PDRefExpr.isInvalid())
   return false;
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c4979b51e68f5e2..06487d3595de557 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15089,7 +15089,10 @@ void 
Sema::DiagnoseUnusedParameters(ArrayRef Parameters) {
 return;
 
   for (const ParmVarDecl *Parameter : Parameters) {
-if (!Parameter->isReferenced() && Parameter->getDeclName() &&
+if (Parameter->isReferenced() && 
!Parameter->isLastReferenceInCoroutineParamMoves())
+  continue;
+
+if (Parameter->getDeclName() &&
 !Parameter->hasAttr() &&
 !Parameter->getIdentifier()->isPlaceholder()) {
   Diag(Parameter->getLocation(), diag::warn_unused_parameter)
diff --git a/clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp 
b/clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp
new file mode 100644
index 000..0fd26ea4a21be79
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify -std=c++20 %s
+
+#include "Inputs/std-coroutine.h"
+
+struct awaitable {
+  bool await_ready() noexcept;
+  void await_resume() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+};
+
+struct task : awaitable {
+  struct promise_type {
+task get_return_object() noexcept;
+awaitable initial_suspend() noexcept;
+awaitable final_suspend() noexcept;
+void unhandled_exception() noexcept;
+void return_void() noexcept;
+  };
+};
+
+task foo(int a) { // expected-warning{{unused parameter 'a'}}
+  co_return;
+}
+
+task bar(int a, int b) { // expected-warning{{unused parameter 'b'}}
+  a = a + 1;
+  co_return;
+}

>From fe7109f18286b8ba7e3e44f1fb31fc60e1ad8422 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Sat, 28 Oct 2023 12:42:01 -0700
Subject: [PATCH 2/3] fix small bug: setLastReferenceInCoroutineParamMoves
 should respect pa

[clang] [OpenMP][Clang] Force use of `num_teams` and `thread_limit` for bare kernel (PR #68373)

2023-10-29 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/68373

>From d0d8bcc9fa002304ef79ca48d736853ca621c0bd Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Sun, 29 Oct 2023 19:17:19 -0400
Subject: [PATCH] [OpenMP][Clang] Force use of `num_teams` and `thread_limit`
 for bare kernel

This patch makes `num_teams` and `thread_limit` mandatory for bare kernels,
similar to a reguar kernel language that when launching a kernel, the grid size
has to be set explicitly.
---
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/lib/Sema/SemaOpenMP.cpp |  20 ++
 clang/test/OpenMP/ompx_bare_messages.c|   7 +-
 clang/test/OpenMP/target_teams_codegen.cpp| 230 +-
 4 files changed, 146 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 453bd8a9a340425..d1398763b49c701 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11333,6 +11333,8 @@ def err_openmp_vla_in_task_untied : Error<
 def warn_omp_unterminated_declare_target : Warning<
   "expected '#pragma omp end declare target' at end of file to match '#pragma 
omp %0'">,
   InGroup;
+def err_ompx_bare_no_grid : Error<
+  "'ompx_bare' clauses requires explicit grid size via 'num_teams' and 
'thread_limit' clauses">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 75f9e152dca9297..90a0d1f70f268f1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14633,6 +14633,26 @@ StmtResult 
Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef Clauses,
   }
   setFunctionHasBranchProtectedScope();
 
+  bool HasBareClause = false;
+  bool HasThreadLimitClause = false;
+  bool HasNumTeamsClause = false;
+  OMPClause *BareClause = nullptr;
+
+  for (auto *C : Clauses) {
+if (isa(C)) {
+  BareClause = C;
+  HasBareClause = true;
+} else if (isa(C))
+  HasNumTeamsClause = true;
+else if (isa(C))
+  HasThreadLimitClause = true;
+  }
+
+  if (HasBareClause && !(HasNumTeamsClause && HasThreadLimitClause)) {
+Diag(BareClause->getBeginLoc(), diag::err_ompx_bare_no_grid);
+return StmtError();
+  }
+
   return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses,
  AStmt);
 }
diff --git a/clang/test/OpenMP/ompx_bare_messages.c 
b/clang/test/OpenMP/ompx_bare_messages.c
index a1b3c380285287d..19ceee5625feecc 100644
--- a/clang/test/OpenMP/ompx_bare_messages.c
+++ b/clang/test/OpenMP/ompx_bare_messages.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
 
 void foo() {
 }
@@ -18,4 +18,7 @@ void bar() {
 #pragma omp target
 #pragma omp teams ompx_bare // expected-error {{unexpected OpenMP clause 
'ompx_bare' in directive '#pragma omp teams'}} expected-note {{OpenMP extension 
clause 'ompx_bare' only allowed with '#pragma omp target teams'}}
   foo();
+
+#pragma omp target teams ompx_bare // expected-error {{'ompx_bare' clauses 
requires explicit grid size via 'num_teams' and 'thread_limit' clauses}}
+  foo();
 }
diff --git a/clang/test/OpenMP/target_teams_codegen.cpp 
b/clang/test/OpenMP/target_teams_codegen.cpp
index 9ee1f74e8fdc468..95182c668c5e822 100644
--- a/clang/test/OpenMP/target_teams_codegen.cpp
+++ b/clang/test/OpenMP/target_teams_codegen.cpp
@@ -121,7 +121,7 @@ int foo(int n) {
 aa += 1;
   }
 
-  #pragma omp target teams ompx_bare
+  #pragma omp target teams ompx_bare num_teams(1) thread_limit(1)
   {
 a += 1;
 aa += 1;
@@ -588,12 +588,12 @@ int bar(int n){
 // CHECK1-NEXT:[[TMP116:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 9
 // CHECK1-NEXT:store i64 0, ptr [[TMP116]], align 8
 // CHECK1-NEXT:[[TMP117:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 10
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP117]], align 4
+// CHECK1-NEXT:store [3 x i32] [i32 1, i32 0, i32 0], ptr [[TMP117]], 
align 4
 // CHECK1-NEXT:[[TMP118:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 11
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP118]], align 4
+// CHECK1-NEXT:store [3 x i32] [i32 1, i32 0, i32 0], ptr [[TMP118]], 
align 4
 // CHECK1-NEXT:[[TMP119:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL

[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70593

>From e4482f4e77f8ed3de5e3aedbfb8662f2deccef2b Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 29 Oct 2023 09:02:12 -0400
Subject: [PATCH] [OpenMP] Add support for Solaris

Tested on `amd64-pc-solaris2.11`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp |  5 +
 clang/test/Driver/fopenmp.c | 19 ++-
 openmp/runtime/src/kmp.h|  8 ++--
 openmp/runtime/src/kmp_ftn_entry.h  |  2 +-
 openmp/runtime/src/kmp_platform.h   | 11 +--
 openmp/runtime/src/kmp_runtime.cpp  |  8 +---
 openmp/runtime/src/z_Linux_util.cpp | 21 -
 7 files changed, 60 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..958ed99c482ed22 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
+// Use the static OpenMP runtime with -static-openmp
+bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
+!Args.hasArg(options::OPT_static);
+addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index cf04340ebc06ac6..291946923b3ea3d 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -16,6 +16,9 @@
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
 //
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
+//
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP 
--check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static 
-static-openmp %s -o %t -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
+//
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
+//
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LD-OMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
 // RUN: %clang -target x86_64-

[clang] no default grid size (PR #70612)

2023-10-29 Thread Shilei Tian via cfe-commits

https://github.com/shiltian created 
https://github.com/llvm/llvm-project/pull/70612

- [OpenMP][Clang] Force use of `num_teams` and `thread_limit` for bare kernel
- [OpenMP] Directly use user's grid and block size in kernel language mode


>From 7b0eaa1606ad2e557105fed9509c135f857db375 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Sun, 29 Oct 2023 19:18:49 -0400
Subject: [PATCH 1/2] [OpenMP][Clang] Force use of `num_teams` and
 `thread_limit` for bare kernel

This patch makes `num_teams` and `thread_limit` mandatory for bare kernels,
similar to a reguar kernel language that when launching a kernel, the grid size
has to be set explicitly.
---
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/lib/Sema/SemaOpenMP.cpp |  20 ++
 clang/test/OpenMP/ompx_bare_messages.c|   7 +-
 clang/test/OpenMP/target_teams_codegen.cpp| 230 +-
 4 files changed, 146 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 453bd8a9a340425..d1398763b49c701 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11333,6 +11333,8 @@ def err_openmp_vla_in_task_untied : Error<
 def warn_omp_unterminated_declare_target : Warning<
   "expected '#pragma omp end declare target' at end of file to match '#pragma 
omp %0'">,
   InGroup;
+def err_ompx_bare_no_grid : Error<
+  "'ompx_bare' clauses requires explicit grid size via 'num_teams' and 
'thread_limit' clauses">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 75f9e152dca9297..90a0d1f70f268f1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14633,6 +14633,26 @@ StmtResult 
Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef Clauses,
   }
   setFunctionHasBranchProtectedScope();
 
+  bool HasBareClause = false;
+  bool HasThreadLimitClause = false;
+  bool HasNumTeamsClause = false;
+  OMPClause *BareClause = nullptr;
+
+  for (auto *C : Clauses) {
+if (isa(C)) {
+  BareClause = C;
+  HasBareClause = true;
+} else if (isa(C))
+  HasNumTeamsClause = true;
+else if (isa(C))
+  HasThreadLimitClause = true;
+  }
+
+  if (HasBareClause && !(HasNumTeamsClause && HasThreadLimitClause)) {
+Diag(BareClause->getBeginLoc(), diag::err_ompx_bare_no_grid);
+return StmtError();
+  }
+
   return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses,
  AStmt);
 }
diff --git a/clang/test/OpenMP/ompx_bare_messages.c 
b/clang/test/OpenMP/ompx_bare_messages.c
index a1b3c380285287d..19ceee5625feecc 100644
--- a/clang/test/OpenMP/ompx_bare_messages.c
+++ b/clang/test/OpenMP/ompx_bare_messages.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
 
 void foo() {
 }
@@ -18,4 +18,7 @@ void bar() {
 #pragma omp target
 #pragma omp teams ompx_bare // expected-error {{unexpected OpenMP clause 
'ompx_bare' in directive '#pragma omp teams'}} expected-note {{OpenMP extension 
clause 'ompx_bare' only allowed with '#pragma omp target teams'}}
   foo();
+
+#pragma omp target teams ompx_bare // expected-error {{'ompx_bare' clauses 
requires explicit grid size via 'num_teams' and 'thread_limit' clauses}}
+  foo();
 }
diff --git a/clang/test/OpenMP/target_teams_codegen.cpp 
b/clang/test/OpenMP/target_teams_codegen.cpp
index 9ee1f74e8fdc468..95182c668c5e822 100644
--- a/clang/test/OpenMP/target_teams_codegen.cpp
+++ b/clang/test/OpenMP/target_teams_codegen.cpp
@@ -121,7 +121,7 @@ int foo(int n) {
 aa += 1;
   }
 
-  #pragma omp target teams ompx_bare
+  #pragma omp target teams ompx_bare num_teams(1) thread_limit(1)
   {
 a += 1;
 aa += 1;
@@ -588,12 +588,12 @@ int bar(int n){
 // CHECK1-NEXT:[[TMP116:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 9
 // CHECK1-NEXT:store i64 0, ptr [[TMP116]], align 8
 // CHECK1-NEXT:[[TMP117:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 10
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP117]], align 4
+// CHECK1-NEXT:store [3 x i32] [i32 1, i32 0, i32 0], ptr [[TMP117]], 
align 4
 // CHECK1-NEXT:[[TMP118:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 11
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP118]], align 4
+// CHECK1-NEXT:store [3 x i3

[clang] [OpenMP] Directly use user's grid and block size in kernel language mode (PR #70612)

2023-10-29 Thread Shilei Tian via cfe-commits

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


[clang] [OpenMP] Directly use user's grid and block size in kernel language mode (PR #70612)

2023-10-29 Thread Shilei Tian via cfe-commits

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


[clang] [OpenMP] Directly use user's grid and block size in kernel language mode (PR #70612)

2023-10-29 Thread Shilei Tian via cfe-commits

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


[clang] [OpenMP] Directly use user's grid and block size in kernel language mode (PR #70612)

2023-10-29 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/70612

>From 7b0eaa1606ad2e557105fed9509c135f857db375 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Sun, 29 Oct 2023 19:18:49 -0400
Subject: [PATCH 1/2] [OpenMP][Clang] Force use of `num_teams` and
 `thread_limit` for bare kernel

This patch makes `num_teams` and `thread_limit` mandatory for bare kernels,
similar to a reguar kernel language that when launching a kernel, the grid size
has to be set explicitly.
---
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/lib/Sema/SemaOpenMP.cpp |  20 ++
 clang/test/OpenMP/ompx_bare_messages.c|   7 +-
 clang/test/OpenMP/target_teams_codegen.cpp| 230 +-
 4 files changed, 146 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 453bd8a9a340425..d1398763b49c701 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11333,6 +11333,8 @@ def err_openmp_vla_in_task_untied : Error<
 def warn_omp_unterminated_declare_target : Warning<
   "expected '#pragma omp end declare target' at end of file to match '#pragma 
omp %0'">,
   InGroup;
+def err_ompx_bare_no_grid : Error<
+  "'ompx_bare' clauses requires explicit grid size via 'num_teams' and 
'thread_limit' clauses">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 75f9e152dca9297..90a0d1f70f268f1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14633,6 +14633,26 @@ StmtResult 
Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef Clauses,
   }
   setFunctionHasBranchProtectedScope();
 
+  bool HasBareClause = false;
+  bool HasThreadLimitClause = false;
+  bool HasNumTeamsClause = false;
+  OMPClause *BareClause = nullptr;
+
+  for (auto *C : Clauses) {
+if (isa(C)) {
+  BareClause = C;
+  HasBareClause = true;
+} else if (isa(C))
+  HasNumTeamsClause = true;
+else if (isa(C))
+  HasThreadLimitClause = true;
+  }
+
+  if (HasBareClause && !(HasNumTeamsClause && HasThreadLimitClause)) {
+Diag(BareClause->getBeginLoc(), diag::err_ompx_bare_no_grid);
+return StmtError();
+  }
+
   return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses,
  AStmt);
 }
diff --git a/clang/test/OpenMP/ompx_bare_messages.c 
b/clang/test/OpenMP/ompx_bare_messages.c
index a1b3c380285287d..19ceee5625feecc 100644
--- a/clang/test/OpenMP/ompx_bare_messages.c
+++ b/clang/test/OpenMP/ompx_bare_messages.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
 
 void foo() {
 }
@@ -18,4 +18,7 @@ void bar() {
 #pragma omp target
 #pragma omp teams ompx_bare // expected-error {{unexpected OpenMP clause 
'ompx_bare' in directive '#pragma omp teams'}} expected-note {{OpenMP extension 
clause 'ompx_bare' only allowed with '#pragma omp target teams'}}
   foo();
+
+#pragma omp target teams ompx_bare // expected-error {{'ompx_bare' clauses 
requires explicit grid size via 'num_teams' and 'thread_limit' clauses}}
+  foo();
 }
diff --git a/clang/test/OpenMP/target_teams_codegen.cpp 
b/clang/test/OpenMP/target_teams_codegen.cpp
index 9ee1f74e8fdc468..95182c668c5e822 100644
--- a/clang/test/OpenMP/target_teams_codegen.cpp
+++ b/clang/test/OpenMP/target_teams_codegen.cpp
@@ -121,7 +121,7 @@ int foo(int n) {
 aa += 1;
   }
 
-  #pragma omp target teams ompx_bare
+  #pragma omp target teams ompx_bare num_teams(1) thread_limit(1)
   {
 a += 1;
 aa += 1;
@@ -588,12 +588,12 @@ int bar(int n){
 // CHECK1-NEXT:[[TMP116:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 9
 // CHECK1-NEXT:store i64 0, ptr [[TMP116]], align 8
 // CHECK1-NEXT:[[TMP117:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 10
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP117]], align 4
+// CHECK1-NEXT:store [3 x i32] [i32 1, i32 0, i32 0], ptr [[TMP117]], 
align 4
 // CHECK1-NEXT:[[TMP118:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 11
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP118]], align 4
+// CHECK1-NEXT:store [3 x i32] [i32 1, i32 0, i32 0], ptr [[TMP118]], 
align 4
 // CHECK1-NEXT:[[TMP119:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KE

[clang] [OpenMP] Directly use user's grid and block size in kernel language mode (PR #70612)

2023-10-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shilei Tian (shiltian)


Changes

In kernel language mode, use user's grid and blocks size directly. No validity
check, which means if user's values are too large, the launch will fail, similar
to what CUDA and HIP are doing right now.

Depends on #68373.

---

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


6 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+20) 
- (modified) clang/test/OpenMP/ompx_bare_messages.c (+5-2) 
- (modified) clang/test/OpenMP/target_teams_codegen.cpp (+119-111) 
- (modified) 
openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp 
(+8) 
- (modified) 
openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h 
(+3) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 453bd8a9a340425..d1398763b49c701 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11333,6 +11333,8 @@ def err_openmp_vla_in_task_untied : Error<
 def warn_omp_unterminated_declare_target : Warning<
   "expected '#pragma omp end declare target' at end of file to match '#pragma 
omp %0'">,
   InGroup;
+def err_ompx_bare_no_grid : Error<
+  "'ompx_bare' clauses requires explicit grid size via 'num_teams' and 
'thread_limit' clauses">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 75f9e152dca9297..90a0d1f70f268f1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14633,6 +14633,26 @@ StmtResult 
Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef Clauses,
   }
   setFunctionHasBranchProtectedScope();
 
+  bool HasBareClause = false;
+  bool HasThreadLimitClause = false;
+  bool HasNumTeamsClause = false;
+  OMPClause *BareClause = nullptr;
+
+  for (auto *C : Clauses) {
+if (isa(C)) {
+  BareClause = C;
+  HasBareClause = true;
+} else if (isa(C))
+  HasNumTeamsClause = true;
+else if (isa(C))
+  HasThreadLimitClause = true;
+  }
+
+  if (HasBareClause && !(HasNumTeamsClause && HasThreadLimitClause)) {
+Diag(BareClause->getBeginLoc(), diag::err_ompx_bare_no_grid);
+return StmtError();
+  }
+
   return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses,
  AStmt);
 }
diff --git a/clang/test/OpenMP/ompx_bare_messages.c 
b/clang/test/OpenMP/ompx_bare_messages.c
index a1b3c380285287d..19ceee5625feecc 100644
--- a/clang/test/OpenMP/ompx_bare_messages.c
+++ b/clang/test/OpenMP/ompx_bare_messages.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
- // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown 
-fopenmp-targets=nvptx64 %s
 
 void foo() {
 }
@@ -18,4 +18,7 @@ void bar() {
 #pragma omp target
 #pragma omp teams ompx_bare // expected-error {{unexpected OpenMP clause 
'ompx_bare' in directive '#pragma omp teams'}} expected-note {{OpenMP extension 
clause 'ompx_bare' only allowed with '#pragma omp target teams'}}
   foo();
+
+#pragma omp target teams ompx_bare // expected-error {{'ompx_bare' clauses 
requires explicit grid size via 'num_teams' and 'thread_limit' clauses}}
+  foo();
 }
diff --git a/clang/test/OpenMP/target_teams_codegen.cpp 
b/clang/test/OpenMP/target_teams_codegen.cpp
index 9ee1f74e8fdc468..95182c668c5e822 100644
--- a/clang/test/OpenMP/target_teams_codegen.cpp
+++ b/clang/test/OpenMP/target_teams_codegen.cpp
@@ -121,7 +121,7 @@ int foo(int n) {
 aa += 1;
   }
 
-  #pragma omp target teams ompx_bare
+  #pragma omp target teams ompx_bare num_teams(1) thread_limit(1)
   {
 a += 1;
 aa += 1;
@@ -588,12 +588,12 @@ int bar(int n){
 // CHECK1-NEXT:[[TMP116:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 9
 // CHECK1-NEXT:store i64 0, ptr [[TMP116]], align 8
 // CHECK1-NEXT:[[TMP117:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 10
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP117]], align 4
+// CHECK1-NEXT:store [3 x i32] [i32 1, i32 0, i32 0], ptr [[TMP117]], 
align 4
 // CHECK1-NEXT:[[TMP118:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS21]], i32 0, i32 11
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP118]], align 4
+// CHECK1-NEXT:store [3 x i32] [i32 1, i32 0, i32 0], ptr [[

[PATCH] D154396: [clang] Add support for SerenityOS

2023-10-29 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster added a comment.

@MaskRay @phosek Daniel and I have updated the patch set,  Would you rather I 
update the phab patch series, or re-upload the set as GitHub PRs?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[clang] 1c876ff - Revert "Perf/lexer faster slow get char and size (#70543)"

2023-10-29 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-10-29T21:11:39-04:00
New Revision: 1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4

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

LOG: Revert "Perf/lexer faster slow get char and size (#70543)"

This reverts commit d8f5a18b6e587aeaa8b99707e87b652f49b160cd.
Breaks build, see:
https://github.com/llvm/llvm-project/pull/70543#issuecomment-1784227421

Added: 


Modified: 
clang/include/clang/Lex/Lexer.h
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Lex/Lexer.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h
index 899e665e7454652..ac0ef14c591bdd7 100644
--- a/clang/include/clang/Lex/Lexer.h
+++ b/clang/include/clang/Lex/Lexer.h
@@ -575,23 +575,19 @@ class Lexer : public PreprocessorLexer {
   /// sequence.
   static bool isNewLineEscaped(const char *BufferStart, const char *Str);
 
-  /// Represents a char and the number of bytes parsed to produce it.
-  struct SizedChar {
-char Char;
-unsigned Size;
-  };
-
   /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever
   /// emit a warning.
-  static inline SizedChar getCharAndSizeNoWarn(const char *Ptr,
-   const LangOptions &LangOpts) {
+  static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size,
+  const LangOptions &LangOpts) {
 // If this is not a trigraph and not a UCN or escaped newline, return
 // quickly.
 if (isObviouslySimpleCharacter(Ptr[0])) {
-  return {*Ptr, 1u};
+  Size = 1;
+  return *Ptr;
 }
 
-return getCharAndSizeSlowNoWarn(Ptr, LangOpts);
+Size = 0;
+return getCharAndSizeSlowNoWarn(Ptr, Size, LangOpts);
   }
 
   /// Returns the leading whitespace for line that corresponds to the given
@@ -669,7 +665,8 @@ class Lexer : public PreprocessorLexer {
 // quickly.
 if (isObviouslySimpleCharacter(Ptr[0])) return *Ptr++;
 
-auto [C, Size] = getCharAndSizeSlow(Ptr, &Tok);
+unsigned Size = 0;
+char C = getCharAndSizeSlow(Ptr, Size, &Tok);
 Ptr += Size;
 return C;
   }
@@ -685,7 +682,9 @@ class Lexer : public PreprocessorLexer {
 
 // Otherwise, re-lex the character with a current token, allowing
 // diagnostics to be emitted and flags to be set.
-return Ptr + getCharAndSizeSlow(Ptr, &Tok).Size;
+Size = 0;
+getCharAndSizeSlow(Ptr, Size, &Tok);
+return Ptr+Size;
   }
 
   /// getCharAndSize - Peek a single 'character' from the specified buffer,
@@ -700,14 +699,14 @@ class Lexer : public PreprocessorLexer {
   return *Ptr;
 }
 
-auto CharAndSize = getCharAndSizeSlow(Ptr);
-Size = CharAndSize.Size;
-return CharAndSize.Char;
+Size = 0;
+return getCharAndSizeSlow(Ptr, Size);
   }
 
   /// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize
   /// method.
-  SizedChar getCharAndSizeSlow(const char *Ptr, Token *Tok = nullptr);
+  char getCharAndSizeSlow(const char *Ptr, unsigned &Size,
+  Token *Tok = nullptr);
 
   /// getEscapedNewLineSize - Return the size of the specified escaped newline,
   /// or 0 if it is not an escaped newline. P[-1] is known to be a "\" on entry
@@ -721,8 +720,8 @@ class Lexer : public PreprocessorLexer {
 
   /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a
   /// diagnostic.
-  static SizedChar getCharAndSizeSlowNoWarn(const char *Ptr,
-const LangOptions &LangOpts);
+  static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size,
+   const LangOptions &LangOpts);
 
   
//======//
   // Other lexer functions.

diff  --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 980f865cf24c97e..2bd2c5f8388c0dd 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -565,8 +565,9 @@ Scanner::cleanStringIfNeeded(const 
dependency_directives_scan::Token &Tok) {
   const char *BufPtr = Input.begin() + Tok.Offset;
   const char *AfterIdent = Input.begin() + Tok.getEnd();
   while (BufPtr < AfterIdent) {
-auto [Char, Size] = Lexer::getCharAndSizeNoWarn(BufPtr, LangOpts);
-Spelling[SpellingLength++] = Char;
+unsigned Size;
+Spelling[SpellingLength++] =
+Lexer::getCharAndSizeNoWarn(BufPtr, Size, LangOpts);
 BufPtr += Size;
   }
 

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 1c53997527732a9..675ec28e514797e 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -287,9 +287,9 @@ static 

[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread Nico Weber via cfe-commits

nico wrote:

Reverted in 1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4 for now.

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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-10-29 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

In D154396#4655494 , @ADKaster wrote:

> @MaskRay @phosek Daniel and I have updated the patch set,  Would you rather I 
> update the phab patch series, or re-upload the set as GitHub PRs?

Update the phab patch series.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[clang] [OpenMP] Add support for Solaris (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70593

>From e59311bf2d895ebd5c031d01113d5de879c9c542 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 29 Oct 2023 09:02:12 -0400
Subject: [PATCH] [OpenMP] Add support for Solaris/x86_64

Tested on `amd64-pc-solaris2.11`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp |  5 +
 clang/test/Driver/fopenmp.c | 19 ++-
 openmp/runtime/src/kmp.h|  8 ++--
 openmp/runtime/src/kmp_ftn_entry.h  |  2 +-
 openmp/runtime/src/kmp_platform.h   | 11 +--
 openmp/runtime/src/kmp_runtime.cpp  |  8 +---
 openmp/runtime/src/z_Linux_util.cpp | 21 -
 7 files changed, 60 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..958ed99c482ed22 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
+// Use the static OpenMP runtime with -static-openmp
+bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
+!Args.hasArg(options::OPT_static);
+addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index cf04340ebc06ac6..291946923b3ea3d 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -16,6 +16,9 @@
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
 //
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
+//
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP 
--check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static 
-static-openmp %s -o %t -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
+//
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
+//
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LD-OMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
 // RUN: %clang -target 

[clang] [OpenMP] Add support for Solaris/x86_64 (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

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


[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

2023-10-29 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

Thank you for working on this! Some nit comments, hope you don't mind.
(Also invited some clang folks to have a detailed look at this. :=)


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


[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

2023-10-29 Thread Younan Zhang via cfe-commits


@@ -3553,6 +3553,56 @@ static unsigned getPackIndexForParam(Sema &S,
   llvm_unreachable("parameter index would not be produced from template");
 }
 
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`
+// we try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult
+tryInstantiateExplicitSpecifier(Sema &S, FunctionDecl *Specialization,

zyn0217 wrote:

nit: Do you think we should make this function a (private) member of `Sema` 
instead of a static function?

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


[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

2023-10-29 Thread Younan Zhang via cfe-commits


@@ -3553,6 +3553,56 @@ static unsigned getPackIndexForParam(Sema &S,
   llvm_unreachable("parameter index would not be produced from template");
 }
 
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`
+// we try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult
+tryInstantiateExplicitSpecifier(Sema &S, FunctionDecl *Specialization,
+const MultiLevelTemplateArgumentList 
&SubstArgs,
+TemplateDeductionInfo &Info,
+FunctionTemplateDecl *FunctionTemplate,
+ArrayRef DeducedArgs) {
+
+  const auto TryInstantiateExplicitSpecifierForSingleDecl =
+  [&](auto *ExplicitDecl) {
+ExplicitSpecifier ExplicitSpecifier =
+ExplicitDecl->getExplicitSpecifier();
+Expr *const Expr = ExplicitSpecifier.getExpr();
+if (!Expr) {
+  return Sema::TDK_Success;
+}
+if (!Expr->isValueDependent()) {
+  return Sema::TDK_Success;
+}
+// TemplateDeclInstantiator::InitFunctionInstantiation set the
+// ActiveInstType to TemplateInstantiation, but we need
+// to enable SFINAE when instantiating explicit specifier.

zyn0217 wrote:

```suggestion
// TemplateDeclInstantiator::InitFunctionInstantiation sets the
// ActiveInstType to TemplateInstantiation, but we need
// to enable SFINAE when instantiating an explicit specifier.
```

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


[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

2023-10-29 Thread Younan Zhang via cfe-commits


@@ -3553,6 +3553,56 @@ static unsigned getPackIndexForParam(Sema &S,
   llvm_unreachable("parameter index would not be produced from template");
 }
 
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`
+// we try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult
+tryInstantiateExplicitSpecifier(Sema &S, FunctionDecl *Specialization,
+const MultiLevelTemplateArgumentList 
&SubstArgs,
+TemplateDeductionInfo &Info,
+FunctionTemplateDecl *FunctionTemplate,
+ArrayRef DeducedArgs) {
+
+  const auto TryInstantiateExplicitSpecifierForSingleDecl =
+  [&](auto *ExplicitDecl) {
+ExplicitSpecifier ExplicitSpecifier =
+ExplicitDecl->getExplicitSpecifier();
+Expr *const Expr = ExplicitSpecifier.getExpr();
+if (!Expr) {
+  return Sema::TDK_Success;
+}
+if (!Expr->isValueDependent()) {
+  return Sema::TDK_Success;
+}
+// TemplateDeclInstantiator::InitFunctionInstantiation set the
+// ActiveInstType to TemplateInstantiation, but we need
+// to enable SFINAE when instantiating explicit specifier.
+Sema::InstantiatingTemplate Inst(
+S, Info.getLocation(), FunctionTemplate, DeducedArgs,
+Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
+Info);
+const auto Instantiated =
+S.instantiateExplicitSpecifier(SubstArgs, ExplicitSpecifier);
+if (Instantiated.isInvalid()) {
+  ExplicitDecl->setInvalidDecl(true);
+  return clang::Sema::TDK_SubstitutionFailure;
+}
+ExplicitDecl->setExplicitSpecifier(Instantiated);
+return clang::Sema::TDK_Success;
+  };
+  Sema::TemplateDeductionResult DeductionResult = clang::Sema::TDK_Success;
+  if (CXXConstructorDecl *ConstructorDecl =
+  dyn_cast_or_null(Specialization)) {

zyn0217 wrote:

nit: use `dyn_cast` since we have ensured that `Specialization` is non-null at 
the caller site `FinishTemplateArgumentDeduction`.

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


[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

2023-10-29 Thread Younan Zhang via cfe-commits


@@ -3553,6 +3553,56 @@ static unsigned getPackIndexForParam(Sema &S,
   llvm_unreachable("parameter index would not be produced from template");
 }
 
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`
+// we try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult
+tryInstantiateExplicitSpecifier(Sema &S, FunctionDecl *Specialization,
+const MultiLevelTemplateArgumentList 
&SubstArgs,
+TemplateDeductionInfo &Info,
+FunctionTemplateDecl *FunctionTemplate,
+ArrayRef DeducedArgs) {
+
+  const auto TryInstantiateExplicitSpecifierForSingleDecl =
+  [&](auto *ExplicitDecl) {
+ExplicitSpecifier ExplicitSpecifier =
+ExplicitDecl->getExplicitSpecifier();
+Expr *const Expr = ExplicitSpecifier.getExpr();
+if (!Expr) {
+  return Sema::TDK_Success;
+}
+if (!Expr->isValueDependent()) {
+  return Sema::TDK_Success;
+}
+// TemplateDeclInstantiator::InitFunctionInstantiation set the
+// ActiveInstType to TemplateInstantiation, but we need
+// to enable SFINAE when instantiating explicit specifier.
+Sema::InstantiatingTemplate Inst(
+S, Info.getLocation(), FunctionTemplate, DeducedArgs,
+Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
+Info);
+const auto Instantiated =
+S.instantiateExplicitSpecifier(SubstArgs, ExplicitSpecifier);
+if (Instantiated.isInvalid()) {
+  ExplicitDecl->setInvalidDecl(true);
+  return clang::Sema::TDK_SubstitutionFailure;
+}
+ExplicitDecl->setExplicitSpecifier(Instantiated);
+return clang::Sema::TDK_Success;
+  };
+  Sema::TemplateDeductionResult DeductionResult = clang::Sema::TDK_Success;
+  if (CXXConstructorDecl *ConstructorDecl =
+  dyn_cast_or_null(Specialization)) {
+DeductionResult =
+TryInstantiateExplicitSpecifierForSingleDecl(ConstructorDecl);
+  } else if (CXXConversionDecl *ConversionDecl =
+ dyn_cast_or_null(Specialization)) {
+DeductionResult =
+TryInstantiateExplicitSpecifierForSingleDecl(ConversionDecl);
+  }
+  return DeductionResult;

zyn0217 wrote:

Rather than returning `clang::Sema::TDK_Success` silently, shall we add an 
assertion that the `Specialization` is either a constructor or a conversion 
function?

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


[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

2023-10-29 Thread Younan Zhang via cfe-commits

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


[clang] [OpenMP] Add support for Solaris/x86_64 (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70593

>From fcb4794f8f27357b456f6c99a51e593c8410477d Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 29 Oct 2023 09:02:12 -0400
Subject: [PATCH] [OpenMP] Add support for Solaris/x86_64

Tested on `amd64-pc-solaris2.11`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp  |  5 +
 clang/test/Driver/fopenmp.c  | 19 +-
 openmp/runtime/cmake/LibompHandleFlags.cmake |  2 +-
 openmp/runtime/src/kmp.h |  8 ++--
 openmp/runtime/src/kmp_ftn_entry.h   |  2 +-
 openmp/runtime/src/kmp_platform.h| 11 --
 openmp/runtime/src/kmp_runtime.cpp   |  8 +---
 openmp/runtime/src/z_Linux_util.cpp  | 21 +++-
 8 files changed, 61 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..958ed99c482ed22 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
+// Use the static OpenMP runtime with -static-openmp
+bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
+!Args.hasArg(options::OPT_static);
+addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
diff --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index cf04340ebc06ac6..291946923b3ea3d 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -16,6 +16,9 @@
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
 // RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
 //
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
+//
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP 
--check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static-openmp %s 
-o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
+// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static 
-static-openmp %s -o %t -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
+//
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
+// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o 
%t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
+//
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LD-OMP
 // RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 
| FileCheck %s --

[PATCH] D154396: [clang] Add support for SerenityOS

2023-10-29 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster updated this revision to Diff 557927.
ADKaster added a comment.
Herald added subscribers: wangpc, s.egerton, ormris, simoncook, asb.

Base on Generic_ELF driver, add tests, add myself as co-author


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Serenity.cpp
  clang/lib/Driver/ToolChains/Serenity.h
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/include/c++/v1/.keep
  
clang/test/Driver/Inputs/serenity_x86_64_tree/usr/include/x86_64-pc-serenity/c++/v1/.keep
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crt0.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crt0_shared.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crti.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crtn.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/local/.keep
  clang/test/Driver/serenity.cpp

Index: clang/test/Driver/serenity.cpp
===
--- /dev/null
+++ clang/test/Driver/serenity.cpp
@@ -0,0 +1,36 @@
+// UNSUPPORTED: system-windows
+
+/// Test a cross compiler.
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot=%S/Inputs/serenity_x86_64_tree \
+// RUN:   -ccc-install-dir %S/Inputs/serenity_x86_64/usr/local/bin -resource-dir=%S/Inputs/resource_dir \
+// RUN:   --stdlib=platform --rtlib=platform --unwindlib=platform 2>&1 | FileCheck %s --check-prefix=SERENITY_x86_64
+// SERENITY_x86_64:  "-resource-dir" "[[RESOURCE:[^"]+]]"
+// SERENITY_x86_64:  "-internal-isystem"
+// SERENITY_x86_64-SAME: {{^}} "[[SYSROOT:[^"]+]]/usr/include/x86_64-pc-serenity/c++/v1"
+// SERENITY_x86_64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/include/c++/v1"
+// SERENITY_x86_64-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// SERENITY_x86_64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/local/include"
+// SERENITY_x86_64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/include"
+// SERENITY_x86_64:  "-L
+// SERENITY_x86_64-SAME: {{^}}[[SYSROOT]]/usr/lib"
+
+/// Loader name is the same for all architectures
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform --unwindlib=platform 2>&1 | FileCheck %s --check-prefix=DYNAMIC_LOADER
+// RUN: %clang -### %s --target=aarch64-pc-serenity --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform --unwindlib=platform 2>&1 | FileCheck %s --check-prefix=DYNAMIC_LOADER
+// RUN: %clang -### %s --target=riscv64-pc-serenity --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform --unwindlib=platform 2>&1 | FileCheck %s --check-prefix=DYNAMIC_LOADER
+// DYNAMIC_LOADER: "-dynamic-linker" "/usr/lib/Loader.so"
+
+/// -r suppresses -dynamic-linker, default -l, and crt*.o like -nostdlib.
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot=%S/Inputs/serenity_x86_64_tree \
+// RUN:   -ccc-install-dir %S/Inputs/serenity_x86_64_tree/usr/local/bin -resource-dir=%S/Inputs/resource_dir \
+// RUN:   --stdlib=platform --rtlib=platform -r 2>&1 | FileCheck %s --check-prefix=RELOCATABLE
+// RELOCATABLE-NOT:  "-dynamic-linker"
+// RELOCATABLE:  "-internal-isystem"
+// RELOCATABLE-SAME: {{^}} "[[SYSROOT:[^"]+]]/usr/include/x86_64-pc-serenity/c++/v1"
+// RELOCATABLE:  "-L
+// RELOCATABLE-SAME: {{^}}[[SYSROOT]]/usr/lib"
+// RELOCATABLE-NOT:  "-l
+// RELOCATABLE-NOT:  crt{{[^./]+}}.o
Index: clang/lib/Driver/ToolChains/Serenity.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/Serenity.h
@@ -0,0 +1,91 @@
+//=== Serenity.h - SerenityOS ToolChain Implementation --*- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SERENITY_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SERENITY_H
+
+#include "Gnu.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace serenity {
+
+class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
+public:
+  Linker(const ToolChain &TC) : Tool("serenity::Linker", "linker", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+  bool isLinkJob() const override { return true; }
+
+  void ConstructJob(Compilation &C, const JobAction &JA,
+const InputInfo &Output, const InputInfoList &Inputs,
+const llvm::opt::ArgList &TCArgs,
+   

[PATCH] D154401: [tools] Support building shared libLLVM and libClang for SerenityOS

2023-10-29 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster updated this revision to Diff 557930.
ADKaster added a comment.

prefer CMake platform defined name SERENITYOS over CMAKE_SYSTEM_NAME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154401

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake
  llvm/tools/llvm-shlib/CMakeLists.txt


Index: llvm/tools/llvm-shlib/CMakeLists.txt
===
--- llvm/tools/llvm-shlib/CMakeLists.txt
+++ llvm/tools/llvm-shlib/CMakeLists.txt
@@ -40,6 +40,7 @@
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
+ OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SerenityOS")
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")) # FIXME: It should be "GNU 
ld for elf"
 configure_file(
 ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
@@ -47,7 +48,7 @@
 
 # GNU ld doesn't resolve symbols in the version script.
 set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
-if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
+if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW AND NOT SERENITYOS)
   # Solaris ld does not accept global: *; so there is no way to version 
*all* global symbols
   set(LIB_NAMES 
-Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map
 ${LIB_NAMES})
 endif()
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -181,7 +181,7 @@
 elseif(FUCHSIA OR UNIX)
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 1)
-  if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+  if(APPLE OR SERENITYOS OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)


Index: llvm/tools/llvm-shlib/CMakeLists.txt
===
--- llvm/tools/llvm-shlib/CMakeLists.txt
+++ llvm/tools/llvm-shlib/CMakeLists.txt
@@ -40,6 +40,7 @@
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
+ OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SerenityOS")
  OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")) # FIXME: It should be "GNU ld for elf"
 configure_file(
 ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
@@ -47,7 +48,7 @@
 
 # GNU ld doesn't resolve symbols in the version script.
 set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
-if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
+if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW AND NOT SERENITYOS)
   # Solaris ld does not accept global: *; so there is no way to version *all* global symbols
   set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
 endif()
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -181,7 +181,7 @@
 elseif(FUCHSIA OR UNIX)
   set(LLVM_ON_WIN32 0)
   set(LLVM_ON_UNIX 1)
-  if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+  if(APPLE OR SERENITYOS OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
   else()
 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154402: [compiler-rt] Enable profile instrumentation for SerenityOS

2023-10-29 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster updated this revision to Diff 557931.
ADKaster added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update Driver as well, and add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154402

Files:
  clang/lib/Driver/ToolChains/Serenity.cpp
  clang/test/Driver/instrprof-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
  compiler-rt/lib/profile/InstrProfilingPlatformOther.c
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -920,7 +920,8 @@
 return false;
   // Use linker script magic to get data/cnts/name start/end.
   if (TT.isOSAIX() || TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
-  TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS() || TT.isOSWindows())
+  TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS() || TT.isOSWindows() ||
+  TT.isOSSerenity())
 return false;
 
   return true;
Index: compiler-rt/lib/profile/InstrProfilingPlatformOther.c
===
--- compiler-rt/lib/profile/InstrProfilingPlatformOther.c
+++ compiler-rt/lib/profile/InstrProfilingPlatformOther.c
@@ -8,7 +8,8 @@
 
 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
 !defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) &&   \
-!defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX)
+!defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX) &&  \
+!defined(__serenity__)
 
 #include 
 #include 
Index: compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
===
--- compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+++ compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
@@ -8,7 +8,7 @@
 
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
 (defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
-defined(_AIX)
+defined(_AIX) || defined(__serenity__)
 
 #if !defined(_AIX)
 #include 
Index: compiler-rt/cmake/config-ix.cmake
===
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -789,7 +789,7 @@
 endif()
 
 if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
-OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
+OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX|SerenityOS")
   set(COMPILER_RT_HAS_PROFILE TRUE)
 else()
   set(COMPILER_RT_HAS_PROFILE FALSE)
Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -54,6 +54,15 @@
 // CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-OPENBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
 
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-pc-serenity -fprofile-instr-generate -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/serenity_x86_64_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SERENITY-X86-64 %s
+
+// CHECK-SERENITY-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
+// CHECK-SERENITY-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}serenity{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: -shared \
 // RUN: --target=i386-unknown-linux -fprofile-instr-generate -fuse-ld=ld \
@@ -104,6 +113,17 @@
 // CHECK-OPENBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-OPENBSD-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
 
+// RUN: %clang -### %s 2>&1 \
+// RUN: -shared \
+// RUN: --target=x86_64-pc-serenity -fprofile-instr-generate -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/serenity_x86_64_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SERENITY-X86-64-SHARED %s
+
+// CHECK-SERENITY-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
+// CHECK-SERENITY-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}serenity{{/|}}libclang_rt.profile-x86_64.a"
+
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin14 -fprofile-instr-generate -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: clang/lib/Driver/ToolChains/Serenity.cpp
===
--- clang/lib/D

[PATCH] D154396: [clang] Add support for SerenityOS

2023-10-29 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster added a comment.

In D154396#4655496 , @brad wrote:

> In D154396#4655494 , @ADKaster 
> wrote:
>
>> @MaskRay @phosek Daniel and I have updated the patch set,  Would you rather 
>> I update the phab patch series, or re-upload the set as GitHub PRs?
>
> Update the phab patch series.

Sounds good, done. Some of the patches didn't need updates, and others needed a 
rebase. I already abandoned the libcxx patch as the project still needs to 
figure out the proper way to provision a machine to use as a libcxx buildkite 
runner (and where to fund it from :) ). We'll resubmit that one on GitHub after 
these are in and we get that sorted out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[clang] 2204364 - [docs] [C++20] [Modules] Add document for the case of duplicated '-fmodule-file=='

2023-10-29 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-10-30T11:25:21+08:00
New Revision: 22043643c64f748cb00ae92476f2085b3c0903c9

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

LOG: [docs] [C++20] [Modules] Add document for the case of duplicated 
'-fmodule-file=='

This patch clarifies that in case there are multiple
'-fmodule-file==' optins for the same ``,
the last '-fmodule-file==' will override the previous
'-fmodule-file==' option.

Added: 


Modified: 
clang/docs/StandardCPlusPlusModules.rst

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 8dd86edc64a80ab..49704575740303c 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -365,6 +365,10 @@ the above example could be rewritten into:
 
   $ clang++ -std=c++20 M.cppm --precompile 
-fmodule-file=M:interface_part=M-interface_part.pcm 
-fmodule-file=M:impl_part=M-impl_part.pcm -o M.pcm
 
+When there are multiple ``-fmodule-file==`` options for the same
+, the last ``-fmodule-file==`` will override the 
previous
+``-fmodule-file==`` options.
+
 ``-fprebuilt-module-path`` is more convenient and ``-fmodule-file`` is faster 
since
 it saves time for file lookup.
 



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


[clang] [C++20] [Modules] Warn if we found #include in module purview (PR #69555)

2023-10-29 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@Bigcheese ping

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


[clang] [OpenMP] Add support for Solaris/x86_64 (PR #70593)

2023-10-29 Thread Brad Smith via cfe-commits

brad0 wrote:

> I'm not familiar with Solaris but does it need dedicated implementation of 
> the function invocation written in ASM?

Can you point out what you're referring to? Looking at the patches for adding 
support for OpenBSD and other OS's I don't see any ASM additions.

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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-10-29 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

Make use of the concat macro with the various header and library paths.
https://github.com/llvm/llvm-project/commit/1d0cc510516d50c459f78896a0375fadb13a2b45




Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:78
+
+  if (Output.isFilename()) {
+CmdArgs.push_back("-o");

Like the other ToolChains this should have before it..

assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:107
+  Args.AddAllArgs(CmdArgs, options::OPT_u);
+
+  TC.AddFilePathLibArgs(Args, CmdArgs);

https://github.com/llvm/llvm-project/commit/894927b491b7c62917ffa7ad665841683095317c



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:119
+  Args.AddAllArgs(CmdArgs, options::OPT_t);
+  Args.AddAllArgs(CmdArgs, options::OPT_r);
+

https://github.com/llvm/llvm-project/commit/894927b491b7c62917ffa7ad665841683095317c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-10-29 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

You also have to add Serenity to clang/lib/Lex/InitHeaderSearch.cpp 
InitHeaderSearch::ShouldAddDefaultIncludePaths().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-10-29 Thread Brad Smith via Phabricator via cfe-commits
brad added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.h:81
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+

This just overrides the default DWARF version anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[clang] [clang-scan-deps] [P1689] Keep consistent behavior for make dependencies with clang (PR #69551)

2023-10-29 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/69551

>From c91007b51e164d22c8f73a864105494ebc10a004 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 30 Oct 2023 11:51:04 +0800
Subject: [PATCH] [clang-scan-deps] [P1689] Keep consistent behavior for make
 dependencies with clang

Close #69439.

This patch tries to reuse the codes to generate make style dependencies
information with P1689 format directly.
---
 .../DependencyScanning/ModuleDepCollector.cpp  | 14 ++
 clang/test/ClangScanDeps/P1689.cppm| 10 ++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 40115b7b5ae25b3..3764ccb0b4749b1 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -666,13 +666,19 @@ static StringRef 
makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path,
 }
 
 void ModuleDepCollector::addFileDep(StringRef Path) {
-  llvm::SmallString<256> Storage;
-  Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage);
+  // Within P1689 format, we don't want all the paths to be absolute path
+  // since it may violate the tranditional make style dependencies info.
+  if (!IsStdModuleP1689Format) {
+llvm::SmallString<256> Storage;
+Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage);
+  }
   FileDeps.push_back(std::string(Path));
 }
 
 void ModuleDepCollector::addFileDep(ModuleDeps &MD, StringRef Path) {
-  llvm::SmallString<256> Storage;
-  Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage);
+  if (!IsStdModuleP1689Format) {
+llvm::SmallString<256> Storage;
+Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage);
+  }
   MD.FileDeps.insert(Path);
 }
diff --git a/clang/test/ClangScanDeps/P1689.cppm 
b/clang/test/ClangScanDeps/P1689.cppm
index dffb16974a3e4e4..24632e25cf7f3bd 100644
--- a/clang/test/ClangScanDeps/P1689.cppm
+++ b/clang/test/ClangScanDeps/P1689.cppm
@@ -42,6 +42,14 @@
 // RUN: clang-scan-deps -format=p1689 \
 // RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
+//
+// Check the path in the make style dependencies are generated in relative 
path form
+// RUN: cd %t
+// RUN: clang-scan-deps -format=p1689 \
+// RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t impl_part.cppm 
-o impl_part.o \
+// RUN:  -MT impl_part.o.ddi -MD -MF impl_part.dep
+// RUN:   cat impl_part.dep | FileCheck impl_part.cppm -DPREFIX=%/t 
--check-prefix=CHECK-MAKE-RELATIVE
+
 
 //--- P1689.json.in
 [
@@ -168,6 +176,8 @@ void World() {
 // CHECK-MAKE:   [[PREFIX]]/impl_part.cppm
 // CHECK-MAKE:   [[PREFIX]]/header.mock
 
+// CHECK-MAKE-RELATIVE: impl_part.o.ddi: impl_part.cppm header.mock
+
 //--- interface_part.cppm
 export module M:interface_part;
 export void World();

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


[clang] [clang-scan-deps] [P1689] Keep consistent behavior for make dependencies with clang (PR #69551)

2023-10-29 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> Thanks for the ping, I had missed your question
> 
> > How do you think about the idea to add a flag to the MDC about whether or 
> > not calling makeAbsoluteAndPreferred?
> 
> SGTM; this seems like a good compromise since we can't easily extract this 
> into the consumer.

Done. Does the current patch look good to you?

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


[clang-tools-extra] create new clang-tidy check to add namespaces to symbol references (PR #70621)

2023-10-29 Thread via cfe-commits

https://github.com/daltairwalter created 
https://github.com/llvm/llvm-project/pull/70621

What should be done when "using namespace" has been abused or used in header 
files?  This check will update all references to include full namespace 
qualification.

>From f44d7746a990a3bd8e53de047a30baee4da2c790 Mon Sep 17 00:00:00 2001
From: Daniel Walter 
Date: Mon, 30 Oct 2023 00:08:56 -0500
Subject: [PATCH 1/3] Initial commit of add new check before changes

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../UseExplicitNamespacesCheck.cpp| 33 +++
 .../readability/UseExplicitNamespacesCheck.h  | 30 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/use-explicit-namespaces.rst   |  6 
 .../readability/use-explicit-namespaces.cpp   | 14 
 8 files changed, 93 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/use-explicit-namespaces.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/use-explicit-namespaces.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..6bcc9ca3e646ce0 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -51,6 +51,7 @@ add_clang_library(clangTidyReadabilityModule
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
   UseAnyOfAllOfCheck.cpp
+  UseExplicitNamespacesCheck.cpp
 
   LINK_LIBS
   clangTidy
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..bdb253f90cebc2b 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -54,6 +54,7 @@
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
 #include "UseAnyOfAllOfCheck.h"
+#include "UseExplicitNamespacesCheck.h"
 
 namespace clang::tidy {
 namespace readability {
@@ -151,6 +152,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-uppercase-literal-suffix");
 CheckFactories.registerCheck(
 "readability-use-anyofallof");
+CheckFactories.registerCheck(
+"readability-use-explicit-namespaces");
   }
 };
 
diff --git 
a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
new file mode 100644
index 000..a803179b822bd2c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
@@ -0,0 +1,33 @@
+//===--- UseExplicitNamespacesCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseExplicitNamespacesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseExplicitNamespacesCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(functionDecl().bind("x"), this);
+}
+
+void UseExplicitNamespacesCheck::check(const MatchFinder::MatchResult &Result) 
{
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
+return;
+  diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
+  << MatchedDecl
+  << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
+  diag(MatchedDecl->getLocation(), "insert 'awesome'", DiagnosticIDs::Note);
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h 
b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
new file mode 100644
index 000..846e47930d05669
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
@@ -0,0 +1,30 @@
+//===--- UseExplicitNamespacesCheck.h - clang-tidy --*- 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: Apach

[clang-tools-extra] create new clang-tidy check to add namespaces to symbol references (PR #70621)

2023-10-29 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 a8d0c86174b4e7355e250b3eb266e055df224f48 
38df6a99730d64eb96945845b69ce7602ce3ddfa -- 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h 
clang-tools-extra/test/clang-tidy/checkers/readability/use-explicit-namespaces.cpp
 clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
index 2143b392a..776c895c8 100644
--- a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
@@ -327,8 +327,8 @@ getDeclContextVector(const DeclContext *context) {
   break;
 case Decl::Namespace:
   namespacesStarted = true;
-  [[fallthrough]] default
-  : if (namespacesStarted && kind != Decl::Namespace) {
+[[fallthrough]] default:
+  if (namespacesStarted && kind != Decl::Namespace) {
 std::cout << "processing namepsace vector after namespace "
  "we have "
   << context->getDeclKindName() << std::endl;

``




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


  1   2   >