[PATCH] D113752: [Parse] Use empty RecoveryExpr when if/while/do/switch conditions fail to parse

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, this looks good (sorry, I missed this.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113752

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


[PATCH] D116859: Fix for: clang-format: break added to macro define with ColumnLimit: 0

2022-01-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:4811
+  verifyFormat("#define STRINGIFY(t) #t\n"
+   "#define MAKEVERSIONSTRING(x, y, z, build) STRINGIFY(x) \".\" 
STRINGIFY(y) \".\" STRINGIFY(z) \".\" STRINGIFY(build)\n",
+   ZeroColumn);

Can you fix this first


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116859

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


[clang] 5c2e7c9 - [clang-format] Ensure we can correctly parse lambda in the template argument list

2022-01-10 Thread via cfe-commits

Author: mydeveloperday
Date: 2022-01-10T08:29:35Z
New Revision: 5c2e7c9ca043d92bed75b08e653fb47c384edd13

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

LOG: [clang-format] Ensure we can correctly parse lambda in the template 
argument list

https://github.com/llvm/llvm-project/issues/46505

The presence of a lambda in an argument template list ignored the [] as a 
lambda at all, this caused the contents of the <> to be incorrectly analyzed.

```
struct Y : X < [] {
  return 0;
} > {};
```
Fixes: #46505

Reviewed By: curdeius

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c293c236193c0..410cce79a0876 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2874,6 +2874,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 if (!tryToParseBracedList())
   break;
   }
+  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
+break;
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 85ce3171bbc89..d3e4479a5aa84 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -23212,6 +23212,15 @@ TEST_F(FormatTest, EmptyShortBlock) {
Style);
 }
 
+TEST_F(FormatTest, ShortTemplatedArgumentLists) {
+  auto Style = getLLVMStyle();
+
+  verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
+  verifyFormat("struct Y<[] { return 0; }> {};", Style);
+
+  verifyFormat("struct Z : X {};", Style);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang



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


[PATCH] D116806: [clang-format] Ensure we can correctly parse lambda in the template argument list

2022-01-10 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c2e7c9ca043: [clang-format] Ensure we can correctly parse 
lambda in the template argument… (authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D116806?vs=398124&id=398521#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116806

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23212,6 +23212,15 @@
Style);
 }
 
+TEST_F(FormatTest, ShortTemplatedArgumentLists) {
+  auto Style = getLLVMStyle();
+
+  verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
+  verifyFormat("struct Y<[] { return 0; }> {};", Style);
+
+  verifyFormat("struct Z : X {};", Style);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2874,6 +2874,8 @@
 if (!tryToParseBracedList())
   break;
   }
+  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
+break;
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23212,6 +23212,15 @@
Style);
 }
 
+TEST_F(FormatTest, ShortTemplatedArgumentLists) {
+  auto Style = getLLVMStyle();
+
+  verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
+  verifyFormat("struct Y<[] { return 0; }> {};", Style);
+
+  verifyFormat("struct Z : X {};", Style);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2874,6 +2874,8 @@
 if (!tryToParseBracedList())
   break;
   }
+  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
+break;
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116859: Fix for: clang-format: break added to macro define with ColumnLimit: 0

2022-01-10 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:4810-4811
+
+  verifyFormat("#define STRINGIFY(t) #t\n"
+   "#define MAKEVERSIONSTRING(x, y, z, build) STRINGIFY(x) \".\" 
STRINGIFY(y) \".\" STRINGIFY(z) \".\" STRINGIFY(build)\n",
+   ZeroColumn);

Please test with something simpler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116859

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


[clang] 4a4b8e4 - [AST] Add more source information for DecltypeTypeLoc.

2022-01-10 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-01-10T09:34:18+01:00
New Revision: 4a4b8e4f99e2a82286b0595d561a51e7ad1945d2

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

LOG: [AST] Add more source information for DecltypeTypeLoc.

Adds the paren source location, and removes the hack in clangd.

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

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang/include/clang/AST/TypeLoc.h
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 7dc8a868ea00e..7c6b8b3134fe1 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -60,21 +60,6 @@ void recordMetrics(const SelectionTree &S, const LangOptions 
&Lang) {
 
 // Return the range covering a node and all its children.
 SourceRange getSourceRange(const DynTypedNode &N) {
-  // DeclTypeTypeLoc::getSourceRange() is incomplete, which would lead to
-  // failing to descend into the child expression.
-  // decltype(2+2);
-  // ~ <-- correct range
-  //   <-- range reported by getSourceRange()
-  //   <-- range with this hack(i.e, missing closing paren)
-  // FIXME: Alter DecltypeTypeLoc to contain parentheses locations and get
-  // rid of this patch.
-  if (const auto *TL = N.get()) {
-if (auto DT = TL->getAs()) {
-  SourceRange S = DT.getSourceRange();
-  S.setEnd(DT.getUnderlyingExpr()->getEndLoc());
-  return S;
-}
-  }
   // MemberExprs to implicitly access anonymous fields should not claim any
   // tokens for themselves. Given:
   //   struct A { struct { int b; }; };

diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 9da111f684c31..7e19f07a2215e 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -390,7 +390,7 @@ TEST(SelectionTest, CommonAncestor) {
 decltype([[^a]] + a) b;
 )cpp",
   "DeclRefExpr"},
-  {"[[decltype]]^(1) b;", "DecltypeTypeLoc"}, // Not the VarDecl.
+  {"[[decltype^(1)]] b;", "DecltypeTypeLoc"}, // Not the VarDecl.
 
   // Objective-C nullability attributes.
   {

diff  --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 7a036836e8c48..9a43d34a9ec38 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -1994,12 +1994,35 @@ class TypeOfTypeLoc
   void initializeLocal(ASTContext &Context, SourceLocation Loc);
 };
 
-// FIXME: location of the 'decltype' and parens.
-class DecltypeTypeLoc : public InheritingConcreteTypeLoc {
+// decltype(expression) abc;
+//   DecltypeLoc
+//~  RParenLoc
+// FIXME: add LParenLoc, it is tricky to support due to the limitation of
+// annotated-decltype token.
+struct DecltypeTypeLocInfo {
+  SourceLocation DecltypeLoc;
+  SourceLocation RParenLoc;
+};
+class DecltypeTypeLoc
+: public ConcreteTypeLoc {
 public:
   Expr *getUnderlyingExpr() const { return getTypePtr()->getUnderlyingExpr(); }
+
+  SourceLocation getDecltypeLoc() const { return getLocalData()->DecltypeLoc; }
+  void setDecltypeLoc(SourceLocation Loc) { getLocalData()->DecltypeLoc = Loc; 
}
+
+  SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
+  void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
+
+  SourceRange getLocalSourceRange() const {
+return SourceRange(getDecltypeLoc(), getRParenLoc());
+  }
+
+  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
+setDecltypeLoc(Loc);
+setRParenLoc(Loc);
+  }
 };
 
 struct UnaryTransformTypeLocInfo {

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 8ab1231e1bc10..c08a586604b1f 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1007,6 +1007,9 @@ SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec 
&DS) {
   if (Tok.is(tok::annot_decltype)) {
 Result = getExprAnnotation(Tok);
 EndLoc = Tok.getAnnotationEndLoc();
+// Unfortunately, we don't know the LParen source location as the annotated
+// token doesn't have it.
+DS.setTypeofParensRange(SourceRange(SourceLocation(), EndLoc));
 ConsumeAnnotationToken();
 if (Result.i

[PATCH] D116793: [AST] Add more source information for DecltypeTypeLoc.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rG4a4b8e4f99e2: [AST] Add more source information for 
DecltypeTypeLoc. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D116793?vs=398101&id=398522#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116793

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang/include/clang/AST/TypeLoc.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/unittests/AST/SourceLocationTest.cpp

Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -215,6 +215,33 @@
   EXPECT_TRUE(Verifier.match("long a;", typeLoc()));
 }
 
+TEST(TypeLoc, DecltypeTypeLocRange) {
+  llvm::Annotations Code(R"(
+$full1[[decltype(1)]] a;
+struct A {struct B{};} var;
+$full2[[decltype(var)]]::B c;
+  )");
+  auto AST = tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{});
+  ASTContext &Ctx = AST->getASTContext();
+  const auto &SM = Ctx.getSourceManager();
+
+  auto MatchedLocs = clang::ast_matchers::match(
+  typeLoc(loc(decltypeType())).bind("target"), Ctx);
+  ASSERT_EQ(MatchedLocs.size(), 2u);
+  auto verify = [&](SourceRange ActualRange,
+const llvm::Annotations::Range &Expected) {
+auto ActualCharRange =
+Lexer::getAsCharRange(ActualRange, SM, Ctx.getLangOpts());
+EXPECT_EQ(SM.getFileOffset(ActualCharRange.getBegin()), Expected.Begin);
+EXPECT_EQ(SM.getFileOffset(ActualCharRange.getEnd()), Expected.End);
+  };
+  const auto *Target1 = MatchedLocs[0].getNodeAs("target");
+  verify(Target1->getSourceRange(), Code.range("full1"));
+
+  const auto *Target2 = MatchedLocs[1].getNodeAs("target");
+  verify(Target2->getSourceRange(), Code.range("full2"));
+}
+
 TEST(TypeLoc, LongDoubleRange) {
   RangeVerifier Verifier;
   Verifier.expectRange(1, 1, 1, 6);
@@ -559,7 +586,7 @@
 
 TEST(FriendDecl, FriendDecltypeRange) {
   RangeVerifier Verifier;
-  Verifier.expectRange(4, 1, 4, 8);
+  Verifier.expectRange(4, 1, 4, 22);
   EXPECT_TRUE(Verifier.match("struct A;\n"
  "A foo();\n"
  "struct A {\n"
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -427,7 +427,8 @@
 }
 
 void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
-  Record.AddSourceLocation(TL.getNameLoc());
+  Record.AddSourceLocation(TL.getDecltypeLoc());
+  Record.AddSourceLocation(TL.getRParenLoc());
 }
 
 void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -6628,7 +6628,8 @@
 }
 
 void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
-  TL.setNameLoc(readSourceLocation());
+  TL.setDecltypeLoc(readSourceLocation());
+  TL.setRParenLoc(readSourceLocation());
 }
 
 void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -6228,15 +6228,15 @@
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   E.get() != T->getUnderlyingExpr()) {
-Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
+Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
 if (Result.isNull())
   return QualType();
   }
   else E.get();
 
   DecltypeTypeLoc NewTL = TLB.push(Result);
-  NewTL.setNameLoc(TL.getNameLoc());
-
+  NewTL.setDecltypeLoc(TL.getDecltypeLoc());
+  NewTL.setRParenLoc(TL.getRParenLoc());
   return Result;
 }
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5973,6 +5973,11 @@
   Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo);
   TL.setUnderlyingTInfo(TInfo);
 }
+void VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
+  assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
+  TL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
+  TL.setRParenLoc(DS.getTypeofParensRange().getEnd());
+   

[PATCH] D94955: [clang-format] Treat ForEachMacros as loops

2022-01-10 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

@GoBigorGoHome, are you still interested in this review?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94955

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


[PATCH] D116713: [clangd] Support configuration of inlay hints.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:51
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+if (!Cfg.InlayHints.DeducedTypes)
+  return true;

sammccall wrote:
> hokein wrote:
> > this should be `!Cfg.InlayHints.ParameterNames`.
> > 
> > What do you think the idea of moving guards deeper (`processCall` and 
> > `addTypeHint`)? The code seems clearer and we don't have to add them in all 
> > Visit* implementation,  this means that we pay cost of running some 
> > necessary code, but I think it is trivial and probably worthy. 
> I agree where to put the checks is an annoying question (and worth 
> minimizing, since I've managed to get two wrong already).
> I do think there needs to be a pattern so we don't accidentally skip checks.
> 
> - Easest is to postfilter (check in addInlayHint). That *does* hurt 
> performance. Debug build on my laptop is ~170ms for all hints, ~160ms for 
> postfilter with all categories disabled, ~5ms for current impl (prefilter) 
> with all categories disabled. (On SemaCodeComplete.cpp, just eyeballing 
> traces)
> - Checking in VisitXXX methods (as done here) is a very regular pattern. 
> Downside is you need many checks, and you can forget/break one
> - Checks in helpers so that one is always hit (as you propose) touches fewer 
> places but it's ad-hoc. I'm afraid of getting it wrong as the impl is 
> modified (missing checks, doing too much work first, etc).
> - Splitting RAV per category is an interesting option. Checking is very 
> elegant, nicer code structure, can trace per-category latency, disabled 
> categories can't crash... The downside is extra overhead, but this must be 
> <5ms in the performance above. We can still choose to bundle simple 
> categories together...
> 
> I think I'll do as you propose for now, improve the tests, and refactor to 
> try to make it feel less ad-hoc later.
> Also I should work out what we're spending 170ms on... EDIT: it turns out 
> it's just assembling JSON objects :-\
Thanks for digging into this.

> ~5ms for current impl (prefilter) with all categories disabled. (On 
> SemaCodeComplete.cpp, just eyeballing traces)

Yeah, we should have this prefilter implementation when all categories are 
disabled.


> Debug build on my laptop is ~170ms for all hints, ~160ms for postfilter with 
> all categories disabled,

The data doesn't seem reasonable, I think the total cost comes from two main 
sources (AST traversal cost + assembling JSON object cost),
I would expect the `allhints` and `postfilter` have the similar AST traversal 
cost, but `postfilter` should have a near zero cost of assembling JSON objectcs 
(as it returns an empty vector), so the AST traversal cost is ~160ms.

> Also I should work out what we're spending 170ms on... EDIT: it turns out 
> it's just assembling JSON objects :-\

And based on this, it turns out the cost of `all-hints` approach should be 
larger than 170ms, which should be ~300ms (160ms for AST traversal + 170ms for 
assembling JSON objects).


Anyway, the current implementation looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116713

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


[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116919

Files:
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang/include/clang/AST/TypeLoc.h
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/unittests/AST/SourceLocationTest.cpp

Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -242,6 +242,13 @@
   verify(Target2->getSourceRange(), Code.range("full2"));
 }
 
+TEST(TypeLoc, AutoTypeLocRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 14);
+  EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())),
+ Lang_CXX11));
+}
+
 TEST(TypeLoc, LongDoubleRange) {
   RangeVerifier Verifier;
   Verifier.expectRange(1, 1, 1, 6);
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -90,7 +90,7 @@
 
 template 
 // CHECK: ClassTemplateDecl 0x{{[^ ]*}}  col:8 U
-// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}}  col:25 'decltype(auto)' depth 0 index 0
+// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}}  col:25 'decltype(auto)' depth 0 index 0
 struct U {};
 
 template 
Index: clang/test/AST/ast-dump-template-decls-json.cpp
===
--- clang/test/AST/ast-dump-template-decls-json.cpp
+++ clang/test/AST/ast-dump-template-decls-json.cpp
@@ -2130,9 +2130,9 @@
 // CHECK-NEXT:"tokLen": 8
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": 705,
-// CHECK-NEXT:"col": 11,
-// CHECK-NEXT:"tokLen": 8
+// CHECK-NEXT:"offset": 718,
+// CHECK-NEXT:"col": 24,
+// CHECK-NEXT:"tokLen": 1
 // CHECK-NEXT:   }
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "type": {
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -452,6 +452,9 @@
   Record.AddTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(),
 TL.getArgLocInfo(I));
   }
+  Record.push_back(TL.isDecltypeAuto());
+  if (TL.isDecltypeAuto())
+Record.AddSourceLocation(TL.getRParenLoc());
 }
 
 void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc(
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -6652,6 +6652,8 @@
   TL.setArgLocInfo(i, Reader.readTemplateArgumentLocInfo(
   TL.getTypePtr()->getArg(i).getKind()));
   }
+  if (Reader.readBool())
+TL.setRParenLoc(readSourceLocation());
 }
 
 void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc(
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/PartialDiagnostic.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/DeclSpec.h"
@@ -6041,6 +6042,8 @@
  DS.getTypeSpecType() == TST_auto_type ||
  DS.getTypeSpecType() == TST_unspecified);
   TL.setNameLoc(DS.getTypeSpecTypeLoc());
+  if (DS.getTypeSpecType() == TST_decltype_auto)
+TL.setRParenLoc(DS.getTypeofParensRange().getEnd());
   if (!DS.isConstrainedAuto())
 return;
   TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();
Index: clang/lib/AST/TypeLoc.cpp
===
--- clang/lib/AST/TypeLoc.cpp
+++ clang/lib/AST/TypeLoc.cpp
@@ -622,6 +622,7 @@
   setFoundDecl(nullptr);
   setRAngleLoc(Loc);
   setLAngleLoc(Loc);
+  setRParenLoc(Loc);
   TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
getTypePtr()->getArgs(),
getArgInfos(), Loc);
Index: clang/include/clang/AST/TypeLoc.h
===
--- clang/include/clang/AST/TypeLoc.h
+++ clang/inc

[PATCH] D99031: [clang-format] Fix CompactNamespaces corner case when AllowShortLambdasOnASingleLine/BraceWrapping.BeforeLambdaBody are set

2022-01-10 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

@aybassiouny, still interested in working on this?


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

https://reviews.llvm.org/D99031

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


[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete

2022-01-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: curdeius, HazardyKnusperkeks, owenpan, thakis.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

https://github.com/llvm/llvm-project/issues/27037

Sorry its taken so long to get to this issue! (got it before it hit its 6th 
birthday!)

  void operator delete(void *foo)ATTRIB;

(void *foo) is incorrectly determined to be a C-Style Cast resulting in the 
space being removed after the ) and before the attrib, due to the detection of

  delete (A* )a;

The following was previously unaffected

  void operator new(void *foo) ATTRIB;

Fixes #27037


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116920

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,9 @@
"new 
(aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1893,6 +1893,14 @@
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
 
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->is(tok::kw_delete) && LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
+
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.
   if (LeftOfParens->Tok.getIdentifierInfo() &&


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,9 @@
"new (aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1893,6 +1893,14 @@
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
 
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->is(tok::kw_delete) && LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
+
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.
   if (LeftOfParens->Tok.getIdentifierInfo() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116921: [clangd] Enable expand-auto for decltype(auto).

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Based on https://reviews.llvm.org/D116919.

Fixes https://github.com/clangd/clangd/issues/121


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116921

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,7 +71,8 @@
   apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
   "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
 
-  EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+  EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
+  EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
   // expanding types in structured bindings is syntactically invalid.
   EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,9 +96,7 @@
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
 if (auto *TypeNode = Node->ASTNode.get()) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
-// Code in apply() does handle 'decltype(auto)' yet.
-if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node) &&
+if (!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
   CachedLocation = Result;


Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,7 +71,8 @@
   apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
   "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
 
-  EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+  EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
+  EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
   // expanding types in structured bindings is syntactically invalid.
   EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,9 +96,7 @@
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
 if (auto *TypeNode = Node->ASTNode.get()) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
-// Code in apply() does handle 'decltype(auto)' yet.
-if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node) &&
+if (!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
   CachedLocation = Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116922: [AST] Use recovery-expr to preserve incomplete-type-member-access expression.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
hokein requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116922

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/OpenMP/declare_reduction_messages.cpp


Index: clang/test/OpenMP/declare_reduction_messages.cpp
===
--- clang/test/OpenMP/declare_reduction_messages.cpp
+++ clang/test/OpenMP/declare_reduction_messages.cpp
@@ -169,7 +169,6 @@
   #pragma omp declare reduction (xxx : U, S : bar(omp_in)) // expected-error 
{{non-const lvalue reference to type 'S<1>' cannot bind to a value of unrelated 
type 'U'}}
   static void bar(S &x); // expected-note {{passing argument to parameter 'x' 
here}}
 };
-// expected-warning@+2 {{extra tokens at the end of '#pragma omp declare 
reduction' are ignored}}
 // expected-note@+1 {{in instantiation of template class 'S<1>' requested 
here}}
 #pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in))
 
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -121,6 +121,16 @@
   foo->func(x);
 }
 
+void AccessIncompleteClass() {
+  struct Forward;
+  Forward* ptr;
+  // CHECK:  CallExpr {{.*}} ''
+  // CHECK-NEXT: `-CXXDependentScopeMemberExpr {{.*}} ''
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Forward *'
+  ptr->method();
+}
+
 struct Foo2 {
   double func();
   class ForwardClass;
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7410,8 +7410,10 @@
   //   the member function body.
   if (!BaseType->isDependentType() &&
   !isThisOutsideMemberFunctionBody(BaseType) &&
-  RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
-return ExprError();
+  RequireCompleteType(OpLoc, BaseType,
+  diag::err_incomplete_member_access)) {
+return CreateRecoveryExpr(Base->getBeginLoc(), Base->getEndLoc(), {Base});
+  }
 
   // C++ [basic.lookup.classref]p2:
   //   If the id-expression in a class member access (5.2.5) is an


Index: clang/test/OpenMP/declare_reduction_messages.cpp
===
--- clang/test/OpenMP/declare_reduction_messages.cpp
+++ clang/test/OpenMP/declare_reduction_messages.cpp
@@ -169,7 +169,6 @@
   #pragma omp declare reduction (xxx : U, S : bar(omp_in)) // expected-error {{non-const lvalue reference to type 'S<1>' cannot bind to a value of unrelated type 'U'}}
   static void bar(S &x); // expected-note {{passing argument to parameter 'x' here}}
 };
-// expected-warning@+2 {{extra tokens at the end of '#pragma omp declare reduction' are ignored}}
 // expected-note@+1 {{in instantiation of template class 'S<1>' requested here}}
 #pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in))
 
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -121,6 +121,16 @@
   foo->func(x);
 }
 
+void AccessIncompleteClass() {
+  struct Forward;
+  Forward* ptr;
+  // CHECK:  CallExpr {{.*}} ''
+  // CHECK-NEXT: `-CXXDependentScopeMemberExpr {{.*}} ''
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Forward *'
+  ptr->method();
+}
+
 struct Foo2 {
   double func();
   class ForwardClass;
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7410,8 +7410,10 @@
   //   the member function body.
   if (!BaseType->isDependentType() &&
   !isThisOutsideMemberFunctionBody(BaseType) &&
-  RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
-return ExprError();
+  RequireCompleteType(OpLoc, BaseType,
+  diag::err_incomplete_member_access)) {
+return CreateRecoveryExpr(Base->getBeginLoc(), Base->getEndLoc(), {Base});
+  }
 
   // C++ [basic.lookup.classref]p2:
   //   If the id-expression in a class member access (5.2.5) is an
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115490: [clangd] Include fixer for missing functions in C

2022-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaDecl.cpp:14995
+DeclFilterCCC CCC{};
+Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc), LookupOrdinaryName,
+S, nullptr, CCC, CTK_NonError);

maybe some comments around importance of the sequencing here? it would probably 
be nice to have that at a higher level documentation too, but unclear where. as 
in theory it's not just about the typo correction but also emitting diagnostics 
while doing so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115490

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


[clang] 27ea0c4 - [Parse] Use empty RecoveryExpr when if/while/do/switch conditions fail to parse

2022-01-10 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-01-10T10:38:27+01:00
New Revision: 27ea0c4e7234f3b15cbbb696e6c408af7141f342

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

LOG: [Parse] Use empty RecoveryExpr when if/while/do/switch conditions fail to 
parse

This allows the body to be parsed.
An special-case that would replace a missing if condition with OpaqueValueExpr
was removed as it's now redundant (unless recovery-expr is disabled).

For loops are not handled at this point, as the parsing is more complicated.

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

Added: 
clang/test/AST/loop-recovery.cpp

Modified: 
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprConstant.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/ast-dump-invalid.cpp
clang/test/Parser/cxx0x-attributes.cpp
clang/test/Sema/complex-int.c
clang/test/SemaCXX/condition.cpp
clang/test/SemaCXX/constexpr-function-recovery-crash.cpp

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index d266a0b37265c..b651929fa9da1 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1975,6 +1975,7 @@ class Parser : public CodeCompletionHandler {
   Sema::ConditionResult ParseCXXCondition(StmtResult *InitStmt,
   SourceLocation Loc,
   Sema::ConditionKind CK,
+  bool MissingOK,
   ForRangeInfo *FRI = nullptr,
   bool EnterForConditionScope = false);
   DeclGroupPtrTy
@@ -2079,8 +2080,8 @@ class Parser : public CodeCompletionHandler {
   bool ParseParenExprOrCondition(StmtResult *InitStmt,
  Sema::ConditionResult &CondResult,
  SourceLocation Loc, Sema::ConditionKind CK,
- SourceLocation *LParenLoc = nullptr,
- SourceLocation *RParenLoc = nullptr);
+ bool MissingOK, SourceLocation *LParenLoc,
+ SourceLocation *RParenLoc);
   StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9521b24e44a79..9b6d9d20ca431 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12080,9 +12080,12 @@ class Sema final {
 ConstexprIf, ///< A constant boolean condition from 'if constexpr'.
 Switch   ///< An integral condition for a 'switch' statement.
   };
+  QualType PreferredConditionType(ConditionKind K) const {
+return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy;
+  }
 
-  ConditionResult ActOnCondition(Scope *S, SourceLocation Loc,
- Expr *SubExpr, ConditionKind CK);
+  ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr,
+ ConditionKind CK, bool MissingOK = false);
 
   ConditionResult ActOnConditionVariable(Decl *ConditionVar,
  SourceLocation StmtLoc,

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 51e8a55f2e4b7..f9416e8e215d1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -4933,8 +4933,13 @@ static EvalStmtResult EvaluateSwitch(StmtResult &Result, 
EvalInfo &Info,
 if (SS->getConditionVariable() &&
 !EvaluateDecl(Info, SS->getConditionVariable()))
   return ESR_Failed;
-if (!EvaluateInteger(SS->getCond(), Value, Info))
-  return ESR_Failed;
+if (SS->getCond()->isValueDependent()) {
+  if (!EvaluateDependentExpr(SS->getCond(), Info))
+return ESR_Failed;
+} else {
+  if (!EvaluateInteger(SS->getCond(), Value, Info))
+return ESR_Failed;
+}
 if (!CondScope.destroy())
   return ESR_Failed;
   }

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 6685c0e897021..cd600c4247a72 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1953,6 +1953,9 @@ 
Parser::ParseAliasDeclarationInInitStatement(DeclaratorContext Context,
 /// \param Loc The location of the start of the statement that requires this
 /// condition, e.g., the "for" in a for loop.
 ///
+/// \param

[clang-tools-extra] 16fd5c2 - [clangd] Support configuration of inlay hints.

2022-01-10 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-01-10T10:49:35+01:00
New Revision: 16fd5c278488b3d3275afc381a00ba0b51b070ee

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

LOG: [clangd] Support configuration of inlay hints.

The idea is that the feature will always be advertised at the LSP level, but
depending on config we'll return partial or no responses.

We try to avoid doing the analysis for hints we're not going to return.

Examples of syntax:
```
InlayHints:
  Enabled: No
---
InlayHints:
  ParameterNames: No
---
InlayHints:
  ParameterNames: Yes
  DeducedTypes: Yes
```

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

Added: 


Modified: 
clang-tools-extra/clangd/Config.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/ConfigFragment.h
clang-tools-extra/clangd/ConfigYAML.cpp
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Config.h 
b/clang-tools-extra/clangd/Config.h
index 38fc93fa361c..952626db31e4 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -122,6 +122,15 @@ struct Config {
 /// Whether hover show a.k.a type.
 bool ShowAKA = false;
   } Hover;
+
+  struct {
+/// If false, inlay hints are completely disabled.
+bool Enabled = true;
+
+// Whether specific categories of hints are enabled.
+bool Parameters = true;
+bool DeducedTypes = true;
+  } InlayHints;
 };
 
 } // namespace clangd

diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index 18afdeb3cb5c..a606b98a2dba 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -197,6 +197,7 @@ struct FragmentCompiler {
 compile(std::move(F.Diagnostics));
 compile(std::move(F.Completion));
 compile(std::move(F.Hover));
+compile(std::move(F.InlayHints));
   }
 
   void compile(Fragment::IfBlock &&F) {
@@ -526,6 +527,22 @@ struct FragmentCompiler {
 }
   }
 
+  void compile(Fragment::InlayHintsBlock &&F) {
+if (F.Enabled)
+  Out.Apply.push_back([Value(**F.Enabled)](const Params &, Config &C) {
+C.InlayHints.Enabled = Value;
+  });
+if (F.ParameterNames)
+  Out.Apply.push_back(
+  [Value(**F.ParameterNames)](const Params &, Config &C) {
+C.InlayHints.Parameters = Value;
+  });
+if (F.DeducedTypes)
+  Out.Apply.push_back([Value(**F.DeducedTypes)](const Params &, Config &C) 
{
+C.InlayHints.DeducedTypes = Value;
+  });
+  }
+
   constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
   constexpr static llvm::SourceMgr::DiagKind Warning =
   llvm::SourceMgr::DK_Warning;

diff  --git a/clang-tools-extra/clangd/ConfigFragment.h 
b/clang-tools-extra/clangd/ConfigFragment.h
index 31c4636efa0b..d165b6305aa5 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -283,6 +283,18 @@ struct Fragment {
 llvm::Optional> ShowAKA;
   };
   HoverBlock Hover;
+
+  /// Configures labels shown inline with the code.
+  struct InlayHintsBlock {
+/// Enables/disables the inlay-hints feature.
+llvm::Optional> Enabled;
+
+/// Show parameter names before function arguments.
+llvm::Optional> ParameterNames;
+/// Show deduced types for `auto`.
+llvm::Optional> DeducedTypes;
+  };
+  InlayHintsBlock InlayHints;
 };
 
 } // namespace config

diff  --git a/clang-tools-extra/clangd/ConfigYAML.cpp 
b/clang-tools-extra/clangd/ConfigYAML.cpp
index 0487c3281576..04c0c633a3bb 100644
--- a/clang-tools-extra/clangd/ConfigYAML.cpp
+++ b/clang-tools-extra/clangd/ConfigYAML.cpp
@@ -66,6 +66,7 @@ class Parser {
 Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
 Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
 Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
+Dict.handle("InlayHints", [&](Node &N) { parse(F.InlayHints, N); });
 Dict.parse(N);
 return !(N.failed() || HadError);
   }
@@ -199,12 +200,8 @@ class Parser {
   void parse(Fragment::CompletionBlock &F, Node &N) {
 DictParser Dict("Completion", this);
 Dict.handle("AllScopes", [&](Node &N) {
-  if (auto Value = scalarValue(N, "AllScopes")) {
-if (auto AllScopes = llvm::yaml::parseBool(**Value))
-  F.AllScopes = *AllScopes;
-else
-  warning("AllScopes should be a boolean", N);
-  }
+  if (auto AllScopes = boolValue(N, "AllScopes"))
+F.AllScopes = *AllScopes;
 });
 Dict.parse(N);
   }
@@ -212,12 +209,25 @@ class Parse

[PATCH] D113752: [Parse] Use empty RecoveryExpr when if/while/do/switch conditions fail to parse

2022-01-10 Thread Sam McCall 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 rG27ea0c4e7234: [Parse] Use empty RecoveryExpr when 
if/while/do/switch conditions fail to parse (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D113752?vs=396662&id=398535#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113752

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-invalid.cpp
  clang/test/AST/loop-recovery.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/complex-int.c
  clang/test/SemaCXX/condition.cpp
  clang/test/SemaCXX/constexpr-function-recovery-crash.cpp

Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -77,3 +77,25 @@
 
 constexpr int test12() { return "wrong"; } // expected-error {{cannot initialize return object of type 'int'}}
 constexpr int force12 = test12();  // expected-error {{must be initialized by a constant}}
+
+#define TEST_EVALUATE(Name, X) \
+  constexpr int testEvaluate##Name() { \
+X return 0;\
+  }\
+  constexpr int forceEvaluate##Name = testEvaluate##Name()
+// Check that a variety of broken loops don't crash constant evaluation.
+// We're not checking specific recovery here so don't assert diagnostics.
+TEST_EVALUATE(Switch, switch (!!){});  // expected-error + {{}}
+TEST_EVALUATE(SwitchInit, switch (auto x = !!){}); // expected-error + {{}}
+TEST_EVALUATE(For, for (!!){}); // expected-error + {{}}
+// FIXME: should bail out instead of looping.
+// expected-note@-2 + {{infinite loop}}
+// expected-note@-3 {{in call}}
+TEST_EVALUATE(ForRange, for (auto x : !!){}); // expected-error + {{}}
+TEST_EVALUATE(While, while (!!){});   // expected-error + {{}}
+TEST_EVALUATE(DoWhile, do {} while (!!););// expected-error + {{}}
+TEST_EVALUATE(If, if (!!){};);// expected-error + {{}}
+TEST_EVALUATE(IfInit, if (auto x = !!; 1){};);// expected-error + {{}}
+TEST_EVALUATE(ForInit, if (!!;;){};); // expected-error + {{}}
+TEST_EVALUATE(ForCond, if (; !!;){};);// expected-error + {{}}
+TEST_EVALUATE(ForInc, if (;; !!){};); // expected-error + {{}}
Index: clang/test/SemaCXX/condition.cpp
===
--- clang/test/SemaCXX/condition.cpp
+++ clang/test/SemaCXX/condition.cpp
@@ -20,6 +20,8 @@
   while (struct S {} *x=0) ; // expected-error {{'S' cannot be defined in a condition}}
   while (struct {} *x=0) ; // expected-error-re {{'(unnamed struct at {{.*}})' cannot be defined in a condition}}
   switch (enum {E} x=0) ; // expected-error-re {{'(unnamed enum at {{.*}})' cannot be defined in a condition}}
+  // expected-warning@-1 {{switch statement has empty body}}
+  // expected-note@-2 {{put the semicolon on a separate line}}
 
   if (int x=0) { // expected-note 2 {{previous definition is here}}
 int x;  // expected-error {{redefinition of 'x'}}
Index: clang/test/Sema/complex-int.c
===
--- clang/test/Sema/complex-int.c
+++ clang/test/Sema/complex-int.c
@@ -18,8 +18,8 @@
 result = xx*yy;
 
 switch (arr) { // expected-error{{statement requires expression of integer type ('_Complex int' invalid)}}
-  case brr: ;
-  case xx: ;
+  case brr: ; // expected-error{{integer constant expression must have integer type}}
+  case xx: ; // expected-error{{integer constant expression must have integer type}}
 }
 switch (ii) {
   case brr: ; // expected-error{{integer constant expression must have integer type}}
Index: clang/test/Parser/cxx0x-attributes.cpp
===
--- clang/test/Parser/cxx0x-attributes.cpp
+++ clang/test/Parser/cxx0x-attributes.cpp
@@ -152,6 +152,7 @@
   [[ab]ab] ns::i); // expected-error {{an attribute list cannot appear here}}
   do {} while ( // expected-note {{to match this '('}}
   alignas(4 ns::i; // expected-note {{to match this '('}}
+   // expected-error@-1 {{expected ';' after do/while}}
 } // expected-error 2{{expected ')'}} expected-error {{expected expression}}
 
 [[]] using T = int; // expected-error {{an attribute list cannot appear here}}
Index: clang/test/AST

[PATCH] D116713: [clangd] Support configuration of inlay hints.

2022-01-10 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16fd5c278488: [clangd] Support configuration of inlay hints. 
(authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116713

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -6,11 +6,13 @@
 //
 //===--===//
 #include "Annotations.h"
+#include "Config.h"
 #include "InlayHints.h"
 #include "Protocol.h"
 #include "TestTU.h"
 #include "TestWorkspace.h"
 #include "XRefs.h"
+#include "support/Context.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -24,6 +26,8 @@
 namespace {
 
 using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+using ::testing::UnorderedElementsAre;
 
 std::vector hintsOfKind(ParsedAST &AST, InlayHintKind Kind) {
   std::vector Result;
@@ -56,6 +60,13 @@
 
 MATCHER_P(labelIs, Label, "") { return arg.label == Label; }
 
+Config noHintsConfig() {
+  Config C;
+  C.InlayHints.Parameters = false;
+  C.InlayHints.DeducedTypes = false;
+  return C;
+}
+
 template 
 void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
  ExpectedHints... Expected) {
@@ -66,6 +77,10 @@
 
   EXPECT_THAT(hintsOfKind(AST, Kind),
   ElementsAre(HintMatcher(Expected, Source)...));
+  // Sneak in a cross-cutting check that hints are disabled by config.
+  // We'll hit an assertion failure if addInlayHint still gets called.
+  WithContextValue WithCfg(Config::Key, noHintsConfig());
+  EXPECT_THAT(inlayHints(AST, llvm::None), IsEmpty());
 }
 
 // Hack to allow expression-statements operating on parameter packs in C++14.
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -228,6 +228,23 @@
   ASSERT_EQ(Results.size(), 1u);
   EXPECT_THAT(Results[0].Hover.ShowAKA, llvm::ValueIs(Val(true)));
 }
+
+TEST(ParseYAML, InlayHints) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+InlayHints:
+  Enabled: No
+  ParameterNames: Yes
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].InlayHints.Enabled, llvm::ValueIs(Val(false)));
+  EXPECT_THAT(Results[0].InlayHints.ParameterNames, llvm::ValueIs(Val(true)));
+  EXPECT_EQ(Results[0].InlayHints.DeducedTypes, llvm::None);
+}
+
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 #include "InlayHints.h"
+#include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "clang/AST/DeclarationName.h"
@@ -23,8 +24,8 @@
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector &Results, ParsedAST &AST,
-   llvm::Optional RestrictRange)
-  : Results(Results), AST(AST.getASTContext()),
+   const Config &Cfg, llvm::Optional RestrictRange)
+  : Results(Results), AST(AST.getASTContext()), Cfg(Cfg),
 RestrictRange(std::move(RestrictRange)),
 MainFileID(AST.getSourceManager().getMainFileID()),
 Resolver(AST.getHeuristicResolver()),
@@ -65,6 +66,9 @@
   }
 
   bool VisitCallExpr(CallExpr *E) {
+if (!Cfg.InlayHints.Parameters)
+  return true;
+
 // Do not show parameter hints for operator calls written using operator
 // syntax or user-defined literals. (Among other reasons, the resulting
 // hints can look awkard, e.g. the expression can itself be a function
@@ -135,7 +139,7 @@
   // the entire argument list likely appears in the main file and can be hinted.
   void processCall(SourceLocation Anchor, const FunctionDecl *Callee,
llvm::ArrayRef Args) {
-if (Args.size() == 0 || !Callee)
+if (!Cfg.InlayHints.Parameters || Args.size() == 0 || !Callee)
   return;
 
 // If the anchor location comes from a macro defintion, there's nowh

[PATCH] D116294: [CodeCompletion] (mostly) fix completion in incomplete C++ ctor initializers.

2022-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/lib/Parse/ParseCXXInlineMethods.cpp:153
+  // probably truncated, so don't eat more tokens.
+  if (!Toks.back().is(tok::code_completion))
+SkipMalformedDecl();

i don't follow the logic here. maybe i am reading the comment wrong, but we are 
actually going to eat **more** tokens by calling `SkipMalformedDecl`, possibly 
the following one, right? for example in a scenario like:
```
struct Foo {
  Foo : ^b
  int bar;
}
```
`ConsumeAndStoreFunctionPrologue` will actually put `b` following the code 
completion token (`^`) into `Toks` as well, hence when we skip, we actually 
skip until the next semicolon and throw away bar. But when the code completion 
token is after `b`, `ConsumeAndStoreFunctionPrologue` we'll have code 
completion token at the end of the `Toks` and won't skip anything

 Do we have cases that break miserably when we don't perform an extra skip here 
for the (possible) reminder of current initalizer?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116294

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


[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete

2022-01-10 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1729
 } else if (Current.is(tok::r_paren)) {
   if (rParenEndsCast(Current))
 Current.setType(TT_CastRParen);

The current solution looks a bit like a hack to me.
Unless I'm mistaken, casts can appear only in expressions, but not in 
declarations (except for inside `decltype` stuff in templates or concepts, but 
these are still expressions at this level).
Given that `void operator delete...` is not an expression but a declaration, we 
shouldn't check `rParenEndsCast` in this case at all, no?
So, would it be possible to check here for e.g. `Line.MightBeFunctionDecl` or 
something like this to avoid it?

Also, how is it that you don't need to special-case `new` operator?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116920

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


[PATCH] D116924: [clang-extdef-mapping] Allow clang-extdef-mapping tool to output customized filename for each index entry

2022-01-10 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie created this revision.
OikawaKirie added reviewers: martong, NoQ, steakhal.
OikawaKirie added a project: clang.
Herald added subscribers: arphaman, rnkovacs.
OikawaKirie requested review of this revision.
Herald added a subscriber: cfe-commits.

The clang-extdef-mapping tool can only output the real file name of the input 
source file. When analyzing with AST file based CTU analysis, the file name 
should be adjusted to the corresponding AST file, where `.ast` will be appended 
to the file name, and sometimes the path will even be changed. It is very 
inconvenient to adjust the file path with such a separated step, especially on 
Windows, where utility tools such as `sed` are not available.

This patch uses `Regex::sub` function to adjust the output file name for each 
index entry with the pattern provided by the user.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116924

Files:
  clang/test/Analysis/func-mapping-path.c
  clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp

Index: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
===
--- clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -30,11 +30,45 @@
 using namespace clang::tooling;
 
 static cl::OptionCategory ClangExtDefMapGenCategory("clang-extdefmapgen options");
+static cl::opt OutputPathAdjusterMatcher(
+"m", cl::desc("Match the part of output path to be replaced with regex"),
+cl::cat(ClangExtDefMapGenCategory));
+static cl::opt OutputPathAdjusterNewPath(
+"r", cl::desc("The string which matched pattern will be replaced to"),
+cl::cat(ClangExtDefMapGenCategory));
+
+namespace {
+class OutputPathAdjuster {
+  Regex Matcher;
+  std::string NewPath;
+
+public:
+  std::string adjust(StringRef Path) const {
+return Matcher.sub(NewPath, Path);
+  }
+
+  bool resetMatcher(StringRef MatcherStr, StringRef NewPathStr);
+};
+
+bool OutputPathAdjuster::resetMatcher(StringRef MatcherStr,
+  StringRef NewPathStr) {
+  std::string ErrMsg;
+  Regex MatcherRegex(MatcherStr);
+  if (!MatcherRegex.isValid(ErrMsg)) {
+errs() << "Invalid adjuster template: " << ErrMsg << '\n';
+return false;
+  }
+
+  Matcher = std::move(MatcherRegex);
+  NewPath = NewPathStr.str();
+  return true;
+}
+} // namespace
 
 class MapExtDefNamesConsumer : public ASTConsumer {
 public:
-  MapExtDefNamesConsumer(ASTContext &Context)
-  : Ctx(Context), SM(Context.getSourceManager()) {}
+  MapExtDefNamesConsumer(const OutputPathAdjuster *Adjuster)
+  : Adjuster(Adjuster) {}
 
   ~MapExtDefNamesConsumer() {
 // Flush results to standard output.
@@ -49,10 +83,9 @@
   void handleDecl(const Decl *D);
   void addIfInMain(const DeclaratorDecl *DD, SourceLocation defStart);
 
-  ASTContext &Ctx;
-  SourceManager &SM;
   llvm::StringMap Index;
   std::string CurrentFileName;
+  const OutputPathAdjuster *Adjuster = nullptr;
 };
 
 void MapExtDefNamesConsumer::handleDecl(const Decl *D) {
@@ -64,7 +97,7 @@
   if (const Stmt *Body = FD->getBody())
 addIfInMain(FD, Body->getBeginLoc());
   } else if (const auto *VD = dyn_cast(D)) {
-if (cross_tu::containsConst(VD, Ctx) && VD->hasInit())
+if (cross_tu::containsConst(VD, VD->getASTContext()) && VD->hasInit())
   if (const Expr *Init = VD->getInit())
 addIfInMain(VD, Init->getBeginLoc());
   }
@@ -82,9 +115,12 @@
 return;
   assert(!LookupName->empty() && "Lookup name should be non-empty.");
 
+  SourceManager &SM = DD->getASTContext().getSourceManager();
   if (CurrentFileName.empty()) {
 CurrentFileName = std::string(
 SM.getFileEntryForID(SM.getMainFileID())->tryGetRealPathName());
+if (Adjuster)
+  CurrentFileName = Adjuster->adjust(CurrentFileName);
 if (CurrentFileName.empty())
   CurrentFileName = "invalid_file";
   }
@@ -101,11 +137,15 @@
   }
 }
 
-class MapExtDefNamesAction : public ASTFrontendAction {
-protected:
-  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
- llvm::StringRef) override {
-return std::make_unique(CI.getASTContext());
+class MapExtDefNamesConsumerFactory {
+  const OutputPathAdjuster *Adjuster = nullptr;
+
+public:
+  MapExtDefNamesConsumerFactory(const OutputPathAdjuster *Adjuster)
+  : Adjuster(Adjuster) {}
+
+  std::unique_ptr newASTConsumer() {
+return std::make_unique(Adjuster);
   }
 };
 
@@ -118,7 +158,8 @@
 
   const char *Overview = "\nThis tool collects the USR name and location "
  "of external definitions in the source files "
- "(excluding headers).\n";
+ "(excluding headers).\n\nReset output path with -m "
+ " -r .\n";
   auto ExpectedParser = CommonOptionsParser::create(
   argc, argv, ClangExtDefMapGenCategory, cl::ZeroOrMore, Overview);
   

[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete

2022-01-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1729
 } else if (Current.is(tok::r_paren)) {
   if (rParenEndsCast(Current))
 Current.setType(TT_CastRParen);

curdeius wrote:
> The current solution looks a bit like a hack to me.
> Unless I'm mistaken, casts can appear only in expressions, but not in 
> declarations (except for inside `decltype` stuff in templates or concepts, 
> but these are still expressions at this level).
> Given that `void operator delete...` is not an expression but a declaration, 
> we shouldn't check `rParenEndsCast` in this case at all, no?
> So, would it be possible to check here for e.g. `Line.MightBeFunctionDecl` or 
> something like this to avoid it?
> 
> Also, how is it that you don't need to special-case `new` operator?
I will check to see if we can use that..

To answer your second question, the existing code was this... 

`!isOneOf(Keywords.kw_in, tok::kw_return, tok::kw_case,tok::kw_delete)`

its the `kw_delete` here that breaks the previous code.

to cover this being a cast

`delete (A *)a;`

my change is to use more context by avoid `operator delete (A* a) a;` from 
being seen as a cast




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116920

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


[PATCH] D116387: [CodeCompletion][clangd] Clean __uglified parameter names in completion & hover

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Agree that __ reserved names are ugly,  but I'm not sure this is a great 
improvement.

I played around the patch locally, and found the new behavior being confused in 
some cases (mostly inconsistencies between deuglified places vs uglified 
places), and seems hard for readers to predict it:

- inconsistency with doc-comment which still uses the __ name (this seems hard 
to fix)

F21562126: image.png 

- the print type in hover still uses __name (maybe this is expected, or we 
could introduce a `reserved` field in hover, like `template-type-param Tp 
(reserved)`)

F21562145: image.png 

- the deuglified behavior is triggered on (template/function) parameters, which 
means we have uglified name for `void foo(_ReservedClass& abc)` vs deuglified 
name for `template void foo(_ReservedClass& abc)` 
(expanding the scope could fix that, but it doesn't seem something we want to 
do)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116387

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


[PATCH] D116387: [CodeCompletion][clangd] Clean __uglified parameter names in completion & hover

2022-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D116387#3230893 , @hokein wrote:

> Agree that __ reserved names are ugly,  but I'm not sure this is a great 
> improvement.
>
> I played around the patch locally, and found the new behavior being confused 
> in some cases (mostly inconsistencies between deuglified places vs uglified 
> places), and seems hard for readers to predict it:

Agree, but I don't think it needs to be predictable, it's enough that the 
output can be understood.
(e.g. I never particularly noticed *which* identifiers in stdlib were ugly, 
just that the thing overall was hard to read).
i.e. if we remove the underscores half the time, that seems like a win.

> - inconsistency with doc-comment which still uses the __ name (this seems 
> hard to fix)
>
> F21562126: image.png 

Yes :-( However I don't think a human reader is likely to be confused by this.

> - the print type in hover still uses __name (maybe this is expected, or we 
> could introduce a `reserved` field in hover, like `template-type-param Tp 
> (reserved)`)
>
> F21562145: image.png 

This is an oversight, I'll fix this.

> - the deuglified behavior is triggered on (template/function) parameters, 
> which means we have uglified name for `void foo(_ReservedClass& abc)` vs 
> deuglified name for `template void 
> foo(_ReservedClass& abc)` (expanding the scope could fix that, but it doesn't 
> seem something we want to do)

This is deliberate: `_ReservedClass` is part of the API of `foo`, so renaming 
it is a semantic change.
I don't this change increases the amount of inconsistency:  today we 
have`vector` vs `push_back` vs `_ReservedClass` vs `_Tp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116387

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


[PATCH] D115490: [clangd] Include fixer for missing functions in C

2022-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:14995
+DeclFilterCCC CCC{};
+Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc), LookupOrdinaryName,
+S, nullptr, CCC, CTK_NonError);

kadircet wrote:
> maybe some comments around importance of the sequencing here? it would 
> probably be nice to have that at a higher level documentation too, but 
> unclear where. as in theory it's not just about the typo correction but also 
> emitting diagnostics while doing so.
Yeah, this is obviously pretty hacky, and I don't have great ideas to improve 
it.
Added a comment to leave some breadcrumbs and discourage moving this code 
around.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115490

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


[clang-tools-extra] 1ab1379 - [clangd] Include fixer for missing functions in C

2022-01-10 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-01-10T12:17:19+01:00
New Revision: 1ab13793beafd1db0159a410560b3ce998b15f5e

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

LOG: [clangd] Include fixer for missing functions in C

A function call `unresolved()` in C will generate an implicit declaration
of the missing function and warn `ext_implicit_function_decl` or so.
(Compared to in C++ where we get `err_undeclared_var_use`).
We want to try to resolve these names.

Unfortunately typo correction is disabled in sema for performance
reasons unless this warning is promoted to error.
(We need typo correction for include-fixer.)
It's not clear to me where a switch to force this correction on should
go, include-fixer is kind of a hack. So hack more by telling sema we're
promoting them to error.

Fixes https://github.com/clangd/clangd/issues/937

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

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/IncludeFixer.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index b90a6a8fa945..126f4c3e50ad 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -419,6 +419,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const 
Diag &D) {
   OS << Sep << Fix;
   Sep = ", ";
 }
+OS << "}";
   }
   return OS;
 }

diff  --git a/clang-tools-extra/clangd/IncludeFixer.cpp 
b/clang-tools-extra/clangd/IncludeFixer.cpp
index 8c020f2486f0..1f0515c1df70 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -193,6 +193,14 @@ std::vector 
IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
   case diag::err_no_member_suggest:
   case diag::err_no_member_template:
   case diag::err_no_member_template_suggest:
+  case diag::warn_implicit_function_decl:
+  case diag::ext_implicit_function_decl:
+  case diag::err_opencl_implicit_function_decl:
+dlog("Unresolved name at {0}, last typo was {1}",
+ Info.getLocation().printToString(Info.getSourceManager()),
+ LastUnresolvedName
+ ? LastUnresolvedName->Loc.printToString(Info.getSourceManager())
+ : "none");
 if (LastUnresolvedName) {
   // Try to fix unresolved name caused by missing declaration.
   // E.g.
@@ -205,8 +213,7 @@ std::vector IncludeFixer::fix(DiagnosticsEngine::Level 
DiagLevel,
   //  UnresolvedName
   // We only attempt to recover a diagnostic if it has the same location as
   // the last seen unresolved name.
-  if (DiagLevel >= DiagnosticsEngine::Error &&
-  LastUnresolvedName->Loc == Info.getLocation())
+  if (LastUnresolvedName->Loc == Info.getLocation())
 return fixUnresolvedName();
 }
 break;
@@ -481,6 +488,7 @@ class IncludeFixer::UnresolvedNameRecorder : public 
ExternalSemaSource {
  CorrectionCandidateCallback &CCC,
  DeclContext *MemberContext, bool EnteringContext,
  const ObjCObjectPointerType *OPT) override {
+dlog("CorrectTypo: {0}", Typo.getAsString());
 assert(SemaPtr && "Sema must have been set.");
 if (SemaPtr->isSFINAEContext())
   return TypoCorrection();

diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 732c36813800..42552e9831a0 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -30,6 +30,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
@@ -37,17 +38,10 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
-#include "clang/Frontend/Utils.h"
-#include "clang/Index/IndexDataConsumer.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
-#include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
-#include "clang/Lex/PreprocessorOptions.h"
-#include "clang/Sema/Sema.h"
 #include "clang/Serialization/ASTWriter.h"
-#include "clang/Serialization/PCHContainerOperations.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -55,7 +49,6 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm

[PATCH] D115490: [clangd] Include fixer for missing functions in C

2022-01-10 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG1ab13793beaf: [clangd] Include fixer for missing functions 
in C (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D115490?vs=393369&id=398556#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115490

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/lib/Sema/SemaDecl.cpp

Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15002,7 +15002,24 @@
 diag_id = diag::ext_implicit_function_decl;
   else
 diag_id = diag::warn_implicit_function_decl;
+
+  TypoCorrection Corrected;
+  // Because typo correction is expensive, only do it if the implicit
+  // function declaration is going to be treated as an error.
+  //
+  // Perform the corection before issuing the main diagnostic, as some consumers
+  // use typo-correction callbacks to enhance the main diagnostic.
+  if (S && !ExternCPrev &&
+  (Diags.getDiagnosticLevel(diag_id, Loc) >= DiagnosticsEngine::Error)) {
+DeclFilterCCC CCC{};
+Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc), LookupOrdinaryName,
+S, nullptr, CCC, CTK_NonError);
+  }
+
   Diag(Loc, diag_id) << &II;
+  if (Corrected)
+diagnoseTypo(Corrected, PDiag(diag::note_function_suggestion),
+ /*ErrorRecovery*/ false);
 
   // If we found a prior declaration of this function, don't bother building
   // another one. We've already pushed that one into scope, so there's nothing
@@ -15010,18 +15027,6 @@
   if (ExternCPrev)
 return ExternCPrev;
 
-  // Because typo correction is expensive, only do it if the implicit
-  // function declaration is going to be treated as an error.
-  if (Diags.getDiagnosticLevel(diag_id, Loc) >= DiagnosticsEngine::Error) {
-TypoCorrection Corrected;
-DeclFilterCCC CCC{};
-if (S && (Corrected =
-  CorrectTypo(DeclarationNameInfo(&II, Loc), LookupOrdinaryName,
-  S, nullptr, CCC, CTK_NonError)))
-  diagnoseTypo(Corrected, PDiag(diag::note_function_suggestion),
-   /*ErrorRecovery*/false);
-  }
-
   // Set a Declarator for the implicit definition: int foo();
   const char *Dummy;
   AttributeFactory attrFactory;
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1285,6 +1285,31 @@
   "Include  for symbol printf");
 }
 
+TEST(IncludeFixerTest, CImplicitFunctionDecl) {
+  Annotations Test("void x() { [[foo]](); }");
+  auto TU = TestTU::withCode(Test.code());
+  TU.Filename = "test.c";
+
+  Symbol Sym = func("foo");
+  Sym.Flags |= Symbol::IndexedForCodeCompletion;
+  Sym.CanonicalDeclaration.FileURI = "unittest:///foo.h";
+  Sym.IncludeHeaders.emplace_back("\"foo.h\"", 1);
+
+  SymbolSlab::Builder Slab;
+  Slab.insert(Sym);
+  auto Index =
+  MemIndex::build(std::move(Slab).build(), RefSlab(), RelationSlab());
+  TU.ExternalIndex = Index.get();
+
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  ElementsAre(AllOf(
+  Diag(Test.range(),
+   "implicit declaration of function 'foo' is invalid in C99"),
+  WithFix(Fix(Range{}, "#include \"foo.h\"\n",
+  "Include \"foo.h\" for symbol foo");
+}
+
 TEST(DiagsInHeaders, DiagInsideHeader) {
   Annotations Main(R"cpp(
 #include [["a.h"]]
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -30,6 +30,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
@@ -37,17 +38,10 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
-#include "clang/Frontend/Utils.h"
-#include "clang/Index/IndexDataConsumer.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
-#include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
-#include "clang/Lex/PreprocessorOptions.h"
-#include "clang/Sema/Sema.h"
 #include "clang/Serialization/ASTWriter.

[PATCH] D112646: [clang-tidy] Add `readability-container-contains` check

2022-01-10 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added a comment.

Happy new year! - and a gentle ping ;)

Afaict, there are only two smaller issues remaining (see non-closed inline 
comments):

- do we want a test expectation to check for unmodified code
- should we remove a couple of comments from the code

Personally, I have no real opinion on those questions. Would be happy to get 
some guidance here, @whisperity, so we can wrap this review up


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112646

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


[PATCH] D116490: [clangd] Code action to declare missing move/copy constructor/assignment

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp:72
+//
+// e.g. given `struct S{};`, produces:
+//   struct S {

nit: add trigger points.



Comment at: clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp:120
+// they should be =default or =delete.
+Inputs.AST->getSema().ForceDeclarationOfImplicitMembers(Class);
+std::string Code = buildSpecialMemberDeclarations(*Class);

I think we need this because these members are created lazily in clang, e.g. if 
the empty struct `s` is not used, there is no constructor decl being created.

The `ForceDeclarationOfImplicitMembers` is a member function which can mutate 
the parameter `Class`, I was wondering whether it would lead some bad 
side-effect, but I didn't come out one (and the mutation is mostly creating a 
new ctor-decl and adding it to the Class).



Comment at: clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp:146
+private:
+  bool NeedCopy, NeedMove;
+  CXXRecordDecl *Class = nullptr;

nit: add default value


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116490

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


[clang] d17fb46 - [Clang][AArch64][ARM] PMUv3.4 Option Added

2022-01-10 Thread Mubashar Ahmad via cfe-commits

Author: Mubashar Ahmad
Date: 2022-01-10T11:28:19Z
New Revision: d17fb46e894501568a1bf3b11a5d920817444630

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

LOG: [Clang][AArch64][ARM] PMUv3.4 Option Added

An option has been added to Clang to enable or disable
the PMU v3.4 architecture extension.

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

Added: 
clang/test/Driver/aarch64-perfmon.c
clang/test/Driver/arm-perfmon.c

Modified: 
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/include/llvm/Support/ARMTargetParser.def
llvm/include/llvm/Support/ARMTargetParser.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Driver/aarch64-perfmon.c 
b/clang/test/Driver/aarch64-perfmon.c
new file mode 100644
index 0..228e6d6f3f15a
--- /dev/null
+++ b/clang/test/Driver/aarch64-perfmon.c
@@ -0,0 +1,13 @@
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.4a+pmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-PERFMON %s
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2a+pmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-PERFMON %s
+// CHECK-PERFMON: "-target-feature" "+perfmon"
+
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.4a+nopmuv3p4 
%s 2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2a+nopmuv3p4 
%s 2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
+// CHECK-NOPERFMON: "-target-feature" "-perfmon"
+
+// RUN: %clang -### -target aarch64-none-none-eabi %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.4a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
+// ABSENTPERFMON-NOT: "-target-feature" "+perfmon"
+// ABSENTPERFMON-NOT: "-target-feature" "-perfmon"
\ No newline at end of file

diff  --git a/clang/test/Driver/arm-perfmon.c b/clang/test/Driver/arm-perfmon.c
new file mode 100644
index 0..618bd98044691
--- /dev/null
+++ b/clang/test/Driver/arm-perfmon.c
@@ -0,0 +1,13 @@
+// RUN: %clang -### -target arm-none-none-eabi -march=armv8.4a+pmuv3p4 %s 2>&1 
| FileCheck --check-prefix=CHECK-PERFMON %s
+// RUN: %clang -### -target arm-none-none-eabi -march=armv8.2a+pmuv3p4 %s 2>&1 
| FileCheck --check-prefix=CHECK-PERFMON %s
+// CHECK-PERFMON: "-target-feature" "+perfmon"
+
+// RUN: %clang -### -target arm-none-none-eabi -march=armv8.4a+nopmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
+// RUN: %clang -### -target arm-none-none-eabi -march=armv8.2a+nopmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
+// CHECK-NOPERFMON: "-target-feature" "-perfmon"
+
+// RUN: %clang -### -target arm-none-none-eabi %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
+// RUN: %clang -### -target arm-none-none-eabi -march=armv8.4a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
+// RUN: %clang -### -target arm-none-none-eabi -march=armv8.2a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
+// ABSENTPERFMON-NOT: "-target-feature" "+perfmon"
+// ABSENTPERFMON-NOT: "-target-feature" "-perfmon"
\ No newline at end of file

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.def 
b/llvm/include/llvm/Support/AArch64TargetParser.def
index 9d45f6abae6be..6619864e7ca16 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.def
+++ b/llvm/include/llvm/Support/AArch64TargetParser.def
@@ -144,6 +144,7 @@ AARCH64_ARCH_EXT_NAME("flagm",AArch64::AEK_FLAGM,   
"+flagm", "-flag
 AARCH64_ARCH_EXT_NAME("sme",  AArch64::AEK_SME, "+sme",   
"-sme")
 AARCH64_ARCH_EXT_NAME("sme-f64",  AArch64::AEK_SMEF64,  "+sme-f64", 
"-sme-f64")
 AARCH64_ARCH_EXT_NAME("sme-i64",  AArch64::AEK_SMEI64,  "+sme-i64", 
"-sme-i64")
+AARCH64_ARCH_EXT_NAME("pmuv3p4",  AArch64::AEK_PERFMON, "+perfmon", 
"-perfmon")
 #undef AARCH64_ARCH_EXT_NAME
 
 #ifndef AARCH64_CPU_NAME

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.h 
b/llvm/include/llvm/Support/AArch64TargetParser.h
index 15bb428f19bcd..06aad515c8bde 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.h
+++ b/llvm/include/llvm/Support/AArch64TargetParser.h
@@ -69,6 +69,7 @@ enum ArchExtKind : uint64_t {
   AEK_SME = 1ULL << 37,
   AEK_SMEF64 =  1ULL << 38,
   AEK_SMEI64 =  1ULL << 39,
+  AEK_PERFMON = 1ULL << 40,
 };
 
 enum class ArchKind {

diff  --git a/llvm/include/llvm/Support/ARMTargetParser.def 
b/llvm/include/llvm/Support/ARMTargetParser.def
index

[PATCH] D116748: [AArch64][ARM][Clang] PerfMon Extension Added

2022-01-10 Thread Mubashar Ahmad 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 rGd17fb46e8945: [Clang][AArch64][ARM] PMUv3.4 Option Added 
(authored by mubashar_).

Changed prior to commit:
  https://reviews.llvm.org/D116748?vs=397893&id=398558#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116748

Files:
  clang/test/Driver/aarch64-perfmon.c
  clang/test/Driver/arm-perfmon.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -728,7 +728,8 @@
   {"sb", "nosb", "+sb", "-sb"},
   {"i8mm", "noi8mm", "+i8mm", "-i8mm"},
   {"mve", "nomve", "+mve", "-mve"},
-  {"mve.fp", "nomve.fp", "+mve.fp", "-mve.fp"}};
+  {"mve.fp", "nomve.fp", "+mve.fp", "-mve.fp"},
+  {"pmuv3p4", "nopmuv3p4", "+perfmon", "-perfmon"}};
 
   for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
 EXPECT_EQ(StringRef(ArchExt[i][2]), ARM::getArchExtFeature(ArchExt[i][0]));
@@ -1428,17 +1429,14 @@
 
 TEST(TargetParserTest, AArch64ExtensionFeatures) {
   std::vector Extensions = {
-AArch64::AEK_CRC,  AArch64::AEK_CRYPTO,
-AArch64::AEK_FP,   AArch64::AEK_SIMD,
-AArch64::AEK_FP16, AArch64::AEK_PROFILE,
-AArch64::AEK_RAS,  AArch64::AEK_LSE,
-AArch64::AEK_RDM,  AArch64::AEK_DOTPROD,
-AArch64::AEK_SVE,  AArch64::AEK_SVE2,
-AArch64::AEK_SVE2AES,  AArch64::AEK_SVE2SM4,
-AArch64::AEK_SVE2SHA3, AArch64::AEK_SVE2BITPERM,
-AArch64::AEK_RCPC, AArch64::AEK_FP16FML,
-AArch64::AEK_SME,  AArch64::AEK_SMEF64,
-AArch64::AEK_SMEI64 };
+  AArch64::AEK_CRC, AArch64::AEK_CRYPTO,  AArch64::AEK_FP,
+  AArch64::AEK_SIMD,AArch64::AEK_FP16,AArch64::AEK_PROFILE,
+  AArch64::AEK_RAS, AArch64::AEK_LSE, AArch64::AEK_RDM,
+  AArch64::AEK_DOTPROD, AArch64::AEK_SVE, AArch64::AEK_SVE2,
+  AArch64::AEK_SVE2AES, AArch64::AEK_SVE2SM4, AArch64::AEK_SVE2SHA3,
+  AArch64::AEK_SVE2BITPERM, AArch64::AEK_RCPC,AArch64::AEK_FP16FML,
+  AArch64::AEK_SME, AArch64::AEK_SMEF64,  AArch64::AEK_SMEI64,
+  AArch64::AEK_PERFMON};
 
   std::vector Features;
 
@@ -1473,6 +1471,7 @@
   EXPECT_TRUE(llvm::is_contained(Features, "+sme"));
   EXPECT_TRUE(llvm::is_contained(Features, "+sme-f64"));
   EXPECT_TRUE(llvm::is_contained(Features, "+sme-i64"));
+  EXPECT_TRUE(llvm::is_contained(Features, "+perfmon"));
 }
 
 TEST(TargetParserTest, AArch64ArchFeatures) {
@@ -1485,43 +1484,41 @@
 }
 
 TEST(TargetParserTest, AArch64ArchExtFeature) {
-  const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
-  {"crypto", "nocrypto", "+crypto", "-crypto"},
-  {"flagm", "noflagm", "+flagm", "-flagm"},
-  {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
-  {"simd", "nosimd", "+neon", "-neon"},
-  {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
-  {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
-  {"profile", "noprofile", "+spe", "-spe"},
-  {"ras", "noras", "+ras", "-ras"},
-  {"lse", "nolse", "+lse", "-lse"},
-  {"rdm", "nordm", "+rdm", "-rdm"},
-  {"sve", "nosve", "+sve", "-sve"},
-  {"sve2", "nosve2", "+sve2", "-sve2"},
-  {"sve2-aes", "nosve2-aes", "+sve2-aes",
-   "-sve2-aes"},
-  {"sve2-sm4", "nosve2-sm4", "+sve2-sm4",
-   "-sve2-sm4"},
-  {"sve2-sha3", "nosve2-sha3", "+sve2-sha3",
-   "-sve2-sha3"},
-  {"sve2-bitperm", "nosve2-bitperm",
-   "+sve2-bitperm", "-sve2-bitperm"},
-  {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
-  {"rcpc", "norcpc", "+rcpc", "-rcpc" },
-  {"rng", "norng", "+rand", "-rand"},
-  {"memtag", "nomemtag", "+mte", "-mte"},
-  {"tme", "notme", "+tme", "-tme"},
-

[PATCH] D116906: [OpenMP][AMDGPU] Optimize the linked in math libraries

2022-01-10 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

Using the optimiser to hide errors in how we're pulling in libm is clearly not 
right, but it leaves us less obviously broken than we are at present.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116906

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


Re: [clang] 80e2c58 - [clang] Remove redundant member initialization (NFC)

2022-01-10 Thread Martin Storsjö via cfe-commits

On Sun, 9 Jan 2022, Kazu Hirata via cfe-commits wrote:



Author: Kazu Hirata
Date: 2022-01-09T00:19:51-08:00
New Revision: 80e2c587498a7b2bf14dde47a33a058da6e88a9a

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

LOG: [clang] Remove redundant member initialization (NFC)

Identified with readability-redundant-member-init.


While technically NFC, this causes lots of build warnings (689 warnings) 
when built with GCC, like this:


In file included from 
llvm-project/clang/include/clang/Basic/SourceManager.h:37:0,
 from 
llvm-project/clang/lib/Lex/ScratchBuffer.cpp:14:
llvm-project/clang/include/clang/Basic/Diagnostic.h: In 
copy constructor ‘clang::DiagnosticBuilder::DiagnosticBuilder(const 
clang::DiagnosticBuilder&)’:
llvm-project/clang/include/clang/Basic/Diagnostic.h:1329:3: 
warning: base class ‘class clang::StreamingDiagnostic’ should be 
explicitly initialized in the copy constructor [-Wextra]

   DiagnosticBuilder(const DiagnosticBuilder &D) {
   ^


With that in mind, I would like to revert this commit - is that ok with 
you?


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


[clang] abe3003 - [AST] Use recovery-expr to preserve incomplete-type-member-access expression.

2022-01-10 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-01-10T12:45:20+01:00
New Revision: abe3003ead808518190d1e9717495735786938d3

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

LOG: [AST] Use recovery-expr to preserve incomplete-type-member-access 
expression.

Fixes https://github.com/clangd/clangd/issues/502

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

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/OpenMP/declare_reduction_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4c6a96acdb91..b34b744d7312 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7410,8 +7410,10 @@ ExprResult Sema::ActOnStartCXXMemberReference(Scope *S, 
Expr *Base,
   //   the member function body.
   if (!BaseType->isDependentType() &&
   !isThisOutsideMemberFunctionBody(BaseType) &&
-  RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
-return ExprError();
+  RequireCompleteType(OpLoc, BaseType,
+  diag::err_incomplete_member_access)) {
+return CreateRecoveryExpr(Base->getBeginLoc(), Base->getEndLoc(), {Base});
+  }
 
   // C++ [basic.lookup.classref]p2:
   //   If the id-expression in a class member access (5.2.5) is an

diff  --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index c196f629bad9..0bdd726ab3ce 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -121,6 +121,16 @@ void test(int x) {
   foo->func(x);
 }
 
+void AccessIncompleteClass() {
+  struct Forward;
+  Forward* ptr;
+  // CHECK:  CallExpr {{.*}} ''
+  // CHECK-NEXT: `-CXXDependentScopeMemberExpr {{.*}} ''
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Forward *'
+  ptr->method();
+}
+
 struct Foo2 {
   double func();
   class ForwardClass;

diff  --git a/clang/test/OpenMP/declare_reduction_messages.cpp 
b/clang/test/OpenMP/declare_reduction_messages.cpp
index b1e59591d998..38a5d766eead 100644
--- a/clang/test/OpenMP/declare_reduction_messages.cpp
+++ b/clang/test/OpenMP/declare_reduction_messages.cpp
@@ -169,7 +169,6 @@ struct S
   #pragma omp declare reduction (xxx : U, S : bar(omp_in)) // expected-error 
{{non-const lvalue reference to type 'S<1>' cannot bind to a value of unrelated 
type 'U'}}
   static void bar(S &x); // expected-note {{passing argument to parameter 'x' 
here}}
 };
-// expected-warning@+2 {{extra tokens at the end of '#pragma omp declare 
reduction' are ignored}}
 // expected-note@+1 {{in instantiation of template class 'S<1>' requested 
here}}
 #pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in))
 



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


[PATCH] D116922: [AST] Use recovery-expr to preserve incomplete-type-member-access expression.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGabe3003ead80: [AST] Use recovery-expr to preserve 
incomplete-type-member-access expression. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116922

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/OpenMP/declare_reduction_messages.cpp


Index: clang/test/OpenMP/declare_reduction_messages.cpp
===
--- clang/test/OpenMP/declare_reduction_messages.cpp
+++ clang/test/OpenMP/declare_reduction_messages.cpp
@@ -169,7 +169,6 @@
   #pragma omp declare reduction (xxx : U, S : bar(omp_in)) // expected-error 
{{non-const lvalue reference to type 'S<1>' cannot bind to a value of unrelated 
type 'U'}}
   static void bar(S &x); // expected-note {{passing argument to parameter 'x' 
here}}
 };
-// expected-warning@+2 {{extra tokens at the end of '#pragma omp declare 
reduction' are ignored}}
 // expected-note@+1 {{in instantiation of template class 'S<1>' requested 
here}}
 #pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in))
 
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -121,6 +121,16 @@
   foo->func(x);
 }
 
+void AccessIncompleteClass() {
+  struct Forward;
+  Forward* ptr;
+  // CHECK:  CallExpr {{.*}} ''
+  // CHECK-NEXT: `-CXXDependentScopeMemberExpr {{.*}} ''
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Forward *'
+  ptr->method();
+}
+
 struct Foo2 {
   double func();
   class ForwardClass;
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7410,8 +7410,10 @@
   //   the member function body.
   if (!BaseType->isDependentType() &&
   !isThisOutsideMemberFunctionBody(BaseType) &&
-  RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
-return ExprError();
+  RequireCompleteType(OpLoc, BaseType,
+  diag::err_incomplete_member_access)) {
+return CreateRecoveryExpr(Base->getBeginLoc(), Base->getEndLoc(), {Base});
+  }
 
   // C++ [basic.lookup.classref]p2:
   //   If the id-expression in a class member access (5.2.5) is an


Index: clang/test/OpenMP/declare_reduction_messages.cpp
===
--- clang/test/OpenMP/declare_reduction_messages.cpp
+++ clang/test/OpenMP/declare_reduction_messages.cpp
@@ -169,7 +169,6 @@
   #pragma omp declare reduction (xxx : U, S : bar(omp_in)) // expected-error {{non-const lvalue reference to type 'S<1>' cannot bind to a value of unrelated type 'U'}}
   static void bar(S &x); // expected-note {{passing argument to parameter 'x' here}}
 };
-// expected-warning@+2 {{extra tokens at the end of '#pragma omp declare reduction' are ignored}}
 // expected-note@+1 {{in instantiation of template class 'S<1>' requested here}}
 #pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in))
 
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -121,6 +121,16 @@
   foo->func(x);
 }
 
+void AccessIncompleteClass() {
+  struct Forward;
+  Forward* ptr;
+  // CHECK:  CallExpr {{.*}} ''
+  // CHECK-NEXT: `-CXXDependentScopeMemberExpr {{.*}} ''
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Forward *'
+  ptr->method();
+}
+
 struct Foo2 {
   double func();
   class ForwardClass;
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7410,8 +7410,10 @@
   //   the member function body.
   if (!BaseType->isDependentType() &&
   !isThisOutsideMemberFunctionBody(BaseType) &&
-  RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
-return ExprError();
+  RequireCompleteType(OpLoc, BaseType,
+  diag::err_incomplete_member_access)) {
+return CreateRecoveryExpr(Base->getBeginLoc(), Base->getEndLoc(), {Base});
+  }
 
   // C++ [basic.lookup.classref]p2:
   //   If the id-expression in a class member access (5.2.5) is an
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116925: [clangd] Suppress warning about system_header pragma when editing headers

2022-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Not sure it's OK to suppress this in clang itself - if we're building a PCH
or module, maybe it matters?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116925

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -350,7 +350,8 @@
   PreambleDiagnostics.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) {
 if (Cfg.Diagnostics.SuppressAll ||
-isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress))
+isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress,
+  *CI.getLangOpts()))
   return DiagnosticsEngine::Ignored;
 switch (Info.getID()) {
 case diag::warn_no_newline_eof:
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -445,7 +445,8 @@
 ASTDiags.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
   const clang::Diagnostic &Info) {
   if (Cfg.Diagnostics.SuppressAll ||
-  isBuiltinDiagnosticSuppressed(Info.getID(), 
Cfg.Diagnostics.Suppress))
+  isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress,
+Clang->getLangOpts()))
 return DiagnosticsEngine::Ignored;
 
   auto It = OverriddenSeverity.find(Info.getID());
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -879,7 +879,13 @@
 }
 
 bool isBuiltinDiagnosticSuppressed(unsigned ID,
-   const llvm::StringSet<> &Suppress) {
+   const llvm::StringSet<> &Suppress,
+   const LangOptions &LangOpts) {
+  // Don't complain about header-only stuff in mainfiles if the main file is a
+  // header. (Not clear if this is reasonable to suppress in clang).
+  if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile)
+return true;
+
   if (const char *CodePtr = getDiagnosticCode(ID)) {
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -350,7 +350,8 @@
   PreambleDiagnostics.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) {
 if (Cfg.Diagnostics.SuppressAll ||
-isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress))
+isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress,
+  *CI.getLangOpts()))
   return DiagnosticsEngine::Ignored;
 switch (Info.getID()) {
 case diag::warn_no_newline_eof:
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -445,7 +445,8 @@
 ASTDiags.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
   const clang::Diagnostic &Info) {
   if (Cfg.Diagnostics.SuppressAll ||
-  isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress))
+  isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress,
+Clang->getLangOpts()))
 return DiagnosticsEngine::Ignored;
 
   auto It = OverriddenSeverity.find(Info.getID());
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -879,7 +879,13 @@
 }
 
 bool isBuiltinDiagnosticSuppressed(unsigned ID,
-   const llvm::StringSet<> &Suppress) {
+   const llvm::StringSet<> &Suppress,
+   const LangOptions &LangOpts) {
+  // Don't complain about header-only stuff in mainfiles if the main file is a
+  // header. (No

[PATCH] D116925: [clangd] Suppress warning about system_header pragma when editing headers

2022-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I wasn't sure whether to suppress this in clang or clangd, wonder what you 
think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116925

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


[clang] 55d96ac - [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-10 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-01-10T12:46:27+01:00
New Revision: 55d96ac3dc56bdebea854952a724c2a50d96ce19

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

LOG: [AST] Add RParen loc for decltype AutoTypeloc.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang/include/clang/AST/TypeLoc.h
clang/lib/AST/TypeLoc.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/AST/ast-dump-template-decls-json.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 7e19f07a2215e..0f4464122c8fb 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -391,6 +391,8 @@ TEST(SelectionTest, CommonAncestor) {
 )cpp",
   "DeclRefExpr"},
   {"[[decltype^(1)]] b;", "DecltypeTypeLoc"}, // Not the VarDecl.
+  // decltype(auto) is an AutoTypeLoc!
+  {"[[de^cltype(a^uto)]] a = 1;", "AutoTypeLoc"},
 
   // Objective-C nullability attributes.
   {

diff  --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 9a43d34a9ec38..9c7ab4e8ddb7b 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -2081,6 +2081,9 @@ struct AutoTypeLocInfo : TypeSpecLocInfo {
   NamedDecl *FoundDecl;
   SourceLocation LAngleLoc;
   SourceLocation RAngleLoc;
+
+  // For decltype(auto).
+  SourceLocation RParenLoc;
 };
 
 class AutoTypeLoc
@@ -2093,6 +2096,10 @@ class AutoTypeLoc
 return getTypePtr()->getKeyword();
   }
 
+  bool isDecltypeAuto() const { return getTypePtr()->isDecltypeAuto(); }
+  SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
+  void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
+
   bool isConstrained() const {
 return getTypePtr()->isConstrained();
   }
@@ -2173,16 +2180,13 @@ class AutoTypeLoc
   }
 
   SourceRange getLocalSourceRange() const {
-return{
-isConstrained()
-  ? (getNestedNameSpecifierLoc()
-   ? getNestedNameSpecifierLoc().getBeginLoc()
-   : (getTemplateKWLoc().isValid()
-  ? getTemplateKWLoc()
-  : getConceptNameLoc()))
-  : getNameLoc(),
-getNameLoc()
-};
+return {isConstrained()
+? (getNestedNameSpecifierLoc()
+   ? getNestedNameSpecifierLoc().getBeginLoc()
+   : (getTemplateKWLoc().isValid() ? getTemplateKWLoc()
+   : getConceptNameLoc()))
+: getNameLoc(),
+isDecltypeAuto() ? getRParenLoc() : getNameLoc()};
   }
 
   void copy(AutoTypeLoc Loc) {

diff  --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index c3ed08d5a8b3e..13aa54c48f66c 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -622,6 +622,7 @@ void AutoTypeLoc::initializeLocal(ASTContext &Context, 
SourceLocation Loc) {
   setFoundDecl(nullptr);
   setRAngleLoc(Loc);
   setLAngleLoc(Loc);
+  setRParenLoc(Loc);
   TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
getTypePtr()->getArgs(),
getArgInfos(), Loc);

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index f0bbbcf59c751..959f4903b0306 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/PartialDiagnostic.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/DeclSpec.h"
@@ -6041,6 +6042,8 @@ namespace {
  DS.getTypeSpecType() == TST_auto_type ||
  DS.getTypeSpecType() == TST_unspecified);
   TL.setNameLoc(DS.getTypeSpecTypeLoc());
+  if (DS.getTypeSpecType() == TST_decltype_auto)
+TL.setRParenLoc(DS.getTypeofParensRange().getEnd());
   if (!DS.isConstrainedAuto())
 return;
   TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index b8ec5b2722a95..9056f00978c8f 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -6652,6 +6652,8 @@ void TypeLocReader::VisitAutoTypeLoc(AutoTy

[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-10 Thread Haojian Wu 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 rG55d96ac3dc56: [AST] Add RParen loc for decltype AutoTypeloc. 
(authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116919

Files:
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang/include/clang/AST/TypeLoc.h
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/unittests/AST/SourceLocationTest.cpp

Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -242,6 +242,13 @@
   verify(Target2->getSourceRange(), Code.range("full2"));
 }
 
+TEST(TypeLoc, AutoTypeLocRange) {
+  RangeVerifier Verifier;
+  Verifier.expectRange(1, 1, 1, 14);
+  EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())),
+ Lang_CXX11));
+}
+
 TEST(TypeLoc, LongDoubleRange) {
   RangeVerifier Verifier;
   Verifier.expectRange(1, 1, 1, 6);
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -90,7 +90,7 @@
 
 template 
 // CHECK: ClassTemplateDecl 0x{{[^ ]*}}  col:8 U
-// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}}  col:25 'decltype(auto)' depth 0 index 0
+// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}}  col:25 'decltype(auto)' depth 0 index 0
 struct U {};
 
 template 
Index: clang/test/AST/ast-dump-template-decls-json.cpp
===
--- clang/test/AST/ast-dump-template-decls-json.cpp
+++ clang/test/AST/ast-dump-template-decls-json.cpp
@@ -2130,9 +2130,9 @@
 // CHECK-NEXT:"tokLen": 8
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": 705,
-// CHECK-NEXT:"col": 11,
-// CHECK-NEXT:"tokLen": 8
+// CHECK-NEXT:"offset": 718,
+// CHECK-NEXT:"col": 24,
+// CHECK-NEXT:"tokLen": 1
 // CHECK-NEXT:   }
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "type": {
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -452,6 +452,9 @@
   Record.AddTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(),
 TL.getArgLocInfo(I));
   }
+  Record.push_back(TL.isDecltypeAuto());
+  if (TL.isDecltypeAuto())
+Record.AddSourceLocation(TL.getRParenLoc());
 }
 
 void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc(
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -6652,6 +6652,8 @@
   TL.setArgLocInfo(i, Reader.readTemplateArgumentLocInfo(
   TL.getTypePtr()->getArg(i).getKind()));
   }
+  if (Reader.readBool())
+TL.setRParenLoc(readSourceLocation());
 }
 
 void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc(
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/PartialDiagnostic.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/DeclSpec.h"
@@ -6041,6 +6042,8 @@
  DS.getTypeSpecType() == TST_auto_type ||
  DS.getTypeSpecType() == TST_unspecified);
   TL.setNameLoc(DS.getTypeSpecTypeLoc());
+  if (DS.getTypeSpecType() == TST_decltype_auto)
+TL.setRParenLoc(DS.getTypeofParensRange().getEnd());
   if (!DS.isConstrainedAuto())
 return;
   TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();
Index: clang/lib/AST/TypeLoc.cpp
===
--- clang/lib/AST/TypeLoc.cpp
+++ clang/lib/AST/TypeLoc.cpp
@@ -622,6 +622,7 @@
   setFoundDecl(nullptr);
   setRAngleLoc(Loc);
   setLAngleLoc(Loc);
+  setRParenLoc(Loc);
   TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
getTypePtr()->getArgs(),
getArgInfos(), Loc);
Index: clang/include/clang/AST/TypeLoc.h
=

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

2022-01-10 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

RFC to clang dev list: 
https://lists.llvm.org/pipermail/cfe-dev/2022-January/069658.html


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

https://reviews.llvm.org/D116266

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


[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

2022-01-10 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

Starting producing `SymbolCast` you should be careful. Please pay attention on 
my revision D105340  before doing this. I 
don't want you walk through the thing I fought.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932

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


[PATCH] D116925: [clangd] Suppress warning about system_header pragma when editing headers

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D116925#3230991 , @sammccall wrote:

> I wasn't sure whether to suppress this in clang or clangd, wonder what you 
> think.

I think it is fine to do it in clang. `pp_pragma_once_in_main_file` is a 
similar diag, and clang has already suppressed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116925

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


[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

2022-01-10 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:415-423
+  // FIXME This should be done in getAsSymbol. But then getAsSymbol should be
+  // the member function of SValBuilder (?)
+  if (symRHS)
+if (auto RLocAsInt = RHS.getAs()) {
+  auto FromTy = symRHS->getType();
+  auto ToTy = RLocAsInt->getType(this->Context);
+  symRHS = this->getSymbolManager().getCastSymbol(symRHS, FromTy, ToTy);

IMO this is not the right place for producing `SymbolCast` because we can meet 
`(type)x`-like semantics in a different contexts and expressions.



Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:419-420
+if (auto RLocAsInt = RHS.getAs()) {
+  auto FromTy = symRHS->getType();
+  auto ToTy = RLocAsInt->getType(this->Context);
+  symRHS = this->getSymbolManager().getCastSymbol(symRHS, FromTy, ToTy);

According to https://llvm.org/docs/CodingStandards.html#id28



Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:471-478
+  if (Optional RV = rhs.getAs()) {
+// Support pointer arithmetic where the addend is on the left
+// and the pointer on the right.
 
-if (IsCommutative(op)) {
-  // Swap operands.
-  return evalBinOpLN(state, op, *RV, lhs.castAs(), type);
-}
+assert(op == BO_Add);
 
+// Commute the operands.

This can be carried out to the separate revert revision as it is not related to 
this one directly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932

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


[clang-tools-extra] 37ec65e - [clangd] Enable expand-auto for decltype(auto).

2022-01-10 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-01-10T13:46:56+01:00
New Revision: 37ec65e1d705f56fe5551de1dfcbac1e071588a2

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

LOG: [clangd] Enable expand-auto for decltype(auto).

Based on https://reviews.llvm.org/D116919.

Fixes https://github.com/clangd/clangd/issues/121

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index 3776e1c3505d1..914564e9ae218 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,9 +96,7 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
 if (auto *TypeNode = Node->ASTNode.get()) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
-// Code in apply() does handle 'decltype(auto)' yet.
-if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node) &&
+if (!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
   CachedLocation = Result;

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
index 96574a67b5a46..6d9d4362be7af 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,7 +71,8 @@ TEST_F(ExpandAutoTypeTest, Test) {
   apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
   "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
 
-  EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+  EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
+  EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
   // expanding types in structured bindings is syntactically invalid.
   EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
 



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


[PATCH] D116921: [clangd] Enable expand-auto for decltype(auto).

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37ec65e1d705: [clangd] Enable expand-auto for 
decltype(auto). (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116921

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,7 +71,8 @@
   apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
   "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
 
-  EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+  EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
+  EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
   // expanding types in structured bindings is syntactically invalid.
   EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,9 +96,7 @@
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
 if (auto *TypeNode = Node->ASTNode.get()) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
-// Code in apply() does handle 'decltype(auto)' yet.
-if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node) &&
+if (!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
   CachedLocation = Result;


Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,7 +71,8 @@
   apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
   "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
 
-  EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+  EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
+  EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
   // expanding types in structured bindings is syntactically invalid.
   EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,9 +96,7 @@
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
 if (auto *TypeNode = Node->ASTNode.get()) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
-// Code in apply() does handle 'decltype(auto)' yet.
-if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node) &&
+if (!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
   CachedLocation = Result;
___
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

2022-01-10 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM.  I made some minor comments, that can be fixed before committing.




Comment at: clang/docs/UsersManual.rst:3567
 
+Linking is done using `spirv-link` linker from `the SPIRV-Tools project
+`_. Similar to other

(or: "+the spirv-link linker")



Comment at: clang/docs/UsersManual.rst:3569
+`_. Similar to other
+linkers Clang will expect `spirv-link` to be installed separately and to be
+present in the ``PATH`` environment variable. Please refer to `the build and





Comment at: clang/lib/Driver/ToolChains/SPIRV.cpp:78
+void SPIRV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+  const InputInfo &Output,
+  const InputInfoList &Inputs,

Indentation seems to be slightly off?  Can be fixed on commit.


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

https://reviews.llvm.org/D116266

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


[PATCH] D116503: [clang] Add --start-no-unused-arguments/--end-no-unused-arguments to silence some unused argument warnings

2022-01-10 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D116503#3223094 , @MaskRay wrote:

> But make sure to wait a bit to see what others think.

Do you think it's ok to go ahead and land this change now, or should I wait a 
bit more? (I'd like to have it landed with enough margin before the 14.x branch 
so that it has time to settle before that.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116503

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


[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

2022-01-10 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:420
+  auto FromTy = symRHS->getType();
+  auto ToTy = RLocAsInt->getType(this->Context);
+  symRHS = this->getSymbolManager().getCastSymbol(symRHS, FromTy, ToTy);

Please take into account that `SVal::getType` may return NULL `QualType`. See 
function's description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932

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


[PATCH] D116643: [clangd] Don't rename on symbols from system headers.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 398588.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116643

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1198,6 +1198,29 @@
 expectedResult(Code, NewName));
 }
 
+TEST(RenameTest, NoRenameOnSymbolsFromSystemHeaders) {
+  // Filter out references not from main file.
+  llvm::StringRef Test =
+  R"cpp(
+#include 
+SystemSym^bol abc;
+)cpp";
+
+  Annotations Code(Test);
+  auto TU = TestTU::withCode(Code.code());
+  TU.AdditionalFiles["system"] = R"cpp(
+class SystemSymbol {};
+)cpp";
+  TU.ExtraArgs = {"-isystem", testRoot()};
+  auto AST = TU.build();
+  llvm::StringRef NewName = "abcde";
+
+  auto Results = rename({Code.point(), NewName, AST, testPath(TU.Filename)});
+  EXPECT_FALSE(Results) << "expected rename returned an error: " << 
Code.code();
+  auto ActualMessage = llvm::toString(Results.takeError());
+  EXPECT_THAT(ActualMessage, testing::HasSubstr("not a supported kind"));
+}
+
 TEST(RenameTest, ProtobufSymbolIsExcluded) {
   Annotations Code("Prot^obuf buf;");
   auto TU = TestTU::withCode(Code.code());
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -159,13 +159,17 @@
   return Result;
 }
 
-// By default, we exclude C++ standard symbols and protobuf symbols as rename
-// these symbols would change system/generated files which are unlikely to be
-// modified.
+// By default, we exclude symbols from system headers and protobuf symbols as
+// renaming these symbols would change system/generated files which are 
unlikely
+// to be good candidates for modification.
 bool isExcluded(const NamedDecl &RenameDecl) {
-  if (isProtoFile(RenameDecl.getLocation(),
-  RenameDecl.getASTContext().getSourceManager()))
+  const auto &SM = RenameDecl.getASTContext().getSourceManager();
+  if (SM.isInSystemHeader(RenameDecl.getLocation()))
 return true;
+  if (isProtoFile(RenameDecl.getLocation(), SM))
+return true;
+  // FIXME: Remove this std symbol list, as they should be covered by the
+  // above isInSystemHeader check.
   static const auto *StdSymbols = new llvm::DenseSet({
 #define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name},
 #include "StdSymbolMap.inc"
@@ -248,6 +252,7 @@
 }
 llvm_unreachable("unhandled reason kind");
   };
+  // abc
   return error("Cannot rename symbol: {0}", Message(Reason));
 }
 


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1198,6 +1198,29 @@
 expectedResult(Code, NewName));
 }
 
+TEST(RenameTest, NoRenameOnSymbolsFromSystemHeaders) {
+  // Filter out references not from main file.
+  llvm::StringRef Test =
+  R"cpp(
+#include 
+SystemSym^bol abc;
+)cpp";
+
+  Annotations Code(Test);
+  auto TU = TestTU::withCode(Code.code());
+  TU.AdditionalFiles["system"] = R"cpp(
+class SystemSymbol {};
+)cpp";
+  TU.ExtraArgs = {"-isystem", testRoot()};
+  auto AST = TU.build();
+  llvm::StringRef NewName = "abcde";
+
+  auto Results = rename({Code.point(), NewName, AST, testPath(TU.Filename)});
+  EXPECT_FALSE(Results) << "expected rename returned an error: " << Code.code();
+  auto ActualMessage = llvm::toString(Results.takeError());
+  EXPECT_THAT(ActualMessage, testing::HasSubstr("not a supported kind"));
+}
+
 TEST(RenameTest, ProtobufSymbolIsExcluded) {
   Annotations Code("Prot^obuf buf;");
   auto TU = TestTU::withCode(Code.code());
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -159,13 +159,17 @@
   return Result;
 }
 
-// By default, we exclude C++ standard symbols and protobuf symbols as rename
-// these symbols would change system/generated files which are unlikely to be
-// modified.
+// By default, we exclude symbols from system headers and protobuf symbols as
+// renaming these symbols would change system/generated files which are unlikely
+// to be good candidates for modification.
 bool isExcluded(const NamedDecl &RenameDecl) {
-  if (isProtoFile(RenameDecl.getLocation(),
-  RenameDecl.getASTC

[PATCH] D116643: [clangd] Don't rename on symbols from system headers.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 398589.
hokein added a comment.

remove accident changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116643

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1198,6 +1198,29 @@
 expectedResult(Code, NewName));
 }
 
+TEST(RenameTest, NoRenameOnSymbolsFromSystemHeaders) {
+  // Filter out references not from main file.
+  llvm::StringRef Test =
+  R"cpp(
+#include 
+SystemSym^bol abc;
+)cpp";
+
+  Annotations Code(Test);
+  auto TU = TestTU::withCode(Code.code());
+  TU.AdditionalFiles["system"] = R"cpp(
+class SystemSymbol {};
+)cpp";
+  TU.ExtraArgs = {"-isystem", testRoot()};
+  auto AST = TU.build();
+  llvm::StringRef NewName = "abcde";
+
+  auto Results = rename({Code.point(), NewName, AST, testPath(TU.Filename)});
+  EXPECT_FALSE(Results) << "expected rename returned an error: " << 
Code.code();
+  auto ActualMessage = llvm::toString(Results.takeError());
+  EXPECT_THAT(ActualMessage, testing::HasSubstr("not a supported kind"));
+}
+
 TEST(RenameTest, ProtobufSymbolIsExcluded) {
   Annotations Code("Prot^obuf buf;");
   auto TU = TestTU::withCode(Code.code());
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -159,13 +159,17 @@
   return Result;
 }
 
-// By default, we exclude C++ standard symbols and protobuf symbols as rename
-// these symbols would change system/generated files which are unlikely to be
-// modified.
+// By default, we exclude symbols from system headers and protobuf symbols as
+// renaming these symbols would change system/generated files which are 
unlikely
+// to be good candidates for modification.
 bool isExcluded(const NamedDecl &RenameDecl) {
-  if (isProtoFile(RenameDecl.getLocation(),
-  RenameDecl.getASTContext().getSourceManager()))
+  const auto &SM = RenameDecl.getASTContext().getSourceManager();
+  if (SM.isInSystemHeader(RenameDecl.getLocation()))
 return true;
+  if (isProtoFile(RenameDecl.getLocation(), SM))
+return true;
+  // FIXME: Remove this std symbol list, as they should be covered by the
+  // above isInSystemHeader check.
   static const auto *StdSymbols = new llvm::DenseSet({
 #define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name},
 #include "StdSymbolMap.inc"


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1198,6 +1198,29 @@
 expectedResult(Code, NewName));
 }
 
+TEST(RenameTest, NoRenameOnSymbolsFromSystemHeaders) {
+  // Filter out references not from main file.
+  llvm::StringRef Test =
+  R"cpp(
+#include 
+SystemSym^bol abc;
+)cpp";
+
+  Annotations Code(Test);
+  auto TU = TestTU::withCode(Code.code());
+  TU.AdditionalFiles["system"] = R"cpp(
+class SystemSymbol {};
+)cpp";
+  TU.ExtraArgs = {"-isystem", testRoot()};
+  auto AST = TU.build();
+  llvm::StringRef NewName = "abcde";
+
+  auto Results = rename({Code.point(), NewName, AST, testPath(TU.Filename)});
+  EXPECT_FALSE(Results) << "expected rename returned an error: " << Code.code();
+  auto ActualMessage = llvm::toString(Results.takeError());
+  EXPECT_THAT(ActualMessage, testing::HasSubstr("not a supported kind"));
+}
+
 TEST(RenameTest, ProtobufSymbolIsExcluded) {
   Annotations Code("Prot^obuf buf;");
   auto TU = TestTU::withCode(Code.code());
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -159,13 +159,17 @@
   return Result;
 }
 
-// By default, we exclude C++ standard symbols and protobuf symbols as rename
-// these symbols would change system/generated files which are unlikely to be
-// modified.
+// By default, we exclude symbols from system headers and protobuf symbols as
+// renaming these symbols would change system/generated files which are unlikely
+// to be good candidates for modification.
 bool isExcluded(const NamedDecl &RenameDecl) {
-  if (isProtoFile(RenameDecl.getLocation(),
-  RenameDecl.getASTContext().getSourceManager()))
+  const auto &SM = RenameDecl.getASTContext().getSourceManager();
+  if (SM.isInSystemHeader(RenameDecl.getLocation()))
 return true;
+  if (isProtoFile(Renam

[PATCH] D116643: [clangd] Don't rename on symbols from system headers.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:171
+return true;
+  // FIXME: Remove this std symbol list, as they should be covered by the
+  // above isInSystemHeader check.

kbobyrev wrote:
> Any reason not to do this right now? (if we keep the comment, then it's 
> probably better as "Remove this check because it is redundant in the presence 
> of isInSystemHeader")
We could do it in this patch, I slightly prefer to do it in a followup patch, 
it'd require some changes in the unittests. (this FIXME was added in the last 
minute -- at the very beginning I didn't notice that it could be simplified) 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116643

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


[PATCH] D116595: [clang][sema] Add missing diagnostic parameter

2022-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Modules/cxx20-export-import.cpp:1-2
+
+// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t 
-fimplicit-module-maps -I%S/Inputs -stdlib=libc++ -verify %s
+export import dummy; // expected-error {{export declaration can only be used 
within a module interface unit after the module declaration}}

Also, does this test require `-fmodules-cache-path=%t` or 
`-fimplicit-module-maps`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116595

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


[clang] f282b68 - set __NO_MATH_ERRNO__ if -fno-math-errno

2022-01-10 Thread Aaron Ballman via cfe-commits

Author: Alex Xu (Hello71)
Date: 2022-01-10T08:45:46-05:00
New Revision: f282b6809105075b65974989459ee420ecd406e9

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

LOG: set __NO_MATH_ERRNO__ if -fno-math-errno

This causes modern glibc to unset math_errhandling MATH_ERRNO. gcc 12
also sets some other macros, but most of them are associated with
flags ignored by clang, so without library examples, it is difficult to
determine whether they should be set. I think setting this one macro is
OK for now.

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Preprocessor/init-aarch64.c
clang/test/Preprocessor/init.c
clang/test/Preprocessor/predefined-macros.c

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 629f991106616..ec40170b0a788 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1039,6 +1039,9 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 
   Builder.defineMacro("__USER_LABEL_PREFIX__", TI.getUserLabelPrefix());
 
+  if (!LangOpts.MathErrno)
+Builder.defineMacro("__NO_MATH_ERRNO__");
+
   if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
 Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
   else

diff  --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/test/Preprocessor/init-aarch64.c
index 3b6f4ddaabde8..8787d24f01cee 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -192,6 +192,7 @@
 // AARCH64-NEXT: #define __LONG_MAX__ 9223372036854775807L
 // AARCH64-NEXT: #define __LP64__ 1
 // AARCH64-NEXT: #define __NO_INLINE__ 1
+// AARCH64-NEXT: #define __NO_MATH_ERRNO__ 1
 // AARCH64-NEXT: #define __OBJC_BOOL_IS_BOOL 0
 // AARCH64-NEXT: #define __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES 3
 // AARCH64-NEXT: #define __OPENCL_MEMORY_SCOPE_DEVICE 2

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 7d838413b8513..45d494112a4f5 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1691,6 +1691,7 @@
 // WEBASSEMBLY64-NEXT:#define __LONG_MAX__ 9223372036854775807L
 // WEBASSEMBLY64-NEXT:#define __LP64__ 1
 // WEBASSEMBLY-NEXT:#define __NO_INLINE__ 1
+// WEBASSEMBLY-NEXT:#define __NO_MATH_ERRNO__ 1
 // WEBASSEMBLY-NEXT:#define __OBJC_BOOL_IS_BOOL 0
 // WEBASSEMBLY-NEXT:#define __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES 3
 // WEBASSEMBLY-NEXT:#define __OPENCL_MEMORY_SCOPE_DEVICE 2

diff  --git a/clang/test/Preprocessor/predefined-macros.c 
b/clang/test/Preprocessor/predefined-macros.c
index 2304eb82b50df..0b67cbe233ca2 100644
--- a/clang/test/Preprocessor/predefined-macros.c
+++ b/clang/test/Preprocessor/predefined-macros.c
@@ -60,6 +60,15 @@
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-FAST-MATH
 // CHECK-FAST-MATH: #define __FAST_MATH__ 1
 // CHECK-FAST-MATH: #define __FINITE_MATH_ONLY__ 1
+// CHECK-FAST-MATH: #define __NO_MATH_ERRNO__ 1
+//
+// RUN: %clang_cc1 %s -E -dM -fmath-errno -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-MATH-ERRNO
+// CHECK-MATH-ERRNO-NOT: __NO_MATH_ERRNO__
+//
+// RUN: %clang %s -E -dM -fno-math-errno -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-NO-MATH-ERRNO
+// CHECK-NO-MATH-ERRNO: #define __NO_MATH_ERRNO__ 1
 //
 // RUN: %clang_cc1 %s -E -dM -ffinite-math-only -o - \
 // RUN:   | FileCheck -match-full-lines %s 
--check-prefix=CHECK-FINITE-MATH-ONLY



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


[PATCH] D116337: [clang] set __NO_MATH_ERRNO__ if -fno-math-errno

2022-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Thanks for the patch! I've landed on your behalf in 
f282b6809105075b65974989459ee420ecd406e9 
.


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

https://reviews.llvm.org/D116337

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


[clang] d2cc6c2 - Use a sorted array instead of a map to store AttrBuilder string attributes

2022-01-10 Thread via cfe-commits

Author: Serge Guelton
Date: 2022-01-10T14:49:53+01:00
New Revision: d2cc6c2d0c2f8a6e272110416a3fd579ed5a3ac1

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

LOG: Use a sorted array instead of a map to store AttrBuilder string attributes

Using and std::map for target dependent attributes is
inefficient: it makes its constructor slightly heavier, and involves extra
allocation for each new string attribute. Storing the attribute key/value as
strings implies extra allocation/copy step.

Use a sorted vector instead. Given the low number of attributes generally
involved, this is cheaper, as showcased by

https://llvm-compile-time-tracker.com/compare.php?from=5de322295f4ade692dc4f1823ae4450ad3c48af2&to=05bc480bf641a9e3b466619af43a2d123ee3f71d&stat=instructions

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

Added: 


Modified: 
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/TargetInfo.cpp
llvm/include/llvm/CodeGen/IndirectThunks.h
llvm/include/llvm/IR/Attributes.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/CodeGen/Analysis.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/tools/bugpoint/CrashDebugger.cpp
llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp
llvm/unittests/ExecutionEngine/Orc/IndirectionUtilsTest.cpp
llvm/unittests/IR/AttributesTest.cpp
llvm/unittests/IR/InstructionsTest.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index e81c5ba5055c6..6532f02879612 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -307,7 +307,7 @@ static RValue emitAtomicLibcall(CodeGenFunction &CGF,
   const CGFunctionInfo &fnInfo =
 CGF.CGM.getTypes().arrangeBuiltinFunctionCall(resultType, args);
   llvm::FunctionType *fnTy = CGF.CGM.getTypes().GetFunctionType(fnInfo);
-  llvm::AttrBuilder fnAttrB;
+  llvm::AttrBuilder fnAttrB(CGF.getLLVMContext());
   fnAttrB.addAttribute(llvm::Attribute::NoUnwind);
   fnAttrB.addAttribute(llvm::Attribute::WillReturn);
   llvm::AttributeList fnAttrs = llvm::AttributeList::get(

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 716134b123dd6..7b5d202afbba2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4925,7 +4925,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   llvm::Value *Block =
   Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
 
-  AttrBuilder B;
+  AttrBuilder B(Builder.getContext());
   B.addByValAttr(NDRangeL.getAddress(*this).getElementType());
   llvm::AttributeList ByValAttrSet =
   llvm::AttributeList::get(CGM.getModule().getContext(), 3U, B);

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d70f78fea6b42..26f005131c7f4 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1892,7 +1892,7 @@ void 
CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
 }
 
 void CodeGenModule::addDefaultFunctionDefinitionAttributes(llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs;
+  llvm::AttrBuilder FuncAttrs(F.getContext());
   getDefaultFunctionAttributes(F.getName(), F.hasOptNone(),
/* AttrOnCallSite = */ false, FuncAttrs);
   // TODO: call GetCPUAndFeaturesAttributes?
@@ -2014,8 +2014,8 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
llvm::AttributeList &AttrList,
unsigned &CallingConv,
bool AttrOnCallSite, bool IsThunk) {
-  llvm::AttrBuilder FuncAttrs;
-  llvm::AttrBuilder RetAttrs;
+  llvm::AttrBuilder FuncAttrs(getLLVMContext());
+  llvm::AttrBuilder RetAttrs(getLLVMContext());
 
   // Collect function IR attributes from the CC lowerin

[PATCH] D116599: Simplify AttrBuilder storage for target dependent attributes

2022-01-10 Thread serge 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 rGd2cc6c2d0c2f: Use a sorted array instead of a map to store 
AttrBuilder string attributes (authored by serge-sans-paille).
Herald added a subscriber: awarzynski.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116599

Files:
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  llvm/include/llvm/CodeGen/IndirectThunks.h
  llvm/include/llvm/IR/Attributes.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/tools/bugpoint/CrashDebugger.cpp
  llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp
  llvm/unittests/ExecutionEngine/Orc/IndirectionUtilsTest.cpp
  llvm/unittests/IR/AttributesTest.cpp
  llvm/unittests/IR/InstructionsTest.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -753,7 +753,7 @@
 return func.emitError(
 "llvm.align attribute attached to LLVM non-pointer argument");
   llvmArg.addAttrs(
-  llvm::AttrBuilder().addAlignmentAttr(llvm::Align(attr.getInt(;
+  llvm::AttrBuilder(llvmArg.getContext()).addAlignmentAttr(llvm::Align(attr.getInt(;
 }
 
 if (auto attr = func.getArgAttrOfType(argIdx, "llvm.sret")) {
@@ -761,7 +761,7 @@
   if (!argTy.isa())
 return func.emitError(
 "llvm.sret attribute attached to LLVM non-pointer argument");
-  llvmArg.addAttrs(llvm::AttrBuilder().addStructRetAttr(
+  llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()).addStructRetAttr(
   llvmArg.getType()->getPointerElementType()));
 }
 
@@ -770,7 +770,7 @@
   if (!argTy.isa())
 return func.emitError(
 "llvm.byval attribute attached to LLVM non-pointer argument");
-  llvmArg.addAttrs(llvm::AttrBuilder().addByValAttr(
+  llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()).addByValAttr(
   llvmArg.getType()->getPointerElementType()));
 }
 
Index: llvm/unittests/IR/InstructionsTest.cpp
===
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -614,7 +614,7 @@
 
   // Test cloning an attribute.
   {
-AttrBuilder AB;
+AttrBuilder AB(C);
 AB.addAttribute(Attribute::ReadOnly);
 Call->setAttributes(
 AttributeList::get(C, AttributeList::FunctionIndex, AB));
@@ -633,7 +633,7 @@
   std::unique_ptr Call(
   CallInst::Create(FnTy, Callee, Args, OldBundle, "result"));
   Call->setTailCallKind(CallInst::TailCallKind::TCK_NoTail);
-  AttrBuilder AB;
+  AttrBuilder AB(C);
   AB.addAttribute(Attribute::Cold);
   Call->setAttributes(AttributeList::get(C, AttributeList::FunctionIndex, AB));
   Call->setDebugLoc(DebugLoc(MDNode::get(C, None)));
@@ -662,7 +662,7 @@
   std::unique_ptr Invoke(
   InvokeInst::Create(FnTy, Callee, NormalDest.get(), UnwindDest.get(), Args,
  OldBundle, "result"));
-  AttrBuilder AB;
+  AttrBuilder AB(C);
   AB.addAttribute(Attribute::Cold);
   Invoke->setAttributes(
   AttributeList::get(C, AttributeList::FunctionIndex, AB));
Index: llvm/unittests/IR/AttributesTest.cpp
===
--- llvm/unittests/IR/AttributesTest.cpp
+++ llvm/unittests/IR/AttributesTest.cpp
@@ -62,9 +62,9 @@
 TEST(Attributes, AddAttributes) {
   LLVMContext C;
   AttributeList AL;
-  AttrBuilder B;
+  AttrBuilder B(C);
   B.addAttribute(Attribute::NoReturn);
-  AL = AL.addFnAttributes(C, AttributeSet::get(C, B));
+  AL = AL.addFnAttributes(C, AttrBuilder(C, AttributeSet::get(C, B)));
   EXPECT_TRUE(AL.hasFnAttr(Attribute::NoReturn));
   B.clear();
   B.addAttribute(Attribute::SExt);
@@ -78,12 +78,12 @@
 
   Attribute AlignAttr = Attribute::getWithAlignment(C, 

[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks tests: http://45.33.8.238/linux/64726/step_8.txt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116919

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


[PATCH] D116412: [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

2022-01-10 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 398601.
egorzhdan added a comment.

Diagnose mismatches between class property of a class and a class property of 
its superclass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116412

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/test/SemaObjC/class-property-inheritance.m

Index: clang/test/SemaObjC/class-property-inheritance.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-property-inheritance.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@class MyObject;
+
+
+@interface TopClassWithClassProperty0
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface SubClassWithClassProperty0 : TopClassWithClassProperty0
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty0'}}
+@end
+
+
+
+@interface TopClassWithInstanceProperty1
+@property(nullable, readonly, strong) MyObject *foo;
+@end
+
+@interface ClassWithClassProperty1 : TopClassWithInstanceProperty1
+@property(nonnull, readonly, copy, class) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithInstanceProperty1 : ClassWithClassProperty1
+@property(nullable, readonly, copy) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithInstanceProperty1'}}
+@end
+
+
+@interface TopClassWithClassProperty2
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface ClassWithInstanceProperty2 : TopClassWithClassProperty2
+@property(nonnull, readonly, copy) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithClassProperty2 : ClassWithInstanceProperty2
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty2'}}
+@end
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -112,8 +112,8 @@
 return;
 
   // Look for a property with the same name.
-  if (ObjCPropertyDecl *ProtoProp =
-  Proto->lookup(Prop->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
+  Prop->getIdentifier(), Prop->isInstanceProperty())) {
 S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
 return;
   }
@@ -231,8 +231,8 @@
 bool FoundInSuper = false;
 ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
-  if (ObjCPropertyDecl *SuperProp =
-  Super->lookup(Res->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *SuperProp = Super->getProperty(
+  Res->getIdentifier(), Res->isInstanceProperty())) {
 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
 FoundInSuper = true;
 break;
Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -232,6 +232,19 @@
   return &Ctx.Idents.get(ivarName.str());
 }
 
+ObjCPropertyDecl *
+ObjCContainerDecl::getProperty(const IdentifierInfo *Id,
+   bool IsInstance) const {
+  for (auto *LookupResult : lookup(Id)) {
+if (auto *Prop = dyn_cast(LookupResult)) {
+  if (Prop->isInstanceProperty() == IsInstance) {
+return Prop;
+  }
+}
+  }
+  return nullptr;
+}
+
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
Index: clang/include/clang/AST/DeclObjC.h
===
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -1071,6 +1071,9 @@
   bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
 
+  ObjCPropertyDecl *getProperty(const IdentifierInfo *Id,
+bool IsInstance) const;
+
   ObjCPropertyDecl *
   FindPropertyDeclaration(const IdentifierInfo *PropertyId,
   ObjCPropertyQueryKind QueryKind) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116919: [AST] Add RParen loc for decltype AutoTypeloc.

2022-01-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D116919#3231246 , @thakis wrote:

> Looks like this breaks tests: http://45.33.8.238/linux/64726/step_8.txt

sorry, looking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116919

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


[clang] 7725331 - [CodeGen] Avoid some pointer element type accesses

2022-01-10 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-01-10T15:02:55+01:00
New Revision: 7725331ccdd82312e1ae82d4d634ee5d7dec2406

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

LOG: [CodeGen] Avoid some pointer element type accesses

Possibly this is sufficient to fix PR53089.

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 053c9f6e06d7..0fb7ec26a85e 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4699,12 +4699,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr 
*E) {
 if (LV.isSimple()) {
   Address V = LV.getAddress(*this);
   if (V.isValid()) {
-llvm::Type *T =
-ConvertTypeForMem(E->getType())
-->getPointerTo(
-cast(V.getType())->getAddressSpace());
-if (V.getType() != T)
-  LV.setAddress(Builder.CreateBitCast(V, T));
+llvm::Type *T = ConvertTypeForMem(E->getType());
+if (V.getElementType() != T)
+  LV.setAddress(Builder.CreateElementBitCast(V, T));
   }
 }
 return LV;
@@ -4763,8 +4760,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) 
{
 
 CGM.EmitExplicitCastExprType(CE, this);
 LValue LV = EmitLValue(E->getSubExpr());
-Address V = Builder.CreateBitCast(LV.getAddress(*this),
-  ConvertType(CE->getTypeAsWritten()));
+Address V = Builder.CreateElementBitCast(
+LV.getAddress(*this),
+ConvertTypeForMem(CE->getTypeAsWritten()->getPointeeType()));
 
 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast))
   EmitVTablePtrCheckForCast(E->getType(), V.getPointer(),



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


[clang] 7b1cb72 - [SROA] Switch replacement of dead/UB/unreachable ops from undef to poison

2022-01-10 Thread Nuno Lopes via cfe-commits

Author: Nuno Lopes
Date: 2022-01-10T14:04:26Z
New Revision: 7b1cb72ad944b460c42adf6df635263064a457f3

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

LOG: [SROA] Switch replacement of dead/UB/unreachable ops from undef to poison

SROA has 3 data-structures where it stores sets of instructions that should
be deleted:
 - DeadUsers -> instructions that are UB or have no users
 - DeadOperands -> instructions that are UB or operands of useless phis
 - DeadInsts -> "dead" instructions, including loads of uninitialized memory
with users

The first 2 sets can be RAUW with poison instead of undef. No brainer as UB
can be replaced with poison, and for instructions with no users RAUW is a
NOP.

The 3rd case cannot be currently replaced with poison because the set mixes
the loads of uninit memory. I leave that alone for now.

Another case where we can use poison is in the construction of vectors from
multiple loads. The base vector for the first insertelement is now poison as
it doesn't matter as it is fully overwritten by inserts.

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

Added: 


Modified: 
clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/Transforms/SROA/basictest-opaque-ptrs.ll
llvm/test/Transforms/SROA/basictest.ll
llvm/test/Transforms/SROA/non-capturing-call.ll
llvm/test/Transforms/SROA/phi-and-select.ll

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c 
b/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
index 0961c49192dcb..01d015782da6d 100644
--- a/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
@@ -64,7 +64,7 @@ bfloat16x4_t test_vld1_dup_bf16(bfloat16_t const *ptr) {
 // CHECK64-NEXT:[[VLD1XN:%.*]] = tail call { <4 x bfloat>, <4 x bfloat> } 
@llvm.aarch64.neon.ld1x2.v4bf16.p0bf16(bfloat* [[PTR:%.*]])
 // CHECK64-NEXT:[[VLD1XN_FCA_0_EXTRACT:%.*]] = extractvalue { <4 x 
bfloat>, <4 x bfloat> } [[VLD1XN]], 0
 // CHECK64-NEXT:[[VLD1XN_FCA_1_EXTRACT:%.*]] = extractvalue { <4 x 
bfloat>, <4 x bfloat> } [[VLD1XN]], 1
-// CHECK64-NEXT:[[DOTFCA_0_0_INSERT:%.*]] = insertvalue 
[[STRUCT_BFLOAT16X4X2_T:%.*]] undef, <4 x bfloat> [[VLD1XN_FCA_0_EXTRACT]], 0, 0
+// CHECK64-NEXT:[[DOTFCA_0_0_INSERT:%.*]] = insertvalue 
[[STRUCT_BFLOAT16X4X2_T:%.*]] poison, <4 x bfloat> [[VLD1XN_FCA_0_EXTRACT]], 0, 0
 // CHECK64-NEXT:[[DOTFCA_0_1_INSERT:%.*]] = insertvalue 
[[STRUCT_BFLOAT16X4X2_T]] [[DOTFCA_0_0_INSERT]], <4 x bfloat> 
[[VLD1XN_FCA_1_EXTRACT]], 0, 1
 // CHECK64-NEXT:ret [[STRUCT_BFLOAT16X4X2_T]] [[DOTFCA_0_1_INSERT]]
 //
@@ -75,7 +75,7 @@ bfloat16x4_t test_vld1_dup_bf16(bfloat16_t const *ptr) {
 // CHECK32-NEXT:[[VLD1XN_FCA_1_EXTRACT:%.*]] = extractvalue { <4 x 
bfloat>, <4 x bfloat> } [[VLD1XN]], 1
 // CHECK32-NEXT:[[TMP0:%.*]] = bitcast <4 x bfloat> 
[[VLD1XN_FCA_0_EXTRACT]] to <2 x i32>
 // CHECK32-NEXT:[[TMP1:%.*]] = bitcast <4 x bfloat> 
[[VLD1XN_FCA_1_EXTRACT]] to <2 x i32>
-// CHECK32-NEXT:[[DOTFCA_0_INSERT:%.*]] = insertvalue [2 x <2 x i32>] 
undef, <2 x i32> [[TMP0]], 0
+// CHECK32-NEXT:[[DOTFCA_0_INSERT:%.*]] = insertvalue [2 x <2 x i32>] 
poison, <2 x i32> [[TMP0]], 0
 // CHECK32-NEXT:[[DOTFCA_1_INSERT:%.*]] = insertvalue [2 x <2 x i32>] 
[[DOTFCA_0_INSERT]], <2 x i32> [[TMP1]], 1
 // CHECK32-NEXT:ret [2 x <2 x i32>] [[DOTFCA_1_INSERT]]
 //
@@ -88,7 +88,7 @@ bfloat16x4x2_t test_vld1_bf16_x2(bfloat16_t const *ptr) {
 // CHECK64-NEXT:[[VLD1XN:%.*]] = tail call { <8 x bfloat>, <8 x bfloat> } 
@llvm.aarch64.neon.ld1x2.v8bf16.p0bf16(bfloat* [[PTR:%.*]])
 // CHECK64-NEXT:[[VLD1XN_FCA_0_EXTRACT:%.*]] = extractvalue { <8 x 
bfloat>, <8 x bfloat> } [[VLD1XN]], 0
 // CHECK64-NEXT:[[VLD1XN_FCA_1_EXTRACT:%.*]] = extractvalue { <8 x 
bfloat>, <8 x bfloat> } [[VLD1XN]], 1
-// CHECK64-NEXT:[[DOTFCA_0_0_INSERT:%.*]] = insertvalue 
[[STRUCT_BFLOAT16X8X2_T:%.*]] undef, <8 x bfloat> [[VLD1XN_FCA_0_EXTRACT]], 0, 0
+// CHECK64-NEXT:[[DOTFCA_0_0_INSERT:%.*]] = insertvalue 
[[STRUCT_BFLOAT16X8X2_T:%.*]] poison, <8 x bfloat> [[VLD1XN_FCA_0_EXTRACT]], 0, 0
 // CHECK64-NEXT:[[DOTFCA_0_1_INSERT:%.*]] = insertvalue 
[[STRUCT_BFLOAT16X8X2_T]] [[DOTFCA_0_0_INSERT]], <8 x bfloat> 
[[VLD1XN_FCA_1_EXTRACT]], 0, 1
 // CHECK64-NEXT:ret [[STRUCT_BFLOAT16X8X2_T]] [[DOTFCA_0_1_INSERT]]
 //
@@ -99,7 +99,7 @@ bfloat16x4x2_t test_vld1_bf16_x2(bfloat16_t const *ptr) {
 // CHECK32-NEXT:[[VLD1XN_FCA_1_EXTRACT:%.*]] = extractvalue { <8 x 
bfloat>, <8 x bfloat> } [[VLD1XN]], 1
 // CHECK32-NEXT:[[TMP0:%.*]] = bitcast <8 x bfloat> 
[[VLD1XN_FCA_0_EXTRACT]] to <4 x i32>
 // CHECK32-NEXT:[[TMP1:%.*]] = bitcast <8 x bfloat> 
[[VLD1XN_FCA_1_EXTRACT]] to <4 x i32>
-// CHECK

[PATCH] D116887: [SROA] Switch replacement of dead/UB/unreachable ops from undef to poison

2022-01-10 Thread Nuno Lopes 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 rG7b1cb72ad944: [SROA] Switch replacement of 
dead/UB/unreachable ops from undef to poison (authored by nlopes).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D116887?vs=398416&id=398605#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116887

Files:
  clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/Transforms/SROA/basictest-opaque-ptrs.ll
  llvm/test/Transforms/SROA/basictest.ll
  llvm/test/Transforms/SROA/non-capturing-call.ll
  llvm/test/Transforms/SROA/phi-and-select.ll

Index: llvm/test/Transforms/SROA/phi-and-select.ll
===
--- llvm/test/Transforms/SROA/phi-and-select.ll
+++ llvm/test/Transforms/SROA/phi-and-select.ll
@@ -237,8 +237,8 @@
 define i32 @test6(i32* %b) {
 ; CHECK-LABEL: @test6(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[SELECT2:%.*]] = select i1 false, i32* undef, i32* [[B:%.*]]
-; CHECK-NEXT:[[SELECT3:%.*]] = select i1 false, i32* undef, i32* [[B]]
+; CHECK-NEXT:[[SELECT2:%.*]] = select i1 false, i32* poison, i32* [[B:%.*]]
+; CHECK-NEXT:[[SELECT3:%.*]] = select i1 false, i32* poison, i32* [[B]]
 ; CHECK-NEXT:call void @f(i32* [[SELECT2]], i32* [[SELECT3]])
 ; CHECK-NEXT:ret i32 1
 ;
@@ -272,7 +272,7 @@
 ; CHECK:   good:
 ; CHECK-NEXT:br label [[EXIT:%.*]]
 ; CHECK:   bad:
-; CHECK-NEXT:[[P_SROA_SPECULATE_LOAD_BAD:%.*]] = load i32, i32* undef, align 4
+; CHECK-NEXT:[[P_SROA_SPECULATE_LOAD_BAD:%.*]] = load i32, i32* poison, align 4
 ; CHECK-NEXT:br label [[EXIT]]
 ; CHECK:   exit:
 ; CHECK-NEXT:[[P_SROA_SPECULATED:%.*]] = phi i32 [ 0, [[GOOD]] ], [ [[P_SROA_SPECULATE_LOAD_BAD]], [[BAD]] ]
@@ -525,7 +525,7 @@
 ; CHECK:   loop2:
 ; CHECK-NEXT:br i1 undef, label [[LOOP1]], label [[EXIT]]
 ; CHECK:   exit:
-; CHECK-NEXT:[[PHI2:%.*]] = phi i32* [ undef, [[LOOP2]] ], [ null, [[ENTRY:%.*]] ]
+; CHECK-NEXT:[[PHI2:%.*]] = phi i32* [ poison, [[LOOP2]] ], [ null, [[ENTRY:%.*]] ]
 ; CHECK-NEXT:ret i32 undef
 ;
 
Index: llvm/test/Transforms/SROA/non-capturing-call.ll
===
--- llvm/test/Transforms/SROA/non-capturing-call.ll
+++ llvm/test/Transforms/SROA/non-capturing-call.ll
@@ -450,7 +450,7 @@
 ; CHECK-NEXT:[[I0:%.*]] = call i32 @user_of_alloca(i32* nocapture nonnull [[RETVAL]])
 ; CHECK-NEXT:[[I1_FCA_0_GEP:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[RETVAL_FULL]], i32 0, i32 0
 ; CHECK-NEXT:[[I1_FCA_0_LOAD:%.*]] = load i32, i32* [[I1_FCA_0_GEP]], align 4
-; CHECK-NEXT:[[I1_FCA_0_INSERT:%.*]] = insertvalue [2 x i32] undef, i32 [[I1_FCA_0_LOAD]], 0
+; CHECK-NEXT:[[I1_FCA_0_INSERT:%.*]] = insertvalue [2 x i32] poison, i32 [[I1_FCA_0_LOAD]], 0
 ; CHECK-NEXT:[[I1_FCA_1_GEP:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[RETVAL_FULL]], i32 0, i32 1
 ; CHECK-NEXT:[[I1_FCA_1_LOAD:%.*]] = load i32, i32* [[I1_FCA_1_GEP]], align 4
 ; CHECK-NEXT:[[I1_FCA_1_INSERT:%.*]] = insertvalue [2 x i32] [[I1_FCA_0_INSERT]], i32 [[I1_FCA_1_LOAD]], 1
@@ -479,7 +479,7 @@
 ; CHECK-OPAQUE-NEXT:[[I0:%.*]] = call i32 @user_of_alloca(ptr nocapture nonnull [[RETVAL]])
 ; CHECK-OPAQUE-NEXT:[[I1_FCA_0_GEP:%.*]] = getelementptr inbounds [2 x i32], ptr [[RETVAL_FULL]], i32 0, i32 0
 ; CHECK-OPAQUE-NEXT:[[I1_FCA_0_LOAD:%.*]] = load i32, ptr [[I1_FCA_0_GEP]], align 4
-; CHECK-OPAQUE-NEXT:[[I1_FCA_0_INSERT:%.*]] = insertvalue [2 x i32] undef, i32 [[I1_FCA_0_LOAD]], 0
+; CHECK-OPAQUE-NEXT:[[I1_FCA_0_INSERT:%.*]] = insertvalue [2 x i32] poison, i32 [[I1_FCA_0_LOAD]], 0
 ; CHECK-OPAQUE-NEXT:[[I1_FCA_1_GEP:%.*]] = getelementptr inbounds [2 x i32], ptr [[RETVAL_FULL]], i32 0, i32 1
 ; CHECK-OPAQUE-NEXT:[[I1_FCA_1_LOAD:%.*]] = load i32, ptr [[I1_FCA_1_GEP]], align 4
 ; CHECK-OPAQUE-NEXT:[[I1_FCA_1_INSERT:%.*]] = insertvalue [2 x i32] [[I1_FCA_0_INSERT]], i32 [[I1_FCA_1_LOAD]], 1
@@ -533,7 +533,7 @@
 ; CHECK-NEXT:[[I0:%.*]] = call i32 @user_of_alloca_with_multiple_args(i32* nocapture nonnull [[RETVAL]], i32* nocapture nonnull [[RETVAL_BASE]])
 ; CHECK-NEXT:[[I1_FCA_0_GEP:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[RETVAL_FULL]], i32 0, i32 0
 ; CHECK-NEXT:[[I1_FCA_0_LOAD:%.*]] = load i32, i32* [[I1_FCA_0_GEP]], align 4
-; CHECK-NEXT:[[I1_FCA_0_INSERT:%.*]] = insertvalue [2 x i32] undef, i32 [[I1_FCA_0_LOAD]], 0
+; CHECK-NEXT:[[I1_FCA_0_INSERT:%.*]] = insertvalue [2 x i32] poison, i32 [[I1_FCA_0_LOAD]], 0
 ; CHECK-NEXT:[[I1_FCA_1_GEP:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[RETVAL_FULL]], i32 0, i32 1
 ; CHECK-NEXT:[[I1_FCA_1_LOAD:%.*]] = load i32, i32* [[I

[PATCH] D116792: [AST] lookup in parent DeclContext for transparent DeclContext

2022-01-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

In D116792#3230478 , @ChuanqiXu wrote:

> In D116792#3227379 , @erichkeane 
> wrote:
>
>> I had to do something similar for this at one point: 
>> https://github.com/llvm/llvm-project/commit/90010c2e1d60c6a9a4a0b30a113d4dae2b7214eb
>>
>> I seem to remember hitting this assert, and from my end, I think I decided 
>> even calling 'lookup' with the linkage spec to be a mistake (BTW, you might 
>> consider updating that 'Encloses' for 'export' as well!).
>
> Yeah, it is another bug for 'export'. I've tried to address it in 
> https://reviews.llvm.org/D116911 with the same style.
>
>> Is there any mechanism in the parent call of 'lookup' here to make it get 
>> the right thing?
>
> And 'lookup' is called in various places. For example, from the stack trace 
> of the crash, we could find that the parent of call is 
> `DeclareImplicitDeductionGuides`. And I tried to handle it in  
> `DeclareImplicitDeductionGuides`, then the compiler would crash again at 
> `LookupDirect` in `SemaLookup.cpp`. I feel it is not good to add checks for 
> places to call `lookup`. I agree that it is odd to lookup in a transparent 
> DeclContext. But I feel it is not bad to lookup in the enclosing context from 
> the definition of transparent DeclContext. Any thoughts?

Hmm... I didn't realize this was the root 'lookup' function, and thank you for 
the above analysis.  It seems to make more sense to me as well to have this be 
tolerant of this lookup setup.  So LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116792

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


[clang] c2293bc - Revert "[AST] Add RParen loc for decltype AutoTypeloc."

2022-01-10 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-01-10T15:18:41+01:00
New Revision: c2293bc17dd09d552c5fdd13ff2b7c5738c5a10a

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

LOG: Revert "[AST] Add RParen loc for decltype AutoTypeloc."

This breaks a clang-tidy check, needs to investigate and fix. Revert
them to bring the buildbot back.

This reverts commit 55d96ac3dc56bdebea854952a724c2a50d96ce19 and
37ec65e1d705f56fe5551de1dfcbac1e071588a2

Added: 


Modified: 
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang/include/clang/AST/TypeLoc.h
clang/lib/AST/TypeLoc.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/AST/ast-dump-template-decls-json.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 0f4464122c8fb..7e19f07a2215e 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -391,8 +391,6 @@ TEST(SelectionTest, CommonAncestor) {
 )cpp",
   "DeclRefExpr"},
   {"[[decltype^(1)]] b;", "DecltypeTypeLoc"}, // Not the VarDecl.
-  // decltype(auto) is an AutoTypeLoc!
-  {"[[de^cltype(a^uto)]] a = 1;", "AutoTypeLoc"},
 
   // Objective-C nullability attributes.
   {

diff  --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 9c7ab4e8ddb7b..9a43d34a9ec38 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -2081,9 +2081,6 @@ struct AutoTypeLocInfo : TypeSpecLocInfo {
   NamedDecl *FoundDecl;
   SourceLocation LAngleLoc;
   SourceLocation RAngleLoc;
-
-  // For decltype(auto).
-  SourceLocation RParenLoc;
 };
 
 class AutoTypeLoc
@@ -2096,10 +2093,6 @@ class AutoTypeLoc
 return getTypePtr()->getKeyword();
   }
 
-  bool isDecltypeAuto() const { return getTypePtr()->isDecltypeAuto(); }
-  SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
-  void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
-
   bool isConstrained() const {
 return getTypePtr()->isConstrained();
   }
@@ -2180,13 +2173,16 @@ class AutoTypeLoc
   }
 
   SourceRange getLocalSourceRange() const {
-return {isConstrained()
-? (getNestedNameSpecifierLoc()
-   ? getNestedNameSpecifierLoc().getBeginLoc()
-   : (getTemplateKWLoc().isValid() ? getTemplateKWLoc()
-   : getConceptNameLoc()))
-: getNameLoc(),
-isDecltypeAuto() ? getRParenLoc() : getNameLoc()};
+return{
+isConstrained()
+  ? (getNestedNameSpecifierLoc()
+   ? getNestedNameSpecifierLoc().getBeginLoc()
+   : (getTemplateKWLoc().isValid()
+  ? getTemplateKWLoc()
+  : getConceptNameLoc()))
+  : getNameLoc(),
+getNameLoc()
+};
   }
 
   void copy(AutoTypeLoc Loc) {

diff  --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index 13aa54c48f66c..c3ed08d5a8b3e 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -622,7 +622,6 @@ void AutoTypeLoc::initializeLocal(ASTContext &Context, 
SourceLocation Loc) {
   setFoundDecl(nullptr);
   setRAngleLoc(Loc);
   setLAngleLoc(Loc);
-  setRParenLoc(Loc);
   TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
getTypePtr()->getArgs(),
getArgInfos(), Loc);

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 959f4903b0306..f0bbbcf59c751 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -22,7 +22,6 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/PartialDiagnostic.h"
-#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/DeclSpec.h"
@@ -6042,8 +6041,6 @@ namespace {
  DS.getTypeSpecType() == TST_auto_type ||
  DS.getTypeSpecType() == TST_unspecified);
   TL.setNameLoc(DS.getTypeSpecTypeLoc());
-  if (DS.getTypeSpecType() == TST_decltype_auto)
-TL.setRParenLoc(DS.getTypeofParensRange().getEnd());
   if (!DS.isConstrainedAuto())
 return;
   TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 9056f00978c8f..b8ec5b2722a9

[PATCH] D116834: [clang][dataflow] Change `transfer` function to update lattice element in place.

2022-01-10 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 398612.
ymandel added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116834

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
  clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
  clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -113,9 +113,8 @@
 
   static NonConvergingLattice initialElement() { return {0}; }
 
-  NonConvergingLattice transfer(const Stmt *S, const NonConvergingLattice &E,
-Environment &Env) {
-return {E.State + 1};
+  void transfer(const Stmt *S, NonConvergingLattice &E, Environment &Env) {
+++E.State;
   }
 };
 
@@ -165,15 +164,12 @@
 
   static FunctionCallLattice initialElement() { return {}; }
 
-  FunctionCallLattice transfer(const Stmt *S, const FunctionCallLattice &E,
-   Environment &Env) {
-FunctionCallLattice R = E;
+  void transfer(const Stmt *S, FunctionCallLattice &E, Environment &Env) {
 if (auto *C = dyn_cast(S)) {
   if (auto *F = dyn_cast(C->getCalleeDecl())) {
-R.CalledFunctions.insert(F->getNameInfo().getAsString());
+E.CalledFunctions.insert(F->getNameInfo().getAsString());
   }
 }
-return R;
   }
 };
 
Index: clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
@@ -121,9 +121,8 @@
 return ConstantPropagationLattice::bottom();
   }
 
-  ConstantPropagationLattice transfer(const Stmt *S,
-  const ConstantPropagationLattice &Element,
-  Environment &Env) {
+  void transfer(const Stmt *S, ConstantPropagationLattice &Element,
+Environment &Env) {
 auto matcher = stmt(
 anyOf(declStmt(hasSingleDecl(varDecl(hasType(isInteger()),
  hasInitializer(expr().bind(kInit)))
@@ -137,7 +136,7 @@
 ASTContext &Context = getASTContext();
 auto Results = match(matcher, *S, Context);
 if (Results.empty())
-  return Element;
+  return;
 const BoundNodes &Nodes = Results[0];
 
 const auto *Var = Nodes.getNodeAs(kVar);
@@ -145,30 +144,26 @@
 
 if (const auto *E = Nodes.getNodeAs(kInit)) {
   Expr::EvalResult R;
-  if (E->EvaluateAsInt(R, Context) && R.Val.isInt())
-return ConstantPropagationLattice{
-{{Var, R.Val.getInt().getExtValue()}}};
-  return ConstantPropagationLattice::top();
-}
-
-if (Nodes.getNodeAs(kJustAssignment)) {
+  Element =
+  (E->EvaluateAsInt(R, Context) && R.Val.isInt())
+  ? ConstantPropagationLattice{{{Var,
+ R.Val.getInt().getExtValue()}}}
+  : ConstantPropagationLattice::top();
+} else if (Nodes.getNodeAs(kJustAssignment)) {
   const auto *RHS = Nodes.getNodeAs(kRHS);
   assert(RHS != nullptr);
 
   Expr::EvalResult R;
-  if (RHS->EvaluateAsInt(R, Context) && R.Val.isInt())
-return ConstantPropagationLattice{
-{{Var, R.Val.getInt().getExtValue()}}};
-  return ConstantPropagationLattice::top();
-}
-
-// Any assignment involving the expression itself resets the variable to
-// "unknown". A more advanced analysis could try to evaluate the compound
-// assignment. For example, `x += 0` need not invalidate `x`.
-if (Nodes.getNodeAs(kAssignment))
-  return ConstantPropagationLattice::top();
-
-llvm_unreachable("expected at least one bound identifier");
+  Element =
+  (RHS->EvaluateAsInt(R, Context) && R.Val.isInt())
+  ? ConstantPropagationLattice{{{Var,
+ R.Val.getInt().getExtValue()}}}
+  : ConstantPropagationLattice::top();
+} else if (Nodes.getNodeAs(kAssignment))
+  // Any assignment involving the expression itself resets the variable to
+  // "unknown". A more advanced analysis could try to evaluate the compound
+  // assignment. For example, `x += 0` need not in

[PATCH] D116736: [Clang] Add __builtin_reduce_or and __builtin_reduce_and

2022-01-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

LGTM other than the NIT found by @fhahn


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116736

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


[PATCH] D116549: [OpenMP][Clang] Allow passing target features in ISA trait for metadirective clause

2022-01-10 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 398614.
saiislam added a comment.

Fixed the lit test failing in pre-check build bot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116549

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/metadirective_device_isa_codegen.cpp
  clang/test/OpenMP/metadirective_device_isa_messages.c

Index: clang/test/OpenMP/metadirective_device_isa_messages.c
===
--- /dev/null
+++ clang/test/OpenMP/metadirective_device_isa_messages.c
@@ -0,0 +1,14 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux -emit-llvm-only -target-cpu znver1 %s -Rremark-backend-plugin
+
+#ifndef HEADER
+#define HEADER
+
+void bar();
+
+void foo() {
+#pragma omp metadirective when(device = {isa("some-unsupported-feature")} : parallel) default(single) // expected-remark {{isa trait 'some-unsupported-feature' is not a valid feature of the target 'x86_64'}}
+  bar();
+}
+
+#endif
Index: clang/test/OpenMP/metadirective_device_isa_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/metadirective_device_isa_codegen.cpp
@@ -0,0 +1,81 @@
+// REQUIRES: amdgpu-registered-target
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -target-cpu gfx906 -o - | FileCheck %s -check-prefix=AMDGPUISA
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope -target-cpu x86-64| FileCheck %s -check-prefixes=X86_64ISA
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+int amdgcn_device_isa_selected() {
+  int threadCount = 0;
+
+#pragma omp target map(tofrom \
+   : threadCount)
+  {
+#pragma omp metadirective \
+when(device = {isa("flat-address-space")} \
+ : parallel) default(single)
+threadCount++;
+  }
+
+  return threadCount;
+}
+
+// AMDGPUISA: define weak amdgpu_kernel void @__omp_offloading_{{.*}}amdgcn_device_isa_selected
+// AMDGPUISA: user_code.entry:
+// AMDGPUISA: call void @__kmpc_parallel_51
+// AMDGPUISA-NOT: call i32 @__kmpc_single
+// AMDGPUISA: ret void
+
+int amdgcn_device_isa_not_selected() {
+  int threadCount = 0;
+
+#pragma omp target map(tofrom \
+   : threadCount)
+  {
+#pragma omp metadirective  \
+when(device = {isa("sse")} \
+ : parallel)   \
+when(device = {isa("another-unsupported-gpu-feature")} \
+ : parallel) default(single)
+threadCount++;
+  }
+
+  return threadCount;
+}
+// AMDGPUISA: define weak amdgpu_kernel void @__omp_offloading_{{.*}}amdgcn_device_isa_not_selected
+// AMDGPUISA: user_code.entry:
+// AMDGPUISA: call i32 @__kmpc_single
+// AMDGPUISA-NOT: call void @__kmpc_parallel_51
+// AMDGPUISA: ret void
+
+void bar();
+
+void x86_64_device_isa_selected() {
+#pragma omp metadirective when(device = {isa("sse2")} \
+   : parallel) default(single)
+  bar();
+}
+// X86_64ISA-LABEL: void @_Z26x86_64_device_isa_selectedv()
+// X86_64ISA: ...) @__kmpc_fork_call{{.*}}@.omp_outlined..1
+// X86_64ISA: ret void
+
+// X86_64ISA: define internal void @.omp_outlined..1(
+// X86_64ISA: @_Z3barv
+// X86_64ISA: ret void
+
+void x86_64_device_isa_not_selected() {
+#pragma omp metadirective when(device = {isa("some-unsupported-feature")} \
+   : parallel) default(single)
+  bar();
+}
+// X86_64ISA-LABEL: void @_Z30x86_64_device_isa_not_selectedv()
+// X86_64ISA: call i32 @__kmpc_single
+// X86_64ISA:  @_Z3barv
+// X86_64ISA: call void @__kmpc_end_single
+// X86_64ISA: ret void
+#endif
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -2529,7 +2529,12 @@
 TPA.Revert();
 // End of the first iteration. Parser is reset to the start of metadirective
 
-TargetOMPContext OMPCtx(ASTContext, /* DiagUnknownTrait */ nullptr,
+std::function DiagUnknownTrait =
+[this, Loc](StringRef ISATrait) {
+  Diag(Loc, diag::remark_unknown_declare_variant_isa_trait)
+  << ISATrait << this->getTargetInfo().getTriple().getArchName();
+};
+TargetOMPContext OMPCtx(ASTContext, std::move(DiagUnknownTrait),
  

[PATCH] D115440: Provide __builtin_alloca*_uninitialized variants

2022-01-10 Thread Marco Elver via Phabricator via cfe-commits
melver added a comment.

Hello,

We need a solution for this problem, and because I haven't heard any objections 
I'll assume the general approach is fine -- @jfb already kindly confirmed that 
"[...] patch you propose here is a good idea".

Review of the implementation would still be much appreciated!

Many thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115440

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


[PATCH] D116549: [OpenMP][Clang] Allow passing target features in ISA trait for metadirective clause

2022-01-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2533
+std::function DiagUnknownTrait = [this, Loc](
+StringRef ISATrait) {};
+TargetOMPContext OMPCtx(ASTContext, std::move(DiagUnknownTrait),

jdoerfert wrote:
> saiislam wrote:
> > jdoerfert wrote:
> > > Why doesn't this diagnose nothing?
> > Because an isa-feature will fail at least once, for either host compilation 
> > or device compilation. So, no point in always giving a warning.
> That is debatable. 
> 
> First, if I compile for a single architecture there is no device compilation 
> and it should warn.
> Second, if I place the metadirective into a declare variant function or add a 
> `kind(...)` selector to it it will also not warn even if you have multiple 
> architectures.
> 
> 
```
ASTContext &Context = getASTContext();
std::function DiagUnknownTrait = [this,
┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊CE](StringRef ISATrait) {
┊ // TODO Track the selector locations in a way that is accessible here to
┊ // improve the diagnostic location.
┊ Diag(CE->getBeginLoc(), diag::warn_unknown_declare_variant_isa_trait)
┊ ┊ ┊ << ISATrait;   
};
TargetOMPContext OMPCtx(Context, std::move(DiagUnknownTrait),   

   
┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ getCurFunctionDecl(), 
DSAStack->getConstructTraits());
```
Already exists (SemaOpenMP). Why do we need a second, different diagnostic?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116549

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


[PATCH] D116834: [clang][dataflow] Change `transfer` function to update lattice element in place.

2022-01-10 Thread Yitzhak Mandelbaum 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 rG64f7b2d4bf92: [clang][dataflow] Change `transfer` function 
to update lattice element in place. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116834

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
  clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
  clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -113,9 +113,8 @@
 
   static NonConvergingLattice initialElement() { return {0}; }
 
-  NonConvergingLattice transfer(const Stmt *S, const NonConvergingLattice &E,
-Environment &Env) {
-return {E.State + 1};
+  void transfer(const Stmt *S, NonConvergingLattice &E, Environment &Env) {
+++E.State;
   }
 };
 
@@ -165,15 +164,12 @@
 
   static FunctionCallLattice initialElement() { return {}; }
 
-  FunctionCallLattice transfer(const Stmt *S, const FunctionCallLattice &E,
-   Environment &Env) {
-FunctionCallLattice R = E;
+  void transfer(const Stmt *S, FunctionCallLattice &E, Environment &Env) {
 if (auto *C = dyn_cast(S)) {
   if (auto *F = dyn_cast(C->getCalleeDecl())) {
-R.CalledFunctions.insert(F->getNameInfo().getAsString());
+E.CalledFunctions.insert(F->getNameInfo().getAsString());
   }
 }
-return R;
   }
 };
 
Index: clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
@@ -121,9 +121,8 @@
 return ConstantPropagationLattice::bottom();
   }
 
-  ConstantPropagationLattice transfer(const Stmt *S,
-  const ConstantPropagationLattice &Element,
-  Environment &Env) {
+  void transfer(const Stmt *S, ConstantPropagationLattice &Element,
+Environment &Env) {
 auto matcher = stmt(
 anyOf(declStmt(hasSingleDecl(varDecl(hasType(isInteger()),
  hasInitializer(expr().bind(kInit)))
@@ -137,7 +136,7 @@
 ASTContext &Context = getASTContext();
 auto Results = match(matcher, *S, Context);
 if (Results.empty())
-  return Element;
+  return;
 const BoundNodes &Nodes = Results[0];
 
 const auto *Var = Nodes.getNodeAs(kVar);
@@ -145,30 +144,26 @@
 
 if (const auto *E = Nodes.getNodeAs(kInit)) {
   Expr::EvalResult R;
-  if (E->EvaluateAsInt(R, Context) && R.Val.isInt())
-return ConstantPropagationLattice{
-{{Var, R.Val.getInt().getExtValue()}}};
-  return ConstantPropagationLattice::top();
-}
-
-if (Nodes.getNodeAs(kJustAssignment)) {
+  Element =
+  (E->EvaluateAsInt(R, Context) && R.Val.isInt())
+  ? ConstantPropagationLattice{{{Var,
+ R.Val.getInt().getExtValue()}}}
+  : ConstantPropagationLattice::top();
+} else if (Nodes.getNodeAs(kJustAssignment)) {
   const auto *RHS = Nodes.getNodeAs(kRHS);
   assert(RHS != nullptr);
 
   Expr::EvalResult R;
-  if (RHS->EvaluateAsInt(R, Context) && R.Val.isInt())
-return ConstantPropagationLattice{
-{{Var, R.Val.getInt().getExtValue()}}};
-  return ConstantPropagationLattice::top();
-}
-
-// Any assignment involving the expression itself resets the variable to
-// "unknown". A more advanced analysis could try to evaluate the compound
-// assignment. For example, `x += 0` need not invalidate `x`.
-if (Nodes.getNodeAs(kAssignment))
-  return ConstantPropagationLattice::top();
-
-llvm_unreachable("expected at least one bound identifier");
+  Element =
+  (RHS->EvaluateAsInt(R, Context) && R.Val.isInt())
+  ? ConstantPropagationLattice{{{Var,
+ R.Val.getInt().getExtValue()}}}
+  : ConstantPropagationLattice::top();
+} else if (Nodes.getNodeAs(kAssignment))
+  // Any assignment involving the

[clang] 64f7b2d - [clang][dataflow] Change `transfer` function to update lattice element in place.

2022-01-10 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-01-10T14:45:30Z
New Revision: 64f7b2d4bf92eeb8f753f46d2a9499688b07293a

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

LOG: [clang][dataflow] Change `transfer` function to update lattice element in 
place.

Currently, the transfer function returns a new lattice element, which forces an
unnecessary copy on processing each CFG statement.

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/NoopAnalysis.h
clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index a96ed0437a439..7402e42749ee2 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -39,9 +39,8 @@ namespace dataflow {
 ///  must provide the following public members:
 ///   * `LatticeT initialElement()` - returns a lattice element that models the
 /// initial state of a basic block;
-///   * `LatticeT transfer(const Stmt *, const LatticeT &, Environment &)` -
-/// applies the analysis transfer function for a given statement and 
lattice
-/// element.
+///   * `void transfer(const Stmt *, LatticeT &, Environment &)` - applies the
+/// analysis transfer function for a given statement and lattice element.
 ///
 ///  `LatticeT` is a bounded join-semilattice that is used by `Derived` and 
must
 ///  provide the following public members:
@@ -79,11 +78,10 @@ class DataflowAnalysis : public TypeErasedDataflowAnalysis {
 return L1 == L2;
   }
 
-  TypeErasedLattice transferTypeErased(const Stmt *Stmt,
-   const TypeErasedLattice &E,
-   Environment &Env) final {
-const Lattice &L = llvm::any_cast(E.Value);
-return {static_cast(this)->transfer(Stmt, L, Env)};
+  void transferTypeErased(const Stmt *Stmt, TypeErasedLattice &E,
+  Environment &Env) final {
+Lattice &L = llvm::any_cast(E.Value);
+static_cast(this)->transfer(Stmt, L, Env);
   }
 
 private:

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
index 65875445a86b1..c0490140d0ce5 100644
--- a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
@@ -64,9 +64,8 @@ class TypeErasedDataflowAnalysis {
 
   /// Applies the analysis transfer function for a given statement and
   /// type-erased lattice element.
-  virtual TypeErasedLattice transferTypeErased(const Stmt *,
-   const TypeErasedLattice &,
-   Environment &) = 0;
+  virtual void transferTypeErased(const Stmt *, TypeErasedLattice &,
+  Environment &) = 0;
 };
 
 /// Type-erased model of the program at a given program point.

diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index deb73b5265ed7..0d7f3b31e6c48 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -123,7 +123,7 @@ TypeErasedDataflowAnalysisState transferBlock(
 assert(S != nullptr);
 
 transfer(*S, State.Env);
-State.Lattice = Analysis.transferTypeErased(S, State.Lattice, State.Env);
+Analysis.transferTypeErased(S, State.Lattice, State.Env);
 
 if (HandleTransferredStmt != nullptr)
   HandleTransferredStmt(CfgStmt.getValue(), State);

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
index d5275b10e946e..972edcd22f009 100644
--- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -132,8 +132,8 @@ class ConstantPropagationAnalysis
 return ConstantPropagationLattice::bottom();
   }
 
-  ConstantPropagationLattice
-  transfer(const Stmt

[PATCH] D115440: Provide __builtin_alloca*_uninitialized variants

2022-01-10 Thread Alexander Potapenko via Phabricator via cfe-commits
glider accepted this revision.
glider added a comment.
This revision is now accepted and ready to land.

FWIW the implementation looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115440

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2022-01-10 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.



> I think for now it is enough to issue a warning of using these functions, and 
> not suggest a replacement. Should we add an option to the checker to also 
> check for these functions?

IMHO, it is okay to start with just simply issuing the warning. Later we might 
add that option (in a subsequent patch).


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

https://reviews.llvm.org/D91000

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


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

2022-01-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

I think it will be cleaner to keep the original amdgpu-asan.cu unchanged 
whereas add amdgpu-asan-printf.cu which tests asan with printf.


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] D113359: [Libomptarget][WIP] Introduce VGPU Plugin

2022-01-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: llvm/lib/Support/Triple.cpp:512
+  .Case("oe", Triple::OpenEmbedded)
+  .Case("vgpu", Triple::OpenMP_VGPU)
+  .Default(Triple::UnknownVendor);





Comment at: openmp/libomptarget/DeviceRTL/src/Debug.cpp:53
+#pragma omp begin declare variant match(   
\
+device = {kind(cpu)}, implementation = {extension(match_any)})
+int32_t vprintf(const char *, void *);





Comment at: openmp/libomptarget/DeviceRTL/src/Kernel.cpp:128
+#pragma omp begin declare variant match(   
\
+device = {kind(cpu)}, implementation = {extension(match_any)})
+void __kmpc_target_deinit(IdentTy *Ident, int8_t Mode, bool) {





Comment at: openmp/libomptarget/DeviceRTL/src/Mapping.cpp:28
+#pragma omp begin declare variant match(   
\
+device = {kind(cpu)}, implementation = {extension(match_any)})
+





Comment at: openmp/libomptarget/DeviceRTL/src/Synchronization.cpp:290
+#pragma omp begin declare variant match(   
\
+device = {kind(cpu)}, implementation = {extension(match_any)})
+





Comment at: openmp/libomptarget/DeviceRTL/src/Synchronization.cpp:314
+// Simply call fenceKernel because there is no need to sync with host
+void fenceSystem(int) { fenceKernel(0); }
+

Pass the memory order, also rename the arguments to match the coding convention.



Comment at: openmp/libomptarget/DeviceRTL/src/Synchronization.cpp:317
+void syncWarp(__kmpc_impl_lanemask_t Mask) {
+  getThreadEnvironment()->syncWarp();
+}

Pass the mask



Comment at: openmp/libomptarget/DeviceRTL/src/Utils.cpp:56
+#pragma omp begin declare variant match(   
\
+device = {kind(cpu)}, implementation = {extension(match_any)})
+





Comment at: openmp/libomptarget/DeviceRTL/src/Utils.cpp:68
+
+#pragma omp end declare variant
+

Can't we merge this with AMDGPU?



Comment at: openmp/libomptarget/DeviceRTL/src/Utils.cpp:138
+#pragma omp begin declare variant match(   
\
+device = {kind(cpu)}, implementation = {extension(match_any)})
+





Comment at: openmp/libomptarget/plugins/vgpu/src/rtl.cpp:303
+TeamIdx += NumCTAs;
+  }
+

Can we split this up and create some helper functions maybe?



Comment at: openmp/libomptarget/src/rtl.cpp:34
+/* Virtual GPU target   */ "libomptarget.rtl.vgpu.so",
 };
 

Introduce an environment variable, if it is set, X86 target should skip the 
image.
Also, add a TODO such that we later look into the image and inspect it to 
decide automatically.



Comment at: openmp/libomptarget/test/lit.cfg:189
 config.substitutions.append(("%libomptarget-compile-and-run-" + \
 libomptarget_target, \
 "echo ignored-command"))

Leftovers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113359

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


[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-10 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
tyb0807 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This introduces clang command line support for new Armv8.8-A and
Armv9.3-A Hinted Conditional Branches instructions.

Change-Id: I2291f8127da671aa31cf68d08ff6cacd9f01e354


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116939

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Driver/aarch64-hbc.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1521,6 +1521,8 @@
   {"sme", "nosme", "+sme", "-sme"},
   {"sme-f64", "nosme-f64", "+sme-f64", "-sme-f64"},
   {"sme-i64", "nosme-i64", "+sme-i64", "-sme-i64"},
+  {"hbc", "nohbc", "+hbc", "-hbc"},
+  {"mops", "nomops", "+mops", "-mops"},
 };
 
   for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -114,6 +114,10 @@
 Features.push_back("+sme-f64");
   if (Extensions & AArch64::AEK_SMEI64)
 Features.push_back("+sme-i64");
+  if (Extensions & AArch64::AEK_HBC)
+Features.push_back("+hbc");
+  if (Extensions & AArch64::AEK_MOPS)
+Features.push_back("+mops");
 
   return true;
 }
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -69,6 +69,8 @@
   AEK_SME = 1ULL << 37,
   AEK_SMEF64 =  1ULL << 38,
   AEK_SMEI64 =  1ULL << 39,
+  AEK_MOPS =1ULL << 40,
+  AEK_HBC = 1ULL << 41,
 };
 
 enum class ArchKind {
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ llvm/include/llvm/Support/AArch64TargetParser.def
@@ -144,6 +144,8 @@
 AARCH64_ARCH_EXT_NAME("sme",  AArch64::AEK_SME, "+sme",   "-sme")
 AARCH64_ARCH_EXT_NAME("sme-f64",  AArch64::AEK_SMEF64,  "+sme-f64", "-sme-f64")
 AARCH64_ARCH_EXT_NAME("sme-i64",  AArch64::AEK_SMEI64,  "+sme-i64", "-sme-i64")
+AARCH64_ARCH_EXT_NAME("hbc",  AArch64::AEK_HBC, "+hbc",  "-hbc")
+AARCH64_ARCH_EXT_NAME("mops", AArch64::AEK_MOPS,"+mops",  "-mops")
 #undef AARCH64_ARCH_EXT_NAME
 
 #ifndef AARCH64_CPU_NAME
Index: clang/test/Driver/aarch64-hbc.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-hbc.c
@@ -0,0 +1,12 @@
+// Test that target feature hbc is implemented and available correctly
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+hbc %s 2>&1 | FileCheck %s
+// CHECK: "-target-feature" "+hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+nohbc %s 2>&1 | FileCheck %s --check-prefix=NO_HBC
+// NO_HBC: "-target-feature" "-hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi  %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// ABSENT_HBC-NOT: "-target-feature" "+hbc"
+// ABSENT_HBC-NOT: "-target-feature" "-hbc"
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -53,6 +53,8 @@
   bool HasMatmulFP32;
   bool HasLSE;
   bool HasFlagM;
+  bool HasHBC;
+  bool HasMOPS;
 
   llvm::AArch64::ArchKind ArchKind;
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -543,6 +543,8 @@
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
   HasLSE = false;
+  HasHBC = false;
+  HasMOPS = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
 
@@ -658,6 +660,26 @@
   HasRandGen = true;
 if (Feature == "+flagm")
   HasFlagM = true;
+if (Feature == "+hbc")
+  HasHBC = true;
+if (Feature == "+mops")
+  HasMO

[PATCH] D116549: [OpenMP][Clang] Allow passing target features in ISA trait for metadirective clause

2022-01-10 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added inline comments.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2533
+std::function DiagUnknownTrait = [this, Loc](
+StringRef ISATrait) {};
+TargetOMPContext OMPCtx(ASTContext, std::move(DiagUnknownTrait),

jdoerfert wrote:
> jdoerfert wrote:
> > saiislam wrote:
> > > jdoerfert wrote:
> > > > Why doesn't this diagnose nothing?
> > > Because an isa-feature will fail at least once, for either host 
> > > compilation or device compilation. So, no point in always giving a 
> > > warning.
> > That is debatable. 
> > 
> > First, if I compile for a single architecture there is no device 
> > compilation and it should warn.
> > Second, if I place the metadirective into a declare variant function or add 
> > a `kind(...)` selector to it it will also not warn even if you have 
> > multiple architectures.
> > 
> > 
> ```
> ASTContext &Context = getASTContext();
> std::function DiagUnknownTrait = [this,
> ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊CE](StringRef 
> ISATrait) {
> ┊ // TODO Track the selector locations in a way that is accessible here to
> ┊ // improve the diagnostic location.
> ┊ Diag(CE->getBeginLoc(), diag::warn_unknown_declare_variant_isa_trait)
> ┊ ┊ ┊ << ISATrait;   
> };
> TargetOMPContext OMPCtx(Context, std::move(DiagUnknownTrait), 
>   
>   
>  
> ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ getCurFunctionDecl(), 
> DSAStack->getConstructTraits());
> ```
> Already exists (SemaOpenMP). Why do we need a second, different diagnostic?
Isn't giving a remark better than a warning, when we know in many cases this 
will be hit during a normal (expected) compilation for target offload?
Remark diagnostic will give ample handle for understanding the flow without the 
need to explicitly deal with this warning during compilation of user programs.

I am fine changing it to a warning if you feel strongly about this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116549

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


[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-10 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 398623.
tyb0807 edited the summary of this revision.
tyb0807 added a comment.

Remove Change-Id


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116939

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Driver/aarch64-hbc.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1521,6 +1521,8 @@
   {"sme", "nosme", "+sme", "-sme"},
   {"sme-f64", "nosme-f64", "+sme-f64", "-sme-f64"},
   {"sme-i64", "nosme-i64", "+sme-i64", "-sme-i64"},
+  {"hbc", "nohbc", "+hbc", "-hbc"},
+  {"mops", "nomops", "+mops", "-mops"},
 };
 
   for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -114,6 +114,10 @@
 Features.push_back("+sme-f64");
   if (Extensions & AArch64::AEK_SMEI64)
 Features.push_back("+sme-i64");
+  if (Extensions & AArch64::AEK_HBC)
+Features.push_back("+hbc");
+  if (Extensions & AArch64::AEK_MOPS)
+Features.push_back("+mops");
 
   return true;
 }
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -69,6 +69,8 @@
   AEK_SME = 1ULL << 37,
   AEK_SMEF64 =  1ULL << 38,
   AEK_SMEI64 =  1ULL << 39,
+  AEK_MOPS =1ULL << 40,
+  AEK_HBC = 1ULL << 41,
 };
 
 enum class ArchKind {
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ llvm/include/llvm/Support/AArch64TargetParser.def
@@ -144,6 +144,8 @@
 AARCH64_ARCH_EXT_NAME("sme",  AArch64::AEK_SME, "+sme",   "-sme")
 AARCH64_ARCH_EXT_NAME("sme-f64",  AArch64::AEK_SMEF64,  "+sme-f64", "-sme-f64")
 AARCH64_ARCH_EXT_NAME("sme-i64",  AArch64::AEK_SMEI64,  "+sme-i64", "-sme-i64")
+AARCH64_ARCH_EXT_NAME("hbc",  AArch64::AEK_HBC, "+hbc",  "-hbc")
+AARCH64_ARCH_EXT_NAME("mops", AArch64::AEK_MOPS,"+mops",  "-mops")
 #undef AARCH64_ARCH_EXT_NAME
 
 #ifndef AARCH64_CPU_NAME
Index: clang/test/Driver/aarch64-hbc.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-hbc.c
@@ -0,0 +1,12 @@
+// Test that target feature hbc is implemented and available correctly
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+hbc %s 2>&1 | FileCheck %s
+// CHECK: "-target-feature" "+hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+nohbc %s 2>&1 | FileCheck %s --check-prefix=NO_HBC
+// NO_HBC: "-target-feature" "-hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi  %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// ABSENT_HBC-NOT: "-target-feature" "+hbc"
+// ABSENT_HBC-NOT: "-target-feature" "-hbc"
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -53,6 +53,8 @@
   bool HasMatmulFP32;
   bool HasLSE;
   bool HasFlagM;
+  bool HasHBC;
+  bool HasMOPS;
 
   llvm::AArch64::ArchKind ArchKind;
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -543,6 +543,8 @@
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
   HasLSE = false;
+  HasHBC = false;
+  HasMOPS = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
 
@@ -658,6 +660,26 @@
   HasRandGen = true;
 if (Feature == "+flagm")
   HasFlagM = true;
+if (Feature == "+hbc")
+  HasHBC = true;
+if (Feature == "+mops")
+  HasMOPS = true;
+  }
+
+  HasHBC |= ArchKind == llvm::AArch64::ArchKind::ARMV8_8A ||
+ArchKind == llvm::AArch64::ArchKind::ARMV9_3A;
+
+  HasMOPS |= ArchKind == llvm::AArch64::Arc

[PATCH] D116731: [Clang] Make Clang copy its CMake modules into the build dir

2022-01-10 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

@PeteSteinfeld , thank you for testing this change!

I want to make sure that people who are just back from their breaks get a 
chance to take a look, so I'll wait another day or two before merging.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116731

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


[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-10 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 398624.
tyb0807 edited the summary of this revision.
tyb0807 added a comment.

Add more context to the patch summary


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116939

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Driver/aarch64-hbc.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1521,6 +1521,8 @@
   {"sme", "nosme", "+sme", "-sme"},
   {"sme-f64", "nosme-f64", "+sme-f64", "-sme-f64"},
   {"sme-i64", "nosme-i64", "+sme-i64", "-sme-i64"},
+  {"hbc", "nohbc", "+hbc", "-hbc"},
+  {"mops", "nomops", "+mops", "-mops"},
 };
 
   for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -114,6 +114,10 @@
 Features.push_back("+sme-f64");
   if (Extensions & AArch64::AEK_SMEI64)
 Features.push_back("+sme-i64");
+  if (Extensions & AArch64::AEK_HBC)
+Features.push_back("+hbc");
+  if (Extensions & AArch64::AEK_MOPS)
+Features.push_back("+mops");
 
   return true;
 }
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -69,6 +69,8 @@
   AEK_SME = 1ULL << 37,
   AEK_SMEF64 =  1ULL << 38,
   AEK_SMEI64 =  1ULL << 39,
+  AEK_MOPS =1ULL << 40,
+  AEK_HBC = 1ULL << 41,
 };
 
 enum class ArchKind {
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ llvm/include/llvm/Support/AArch64TargetParser.def
@@ -144,6 +144,8 @@
 AARCH64_ARCH_EXT_NAME("sme",  AArch64::AEK_SME, "+sme",   "-sme")
 AARCH64_ARCH_EXT_NAME("sme-f64",  AArch64::AEK_SMEF64,  "+sme-f64", "-sme-f64")
 AARCH64_ARCH_EXT_NAME("sme-i64",  AArch64::AEK_SMEI64,  "+sme-i64", "-sme-i64")
+AARCH64_ARCH_EXT_NAME("hbc",  AArch64::AEK_HBC, "+hbc",  "-hbc")
+AARCH64_ARCH_EXT_NAME("mops", AArch64::AEK_MOPS,"+mops",  "-mops")
 #undef AARCH64_ARCH_EXT_NAME
 
 #ifndef AARCH64_CPU_NAME
Index: clang/test/Driver/aarch64-hbc.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-hbc.c
@@ -0,0 +1,12 @@
+// Test that target feature hbc is implemented and available correctly
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+hbc %s 2>&1 | FileCheck %s
+// CHECK: "-target-feature" "+hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+nohbc %s 2>&1 | FileCheck %s --check-prefix=NO_HBC
+// NO_HBC: "-target-feature" "-hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi  %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// ABSENT_HBC-NOT: "-target-feature" "+hbc"
+// ABSENT_HBC-NOT: "-target-feature" "-hbc"
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -53,6 +53,8 @@
   bool HasMatmulFP32;
   bool HasLSE;
   bool HasFlagM;
+  bool HasHBC;
+  bool HasMOPS;
 
   llvm::AArch64::ArchKind ArchKind;
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -543,6 +543,8 @@
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
   HasLSE = false;
+  HasHBC = false;
+  HasMOPS = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
 
@@ -658,6 +660,26 @@
   HasRandGen = true;
 if (Feature == "+flagm")
   HasFlagM = true;
+if (Feature == "+hbc")
+  HasHBC = true;
+if (Feature == "+mops")
+  HasMOPS = true;
+  }
+
+  HasHBC |= ArchKind == llvm::AArch64::ArchKind::ARMV8_8A ||
+ArchKind == llvm::AArch64::ArchKind::ARMV9_3A;
+
+  HasMOPS |= ArchKind 

[PATCH] D116596: [clang][dataflow] Add transfer functions for assignment

2022-01-10 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 398629.
sgatev marked 8 inline comments as done.
sgatev added a comment.

Address reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116596

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -82,7 +82,8 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-const StorageLocation *FooLoc = Env.getStorageLocation(*FooDecl);
+const StorageLocation *FooLoc =
+Env.getStorageLocation(*FooDecl, SkipPast::None);
 ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
 const Value *FooVal = Env.getValue(*FooLoc);
@@ -125,8 +126,8 @@
 }
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
+const auto *FooLoc = cast(
+Env.getStorageLocation(*FooDecl, SkipPast::None));
 const auto *BarLoc =
 cast(&FooLoc->getChild(*BarDecl));
 
@@ -171,8 +172,8 @@
 }
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
+const auto *FooLoc = cast(
+Env.getStorageLocation(*FooDecl, SkipPast::None));
 const auto *BarLoc =
 cast(&FooLoc->getChild(*BarDecl));
 
@@ -204,7 +205,8 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-const StorageLocation *FooLoc = Env.getStorageLocation(*FooDecl);
+const StorageLocation *FooLoc =
+Env.getStorageLocation(*FooDecl, SkipPast::None);
 ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
 const ReferenceValue *FooVal =
@@ -293,8 +295,8 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
+const auto *FooLoc = cast(
+Env.getStorageLocation(*FooDecl, SkipPast::None));
 const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *FooPointeeVal =
 cast(Env.getValue(FooVal->getPointeeLoc()));
@@ -348,7 +350,8 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-const StorageLocation *FooLoc = Env.getStorageLocation(*FooDecl);
+const StorageLocation *FooLoc =
+Env.getStorageLocation(*FooDecl, SkipPast::None);
 ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
 const PointerValue *FooVal = cast(Env.getValue(*FooLoc));
@@ -449,8 +452,8 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
+const auto *FooLoc = cast(
+Env.getStorageLocation(*FooDecl, SkipPast::None));
 const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *FooPointeeVal =
 cast(Env.getValue(FooVal->getPointeeLoc()));
@@ -498,42 +501,225 @@
   // [[p4]]
 }
   )";
+  runDataflow(Code, [](llvm::ArrayRef>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p4", _), Pair("p3", _),
+ Pair("p2", _), Pair("p1", _)));
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "baz");
+ASSERT_THAT(BazDecl, NotNull());
+
+const Environment &Env1 = Results[3].second.Env;
+const StorageLocation *FooLoc =
+Env1.getStorageLocation(*FooDecl, SkipPast::None);
+ASSERT_THAT(FooLoc, NotNull());
+ASSERT_THAT(Env1.getStorageLocation(*BarDecl, SkipPast::None), IsNull());
+ASSERT_THAT(Env1.getStorageLocation(*BazDecl, SkipPast::None), IsNull());
+
+const Environment &Env2 = Results[2].second.Env;
+ASSERT_EQ(Env2.getStorageLocation(*FooDecl, SkipPast::None), FooLoc);
+ASSERT_THAT(Env2.getStorageLocation(*BarDecl, SkipPast::None), NotNull());
+ASSERT_THAT(Env2.getStorageLocation(*BazDecl, SkipPast::None), IsNull());
+
+const Environment &Env3 = Results[1].second.Env;
+ASSERT_EQ(Env3.getStorageLocation(*FooDecl, SkipPast::None), FooL

[PATCH] D116596: [clang][dataflow] Add transfer functions for assignment

2022-01-10 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:36
+/// FIXME: Consider replacing this with a model that is more aligned with C++
+/// value categories.
+enum class SkipPast {

xazax.hun wrote:
> ymandel wrote:
> > I'm not sure that value categories are right here.  The key is that 
> > skipping is optional, unlike value categories which are fixed.  I think the 
> > problem is just that C++ references are weird (for lack of a technical 
> > term). A reference variable exists simultaneously in two different 
> > categories -- a pointer and the value it points to. That's what this is 
> > trying to capture.
> > 
> > So, I'd recommend just changing the name to reflect that. WDYT of something 
> > like this?
> > 
> > ```
> > /// Indicates how to treat references, if encountered -- as a reference or 
> > the value referred to -- when retrieving
> > /// storage locations or values.
> > enum class RefTreatment {
> >/// Consider the reference itself.
> >   AsSelf,
> >   /// Consider the referent.
> >   AsReferent,
> > };
> > ```
> Yeah, value categories are indeed fixed, I was thinking along the lines of 
> treating expressions as if there was an `LValueToRValue` or `RValueToLValue` 
> conversion. I think some of this problem might come from the ambiguity. E.g., 
> when I want to query the analysis state about the value of `*p`, what do I 
> want? Do I want the value for `*p` as an lvalue or `*p` as an rvalue? I would 
> get a different answer in both cases. If I see `*p` in the source code it is 
> fixed but when I want to query the analysis state it is not.
> 
> On the other hand I see that `SkipPast` is used in the transfer functions, 
> and I am wondering if that is justified. According to the language rules, I 
> can never observe the actual value of the reference. I can modify the 
> pointee, (`ref = val`) or create a pointer to the same value (`&ref`), but I 
> cannot actually read or modify what is inside the reference. So I wonder if 
> it might be less error prone if there would be no way in the transfer 
> functions to observe the values of the references either. 
> 
> But I do not have a strong feeling about any of this at this point so feel 
> free to leave everything as it is. 
> 
> > So, I'd recommend just changing the name to reflect that.
> 
> I am not sure how clear `Referent` is. For a non-native speaker `Pointee` 
> might be clearer, although I do see how it can be confusing. 
Thanks both! I agree with the comments. I prefer to keep it as is for now. I 
updated the FIXME with a pointer to this discussion so that we remember to get 
back to it at some point.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:111
+  /// value in the environment.
+  Value *getValue(const StorageLocation &Loc, SkipPast SP) const;
+

ymandel wrote:
> Why have a SkipPast argument here? I understand the concept for considering 
> var-decls - it corresponds to the weirdness of lvalue-refs themselves. But 
> StorageLocation is a lower-level (and simpler) concept, to which this doesn't 
> seem to map. I'm fine with resolving indirections, but what is the value of 
> only doing so conditionally?
You're right. It's not necessary here. Removed it.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:95
+StorageLocation &Environment::createStorageLocation(const Expr &E) {
+  // Evaluated expressions are always assigned the same storage locations to
+  // ensure that the environment stabilizes across loop iterations. Storage

xazax.hun wrote:
> sgatev wrote:
> > xazax.hun wrote:
> > > What is the model for expressions that evaluate to different locations in 
> > > every loop iterations, e.g.:
> > > ```
> > > for(int *p = array; p != array + size; ++p)
> > >   *p; // The dereference expression
> > > ```
> > > 
> > > Here, having `*p` always evaluate to the same location is not correct, 
> > > we'd probably need a way to widen this. 
> > In the current model, the storage location for `p` is stable and the value 
> > that is assigned to it changes. So, in one iteration the value assigned to 
> > the storage location for `p` is `val1` which is a `PointerValue` that 
> > points to `loc1` and in another iteration the value assigned to the storage 
> > location for `p` is `val2` which is a `PointerValue` that points to `loc2`. 
> > The storage location for `*p` is also stable and the value that is assigned 
> > to it is a `ReferenceValue` that points to either `loc1` or `loc2`. I 
> > implemented this and added a test.
> In this case, does it really make sense to materialize this mapping? If every 
> subexpression corresponds to a unique location, and always the same location, 
> we could use the subexpression directly as a location. 
True, but a `StorageLocation` can also be assigned to a `ValueDecl`, not only 
to `Expr`. We 

[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-10 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 398638.
tyb0807 added a comment.

Support for MOPS extension should be committed in a separate patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116939

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Driver/aarch64-hbc.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1521,6 +1521,7 @@
   {"sme", "nosme", "+sme", "-sme"},
   {"sme-f64", "nosme-f64", "+sme-f64", "-sme-f64"},
   {"sme-i64", "nosme-i64", "+sme-i64", "-sme-i64"},
+  {"hbc", "nohbc", "+hbc", "-hbc"},
 };
 
   for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -114,6 +114,8 @@
 Features.push_back("+sme-f64");
   if (Extensions & AArch64::AEK_SMEI64)
 Features.push_back("+sme-i64");
+  if (Extensions & AArch64::AEK_HBC)
+Features.push_back("+hbc");
 
   return true;
 }
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -69,6 +69,7 @@
   AEK_SME = 1ULL << 37,
   AEK_SMEF64 =  1ULL << 38,
   AEK_SMEI64 =  1ULL << 39,
+  AEK_HBC = 1ULL << 40,
 };
 
 enum class ArchKind {
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ llvm/include/llvm/Support/AArch64TargetParser.def
@@ -144,6 +144,7 @@
 AARCH64_ARCH_EXT_NAME("sme",  AArch64::AEK_SME, "+sme",   "-sme")
 AARCH64_ARCH_EXT_NAME("sme-f64",  AArch64::AEK_SMEF64,  "+sme-f64", "-sme-f64")
 AARCH64_ARCH_EXT_NAME("sme-i64",  AArch64::AEK_SMEI64,  "+sme-i64", "-sme-i64")
+AARCH64_ARCH_EXT_NAME("hbc",  AArch64::AEK_HBC, "+hbc",  "-hbc")
 #undef AARCH64_ARCH_EXT_NAME
 
 #ifndef AARCH64_CPU_NAME
Index: clang/test/Driver/aarch64-hbc.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-hbc.c
@@ -0,0 +1,12 @@
+// Test that target feature hbc is implemented and available correctly
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+hbc %s 2>&1 | FileCheck %s
+// CHECK: "-target-feature" "+hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+nohbc %s 2>&1 | FileCheck %s --check-prefix=NO_HBC
+// NO_HBC: "-target-feature" "-hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi  %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a %s 2>&1 | FileCheck %s --check-prefix=ABSENT_HBC
+// ABSENT_HBC-NOT: "-target-feature" "+hbc"
+// ABSENT_HBC-NOT: "-target-feature" "-hbc"
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -53,6 +53,7 @@
   bool HasMatmulFP32;
   bool HasLSE;
   bool HasFlagM;
+  bool HasHBC;
 
   llvm::AArch64::ArchKind ArchKind;
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -543,6 +543,7 @@
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
   HasLSE = false;
+  HasHBC = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
 
@@ -658,6 +659,19 @@
   HasRandGen = true;
 if (Feature == "+flagm")
   HasFlagM = true;
+if (Feature == "+hbc")
+  HasHBC = true;
+  }
+
+  HasHBC |= ArchKind == llvm::AArch64::ArchKind::ARMV8_8A ||
+ArchKind == llvm::AArch64::ArchKind::ARMV9_3A;
+
+  // Check features that are manually disabled by command line options.
+  // This needs to be checked after architecture-related features are handled,
+  // making sure they are properly disabled when required.
+  for (const auto &Feature : Features) {
+if (Feature == "-hbc")
+  HasHBC = false;
   }
 
   setDataLayout();
___
cfe-com

[PATCH] D116840: [HIP] Fix device only linking for -fgpu-rdc

2022-01-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:3173
+  AssociatedOffloadKind);
+AL.clear();
+// Offload the host object to the host linker.

tra wrote:
> Doing `clear()` in a function intended to append looks suspicious.  
> We may potentially discard whatever was in AL on entry to the function, plus 
> whatever has been added per `DeviceLinkerInputs`. 
> 
> I wonder if a better API would be to return a new action list, instead of 
> modifying one. 
> 
> At the very least I'd like to see a comment explaining what's going on here 
> and, maybe, some assertions (e.g. if we expect AL to be empty on entry).
Good point.

What we want to do here is that if bundling is disabled, append link actions, 
otherwise create a bundle action with link actions as input, then append bundle 
action.

I will save link actions to some temporary action list instead of using `AL`. 
Then I can avoid clear previous entries in `AL` unintentionally. 


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

https://reviews.llvm.org/D116840

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


[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-10 Thread Alex Hoppen via Phabricator via cfe-commits
ahoppen added a comment.

I like this a lot better. Some comments inline.




Comment at: clang/include/clang/Lex/HeaderSearch.h:179
   /// directory is suppressed.
-  std::vector SearchDirs;
-  /// Whether the DirectoryLookup at the corresponding index in SearchDirs has
-  /// been successfully used to lookup a file.
-  std::vector SearchDirsUsage;
+  std::vector SearchDirs;
+  /// Set of SearchDirs that have been successfully used to lookup a file.

I haven’t tried it but is there a particular reason why this can’t be a `const 
DirectoryLookup *`?



Comment at: clang/lib/Lex/HeaderSearch.cpp:323
+
+if (SearchDirs[Idx]->isFramework()) {
   // Search for or infer a module map for a framework. Here we use

Nitpick: `SearchDirs[Idx]` can be simplified to `SearchDir->isFramework()`. 
Similarly below.



Comment at: clang/unittests/Lex/HeaderSearchTest.cpp:276
+std::vector ExpectedSearchDirUsageAfterM2{false, true, false};
+EXPECT_EQ(Search.getSearchDirUsage(), ExpectedSearchDirUsageAfterM2);
+std::vector ExpectedUserEntryUsageAfterM2{false, true, false};

Wouldn’t it be cleaner to just check that `UsedSearchDirs` only contains a 
single element and that it’s name is `/M2`? In that case we could also remove 
`getSearchDirUsage`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

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


[PATCH] D116935: [IRBuilder] Introduce folder using inst-simplify, use for Or fold.

2022-01-10 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D116935#3231615 , @fhahn wrote:

> In D116935#3231477 , @nikic wrote:
>
>> Why do we need / want to use the InstSimplifyFolder in SROA?
>
> I don't have any strong opinions either way. The reason I updated SROA to use 
> it was that there are a few tests that otherwise create some redundant ORs 
> that otherwise are simplified.

I'd go for "do not simplify" as the default assumption, if we don't have any 
particular motivation to the contrary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116935

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


[PATCH] D116935: [IRBuilder] Introduce folder using inst-simplify, use for Or fold.

2022-01-10 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116935

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


[PATCH] D116948: [CodeGen] Treat ObjC `__unsafe_unretained` and class types as trivial when generating copy/dispose helper functions

2022-01-10 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
ahatanak added a project: clang.
Herald added a subscriber: mgrang.
ahatanak requested review of this revision.

Analyze the block captures just once before generating copy/dispose block 
helper functions and honor the inert `__unsafe_unretained` qualifier. This 
refactor fixes a bug where captures of ObjC `__unsafe_unretained` and class 
types were needlessly retained/released by the copy/dispose helper functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116948

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBlocks.h
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/arc-blocks.m
  clang/test/CodeGenObjC/blocks.m

Index: clang/test/CodeGenObjC/blocks.m
===
--- clang/test/CodeGenObjC/blocks.m
+++ clang/test/CodeGenObjC/blocks.m
@@ -1,5 +1,14 @@
 // RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -fblocks -o - %s | FileCheck %s
 
+// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i32, i32 }
+
+// Check that there is only one capture (20o) in the copy/dispose function
+// names.
+
+// CHECK: @[[BLOCK_DESCRIPTOR0:.*]] = linkonce_odr hidden unnamed_addr constant { i32, i32, i8*, i8*, i8*, i32 } { i32 0, i32 28, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_4_20o to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_4_20o to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i32 512 },
+
+void (^gb0)(void);
+
 // test1.  All of this is somehow testing rdar://6676764
 struct S {
   void (^F)(struct S*);
@@ -132,3 +141,12 @@
 // CHECK-NEXT: [[T5:%.*]] = bitcast i8* [[T4]] to void (i8*, i32, i32, i32, i32)*
 // CHECK-NEXT: call void [[T5]](i8* [[T3]], i32 0, i32 1, i32 2, i32 3)
 // CHECK-NEXT: ret void
+
+void test5(A *a) {
+  __unsafe_unretained A *t = a;
+  gb0 = ^{ (void)a; (void)t; };
+}
+
+// CHECK-LABEL: define void @test5(
+// CHECK: %[[V0:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, {{.*}}*, {{.*}}* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, {{.*}}*, {{.*}}* }>* %{{.*}}, i32 0, i32 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i32, i32, i8*, i8*, i8*, i32 }* @[[BLOCK_DESCRIPTOR0]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[V0]],
Index: clang/test/CodeGenObjC/arc-blocks.m
===
--- clang/test/CodeGenObjC/arc-blocks.m
+++ clang/test/CodeGenObjC/arc-blocks.m
@@ -8,6 +8,10 @@
 // CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP46:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i8* } { i64 0, i64 48, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @{{.*}}, i32 0, i32 0) }, align 8
 // CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP48:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32b to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
 
+// Check that no copy/dispose helpers are emitted for this block.
+
+// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP10:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8* } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @{{.*}}, i32 0, i32 0) }, align 8
+
 // This shouldn't crash.
 void test0(id (^maker)(void)) {
   maker();
@@ -769,5 +773,20 @@
   [t m:123, ^{ (void)x; }];
 }
 
+// CHECK-COMMON-LABEL: define internal void @"\01+[Test24 m]"(
+// CHECK-COMMON: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %{{.*}}, i32 0, i32 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8* }* @[[BLOCK_DESCRIPTOR_TMP10]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]],
+
+@interface Test24
+@property (class) void (^block)(void);
++(void)m;
+@end
+
+@implementation Test24
++(void)m {
+  self.block = ^{ (void)self; };
+}
+@end
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -2935,8 +2935,7 @@
 std::string CGObjCCommonMac::getRCBlockLayoutStr(CodeGenModule &CGM,
  const CGBlockInfo &blockInfo) {
   fillRu

[clang] 4e77868 - [SemaDecl] Use castAs<> instead of getAs<> to avoid dereference of nullptr

2022-01-10 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-10T16:31:08Z
New Revision: 4e77868c7c4ba79ed025b87f84ce66fc8dca25d6

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

LOG: [SemaDecl] Use castAs<> instead of getAs<> to avoid dereference of nullptr

This will assert the cast is correct instead of returning nullptr

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d39d010f5eae4..1e6d4fd04604e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9921,7 +9921,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   << NewFD;
 
 // Turn this into a variadic function with no parameters.
-const FunctionType *FT = NewFD->getType()->getAs();
+const auto *FT = NewFD->getType()->castAs();
 FunctionProtoType::ExtProtoInfo EPI(
 Context.getDefaultCallingConvention(true, false));
 EPI.Variadic = true;



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


[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-10 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Lex/HeaderSearch.h:179
   /// directory is suppressed.
-  std::vector SearchDirs;
-  /// Whether the DirectoryLookup at the corresponding index in SearchDirs has
-  /// been successfully used to lookup a file.
-  std::vector SearchDirsUsage;
+  std::vector SearchDirs;
+  /// Set of SearchDirs that have been successfully used to lookup a file.

ahoppen wrote:
> I haven’t tried it but is there a particular reason why this can’t be a 
> `const DirectoryLookup *`?
While iterating over `SearchDirs`, the elements can be passed to 
`HeaderSearch::loadSubdirectoryModuleMaps` that mutates them.



Comment at: clang/lib/Lex/HeaderSearch.cpp:323
+
+if (SearchDirs[Idx]->isFramework()) {
   // Search for or infer a module map for a framework. Here we use

ahoppen wrote:
> Nitpick: `SearchDirs[Idx]` can be simplified to `SearchDir->isFramework()`. 
> Similarly below.
`SearchDir` will be removed in the following patch: D113676.



Comment at: clang/unittests/Lex/HeaderSearchTest.cpp:276
+std::vector ExpectedSearchDirUsageAfterM2{false, true, false};
+EXPECT_EQ(Search.getSearchDirUsage(), ExpectedSearchDirUsageAfterM2);
+std::vector ExpectedUserEntryUsageAfterM2{false, true, false};

ahoppen wrote:
> Wouldn’t it be cleaner to just check that `UsedSearchDirs` only contains a 
> single element and that it’s name is `/M2`? In that case we could also remove 
> `getSearchDirUsage`.
Maybe I'm misunderstanding you, but I don't think so. We'd still need accessor 
for `HeaderSearch::UsedSearchDirs` and we don't have the expected 
`DirectoryLookup *` lying around, making matching more cumbersome:

```
const llvm::DenseSet &UsedSearchDirs =
Search.getUsedSearchDirs();
EXPECT_EQ(UsedSearchDirs.size(), 2);
EXPECT_EQ(1, llvm::count_if(UsedSearchDirs, [](const auto *SearchDir) {
return SearchDir->getName() == "/M1";
  }));
EXPECT_EQ(1, llvm::count_if(UsedSearchDirs, [](const auto *SearchDir) {
return SearchDir->getName() == "/M2";
  }));
```

or

```
llvm::DenseSet UsedSearchDirsStr;
for (const auto *SearchDir : Search.getUsedSearchDirs())
  UsedSearchDirsStr.insert(SearchDir->getName());
EXPECT_EQ(UsedSearchDirsStr, (llvm::DenseSet{"/M1", "/M2"}));
```

I think having bit-vector, whose indices correspond to the directory names 
(`"/M{i}"`), and using `operator==` for matching is simpler.

Let me know if you had something else in mind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

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


[PATCH] D116048: [clang][CodeGen][UBSan] VLA size checking for unsigned integer parameter

2022-01-10 Thread Adam Magier via Phabricator via cfe-commits
AdamMagierFOSS added a comment.

Thank you for the feedback - I've added responses inline and I'll update the 
change to reflect the feedback.




Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2247
   // Otherwise, evaluate and record it.
-  if (const Expr *size = vat->getSizeExpr()) {
+  if (const Expr *SizeExpr = vat->getSizeExpr()) {
 // It's possible that we might have emitted this already,

rjmccall wrote:
> Please continue to use lowercase names for local variables for consistency 
> with the surrounding code.  The rename to `sizeExpr` is good; you can then 
> rename `Size` to `size` or `sizeValue`.
Thank you for clarifying. I was unsure which style to stick to since I saw both 
"new style" code and "old style" code within the same scope, so I went with the 
"new style" to align with recent submissions to the clang project I looked at. 
It's no problem at all for me to switch my changes to the "old style" if that's 
preferred in this instance.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2259
   //   greater than zero.
-  if (SanOpts.has(SanitizerKind::VLABound) &&
-  size->getType()->isSignedIntegerType()) {
+  if (SanOpts.has(SanitizerKind::VLABound) && SEType->isIntegerType()) 
{
 SanitizerScope SanScope(this);

rjmccall wrote:
> Sema requires the bound expression to have integral type, so you don't need 
> to do this.
I suspected this would be unnecessary - thank you for confirming, I'll remove 
this.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2275
   // undefined behavior to have a negative bound.
-  entry = Builder.CreateIntCast(Size, SizeTy, /*signed*/ false);
+  MapEntry = Builder.CreateIntCast(Size, SizeTy, /*signed*/ false);
 }

rjmccall wrote:
> This would be a different bug, but should UBSan also be doing a bounds check 
> if the type is larger than `size_t`?
Interesting point, I'd have to reread through the spec to give a 
precise/definitive answer. To keep this review focused I'll table the 
discussion for a separate forum.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116048

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


[PATCH] D116840: [HIP] Fix device only linking for -fgpu-rdc

2022-01-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 398662.
yaxunl added a comment.

avoid clearing AL


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

https://reviews.llvm.org/D116840

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/hip-phases.hip
  clang/test/Driver/hip-toolchain-rdc-separate.hip

Index: clang/test/Driver/hip-toolchain-rdc-separate.hip
===
--- clang/test/Driver/hip-toolchain-rdc-separate.hip
+++ clang/test/Driver/hip-toolchain-rdc-separate.hip
@@ -88,47 +88,66 @@
 // RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
 // RUN:   -fuse-ld=lld -fgpu-rdc -nogpuinc \
 // RUN:   %T/a.o %T/b.o \
-// RUN: 2>&1 | FileCheck -check-prefix=LINK %s
+// RUN: 2>&1 | FileCheck -check-prefixes=LINK,LINK-HOST-UNBUNDLE,LLD-TMP,LINK-BUNDLE,LINK-EMBED %s
 
-// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
-// LINK-SAME: "-inputs=[[A_O:.*a.o]]" "-outputs=[[A_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
-// LINK: "-unbundle" "-allow-missing-bundles"
+// RUN: %clang --hip-link -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN:   -fuse-ld=lld -fgpu-rdc -nogpuinc \
+// RUN:   %T/a.o %T/b.o --cuda-device-only \
+// RUN: 2>&1 | FileCheck -check-prefixes=LINK,LLD-TMP,LINK-BUNDLE,LINK-NOEMBED %s
 
-// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
-// LINK-SAME: "-inputs=[[B_O:.*b.o]]" "-outputs=[[B_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
-// LINK: "-unbundle" "-allow-missing-bundles"
+// RUN: %clang --hip-link -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN:   -fuse-ld=lld -fgpu-rdc -nogpuinc \
+// RUN:   %T/a.o %T/b.o --cuda-device-only --no-gpu-bundle-output \
+// RUN: 2>&1 | FileCheck -check-prefixes=LINK,LLD-FIN,LINK-NOBUNDLE,LINK-NOEMBED %s
+
+// LINK-HOST-UNBUNDLE: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
+// LINK-HOST-UNBUNDLE-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
+// LINK-HOST-UNBUNDLE-SAME: "-inputs=[[A_O:.*a.o]]" "-outputs=[[A_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
+// LINK-HOST-UNBUNDLE: "-unbundle" "-allow-missing-bundles"
+
+// LINK-HOST-UNBUNDLE: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
+// LINK-HOST-UNBUNDLE-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
+// LINK-HOST-UNBUNDLE-SAME: "-inputs=[[B_O:.*b.o]]" "-outputs=[[B_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
+// LINK-HOST-UNBUNDLE: "-unbundle" "-allow-missing-bundles"
 
 // LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
 // LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
-// LINK-SAME: "-inputs=[[A_O]]" "-outputs={{.*o}},[[A_BC1:.*o]],[[A_BC2:.*o]]"
-// LINK: "-unbundle" "-allow-missing-bundles"
+// LINK-SAME: "-inputs=[[A_O:.*a.o]]" "-outputs={{.*o}},[[A_BC1:.*o]],[[A_BC2:.*o]]"
+// LINK-SAME: "-unbundle" "-allow-missing-bundles"
 
 // LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
 // LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
-// LINK-SAME: "-inputs=[[B_O]]" "-outputs={{.*o}},[[B_BC1:.*o]],[[B_BC2:.*o]]"
-// LINK: "-unbundle" "-allow-missing-bundles"
+// LINK-SAME: "-inputs=[[B_O:.*b.o]]" "-outputs={{.*o}},[[B_BC1:.*o]],[[B_BC2:.*o]]"
+// LINK-SAME: "-unbundle" "-allow-missing-bundles"
 
 // LINK-NOT: "*.llvm-link"
 // LINK-NOT: ".*opt"
 // LINK-NOT: ".*llc"
 // LINK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
-// LINK: "-plugin-opt=mcpu=gfx803"
-// LINK-SAME: "-o" "[[IMG_DEV1:.*.out]]" "[[A_BC1]]" "[[B_BC1]]"
+// LINK-SAME: "-plugin-opt=mcpu=gfx803"
+// LLD-TMP-SAME: "-o" "[[IMG_DEV1:.*.out]]"
+// LLD-FIN-SAME: "-o" "[[IMG_DEV1:a.out-.*gfx803]]"
+// LINK-SAME "[[A_BC1]]" "[[B_BC1]]"
 
 // LINK-NOT: "*.llvm-link"
 // LINK-NOT: ".*opt"
 // LINK-NOT: ".*llc"
 // LINK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
-// LINK: "-plugin-opt=mcpu=gfx900"
-// LINK-SAME: "-o" "[[IMG_DEV2:.*.out]]" "[[A_BC2]]" "[[B_BC2]]"
-
-// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// LINK-SAME: "-targets={{.*}},hipv4-amdgcn-amd-amdhsa--gfx803,hipv4-amdgcn-amd-amdhsa--gfx900"
-// LINK-SAME: "-inputs={{.*}},[[IMG_DEV1]],[[IMG_DEV2]]" "-outputs=[[BUNDLE:.*hipfb]]"
-
-// LINK: {{".*llvm-mc.*"}} "-o" "[[OBJBUNDLE:.*o]]" "{{.*}}.mcin" "--filetype=obj"
-
-// LINK: [[LD:".*ld.*"]] {{.*}} "-o" "a.out" {{.*}} "[[A_OBJ_HOST]]"
-// LINK-SAME: "[[B_OBJ_HOST]]" "[[OBJBUNDLE]]"
+// LINK-SAME: "-plugin-opt=mcpu=gfx900"
+// LLD-TMP-SAME: "-o" "[[IMG_DEV2:.*.out]]"
+// LLD-FIN-SAME: "-o" "[[IMG_DEV1:a.out-.*gfx900]]"
+// LINK-SAME "[[A_BC2]]" "[[B_BC2]]"
+
+// LINK-BUNDLE: [[BUNDL

[PATCH] D116921: [clangd] Enable expand-auto for decltype(auto).

2022-01-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This broke check-clangd: http://45.33.8.238/linux/64747/step_9.txt (maybe 
triggered by the revert for D116919  which 
broke check-clang-tools.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116921

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


[PATCH] D112427: [ARM] Implement setjmp BTI placement for PACBTI-M

2022-01-10 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added inline comments.



Comment at: llvm/lib/Target/ARM/ARMInstrThumb2.td:5745
+ IIC_Br, [(ARMt2CallBTI tglobaladdr:$func)]>,
+ Requires<[IsThumb2]>, Sched<[WriteBrL]>;

Should this require `IsMClass` instead/also? Though I wasn't able to get 
anything weird to happen when using an A profile triple so maybe I'm missing a 
check elsewhere that means you'd never get to this point with A profile Arm.

For example this A profile triple:
```
$ ./bin/clang --target=thumbv8-arm-none-eabi /tmp/test.c -o /tmp/test.o -o - -S 
-mbranch-protection=bti -mthumb
```

Doesn't put anything after a call to `setjmp`, nop or otherwise, but I can't 
place where that decision is made.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112427

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


[clang-tools-extra] cf90b3c - Revert "[clangd] Enable expand-auto for decltype(auto)."

2022-01-10 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-01-10T12:01:42-05:00
New Revision: cf90b3cf7e467db9052a2fd392faa68ef2f175d8

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

LOG: Revert "[clangd] Enable expand-auto for decltype(auto)."

This reverts commit 37ec65e1d705f56fe5551de1dfcbac1e071588a2.

Its prerequisite 55d96ac3dc56bdebea854952a724c2a50d96ce19 wsa
reverted in c2293bc17dd09d552c5fdd13ff2b7c5738c5a10a. c2293bc's
patch description claimed that it reverted 37ec65 as well,
but it apparently didn't.

See https://reviews.llvm.org/D116921#3231802

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index 914564e9ae218..3776e1c3505d1 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,7 +96,9 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
 if (auto *TypeNode = Node->ASTNode.get()) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
-if (!isStructuredBindingType(Node) &&
+// Code in apply() does handle 'decltype(auto)' yet.
+if (!Result.getTypePtr()->isDecltypeAuto() &&
+!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
   CachedLocation = Result;

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
index 6d9d4362be7af..96574a67b5a46 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,8 +71,7 @@ TEST_F(ExpandAutoTypeTest, Test) {
   apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
   "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
 
-  EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
-  EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
+  EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
   // expanding types in structured bindings is syntactically invalid.
   EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
 



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


[PATCH] D112427: [ARM] Implement setjmp BTI placement for PACBTI-M

2022-01-10 Thread Momchil Velikov via Phabricator via cfe-commits
chill added inline comments.



Comment at: llvm/lib/Target/ARM/ARMInstrThumb2.td:5745
+ IIC_Br, [(ARMt2CallBTI tglobaladdr:$func)]>,
+ Requires<[IsThumb2]>, Sched<[WriteBrL]>;

DavidSpickett wrote:
> Should this require `IsMClass` instead/also? Though I wasn't able to get 
> anything weird to happen when using an A profile triple so maybe I'm missing 
> a check elsewhere that means you'd never get to this point with A profile Arm.
> 
> For example this A profile triple:
> ```
> $ ./bin/clang --target=thumbv8-arm-none-eabi /tmp/test.c -o /tmp/test.o -o - 
> -S -mbranch-protection=bti -mthumb
> ```
> 
> Doesn't put anything after a call to `setjmp`, nop or otherwise, but I can't 
> place where that decision is made.
The decision is made in ARMMachineFunctionInfo

https://github.com/llvm/llvm-project/blob/a02af37560ff5aa22dcef5735ef25eaf58eaaf64/llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp#L18


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112427

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


[PATCH] D112427: [ARM] Implement setjmp BTI placement for PACBTI-M

2022-01-10 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added inline comments.



Comment at: llvm/lib/Target/ARM/ARMInstrThumb2.td:5745
+ IIC_Br, [(ARMt2CallBTI tglobaladdr:$func)]>,
+ Requires<[IsThumb2]>, Sched<[WriteBrL]>;

chill wrote:
> DavidSpickett wrote:
> > Should this require `IsMClass` instead/also? Though I wasn't able to get 
> > anything weird to happen when using an A profile triple so maybe I'm 
> > missing a check elsewhere that means you'd never get to this point with A 
> > profile Arm.
> > 
> > For example this A profile triple:
> > ```
> > $ ./bin/clang --target=thumbv8-arm-none-eabi /tmp/test.c -o /tmp/test.o -o 
> > - -S -mbranch-protection=bti -mthumb
> > ```
> > 
> > Doesn't put anything after a call to `setjmp`, nop or otherwise, but I 
> > can't place where that decision is made.
> The decision is made in ARMMachineFunctionInfo
> 
> https://github.com/llvm/llvm-project/blob/a02af37560ff5aa22dcef5735ef25eaf58eaaf64/llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp#L18
Never mind, I figured it out as per usual just after leaving the comment.

```
static bool GetBranchTargetEnforcement(MachineFunction &MF) {
  const auto &Subtarget = MF.getSubtarget();
  if (!Subtarget.isMClass() || !Subtarget.hasV7Ops())
return false;
```

This returns false for the A profile which means that GuardWithBTI is false so 
we don't add a BTI. Maybe one could craft some IR example that got around that 
but doesn't seem a likely issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112427

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


[PATCH] D112427: [ARM] Implement setjmp BTI placement for PACBTI-M

2022-01-10 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added inline comments.



Comment at: llvm/lib/Target/ARM/ARMInstrThumb2.td:5745
+ IIC_Br, [(ARMt2CallBTI tglobaladdr:$func)]>,
+ Requires<[IsThumb2]>, Sched<[WriteBrL]>;

DavidSpickett wrote:
> chill wrote:
> > DavidSpickett wrote:
> > > Should this require `IsMClass` instead/also? Though I wasn't able to get 
> > > anything weird to happen when using an A profile triple so maybe I'm 
> > > missing a check elsewhere that means you'd never get to this point with A 
> > > profile Arm.
> > > 
> > > For example this A profile triple:
> > > ```
> > > $ ./bin/clang --target=thumbv8-arm-none-eabi /tmp/test.c -o /tmp/test.o 
> > > -o - -S -mbranch-protection=bti -mthumb
> > > ```
> > > 
> > > Doesn't put anything after a call to `setjmp`, nop or otherwise, but I 
> > > can't place where that decision is made.
> > The decision is made in ARMMachineFunctionInfo
> > 
> > https://github.com/llvm/llvm-project/blob/a02af37560ff5aa22dcef5735ef25eaf58eaaf64/llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp#L18
> Never mind, I figured it out as per usual just after leaving the comment.
> 
> ```
> static bool GetBranchTargetEnforcement(MachineFunction &MF) {
>   const auto &Subtarget = MF.getSubtarget();
>   if (!Subtarget.isMClass() || !Subtarget.hasV7Ops())
> return false;
> ```
> 
> This returns false for the A profile which means that GuardWithBTI is false 
> so we don't add a BTI. Maybe one could craft some IR example that got around 
> that but doesn't seem a likely issue.
> The decision is made in ARMMachineFunctionInfo

Left my comment just as you did. Thanks! I see how it works now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112427

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


[clang] 7485e6c - Revert "[clang] Remove redundant member initialization (NFC)"

2022-01-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-01-10T09:21:59-08:00
New Revision: 7485e6c7e9c7d484ba1faf2dc53c9b598286455b

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

LOG: Revert "[clang] Remove redundant member initialization (NFC)"

This reverts commit 80e2c587498a7b2bf14dde47a33a058da6e88a9a.

The original patch causes a lot of warnings on gcc like:

  llvm-project/clang/include/clang/Basic/Diagnostic.h:1329:3: warning:
  base class ‘class clang::StreamingDiagnostic’ should be explicitly
  initialized in the copy constructor [-Wextra]

Added: 


Modified: 
clang/include/clang/AST/ASTConcept.h
clang/include/clang/ASTMatchers/Dynamic/Diagnostics.h
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/PartialDiagnostic.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/ParsedAttr.h
clang/include/clang/Sema/ParsedTemplate.h
clang/lib/AST/MicrosoftCXXABI.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/utils/TableGen/MveEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index 25e00860060f..fbd506f2a160 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -131,7 +131,8 @@ class ConceptReference {
 NamedConcept(NamedConcept), ArgsAsWritten(ArgsAsWritten) {}
 
   ConceptReference()
-  : FoundDecl(nullptr), NamedConcept(nullptr), ArgsAsWritten(nullptr) {}
+  : TemplateKWLoc(), FoundDecl(nullptr), NamedConcept(nullptr),
+ArgsAsWritten(nullptr) {}
 
   const NestedNameSpecifierLoc &getNestedNameSpecifierLoc() const {
 return NestedNameSpec;

diff  --git a/clang/include/clang/ASTMatchers/Dynamic/Diagnostics.h 
b/clang/include/clang/ASTMatchers/Dynamic/Diagnostics.h
index 3f6f364d6505..25eb38e6435e 100644
--- a/clang/include/clang/ASTMatchers/Dynamic/Diagnostics.h
+++ b/clang/include/clang/ASTMatchers/Dynamic/Diagnostics.h
@@ -40,7 +40,7 @@ struct SourceRange {
 
 /// A VariantValue instance annotated with its parser context.
 struct ParserValue {
-  ParserValue() {}
+  ParserValue() : Range() {}
   StringRef Text;
   SourceRange Range;
   VariantValue Value;

diff  --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 6a80823d1242..e5577e74fa63 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1326,7 +1326,7 @@ class DiagnosticBuilder : public StreamingDiagnostic {
 public:
   /// Copy constructor.  When copied, this "takes" the diagnostic info from the
   /// input and neuters it.
-  DiagnosticBuilder(const DiagnosticBuilder &D) {
+  DiagnosticBuilder(const DiagnosticBuilder &D) : StreamingDiagnostic() {
 DiagObj = D.DiagObj;
 DiagStorage = D.DiagStorage;
 IsActive = D.IsActive;

diff  --git a/clang/include/clang/Basic/PartialDiagnostic.h 
b/clang/include/clang/Basic/PartialDiagnostic.h
index d2135f5da0bd..ddee6821e2e1 100644
--- a/clang/include/clang/Basic/PartialDiagnostic.h
+++ b/clang/include/clang/Basic/PartialDiagnostic.h
@@ -46,7 +46,8 @@ class PartialDiagnostic : public StreamingDiagnostic {
   PartialDiagnostic(unsigned DiagID, DiagStorageAllocator &Allocator_)
   : StreamingDiagnostic(Allocator_), DiagID(DiagID) {}
 
-  PartialDiagnostic(const PartialDiagnostic &Other) : DiagID(Other.DiagID) {
+  PartialDiagnostic(const PartialDiagnostic &Other)
+  : StreamingDiagnostic(), DiagID(Other.DiagID) {
 Allocator = Other.Allocator;
 if (Other.DiagStorage) {
   DiagStorage = getStorage();

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index b651929fa9da..a98ad78401f0 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1475,7 +1475,8 @@ class Parser : public CodeCompletionHandler {
   /// information that has been parsed prior to parsing declaration
   /// specifiers.
   struct ParsedTemplateInfo {
-ParsedTemplateInfo() : Kind(NonTemplate), TemplateParams(nullptr) {}
+ParsedTemplateInfo()
+  : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { }
 
 ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
bool isSpecialization,

diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index 4fa6f09d3321..657cf9253c77 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -1080,7 +1080,7 @@ struct ParsedAttributesWithRange : ParsedAttributes {
   SourceRange Range;
 };
 struct ParsedAttributesViewWithRange : ParsedAttributesView {
-  ParsedAttributesViewWithRange() {}
+  ParsedAttributesViewWithRange() : ParsedAttributesView() {}
   void clearListOnly() {

  1   2   3   >