[PATCH] D158413: [Lex] Introduce Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 557603.
Hahnfeld marked an inline comment as done.
Hahnfeld added a comment.

Address minor naming convention nit.


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

https://reviews.llvm.org/D158413

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Preprocessor.cpp
  clang/unittests/Analysis/MacroExpansionContextTest.cpp
  clang/unittests/Basic/SourceManagerTest.cpp
  clang/unittests/Lex/LexerTest.cpp
  clang/unittests/Lex/ModuleDeclStateTest.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp
  clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp
  clang/unittests/Lex/PPMemoryAllocationsTest.cpp

Index: clang/unittests/Lex/PPMemoryAllocationsTest.cpp
===
--- clang/unittests/Lex/PPMemoryAllocationsTest.cpp
+++ clang/unittests/Lex/PPMemoryAllocationsTest.cpp
@@ -75,12 +75,7 @@
   PP.Initialize(*Target);
   PP.EnterMainSourceFile();
 
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-  }
+  PP.LexTokensUntilEOF();
 
   size_t NumAllocated = PP.getPreprocessorAllocator().getBytesAllocated();
   float BytesPerDefine = float(NumAllocated) / float(NumMacros);
Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- clang/unittests/Lex/PPDependencyDirectivesTest.cpp
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -133,12 +133,7 @@
   SmallVector IncludedFiles;
   PP.addPPCallbacks(std::make_unique(PP, IncludedFiles));
   PP.EnterMainSourceFile();
-  while (true) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-  }
+  PP.LexTokensUntilEOF();
 
   SmallVector IncludedFilesSlash;
   for (StringRef IncludedFile : IncludedFiles)
Index: clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
===
--- clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
+++ clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
@@ -87,13 +87,7 @@
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF(&toks);
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(10U, toks.size());
Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -229,13 +229,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 // Callbacks have been executed at this point -- return filename range.
 return Callbacks;
@@ -259,13 +253,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 return Callbacks->Results;
   }
@@ -290,12 +278,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 return Callbacks->Marks;
   }
@@ -334,12 +317,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 PragmaOpenCLExtensionCallbacks::CallbackParameters RetVal = {
   Callbacks->Name,
@@ -477,12 +455,7 @@
 
   // Lex source text.
   PP.EnterMainSourceFile();
-  while (true) {
-Token Tok;
-PP.Lex(Tok);
-if (Tok.is(tok::eof))
-  break;
-  }
+  PP.LexTokensUntilEOF();
 
   ASSERT_EQ(1u, Callbacks->NumCalls);
   ASSERT_EQ(0u, DiagConsumer->getNumErrors());
Index: clang/unittests/Lex/ModuleDeclStateTest.cpp
===
--- clang/unittests/Lex/ModuleDeclStateTest.cpp
+++ clang/unittests/Lex/ModuleDeclStateTest.cpp
@@ -90,12 +90,7 @@
 PP.addPPCallbacks(std::move(C));
 PP.EnterMainSourceFile();
 
-while (1) {
-  Token tok;
-  PP.Lex(tok);
-  if (tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
   }
 
   FileSystemOptions FileMgrOpts;
Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -74,13 +74,7 @@
 PP = CreatePP(Source, ModLoader);
 
 std::vector toks;
-while (1) {
-  Token tok;
-  PP->Lex(tok);
-  if (tok.is(tok::eof))
-break;
-  toks.push_back(tok);
-}
+PP->LexTokensUntilEOF(

[PATCH] D158413: [Lex] Introduce Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: clang/lib/Lex/Preprocessor.cpp:1000
+  std::vector toks;
+  while (1) {
+Token tok;

v.g.vassilev wrote:
> Hahnfeld wrote:
> > aaron.ballman wrote:
> > > v.g.vassilev wrote:
> > > > aaron.ballman wrote:
> > > > > Hahnfeld wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > I'd prefer not to assume the token stream has an EOF token 
> > > > > > > (perhaps the stream is one only being used to parse until the 
> > > > > > > `eod` token instead), so if we can turn this into a non-infinite 
> > > > > > > loop, that would make me more comfortable.
> > > > > > I'm not sure I understand entirely. Do you want something like
> > > > > > ```
> > > > > > tok.isOneOf(tok::unknown, tok::eof, tok::eod)
> > > > > > ```
> > > > > > instead of `tok.is(tok::eof)`? Can this happen at the level of the 
> > > > > > `Preprocessor`?
> > > > > I was thinking something more along the lines of:
> > > > > ```
> > > > > if (Tokens) {
> > > > >   for (Token Tok; !Tok.isOneOf(tok::eof, tok::eod); Lex(Tok))
> > > > > Tokens->push_back(Tok);
> > > > > }
> > > > > ```
> > > > > but I hadn't thought about `tok::unknown`; that might be a good one 
> > > > > to also include given that clangd operates on partial sources.
> > > > > 
> > > > I was wondering if we could somehow merge this routine with 
> > > > `Parser::SkipUntil` since they seem to be doing a very similar tasks.
> > > That could perhaps end up looking reasonable (they do similar tasks aside 
> > > from collecting the tokens that are being skipped). Do you need the 
> > > interface to be on `Preprocessor` or `Parser` though (or does it not 
> > > really matter for you)?
> > > `tok.isOneOf(tok::unknown, tok::eof, tok::eod)`
> > 
> > I implemented this check, let me know if this looks reasonable. The code 
> > you posted doesn't do what we need because we also want to lex if `Tokens` 
> > is `nullptr`, so the hierarchy must be an `if` inside the loop.
> > Given these additional token kinds, does `UntilEOF` still make sense or do 
> > we want another name? Note that I'll leave `repl_input_end` to 
> > https://reviews.llvm.org/D158415.
> > 
> > > I was wondering if we could somehow merge this routine with 
> > > `Parser::SkipUntil` since they seem to be doing a very similar tasks.
> > 
> > I'm not sure this makes sense, given that `Parser::SkipUntil` requires some 
> > knowledge about the structural input. At the very least, I'd prefer not to 
> > go into that direction for this change.
> I am not sure I understand the reasoning but I somewhat see that having 
> Parser's `SkipUntil` be implemented with our new `Preprocessor::LexUntil...` 
> would require a lot more work. How about adding a fixme note capturing this 
> as a future possible refactoring?
@v.g.vassilev `Parser::SkipUntil` has a long `switch` statement looking at the 
token and taking special actions depending on their kind and the context it 
appears in. I don't see how to generalize this in the way `LexTokensUntilEOF` 
works.


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

https://reviews.llvm.org/D158413

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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-05 Thread via cfe-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/65246

>From aa41086f545daec80770bf17a3cfcc3d3168e394 Mon Sep 17 00:00:00 2001
From: "kasuga.ryotaro" 
Date: Wed, 30 Aug 2023 13:26:31 +0900
Subject: [PATCH] [Clang] Fix missing diagnostic for non-standard layout type
 in `offsetof`

Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
diagnostic if you use `offsetof` on non-standard layout types in any
other contexts
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/Sema/SemaExpr.cpp   |  9 ++-
 clang/test/SemaCXX/class-layout.cpp   | 62 +--
 clang/test/SemaCXX/ms_struct.cpp  |  6 +-
 clang/test/SemaCXX/offsetof.cpp   |  9 +--
 libcxx/include/__type_traits/datasizeof.h |  5 ++
 .../non_trivial_copy_move_ABI.pass.cpp|  2 +-
 .../pairs.pair/trivial_copy_move_ABI.pass.cpp |  1 +
 8 files changed, 52 insertions(+), 44 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2362e479dfbbc5a..f67ceb1d6173c93 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,8 @@ Improvements to Clang's diagnostics
 source:1:24: note: expression evaluates to ''\n' (0x0A, 10) == U'🌍' 
(0x1F30D, 127757)'
 1 | static_assert("A\n"[1] == U'🌍');
   |   ~^~~~
+- Clang now always diagnoses when using non-standard layout types in 
``offsetof`` .
+  (`#64619: `_)
 
 Bug Fixes in This Version
 -
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 304aa7d105e269b..b86f3c004403afe 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16796,12 +16796,11 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation 
BuiltinLoc,
 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
 : diag::ext_offsetof_non_pod_type;
 
-  if (!IsSafe && !DidWarnAboutNonPOD &&
-  DiagRuntimeBehavior(BuiltinLoc, nullptr,
-  PDiag(DiagID)
-  << SourceRange(Components[0].LocStart, OC.LocEnd)
-  << CurrentType))
+  if (!IsSafe && !DidWarnAboutNonPOD && !isUnevaluatedContext()) {
+Diag(BuiltinLoc, DiagID)
+<< SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
 DidWarnAboutNonPOD = true;
+  }
 }
 
 // Look for the field.
diff --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 9782ff08100b2d6..22fb34b8419c583 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,34 +1,34 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-
-// RUN: %clang_cc1 -fex

[clang] 4d7f4a7 - [clang][Interp] Only lazily visit constant globals

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

Author: Timm Bäder
Date: 2023-10-05T09:37:37+02:00
New Revision: 4d7f4a7c82cb742dd9711cce1cfbe574ac08c068

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

LOG: [clang][Interp] Only lazily visit constant globals

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/c.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f4ab30a5c8e7238..00d3b469d9049f6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2536,7 +2536,8 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   // This happens in C.
   if (!Ctx.getLangOpts().CPlusPlus) {
 if (const auto *VD = dyn_cast(D);
-VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) {
+VD && VD->hasGlobalStorage() && VD->getAnyInitializer() &&
+VD->getType().isConstQualified()) {
   if (!this->visitVarDecl(VD))
 return false;
   // Retry.

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index c0ec5f8339dd1d7..47058b8a93203b6 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -14,11 +14,15 @@ _Static_assert(!!1.0, ""); // pedantic-ref-warning {{not an 
integer constant exp
// pedantic-expected-warning {{not an integer 
constant expression}}
 _Static_assert(!!1, "");
 
-/// FIXME: Should also be rejected in the new interpreter
-int a = (1 == 1 ? 5 : 3);
+int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \
+  // pedantic-expected-note {{declared here}}
 _Static_assert(a == 5, ""); // ref-error {{not an integral constant 
expression}} \
 // pedantic-ref-error {{not an integral constant 
expression}} \
-// pedantic-expected-warning {{not an integer 
constant expression}}
+// expected-error {{not an integral constant 
expression}} \
+// expected-note {{read of non-const variable}} \
+// pedantic-expected-error {{not an integral 
constant expression}} \
+// pedantic-expected-note {{read of non-const 
variable}}
+
 
 const int b = 3;
 _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant 
expression}} \



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


[PATCH] D158516: [clang][Interp] Only lazily visit constant globals

2023-10-05 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d7f4a7c82cb: [clang][Interp] Only lazily visit constant 
globals (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158516

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/c.c


Index: clang/test/AST/Interp/c.c
===
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -14,11 +14,15 @@
// pedantic-expected-warning {{not an integer 
constant expression}}
 _Static_assert(!!1, "");
 
-/// FIXME: Should also be rejected in the new interpreter
-int a = (1 == 1 ? 5 : 3);
+int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \
+  // pedantic-expected-note {{declared here}}
 _Static_assert(a == 5, ""); // ref-error {{not an integral constant 
expression}} \
 // pedantic-ref-error {{not an integral constant 
expression}} \
-// pedantic-expected-warning {{not an integer 
constant expression}}
+// expected-error {{not an integral constant 
expression}} \
+// expected-note {{read of non-const variable}} \
+// pedantic-expected-error {{not an integral 
constant expression}} \
+// pedantic-expected-note {{read of non-const 
variable}}
+
 
 const int b = 3;
 _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant 
expression}} \
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2536,7 +2536,8 @@
   // This happens in C.
   if (!Ctx.getLangOpts().CPlusPlus) {
 if (const auto *VD = dyn_cast(D);
-VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) {
+VD && VD->hasGlobalStorage() && VD->getAnyInitializer() &&
+VD->getType().isConstQualified()) {
   if (!this->visitVarDecl(VD))
 return false;
   // Retry.


Index: clang/test/AST/Interp/c.c
===
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -14,11 +14,15 @@
// pedantic-expected-warning {{not an integer constant expression}}
 _Static_assert(!!1, "");
 
-/// FIXME: Should also be rejected in the new interpreter
-int a = (1 == 1 ? 5 : 3);
+int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \
+  // pedantic-expected-note {{declared here}}
 _Static_assert(a == 5, ""); // ref-error {{not an integral constant expression}} \
 // pedantic-ref-error {{not an integral constant expression}} \
-// pedantic-expected-warning {{not an integer constant expression}}
+// expected-error {{not an integral constant expression}} \
+// expected-note {{read of non-const variable}} \
+// pedantic-expected-error {{not an integral constant expression}} \
+// pedantic-expected-note {{read of non-const variable}}
+
 
 const int b = 3;
 _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2536,7 +2536,8 @@
   // This happens in C.
   if (!Ctx.getLangOpts().CPlusPlus) {
 if (const auto *VD = dyn_cast(D);
-VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) {
+VD && VD->hasGlobalStorage() && VD->getAnyInitializer() &&
+VD->getType().isConstQualified()) {
   if (!this->visitVarDecl(VD))
 return false;
   // Retry.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][driver] Prevent clang picking the system headers when started via a symlink (PR #68091)

2023-10-05 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> > ... I understand this is only a bug on MacOS?
> 
> I'm using clang only to compile my binary packages on macOS (the Linux 
> binaries are compiled with gcc), so I got bitten by this bug only on macOS. 
> The other platforms/targets may or may not be affected, I don't know; but my 
> initial search for InstalledDir showed multiple references not paired with 
> references to Dir.

This is one of the issues I have with mainly with the problem formulation - as 
there are two levels of logic involved here. The generic code which sets the 
install dir, and the target specific files in clang/lib/Driver/ToolChains, 
which do various things based on the install dir that has been detected 
elsewhere, plus target specific heuristics for falling back on other ways to 
detecting things that are needed.

If the installation dir is detected as the wrong thing, this would be fatal for 
all targets, but the exact behaviour you'd see would be quite target dependent. 
That's why explanations like "silently using system headers from a different 
version is hard to debug here" are out of scope here; using the wrong install 
dir is fatal of course.

If the darwin specific fallback handling could be improved, that'd of course be 
great.


On the other hand - in principle I kinda agree that the fix itself, locating 
things based on the actual executable, sounds like the right thing to do in any 
case. We're early in the 18.x cycle, and if we could get the tests fixed to 
work despite that, we'd have lots of time to see if someone is affected 
negatively by it, before 18.x is released.

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

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

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


[clang] 57147bb - [clang][Interp] Support LambdaThisCaptures

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

Author: Timm Bäder
Date: 2023-10-05T09:46:15+02:00
New Revision: 57147bb25303aef5edf251d1f2243e75dc687aec

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

LOG: [clang][Interp] Support LambdaThisCaptures

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeEmitter.h
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/EvalEmitter.h
clang/test/AST/Interp/lambda.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index ea4e48cb4262772..a634ee288f57c99 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -64,8 +64,8 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
 this->LambdaCaptures[Cap.first] = {
 Offset, Cap.second->getType()->isReferenceType()};
   }
-  // FIXME: LambdaThisCapture
-  (void)LTC;
+  if (LTC)
+this->LambdaThisCapture = R->getField(LTC)->Offset;
 }
   }
 

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.h 
b/clang/lib/AST/Interp/ByteCodeEmitter.h
index d184484a9197f93..5520f8c3006106f 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.h
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -67,7 +67,8 @@ class ByteCodeEmitter {
   llvm::DenseMap Params;
   /// Lambda captures.
   llvm::DenseMap LambdaCaptures;
-  unsigned LambdaThisCapture;
+  /// Offset of the This parameter in a lambda record.
+  unsigned LambdaThisCapture = 0;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
 

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 00d3b469d9049f6..3cf8bf874b1d210 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2305,6 +2305,10 @@ template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)
 return true;
+
+  if (this->LambdaThisCapture > 0)
+return this->emitGetThisFieldPtr(this->LambdaThisCapture, E);
+
   return this->emitThis(E);
 }
 

diff  --git a/clang/lib/AST/Interp/EvalEmitter.h 
b/clang/lib/AST/Interp/EvalEmitter.h
index c63e46bbf347bdf..1128e0fb09f0de8 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -73,7 +73,8 @@ class EvalEmitter : public SourceMapper {
   llvm::DenseMap Params;
   /// Lambda captures.
   llvm::DenseMap LambdaCaptures;
-  unsigned LambdaThisCapture;
+  /// Offset of the This parameter in a lambda record.
+  unsigned LambdaThisCapture = 0;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
 

diff  --git a/clang/test/AST/Interp/lambda.cpp 
b/clang/test/AST/Interp/lambda.cpp
index da1d706af1d0501..f8400898acc0c05 100644
--- a/clang/test/AST/Interp/lambda.cpp
+++ b/clang/test/AST/Interp/lambda.cpp
@@ -179,3 +179,24 @@ namespace LambdasAsParams {
   }
   static_assert(heh() == 1.0);
 }
+
+namespace ThisCapture {
+  class Foo {
+  public:
+int b = 32;
+int a;
+
+constexpr Foo() : a([this](){ return b + 1;}()) {}
+
+constexpr int Aplus2() const {
+  auto F = [this]() {
+return a + 2;
+  };
+
+  return F();
+}
+  };
+  constexpr Foo F;
+  static_assert(F.a == 33, "");
+  static_assert(F.Aplus2() == (33 + 2), "");
+}



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


[PATCH] D154262: [clang][Interp] LambdaThisCaptures

2023-10-05 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57147bb25303: [clang][Interp] Support LambdaThisCaptures 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D154262?vs=536427&id=557605#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154262

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeEmitter.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/EvalEmitter.h
  clang/test/AST/Interp/lambda.cpp


Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -179,3 +179,24 @@
   }
   static_assert(heh() == 1.0);
 }
+
+namespace ThisCapture {
+  class Foo {
+  public:
+int b = 32;
+int a;
+
+constexpr Foo() : a([this](){ return b + 1;}()) {}
+
+constexpr int Aplus2() const {
+  auto F = [this]() {
+return a + 2;
+  };
+
+  return F();
+}
+  };
+  constexpr Foo F;
+  static_assert(F.a == 33, "");
+  static_assert(F.Aplus2() == (33 + 2), "");
+}
Index: clang/lib/AST/Interp/EvalEmitter.h
===
--- clang/lib/AST/Interp/EvalEmitter.h
+++ clang/lib/AST/Interp/EvalEmitter.h
@@ -73,7 +73,8 @@
   llvm::DenseMap Params;
   /// Lambda captures.
   llvm::DenseMap LambdaCaptures;
-  unsigned LambdaThisCapture;
+  /// Offset of the This parameter in a lambda record.
+  unsigned LambdaThisCapture = 0;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2305,6 +2305,10 @@
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)
 return true;
+
+  if (this->LambdaThisCapture > 0)
+return this->emitGetThisFieldPtr(this->LambdaThisCapture, E);
+
   return this->emitThis(E);
 }
 
Index: clang/lib/AST/Interp/ByteCodeEmitter.h
===
--- clang/lib/AST/Interp/ByteCodeEmitter.h
+++ clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -67,7 +67,8 @@
   llvm::DenseMap Params;
   /// Lambda captures.
   llvm::DenseMap LambdaCaptures;
-  unsigned LambdaThisCapture;
+  /// Offset of the This parameter in a lambda record.
+  unsigned LambdaThisCapture = 0;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
 
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -64,8 +64,8 @@
 this->LambdaCaptures[Cap.first] = {
 Offset, Cap.second->getType()->isReferenceType()};
   }
-  // FIXME: LambdaThisCapture
-  (void)LTC;
+  if (LTC)
+this->LambdaThisCapture = R->getField(LTC)->Offset;
 }
   }
 


Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -179,3 +179,24 @@
   }
   static_assert(heh() == 1.0);
 }
+
+namespace ThisCapture {
+  class Foo {
+  public:
+int b = 32;
+int a;
+
+constexpr Foo() : a([this](){ return b + 1;}()) {}
+
+constexpr int Aplus2() const {
+  auto F = [this]() {
+return a + 2;
+  };
+
+  return F();
+}
+  };
+  constexpr Foo F;
+  static_assert(F.a == 33, "");
+  static_assert(F.Aplus2() == (33 + 2), "");
+}
Index: clang/lib/AST/Interp/EvalEmitter.h
===
--- clang/lib/AST/Interp/EvalEmitter.h
+++ clang/lib/AST/Interp/EvalEmitter.h
@@ -73,7 +73,8 @@
   llvm::DenseMap Params;
   /// Lambda captures.
   llvm::DenseMap LambdaCaptures;
-  unsigned LambdaThisCapture;
+  /// Offset of the This parameter in a lambda record.
+  unsigned LambdaThisCapture = 0;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2305,6 +2305,10 @@
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)
 return true;
+
+  if (this->LambdaThisCapture > 0)
+return this->emitGetThisFieldPtr(this->LambdaThisCapture, E);
+
   return this->emitThis(E);
 }
 
Index: clang/lib/AST/Interp/ByteCodeEmitter.h
===
--- clang/lib/AST/Interp/ByteCodeEmitter.h
+++ clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -67,7 +67,8 @@
 

[clang] [HIP] Support compressing device binary (PR #67162)

2023-10-05 Thread via cfe-commits

mikaelholmen wrote:

Hi,

I noticed that with UBSan this new testcase fails
```
09:59:08 Failed Tests (1):
09:59:08   Clang :: Driver/clang-offload-bundler-zlib.c
```
with
```
09:39:53 ../../clang/lib/Driver/OffloadBundler.cpp:1012:25: runtime error: load 
of misaligned address 0x55ceca16e46c for type 'const uint64_t' (aka 'const 
unsigned long'), which requires 8 byte alignment
09:39:53 0x55ceca16e46c: note: pointer points here
09:39:53   bc 00 00 00 94 dc 29 9a  89 fb ca 2b 78 9c 8b 8f  77 f6 71 f4 73 8f 
f7 77  73 f3 f1 77 74 89 77 0a
09:39:53   ^ 
09:39:53 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
../../clang/lib/Driver/OffloadBundler.cpp:1012:25 in 
```

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


[clang] [mlir][llvm] Fix elem type passing into `getelementptr` (PR #68136)

2023-10-05 Thread Oleksandr Alex Zinenko via cfe-commits

ftynse wrote:

What I meant in the comment was that MLIR doesn't need to make a hard switch to 
using opaque pointers and immediately turn off typed pointers. I didn't really 
imply that an operations in the IR should freely mix the two. Typed pointers 
should and will be removed from the LLVM dialect as well. I consider any 
significant investment into typed pointer support, let alone a "mixed mode", a 
waste of time. Since this PR fixes a crash, I'm fine with it landing as is 
instead of spending cycles on an arguably better fix that will get removed 
within months as I hope opaque pointers to be gone from the dialect by the next 
release. Improving verifiers otherwise is greatly appreciated!

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


[clang] [mlir][llvm] Fix elem type passing into `getelementptr` (PR #68136)

2023-10-05 Thread Oleksandr Alex Zinenko via cfe-commits

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


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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

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

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

>From https://reviews.llvm.org/D154951 - which is never gonna make it out of 
>Phabricator anyway.


The tests are failing because https://reviews.llvm.org/D154581 is not pushed.

Aaron's review mentioned that we should support bitfields before pushing this.

>From e208c2fc7932d80d441d90bfa0fd949b8910a4c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 11 Jul 2023 13:45:04 +0200
Subject: [PATCH] Bitcasts

---
 clang/lib/AST/CMakeLists.txt   |   1 +
 clang/lib/AST/Interp/Boolean.h |  15 +-
 clang/lib/AST/Interp/ByteCodeExprGen.cpp   |  71 +++
 clang/lib/AST/Interp/ByteCodeExprGen.h |   1 +
 clang/lib/AST/Interp/Floating.h|  11 +
 clang/lib/AST/Interp/Integral.h|  19 +-
 clang/lib/AST/Interp/Interp.cpp|  17 +
 clang/lib/AST/Interp/Interp.h  |  66 ++
 clang/lib/AST/Interp/InterpBitcast.cpp | 482 +++
 clang/lib/AST/Interp/Opcodes.td|  17 +
 clang/lib/AST/Interp/PrimType.h|   4 +
 clang/test/AST/Interp/builtin-bit-cast.cpp | 683 +
 clang/test/AST/Interp/literals.cpp |   5 +
 13 files changed, 1389 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/AST/Interp/InterpBitcast.cpp
 create mode 100644 clang/test/AST/Interp/builtin-bit-cast.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..5a188b583022bda 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -74,6 +74,7 @@ add_clang_library(clangAST
   Interp/Frame.cpp
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
+  Interp/InterpBitcast.cpp
   Interp/Floating.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
diff --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index c3ed3d61f76ca1c..d395264ab2de448 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -9,14 +9,15 @@
 #ifndef LLVM_CLANG_AST_INTERP_BOOLEAN_H
 #define LLVM_CLANG_AST_INTERP_BOOLEAN_H
 
-#include 
-#include 
 #include "Integral.h"
 #include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/ComparisonCategories.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -65,6 +66,9 @@ class Boolean final {
   Boolean toUnsigned() const { return *this; }
 
   constexpr static unsigned bitWidth() { return 1; }
+  constexpr static unsigned objectReprBits() { return 8; }
+  constexpr static unsigned valueReprBytes(const ASTContext &Ctx) { return 1; }
+
   bool isZero() const { return !V; }
   bool isMin() const { return isZero(); }
 
@@ -106,6 +110,13 @@ class Boolean final {
 return Boolean(!Value.isZero());
   }
 
+  static Boolean bitcastFromMemory(const std::byte *Buff) {
+bool Val = static_cast(*Buff);
+return Boolean(Val);
+  }
+
+  void bitcastToMemory(std::byte *Buff) { std::memcpy(Buff, &V, sizeof(V)); }
+
   static Boolean zero() { return from(false); }
 
   template 
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3cf8bf874b1d210..8cc010d6f100ccb 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -67,6 +67,74 @@ template  class OptionScope final {
 } // namespace interp
 } // namespace clang
 
+//  This function is constexpr if and only if To, From, and the types of
+//  all subobjects of To and From are types T such that...
+//  (3.1) - is_union_v is false;
+//  (3.2) - is_pointer_v is false;
+//  (3.3) - is_member_pointer_v is false;
+//  (3.4) - is_volatile_v is false; and
+//  (3.5) - T has no non-static data members of reference type
+template 
+bool ByteCodeExprGen::emitBuiltinBitCast(const CastExpr *E) {
+  const Expr *SubExpr = E->getSubExpr();
+  QualType FromType = SubExpr->getType();
+  QualType ToType = E->getType();
+  std::optional ToT = classify(ToType);
+
+  // FIXME: This is wrong. We need to do the bitcast and then
+  //   throw away the result, so we still get the diagnostics.
+  if (DiscardResult)
+return this->discard(SubExpr);
+
+  if (ToType->isNullPtrType()) {
+if (!this->discard(SubExpr))
+  return false;
+
+return this->emitNullPtr(E);
+  }
+
+  if (FromType->isNullPtrType() && ToT) {
+if (!this->discard(SubExpr))
+  return false;
+
+return visitZeroInitializer(ToType, E);
+  }
+  assert(!ToType->isReferenceType());
+
+  // Get a pointer to the value-to-cast on the stack.
+  if (!this->visit(SubExpr))
+return false;
+
+  if (!ToT || ToT == PT_Ptr) {
+// Conversion to an array or record type.
+return this->emitBitCastPtr(E);
+  }
+
+  assert(ToT);
+
+  // Conversion to a primitive type. FromType can be another
+  // primitive type, or a record/array.
+  //
+  // Same thing for floa

[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-10-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

>From https://reviews.llvm.org/D154951 - which is never gonna make it out of 
>Phabricator anyway.


The tests are failing because https://reviews.llvm.org/D154581 is not pushed.

Aaron's review mentioned that we should support bitfields before pushing this.

---

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


13 Files Affected:

- (modified) clang/lib/AST/CMakeLists.txt (+1) 
- (modified) clang/lib/AST/Interp/Boolean.h (+13-2) 
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+71) 
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.h (+1) 
- (modified) clang/lib/AST/Interp/Floating.h (+11) 
- (modified) clang/lib/AST/Interp/Integral.h (+18-1) 
- (modified) clang/lib/AST/Interp/Interp.cpp (+17) 
- (modified) clang/lib/AST/Interp/Interp.h (+66) 
- (added) clang/lib/AST/Interp/InterpBitcast.cpp (+482) 
- (modified) clang/lib/AST/Interp/Opcodes.td (+17) 
- (modified) clang/lib/AST/Interp/PrimType.h (+4) 
- (added) clang/test/AST/Interp/builtin-bit-cast.cpp (+683) 
- (modified) clang/test/AST/Interp/literals.cpp (+5) 


``diff
diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..5a188b583022bda 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -74,6 +74,7 @@ add_clang_library(clangAST
   Interp/Frame.cpp
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
+  Interp/InterpBitcast.cpp
   Interp/Floating.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
diff --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index c3ed3d61f76ca1c..d395264ab2de448 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -9,14 +9,15 @@
 #ifndef LLVM_CLANG_AST_INTERP_BOOLEAN_H
 #define LLVM_CLANG_AST_INTERP_BOOLEAN_H
 
-#include 
-#include 
 #include "Integral.h"
 #include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/ComparisonCategories.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -65,6 +66,9 @@ class Boolean final {
   Boolean toUnsigned() const { return *this; }
 
   constexpr static unsigned bitWidth() { return 1; }
+  constexpr static unsigned objectReprBits() { return 8; }
+  constexpr static unsigned valueReprBytes(const ASTContext &Ctx) { return 1; }
+
   bool isZero() const { return !V; }
   bool isMin() const { return isZero(); }
 
@@ -106,6 +110,13 @@ class Boolean final {
 return Boolean(!Value.isZero());
   }
 
+  static Boolean bitcastFromMemory(const std::byte *Buff) {
+bool Val = static_cast(*Buff);
+return Boolean(Val);
+  }
+
+  void bitcastToMemory(std::byte *Buff) { std::memcpy(Buff, &V, sizeof(V)); }
+
   static Boolean zero() { return from(false); }
 
   template 
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3cf8bf874b1d210..8cc010d6f100ccb 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -67,6 +67,74 @@ template  class OptionScope final {
 } // namespace interp
 } // namespace clang
 
+//  This function is constexpr if and only if To, From, and the types of
+//  all subobjects of To and From are types T such that...
+//  (3.1) - is_union_v is false;
+//  (3.2) - is_pointer_v is false;
+//  (3.3) - is_member_pointer_v is false;
+//  (3.4) - is_volatile_v is false; and
+//  (3.5) - T has no non-static data members of reference type
+template 
+bool ByteCodeExprGen::emitBuiltinBitCast(const CastExpr *E) {
+  const Expr *SubExpr = E->getSubExpr();
+  QualType FromType = SubExpr->getType();
+  QualType ToType = E->getType();
+  std::optional ToT = classify(ToType);
+
+  // FIXME: This is wrong. We need to do the bitcast and then
+  //   throw away the result, so we still get the diagnostics.
+  if (DiscardResult)
+return this->discard(SubExpr);
+
+  if (ToType->isNullPtrType()) {
+if (!this->discard(SubExpr))
+  return false;
+
+return this->emitNullPtr(E);
+  }
+
+  if (FromType->isNullPtrType() && ToT) {
+if (!this->discard(SubExpr))
+  return false;
+
+return visitZeroInitializer(ToType, E);
+  }
+  assert(!ToType->isReferenceType());
+
+  // Get a pointer to the value-to-cast on the stack.
+  if (!this->visit(SubExpr))
+return false;
+
+  if (!ToT || ToT == PT_Ptr) {
+// Conversion to an array or record type.
+return this->emitBitCastPtr(E);
+  }
+
+  assert(ToT);
+
+  // Conversion to a primitive type. FromType can be another
+  // primitive type, or a record/array.
+  //
+  // Same thing for floats, but we need the target
+  // semantics here.
+  if (ToT == PT_Float) {
+const auto *TargetSemantics = &Ctx.getFloatSemantics(ToType);
+CharUnits FloatSize = Ctx.getASTContext().getTypeSizeInChars(ToType);
+return this-

[clang] [OpenMP] Prevent AMDGPU from overriding visibility on DT_nohost variables (PR #68264)

2023-10-05 Thread Jon Chesterfield via cfe-commits

https://github.com/JonChesterfield commented:

This stuff looks very cuda/opencl specific. It's definitely surprising for C++ 
code. Do we need it for openmp? If not it seems better to guard the hack with 
visibility behind if (hip)

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


[clang] [Clang] Fix constant evaluating a captured variable in a lambda (PR #68090)

2023-10-05 Thread via cfe-commits

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


[clang] 49666ec - [Clang] Fix constant evaluating a captured variable in a lambda (#68090)

2023-10-05 Thread via cfe-commits

Author: cor3ntin
Date: 2023-10-05T10:17:50+02:00
New Revision: 49666ec0386174b9fcf637560951b8ee29ca82c7

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

LOG: [Clang] Fix constant evaluating a captured variable in a lambda (#68090)

with an explicit parameter.

We tried to read a pointer to a non-existent `This` APValue when
constant-evaluating an explicit object lambda call operator (the `this`
pointer is never set in explicit object member functions)

Fixes #68070

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d0e27de743604da..5a33e918db8e8c0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8370,7 +8370,13 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, 
const VarDecl *VD) {
 
 if (auto *FD = Info.CurrentCall->LambdaCaptureFields.lookup(VD)) {
   // Start with 'Result' referring to the complete closure object...
-  Result = *Info.CurrentCall->This;
+  if (auto *MD = cast(Info.CurrentCall->Callee);
+  MD->isExplicitObjectMemberFunction()) {
+APValue *RefValue =
+Info.getParamSlot(Info.CurrentCall->Arguments, 
MD->getParamDecl(0));
+Result.setFrom(Info.Ctx, *RefValue);
+  } else
+Result = *Info.CurrentCall->This;
   // ... then update it to refer to the field of the closure object
   // that represents the capture.
   if (!HandleLValueMember(Info, E, Result, FD))

diff  --git a/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp
index 44de0d711674ba8..9dbea17dd2cae34 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp
@@ -54,3 +54,21 @@ consteval void test() {
 static_assert(*s == 42);
 static_assert((s << 11) == 31);
 }
+
+namespace GH68070 {
+
+constexpr auto f = [x = 3](this Self&& self) {
+return x;
+};
+
+auto g = [x = 3](this Self&& self) {
+return x;
+};
+
+int test() {
+  constexpr int a = f();
+  static_assert(a == 3);
+  return f() + g();
+}
+
+}



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


[clang] [Clang] Fix constant evaluating a captured variable in a lambda (PR #68090)

2023-10-05 Thread via cfe-commits

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


[clang] 8902f12 - [clang-format][doc] Update the Linux kernel coding style URL

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

Author: Owen Pan
Date: 2023-10-05T01:18:49-07:00
New Revision: 8902f12e61aa2d3053ad4d536e36569fc8bc9512

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

LOG: [clang-format][doc] Update the Linux kernel coding style URL

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 5ebb8c82b30495a..c5c72c68ee9b800 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5730,7 +5730,7 @@ Examples
 
 
 A style similar to the `Linux Kernel style
-`_:
+`_:
 
 .. code-block:: yaml
 



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


[clang] [Clang] Handle consteval expression in array bounds expressions (PR #66222)

2023-10-05 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/66222

>From dc95c839c104a0af50da1466e7249bde306bd662 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 13 Sep 2023 17:36:39 +0200
Subject: [PATCH 1/8] [Clang] Handle consteval expression in array bounds
 expressions

The bounds of a c++ array is a _constant-expression_.
And in C++ it is also a constant expression.

But we also support VLAs, ie arrays with non-constant bounds.

We need to take care to handle the case of a consteval function
(which are specified to be only immediately called in
non-constant contexts) that appear in arrays bounds.

This introduces `Sema::isAlwayConstantEvaluatedContext`,
and a flag in ExpressionEvaluationContextRecord, such that
immediate functions in array bounds are always immediately invoked.

Sema had both `isConstantEvaluatedContext` and
`isConstantEvaluated`, so I took the opportunity to cleanup that.

The change in `TimeProfilerTest.cpp` is an unfortunate
manifestation of the problem that #66203 seeks to address.

Fixes #65520
---
 clang/docs/ReleaseNotes.rst  |  3 +
 clang/include/clang/Parse/Parser.h   |  1 +
 clang/include/clang/Sema/Sema.h  | 60 +++-
 clang/lib/Parse/ParseDecl.cpp|  2 +-
 clang/lib/Parse/ParseExpr.cpp|  9 +++
 clang/lib/Sema/SemaCUDA.cpp  |  2 +-
 clang/lib/Sema/SemaChecking.cpp  | 55 ++
 clang/lib/Sema/SemaExpr.cpp  |  4 +-
 clang/lib/Sema/TreeTransform.h   |  3 +
 clang/test/SemaCXX/cxx2a-consteval.cpp   | 21 +--
 clang/unittests/Support/TimeProfilerTest.cpp |  1 +
 11 files changed, 100 insertions(+), 61 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2362e479dfbbc5a..e498969b2c46bfb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -434,6 +434,9 @@ Bug Fixes to C++ Support
 - Fix crash caused by a spaceship operator returning a comparision category by
   reference. Fixes:
   (`#64162 `_)
+- Fix a crash when calling a consteval function in an expression used as
+  the size of an array.
+  (`#65520 `_)
 
 - Clang no longer tries to capture non-odr-used variables that appear
   in the enclosing expression of a lambda expression with a noexcept specifier.
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 0e969f341bbe19f..79ac622fd03e24e 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1766,6 +1766,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstantExpressionInExprEvalContext(
   TypeCastState isTypeCast = NotTypeCast);
   ExprResult ParseConstantExpression();
+  ExprResult ParseArrayBoundExpression();
   ExprResult ParseCaseExpression(SourceLocation CaseLoc);
   ExprResult ParseConstraintExpression();
   ExprResult
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 79361aa19a567b6..a6d0d1a2152c0ec 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1062,20 +1062,6 @@ class Sema final {
 }
   };
 
-  /// Whether the AST is currently being rebuilt to correct immediate
-  /// invocations. Immediate invocation candidates and references to consteval
-  /// functions aren't tracked when this is set.
-  bool RebuildingImmediateInvocation = false;
-
-  /// Used to change context to isConstantEvaluated without pushing a heavy
-  /// ExpressionEvaluationContextRecord object.
-  bool isConstantEvaluatedOverride;
-
-  bool isConstantEvaluated() const {
-return ExprEvalContexts.back().isConstantEvaluated() ||
-   isConstantEvaluatedOverride;
-  }
-
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -1361,6 +1347,10 @@ class Sema final {
 
 bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false;
 
+// We are in a constant context, but we also allow
+// non constant expressions, for example for array bounds (which may be 
VLAs).
+bool InConditionallyConstantEvaluateContext = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -9878,30 +9868,44 @@ class Sema final {
   /// diagnostics that will be suppressed.
   std::optional isSFINAEContext() const;
 
-  /// Determines whether we are currently in a context that
-  /// is not evaluated as per C++ [expr] p5.
-  bool isUnevaluatedContext() const {
+  /// Whether the AST is currently being rebuilt to correct immediate
+  /// invocations. Immediate invocation candidates and references to consteval
+  /// functions

[clang] [MLIR][NVGPU] Introduce `nvgpu.wargroup.mma.store` Op for Hopper GPUs (PR #65441)

2023-10-05 Thread Guray Ozen via cfe-commits


@@ -53,6 +55,16 @@ static Value truncToI32(ConversionPatternRewriter &rewriter, 
Location loc,
   return rewriter.create(loc, rewriter.getI32Type(), value);
 }
 
+/// Returns warp-size as a value.
+static Value getWarpSizeValue(ImplicitLocOpBuilder &b) {

grypp wrote:

it was a bad idea to put a singleton. I thought with my previous compiler's 
logic, my bad. removed

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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-05 Thread via cfe-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/65246

>From 57219322f804a099c66c7ea8f4dd069fdd907e21 Mon Sep 17 00:00:00 2001
From: "kasuga.ryotaro" 
Date: Wed, 30 Aug 2023 13:26:31 +0900
Subject: [PATCH] [Clang] Fix missing diagnostic for non-standard layout type
 in `offsetof`

Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
diagnostic if you use `offsetof` on non-standard layout types in any
other contexts
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/Sema/SemaExpr.cpp   |  9 ++-
 clang/test/SemaCXX/class-layout.cpp   | 62 +--
 clang/test/SemaCXX/ms_struct.cpp  |  6 +-
 clang/test/SemaCXX/offsetof.cpp   |  9 +--
 libcxx/include/__type_traits/datasizeof.h |  5 ++
 .../non_trivial_copy_move_ABI.pass.cpp|  2 +-
 .../pairs.pair/trivial_copy_move_ABI.pass.cpp |  1 +
 8 files changed, 52 insertions(+), 44 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2362e479dfbbc5a..f67ceb1d6173c93 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,8 @@ Improvements to Clang's diagnostics
 source:1:24: note: expression evaluates to ''\n' (0x0A, 10) == U'🌍' 
(0x1F30D, 127757)'
 1 | static_assert("A\n"[1] == U'🌍');
   |   ~^~~~
+- Clang now always diagnoses when using non-standard layout types in 
``offsetof`` .
+  (`#64619: `_)
 
 Bug Fixes in This Version
 -
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 304aa7d105e269b..b86f3c004403afe 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16796,12 +16796,11 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation 
BuiltinLoc,
 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
 : diag::ext_offsetof_non_pod_type;
 
-  if (!IsSafe && !DidWarnAboutNonPOD &&
-  DiagRuntimeBehavior(BuiltinLoc, nullptr,
-  PDiag(DiagID)
-  << SourceRange(Components[0].LocStart, OC.LocEnd)
-  << CurrentType))
+  if (!IsSafe && !DidWarnAboutNonPOD && !isUnevaluatedContext()) {
+Diag(BuiltinLoc, DiagID)
+<< SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
 DidWarnAboutNonPOD = true;
+  }
 }
 
 // Look for the field.
diff --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 9782ff08100b2d6..22fb34b8419c583 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,34 +1,34 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-
-// RUN: %clang_cc1 -fex

[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)

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

tbaederr wrote:

Ping

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-05 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/68276

>From 3f5fc972933535ba57c1a833fbd329f81c365f91 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Thu, 5 Oct 2023 02:39:12 +0200
Subject: [PATCH] [Sema] Add check for bitfield assignments to integral types

We noticed that clang does not check for bitfield assignment widths,
while gcc does check this.

gcc produced a warning like so for it's -Wconversion flag:

$ gcc -Wconversion -c test.c
test.c: In function 'foo':
test.c:10:15: warning: conversion from 'int' to 'signed char:7' may
change value [-Wconversion]
   10 |  vxx.bf = x; // no warning
  |   ^

This change simply adds this for integral types under the -Wconversion
compiler option.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +++
 clang/lib/Sema/SemaChecking.cpp   | 10 +++
 clang/test/SemaCXX/bitfield-width.c   | 26 +++
 3 files changed, 39 insertions(+)
 create mode 100644 clang/test/SemaCXX/bitfield-width.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 217309c4ecbca52..a66fd57054a1ce7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6165,6 +6165,9 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+  "bit-field %0 is not wide enough to store type of %1 ">,
+  InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3b0cc154c2e46ab..eb567bc4935e768 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14300,6 +14300,16 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
 << BitsNeeded << ED << WidthExpr->getSourceRange();
   }
+} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
+  TypeInfo TI = S.Context.getTypeInfo(OriginalInit->getType());
+  if (TI.Width > FieldWidth) {
+Expr *WidthExpr = Bitfield->getBitWidth();
+S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
+<< Bitfield << OriginalInit->getType();
+S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
+<< TI.Width << OriginalInit->getType()
+<< WidthExpr->getSourceRange();
+  }
 }
 
 return false;
diff --git a/clang/test/SemaCXX/bitfield-width.c 
b/clang/test/SemaCXX/bitfield-width.c
new file mode 100644
index 000..c9856f53922c490
--- /dev/null
+++ b/clang/test/SemaCXX/bitfield-width.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s
+
+typedef struct _xx {
+ int bf:9; // expected-note{{widen this field to 32 bits to store all 
values of 'int'}}
+ // expected-note@-1{{widen this field to 16 bits to store all values of 
'short'}}
+ // expected-note@-3{{widen this field to 32 bits to store all values of 
'int'}}
+ } xx, *pxx; 
+
+ xx vxx;
+
+ void foo1(int x) { 
+ vxx.bf = x; // expected-warning{{bit-field 'bf' is not wide enough to 
store type of 'int'}}
+ } 
+ void foo2(short x) { 
+ vxx.bf = x; // expected-warning{{bit-field 'bf' is not wide enough to 
store type of 'short'}}
+ } 
+ void foo3(char x) { 
+ vxx.bf = x; // no warning expected
+ } 
+ void foo5(void * x) { 
+ vxx.bf = (int)x; // expected-warning{{cast to smaller integer type 'int' 
from 'void *'}}
+ // expected-warning@-1{{bit-field 'bf' is not wide enough to store type 
of 'int'}}
+ } 
+ int fee(void) {
+ return 0;
+ }

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


[clang] [Support] Deprecate system_endianness (PR #68279)

2023-10-05 Thread Markus Böck via cfe-commits

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


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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-05 Thread via cfe-commits

vabridgers wrote:

@shafik , I updated the check into -Wconversion. Temporarily addressed the CI 
failure (to get a passing baseline). Awaiting further review comments. Thank 
you.

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


[clang] 3116d60 - [Lex] Introduce Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-10-05T11:04:07+02:00
New Revision: 3116d60494f219bfcb284d05d9ebed5b6c196ca5

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

LOG: [Lex] Introduce Preprocessor::LexTokensUntilEOF()

This new method repeatedly calls Lex() until end of file is reached
and optionally fills a std::vector of Tokens. Use it in Clang's unit
tests to avoid quite some code duplication.

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

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/Preprocessor.cpp
clang/unittests/Analysis/MacroExpansionContextTest.cpp
clang/unittests/Basic/SourceManagerTest.cpp
clang/unittests/Lex/LexerTest.cpp
clang/unittests/Lex/ModuleDeclStateTest.cpp
clang/unittests/Lex/PPCallbacksTest.cpp
clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
clang/unittests/Lex/PPDependencyDirectivesTest.cpp
clang/unittests/Lex/PPMemoryAllocationsTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index e88164f196c1f7c..a8d2599d94ebc66 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1722,6 +1722,9 @@ class Preprocessor {
   /// Lex the next token for this preprocessor.
   void Lex(Token &Result);
 
+  /// Lex all tokens for this preprocessor until (and excluding) end of file.
+  void LexTokensUntilEOF(std::vector *Tokens = nullptr);
+
   /// Lex a token, forming a header-name token if possible.
   bool LexHeaderName(Token &Result, bool AllowMacroExpansion = true);
 

diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 73c37bc5161c4b6..b82dd1fe49c7040 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -998,6 +998,17 @@ void Preprocessor::Lex(Token &Result) {
   }
 }
 
+void Preprocessor::LexTokensUntilEOF(std::vector *Tokens) {
+  while (1) {
+Token Tok;
+Lex(Tok);
+if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+  break;
+if (Tokens != nullptr)
+  Tokens->push_back(Tok);
+  }
+}
+
 /// Lex a header-name token (including one formed from header-name-tokens if
 /// \p AllowConcatenation is \c true).
 ///

diff  --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp 
b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 5c694c836a48814..54b209e7b28c185 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -73,12 +73,7 @@ class MacroExpansionContextTest : public ::testing::Test {
 // Lex source text.
 PP.EnterMainSourceFile();
 
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 // Callbacks have been executed at this point.
 return Ctx;

diff  --git a/clang/unittests/Basic/SourceManagerTest.cpp 
b/clang/unittests/Basic/SourceManagerTest.cpp
index f451e43bb53d78e..cd2bd12106b0edb 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -138,13 +138,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF(&toks);
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(3U, toks.size());
@@ -195,13 +189,7 @@ TEST_F(SourceManagerTest, 
isBeforeInTranslationUnitWithTokenSplit) {
   llvm::SmallString<8> Scratch;
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF(&toks);
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(4U, toks.size()) << "a >> b c";
@@ -452,13 +440,7 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF(&toks);
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(4U, toks.size());
@@ -574,13 +556,7 @@ TEST_F(SourceManagerTest, 
isBeforeInTranslationUnitWithMacroInInclude) {
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF(&toks);
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(0U, toks.size());

diff  --git a/clang/unittests/Lex/LexerTest.cpp 
b/clang/unittests/Lex/LexerTest.cpp
index 8932265674a59a1..47aa2c131a

[PATCH] D158413: [Lex] Introduce Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3116d60494f2: [Lex] Introduce 
Preprocessor::LexTokensUntilEOF() (authored by Hahnfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158413

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Preprocessor.cpp
  clang/unittests/Analysis/MacroExpansionContextTest.cpp
  clang/unittests/Basic/SourceManagerTest.cpp
  clang/unittests/Lex/LexerTest.cpp
  clang/unittests/Lex/ModuleDeclStateTest.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp
  clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp
  clang/unittests/Lex/PPMemoryAllocationsTest.cpp

Index: clang/unittests/Lex/PPMemoryAllocationsTest.cpp
===
--- clang/unittests/Lex/PPMemoryAllocationsTest.cpp
+++ clang/unittests/Lex/PPMemoryAllocationsTest.cpp
@@ -75,12 +75,7 @@
   PP.Initialize(*Target);
   PP.EnterMainSourceFile();
 
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-  }
+  PP.LexTokensUntilEOF();
 
   size_t NumAllocated = PP.getPreprocessorAllocator().getBytesAllocated();
   float BytesPerDefine = float(NumAllocated) / float(NumMacros);
Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- clang/unittests/Lex/PPDependencyDirectivesTest.cpp
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -133,12 +133,7 @@
   SmallVector IncludedFiles;
   PP.addPPCallbacks(std::make_unique(PP, IncludedFiles));
   PP.EnterMainSourceFile();
-  while (true) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-  }
+  PP.LexTokensUntilEOF();
 
   SmallVector IncludedFilesSlash;
   for (StringRef IncludedFile : IncludedFiles)
Index: clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
===
--- clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
+++ clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
@@ -87,13 +87,7 @@
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF(&toks);
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(10U, toks.size());
Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -229,13 +229,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 // Callbacks have been executed at this point -- return filename range.
 return Callbacks;
@@ -259,13 +253,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 return Callbacks->Results;
   }
@@ -290,12 +278,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 return Callbacks->Marks;
   }
@@ -334,12 +317,7 @@
 
 // Lex source text.
 PP.EnterMainSourceFile();
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 PragmaOpenCLExtensionCallbacks::CallbackParameters RetVal = {
   Callbacks->Name,
@@ -477,12 +455,7 @@
 
   // Lex source text.
   PP.EnterMainSourceFile();
-  while (true) {
-Token Tok;
-PP.Lex(Tok);
-if (Tok.is(tok::eof))
-  break;
-  }
+  PP.LexTokensUntilEOF();
 
   ASSERT_EQ(1u, Callbacks->NumCalls);
   ASSERT_EQ(0u, DiagConsumer->getNumErrors());
Index: clang/unittests/Lex/ModuleDeclStateTest.cpp
===
--- clang/unittests/Lex/ModuleDeclStateTest.cpp
+++ clang/unittests/Lex/ModuleDeclStateTest.cpp
@@ -90,12 +90,7 @@
 PP.addPPCallbacks(std::move(C));
 PP.EnterMainSourceFile();
 
-while (1) {
-  Token tok;
-  PP.Lex(tok);
-  if (tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
   }
 
   FileSystemOptions FileMgrOpts;
Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -74,13 +74,7 @@
 PP = CreatePP(Source, ModLoader);
 
 std::vector toks;
-while (1) {
-  Token tok;
- 

[clang] [clang][driver] Prevent clang picking the system headers when started via a symlink (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

https://github.com/ilg-ul updated 
https://github.com/llvm/llvm-project/pull/68091

>From f3812174546270051c4a2903b9a99408bf5b7ba0 Mon Sep 17 00:00:00 2001
From: Liviu Ionescu 
Date: Tue, 3 Oct 2023 14:07:48 +0300
Subject: [PATCH 1/4] [clang][driver] Use platform specific calls to get the
 executable absolute path (#66704)

In clang/tools/driver/driver.cpp, the function SetInstallDir() tries to 
determine the
location where the toolchain is installed, basically by taking the parent 
folder of
the executable absolute path. This is not correct when the compiler is invoked
via a link, since it returns the parent of the link.

This leads to subtle errors, for example on macOS it silently picks the wrong
system headers.
---
 clang/tools/driver/driver.cpp | 61 +++
 1 file changed, 61 insertions(+)

diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 531b5b4a61c1804..c8ad167cba0a423 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -57,6 +57,15 @@ using namespace clang;
 using namespace clang::driver;
 using namespace llvm::opt;
 
+#if defined(__linux__)
+#include 
+#elif defined(__APPLE__)
+#include 
+#include 
+#elif defined(__MINGW32__)
+#include 
+#endif
+
 std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
   if (!CanonicalPrefixes) {
 SmallString<128> ExecutablePath(Argv0);
@@ -331,6 +340,56 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   // path being a symlink.
   SmallString<128> InstalledPath(argv[0]);
 
+#if defined(__linux__)
+
+  char ProcessAbsolutePath[PATH_MAX];
+
+  int len = readlink("/proc/self/exe", ProcessAbsolutePath,
+ sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: readlink(\"/proc/self/exe\") failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#elif defined(__APPLE__)
+
+  // The size must be higher than PROC_PIDPATHINFO_SIZE, otherwise the call
+  // fails with ENOMEM (12) - Cannot allocate memory.
+  // https://opensource.apple.com/source/Libc/Libc-498/darwin/libproc.c
+  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE+1];
+
+  int len = proc_pidpath(getpid(), ProcessAbsolutePath,
+ sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: proc_pidpath() failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#elif defined(__MINGW32__)
+
+  char ProcessAbsolutePath[PATH_MAX];
+
+  len = GetModuleFileName(NULL, ProcessAbsolutePath,
+  sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: GetModuleFileName() failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#else
+
   // Do a PATH lookup, if there are no directory components.
   if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
 if (llvm::ErrorOr Tmp = llvm::sys::findProgramByName(
@@ -341,6 +400,8 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   if (CanonicalPrefixes)
 llvm::sys::fs::make_absolute(InstalledPath);
 
+#endif
+
   StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
   if (llvm::sys::fs::exists(InstalledPathParent))
 TheDriver.setInstalledDir(InstalledPathParent);

>From eb7b122d5e6ce160d3f0880aac44a2df720d182f Mon Sep 17 00:00:00 2001
From: Liviu Ionescu 
Date: Tue, 3 Oct 2023 14:16:30 +0300
Subject: [PATCH 2/4] clang-format driver.cpp patch

---
 clang/tools/driver/driver.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index c8ad167cba0a423..45e1469aafca95e 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -346,7 +346,7 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
 
   int len = readlink("/proc/self/exe", ProcessAbsolutePath,
  sizeof(ProcessAbsolutePath) - 1);
-  if ( len <= 0 ) {
+  if (len <= 0) {
 llvm::errs() << "Internal error: readlink(\"/proc/self/exe\") failed with "
  << strerror(errno) << "\n";
 exit(1);
@@ -360,11 +360,11 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   // The size must be higher than PROC_PIDPATHINFO_SIZE, otherwise the call
   // fails with ENOMEM (12) - Cannot allocate memory.
   // https://opensource.apple.com/source/Libc/Libc-498/darwin/libproc.c
-  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE+1];
+  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE + 1];
 
   int len = proc_pidpath(getpid(), ProcessAbsolutePath,
  sizeof(ProcessAbsolutePath) - 1);
-  if ( len <= 0 ) {
+  if (len <= 0) {
 llvm::errs() << "Inte

[clang] [clang][driver] Prevent clang picking the system headers when started via a symlink (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

https://github.com/ilg-ul updated 
https://github.com/llvm/llvm-project/pull/68091

>From f3812174546270051c4a2903b9a99408bf5b7ba0 Mon Sep 17 00:00:00 2001
From: Liviu Ionescu 
Date: Tue, 3 Oct 2023 14:07:48 +0300
Subject: [PATCH 1/5] [clang][driver] Use platform specific calls to get the
 executable absolute path (#66704)

In clang/tools/driver/driver.cpp, the function SetInstallDir() tries to 
determine the
location where the toolchain is installed, basically by taking the parent 
folder of
the executable absolute path. This is not correct when the compiler is invoked
via a link, since it returns the parent of the link.

This leads to subtle errors, for example on macOS it silently picks the wrong
system headers.
---
 clang/tools/driver/driver.cpp | 61 +++
 1 file changed, 61 insertions(+)

diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 531b5b4a61c1804..c8ad167cba0a423 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -57,6 +57,15 @@ using namespace clang;
 using namespace clang::driver;
 using namespace llvm::opt;
 
+#if defined(__linux__)
+#include 
+#elif defined(__APPLE__)
+#include 
+#include 
+#elif defined(__MINGW32__)
+#include 
+#endif
+
 std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
   if (!CanonicalPrefixes) {
 SmallString<128> ExecutablePath(Argv0);
@@ -331,6 +340,56 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   // path being a symlink.
   SmallString<128> InstalledPath(argv[0]);
 
+#if defined(__linux__)
+
+  char ProcessAbsolutePath[PATH_MAX];
+
+  int len = readlink("/proc/self/exe", ProcessAbsolutePath,
+ sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: readlink(\"/proc/self/exe\") failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#elif defined(__APPLE__)
+
+  // The size must be higher than PROC_PIDPATHINFO_SIZE, otherwise the call
+  // fails with ENOMEM (12) - Cannot allocate memory.
+  // https://opensource.apple.com/source/Libc/Libc-498/darwin/libproc.c
+  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE+1];
+
+  int len = proc_pidpath(getpid(), ProcessAbsolutePath,
+ sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: proc_pidpath() failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#elif defined(__MINGW32__)
+
+  char ProcessAbsolutePath[PATH_MAX];
+
+  len = GetModuleFileName(NULL, ProcessAbsolutePath,
+  sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: GetModuleFileName() failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#else
+
   // Do a PATH lookup, if there are no directory components.
   if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
 if (llvm::ErrorOr Tmp = llvm::sys::findProgramByName(
@@ -341,6 +400,8 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   if (CanonicalPrefixes)
 llvm::sys::fs::make_absolute(InstalledPath);
 
+#endif
+
   StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
   if (llvm::sys::fs::exists(InstalledPathParent))
 TheDriver.setInstalledDir(InstalledPathParent);

>From eb7b122d5e6ce160d3f0880aac44a2df720d182f Mon Sep 17 00:00:00 2001
From: Liviu Ionescu 
Date: Tue, 3 Oct 2023 14:16:30 +0300
Subject: [PATCH 2/5] clang-format driver.cpp patch

---
 clang/tools/driver/driver.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index c8ad167cba0a423..45e1469aafca95e 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -346,7 +346,7 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
 
   int len = readlink("/proc/self/exe", ProcessAbsolutePath,
  sizeof(ProcessAbsolutePath) - 1);
-  if ( len <= 0 ) {
+  if (len <= 0) {
 llvm::errs() << "Internal error: readlink(\"/proc/self/exe\") failed with "
  << strerror(errno) << "\n";
 exit(1);
@@ -360,11 +360,11 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   // The size must be higher than PROC_PIDPATHINFO_SIZE, otherwise the call
   // fails with ENOMEM (12) - Cannot allocate memory.
   // https://opensource.apple.com/source/Libc/Libc-498/darwin/libproc.c
-  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE+1];
+  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE + 1];
 
   int len = proc_pidpath(getpid(), ProcessAbsolutePath,
  sizeof(ProcessAbsolutePath) - 1);
-  if ( len <= 0 ) {
+  if (len <= 0) {
 llvm::errs() << "Inte

[clang] [clang][driver] Prevent clang picking the system headers when started via a symlink (PR #68091)

2023-10-05 Thread via cfe-commits

nolange wrote:

> @nolange, English is not my first language, and I know sometimes I'm very 
> confusing. In my understanding, the title suggest that if clang is not 
> invoked directly but via a symlink, it does not behave correctly, i.e. 
> instead of picking the headers from the folders where clang is installed, it 
> picks the system headers. This is documented with examples in the bug report.

Yes, my problem with the title is, that it sound like you want to change the 
way how clang should behave when using symlinks.

> 
> If this is not what the title reads, please suggest a better phrasing.

Here is how I would phrase it:
"Fix an issue where clang does not correctly resolve the system header if 
invoked via symlink" (on MacOS)

Main point being that you fix a bug and don't want to change the usual behavior 
(like gcc, like it works on Linux),
and that you don't **prevent** clang picking up the system headers but **fix** 
picking up the system headers .
This is how I understand the Bug Report and the discussion.

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


[clang] [clang][driver] Prevent clang picking the system headers when started via a symlink (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

https://github.com/ilg-ul updated 
https://github.com/llvm/llvm-project/pull/68091

>From f3812174546270051c4a2903b9a99408bf5b7ba0 Mon Sep 17 00:00:00 2001
From: Liviu Ionescu 
Date: Tue, 3 Oct 2023 14:07:48 +0300
Subject: [PATCH 1/6] [clang][driver] Use platform specific calls to get the
 executable absolute path (#66704)

In clang/tools/driver/driver.cpp, the function SetInstallDir() tries to 
determine the
location where the toolchain is installed, basically by taking the parent 
folder of
the executable absolute path. This is not correct when the compiler is invoked
via a link, since it returns the parent of the link.

This leads to subtle errors, for example on macOS it silently picks the wrong
system headers.
---
 clang/tools/driver/driver.cpp | 61 +++
 1 file changed, 61 insertions(+)

diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 531b5b4a61c1804..c8ad167cba0a423 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -57,6 +57,15 @@ using namespace clang;
 using namespace clang::driver;
 using namespace llvm::opt;
 
+#if defined(__linux__)
+#include 
+#elif defined(__APPLE__)
+#include 
+#include 
+#elif defined(__MINGW32__)
+#include 
+#endif
+
 std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
   if (!CanonicalPrefixes) {
 SmallString<128> ExecutablePath(Argv0);
@@ -331,6 +340,56 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   // path being a symlink.
   SmallString<128> InstalledPath(argv[0]);
 
+#if defined(__linux__)
+
+  char ProcessAbsolutePath[PATH_MAX];
+
+  int len = readlink("/proc/self/exe", ProcessAbsolutePath,
+ sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: readlink(\"/proc/self/exe\") failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#elif defined(__APPLE__)
+
+  // The size must be higher than PROC_PIDPATHINFO_SIZE, otherwise the call
+  // fails with ENOMEM (12) - Cannot allocate memory.
+  // https://opensource.apple.com/source/Libc/Libc-498/darwin/libproc.c
+  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE+1];
+
+  int len = proc_pidpath(getpid(), ProcessAbsolutePath,
+ sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: proc_pidpath() failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#elif defined(__MINGW32__)
+
+  char ProcessAbsolutePath[PATH_MAX];
+
+  len = GetModuleFileName(NULL, ProcessAbsolutePath,
+  sizeof(ProcessAbsolutePath) - 1);
+  if ( len <= 0 ) {
+llvm::errs() << "Internal error: GetModuleFileName() failed with "
+ << strerror(errno) << "\n";
+exit(1);
+  }
+
+  ProcessAbsolutePath[len] = 0;
+  InstalledPath = ProcessAbsolutePath;
+
+#else
+
   // Do a PATH lookup, if there are no directory components.
   if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
 if (llvm::ErrorOr Tmp = llvm::sys::findProgramByName(
@@ -341,6 +400,8 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   if (CanonicalPrefixes)
 llvm::sys::fs::make_absolute(InstalledPath);
 
+#endif
+
   StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
   if (llvm::sys::fs::exists(InstalledPathParent))
 TheDriver.setInstalledDir(InstalledPathParent);

>From eb7b122d5e6ce160d3f0880aac44a2df720d182f Mon Sep 17 00:00:00 2001
From: Liviu Ionescu 
Date: Tue, 3 Oct 2023 14:16:30 +0300
Subject: [PATCH 2/6] clang-format driver.cpp patch

---
 clang/tools/driver/driver.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index c8ad167cba0a423..45e1469aafca95e 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -346,7 +346,7 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
 
   int len = readlink("/proc/self/exe", ProcessAbsolutePath,
  sizeof(ProcessAbsolutePath) - 1);
-  if ( len <= 0 ) {
+  if (len <= 0) {
 llvm::errs() << "Internal error: readlink(\"/proc/self/exe\") failed with "
  << strerror(errno) << "\n";
 exit(1);
@@ -360,11 +360,11 @@ static void SetInstallDir(SmallVectorImpl 
&argv,
   // The size must be higher than PROC_PIDPATHINFO_SIZE, otherwise the call
   // fails with ENOMEM (12) - Cannot allocate memory.
   // https://opensource.apple.com/source/Libc/Libc-498/darwin/libproc.c
-  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE+1];
+  char ProcessAbsolutePath[PROC_PIDPATHINFO_SIZE + 1];
 
   int len = proc_pidpath(getpid(), ProcessAbsolutePath,
  sizeof(ProcessAbsolutePath) - 1);
-  if ( len <= 0 ) {
+  if (len <= 0) {
 llvm::errs() << "Inte

[clang] [Clang][Driver] Add new flags to control IR verification (PR #68172)

2023-10-05 Thread Florian Hahn via cfe-commits


@@ -5150,9 +5150,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   const bool IsAssertBuild = true;
 #endif
 
-  // Disable the verification pass in -asserts builds.

fhahn wrote:

Hmm, I might be missing something here, but doesn't this disable the verifier 
for builds without assertions?

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


[clang] [clang][driver] Fix an issue where clang does not correctly resolve the system header if invoked via symlink (on MacOS) (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

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


[clang] [Clang] Handle consteval expression in array bounds expressions (PR #66222)

2023-10-05 Thread via cfe-commits

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


[clang] c72d3a0 - [Clang] Handle consteval expression in array bounds expressions (#66222)

2023-10-05 Thread via cfe-commits

Author: cor3ntin
Date: 2023-10-05T11:36:27+02:00
New Revision: c72d3a0966afd2dcb4421dde922c0faf06d65c0e

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

LOG: [Clang] Handle consteval expression in array bounds expressions (#66222)

The bounds of a c++ array is a _constant-expression_. And in C++ it is
also a constant expression.

But we also support VLAs, ie arrays with non-constant bounds.

We need to take care to handle the case of a consteval function (which
are specified to be only immediately called in non-constant contexts)
that appear in arrays bounds.

This introduces `Sema::isAlwayConstantEvaluatedContext`, and a flag in
ExpressionEvaluationContextRecord, such that immediate functions in
array bounds are always immediately invoked.

Sema had both `isConstantEvaluatedContext` and
`isConstantEvaluated`, so I took the opportunity to cleanup that.

The change in `TimeProfilerTest.cpp` is an unfortunate manifestation of
the problem that #66203 seeks to address.

Fixes #65520

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/unittests/Support/TimeProfilerTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2362e479dfbbc5a..e498969b2c46bfb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -434,6 +434,9 @@ Bug Fixes to C++ Support
 - Fix crash caused by a spaceship operator returning a comparision category by
   reference. Fixes:
   (`#64162 `_)
+- Fix a crash when calling a consteval function in an expression used as
+  the size of an array.
+  (`#65520 `_)
 
 - Clang no longer tries to capture non-odr-used variables that appear
   in the enclosing expression of a lambda expression with a noexcept specifier.

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 0e969f341bbe19f..79ac622fd03e24e 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1766,6 +1766,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstantExpressionInExprEvalContext(
   TypeCastState isTypeCast = NotTypeCast);
   ExprResult ParseConstantExpression();
+  ExprResult ParseArrayBoundExpression();
   ExprResult ParseCaseExpression(SourceLocation CaseLoc);
   ExprResult ParseConstraintExpression();
   ExprResult

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 79361aa19a567b6..1037086d12afb06 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1062,20 +1062,6 @@ class Sema final {
 }
   };
 
-  /// Whether the AST is currently being rebuilt to correct immediate
-  /// invocations. Immediate invocation candidates and references to consteval
-  /// functions aren't tracked when this is set.
-  bool RebuildingImmediateInvocation = false;
-
-  /// Used to change context to isConstantEvaluated without pushing a heavy
-  /// ExpressionEvaluationContextRecord object.
-  bool isConstantEvaluatedOverride;
-
-  bool isConstantEvaluated() const {
-return ExprEvalContexts.back().isConstantEvaluated() ||
-   isConstantEvaluatedOverride;
-  }
-
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -1361,6 +1347,11 @@ class Sema final {
 
 bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false;
 
+// We are in a constant context, but we also allow
+// non constant expressions, for example for array bounds (which may be
+// VLAs).
+bool InConditionallyConstantEvaluateContext = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -9878,30 +9869,44 @@ class Sema final {
   /// diagnostics that will be suppressed.
   std::optional isSFINAEContext() const;
 
-  /// Determines whether we are currently in a context that
-  /// is not evaluated as per C++ [expr] p5.
-  bool isUnevaluatedContext() const {
+  /// Whether the AST is currently being rebuilt to correct immediate
+  /// invocations. Immediate invocation candidates and references to consteval
+  /// functions aren't tracked when this is set.
+  bool RebuildingIm

[clang] [clang][driver] Fix an issue where clang does not correctly resolve the system header if invoked via symlink (on MacOS) (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

ilg-ul wrote:

@nolange, thank you for rephrasing the title.

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

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


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

>From e208c2fc7932d80d441d90bfa0fd949b8910a4c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 11 Jul 2023 13:45:04 +0200
Subject: [PATCH 1/2] Bitcasts

---
 clang/lib/AST/CMakeLists.txt   |   1 +
 clang/lib/AST/Interp/Boolean.h |  15 +-
 clang/lib/AST/Interp/ByteCodeExprGen.cpp   |  71 +++
 clang/lib/AST/Interp/ByteCodeExprGen.h |   1 +
 clang/lib/AST/Interp/Floating.h|  11 +
 clang/lib/AST/Interp/Integral.h|  19 +-
 clang/lib/AST/Interp/Interp.cpp|  17 +
 clang/lib/AST/Interp/Interp.h  |  66 ++
 clang/lib/AST/Interp/InterpBitcast.cpp | 482 +++
 clang/lib/AST/Interp/Opcodes.td|  17 +
 clang/lib/AST/Interp/PrimType.h|   4 +
 clang/test/AST/Interp/builtin-bit-cast.cpp | 683 +
 clang/test/AST/Interp/literals.cpp |   5 +
 13 files changed, 1389 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/AST/Interp/InterpBitcast.cpp
 create mode 100644 clang/test/AST/Interp/builtin-bit-cast.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..5a188b583022bda 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -74,6 +74,7 @@ add_clang_library(clangAST
   Interp/Frame.cpp
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
+  Interp/InterpBitcast.cpp
   Interp/Floating.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
diff --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index c3ed3d61f76ca1c..d395264ab2de448 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -9,14 +9,15 @@
 #ifndef LLVM_CLANG_AST_INTERP_BOOLEAN_H
 #define LLVM_CLANG_AST_INTERP_BOOLEAN_H
 
-#include 
-#include 
 #include "Integral.h"
 #include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/ComparisonCategories.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -65,6 +66,9 @@ class Boolean final {
   Boolean toUnsigned() const { return *this; }
 
   constexpr static unsigned bitWidth() { return 1; }
+  constexpr static unsigned objectReprBits() { return 8; }
+  constexpr static unsigned valueReprBytes(const ASTContext &Ctx) { return 1; }
+
   bool isZero() const { return !V; }
   bool isMin() const { return isZero(); }
 
@@ -106,6 +110,13 @@ class Boolean final {
 return Boolean(!Value.isZero());
   }
 
+  static Boolean bitcastFromMemory(const std::byte *Buff) {
+bool Val = static_cast(*Buff);
+return Boolean(Val);
+  }
+
+  void bitcastToMemory(std::byte *Buff) { std::memcpy(Buff, &V, sizeof(V)); }
+
   static Boolean zero() { return from(false); }
 
   template 
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3cf8bf874b1d210..8cc010d6f100ccb 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -67,6 +67,74 @@ template  class OptionScope final {
 } // namespace interp
 } // namespace clang
 
+//  This function is constexpr if and only if To, From, and the types of
+//  all subobjects of To and From are types T such that...
+//  (3.1) - is_union_v is false;
+//  (3.2) - is_pointer_v is false;
+//  (3.3) - is_member_pointer_v is false;
+//  (3.4) - is_volatile_v is false; and
+//  (3.5) - T has no non-static data members of reference type
+template 
+bool ByteCodeExprGen::emitBuiltinBitCast(const CastExpr *E) {
+  const Expr *SubExpr = E->getSubExpr();
+  QualType FromType = SubExpr->getType();
+  QualType ToType = E->getType();
+  std::optional ToT = classify(ToType);
+
+  // FIXME: This is wrong. We need to do the bitcast and then
+  //   throw away the result, so we still get the diagnostics.
+  if (DiscardResult)
+return this->discard(SubExpr);
+
+  if (ToType->isNullPtrType()) {
+if (!this->discard(SubExpr))
+  return false;
+
+return this->emitNullPtr(E);
+  }
+
+  if (FromType->isNullPtrType() && ToT) {
+if (!this->discard(SubExpr))
+  return false;
+
+return visitZeroInitializer(ToType, E);
+  }
+  assert(!ToType->isReferenceType());
+
+  // Get a pointer to the value-to-cast on the stack.
+  if (!this->visit(SubExpr))
+return false;
+
+  if (!ToT || ToT == PT_Ptr) {
+// Conversion to an array or record type.
+return this->emitBitCastPtr(E);
+  }
+
+  assert(ToT);
+
+  // Conversion to a primitive type. FromType can be another
+  // primitive type, or a record/array.
+  //
+  // Same thing for floats, but we need the target
+  // semantics here.
+  if (ToT == PT_Float) {
+const auto *TargetSemantics = &Ctx.getFloatSemantics(ToType);
+CharUnits FloatSize = Ctx.getASTContext().getTypeSizeInCha

[clang] [Clang][Driver] Add new flags to control IR verification (PR #68172)

2023-10-05 Thread Matheus Izvekov via cfe-commits


@@ -5150,9 +5150,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   const bool IsAssertBuild = true;
 #endif
 
-  // Disable the verification pass in -asserts builds.

mizvekov wrote:

I edited the line to append the `unless otherwise specified`, since now we 
allow overriding that with the new flag.

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


[clang] [clang][driver] Fix an issue where clang does not correctly resolve the system header if invoked via symlink (on MacOS) (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

ilg-ul wrote:

The latest patch fixes the issue #66704 without changing the meaning of 
InstalledDir.

It is specific to macOS headers, the libraries were ok.

I also checked the other places where `installedDir` is used, but I'm not 
familiar with them (`Hexagon.cpp`, `MipsLinux.cpp`, `OHOS.cpp`, 
`WebAssembly.cpp`).

There are also several references in `MinGW.cpp`, but on Windows starting clang 
via a link is highly unlikely, so I'll leave them to Martin, to decide if they 
need any changes.

One other file where checking for the path where the executable is located 
might be in `Gnu.cpp`, around line 2132, where the list of prefixes is 
calculated, but I don't know the logic well enough to suggest a change:

```cpp
// Then look for gcc installed alongside clang.
Prefixes.push_back(D.InstalledDir + "/..");
```

> in principle I kinda agree that the fix itself, locating things based on the 
> actual executable, sounds like the right thing to do in any case. We're early 
> in the 18.x cycle, and if we could get the tests fixed to work despite that, 
> we'd have lots of time to see if someone is affected negatively by it, before 
> 18.x is released.

Fully agree, but I suggest we first fix this specific issue in this PR, and do 
the rest in a separate PR.








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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v


Changes

SiFive Int8 Matrix Multiplication Extensions Specification
https://sifive.cdn.prismic.io/sifive/c4f0e51d-4dd3-402a-98bc-1ffad6011259_int8-matmul-spec.pdf


---

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


55 Files Affected:

- (modified) clang/include/clang/Basic/riscv_sifive_vector.td (+24) 
- (modified) clang/include/clang/Basic/riscv_vector_common.td (+2) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+11-8) 
- (modified) clang/lib/Sema/SemaRISCVVectorLookup.cpp (+2) 
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (+9-1) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmacc_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccsu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccus_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmacc_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmacc_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccsu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccus_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccus_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmacc_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmacc_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccsu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccus_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccus_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmacc_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmacc_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccsu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccsu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccu_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccu_4x8x4.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccus_2x8x2.c
 (+47) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccus_4x8x4.c
 (+47) 
- (modified) clang/test/Sema/rvv-required-features-invalid.c (+8) 
- (modified) clang/test/Sema/rvv-required-features.c (+10-1) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+2) 
- (modified) llvm/include/llvm/IR/IntrinsicsRISCVXsf.td (+20) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+6) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+4) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+16) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td (+90) 
- (added) llvm/test/CodeGen/RISCV/rvv/sf_vqmacc_2x8x2.ll (+159) 
- (added) llvm/test/CodeGen/RISCV/rvv/sf_vqmacc_4x8x4.ll (+159) 
- (added)

[clang] [RISCV] Support Xsfvfwmaccqqq extensions (PR #68296)

2023-10-05 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/68296

Bfloat16 Matrix Multiply Accumulate Instruction
https://sifive.cdn.prismic.io/sifive/c391d53e-ffcf-4091-82f6-c37bf3e883ed_xsfvfwmaccqqq-spec.pdf


>From fc484770303cf50819e09dafd0f4f00760e67e3c Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Wed, 4 Oct 2023 10:23:52 -0700
Subject: [PATCH] [RISCV] Support Xsfvfwmaccqqq extensions

Bfloat16 Matrix Multiply Accumulate Instruction
https://sifive.cdn.prismic.io/sifive/c391d53e-ffcf-4091-82f6-c37bf3e883ed_xsfvfwmaccqqq-spec.pdf
---
 .../clang/Basic/riscv_sifive_vector.td|  12 ++
 .../clang/Support/RISCVVIntrinsicUtils.h  |  17 +-
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |   1 +
 .../non-overloaded/sf_vfwmacc_4x4x4.c |  57 +
 .../non-policy/overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../policy/non-overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../policy/overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../test/Sema/rvv-required-features-invalid.c |   4 +
 clang/test/Sema/rvv-required-features.c   |   7 +-
 clang/utils/TableGen/RISCVVEmitter.cpp|   1 +
 llvm/include/llvm/IR/IntrinsicsRISCVXsf.td|  11 +
 llvm/lib/Support/RISCVISAInfo.cpp |   3 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |   2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   8 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td|  53 +
 .../CodeGen/RISCV/rvv/sf_vfwmacc_4x4x4.ll | 195 ++
 llvm/test/MC/RISCV/rvv/xsfvfwmacc.s   |  15 ++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   1 +
 18 files changed, 549 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 llvm/test/CodeGen/RISCV/rvv/sf_vfwmacc_4x4x4.ll
 create mode 100644 llvm/test/MC/RISCV/rvv/xsfvfwmacc.s

diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index 6583a7eb7b2e59b..d9be21a2a602944 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -103,3 +103,15 @@ let SupportOverloading = false in {
 defm sf_vc_v_fvw : RVVVCIXBuiltinSet<["si"],  "UwKzUwUvFe", [-1, 0, 2, 3], 
UseGPR=0>;
   }
 }
+
+multiclass RVVVFWMACCBuiltinSet> suffixes_prototypes> {
+  let OverloadedName = NAME,
+  Name = NAME,
+  HasMasked = false,
+  Log2LMUL = [-2, -1, 0, 1, 2] in
+defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
+let UnMaskedPolicyScheme = HasPolicyOperand in
+  let RequiredFeatures = ["Xsfvfwmaccqqq"] in
+defm sf_vfwmacc_4x4x4 : RVVVFWMACCBuiltinSet<[["", "w", "wwSvv"]]>;
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 8ba57d77221dc52..c6ce4884cdbb005 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,14 +485,15 @@ enum RVVRequire : uint16_t {
   RVV_REQ_RV64 = 1 << 0,
   RVV_REQ_ZvfhminOrZvfh = 1 << 1,
   RVV_REQ_Xsfvcp = 1 << 2,
-  RVV_REQ_Zvbb = 1 << 3,
-  RVV_REQ_Zvbc = 1 << 4,
-  RVV_REQ_Zvkb = 1 << 5,
-  RVV_REQ_Zvkg = 1 << 6,
-  RVV_REQ_Zvkned = 1 << 7,
-  RVV_REQ_Zvknha = 1 << 8,
-  RVV_REQ_Zvksed = 1 << 9,
-  RVV_REQ_Zvksh = 1 << 10,
+  RVV_REQ_Xsfvfwmaccqqq = 1 << 3,
+  RVV_REQ_Zvbb = 1 << 4,
+  RVV_REQ_Zvbc = 1 << 5,
+  RVV_REQ_Zvkb = 1 << 6,
+  RVV_REQ_Zvkg = 1 << 7,
+  RVV_REQ_Zvkned = 1 << 8,
+  RVV_REQ_Zvknha = 1 << 9,
+  RVV_REQ_Zvksed = 1 << 10,
+  RVV_REQ_Zvksh = 1 << 11,
 
   LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvksh)
 };
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index ae584dc68719901..97ebeed8ca4375d 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -205,6 +205,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
   static const std::pair FeatureCheckList[] = {
   {"64bit", RVV_REQ_RV64},
   {"xsfvcp", RVV_REQ_Xsfvcp},
+  {"xsfvfwmaccqqq", RVV_REQ_Xsfvfwmaccqqq},
   {"experimental-zvbb", RVV_REQ_Zvbb},
   {"experimental-zvbc", RVV_REQ_Zvbc},
   {"experimental-zvkb", RVV_REQ_Zvkb},
diff --git 
a/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
new file mode 100644
index 000..185b8f236b62a8d
--- /dev/null
+++ 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c

[clang] [RISCV] Support Xsfvfwmaccqqq extensions (PR #68296)

2023-10-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support


Changes

Bfloat16 Matrix Multiply Accumulate Instruction
https://sifive.cdn.prismic.io/sifive/c391d53e-ffcf-4091-82f6-c37bf3e883ed_xsfvfwmaccqqq-spec.pdf


---

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


18 Files Affected:

- (modified) clang/include/clang/Basic/riscv_sifive_vector.td (+12) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+9-8) 
- (modified) clang/lib/Sema/SemaRISCVVectorLookup.cpp (+1) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 (+57) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfwmacc_4x4x4.c
 (+57) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfwmacc_4x4x4.c
 (+57) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfwmacc_4x4x4.c
 (+57) 
- (modified) clang/test/Sema/rvv-required-features-invalid.c (+4) 
- (modified) clang/test/Sema/rvv-required-features.c (+6-1) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+1) 
- (modified) llvm/include/llvm/IR/IntrinsicsRISCVXsf.td (+11) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+3) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+2) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+8) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td (+53) 
- (added) llvm/test/CodeGen/RISCV/rvv/sf_vfwmacc_4x4x4.ll (+195) 
- (added) llvm/test/MC/RISCV/rvv/xsfvfwmacc.s (+15) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index 6583a7eb7b2e59b..d9be21a2a602944 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -103,3 +103,15 @@ let SupportOverloading = false in {
 defm sf_vc_v_fvw : RVVVCIXBuiltinSet<["si"],  "UwKzUwUvFe", [-1, 0, 2, 3], 
UseGPR=0>;
   }
 }
+
+multiclass RVVVFWMACCBuiltinSet> suffixes_prototypes> {
+  let OverloadedName = NAME,
+  Name = NAME,
+  HasMasked = false,
+  Log2LMUL = [-2, -1, 0, 1, 2] in
+defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
+let UnMaskedPolicyScheme = HasPolicyOperand in
+  let RequiredFeatures = ["Xsfvfwmaccqqq"] in
+defm sf_vfwmacc_4x4x4 : RVVVFWMACCBuiltinSet<[["", "w", "wwSvv"]]>;
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 8ba57d77221dc52..c6ce4884cdbb005 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,14 +485,15 @@ enum RVVRequire : uint16_t {
   RVV_REQ_RV64 = 1 << 0,
   RVV_REQ_ZvfhminOrZvfh = 1 << 1,
   RVV_REQ_Xsfvcp = 1 << 2,
-  RVV_REQ_Zvbb = 1 << 3,
-  RVV_REQ_Zvbc = 1 << 4,
-  RVV_REQ_Zvkb = 1 << 5,
-  RVV_REQ_Zvkg = 1 << 6,
-  RVV_REQ_Zvkned = 1 << 7,
-  RVV_REQ_Zvknha = 1 << 8,
-  RVV_REQ_Zvksed = 1 << 9,
-  RVV_REQ_Zvksh = 1 << 10,
+  RVV_REQ_Xsfvfwmaccqqq = 1 << 3,
+  RVV_REQ_Zvbb = 1 << 4,
+  RVV_REQ_Zvbc = 1 << 5,
+  RVV_REQ_Zvkb = 1 << 6,
+  RVV_REQ_Zvkg = 1 << 7,
+  RVV_REQ_Zvkned = 1 << 8,
+  RVV_REQ_Zvknha = 1 << 9,
+  RVV_REQ_Zvksed = 1 << 10,
+  RVV_REQ_Zvksh = 1 << 11,
 
   LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvksh)
 };
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index ae584dc68719901..97ebeed8ca4375d 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -205,6 +205,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
   static const std::pair FeatureCheckList[] = {
   {"64bit", RVV_REQ_RV64},
   {"xsfvcp", RVV_REQ_Xsfvcp},
+  {"xsfvfwmaccqqq", RVV_REQ_Xsfvfwmaccqqq},
   {"experimental-zvbb", RVV_REQ_Zvbb},
   {"experimental-zvbc", RVV_REQ_Zvbc},
   {"experimental-zvkb", RVV_REQ_Zvkb},
diff --git 
a/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
new file mode 100644
index 000..185b8f236b62a8d
--- /dev/null
+++ 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zvfh 
-target-feature +xsfvfwmaccqqq \
+// RUN:   -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | \
+// RUN:   FileCheck --check-prefix=CHECK-RV64 %s
+
+#include 
+
+// CHECK-RV64-LABEL: define dso_local  
@test_sf_vfwmacc_4x4x4_f32mf2
+// CHECK-RV64-SAME: ( [[VD:%.*]],  
[[VS1:%.*

[clang] [RISCV] Support Xsfvfnrclipxfqf extensions (PR #68297)

2023-10-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support


Changes

FP32-to-int8 Ranged Clip Instructions
https://sifive.cdn.prismic.io/sifive/0aacff47-f530-43dc-8446-5caa2260ece0_xsfvfnrclipxfqf-spec.pdf


---

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


33 Files Affected:

- (modified) clang/include/clang/Basic/riscv_sifive_vector.td (+62) 
- (modified) clang/include/clang/Basic/riscv_vector_common.td (+1) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+10-8) 
- (modified) clang/lib/Sema/SemaRISCVVectorLookup.cpp (+1) 
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (+8-1) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_x_f_qf.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_x_f_qf_rm.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_xu_f_qf.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_xu_f_qf_rm.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_x_f_qf.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_x_f_qf_rm.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_xu_f_qf.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_xu_f_qf_rm.c
 (+98) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_x_f_qf.c
 (+188) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_x_f_qf_rm.c
 (+188) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_xu_f_qf.c
 (+188) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_xu_f_qf_rm.c
 (+188) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_x_f_qf.c
 (+188) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_x_f_qf_rm.c
 (+188) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_xu_f_qf.c
 (+188) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_xu_f_qf_rm.c
 (+188) 
- (modified) clang/test/Sema/rvv-required-features-invalid.c (+8) 
- (modified) clang/test/Sema/rvv-required-features.c (+10-1) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+1) 
- (modified) llvm/include/llvm/IR/IntrinsicsRISCVXsf.td (+28) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+3) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+2) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+8) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td (+49) 
- (added) llvm/test/CodeGen/RISCV/rvv/sf_vfnrclip_x_f_qf.ll (+260) 
- (added) llvm/test/CodeGen/RISCV/rvv/sf_vfnrclip_xu_f_qf.ll (+260) 
- (added) llvm/test/MC/RISCV/rvv/xsfvfnrclip.s (+33) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index 6583a7eb7b2e59b..6e171cc7618b03a 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -103,3 +103,65 @@ let SupportOverloading = false in {
 defm sf_vc_v_fvw : RVVVCIXBuiltinSet<["si"],  "UwKzUwUvFe", [-1, 0, 2, 3], 
UseGPR=0>;
   }
 }
+
+multiclass RVVVFNRCLIPBuiltinSet {
+  let Log2LMUL = [-3, -2, -1, 0, 1, 2],
+  Name = NAME,
+  IRName = NAME,
+  MaskedIRName = NAME # "_mask" in
+  def : RVVConvBuiltin;
+}
+
+let UnMaskedPolicyScheme = HasPassthruOperand, RequiredFeatures = 
["Xsfvfnrclipxfqf"] in {
+let ManualCodegen = [{
+  {
+// LLVM intrinsic
+// Unmasked: (passthru, vector_in, scalar_in, frm, vl)
+// Masked:   (passthru, vector_in, scalar_in, mask, frm, vl, policy)
+
+SmallVector Operands;
+bool HasMaskedOff = !(
+(IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) ||
+(!IsMasked && PolicyAttrs & RVV_VTA));
+bool HasRoundModeOp = IsMasked ?
+  (HasMaskedOff ? Ops.size() == 6 : Ops.size() == 5) :
+  (HasMaskedOff ? Ops.size() == 5 : Ops.size() == 4);
+
+unsigned Offset = IsMasked ?
+(HasMaskedOff ? 2 : 1) : (HasMaskedOff ? 1 : 0);
+
+if (!HasMaskedOff)
+  Operands.push_back(llvm::PoisonValue::get(ResultType));
+else
+  Operands.push_back(Ops[IsMasked ? 1 : 0]);
+
+Operands.push_back(Ops[Offset]); // op0
+Operands.push_back(Ops[Offset + 1]); // op1
+
+if (IsMasked)
+  Operands.push_back(Ops[0]); // mask
+
+if

[clang] abb9eb2 - [Lex] Handle repl_input_end in Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-10-05T12:09:14+02:00
New Revision: abb9eb2778dc68ca3bc2ca786632e65682741469

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

LOG: [Lex] Handle repl_input_end in Preprocessor::LexTokensUntilEOF()

This fixes many unit tests when trying to enable IncrementalExtensions
by default for testing purposes.

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

Added: 


Modified: 
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index b82dd1fe49c7040..c16dd75fbbd3f53 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -1002,7 +1002,8 @@ void Preprocessor::LexTokensUntilEOF(std::vector 
*Tokens) {
   while (1) {
 Token Tok;
 Lex(Tok);
-if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod,
+tok::annot_repl_input_end))
   break;
 if (Tokens != nullptr)
   Tokens->push_back(Tok);



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


[PATCH] D158415: [Lex] Handle repl_input_end in Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGabb9eb2778dc: [Lex] Handle repl_input_end in 
Preprocessor::LexTokensUntilEOF() (authored by Hahnfeld).

Changed prior to commit:
  https://reviews.llvm.org/D158415?vs=556849&id=557607#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158415

Files:
  clang/lib/Lex/Preprocessor.cpp


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -1002,7 +1002,8 @@
   while (1) {
 Token Tok;
 Lex(Tok);
-if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod,
+tok::annot_repl_input_end))
   break;
 if (Tokens != nullptr)
   Tokens->push_back(Tok);


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -1002,7 +1002,8 @@
   while (1) {
 Token Tok;
 Lex(Tok);
-if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod,
+tok::annot_repl_input_end))
   break;
 if (Tokens != nullptr)
   Tokens->push_back(Tok);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-05 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 3a35ca01fc55f27315d1652ec1dedff10e79918b 
8042b2232c45a93418bab17eff78a38b527fcb95 -- 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmacc_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmacc_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccsu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccus_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vqmaccus_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmacc_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmacc_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccsu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccsu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccus_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vqmaccus_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmacc_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmacc_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccsu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccsu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccus_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vqmaccus_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmacc_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmacc_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccsu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccsu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccu_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccu_4x8x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccus_2x8x2.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vqmaccus_4x8x4.c
 clang/include/clang/Support/RISCVVIntrinsicUtils.h 
clang/lib/Sema/SemaRISCVVectorLookup.cpp 
clang/lib/Support/RISCVVIntrinsicUtils.cpp 
clang/test/Sema/rvv-required-features-invalid.c 
clang/test/Sema/rvv-required-features.c clang/utils/TableGen/RISCVVEmitter.cpp 
llvm/lib/Support/RISCVISAInfo.cpp 
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
llvm/unittests/Support/RISCVISAInfoTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 845d23945b1d..904cc235a8ca 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -558,10 +558,12 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst 
&MI, uint64_t &Size,
   "XTHeadVdot custom opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvcp, DecoderTableXSfvcp32,
   "SiFive VCIX custom opcode table");
-TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvqmaccdod, 
DecoderTableXSfvqmaccdod32,
-  "SiFive Matrix Multiplication Instruction opcode 
table");
-TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvqmaccqoq, 
DecoderTableXSfvqmaccqoq32,
-  "SiFive Matrix Multiplication Instruction opcode 
table");
+TRY_TO_DECODE_FEATURE(
+RISCV::FeatureVendorXSfvqmaccdod, DecoderTableXSfvqmaccdod32,
+"SiFive Matrix Multiplication Instruction opcode table");

[clang] [RISCV] Support Xsfvfwmaccqqq extensions (PR #68296)

2023-10-05 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 3a35ca01fc55f27315d1652ec1dedff10e79918b 
fc484770303cf50819e09dafd0f4f00760e67e3c -- 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfwmacc_4x4x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfwmacc_4x4x4.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfwmacc_4x4x4.c
 clang/include/clang/Support/RISCVVIntrinsicUtils.h 
clang/lib/Sema/SemaRISCVVectorLookup.cpp 
clang/test/Sema/rvv-required-features-invalid.c 
clang/test/Sema/rvv-required-features.c clang/utils/TableGen/RISCVVEmitter.cpp 
llvm/lib/Support/RISCVISAInfo.cpp 
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
llvm/unittests/Support/RISCVISAInfoTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 33f654b26884..b6b3c4ae4bbb 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -558,8 +558,9 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, 
uint64_t &Size,
   "XTHeadVdot custom opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvcp, DecoderTableXSfvcp32,
   "SiFive VCIX custom opcode table");
-TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvfwmaccqqq, 
DecoderTableXSfvfwmaccqqq32,
-  "SiFive Matrix Multiplication Instruction opcode 
table");
+TRY_TO_DECODE_FEATURE(
+RISCV::FeatureVendorXSfvfwmaccqqq, DecoderTableXSfvfwmaccqqq32,
+"SiFive Matrix Multiplication Instruction opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfcie, DecoderTableXSfcie32,
   "Sifive CIE custom opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbitmanip,
diff --git a/llvm/unittests/Support/RISCVISAInfoTest.cpp 
b/llvm/unittests/Support/RISCVISAInfoTest.cpp
index cf344b786fb5..1a029b87135a 100644
--- a/llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -630,7 +630,7 @@ TEST(getTargetFeatureForExtension, 
RetrieveTargetFeatureFromOneExt) {
 
 TEST(RiscvExtensionsHelp, CheckExtensions) {
   std::string ExpectedOutput =
-R"(All available -march extensions for RISC-V
+  R"(All available -march extensions for RISC-V
 
 NameVersion   Description
 i   2.1   This is a long dummy description

``




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


[clang] [clang][driver] Fix an issue where clang does not correctly resolve the system header if invoked via symlink (on MacOS) (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

ilg-ul wrote:

The Linux tests were fine, but the Windows tests failed in 
`Interpreter/const.cpp`, which does not seem to be related to my patch.



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


[clang] [RISCV] Support Xsfvfnrclipxfqf extensions (PR #68297)

2023-10-05 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 3a35ca01fc55f27315d1652ec1dedff10e79918b 
8281ab66e5315f5b8b4290894c8b9229bd6518d2 -- 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_x_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_x_f_qf_rm.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_xu_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfnrclip_xu_f_qf_rm.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_x_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_x_f_qf_rm.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_xu_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfnrclip_xu_f_qf_rm.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_x_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_x_f_qf_rm.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_xu_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfnrclip_xu_f_qf_rm.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_x_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_x_f_qf_rm.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_xu_f_qf.c
 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfnrclip_xu_f_qf_rm.c
 clang/include/clang/Support/RISCVVIntrinsicUtils.h 
clang/lib/Sema/SemaRISCVVectorLookup.cpp 
clang/lib/Support/RISCVVIntrinsicUtils.cpp 
clang/test/Sema/rvv-required-features-invalid.c 
clang/test/Sema/rvv-required-features.c clang/utils/TableGen/RISCVVEmitter.cpp 
llvm/lib/Support/RISCVISAInfo.cpp 
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
llvm/unittests/Support/RISCVISAInfoTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index eaba8d80d217..4d5e947f4ea5 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -652,20 +652,21 @@ void RVVEmitter::createRVVIntrinsics(
 
 SR.RequiredExtensions = 0;
 for (auto RequiredFeature : RequiredFeatures) {
-  RVVRequire RequireExt = StringSwitch(RequiredFeature)
-  .Case("RV64", RVV_REQ_RV64)
-  .Case("ZvfhminOrZvfh", RVV_REQ_ZvfhminOrZvfh)
-  .Case("Xsfvcp", RVV_REQ_Xsfvcp)
-  .Case("Xsfvfnrclipxfqf", 
RVV_REQ_Xsfvfnrclipxfqf)
-  .Case("Zvbb", RVV_REQ_Zvbb)
-  .Case("Zvbc", RVV_REQ_Zvbc)
-  .Case("Zvkb", RVV_REQ_Zvkb)
-  .Case("Zvkg", RVV_REQ_Zvkg)
-  .Case("Zvkned", RVV_REQ_Zvkned)
-  .Case("Zvknha", RVV_REQ_Zvknha)
-  .Case("Zvksed", RVV_REQ_Zvksed)
-  .Case("Zvksh", RVV_REQ_Zvksh)
-  .Default(RVV_REQ_None);
+  RVVRequire RequireExt =
+  StringSwitch(RequiredFeature)
+  .Case("RV64", RVV_REQ_RV64)
+  .Case("ZvfhminOrZvfh", RVV_REQ_ZvfhminOrZvfh)
+  .Case("Xsfvcp", RVV_REQ_Xsfvcp)
+  .Case("Xsfvfnrclipxfqf", RVV_REQ_Xsfvfnrclipxfqf)
+  .Case("Zvbb", RVV_REQ_Zvbb)
+  .Case("Zvbc", RVV_REQ_Zvbc)
+  .Case("Zvkb", RVV_REQ_Zvkb)
+  .Case("Zvkg", RVV_REQ_Zvkg)
+  .Case("Zvkned", RVV_REQ_Zvkned)
+  .Case("Zvknha", RVV_REQ_Zvknha)
+  .Case("Zvksed", RVV_REQ_Zvksed)
+  .Case("Zvksh", RVV_REQ_Zvksh)
+  .Default(RVV_REQ_None);
   assert(RequireExt != RVV_REQ_None && "Unrecognized required feature?");
   SR.RequiredExtensions |= RequireExt;
 }
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 75a93406ee71..3a7928e49d9a 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -558,8 +558,9 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, 
uint64_t &Size,
   "XTHeadVdot custom opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::

[clang-tools-extra] [AArch64][LoopVectorize] Use upper bound trip count instead of the constant TC when choosing max VF (PR #67697)

2023-10-05 Thread via cfe-commits

https://github.com/Rin18 updated https://github.com/llvm/llvm-project/pull/67697

>From 1bf78c81c678de436795a07c0b62037f782aa53f Mon Sep 17 00:00:00 2001
From: Rin Dobrescu 
Date: Mon, 25 Sep 2023 11:34:15 +
Subject: [PATCH 1/4] [AArch64][LoopVectorize] Use either fixed-width or
 scalable VF when tail-folding

---
 .../Transforms/Vectorize/LoopVectorize.cpp|   4 +-
 .../AArch64/clamped-trip-count.ll | 109 ++
 2 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index cc17d91d4f43727..d352bdaf939e36b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5142,7 +5142,9 @@ ElementCount 
LoopVectorizationCostModel::getMaximizedVFForTarget(
 LLVM_DEBUG(dbgs() << "LV: Clamping the MaxVF to maximum power of two not "
  "exceeding the constant trip count: "
   << ClampedConstTripCount << "\n");
-return ElementCount::getFixed(ClampedConstTripCount);
+return ElementCount::get(
+ClampedConstTripCount,
+FoldTailByMasking ? MaxVectorElementCount.isScalable() : false);
   }
 
   TargetTransformInfo::RegisterKind RegKind =
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll 
b/llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll
new file mode 100644
index 000..14507a71450b0ae
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll
@@ -0,0 +1,109 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt -S < %s -passes=loop-vectorize -mtriple aarch64-linux-gnu 
-mattr=+sve 2>&1 | FileCheck %s
+
+define void @test(ptr nocapture noundef writeonly %dst, i32 noundef %n, i64 
noundef %val) local_unnamed_addr #0 {
+; CHECK-LABEL: define void @test
+; CHECK-SAME: (ptr nocapture noundef writeonly [[DST:%.*]], i32 noundef 
[[N:%.*]], i64 noundef [[VAL:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[REM:%.*]] = and i32 [[N]], 63
+; CHECK-NEXT:[[CMP8_NOT:%.*]] = icmp eq i32 [[REM]], 0
+; CHECK-NEXT:br i1 [[CMP8_NOT]], label [[FOR_COND_CLEANUP:%.*]], label 
[[FOR_BODY_PREHEADER:%.*]]
+; CHECK:   for.body.preheader:
+; CHECK-NEXT:[[ADD:%.*]] = add nuw nsw i32 [[REM]], 7
+; CHECK-NEXT:[[SHR:%.*]] = lshr i32 [[ADD]], 3
+; CHECK-NEXT:[[WIDE_TRIP_COUNT:%.*]] = zext i32 [[SHR]] to i64
+; CHECK-NEXT:br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; CHECK:   vector.ph:
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 8
+; CHECK-NEXT:[[TMP2:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP3:%.*]] = mul i64 [[TMP2]], 8
+; CHECK-NEXT:[[TMP4:%.*]] = sub i64 [[TMP3]], 1
+; CHECK-NEXT:[[N_RND_UP:%.*]] = add i64 8, [[TMP4]]
+; CHECK-NEXT:[[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
+; CHECK-NEXT:[[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
+; CHECK-NEXT:[[IND_END:%.*]] = getelementptr i8, ptr [[DST]], i64 [[N_VEC]]
+; CHECK-NEXT:[[TMP5:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP6:%.*]] = mul i64 [[TMP5]], 8
+; CHECK-NEXT:[[TMP7:%.*]] = sub i64 8, [[TMP6]]
+; CHECK-NEXT:[[TMP8:%.*]] = icmp ugt i64 8, [[TMP6]]
+; CHECK-NEXT:[[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
+; CHECK-NEXT:[[ACTIVE_LANE_MASK_ENTRY:%.*]] = call  
@llvm.get.active.lane.mask.nxv8i1.i64(i64 0, i64 8)
+; CHECK-NEXT:[[TMP10:%.*]] = call  
@llvm.experimental.stepvector.nxv8i64()
+; CHECK-NEXT:[[TMP11:%.*]] = add  [[TMP10]], 
zeroinitializer
+; CHECK-NEXT:[[TMP12:%.*]] = mul  [[TMP11]], 
shufflevector ( insertelement ( poison, i64 
1, i64 0),  poison,  zeroinitializer)
+; CHECK-NEXT:[[INDUCTION:%.*]] = add  zeroinitializer, 
[[TMP12]]
+; CHECK-NEXT:[[TMP13:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP14:%.*]] = mul i64 [[TMP13]], 8
+; CHECK-NEXT:[[TMP15:%.*]] = mul i64 1, [[TMP14]]
+; CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement  
poison, i64 [[TMP15]], i64 0
+; CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector  
[[DOTSPLATINSERT]],  poison,  
zeroinitializer
+; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement  poison, i64 [[VAL]], i64 0
+; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector  
[[BROADCAST_SPLATINSERT]],  poison,  
zeroinitializer
+; CHECK-NEXT:br label [[VECTOR_BODY:%.*]]
+; CHECK:   vector.body:
+; CHECK-NEXT:[[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ 
[[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; CHECK-NEXT:[[ACTIVE_LANE_MASK:%.*]] = phi  [ 
[[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], 
[[VECTOR_BODY]] ]
+; CHECK-NEXT:[[

[clang] [AArch64][LoopVectorize] Use upper bound trip count instead of the constant TC when choosing max VF (PR #67697)

2023-10-05 Thread via cfe-commits

https://github.com/Rin18 updated https://github.com/llvm/llvm-project/pull/67697

>From 1bf78c81c678de436795a07c0b62037f782aa53f Mon Sep 17 00:00:00 2001
From: Rin Dobrescu 
Date: Mon, 25 Sep 2023 11:34:15 +
Subject: [PATCH 1/4] [AArch64][LoopVectorize] Use either fixed-width or
 scalable VF when tail-folding

---
 .../Transforms/Vectorize/LoopVectorize.cpp|   4 +-
 .../AArch64/clamped-trip-count.ll | 109 ++
 2 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index cc17d91d4f43727..d352bdaf939e36b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5142,7 +5142,9 @@ ElementCount 
LoopVectorizationCostModel::getMaximizedVFForTarget(
 LLVM_DEBUG(dbgs() << "LV: Clamping the MaxVF to maximum power of two not "
  "exceeding the constant trip count: "
   << ClampedConstTripCount << "\n");
-return ElementCount::getFixed(ClampedConstTripCount);
+return ElementCount::get(
+ClampedConstTripCount,
+FoldTailByMasking ? MaxVectorElementCount.isScalable() : false);
   }
 
   TargetTransformInfo::RegisterKind RegKind =
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll 
b/llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll
new file mode 100644
index 000..14507a71450b0ae
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll
@@ -0,0 +1,109 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt -S < %s -passes=loop-vectorize -mtriple aarch64-linux-gnu 
-mattr=+sve 2>&1 | FileCheck %s
+
+define void @test(ptr nocapture noundef writeonly %dst, i32 noundef %n, i64 
noundef %val) local_unnamed_addr #0 {
+; CHECK-LABEL: define void @test
+; CHECK-SAME: (ptr nocapture noundef writeonly [[DST:%.*]], i32 noundef 
[[N:%.*]], i64 noundef [[VAL:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[REM:%.*]] = and i32 [[N]], 63
+; CHECK-NEXT:[[CMP8_NOT:%.*]] = icmp eq i32 [[REM]], 0
+; CHECK-NEXT:br i1 [[CMP8_NOT]], label [[FOR_COND_CLEANUP:%.*]], label 
[[FOR_BODY_PREHEADER:%.*]]
+; CHECK:   for.body.preheader:
+; CHECK-NEXT:[[ADD:%.*]] = add nuw nsw i32 [[REM]], 7
+; CHECK-NEXT:[[SHR:%.*]] = lshr i32 [[ADD]], 3
+; CHECK-NEXT:[[WIDE_TRIP_COUNT:%.*]] = zext i32 [[SHR]] to i64
+; CHECK-NEXT:br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; CHECK:   vector.ph:
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 8
+; CHECK-NEXT:[[TMP2:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP3:%.*]] = mul i64 [[TMP2]], 8
+; CHECK-NEXT:[[TMP4:%.*]] = sub i64 [[TMP3]], 1
+; CHECK-NEXT:[[N_RND_UP:%.*]] = add i64 8, [[TMP4]]
+; CHECK-NEXT:[[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
+; CHECK-NEXT:[[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
+; CHECK-NEXT:[[IND_END:%.*]] = getelementptr i8, ptr [[DST]], i64 [[N_VEC]]
+; CHECK-NEXT:[[TMP5:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP6:%.*]] = mul i64 [[TMP5]], 8
+; CHECK-NEXT:[[TMP7:%.*]] = sub i64 8, [[TMP6]]
+; CHECK-NEXT:[[TMP8:%.*]] = icmp ugt i64 8, [[TMP6]]
+; CHECK-NEXT:[[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
+; CHECK-NEXT:[[ACTIVE_LANE_MASK_ENTRY:%.*]] = call  
@llvm.get.active.lane.mask.nxv8i1.i64(i64 0, i64 8)
+; CHECK-NEXT:[[TMP10:%.*]] = call  
@llvm.experimental.stepvector.nxv8i64()
+; CHECK-NEXT:[[TMP11:%.*]] = add  [[TMP10]], 
zeroinitializer
+; CHECK-NEXT:[[TMP12:%.*]] = mul  [[TMP11]], 
shufflevector ( insertelement ( poison, i64 
1, i64 0),  poison,  zeroinitializer)
+; CHECK-NEXT:[[INDUCTION:%.*]] = add  zeroinitializer, 
[[TMP12]]
+; CHECK-NEXT:[[TMP13:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP14:%.*]] = mul i64 [[TMP13]], 8
+; CHECK-NEXT:[[TMP15:%.*]] = mul i64 1, [[TMP14]]
+; CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement  
poison, i64 [[TMP15]], i64 0
+; CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector  
[[DOTSPLATINSERT]],  poison,  
zeroinitializer
+; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement  poison, i64 [[VAL]], i64 0
+; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector  
[[BROADCAST_SPLATINSERT]],  poison,  
zeroinitializer
+; CHECK-NEXT:br label [[VECTOR_BODY:%.*]]
+; CHECK:   vector.body:
+; CHECK-NEXT:[[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ 
[[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; CHECK-NEXT:[[ACTIVE_LANE_MASK:%.*]] = phi  [ 
[[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], 
[[VECTOR_BODY]] ]
+; CHECK-NEXT:[[

[clang] [RISCV] Support Xsfvfwmaccqqq extensions (PR #68296)

2023-10-05 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/68296

>From fc484770303cf50819e09dafd0f4f00760e67e3c Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Wed, 4 Oct 2023 10:23:52 -0700
Subject: [PATCH 1/2] [RISCV] Support Xsfvfwmaccqqq extensions

Bfloat16 Matrix Multiply Accumulate Instruction
https://sifive.cdn.prismic.io/sifive/c391d53e-ffcf-4091-82f6-c37bf3e883ed_xsfvfwmaccqqq-spec.pdf
---
 .../clang/Basic/riscv_sifive_vector.td|  12 ++
 .../clang/Support/RISCVVIntrinsicUtils.h  |  17 +-
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |   1 +
 .../non-overloaded/sf_vfwmacc_4x4x4.c |  57 +
 .../non-policy/overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../policy/non-overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../policy/overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../test/Sema/rvv-required-features-invalid.c |   4 +
 clang/test/Sema/rvv-required-features.c   |   7 +-
 clang/utils/TableGen/RISCVVEmitter.cpp|   1 +
 llvm/include/llvm/IR/IntrinsicsRISCVXsf.td|  11 +
 llvm/lib/Support/RISCVISAInfo.cpp |   3 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |   2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   8 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td|  53 +
 .../CodeGen/RISCV/rvv/sf_vfwmacc_4x4x4.ll | 195 ++
 llvm/test/MC/RISCV/rvv/xsfvfwmacc.s   |  15 ++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   1 +
 18 files changed, 549 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 llvm/test/CodeGen/RISCV/rvv/sf_vfwmacc_4x4x4.ll
 create mode 100644 llvm/test/MC/RISCV/rvv/xsfvfwmacc.s

diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index 6583a7eb7b2e59b..d9be21a2a602944 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -103,3 +103,15 @@ let SupportOverloading = false in {
 defm sf_vc_v_fvw : RVVVCIXBuiltinSet<["si"],  "UwKzUwUvFe", [-1, 0, 2, 3], 
UseGPR=0>;
   }
 }
+
+multiclass RVVVFWMACCBuiltinSet> suffixes_prototypes> {
+  let OverloadedName = NAME,
+  Name = NAME,
+  HasMasked = false,
+  Log2LMUL = [-2, -1, 0, 1, 2] in
+defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
+let UnMaskedPolicyScheme = HasPolicyOperand in
+  let RequiredFeatures = ["Xsfvfwmaccqqq"] in
+defm sf_vfwmacc_4x4x4 : RVVVFWMACCBuiltinSet<[["", "w", "wwSvv"]]>;
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 8ba57d77221dc52..c6ce4884cdbb005 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,14 +485,15 @@ enum RVVRequire : uint16_t {
   RVV_REQ_RV64 = 1 << 0,
   RVV_REQ_ZvfhminOrZvfh = 1 << 1,
   RVV_REQ_Xsfvcp = 1 << 2,
-  RVV_REQ_Zvbb = 1 << 3,
-  RVV_REQ_Zvbc = 1 << 4,
-  RVV_REQ_Zvkb = 1 << 5,
-  RVV_REQ_Zvkg = 1 << 6,
-  RVV_REQ_Zvkned = 1 << 7,
-  RVV_REQ_Zvknha = 1 << 8,
-  RVV_REQ_Zvksed = 1 << 9,
-  RVV_REQ_Zvksh = 1 << 10,
+  RVV_REQ_Xsfvfwmaccqqq = 1 << 3,
+  RVV_REQ_Zvbb = 1 << 4,
+  RVV_REQ_Zvbc = 1 << 5,
+  RVV_REQ_Zvkb = 1 << 6,
+  RVV_REQ_Zvkg = 1 << 7,
+  RVV_REQ_Zvkned = 1 << 8,
+  RVV_REQ_Zvknha = 1 << 9,
+  RVV_REQ_Zvksed = 1 << 10,
+  RVV_REQ_Zvksh = 1 << 11,
 
   LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvksh)
 };
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index ae584dc68719901..97ebeed8ca4375d 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -205,6 +205,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
   static const std::pair FeatureCheckList[] = {
   {"64bit", RVV_REQ_RV64},
   {"xsfvcp", RVV_REQ_Xsfvcp},
+  {"xsfvfwmaccqqq", RVV_REQ_Xsfvfwmaccqqq},
   {"experimental-zvbb", RVV_REQ_Zvbb},
   {"experimental-zvbc", RVV_REQ_Zvbc},
   {"experimental-zvkb", RVV_REQ_Zvkb},
diff --git 
a/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
new file mode 100644
index 000..185b8f236b62a8d
--- /dev/null
+++ 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// REQUIRES: riscv-regi

[clang] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)

2023-10-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-presburger


Changes

We modify `Fraction.reduce()` to work with negative fractions as well.
We add tests to verify the implementation of arithmetic and relational 
operators on Fractions.

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


5 Files Affected:

- (added) libcxx/modules/std/mdspan.cppm (+33) 
- (added) libcxx/modules/std/print.cppm (+25) 
- (modified) mlir/include/mlir/Analysis/Presburger/Fraction.h (+9-7) 
- (modified) mlir/unittests/Analysis/Presburger/CMakeLists.txt (+1) 
- (added) mlir/unittests/Analysis/Presburger/FractionTest.cpp (+51) 


``diff
diff --git a/libcxx/modules/std/mdspan.cppm b/libcxx/modules/std/mdspan.cppm
new file mode 100644
index 000..40426cce3fce8c2
--- /dev/null
+++ b/libcxx/modules/std/mdspan.cppm
@@ -0,0 +1,33 @@
+// -*- 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
+//
+//===--===//
+
+module;
+#include 
+
+export module std:mdspan;
+export namespace std {
+#if _LIBCPP_STD_VER >= 23
+  // [mdspan.extents], class template extents
+  using std::extents;
+
+  // [mdspan.extents.dextents], alias template dextents
+  using std::dextents;
+
+  // [mdspan.layout], layout mapping
+  using std::layout_left;
+  using std::layout_right;
+  // using std::layout_stride;
+
+  // [mdspan.accessor.default], class template default_accessor
+  using std::default_accessor;
+
+  // [mdspan.mdspan], class template mdspan
+  using std::mdspan;
+#endif // _LIBCPP_STD_VER >= 23
+} // namespace std
diff --git a/libcxx/modules/std/print.cppm b/libcxx/modules/std/print.cppm
new file mode 100644
index 000..02362633c6d9fbb
--- /dev/null
+++ b/libcxx/modules/std/print.cppm
@@ -0,0 +1,25 @@
+// -*- 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
+//
+//===--===//
+
+module;
+#include 
+
+export module std:print;
+export namespace std {
+#if _LIBCPP_STD_VER >= 23
+  // [print.fun], print functions
+  using std::print;
+  using std::println;
+
+  using std::vprint_nonunicode;
+#  ifndef _LIBCPP_HAS_NO_UNICODE
+  using std::vprint_unicode;
+#  endif // _LIBCPP_HAS_NO_UNICODE
+#endif   // _LIBCPP_STD_VER >= 23
+} // namespace std
diff --git a/mlir/include/mlir/Analysis/Presburger/Fraction.h 
b/mlir/include/mlir/Analysis/Presburger/Fraction.h
index 74127a900d53ed2..a410f528e1f8001 100644
--- a/mlir/include/mlir/Analysis/Presburger/Fraction.h
+++ b/mlir/include/mlir/Analysis/Presburger/Fraction.h
@@ -30,7 +30,8 @@ struct Fraction {
   Fraction() = default;
 
   /// Construct a Fraction from a numerator and denominator.
-  Fraction(const MPInt &oNum, const MPInt &oDen = MPInt(1)) : num(oNum), 
den(oDen) {
+  Fraction(const MPInt &oNum, const MPInt &oDen = MPInt(1))
+  : num(oNum), den(oDen) {
 if (den < 0) {
   num = -num;
   den = -den;
@@ -38,7 +39,8 @@ struct Fraction {
   }
   /// Overloads for passing literals.
   Fraction(const MPInt &num, int64_t den = 1) : Fraction(num, MPInt(den)) {}
-  Fraction(int64_t num, const MPInt &den = MPInt(1)) : Fraction(MPInt(num), 
den) {}
+  Fraction(int64_t num, const MPInt &den = MPInt(1))
+  : Fraction(MPInt(num), den) {}
   Fraction(int64_t num, int64_t den) : Fraction(MPInt(num), MPInt(den)) {}
 
   // Return the value of the fraction as an integer. This should only be called
@@ -102,7 +104,7 @@ inline bool operator>=(const Fraction &x, const Fraction 
&y) {
 inline Fraction reduce(const Fraction &f) {
   if (f == Fraction(0))
 return Fraction(0, 1);
-  MPInt g = gcd(f.num, f.den);
+  MPInt g = gcd(abs(f.num), abs(f.den));
   return Fraction(f.num / g, f.den / g);
 }
 
@@ -122,22 +124,22 @@ inline Fraction operator-(const Fraction &x, const 
Fraction &y) {
   return reduce(Fraction(x.num * y.den - x.den * y.num, x.den * y.den));
 }
 
-inline Fraction& operator+=(Fraction &x, const Fraction &y) {
+inline Fraction &operator+=(Fraction &x, const Fraction &y) {
   x = x + y;
   return x;
 }
 
-inline Fraction& operator-=(Fraction &x, const Fraction &y) {
+inline Fraction &operator-=(Fraction &x, const Fraction &y) {
   x = x - y;
   return x;
 }
 
-inline Fraction& operator/=(Fraction &x, const Fraction &y) {
+inline Fraction &operator/=(Fraction &x, const Fraction &y) {
   x = x / y;
   return x;
 }
 
-inline Fraction& operator*=(Fraction &x, const Fraction &y) {
+inline Fraction &operator*=(Fraction &x, const Frac

[clang-tools-extra] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)

2023-10-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-presburger


Changes

We modify `Fraction.reduce()` to work with negative fractions as well.
We add tests to verify the implementation of arithmetic and relational 
operators on Fractions.

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


5 Files Affected:

- (added) libcxx/modules/std/mdspan.cppm (+33) 
- (added) libcxx/modules/std/print.cppm (+25) 
- (modified) mlir/include/mlir/Analysis/Presburger/Fraction.h (+9-7) 
- (modified) mlir/unittests/Analysis/Presburger/CMakeLists.txt (+1) 
- (added) mlir/unittests/Analysis/Presburger/FractionTest.cpp (+51) 


``diff
diff --git a/libcxx/modules/std/mdspan.cppm b/libcxx/modules/std/mdspan.cppm
new file mode 100644
index 000..40426cce3fce8c2
--- /dev/null
+++ b/libcxx/modules/std/mdspan.cppm
@@ -0,0 +1,33 @@
+// -*- 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
+//
+//===--===//
+
+module;
+#include 
+
+export module std:mdspan;
+export namespace std {
+#if _LIBCPP_STD_VER >= 23
+  // [mdspan.extents], class template extents
+  using std::extents;
+
+  // [mdspan.extents.dextents], alias template dextents
+  using std::dextents;
+
+  // [mdspan.layout], layout mapping
+  using std::layout_left;
+  using std::layout_right;
+  // using std::layout_stride;
+
+  // [mdspan.accessor.default], class template default_accessor
+  using std::default_accessor;
+
+  // [mdspan.mdspan], class template mdspan
+  using std::mdspan;
+#endif // _LIBCPP_STD_VER >= 23
+} // namespace std
diff --git a/libcxx/modules/std/print.cppm b/libcxx/modules/std/print.cppm
new file mode 100644
index 000..02362633c6d9fbb
--- /dev/null
+++ b/libcxx/modules/std/print.cppm
@@ -0,0 +1,25 @@
+// -*- 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
+//
+//===--===//
+
+module;
+#include 
+
+export module std:print;
+export namespace std {
+#if _LIBCPP_STD_VER >= 23
+  // [print.fun], print functions
+  using std::print;
+  using std::println;
+
+  using std::vprint_nonunicode;
+#  ifndef _LIBCPP_HAS_NO_UNICODE
+  using std::vprint_unicode;
+#  endif // _LIBCPP_HAS_NO_UNICODE
+#endif   // _LIBCPP_STD_VER >= 23
+} // namespace std
diff --git a/mlir/include/mlir/Analysis/Presburger/Fraction.h 
b/mlir/include/mlir/Analysis/Presburger/Fraction.h
index 74127a900d53ed2..a410f528e1f8001 100644
--- a/mlir/include/mlir/Analysis/Presburger/Fraction.h
+++ b/mlir/include/mlir/Analysis/Presburger/Fraction.h
@@ -30,7 +30,8 @@ struct Fraction {
   Fraction() = default;
 
   /// Construct a Fraction from a numerator and denominator.
-  Fraction(const MPInt &oNum, const MPInt &oDen = MPInt(1)) : num(oNum), 
den(oDen) {
+  Fraction(const MPInt &oNum, const MPInt &oDen = MPInt(1))
+  : num(oNum), den(oDen) {
 if (den < 0) {
   num = -num;
   den = -den;
@@ -38,7 +39,8 @@ struct Fraction {
   }
   /// Overloads for passing literals.
   Fraction(const MPInt &num, int64_t den = 1) : Fraction(num, MPInt(den)) {}
-  Fraction(int64_t num, const MPInt &den = MPInt(1)) : Fraction(MPInt(num), 
den) {}
+  Fraction(int64_t num, const MPInt &den = MPInt(1))
+  : Fraction(MPInt(num), den) {}
   Fraction(int64_t num, int64_t den) : Fraction(MPInt(num), MPInt(den)) {}
 
   // Return the value of the fraction as an integer. This should only be called
@@ -102,7 +104,7 @@ inline bool operator>=(const Fraction &x, const Fraction 
&y) {
 inline Fraction reduce(const Fraction &f) {
   if (f == Fraction(0))
 return Fraction(0, 1);
-  MPInt g = gcd(f.num, f.den);
+  MPInt g = gcd(abs(f.num), abs(f.den));
   return Fraction(f.num / g, f.den / g);
 }
 
@@ -122,22 +124,22 @@ inline Fraction operator-(const Fraction &x, const 
Fraction &y) {
   return reduce(Fraction(x.num * y.den - x.den * y.num, x.den * y.den));
 }
 
-inline Fraction& operator+=(Fraction &x, const Fraction &y) {
+inline Fraction &operator+=(Fraction &x, const Fraction &y) {
   x = x + y;
   return x;
 }
 
-inline Fraction& operator-=(Fraction &x, const Fraction &y) {
+inline Fraction &operator-=(Fraction &x, const Fraction &y) {
   x = x - y;
   return x;
 }
 
-inline Fraction& operator/=(Fraction &x, const Fraction &y) {
+inline Fraction &operator/=(Fraction &x, const Fraction &y) {
   x = x / y;
   return x;
 }
 
-inline Fraction& operator*=(Fraction &x, const Fraction &y) {
+inline Fraction &operator*=(Fraction &x, const Frac

[clang-tools-extra] [AArch64][LoopVectorize] Use upper bound trip count instead of the constant TC when choosing max VF (PR #67697)

2023-10-05 Thread via cfe-commits

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


[clang] [RISCV] Fix wrong implication for zvknhb. (PR #66860)

2023-10-05 Thread Brandon Wu via cfe-commits

4vtomat wrote:

ping

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


[clang] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)

2023-10-05 Thread Kunwar Grover via cfe-commits

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

Please remove the libcxx changes

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


[clang-tools-extra] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)

2023-10-05 Thread Kunwar Grover via cfe-commits

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

Please remove the libcxx changes

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


[libunwind] [AMDGPU] Add another SIFoldOperands instance after shrink (PR #67878)

2023-10-05 Thread Jay Foad via cfe-commits

jayfoad wrote:

> > > I've just tested this on 1 graphics shaders and it seems to make no 
> > > difference at all. I tried gfx900 and gfx1100. Can anyone else from the 
> > > graphics team confirm this?
> > 
> > 
> > I can confirm no difference on gfx1102
> 
> gfx11 is the same as gfx10, it just bails because of the VOP3 literal 
> support. This is strange for gfx9. Do these shaders use -O2 or -O3?

I just use the default which is supposed to be -O2.

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


[PATCH] D155688: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP

2023-10-05 Thread Dmitriy Smirnov via Phabricator via cfe-commits
d-smirnov updated this revision to Diff 557609.
d-smirnov added a comment.

Updated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155688

Files:
  clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/CodeGen/Hexagon/autohvx/vector-align-tbaa.ll
  llvm/test/Transforms/InstCombine/align-addr.ll
  llvm/test/Transforms/InstCombine/mem-par-metadata-memcpy.ll
  llvm/test/Transforms/InstCombine/memrchr-4.ll
  llvm/test/Transforms/InstCombine/shift.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-interleaved-accesses.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
  llvm/test/Transforms/LoopVectorize/induction.ll
  llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll
  llvm/test/Transforms/LoopVectorize/invariant-store-vectorization.ll
  llvm/test/Transforms/LoopVectorize/runtime-check.ll
  llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll

Index: llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
===
--- llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
+++ llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
@@ -27,14 +27,14 @@
 ; CHECK-NEXT:br label [[INNER_BODY:%.*]]
 ; CHECK:   inner.body:
 ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 2
-; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP1]]
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[TMP1]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x double>, ptr [[TMP2]], align 8
 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr double, ptr [[TMP2]], i64 4
 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x double>, ptr [[VEC_GEP]], align 8
 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]]
-; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP4]]
+; CHECK-NEXT:[[TMP4:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[TMP4]], i64 [[INNER_IV]]
 ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x double>, ptr [[TMP5]], align 8
 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr double, ptr [[TMP5]], i64 4
 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x double>, ptr [[VEC_GEP3]], align 8
@@ -55,8 +55,8 @@
 ; CHECK-NEXT:[[ROWS_STEP]] = add i64 [[ROWS_IV]], 2
 ; CHECK-NEXT:[[ROWS_COND_NOT:%.*]] = icmp eq i64 [[ROWS_STEP]], 4
 ; CHECK-NEXT:[[TMP10:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP11:%.*]] = add i64 [[TMP10]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP11]]
+; CHECK-NEXT:[[TMP11:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP10]]
+; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[TMP11]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:store <2 x double> [[TMP7]], ptr [[TMP12]], align 8
 ; CHECK-NEXT:[[VEC_GEP16:%.*]] = getelementptr double, ptr [[TMP12]], i64 4
 ; CHECK-NEXT:store <2 x double> [[TMP9]], ptr [[VEC_GEP16]], align 8
@@ -103,14 +103,14 @@
 ; CHECK-NEXT:br label [[INNER_BODY:%.*]]
 ; CHECK:   inner.body:
 ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 1
-; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP1]]
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[TMP1]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x i64>, ptr [[TMP2]], align 8
 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr i64, ptr [[TMP2]], i64 2
 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x i64>, ptr [[VEC_GEP]], align 8
 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]]
-; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP4]]
+; CHECK-NEXT:[[TMP4:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[TMP4]], i64 [[INNER_IV]]
 ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x i64>, ptr [[TMP5]], align 8
 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr i64, ptr [[TMP5]], i64 4
 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x i64>, ptr [[VEC_GEP3]], align 8
@@ -135,8 +135,8 @@
 ; CHECK-NEXT:[[ROWS_STEP]] = add i64 [[ROWS_IV]], 2
 ; CHECK-NEXT:[[ROWS_COND_NOT:%.*]] = icmp eq i64 [[ROWS_IV]], 0
 ; CHECK-NEXT:[[TMP14:%.*]] = shl i64 [[COLS_IV]], 1
-; CHECK-NEXT:[[TMP15:%.*]] = add i64 [[TMP14]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP16:%.*]] = getelementptr i64,

[PATCH] D155688: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP

2023-10-05 Thread Dmitriy Smirnov via Phabricator via cfe-commits
d-smirnov marked an inline comment as done.
d-smirnov added a comment.

Updated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155688

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


[clang-tools-extra] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits

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


[clang-tools-extra] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -5748,6 +5758,7 @@ OpenMPIRBuilder::createTeams(const LocationDescription 
&Loc,
 BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, 
"teams.entry");
 Builder.SetInsertPoint(BodyBB, BodyBB->begin());
   }
+  InsertPointTy OuterAllocaIP(&OuterAllocaBB, OuterAllocaBB.begin());

kiranchandramohan wrote:

Can this be defined close to its use?

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


[clang] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -5748,6 +5758,7 @@ OpenMPIRBuilder::createTeams(const LocationDescription 
&Loc,
 BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, 
"teams.entry");
 Builder.SetInsertPoint(BodyBB, BodyBB->begin());
   }
+  InsertPointTy OuterAllocaIP(&OuterAllocaBB, OuterAllocaBB.begin());

kiranchandramohan wrote:

Can this be defined close to its use?

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


[clang-tools-extra] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -340,6 +340,44 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase 
&Builder, bool CreateBranch,
   return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
 }
 
+// This function creates a fake integer value and a fake use for the integer
+// value. It returns the fake value created. This is useful in modeling the
+// extra arguments to the outlined functions.
+Value *createFakeIntVal(IRBuilder<> &Builder,
+OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
+std::stack &ToBeDeleted,
+OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
+const Twine &Name = "", bool AsPtr = true) {
+  Builder.restoreIP(OuterAllocaIP);
+  Instruction *FakeVal;
+  AllocaInst *FakeValAddr =
+  Builder.CreateAlloca(Builder.getInt32Ty(), nullptr, Name + ".addr");
+  ToBeDeleted.push(FakeValAddr);
+
+  if (AsPtr)
+FakeVal = FakeValAddr;
+  else {
+FakeVal =
+Builder.CreateLoad(Builder.getInt32Ty(), FakeValAddr, Name + ".val");
+ToBeDeleted.push(FakeVal);

kiranchandramohan wrote:

Would this delete twice for the `AsPtr` case?

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


[libunwind] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -340,6 +340,44 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase 
&Builder, bool CreateBranch,
   return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
 }
 
+// This function creates a fake integer value and a fake use for the integer
+// value. It returns the fake value created. This is useful in modeling the
+// extra arguments to the outlined functions.
+Value *createFakeIntVal(IRBuilder<> &Builder,
+OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
+std::stack &ToBeDeleted,
+OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
+const Twine &Name = "", bool AsPtr = true) {
+  Builder.restoreIP(OuterAllocaIP);
+  Instruction *FakeVal;
+  AllocaInst *FakeValAddr =
+  Builder.CreateAlloca(Builder.getInt32Ty(), nullptr, Name + ".addr");
+  ToBeDeleted.push(FakeValAddr);
+
+  if (AsPtr)
+FakeVal = FakeValAddr;
+  else {

kiranchandramohan wrote:

Nit: braces to match else. Same for tid below.

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


[clang] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan commented:

Could you expand the summary to describe the changes.
What are the changes required to remove the wrapper function (Why was it 
required in the first place?)
Why are the fake vals necessary?


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


[libunwind] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits

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


[clang] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -340,6 +340,44 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase 
&Builder, bool CreateBranch,
   return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
 }
 
+// This function creates a fake integer value and a fake use for the integer
+// value. It returns the fake value created. This is useful in modeling the
+// extra arguments to the outlined functions.
+Value *createFakeIntVal(IRBuilder<> &Builder,
+OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
+std::stack &ToBeDeleted,
+OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
+const Twine &Name = "", bool AsPtr = true) {
+  Builder.restoreIP(OuterAllocaIP);
+  Instruction *FakeVal;
+  AllocaInst *FakeValAddr =
+  Builder.CreateAlloca(Builder.getInt32Ty(), nullptr, Name + ".addr");
+  ToBeDeleted.push(FakeValAddr);
+
+  if (AsPtr)
+FakeVal = FakeValAddr;
+  else {
+FakeVal =
+Builder.CreateLoad(Builder.getInt32Ty(), FakeValAddr, Name + ".val");
+ToBeDeleted.push(FakeVal);

kiranchandramohan wrote:

Would this delete twice for the `AsPtr` case?

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


[libunwind] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -5748,6 +5758,7 @@ OpenMPIRBuilder::createTeams(const LocationDescription 
&Loc,
 BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, 
"teams.entry");
 Builder.SetInsertPoint(BodyBB, BodyBB->begin());
   }
+  InsertPointTy OuterAllocaIP(&OuterAllocaBB, OuterAllocaBB.begin());

kiranchandramohan wrote:

Can this be defined close to its use?

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


[clang-tools-extra] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -340,6 +340,44 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase 
&Builder, bool CreateBranch,
   return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
 }
 
+// This function creates a fake integer value and a fake use for the integer
+// value. It returns the fake value created. This is useful in modeling the
+// extra arguments to the outlined functions.
+Value *createFakeIntVal(IRBuilder<> &Builder,
+OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
+std::stack &ToBeDeleted,
+OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
+const Twine &Name = "", bool AsPtr = true) {
+  Builder.restoreIP(OuterAllocaIP);
+  Instruction *FakeVal;
+  AllocaInst *FakeValAddr =
+  Builder.CreateAlloca(Builder.getInt32Ty(), nullptr, Name + ".addr");
+  ToBeDeleted.push(FakeValAddr);
+
+  if (AsPtr)
+FakeVal = FakeValAddr;
+  else {

kiranchandramohan wrote:

Nit: braces to match else. Same for tid below.

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


[libunwind] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits


@@ -340,6 +340,44 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase 
&Builder, bool CreateBranch,
   return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
 }
 
+// This function creates a fake integer value and a fake use for the integer
+// value. It returns the fake value created. This is useful in modeling the
+// extra arguments to the outlined functions.
+Value *createFakeIntVal(IRBuilder<> &Builder,
+OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
+std::stack &ToBeDeleted,
+OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
+const Twine &Name = "", bool AsPtr = true) {
+  Builder.restoreIP(OuterAllocaIP);
+  Instruction *FakeVal;
+  AllocaInst *FakeValAddr =
+  Builder.CreateAlloca(Builder.getInt32Ty(), nullptr, Name + ".addr");
+  ToBeDeleted.push(FakeValAddr);
+
+  if (AsPtr)
+FakeVal = FakeValAddr;
+  else {
+FakeVal =
+Builder.CreateLoad(Builder.getInt32Ty(), FakeValAddr, Name + ".val");
+ToBeDeleted.push(FakeVal);

kiranchandramohan wrote:

Would this delete twice for the `AsPtr` case?

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


[clang] [OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` (PR #67723)

2023-10-05 Thread Kiran Chandramohan via cfe-commits

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


[libunwind] [AMDGPU] Add another SIFoldOperands instance after shrink (PR #67878)

2023-10-05 Thread Jay Foad via cfe-commits

jayfoad wrote:

I've taken another look at this. The patch does not show any benefit from 
running another `SIFoldOperands` pass _after_ `SIShrinkInstructions` per se; 
you get exactly the same results (modulo a couple of add instructions that have 
their operands commuted differently) if you put the second `SIFoldOperands` run 
_before_ `SIShrinkInstructions` instead.

In other words `SIFoldOperands` is not idempotent, and the reason for the that 
seems to be:

> And the reason it only happens for some SUBREV instructions is even more 
> convoluted. It's because SIFoldOperands will sometimes shrink 
> V_SUB_CO_U32_e64 to V_SUBREV_CO_U32_e32 even it does not manage to fold 
> anything into it. This does seem wrong and is probably worth a closer look.

This goes back to https://reviews.llvm.org/D51345. Notice how the code that was 
added to `updateOperand` does the shrinking but does not actually do any 
folding; it returns before we get to 
`Old.ChangeToImmediate`/`Old.substVirtReg`. A second run of `SIFoldOperands` 
will see the shrunk instruction and fold into it.

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


[clang] [AMDGPU] Add another SIFoldOperands instance after shrink (PR #67878)

2023-10-05 Thread Jay Foad via cfe-commits

jayfoad wrote:

I've taken another look at this. The patch does not show any benefit from 
running another `SIFoldOperands` pass _after_ `SIShrinkInstructions` per se; 
you get exactly the same results (modulo a couple of add instructions that have 
their operands commuted differently) if you put the second `SIFoldOperands` run 
_before_ `SIShrinkInstructions` instead.

In other words `SIFoldOperands` is not idempotent, and the reason for the that 
seems to be:

> And the reason it only happens for some SUBREV instructions is even more 
> convoluted. It's because SIFoldOperands will sometimes shrink 
> V_SUB_CO_U32_e64 to V_SUBREV_CO_U32_e32 even it does not manage to fold 
> anything into it. This does seem wrong and is probably worth a closer look.

This goes back to https://reviews.llvm.org/D51345. Notice how the code that was 
added to `updateOperand` does the shrinking but does not actually do any 
folding; it returns before we get to 
`Old.ChangeToImmediate`/`Old.substVirtReg`. A second run of `SIFoldOperands` 
will see the shrunk instruction and fold into it.

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


[clang-tools-extra] [clang-tidy][IncludeCleaner] Fix analysis supression in presence of verbatim spellings (PR #68185)

2023-10-05 Thread kadir çetinkaya via cfe-commits


@@ -179,12 +183,14 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
   if (getCurrentMainFile().endswith(PHeader))
 continue;
 }
-
-if (llvm::none_of(
-IgnoreHeadersRegex,
-[Resolved = (*I.Resolved).getFileEntry().tryGetRealPathName()](
-const llvm::Regex &R) { return R.match(Resolved); }))
-  Unused.push_back(&I);
+auto StdHeader = tooling::stdlib::Header::named(

kadircet wrote:

I think that would be even better, but it would be a regression to current 
users. ATM this code is checking both the StdHeader and the Resolved header. In 
your suggestion we would only check for one or the other.

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


[clang-tools-extra] [clang-tidy][IncludeCleaner] Fix analysis supression in presence of verbatim spellings (PR #68185)

2023-10-05 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/68185

From 91ce80c89689518c20f18efd172628a51aebb769 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 4 Oct 2023 09:38:28 +0200
Subject: [PATCH 1/3] [clang-tidy][IncludeCleaner] Fix analysis supression in
 presence of verbatim spellings

---
 .../clang-tidy/misc/IncludeCleanerCheck.cpp   | 20 ---
 .../clang-tidy/IncludeCleanerTest.cpp | 16 ---
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index fed19bdcc291436..a95a1feb9852b99 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -30,6 +30,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Inclusions/HeaderIncludes.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -97,9 +98,12 @@ bool IncludeCleanerCheck::shouldIgnore(const 
include_cleaner::Header &H) {
   return llvm::any_of(IgnoreHeadersRegex, [&H](const llvm::Regex &R) {
 switch (H.kind()) {
 case include_cleaner::Header::Standard:
+  // We don't trim braces around standard library headers deliberately, so
+  // that they are only matched as , otherwise having just
+  // `.*/vector` might yield false positives.
   return R.match(H.standard().name());
 case include_cleaner::Header::Verbatim:
-  return R.match(H.verbatim());
+  return R.match(H.verbatim().trim("<>\""));
 case include_cleaner::Header::Physical:
   return R.match(H.physical().getFileEntry().tryGetRealPathName());
 }
@@ -179,12 +183,14 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
   if (getCurrentMainFile().endswith(PHeader))
 continue;
 }
-
-if (llvm::none_of(
-IgnoreHeadersRegex,
-[Resolved = (*I.Resolved).getFileEntry().tryGetRealPathName()](
-const llvm::Regex &R) { return R.match(Resolved); }))
-  Unused.push_back(&I);
+auto StdHeader = tooling::stdlib::Header::named(
+I.quote(), PP->getLangOpts().CPlusPlus ? tooling::stdlib::Lang::CXX
+   : tooling::stdlib::Lang::C);
+if (StdHeader && shouldIgnore(*StdHeader))
+  continue;
+if (shouldIgnore(*I.Resolved))
+  continue;
+Unused.push_back(&I);
   }
 
   llvm::StringRef Code = SM->getBufferData(SM->getMainFileID());
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index 0c29b469b617b7c..8da1051a860a8c7 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -59,18 +59,20 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
 #include "foo/qux.h"
 #include "baz/qux/qux.h"
 #include 
+#include 
 )";
 
   const char *PostCode = R"(
 #include "bar.h"
 #include "foo/qux.h"
 #include 
+#include 
 )";
 
   std::vector Errors;
   ClangTidyOptions Opts;
   Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
-  "bar.h;{0};{1};vector",
+  "bar.h;{0};{1};vector;;",
   llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"})),
   llvm::Regex::escape(appendPathFileSystemIndependent({"baz", "qux"})))};
   EXPECT_EQ(
@@ -79,6 +81,7 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
   PreCode, &Errors, "file.cpp", std::nullopt, Opts,
   {{"bar.h", "#pragma once"},
{"vector", "#pragma once"},
+   {"list", "#pragma once"},
{appendPathFileSystemIndependent({"foo", "qux.h"}), "#pragma once"},
{appendPathFileSystemIndependent({"baz", "qux", "qux.h"}),
 "#pragma once"}}));
@@ -163,11 +166,13 @@ TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
 int BarResult = bar();
 int BazResult = baz();
 int QuxResult = qux();
+int PrivResult = test();
+std::vector x;
 )";
 
   ClangTidyOptions Opts;
   Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{
-  "baz.h;" +
+  "public.h;;baz.h;" +
   llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"}))};
   std::vector Errors;
   EXPECT_EQ(PreCode, runCheckOnCode(
@@ -175,18 +180,23 @@ int QuxResult = qux();
  {{"bar.h", R"(#pragma once
   #include "baz.h"
   #include "foo/qux.h"
+  #include "private.h"
   int bar();
+  namespace std { struct vector {}; }
)"},
   {"baz.h", R"(#pragma once

[clang-tools-extra] [clang-tidy][IncludeCleaner] Fix analysis supression in presence of verbatim spellings (PR #68185)

2023-10-05 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

> Overall looks fine, but please update release notes for this (update current 
> entry or even merge them together instead of adding new one). And make sure 
> that there is a commit description for this change when committing, instead 
> of just having only a title.

done.

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


[PATCH] D157613: [Clang][ExtendLifetimes][3/4] Add -fextend-lifetimes flag to Clang to extend the lifetime of local variables

2023-10-05 Thread Jeremy Morse via Phabricator via cfe-commits
jmorse added a comment.

The code changes here look good, but it's time to be annoying about the tests 
-- most of them appear to run the optimisation pipelines, which is testing all 
of LLVM as well as clang in these tests. Possibly a simple fix to that is to 
put these in cross-project-tests. Otherwise, I believe these should be only 
testing the plain codegen output without optimisations at all, i.e. 
--disable-llvm-passes.




Comment at: clang/lib/CodeGen/CGCall.cpp:3492-3499
+// Ignore fake uses and the instructions that load their
+// operands.
+if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::fake_use) {
+  const llvm::Value *FakeUseArg = Intrinsic->getArgOperand(0);
+  if (++II == IE || &*II != FakeUseArg)
+break;
+  continue;

It's a bit ugly to switch away from having a range-based loop, am I right in 
thinking this is because you need to skip the load-to-fake-use? Annoying but 
necessary I guess. Could I request an explicit "II = std::next(II);" though to 
really ram home to the reader that we're skipping an extra instruction, using 
the pre-increment is liable to be missed, and we're not trying to be 
super-concise here IMO.

The addition of the "I" variable looks like it might be un-necessary, that's 
only _used_ by GetStoreIfValid which has a domination assignment above it no?



Comment at: clang/lib/CodeGen/CGDecl.cpp:1729-1730
+  // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
+  // calls for local variables. We are exempting volatile variables and
+  // non-scalars larger than 4 times the size of an unsigned int (32 bytes).
+  // Larger non-scalars are often allocated in memory and may create 
unnecessary

(This could be even more concise; no strong opinion though).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157613

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


[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)

2023-10-05 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Ping.

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


[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)

2023-10-05 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Ping.

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


[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-05 Thread via cfe-commits


@@ -10517,41 +10598,19 @@ bool VectorExprEvaluator::VisitCastExpr(const 
CastExpr *E) {
 return Success(Elts, E);
   }
   case CK_BitCast: {
-// Evaluate the operand into an APInt we can extract from.
-llvm::APInt SValInt;
-if (!EvalAndBitcastToAPInt(Info, SE, SValInt))
+APValue SVal;
+if (!Evaluate(SVal, Info, SE))
   return false;
-// Extract the elements
-QualType EltTy = VTy->getElementType();
-unsigned EltSize = Info.Ctx.getTypeSize(EltTy);
-bool BigEndian = Info.Ctx.getTargetInfo().isBigEndian();
-SmallVector Elts;
-if (EltTy->isRealFloatingType()) {
-  const llvm::fltSemantics &Sem = Info.Ctx.getFloatTypeSemantics(EltTy);
-  unsigned FloatEltSize = EltSize;
-  if (&Sem == &APFloat::x87DoubleExtended())
-FloatEltSize = 80;
-  for (unsigned i = 0; i < NElts; i++) {
-llvm::APInt Elt;
-if (BigEndian)
-  Elt = SValInt.rotl(i * EltSize + FloatEltSize).trunc(FloatEltSize);
-else
-  Elt = SValInt.rotr(i * EltSize).trunc(FloatEltSize);
-Elts.push_back(APValue(APFloat(Sem, Elt)));
-  }
-} else if (EltTy->isIntegerType()) {
-  for (unsigned i = 0; i < NElts; i++) {
-llvm::APInt Elt;
-if (BigEndian)
-  Elt = SValInt.rotl(i*EltSize+EltSize).zextOrTrunc(EltSize);
-else
-  Elt = SValInt.rotr(i*EltSize).zextOrTrunc(EltSize);
-Elts.push_back(APValue(APSInt(Elt, !EltTy->isSignedIntegerType(;
-  }
-} else {
+
+if (!SVal.isInt() && !SVal.isFloat() && !SVal.isVector())
+  // Give up if the input isn't an int, float, or vector.  For example, we
+  // reject "(v4i16)(intptr_t)&a".

DaMatrix wrote:

Well, `handleRValueToRValueBitCast` allows structs and arrays... I'll just 
improve the diagnostic message produced here instead.

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


[clang-tools-extra] llvm-canon (PR #68176)

2023-10-05 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Added @plotfi as a reviewer; one drive-by question is whether adding a new LLVM 
tool like this requires an RFC to be posted to Discourse or not 
(https://llvm.org/docs/DeveloperPolicy.html#introducing-new-components-into-llvm).
 (I don't have any opinions on the tool; just trying to help the review move 
along.)

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


[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-05 Thread via cfe-commits


@@ -7441,6 +7500,28 @@ static bool handleLValueToRValueBitCast(EvalInfo &Info, 
APValue &DestValue,
   return true;
 }
 
+static bool handleLValueToRValueBitCast(EvalInfo &Info, APValue &DestValue,
+APValue &SourceValue,
+const CastExpr *BCE) {
+  assert(CHAR_BIT == 8 && Info.Ctx.getTargetInfo().getCharWidth() == 8 &&
+ "no host or target supports non 8-bit chars");
+  assert(SourceValue.isLValue() &&
+ "LValueToRValueBitcast requires an lvalue operand!");
+
+  if (!checkBitCastConstexprEligibility(&Info, Info.Ctx, BCE))
+return false;

DaMatrix wrote:

I did it this way so that `handleLValueToRValueBitCast` would be able to break 
out early to avoid copying the source LValue into an RValue if the expression 
wasn't eligible, but now that you mention it it doesn't make much sense to do 
an expensive check twice in order to optimize the exceptional path. Will remove 
this from `handleLValueToRValueBitCast`.

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


[clang] [AMDGPU] Add encoding/decoding support for non-result-returning ATOMIC_CSUB instructions (PR #68197)

2023-10-05 Thread Stephen Thomas via cfe-commits

https://github.com/stepthomas updated 
https://github.com/llvm/llvm-project/pull/68197

>From ed42bb63a3fe4a840071b74a3f9613dda815aa29 Mon Sep 17 00:00:00 2001
From: Stephen Thomas 
Date: Wed, 4 Oct 2023 10:16:49 +0100
Subject: [PATCH] [AMDGPU] Add encoding/decoding support for
 non-result-returning ATOMIC_CSUB instructions

The BUFFER_ATOMIC_CSUB and GLOBAL_ATOMIC_CSUB instructions have encodings for
non-value-returning forms, although actually using them isn't supported by
hardware. However, these encodings aren't supported by the backend, meaning
that they can't even be assembled or disassembled.

Add support for the non-returning encodings, but gate actually using them
in instruction selection behind a new feature FeatureAtomicCsubNoRtnInsts,
which no target uses. This does allow the non-returning instructions to be
tested manually and llvm.amdgcn.atomic.csub.ll is extended to cover them.
The feature does not gate assembling or disassembling them, this is now
not an error.
---
 llvm/lib/Target/AMDGPU/AMDGPU.td  |  9 
 llvm/lib/Target/AMDGPU/AMDGPUInstructions.td  |  1 +
 llvm/lib/Target/AMDGPU/BUFInstructions.td | 19 +--
 llvm/lib/Target/AMDGPU/FLATInstructions.td| 18 +--
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |  4 ++
 llvm/lib/Target/AMDGPU/SIInstrInfo.td |  1 +
 .../CodeGen/AMDGPU/llvm.amdgcn.atomic.csub.ll | 51 ---
 llvm/test/MC/AMDGPU/gfx1030_err.s |  6 ---
 8 files changed, 85 insertions(+), 24 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index bf5a7b0a96977c7..9ec062d45ba9f48 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -693,6 +693,13 @@ def FeatureAtomicGlobalPkAddBF16Inst : 
SubtargetFeature<"atomic-global-pk-add-bf
  [FeatureFlatGlobalInsts]
 >;
 
+def FeatureAtomicCsubNoRtnInsts : SubtargetFeature<"atomic-csub-no-rtn-insts",
+  "HasAtomicCsubNoRtnInsts",
+  "true",
+  "Has buffer_atomic_csub and global_atomic_csub instructions that don't "
+  "return original value"
+>;
+
 def FeatureFlatAtomicFaddF32Inst
   : SubtargetFeature<"flat-atomic-fadd-f32-inst",
   "HasFlatAtomicFaddF32Inst",
@@ -1927,6 +1934,8 @@ def HasGWS : Predicate<"Subtarget->hasGWS()">;
 def HasCvtFP8VOP1Bug : Predicate<"Subtarget->hasCvtFP8VOP1Bug()">;
 def HasNoCvtFP8VOP1Bug : Predicate<"!Subtarget->hasCvtFP8VOP1Bug()">;
 
+def HasAtomicCsubNoRtnInsts : 
Predicate<"Subtarget->hasAtomicCsubNoRtnInsts()">;
+
 // Include AMDGPU TD files
 include "SISchedule.td"
 include "GCNProcessors.td"
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td 
b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
index 12ccfd29f26c030..81fc28d293021ab 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
@@ -621,6 +621,7 @@ defm int_amdgcn_flat_atomic_fadd : 
global_addr_space_atomic_op;
 defm int_amdgcn_global_atomic_fadd_v2bf16 : noret_op;
 defm int_amdgcn_global_atomic_fmin : noret_op;
 defm int_amdgcn_global_atomic_fmax : noret_op;
+defm int_amdgcn_global_atomic_csub : noret_op;
 defm int_amdgcn_flat_atomic_fadd : local_addr_space_atomic_op;
 defm int_amdgcn_ds_fadd_v2bf16 : noret_op;
 
diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td 
b/llvm/lib/Target/AMDGPU/BUFInstructions.td
index cec35d1147bb0ae..3e71141431d7dc9 100644
--- a/llvm/lib/Target/AMDGPU/BUFInstructions.td
+++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td
@@ -1022,10 +1022,16 @@ defm BUFFER_ATOMIC_DEC_X2 : MUBUF_Pseudo_Atomics <
   "buffer_atomic_dec_x2", VReg_64, i64
 >;
 
-let SubtargetPredicate = HasGFX10_BEncoding in
-defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_RTN <
-  "buffer_atomic_csub", VGPR_32, i32, int_amdgcn_global_atomic_csub
->;
+let SubtargetPredicate = HasGFX10_BEncoding in {
+  defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_RTN <
+"buffer_atomic_csub", VGPR_32, i32, int_amdgcn_global_atomic_csub
+  >;
+
+  let OtherPredicates = [HasAtomicCsubNoRtnInsts] in
+defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_NO_RTN <
+  "buffer_atomic_csub", VGPR_32, i32
+>;
+}
 
 let SubtargetPredicate = isGFX8GFX9 in {
 def BUFFER_STORE_LDS_DWORD : MUBUF_Pseudo_Store_Lds <"buffer_store_lds_dword">;
@@ -1561,6 +1567,9 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_xor", i64, 
"BUFFER_ATOMIC_XOR_X2">;
 defm : SIBufferAtomicPat<"SIbuffer_atomic_inc", i64, "BUFFER_ATOMIC_INC_X2">;
 defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, "BUFFER_ATOMIC_DEC_X2">;
 
+let SubtargetPredicate = HasAtomicCsubNoRtnInsts in
+defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", 
["noret"]>;
+
 let SubtargetPredicate = isGFX6GFX7GFX10Plus in {
   defm : SIBufferAtomicPat<"SIbuffer_atomic_fmin", f32, "BUFFER_ATOMIC_FMIN">;
   defm : SIBufferAtomicPat<"SIbuffer_atomic_fmax", f32, "BUFFER_ATOMIC_FMAX">;
@@ -2491,7 +2500,7 @@ defm BUFFER_ATOMIC_FCMPSWAP_X2 : 
MUBUF_Real_Atomics_gfx6_gfx7_gfx10<0x05e>;
 defm BUFFER_ATOMIC_FMIN_X2 : MUBU

[clang] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 (PR #67915)

2023-10-05 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/67915

>From c4ce28c942c172e5646b5922f0b02b4169197840 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sun, 1 Oct 2023 21:52:47 +0800
Subject: [PATCH] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when
 Y is a power of 2

---
 .../InstCombine/InstCombineAndOrXor.cpp   |  8 
 llvm/test/Transforms/InstCombine/and.ll   | 44 +--
 2 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index cbdab3e9c5fb91d..4322cc96f5a2b6c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2250,6 +2250,14 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator 
&I) {
 return SelectInst::Create(Cmp, ConstantInt::getNullValue(Ty), Y);
   }
 
+  // Canonicalize:
+  // (X +/- Y) & Y --> ~X & Y when Y is a power of 2.
+  if (match(&I, m_c_And(m_Value(Y), m_OneUse(m_CombineOr(
+m_c_Add(m_Value(X), m_Deferred(Y)),
+m_Sub(m_Value(X), m_Deferred(Y)) &&
+  isKnownToBeAPowerOfTwo(Y, /*OrZero*/ true, /*Depth*/ 0, &I))
+return BinaryOperator::CreateAnd(Builder.CreateNot(X), Y);
+
   const APInt *C;
   if (match(Op1, m_APInt(C))) {
 const APInt *XorC;
diff --git a/llvm/test/Transforms/InstCombine/and.ll 
b/llvm/test/Transforms/InstCombine/and.ll
index 90f027010e2aea6..eb39ff9014ff3a4 100644
--- a/llvm/test/Transforms/InstCombine/and.ll
+++ b/llvm/test/Transforms/InstCombine/and.ll
@@ -1595,8 +1595,8 @@ define <2 x i8> @flip_masked_bit_uniform(<2 x i8> %A) {
 
 define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) {
 ; CHECK-LABEL: @flip_masked_bit_undef(
-; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], 
-; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], 
+; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], 
+; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], 
 ; CHECK-NEXT:ret <2 x i8> [[C]]
 ;
   %B = add <2 x i8> %A, 
@@ -1606,8 +1606,8 @@ define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) {
 
 define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) {
 ; CHECK-LABEL: @flip_masked_bit_nonuniform(
-; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], 
-; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], 
+; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], 
+; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], 
 ; CHECK-NEXT:ret <2 x i8> [[C]]
 ;
   %B = add <2 x i8> %A, 
@@ -2546,3 +2546,39 @@ define i32 @and_zext_eq_zero(i32 %A, i32 %C)  {
   %5 = and i32 %2, %4
   ret i32 %5
 }
+
+define i32 @canonicalize_and_add_power2_or_zero(i32 %x, i32 %y) {
+; CHECK-LABEL: @canonicalize_and_add_power2_or_zero(
+; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]]
+; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]]
+; CHECK-NEXT:call void @use32(i32 [[P2]])
+; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]]
+; CHECK-NEXT:ret i32 [[AND]]
+;
+  %ny = sub i32 0, %y
+  %p2 = and i32 %y, %ny
+  call void @use32(i32 %p2) ; keep p2
+
+  %val = add i32 %x, %p2
+  %and = and i32 %val, %p2
+  ret i32 %and
+}
+
+define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) {
+; CHECK-LABEL: @canonicalize_and_sub_power2_or_zero(
+; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]]
+; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]]
+; CHECK-NEXT:call void @use32(i32 [[P2]])
+; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]]
+; CHECK-NEXT:ret i32 [[AND]]
+;
+  %ny = sub i32 0, %y
+  %p2 = and i32 %y, %ny
+  call void @use32(i32 %p2) ; keep p2
+
+  %val = sub i32 %x, %p2
+  %and = and i32 %val, %p2
+  ret i32 %and
+}

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


[clang] 5d78b78 - [C2X] N3007 Type inference for object definitions

2023-10-05 Thread Aaron Ballman via cfe-commits

Author: Guillot Tony
Date: 2023-10-05T08:11:02-04:00
New Revision: 5d78b78c853830516e734cfa64bfba70479e35dc

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

LOG: [C2X] N3007 Type inference for object definitions

This patches implements the auto keyword from the N3007 standard
specification.
This allows deducing the type of the variable like in C++:
```
auto nb = 1;
auto chr = 'A';
auto str = "String";
```
The list of statements which allows the usage of auto:

* Basic variables declarations (int, float, double, char, char*...)
* Macros declaring a variable with the auto type

The list of statements which will not work with the auto keyword:

* auto arrays
* sizeof(), alignas()
* auto parameters, auto return type
* auto as a struct/typedef member
* uninitialized auto variables
* auto in an union
* auto as a enum type specifier
* auto casts
* auto in an compound literals

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

Added: 
clang/test/C/C2x/n3007.c
clang/test/CodeGen/auto.c
clang/test/Parser/c2x-auto.c
clang/test/Sema/c2x-auto.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaType.cpp
clang/www/c_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 217309c4ecbca52..28f1db29e62fa91 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -240,6 +240,10 @@ def ext_imaginary_constant : Extension<
   "imaginary constants are a GNU extension">, InGroup;
 def ext_integer_complex : Extension<
   "complex integer types are a GNU extension">, InGroup;
+def ext_c23_auto_non_plain_identifier : Extension<
+  "type inference of a declaration other than a plain identifier with optional 
"
+  "trailing attributes is a Clang extension">,
+  InGroup>;
 
 def err_invalid_saturation_spec : Error<"'_Sat' specifier is only valid on "
   "'_Fract' or '_Accum', not '%0'">;
@@ -2388,7 +2392,8 @@ def err_auto_not_allowed : Error<
   "|in conversion function type|here|in lambda parameter"
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
-  "not a function declaration|in requires expression parameter}1">;
+  "not a function declaration|in requires expression parameter"
+  "|in array declaration}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
@@ -2461,7 +2466,8 @@ def err_implied_std_initializer_list_not_found : Error<
 def err_malformed_std_initializer_list : Error<
   "std::initializer_list must be a class template with a single type 
parameter">;
 def err_auto_init_list_from_c : Error<
-  "cannot use __auto_type with initializer list in C">;
+  "cannot use %select{'auto'||'__auto_type'}0 with "
+  "%select{initializer list|array}1 in C">;
 def err_auto_bitfield : Error<
   "cannot pass bit-field as __auto_type initializer in C">;
 
@@ -6664,8 +6670,8 @@ def err_func_def_incomplete_result : Error<
 def err_atomic_specifier_bad_type
 : Error<"_Atomic cannot be applied to "
 "%select{incomplete |array |function |reference |atomic |qualified 
"
-"|sizeless ||integer }0type "
-"%1 %select{|||which is not trivially copyable|}0">;
+"|sizeless ||integer |}0type "
+"%1 %select{|||which is not trivially copyable||in C23}0">;
 def warn_atomic_member_access : Warning<
   "accessing a member of an atomic structure or union is undefined behavior">,
   InGroup>, DefaultError;

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 93515940d15df08..bcc70c04dec91ba 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4038,7 +4038,7 @@ void Parser::ParseDeclarationSpecifiers(
   isStorageClass = true;
   break;
 case tok::kw_auto:
-  if (getLangOpts().CPlusPlus11) {
+  if (getLangOpts().CPlusPlus11 || getLangOpts().C23) {
 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
   isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
  PrevSpec, DiagID, Policy);

diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 2d0d575f173a8b6..781f24cb71ae994 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1375,8 +1375,9 @@ void DeclSpec::Finish(Sema &S

[PATCH] D133289: [C2X] N3007 Type inference for object definitions

2023-10-05 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d78b78c8538: [C2X] N3007 Type inference for object 
definitions (authored by to268, committed by aaron.ballman).

Changed prior to commit:
  https://reviews.llvm.org/D133289?vs=557115&id=557610#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/C/C2x/n3007.c
  clang/test/CodeGen/auto.c
  clang/test/Parser/c2x-auto.c
  clang/test/Sema/c2x-auto.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1186,12 +1186,12 @@
 
   Underspecified object definitions
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3006.htm";>N3006
-  Unknown
+  No
 
 
   Type inference for object declarations
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm";>N3007
-  No
+  Clang 18
 
 
   constexpr for object definitions
Index: clang/test/Sema/c2x-auto.c
===
--- /dev/null
+++ clang/test/Sema/c2x-auto.c
@@ -0,0 +1,137 @@
+// RUN: %clang_cc1 -std=c2x -verify -pedantic -Wno-comments %s
+
+void test_basic_types(void) {
+  auto undefined; // expected-error {{declaration of variable 'undefined' with deduced type 'auto' requires an initializer}}
+  auto auto_int = 4;
+  auto auto_long = 4UL;
+  signed auto a = 1L; // expected-error {{'auto' cannot be signed or unsigned}}
+
+  _Static_assert(_Generic(auto_int, int : 1));
+  _Static_assert(_Generic(auto_long, unsigned long : 1));
+}
+
+void test_complex_types(void) {
+  _Complex auto i = 12.0; // expected-error {{'_Complex auto' is invalid}}
+}
+
+void test_gnu_extensions(void) {
+  auto t = ({ // expected-warning {{use of GNU statement expression extension}}
+auto b = 12;
+b;
+  });
+  _Static_assert(_Generic(t, int : 1));
+}
+
+void test_sizeof_typeof(void) {
+  auto auto_size = sizeof(auto);  // expected-error {{expected expression}}
+  typeof(auto) tpof = 4;  // expected-error {{expected expression}}
+}
+
+void test_casts(void) {
+  auto int_cast = (int)(4 + 3);
+  auto double_cast = (double)(1 / 3);
+  auto long_cast = (long)(4UL + 3UL);
+  auto auto_cast = (auto)(4 + 3); // expected-error {{expected expression}}
+
+  _Static_assert(_Generic(int_cast, int : 1));
+  _Static_assert(_Generic(double_cast, double : 1));
+  _Static_assert(_Generic(long_cast, long : 1));
+}
+
+void test_compound_literral(void) {
+  auto int_cl = (int){13};
+  auto double_cl = (double){2.5};
+  auto array[] = { 1, 2, 3 }; // expected-error {{cannot use 'auto' with array in C}}
+
+  auto auto_cl = (auto){13};  // expected-error {{expected expression}}
+
+  _Static_assert(_Generic(int_cl, int : 1));
+  _Static_assert(_Generic(double_cl, double : 1));
+}
+
+void test_array_pointers(void) {
+  double array[3] = { 0 };
+  auto a = array;
+  auto b = &array;
+
+  _Static_assert(_Generic(array, double * : 1));
+  _Static_assert(_Generic(a, double * : 1));
+  _Static_assert(_Generic(b, double (*)[3] : 1));
+}
+
+void test_typeof() {
+  int typeof_target();
+  auto result = (typeof(typeof_target())){12};
+
+  _Static_assert(_Generic(result, int : 1));
+}
+
+void test_qualifiers(const int y) {
+  const auto a = 12;
+  auto b = y;
+  static auto c = 1UL;
+  int* pa = &a; // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
+  const int* pb = &b;
+  int* pc = &c; // expected-warning {{incompatible pointer types initializing 'int *' with an expression of type 'unsigned long *'}}
+
+  _Static_assert(_Generic(a, int : 1));
+  _Static_assert(_Generic(b, int : 1));
+  _Static_assert(_Generic(c, unsigned long : 1));
+  _Static_assert(_Generic(pa, int * : 1));
+  _Static_assert(_Generic(pb, const int * : 1));
+  _Static_assert(_Generic(pc, int * : 1));
+}
+
+void test_strings(void) {
+  auto str = "this is a string";
+  auto str2[] = "this is a string";   // expected-warning {{type inference of a declaration other than a plain identifier with optional trailing attributes is a Clang extension}}
+  auto (str3) = "this is a string";
+  auto (((str4))) = "this is a string";
+
+  _Static_assert(_Generic(str, char * : 1));
+  _Static_assert(_Generic(str2, char * : 1));
+  _Static_assert(_Generic(str3, char * : 1));
+  _Static_assert(_Generic(str4, char * : 1));
+}
+
+void test_pointers(void) {
+  auto a = 12;
+  auto *ptr = &a; // expected-warning {{type inference of a declaration other than a plain identifier with optional trailing attributes is a Clang ex

[clang] [clang][driver] Fix an issue where clang does not correctly resolve the system header if invoked via symlink (on MacOS) (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

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


[clang] [clang][driver] Fix an issue where clang does not correctly resolve the system header if invoked via symlink (on MacOS) (PR #68091)

2023-10-05 Thread Liviu Ionescu via cfe-commits

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-05 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/68276

>From 5e95a4318434e0e72fe37ebfb286405d40ff7a73 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Thu, 5 Oct 2023 02:39:12 +0200
Subject: [PATCH] [Sema] Add check for bitfield assignments to integral types

We noticed that clang does not check for bitfield assignment widths,
while gcc does check this.

gcc produced a warning like so for it's -Wconversion flag:

$ gcc -Wconversion -c test.c
test.c: In function 'foo':
test.c:10:15: warning: conversion from 'int' to 'signed char:7' may
change value [-Wconversion]
   10 |  vxx.bf = x; // no warning
  |   ^

This change simply adds this for integral types under the -Wconversion
compiler option.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +++
 clang/lib/Sema/SemaChecking.cpp   | 10 +++
 clang/test/SemaCXX/bitfield-width.c   | 26 +++
 3 files changed, 39 insertions(+)
 create mode 100644 clang/test/SemaCXX/bitfield-width.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 28f1db29e62fa91..5bed9d825b65d52 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6171,6 +6171,9 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+  "bit-field %0 is not wide enough to store type of %1 ">,
+  InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 446e35218bff0ad..81c5fec333fe7e9 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14299,6 +14299,16 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
 << BitsNeeded << ED << WidthExpr->getSourceRange();
   }
+} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
+  TypeInfo TI = S.Context.getTypeInfo(OriginalInit->getType());
+  if (TI.Width > FieldWidth) {
+Expr *WidthExpr = Bitfield->getBitWidth();
+S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
+<< Bitfield << OriginalInit->getType();
+S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
+<< TI.Width << OriginalInit->getType()
+<< WidthExpr->getSourceRange();
+  }
 }
 
 return false;
diff --git a/clang/test/SemaCXX/bitfield-width.c 
b/clang/test/SemaCXX/bitfield-width.c
new file mode 100644
index 000..375a3799e95d439
--- /dev/null
+++ b/clang/test/SemaCXX/bitfield-width.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s
+
+typedef struct _xx {
+ int bf:9; // expected-note{{widen this field to 32 bits to store all 
values of 'int'}}
+ // expected-note@-1{{widen this field to 16 bits to store all values of 
'short'}}
+ // expected-note@-2{{widen this field to 32 bits to store all values of 
'int'}}
+ } xx, *pxx; 
+
+ xx vxx;
+
+ void foo1(int x) { 
+ vxx.bf = x; // expected-warning{{bit-field 'bf' is not wide enough to 
store type of 'int'}}
+ } 
+ void foo2(short x) { 
+ vxx.bf = x; // expected-warning{{bit-field 'bf' is not wide enough to 
store type of 'short'}}
+ } 
+ void foo3(char x) { 
+ vxx.bf = x; // no warning expected
+ } 
+ void foo5(void * x) { 
+ vxx.bf = (int)x; // expected-warning{{cast to smaller integer type 'int' 
from 'void *'}}
+ // expected-warning@-1{{bit-field 'bf' is not wide enough to store type 
of 'int'}}
+ } 
+ int fee(void) {
+ return 0;
+ }

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


[clang] [OpenMP] Prevent AMDGPU from overriding visibility on DT_nohost variables (PR #68264)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/68264

>From 52d11d0d975f03a3cd2760b42236b5ec8097331b Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Wed, 4 Oct 2023 16:50:20 -0500
Subject: [PATCH 1/2] [OpenMP] Prevent AMDGPU from overriding visibility on
 DT_nohost variables

Summary:
There's some logic in the AMDGPU target that manually resets the
requested visibility of certain variables. This was triggering when we
set a constant variable in OpenMP. However, we shouldn't do this for
OpenMP when the variable has the `nohost` type. That implies that the
variable is not visible to the host and therefore does not need to be
visible, so we should respect the original value of it.
---
 clang/lib/CodeGen/Targets/AMDGPU.cpp| 4 
 clang/test/OpenMP/target_visibility.cpp | 6 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index dc628b7345f59fd..70f906a42e6d9c4 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -308,6 +308,10 @@ static bool requiresAMDGPUProtectedVisibility(const Decl 
*D,
   if (GV->getVisibility() != llvm::GlobalValue::HiddenVisibility)
 return false;
 
+  if (auto *Attr = D->getAttr())
+if (OMPDeclareTargetDeclAttr::DT_NoHost == Attr->getDevType())
+  return false;
+
   return D->hasAttr() ||
  (isa(D) && D->hasAttr()) ||
  (isa(D) &&
diff --git a/clang/test/OpenMP/target_visibility.cpp 
b/clang/test/OpenMP/target_visibility.cpp
index 938d164df89bffb..2ed90d4b8ba9a77 100644
--- a/clang/test/OpenMP/target_visibility.cpp
+++ b/clang/test/OpenMP/target_visibility.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
 // expected-no-diagnostics
 
 
@@ -21,6 +21,10 @@ void B::bar() { A a; a.foo(); }
 void B::sbar() { A::sfoo(); }
 #pragma omp declare target to(B::bar, B::sbar)
 
+[[gnu::visibility("hidden")]] extern const int x = 0;
+#pragma omp declare target to(x) device_type(nohost)
+
+// CHECK-DAG: @x = hidden{{.*}} constant i32 0
 // CHECK-DAG: define hidden void @_ZN1B4sbarEv()
 // CHECK-DAG: define linkonce_odr hidden void @_ZN1A4sfooEv()
 // CHECK-DAG: define hidden void @_ZN1B3barEv(

>From 0be9c9fc769eb580a602ce075d8904d683c3596b Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 5 Oct 2023 07:41:24 -0500
Subject: [PATCH 2/2] Refine logic

We need to change the visibility to protected for declare target
variables, this is because they need to be readable by the host runtime.
---
 clang/lib/CodeGen/Targets/AMDGPU.cpp| 4 ++--
 clang/test/OpenMP/target_visibility.cpp | 6 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index 70f906a42e6d9c4..def8bf45af761c2 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -309,8 +309,8 @@ static bool requiresAMDGPUProtectedVisibility(const Decl *D,
 return false;
 
   if (auto *Attr = D->getAttr())
-if (OMPDeclareTargetDeclAttr::DT_NoHost == Attr->getDevType())
-  return false;
+return isa(D) && OMPDeclareTargetDeclAttr::DT_NoHost !=
+  Attr->getDevType();
 
   return D->hasAttr() ||
  (isa(D) && D->hasAttr()) ||
diff --git a/clang/test/OpenMP/target_visibility.cpp 
b/clang/test/OpenMP/target_visibility.cpp
index 2ed90d4b8ba9a77..16c1e5aa6940bec 100644
--- a/clang/test/OpenMP/target_visibility.cpp
+++ b/clang/test/OpenMP/target_visibility.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s --check-prefixes=CHECK,AMDGPU
 // expected-no-diagnostics
 
 
@@ -24,7 +24,11 @@ void B::sbar() { A::sfoo(); }
 [[gnu::visibility("hidden")]] extern const int x = 0;
 #pragma omp declare target to(x) device_type(nohost)
 
+[[gnu::visibility("hidden")]] int y = 0;
+#pragma omp declare target to(y)
+
 

[clang] [OpenMP] Prevent AMDGPU from overriding visibility on DT_nohost variables (PR #68264)

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

jhuber6 wrote:

> This stuff looks very cuda/opencl specific. It's definitely surprising for 
> C++ code. Do we need it for openmp? If not it seems better to guard the hack 
> with visibility behind if (hip)

You reminded me that I need to refine this logic as well. What it's doing here 
is basically the same as what we want to happen. If someone uses `#pragma omp 
declare target` on a variable without `device_type(nohost)` that means the host 
runtime will need to register it. If it's hidden then that will be a lookup 
error. I refined the logic to do the same handling for OpenMP, but ignore it if 
it's `DT_nohost` because then there's no registration code required.

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


[clang] [OpenMP] Prevent AMDGPU from overriding visibility on DT_nohost variables (PR #68264)

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


@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s

jhuber6 wrote:

I just added `--check-prefixes=CHECK,AMDGPU` for the differences. Figured it's 
not worth making a new test just for this.

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


[clang] [Driver] Silence stdlib warning when linking C on FreeBSD (PR #68011)

2023-10-05 Thread Egor Zhdan via cfe-commits

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

The Darwin toolchain also does this. This change LGTM, although I'm not an 
expert in FreeBSD.

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


[clang] dc1000d - Revert "[C2X] N3007 Type inference for object definitions"

2023-10-05 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-10-05T08:52:12-04:00
New Revision: dc1000d5b24cfad2b0429b55f034488397d809dc

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

LOG: Revert "[C2X] N3007 Type inference for object definitions"

This reverts commit 5d78b78c853830516e734cfa64bfba70479e35dc.

Reverting due to the failure found by:
https://lab.llvm.org/buildbot/#/builders/245/builds/14999

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaType.cpp
clang/www/c_status.html

Removed: 
clang/test/C/C2x/n3007.c
clang/test/CodeGen/auto.c
clang/test/Parser/c2x-auto.c
clang/test/Sema/c2x-auto.c



diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 28f1db29e62fa91..217309c4ecbca52 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -240,10 +240,6 @@ def ext_imaginary_constant : Extension<
   "imaginary constants are a GNU extension">, InGroup;
 def ext_integer_complex : Extension<
   "complex integer types are a GNU extension">, InGroup;
-def ext_c23_auto_non_plain_identifier : Extension<
-  "type inference of a declaration other than a plain identifier with optional 
"
-  "trailing attributes is a Clang extension">,
-  InGroup>;
 
 def err_invalid_saturation_spec : Error<"'_Sat' specifier is only valid on "
   "'_Fract' or '_Accum', not '%0'">;
@@ -2392,8 +2388,7 @@ def err_auto_not_allowed : Error<
   "|in conversion function type|here|in lambda parameter"
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
-  "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "not a function declaration|in requires expression parameter}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
@@ -2466,8 +2461,7 @@ def err_implied_std_initializer_list_not_found : Error<
 def err_malformed_std_initializer_list : Error<
   "std::initializer_list must be a class template with a single type 
parameter">;
 def err_auto_init_list_from_c : Error<
-  "cannot use %select{'auto'||'__auto_type'}0 with "
-  "%select{initializer list|array}1 in C">;
+  "cannot use __auto_type with initializer list in C">;
 def err_auto_bitfield : Error<
   "cannot pass bit-field as __auto_type initializer in C">;
 
@@ -6670,8 +6664,8 @@ def err_func_def_incomplete_result : Error<
 def err_atomic_specifier_bad_type
 : Error<"_Atomic cannot be applied to "
 "%select{incomplete |array |function |reference |atomic |qualified 
"
-"|sizeless ||integer |}0type "
-"%1 %select{|||which is not trivially copyable||in C23}0">;
+"|sizeless ||integer }0type "
+"%1 %select{|||which is not trivially copyable|}0">;
 def warn_atomic_member_access : Warning<
   "accessing a member of an atomic structure or union is undefined behavior">,
   InGroup>, DefaultError;

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index bcc70c04dec91ba..93515940d15df08 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4038,7 +4038,7 @@ void Parser::ParseDeclarationSpecifiers(
   isStorageClass = true;
   break;
 case tok::kw_auto:
-  if (getLangOpts().CPlusPlus11 || getLangOpts().C23) {
+  if (getLangOpts().CPlusPlus11) {
 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
   isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
  PrevSpec, DiagID, Policy);

diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 781f24cb71ae994..2d0d575f173a8b6 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1375,9 +1375,8 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy 
&Policy) {
 StorageClassSpecLoc = SourceLocation();
   }
   // Diagnose if we've recovered from an ill-formed 'auto' storage class
-  // specifier in a pre-C++11 dialect of C++ or in a pre-C23 dialect of C.
-  if (!S.getLangOpts().CPlusPlus11 && !S.getLangOpts().C23 &&
-  TypeSpecType == TST_auto)
+  // specifier in a pre-C++11 dialect of C++.
+  if (!S.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto)
 S.Diag(TSTLoc, diag::ext_auto_type_specifier);
   if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11 &&
   StorageClassSpec == SCS_auto)


[clang] [OpenMP] Prevent AMDGPU from overriding visibility on DT_nohost variables (PR #68264)

2023-10-05 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 5099dc341f7fa9baec160c2991072eb445469d46 
0be9c9fc769eb580a602ce075d8904d683c3596b -- 
clang/lib/CodeGen/Targets/AMDGPU.cpp clang/test/OpenMP/target_visibility.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index def8bf45af76..4fb0aa352931 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -309,8 +309,8 @@ static bool requiresAMDGPUProtectedVisibility(const Decl *D,
 return false;
 
   if (auto *Attr = D->getAttr())
-return isa(D) && OMPDeclareTargetDeclAttr::DT_NoHost !=
-  Attr->getDevType();
+return isa(D) &&
+   OMPDeclareTargetDeclAttr::DT_NoHost != Attr->getDevType();
 
   return D->hasAttr() ||
  (isa(D) && D->hasAttr()) ||

``




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


[clang] [OpenMP] Prevent AMDGPU from overriding visibility on DT_nohost variables (PR #68264)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/68264

>From 52d11d0d975f03a3cd2760b42236b5ec8097331b Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Wed, 4 Oct 2023 16:50:20 -0500
Subject: [PATCH 1/2] [OpenMP] Prevent AMDGPU from overriding visibility on
 DT_nohost variables

Summary:
There's some logic in the AMDGPU target that manually resets the
requested visibility of certain variables. This was triggering when we
set a constant variable in OpenMP. However, we shouldn't do this for
OpenMP when the variable has the `nohost` type. That implies that the
variable is not visible to the host and therefore does not need to be
visible, so we should respect the original value of it.
---
 clang/lib/CodeGen/Targets/AMDGPU.cpp| 4 
 clang/test/OpenMP/target_visibility.cpp | 6 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index dc628b7345f59fd..70f906a42e6d9c4 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -308,6 +308,10 @@ static bool requiresAMDGPUProtectedVisibility(const Decl 
*D,
   if (GV->getVisibility() != llvm::GlobalValue::HiddenVisibility)
 return false;
 
+  if (auto *Attr = D->getAttr())
+if (OMPDeclareTargetDeclAttr::DT_NoHost == Attr->getDevType())
+  return false;
+
   return D->hasAttr() ||
  (isa(D) && D->hasAttr()) ||
  (isa(D) &&
diff --git a/clang/test/OpenMP/target_visibility.cpp 
b/clang/test/OpenMP/target_visibility.cpp
index 938d164df89bffb..2ed90d4b8ba9a77 100644
--- a/clang/test/OpenMP/target_visibility.cpp
+++ b/clang/test/OpenMP/target_visibility.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
 // expected-no-diagnostics
 
 
@@ -21,6 +21,10 @@ void B::bar() { A a; a.foo(); }
 void B::sbar() { A::sfoo(); }
 #pragma omp declare target to(B::bar, B::sbar)
 
+[[gnu::visibility("hidden")]] extern const int x = 0;
+#pragma omp declare target to(x) device_type(nohost)
+
+// CHECK-DAG: @x = hidden{{.*}} constant i32 0
 // CHECK-DAG: define hidden void @_ZN1B4sbarEv()
 // CHECK-DAG: define linkonce_odr hidden void @_ZN1A4sfooEv()
 // CHECK-DAG: define hidden void @_ZN1B3barEv(

>From d770f8a59d18d29e6df851c17c38143629464a3e Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 5 Oct 2023 07:41:24 -0500
Subject: [PATCH 2/2] Refine logic

We need to change the visibility to protected for declare target
variables, this is because they need to be readable by the host runtime.
---
 clang/lib/CodeGen/Targets/AMDGPU.cpp| 4 ++--
 clang/test/OpenMP/target_visibility.cpp | 6 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index 70f906a42e6d9c4..4fb0aa352931ca1 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -309,8 +309,8 @@ static bool requiresAMDGPUProtectedVisibility(const Decl *D,
 return false;
 
   if (auto *Attr = D->getAttr())
-if (OMPDeclareTargetDeclAttr::DT_NoHost == Attr->getDevType())
-  return false;
+return isa(D) &&
+   OMPDeclareTargetDeclAttr::DT_NoHost != Attr->getDevType();
 
   return D->hasAttr() ||
  (isa(D) && D->hasAttr()) ||
diff --git a/clang/test/OpenMP/target_visibility.cpp 
b/clang/test/OpenMP/target_visibility.cpp
index 2ed90d4b8ba9a77..16c1e5aa6940bec 100644
--- a/clang/test/OpenMP/target_visibility.cpp
+++ b/clang/test/OpenMP/target_visibility.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s 
-fopenmp-is-target-device -o - | FileCheck %s --check-prefixes=CHECK,AMDGPU
 // expected-no-diagnostics
 
 
@@ -24,7 +24,11 @@ void B::sbar() { A::sfoo(); }
 [[gnu::visibility("hidden")]] extern const int x = 0;
 #pragma omp declare target to(x) device_type(nohost)
 
+[[gnu::visibility("hidden")]] int y = 0;
+#pragma omp declare target to(y

[clang-tools-extra] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #67592)

2023-10-05 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> struct S { int x; };
> namespace NS {
> class C {};
> }
> 
> S foo(S s1, NS::C c1) {
>   S s12{12};
>   using namespace NS;
>   C c;
> }

@AaronBallman By pretty printed you mean the use of __PRETTY_FUNCTION__ right?
In MSVC this macro is not defined. The equivalent one is FUNCSIG, although 
maybe not quite the same. 
On Linux GCC and clang are generating the same string. See 
https://godbolt.org/z/zd37orvdG
I can't figure out from godbolt, what string is generated for clang on Windows. 
 Running on the command line (without my patch), in the asm output I see
.asciz  "S foo(S, NS::C)" 
That's different than what MSVC is generating with __FUNCSIG__.  If we want to 
generate struct S foo(struct S,class NS::C then this seems to always have been 
broken. Right?

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


  1   2   3   4   >