[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2021-12-24 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray marked 2 inline comments as done.
lichray added inline comments.



Comment at: clang/include/clang/AST/PrettyPrinter.h:288
+  /// template parameters, no matter how many elements there are.
+  unsigned EntireContentsOfLargeArray : 1;
+

rsmith wrote:
> It looks like nothing is setting this to `true` yet, so that part of this 
> patch seems untested. The places I think we want to set this to `true` are:
> 
> 1) When forming types in a diagnostic, if we have two types that differ only 
> in the contents of large arrays. That's checked in here: 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ASTDiagnostic.cpp#L259
> 
> I think what we'd want is: if we still have a collision between type 
> names after comparing the canonical strings 
> (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ASTDiagnostic.cpp#L291),
>  then set this policy to `true` for the rest of the function, and recompute 
> `S` and `CanS`.
> 
> This should be detectable in a case such as:
> 
> ```
> void f(X<{"some very long string that differs here: x"}>);
> void g() {
>   f(X<{"some very long string that differs here: y"}>());
> }
> ```
> 
> ... where the diagnostic should include the whole string, not elide the 
> differing portion at the end.
> 
> 2) In the `-ast-print` output: when pretty-printing as code, we want to 
> produce correct, non-elided template arguments. I think this will require 
> passing a printing policy into `TemplateParamObjectDecl::printAsInit` and 
> `::printAsExpr` 
> (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/DeclTemplate.cpp#L1509).
>  This should be detectable in the output of `-ast-print`, where we do not 
> want to elide any part of template arguments. Perhaps `StmtPrinter` and 
> `DeclPrinter` should enable this `PrintingPolicy` flag?
> 
> 3) When generating debug information: 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGDebugInfo.cpp#L230
> 
> It's generally important that debug information has complete type names.
Added `PrintingPolicy` parameter to `TemplateParamObjectDecl::printAsInit` and 
`printAsExpr`, fixed the implementation, and added tests for the effect of the 
new `EntireContentsOfLargeArray` bit.

Whether how diagnosis, codegen, and higher-level printers should make use of 
them, I think they're outside the scope of this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

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


[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2021-12-24 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 396187.
lichray marked an inline comment as done.
lichray added a comment.
Herald added a subscriber: mgorny.

- Fix categorizing int64_t chars of negative values
- More ArrayRef
- Fix and test the EntireContentsOfLargeArray bit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Basic/CharInfo.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/test/SemaTemplate/temp_arg_string_printing.cpp
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/ElidePrinterTest.cpp

Index: clang/unittests/AST/ElidePrinterTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/ElidePrinterTest.cpp
@@ -0,0 +1,74 @@
+//===- unittests/AST/ElidePrinterTest.cpp --- Elide printer output tests --===//
+//
+// 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
+//
+//===--===//
+//
+// This file contains tests for shortening NTTP in AST printer.
+//
+//===--===//
+
+#include "ASTPrint.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/SmallString.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace ast_matchers;
+using namespace tooling;
+
+namespace {
+
+void PrintDecl(raw_ostream , const ASTContext *Context, const Decl *D,
+   PrintingPolicyAdjuster PolicyModifier) {
+  PrintingPolicy Policy = Context->getPrintingPolicy();
+  Policy.Indentation = 0;
+  if (PolicyModifier)
+PolicyModifier(Policy);
+  D->print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ false);
+}
+
+::testing::AssertionResult
+PrintedDeclMatches(StringRef Code, const std::vector ,
+   const DeclarationMatcher ,
+   StringRef ExpectedPrinted,
+   PrintingPolicyAdjuster PolicyModifier) {
+  return PrintedNodeMatches(Code, Args, NodeMatch, ExpectedPrinted, "",
+  PrintDecl, PolicyModifier);
+}
+
+} // unnamed namespace
+
+TEST(ElidePrinter, TemplateIdWithNTTP) {
+  constexpr char Code[] = R"cpp(
+template 
+struct Str {
+  constexpr Str(char const ()[N]) { __builtin_memcpy(value, s, N); }
+  char value[N];
+};
+template  class ASCII {};
+
+ASCII<"this nontype template argument is too long to print"> x;
+  )cpp";
+  auto Matcher = classTemplateSpecializationDecl(hasName("ASCII")).bind("id");
+
+  ASSERT_TRUE(PrintedDeclMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(template<> class ASCII<{"this nontype template argument is [...]"}> {
+})",
+  [](PrintingPolicy ) {
+Policy.EntireContentsOfLargeArray = false;
+  }));
+
+  ASSERT_TRUE(PrintedDeclMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(template<> class ASCII<{"this nontype template argument is too long to print"}> {
+})",
+  [](PrintingPolicy ) {
+Policy.EntireContentsOfLargeArray = true;
+  }));
+}
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -22,6 +22,7 @@
   DataCollectionTest.cpp
   DeclPrinterTest.cpp
   DeclTest.cpp
+  ElidePrinterTest.cpp
   EvaluateAsRValueTest.cpp
   ExternalASTSourceTest.cpp
   NamedDeclPrinterTest.cpp
Index: clang/test/SemaTemplate/temp_arg_string_printing.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_string_printing.cpp
@@ -0,0 +1,141 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-print %s | FileCheck %s
+
+using size_t = __SIZE_TYPE__;
+static_assert(__has_builtin(__make_integer_seq));
+
+template  class idx_seq {};
+template  using make_idx_seq = __make_integer_seq;
+
+template 
+struct Str {
+  constexpr Str(CharT const ()[N]) : Str(s, make_idx_seq()) {}
+  CharT value[N];
+
+private:
+  template 
+  constexpr Str(CharT const ()[N], idx_seq) : value{s[I]...} {}
+};
+
+template  class ASCII {};
+
+void not_string() {
+  // CHECK{LITERAL}: ASCII<{{9, -1, 42}}>
+  new ASCII<(int[]){9, -1, 42}>;
+  // CHECK{LITERAL}: ASCII<{{3.14e+00, 0.00e+00, 4.20e+01}}>
+  new ASCII<(double[]){3.14, 0., 42.}>;
+}
+
+void narrow() {
+  // CHECK{LITERAL}: ASCII<{""}>
+  new ASCII<"">;
+  // CHECK{LITERAL}: ASCII<{"the quick brown fox jumps"}>
+  new ASCII<"the quick brown fox jumps">;
+  // CHECK{LITERAL}: ASCII<{"OVER THE 

[clang] 3cfe375 - Use StringRef::contains (NFC)

2021-12-24 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2021-12-24T22:05:34-08:00
New Revision: 3cfe375ae43139839af01e29c3ec03654e98186b

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

LOG: Use StringRef::contains (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
clang/tools/driver/driver.cpp
llvm/lib/Support/RISCVISAInfo.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp 
b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
index 64c8797934d23..d373877713f18 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
@@ -87,7 +87,7 @@ void CloexecCheck::insertStringFlag(
 
   // Check if the  may be in the mode string.
   const auto *ModeStr = dyn_cast(ModeArg->IgnoreParenCasts());
-  if (!ModeStr || (ModeStr->getString().find(Mode) != StringRef::npos))
+  if (!ModeStr || ModeStr->getString().contains(Mode))
 return;
 
   std::string ReplacementText = buildFixMsgForStringFlag(

diff  --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
index 8da0469554250..4bf841648f948 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -64,7 +64,7 @@ static std::string collapseConsecutive(StringRef Str, char C) 
{
 static bool hasReservedDoubleUnderscore(StringRef Name,
 const LangOptions ) {
   if (LangOpts.CPlusPlus)
-return Name.find("__") != StringRef::npos;
+return Name.contains("__");
   return Name.startswith("__");
 }
 

diff  --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
index 26b1d8ecdc319..40dda98b1e49b 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -25,7 +25,7 @@ bool containsEscapes(StringRef HayStack, StringRef Escapes) {
 return false;
 
   while (BackSlash != StringRef::npos) {
-if (Escapes.find(HayStack[BackSlash + 1]) == StringRef::npos)
+if (!Escapes.contains(HayStack[BackSlash + 1]))
   return false;
 BackSlash = HayStack.find('\\', BackSlash + 2);
   }

diff  --git 
a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
index 7dc519c152828..07e962a07e843 100644
--- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -81,7 +81,7 @@ static SourceLocation findEndLocation(const Stmt , const 
SourceManager ,
 SourceRange TokRange(Loc, TokEndLoc);
 StringRef Comment = Lexer::getSourceText(
 CharSourceRange::getTokenRange(TokRange), SM, Context->getLangOpts());
-if (Comment.startswith("/*") && Comment.find('\n') != StringRef::npos) {
+if (Comment.startswith("/*") && Comment.contains('\n')) {
   // Multi-line block comment, insert brace before.
   break;
 }

diff  --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
index 4f81dc49ded7c..c8a8edf67884e 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
@@ -71,7 +71,7 @@ void NamedParameterCheck::check(const 
MatchFinder::MatchResult ) {
 const char *Begin = SM.getCharacterData(Parm->getBeginLoc());
 const char *End = SM.getCharacterData(Parm->getLocation());
 StringRef Data(Begin, End - Begin);
-if (Data.find("/*") != StringRef::npos)
+if (Data.contains("/*"))
   continue;
 
 UnnamedParams.push_back(std::make_pair(Function, I));

diff  --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index c9129ee9e502c..a7bfb07e002bf 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -120,7 +120,7 @@ static void ApplyOneQAOverride(raw_ostream ,
 OS << "### Adding argument " << Str << " at end\n";
 Args.push_back(Str);
   } else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
- Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) {
+ Edit.slice(2, 

[clang-tools-extra] 62e48ed - Use isa instead of dyn_cast (NFC)

2021-12-24 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2021-12-24T21:22:27-08:00
New Revision: 62e48ed10f9d2328331378f7c070487e58346a7e

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

LOG: Use isa instead of dyn_cast (NFC)

Added: 


Modified: 
clang-tools-extra/clang-doc/Mapper.cpp
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
clang/lib/Sema/SemaExprCXX.cpp
lld/COFF/Driver.cpp
lld/ELF/Symbols.cpp
lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 790f11bb69c5b..de7e4c3410866 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -68,7 +68,7 @@ bool MapASTVisitor::VisitCXXMethodDecl(const CXXMethodDecl 
*D) {
 
 bool MapASTVisitor::VisitFunctionDecl(const FunctionDecl *D) {
   // Don't visit CXXMethodDecls twice
-  if (dyn_cast(D))
+  if (isa(D))
 return true;
   return mapDecl(D);
 }

diff  --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index e132c56cb0001..29762b6b54b1e 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -382,7 +382,7 @@ populateParentNamespaces(llvm::SmallVector 
,
   // corresponds to a Record and if it doesn't have any namespace (because this
   // means it's in the global namespace). Also if its outermost namespace is a
   // record because that record matches the previous condition mentioned.
-  if ((Namespaces.empty() && dyn_cast(D)) ||
+  if ((Namespaces.empty() && isa(D)) ||
   (!Namespaces.empty() && Namespaces.back().RefType == 
InfoType::IT_record))
 Namespaces.emplace_back(SymbolID(), "GlobalNamespace",
 InfoType::IT_namespace);
@@ -419,10 +419,10 @@ static void populateFunctionInfo(FunctionInfo , const 
FunctionDecl *D,
   populateSymbolInfo(I, D, FC, LineNumber, Filename, IsFileInRootDir,
  IsInAnonymousNamespace);
   if (const auto *T = getDeclForType(D->getReturnType())) {
-if (dyn_cast(T))
+if (isa(T))
   I.ReturnType = TypeInfo(getUSRForDecl(T), T->getNameAsString(),
   InfoType::IT_enum, getInfoRelativePath(T));
-else if (dyn_cast(T))
+else if (isa(T))
   I.ReturnType = TypeInfo(getUSRForDecl(T), T->getNameAsString(),
   InfoType::IT_record, getInfoRelativePath(T));
   } else {

diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 432d929057d14..b0b882be1a6c7 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -829,7 +829,7 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
   } else if (FixerKind == LFK_PseudoArray) {
 // This call is required to obtain the container.
 const auto *EndCall = Nodes.getNodeAs(EndCallName);
-if (!EndCall || !dyn_cast(EndCall->getCallee()))
+if (!EndCall || !isa(EndCall->getCallee()))
   return false;
   }
   return true;

diff  --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 4a58fe8709442..a0ae44131b45a 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -155,7 +155,7 @@ class CFGWalker {
   return false;
 
 // Ignore anonymous functions.
-if (!dyn_cast_or_null(AC.getDecl()))
+if (!isa_and_nonnull(AC.getDecl()))
   return false;
 
 SortedGraph = AC.getAnalysis();

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d25f329f85e45..54f0242d2ca12 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1346,7 +1346,7 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, const 
bool Explicit,
   // implicitly capturing the *enclosing  object* by reference (see loop
   // above)).
   assert((!ByCopy ||
-  dyn_cast(FunctionScopes[MaxFunctionScopesIndex])) &&
+  isa(FunctionScopes[MaxFunctionScopesIndex])) &&
  "Only a lambda can capture the enclosing object (referred to by "
  "*this) by copy");
   QualType ThisTy = getCurrentThisType();

diff  --git 

[clang] 62e48ed - Use isa instead of dyn_cast (NFC)

2021-12-24 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2021-12-24T21:22:27-08:00
New Revision: 62e48ed10f9d2328331378f7c070487e58346a7e

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

LOG: Use isa instead of dyn_cast (NFC)

Added: 


Modified: 
clang-tools-extra/clang-doc/Mapper.cpp
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
clang/lib/Sema/SemaExprCXX.cpp
lld/COFF/Driver.cpp
lld/ELF/Symbols.cpp
lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 790f11bb69c5b..de7e4c3410866 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -68,7 +68,7 @@ bool MapASTVisitor::VisitCXXMethodDecl(const CXXMethodDecl 
*D) {
 
 bool MapASTVisitor::VisitFunctionDecl(const FunctionDecl *D) {
   // Don't visit CXXMethodDecls twice
-  if (dyn_cast(D))
+  if (isa(D))
 return true;
   return mapDecl(D);
 }

diff  --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index e132c56cb0001..29762b6b54b1e 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -382,7 +382,7 @@ populateParentNamespaces(llvm::SmallVector 
,
   // corresponds to a Record and if it doesn't have any namespace (because this
   // means it's in the global namespace). Also if its outermost namespace is a
   // record because that record matches the previous condition mentioned.
-  if ((Namespaces.empty() && dyn_cast(D)) ||
+  if ((Namespaces.empty() && isa(D)) ||
   (!Namespaces.empty() && Namespaces.back().RefType == 
InfoType::IT_record))
 Namespaces.emplace_back(SymbolID(), "GlobalNamespace",
 InfoType::IT_namespace);
@@ -419,10 +419,10 @@ static void populateFunctionInfo(FunctionInfo , const 
FunctionDecl *D,
   populateSymbolInfo(I, D, FC, LineNumber, Filename, IsFileInRootDir,
  IsInAnonymousNamespace);
   if (const auto *T = getDeclForType(D->getReturnType())) {
-if (dyn_cast(T))
+if (isa(T))
   I.ReturnType = TypeInfo(getUSRForDecl(T), T->getNameAsString(),
   InfoType::IT_enum, getInfoRelativePath(T));
-else if (dyn_cast(T))
+else if (isa(T))
   I.ReturnType = TypeInfo(getUSRForDecl(T), T->getNameAsString(),
   InfoType::IT_record, getInfoRelativePath(T));
   } else {

diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 432d929057d14..b0b882be1a6c7 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -829,7 +829,7 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
   } else if (FixerKind == LFK_PseudoArray) {
 // This call is required to obtain the container.
 const auto *EndCall = Nodes.getNodeAs(EndCallName);
-if (!EndCall || !dyn_cast(EndCall->getCallee()))
+if (!EndCall || !isa(EndCall->getCallee()))
   return false;
   }
   return true;

diff  --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 4a58fe8709442..a0ae44131b45a 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -155,7 +155,7 @@ class CFGWalker {
   return false;
 
 // Ignore anonymous functions.
-if (!dyn_cast_or_null(AC.getDecl()))
+if (!isa_and_nonnull(AC.getDecl()))
   return false;
 
 SortedGraph = AC.getAnalysis();

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d25f329f85e45..54f0242d2ca12 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1346,7 +1346,7 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, const 
bool Explicit,
   // implicitly capturing the *enclosing  object* by reference (see loop
   // above)).
   assert((!ByCopy ||
-  dyn_cast(FunctionScopes[MaxFunctionScopesIndex])) &&
+  isa(FunctionScopes[MaxFunctionScopesIndex])) &&
  "Only a lambda can capture the enclosing object (referred to by "
  "*this) by copy");
   QualType ThisTy = getCurrentThisType();

diff  --git 

[PATCH] D115456: Implement on-demand TLS initialization for Microsoft CXX ABI

2021-12-24 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: clang/lib/CodeGen/MicrosoftCXXABI.cpp:404
   bool usesThreadWrapperFunction(const VarDecl *VD) const override {
-return false;
+return true;
   }

Should this depend on the MSVC compatibility version?


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

https://reviews.llvm.org/D115456

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


[PATCH] D116272: [Clang][Sema] Avoid crashing for va_arg expressions with bool argument

2021-12-24 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change fixes a compiler crash that was introduced in 
https://reviews.llvm.org/D103611: `Sema::BuildVAArgExpr` attempted to retrieve 
a corresponding signed type for `bool` by calling 
`ASTContext::getCorrespondingSignedType`.

rdar://86580370


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116272

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/varargs.cpp


Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -53,6 +53,8 @@
 
   // Ensure that signed vs unsigned doesn't matter either.
   (void)__builtin_va_arg(ap, unsigned int);
+
+  (void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 
'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior 
because arguments will be promoted to 'int'}}
 }
 
 #if __cplusplus >= 201103L
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15913,7 +15913,7 @@
   // promoted type and the underlying type are the same except for
   // signedness. Ask the AST for the correctly corresponding type and see
   // if that's compatible.
-  if (!PromoteType.isNull() &&
+  if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() &&
   PromoteType->isUnsignedIntegerType() !=
   UnderlyingType->isUnsignedIntegerType()) {
 UnderlyingType =


Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -53,6 +53,8 @@
 
   // Ensure that signed vs unsigned doesn't matter either.
   (void)__builtin_va_arg(ap, unsigned int);
+
+  (void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
 }
 
 #if __cplusplus >= 201103L
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15913,7 +15913,7 @@
   // promoted type and the underlying type are the same except for
   // signedness. Ask the AST for the correctly corresponding type and see
   // if that's compatible.
-  if (!PromoteType.isNull() &&
+  if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() &&
   PromoteType->isUnsignedIntegerType() !=
   UnderlyingType->isUnsignedIntegerType()) {
 UnderlyingType =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116229: [clang-format] Add option to align pointers in C style casts differently

2021-12-24 Thread Gabriel Smith via Phabricator via cfe-commits
yodaldevoid abandoned this revision.
yodaldevoid added a comment.

In D116229#3209414 , @owenpan wrote:

> In D116229#3208507 , @curdeius 
> wrote:
>
>> Why this option is useful? Why would someone want to have a different 
>> alignment in casts than in other places?
>> As such I'm opposed to introducing one more option. Is there any well 
>> established code style that has something like this?
>
> Yes, we should adhere to the policy 
> 
>  when adding new options.

Understood. I'll close this out, then, as I don't know of a major project that 
needs this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116229

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


[PATCH] D115103: Leak Sanitizer port to Windows

2021-12-24 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D115103#3209326 , @clemenswasser 
wrote:

> @vitalybuka
> No `check-asan` **doesn't work** for me. It just hangs forever and does 
> absolutely nothing. No output, nothing showing up in Task Manager with high 
> CPU usage or anything.
> However `check-clang` **does work**. Is there some documentation on running 
> `check-asan` on windows.
> I also saw that none of the Windows buildbots check/test anything related to 
> sanitizers. It seems to me that none of the sanitizer stuff gets ever tested 
> on Windows?
> Do the test for sanitizers_common/asan/ubsan/etc. even work on Windows?

This one runs asan on Windows, you can try to replicated using logs. 
https://lab.llvm.org/buildbot/#/builders/127
I rarely work on Windows, but i did similar setup some time ago.


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

https://reviews.llvm.org/D115103

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


[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 396178.
cjdb added a comment.

minor fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116203

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/add_cv.cpp
  clang/test/SemaCXX/remove_cvref.cpp

Index: clang/test/SemaCXX/remove_cvref.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/remove_cvref.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -std=c++11 %s
+
+template 
+struct check_remove_reference {
+  constexpr check_remove_reference() {
+static_assert(__is_same(__remove_reference(T &), T), "");
+static_assert(__is_same(__remove_reference(const T &), const T), "");
+static_assert(__is_same(__remove_reference(volatile T &), volatile T), "");
+static_assert(__is_same(__remove_reference(const volatile T &), const volatile T), "");
+
+static_assert(__is_same(__remove_reference(T &&), T), "");
+static_assert(__is_same(__remove_reference(const T &&), const T), "");
+static_assert(__is_same(__remove_reference(volatile T &&), volatile T), "");
+static_assert(__is_same(__remove_reference(const volatile T &&), const volatile T), "");
+
+static_assert(__is_same(__remove_cvref(T &), T), "");
+static_assert(__is_same(__remove_cvref(const T &), T), "");
+static_assert(__is_same(__remove_cvref(volatile T &), T), "");
+static_assert(__is_same(__remove_cvref(const volatile T &), T), "");
+
+static_assert(__is_same(__remove_cvref(T &&), T), "");
+static_assert(__is_same(__remove_cvref(const T &&), T), "");
+static_assert(__is_same(__remove_cvref(volatile T &&), T), "");
+static_assert(__is_same(__remove_cvref(const volatile T &&), T), "");
+  }
+};
+
+template <> struct check_remove_reference {};
+template  struct check_remove_reference {};
+template  struct check_remove_reference {};
+
+template 
+constexpr bool check_remove_qualifiers() {
+  static_assert(__is_same(__remove_const(const T), T), "");
+  static_assert(__is_same(__remove_const(volatile T), volatile T), "");
+  static_assert(__is_same(__remove_const(const volatile T), volatile T), "");
+
+  static_assert(__is_same(__remove_volatile(const T), const T), "");
+  static_assert(__is_same(__remove_volatile(volatile T), T), "");
+  static_assert(__is_same(__remove_volatile(const volatile T), const T), "");
+
+  static_assert(__is_same(__remove_cv(const T), T), "");
+  static_assert(__is_same(__remove_cv(volatile T), T), "");
+  static_assert(__is_same(__remove_cv(const volatile T), T), "");
+
+  check_remove_reference();
+
+  return true;
+}
+
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+
+struct S {};
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
Index: clang/test/SemaCXX/add_cv.cpp
===
--- /dev/null
+++ 

[PATCH] D116264: [clang] adds `__remove_cvref` as a compiler buiilt-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb abandoned this revision.
cjdb added a comment.

Merged into D116203 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116264

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


[PATCH] D116262: [clang] adds `__remove_reference` as a compiler built-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Merged into D116203 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116262

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


[PATCH] D116260: [clang] adds `__remove_cv` as a compiler built-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb abandoned this revision.
cjdb added a comment.

Merged into D116203 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116260

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


[PATCH] D116242: [clang] adds `__remove_volatile` as a compiler built-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb abandoned this revision.
cjdb added a comment.

Merged into D116203 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116242

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


[PATCH] D116226: [clang] adds `__remove_const` as a compiler built-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb abandoned this revision.
cjdb added a comment.

Merged into D116203 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116226

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


[PATCH] D116206: [clang] adds `__add_cv` as a compiler built-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb abandoned this revision.
cjdb added a comment.

Merged into D116203 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116206

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


[PATCH] D116205: [clang] adds `__add_volatile` as a compiler built-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb abandoned this revision.
cjdb added a comment.

Merged into D116203 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116205

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


[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 396177.
cjdb retitled this revision from "[clang] adds `__add_const` as a compiler 
built-in" to "[clang] adds unary type transformations as compiler built-ins".
cjdb edited the summary of this revision.
cjdb added a comment.

merges D116205 , D116206 
, D116226 , 
D116242 , D116260 
, D116262  
and D116264 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116203

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/add_cv.cpp
  clang/test/SemaCXX/remove_cvref.cpp

Index: clang/test/SemaCXX/remove_cvref.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/remove_cvref.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -std=c++11 %s
+
+template 
+struct check_remove_reference {
+  constexpr check_remove_reference() {
+static_assert(__is_same(__remove_reference(T &), T), "");
+static_assert(__is_same(__remove_reference(const T &), const T), "");
+static_assert(__is_same(__remove_reference(volatile T &), volatile T), "");
+static_assert(__is_same(__remove_reference(const volatile T &), const volatile T), "");
+
+static_assert(__is_same(__remove_reference(T &&), T), "");
+static_assert(__is_same(__remove_reference(const T &&), const T), "");
+static_assert(__is_same(__remove_reference(volatile T &&), volatile T), "");
+static_assert(__is_same(__remove_reference(const volatile T &&), const volatile T), "");
+
+static_assert(__is_same(__remove_cvref(T &), T), "");
+static_assert(__is_same(__remove_cvref(const T &), T), "");
+static_assert(__is_same(__remove_cvref(volatile T &), T), "");
+static_assert(__is_same(__remove_cvref(const volatile T &), T), "");
+
+static_assert(__is_same(__remove_cvref(T &&), T), "");
+static_assert(__is_same(__remove_cvref(const T &&), T), "");
+static_assert(__is_same(__remove_cvref(volatile T &&), T), "");
+static_assert(__is_same(__remove_cvref(const volatile T &&), T), "");
+  }
+};
+
+template <> struct check_remove_reference {};
+template  struct check_remove_reference {};
+template  struct check_remove_reference {};
+
+template 
+constexpr bool check_remove_qualifiers() {
+  static_assert(__is_same(__remove_const(const T), T), "");
+  static_assert(__is_same(__remove_const(volatile T), volatile T), "");
+  static_assert(__is_same(__remove_const(const volatile T), volatile T), "");
+
+  static_assert(__is_same(__remove_volatile(const T), const T), "");
+  static_assert(__is_same(__remove_volatile(volatile T), T), "");
+  static_assert(__is_same(__remove_volatile(const volatile T), const T), "");
+
+  static_assert(__is_same(__remove_cv(const T), T), "");
+  static_assert(__is_same(__remove_cv(volatile T), T), "");
+  static_assert(__is_same(__remove_cv(const volatile T), T), "");
+
+  check_remove_reference();
+
+  return true;
+}
+
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+
+struct S {};
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");
+static_assert(check_remove_qualifiers(), "");

[PATCH] D116229: [clang-format] Add option to align pointers in C style casts differently

2021-12-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D116229#3208507 , @curdeius wrote:

> Why this option is useful? Why would someone want to have a different 
> alignment in casts than in other places?
> As such I'm opposed to introducing one more option. Is there any well 
> established code style that has something like this?

Yes, we should adhere to the policy 

 when adding new options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116229

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


[PATCH] D116188: [clang-format] Fix short enums getting wrapped even when denied

2021-12-24 Thread Owen Pan 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 rG8ea64d5585ec: [clang-format] Fix short enums getting wrapped 
even when denied (authored by yodaldevoid, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116188

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2504,6 +2504,7 @@
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortEnumsOnASingleLine = true;
   verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
+  verifyFormat("typedef enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
   Style.AllowShortEnumsOnASingleLine = false;
   verifyFormat("enum {\n"
"  A,\n"
@@ -2511,6 +2512,20 @@
"  C\n"
"} ShortEnum1, ShortEnum2;",
Style);
+  verifyFormat("typedef enum {\n"
+   "  A,\n"
+   "  B,\n"
+   "  C\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  verifyFormat("enum {\n"
+   "  A,\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  verifyFormat("typedef enum {\n"
+   "  A,\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterEnum = true;
   verifyFormat("enum\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -393,11 +393,18 @@
 
 // Try to merge a block with left brace wrapped that wasn't yet covered
 if (TheLine->Last->is(tok::l_brace)) {
+  const FormatToken *Tok = TheLine->First;
   bool ShouldMerge = false;
-  if (TheLine->First->isOneOf(tok::kw_class, tok::kw_struct)) {
+  if (Tok->is(tok::kw_typedef)) {
+Tok = Tok->getNextNonComment();
+assert(Tok);
+  }
+  if (Tok->isOneOf(tok::kw_class, tok::kw_struct)) {
 ShouldMerge = !Style.BraceWrapping.AfterClass ||
   (I[1]->First->is(tok::r_brace) &&
!Style.BraceWrapping.SplitEmptyRecord);
+  } else if (Tok->is(tok::kw_enum)) {
+ShouldMerge = Style.AllowShortEnumsOnASingleLine;
   } else {
 ShouldMerge = !Style.BraceWrapping.AfterFunction ||
   (I[1]->First->is(tok::r_brace) &&


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2504,6 +2504,7 @@
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortEnumsOnASingleLine = true;
   verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
+  verifyFormat("typedef enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
   Style.AllowShortEnumsOnASingleLine = false;
   verifyFormat("enum {\n"
"  A,\n"
@@ -2511,6 +2512,20 @@
"  C\n"
"} ShortEnum1, ShortEnum2;",
Style);
+  verifyFormat("typedef enum {\n"
+   "  A,\n"
+   "  B,\n"
+   "  C\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  verifyFormat("enum {\n"
+   "  A,\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  verifyFormat("typedef enum {\n"
+   "  A,\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterEnum = true;
   verifyFormat("enum\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -393,11 +393,18 @@
 
 // Try to merge a block with left brace wrapped that wasn't yet covered
 if (TheLine->Last->is(tok::l_brace)) {
+  const FormatToken *Tok = TheLine->First;
   bool ShouldMerge = false;
-  if (TheLine->First->isOneOf(tok::kw_class, tok::kw_struct)) {
+  if (Tok->is(tok::kw_typedef)) {
+Tok = Tok->getNextNonComment();
+assert(Tok);
+  }
+  if (Tok->isOneOf(tok::kw_class, tok::kw_struct)) {
 ShouldMerge = !Style.BraceWrapping.AfterClass ||
   (I[1]->First->is(tok::r_brace) &&
!Style.BraceWrapping.SplitEmptyRecord);
+  } else if (Tok->is(tok::kw_enum)) {
+ShouldMerge = Style.AllowShortEnumsOnASingleLine;
   } 

[clang] 8ea64d5 - [clang-format] Fix short enums getting wrapped even when denied

2021-12-24 Thread via cfe-commits

Author: Gabriel Smith
Date: 2021-12-24T11:38:55-08:00
New Revision: 8ea64d5585ec3a0a52db20c9e57ac9bed9e80fc2

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

LOG: [clang-format] Fix short enums getting wrapped even when denied

Single-variant enums were still getting placed on a single line
even when AllowShortEnumsOnASingleLine was false. This fixes that
by checking that setting when looking to merge lines.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 3d4c1a4f903b2..f652a4e7088f1 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -393,11 +393,18 @@ class LineJoiner {
 
 // Try to merge a block with left brace wrapped that wasn't yet covered
 if (TheLine->Last->is(tok::l_brace)) {
+  const FormatToken *Tok = TheLine->First;
   bool ShouldMerge = false;
-  if (TheLine->First->isOneOf(tok::kw_class, tok::kw_struct)) {
+  if (Tok->is(tok::kw_typedef)) {
+Tok = Tok->getNextNonComment();
+assert(Tok);
+  }
+  if (Tok->isOneOf(tok::kw_class, tok::kw_struct)) {
 ShouldMerge = !Style.BraceWrapping.AfterClass ||
   (I[1]->First->is(tok::r_brace) &&
!Style.BraceWrapping.SplitEmptyRecord);
+  } else if (Tok->is(tok::kw_enum)) {
+ShouldMerge = Style.AllowShortEnumsOnASingleLine;
   } else {
 ShouldMerge = !Style.BraceWrapping.AfterFunction ||
   (I[1]->First->is(tok::r_brace) &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index ee486f4521949..374f3865acc3b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2504,6 +2504,7 @@ TEST_F(FormatTest, ShortEnums) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortEnumsOnASingleLine = true;
   verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
+  verifyFormat("typedef enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
   Style.AllowShortEnumsOnASingleLine = false;
   verifyFormat("enum {\n"
"  A,\n"
@@ -2511,6 +2512,20 @@ TEST_F(FormatTest, ShortEnums) {
"  C\n"
"} ShortEnum1, ShortEnum2;",
Style);
+  verifyFormat("typedef enum {\n"
+   "  A,\n"
+   "  B,\n"
+   "  C\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  verifyFormat("enum {\n"
+   "  A,\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  verifyFormat("typedef enum {\n"
+   "  A,\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterEnum = true;
   verifyFormat("enum\n"



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


[PATCH] D116238: [mips] Add -mfix4300 flag to enable vr4300 mulmul bugfix pass

2021-12-24 Thread Random via Phabricator via cfe-commits
Random06457 updated this revision to Diff 396171.
Random06457 added a comment.

Addressed the comments.
I also updated `isFirstMul` to exclude integer multiplications which do not 
produce the bug. That change made me fix the tests too.


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

https://reviews.llvm.org/D116238

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/lib/Target/Mips/CMakeLists.txt
  llvm/lib/Target/Mips/Mips.h
  llvm/lib/Target/Mips/MipsMulMulBugPass.cpp
  llvm/lib/Target/Mips/MipsTargetMachine.cpp
  llvm/test/CodeGen/Mips/vr4300mulmul/mulbranch.ll
  llvm/test/CodeGen/Mips/vr4300mulmul/mulmul.ll

Index: llvm/test/CodeGen/Mips/vr4300mulmul/mulmul.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/vr4300mulmul/mulmul.ll
@@ -0,0 +1,24 @@
+; RUN: llc -march=mips -mfix4300 -verify-machineinstrs < %s | FileCheck %s
+
+; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn
+define dso_local float @fun_s(float %x) local_unnamed_addr #0 {
+entry:
+; CHECK-LABEL: fun_s
+; CHECK: mul.s
+; CHECK-NEXT: nop
+; CHECK: mul.s
+  %mul = fmul float %x, %x
+  %mul1 = fmul float %mul, %x
+  ret float %mul1
+}
+
+define dso_local double @fun_d(double %x) local_unnamed_addr #0 {
+entry:
+; CHECK-LABEL: fun_d
+; CHECK: mul.d
+; CHECK-NEXT: nop
+; CHECK: mul.d
+  %mul = fmul double %x, %x
+  %mul1 = fmul double %mul, %x
+  ret double %mul1
+}
\ No newline at end of file
Index: llvm/test/CodeGen/Mips/vr4300mulmul/mulbranch.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/vr4300mulmul/mulbranch.ll
@@ -0,0 +1,27 @@
+; RUN: llc -march=mips -mfix4300 -verify-machineinstrs < %s | FileCheck %s
+
+; Function Attrs: nounwind
+define dso_local void @fun_s(float %a) local_unnamed_addr #0 {
+entry:
+; CHECK-LABEL: fun_s
+; CHECK: mul.s
+; CHECK-NEXT: nop
+  %mul = fmul float %a, %a
+  tail call void @foo_s(float %mul) #2
+  ret void
+}
+
+declare dso_local void @foo_s(float) local_unnamed_addr #1
+
+; Function Attrs: nounwind
+define dso_local void @fun_d(double %a) local_unnamed_addr #0 {
+entry:
+; CHECK-LABEL: fun_d
+; CHECK: mul.d
+; CHECK-NEXT: nop
+  %mul = fmul double %a, %a
+  tail call void @foo_d(double %mul) #2
+  ret void
+}
+
+declare dso_local void @foo_d(double) local_unnamed_addr #1
\ No newline at end of file
Index: llvm/lib/Target/Mips/MipsTargetMachine.cpp
===
--- llvm/lib/Target/Mips/MipsTargetMachine.cpp
+++ llvm/lib/Target/Mips/MipsTargetMachine.cpp
@@ -45,6 +45,10 @@
 
 #define DEBUG_TYPE "mips"
 
+static cl::opt
+EnableMulMulFix("mfix4300", cl::init(false),
+cl::desc("Enable the VR4300 mulmul bug fix."), cl::Hidden);
+
 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMipsTarget() {
   // Register the target.
   RegisterTargetMachine X(getTheMipsTarget());
@@ -292,6 +296,11 @@
   // instructions which can be remapped to a 16 bit instruction.
   addPass(createMicroMipsSizeReducePass());
 
+  // This pass inserts a nop instruction between two back-to-back multiplication
+  // instructions when the "mfix4300" flag is passed.
+  if (EnableMulMulFix)
+addPass(createMipsMulMulBugPass());
+
   // The delay slot filler pass can potientially create forbidden slot hazards
   // for MIPSR6 and therefore it should go before MipsBranchExpansion pass.
   addPass(createMipsDelaySlotFillerPass());
Index: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp
===
--- /dev/null
+++ llvm/lib/Target/Mips/MipsMulMulBugPass.cpp
@@ -0,0 +1,111 @@
+#include "Mips.h"
+#include "MipsInstrInfo.h"
+#include "MipsSubtarget.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Target/TargetMachine.h"
+
+#define DEBUG_TYPE "mips-r4300-mulmul-fix"
+
+using namespace llvm;
+
+namespace {
+
+class MipsMulMulBugFix : public MachineFunctionPass {
+public:
+  MipsMulMulBugFix() : MachineFunctionPass(ID) {}
+
+  StringRef getPassName() const override { return "Mips mulmul bugfix"; }
+
+  MachineFunctionProperties getRequiredProperties() const override {
+return MachineFunctionProperties().set(
+MachineFunctionProperties::Property::NoVRegs);
+  }
+
+  bool runOnMachineFunction(MachineFunction ) override;
+
+  static char ID;
+
+private:
+  bool fixMulMulBB(MachineBasicBlock , const MipsInstrInfo );
+};
+
+} // namespace
+
+char MipsMulMulBugFix::ID = 0;
+
+bool MipsMulMulBugFix::runOnMachineFunction(MachineFunction ) {
+
+  const MipsInstrInfo  =
+  *static_cast(MF.getSubtarget().getInstrInfo());
+
+  bool Modified = false;
+
+  for (auto  : MF)
+Modified |= fixMulMulBB(MBB, MipsII);
+
+  

[PATCH] D116238: [mips] Add -mfix4300 flag to enable vr4300 mulmul bugfix pass

2021-12-24 Thread Simon Atanasyan via Phabricator via cfe-commits
atanasyan requested changes to this revision.
atanasyan added a comment.
This revision now requires changes to proceed.

Thanks for the patch. Some notes are below.




Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:16
+static cl::opt
+EnableMulMulFix("mfix4300", cl::init(false),
+cl::desc("Enable the VR4300 mulmul bug fix."), cl::Hidden);

We can move this option to the `MipsTargetMachine.cpp` and just do not add the 
pass when it is not necessary.



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:19
+
+class MipsMulMulBugFix : public MachineFunctionPass {
+public:

Put this class into an anonymous namespace to reduce work for a linker.



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:31
+  bool runOnMachineFunction(MachineFunction ) override;
+  bool FixMulMulBB(MachineBasicBlock );
+

Let's rename the function to the `fixMulMulBB` and move it to the `private` 
section of the class.



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:36
+private:
+  static const MipsInstrInfo *MipsII;
+  const MipsSubtarget *Subtarget;

I do not think it's a good idea to save `MipsInstrInfo` into the **static** 
field. AFAIK now passes cannot be run in parallel. But if that changes in the 
future we get a problem with the static field. As to me I would get a reference 
to the `MipsInstrInfo` in the `runOnMachineFunction` and pass this reference to 
the `FixMulMulBB` as a parameter.



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:37
+  static const MipsInstrInfo *MipsII;
+  const MipsSubtarget *Subtarget;
+};

Do you really need to keep a pointer to the `Subtarget` in the object?



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:48-49
+
+  Subtarget = _cast(MF.getSubtarget());
+  MipsII = static_cast(Subtarget->getInstrInfo());
+

These lines can be merged into the single one:
```
MipsII = MF.getSubtarget().getInstrInfo();
```



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:52-55
+  MachineFunction::iterator I = MF.begin(), E = MF.end();
+
+  for (; I != E; ++I)
+Modified |= FixMulMulBB(*I);

This code can be made a bit more compact:
```
for (auto : MF)
  Modified |= FixMulMulBB(MBB);
```



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:60
+
+static bool isFirstMul(const MachineInstr *MI) {
+  switch (MI->getOpcode()) {

This function does not work with null pointer so change the argument's type to 
a reference.



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:73
+
+static bool isSecondMulOrBranch(const MachineInstr *MI) {
+  if (MI->isBranch() || MI->isIndirectBranch() || MI->isCall())

Ditto



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:95-103
+  MachineBasicBlock::instr_iterator MII = MBB.instr_begin(),
+E = MBB.instr_end();
+  MachineBasicBlock::instr_iterator NextMII;
+
+  // Iterate through the instructions in the basic block
+  for (; MII != E; MII = NextMII) {
+

`std::next` call and the iterator incrementation are cheap calls. So we can 
write the loop in a more idiomatic form:
```
for (MachineBasicBlock::instr_iterator MII = MBB.instr_begin(),
   E = MBB.instr_end();
 MII != E; ++MII) {
  MachineBasicBlock::instr_iterator NextMII = std::next(MII);
...
```



Comment at: llvm/lib/Target/Mips/MipsMulMulBugPass.cpp:110
+
+  MachineBasicBlock  = *MI->getParent();
+  const MCInstrDesc  = MipsII->get(Mips::NOP);

You do not need a new `MBB` variable. Use `MBB` passed as an argument to the 
`FixMulMulBB`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116238

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


[PATCH] D116271: [Docs] Document C++ for OpenCL 2021 support in clang

2021-12-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added reviewers: Topotuna, svenvh.
Herald added subscribers: Naghasan, ebevhan, yaxunl.
Anastasia requested review of this revision.

This patch contains an update of  C++ for OpenCL 2021 support status along with 
other misc updates:

- OpenCL 3.0
- Bugzilla -> Github issues


https://reviews.llvm.org/D116271

Files:
  clang/docs/OpenCLSupport.rst
  clang/docs/UsersManual.rst

Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -41,8 +41,8 @@
variants depending on base language.
 -  :ref:`C++ Language `
 -  :ref:`Objective C++ Language `
--  :ref:`OpenCL Kernel Language `: OpenCL C v1.0, v1.1, v1.2, v2.0,
-   plus C++ for OpenCL.
+-  :ref:`OpenCL Kernel Language `: OpenCL C 1.0, 1.1, 1.2, 2.0, 3.0,
+   and C++ for OpenCL 1.0 and 2021.
 
 In addition to these base languages and their dialects, Clang supports a
 broad variety of language extensions, which are documented in the
@@ -3303,20 +3303,25 @@
 `_ and
 there is no plan to support it in clang in any new releases in the near future.
 
-
-Clang currently supports C++ for OpenCL v1.0.
+Clang currently supports C++ for OpenCL 1.0 and 2021.
 For detailed information about this language refer to the C++ for OpenCL
 Programming Language Documentation available
 in `the latest build
 `_
 or in `the official release
-`_.
+`_.
 
 To enable the C++ for OpenCL mode, pass one of following command line options when
-compiling ``.cl`` file ``-cl-std=clc++``, ``-cl-std=CLC++``, ``-cl-std=clc++1.0``,
-``-cl-std=CLC++1.0``, ``-std=clc++``, ``-std=CLC++``, ``-std=clc++1.0`` or
-``-std=CLC++1.0``.
+compiling ``.clcpp`` file:
+
+- C++ for OpenCL 1.0: ``-cl-std=clc++``, ``-cl-std=CLC++``, ``-cl-std=clc++1.0``,
+  ``-cl-std=CLC++1.0``, ``-std=clc++``, ``-std=CLC++``, ``-std=clc++1.0`` or
+  ``-std=CLC++1.0``.
+
+- C++ for OpenCL 2021: ``-cl-std=clc++2021``, ``-cl-std=CLC++2021``,
+  ``-std=clc++2021``, ``-std=CLC++2021``.
 
+Example of use:
.. code-block:: c++
 
  template T add( T x, T y )
@@ -,15 +3338,27 @@
 
.. code-block:: console
 
- clang -cl-std=clc++ test.cl
+ clang -cl-std=clc++1.0 test.clcpp
+
 
-Alternatively, files with ``.clcpp`` extension are compiled with the C++ for OpenCL
-mode.
+By default, files with ``.clcpp`` extension are compiled with the C++ for
+OpenCL 1.0 mode.
 
.. code-block:: console
 
  clang test.clcpp
 
+For backward compatibility files with ``.cl`` extensions can also be compiled
+in C++ for OpenCL mode but the desirable language mode must be activated with
+a flag.
+
+   .. code-block:: console
+
+ clang -cl-std=clc++ test.cl
+
+Support of C++ for OpenCL 2021 is currently in experimental phase, refer to
+:doc:`OpenCLSupport` for more details.
+
 C++ for OpenCL kernel sources can also be compiled online in drivers supporting
 `cl_ext_cxx_for_opencl
 `_
Index: clang/docs/OpenCLSupport.rst
===
--- clang/docs/OpenCLSupport.rst
+++ clang/docs/OpenCLSupport.rst
@@ -18,15 +18,16 @@
 ==
 
 Clang has complete support of OpenCL C versions from 1.0 to 2.0.
+There is an ongoing work to support :ref:`OpenCL 3.0 `.
 
 Clang also supports :ref:`the C++ for OpenCL kernel language `.
 
-There is an ongoing work to support :ref:`OpenCL 3.0 `.
-
-There are also other :ref:`new and experimental features ` available.
+There are also other :ref:`new and experimental features `
+available.
 
-For general issues and bugs with OpenCL in clang refer to `Bugzilla
-`__.
+For general issues and bugs with OpenCL in clang refer to `the following Github issue
+list
+`__.
 
 Internals Manual
 
@@ -127,7 +128,7 @@
 
.. code-block:: console
 
- $ clang -target spir-unknown-unknown -c -emit-llvm -Xclang -finclude-default-header -fmodules -fimplicit-module-maps -fm odules-cache-path= test.cl
+ $ clang -target spir-unknown-unknown -c -emit-llvm -Xclang -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path= test.cl
 
 Another way to circumvent long parsing latency for the OpenCL builtin
 declarations is to use mechanism enabled by :ref:`-fdeclare-opencl-builtins
@@ -319,24 +320,32 @@
 C++ for OpenCL Implementation Status
 
 
-Clang implements language version 1.0 published in `the official

[PATCH] D116216: Prevent adding module flag - amdgpu_hostcall multiple times.

2021-12-24 Thread praveen velliengiri via Phabricator via cfe-commits
pvellien added a comment.

@yaxunl It would be very much helpful to know how to write test coverage for 
this particular patch? thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116216

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


[PATCH] D115103: Leak Sanitizer port to Windows

2021-12-24 Thread Clemens Wasser via Phabricator via cfe-commits
clemenswasser added a comment.

@vitalybuka
No `check-asan` **doesn't work** for me. It just hangs forever and does 
absolutely nothing. No output, nothing showing up in Task Manager with high CPU 
usage or anything.
However `check-clang` **does work**. Is there some documentation on running 
`check-asan` on windows.
I also saw that none of the Windows buildbots check/test anything related to 
sanitizers. It seems to me that none of the sanitizer stuff gets ever tested on 
Windows?
Do the test for sanitizers_common/asan/ubsan/etc. even work on Windows?


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

https://reviews.llvm.org/D115103

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


[clang] dc8f9fb - [Docs] Minor fix in clang user manual

2021-12-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-12-24T16:21:56Z
New Revision: dc8f9fb196dab8ca31361928bd6a361dc80d8ade

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

LOG: [Docs] Minor fix in clang user manual

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 3f9947afc29be..26da5a0ff2554 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3537,7 +3537,7 @@ should be built or installed. Please refer to `the 
following instructions
 `_
 for more details. Clang will expects the ``llvm-spirv`` executable to
 be present in the ``PATH`` environment variable. Clang uses ``llvm-spirv``
-with `the conformant assembly syntax package
+with `the widely adopted assembly syntax package
 
`_.
 
 `The versioning



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


[PATCH] D116161: [Clang] Add an overload for emitUnaryBuiltin.

2021-12-24 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D116161#3209292 , @fhahn wrote:

> In D116161#3209286 , @junaire wrote:
>
>>   35:  %0 = load float, float* %f1.addr, align 4 
>>   36:  %1 = load float, float* %f1.addr, align 4 
>>   37:  %elt.abs = call float @llvm.fabs.f32(float %1) 
>
> It looks like the argument expression is evaluated twice. Did you remove the 
> `Value *Op0 = EmitScalarExpr(E->getArg(0));` calls?

Well, for example:
For `__builtin_elementwise_abs`, we have code like:

  case Builtin::BI__builtin_elementwise_abs: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
Value *Result;
if (Op0->getType()->isIntOrIntVectorTy())
  Result = Builder.CreateBinaryIntrinsic(
  llvm::Intrinsic::abs, Op0, Builder.getFalse(), nullptr, "elt.abs");
else
  Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, nullptr,
"elt.abs");
  
return RValue::get(Result);
  }

If we use `emitUnaryBuiltin`, we are supposed to do something like:

  Result = emitUnaryBuiltin(*this, E, llvm::Intrinsic::fabs, "elt.abs");

We need to pass `CallExpr* E` to the function to meet its interface, and it 
calls `CGF.EmitScalarExpr(E->getArg(0));` inside. Maybe this is what you said 
about the argument expression being evaluated twice? I think it is avoidable if 
we don't change the function's interface.

Maybe we can have something like:

  static Value *emitUnaryBuiltin(CodeGenFunction , Value* Op0,
 unsigned IntrinsicID, llvm::StringRef Name) {
return CGF.Builder.CreateUnaryIntrinsic(IntrinsicID, Op0, nullptr, Name);
  }

Then for `__builtin_elementwise_abs` we can have:

  Result = emitUnaryBuiltin(*this, Op0, llvm::Intrinsic::fabs, "elt.abs");

and for `__builtin_elementwise_ceil` have:

  return RValue::get(
  emitUnaryBuiltin(*this, EmitScalarExpr(E->getArg(0)), 
llvm::Intrinsic::ceil, "elt.ceil"));

WDYT? Well, franking speaking I think this one-line function is ugly but I 
can't come up with a more elegant solution, I would appreciate it if you can 
offer some suggestions. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116161

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


[PATCH] D116161: [Clang] Add an overload for emitUnaryBuiltin.

2021-12-24 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D116161#3209286 , @junaire wrote:

>   35:  %0 = load float, float* %f1.addr, align 4 
>   36:  %1 = load float, float* %f1.addr, align 4 
>   37:  %elt.abs = call float @llvm.fabs.f32(float %1) 

It looks like the argument expression is evaluated twice. Did you remove the `  
  Value *Op0 = EmitScalarExpr(E->getArg(0));` calls?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116161

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


[PATCH] D116188: [clang-format] Fix short enums getting wrapped even when denied

2021-12-24 Thread Gabriel Smith via Phabricator via cfe-commits
yodaldevoid added a comment.

In D116188#3208456 , 
@HazardyKnusperkeks wrote:

> Since you only upload a diff, there is no name or email. ;)

It had looked like arcanist was retaining this information, but I now realize 
what it was doing.

At any rate, I would appreciate it if someone could merge this for me as I 
don't have commit access.

Gabriel Smith 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116188

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


[PATCH] D116161: [Clang] Add an overload for emitUnaryBuiltin.

2021-12-24 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

I confirmed that we can use `emitUnaryBuiltin` in the cases you pointed out. 
Please see the logs below:

  $ path/to/llvm-project/build/bin/clang -cc1 -internal-isystem 
/path/to/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -triple 
x86_64-apple-darwin 
/path/to/llvm-project/clang/test/CodeGen/builtins-elementwise-math.c -emit-llvm 
-disable-llvm-passes -o - | /path/to/llvm-project/build/bin/FileCheck 
/path/to/llvm-project/clang/test/CodeGen/builtins-elementwise-math.c
  /path/to/llvm-project/clang/test/CodeGen/builtins-elementwise-math.c:16:17: 
error: CHECK-NEXT: expected string not found in input
   // CHECK-NEXT: call float @llvm.fabs.f32(float [[F1]])
  ^
  :35:43: note: scanning from here
   %0 = load float, float* %f1.addr, align 4
^
  :35:43: note: with "F1" equal to "%0"
   %0 = load float, float* %f1.addr, align 4
^
  :37:13: note: possible intended match here
   %elt.abs = call float @llvm.fabs.f32(float %1)
  ^
  
  Input file: 
  Check file: 
/path/to/llvm-project/clang/test/CodeGen/builtins-elementwise-math.c
  
  -dump-input=help explains the following input dump.
  
  Input was:
  <<
30:  store <8 x i16> %vi1, <8 x i16>* %vi1.addr, align 16 
31:  store <8 x i16> %vi2, <8 x i16>* %vi2.addr, align 16 
32:  store i64 %i1, i64* %i1.addr, align 8 
33:  store i64 %i2, i64* %i2.addr, align 8 
34:  store i16 %si, i16* %si.addr, align 2 
35:  %0 = load float, float* %f1.addr, align 4 
  next:16'0   X error: no match 
found
  next:16'1 with "F1" equal to 
"%0"
36:  %1 = load float, float* %f1.addr, align 4 
  next:16'0 ~~~
37:  %elt.abs = call float @llvm.fabs.f32(float %1) 
  next:16'0 
  next:16'2 ?possible 
intended match
38:  store float %elt.abs, float* %f2.addr, align 4 
  next:16'0 
39:  %2 = load double, double* %d1.addr, align 8 
  next:16'0 ~
40:  %3 = load double, double* %d1.addr, align 8 
  next:16'0 ~
41:  %elt.abs1 = call double @llvm.fabs.f64(double %3) 
  next:16'0 ~~~
42:  store double %elt.abs1, double* %d2.addr, align 8 
  next:16'0 ~~~
  >>



  $ /path/to/llvm-project/build/bin/clang -cc1 -internal-isystem 
/path/to/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -triple 
x86_64-apple-darwin 
~/dev/cpp-projects/llvm-project/clang/test/CodeGen/builtins-reduction-math.c 
-emit-llvm -disable-llvm-passes -o - | 
~/dev/cpp-projects/llvm-project/build/bin/FileCheck 
~/dev/cpp-projects/llvm-project/clang/test/CodeGen/builtins-reduction-math.c
  /path/to/llvm-project/clang/test/CodeGen/builtins-reduction-math.c:12:17: 
error: CHECK-NEXT: expected string not found in input
   // CHECK-NEXT: call float @llvm.vector.reduce.fmax.v4f32(<4 x float> [[VF1]])
  ^
  :23:57: note: scanning from here
   %0 = load <4 x float>, <4 x float>* %vf1.addr, align 16
  ^
  :23:57: note: with "VF1" equal to "%0"
   %0 = load <4 x float>, <4 x float>* %vf1.addr, align 16
  ^
  :25:13: note: possible intended match here
   %rdx.min = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %1)
  ^
  /path/to/llvm-project/clang/test/CodeGen/builtins-reduction-math.c:38:17: 
error: CHECK-NEXT: expected string not found in input
   // CHECK-NEXT: call float @llvm.vector.reduce.fmin.v4f32(<4 x float> [[VF1]])
  ^
  :74:57: note: scanning from here
   %0 = load <4 x float>, <4 x float>* %vf1.addr, align 16
  ^
  :74:57: note: with "VF1" equal to "%0"
   %0 = load <4 x float>, <4 x float>* %vf1.addr, align 16
  ^
  :76:13: note: possible intended match here
   %rdx.min = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %1)
  ^
  
  Input file: 
  Check file: /path/to/llvm-project/clang/test/CodeGen/builtins-reduction-math.c
  
  -dump-input=help explains the following input dump.
  
  Input was:
  <<
18:  %cvi1 = alloca <8 x i16>, align 16 
19:  %r5 = alloca i64, align 8 
20:  store <4 x float> %vf1, <4 x float>* %vf1.addr, align 16 
21:  store <8 x i16> %vi1, <8 x i16>* 

[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2021-12-24 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked 4 inline comments as done.
MyDeveloperDay added a comment.

Please go ahead


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

https://reviews.llvm.org/D72326

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


[PATCH] D115561: [Clang][OpenMP] Add the support for atomic compare in parser

2021-12-24 Thread Shilei Tian via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tianshilei1992 marked an inline comment as done.
Closed by commit rGc7a589a2c4e2: [Clang][OpenMP] Add the support for atomic 
compare in parser (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115561

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/atomic_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -180,6 +180,7 @@
 def OMPC_Write : Clause<"write"> { let clangClass = "OMPWriteClause"; }
 def OMPC_Update : Clause<"update"> { let clangClass = "OMPUpdateClause"; }
 def OMPC_Capture : Clause<"capture"> { let clangClass = "OMPCaptureClause"; }
+def OMPC_Compare : Clause<"compare"> { let clangClass = "OMPCompareClause"; }
 def OMPC_SeqCst : Clause<"seq_cst"> { let clangClass = "OMPSeqCstClause"; }
 def OMPC_AcqRel : Clause<"acq_rel"> { let clangClass = "OMPAcqRelClause"; }
 def OMPC_Acquire : Clause<"acquire"> { let clangClass = "OMPAcquireClause"; }
@@ -536,6 +537,7 @@
 VersionedClause,
 VersionedClause,
 VersionedClause,
+VersionedClause
   ];
   let allowedOnceClauses = [
 VersionedClause,
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1482,6 +1482,7 @@
 CHECK_SIMPLE_CLAUSE(MemoryOrder, OMPC_memory_order)
 CHECK_SIMPLE_CLAUSE(Bind, OMPC_bind)
 CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
+CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2275,6 +2275,8 @@
 
 void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {}
 
+void OMPClauseEnqueue::VisitOMPCompareClause(const OMPCompareClause *) {}
+
 void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
 
 void OMPClauseEnqueue::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -ferror-limit 150 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -ferror-limit 150 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50,omp51 -fopenmp -fopenmp-version=51 -ferror-limit 150 %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -ferror-limit 150 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -ferror-limit 150 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50,omp51 -fopenmp-simd -fopenmp-version=51 -ferror-limit 150 %s -Wuninitialized
 
 int foo() {
 L1:
@@ -896,19 +898,19 @@
 template 
 T mixed() {
   T a, b = T();
-// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause}}
+// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 2 {{'read' clause used here}}
 #pragma omp atomic read write
   a = b;
-// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause}}
+// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 2 {{'write' clause used here}}
 #pragma omp atomic write read
   a = b;
-// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause}}
+// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 

[clang] c7a589a - [Clang][OpenMP] Add the support for atomic compare in parser

2021-12-24 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2021-12-24T08:16:51-05:00
New Revision: c7a589a2c4e2db496d732821a8dba59508326250

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

LOG: [Clang][OpenMP] Add the support for atomic compare in parser

This patch adds the support for `atomic compare` in parser. The support
in Sema and CodeGen will come soon. For now, it simply eimits an error when it
is encountered.

Reviewed By: ABataev

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/atomic_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 565eb0c9cf99d..3fd1b6d300803 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2224,6 +2224,47 @@ class OMPCaptureClause : public OMPClause {
   }
 };
 
+/// This represents 'compare' clause in the '#pragma omp atomic'
+/// directive.
+///
+/// \code
+/// #pragma omp atomic compare
+/// \endcode
+/// In this example directive '#pragma omp atomic' has 'compare' clause.
+class OMPCompareClause final : public OMPClause {
+public:
+  /// Build 'compare' clause.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param EndLoc Ending location of the clause.
+  OMPCompareClause(SourceLocation StartLoc, SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
+
+  /// Build an empty clause.
+  OMPCompareClause()
+  : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) 
{
+  }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_compare;
+  }
+};
+
 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
 /// directive.
 ///

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 8bcee8790e7b1..f62dc36de556e 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3234,6 +3234,11 @@ bool 
RecursiveASTVisitor::VisitOMPCaptureClause(OMPCaptureClause *) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPCompareClause(OMPCompareClause *) {
+  return true;
+}
+
 template 
 bool RecursiveASTVisitor::VisitOMPSeqCstClause(OMPSeqCstClause *) {
   return true;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3b6341d2232d8..f2089bfda04dc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10509,7 +10509,7 @@ def err_omp_atomic_capture_not_compound_statement : 
Error<
 def note_omp_atomic_capture: Note<
   "%select{expected assignment expression|expected compound statement|expected 
exactly two expression statements|expected in right hand side of the first 
expression}0">;
 def err_omp_atomic_several_clauses : Error<
-  "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update' or 'capture' clause">;
+  "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<
   "directive '#pragma omp %0' cannot contain more than one %select{'seq_cst', 
'relaxed', |}1'acq_rel', 'acquire' or 'release' clause">;
 def err_omp_atomic_incompatible_mem_order_clause : Error<

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 55171767da109..79834554a50d9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11190,6 +11190,9 @@ class Sema final {
   /// Called 

[PATCH] D115561: [Clang][OpenMP] Add the support for atomic compare in parser

2021-12-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115561

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


[PATCH] D116266: [SPIR-V] Add linking of separate translation units using spirv-link

2021-12-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added reviewers: svenvh, linjamaki, azabaznov.
Herald added subscribers: ThomasRaoux, ebevhan.
Anastasia requested review of this revision.

Add support of linking files compiled into SPIR-V object files using spirv-link 
(https://github.com/KhronosGroup/SPIRV-Tools#linker).

Examples:

  clang --target=spirv64 test1.cl test2.cl



  clang  --target=spirv64 test1.cl -o test1.o
  clang  --target=spirv64 test1.o test2.cl




https://reviews.llvm.org/D116266

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/SPIRV.cpp
  clang/lib/Driver/ToolChains/SPIRV.h
  clang/test/Driver/spirv-toolchain.cl

Index: clang/test/Driver/spirv-toolchain.cl
===
--- clang/test/Driver/spirv-toolchain.cl
+++ clang/test/Driver/spirv-toolchain.cl
@@ -59,7 +59,12 @@
 // TMP: {{llvm-spirv.*"}} [[S]] "-to-binary" "-o" {{".*o"}}
 
 //-
-// Check that warning occurs if multiple input files are passed.
-// RUN: %clang -### -target spirv64 %s %s 2>&1 | FileCheck --check-prefix=WARN %s
-
-// WARN: warning: Linking multiple input files is not supported for SPIR-V yet
+// Check linking when multiple input files are passed.
+// RUN: %clang -### -target spirv64 %s %s 2>&1 | FileCheck --check-prefix=SPLINK %s
+// SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
+// SPLINK-SAME: "-o" [[BC:".*bc"]]
+// SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV1:".*o"]]
+// SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
+// SPLINK-SAME: "-o" [[BC:".*bc"]]
+// SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
+// SPLINK: {{"spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"
Index: clang/lib/Driver/ToolChains/SPIRV.h
===
--- clang/lib/Driver/ToolChains/SPIRV.h
+++ clang/lib/Driver/ToolChains/SPIRV.h
@@ -39,6 +39,17 @@
 const char *LinkingOutput) const override;
 };
 
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("SPIRV::Linker", "spirv-link", TC) {}
+  bool hasIntegratedCPP() const override { return false; }
+  bool isLinkJob() const override { return true; }
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+};
+
 } // namespace SPIRV
 } // namespace tools
 
@@ -68,6 +79,7 @@
 
 protected:
   clang::driver::Tool *getTool(Action::ActionClass AC) const override;
+  Tool *buildLinker() const override;
 
 private:
   clang::driver::Tool *getTranslator() const;
Index: clang/lib/Driver/ToolChains/SPIRV.cpp
===
--- clang/lib/Driver/ToolChains/SPIRV.cpp
+++ clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -70,3 +70,25 @@
   }
   return ToolChain::getTool(AC);
 }
+clang::driver::Tool *SPIRVToolChain::buildLinker() const {
+  return new tools::SPIRV::Linker(*this);
+}
+
+void SPIRV::Linker::ConstructJob(Compilation , const JobAction ,
+  const InputInfo ,
+  const InputInfoList ,
+  const ArgList ,
+  const char *LinkingOutput) const {
+  const ToolChain  = getToolChain();
+  const Driver  = ToolChain.getDriver();
+  std::string Linker = ToolChain.GetProgramPath(getShortName());
+  ArgStringList CmdArgs;
+  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+
+  CmdArgs.push_back("-o");
+  CmdArgs.push_back(Output.getFilename());
+
+  C.addCommand(std::make_unique(
+  JA, *this, ResponseFileSupport::None(), Args.MakeArgString(Linker),
+  CmdArgs, Inputs, Output));
+}
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3725,14 +3725,6 @@
 }
   }
 
-  // FIXME: Linking separate translation units for SPIR-V is not supported yet.
-  // It can be done either by LLVM IR linking before conversion of the final
-  // linked module to SPIR-V or external SPIR-V linkers can be used e.g.
-  // spirv-link.
-  if (C.getDefaultToolChain().getTriple().isSPIRV() && Inputs.size() > 1) {
-Diag(clang::diag::warn_drv_spirv_linking_multiple_inputs_unsupported);
-  }
-
   handleArguments(C, Args, Inputs, Actions);
 
   // Builder to be used to build offloading actions.
@@ -3772,15 +3764,8 @@
   // Queue linker inputs.
   if (Phase == phases::Link) {
 assert(Phase == PL.back() && "linking must be final compilation step.");
-// Compilation phases are setup per language, however for SPIR-V the
-// final linking phase is meaningless since the compilation phase
-

[PATCH] D116221: [AArch64][ARM][Clang] Unaligned Access Warning Added

2021-12-24 Thread Mubashar Ahmad via Phabricator via cfe-commits
mubashar_ updated this revision to Diff 396151.
mubashar_ edited the summary of this revision.
mubashar_ added a comment.

Cleaned up code to make it more clang format friendly. Added another test suite 
in C.


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

https://reviews.llvm.org/D116221

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.h
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Sema/test-wunaligned-access.c
  clang/test/Sema/test-wunaligned-access.cpp

Index: clang/test/Sema/test-wunaligned-access.cpp
===
--- /dev/null
+++ clang/test/Sema/test-wunaligned-access.cpp
@@ -0,0 +1,285 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wunaligned-access
+
+// Packed-Unpacked Tests (No Pragma)
+
+struct T1 {
+  char a;
+  int b;
+};
+
+struct __attribute__((packed)) U1 // Causes warning
+{
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U1' has an alignment greater than its parent this may be caused by 'U1' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((packed)) U2 // No warning
+{
+  char a;
+  T1 b __attribute__((aligned(4)));
+  int c;
+};
+
+struct __attribute__((packed)) U3 // No warning
+{
+  char a;
+  char b;
+  short c;
+  T1 d;
+};
+
+struct __attribute__((packed)) U4 // No warning
+{
+  T1 a;
+  int b;
+};
+
+struct __attribute__((aligned(4), packed)) U5 // Causes warning
+{
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U5' has an alignment greater than its parent this may be caused by 'U5' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((aligned(4), packed)) U6 // No warning
+{
+  char a;
+  char b;
+  short c;
+  T1 d;
+};
+
+// Packed-Unpacked Tests with Pragma
+
+#pragma pack(push, 1)
+
+struct __attribute__((packed)) U7 // Causes warning
+{
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U7' has an alignment greater than its parent this may be caused by 'U7' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((packed)) U8 {
+  char a;
+  T1 b __attribute__((aligned(4))); // expected-warning {{field b within its parent 'U8' has an alignment greater than its parent this may be caused by 'U8' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct __attribute__((aligned(4))) U9 {
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U9' has an alignment greater than its parent this may be caused by 'U9' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+struct U10 {
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'U10' has an alignment greater than its parent this may be caused by 'U10' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+#pragma pack(pop)
+
+// Packed-Packed Tests
+
+struct __attribute__((packed)) T2 {
+  char a;
+  int b;
+};
+
+struct __attribute__((packed)) U11 {
+  char a;
+  T2 b;
+  int c;
+};
+
+#pragma pack(push, 1)
+struct U12 // No warning
+{
+  char a;
+  T2 b;
+  int c;
+};
+#pragma pack(pop)
+
+// Unpacked-Packed Tests
+
+struct U13 // No warning
+{
+  char a;
+  T2 b;
+  int c;
+};
+
+struct U14 // No warning
+{
+  char a;
+  T2 b __attribute__((aligned(4)));
+  int c;
+};
+
+// Unpacked-Unpacked Test
+
+struct T3 {
+  char a;
+  int b;
+};
+
+struct U15 // No warning
+{
+  char a;
+  T3 b;
+  int c;
+};
+
+// Packed-Packed-Unpacked Test (No pragma)
+
+struct __attribute__((packed)) A1 {
+  char a;
+  T1 b; // expected-warning {{field b within its parent 'A1' has an alignment greater than its parent this may be caused by 'A1' being packed and can lead to unaligned accesses}}
+};
+
+struct __attribute__((packed)) U16 // No warning
+{
+  char a;
+  A1 b;
+  int c;
+};
+
+struct __attribute__((packed)) A2 // No warning
+{
+  char a;
+  T1 b __attribute__((aligned(4)));
+};
+
+struct __attribute__((packed)) U17 // Caused warning
+{
+  char a;
+  A2 b; // expected-warning {{field b within its parent 'U17' has an alignment greater than its parent this may be caused by 'U17' being packed and can lead to unaligned accesses}}
+  int c;
+};
+
+// Packed-Unpacked-Packed tests
+
+struct A3 {
+  char a;
+  T2 b;
+};
+
+struct __attribute__((packed)) U18 {
+  char a;
+  A3 b;
+  int c;
+};
+
+struct A4 {
+  char a;
+  T2 b;
+  int c;
+};
+
+#pragma pack(push, 1)
+struct U19 // Caused warning
+{
+  char a;
+  A4 b; // expected-warning {{field b within its parent 'U19' has an alignment greater than its parent this may be caused by 'U19' being packed and can lead to unaligned accesses}}
+  int c;
+};
+#pragma pack(pop)
+
+// Packed-Unpacked-Unpacked tests
+
+struct A5 {
+  char a;
+  T1 b;
+};
+
+struct 

[PATCH] D112410: [SPIR-V] Add a toolchain for SPIR-V in clang

2021-12-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D112410#3208353 , @MaskRay wrote:

> I slightly adjusted the test in eafc64ed6325eba962096d4a947d7e45e909bfde 
>  :)
>
> `-no-canonical-prefixes` can usually be omitted.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112410

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


[clang] 969a51f - Revert "[ASan] Moved optimized callbacks into a separate library."

2021-12-24 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2021-12-24T12:01:36+01:00
New Revision: 969a51ff363263a3b5f2df55eba6b4d392bf30c0

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

LOG: Revert "[ASan] Moved optimized callbacks into a separate library."

We need some internal updates for this, shared directly with the author.

This reverts commit 71b3bfde9cd296525bbf5b1619e199074156d12b.

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/sanitizer-ld.c
compiler-rt/lib/asan/CMakeLists.txt
compiler-rt/lib/asan/tests/CMakeLists.txt

Removed: 
compiler-rt/lib/asan/asan_rtl_static.cpp



diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 267625c70b251..407f81a2ae09a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -826,11 +826,6 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
   if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
 StaticRuntimes.push_back("stats_client");
 
-  // Always link the static runtime regardless of DSO or executable.
-  if (SanArgs.needsAsanRt()) {
-HelperStaticRuntimes.push_back("asan_static");
-  }
-
   // Collect static runtimes.
   if (Args.hasArg(options::OPT_shared)) {
 // Don't link static runtimes into DSOs.

diff  --git a/clang/test/Driver/sanitizer-ld.c 
b/clang/test/Driver/sanitizer-ld.c
index ea8c49f2384ad..d62e19fd4021b 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -22,7 +22,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
 //
-// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
+// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address 
-shared-libsan \

diff  --git a/compiler-rt/lib/asan/CMakeLists.txt 
b/compiler-rt/lib/asan/CMakeLists.txt
index b79b7278f6dbb..2e63c8d051688 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -34,6 +34,7 @@ set(ASAN_SOURCES
 
 if (NOT WIN32 AND NOT APPLE)
   list(APPEND ASAN_SOURCES
+asan_rtl_x86_64.S
 asan_interceptors_vfork.S
 )
 endif()
@@ -42,16 +43,6 @@ set(ASAN_CXX_SOURCES
   asan_new_delete.cpp
   )
 
-set(ASAN_STATIC_SOURCES
-  asan_rtl_static.cpp
-  )
-
-if (NOT WIN32 AND NOT APPLE)
-  list(APPEND ASAN_STATIC_SOURCES
-asan_rtl_x86_64.S
-  )
-endif()
-
 set(ASAN_PREINIT_SOURCES
   asan_preinit.cpp
   )
@@ -144,12 +135,6 @@ if(NOT APPLE)
 ADDITIONAL_HEADERS ${ASAN_HEADERS}
 CFLAGS ${ASAN_CFLAGS}
 DEFS ${ASAN_COMMON_DEFINITIONS})
-  add_compiler_rt_object_libraries(RTAsan_static
-ARCHS ${ASAN_SUPPORTED_ARCH}
-SOURCES ${ASAN_STATIC_SOURCES}
-ADDITIONAL_HEADERS ${ASAN_HEADERS}
-CFLAGS ${ASAN_CFLAGS}
-DEFS ${ASAN_COMMON_DEFINITIONS})
   add_compiler_rt_object_libraries(RTAsan_preinit
 ARCHS ${ASAN_SUPPORTED_ARCH}
 SOURCES ${ASAN_PREINIT_SOURCES}
@@ -191,14 +176,6 @@ if(APPLE)
 LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
 DEFS ${ASAN_DYNAMIC_DEFINITIONS}
 PARENT_TARGET asan)
-
-  add_compiler_rt_runtime(clang_rt.asan_static
-STATIC
-ARCHS ${ASAN_SUPPORTED_ARCH}
-OBJECT_LIBS RTAsan_static
-CFLAGS ${ASAN_CFLAGS}
-DEFS ${ASAN_COMMON_DEFINITIONS}
-PARENT_TARGET asan)
 else()
   # Build separate libraries for each target.
 
@@ -230,14 +207,6 @@ else()
 DEFS ${ASAN_COMMON_DEFINITIONS}
 PARENT_TARGET asan)
 
-  add_compiler_rt_runtime(clang_rt.asan_static
-STATIC
-ARCHS ${ASAN_SUPPORTED_ARCH}
-OBJECT_LIBS RTAsan_static
-CFLAGS ${ASAN_CFLAGS}
-DEFS ${ASAN_COMMON_DEFINITIONS}
-PARENT_TARGET asan)
-
   add_compiler_rt_runtime(clang_rt.asan-preinit
 STATIC
 ARCHS ${ASAN_SUPPORTED_ARCH}

diff  --git a/compiler-rt/lib/asan/asan_rtl_static.cpp 
b/compiler-rt/lib/asan/asan_rtl_static.cpp
deleted file mode 100644
index 74e6eb0ddf1cf..0
--- a/compiler-rt/lib/asan/asan_rtl_static.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-//===-- asan_static_rtl.cpp 
---===//
-//
-// 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
-//
-//===--===//
-//
-// This file is a part of AddressSanitizer, an address sanity checker.
-//
-// Main file of the ASan run-time library.
-//===--===//
-
-// This file is empty 

[PATCH] D115124: [clang-tidy] Fix `readability-container-size-empty` check for smart pointers

2021-12-24 Thread gehry via Phabricator via cfe-commits
Sockke requested changes to this revision.
Sockke added a comment.
This revision now requires changes to proceed.

Could you please add a test case where the smart pointer object is dereferenced 
before calling `size()`? E.g. `return (*ptr).size() == 0;`. I think this change 
doesn't work on this test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115124

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


[PATCH] D116161: [Clang] Add an overload for emitUnaryBuiltin.

2021-12-24 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

I don't know why but these will cause tests to fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116161

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


[PATCH] D116090: [X86][MS-InlineAsm] Use exact conditions to recognize MS global variables

2021-12-24 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24c68ea1eb4f: Reland [X86][MS-InlineAsm] Use exact 
conditions to recognize MS global… (authored by pengfei).

Changed prior to commit:
  https://reviews.llvm.org/D116090?vs=395962=396145#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116090

Files:
  clang/test/CodeGen/ms-inline-asm-functions.c
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  llvm/lib/Target/X86/AsmParser/X86Operand.h


Index: llvm/lib/Target/X86/AsmParser/X86Operand.h
===
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -286,10 +286,9 @@
   bool isOffsetOfLocal() const override { return isImm() && Imm.LocalRef; }
 
   bool isMemPlaceholder(const MCInstrDesc ) const override {
-// Add more restrictions to avoid the use of global symbols. This helps
-// with reducing the code size.
-return !Desc.isRematerializable() && !Desc.isCall() && isMem() &&
-   !Mem.BaseReg && !Mem.IndexReg;
+// Only MS InlineAsm uses global variables with registers rather than
+// rip/eip.
+return isMem() && !Mem.DefaultBaseReg && Mem.FrontendSize;
   }
 
   bool needAddressOf() const override { return AddressOf; }
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1759,7 +1759,8 @@
   // registers in a mmory expression, and though unaccessible via rip/eip.
   if (IsGlobalLV && (BaseReg || IndexReg)) {
 Operands.push_back(X86Operand::CreateMem(getPointerWidth(), Disp, Start,
- End, Size, Identifier, Decl));
+ End, Size, Identifier, Decl,
+ FrontendSize));
 return false;
   }
   // Otherwise, we set the base register to a non-zero value
Index: clang/test/CodeGen/ms-inline-asm-functions.c
===
--- clang/test/CodeGen/ms-inline-asm-functions.c
+++ clang/test/CodeGen/ms-inline-asm-functions.c
@@ -39,7 +39,7 @@
 int baz() {
   // CHECK-LABEL: _baz:
   __asm mov eax, k;
-  // CHECK: movlk, %eax
+  // CHECK: movl_k, %eax
   __asm mov eax, kptr;
   // CHECK: movl_kptr, %eax
 }


Index: llvm/lib/Target/X86/AsmParser/X86Operand.h
===
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -286,10 +286,9 @@
   bool isOffsetOfLocal() const override { return isImm() && Imm.LocalRef; }
 
   bool isMemPlaceholder(const MCInstrDesc ) const override {
-// Add more restrictions to avoid the use of global symbols. This helps
-// with reducing the code size.
-return !Desc.isRematerializable() && !Desc.isCall() && isMem() &&
-   !Mem.BaseReg && !Mem.IndexReg;
+// Only MS InlineAsm uses global variables with registers rather than
+// rip/eip.
+return isMem() && !Mem.DefaultBaseReg && Mem.FrontendSize;
   }
 
   bool needAddressOf() const override { return AddressOf; }
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1759,7 +1759,8 @@
   // registers in a mmory expression, and though unaccessible via rip/eip.
   if (IsGlobalLV && (BaseReg || IndexReg)) {
 Operands.push_back(X86Operand::CreateMem(getPointerWidth(), Disp, Start,
- End, Size, Identifier, Decl));
+ End, Size, Identifier, Decl,
+ FrontendSize));
 return false;
   }
   // Otherwise, we set the base register to a non-zero value
Index: clang/test/CodeGen/ms-inline-asm-functions.c
===
--- clang/test/CodeGen/ms-inline-asm-functions.c
+++ clang/test/CodeGen/ms-inline-asm-functions.c
@@ -39,7 +39,7 @@
 int baz() {
   // CHECK-LABEL: _baz:
   __asm mov eax, k;
-  // CHECK: movlk, %eax
+  // CHECK: movl_k, %eax
   __asm mov eax, kptr;
   // CHECK: movl_kptr, %eax
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 24c68ea - Reland "[X86][MS-InlineAsm] Use exact conditions to recognize MS global variables"

2021-12-24 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2021-12-24T17:42:51+08:00
New Revision: 24c68ea1eb4fc0d0e782424ddb02da9e8c53ddf5

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

LOG: Reland "[X86][MS-InlineAsm] Use exact conditions to recognize MS global 
variables"

This reverts commit a954558e878ed9e97e99036229e99af8c6b6c881.

Thanks Yuanfang's help. I think I found the root cause of the buildbot
fail.

The failed test has both Memory and Immediate X86Operand. All data of
different operand kinds share the same memory space by a union
definition. So it has chance we get the wrong result if we don't check
the operand kind.

It's probably it happen to be the correct value in my local environment
so that I can't reproduce the fail.

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

Added: 


Modified: 
clang/test/CodeGen/ms-inline-asm-functions.c
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/lib/Target/X86/AsmParser/X86Operand.h

Removed: 




diff  --git a/clang/test/CodeGen/ms-inline-asm-functions.c 
b/clang/test/CodeGen/ms-inline-asm-functions.c
index c958d88038716..1a6ead9286dff 100644
--- a/clang/test/CodeGen/ms-inline-asm-functions.c
+++ b/clang/test/CodeGen/ms-inline-asm-functions.c
@@ -39,7 +39,7 @@ int bar() {
 int baz() {
   // CHECK-LABEL: _baz:
   __asm mov eax, k;
-  // CHECK: movlk, %eax
+  // CHECK: movl_k, %eax
   __asm mov eax, kptr;
   // CHECK: movl_kptr, %eax
 }

diff  --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp 
b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 6bae55695f3d8..2ba0b97229cc6 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1759,7 +1759,8 @@ bool X86AsmParser::CreateMemForMSInlineAsm(
   // registers in a mmory expression, and though unaccessible via rip/eip.
   if (IsGlobalLV && (BaseReg || IndexReg)) {
 Operands.push_back(X86Operand::CreateMem(getPointerWidth(), Disp, Start,
- End, Size, Identifier, Decl));
+ End, Size, Identifier, Decl,
+ FrontendSize));
 return false;
   }
   // Otherwise, we set the base register to a non-zero value

diff  --git a/llvm/lib/Target/X86/AsmParser/X86Operand.h 
b/llvm/lib/Target/X86/AsmParser/X86Operand.h
index 6d20c6af5fd2c..67b1244708a8c 100644
--- a/llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ b/llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -286,10 +286,9 @@ struct X86Operand final : public MCParsedAsmOperand {
   bool isOffsetOfLocal() const override { return isImm() && Imm.LocalRef; }
 
   bool isMemPlaceholder(const MCInstrDesc ) const override {
-// Add more restrictions to avoid the use of global symbols. This helps
-// with reducing the code size.
-return !Desc.isRematerializable() && !Desc.isCall() && isMem() &&
-   !Mem.BaseReg && !Mem.IndexReg;
+// Only MS InlineAsm uses global variables with registers rather than
+// rip/eip.
+return isMem() && !Mem.DefaultBaseReg && Mem.FrontendSize;
   }
 
   bool needAddressOf() const override { return AddressOf; }



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


[PATCH] D116161: [Clang] Add an overload for emitUnaryBuiltin.

2021-12-24 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3137
 else
   Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, 
nullptr,
 "elt.abs");

Should also be used here?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3193
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Result = Builder.CreateUnaryIntrinsic(
 GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()), Op0, nullptr,

Should also be used here?




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3212
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Result = Builder.CreateUnaryIntrinsic(
 GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()), Op0, nullptr,

Should also be used here?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116161

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


[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2021-12-24 Thread Zhao Wei Liew via Phabricator via cfe-commits
zwliew added a comment.

On further thought, the logic for `loadConfigFile()` looks incomplete. It does 
not properly handle the `InheritParentConfig` argument for `BasedOnStyle`. In 
fact, `loadConfigFile()` should probably use the same logic as that for 
`-style=file`. I can look into making this change, and possibly refactoring the 
code to reduce code duplication.


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

https://reviews.llvm.org/D72326

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


[PATCH] D116264: [clang] adds `__remove_cvref` as a compiler buiilt-in

2021-12-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added a reviewer: aaron.ballman.
Herald added a subscriber: dexonsmith.
cjdb 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/D116264

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/remove_cvref.cpp

Index: clang/test/SemaCXX/remove_cvref.cpp
===
--- clang/test/SemaCXX/remove_cvref.cpp
+++ clang/test/SemaCXX/remove_cvref.cpp
@@ -12,6 +12,16 @@
 static_assert(__is_same(__remove_reference(const T&&), const T), "");
 static_assert(__is_same(__remove_reference(volatile T&&), volatile T), "");
 static_assert(__is_same(__remove_reference(const volatile T&&), const volatile T), "");
+
+static_assert(__is_same(__remove_cvref(T&), T), "");
+static_assert(__is_same(__remove_cvref(const T&), T), "");
+static_assert(__is_same(__remove_cvref(volatile T&), T), "");
+static_assert(__is_same(__remove_cvref(const volatile T&), T), "");
+
+static_assert(__is_same(__remove_cvref(T&&), T), "");
+static_assert(__is_same(__remove_cvref(const T&&), T), "");
+static_assert(__is_same(__remove_cvref(volatile T&&), T), "");
+static_assert(__is_same(__remove_cvref(const volatile T&&), T), "");
   }
 };
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1271,6 +1271,8 @@
 return UnaryTransformType::RemoveConst;
   case TST_remove_cv:
 return UnaryTransformType::RemoveCV;
+  case TST_remove_cvref:
+return UnaryTransformType::RemoveCVRef;
   case TST_remove_reference:
 return UnaryTransformType::RemoveReference;
   case TST_remove_volatile:
@@ -1670,6 +1672,7 @@
   case DeclSpec::TST_add_volatile:
   case DeclSpec::TST_remove_const:
   case DeclSpec::TST_remove_cv:
+  case DeclSpec::TST_remove_cvref:
   case DeclSpec::TST_remove_reference:
   case DeclSpec::TST_remove_volatile:
 Result = S.GetTypeFromParser(DS.getRepAsType());
@@ -9099,10 +9102,19 @@
   return Context.getUnaryTransformType(BaseType, Underlying,
 UnaryTransformType::EnumUnderlyingType);
 }
+  case UnaryTransformType::RemoveCVRef:
   case UnaryTransformType::RemoveReference: {
 QualType Underlying = BaseType.getNonReferenceType();
-return Context.getUnaryTransformType(BaseType, Underlying,
- UnaryTransformType::RemoveReference);
+Qualifiers Quals = Underlying.getQualifiers();
+if (UKind == UnaryTransformType::RemoveCVRef) {
+  Quals.removeConst();
+  Quals.removeVolatile();
+}
+return Context.getUnaryTransformType(
+BaseType,
+QualType(Underlying.getSplitUnqualifiedType().Ty,
+ Quals.getAsOpaqueValue()),
+UKind);
   }
   case UnaryTransformType::AddConst:
   case UnaryTransformType::AddCV:
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -866,6 +866,7 @@
   case TST_add_volatile:
   case TST_remove_const:
   case TST_remove_cv:
+  case TST_remove_cvref:
   case TST_remove_reference:
   case TST_remove_volatile:
   case TST_atomic: {
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -150,6 +150,7 @@
   case tok::kw___add_volatile:
   case tok::kw___remove_const:
   case tok::kw___remove_cv:
+  case tok::kw___remove_cvref:
   case tok::kw___remove_reference:
   case tok::kw___remove_volatile:
   case tok::kw___auto_type:
@@ -5611,6 +5612,7 @@
   case DeclSpec::TST_add_volatile:
   case DeclSpec::TST_remove_const:
   case DeclSpec::TST_remove_cv:
+  case DeclSpec::TST_remove_cvref:
   case DeclSpec::TST_remove_reference:
   case DeclSpec::TST_remove_volatile:
   case DeclSpec::TST_atomic: {
Index: clang/lib/Sema/DeclSpec.cpp
===
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -396,6 +396,7 @@
 case TST_add_volatile:
 case TST_remove_const:
 case TST_remove_cv:
+case TST_remove_cvref:
 case TST_remove_reference:
 case TST_remove_volatile:
 

[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2021-12-24 Thread Zhao Wei Liew via Phabricator via cfe-commits
zwliew added a comment.

Hi, I'd like to help to get this patch accepted and merged. I have a few 
suggestions/questions below, and I can help make any changes to the patch if 
needed!




Comment at: clang/docs/ClangFormatStyleOptions.rst:35
 
+When using ``-style=file:, :program:`clang-format` for 
+each input file will use the format file located at ``.

I think two backticks are missing here.



Comment at: clang/include/clang/Format/Format.h:4068
 /// directory if ``FileName`` is empty.
+/// * "file:" to explicitly specify the configuration file to use.
 ///

To be consistent with the `ClangFormatOptions.rst` docs, I think `configfile` 
should be changed to `format_file_path`.



Comment at: clang/lib/Format/Format.cpp:3166
 "directory for stdin).\n"
+"Use -style=file: to explicitly specify"
+"the configuration file.\n"

Similar to above, `configfile` should be changed to `format_file_path`.



Comment at: clang/lib/Format/Format.cpp:3219
+   llvm::vfs::FileSystem *FS,
+   bool *IsSuitable) {
+  FormatStyle Style = getLLVMStyle();

I think `LoadConfigFile` could be refactored to return `std::error_code` 
instead, similar to `parseConfiguration()`, like so:

```
// note I renamed LoadConfigFile to loadConfigFile to follow the existing 
function naming style.
std::error_code loadConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS, 
FormatStyle *Style) {
llvm::ErrorOr> Text = 
FS->getBufferForFile(ConfigFile.str());
if (auto ec = Text.getError()) {
return ec;
}
return parseConfiguration(Text.get()->getBuffer(), Style);
}
```

And the part in `getStyle()` would look like this:
```
// Check for explicit config filename
if (StyleName.startswith_insensitive("file:")) {
auto StyleFileName = StyleName.substr(5);
if (auto ec = loadConfigFile(StyleFileName, FS, )) {
return make_string_error(ec.message());
}
LLVM_DEBUG(llvm::dbgs() << "Using configuration file " << StyleFileName << 
'\n');
return Style;
}
```

What do you think?



Comment at: clang/lib/Format/Format.cpp:3273
 
+  llvm::SmallVector FilesToLookFor;
+  // User provided clang-format file using -style=file:/path/to/format/file

HazardyKnusperkeks wrote:
> Why move that, it it's not used here?
Yup, I think this shouldn't be moved.



Comment at: clang/lib/Format/Format.cpp:3276
+  // Check for explicit config filename
+  if (StyleName.startswith_insensitive("file:")) {
+auto StyleNameFile = StyleName.substr(5);

Following my code suggestion above, I think this code block could be refactored 
to this: 
```
// Check for explicit config filename
if (StyleName.startswith_insensitive("file:")) {
auto StyleFileName = StyleName.substr(5);
if (auto ec = loadConfigFile(StyleFileName, FS, )) {
return make_string_error(ec.message());
}
LLVM_DEBUG(llvm::dbgs() << "Using configuration file " << StyleFileName << 
'\n');
return Style;
}
```

What do you think?

Also, on another note, I feel like the `-style` option is too overloaded. Would 
it be better to use a separate option like `-style-file` instead?



Comment at: clang/lib/Format/Format.cpp:2693
+   llvm::vfs::FileSystem *FS,
+   bool *IsSuitable) {
+  FormatStyle Style = getLLVMStyle();

MyDeveloperDay wrote:
> pass Style in, don't keep assuming LLVM
I think it's still a good idea to pass Style into the function instead.


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

https://reviews.llvm.org/D72326

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


[PATCH] D116161: [Clang] Add an overload for emitUnaryBuiltin.

2021-12-24 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 396140.
junaire added a comment.

Fix wrong usage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116161

Files:
  clang/lib/CodeGen/CGBuiltin.cpp


Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -541,6 +541,12 @@
   return CGF.Builder.CreateCall(F, Src0);
 }
 
+static Value *emitUnaryBuiltin(CodeGenFunction , const CallExpr *E,
+   unsigned IntrinsicID, llvm::StringRef Name) {
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+  return CGF.Builder.CreateUnaryIntrinsic(IntrinsicID, Src0, nullptr, Name);
+}
+
 // Emit an intrinsic that has 2 operands of the same type as its result.
 static Value *emitBinaryBuiltin(CodeGenFunction ,
 const CallExpr *E,
@@ -3130,16 +3136,14 @@
 else
   Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, 
nullptr,
 "elt.abs");
-return RValue::get(Result);
-  }
 
-  case Builtin::BI__builtin_elementwise_ceil: {
-Value *Op0 = EmitScalarExpr(E->getArg(0));
-Value *Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::ceil, Op0,
- nullptr, "elt.ceil");
 return RValue::get(Result);
   }
 
+  case Builtin::BI__builtin_elementwise_ceil:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::ceil, "elt.ceil"));
+
   case Builtin::BI__builtin_elementwise_max: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
@@ -3211,12 +3215,9 @@
 return RValue::get(Result);
   }
 
-  case Builtin::BI__builtin_reduce_xor: {
-Value *Op0 = EmitScalarExpr(E->getArg(0));
-Value *Result = Builder.CreateUnaryIntrinsic(
-llvm::Intrinsic::vector_reduce_xor, Op0, nullptr, "rdx.xor");
-return RValue::get(Result);
-  }
+  case Builtin::BI__builtin_reduce_xor:
+return RValue::get(emitUnaryBuiltin(
+*this, E, llvm::Intrinsic::vector_reduce_xor, "rdx.xor"));
 
   case Builtin::BI__builtin_matrix_transpose: {
 const auto *MatrixTy = 
E->getArg(0)->getType()->getAs();


Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -541,6 +541,12 @@
   return CGF.Builder.CreateCall(F, Src0);
 }
 
+static Value *emitUnaryBuiltin(CodeGenFunction , const CallExpr *E,
+   unsigned IntrinsicID, llvm::StringRef Name) {
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+  return CGF.Builder.CreateUnaryIntrinsic(IntrinsicID, Src0, nullptr, Name);
+}
+
 // Emit an intrinsic that has 2 operands of the same type as its result.
 static Value *emitBinaryBuiltin(CodeGenFunction ,
 const CallExpr *E,
@@ -3130,16 +3136,14 @@
 else
   Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, nullptr,
 "elt.abs");
-return RValue::get(Result);
-  }
 
-  case Builtin::BI__builtin_elementwise_ceil: {
-Value *Op0 = EmitScalarExpr(E->getArg(0));
-Value *Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::ceil, Op0,
- nullptr, "elt.ceil");
 return RValue::get(Result);
   }
 
+  case Builtin::BI__builtin_elementwise_ceil:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::ceil, "elt.ceil"));
+
   case Builtin::BI__builtin_elementwise_max: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
@@ -3211,12 +3215,9 @@
 return RValue::get(Result);
   }
 
-  case Builtin::BI__builtin_reduce_xor: {
-Value *Op0 = EmitScalarExpr(E->getArg(0));
-Value *Result = Builder.CreateUnaryIntrinsic(
-llvm::Intrinsic::vector_reduce_xor, Op0, nullptr, "rdx.xor");
-return RValue::get(Result);
-  }
+  case Builtin::BI__builtin_reduce_xor:
+return RValue::get(emitUnaryBuiltin(
+*this, E, llvm::Intrinsic::vector_reduce_xor, "rdx.xor"));
 
   case Builtin::BI__builtin_matrix_transpose: {
 const auto *MatrixTy = E->getArg(0)->getType()->getAs();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116214: [OpenMP] Avoid creating null pointer lvalue (NFC)

2021-12-24 Thread Nikita Popov 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 rGdd903173c0fb: [OpenMP] Avoid creating null pointer lvalue 
(NFC) (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116214

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp

Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1247,7 +1247,7 @@
 RedCG.emitAggregateType(*this, Count);
 AutoVarEmission Emission = EmitAutoVarAlloca(*PrivateVD);
 RedCG.emitInitialization(*this, Count, Emission.getAllocatedAddress(),
- RedCG.getSharedLValue(Count),
+ RedCG.getSharedLValue(Count).getAddress(*this),
  [](CodeGenFunction ) {
CGF.EmitAutoVarInit(Emission);
return true;
Index: clang/lib/CodeGen/CGOpenMPRuntime.h
===
--- clang/lib/CodeGen/CGOpenMPRuntime.h
+++ clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -162,10 +162,10 @@
   /// Performs aggregate initialization.
   /// \param N Number of reduction item in the common list.
   /// \param PrivateAddr Address of the corresponding private item.
-  /// \param SharedLVal Address of the original shared variable.
+  /// \param SharedAddr Address of the original shared variable.
   /// \param DRD Declare reduction construct used for reduction item.
   void emitAggregateInitialization(CodeGenFunction , unsigned N,
-   Address PrivateAddr, LValue SharedLVal,
+   Address PrivateAddr, Address SharedAddr,
const OMPDeclareReductionDecl *DRD);
 
 public:
@@ -187,10 +187,10 @@
   /// \param PrivateAddr Address of the corresponding private item.
   /// \param DefaultInit Default initialization sequence that should be
   /// performed if no reduction specific initialization is found.
-  /// \param SharedLVal Address of the original shared variable.
+  /// \param SharedAddr Address of the original shared variable.
   void
   emitInitialization(CodeGenFunction , unsigned N, Address PrivateAddr,
- LValue SharedLVal,
+ Address SharedAddr,
  llvm::function_ref DefaultInit);
   /// Returns true if the private copy requires cleanups.
   bool needCleanups(unsigned N);
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -774,7 +774,7 @@
 }
 
 void ReductionCodeGen::emitAggregateInitialization(
-CodeGenFunction , unsigned N, Address PrivateAddr, LValue SharedLVal,
+CodeGenFunction , unsigned N, Address PrivateAddr, Address SharedAddr,
 const OMPDeclareReductionDecl *DRD) {
   // Emit VarDecl with copy init for arrays.
   // Get the address of the original variable captured in current
@@ -787,7 +787,7 @@
EmitDeclareReductionInit,
EmitDeclareReductionInit ? ClausesData[N].ReductionOp
 : PrivateVD->getInit(),
-   DRD, SharedLVal.getAddress(CGF));
+   DRD, SharedAddr);
 }
 
 ReductionCodeGen::ReductionCodeGen(ArrayRef Shareds,
@@ -881,7 +881,7 @@
 }
 
 void ReductionCodeGen::emitInitialization(
-CodeGenFunction , unsigned N, Address PrivateAddr, LValue SharedLVal,
+CodeGenFunction , unsigned N, Address PrivateAddr, Address SharedAddr,
 llvm::function_ref DefaultInit) {
   assert(SharedAddresses.size() > N && "No variable was generated");
   const auto *PrivateVD =
@@ -891,21 +891,15 @@
   QualType PrivateType = PrivateVD->getType();
   PrivateAddr = CGF.Builder.CreateElementBitCast(
   PrivateAddr, CGF.ConvertTypeForMem(PrivateType));
-  QualType SharedType = SharedAddresses[N].first.getType();
-  SharedLVal = CGF.MakeAddrLValue(
-  CGF.Builder.CreateElementBitCast(SharedLVal.getAddress(CGF),
-   CGF.ConvertTypeForMem(SharedType)),
-  SharedType, SharedAddresses[N].first.getBaseInfo(),
-  CGF.CGM.getTBAAInfoForSubobject(SharedAddresses[N].first, SharedType));
   if (CGF.getContext().getAsArrayType(PrivateVD->getType())) {
 if (DRD && DRD->getInitializer())
   (void)DefaultInit(CGF);
-emitAggregateInitialization(CGF, N, PrivateAddr, SharedLVal, DRD);
+emitAggregateInitialization(CGF, N, PrivateAddr, SharedAddr, DRD);
   } else if (DRD 

[clang] dd90317 - [OpenMP] Avoid creating null pointer lvalue (NFC)

2021-12-24 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2021-12-24T09:01:56+01:00
New Revision: dd903173c0fb9ead398b8b516f0672d30d25b120

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

LOG: [OpenMP] Avoid creating null pointer lvalue (NFC)

The reduction initialization code creates a "naturally aligned null
pointer to void lvalue", which I found somewhat odd, even though it
works out in the end because it is not actually used. It doesn't
look like this code actually needs an LValue for anything though,
and we can use an invalid Address to represent this case instead.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 03aa84aecef44..0c71fee140259 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -774,7 +774,7 @@ LValue ReductionCodeGen::emitSharedLValueUB(CodeGenFunction 
,
 }
 
 void ReductionCodeGen::emitAggregateInitialization(
-CodeGenFunction , unsigned N, Address PrivateAddr, LValue SharedLVal,
+CodeGenFunction , unsigned N, Address PrivateAddr, Address SharedAddr,
 const OMPDeclareReductionDecl *DRD) {
   // Emit VarDecl with copy init for arrays.
   // Get the address of the original variable captured in current
@@ -787,7 +787,7 @@ void ReductionCodeGen::emitAggregateInitialization(
EmitDeclareReductionInit,
EmitDeclareReductionInit ? ClausesData[N].ReductionOp
 : PrivateVD->getInit(),
-   DRD, SharedLVal.getAddress(CGF));
+   DRD, SharedAddr);
 }
 
 ReductionCodeGen::ReductionCodeGen(ArrayRef Shareds,
@@ -881,7 +881,7 @@ void ReductionCodeGen::emitAggregateType(CodeGenFunction 
, unsigned N,
 }
 
 void ReductionCodeGen::emitInitialization(
-CodeGenFunction , unsigned N, Address PrivateAddr, LValue SharedLVal,
+CodeGenFunction , unsigned N, Address PrivateAddr, Address SharedAddr,
 llvm::function_ref DefaultInit) {
   assert(SharedAddresses.size() > N && "No variable was generated");
   const auto *PrivateVD =
@@ -891,21 +891,15 @@ void ReductionCodeGen::emitInitialization(
   QualType PrivateType = PrivateVD->getType();
   PrivateAddr = CGF.Builder.CreateElementBitCast(
   PrivateAddr, CGF.ConvertTypeForMem(PrivateType));
-  QualType SharedType = SharedAddresses[N].first.getType();
-  SharedLVal = CGF.MakeAddrLValue(
-  CGF.Builder.CreateElementBitCast(SharedLVal.getAddress(CGF),
-   CGF.ConvertTypeForMem(SharedType)),
-  SharedType, SharedAddresses[N].first.getBaseInfo(),
-  CGF.CGM.getTBAAInfoForSubobject(SharedAddresses[N].first, SharedType));
   if (CGF.getContext().getAsArrayType(PrivateVD->getType())) {
 if (DRD && DRD->getInitializer())
   (void)DefaultInit(CGF);
-emitAggregateInitialization(CGF, N, PrivateAddr, SharedLVal, DRD);
+emitAggregateInitialization(CGF, N, PrivateAddr, SharedAddr, DRD);
   } else if (DRD && (DRD->getInitializer() || !PrivateVD->hasInit())) {
 (void)DefaultInit(CGF);
+QualType SharedType = SharedAddresses[N].first.getType();
 emitInitWithReductionInitializer(CGF, DRD, ClausesData[N].ReductionOp,
- PrivateAddr, SharedLVal.getAddress(CGF),
- SharedLVal.getType());
+ PrivateAddr, SharedAddr, SharedType);
   } else if (!DefaultInit(CGF) && PrivateVD->hasInit() &&
  !CGF.isTrivialInitializer(PrivateVD->getInit())) {
 CGF.EmitAnyExprToMem(PrivateVD->getInit(), PrivateAddr,
@@ -5915,25 +5909,20 @@ static llvm::Value 
*emitReduceInitFunction(CodeGenModule ,
 CGM.getContext().getSizeType(), Loc);
   }
   RCG.emitAggregateType(CGF, N, Size);
-  LValue OrigLVal;
+  Address OrigAddr = Address::invalid();
   // If initializer uses initializer from declare reduction construct, emit a
   // pointer to the address of the original reduction item (reuired by 
reduction
   // initializer)
   if (RCG.usesReductionInitializer(N)) {
 Address SharedAddr = CGF.GetAddrOfLocalVar();
-SharedAddr = CGF.EmitLoadOfPointer(
+OrigAddr = CGF.EmitLoadOfPointer(
 SharedAddr,
 CGM.getContext().VoidPtrTy.castAs()->getTypePtr());
-OrigLVal = CGF.MakeAddrLValue(SharedAddr, CGM.getContext().VoidPtrTy);
-  } else {
-OrigLVal = CGF.MakeNaturalAlignAddrLValue(
-llvm::ConstantPointerNull::get(CGM.VoidPtrTy),
-CGM.getContext().VoidTy);
   }
   // Emit the