[clang] ebd3eef - [Frontend] Use std::optional in TextDiagnostic.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:22:41-08:00
New Revision: ebd3eef0b2b0255e4cf1cd825019ff66d3cd1426

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

LOG: [Frontend] Use std::optional in TextDiagnostic.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Frontend/TextDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 52129aa4ff2b..809d5309d1af 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 
 using namespace clang;
 
@@ -923,7 +924,7 @@ void 
TextDiagnostic::emitBuildingModuleLocation(FullSourceLoc Loc,
 }
 
 /// Find the suitable set of lines to show to include a set of ranges.
-static llvm::Optional>
+static std::optional>
 findLinesForRange(const CharSourceRange &R, FileID FID,
   const SourceManager &SM) {
   if (!R.isValid())



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


[clang] cd45f1b - [Rewrite] Use std::optional in InclusionRewriter.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:21:35-08:00
New Revision: cd45f1be8f9e218aebf2c20511bba6b0a5e34b96

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

LOG: [Rewrite] Use std::optional in InclusionRewriter.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Frontend/Rewrite/InclusionRewriter.cpp

Removed: 




diff  --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp 
b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
index 9141adec58c48..37178d12a4790 100644
--- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -18,6 +18,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 using namespace clang;
 using namespace llvm;
@@ -252,7 +253,8 @@ bool InclusionRewriter::IsIfAtLocationTrue(SourceLocation 
Loc) const {
 }
 
 void InclusionRewriter::detectMainFileEOL() {
-  Optional FromFile = *SM.getBufferOrNone(SM.getMainFileID());
+  std::optional FromFile =
+  *SM.getBufferOrNone(SM.getMainFileID());
   assert(FromFile);
   if (!FromFile)
 return; // Should never happen, but whatever.



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


[clang] 1ce8e35 - [Frontend] Use std::optional in CompilerInvocation.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:19:23-08:00
New Revision: 1ce8e3543bba774e5200c73574420f1afd9d2fcd

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

LOG: [Frontend] Use std::optional in CompilerInvocation.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 06a8815dd959..ef3fc6c2afb7 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -98,6 +98,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -170,18 +171,19 @@ CompilerInvocationRefBase::~CompilerInvocationRefBase() = 
default;
 #include "clang/Driver/Options.inc"
 #undef SIMPLE_ENUM_VALUE_TABLE
 
-static llvm::Optional normalizeSimpleFlag(OptSpecifier Opt,
-unsigned TableIndex,
-const ArgList &Args,
-DiagnosticsEngine &Diags) {
+static std::optional normalizeSimpleFlag(OptSpecifier Opt,
+   unsigned TableIndex,
+   const ArgList &Args,
+   DiagnosticsEngine &Diags) {
   if (Args.hasArg(Opt))
 return true;
   return std::nullopt;
 }
 
-static Optional normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
-  const ArgList &Args,
-  DiagnosticsEngine &) {
+static std::optional normalizeSimpleNegativeFlag(OptSpecifier Opt,
+   unsigned,
+   const ArgList &Args,
+   DiagnosticsEngine &) {
   if (Args.hasArg(Opt))
 return false;
   return std::nullopt;
@@ -206,7 +208,7 @@ template (), bool> = false>
 static auto makeFlagToValueNormalizer(T Value) {
   return [Value](OptSpecifier Opt, unsigned, const ArgList &Args,
- DiagnosticsEngine &) -> Optional {
+ DiagnosticsEngine &) -> std::optional {
 if (Args.hasArg(Opt))
   return Value;
 return std::nullopt;
@@ -221,9 +223,9 @@ static auto makeFlagToValueNormalizer(T Value) {
 
 static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,
 OptSpecifier OtherOpt) {
-  return [Value, OtherValue, OtherOpt](OptSpecifier Opt, unsigned,
-   const ArgList &Args,
-   DiagnosticsEngine &) -> Optional {
+  return [Value, OtherValue,
+  OtherOpt](OptSpecifier Opt, unsigned, const ArgList &Args,
+DiagnosticsEngine &) -> std::optional {
 if (const Arg *A = Args.getLastArg(Opt, OtherOpt)) {
   return A->getOption().matches(Opt) ? Value : OtherValue;
 }
@@ -270,7 +272,7 @@ denormalizeString(SmallVectorImpl &Args, 
const char *Spelling,
   denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, 
Twine(Value));
 }
 
-static Optional
+static std::optional
 findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
   for (int I = 0, E = Table.Size; I != E; ++I)
 if (Name == Table.Table[I].Name)
@@ -279,7 +281,7 @@ findValueTableByName(const SimpleEnumValueTable &Table, 
StringRef Name) {
   return std::nullopt;
 }
 
-static Optional
+static std::optional
 findValueTableByValue(const SimpleEnumValueTable &Table, unsigned Value) {
   for (int I = 0, E = Table.Size; I != E; ++I)
 if (Value == Table.Table[I].Value)
@@ -288,10 +290,10 @@ findValueTableByValue(const SimpleEnumValueTable &Table, 
unsigned Value) {
   return std::nullopt;
 }
 
-static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
-unsigned TableIndex,
-const ArgList &Args,
-DiagnosticsEngine &Diags) {
+static std::optional normalizeSimpleEnum(OptSpecifier Opt,
+   unsigned TableIndex,
+   const ArgList &Args,
+   DiagnosticsEngine &Diags) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
 
@@ -334,9 +336,10 @@ 

[clang] 8d83867 - [Frontend] Use std::optional in CompilerInstance.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:16:32-08:00
New Revision: 8d83867dc913bb1b40571c8b36726e22ff824a0d

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

LOG: [Frontend] Use std::optional in CompilerInstance.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c039169ff150..b3ec8e48be82 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -55,6 +55,7 @@
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 #include 
 
@@ -804,7 +805,7 @@ std::unique_ptr 
CompilerInstance::createDefaultOutputFile(
 bool Binary, StringRef InFile, StringRef Extension, bool 
RemoveFileOnSignal,
 bool CreateMissingDirectories, bool ForceUseTemporary) {
   StringRef OutputPath = getFrontendOpts().OutputFile;
-  Optional> PathStorage;
+  std::optional> PathStorage;
   if (OutputPath.empty()) {
 if (InFile == "-" || Extension.empty()) {
   OutputPath = "-";
@@ -848,7 +849,7 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 
   // If '-working-directory' was passed, the output filename should be
   // relative to that.
-  Optional> AbsPath;
+  std::optional> AbsPath;
   if (OutputPath != "-" && !llvm::sys::path::is_absolute(OutputPath)) {
 AbsPath.emplace(OutputPath);
 FileMgr->FixupRelativePath(*AbsPath);
@@ -856,7 +857,7 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
   }
 
   std::unique_ptr OS;
-  Optional OSFile;
+  std::optional OSFile;
 
   if (UseTemporary) {
 if (OutputPath == "-")



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


[clang] e90e848 - [Frontend] Use std::optional in ASTUnit.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:12:19-08:00
New Revision: e90e8487dce37ace5cfabb5b27cb0dc0ba5b566f

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

LOG: [Frontend] Use std::optional in ASTUnit.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Frontend/ASTUnit.cpp

Removed: 




diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index c133746734704..f5d4b56bca027 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -99,6 +99,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -734,7 +735,7 @@ void FilterAndStoreDiagnosticConsumer::HandleDiagnostic(
 }
 
 if (StandaloneDiags) {
-  llvm::Optional StoredDiag;
+  std::optional StoredDiag;
   if (!ResultDiag) {
 StoredDiag.emplace(Level, Info);
 ResultDiag = &*StoredDiag;
@@ -1378,7 +1379,7 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
   SmallVector NewPreambleDiags;
   ASTUnitPreambleCallbacks Callbacks;
   {
-llvm::Optional Capture;
+std::optional Capture;
 if (CaptureDiagnostics != CaptureDiagsKind::None)
   Capture.emplace(CaptureDiagnostics, *Diagnostics, &NewPreambleDiags,
   &NewPreambleDiagsStandalone);
@@ -2243,7 +2244,7 @@ void ASTUnit::CodeComplete(
   Clang->setCodeCompletionConsumer(AugmentedConsumer);
 
   auto getUniqueID =
-  [&FileMgr](StringRef Filename) -> Optional {
+  [&FileMgr](StringRef Filename) -> std::optional 
{
 if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
   return Status->getUniqueID();
 return std::nullopt;



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


[clang] 538401d - [Format] Use std::optional in QualifierAlignmentFixer.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:09:06-08:00
New Revision: 538401da1d16e4ca84423f6da3526c72b2fdb493

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

LOG: [Format] Use std::optional in QualifierAlignmentFixer.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Format/QualifierAlignmentFixer.cpp

Removed: 




diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 174adb160c63..6ee0d6da76a4 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Support/Regex.h"
 
 #include 
+#include 
 
 #define DEBUG_TYPE "format-qualifier-alignment-fixer"
 
@@ -66,7 +67,7 @@ std::pair 
QualifierAlignmentFixer::analyze(
NextStartColumn, LastStartColumn);
   if (!Env)
 return {};
-  llvm::Optional CurrentCode;
+  std::optional CurrentCode;
   tooling::Replacements Fixes;
   for (size_t I = 0, E = Passes.size(); I < E; ++I) {
 std::pair PassFixes = Passes[I](*Env);



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


[clang] 7d3178d - [Format] Use std::optional in Format.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:07:59-08:00
New Revision: 7d3178d76aa8d67bfbacd45794ef5740823a43c0

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

LOG: [Format] Use std::optional in Format.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Format/Format.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 983246d6cca5..b71add7f2e28 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -46,6 +46,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -3455,7 +3456,7 @@ reformat(const FormatStyle &Style, StringRef Code,
NextStartColumn, LastStartColumn);
   if (!Env)
 return {};
-  llvm::Optional CurrentCode;
+  std::optional CurrentCode;
   tooling::Replacements Fixes;
   unsigned Penalty = 0;
   for (size_t I = 0, E = Passes.size(); I < E; ++I) {



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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

The removal is also breaking ChromeOS builds which use -Xpattern in some cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[clang] 7edc552 - [Format] Use std::optional in ContinuationIndenter.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:06:32-08:00
New Revision: 7edc552d0ae4d0b2e3525bc64d428e7b3bc96db0

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

LOG: [Format] Use std::optional in ContinuationIndenter.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6c8f7eb6e2902..04244c1468278 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -21,6 +21,7 @@
 #include "clang/Format/Format.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Debug.h"
+#include 
 
 #define DEBUG_TYPE "format-indenter"
 
@@ -149,7 +150,7 @@ static bool opensProtoMessageField(const FormatToken 
&LessTok,
 // Returns the delimiter of a raw string literal, or std::nullopt if TokenText
 // is not the text of a raw string literal. The delimiter could be the empty
 // string.  For example, the delimiter of R"deli(cont)deli" is deli.
-static llvm::Optional getRawStringDelimiter(StringRef TokenText) {
+static std::optional getRawStringDelimiter(StringRef TokenText) {
   if (TokenText.size() < 5 // The smallest raw string possible is 'R"()"'.
   || !TokenText.startswith("R\"") || !TokenText.endswith("\"")) {
 return std::nullopt;



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


[clang] f655cb0 - [ExtractAPI] Use std::optional in ExtractAPIConsumer.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T23:03:10-08:00
New Revision: f655cb0f580ffab1a7d2ffb73043661bba449a44

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

LOG: [ExtractAPI] Use std::optional in ExtractAPIConsumer.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 7c56818156e3..5f185d0bd6aa 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -47,6 +47,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -61,9 +62,9 @@ StringRef getTypedefName(const TagDecl *Decl) {
   return {};
 }
 
-Optional getRelativeIncludeName(const CompilerInstance &CI,
- StringRef File,
- bool *IsQuoted = nullptr) {
+std::optional getRelativeIncludeName(const CompilerInstance &CI,
+  StringRef File,
+  bool *IsQuoted = nullptr) {
   assert(CI.hasFileManager() &&
  "CompilerInstance does not have a FileNamager!");
 



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


[clang] e8aee7e - [linux] Use std::optional in DirectoryWatcher-linux.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:55:06-08:00
New Revision: e8aee7ef73a759e9307fccb0fc3329d676eca737

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

LOG: [linux] Use std::optional in DirectoryWatcher-linux.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp

Removed: 




diff  --git a/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp 
b/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
index e9950088e1f1d..9b3d2571f29f6 100644
--- a/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ b/clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -25,6 +25,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -72,7 +73,7 @@ struct SemaphorePipe {
   const int FDWrite;
   bool OwnsFDs;
 
-  static llvm::Optional create() {
+  static std::optional create() {
 int InotifyPollingStopperFDs[2];
 if (pipe2(InotifyPollingStopperFDs, O_CLOEXEC) == -1)
   return std::nullopt;



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


[clang] 0a4c70f - [Targets] Use std::optional in RISCV.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:52:29-08:00
New Revision: 0a4c70feb19fd95689e9a99d27114e217ada5da0

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

LOG: [Targets] Use std::optional in RISCV.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index b76ef15fa3771..86f7e026ebfe7 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 using namespace clang;
 using namespace clang::targets;
@@ -270,7 +271,7 @@ RISCVTargetInfo::getVScaleRange(const LangOptions 
&LangOpts) const {
 /// Return true if has this feature, need to sync with handleTargetFeatures.
 bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
   bool Is64Bit = getTriple().getArch() == llvm::Triple::riscv64;
-  auto Result = llvm::StringSwitch>(Feature)
+  auto Result = llvm::StringSwitch>(Feature)
 .Case("riscv", true)
 .Case("riscv32", !Is64Bit)
 .Case("riscv64", Is64Bit)



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


[clang] defa6ee - [Basic] Use std::optional in TargetID.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:51:10-08:00
New Revision: defa6eec7d00057cf4d481fe64e745f1b688c646

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

LOG: [Basic] Use std::optional in TargetID.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Basic/TargetID.cpp

Removed: 




diff  --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index 23c0281c1989..20e07cb7266a 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -12,6 +12,7 @@
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 
 namespace clang {
 
@@ -62,7 +63,7 @@ llvm::StringRef getProcessorFromTargetID(const llvm::Triple 
&T,
 // A target ID is a processor name followed by a list of target features
 // delimited by colon. Each target feature is a string post-fixed by a plus
 // or minus sign, e.g. gfx908:sramecc+:xnack-.
-static llvm::Optional
+static std::optional
 parseTargetIDWithFormatCheckingOnly(llvm::StringRef TargetID,
 llvm::StringMap *FeatureMap) {
   llvm::StringRef Processor;



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


[clang] 3e1856e - [Basic] Use std::optional in FileManager.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:49:47-08:00
New Revision: 3e1856edb062b4e3d4848c03bac59b3c4953000e

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

LOG: [Basic] Use std::optional in FileManager.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Basic/FileManager.cpp

Removed: 




diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 69ebd3bc078d..4fefbaa01e52 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -123,7 +124,7 @@ FileManager::getDirectoryRef(StringRef DirName, bool 
CacheFailure) {
   DirName != llvm::sys::path::root_path(DirName) &&
   llvm::sys::path::is_separator(DirName.back()))
 DirName = DirName.substr(0, DirName.size()-1);
-  Optional DirNameStr;
+  std::optional DirNameStr;
   if (is_style_windows(llvm::sys::path::Style::native)) {
 // Fixing a problem with "clang C:test.c" on Windows.
 // Stat("C:") does not recognize "C:" as a valid directory



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


[clang] a12b82a - [Basic] Use std::optional in DarwinSDKInfo.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:48:14-08:00
New Revision: a12b82adb82eda76d6d7afd340b890f56f62771d

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

LOG: [Basic] Use std::optional in DarwinSDKInfo.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/Basic/DarwinSDKInfo.cpp

Removed: 




diff  --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index 5543acb126df7..4fb3409269c6c 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -11,6 +11,7 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
+#include 
 
 using namespace clang;
 
@@ -61,8 +62,8 @@ DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(
   Min, Max, MinValue, MaximumDeploymentTarget, std::move(Mapping));
 }
 
-static Optional getVersionKey(const llvm::json::Object &Obj,
-StringRef Key) {
+static std::optional getVersionKey(const llvm::json::Object &Obj,
+ StringRef Key) {
   auto Value = Obj.getString(Key);
   if (!Value)
 return std::nullopt;



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


[clang] d009b98 - [AST] Use std::optional in OSLog.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:21:54-08:00
New Revision: d009b985a84ce5a4251255dd138da6a687e9466b

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

LOG: [AST] Use std::optional in OSLog.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/AST/OSLog.cpp

Removed: 




diff  --git a/clang/lib/AST/OSLog.cpp b/clang/lib/AST/OSLog.cpp
index 40fa8c3802c3..5e320416b30d 100644
--- a/clang/lib/AST/OSLog.cpp
+++ b/clang/lib/AST/OSLog.cpp
@@ -8,6 +8,7 @@
 #include "clang/AST/FormatString.h"
 #include "clang/Basic/Builtins.h"
 #include "llvm/ADT/SmallBitVector.h"
+#include 
 
 using namespace clang;
 
@@ -20,11 +21,11 @@ class OSLogFormatStringHandler
 private:
   struct ArgData {
 const Expr *E = nullptr;
-Optional Kind;
-Optional Size;
-Optional Count;
-Optional Precision;
-Optional FieldWidth;
+std::optional Kind;
+std::optional Size;
+std::optional Count;
+std::optional Precision;
+std::optional FieldWidth;
 unsigned char Flags = 0;
 StringRef MaskType;
   };



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


[clang] 50ba59d - [AST] Use std::optional in ExprConstant.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:19:46-08:00
New Revision: 50ba59d1b659558a06273003bbf28227323a055f

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

LOG: [AST] Use std::optional in ExprConstant.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index ce9774422b12..280b37adc032 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -60,6 +60,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 
 #define DEBUG_TYPE "exprconstant"
 
@@ -6833,7 +6834,7 @@ class BitCastBuffer {
   // FIXME: Its possible under the C++ standard for 'char' to not be 8 bits, 
but
   // we don't support a host or target where that is the case. Still, we should
   // use a more generic type in case we ever do.
-  SmallVector, 32> Bytes;
+  SmallVector, 32> Bytes;
 
   static_assert(std::numeric_limits::digits >= 8,
 "Need at least 8 bit unsigned char");



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


[clang] 17d779b - [AST] Use std::optional in ASTImporter.cpp (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T22:17:46-08:00
New Revision: 17d779be76d9597fe13478392b266543761fedca

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

LOG: [AST] Use std::optional in ASTImporter.cpp (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 5fb289b9c9e4c..14d2d4a58eb46 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -68,6 +68,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -3981,7 +3982,7 @@ static FriendCountAndPosition getFriendCountAndPosition(
 const FriendDecl *FD,
 llvm::function_ref GetCanTypeOrDecl) {
   unsigned int FriendCount = 0;
-  llvm::Optional FriendPosition;
+  std::optional FriendPosition;
   const auto *RD = cast(FD->getLexicalDeclContext());
 
   T TypeOrDecl = GetCanTypeOrDecl(FD);



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


[PATCH] D139612: [Clang][LoongArch] Add intrinsic for iocsrrd and iocsrwr

2022-12-09 Thread Gong LingQin 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 rG048612050a2f: [Clang][LoongArch] Add intrinsic for iocsrrd 
and iocsrwr (authored by gonglingqin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139612

Files:
  clang/include/clang/Basic/BuiltinsLoongArch.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/larchintrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
  clang/test/CodeGen/LoongArch/intrinsic-la32.c
  clang/test/CodeGen/LoongArch/intrinsic-la64.c
  llvm/include/llvm/IR/IntrinsicsLoongArch.td
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
  llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
  llvm/test/CodeGen/LoongArch/intrinsic.ll

Index: llvm/test/CodeGen/LoongArch/intrinsic.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic.ll
@@ -9,6 +9,12 @@
 declare i32 @llvm.loongarch.csrrd.w(i32 immarg)
 declare i32 @llvm.loongarch.csrwr.w(i32, i32 immarg)
 declare i32 @llvm.loongarch.csrxchg.w(i32, i32, i32 immarg)
+declare i32 @llvm.loongarch.iocsrrd.b(i32)
+declare i32 @llvm.loongarch.iocsrrd.h(i32)
+declare i32 @llvm.loongarch.iocsrrd.w(i32)
+declare void @llvm.loongarch.iocsrwr.b(i32, i32)
+declare void @llvm.loongarch.iocsrwr.h(i32, i32)
+declare void @llvm.loongarch.iocsrwr.w(i32, i32)
 
 define void @foo() nounwind {
 ; CHECK-LABEL: foo:
@@ -79,3 +85,63 @@
   %0 = tail call i32 @llvm.loongarch.csrxchg.w(i32 %a, i32 %b, i32 1)
   ret i32 %0
 }
+
+define i32 @iocsrrd_b(i32 %a) {
+; CHECK-LABEL: iocsrrd_b:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrrd.b $a0, $a0
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i32 @llvm.loongarch.iocsrrd.b(i32 %a)
+  ret i32 %0
+}
+
+define i32 @iocsrrd_h(i32 %a) {
+; CHECK-LABEL: iocsrrd_h:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrrd.h $a0, $a0
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i32 @llvm.loongarch.iocsrrd.h(i32 %a)
+  ret i32 %0
+}
+
+define i32 @iocsrrd_w(i32 %a) {
+; CHECK-LABEL: iocsrrd_w:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrrd.w $a0, $a0
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i32 @llvm.loongarch.iocsrrd.w(i32 %a)
+  ret i32 %0
+}
+
+define void @iocsrwr_b(i32 %a, i32 %b) {
+; CHECK-LABEL: iocsrwr_b:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrwr.b $a0, $a1
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.loongarch.iocsrwr.b(i32 %a, i32 %b)
+  ret void
+}
+
+define void @iocsrwr_h(i32 %a, i32 %b) {
+; CHECK-LABEL: iocsrwr_h:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrwr.h $a0, $a1
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.loongarch.iocsrwr.h(i32 %a, i32 %b)
+  ret void
+}
+
+define void @iocsrwr_w(i32 %a, i32 %b) {
+; CHECK-LABEL: iocsrwr_w:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrwr.w $a0, $a1
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.loongarch.iocsrwr.w(i32 %a, i32 %b)
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
@@ -12,6 +12,8 @@
 declare i64 @llvm.loongarch.csrrd.d(i32 immarg)
 declare i64 @llvm.loongarch.csrwr.d(i64, i32 immarg)
 declare i64 @llvm.loongarch.csrxchg.d(i64, i64, i32 immarg)
+declare i64 @llvm.loongarch.iocsrrd.d(i32)
+declare void @llvm.loongarch.iocsrwr.d(i64, i32)
 
 define i32 @crc_w_b_w(i32 %a, i32 %b) nounwind {
 ; CHECK-LABEL: crc_w_b_w:
@@ -114,3 +116,23 @@
   %0 = tail call i64 @llvm.loongarch.csrxchg.d(i64 %a, i64 %b, i32 1)
   ret i64 %0
 }
+
+define i64 @iocsrrd_d(i32 %a) {
+; CHECK-LABEL: iocsrrd_d:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrrd.d $a0, $a0
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i64 @llvm.loongarch.iocsrrd.d(i32 %a)
+  ret i64 %0
+}
+
+define void @iocsrwr_d(i64 %a, i32 signext %b) {
+; CHECK-LABEL: iocsrwr_d:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:iocsrwr.d $a0, $a1
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.loongarch.iocsrwr.d(i64 %a, i32 %b)
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
@@ -11,6 +11,8 @@
 declare i64 @llvm.loongarch.csrrd.d(i32 immarg)
 declare i64 @llvm.loongarch.csrwr.d(i64, i32 immarg)
 declare i64 @llvm.loongarch.csrxchg.d(i64, i64, i32 immarg)
+declare i64 @llvm.loongarch.iocsrrd.d(i32)
+declare void @llvm.loongarch.ioc

[clang] 0486120 - [Clang][LoongArch] Add intrinsic for iocsrrd and iocsrwr

2022-12-09 Thread via cfe-commits

Author: gonglingqin
Date: 2022-12-10T14:05:19+08:00
New Revision: 048612050a2fc0a89b84632a48da0d86f0d13646

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

LOG: [Clang][LoongArch] Add intrinsic for iocsrrd and iocsrwr

These intrinsics are required by Linux [1].

[1]: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/asm/loongarch.h#n240

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsLoongArch.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/larchintrin.h
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
clang/test/CodeGen/LoongArch/intrinsic-la32.c
clang/test/CodeGen/LoongArch/intrinsic-la64.c
llvm/include/llvm/IR/IntrinsicsLoongArch.td
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h
llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
llvm/test/CodeGen/LoongArch/intrinsic.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsLoongArch.def 
b/clang/include/clang/Basic/BuiltinsLoongArch.def
index fa4aaffa5ff71..5b0dd799a4bcd 100644
--- a/clang/include/clang/Basic/BuiltinsLoongArch.def
+++ b/clang/include/clang/Basic/BuiltinsLoongArch.def
@@ -38,5 +38,14 @@ TARGET_BUILTIN(__builtin_loongarch_csrwr_d, "ULiULiIUi", 
"nc", "64bit")
 TARGET_BUILTIN(__builtin_loongarch_csrxchg_w, "UiUiUiIUi", "nc", "")
 TARGET_BUILTIN(__builtin_loongarch_csrxchg_d, "ULiULiULiIUi", "nc", "64bit")
 
+TARGET_BUILTIN(__builtin_loongarch_iocsrrd_b, "UiUi", "nc", "")
+TARGET_BUILTIN(__builtin_loongarch_iocsrrd_h, "UiUi", "nc", "")
+TARGET_BUILTIN(__builtin_loongarch_iocsrrd_w, "UiUi", "nc", "")
+TARGET_BUILTIN(__builtin_loongarch_iocsrrd_d, "ULiUi", "nc", "64bit")
+TARGET_BUILTIN(__builtin_loongarch_iocsrwr_b, "vUiUi", "nc", "")
+TARGET_BUILTIN(__builtin_loongarch_iocsrwr_h, "vUiUi", "nc", "")
+TARGET_BUILTIN(__builtin_loongarch_iocsrwr_w, "vUiUi", "nc", "")
+TARGET_BUILTIN(__builtin_loongarch_iocsrwr_d, "vULiUi", "nc", "64bit")
+
 #undef BUILTIN
 #undef TARGET_BUILTIN

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9650b9ce978f7..be1ce2796c8aa 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19718,6 +19718,30 @@ Value 
*CodeGenFunction::EmitLoongArchBuiltinExpr(unsigned BuiltinID,
   case LoongArch::BI__builtin_loongarch_csrxchg_d:
 ID = Intrinsic::loongarch_csrxchg_d;
 break;
+  case LoongArch::BI__builtin_loongarch_iocsrrd_b:
+ID = Intrinsic::loongarch_iocsrrd_b;
+break;
+  case LoongArch::BI__builtin_loongarch_iocsrrd_h:
+ID = Intrinsic::loongarch_iocsrrd_h;
+break;
+  case LoongArch::BI__builtin_loongarch_iocsrrd_w:
+ID = Intrinsic::loongarch_iocsrrd_w;
+break;
+  case LoongArch::BI__builtin_loongarch_iocsrrd_d:
+ID = Intrinsic::loongarch_iocsrrd_d;
+break;
+  case LoongArch::BI__builtin_loongarch_iocsrwr_b:
+ID = Intrinsic::loongarch_iocsrwr_b;
+break;
+  case LoongArch::BI__builtin_loongarch_iocsrwr_h:
+ID = Intrinsic::loongarch_iocsrwr_h;
+break;
+  case LoongArch::BI__builtin_loongarch_iocsrwr_w:
+ID = Intrinsic::loongarch_iocsrwr_w;
+break;
+  case LoongArch::BI__builtin_loongarch_iocsrwr_d:
+ID = Intrinsic::loongarch_iocsrwr_d;
+break;
 // TODO: Support more Intrinsics.
   }
 

diff  --git a/clang/lib/Headers/larchintrin.h b/clang/lib/Headers/larchintrin.h
index 02c31657a2bc9..787b7b8deda2d 100644
--- a/clang/lib/Headers/larchintrin.h
+++ b/clang/lib/Headers/larchintrin.h
@@ -95,6 +95,58 @@ extern __inline int
   (unsigned long int)(_1), (unsigned long int)(_2), (_3)))
 #endif
 
+extern __inline unsigned char
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__iocsrrd_b(unsigned int _1) {
+  return (unsigned char)__builtin_loongarch_iocsrrd_b((unsigned int)_1);
+}
+
+extern __inline unsigned char
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__iocsrrd_h(unsigned int _1) {
+  return (unsigned short)__builtin_loongarch_iocsrrd_h((unsigned int)_1);
+}
+
+extern __inline unsigned int
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__iocsrrd_w(unsigned int _1) {
+  return (unsigned int)__builtin_loongarch_iocsrrd_w((unsigned int)_1);
+}
+
+#if __loongarch_grlen == 64
+extern __inline unsigned long int
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__iocsrrd_d(unsigned int _1) {
+  return (unsigned long int)__builtin_loongarch_iocsrrd_d((unsigned int)_1);
+}
+#endif
+
+extern 

[PATCH] D139768: [SPARC][clang] Add SPARC target feature flags

2022-12-09 Thread Koakuma via Phabricator via cfe-commits
koakuma created this revision.
koakuma added reviewers: jrtc27, brad, ro, dcederman.
Herald added subscribers: fedor.sergeev, jyknight.
Herald added a project: All.
koakuma requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

This adds some SPARC feature flags to clang, for those that we have in common 
with GCC:

- `-m[no-]fpu`
- `-m[no-]fsmuld`
- `-m[no-]popc`
- `-m[no-]vis`
- `-m[no-]vis2`
- `-m[no-]vis3`
- `-m[hard/soft]-quad-float`

All have the same meanings as GCC's options 
(https://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html).

This fixes, among other things, the -mno-fpu part of bug #40792 
(https://github.com/llvm/llvm-project/issues/40792).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139768

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp
  clang/test/Driver/sparc-target-features.c

Index: clang/test/Driver/sparc-target-features.c
===
--- /dev/null
+++ clang/test/Driver/sparc-target-features.c
@@ -0,0 +1,34 @@
+// RUN: %clang --target=sparc -mfpu %s -### 2>&1 | FileCheck -check-prefix=FPU %s
+// RUN: %clang --target=sparc -mno-fpu %s -### 2>&1 | FileCheck -check-prefix=NO-FPU %s
+// FPU: "-mfloat-abi" "hard"
+// NO-FPU: "-mfloat-abi" "soft"
+
+// RUN: %clang --target=sparc -mfsmuld %s -### 2>&1 | FileCheck -check-prefix=FSMULD %s
+// RUN: %clang --target=sparc -mno-fsmuld %s -### 2>&1 | FileCheck -check-prefix=NO-FSMULD %s
+// FSMULD: "-target-feature" "+fsmuld"
+// NO-FSMULD: "-target-feature" "-fsmuld"
+
+// RUN: %clang --target=sparc -mpopc %s -### 2>&1 | FileCheck -check-prefix=POPC %s
+// RUN: %clang --target=sparc -mno-popc %s -### 2>&1 | FileCheck -check-prefix=NO-POPC %s
+// POPC: "-target-feature" "+popc"
+// NO-POPC: "-target-feature" "-popc"
+
+// RUN: %clang --target=sparc -mvis %s -### 2>&1 | FileCheck -check-prefix=VIS %s
+// RUN: %clang --target=sparc -mno-vis %s -### 2>&1 | FileCheck -check-prefix=NO-VIS %s
+// VIS: "-target-feature" "+vis"
+// NO-VIS: "-target-feature" "-vis"
+
+// RUN: %clang --target=sparc -mvis2 %s -### 2>&1 | FileCheck -check-prefix=VIS2 %s
+// RUN: %clang --target=sparc -mno-vis2 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS2 %s
+// VIS2: "-target-feature" "+vis2"
+// NO-VIS2: "-target-feature" "-vis2"
+
+// RUN: %clang --target=sparc -mvis3 %s -### 2>&1 | FileCheck -check-prefix=VIS3 %s
+// RUN: %clang --target=sparc -mno-vis3 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS3 %s
+// VIS3: "-target-feature" "+vis3"
+// NO-VIS3: "-target-feature" "-vis3"
+
+// RUN: %clang --target=sparc -mhard-quad-float %s -### 2>&1 | FileCheck -check-prefix=HARD-QUAD-FLOAT %s
+// RUN: %clang --target=sparc -msoft-quad-float %s -### 2>&1 | FileCheck -check-prefix=SOFT-QUAD-FLOAT %s
+// HARD-QUAD-FLOAT: "-target-feature" "+hard-quad-float"
+// SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -82,12 +82,14 @@
 sparc::FloatABI sparc::getSparcFloatABI(const Driver &D,
 const ArgList &Args) {
   sparc::FloatABI ABI = sparc::FloatABI::Invalid;
-  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
-   options::OPT_mhard_float,
+  if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mno_fpu,
+   options::OPT_mhard_float, options::OPT_mfpu,
options::OPT_mfloat_abi_EQ)) {
-if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
+if (A->getOption().matches(options::OPT_msoft_float) ||
+A->getOption().matches(options::OPT_mno_fpu))
   ABI = sparc::FloatABI::Soft;
-else if (A->getOption().matches(options::OPT_mhard_float))
+else if (A->getOption().matches(options::OPT_mhard_float) ||
+ A->getOption().matches(options::OPT_mfpu))
   ABI = sparc::FloatABI::Hard;
 else {
   ABI = llvm::StringSwitch(A->getValue())
@@ -143,4 +145,47 @@
   sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
   if (FloatABI == sparc::FloatABI::Soft)
 Features.push_back("+soft-float");
+
+  if (Arg *A = Args.getLastArg(options::OPT_mfsmuld, options::OPT_mno_fsmuld)) {
+if (A->getOption().matches(options::OPT_mfsmuld))
+  Features.push_back("+fsmuld");
+else
+  Features.push_back("-fsmuld");
+  }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mpopc, options::OPT_mno_popc)) {
+if (A->getOption().matches(options::OPT_mpopc))
+  Features.push_back("+popc");
+else
+  Features.push_back("-popc");
+  }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
+if (A->getOption().matches(options::OPT_mvis))
+  Features.p

[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2022-12-09 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added inline comments.



Comment at: clang/test/Driver/save-std-c++-module-file.cpp:1
+// RUN: rm -rf %t
+// RUN: mkdir %t

The filename of this test still reflects the old option name and should 
presumably be changed.


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

https://reviews.llvm.org/D137058

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


[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

2022-12-09 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added a reviewer: shafik.
v1nh1shungry marked an inline comment as done.
v1nh1shungry added a comment.

@shafik Thank you for reviewing and giving suggestions!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139705

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


[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

2022-12-09 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 481819.
v1nh1shungry added a comment.

address the comment's suggestion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139705

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/FixIt/fixit-const-var-init.cpp


Index: clang/test/FixIt/fixit-const-var-init.cpp
===
--- /dev/null
+++ clang/test/FixIt/fixit-const-var-init.cpp
@@ -0,0 +1,25 @@
+// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ -std=c++14 %s 
2>&1 | FileCheck %s
+
+const int a; // expected-error {{default initialization of an object of const 
type}}
+// CHECK: fix-it:"{{.*}}":{3:12-3:12}:" = 0"
+
+template  const int b; // expected-error {{default 
initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{6:36-6:36}:" = 0"
+
+template  const int b; // expected-error {{default 
initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{9:39-9:39}:" = 0"
+
+template <> const int b; // expected-error {{default 
initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{12:36-12:36}:" = 0"
+
+constexpr float c; // expected-error {{must be initialized by a constant 
expression}}
+// CHECK: fix-it:"{{.*}}":{15:18-15:18}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be 
initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{18:42-18:42}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be 
initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{21:45-21:45}:" = 0.0"
+
+template <> constexpr float d; // expected-error {{must be 
initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{24:42-24:42}:" = 0.0"
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -3860,8 +3860,21 @@
   if (VD->getInit() || VD->getEndLoc().isMacroID())
 return false;
 
+  SourceLocation EndLoc = VD->getEndLoc();
+  if (const auto *VTSD = dyn_cast(VD)) {
+if (const auto *VTPSD =
+dyn_cast(VD)) {
+  if (const ASTTemplateArgumentListInfo *Info =
+  VTPSD->getTemplateArgsAsWritten())
+EndLoc = Info->getRAngleLoc();
+} else if (const ASTTemplateArgumentListInfo *Info =
+   VTSD->getTemplateArgsInfo()) {
+  EndLoc = Info->getRAngleLoc();
+}
+  }
+
   QualType VariableTy = VD->getType().getCanonicalType();
-  SourceLocation Loc = S.getLocForEndOfToken(VD->getEndLoc());
+  SourceLocation Loc = S.getLocForEndOfToken(EndLoc);
   std::string Init = S.getFixItZeroInitializerForType(VariableTy, Loc);
   if (!Init.empty()) {
 Sequence.AddZeroInitializationStep(Entity.getType());


Index: clang/test/FixIt/fixit-const-var-init.cpp
===
--- /dev/null
+++ clang/test/FixIt/fixit-const-var-init.cpp
@@ -0,0 +1,25 @@
+// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ -std=c++14 %s 2>&1 | FileCheck %s
+
+const int a; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{3:12-3:12}:" = 0"
+
+template  const int b; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{6:36-6:36}:" = 0"
+
+template  const int b; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{9:39-9:39}:" = 0"
+
+template <> const int b; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{12:36-12:36}:" = 0"
+
+constexpr float c; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{15:18-15:18}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{18:42-18:42}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{21:45-21:45}:" = 0.0"
+
+template <> constexpr float d; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{24:42-24:42}:" = 0.0"
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -3860,8 +3860,21 @@
   if (VD->getInit() || VD->getEndLoc().isMacroID())
 return false;
 
+  SourceLocation EndLoc = VD->getEndLoc();
+  if (const auto *VTSD = dyn_cast(VD)) {
+if (const auto *VTPSD =
+dyn_cast(VD)) {
+  if (const ASTTemplateArgumentListInfo *Info =
+  VTPSD->getTemplateArgsAsWritten())
+EndLoc = Info->getRAngleLoc();
+} else if (const ASTTemplateArgumentListInfo *Info =
+   VTSD->getTemplateArgsInfo()) {
+  EndLoc = Info->getRAngleLoc();
+}
+

[PATCH] D139612: [Clang][LoongArch] Add intrinsic for iocsrrd and iocsrwr

2022-12-09 Thread Lu Weining via Phabricator via cfe-commits
SixWeining accepted this revision.
SixWeining added a comment.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139612

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


[PATCH] D139397: [LoongArch] Add testcases for privileged intrinsic macros

2022-12-09 Thread Gong LingQin 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 rG9a5e5402cf80: [LoongArch] Add testcases for privileged 
intrinsic macros (authored by gonglingqin).

Changed prior to commit:
  https://reviews.llvm.org/D139397?vs=480355&id=481814#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139397

Files:
  clang/test/CodeGen/LoongArch/intrinsic-la32.c
  clang/test/CodeGen/LoongArch/intrinsic-la64.c

Index: clang/test/CodeGen/LoongArch/intrinsic-la64.c
===
--- clang/test/CodeGen/LoongArch/intrinsic-la64.c
+++ clang/test/CodeGen/LoongArch/intrinsic-la64.c
@@ -6,36 +6,44 @@
 // CHECK-LABEL: @dbar(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.dbar(i32 0)
+// CHECK-NEXT:tail call void @llvm.loongarch.dbar(i32 0)
 // CHECK-NEXT:ret void
 //
 void dbar() {
-  return __builtin_loongarch_dbar(0);
+  __dbar(0);
+  __builtin_loongarch_dbar(0);
 }
 
 // CHECK-LABEL: @ibar(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.ibar(i32 0)
+// CHECK-NEXT:tail call void @llvm.loongarch.ibar(i32 0)
 // CHECK-NEXT:ret void
 //
 void ibar() {
-  return __builtin_loongarch_ibar(0);
+  __ibar(0);
+  __builtin_loongarch_ibar(0);
 }
 
 // CHECK-LABEL: @loongarch_break(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.break(i32 1)
+// CHECK-NEXT:tail call void @llvm.loongarch.break(i32 1)
 // CHECK-NEXT:ret void
 //
 void loongarch_break() {
+  __break(1);
   __builtin_loongarch_break(1);
 }
 
 // CHECK-LABEL: @syscall(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.syscall(i32 1)
+// CHECK-NEXT:tail call void @llvm.loongarch.syscall(i32 1)
 // CHECK-NEXT:ret void
 //
 void syscall() {
+  __syscall(1);
   __builtin_loongarch_syscall(1);
 }
 
@@ -77,74 +85,106 @@
 
 // CHECK-LABEL: @crc_w_b_w(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = shl i32 [[A:%.*]], 24
+// CHECK-NEXT:[[CONV_I:%.*]] = ashr exact i32 [[TMP0]], 24
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 [[CONV_I]], i32 [[B:%.*]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_b_w(int a, int b) {
-  return __builtin_loongarch_crc_w_b_w(a, b);
+  int c = __crc_w_b_w(a, b);
+  int d = __builtin_loongarch_crc_w_b_w(a, b);
+  return 0;
 }
 
 // CHECK-LABEL: @crc_w_h_w(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = shl i32 [[A:%.*]], 16
+// CHECK-NEXT:[[CONV_I:%.*]] = ashr exact i32 [[TMP0]], 16
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 [[CONV_I]], i32 [[B:%.*]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_h_w(int a, int b) {
-  return __builtin_loongarch_crc_w_h_w(a, b);
+  int c = __crc_w_h_w(a, b);
+  int d = __builtin_loongarch_crc_w_h_w(a, b);
+  return 0;
 }
 
 // CHECK-LABEL: @crc_w_w_w(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.w.w(i32 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.w.w(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_w_w(int a, int b) {
-  return __builtin_loongarch_crc_w_w_w(a, b);
+  int c = __crc_w_w_w(a, b);
+  int d = __builtin_loongarch_crc_w_w_w(a, b);
+  return 0;
 }
 
 // CHECK-LABEL: @crc_w_d_w(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.d.w(i64 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.d.w(i64 [[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_d_w(long int a, int b) {
-  return __builtin_loongarch_crc_w_d_w(a, b);
+  int c = __crc_w_d_w(a, b);
+  int d = __builtin_loongarch_crc_w_d_w(a, b);
+  return 0;
 }
 
 // CHECK-LABEL: @crcc_w_b_w(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crcc.w.b.w(i32 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = shl i32 [[A:%.*]], 24
+// CHECK-NEXT:[[CONV_I:%.*]] = ashr exact i32 [[TMP0]], 24
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crcc.w.b.w(i32 [[CONV_I]], i32 [[B:%.*]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call i32 @llvm.loongarch.crcc.w.b.w(i32 [[A]], i32 [[B]])

[clang] 9a5e540 - [LoongArch] Add testcases for privileged intrinsic macros

2022-12-09 Thread via cfe-commits

Author: gonglingqin
Date: 2022-12-10T11:36:56+08:00
New Revision: 9a5e5402cf809ea22ed771f59144543f9ea78ff1

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

LOG: [LoongArch] Add testcases for privileged intrinsic macros

Add testcases calling macros to the implemented privileged intrinsics
as discussed in D139288. The intrinsics involved include ibar, dbar,
break, syscall, and CRC check intrinsics.

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

Added: 


Modified: 
clang/test/CodeGen/LoongArch/intrinsic-la32.c
clang/test/CodeGen/LoongArch/intrinsic-la64.c

Removed: 




diff  --git a/clang/test/CodeGen/LoongArch/intrinsic-la32.c 
b/clang/test/CodeGen/LoongArch/intrinsic-la32.c
index ec74a3da7e3f4..4d973d4a65691 100644
--- a/clang/test/CodeGen/LoongArch/intrinsic-la32.c
+++ b/clang/test/CodeGen/LoongArch/intrinsic-la32.c
@@ -7,36 +7,44 @@
 // LA32-LABEL: @dbar(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.dbar(i32 0)
+// LA32-NEXT:call void @llvm.loongarch.dbar(i32 0)
 // LA32-NEXT:ret void
 //
 void dbar() {
-  return __builtin_loongarch_dbar(0);
+  __dbar(0);
+  __builtin_loongarch_dbar(0);
 }
 
 // LA32-LABEL: @ibar(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.ibar(i32 0)
+// LA32-NEXT:call void @llvm.loongarch.ibar(i32 0)
 // LA32-NEXT:ret void
 //
 void ibar() {
-  return __builtin_loongarch_ibar(0);
+  __ibar(0);
+  __builtin_loongarch_ibar(0);
 }
 
 // LA32-LABEL: @loongarch_break(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.break(i32 1)
+// LA32-NEXT:call void @llvm.loongarch.break(i32 1)
 // LA32-NEXT:ret void
 //
 void loongarch_break() {
+  __break(1);
   __builtin_loongarch_break(1);
 }
 
 // LA32-LABEL: @syscall(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.syscall(i32 1)
+// LA32-NEXT:call void @llvm.loongarch.syscall(i32 1)
 // LA32-NEXT:ret void
 //
 void syscall() {
+  __syscall(1);
   __builtin_loongarch_syscall(1);
 }
 

diff  --git a/clang/test/CodeGen/LoongArch/intrinsic-la64.c 
b/clang/test/CodeGen/LoongArch/intrinsic-la64.c
index d2bad0ed60cb8..97b93a6077c0b 100644
--- a/clang/test/CodeGen/LoongArch/intrinsic-la64.c
+++ b/clang/test/CodeGen/LoongArch/intrinsic-la64.c
@@ -6,36 +6,44 @@
 // CHECK-LABEL: @dbar(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.dbar(i32 0)
+// CHECK-NEXT:tail call void @llvm.loongarch.dbar(i32 0)
 // CHECK-NEXT:ret void
 //
 void dbar() {
-  return __builtin_loongarch_dbar(0);
+  __dbar(0);
+  __builtin_loongarch_dbar(0);
 }
 
 // CHECK-LABEL: @ibar(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.ibar(i32 0)
+// CHECK-NEXT:tail call void @llvm.loongarch.ibar(i32 0)
 // CHECK-NEXT:ret void
 //
 void ibar() {
-  return __builtin_loongarch_ibar(0);
+  __ibar(0);
+  __builtin_loongarch_ibar(0);
 }
 
 // CHECK-LABEL: @loongarch_break(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.break(i32 1)
+// CHECK-NEXT:tail call void @llvm.loongarch.break(i32 1)
 // CHECK-NEXT:ret void
 //
 void loongarch_break() {
+  __break(1);
   __builtin_loongarch_break(1);
 }
 
 // CHECK-LABEL: @syscall(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.loongarch.syscall(i32 1)
+// CHECK-NEXT:tail call void @llvm.loongarch.syscall(i32 1)
 // CHECK-NEXT:ret void
 //
 void syscall() {
+  __syscall(1);
   __builtin_loongarch_syscall(1);
 }
 
@@ -77,74 +85,106 @@ unsigned int csrxchg_w(unsigned int a, unsigned int b) {
 
 // CHECK-LABEL: @crc_w_b_w(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 
[[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = shl i32 [[A:%.*]], 24
+// CHECK-NEXT:[[CONV_I:%.*]] = ashr exact i32 [[TMP0]], 24
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 
[[CONV_I]], i32 [[B:%.*]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 
[[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_b_w(int a, int b) {
-  return __builtin_loongarch_crc_w_b_w(a, b);
+  int c = __crc_w_b_w(a, b);
+  int d = __builtin_loongarch_crc_w_b_w(a, b);
+  return 0;
 }
 
 // CHECK-LABEL: @crc_w_h_w(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 
[[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = shl i32 [[A:%.*]], 16
+// CHECK-NEXT:[[CONV_I:%.*]] = ashr exact i32 [[TMP0]], 16
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 
[[CONV_I]], i32 [[B:%.*]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call i32 @llvm.loong

[PATCH] D139640: clang: Add __builtin_elementwise canonicalize and copysign

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm marked an inline comment as done.
arsenm added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:644
  magnitude than x
+ T__builtin_elementwise_canonicalize(T x)  return the platform specific 
canonical encoding of a floating-point number floating point types
+

fhahn wrote:
> I think this needs re-flowing , otherwise the table won't be rendered 
> properly? Same for the next line
I'm not really sure what's going on with the formatting or how this works. It 
looks worse on Phabricator than in the editor 


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

https://reviews.llvm.org/D139640

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


[PATCH] D139640: clang: Add __builtin_elementwise canonicalize and copysign

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 481812.
arsenm added a comment.

Try to fix formatting


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

https://reviews.llvm.org/D139640

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -384,3 +384,79 @@
   uv = __builtin_elementwise_trunc(uv);
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
+
+void test_builtin_elementwise_canonicalize(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_canonicalize(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_canonicalize();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_canonicalize(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_canonicalize(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_canonicalize(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_canonicalize(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
+void test_builtin_elementwise_copysign(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
+  i = __builtin_elementwise_copysign(p, d);
+  // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+
+  struct Foo foo = __builtin_elementwise_copysign(i, i);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+  i = __builtin_elementwise_copysign(i);
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
+
+  i = __builtin_elementwise_copysign();
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 0}}
+
+  i = __builtin_elementwise_copysign(i, i, i);
+  // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
+
+  i = __builtin_elementwise_copysign(v, iv);
+  // expected-error@-1 {{arguments are of different types ('float4' (vector of 4 'float' values) vs 'int3' (vector of 3 'int' values))}}
+
+  i = __builtin_elementwise_copysign(uv, iv);
+  // expected-error@-1 {{arguments are of different types ('unsigned3' (vector of 3 'unsigned int' values) vs 'int3' (vector of 3 'int' values))}}
+
+  s = __builtin_elementwise_copysign(i, s);
+
+  enum e { one,
+   two };
+  i = __builtin_elementwise_copysign(one, two);
+
+  enum f { three };
+  enum f x = __builtin_elementwise_copysign(one, three);
+
+  _BitInt(32) ext; // expected-warning {{'_BitInt' in C17 and earlier is a Clang extension}}
+  ext = __builtin_elementwise_copysign(ext, ext);
+
+  const int ci;
+  i = __builtin_elementwise_copysign(ci, i);
+  i = __builtin_elementwise_copysign(i, ci);
+  i = __builtin_elementwise_copysign(ci, ci);
+
+  i = __builtin_elementwise_copysign(i, int_as_one); // ok (attributes don't match)?
+  i = __builtin_elementwise_copysign(i, b);  // ok (sugar doesn't match)?
+
+  int A[10];
+  A = __builtin_elementwise_copysign(A, A);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'int *')}}
+
+  int(ii);
+  int j;
+  j = __builtin_elementwise_copysign(i, j);
+
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_copysign(c1, c2);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -3,6 +3,8 @@
 typedef float float4 __attribute__((ext_vector_type(4)));
 typedef short int si8 __attribute__((ext_vector_type(8)));
 typedef unsigned int u4 __attribute__((ext_vector_type(4)));
+typedef double double2 __attribute__((ext_vector_type(2)));
+typedef double double3 __attribute__((ext_vector_type(3)));
 
 __attribute__((address_space(1))) int int_as_one;
 typedef int bar;
@@ -412,3 +414,53 @@
   // CHECK-NEXT: call <4 x float> @llvm.trunc.v4f32(<4 x float> [[VF1]])
   vf2 = __builtin_elementwise_trunc(vf1);
 }
+
+void test_builtin_elementwise_canonicalize(float f1, float f2, double d1, double d2,
+   

[clang] 37a3e98 - [clang] Use std::nullopt instead of None in comments (NFC)

2022-12-09 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-12-09T18:39:01-08:00
New Revision: 37a3e98c841e5d33f7e77e97dfb058965105eb4b

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

LOG: [clang] Use std::nullopt instead of None in comments (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/include/clang/AST/ASTImporter.h
clang/include/clang/Basic/DarwinSDKInfo.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/include/clang/Sema/Scope.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
clang/lib/CodeGen/CGObjC.cpp
clang/lib/Driver/OffloadBundler.cpp
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Sema/SemaAvailability.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h

clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTImporter.h 
b/clang/include/clang/AST/ASTImporter.h
index f03a76bdeb443..a6bb0e8aa9506 100644
--- a/clang/include/clang/AST/ASTImporter.h
+++ b/clang/include/clang/AST/ASTImporter.h
@@ -577,7 +577,7 @@ class TypeSourceInfo;
 /// Determine the index of a field in its parent record.
 /// F should be a field (or indirect field) declaration.
 /// \returns The index of the field in its parent context (starting from 
0).
-/// On error `None` is returned (parent context is non-record).
+/// On error `std::nullopt` is returned (parent context is non-record).
 static llvm::Optional getFieldIndex(Decl *F);
   };
 

diff  --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index eed7668c5218c..6a13ddd9d522e 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -160,8 +160,8 @@ class DarwinSDKInfo {
 
 /// Parse the SDK information from the SDKSettings.json file.
 ///
-/// \returns an error if the SDKSettings.json file is invalid, None if the
-/// SDK has no SDKSettings.json, or a valid \c DarwinSDKInfo otherwise.
+/// \returns an error if the SDKSettings.json file is invalid, std::nullopt if
+/// the SDK has no SDKSettings.json, or a valid \c DarwinSDKInfo otherwise.
 Expected>
 parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath);
 

diff  --git 
a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h 
b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
index 7c82c8fa53b95..e20ca85fc8d6e 100644
--- a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
+++ b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
@@ -121,8 +121,8 @@ class SymbolGraphSerializer : public APISerializer {
   /// This method also checks if the given \p Record should be skipped during
   /// serialization.
   ///
-  /// \returns \c None if this \p Record should be skipped, or a JSON object
-  /// containing common symbol information of \p Record.
+  /// \returns \c std::nullopt if this \p Record should be skipped, or a JSON
+  /// object containing common symbol information of \p Record.
   template 
   Optional serializeAPIRecord(const RecordTy &Record) const;
 

diff  --git a/clang/include/clang/Sema/Scope.h 
b/clang/include/clang/Sema/Scope.h
index deb011892b850..f8fbc9d27a009 100644
--- a/clang/include/clang/Sema/Scope.h
+++ b/clang/include/clang/Sema/Scope.h
@@ -215,7 +215,7 @@ class Scope {
   ///  1) pointer to VarDecl that denotes NRVO candidate itself.
   ///  2) nullptr value means that NRVO is not allowed in this scope
   /// (e.g. return a function parameter).
-  ///  3) None value means that there is no NRVO candidate in this scope
+  ///  3) std::nullopt value means that there is no NRVO candidate in this 
scope
   /// (i.e. there are no return statements in this scope).
   Optional NRVO;
 

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
index a4fa3fbf45dbe..adc3af9e775b9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -235,7 +235,7 @@ class SValBuilder {
   /// Returns the value of \p E, if it can be determined in a 
non-path-sensitive
   /// manner.
   ///
-  /// If \p E is not a

[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

2022-12-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Some debug context ...

  (gdb) frame 4
  #4  0x06f55b73 in clang::ento::BasicValueFactory::getAPSIntType 
(this=0x1088e470, T=...)
  at 
/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:155
  155   assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
  (gdb) p T
  $1 = {Value = {Value = 276884496}}
  (gdb) p T.dump()
  BuiltinType 0x1080ec10 'long _Accum'
  $2 = void
  (gdb) p T->isIntegralOrEnumerationType()
  $3 = false
  (gdb) p Loc::isLocType(T)
  $4 = false
  (gdb) p Ctx.getIntWidth(T)
  $5 = 64
  (gdb) p !T->isSignedIntegerOrEnumerationType()
  $6 = true


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139759

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


[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

2022-12-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 481809.
vabridgers added a comment.

update commit header


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139759

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/test/Analysis/fixed-point.c


Index: clang/test/Analysis/fixed-point.c
===
--- /dev/null
+++ clang/test/Analysis/fixed-point.c
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN:   -analyzer-checker=core,debug.ExprInspection -Wno-unused -verify %s
+
+// expected-no-diagnostics
+
+long a(int c) {
   
+  (long _Accum) c >> 4;
+  return c;
+}  
+
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -152,7 +152,8 @@
   T = AT->getValueType();
 }
 
-assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }


Index: clang/test/Analysis/fixed-point.c
===
--- /dev/null
+++ clang/test/Analysis/fixed-point.c
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN:   -analyzer-checker=core,debug.ExprInspection -Wno-unused -verify %s
+
+// expected-no-diagnostics
+
+long a(int c) {   
+  (long _Accum) c >> 4;
+  return c;
+}  
+
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -152,7 +152,8 @@
   T = AT->getValueType();
 }
 
-assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139760: Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"

2022-12-09 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: HazardyKnusperkeks, MyDeveloperDay, rymiel.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

But keep the added test case and also add another test case.

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

This reverts commit e33243c950ac 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139760

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/BracesRemoverTest.cpp

Index: clang/unittests/Format/BracesRemoverTest.cpp
===
--- clang/unittests/Format/BracesRemoverTest.cpp
+++ clang/unittests/Format/BracesRemoverTest.cpp
@@ -683,6 +683,41 @@
"return a;",
Style);
 
+  verifyFormat("if (a)\n"
+   "#ifdef FOO\n"
+   "  if (b)\n"
+   "bar = c;\n"
+   "  else\n"
+   "#endif\n"
+   "  {\n"
+   "foo = d;\n"
+   "#ifdef FOO\n"
+   "bar = e;\n"
+   "#else\n"
+   "  bar = f;\n" // FIXME: should be indented 1 more level.
+   "#endif\n"
+   "  }\n"
+   "else\n"
+   "  bar = g;",
+   "if (a)\n"
+   "#ifdef FOO\n"
+   "  if (b)\n"
+   "bar = c;\n"
+   "  else\n"
+   "#endif\n"
+   "  {\n"
+   "foo = d;\n"
+   "#ifdef FOO\n"
+   "bar = e;\n"
+   "#else\n"
+   "bar = f;\n"
+   "#endif\n"
+   "  }\n"
+   "else {\n"
+   "  bar = g;\n"
+   "}",
+   Style);
+
   Style.ColumnLimit = 65;
   verifyFormat("if (condition) {\n"
"  ff(Indices,\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -934,9 +934,6 @@
 return IfLBrace;
   }
 
-  Tok->MatchingParen = FormatTok;
-  FormatTok->MatchingParen = Tok;
-
   const bool IsFunctionRBrace =
   FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
 
@@ -970,7 +967,10 @@
 }
 return mightFitOnOneLine((*CurrentLines)[Index], Tok);
   };
-  Tok->Optional = RemoveBraces();
+  if (RemoveBraces()) {
+Tok->MatchingParen = FormatTok;
+FormatTok->MatchingParen = Tok;
+  }
 
   size_t PPEndHash = computePPHash();
 
@@ -2707,20 +2707,10 @@
 
   assert(RightBrace->is(tok::r_brace));
   assert(RightBrace->MatchingParen == LeftBrace);
+  assert(LeftBrace->Optional == RightBrace->Optional);
 
-  RightBrace->Optional = LeftBrace->Optional;
-}
-
-static void resetOptional(FormatToken *LeftBrace) {
-  if (!LeftBrace)
-return;
-
-  const auto *RightBrace = LeftBrace->MatchingParen;
-  const bool IsOptionalRightBrace = RightBrace && RightBrace->Optional;
-  assert(LeftBrace->Optional || !IsOptionalRightBrace);
-
-  if (!IsOptionalRightBrace)
-LeftBrace->Optional = false;
+  LeftBrace->Optional = true;
+  RightBrace->Optional = true;
 }
 
 void UnwrappedLineParser::handleAttributes() {
@@ -2788,7 +2778,8 @@
 
   if (Style.RemoveBracesLLVM) {
 assert(!NestedTooDeep.empty());
-KeepIfBraces = KeepIfBraces || (IfLeftBrace && !IfLeftBrace->Optional) ||
+KeepIfBraces = KeepIfBraces ||
+   (IfLeftBrace && !IfLeftBrace->MatchingParen) ||
NestedTooDeep.back() || IfBlockKind == IfStmtKind::IfOnly ||
IfBlockKind == IfStmtKind::IfElseIf;
   }
@@ -2819,9 +2810,8 @@
  ElseBlockKind == IfStmtKind::IfElseIf;
   } else if (FollowedByIf && IfLBrace && !IfLBrace->Optional) {
 KeepElseBraces = true;
-assert(ElseLeftBrace->Optional);
 assert(ElseLeftBrace->MatchingParen);
-ElseLeftBrace->MatchingParen->Optional = true;
+markOptionalBraces(ElseLeftBrace);
   }
   addUnwrappedLine();
 } else if (FormatTok->is(tok::kw_if)) {
@@ -2856,7 +2846,7 @@
 
   assert(!NestedTooDeep.empty());
   KeepElseBraces = KeepElseBraces ||
-   (ElseLeftBrace && !ElseLeftBrace->Optional) ||
+   (ElseLeftBrace && !ElseLeftBrace->MatchingParen) ||
NestedTooDeep.back();
 
   NestedTooDeep.pop_back();
@@ -2864,11 +2854,17 @@
   if (!KeepIfBraces && !KeepElseBraces) {
 markOptionalBraces(IfLeftBrace);
 markOptionalBraces(ElseLeftBrace);
+  } else if (IfLeftBrace) {
+FormatToken *IfRightBrace = IfLeftBrace->MatchingParen;
+if (IfRightBrace) {
+  assert(IfRightBrace->MatchingParen == IfLeftBrace);
+  assert(!IfLeftBra

[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

2022-12-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

getAPSIntType crashes when analzying a simple case that uses a fixed
point type. Just add a check for isFixedPointType() to the assert to
address the problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139759

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/test/Analysis/fixed-point.c


Index: clang/test/Analysis/fixed-point.c
===
--- /dev/null
+++ clang/test/Analysis/fixed-point.c
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN:   -analyzer-checker=core,debug.ExprInspection -Wno-unused -verify %s
+
+// expected-no-diagnostics
+
+long a(int c) {
   
+  (long _Accum) c >> 4;
+  return c;
+}  
+
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -152,7 +152,8 @@
   T = AT->getValueType();
 }
 
-assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }


Index: clang/test/Analysis/fixed-point.c
===
--- /dev/null
+++ clang/test/Analysis/fixed-point.c
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN:   -analyzer-checker=core,debug.ExprInspection -Wno-unused -verify %s
+
+// expected-no-diagnostics
+
+long a(int c) {   
+  (long _Accum) c >> 4;
+  return c;
+}  
+
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -152,7 +152,8 @@
   T = AT->getValueType();
 }
 
-assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+   Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139387: [NFC][Clang] Add missing test cases for segment load

2022-12-09 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139387

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


[PATCH] D139115: [clang][ExtractAPI] Add support for single symbol SGF

2022-12-09 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

Thanks, the libclang change LGTM other than my comment about the function names.




Comment at: clang/include/clang-c/Documentation.h:589
+ */
+CINDEX_LINKAGE CXString clang_getSingleSymbolSymbolGraphForUSR(const char *usr,
+   CXAPISet api);

`clang_getSingleSymbolSymbolGraphForUSR` is a bit hard to read with the double 
"symbol".  What do you think of 

* `clang_getSymbolGraphForUSR`
* `clang_getSymbolGraphForCursor`

Or perhaps `clang_getSymbolGraphFragmentFor...`?  My thinking is that both USR 
and Cursor are already implying it is a single symbol so we can avoid the 
"single-symbol symbol-graph" term.

I'm not deeply familiar with this API, so apologies if this suggestion makes no 
sense 😅 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139115

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


[PATCH] D136554: Implement CWG2631

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks!

Cleaned up version:

  struct string {
constexpr string(const char*) {};
constexpr ~string();
  };
  struct AutocompleteParsingResult;
  struct optional {
  template  
  constexpr optional(U &&) {}
  };
  struct AutocompleteParsingResult {
  string StringPiece;
  optional expected_result;
  int max_length = 0;
  } kAutocompleteTestcases {
  "", {
  { "", 0 }
  }
  };

And yes, this is about as reduced as I can make it.
I'll investigate later


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D139749: Headers: make a couple of builtins non-static

2022-12-09 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd created this revision.
compnerd added a reviewer: aaron.ballman.
Herald added a project: All.
compnerd requested review of this revision.
Herald added a project: clang.

When building with the 17.5.0 preview toolset for MSVC and building with 
modules, the definition of `_addcarry_u64` and `_subborrow_u64` seem to cause 
issues due to the `static` definition following the non-static declaration in 
the MSVC headers.  Elide the `static` storage class on the declaration in MSVC 
mode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139749

Files:
  clang/lib/Headers/adxintrin.h


Index: clang/lib/Headers/adxintrin.h
===
--- clang/lib/Headers/adxintrin.h
+++ clang/lib/Headers/adxintrin.h
@@ -43,7 +43,10 @@
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+#if !defined(_MSC_VER)
+static
+#endif
+__inline unsigned char __DEFAULT_FN_ATTRS
 _addcarry_u64(unsigned char __cf, unsigned long long __x,
   unsigned long long __y, unsigned long long  *__p)
 {
@@ -59,7 +62,10 @@
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+#if !defined(_MSC_VER)
+static
+#endif
+__inline unsigned char __DEFAULT_FN_ATTRS
 _subborrow_u64(unsigned char __cf, unsigned long long __x,
unsigned long long __y, unsigned long long  *__p)
 {


Index: clang/lib/Headers/adxintrin.h
===
--- clang/lib/Headers/adxintrin.h
+++ clang/lib/Headers/adxintrin.h
@@ -43,7 +43,10 @@
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+#if !defined(_MSC_VER)
+static
+#endif
+__inline unsigned char __DEFAULT_FN_ATTRS
 _addcarry_u64(unsigned char __cf, unsigned long long __x,
   unsigned long long __y, unsigned long long  *__p)
 {
@@ -59,7 +62,10 @@
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+#if !defined(_MSC_VER)
+static
+#endif
+__inline unsigned char __DEFAULT_FN_ATTRS
 _subborrow_u64(unsigned char __cf, unsigned long long __x,
unsigned long long __y, unsigned long long  *__p)
 {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139742: [HLSL] Add trunc library function

2022-12-09 Thread Xiang Li via Phabricator via cfe-commits
python3kgae accepted this revision.
python3kgae added a comment.
This revision is now accepted and ready to land.

LGTM.
Remember to double check the commit message updated to trunc too.

Just noticed we don't have double trunc(double) for hlsl now (hlsl 2021). Need 
make sure to generate float overload DXIL on older shader model when parameter 
is double in hlsl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139742

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


[PATCH] D139640: clang: Add __builtin_elementwise canonicalize and copysign

2022-12-09 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:644
  magnitude than x
+ T__builtin_elementwise_canonicalize(T x)  return the platform specific 
canonical encoding of a floating-point number floating point types
+

I think this needs re-flowing , otherwise the table won't be rendered properly? 
Same for the next line



Comment at: clang/docs/LanguageExtensions.rst:646
+
+ T__builtin_elementwise_copysign(T x, T y)   return the magnitude of T with 
the sign of Y. floating point types
  T __builtin_elementwise_max(T x, T y)   return x or y, whichever is 
larger   integer and floating point types

`T` -> `x`? Also, the argument `y` is lowercase, so `Y` -> `y`?


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

https://reviews.llvm.org/D139640

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


[PATCH] D136515: [builtins] Add __builtin_assume_separate_storage.

2022-12-09 Thread David Goldblatt via Phabricator via cfe-commits
davidtgoldblatt updated this revision to Diff 481770.
davidtgoldblatt added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136515

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-assume-separate-storage.c
  clang/test/Sema/builtin-assume-separate-storage.c

Index: clang/test/Sema/builtin-assume-separate-storage.c
===
--- /dev/null
+++ clang/test/Sema/builtin-assume-separate-storage.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+
+void *nonconst(void);
+
+void test1(int *a, int *b) {
+  __builtin_assume_separate_storage(a, b);
+  // Separate storage assumptions evaluate their arguments unconditionally, like
+  // assume_aligned but *unlike* assume. Check that we don't warn on it.
+  __builtin_assume_separate_storage(a, nonconst());
+  __builtin_assume_separate_storage(nonconst(), a);
+  __builtin_assume_separate_storage(a, 3); // expected-error {{incompatible integer to pointer conversion}}
+  __builtin_assume_separate_storage(3, a); // expected-error {{incompatible integer to pointer conversion}}
+}
Index: clang/test/CodeGen/builtin-assume-separate-storage.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin-assume-separate-storage.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+void *nonconst(void);
+
+// CHECK-LABEL: @test1
+void test1(int *a, int *b) {
+  // CHECK: store ptr %a, ptr [[A_ADDR:%.+]], align
+  // CHECK: store ptr %b, ptr [[B_ADDR:%.+]], align
+  // CHECK: [[A:%.+]] = load ptr, ptr [[A_ADDR]]
+  // CHECK: [[B:%.+]] = load ptr, ptr [[B_ADDR]]
+
+  // CHECK: call void @llvm.assume(i1 true) [ "separate_storage"(ptr [[A]], ptr [[B]]) ]
+  __builtin_assume_separate_storage(a, b);
+}
+
+// Separate storage assumptions evaluate their arguments unconditionally, like
+// assume_aligned but *unlike* assume. Check that we actually do so.
+// CHECK-LABEL: @test2
+void test2(int *a, int *b) {
+  // CHECK: call ptr @nonconst()
+  // CHECK: call void @llvm.assume
+  __builtin_assume_separate_storage(a, nonconst());
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2169,6 +2169,10 @@
 if (SemaBuiltinAssumeAligned(TheCall))
   return ExprError();
 break;
+  case Builtin::BI__builtin_assume_separate_storage:
+if (SemaBuiltinAssumeSeparateStorage(TheCall))
+  return ExprError();
+break;
   case Builtin::BI__builtin_dynamic_object_size:
   case Builtin::BI__builtin_object_size:
 if (SemaBuiltinConstantArgRange(TheCall, 1, 0, 3))
@@ -7800,6 +7804,11 @@
   return false;
 }
 
+/// Handle __builtin_assume_separate_storage. For now this is a no-op, but
+/// eventually we expect an optional multi-arg variadic version (to handle an
+/// excluded range).
+bool Sema::SemaBuiltinAssumeSeparateStorage(CallExpr *TheCall) { return false; }
+
 bool Sema::SemaBuiltinOSLogFormat(CallExpr *TheCall) {
   unsigned BuiltinID =
   cast(TheCall->getCalleeDecl())->getBuiltinID();
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -2823,6 +2823,19 @@
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
+
   case Builtin::BI__arithmetic_fence: {
 // Create the builtin call if FastMath is selected, and the target
 // supports the builtin, otherwise just return the argument.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13411,6 +13411,7 @@
   bool SemaBuiltinArithmeticFence(CallExpr *TheCall);
   bool SemaBuiltinAssume(CallExpr *TheCall);
   bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
+  bool SemaBuiltinAssumeSeparateStorage(CallExpr *TheCall);
   bool SemaBuiltinLongjmp(CallExpr *TheCall);
   bool SemaBuiltinSetjmp(CallExpr *TheCall);
   ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
Index: clang/include/clang/Basic/Builtins.def
=

[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3386
+
+  if (!Result || CurPtr - StartPtr == (ptrdiff_t)(Buffer.size() + 4))
 StartPtr = CurPtr;

tahonermann wrote:
> cor3ntin wrote:
> > tahonermann wrote:
> > > cor3ntin wrote:
> > > > cor3ntin wrote:
> > > > > tahonermann wrote:
> > > > > > This is a bit of a tangent, but under what circumstances would 
> > > > > > `CurPtr - StartPtr` not be equal to `Buffer.size() + 4`? Actually, 
> > > > > > I'm not sure that +4 is correct. It looks like `StartPtr` is 
> > > > > > expected to point to `N` at the beginning of the function, so the 
> > > > > > initial `\` is not included in the range. If `N` isn't seen, the 
> > > > > > function returns early. Likewise, if either of the `{` or `}` 
> > > > > > delimiters is not found, the function returns early.
> > > > > > 
> > > > > > I think the goal of this code is to skip the `getAndAdvanceChar()` 
> > > > > > machinery when the buffer is being claimed (no need to parse UCNs 
> > > > > > or trigraphs in the character name), but it looks like, 
> > > > > > particularly with this DR, that we might always be able to do that.
> > > > > afaict, 4 is correct here because we are one past-the-end.
> > > > > I do however agree that this whole pattern which is used a few times 
> > > > > is probably unnecessary, i do think it would be good to investigate. 
> > > > > Not in this patch though, imo
> > > > I looked into it, I'm sure we could improve but not easily, 
> > > > `getAndAdvanceChar` does set some flags on the token in the presence of 
> > > > trigraphs/line splicing and we need those flags to be set, this is the 
> > > > reason we do need to call that method.
> > > > It's not super efficient but it's such an edge case... I'd rather not 
> > > > touch that now
> > > My concern is that, as is, the code always takes the `else` branch 
> > > (except when `Result` is non-null). Assuming a buffer containing "X", the 
> > > pointers are arranged as follows (where `$` is one past the end).
> > >   \ N { X } $
> > > |   |   `- CurPtr
> > > |   `- Buffer
> > > `- StartPtr
> > > `CurPtr - StartPtr` is 4, but `Buffer.size() + 4` is 5 (`Buffer.size()` 
> > > is 1 in this case).
> > > 
> > > I think there might be an easy test to see if this is working as 
> > > intended. If it isn't, I would expect a diagnostic to be issued if 
> > > trigraphs are enabled and the buffer contains a trigraph sequence. 
> > > Something like:
> > >   \N{LOTUS??>}
> > I can try to add tests
> > 
> > > My concern is that, as is, the code always takes the else branch (except 
> > > when Result is non-null). 
> > Yes, the if branch sole purpose is to set some state in Result.
> > 
> > At the start of the function, StartPtr points to `\`
> > And I'll leave a comment, maybe that will clear up future confusions
> > 
> > There may be a potential refactor here, which is to have 
> > `getAndAdvanceChar` take a `bool & ShouldCleanupToken` parameter instead of 
> > a token so that we don't have to do that dance, but it's a bit outside of 
> > the scope of this patch...
> > At the start of the function, StartPtr points to `\`
> 
> It doesn't look like it does. The first use of `StartPtr` is at line 3314 and 
> it expects to read `N`:
>   3314:   char C = getCharAndSize(StartPtr, CharSize);
>   3315:   assert(C == 'N' && "expected \\N{...}");
Yes, you are right. There was a bug in \u too, probably has been there for ages.
It's unfortunately not testable, any incorrect value would call getCharAndSize 
which is going to do the right thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

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


[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 481767.
cor3ntin added a comment.

Format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15647,7 +15647,7 @@
 https://wg21.link/cwg2640";>2640
 accepted
 Allow more characters in an n-char sequence
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2641";>2641
Index: clang/test/Preprocessor/ucn-pp-identifier.c
===
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef
-// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef
-// RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++2b -pedantic -ftrigraphs -verify=expected,cxx2b -Wundef -Wpre-c++2b-compat
+// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
+// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -fno-trigraphs
+// RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++2b -pedantic -ftrigraphs -DTRIGRAPHS=1 -verify=expected,cxx2b -Wundef -Wpre-c++2b-compat
 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
 // RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s
 
@@ -40,7 +40,6 @@
// ext-warning {{extension}} cxx2b-warning {{before C++2b}}
 #define \N{WASTEBASKET} // expected-error {{macro name must be an identifier}} \
 // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
-
 #define a\u0024
 
 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
@@ -121,20 +120,39 @@
 #define \u{123456789}  // expected-error {{hex escape sequence out of range}} expected-error {{macro name must be an identifier}}
 #define \u{// expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
 #define \u{fgh}// expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
-#define \N{// expected-warning {{incomplete delimited universal character name; treating as '\' 'N' '{' identifier}} expected-error {{macro name must be an identifier}}
+#define \N{
+// expected-warning@-1 {{incomplete delimited universal character name; treating as '\' 'N' '{' identifier}}
+// expected-error@-2 {{macro name must be an identifier}}
 #define \N{}   // expected-warning {{empty delimited universal character name; treating as '\' 'N' '{' '}'}} expected-error {{macro name must be an identifier}}
 #define \N{NOTATHING}  // expected-error {{'NOTATHING' is not a valid Unicode character name}} \
// expected-error {{macro name must be an identifier}}
 #define \NN// expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
 #define \N{GREEK_SMALL-LETTERALPHA}  // expected-error {{'GREEK_SMALL-LETTERALPHA' is not a valid Unicode character name}} \
  // expected-note {{characters names in Unicode escape sequences are sensitive to case and whitespaces}}
+#define \N{🤡}  // expected-error {{'🤡' is not a valid Unicode character name}} \
+// expected-error {{macro name must be an identifier}}
 
 #define CONCAT(A, B) A##B
-int CONCAT(\N{GREEK, CAPITALLETTERALPHA}); // expected-error{{expected}} \
-   // expected-warning {{incomplete delimited universal character name}}
+int CONCAT(\N{GREEK
+, CAPITALLETTERALPHA});
+// expected-error@-2 {{expected}} \
+// expected-warning@-2 {{incomplete delimited universal character name}}
+
+int \N{\
+LATIN CAPITAL LETTER A WITH GRAVE};
+//ext-warning@-2 {{extension}} cxx2b-warning@-2 {{before C++2b}}
 
 #ifdef TRIGRAPHS
-int \N?? = 0; // expected-warning{{extension}} cxx2b-warning {{before C++2b}} \
+int \N?? = 0; // cxx2b-warning {{before C++2b}} \
+//ext-warning {{extension}}\
 // expected-warning 2{{trigraph converted}}
 
+int a\N{LATIN CAPITAL LETTER A WITH GRAVE??>; // ex

[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 481766.
cor3ntin added a comment.

- Rebase
- Add/Improve comments
- Add more trigrahs tests
- Fix crash when a trigraph appears at the end of a named escape sequence and 
trigraphs are disabled
- Fix when getAndAdvanceChar is called - alas there is no way to write tests 
for that but I did check in a debugger.
- Rename s/Res/Match

There are still some inefficiencies with getAndAdvanceChar, but it calls for a
much bigger refactor than what should be in scope for this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15647,7 +15647,7 @@
 https://wg21.link/cwg2640";>2640
 accepted
 Allow more characters in an n-char sequence
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2641";>2641
Index: clang/test/Preprocessor/ucn-pp-identifier.c
===
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef
-// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef
-// RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++2b -pedantic -ftrigraphs -verify=expected,cxx2b -Wundef -Wpre-c++2b-compat
+// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
+// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -fno-trigraphs
+// RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++2b -pedantic -ftrigraphs -DTRIGRAPHS=1 -verify=expected,cxx2b -Wundef -Wpre-c++2b-compat
 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
 // RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s
 
@@ -40,7 +40,6 @@
// ext-warning {{extension}} cxx2b-warning {{before C++2b}}
 #define \N{WASTEBASKET} // expected-error {{macro name must be an identifier}} \
 // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
-
 #define a\u0024
 
 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
@@ -121,20 +120,39 @@
 #define \u{123456789}  // expected-error {{hex escape sequence out of range}} expected-error {{macro name must be an identifier}}
 #define \u{// expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
 #define \u{fgh}// expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
-#define \N{// expected-warning {{incomplete delimited universal character name; treating as '\' 'N' '{' identifier}} expected-error {{macro name must be an identifier}}
+#define \N{
+// expected-warning@-1 {{incomplete delimited universal character name; treating as '\' 'N' '{' identifier}}
+// expected-error@-2 {{macro name must be an identifier}}
 #define \N{}   // expected-warning {{empty delimited universal character name; treating as '\' 'N' '{' '}'}} expected-error {{macro name must be an identifier}}
 #define \N{NOTATHING}  // expected-error {{'NOTATHING' is not a valid Unicode character name}} \
// expected-error {{macro name must be an identifier}}
 #define \NN// expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
 #define \N{GREEK_SMALL-LETTERALPHA}  // expected-error {{'GREEK_SMALL-LETTERALPHA' is not a valid Unicode character name}} \
  // expected-note {{characters names in Unicode escape sequences are sensitive to case and whitespaces}}
+#define \N{🤡}  // expected-error {{'🤡' is not a valid Unicode character name}} \
+// expected-error {{macro name must be an identifier}}
 
 #define CONCAT(A, B) A##B
-int CONCAT(\N{GREEK, CAPITALLETTERALPHA}); // expected-error{{expected}} \
-   // expected-warning {{incomplete delimited universal character name}}
+int CONCAT(\N{GREEK
+, CAPITALLETTERALPHA});
+// expected-error@-2 {{expected}} \
+// expected-warning@-2 {{incomplete delimited universal character name}}
+
+int \N{\
+LATIN CAPITAL LETTER A WITH GRAVE

[PATCH] D139745: Use poison instead of undef where its used as placeholder[NFC]

2022-12-09 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito created this revision.
ManuelJBrito added a reviewer: nlopes.
Herald added subscribers: Enna1, ThomasRaoux, hiraditya.
Herald added a project: All.
ManuelJBrito requested review of this revision.
Herald added a reviewer: zuban32.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Replacing the following instances of undef with poison where undef is used as a 
placeholder for aggregate construction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139745

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/builtinshufflevector2.c
  clang/test/CodeGenCXX/nrvo.cpp
  clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
  clang/test/CodeGenCXX/vla-consruct.cpp
  clang/test/CodeGenCoroutines/coro-eh-cleanup-exp-namespace.cpp
  clang/test/CodeGenCoroutines/coro-eh-cleanup.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/single_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/threadprivate_codegen.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/CodeGen/SjLjEHPrepare.cpp
  llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
  llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
  llvm/test/Instrumentation/ThreadSanitizer/atomic.ll

Index: llvm/test/Instrumentation/ThreadSanitizer/atomic.ll
===
--- llvm/test/Instrumentation/ThreadSanitizer/atomic.ll
+++ llvm/test/Instrumentation/ThreadSanitizer/atomic.ll
@@ -1645,7 +1645,7 @@
 ; CHECK-NEXT: {{.*}} = call i64 @__tsan_atomic64_compare_exchange_val(ptr {{.*}}, i64 {{.*}}, i64 {{.*}}, i32 5, i32 5), !dbg
 ; CHECK-NEXT: {{.*}} = icmp eq i64
 ; CHECK-NEXT: {{.*}} = inttoptr i64 {{.*}} to ptr
-; CHECK-NEXT: {{.*}} = insertvalue { ptr, i1 } undef, ptr {{.*}}, 0
+; CHECK-NEXT: {{.*}} = insertvalue { ptr, i1 } poison, ptr {{.*}}, 0
 ; CHECK-NEXT: {{.*}} = insertvalue { ptr, i1 } {{.*}}, i1 {{.*}}, 1
 
 define i128 @atomic128_load_unordered(ptr %a) nounwind uwtable {
Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -801,7 +801,7 @@
 }
 
 Value *Res =
-  IRB.CreateInsertValue(UndefValue::get(CASI->getType()), OldVal, 0);
+  IRB.CreateInsertValue(PoisonValue::get(CASI->getType()), OldVal, 0);
 Res = IRB.CreateInsertValue(Res, Success, 1);
 
 I->replaceAllUsesWith(Res);
Index: llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
===
--- llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
+++ llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
@@ -283,7 +283,7 @@
   // umul.with.overflow intrinsic return a structure, where the first element
   // is the multiplication result, and the second is an overflow bit.
   Type *StructTy = UMulFunc->getReturnType();
-  Value *Agg = IRB.CreateInsertValue(UndefValue::get(StructTy), Mul, {0});
+  Value *Agg = IRB.CreateInsertValue(PoisonValue::get(StructTy), Mul, {0});
   Value *Res = IRB.CreateInsertValue(Agg, Overflow, {1});
   IRB.CreateRet(Res);
 }
Index: llvm/lib/CodeGen/SjLjEHPrepare.cpp
===
--- llvm/lib/CodeGen/SjLjEHPrepare.cpp
+++ llvm/lib/CodeGen/SjLjEHPrepare.cpp
@@ -164,7 +164,7 @@
   // There are still some uses of LPI. Construct an aggregate with the exception
   // values and replace the LPI with that aggregate.
   Type *LPadType = LPI->getType();
-  Value *LPadVal = UndefValue::get(LPadType);
+  Value *LPadVal = PoisonValue::get(LPadType);
   auto *SelI = cast(SelVal);
   IRBuilder<> Builder(SelI->getParent(), std::next(SelI->getIterator()));
   LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
Index: llvm/lib/Analysis/ValueTracking.cpp
===
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4107,7 +4107,7 @@
   assert(InsertBefore && "Must have someplace to insert!");
   Type *IndexedType = ExtractValueInst::getIndexedType(From->getType(),
  idx_range);
-  Value *To = UndefValue::get(IndexedType);
+  Value *To = PoisonValue::get(IndexedType);
   SmallVector Idxs(idx_range.begin(), idx_range.end());
   unsigned IdxSkip = Idxs.size();
 
Index: clang/test/OpenMP/threadprivate_codegen.cpp
==

[PATCH] D128372: [Clang-Tidy] Empty Check

2022-12-09 Thread Christopher Di Bella via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec3f8feddf81: [Clang-Tidy] Empty Check (authored by 
abrahamcd, committed by cjdb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
@@ -0,0 +1,578 @@
+// RUN: %check_clang_tidy %s bugprone-standalone-empty %t
+
+namespace std {
+template 
+struct vector {
+  bool empty();
+};
+
+template 
+struct vector_with_clear {
+  bool empty();
+  void clear();
+};
+
+template 
+struct vector_with_void_empty {
+  void empty();
+  void clear();
+};
+
+template 
+struct vector_with_int_empty {
+  int empty();
+  void clear();
+};
+
+template 
+struct vector_with_clear_args {
+  bool empty();
+  void clear(int i);
+};
+
+template 
+struct vector_with_clear_variable {
+  bool empty();
+  int clear;
+};
+
+template 
+bool empty(T &&);
+
+} // namespace std
+
+namespace absl {
+struct string {
+  bool empty();
+};
+
+struct string_with_clear {
+  bool empty();
+  void clear();
+};
+
+struct string_with_void_empty {
+  void empty();
+  void clear();
+};
+
+struct string_with_int_empty {
+  int empty();
+  void clear();
+};
+
+struct string_with_clear_args {
+  bool empty();
+  void clear(int i);
+};
+
+struct string_with_clear_variable {
+  bool empty();
+  int clear;
+};
+
+template 
+bool empty(T &&);
+} // namespace absl
+
+namespace test {
+template 
+void empty(T &&);
+} // namespace test
+
+namespace base {
+template 
+struct base_vector {
+void clear();
+};
+
+template 
+struct base_vector_clear_with_args {
+void clear(int i);
+};
+
+template 
+struct base_vector_clear_variable {
+int clear;
+};
+
+struct base_vector_non_dependent {
+void clear();
+};
+
+template 
+struct vector : base_vector {
+bool empty();
+};
+
+template 
+struct vector_clear_with_args : base_vector_clear_with_args {
+bool empty();
+};
+
+template 
+struct vector_clear_variable : base_vector_clear_variable {
+bool empty();
+};
+
+template 
+struct vector_non_dependent : base_vector_non_dependent {
+bool empty();
+};
+
+template 
+bool empty(T &&);
+
+} // namespace base
+
+namespace qualifiers {
+template 
+struct vector_with_const_clear {
+  bool empty() const;
+  void clear() const;
+};
+
+template 
+struct vector_with_const_empty {
+  bool empty() const;
+  void clear();
+};
+
+template 
+struct vector_with_volatile_clear {
+  bool empty() volatile;
+  void clear() volatile;
+};
+
+template 
+struct vector_with_volatile_empty {
+  bool empty() volatile;
+  void clear();
+};
+
+template 
+bool empty(T &&);
+} // namespace qualifiers
+
+
+void test_member_empty() {
+  {
+std::vector v;
+v.empty();
+// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+  }
+
+  {
+std::vector_with_void_empty v;
+v.empty();
+// no-warning
+  }
+
+  {
+std::vector_with_clear v;
+v.empty();
+// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 'empty()'; did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+  }
+
+  {
+std::vector_with_int_empty v;
+v.empty();
+// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 'empty()'; did you mean 'clear()'? [bugprone-standalone-empty]
+// CHECK-FIXES: {{^  }}  v.clear();{{$}}
+  }
+
+  {
+std::vector_with_clear_args v;
+v.empty();
+// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+  }
+
+  {
+std::vector_with_clear_variable v;
+v.empty();
+// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+  }
+
+  {
+absl::string s;
+s.empty();
+// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+  }
+
+  {
+absl::string_with_void_empty s;
+s.empty();
+// no-warning
+  }
+
+  {
+absl::string_with_clear s;
+s.empty();
+// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 'empty()'; did you mean 'clear()'? [bugpro

[clang-tools-extra] ec3f8fe - [Clang-Tidy] Empty Check

2022-12-09 Thread Christopher Di Bella via cfe-commits

Author: Abraham Corea Diaz
Date: 2022-12-09T23:19:45Z
New Revision: ec3f8feddf81f2868c840f8e9af8587f055c713c

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

LOG: [Clang-Tidy] Empty Check

Adds a clang-tidy check for the incorrect use of `empty()` on a
container when the result of the call is ignored.

Authored-by: Abraham Corea Diaz 
Co-authored-by: Denis Nikitin 

Reviewed By: cjdb

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

Added: 
clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.h
clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 34386a0cb0154..f2842a62c5fe1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -49,6 +49,7 @@
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
 #include "SpuriouslyWakeUpFunctionsCheck.h"
+#include "StandaloneEmptyCheck.h"
 #include "StringConstructorCheck.h"
 #include "StringIntegerAssignmentCheck.h"
 #include "StringLiteralWithEmbeddedNulCheck.h"
@@ -156,6 +157,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-sizeof-expression");
 CheckFactories.registerCheck(
 "bugprone-spuriously-wake-up-functions");
+CheckFactories.registerCheck(
+"bugprone-standalone-empty");
 CheckFactories.registerCheck(
 "bugprone-string-constructor");
 CheckFactories.registerCheck(

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 34c019357dab5..643c62132d875 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -45,6 +45,7 @@ add_clang_library(clangTidyBugproneModule
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
   SpuriouslyWakeUpFunctionsCheck.cpp
+  StandaloneEmptyCheck.cpp
   StringConstructorCheck.cpp
   StringIntegerAssignmentCheck.cpp
   StringLiteralWithEmbeddedNulCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
new file mode 100644
index 0..0fa58ce58eb69
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
@@ -0,0 +1,207 @@
+//===--- StandaloneEmptyCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "StandaloneEmptyCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Casting.h"
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+using ast_matchers::BoundNodes;
+using ast_matchers::callee;
+using ast_matchers::callExpr;
+using ast_matchers::cxxMemberCallExpr;
+using ast_matchers::cxxMethodDecl;
+using ast_matchers::expr;
+using ast_matchers::functionDecl;
+using ast_matchers::hasName;
+using ast_matchers::hasParent;
+using ast_matchers::ignoringImplicit;
+using ast_matchers::ignoringParenImpCasts;
+using ast_matchers::MatchFinder;
+using ast_matchers::optionally;
+using ast_matchers::returns;
+using ast_matchers::stmt;
+using ast_matchers::stmtExpr;
+using ast_matchers::unless;
+using ast_matchers::voidType;
+
+const Expr *getCondition(const BoundNodes &Nodes, const StringRef NodeId) {
+  const auto *If = Nodes.getNodeAs(NodeId);
+  if (If != nullptr)
+return If->getCond();
+
+  const auto *For = Nodes.getNodeAs(NodeId);
+  if (For != nullptr)
+return For->getCond();

[PATCH] D139742: [HLSL] Add acos library function

2022-12-09 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added a comment.

The PR title is acos but trunc is added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139742

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


[PATCH] D139503: [Headers][ARM] Allow `struct _Unwind_Exception` in unwind.h

2022-12-09 Thread Ryan Prichard via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG106a99276f9e: [Headers][ARM] Allow `struct 
_Unwind_Exception` in unwind.h (authored by rprichard).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139503

Files:
  clang/lib/Headers/unwind.h


Index: clang/lib/Headers/unwind.h
===
--- clang/lib/Headers/unwind.h
+++ clang/lib/Headers/unwind.h
@@ -65,7 +65,8 @@
 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
   defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
-typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
+typedef struct _Unwind_Control_Block _Unwind_Control_Block;
+#define _Unwind_Exception _Unwind_Control_Block /* Alias */
 #else
 struct _Unwind_Exception;
 typedef struct _Unwind_Exception _Unwind_Exception;


Index: clang/lib/Headers/unwind.h
===
--- clang/lib/Headers/unwind.h
+++ clang/lib/Headers/unwind.h
@@ -65,7 +65,8 @@
 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
   defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
-typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
+typedef struct _Unwind_Control_Block _Unwind_Control_Block;
+#define _Unwind_Exception _Unwind_Control_Block /* Alias */
 #else
 struct _Unwind_Exception;
 typedef struct _Unwind_Exception _Unwind_Exception;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 106a992 - [Headers][ARM] Allow `struct _Unwind_Exception` in unwind.h

2022-12-09 Thread Ryan Prichard via cfe-commits

Author: Ryan Prichard
Date: 2022-12-09T15:16:20-08:00
New Revision: 106a99276f9e7b9eec9542cc2b4dcd8489eb1a6b

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

LOG: [Headers][ARM] Allow `struct _Unwind_Exception` in unwind.h

Use the same approach as used in libunwind/include/unwind_arm_ehabi.h
(D89570) and GCC's unwind-arm-common.h, so that _Unwind_Exception can be
used both with and without the struct tag.

Fixes a build failure in libcxxabi/test/forced_unwind1.pass.cpp.

Reviewed By: danielkiss

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

Added: 


Modified: 
clang/lib/Headers/unwind.h

Removed: 




diff  --git a/clang/lib/Headers/unwind.h b/clang/lib/Headers/unwind.h
index 971a62da0d212..33e1792cd1fb7 100644
--- a/clang/lib/Headers/unwind.h
+++ b/clang/lib/Headers/unwind.h
@@ -65,7 +65,8 @@ struct _Unwind_Context;
 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
   defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
-typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
+typedef struct _Unwind_Control_Block _Unwind_Control_Block;
+#define _Unwind_Exception _Unwind_Control_Block /* Alias */
 #else
 struct _Unwind_Exception;
 typedef struct _Unwind_Exception _Unwind_Exception;



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


[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Headers/__clang_hip_math.h:145
 // BEGIN FLOAT
-#if defined(__cplusplus)
 __DEVICE__

doru1004 wrote:
> arsenm wrote:
> > Why not introduce __clang_hip_stdlib.h now?
> Do we want to do this in this patch or as a separate patch? Is the work on 
> libc_gpu/libm_gpu going to build up on these headers or will these headers be 
> replaced in the process?
Yes. I think this kind of thing is hard to untangle once people start using it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

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


[PATCH] D139115: [clang][ExtractAPI] Add support for single symbol SGF

2022-12-09 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/include/clang/ExtractAPI/DeclarationFragments.h:91
+/// The associated declaration, if applicable.
+const Decl *Declaration;
+

zixuw wrote:
> Is the decl guaranteed to be available when `Fragment` is used?
> In our existing use case this might be fine as the serializer will be used 
> while the AST is still alive. But this is actually the first thing that adds 
> the dependency to the AST IIRC. So this makes the whole APISet dependent on 
> the AST
Currently yes, the Decl is available as the APISet is not kept around beyond 
the lifetime of the AST. Nonetheless I agree that it is used in an unusual 
manner, to help traverse the AST in libclang as opposed to truly encoding 
information about the available APIs. I think if we introduce new clients of 
APISet we would need to add an extension mechanism to the visitation mechanism 
to enable use cases like this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139115

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


[PATCH] D131830: [OpenMP] Clang Support for taskwait nowait clause

2022-12-09 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 481742.
koops added a comment.

git pull & reloading the earlier patch.


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

https://reviews.llvm.org/D131830

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/target_depend_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_simd_depend_codegen.cpp
  clang/test/OpenMP/target_teams_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
  clang/test/OpenMP/target_update_depend_codegen.cpp
  clang/test/OpenMP/task_codegen.cpp
  clang/test/OpenMP/task_if_codegen.cpp
  clang/test/OpenMP/taskwait_ast_print.cpp
  clang/test/OpenMP/taskwait_codegen.cpp
  clang/test/OpenMP/taskwait_depend_codegen.cpp
  clang/test/OpenMP/taskwait_depend_nowait_codegen.cpp
  clang/test/OpenMP/taskwait_nowait_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp.h
  openmp/runtime/src/kmp_taskdeps.cpp
  openmp/runtime/src/kmp_tasking.cpp

Index: openmp/runtime/src/kmp_tasking.cpp
===
--- openmp/runtime/src/kmp_tasking.cpp
+++ openmp/runtime/src/kmp_tasking.cpp
@@ -2049,7 +2049,8 @@
 template 
 static kmp_int32 __kmpc_omp_taskwait_template(ident_t *loc_ref, kmp_int32 gtid,
   void *frame_address,
-  void *return_address) {
+  void *return_address,
+  kmp_int32 has_no_wait) {
   kmp_taskdata_t *taskdata = nullptr;
   kmp_info_t *thread;
   int thread_finished = FALSE;
@@ -2162,23 +2163,34 @@
 OMPT_NOINLINE
 static kmp_int32 __kmpc_omp_taskwait_ompt(ident_t *loc_ref, kmp_int32 gtid,
   void *frame_address,
-  void *return_address) {
+  void *return_address,
+  kmp_int32 has_no_wait) {
   return __kmpc_omp_taskwait_template(loc_ref, gtid, frame_address,
-return_address);
+return_address, has_no_wait);
 }
 #endif // OMPT_SUPPORT && OMPT_OPTIONAL
 
 // __kmpc_omp_taskwait: Wait until all tasks generated by the current task are
 // complete
 kmp_int32 __kmpc_omp_taskwait(ident_t *loc_ref, kmp_int32 gtid) {
+  return __kmpc_omp_taskwait_51(loc_ref, gtid, false);
+}
+
+/* __kmpc_omp_taskwait_51 : Function for OpenMP 5.1 nowait clause.
+ *  Placeholder for taskwait with nowait clause.
+ *  The code is a copy of __kmpc_omp_taskwait.*/
+kmp_int32 __kmpc_omp_taskwait_51(ident_t *loc_ref, kmp_int32 gtid,
+ kmp_int32 has_no_wait) {
 #if OMPT_SUPPORT && OMPT_OPTIONAL
   if (UNLIKELY(ompt_enabled.enabled)) {
 OMPT_STORE_RETURN_ADDRESS(gtid);
 return __kmpc_omp_taskwait_ompt(loc_ref, gtid, OMPT_GET_FRAME_ADDRESS(0),
-OMPT_LOAD_RETURN_ADDRESS(gtid));
+OMPT_LOAD_RETURN_ADDRESS(gtid),
+has_no_wait);
   }
 #endif
-  return __kmpc_omp_taskwait_template(loc_ref, gtid, NULL, NULL);
+  return __kmpc_omp_taskwait_template(loc_ref, gtid, NULL, NULL,
+ has_no_wait);
 }
 
 // __kmpc_omp_taskyield: switch to a different task
Index: openmp/runtime/src/kmp_taskdeps.cpp
===
--- openmp/runtime/src/kmp_taskdeps.cpp
+++ openmp/runtime/src/kmp_taskdeps.cpp
@@ -744,10 +744,24 @@
 void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps,
   kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias,
   kmp_depend_info_t *noalias_dep_list) {
-  KA_TRACE(10, ("__kmpc_omp_wait_deps(enter): T#%d loc=%p\n", gtid, loc_ref));
+  __kmpc_omp_taskwait_deps_51(loc_ref, gtid, ndeps, dep_list, ndeps_noalias,
+  noalias_dep_list, false);
+}
 
+/* __kmpc_omp_taskwait_deps_51

[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Headers/__clang_hip_math.h:145
 // BEGIN FLOAT
-#if defined(__cplusplus)
 __DEVICE__

arsenm wrote:
> Why not introduce __clang_hip_stdlib.h now?
Do we want to do this in this patch or as a separate patch? Is the work on 
libc_gpu/libm_gpu going to build up on these headers or will these headers be 
replaced in the process?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

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


[PATCH] D136554: Implement CWG2631

2022-12-09 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

a really bad reduced repro which also has random syntax errors:

  using string = struct basic_string {
constexpr basic_string(char *) {} constexpr ~basic_string(
  } struct AutocompleteParsingResult struct optional {
template  constexpr optional(U &&) 
{}
namespace enum { kName } struct AutocompleteParsingResult {
  string StringPiece;
  optional expected_result;
  int max_length = 0
} kAutocompleteTestcases {
  "", {
{ "", kName }
  }
  }

`clang -cc1 -x c++ -triple x86_64-unknown-linux-gnu  -std=c++20  -fsyntax-only  
/tmp/reduced.cpp.orig -ferror-limit 1`
working on a reduced repro with -ferror-limit=1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D139742: [HLSL] Add acos library function

2022-12-09 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 481748.
bob80905 added a comment.

The commit still isn't included, adding ^ character


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139742

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/trunc.hlsl

Index: clang/test/CodeGenHLSL/builtins/trunc.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/trunc.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.trunc.f16(
+// NO_HALF: define noundef float @"?test_trunc_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.trunc.f32(
+half test_trunc_half ( half p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.trunc.v2f16
+// NO_HALF: define noundef <2 x float> @"?test_trunc_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.trunc.v2f32(
+half2 test_trunc_half2 ( half2 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.trunc.v3f16
+// NO_HALF: define noundef <3 x float> @"?test_trunc_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.trunc.v3f32(
+half3 test_trunc_half3 ( half3 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.trunc.v4f16
+// NO_HALF: define noundef <4 x float> @"?test_trunc_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.trunc.v4f32(
+half4 test_trunc_half4 ( half4 p0 ) {
+  return trunc ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.trunc.f32(
+float test_trunc_float ( float p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.trunc.v2f32
+float2 test_trunc_float2 ( float2 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float> @llvm.trunc.v3f32
+float3 test_trunc_float3 ( float3 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <4 x float> @
+// CHECK: call <4 x float> @llvm.trunc.v4f32
+float4 test_trunc_float4 ( float4 p0 ) {
+  return trunc ( p0 );
+}
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -189,5 +189,35 @@
 __attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
 double4 sin(double4);
 
+// trunc builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half trunc(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half2 trunc(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half3 trunc(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half4 trunc(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc))) float
+trunc(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+float2 trunc(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+float3 trunc(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+float4 trunc(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc))) double
+trunc(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+double2 trunc(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+double3 trunc(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+double4 trunc(double4);
+
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] be30567 - Revert "Implement CWG2631"

2022-12-09 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2022-12-09T14:20:30-08:00
New Revision: be305674bfd9e559b5e2d9297519124c70c65789

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

LOG: Revert "Implement CWG2631"

This reverts commit c9a6713b4788f10b81202b70993068e475b392f7.

Causes crashes, see D136554.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Sema/UsedDeclVisitor.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp
clang/test/SemaCXX/cxx11-default-member-initializers.cpp
clang/test/SemaCXX/source_location.cpp
clang/www/cxx_dr_status.html

Removed: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/CodeGenCXX/meminit-initializers-odr.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6bd038fbdc16f..53155b0e2a492 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -642,11 +642,6 @@ C++ Language Changes in Clang
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
 - implemented `DR2654 `_ which undeprecates
   all compound assignements operations on volatile qualified variables.
-- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
-  member initializers are diagnosed when and if the default is used.
-  This Fixes `Issue 56379 `_
-  and changes the value of ``std::source_location::current()``
-  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 9d3fd98f65e29..81267ff568c5b 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1245,12 +1245,8 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final
-: public Expr,
-  private llvm::TrailingObjects {
+class CXXDefaultArgExpr final : public Expr {
   friend class ASTStmtReader;
-  friend class ASTReader;
-  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1259,7 +1255,7 @@ class CXXDefaultArgExpr final
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-Expr *RewrittenExpr, DeclContext *UsedContext)
+DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1268,58 +1264,28 @@ class CXXDefaultArgExpr final
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
-CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
-if (RewrittenExpr)
-  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
-  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
-  : Expr(CXXDefaultArgExprClass, Empty) {
-CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
-  }
-
-  size_t numTrailingObjects() const {
-return CXXDefaultArgExprBits.HasRewrittenInit;
-  }
-
 public:
-  static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
-bool HasRewrittenInit);
+  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
 
   // \p Param is the parameter whose default argument is used by this
   // expression.
   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
-   ParmVarDecl *Param, Expr *RewrittenExpr,
-   DeclContext *UsedContext);
+   ParmVarDecl *Param,
+

[PATCH] D139742: [HLSL] Add acos library function

2022-12-09 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 481747.
bob80905 added a comment.

dont just paste the clang format commit onto the revision


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139742

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h


Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -221,5 +221,3 @@
 
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_
-
-


Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -221,5 +221,3 @@
 
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_
-
-
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139742: [HLSL] Add acos library function

2022-12-09 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
bob80905 added reviewers: beanz, python3kgae.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139742

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h


Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -221,5 +221,3 @@
 
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_
-
-


Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -221,5 +221,3 @@
 
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_
-
-
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136554: Implement CWG2631

2022-12-09 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks reopened this revision.
aeubanks added a comment.
This revision is now accepted and ready to land.

I've bisected another crash to this change. Reverting, and currently creducing 
a repro.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D131830: [OpenMP] Clang Support for taskwait nowait clause

2022-12-09 Thread Sunil K via Phabricator via cfe-commits
koops added a comment.

mstorsjo, I have uploaded a new patch which has __kmpc_omp_taskwait_51 in 
dllexports. 
Can you please check the patch on windows?


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

https://reviews.llvm.org/D131830

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


[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3323
 if (Diagnose)
   Diag(StartPtr, diag::warn_ucn_escape_incomplete);
 return llvm::None;

I was able to confirm that `StartPtr` does point to `N`. See the diagnostic 
generated at https://godbolt.org/z/qnajcMeso; the diagnostic caret points to 
`N` instead of `\`.
  :1:2: warning: incomplete delimited universal character name; 
treating as '\' 'N' '{' identifier [-Wunicode]
  \N{abc
   ^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

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


[PATCH] D139450: Warn about unsupported ibmlongdouble

2022-12-09 Thread Tulio Magno Quites Machado Filho via Phabricator via cfe-commits
tuliom marked 3 inline comments as done.
tuliom added inline comments.



Comment at: clang/lib/Driver/ToolChains/PPCLinux.cpp:74
+const Driver &D,
+const llvm::opt::ArgList &Args) const {
+  if (Args.hasArg(options::OPT_nostdlib, options::OPT_nostdlibxx))

nikic wrote:
> I don't think this formatting is right. You may find 
> clang/tools/clang-format/clang-format-diff.py helpful.
> 
> I use this script locally:
> ```
> #!/bin/sh
> git diff -U ${1:-HEAD} | clang/tools/clang-format/clang-format-diff.py -p1
> ```
> And then do something like `./clang_format_diff.sh | patch -p0` after 
> checking that it did not reformat too much.
Thanks, this pointed out 2 errors.



Comment at: clang/lib/Driver/ToolChains/PPCLinux.cpp:96
   bool HasUnsupportedCXXLib =
-  StdLib == CST_Libcxx ||
+  (StdLib == CST_Libcxx && !defaultToIEEELongDouble()) ||
   (StdLib == CST_Libstdcxx &&

qiucf wrote:
> `SupportIEEEFloat128` checks the library version:
> 
> * If using libstdc++, then libstdc++ (GCC) >= 12.1.0 is okay.
> * If using libc++, then sorry, no libc++ supports `-mabi=ieeelongdouble` now.
> * Glibc should >= 2.32
> 
> If the assumptions are still right, this changes its meaning (and 
> `supportIBMLongDouble` has different meaning from it).
@qiucf In operating systems that switched to IEEE long double by default, all 
libraries (and programs) are built with IEEE long double, including libc++.



Comment at: clang/test/Driver/lit.local.cfg:25
+
+if config.ppc_linux_default_ieeelongdouble == "ON":
+  config.available_features.add('ppc_linux_default_ieeelongdouble')

nikic wrote:
> I believe this isn't robust, because ON is not the only possible value. 
> Instead, you'll want to canonicalize the variable: 
> https://github.com/llvm/llvm-project/blob/03e6d9d9d1d48e43f3efc35eb75369b90d4510d5/clang/test/CMakeLists.txt#L4
Changed. This caused a few other modifications in the latest revision.



Comment at: clang/test/Driver/lit.local.cfg:26
+if config.ppc_linux_default_ieeelongdouble == "ON":
+  config.available_features.add('ppc_linux_default_ieeelongdouble')

qiucf wrote:
> Can we assume if we are compiling with `-mabi=ieeelongdouble`, then libc++ 
> 'must' be built with the same long double ABI? If I understand correctly, 
> they're unrelated.
@qiucf I didn't understand this part. Are you suggesting to remove the long 
double warnings because the way the compiler was built is unrelated to the way 
libc++ was built?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139450

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


[PATCH] D131830: [OpenMP] Clang Support for taskwait nowait clause

2022-12-09 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 481740.
koops added a comment.

Addition of __kmpc_omp_taskwait_51 in dllexports.


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

https://reviews.llvm.org/D131830

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/target_depend_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_simd_depend_codegen.cpp
  clang/test/OpenMP/target_teams_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
  clang/test/OpenMP/target_update_depend_codegen.cpp
  clang/test/OpenMP/task_codegen.cpp
  clang/test/OpenMP/task_if_codegen.cpp
  clang/test/OpenMP/taskwait_ast_print.cpp
  clang/test/OpenMP/taskwait_codegen.cpp
  clang/test/OpenMP/taskwait_depend_codegen.cpp
  clang/test/OpenMP/taskwait_depend_nowait_codegen.cpp
  clang/test/OpenMP/taskwait_nowait_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp.h
  openmp/runtime/src/kmp_taskdeps.cpp
  openmp/runtime/src/kmp_tasking.cpp

Index: openmp/runtime/src/kmp_tasking.cpp
===
--- openmp/runtime/src/kmp_tasking.cpp
+++ openmp/runtime/src/kmp_tasking.cpp
@@ -2049,7 +2049,8 @@
 template 
 static kmp_int32 __kmpc_omp_taskwait_template(ident_t *loc_ref, kmp_int32 gtid,
   void *frame_address,
-  void *return_address) {
+  void *return_address,
+  kmp_int32 has_no_wait) {
   kmp_taskdata_t *taskdata = nullptr;
   kmp_info_t *thread;
   int thread_finished = FALSE;
@@ -2162,23 +2163,34 @@
 OMPT_NOINLINE
 static kmp_int32 __kmpc_omp_taskwait_ompt(ident_t *loc_ref, kmp_int32 gtid,
   void *frame_address,
-  void *return_address) {
+  void *return_address,
+  kmp_int32 has_no_wait) {
   return __kmpc_omp_taskwait_template(loc_ref, gtid, frame_address,
-return_address);
+return_address, has_no_wait);
 }
 #endif // OMPT_SUPPORT && OMPT_OPTIONAL
 
 // __kmpc_omp_taskwait: Wait until all tasks generated by the current task are
 // complete
 kmp_int32 __kmpc_omp_taskwait(ident_t *loc_ref, kmp_int32 gtid) {
+  return __kmpc_omp_taskwait_51(loc_ref, gtid, false);
+}
+
+/* __kmpc_omp_taskwait_51 : Function for OpenMP 5.1 nowait clause.
+ *  Placeholder for taskwait with nowait clause.
+ *  The code is a copy of __kmpc_omp_taskwait.*/
+kmp_int32 __kmpc_omp_taskwait_51(ident_t *loc_ref, kmp_int32 gtid,
+ kmp_int32 has_no_wait) {
 #if OMPT_SUPPORT && OMPT_OPTIONAL
   if (UNLIKELY(ompt_enabled.enabled)) {
 OMPT_STORE_RETURN_ADDRESS(gtid);
 return __kmpc_omp_taskwait_ompt(loc_ref, gtid, OMPT_GET_FRAME_ADDRESS(0),
-OMPT_LOAD_RETURN_ADDRESS(gtid));
+OMPT_LOAD_RETURN_ADDRESS(gtid),
+has_no_wait);
   }
 #endif
-  return __kmpc_omp_taskwait_template(loc_ref, gtid, NULL, NULL);
+  return __kmpc_omp_taskwait_template(loc_ref, gtid, NULL, NULL,
+ has_no_wait);
 }
 
 // __kmpc_omp_taskyield: switch to a different task
Index: openmp/runtime/src/kmp_taskdeps.cpp
===
--- openmp/runtime/src/kmp_taskdeps.cpp
+++ openmp/runtime/src/kmp_taskdeps.cpp
@@ -744,10 +744,24 @@
 void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps,
   kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias,
   kmp_depend_info_t *noalias_dep_list) {
-  KA_TRACE(10, ("__kmpc_omp_wait_deps(enter): T#%d loc=%p\n", gtid, loc_ref));
+  __kmpc_omp_taskwait_deps_51(loc_ref, gtid, ndeps, dep_list, ndeps_noalias,
+  noalias_dep_list, false);
+}
 
+/* __kmpc_omp_taskwa

[PATCH] D139720: [clang][PPC] Checking Unknown Values Passed to -mcpu

2022-12-09 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 481739.
qiongsiwu1 added a comment.

Update to include a new test case against the unknown target error message. 
Thanks for the suggestion @amyk !


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

https://reviews.llvm.org/D139720

Files:
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/lib/Driver/ToolChains/Arch/PPC.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/ppc-cpus.c

Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -5,6 +5,15 @@
 // RUN: %clang -### -c -target powerpc64 %s -mcpu=native 2>&1 | FileCheck --check-prefix=MCPU_NATIVE %s
 // MCPU_NATIVE-NOT: "-target-cpu" "native"
 
+/// Check that we are passing unknown mcpu options to the backend so an error
+/// can be triggered.
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=asdf1234 2>&1 | FileCheck --check-prefix=MCPU_UNKNOWN %s
+// MCPU_UNKNOWN: "-target-cpu" "asdf1234"
+
+/// Check for the unknown target error if an unknown mcpu option is used.
+// RUN: not %clang -c -target powerpc64 %s -mcpu=asdf1234 2>&1 | FileCheck --check-prefix=MCPU_ERR %s
+// MCPU_ERR: unknown target CPU 'asdf1234'
+
 // RUN: %clang -### -c -target powerpc64 %s -mcpu=7400 2>&1 | FileCheck --check-prefix=MCPU_7400 %s
 // MCPU_7400: "-target-cpu" "7400"
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -409,25 +409,9 @@
   case llvm::Triple::ppc:
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
-  case llvm::Triple::ppc64le: {
-std::string TargetCPUName = ppc::getPPCTargetCPU(Args);
-// LLVM may default to generating code for the native CPU,
-// but, like gcc, we default to a more generic option for
-// each architecture. (except on AIX)
-if (!TargetCPUName.empty())
-  return TargetCPUName;
-
-if (T.isOSAIX())
-  TargetCPUName = "pwr7";
-else if (T.getArch() == llvm::Triple::ppc64le)
-  TargetCPUName = "ppc64le";
-else if (T.getArch() == llvm::Triple::ppc64)
-  TargetCPUName = "ppc64";
-else
-  TargetCPUName = "ppc";
+  case llvm::Triple::ppc64le:
+return ppc::getPPCTargetCPU(Args, T);
 
-return TargetCPUName;
-  }
   case llvm::Triple::csky:
 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
   return A->getValue();
Index: clang/lib/Driver/ToolChains/Arch/PPC.h
===
--- clang/lib/Driver/ToolChains/Arch/PPC.h
+++ clang/lib/Driver/ToolChains/Arch/PPC.h
@@ -35,7 +35,8 @@
 
 FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
-std::string getPPCTargetCPU(const llvm::opt::ArgList &Args);
+std::string getPPCTargetCPU(const llvm::opt::ArgList &Args,
+const llvm::Triple &T);
 const char *getPPCAsmModeForCPU(StringRef Name);
 ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
 const llvm::opt::ArgList &Args);
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,74 +20,64 @@
 using namespace clang;
 using namespace llvm::opt;
 
+static std::string getPPCGenericTargetCPU(const llvm::Triple &T) {
+  // LLVM may default to generating code for the native CPU,
+  // but, like gcc, we default to a more generic option for
+  // each architecture. (except on AIX)
+  if (T.isOSAIX())
+return "pwr7";
+  else if (T.getArch() == llvm::Triple::ppc64le)
+return "ppc64le";
+  else if (T.getArch() == llvm::Triple::ppc64)
+return "ppc64";
+  else
+return "ppc";
+}
+
 /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
-std::string ppc::getPPCTargetCPU(const ArgList &Args) {
+std::string ppc::getPPCTargetCPU(const ArgList &Args, const llvm::Triple &T) {
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 
+if (CPUName == "generic")
+  return getPPCGenericTargetCPU(T);
+
 if (CPUName == "native") {
   std::string CPU = std::string(llvm::sys::getHostCPUName());
   if (!CPU.empty() && CPU != "generic")
 return CPU;
   else
-return "";
+return getPPCGenericTargetCPU(T);
 }
 
-return llvm::StringSwitch(CPUName)
-.Case("common", "generic")
-.Case("440", "440")
-.Case("440fp", "440")
-.Case("450", "450")
-.Case("601", "601")
-.Case("602", "602")
-.Case("603", "603")
-.Case("603e", "603e")
-.Case("603ev", "603ev")
-.Case("604", "604")
-.Case("604e", "604e")
-.Case("6

[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Headers/__clang_hip_math.h:145
 // BEGIN FLOAT
-#if defined(__cplusplus)
 __DEVICE__

Why not introduce __clang_hip_stdlib.h now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

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


[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 481738.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

Files:
  clang/lib/Headers/__clang_hip_math.h
  clang/test/Headers/Inputs/include/stdlib.h
  clang/test/Headers/amdgcn_openmp_device_math_c.c

Index: clang/test/Headers/amdgcn_openmp_device_math_c.c
===
--- /dev/null
+++ clang/test/Headers/amdgcn_openmp_device_math_c.c
@@ -0,0 +1,132 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]"
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -x c -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -D__OFFLOAD_ARCH_gfx90a__ -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -x c -fopenmp -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s --check-prefixes=CHECK
+// REQUIRES: amdgpu-registered-target
+
+#include 
+#include 
+
+void test_math_int(int x) {
+#pragma omp target
+  {
+int l1 = abs(x);
+  }
+}
+
+void test_math_long(long x) {
+#pragma omp target
+  {
+long l1 = labs(x);
+  }
+}
+
+void test_math_long_long(long long x) {
+#pragma omp target
+  {
+long long l1 = llabs(x);
+  }
+}
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_test_math_int_l10
+// CHECK-SAME: (i64 noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__SGN_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[L1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[X_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[X_ADDR]] to ptr
+// CHECK-NEXT:[[L1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[L1]] to ptr
+// CHECK-NEXT:store i64 [[X]], ptr [[X_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[X_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[RETVAL_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL_I]] to ptr
+// CHECK-NEXT:[[__X_ADDR_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[__X_ADDR_I]] to ptr
+// CHECK-NEXT:[[__SGN_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[__SGN_I]] to ptr
+// CHECK-NEXT:store i32 [[TMP1]], ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[SHR_I:%.*]] = ashr i32 [[TMP2]], 31
+// CHECK-NEXT:store i32 [[SHR_I]], ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[XOR_I:%.*]] = xor i32 [[TMP3]], [[TMP4]]
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[SUB_I:%.*]] = sub nsw i32 [[XOR_I]], [[TMP5]]
+// CHECK-NEXT:store i32 [[SUB_I]], ptr [[L1_ASCAST]], align 4
+// CHECK-NEXT:call void @__kmpc_target_deinit(ptr addrspacecast (ptr addrspace(1) @[[GLOB1]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:ret void
+// CHECK:   worker.exit:
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_test_math_long_l17
+// CHECK-SAME: (i64 noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[__X_ADDR_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[__SGN_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[L1:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[X_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[X_ADDR]] to ptr
+// CHECK-NEXT:[[L1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[L1]] to ptr
+// CHECK-NEXT:store i64 [[X]], ptr [[X_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_ta

[PATCH] D139450: Warn about unsupported ibmlongdouble

2022-12-09 Thread Tulio Magno Quites Machado Filho via Phabricator via cfe-commits
tuliom updated this revision to Diff 481730.
tuliom added a comment.

Fix the issues pointed by @nikic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139450

Files:
  clang/lib/Driver/ToolChains/PPCLinux.cpp
  clang/lib/Driver/ToolChains/PPCLinux.h
  clang/test/CMakeLists.txt
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/ppc-float-abi-warning.cpp
  clang/test/lit.site.cfg.py.in

Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -38,6 +38,7 @@
 config.clang_vendor_uti = "@CLANG_VENDOR_UTI@"
 config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
+config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
Index: clang/test/Driver/ppc-float-abi-warning.cpp
===
--- clang/test/Driver/ppc-float-abi-warning.cpp
+++ clang/test/Driver/ppc-float-abi-warning.cpp
@@ -7,12 +7,23 @@
 // RUN:  --dyld-prefix=%S/Inputs/powerpc64le-linux-gnu-tree/gcc-12 \
 // RUN:  -mabi=ieeelongdouble -stdlib=libstdc++ 2>&1 | \
 // RUN:  FileCheck %s --check-prefix=NOWARN
-// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s \
-// RUN:  -mabi=ieeelongdouble -stdlib=libc++ 2>&1 | FileCheck %s
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
+// RUN:  -stdlib=libc++ 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=NOWARN
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
+// RUN:  -mabi=ibmlongdouble -stdlib=libc++ -Wno-unsupported-abi 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=NOWARN
 // RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
 // RUN:  -mabi=ieeelongdouble -stdlib=libc++ -Wno-unsupported-abi 2>&1 | \
 // RUN:  FileCheck %s --check-prefix=NOWARN
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
+// RUN:  -mabi=%if ppc_linux_default_ieeelongdouble %{ieeelongdouble%} \
+// RUN:  %else %{ibmlongdouble%} -stdlib=libc++ 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=NOWARN
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
+// RUN:  -mabi=%if ppc_linux_default_ieeelongdouble %{ibmlongdouble%} \
+// RUN:  %else %{ieeelongdouble%} -stdlib=libc++ 2>&1 | FileCheck %s
 
-// CHECK: warning: float ABI 'ieeelongdouble' is not supported by current library
-// NOWARN-NOT: warning: float ABI 'ieeelongdouble' is not supported by current library
+// CHECK: warning: float ABI '{{.*}}' is not supported by current library
+// NOWARN-NOT: warning: float ABI '{{.*}}' is not supported by current library
 long double foo(long double x) { return x; }
Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -21,3 +21,6 @@
 
 if llvm_config.use_lld(required=False):
 config.available_features.add('lld')
+
+if config.ppc_linux_default_ieeelongdouble:
+  config.available_features.add('ppc_linux_default_ieeelongdouble')
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -15,6 +15,7 @@
   LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
   LLVM_ENABLE_THREADS
   LLVM_WITH_Z3
+  PPC_LINUX_DEFAULT_IEEELONGDOUBLE
   )
 
 configure_lit_site_cfg(
Index: clang/lib/Driver/ToolChains/PPCLinux.h
===
--- clang/lib/Driver/ToolChains/PPCLinux.h
+++ clang/lib/Driver/ToolChains/PPCLinux.h
@@ -27,6 +27,8 @@
 private:
   bool SupportIEEEFloat128(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args) const;
+  bool supportIBMLongDouble(const Driver &D,
+const llvm::opt::ArgList &Args) const;
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/PPCLinux.cpp
===
--- clang/lib/Driver/ToolChains/PPCLinux.cpp
+++ clang/lib/Driver/ToolChains/PPCLinux.cpp
@@ -49,7 +49,10 @@
 : Linux(D, Triple, Args) {
   if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
 StringRef ABIName = A->getValue();
-if (ABIName == "ieeelongdouble" && !SupportIEEEFloat128(D, Triple, Args))
+
+if ((ABIName == "ieeelongdouble" &&
+ !SupportIEEEFloat128(D, Triple, Args)) ||
+(ABIName == "ibmlongdouble" && !supportIBMLongDouble(D, Args)))
   D.Diag(diag::warn_drv_unsupported_float_abi_by_lib) << ABIName;
   }
 }
@@ -67,6 +70,18 @@
   Linux::AddClangSystemIncludeArgs(DriverArgs, CC1Args);
 }
 
+bool PPCLinuxToolChain::supportIBMLongDouble(
+const Driver &D, const llvm::opt::ArgList &Args) const 

[PATCH] D139632: [clang-cl] Ignore #pragma managed / #pragma unmanaged

2022-12-09 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

It still looks odd to me, but since the rest of the file has comments like that 
I am fine with it. But I think we should figure out if they are like that 
because some tool is parsing them or if it's just legacy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139632

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


[PATCH] D139741: [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2022-12-09 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev created this revision.
dzhidzhoev added reviewers: kjdyck, rjmccall, efriedma, majnemer, 
aaron.ballman, rsmith.
Herald added a project: All.
dzhidzhoev requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

RecordLayoutBuilder assumes the size of a potentially-overlapping field
with non-zero size as the size of the base subobject type corresponding
to the field type.
Make RecordLayoutBuilder to acknowledge that in order to avoid incorrect
padding insertion.

Without this patch, test fails on assertion

  Assertion failed: (Offset >= Size), function insertPadding, file 
CGRecordLayoutBuilder.cpp, line 802.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139741

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/no-unique-address-3.cpp

Index: clang/test/CodeGenCXX/no-unique-address-3.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/no-unique-address-3.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-obj -fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Empty (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Second
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   0:0-0 |   short A
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=2,
+// CHECK-NEXT: |  nvsize=1, nvalign=2]
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Foo
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second NZNoUnique
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   3 |   char B
+// CHECK-NEXT: | [sizeof=4, dsize=4, align=2,
+// CHECK-NEXT: |  nvsize=4, nvalign=2]
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class SecondEmpty (empty)
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=0, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Bar
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   1 |   class SecondEmpty ZNoUnique (empty)
+// CHECK-NEXT:   1 | class Empty (base) (empty)
+// CHECK-NEXT:   0 |   char C
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=2, nvalign=1]
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class IntFieldClass
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second Field
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   4 |   int C
+// CHECK-NEXT: | [sizeof=8, dsize=8, align=4,
+// CHECK-NEXT: |  nvsize=8, nvalign=4]
+
+class Empty {};
+
+class Second : Empty {
+  short A : 1;
+};
+
+class Foo : Empty {
+  [[no_unique_address]] Second NZNoUnique;
+  char B;
+};
+Foo I;
+
+class SecondEmpty: Empty {
+};
+class Bar : Empty {
+  [[no_unique_address]] SecondEmpty ZNoUnique;
+  char C;
+};
+Bar J;
+
+class IntFieldClass : Empty {
+  [[no_unique_address]] Second Field;
+  int C;
+};
+IntFieldClass K;
Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,9 +379,14 @@
   for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
   accumulateBitFields(Start, Field);
 } else if (!Field->isZeroSize(Context)) {
+  // Use base subobject layout for the potentially-overlapping field,
+  // as it is done in RecordLayoutBuilder
   Members.push_back(MemberInfo(
   bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-  getStorageType(*Field), *Field));
+  (Field->isPotentiallyOverlapping()
+   ? getStorageType(Field->getType()->getAsCXXRecordDecl())
+   : getStorageType(*Field)),
+  *Field));
   ++Field;
 } else {
   ++Field;
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1853,9 +1853,8 @@
 void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
 

[PATCH] D139632: [clang-cl] Ignore #pragma managed / #pragma unmanaged

2022-12-09 Thread Sylvain Audi via Phabricator via cfe-commits
saudi added a comment.

In D139632#3985341 , @thakis wrote:

> LG (except for thieta's nit.)
>
> Do you have commit permissions, or do you need someone to land this for you? 
> If the latter, which name and email should we use for landing it?

I have commit permissions, I can land it myself, thanks!

@thieta The comments formatting I used was copied from similar classes in that 
same `Pragma.cpp`file; could you re-check?
e.g. https://github.com/llvm-mirror/clang/blob/master/lib/Lex/Pragma.cpp#L1825


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139632

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


[PATCH] D139720: [clang][PPC] Checking Unknown Values Passed to -mcpu

2022-12-09 Thread Amy Kwan via Phabricator via cfe-commits
amyk added a comment.

It might be good to add a test case to illustrate the 'unknown target CPU' 
error that is issued as a result of this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139720

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


[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

2022-12-09 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir updated this revision to Diff 481732.
schittir added a comment.

Add `(Initializer && ` and assert to else branch per Tom's comments.


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

https://reviews.llvm.org/D139148

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5936,6 +5936,7 @@
   // We're at the end of the line for C: it's either a write-back conversion
   // or it's a C assignment. There's no need to check anything else.
   if (!S.getLangOpts().CPlusPlus) {
+assert(Initializer && "Intializer must be non-null");
 // If allowed, check whether this is an Objective-C writeback conversion.
 if (allowObjCWritebackConversion &&
 tryObjCWritebackConversion(S, *this, Entity, Initializer)) {
@@ -5962,7 +5963,8 @@
 if (Kind.getKind() == InitializationKind::IK_Direct ||
 (Kind.getKind() == InitializationKind::IK_Copy &&
  (Context.hasSameUnqualifiedType(SourceType, DestType) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType
+  (Initilializer &&
+   S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, 
DestType)
   TryConstructorInitialization(S, Entity, Kind, Args,
DestType, DestType, *this);
 // - Otherwise (i.e., for the remaining copy-initialization cases),
@@ -5971,9 +5973,11 @@
 //   used) to a derived class thereof are enumerated as described in
 //   13.3.1.4, and the best one is chosen through overload resolution
 //   (13.3).
-else
+else {
+  assert(Initializer && "Intializer must be non-null");
   TryUserDefinedConversion(S, DestType, Kind, Initializer, *this,
TopLevelOfInitList);
+}
 return;
   }
 
@@ -6022,6 +6026,7 @@
   //- Otherwise, if the source type is a (possibly cv-qualified) class
   //  type, conversion functions are considered.
   if (!SourceType.isNull() && SourceType->isRecordType()) {
+assert(Initializer && "Intializer must be non-null");
 // For a conversion to _Atomic(T) from either T or a class type derived
 // from T, initialize the T object then convert to _Atomic type.
 bool NeedAtomicConversion = false;


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5936,6 +5936,7 @@
   // We're at the end of the line for C: it's either a write-back conversion
   // or it's a C assignment. There's no need to check anything else.
   if (!S.getLangOpts().CPlusPlus) {
+assert(Initializer && "Intializer must be non-null");
 // If allowed, check whether this is an Objective-C writeback conversion.
 if (allowObjCWritebackConversion &&
 tryObjCWritebackConversion(S, *this, Entity, Initializer)) {
@@ -5962,7 +5963,8 @@
 if (Kind.getKind() == InitializationKind::IK_Direct ||
 (Kind.getKind() == InitializationKind::IK_Copy &&
  (Context.hasSameUnqualifiedType(SourceType, DestType) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType
+  (Initilializer &&
+   S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType)
   TryConstructorInitialization(S, Entity, Kind, Args,
DestType, DestType, *this);
 // - Otherwise (i.e., for the remaining copy-initialization cases),
@@ -5971,9 +5973,11 @@
 //   used) to a derived class thereof are enumerated as described in
 //   13.3.1.4, and the best one is chosen through overload resolution
 //   (13.3).
-else
+else {
+  assert(Initializer && "Intializer must be non-null");
   TryUserDefinedConversion(S, DestType, Kind, Initializer, *this,
TopLevelOfInitList);
+}
 return;
   }
 
@@ -6022,6 +6026,7 @@
   //- Otherwise, if the source type is a (possibly cv-qualified) class
   //  type, conversion functions are considered.
   if (!SourceType.isNull() && SourceType->isRecordType()) {
+assert(Initializer && "Intializer must be non-null");
 // For a conversion to _Atomic(T) from either T or a class type derived
 // from T, initialize the T object then convert to _Atomic type.
 bool NeedAtomicConversion = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139632: [clang-cl] Ignore #pragma managed / #pragma unmanaged

2022-12-09 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

LG (except for thieta's nit.)

Do you have commit permissions, or do you need someone to land this for you? If 
the latter, which name and email should we use for landing it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139632

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


[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

2022-12-09 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:5959
   if (DestType->isRecordType()) {
+assert(Initializer && "Intializer must be non-null");
 // - If the initialization is direct-initialization, or if it is

It looks like this assertion was triggered for both the Linux and Windows 
builds.

Since the `else` branch below unconditionally dereferences `Initializer`, I 
think the only way for `Initializer` to be null and for a crash not to occur is 
if the `then` branch is taken, but without `Initializer->getBeginLoc()` being 
evaluated due to short circuiting. I think we should do this:
1) Add a `Initializer &&` condition prior to the call to 
`S.IsDerivedFrom(Initializer->getBeginLoc(), ...)`. This will require yet more 
parenthesis for the conditional logic.
2) Add the assert to the `else` branch.


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

https://reviews.llvm.org/D139148

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


[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added a comment.

In D139723#3984846 , @jdoerfert wrote:

> I'm not 100% sure if this was excluded on purpose or not. FWIW, in C, these 
> functions are not defined in math.h 
> (https://en.cppreference.com/w/c/numeric/math/abs), but in C++ they are 
> (https://en.cppreference.com/w/cpp/numeric/math/abs).
>
> Once we enable libm_gpu it might not make a difference. For now, I'm OK with 
> this if it doesn't break peoples code.

This fixes the case where we have a C file with offloading OpenMP in it that 
calls these functions. I'm not sure I see another way to do this in the current 
setup but I'm open to other solutions if this one breaks things unexpectedly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

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


[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3386
+
+  if (!Result || CurPtr - StartPtr == (ptrdiff_t)(Buffer.size() + 4))
 StartPtr = CurPtr;

cor3ntin wrote:
> tahonermann wrote:
> > cor3ntin wrote:
> > > cor3ntin wrote:
> > > > tahonermann wrote:
> > > > > This is a bit of a tangent, but under what circumstances would 
> > > > > `CurPtr - StartPtr` not be equal to `Buffer.size() + 4`? Actually, 
> > > > > I'm not sure that +4 is correct. It looks like `StartPtr` is expected 
> > > > > to point to `N` at the beginning of the function, so the initial `\` 
> > > > > is not included in the range. If `N` isn't seen, the function returns 
> > > > > early. Likewise, if either of the `{` or `}` delimiters is not found, 
> > > > > the function returns early.
> > > > > 
> > > > > I think the goal of this code is to skip the `getAndAdvanceChar()` 
> > > > > machinery when the buffer is being claimed (no need to parse UCNs or 
> > > > > trigraphs in the character name), but it looks like, particularly 
> > > > > with this DR, that we might always be able to do that.
> > > > afaict, 4 is correct here because we are one past-the-end.
> > > > I do however agree that this whole pattern which is used a few times is 
> > > > probably unnecessary, i do think it would be good to investigate. Not 
> > > > in this patch though, imo
> > > I looked into it, I'm sure we could improve but not easily, 
> > > `getAndAdvanceChar` does set some flags on the token in the presence of 
> > > trigraphs/line splicing and we need those flags to be set, this is the 
> > > reason we do need to call that method.
> > > It's not super efficient but it's such an edge case... I'd rather not 
> > > touch that now
> > My concern is that, as is, the code always takes the `else` branch (except 
> > when `Result` is non-null). Assuming a buffer containing "X", the pointers 
> > are arranged as follows (where `$` is one past the end).
> >   \ N { X } $
> > |   |   `- CurPtr
> > |   `- Buffer
> > `- StartPtr
> > `CurPtr - StartPtr` is 4, but `Buffer.size() + 4` is 5 (`Buffer.size()` is 
> > 1 in this case).
> > 
> > I think there might be an easy test to see if this is working as intended. 
> > If it isn't, I would expect a diagnostic to be issued if trigraphs are 
> > enabled and the buffer contains a trigraph sequence. Something like:
> >   \N{LOTUS??>}
> I can try to add tests
> 
> > My concern is that, as is, the code always takes the else branch (except 
> > when Result is non-null). 
> Yes, the if branch sole purpose is to set some state in Result.
> 
> At the start of the function, StartPtr points to `\`
> And I'll leave a comment, maybe that will clear up future confusions
> 
> There may be a potential refactor here, which is to have `getAndAdvanceChar` 
> take a `bool & ShouldCleanupToken` parameter instead of a token so that we 
> don't have to do that dance, but it's a bit outside of the scope of this 
> patch...
> At the start of the function, StartPtr points to `\`

It doesn't look like it does. The first use of `StartPtr` is at line 3314 and 
it expects to read `N`:
  3314:   char C = getCharAndSize(StartPtr, CharSize);
  3315:   assert(C == 'N' && "expected \\N{...}");


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

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


[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 481722.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

Files:
  clang/lib/Headers/__clang_hip_math.h
  clang/test/Headers/Inputs/include/stdlib.h
  clang/test/Headers/amdgcn_openmp_device_math_c.c

Index: clang/test/Headers/amdgcn_openmp_device_math_c.c
===
--- /dev/null
+++ clang/test/Headers/amdgcn_openmp_device_math_c.c
@@ -0,0 +1,132 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -x c -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -D__OFFLOAD_ARCH_gfx90a__ -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -x c -fopenmp -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s --check-prefixes=CHECK
+// REQUIRES: amdgpu-registered-target
+
+#include 
+#include 
+
+void test_math_int(int x) {
+#pragma omp target
+  {
+int l1 = abs(x);
+  }
+}
+
+void test_math_long(long x) {
+#pragma omp target
+  {
+long l1 = labs(x);
+  }
+}
+
+void test_math_long_long(long long x) {
+#pragma omp target
+  {
+long long l1 = llabs(x);
+  }
+}
+// CHECK-LABEL: define {{[^@]+}}@__omp_offloading_802_abeeaa0_test_math_int_l10
+// CHECK-SAME: (i64 noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__SGN_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[L1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[X_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[X_ADDR]] to ptr
+// CHECK-NEXT:[[L1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[L1]] to ptr
+// CHECK-NEXT:store i64 [[X]], ptr [[X_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[X_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[RETVAL_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL_I]] to ptr
+// CHECK-NEXT:[[__X_ADDR_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[__X_ADDR_I]] to ptr
+// CHECK-NEXT:[[__SGN_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[__SGN_I]] to ptr
+// CHECK-NEXT:store i32 [[TMP1]], ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[SHR_I:%.*]] = ashr i32 [[TMP2]], 31
+// CHECK-NEXT:store i32 [[SHR_I]], ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[XOR_I:%.*]] = xor i32 [[TMP3]], [[TMP4]]
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[SUB_I:%.*]] = sub nsw i32 [[XOR_I]], [[TMP5]]
+// CHECK-NEXT:store i32 [[SUB_I]], ptr [[L1_ASCAST]], align 4
+// CHECK-NEXT:call void @__kmpc_target_deinit(ptr addrspacecast (ptr addrspace(1) @[[GLOB1]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:ret void
+// CHECK:   worker.exit:
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@__omp_offloading_802_abeeaa0_test_math_long_l17
+// CHECK-SAME: (i64 noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[__X_ADDR_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[__SGN_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[L1:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[X_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[X_ADDR]] to ptr
+// CHECK-NEXT:[[L1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[L1]] to ptr
+// CHECK-NEXT:store i64 [[X]], ptr [[X_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1]] to ptr), i8 1, i1 true, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]

[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

2022-12-09 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: jkorous, NoQ, t-rasmud, malavikasamak, 
aaron.ballman, xazax.hun, gribozavr.
Herald added a subscriber: rnkovacs.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use clang fix-its to transform declarations of local variables, which are used 
for buffer access , to be of `std::span` type.

We placed a few limitations to keep the solution simple:

1. it only transforms local variable declarations (no parameter declaration)
2. it only considers single level pointers, i.e., pointers of type `T *` 
regardless of whether `T` is again a pointer.
3. it only transforms to `std::span` types (no `std::array`, or 
`std::span::iterator`, or ...)
4. it can only transform a `VarDecl` that belongs to a `DeclStmt` whose has a 
single child.

One of the purposes of keeping this patch simple enough is to first evaluate if 
fix-it is an appropriate approach to do the transformation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139737

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -69,19 +69,19 @@
 
   auto ap1 = a; // expected-warning{{variable 'ap1' participates in unchecked buffer operations}}
 
-  foo(ap1[1]);  // expected-warning{{unchecked operation on raw buffer in expression}}
+  foo(ap1[1]);
 
   auto ap2 = p; // expected-warning{{variable 'ap2' participates in unchecked buffer operations}}
 
-  foo(ap2[1]);  // expected-warning{{unchecked operation on raw buffer in expression}}
+  foo(ap2[1]);
 
-  auto ap3 = pp;
+  auto ap3 = pp; // expected-warning{{variable 'ap3' participates in unchecked buffer operations}}
 
-  foo(ap3[1][1]); // expected-warning2{{unchecked operation on raw buffer in expression}}
+  foo(ap3[1][1]); // expected-warning{{unchecked operation on raw buffer in expression}}
 
   auto ap4 = *pp; // expected-warning{{variable 'ap4' participates in unchecked buffer operations}}
 
-  foo(ap4[1]);  // expected-warning{{unchecked operation on raw buffer in expression}}
+  foo(ap4[1]);
 }
 
 void testQualifiedParameters(const int * p, const int * const q,
Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
@@ -3,16 +3,71 @@
 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fixit %t.cpp
 // RUN: grep -v CHECK %t.cpp | FileCheck %s
 
+void foo(...);
+typedef int * Int_ptr_t;
+typedef int Int_t;
+
 void local_array_subscript_simple() {
-// CHECK: std::span p = new int[10];
+// CHECK: std::span p{new int [10], 10};
 // CHECK: p[5] = 5;
   int *p = new int[10]; // expected-warning{{variable 'p' participates in unchecked buffer operations}}
   p[5] = 5;
+
+// CHECK: std::span q{new int [10], 10};
+// CHECK: std::span x{new int [10], 10};
+// CHECK: std::span y{new int, 1};
+// CHECK: std::span z{new int [10], 10};
+// CHECK: std::span w{new Int_t [10], 10};
+// CHECK: foo(q[5], x[5], y[5], z[5], w[5]);
+  const int *q = new int[10]; // expected-warning{{variable 'q' participates in unchecked buffer operations}}
+  Int_ptr_t x = new int[10];  // expected-warning{{variable 'x' participates in unchecked buffer operations}}
+  Int_ptr_t y = new int;  // expected-warning{{variable 'y' participates in unchecked buffer operations}}
+  Int_t * z = new int[10];// expected-warning{{variable 'z' participates in unchecked buffer operations}}
+  Int_t * w = new Int_t[10];  // expected-warning{{variable 'w' participates in unchecked buffer operations}}
+  foo(q[5], x[5], y[5], z[5], w[5]);
+  // y[5] will crash after being span
 }
 
 void local_array_subscript_auto() {
-// CHECK: std::span p = new int[10];
+// CHECK: std::span p{new int [10], 10};
 // CHECK: p[5] = 5;
   auto p = new int[10]; // expected-warning{{variable 'p' participates in unchecked buffer operations}}
   p[5] = 5;
 }
+
+void local_array_subscript_variable_extent() {
+  int n = 10;
+// CHECK: std::span p{new int [n], n};
+// CHECK: std::span q{new int [n++], ...};
+// CHECK: foo(p[5], q[5]);
+  int *p = new int[n]; // expected-warning{{variable 'p' participates in unchecked buffer operations}}
+  // If the extent expression does not have a constant value, we cannot fill the extent for users...
+  int *q = new int[n++]; // expected-warning{{variable 'q' participates in unchecked buffer operations}}
+  foo(p[5], q[5]);
+}
+
+
+void local_ptr_to_array() {
+  int n = 10;
+  int 

[PATCH] D138675: [flang] Add -ffast-math and -Ofast

2022-12-09 Thread Tom Eccles via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7b6660243d1: [flang] Add -ffast-math and -Ofast (authored 
by tblah).
Herald added projects: clang, Flang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138675

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/docs/FlangDriver.md
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/fast_math.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Lower/fast-math-arithmetic.f90

Index: flang/test/Lower/fast-math-arithmetic.f90
===
--- flang/test/Lower/fast-math-arithmetic.f90
+++ flang/test/Lower/fast-math-arithmetic.f90
@@ -6,6 +6,7 @@
 ! RUN: %flang_fc1 -emit-fir -mreassociate -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=REASSOC,ALL %s
 ! RUN: %flang_fc1 -emit-fir -freciprocal-math -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=ARCP,ALL %s
 ! RUN: %flang_fc1 -emit-fir -ffp-contract=fast -menable-no-infs -menable-no-nans -fapprox-func -fno-signed-zeros -mreassociate -freciprocal-math %s -o - 2>&1 | FileCheck --check-prefixes=FAST,ALL %s
+! RUN: %flang_fc1 -emit-fir -ffast-math %s -o - 2>&1 | FileCheck --check-prefixes=FAST,ALL %s
 
 ! ALL-LABEL: func.func @_QPtest
 subroutine test(x)
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -9,7 +9,6 @@
 ! RUN: -flarge-sizes \
 ! RUN: -fconvert=little-endian \
 ! RUN: -ffp-contract=fast \
-! RUN: -fno-honor-infinities \
 ! RUN: -fno-honor-nans \
 ! RUN: -fapprox-func \
 ! RUN: -fno-signed-zeros \
@@ -27,7 +26,6 @@
 ! CHECK: "-fdefault-real-8"
 ! CHECK: "-flarge-sizes"
 ! CHECK: "-ffp-contract=fast"
-! CHECK: "-menable-no-infs"
 ! CHECK: "-menable-no-nans"
 ! CHECK: "-fapprox-func"
 ! CHECK: "-fno-signed-zeros"
Index: flang/test/Driver/fast_math.f90
===
--- /dev/null
+++ flang/test/Driver/fast_math.f90
@@ -0,0 +1,65 @@
+! Test for correct forwarding of fast-math flags from the compiler driver to the
+! frontend driver
+
+! -Ofast => -ffast-math -O3
+! RUN: %flang -Ofast -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-OFAST %s
+! CHECK-OFAST: -fc1
+! CHECK-OFAST-SAME: -ffast-math
+! CHECK-OFAST-SAME: -O3
+
+! TODO: update once -fstack-arays is added
+! RUN: %flang -fstack-arrays -fsyntax-only %s -o %t 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-STACK-ARRAYS %s
+! CHECK-STACK-ARRAYS: warning: argument unused during compilation: '-fstack-arrays'
+
+! -Ofast -fno-fast-math => -O3
+! RUN: %flang -Ofast -fno-fast-math -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-OFAST-NO-FAST %s
+! CHECK-OFAST-NO-FAST: -fc1
+! CHECK-OFAST-NO-FAST-NOT: -ffast-math
+! CHECK-OFAST-NO-FAST-SAME: -O3
+
+! -ffast-math => -ffast-math
+! RUN: %flang -ffast-math -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-FFAST %s
+! CHECK-FFAST: -fc1
+! CHECK-FFAST-SAME: -ffast-math
+
+! (component flags) => -ffast-math
+! RUN: %flang -fsyntax-only -### %s -o %t \
+! RUN: -fno-honor-infinities \
+! RUN: -fno-honor-nans \
+! RUN: -fassociative-math \
+! RUN: -freciprocal-math \
+! RUN: -fapprox-func \
+! RUN: -fno-signed-zeros \
+! RUN: -ffp-contract=fast \
+! RUN: 2>&1 | FileCheck --check-prefix=CHECK-FROM-COMPS %s
+! CHECK-FROM-COMPS: -fc1
+! CHECK-FROM-COMPS-SAME: -ffast-math
+
+! -ffast-math (followed by an alteration) => (component flags)
+! RUN: %flang -ffast-math -fhonor-infinities -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-TO-COMPS %s
+! CHECK-TO-COMPS: -fc1
+! CHECK-TO-COMPS-SAME: -ffp-contract=fast
+! CHECK-TO-COMPS-SAME: -menable-no-nans
+! CHECK-TO-COMPS-SAME: -fapprox-func
+! CHECK-TO-COMPS-SAME: -fno-signed-zeros
+! CHECK-TO-COMPS-SAME: -mreassociate
+! CHECK-TO-COMPS-SAME: -freciprocal-math
+
+! Check that -fno-fast-math doesn't clobber -ffp-contract
+! RUN: %flang -ffp-contract=off -fno-fast-math -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-CONTRACT %s
+! CHECK-CONTRACT: -fc1
+! CHECK-CONTRACT-SAME: -ffp-contract=off
+
+! Check that -ffast-math causes us to link to crtfastmath.o
+! UNSUPPORTED: system-windows
+! RUN: %flang -ffast-math -### %s -o %t 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-CRT %s
+! CHECK-CRT: crtbeginS.o
+! CHECK-CRT-SAME: crtfastmath.o
+! CHECK-CRT-SAME: crtendS.o
Index: flang/test/Driver/driver-help.f90
===

[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3378-3379
 
-  if (LooseMatch)
+  // If no diagnostic has been emitted yet we do not want to recover here
+  // to make sure this function will be called again and a diagnostic emitted 
then.
+  if (LooseMatch && Diagnose)

tahonermann wrote:
> cor3ntin wrote:
> > tahonermann wrote:
> > > I'm having a hard time understanding what this comment is trying to 
> > > convey. The comment response to Aaron was much more helpful to me. How 
> > > about this suggested edit?
> > It's not that a diagnostic would be emitted twice, is that it would not be 
> > emitted at all.
> > By recovering - ie returning a loose match - we prevent the function to be 
> > called again on the same buffer.
> > So if during the first call Diagnose is false (because we were called from 
> > a try function), then the compilation will continue assuming we were in 
> > fact able to parse an identifier and never informs us of an invalid name.
> More evidence of the difficulty I'm having appreciating this comment :)
> 
> Does this sound right?
>   // Only map a loose match to a code point when in a diagnosing state.
>   // If a mapped code point were to be returned in a non-diagnosing state,
>   // token caching would prevent the opportunity to issue a diagnostic when
>   // the token is later used.
> 
> Tangent: It might be worth renaming one of `Res` and `Result`. I keep getting 
> confused due to the similar names. Perhaps rename `Result` to `Token` or 
> `ResultToken`?
I'm not sure caching is exactly right.
There are tentative parses, that should not give false positive answers. I'll 
try to message a better comment



Comment at: clang/lib/Lex/Lexer.cpp:3386
+
+  if (!Result || CurPtr - StartPtr == (ptrdiff_t)(Buffer.size() + 4))
 StartPtr = CurPtr;

tahonermann wrote:
> cor3ntin wrote:
> > cor3ntin wrote:
> > > tahonermann wrote:
> > > > This is a bit of a tangent, but under what circumstances would `CurPtr 
> > > > - StartPtr` not be equal to `Buffer.size() + 4`? Actually, I'm not sure 
> > > > that +4 is correct. It looks like `StartPtr` is expected to point to 
> > > > `N` at the beginning of the function, so the initial `\` is not 
> > > > included in the range. If `N` isn't seen, the function returns early. 
> > > > Likewise, if either of the `{` or `}` delimiters is not found, the 
> > > > function returns early.
> > > > 
> > > > I think the goal of this code is to skip the `getAndAdvanceChar()` 
> > > > machinery when the buffer is being claimed (no need to parse UCNs or 
> > > > trigraphs in the character name), but it looks like, particularly with 
> > > > this DR, that we might always be able to do that.
> > > afaict, 4 is correct here because we are one past-the-end.
> > > I do however agree that this whole pattern which is used a few times is 
> > > probably unnecessary, i do think it would be good to investigate. Not in 
> > > this patch though, imo
> > I looked into it, I'm sure we could improve but not easily, 
> > `getAndAdvanceChar` does set some flags on the token in the presence of 
> > trigraphs/line splicing and we need those flags to be set, this is the 
> > reason we do need to call that method.
> > It's not super efficient but it's such an edge case... I'd rather not touch 
> > that now
> My concern is that, as is, the code always takes the `else` branch (except 
> when `Result` is non-null). Assuming a buffer containing "X", the pointers 
> are arranged as follows (where `$` is one past the end).
>   \ N { X } $
> |   |   `- CurPtr
> |   `- Buffer
> `- StartPtr
> `CurPtr - StartPtr` is 4, but `Buffer.size() + 4` is 5 (`Buffer.size()` is 1 
> in this case).
> 
> I think there might be an easy test to see if this is working as intended. If 
> it isn't, I would expect a diagnostic to be issued if trigraphs are enabled 
> and the buffer contains a trigraph sequence. Something like:
>   \N{LOTUS??>}
I can try to add tests

> My concern is that, as is, the code always takes the else branch (except when 
> Result is non-null). 
Yes, the if branch sole purpose is to set some state in Result.

At the start of the function, StartPtr points to `\`
And I'll leave a comment, maybe that will clear up future confusions

There may be a potential refactor here, which is to have `getAndAdvanceChar` 
take a `bool & ShouldCleanupToken` parameter instead of a token so that we 
don't have to do that dance, but it's a bit outside of the scope of this 
patch...



Comment at: clang/test/Preprocessor/ucn-pp-identifier.c:141
+// expected-warning@-2 {{incomplete delimited universal character name}}
 
 #ifdef TRIGRAPHS

tahonermann wrote:
> How about adding a test for an escaped new line? I think this is currently UB 
> according to the standard ([[ http://eel.is/c++draft/lex.phases#1.2 | 
> (lex.phases)p2 ]]), but I believe you are trying to change that 

[clang] e7b6660 - [flang] Add -ffast-math and -Ofast

2022-12-09 Thread Tom Eccles via cfe-commits

Author: Tom Eccles
Date: 2022-12-09T19:55:58Z
New Revision: e7b6660243d1a4548f7aaac992b777ef0f0ba5b7

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

LOG: [flang] Add -ffast-math and -Ofast

clang -cc1 accepts -Ofast. I did not add it to flang -fc1 because this
seems redundant because the compiler driver will always resolve -Ofast
into -O3 -ffast-math (I added a test for this).

-menable-infs is removed from the frontend-forwarding test because if
all of the fast-math component flags are present, these will be resolved
into the fast-math flag. Instead -menable-infs is tested in the
fast-math test.

Specifying -ffast-math to the compiler driver causes linker invocations
to include crtfastmath.o.

RFC: https://discourse.llvm.org/t/rfc-the-meaning-of-ofast/66554

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

Added: 
flang/test/Driver/fast_math.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/docs/FlangDriver.md
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/frontend-forwarding.f90
flang/test/Lower/fast-math-arithmetic.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fd0ca5f94a515..ba2010e743459 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -741,7 +741,7 @@ def ObjC : Flag<["-"], "ObjC">, Flags<[NoXarchOption]>,
   HelpText<"Treat source input files as Objective-C inputs">;
 def O : Joined<["-"], "O">, Group, Flags<[CC1Option,FC1Option]>;
 def O_flag : Flag<["-"], "O">, Flags<[CC1Option,FC1Option]>, Alias, 
AliasArgs<["1"]>;
-def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option]>;
+def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option, 
FlangOption]>;
 def P : Flag<["-"], "P">, Flags<[CC1Option,FlangOption,FC1Option]>, 
Group,
   HelpText<"Disable linemarker output in -E mode">,
   MarshallingInfoNegativeFlag>;
@@ -1603,7 +1603,7 @@ def ffp_exception_behavior_EQ : Joined<["-"], 
"ffp-exception-behavior=">, Group<
   MarshallingInfoEnum, "FPE_Default">;
 defm fast_math : BoolFOption<"fast-math",
   LangOpts<"FastMath">, DefaultFalse,
-  PosFlag,
   NegFlag>;
 defm math_errno : BoolFOption<"math-errno",

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index b2b08f960842e..4ee046be9ea97 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -176,12 +176,43 @@ static void addFloatingPointOptions(const Driver &D, 
const ArgList &Args,
 case options::OPT_fno_reciprocal_math:
   ReciprocalMath = false;
   break;
+case options::OPT_Ofast:
+  [[fallthrough]];
+case options::OPT_ffast_math:
+  HonorINFs = false;
+  HonorNaNs = false;
+  AssociativeMath = true;
+  ReciprocalMath = true;
+  ApproxFunc = true;
+  SignedZeros = false;
+  FPContract = "fast";
+  break;
+case options::OPT_fno_fast_math:
+  HonorINFs = true;
+  HonorNaNs = true;
+  AssociativeMath = false;
+  ReciprocalMath = false;
+  ApproxFunc = false;
+  SignedZeros = true;
+  // -fno-fast-math should undo -ffast-math so I return FPContract to the
+  // default. It is important to check it is "fast" (the default) so that
+  // --ffp-contract=off -fno-fast-math --> -ffp-contract=off
+  if (FPContract == "fast")
+FPContract = "";
+  break;
 }
 
 // If we handled this option claim it
 A->claim();
   }
 
+  if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
+  ApproxFunc && !SignedZeros &&
+  (FPContract == "fast" || FPContract == "")) {
+CmdArgs.push_back("-ffast-math");
+return;
+  }
+
   if (!FPContract.empty())
 CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + FPContract));
 
@@ -295,6 +326,8 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 if (A->getOption().matches(options::OPT_O4)) {
   CmdArgs.push_back("-O3");
   D.Diag(diag::warn_O4_is_O3);
+} else if (A->getOption().matches(options::OPT_Ofast)) {
+  CmdArgs.push_back("-O3");
 } else {
   A->render(Args, CmdArgs);
 }

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index 7e182b75d477e..d3db110565f42 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -544,3 +544,56 @@ into `flang-new` as built-in middle-end passes.
 See the
 
[`WritingAnLLVMNewPMPass`](https://llvm.org/docs/WritingAnLLVMNewPMPass.html#id9)
 documentation for more details.
+
+## Ofast and Fast Math
+`-Ofast` in Flang means `-O3 -ffast-math`. `-fstack-arrays` 

[PATCH] D137944: [ObjC][ARC] Teach the OptimizeSequences step of ObjCARCOpts about WinEH funclet tokens

2022-12-09 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp:767
+const ColorVector &CV = BlockColors.find(BB)->second;
+assert(CV.size() == 1 && "non-unique color for block!");
+BasicBlock *EHPadBB = CV.front();

sgraenitz wrote:
> rnk wrote:
> > I don't think the verifier changes you made guarantee this. I would 
> > consider strengthening this to `report_fatal_error`, since valid IR 
> > transforms can probably reach this code.
> Right, I guess the Verifier change is correct and this should change to work 
> for multi-color BBs?
> ```
>   assert(CV.size() > 0 && "Uncolored block");
>   for (BasicBlock *EHPadBB : CV)
> if (auto *EHPad = 
> dyn_cast(ColorFirstBB->getFirstNonPHI())) {
>   OpBundles.emplace_back("funclet", EHPad);
>   break;
> }
> ```
> 
> There is no test that covers this case, but it appears that the unique color 
> invariant only holds **after** WinEHPrepare. [The assertion 
> here](https://github.com/llvm/llvm-project/blob/release/15.x/llvm/lib/CodeGen/WinEHPrepare.cpp#L185)
>  seems to imply it:
> ```
> assert(BBColors.size() == 1 && "multi-color BB not removed by preparation");
> ```
> 
> Since it would be equivalent to the Verifier check, I'd stick with the 
> assertion and not report a fatal error.
Is the assertion `assert(CV.size() == 1 && "non-unique color for block!");` in 
`CloneCallInstForBB` incorrect too?



Comment at: llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp:2040-2041
+  DenseMap BlockColors;
+  if (F.hasPersonalityFn() &&
+  isScopedEHPersonality(classifyEHPersonality(F.getPersonalityFn(
+BlockColors = colorEHFunclets(F);

sgraenitz wrote:
> rnk wrote:
> > I think this code snippet probably deserves a Function helper, 
> > `F->hasScopedEHPersonality()`. Another part of me thinks we should cache 
> > the personality enum similar to the way we cache intrinsic ids, but I 
> > wouldn't want to increase Function memory usage, so that seems premature. 
> > "No action required", I guess.
> It doesn't really fit the the scope of this patch but I am happy to add the 
> helper function in a follow-up (for now without personality enum caching).
`OptimizeIndividualCall` calls `colorEHFunclets` too. Is it possible to just 
call it once? Or we don't care because it's not expensive?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137944

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


[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

2022-12-09 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:3870-3872
+}
+if (const ASTTemplateArgumentListInfo *Info = VTSD->getTemplateArgsInfo())
+  EndLoc = Info->getRAngleLoc();

If I understand correctly we either have a 
`VarTemplatePartialSpecializationDecl` or `ASTTemplateArgumentListInfo ` so we 
should use an `else if` and if we do then we should add a brace to [make the 
else if consistent with the 
else](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139705

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-09 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss accepted this revision.
danielkiss added a comment.
This revision is now accepted and ready to land.

just small comment, thanks @ilinpv
LGTM, just let others to chime in.




Comment at: clang/lib/Basic/Targets/AArch64.cpp:652
+  // AARCH64_ARCH_EXT_NAME feature with top priority must be taken.
+  return multiVersionSortPriority("sme2");
+}

wondering if we could use `FEAT_MAX` (or similar) here to avoid error as add 
features later. maybe a comment in `AArch64TargetParser.def` is the solution.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:771-790
+  HasRDM = false;
+  HasDIT = false;
+  HasCCPP = false;
+  HasCCDP = false;
+  HasFRInt3264 = false;
+  HasFlagM = false;
+  HasAlternativeNZCV = false;

Please note the initialisation moved, see D139622. 
Sorry , but hopefully an easy rebase.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:1010-1011
+
+  if (HasNoNeon)
+FPU &= ~NeonMode;
+  if (HasNoSVE)

maybe we need do disable SVE too here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D138263: [clang-format] Supress aligning of trailing namespace comments

2022-12-09 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks planned changes to this revision.
HazardyKnusperkeks added a comment.

I'll wait for the revert and then look how to go forth.


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

https://reviews.llvm.org/D138263

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


[PATCH] D139257: [clang-format] Link the braces of a block in UnwrappedLineParser

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

In D139257#3983332 , @owenpan wrote:

> I have second thoughts about linking block braces in `UnwrappedLineParser`. 
> Consider the following example:
>
>   #if A
>   while (a) { // Linked to the r_brace below
>   #else
>   while(b) { // Also linked to the r_brace below
>   #endif
> foo();
>   }  // Linked to the l_brace of while(b) above
>
> The `l_brace` of `while (a)` is still linked  to the `r_brace` that has been 
> re-linked to another `l_bace`.
>
> Because `MatchingParen` will be reset in the annotator anyway, linking it for 
> block braces in `UnwrappedLineParser` has little or no value. I will revert 
> this patch if no one objects.

I don't like it, but that seems to be the reasonable approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139257

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


[clang] ef783af - Move Clang's per-suite test targets into a folder

2022-12-09 Thread Chris B via cfe-commits

Author: Chris Bieneman
Date: 2022-12-09T13:44:38-06:00
New Revision: ef783af0b9d299e0912a17f4841f74fae4352fee

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

LOG: Move Clang's per-suite test targets into a folder

Putting these under a folder allows the CMake integraiton for IDEs to
sort the per-suite targets under a folder nested under the clang tests.

Added: 


Modified: 
clang/test/CMakeLists.txt

Removed: 




diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 09394a0f7f73..bd325285636e 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -173,6 +173,7 @@ set_target_properties(check-clang PROPERTIES FOLDER "Clang 
tests")
 add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR}
   PARAMS ${CLANG_TEST_PARAMS}
   DEPENDS ${CLANG_TEST_DEPS}
+  FOLDER "Clang tests/Suites"
 )
 
 # Add a legacy target spelling: clang-test



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


[clang] d16c590 - Resolve possible test failure on Windows

2022-12-09 Thread Chris B via cfe-commits

Author: Chris Bieneman
Date: 2022-12-09T13:43:52-06:00
New Revision: d16c59013056f1bf8844ded8faeb0cf01b1c3613

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

LOG: Resolve possible test failure on Windows

If dr0xx.c's timestamp is newer than dr324.c the preprocessor will issue
an unexpected diagnostic in dr324.c. To prevent this diagnostic we can
have dr324.c run touch against itself to force its timestamp to be new.

Added: 


Modified: 
clang/test/C/drs/dr324.c

Removed: 




diff  --git a/clang/test/C/drs/dr324.c b/clang/test/C/drs/dr324.c
index 9d5264017b3db..2d75853e5af7c 100644
--- a/clang/test/C/drs/dr324.c
+++ b/clang/test/C/drs/dr324.c
@@ -1,4 +1,5 @@
-/* RUN: %clang_cc1 -std=c89 -fsyntax-only -fms-extensions -pedantic -verify %s
+/* RUN: touch %s
+   RUN: %clang_cc1 -std=c89 -fsyntax-only -fms-extensions -pedantic -verify %s
RUN: %clang_cc1 -std=c99 -fsyntax-only -fms-extensions -pedantic -verify %s
RUN: %clang_cc1 -std=c11 -fsyntax-only -fms-extensions -pedantic -verify %s
RUN: %clang_cc1 -std=c17 -fsyntax-only -fms-extensions -pedantic -verify %s



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


[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3378-3379
 
-  if (LooseMatch)
+  // If no diagnostic has been emitted yet we do not want to recover here
+  // to make sure this function will be called again and a diagnostic emitted 
then.
+  if (LooseMatch && Diagnose)

cor3ntin wrote:
> tahonermann wrote:
> > I'm having a hard time understanding what this comment is trying to convey. 
> > The comment response to Aaron was much more helpful to me. How about this 
> > suggested edit?
> It's not that a diagnostic would be emitted twice, is that it would not be 
> emitted at all.
> By recovering - ie returning a loose match - we prevent the function to be 
> called again on the same buffer.
> So if during the first call Diagnose is false (because we were called from a 
> try function), then the compilation will continue assuming we were in 
> fact able to parse an identifier and never informs us of an invalid name.
More evidence of the difficulty I'm having appreciating this comment :)

Does this sound right?
  // Only map a loose match to a code point when in a diagnosing state.
  // If a mapped code point were to be returned in a non-diagnosing state,
  // token caching would prevent the opportunity to issue a diagnostic when
  // the token is later used.

Tangent: It might be worth renaming one of `Res` and `Result`. I keep getting 
confused due to the similar names. Perhaps rename `Result` to `Token` or 
`ResultToken`?



Comment at: clang/lib/Lex/Lexer.cpp:3386
+
+  if (!Result || CurPtr - StartPtr == (ptrdiff_t)(Buffer.size() + 4))
 StartPtr = CurPtr;

cor3ntin wrote:
> cor3ntin wrote:
> > tahonermann wrote:
> > > This is a bit of a tangent, but under what circumstances would `CurPtr - 
> > > StartPtr` not be equal to `Buffer.size() + 4`? Actually, I'm not sure 
> > > that +4 is correct. It looks like `StartPtr` is expected to point to `N` 
> > > at the beginning of the function, so the initial `\` is not included in 
> > > the range. If `N` isn't seen, the function returns early. Likewise, if 
> > > either of the `{` or `}` delimiters is not found, the function returns 
> > > early.
> > > 
> > > I think the goal of this code is to skip the `getAndAdvanceChar()` 
> > > machinery when the buffer is being claimed (no need to parse UCNs or 
> > > trigraphs in the character name), but it looks like, particularly with 
> > > this DR, that we might always be able to do that.
> > afaict, 4 is correct here because we are one past-the-end.
> > I do however agree that this whole pattern which is used a few times is 
> > probably unnecessary, i do think it would be good to investigate. Not in 
> > this patch though, imo
> I looked into it, I'm sure we could improve but not easily, 
> `getAndAdvanceChar` does set some flags on the token in the presence of 
> trigraphs/line splicing and we need those flags to be set, this is the reason 
> we do need to call that method.
> It's not super efficient but it's such an edge case... I'd rather not touch 
> that now
My concern is that, as is, the code always takes the `else` branch (except when 
`Result` is non-null). Assuming a buffer containing "X", the pointers are 
arranged as follows (where `$` is one past the end).
  \ N { X } $
|   |   `- CurPtr
|   `- Buffer
`- StartPtr
`CurPtr - StartPtr` is 4, but `Buffer.size() + 4` is 5 (`Buffer.size()` is 1 in 
this case).

I think there might be an easy test to see if this is working as intended. If 
it isn't, I would expect a diagnostic to be issued if trigraphs are enabled and 
the buffer contains a trigraph sequence. Something like:
  \N{LOTUS??>}



Comment at: clang/test/Preprocessor/ucn-pp-identifier.c:141
+// expected-warning@-2 {{incomplete delimited universal character name}}
 
 #ifdef TRIGRAPHS

How about adding a test for an escaped new line? I think this is currently UB 
according to the standard ([[ http://eel.is/c++draft/lex.phases#1.2 | 
(lex.phases)p2 ]]), but I believe you are trying to change that with [[ 
https://wg21.link/p2621 | P2621 ]].
  int \N{\
  LATIN CAPITAL LETTER A WITH GRAVE};


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

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


[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2022-12-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Could we elaborate on the benefits, please. Now we support two versions?

Why is this helpful:

> DeviceRTL uses rocm-device-libs instead of directly calling amdgcn builtins 
> for the functions which are affected by cov5.




Comment at: openmp/libomptarget/DeviceRTL/src/State.cpp:81
+#endif
+} // extern "C"
+

Why do we need the "external..." stuff anyway?



Comment at: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp:2233
+  }
+}
+

What is this all about?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

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


[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2022-12-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7085
   if (Triple.isAMDGPU()) {
-handleAMDGPUCodeObjectVersionOptions(D, Args, CmdArgs);
+handleAMDGPUCodeObjectVersionOptions(D, C.getArgs(), CmdArgs,
+ /*IsCC1As=*/true);

Any reason you need the original args? This will bypass the driver translation, 
which should not in normal cases.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7086
+handleAMDGPUCodeObjectVersionOptions(D, C.getArgs(), CmdArgs,
+ /*IsCC1As=*/true);
 

clang -cc1 needs this to be default value false to emit code object version 
module flag


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

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


[PATCH] D137337: Replace LLVM_LIBDIR_SUFFIX by CMAKE_INSTALL_LIBDIR

2022-12-09 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: bolt/lib/RuntimeLibs/RuntimeLibrary.cpp:32
   SmallString<128> LibPath = llvm::sys::path::parent_path(Dir);
-  llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
+  llvm::sys::path::append(LibPath, CMAKE_INSTALL_LIBDIR);
   if (!llvm::sys::fs::exists(LibPath)) {

Ericson2314 wrote:
> compnerd wrote:
> > serge-sans-paille wrote:
> > > Ericson2314 wrote:
> > > > mgorny wrote:
> > > > > Well, one thing I immediately notice is that technically 
> > > > > `CMAKE_INSTALL_LIBDIR` can be an absolute path, while in many 
> > > > > locations you are assuming it will always be relative. Not saying 
> > > > > that's a blocker but I think you should add checks for that into 
> > > > > `CMakeLists.txt`.
> > > > Yes I was working on this, and I intend to use `CMAKE_INSTALL_LIBDIR` 
> > > > with an absolute path.
> > > > 
> > > > OK if this isn't supported initially but we should ovoid regressing 
> > > > where possible.
> > > Turns out LLVM_LIBDIR_SUFFIX is used in several situations: (a) for the 
> > > library install dir or (b) for the location where build artifact as 
> > > stored in CMAKE_BINARY_DIR. (a) could accept a path but not (b), unless 
> > > we derive it from (a) but I can see a lot of complication there for the 
> > > testing step. Would that be ok to choke on CMAKE_INSTALL_LIBDIR being a 
> > > path and not a directory component?
> > > 
> > I think that is absolutely reasonable.  There is the 
> > `CMAKE_INSTALL_FULL_LIBDIR` which should be the relatively absolute path 
> > (it is relative to `DESTDIR`).  The `CMAKE_INSTALL_LIBDIR` should be the 
> > relative component which is added to `CMAKE_INSTALL_PREFIX`.
> Please do not do this. In NixOS we uses absolute paths for these which are 
> *not* within `CMAKE_INSTALL_PREFIX` and I would very much like that to 
> continue to work, and have put a lot of effort into it.
> 
> (I am sorry I have been a bit AWAL on LLVM things in general but hopefully 
> will have more time as we head into the new year.)
Why can NixOS not use `CMAKE_INSTALL_FULL_LIBDIR`?  That is computed to 
`${CMAKE_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}` only if it is not already 
defined to an absolute path.


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

https://reviews.llvm.org/D137337

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


[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2022-12-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

I'm not fully up-to-date, what's the main difference and advantage of the new 
code object version? What do all the new implicit arguments do.




Comment at: clang/lib/Driver/ToolChains/AMDGPU.cpp:953
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
+
   if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,

Unrelated?



Comment at: openmp/libomptarget/DeviceRTL/include/Interface.h:169
+
+#ifdef __AMDGCN__
+size_t external_get_local_size(uint32_t dim);

This should probably use variants to match the rest of the style, also if you 
intend to read these outside of the library you'll need to put them in the 
exports file and set their visibility.



Comment at: openmp/libomptarget/DeviceRTL/src/Mapping.cpp:19
 #pragma omp begin declare target device_type(nohost)
-
+extern const uint16_t __oclc_ABI_version;
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"

What if this isn't defined? We should be able to use the OpenMP library without 
the AMD device libraries. Should it be extern weak?



Comment at: openmp/libomptarget/DeviceRTL/src/State.cpp:73
+extern "C" {
+#ifdef __AMDGCN__
+size_t external_get_local_size(uint32_t dim) {

Variants



Comment at: openmp/libomptarget/plugins/amdgpu/impl/get_elf_mach_gfx_name.h:15
 
+enum IMPLICITARGS : uint16_t {
+  COV4_SIZE = 56,

Unrelated, but is there any particular reason these aren't defined in the 
`hsa_amd_ext.h`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-09 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:572
 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
+  } else if (D->hasConstantInitialization() && !(D->hasAttr())) 
{
+OrderGlobalInitsOrStermFinalizers Key(201,

efriedma wrote:
> zahiraam wrote:
> > efriedma wrote:
> > > zahiraam wrote:
> > > > efriedma wrote:
> > > > > zahiraam wrote:
> > > > > > efriedma wrote:
> > > > > > > zahiraam wrote:
> > > > > > > > efriedma wrote:
> > > > > > > > > How is ConstInitAttr relevant here?
> > > > > > > > This change made (without the !(D->hasAttr()) 
> > > > > > > > made the LIT behavior of aix-static-init.cpp. The IR generated 
> > > > > > > > for 
> > > > > > > > namespace test3 {
> > > > > > > >   struct Test3 {
> > > > > > > > constexpr Test3() {};
> > > > > > > > ~Test3() {};
> > > > > > > >   };
> > > > > > > > 
> > > > > > > >   constinit Test3 t;
> > > > > > > > } // namespace test3
> > > > > > > > 
> > > > > > > > was different. I would have thought that the change we made for 
> > > > > > > > constexpr wouldn't affter constinit? 
> > > > > > > I think the significant bit there isn't the use of constinit; 
> > > > > > > it's the non-trivial destructor.  I think the priority 
> > > > > > > modification should only affect constructors, not destructors.  
> > > > > > > (Not sure how to make that work, at first glance.)
> > > > > > Let's see if this is an acceptable solution.
> > > > > To fake constant initialization, we need to initialize the variable 
> > > > > before anything else runs.  But the rearranged prioritization isn't 
> > > > > supposed to affect the destructor.  From [basic.start.term]: "If an 
> > > > > object is initialized statically, the object is destroyed in the same 
> > > > > order as if the object was dynamically initialized."
> > > > > 
> > > > > What you're doing here isn't exactly implementing that.  What you're 
> > > > > doing here is delaying both the initialization and the destruction if 
> > > > > the variable has a non-trivial destructor.  We need to separate the 
> > > > > two to get the behavior we want.
> > > > Could we consider adding a field to EvaluatedStmt called 
> > > > "HasTrivialDestrutor" and only perform the prioritization change when 
> > > > !D->HasTrivialDesctructor?  Instead of using the test for 
> > > > D->hasConstantInitialization(). This seems to be englobing to many 
> > > > cases.
> > > > 
> > > > I considered returning null for HasConstantInitialization in case of 
> > > > var has a non-trivial destructor but that doesn't seem to work.
> > > Once you separate out the initialization from the destruction, the rest 
> > > should come together naturally, I think? I'm not sure what other cases 
> > > could be caught by hasConstantInitialization().
> > Does this change accomplish this? Thanks.
> When a global variable is dynamically initialized, there are two parts to the 
> initialization:
> 
> - Constructing the variable (calling the constructor, or equivalent)
> - Registering the destructor with the runtime (atexit on Windows)
> 
> If an object is initialized statically, the two parts are separated: the 
> variable is emitted already initialized by the compiler.  But we still 
> register the destructor at the same time, in the same way.
> 
> If a dllimport object is initialized statically, we need to make it appear to 
> user code that the same thing happened.  So we need to initialize the object 
> early, but we need to register the destructor at the same time we would have 
> otherwise registered it.  To make this work, we need two separate initializer 
> functions with different priorities.
Thanks for the clarification. I am slowly getting it, I think.

In terms of IR, for example for this:
  struct Test3 {
constexpr Test3() {};
~Test3() {};
  };

  constinit Test3 t;

Are we looking for something like this (partial IR):

  @t = global %struct.Test3 undef
  @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, 
ptr } { i32 **201**, ptr @_GLOBAL__I_000201, ptr null }]
  @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, 
ptr } { i32 **65535**, ptr @_GLOBAL__D_a, ptr null }]
  define internal void @__cxx_global_var_init() {
  entry:
call void @_ZN5Test3C1Ev(ptr noundef nonnull align 1 dereferenceable(1) @t)
%0 = call i32 @atexit(ptr @__dtor_t) 
ret void
  }
  define internal void @__finalize_t() {
   %0 = call i32 @unatexit(ptr @__dtor_t) 
   %needs_destruct = icmp eq i32 %0, 0
   br i1 %needs_destruct, label %destruct.call, label %destruct.end

  destruct.call:  
call void @__dtor_t()
  .}
  }

Or

  define internal void @__cxx_global_var_init()  {
  entry:
call void @_ZN5Test3C1Ev(ptr noundef nonnull align 1 dereferenceable(1) @t)
ret void
  }
  define internal void @__finalize_t()  {
  %0 = call i32 @atexit(ptr @__dtor_t) 
  }


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D13

[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2022-12-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Maybe we should wait until D138389  lands and 
we can update both, otherwise we'd need a second patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

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


[PATCH] D129531: [clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values

2022-12-09 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:5380
+  }
+  InitExprs.push_back(ER.get());
+}

ilya-biryukov wrote:
> ayzhao wrote:
> > ayzhao wrote:
> > > So the libc++ test compile failures are due to this line.
> > > 
> > > One example of a failing unit test is 
> > > [range.take.while/ctor.view.pass](https://github.com/llvm/llvm-project/blob/main/libcxx/test/std/ranges/range.adaptors/range.take.while/ctor.view.pass.cpp).
> > >  Clang calls this function twice in `TreeTransform.h` - once with 
> > > `VerifyOnly` set to `true`, once with it set to `false`.
> > > 
> > > For some reason, when this function tries to value-initialize the member 
> > > `MoveOnly mo` in `View`, `Seq.Failed()` returns false after 
> > > `TryValueInitialization(...)`, but the resulting `ExprResult` is 
> > > `nullptr`, causing the segfault we see when we push `nullptr` to 
> > > `InitExprs` and pass `InitExprs` to the constructor of 
> > > `CXXParenListInitExpr`. One way to be fix this is to move the line 
> > > `ExprResult ER = Seq.Perform(...)` out of the `if (!VerifyOnly)` block 
> > > and check for `ER.isInvalid()` instead of `Seq.Failed()`, but that 
> > > results in test failures due to excess diagnostic messages in 
> > > `Seq.Perform(...)`
> > > 
> > > I'm still looking into this, but if anyone has any ideas, they would be 
> > > very welcome.
> > > 
> > > To repro the buildbot failures, just build clang with this patch, and 
> > > then in a separate build directory, build the target `check-cxx` using 
> > > the previously built clang.
> > I was able to get the above workaround to pass the test by clearing the 
> > diagnostics after calling `Seq.Perform(...)`.
> > 
> > IMO, this should be OK for now, but I'm open to better ideas if anyone has 
> > any.
> Clearing all the diagnostics is a nuclear options and definitely seems off 
> here. We should not call `Perform()` when `VerifyOnly` is `true` to avoid 
> producing the diagnostics in the first place.
> 
> It's fine for the call with `VerifyOnly = true` to return no errors and later 
> produce diagnostics with `VerifyOnly = false`, I believe this is what 
> `InitListChecker` is already doing.
> I have been playing around with the old version of the code, but couldn't fix 
> it fully. I do have a small example that breaks, we should add it to the test 
> and it should also be easier to understand what's going on:
> 
> ```
> struct MoveOnly
> {
>   MoveOnly(int data = 1);
>   MoveOnly(const MoveOnly&) = delete;
>   MoveOnly(MoveOnly&&) = default;
> };
> 
> struct View {
>   int a;
>   MoveOnly mo;
> };
> 
> void test() {
>   View{0};
>   View(0); // should work, but crashes and produces invalid diagnostics.
> }
> ```
> 
> In general, my approach would be to try mimicing what `InitListChecker` is 
> doing as much as possible, trimming all the unnecessary complexity that 
> braced-init-lists entail.
> Hope it's helpful.
So it looks like all I had to do was remove the call to 
`TryValueInitialization(...)` and just check for `Seq.Failed()`. This is also 
what we do in `InitListChecker`.

The `check-cxx` target appears to work for me locally, so fingers crossed that 
the build passes.

>  I do have a small example that breaks, we should add it to the test and it 
> should also be easier to understand what's going on:

Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2022-12-09 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: jdoerfert, JonChesterfield, jhuber6, yaxunl.
Herald added subscribers: kosarev, kerbowa, guansong, tpr, dstuttard, jvesely, 
kzhuravl.
Herald added a project: All.
saiislam requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1, MaskRay, wdng.
Herald added projects: clang, OpenMP.

Update DeviceRTL and the AMDGPU plugin to use code
object version 5. Default is code object version 4.

DeviceRTL uses rocm-device-libs instead of directly calling
amdgcn builtins for the functions which are affected by
cov5.

AMDGPU plugin queries the ELF for code object version
and then prepares various implicitargs accordingly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139730

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.h
  clang/lib/Driver/ToolChains/Clang.cpp
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/src/Mapping.cpp
  openmp/libomptarget/DeviceRTL/src/State.cpp
  openmp/libomptarget/plugins/amdgpu/impl/get_elf_mach_gfx_name.cpp
  openmp/libomptarget/plugins/amdgpu/impl/get_elf_mach_gfx_name.h
  openmp/libomptarget/plugins/amdgpu/impl/internal.h
  openmp/libomptarget/plugins/amdgpu/impl/system.cpp
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp

Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -124,9 +124,10 @@
   uint32_t KernargSegmentSize;
   void *KernargRegion = nullptr;
   std::queue FreeKernargSegments;
+  uint16_t CodeObjectVersion;
 
   uint32_t kernargSizeIncludingImplicit() {
-return KernargSegmentSize + sizeof(impl_implicit_args_t);
+return KernargSegmentSize + implicitArgsSize(CodeObjectVersion);
   }
 
   ~KernelArgPool() {
@@ -143,8 +144,10 @@
   KernelArgPool(const KernelArgPool &) = delete;
   KernelArgPool(KernelArgPool &&) = delete;
 
-  KernelArgPool(uint32_t KernargSegmentSize, hsa_amd_memory_pool_t &MemoryPool)
-  : KernargSegmentSize(KernargSegmentSize) {
+  KernelArgPool(uint32_t KernargSegmentSize, hsa_amd_memory_pool_t &MemoryPool,
+uint16_t CodeObjectVersion)
+  : KernargSegmentSize(KernargSegmentSize),
+CodeObjectVersion(CodeObjectVersion) {
 
 // impl uses one pool per kernel for all gpus, with a fixed upper size
 // preserving that exact scheme here, including the queue
@@ -228,16 +231,16 @@
   KernelTy(llvm::omp::OMPTgtExecModeFlags ExecutionMode, int16_t ConstWgSize,
int32_t DeviceId, void *CallStackAddr, const char *Name,
uint32_t KernargSegmentSize,
-   hsa_amd_memory_pool_t &KernArgMemoryPool)
+   hsa_amd_memory_pool_t &KernArgMemoryPool, uint16_t CodeObjectVersion)
   : ExecutionMode(ExecutionMode), ConstWGSize(ConstWgSize),
 DeviceId(DeviceId), CallStackAddr(CallStackAddr), Name(Name) {
 DP("Construct kernelinfo: ExecMode %d\n", ExecutionMode);
 
 std::string N(Name);
 if (KernelArgPoolMap.find(N) == KernelArgPoolMap.end()) {
-  KernelArgPoolMap.insert(
-  std::make_pair(N, std::unique_ptr(new KernelArgPool(
-KernargSegmentSize, KernArgMemoryPool;
+  KernelArgPoolMap.insert(std::make_pair(
+  N, std::unique_ptr(new KernelArgPool(
+ KernargSegmentSize, KernArgMemoryPool, CodeObjectVersion;
 }
   }
 };
@@ -474,6 +477,7 @@
   std::vector WarpSize;
   std::vector GPUName;
   std::vector TargetID;
+  uint16_t CodeObjectVersion;
 
   // OpenMP properties
   std::vector NumTeams;
@@ -487,6 +491,7 @@
 
   // Resource pools
   SignalPoolT FreeSignalPool;
+  std::vector PreallocatedDeviceHeap;
 
   bool HostcallRequired = false;
 
@@ -861,7 +866,6 @@
"Unexpected device id!");
 FuncGblEntries[DeviceId].emplace_back();
 FuncOrGblEntryTy &E = FuncGblEntries[DeviceId].back();
-// KernelArgPoolMap.clear();
 E.Entries.clear();
 E.Table.EntriesBegin = E.Table.EntriesEnd = 0;
   }
@@ -1032,6 +1036,7 @@
 SymbolInfoTable.resize(NumberOfDevices);
 DeviceCoarseGrainedMemoryPools.resize(NumberOfDevices);
 DeviceFineGrainedMemoryPools.resize(NumberOfDevices);
+PreallocatedDeviceHeap.resize(NumberOfDevices);
 
 Err = setupDevicePools(HSAAgents);
 if (Err != HSA_STATUS_SUCCESS) {
@@ -1361,6 +1366,27 @@
   return PacketId;
 }
 
+const uint16_t getCodeObjectVersionFromELF(__tgt_device_image *Image) {
+  char *ImageBegin = (char *)Image->ImageStart;
+  size_t ImageSize = (char *)Image->ImageEnd - ImageBegin;
+
+  StringRef Buffer = StringRef(ImageBegin, ImageSize);
+  auto ElfOrErr = ObjectFile::createELFObjectFile(MemoryBufferRef(Buffer, ""),
+  /*InitContent

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-12-09 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D131858#3984855 , @arphaman wrote:

> Ping @mizvekov.
>
> Unfortunately I'm unable to revert this commit now so we won't be able to get 
> the bot back to green until it's fixed.

Hello, sorry for the long time to respond.

Can you tell if this has been fixed by 
https://github.com/llvm/llvm-project/commit/303f20a2cab4554a10ec225fd853709146f8c51c
 ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D129531: [clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values

2022-12-09 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 481700.
ayzhao marked 6 inline comments as done.
ayzhao added a comment.

address comments + rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/PCH/cxx_paren_init.cpp
  clang/test/PCH/cxx_paren_init.h
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1156,7 +1156,7 @@
 
   Parenthesized initialization of aggregates
   https://wg21.link/p0960r3";>P0960R3
-  No
+  Clang 16
 

 https://wg21.link/p1975r0";>P1975R0
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -643,6 +643,10 @@
 K = CXCursor_RequiresExpr;
 break;
 
+  case Stmt::CXXParenListInitExprClass:
+K = CXCursor_CXXParenListInitExpr;
+break;
+
   case Stmt::MSDependentExistsStmtClass:
 K = CXCursor_UnexposedStmt;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2139,6 +2139,7 @@
   void VisitLambdaExpr(const LambdaExpr *E);
   void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E);
   void VisitRequiresExpr(const RequiresExpr *E);
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *E);
   void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
   void VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *D);
   void VisitOMPLoopDirective(const OMPLoopDirective *D);
@@ -3006,6 +3007,9 @@
   for (ParmVarDecl *VD : E->getLocalParameters())
 AddDecl(VD);
 }
+void EnqueueVisitor::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E) {
+  EnqueueChildren(E);
+}
 void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
   // Treat the expression like its syntactic form.
   Visit(E->getSyntacticForm());
@@ -5587,6 +5591,8 @@
 return cxstring::createRef("ConceptSpecializationExpr");
   case CXCursor_RequiresExpr:
 return cxstring::createRef("RequiresExpr");
+  case CXCursor_CXXParenListInitExpr:
+return cxstring::createRef("CXXParenListInitExpr");
   case CXCursor_UnexposedStmt:
 return cxstring::createRef("UnexposedStmt");
   case CXCursor_DeclStmt:
Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -0,0 +1,172 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+// RUN: %clang_cc1 -verify=expected,beforecxx20 -Wc++20-extensions -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int &&c; // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 5{{candidate constructor}}
+  A a;
+  int b[20];
+};
+
+struct D : public C, public A {
+  int a;
+};
+
+struct E { // expected-note 3{{candidate constructor}}
+  struct F {
+F(int, int);
+  };
+  int a;
+  F f;
+};
+
+int getint(); // expected-note {{declared here}}
+
+struct F {
+  int a;
+  int b = getint(); // expected-note {{non-constexpr function 'getint' cannot be used i

  1   2   3   >