[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D137181#3910404 , @goldstein.w.n 
wrote:

> Doesn't that add an arbitrary +1 to the begining of the indentation?
> Shouldn't it be:
>
>   // IndentPPDirectives: AfterHash
>   #ifdef foo
>   # define bar() \\
> if (A) { \\
> B(); \\
> }\\
> C();
>   #endif
>   
>   // IndentPPDirectives: BeforeHash
>   #ifdef foo
>#define bar() \\
> if (A) { \\
> B(); \\
> }\\
> C();
>   #endif
>   
>   // IndentPPDirectives: NoneHash
>   #ifdef foo
>   #define bar() \\
>if (A) { \\
>B(); \\
>}\\
>C();
>   #endif

Given the settings used in your example:

  PPIndentWidth: 1
  IndentWidth: 4

IMO the macro body should be shifted to the right by 1 column (except when 
`IndentPPDirectives` is set to `None`). That is, the indent of the macro body 
relative to the start of `define` should be the same with any setting of 
`IndentPPDirective`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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


[PATCH] D137486: [clang-format] Correctly annotate function names before attributes

2022-11-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D137486#3909970 , @rymiel wrote:

> Are both isCpp11AttributeSpecifier and isCppAttribute required?

Not really, but I've kept `isCpp11AttributeSpecifier` for now as it might 
become handy if it needs to be called at other places when we add an option for 
breaking after C++ attributes. Otherwise, I will remove it in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137486

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-11-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 473485.
v.g.vassilev marked 2 inline comments as done.
v.g.vassilev edited the summary of this revision.
v.g.vassilev added a comment.

Address comments. Call `isCurrentClassName` before calling 
`isConstructorDeclarator`.


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

https://reviews.llvm.org/D127284

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Interpreter/disambiguate-decl-stmt.cpp
  clang/test/Interpreter/execute-stmts.cpp
  clang/test/Interpreter/stmt-serialization.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -126,12 +126,7 @@
 
   // FIXME: Add support for wrapping and running statements.
   auto R2 = Interp->Parse("var1++; printf(\"var1 value %d\\n\", var1);");
-  EXPECT_FALSE(!!R2);
-  using ::testing::HasSubstr;
-  EXPECT_THAT(DiagnosticsOS.str(),
-  HasSubstr("error: unknown type name 'var1'"));
-  auto Err = R2.takeError();
-  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+  EXPECT_TRUE(!!R2);
 }
 
 TEST(InterpreterTest, UndoCommand) {
Index: clang/test/Interpreter/stmt-serialization.cpp
===
--- /dev/null
+++ clang/test/Interpreter/stmt-serialization.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++20 -fincremental-extensions -fmodules-cache-path=%t \
+// RUN:-x c++ %s -verify
+// expected-no-diagnostics
+
+#pragma clang module build TopLevelStmt
+module TopLevelStmt { module Statements {} }
+#pragma clang module contents
+
+#pragma clang module begin TopLevelStmt.Statements
+extern "C" int printf(const char*,...);
+int i = 0;
+i++;
+#pragma clang module end /*TopLevelStmt.Statements*/
+#pragma clang module endbuild /*TopLevelStmt*/
+
+#pragma clang module import TopLevelStmt.Statements
+
+printf("Value of i is '%d'", i);
Index: clang/test/Interpreter/execute-stmts.cpp
===
--- /dev/null
+++ clang/test/Interpreter/execute-stmts.cpp
@@ -0,0 +1,34 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc  -verify | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fincremental-extensions %s
+
+// expected-no-diagnostics
+
+extern "C" int printf(const char*,...);
+
+// FIXME: Support template instantiation calls.
+//template  T call() { printf("call\n"); return T(); }
+//call();
+ C: call
+
+int i = 1;
+++i;
+printf("i = %d\n", i);
+// CHECK: i = 2
+
+namespace Ns { void f(){ i++; } }
+Ns::f();
+
+void g() { ++i; }
+g();
+::g();
+
+printf("i = %d\n", i);
+// CHECK-NEXT: i = 5
+
+for (; i > 4; --i) printf("i = %d\n", i);
+// CHECK-NEXT: i = 5
+
+int j = i; printf("j = %d\n", j);
+// CHECK-NEXT: j = 4
Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- /dev/null
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -0,0 +1,52 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fincremental-extensions %s
+
+// expected-no-diagnostics
+
+extern "C" int printf(const char*,...);
+
+// Decls which are hard to disambiguate
+
+// FIXME: Support operators.
+// struct S1 { operator int(); };
+// S1::operator int() { return 0; }
+
+
+// Dtors
+using I = int;
+I x = 10;
+x.I::~I();
+x = 20;
+
+// Ctors
+
+// FIXME: Support deduction guide
+// template struct A { A(); A(T); };
+// A() -> A;
+
+struct S2 { S2(); };
+S2::S2() = default;
+
+namespace N { struct S { S(); }; }
+N::S::S() { printf("N::S::S()\n"); }
+N::S s;
+// CHECK: N::S::S()
+
+namespace Ns {namespace Ns { void Ns(); void Fs();}}
+void Ns::Ns::Ns() { printf("void 

[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-11-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:-5568
+  if (SS.isNotEmpty() && SS.getScopeRep()) {
+NestedNameSpecifier *NNS = SS.getScopeRep();
+if (NNS->getAsNamespace() || NNS->getAsNamespaceAlias()) {
+  TPA.Revert();
+  return false;
+}
+if (CtorII) {

rsmith wrote:
> I don't think any of this should be necessary. Per the function comment, it's 
> a precondition of this function that we're looking at either `ClassName` or 
> `ClassNameScope::ClassName` and we shouldn't be re-checking that.
> 
> I also think we should not be returning `true` here if we see 
> `ClassName::ClassName` without looking at the rest of the tokens. That'll 
> cause diagnostic quality regressions like the one you're seeing. We should 
> continue to the rest of this function to see if we have `(Type` or `()` next.
Indeed. I've reverted that and I did not need to have changes in this routine 
anymore. Thanks!!



Comment at: clang/lib/Parse/ParseTentative.cpp:61
+  if (getLangOpts().CPlusPlus) {
+if (isConstructorDeclarator(/*Unqualified=*/false,
+/*DeductionGuide=*/false,

rsmith wrote:
> v.g.vassilev wrote:
> > aaron.ballman wrote:
> > > Do you need special handling for:
> > > ```
> > > struct S {
> > >   operator int();
> > > };
> > > 
> > > S::operator int() { return 0; }
> > > ```
> > We seem to need that. Thanks. I've added a FIXME.
> I think you should check `isCurrentClassName` before calling this, like the 
> other callers of this function do. My understanding is that the intent is for 
> `isConstructorDeclarator` to only check the (potential) function declarator 
> that appears after the name, not to check the name itself.
Ah, okay, that was the missing bit.


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

https://reviews.llvm.org/D127284

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-06 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders accepted this revision.
tom-anders added a comment.
This revision is now accepted and ready to land.

Thanks for the fix, LGTM! Do you want me to commit this for you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-06 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added a comment.

In D137494#3910598 , @tom-anders 
wrote:

> Thanks for the fix, LGTM! Do you want me to commit this for you?

Yes! Thanks a lot!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-06 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n updated this revision to Diff 473489.
goldstein.w.n added a comment.



1. Updating D137181 : [clang-format] Don't 
use 'PPIndentWidth' inside multi-line macros #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Make it so that code indentation always starts where 'd' in "define" is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

Files:
  clang/lib/Format/MacroCallReconstructor.cpp
  clang/lib/Format/Macros.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/TokenAnnotator.h
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/MacroCallReconstructorTest.cpp

Index: clang/unittests/Format/MacroCallReconstructorTest.cpp
===
--- clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -194,7 +194,7 @@
   Expansion Exp(Lex, *Macros);
   TokenList Call = Exp.expand("X");
 
-  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  MacroCallReconstructor Unexp(0, 0, Exp.getUnexpanded());
   Unexp.addLine(line(Exp.getTokens()));
   EXPECT_TRUE(Unexp.finished());
   Matcher U(Call, Lex);
@@ -206,7 +206,7 @@
   Expansion Exp(Lex, *Macros);
   TokenList Call = Exp.expand("C", {"void f()"});
 
-  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  MacroCallReconstructor Unexp(0, 0, Exp.getUnexpanded());
   Matcher E(Exp.getTokens(), Lex);
   Unexp.addLine(line(E.consume("class X {")));
   EXPECT_FALSE(Unexp.finished());
@@ -228,7 +228,7 @@
 
   UnexpandedMap Unexpanded =
   mergeUnexpanded(Exp1.getUnexpanded(), Exp2.getUnexpanded());
-  MacroCallReconstructor Unexp(0, Unexpanded);
+  MacroCallReconstructor Unexp(0, 0, Unexpanded);
   Matcher E(Exp2.getTokens(), Lex);
   Unexp.addLine(line(E.consume("a")));
   EXPECT_FALSE(Unexp.finished());
@@ -257,7 +257,7 @@
   TokenList Call2 = Exp.expand("SEMI");
   TokenList Call3 = Exp.expand("SEMI");
 
-  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  MacroCallReconstructor Unexp(0, 0, Exp.getUnexpanded());
   Matcher E(Exp.getTokens(), Lex);
   Unexp.addLine(line(E.consume(";")));
   EXPECT_TRUE(Unexp.finished());
@@ -296,7 +296,7 @@
   // }
   UnexpandedMap Unexpanded =
   mergeUnexpanded(Exp1.getUnexpanded(), Exp2.getUnexpanded());
-  MacroCallReconstructor Unexp(0, Unexpanded);
+  MacroCallReconstructor Unexp(0, 0, Unexpanded);
   Matcher E(Exp2.getTokens(), Lex);
   Unexp.addLine(line(E.consume("{")));
   EXPECT_FALSE(Unexp.finished());
@@ -357,7 +357,7 @@
   UnexpandedMap Unexpanded = mergeUnexpanded(
   Exp1.getUnexpanded(),
   mergeUnexpanded(Exp2.getUnexpanded(), Exp3.getUnexpanded()));
-  MacroCallReconstructor Unexp(0, Unexpanded);
+  MacroCallReconstructor Unexp(0, 0, Unexpanded);
   Matcher E(Exp3.getTokens(), Lex);
   Unexp.addLine(line(E.consume("{")));
   Unexp.addLine(
@@ -409,7 +409,7 @@
   Expansion Exp(Lex, *Macros);
   TokenList Call = Exp.expand("CALL", {std::string("int a"), "int b"});
 
-  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  MacroCallReconstructor Unexp(0, 0, Exp.getUnexpanded());
   Matcher E(Exp.getTokens(), Lex);
   Unexp.addLine(line({
   E.consume("f([] {"),
@@ -430,7 +430,7 @@
   Expansion Exp(Lex, *Macros);
   TokenList Call = Exp.expand("CALL", {std::string("x"), "y"});
 
-  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  MacroCallReconstructor Unexp(0, 0, Exp.getUnexpanded());
   Matcher E(Exp.getTokens(), Lex);
   Unexp.addLine(line(E.consume("y + x")));
   EXPECT_TRUE(Unexp.finished());
@@ -444,7 +444,7 @@
   Expansion Exp(Lex, *Macros);
   TokenList Call = Exp.expand("ID", {std::string("x; x"), "y"});
 
-  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  MacroCallReconstructor Unexp(0, 0, Exp.getUnexpanded());
   Matcher E(Exp.getTokens(), Lex);
   Unexp.addLine(line(E.consume("x;")));
   Unexp.addLine(line(E.consume("x y")));
@@ -482,7 +482,7 @@
   // 2: }
   UnexpandedMap Unexpanded =
   mergeUnexpanded(Exp1.getUnexpanded(), Exp2.getUnexpanded());
-  MacroCallReconstructor Unexp(0, Unexpanded);
+  MacroCallReconstructor Unexp(0, 0, Unexpanded);
   Matcher E(Exp2.getTokens(), Lex);
   Unexp.addLine(line(E.consume("{")));
   Unexp.addLine(line(E.consume("a * b;")));
@@ -524,7 +524,7 @@
 
   auto Prefix = tokens("int a = []() {");
   auto Postfix = tokens("}();");
-  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  MacroCallReconstructor Unexp(0, 0, Exp.getUnexpanded());
   Matcher E(Exp.getTokens(), Lex);
   Unexp.addLine(line({
   Prefix,
@@ -560,7 +560,7 @@
   Expansion Exp(Lex, *Macros);
  

[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-06 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n added a comment.

In D137181#3910566 , @owenpan wrote:

> In D137181#3910404 , @goldstein.w.n 
> wrote:
>
>> Doesn't that add an arbitrary +1 to the begining of the indentation?
>> Shouldn't it be:
>>
>>   // IndentPPDirectives: AfterHash
>>   #ifdef foo
>>   # define bar() \\
>> if (A) { \\
>> B(); \\
>> }\\
>> C();
>>   #endif
>>   
>>   // IndentPPDirectives: BeforeHash
>>   #ifdef foo
>>#define bar() \\
>> if (A) { \\
>> B(); \\
>> }\\
>> C();
>>   #endif
>>   
>>   // IndentPPDirectives: NoneHash
>>   #ifdef foo
>>   #define bar() \\
>>if (A) { \\
>>B(); \\
>>}\\
>>C();
>>   #endif
>
> Given the settings used in your example:
>
>   PPIndentWidth: 1
>   IndentWidth: 4
>
> IMO the macro body should be shifted to the right by 1 column (except when 
> `IndentPPDirectives` is set to `None`). That is, the indent of the macro body 
> relative to the start of `define` should be the same with any setting of 
> `IndentPPDirective`.

Okay set it up so that where the 'd' in "define" is is always where indentation 
starts.
Essentially track `PPLevel` independently of `Level` and use the two seperarely.

I probably missed a few places / added in a few bad places.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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


[PATCH] D137474: [clang-format] Defer formatting of operator< to honor paren spacing

2022-11-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Format/FormatTest.cpp:15476
+  verifyFormat("bool operator< ();", Space);
+  verifyFormat("bool operator> ();", Space);
   verifyFormat("void f (int a, T b) {\n"

Drop it as it doesn't test the patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137474

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


[PATCH] D137340: [clang-tidy] Add misc-use-anonymous-namespace check

2022-11-06 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 473494.
carlosgalvezp added a comment.

Simplify code for printing the type of the declaration.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137340

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -0,0 +1,59 @@
+// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t
+
+static void f1();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
+static int v1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
+
+namespace {
+  static void f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
+  static int v2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
+}
+
+namespace a {
+  static void f3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead
+  static int v3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead
+}
+
+namespace a {
+namespace {
+  static void f4();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
+  static int v4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
+}
+}
+
+// OK
+void f5();
+int v5;
+
+// OK
+namespace {
+  void f6();
+  int v6;
+}
+
+// OK
+namespace a {
+namespace {
+  void f7();
+  int v7;
+}
+}
+
+// OK
+struct Foo {
+  static void f();
+  static int x;
+};
+
+// OK
+void foo()
+{
+  static int x;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
@@ -0,0 +1,44 @@
+.. title:: clang-tidy - misc-use-anonymous-namespace
+
+misc-use-anonymous-namespace
+
+
+Finds instances of ``static`` functions or variables declared at global scope
+that could instead be moved into the anonymous namespace. It also detects
+instances moved to the anonymous namespace that still keep the redundant
+``static``.
+
+Anonymous namespaces are the "superior alternative" according to the C++
+Standard. ``static`` was proposed for deprecation, but later un-deprecated to
+keep C compatibility [1]. ``static`` is an overloaded term with different meanings in
+different contexts, so it can create confusion.
+
+Examples:
+
+.. code-block:: c++
+
+  // Bad
+  static void foo();
+  static int x;
+
+  // Good
+  namespace {
+void foo();
+int x;
+  } // namespace
+
+.. code-block:: c++
+
+  // Bad
+  namespace {
+static void foo();
+static int x;
+  }
+
+  // Good
+  namespace {
+void foo();
+int x;
+  }  // namespace
+
+[1] `Undeprecating static `_
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -259,6 +259,7 @@
`misc-unused-alias-decls `_, "Yes"
`misc-unused-parameters `_, "Yes"
`misc-unused-using-decls `_, "Yes"
+   `misc-use-anonymous-namespace `_,
`modernize-avoid-bind `_, "Yes"
`modernize-avoid-c-arrays `_,
`modernize-concat-nested-namespaces `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,12 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`misc-use-anonymous-namespace
+  ` check.
+
+  Warns when using ``static`` function or variables at global scope, and suggests
+  moving them into the anonymous namespace.
+
 New check aliases
 ^
 
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
=

[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-06 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 473495.
zhouyizhou added a comment.

add a test case
thank you ;-)


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

https://reviews.llvm.org/D137263

Files:
  clang/include/clang/AST/ASTUnresolvedSet.h
  clang/test/SemaCXX/using-decl-templates.cpp


Index: clang/test/SemaCXX/using-decl-templates.cpp
===
--- clang/test/SemaCXX/using-decl-templates.cpp
+++ clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,32 @@
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+  template 
+  struct A
+  {
+struct Nested {};
+operator Nested*() {return 0;};
+  };
+
+  template 
+  struct B : A
+  {
+using A::operator typename A::Nested*;
+operator typename A::Nested *() {
+  struct A * thi = this;
+  return *thi;
+   };
+  };
+
+  int
+  foo ()
+  {
+struct B b;
+auto s = *b;
+  }
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);
Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == (Decls.size() - 1))
+  Decls.pop_back();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 


Index: clang/test/SemaCXX/using-decl-templates.cpp
===
--- clang/test/SemaCXX/using-decl-templates.cpp
+++ clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,32 @@
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+  template 
+  struct A
+  {
+struct Nested {};
+operator Nested*() {return 0;};
+  };
+
+  template 
+  struct B : A
+  {
+using A::operator typename A::Nested*;
+operator typename A::Nested *() {
+  struct A * thi = this;
+  return *thi;
+   };
+  };
+
+  int
+  foo ()
+  {
+struct B b;
+auto s = *b;
+  }
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);
Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == (Decls.size() - 1))
+  Decls.pop_back();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-11-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 473496.
v.g.vassilev added a comment.

Remove several fixmes. Now we can deal with templates, deduction guides and 
operators.


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

https://reviews.llvm.org/D127284

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Interpreter/disambiguate-decl-stmt.cpp
  clang/test/Interpreter/execute-stmts.cpp
  clang/test/Interpreter/stmt-serialization.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -124,14 +124,8 @@
   auto *PTU1 = R1->TUPart;
   EXPECT_EQ(2U, DeclsSize(PTU1));
 
-  // FIXME: Add support for wrapping and running statements.
   auto R2 = Interp->Parse("var1++; printf(\"var1 value %d\\n\", var1);");
-  EXPECT_FALSE(!!R2);
-  using ::testing::HasSubstr;
-  EXPECT_THAT(DiagnosticsOS.str(),
-  HasSubstr("error: unknown type name 'var1'"));
-  auto Err = R2.takeError();
-  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+  EXPECT_TRUE(!!R2);
 }
 
 TEST(InterpreterTest, UndoCommand) {
Index: clang/test/Interpreter/stmt-serialization.cpp
===
--- /dev/null
+++ clang/test/Interpreter/stmt-serialization.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++20 -fincremental-extensions -fmodules-cache-path=%t \
+// RUN:-x c++ %s -verify
+// expected-no-diagnostics
+
+#pragma clang module build TopLevelStmt
+module TopLevelStmt { module Statements {} }
+#pragma clang module contents
+
+#pragma clang module begin TopLevelStmt.Statements
+extern "C" int printf(const char*,...);
+int i = 0;
+i++;
+#pragma clang module end /*TopLevelStmt.Statements*/
+#pragma clang module endbuild /*TopLevelStmt*/
+
+#pragma clang module import TopLevelStmt.Statements
+
+printf("Value of i is '%d'", i);
Index: clang/test/Interpreter/execute-stmts.cpp
===
--- /dev/null
+++ clang/test/Interpreter/execute-stmts.cpp
@@ -0,0 +1,33 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc  -verify | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fincremental-extensions %s
+
+// expected-no-diagnostics
+
+extern "C" int printf(const char*,...);
+
+template  T call() { printf("called\n"); return T(); }
+call();
+// CHECK: called
+
+int i = 1;
+++i;
+printf("i = %d\n", i);
+// CHECK: i = 2
+
+namespace Ns { void f(){ i++; } }
+Ns::f();
+
+void g() { ++i; }
+g();
+::g();
+
+printf("i = %d\n", i);
+// CHECK-NEXT: i = 5
+
+for (; i > 4; --i) printf("i = %d\n", i);
+// CHECK-NEXT: i = 5
+
+int j = i; printf("j = %d\n", j);
+// CHECK-NEXT: j = 4
Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- /dev/null
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -0,0 +1,51 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fincremental-extensions %s
+
+// expected-no-diagnostics
+
+extern "C" int printf(const char*,...);
+
+// Decls which are hard to disambiguate
+
+// Operators.
+struct S1 { operator int(); };
+S1::operator int() { return 0; }
+
+// Dtors
+using I = int;
+I x = 10;
+x.I::~I();
+x = 20;
+
+// Ctors
+
+// Deduction guide
+template struct A { A(); A(T); };
+A() -> A;
+
+struct S2 { S2(); };
+S2::S2() = default;
+
+namespace N { struct S { S(); }; }
+N::S::S() { printf("N::S::S()\n"); }
+N::S s;
+// CHECK: N::S::S()
+
+namespace Ns {namespace Ns { void Ns(); void Fs();}}
+void Ns::Ns::Ns() { printf("void Ns::Ns::Ns()\n"); }
+void Ns::Ns::Fs() {}
+
+Ns::Ns::Fs();
+Ns::Ns::Ns();
+// CHECK-NEXT: void Ns::Ns::Ns()
+
+struct Attrs1

[PATCH] D137329: [flang] Add -f[no-]associative-math and -mreassociate

2022-11-06 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D137329#3910249 , 
@kiranchandramohan wrote:

> In D137329#3909943 , @awarzynski 
> wrote:
>
>> In D137329#3909082 , @clementval 
>> wrote:
>>
>>> Wouldn't it be good to have a RFC for all these options and what they will 
>>> do in Flang instead of just adding them all? Or did I miss the RFC?
>>
>> +1
>
> Fast Math attributes supported in LLVM IR are documented in 
> https://llvm.org/docs/LangRef.html#fast-math-flags. This set of patches 
> (details below) provides a way to set or unset each of these attributes.
>
> While making policy decisions about these flags, like for ffp-contract, we 
> have created an RFC 
> (https://discourse.llvm.org/t/rfc-ffp-contract-default-value/66301).  When 
> adding umbrella flags like 
> -ffast-math/-Ofast/-ffp-model/-funsafe-math-optimizations, we will submit 
> RFCs.
>
> Patch : Flag Name : LLVM IR Attribute
> https://reviews.llvm.org/D137325 : f[no-]honor-nans: nnan
> https://reviews.llvm.org/D137072 : f[no-]honor-infinities  : ninf
> https://reviews.llvm.org/D137328 : f[no-]signed-zeros  : nsz
> https://reviews.llvm.org/D137330 : f[no-]reciprocal-math : arcp
> https://reviews.llvm.org/D136080 : ffp-contract option : contract
> https://reviews.llvm.org/D137326 : f[no-]approx-func: afn
> https://reviews.llvm.org/D137329 : f[no-]associative-math: reassoc

Thanks for this summary Kiran!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137329

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-11-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/Parse/Parser.cpp:1033
+!isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
+  SingleDecl = ParseTopLevelStmtDecl();
+

There is a remaining challenge which probably could be addressed outside of 
this patch.

Consider this statement block:
```
int i =  12;
++i; 
i--;

template struct A { };
```

Ideally we should model `++i; i--;` as a single `TopLevelStmtDecl` as the 
statement block is contiguous. That would require the creation of 2 AST nodes 
per block (one for the `TopLevelStmtDecl` and one for its conversion to 
`FunctionDecl`). This will give us also a nice property on the REPL side where 
the user could decide to squash multiple statements into a statement block to 
save on memory.

To do so, we will need to use `isDeclarationStatement` as a stop rule in 
`ParseTopLevelDecl`. In turn, this would mean that we should duplicate all of 
the switch cases described in the `ParseExternalDeclaration` function here. [We 
need teach  `isDeclarationStatement` everything we know about declarations, eg. 
it must tell us to stop when we see definition `struct A`].

The last version of this patch goes in the opposite direction, trying to 
minimize the code duplication (bloat?) by wrapping each global statement into a 
`TopLevelStmtDecl`, reusing the logic in `ParseExternalDeclaration`. However, 
we pay the price for 2 AST node allocations per global statement. That is a 
serious hit for people that want to control the parsing granularity of an 
interpreter.

I wonder if we can do something better hitting both requirements in some smart 
way I cannot see...


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

https://reviews.llvm.org/D127284

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


[PATCH] D134337: [clang] [Driver] More flexible rules for loading default configs

2022-11-06 Thread Arfrever Frehtes Taifersar Arahesis via Phabricator via cfe-commits
Arfrever added a comment.

After reading this discussion, I need some clarification.

If there were the followining symlinks pointing to `clang`: 
`i386-pc-linux-gnu-clang`, `i486-pc-linux-gnu-clang`, 
`i586-pc-linux-gnu-clang`, `i686-pc-linux-gnu-clang`, 
`x86_64-pc-linux-gnu-clang`.
Then do I assume correctly that:

1. `x86_64-pc-linux-gnu-clang -m32` would try to load `i386.cfg`
2. `i386-pc-linux-gnu-clang` would try to load `i386.cfg`
3. `i486-pc-linux-gnu-clang` would try to load `i486.cfg`
4. `i586-pc-linux-gnu-clang` would try to load `i586.cfg`
5. `i686-pc-linux-gnu-clang` would try to load `i686.cfg`

?

In modern multilib `x86_64` systems, only `i686-pc-linux-gnu-clang` and 
`x86_64-pc-linux-gnu-clang` symlinks (from above list) are likely to exist, but 
discrepancy in behavior between `x86_64-pc-linux-gnu-clang -m32` and 
`i686-pc-linux-gnu-clang` will cause confusion of users...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134337

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


[PATCH] D136283: [clang-tools-extra] [clangd] Split huge generated CompletionModel.cpp into smaller files

2022-11-06 Thread Arfrever Frehtes Taifersar Arahesis via Phabricator via cfe-commits
Arfrever added inline comments.



Comment at: clang-tools-extra/clangd/quality/CompletionModel.cmake:25
+
+  file(GLOB cpp_files "${output_dir}/${filename}*.cpp")
+

thakis wrote:
> Can we list them? We try not to use globs in cmakelists.txt files.
This `gen_decision_forest()` function is called from 2 places 
(`clang-tools-extra/clangd/CMakeLists.txt`, 
`clang-tools-extra/clangd/unittests/CMakeLists.txt`), on different models, so 
this is impossible to do, at least in this file 
(`clang-tools-extra/clangd/quality/CompletionModel.cmake`).

And hardcoding of list of files in those `CMakeLists.txt` files would be 
inflexible and more fragile, since 
`gen_decision_forest(${CMAKE_CURRENT_SOURCE_DIR}/quality/model CompletionModel 
...)` generates 301 `.cpp` files (1 file for each of 300 trees: 
`CompletionModel0.cpp`, `CompletionModel1.cpp`, ... until 
`CompletionModel299.cpp`, and 1 file for final function: `CompletionModel.cpp`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136283

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


[clang-tools-extra] f5a2ef8 - [clangd] Fix the code action `RemoveUsingNamespace`

2022-11-06 Thread Tom Praschan via cfe-commits

Author: v1nh1shungry
Date: 2022-11-06T18:31:20+01:00
New Revision: f5a2ef80fa47d657877d5be314ce29ff7195d887

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

LOG: [clangd] Fix the code action `RemoveUsingNamespace`

Avoid adding qualifiers before C++ operators declared in a non-class context

Reviewed By: tom-anders

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
index 8df7a448c4383..93fdbb9486cc7 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@ Expected RemoveUsingNamespace::apply(const 
Selection &Inputs) {
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {

diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
index 59788e75d1698..3449c6475e3fc 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,6 +226,29 @@ TEST_F(RemoveUsingNamespaceTest, All) {
   int main() {
 std::vector V;
   }
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+)cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;



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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-06 Thread Tom Praschan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf5a2ef80fa47: [clangd] Fix the code action 
`RemoveUsingNamespace` (authored by v1nh1shungry, committed by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,6 +226,29 @@
   int main() {
 std::vector V;
   }
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+)cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,6 +226,29 @@
   int main() {
 std::vector V;
   }
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+)cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

Thanks!




Comment at: clang/include/clang/AST/ASTUnresolvedSet.h:73
+  void erase(unsigned I) {
+if (I == (Decls.size() - 1))
+  Decls.pop_back();

`if (I == Decls.size() - 1)`



Comment at: clang/test/SemaCXX/using-decl-templates.cpp:107
+  template 
+  struct A
+  {

The llvm style prefers `{` at the end of the previous line. Tests usually don't 
need to follow the convention but the previous code in this test file follows 
the convention.



Comment at: clang/test/SemaCXX/using-decl-templates.cpp:123
+
+  int
+  foo ()

`int foo() {`


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

https://reviews.llvm.org/D137263

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


[PATCH] D137327: [clang-format] Handle object instansiation in if-statements

2022-11-06 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137327

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


[PATCH] D137486: [clang-format] Correctly annotate function names before attributes

2022-11-06 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/TokenAnnotator.cpp:76
+static bool isCppAttribute(bool IsCpp, const FormatToken &Tok) {
+  if (!IsCpp || !Tok.startsSequence(tok::l_square, tok::l_square))
+return false;

What about  `__declspec`, or `__attribute__(())`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137486

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-06 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe updated this revision to Diff 473508.
Febbe marked 19 inline comments as done.
Febbe added a comment.

Applied feedback

- replaced some auto types with the actual type
- added `IncludeStyle` to the options list in the documentation
- Added "Limitations" paragraph, describing known limitations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s -std=c++17 performance-unnecessary-copy-on-last-use %t
+// RUN: %check_clang_tidy %s -std=c++11 performance-unnecessary-copy-on-last-use %t
+// CHECK-FIXES: #include 
+
+struct Movable {
+  Movable() = default;
+  Movable(Movable const &) = default;
+  Movable(Movable &&) = default;
+  Movable &operator=(Movable const &) = default;
+  Movable &operator=(Movable &&) = default;
+  ~Movable();
+
+  void memberUse() {}
+};
+// static_assert(!std::is_trivially_copyable_v, "Movable must not be trivially copyable");
+
+void valueReceiver(Movable Mov);
+void constRefReceiver(Movable const &Mov);
+
+void valueTester() {
+  Movable Mov{};
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+  Mov = Movable{};
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+}
+
+void testUsageInBranch(bool Splitter) {
+  Movable Mov{};
+
+  valueReceiver(Mov);
+  if(Splitter){
+Mov.memberUse();
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+
+  if(Splitter){
+Mov = Movable{};
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  Mov.memberUse();
+}
+
+void testExplicitCopy() {
+  Movable Mov{};
+  constRefReceiver(Movable{Mov});
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: constRefReceiver(Movable{std::move(Mov)});
+}
+
+Movable testReturn() {
+  Movable Mov{};
+  return Mov; // no warning, copy elision
+}
+
+Movable testReturn2(Movable && Mov, bool F) {
+  return F? Mov: Movable{}; 
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use] 
+  // CHECK-FIXES: return F? std::move(Mov): Movable{};
+}
+
+/* 
+Todo (improvement):
+Currently the check does not find last usages of fields of local objects.
+
+struct MoveOwner{
+  Movable Mov{};
+};
+
+void testFieldMove(){
+  MoveOwner Owner{};
+  valueReceiver(Owner.Mov);
+  Owner.Mov = Movable{};
+  valueReceiver(Owner.Mov);
+  // DISABLED-CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Owner.Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // DISABLED-CHECK-FIXES: valueReceiver(std::move(Owner.Mov));
+}
+*/
+
+/*
+Todo (improvement):
+Currently a heuristic detection of guards is not implemented, so this test is disabled
+But before this is done, the check should not be used for automatic fixing
+
+using NoMove = std::shared_ptr>;
+
+void shareMutex(NoMove Nmov);
+
+void testNoMove(std::mutex& M, int& I) {
+NoMove Nmov = std::make_shared>(M);
+shareMutex(Nmov);
+I = 42;
+}
+*/
Index: clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
@@ -0,0 +1,72 @@
+.. title:: clang-tidy - performance-unnecessary-copy-on-last-use
+
+performance-unnecessary-copy-on-last-use
+===

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-06 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe added a comment.

So I finally had time to apply your feedback.




Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:141
+  assert(BlockElement.DeclRefBlock);
+  auto Block = BlockElement.DeclRefBlock->succs();
+  // No successing DeclRefExpr found, appending successors

njames93 wrote:
> replace auto with type here.
Unused, because inlined next line.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:236
+  for (auto &Type : BlockedTypes) {
+if (Param->getType().getAsString().find(Type) != std::string::npos) {
+  return; // The type is blocked

njames93 wrote:
> Isn't blocked types meant to be a regular expression?
It is also handled twice, therefor I just removed it.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:294
+  }
+  // Generate Diagnostic
+}

njames93 wrote:
> What's this comment for?
Removed, old Todo I have overseen.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h:10
+
+#pragma once
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_ON_LAST_USE_H

njames93 wrote:
> Remove this, the include guard is enough.
Yes, I thought, `#pragma once` is less bug prone and might be faster. 



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h:21
+namespace clang {
+namespace tidy::performance {
+

njames93 wrote:
> I have no preference either way, but can these namespaces all be nested or 
> none nested.
Had a forward declaration there, and added it again to reduce include 
dependencies.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp:3
+// RUN: %check_clang_tidy %s -std=c++11 
performance-unnecessary-copy-on-last-use %t
+#include 
+// CHECK-FIXES: #include 

njames93 wrote:
> We avoid using the standard library for tests, if you need to use anything 
> from it you have to reimplement the parts you need yourself.
Kept the `static_assert` as comment and removed the header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D135658: demangle OptFunction trace names

2022-11-06 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

@thakis ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135658

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


[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

IMO we should find a simpler way to indent bodies of macro definitions that are 
nested more than one level deep. I prefer we handle that in another patch and 
only support the examples in the summary for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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


[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-06 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n added a comment.

In D137181#3910799 , @owenpan wrote:

> IMO we should find a simpler way to indent bodies of macro definitions that 
> are nested more than one level deep. I prefer we handle that in another patch 
> and only support the examples in the summary for now.

I'm not sure what changes to the patch that would imply?
I can drop the double-indented tests but seems to me that it would simply be 
buggy if it overintented the code due to header guards or if the define was 
placed in code.

Maybe would be cleaner if we made `Level` a new struct and overloading +/- to 
check if in PP region to keep track of PP level?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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


[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-06 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 473509.
zhouyizhou added a comment.

Thank Ray for your guidance!
I achieved a lot in the process ;-)

Thanks
Zhouyi


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

https://reviews.llvm.org/D137263

Files:
  clang/include/clang/AST/ASTUnresolvedSet.h
  clang/test/SemaCXX/using-decl-templates.cpp


Index: clang/test/SemaCXX/using-decl-templates.cpp
===
--- clang/test/SemaCXX/using-decl-templates.cpp
+++ clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,28 @@
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+  template 
+  struct A {
+struct Nested {};
+operator Nested*() {return 0;};
+  };
+
+  template 
+  struct B : A {
+using A::operator typename A::Nested*;
+operator typename A::Nested *() {
+  struct A * thi = this;
+  return *thi;
+   };
+  };
+
+  int foo () {
+struct B b;
+auto s = *b;
+  }
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);
Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == Decls.size() - 1)
+  Decls.pop_back();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 


Index: clang/test/SemaCXX/using-decl-templates.cpp
===
--- clang/test/SemaCXX/using-decl-templates.cpp
+++ clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,28 @@
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+  template 
+  struct A {
+struct Nested {};
+operator Nested*() {return 0;};
+  };
+
+  template 
+  struct B : A {
+using A::operator typename A::Nested*;
+operator typename A::Nested *() {
+  struct A * thi = this;
+  return *thi;
+   };
+  };
+
+  int foo () {
+struct B b;
+auto s = *b;
+  }
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);
Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == Decls.size() - 1)
+  Decls.pop_back();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b84fd82 - Add boundary check for ASTUnresolvedSet::erase

2022-11-06 Thread Fangrui Song via cfe-commits

Author: Zhouyi Zhou
Date: 2022-11-06T15:07:42-08:00
New Revision: b84fd822fa7eeaec2bb084a26caa9e41f3495923

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

LOG: Add boundary check for ASTUnresolvedSet::erase

When compile following code with clang (Debug build), Assertion will be 
triggered.

```
struct A
{
struct Nested {};
operator Nested*() {return 0;};
};

struct B : A
{
using A::operator typename A::Nested*;
operator typename A::Nested *() {
struct A * thi = this;
return *thi;
};
};
```

The assertion fail is caused by: `void erase(unsigned I) { Decls[I] = 
Decls.pop_back_val(); }` when size of `Decls` is 1 before erase.

Reviewed By: rjmccall, MaskRay

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

Added: 


Modified: 
clang/include/clang/AST/ASTUnresolvedSet.h
clang/test/SemaCXX/using-decl-templates.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTUnresolvedSet.h 
b/clang/include/clang/AST/ASTUnresolvedSet.h
index 8d2b23b3539a2..398ffb188c95b 100644
--- a/clang/include/clang/AST/ASTUnresolvedSet.h
+++ b/clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@ class ASTUnresolvedSet {
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == Decls.size() - 1)
+  Decls.pop_back();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 

diff  --git a/clang/test/SemaCXX/using-decl-templates.cpp 
b/clang/test/SemaCXX/using-decl-templates.cpp
index 73d9bc3e774cb..77dc596fdfc9f 100644
--- a/clang/test/SemaCXX/using-decl-templates.cpp
+++ b/clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,28 @@ struct Derived : Base { // expected-note 
{{requested here}}
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+template 
+struct A {
+  struct Nested {};
+  operator Nested*() {return 0;};
+};
+
+template 
+struct B : A {
+  using A::operator typename A::Nested*;
+  operator typename A::Nested *() {
+struct A * thi = this;
+return *thi;
+ };
+};
+
+int foo () {
+  struct B b;
+  auto s = *b;
+}
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);



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


[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-06 Thread Fangrui Song 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 rGb84fd822fa7e: Add boundary check for ASTUnresolvedSet::erase 
(authored by zhouyizhou, committed by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D137263?vs=473509&id=473512#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137263

Files:
  clang/include/clang/AST/ASTUnresolvedSet.h
  clang/test/SemaCXX/using-decl-templates.cpp


Index: clang/test/SemaCXX/using-decl-templates.cpp
===
--- clang/test/SemaCXX/using-decl-templates.cpp
+++ clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,28 @@
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+template 
+struct A {
+  struct Nested {};
+  operator Nested*() {return 0;};
+};
+
+template 
+struct B : A {
+  using A::operator typename A::Nested*;
+  operator typename A::Nested *() {
+struct A * thi = this;
+return *thi;
+ };
+};
+
+int foo () {
+  struct B b;
+  auto s = *b;
+}
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);
Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == Decls.size() - 1)
+  Decls.pop_back();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 


Index: clang/test/SemaCXX/using-decl-templates.cpp
===
--- clang/test/SemaCXX/using-decl-templates.cpp
+++ clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,28 @@
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+template 
+struct A {
+  struct Nested {};
+  operator Nested*() {return 0;};
+};
+
+template 
+struct B : A {
+  using A::operator typename A::Nested*;
+  operator typename A::Nested *() {
+struct A * thi = this;
+return *thi;
+ };
+};
+
+int foo () {
+  struct B b;
+  auto s = *b;
+}
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);
Index: clang/include/clang/AST/ASTUnresolvedSet.h
===
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
 return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+if (I == Decls.size() - 1)
+  Decls.pop_back();
+else
+  Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137510: [clang] Add SwiftABIInfo support for PPC32

2022-11-06 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda created this revision.
Herald added subscribers: shchenz, kbarton, nemanjai.
Herald added a project: All.
colemancda requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[clang] Add Swift CC support to PPC


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137510

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4700,19 +4700,23 @@
 // PowerPC-32
 namespace {
 /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
-class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
+class PPC32_SVR4_ABIInfo final : public SwiftABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
 
+private:
+  DefaultABIInfo defaultInfo;
+
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
  bool RetSmallStructInRegABI)
-  : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+  : SwiftABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
+IsRetSmallStructInRegABI(RetSmallStructInRegABI), defaultInfo(CGT) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
 if (!getCXXABI().classifyReturnType(FI))
@@ -4723,6 +4727,15 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+  bool isSwiftErrorInRegister() const override { return false; }
+  bool isLegalVectorTypeForSwift(CharUnits totalSize, llvm::Type *eltTy,
+ unsigned elts) const override;
 };
 
 class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -4794,7 +4807,25 @@
 }
   }
 
-  return DefaultABIInfo::classifyReturnType(RetTy);
+  return defaultInfo.classifyArgumentType(RetTy);
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
+  return defaultInfo.classifyArgumentType(Ty);
+}
+
+bool PPC32_SVR4_ABIInfo::isLegalVectorTypeForSwift(CharUnits vectorSize,
+   llvm::Type *eltTy,
+   unsigned numElts) const {
+  if (!llvm::isPowerOf2_32(numElts))
+return false;
+  unsigned size = getDataLayout().getTypeStoreSizeInBits(eltTy);
+  if (size > 64)
+return false;
+  if (vectorSize.getQuantity() != 8 &&
+  (vectorSize.getQuantity() != 16 || numElts == 1))
+return false;
+  return true;
 }
 
 // TODO: this implementation is now likely redundant with
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -405,6 +405,17 @@
 // This is the ELF definition, and is overridden by the Darwin sub-target
 return TargetInfo::PowerABIBuiltinVaList;
   }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 
 // Note: ABI differences may eventually require us to have a separate


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4700,19 +4700,23 @@
 // PowerPC-32
 namespace {
 /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
-class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
+class PPC32_SVR4_ABIInfo final : public SwiftABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
 
+private:
+  DefaultABIInfo defaultInfo;
+
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
  bool RetSmallStructInRegABI)
-  : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+  : SwiftABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
+IsRetSmallStructInRegABI(RetSmallStructInRegABI), defaultInfo(CGT) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
 if (!getCXXABI().classifyReturnType(FI))
@@ -4723,6 +4727,15 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
  

[PATCH] D137510: [clang] Add SwiftABIInfo support for PPC32

2022-11-06 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda updated this revision to Diff 473517.
colemancda added a comment.

Updated clang changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137510

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4700,19 +4700,23 @@
 // PowerPC-32
 namespace {
 /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
-class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
+class PPC32_SVR4_ABIInfo final : public SwiftABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
 
+private:
+  DefaultABIInfo defaultInfo;
+
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
  bool RetSmallStructInRegABI)
-  : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+  : SwiftABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
+IsRetSmallStructInRegABI(RetSmallStructInRegABI), defaultInfo(CGT) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
 if (!getCXXABI().classifyReturnType(FI))
@@ -4723,6 +4727,15 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+  bool isSwiftErrorInRegister() const override { return false; }
+  bool isLegalVectorTypeForSwift(CharUnits totalSize, llvm::Type *eltTy,
+ unsigned elts) const override;
 };
 
 class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -4794,7 +4807,25 @@
 }
   }
 
-  return DefaultABIInfo::classifyReturnType(RetTy);
+  return defaultInfo.classifyArgumentType(RetTy);
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
+  return defaultInfo.classifyArgumentType(Ty);
+}
+
+bool PPC32_SVR4_ABIInfo::isLegalVectorTypeForSwift(CharUnits vectorSize,
+   llvm::Type *eltTy,
+   unsigned numElts) const {
+  if (!llvm::isPowerOf2_32(numElts))
+return false;
+  unsigned size = getDataLayout().getTypeStoreSizeInBits(eltTy);
+  if (size > 64)
+return false;
+  if (vectorSize.getQuantity() != 8 &&
+  (vectorSize.getQuantity() != 16 || numElts == 1))
+return false;
+  return true;
 }
 
 // TODO: this implementation is now likely redundant with
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -405,6 +405,17 @@
 // This is the ELF definition, and is overridden by the Darwin sub-target
 return TargetInfo::PowerABIBuiltinVaList;
   }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 
 // Note: ABI differences may eventually require us to have a separate


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4700,19 +4700,23 @@
 // PowerPC-32
 namespace {
 /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
-class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
+class PPC32_SVR4_ABIInfo final : public SwiftABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
 
+private:
+  DefaultABIInfo defaultInfo;
+
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
  bool RetSmallStructInRegABI)
-  : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+  : SwiftABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
+IsRetSmallStructInRegABI(RetSmallStructInRegABI), defaultInfo(CGT) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
 if (!getCXXABI().classifyReturnType(FI))
@@ -4723,6 +4727,15 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalar

[PATCH] D137511: [PPC] Undefine __ppc64__ to match GCC

2022-11-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: q66, thesamesam.
Herald added subscribers: StephenFan, shchenz, kbarton, nemanjai.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC only defines `__ppc64__` for darwin while the darwin support has been
removed from llvm-project. The existence of `__ppc64__` lures users to make typo
mistakes: if they write code to check `__ppc64__`, the code will not work with
GCC.

It is straightforward if a distro wants to keep the macro: add
`-D__PPC64__=1` to a Clang configuration file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137511

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/Preprocessor/init-ppc64.c


Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -198,7 +198,6 @@
 // PPC64:#define __WCHAR_WIDTH__ 32
 // PPC64:#define __WINT_TYPE__ int
 // PPC64:#define __WINT_WIDTH__ 32
-// PPC64:#define __ppc64__ 1
 // PPC64:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-none-none 
-target-cpu pwr7 -fno-signed-char < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC64LE %s
@@ -403,7 +402,6 @@
 // PPC64LE:#define __WCHAR_WIDTH__ 32
 // PPC64LE:#define __WINT_TYPE__ int
 // PPC64LE:#define __WINT_WIDTH__ 32
-// PPC64LE:#define __ppc64__ 1
 // PPC64LE:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none 
-target-cpu 630 -fno-signed-char < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC630 %s
@@ -865,7 +863,6 @@
 // PPC64-AIX:#define __WINT_WIDTH__ 32
 // PPC64-AIX:#define __powerpc64__ 1
 // PPC64-AIX:#define __powerpc__ 1
-// PPC64-AIX:#define __ppc64__ 1
 // PPC64-AIX:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC64-LINUX %s
@@ -1064,7 +1061,6 @@
 // PPC64-LINUX:#define __WINT_WIDTH__ 32
 // PPC64-LINUX:#define __powerpc64__ 1
 // PPC64-LINUX:#define __powerpc__ 1
-// PPC64-LINUX:#define __ppc64__ 1
 // PPC64-LINUX:#define __ppc__ 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=powerpc64-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC64-ELFv1 %s
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -281,7 +281,6 @@
   if (PointerWidth == 64) {
 Builder.defineMacro("_ARCH_PPC64");
 Builder.defineMacro("__powerpc64__");
-Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
   } else if (getTriple().isOSAIX()) {
 // The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.


Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -198,7 +198,6 @@
 // PPC64:#define __WCHAR_WIDTH__ 32
 // PPC64:#define __WINT_TYPE__ int
 // PPC64:#define __WINT_WIDTH__ 32
-// PPC64:#define __ppc64__ 1
 // PPC64:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-none-none -target-cpu pwr7 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC64LE %s
@@ -403,7 +402,6 @@
 // PPC64LE:#define __WCHAR_WIDTH__ 32
 // PPC64LE:#define __WINT_TYPE__ int
 // PPC64LE:#define __WINT_WIDTH__ 32
-// PPC64LE:#define __ppc64__ 1
 // PPC64LE:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu 630 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC630 %s
@@ -865,7 +863,6 @@
 // PPC64-AIX:#define __WINT_WIDTH__ 32
 // PPC64-AIX:#define __powerpc64__ 1
 // PPC64-AIX:#define __powerpc__ 1
-// PPC64-AIX:#define __ppc64__ 1
 // PPC64-AIX:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-LINUX %s
@@ -1064,7 +1061,6 @@
 // PPC64-LINUX:#define __WINT_WIDTH__ 32
 // PPC64-LINUX:#define __powerpc64__ 1
 // PPC64-LINUX:#define __powerpc__ 1
-// PPC64-LINUX:#define __ppc64__ 1
 // PPC64-LINUX:#define __ppc__ 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -281,7 +281,6 @@
   if (PointerWidth == 64) {
 Builder.defineMacro("_ARCH_PPC64");
 Builder.defineMacro("__powerpc64__");
-Builder.

[PATCH] D137511: [PPC] Undefine __ppc64__ to match GCC

2022-11-06 Thread Daniel Kolesa via Phabricator via cfe-commits
q66 added a comment.

The `__ppc__` macro should get the same treatment. That said, I believe there 
are instances of both macros being used across the LLVM codebase, and those 
cases are valid, so that should also be updated (one instance i know of is the 
limits header of libcxx, there are likely more)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137511

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


[clang] 7aa90b2 - [PowerPC] Replace __ppc64__ with __powerpc64__

2022-11-06 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-11-06T16:16:50-08:00
New Revision: 7aa90b21b453d1ca52fdfccfd7e01e61d9e5b1f1

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

LOG: [PowerPC] Replace __ppc64__ with __powerpc64__

The lowercase __ppc64__ is not defined by non-darwin GCC, therefore it lures
users to write code which is not portable to GCC. Migrate to __powerpc64__ in
preparation for undefining __ppc64__. __powerpc64__ is much more common than
__PPC64__.

Added: 


Modified: 
clang/lib/Headers/ppc_wrappers/emmintrin.h
clang/lib/Headers/ppc_wrappers/mm_malloc.h
clang/lib/Headers/ppc_wrappers/mmintrin.h
clang/lib/Headers/ppc_wrappers/pmmintrin.h
clang/lib/Headers/ppc_wrappers/smmintrin.h
clang/lib/Headers/ppc_wrappers/tmmintrin.h
clang/lib/Headers/ppc_wrappers/xmmintrin.h

Removed: 




diff  --git a/clang/lib/Headers/ppc_wrappers/emmintrin.h 
b/clang/lib/Headers/ppc_wrappers/emmintrin.h
index a4c458a41bcf..0814ea5593ba 100644
--- a/clang/lib/Headers/ppc_wrappers/emmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/emmintrin.h
@@ -36,7 +36,7 @@
 #ifndef EMMINTRIN_H_
 #define EMMINTRIN_H_
 
-#if defined(__ppc64__) &&  
\
+#if defined(__powerpc64__) &&  
\
 (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 #include 
@@ -2262,7 +2262,7 @@ extern __inline __m128d
 
 #else
 #include_next 
-#endif /* defined(__ppc64__) &&
+#endif /* defined(__powerpc64__) &&
\
 *   (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX)) */
 
 #endif /* EMMINTRIN_H_ */

diff  --git a/clang/lib/Headers/ppc_wrappers/mm_malloc.h 
b/clang/lib/Headers/ppc_wrappers/mm_malloc.h
index 65920917f3bd..7c1e625e44d5 100644
--- a/clang/lib/Headers/ppc_wrappers/mm_malloc.h
+++ b/clang/lib/Headers/ppc_wrappers/mm_malloc.h
@@ -10,7 +10,7 @@
 #ifndef _MM_MALLOC_H_INCLUDED
 #define _MM_MALLOC_H_INCLUDED
 
-#if defined(__ppc64__) &&  
\
+#if defined(__powerpc64__) &&  
\
 (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 #include 

diff  --git a/clang/lib/Headers/ppc_wrappers/mmintrin.h 
b/clang/lib/Headers/ppc_wrappers/mmintrin.h
index 70e8b81e11ee..0be3af2b0bd7 100644
--- a/clang/lib/Headers/ppc_wrappers/mmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/mmintrin.h
@@ -35,7 +35,7 @@
 #ifndef _MMINTRIN_H_INCLUDED
 #define _MMINTRIN_H_INCLUDED
 
-#if defined(__ppc64__) &&  
\
+#if defined(__powerpc64__) &&  
\
 (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 #include 
@@ -1447,7 +1447,7 @@ extern __inline __m64
 
 #else
 #include_next 
-#endif /* defined(__ppc64__) &&
+#endif /* defined(__powerpc64__) &&
\
 *   (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX)) */
 
 #endif /* _MMINTRIN_H_INCLUDED */

diff  --git a/clang/lib/Headers/ppc_wrappers/pmmintrin.h 
b/clang/lib/Headers/ppc_wrappers/pmmintrin.h
index fda39edbaa22..db128192abfb 100644
--- a/clang/lib/Headers/ppc_wrappers/pmmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/pmmintrin.h
@@ -39,7 +39,7 @@
 #ifndef PMMINTRIN_H_
 #define PMMINTRIN_H_
 
-#if defined(__ppc64__) &&  
\
+#if defined(__powerpc64__) &&  
\
 (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 /* We need definitions from the SSE2 and SSE header files*/
@@ -139,7 +139,7 @@ extern __inline __m128i
 
 #else
 #include_next 
-#endif /* defined(__ppc64__) &&
+#endif /* defined(__powerpc64__) &&
\
 *   (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX)) */
 
 #endif /* PMMINTRIN_H_ */

diff  --git a/clang/lib/Headers/ppc_wrappers/smmintrin.h 
b/clang/lib/Headers/ppc_wrappers/smmintrin.h
index 6fe6c8a93d9b..6fe6d2a157a5 100644
--- a/clang/lib/Headers/ppc_wrappers/smmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/smmintrin.h
@@ -29,7 +29,7 @@
 #ifndef SMMINTRIN_H_
 #define SMMINTRIN_H_
 
-#if defined(__ppc64__) &&  
\
+#if defined(__powerpc64__) &&  
\
 (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 #include 
@@ -657,7 +657,7 @@ extern __inline __m128i
 
 #else
 #include_next 
-#endif /* defined(__ppc64__) &&
+#endif /* defined(__powerpc64__) &&
\
 *   (defined(__linux__) || defin

[PATCH] D134231: [clang][C++20] p0960 Allow initializing aggregates from a parenthesized list of values

2022-11-06 Thread Ed Catmur via Phabricator via cfe-commits
ecatmur added a comment.

In D134231#3803380 , @shafik wrote:

> Hello Ed, thank you for picking up this work.
>
> I liked the approach in the first PR, did you consider reaching out to the 
> author is asking if it was ok to commandeer the work to allow it to move 
> forward?

Hi Shafik,

No, I didn't consider that - sorry! I felt that having done this work 
independently it was worth presenting separately. Sorry if I wasted anyone's 
time and happy to see that Alan has picked up the other PR. I'll close this as 
superseded if I can work out how.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134231

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


[PATCH] D137512: [clang] Add Swift support for MIPS

2022-11-06 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda created this revision.
Herald added subscribers: atanasyan, jrtc27, arichardson, sdardis.
Herald added a project: All.
colemancda requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds support for compiling Swift targeting the MIPS ABI


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137512

Files:
  clang/lib/Basic/Targets/Mips.h
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7704,7 +7704,7 @@
 
//===--===//
 
 namespace {
-class MipsABIInfo : public ABIInfo {
+class MipsABIInfo : public SwiftABIInfo {
   bool IsO32;
   unsigned MinABIStackAlignInBytes, StackAlignInBytes;
   void CoerceToIntArgs(uint64_t TySize,
@@ -7713,9 +7713,10 @@
   llvm::Type* returnAggregateInRegs(QualType RetTy, uint64_t Size) const;
   llvm::Type* getPaddingType(uint64_t Align, uint64_t Offset) const;
 public:
-  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32) :
-ABIInfo(CGT), IsO32(_IsO32), MinABIStackAlignInBytes(IsO32 ? 4 : 8),
-StackAlignInBytes(IsO32 ? 8 : 16) {}
+  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32)
+  : SwiftABIInfo(CGT), IsO32(_IsO32),
+MinABIStackAlignInBytes(IsO32 ? 4 : 8),
+StackAlignInBytes(IsO32 ? 8 : 16) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
@@ -7723,6 +7724,14 @@
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
   ABIArgInfo extendType(QualType Ty) const;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override { return false; }
 };
 
 class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
Index: clang/lib/Basic/Targets/Mips.h
===
--- clang/lib/Basic/Targets/Mips.h
+++ clang/lib/Basic/Targets/Mips.h
@@ -407,6 +407,17 @@
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
   bool hasExtIntType() const override { return true; }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 } // namespace targets
 } // namespace clang


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7704,7 +7704,7 @@
 //===--===//
 
 namespace {
-class MipsABIInfo : public ABIInfo {
+class MipsABIInfo : public SwiftABIInfo {
   bool IsO32;
   unsigned MinABIStackAlignInBytes, StackAlignInBytes;
   void CoerceToIntArgs(uint64_t TySize,
@@ -7713,9 +7713,10 @@
   llvm::Type* returnAggregateInRegs(QualType RetTy, uint64_t Size) const;
   llvm::Type* getPaddingType(uint64_t Align, uint64_t Offset) const;
 public:
-  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32) :
-ABIInfo(CGT), IsO32(_IsO32), MinABIStackAlignInBytes(IsO32 ? 4 : 8),
-StackAlignInBytes(IsO32 ? 8 : 16) {}
+  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32)
+  : SwiftABIInfo(CGT), IsO32(_IsO32),
+MinABIStackAlignInBytes(IsO32 ? 4 : 8),
+StackAlignInBytes(IsO32 ? 8 : 16) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
@@ -7723,6 +7724,14 @@
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
   ABIArgInfo extendType(QualType Ty) const;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override { return false; }
 };
 
 class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
Index: clang/lib/Basic/Targets/Mips.h
===
--- clang/lib/Basic/Targets/Mips.h
+++ clang/lib/Basic/Targets/Mips.h
@@ -407,6 +407,17 @@
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
   bool hasExtIntType() const override { return true; }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 

[PATCH] D137514: [clang-tidy] add check for capturing lambda coroutines

2022-11-06 Thread Noah Watkins via Phabricator via cfe-commits
dotnwat created this revision.
Herald added subscribers: carlosgalvezp, ChuanqiXu, kbarton, xazax.hun, 
nemanjai.
Herald added a project: All.
dotnwat requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Signed-off-by: Noah Watkins 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137514

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCapturingLambdaCoroutinesCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCapturingLambdaCoroutinesCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-capturing-lambda-coroutines.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-capturing-lambda-coroutines.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-capturing-lambda-coroutines.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-capturing-lambda-coroutines.cpp
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy -std=c++20-or-later %s cppcoreguidelines-avoid-capturing-lambda-coroutines %t -- -- \
+// RUN:   -isystem %S/readability/Inputs/identifier-naming/system
+
+#include 
+
+void Caught() {
+int v;
+
+[&] () -> task { int y = v; co_return; };
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
+[=] () -> task { int y = v; co_return; };
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
+[v] () -> task { co_return; };
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
+[&v] () -> task { co_return; };
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
+[y=v] () -> task { co_return; };
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
+[y{v}] () -> task { co_return; };
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
+}
+
+struct S {
+void m() {
+[this] () -> task { co_return; };
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
+}
+};
+
+void Safe() {
+int v;
+[] () -> task { co_return; };
+[&] () -> task { co_return; };
+[=] () -> task { co_return; };
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -177,6 +177,7 @@
`clang-analyzer-valist.Unterminated `_,
`concurrency-mt-unsafe `_,
`concurrency-thread-canceltype-asynchronous `_,
+   `cppcoreguidelines-avoid-capturing-lambda-coroutines `_, "Yes"
`cppcoreguidelines-avoid-const-or-ref-data-members `_,
`cppcoreguidelines-avoid-do-while `_,
`cppcoreguidelines-avoid-goto `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-capturing-lambda-coroutines.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-capturing-lambda-coroutines.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-capturing-lambda-coroutines
+
+cppcoreguidelines-avoid-capturing-lambda-coroutines
+===
+
+Warns if a capturing lambda is a coroutine. For example:
+
+.. code-block:: c++
+
+   int c;
+
+   [c] () -> task { co_return; };
+   [&] () -> task { int y = c; co_return; };
+   [=] () -> task { int y = c; co_return; };
+
+   struct s {
+   void m() {
+   [this] () -> task { co_return; };
+   }
+   };
+
+All of the cases above will trigger the warning. However, implicit captures
+do not trigger the warning unless the body of the lambda uses the capture.
+For example, the following do not trigger the warning.
+
+.. code-block:: c++
+
+   int c;
+
+   [&] () -> task { co_return; };
+   [=] () -> task { co_return; };
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,13 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`cppcoreguidelines-avoid-capturing-lambda-corou

[PATCH] D137515: [TargetSupport] Move TargetParser API in a separate LLVM component.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli created this revision.
Herald added subscribers: kosarev, foad, frasercrmck, kerbowa, luismarques, 
apazos, sameer.abuasal, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson, jvesely, 
arsenm.
Herald added a reviewer: NoQ.
Herald added a project: All.
fpetrogalli requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, MaskRay.
Herald added projects: clang, LLVM.

[TargetSupport] Generate the defs for RISCV CPUs using llvm-tblgen.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137515

Files:
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/TargetID.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/lib/Driver/ToolChains/Arch/CSKY.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/unittests/Basic/CMakeLists.txt
  llvm/include/llvm/Support/RISCVTargetParser.def
  llvm/include/llvm/Support/TargetParser.h
  llvm/include/llvm/TargetSupport/TargetParser.h
  llvm/include/llvm/module.modulemap
  llvm/lib/CMakeLists.txt
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/AArch64/AsmParser/CMakeLists.txt
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
  llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
  llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
  llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.h
  llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
  llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
  llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
  llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
  llvm/lib/Target/ARM/ARMAsmPrinter.cpp
  llvm/lib/Target/ARM/ARMSubtarget.cpp
  llvm/lib/Target/ARM/ARMTargetMachine.cpp
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/AsmParser/CMakeLists.txt
  llvm/lib/Target/ARM/CMakeLists.txt
  llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
  llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/RISCV/CMakeLists.txt
  llvm/lib/Target/RISCV/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/X86/MCA/X86CustomBehaviour.h
  llvm/lib/TargetSupport/CMakeLists.txt
  llvm/lib/TargetSupport/TargetParser.cpp
  llvm/unittests/CMakeLists.txt
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/CSKYTargetParserTest.cpp
  llvm/unittests/Support/TargetParserTest.cpp
  llvm/unittests/TargetSupport/CMakeLists.txt
  llvm/unittests/TargetSupport/TargetParserTest.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   Gen

[PATCH] D137515: [TargetSupport] Move TargetParser API in a separate LLVM component.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli abandoned this revision.
fpetrogalli added a comment.

Abandoning because I accidentally squashed the two commits together when using 
Arcanist. I'll follow up with two new revisions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137515

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


[PATCH] D137516: [TargetSupport] Move TargetParser API in a separate LLVM component.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli created this revision.
Herald added subscribers: kosarev, foad, frasercrmck, kerbowa, luismarques, 
apazos, sameer.abuasal, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson, jvesely, 
arsenm.
Herald added a reviewer: NoQ.
Herald added a project: All.
fpetrogalli requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137516

Files:
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/TargetID.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/lib/Driver/ToolChains/Arch/CSKY.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/unittests/Basic/CMakeLists.txt
  llvm/include/llvm/Support/RISCVTargetParser.def
  llvm/include/llvm/Support/TargetParser.h
  llvm/include/llvm/TargetSupport/RISCVTargetParser.def
  llvm/include/llvm/TargetSupport/TargetParser.h
  llvm/lib/CMakeLists.txt
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
  llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
  llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
  llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.h
  llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
  llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
  llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
  llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
  llvm/lib/Target/ARM/ARMAsmPrinter.cpp
  llvm/lib/Target/ARM/ARMSubtarget.cpp
  llvm/lib/Target/ARM/ARMTargetMachine.cpp
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/X86/MCA/X86CustomBehaviour.h
  llvm/lib/TargetSupport/CMakeLists.txt
  llvm/lib/TargetSupport/TargetParser.cpp
  llvm/unittests/CMakeLists.txt
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/CSKYTargetParserTest.cpp
  llvm/unittests/Support/TargetParserTest.cpp
  llvm/unittests/TargetSupport/CMakeLists.txt
  llvm/unittests/TargetSupport/TargetParserTest.cpp

Index: llvm/unittests/TargetSupport/TargetParserTest.cpp
===
--- llvm/unittests/TargetSupport/TargetParserTest.cpp
+++ llvm/unittests/TargetSupport/TargetParserTest.cpp
@@ -11,7 +11,7 @@
 #include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ARMBuildAttributes.h"
 #include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/TargetParser.h"
+#include "llvm/TargetSupport/TargetParser.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
Index: llvm/unittests/TargetSupport/CMakeLists.txt
===
--- /dev/null
+++ llvm/unittests/TargetSupport/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(LLVM_LINK_COMPONENTS
+  TargetSupport
+  )
+
+add_llvm_unittest(TargetSupportTests
+  TargetParserTest.cpp
+  )
+
+target_link_libraries(TargetSupportTests PRIVATE LLVMTestingSupport)
Index: llvm/unittests/Support/CSKYTargetParserTest.cpp
===
--- llvm/unittests/Support/CSKYTargetParserTest.cpp
+++ llvm/unittests/Support/CSKYTargetParserTest.cpp
@@ -11,7 +11,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CSKYAttributes.h"
 #include "llvm/Suppor

[PATCH] D137517: [TargetSupport] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli created this revision.
Herald added subscribers: kosarev, sunshaoce, VincentWu, foad, vkmr, 
frasercrmck, evandro, kerbowa, luismarques, apazos, sameer.abuasal, s.egerton, 
Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb, hiraditya, arichardson, jvesely, arsenm.
Herald added a project: All.
fpetrogalli requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Driver/CMakeLists.txt
  llvm/include/llvm/TargetSupport/RISCVTargetParser.def
  llvm/include/llvm/TargetSupport/TargetParser.h
  llvm/include/llvm/module.modulemap
  llvm/lib/Target/AArch64/AsmParser/CMakeLists.txt
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
  llvm/lib/Target/ARM/AsmParser/CMakeLists.txt
  llvm/lib/Target/ARM/CMakeLists.txt
  llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/RISCV/CMakeLists.txt
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/TargetSupport/CMakeLists.txt
  llvm/lib/TargetSupport/TargetParser.cpp
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/TargetSupport/CMakeLists.txt
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,49 @@
+//===- AsmWriterEmitter.cpp - Generate an assembly writer -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits an assembly printer for the current target.
+// Note that this is currently fairly skeletal, but will grow over time.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getValueAsString("Enum") << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"}, "
+ << Record->getValueAsString("EnumFeatures") << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "

[PATCH] D137375: [AIX][pg] Add Correct Search Paths for Profiled Libraries

2022-11-06 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 473528.
francii added a comment.

Including test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137375

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/aix-ld.c


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -162,6 +162,8 @@
 // CHECK-LD64-GPROF-NOT: "--no-as-needed"
 // CHECK-LD64-GPROF-NOT: "-lm"
 // CHECK-LD64-GPROF: "-lc"
+// CHECK-LD64-GPROF: "-L/lib/profiled"
+// CHECK-LD64-GPROF: "-L/usr/lib/profiled"
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Static linking.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -250,6 +250,11 @@
   CmdArgs.push_back("-lm");
 
 CmdArgs.push_back("-lc");
+
+if (Args.hasArg(options::OPT_pg)) {
+  CmdArgs.push_back("-L/lib/profiled");
+  CmdArgs.push_back("-L/usr/lib/profiled");
+}
   }
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -162,6 +162,8 @@
 // CHECK-LD64-GPROF-NOT: "--no-as-needed"
 // CHECK-LD64-GPROF-NOT: "-lm"
 // CHECK-LD64-GPROF: "-lc"
+// CHECK-LD64-GPROF: "-L/lib/profiled"
+// CHECK-LD64-GPROF: "-L/usr/lib/profiled"
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Static linking.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -250,6 +250,11 @@
   CmdArgs.push_back("-lm");
 
 CmdArgs.push_back("-lc");
+
+if (Args.hasArg(options::OPT_pg)) {
+  CmdArgs.push_back("-L/lib/profiled");
+  CmdArgs.push_back("-L/usr/lib/profiled");
+}
   }
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 34f687c - [test] Canonicalize PowerPC detection macros to __powerpc__

2022-11-06 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-11-06T17:38:57-08:00
New Revision: 34f687cbe468e8044e8d94c977a2e47cbd3f3799

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

LOG: [test] Canonicalize PowerPC detection macros to __powerpc__

Added: 


Modified: 
clang/test/Sema/128bitfloat.cpp
clang/test/Sema/attr-mode.c

Removed: 




diff  --git a/clang/test/Sema/128bitfloat.cpp b/clang/test/Sema/128bitfloat.cpp
index 6b9d63e6af4cf..b98b42496e8db 100644
--- a/clang/test/Sema/128bitfloat.cpp
+++ b/clang/test/Sema/128bitfloat.cpp
@@ -7,7 +7,7 @@
 
 #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
 
-#if defined(__ppc__)
+#if defined(__powerpc__)
 template  struct __is_float128 { static constexpr bool value = 
false; };
 template <> struct __is_float128<__float128> { static constexpr bool value = 
true; };
 static_assert(__is_float128<__ieee128>::value, "__ieee128 aliases to 
__float128");
@@ -45,7 +45,7 @@ int g(int x, __float128 *y) {  // expected-error {{__float128 
is not supported o
 #endif
 #endif
 
-#ifdef __ppc__
+#ifdef __powerpc__
 __ibm128 i;
 template <> struct __is_floating_point_helper<__ibm128> {};
 int w(int x, __ibm128 *y) {

diff  --git a/clang/test/Sema/attr-mode.c b/clang/test/Sema/attr-mode.c
index 71d82a20f66d0..5e99c4583155a 100644
--- a/clang/test/Sema/attr-mode.c
+++ b/clang/test/Sema/attr-mode.c
@@ -46,7 +46,7 @@ typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
 typedef _Complex float c64 __attribute((mode(DC)));
 
-#if !defined(__ppc__) && !defined(__mips__) // Note, 'XC' mode is illegal for 
PPC64 and MIPS machines.
+#if !defined(__powerpc__) && !defined(__mips__) // Note, 'XC' mode is illegal 
for PPC64 and MIPS machines.
 typedef _Complex float c80 __attribute((mode(XC)));
 #endif
 



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


[PATCH] D137517: [TargetSupport] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 473532.
fpetrogalli added a comment.

I updated the text of the header of the file `RISCVTargetDefEmitter.cpp`. NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Driver/CMakeLists.txt
  llvm/include/llvm/TargetSupport/RISCVTargetParser.def
  llvm/include/llvm/TargetSupport/TargetParser.h
  llvm/include/llvm/module.modulemap
  llvm/lib/Target/AArch64/AsmParser/CMakeLists.txt
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
  llvm/lib/Target/ARM/AsmParser/CMakeLists.txt
  llvm/lib/Target/ARM/CMakeLists.txt
  llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/RISCV/CMakeLists.txt
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/TargetSupport/CMakeLists.txt
  llvm/lib/TargetSupport/TargetParser.cpp
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/TargetSupport/CMakeLists.txt
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,49 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits an assembly printer for the current target.
+// Note that this is currently fairly skeletal, but will grow over time.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getValueAsString("Enum") << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"}, "
+ << Record->getValueAsString("EnumFeatures") << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getValueAsStrin

[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-06 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

Here is one problem:

  clang-format -style='{IndentPPDirectives: BeforeHash, PPIndentWidth: 1, 
IndentWidth: 4, IndentCaseLabels: true}'
  
  actual:
  #define X 
 \
   switch (x) { 
 \
   case 0:  
 \
break;  
 \
   default: 
 \
break;  
 \
   }
  
  expected:
  #define X 
 \
   switch (x) { 
 \
   case 0:  
 \
   break;   
 \
   default: 
 \
   break;   
 \
   }

Me guessing what caused the problem.  You intend for `PPLevel` to mean the 
depth of `#if` sections.  But you accidentally made it change along with 
`Level` where you shouldn't, for example in `UnwrappedLineParser.cpp: 600`.

In addition, I suggest including `PPBranchLevel` in `PPLevel` only instead of 
also in `Level`.




Comment at: clang/lib/Format/UnwrappedLineParser.h:47
 
+  /// The preprocessor indent level of the \c UnwrappedLine.
+  int PPLevel;

Please elaborate what preprocessor indent level means.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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


[PATCH] D137381: [clang][compiler-rt] Exception escape out of an non-unwinding function is an undefined behaviour

2022-11-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 473529.
lebedev.ri edited the summary of this revision.
lebedev.ri added a comment.
Herald added a subscriber: mstorsjo.

In D137381#3907799 , @lebedev.ri 
wrote:

> In D137381#3907104 , @MaskRay wrote:
>
>> In your example, `clang++ a.cc; ./a.out` gives a libstdc++ error:
>>
>>   terminate called after throwing an instance of 'int'
>>
>> libc++'s is similar.
>
> That's great, but just a symptom of misreduced testcase.
> The whole problem is that in the original bug *no* abort happened at runtime,
> the program terminated successfully, with a mysterious leak.
>
>> footgun is nounwind (due to the GNU pure attribute), so Clang uses `call` 
>> instead of `invoke` and the function call is described by a call site entry 
>> with a zero action_record_offset (i.e. not a handler) in `.gcc_except_table`.
>> In `_Unwind_RaiseException` called by `__cxa_throw`, the missing exception 
>> handler causes `__terminate`.
>>
>> `g++ a.cc; ./a.out` succeeds, because its `footgun` call is caught by `catch 
>> (...)`. (Perhaps GCC doesn't have Clang's nounwind optimization.)

FWIW, i now have a standalone reproducer (~3MiB filesize),
and without sanitizers there's no abort regardless of optimization level,
with sanitizers there's only the leak report, and no mention of the exception.

I've already reduced it, but something gone wrong, and for some inexplicable 
reason,
creduce succeeded with a repro that does not pass the interestingness test
(this is not an error in said interestingness test.) So i will need to 
re-reduce.

But as as i have expected, the problem will likely end up being more 
fundamental,
because, not unexpectedly, this new diagnostic does not show up either.

TLDR:

thisisfine 


>> The patch doesn't implement the runtime correctly (I get a linker error) so 
>> I cannot try it out.

I believe this should now be fixed.
I did not update `getRecoverableKind()`, which, conveniently, duplicates 
`Unrecoverable` from `SanitizerArgs.cpp`...

>> How expensive is your instrumentation?
>> Does it work with `-fno-exceptions` intermediate functions? (Unwinding 
>> through such functions should fail as well). Note that this check can be 
>> done today,without any instrumentation: just use 
>> `-fno-asynchronous-unwind-tables` (for some targets which default to async 
>> unwind tables (aarch64,x86,etc)).
>> If the process installs a SIGABRT signal handler, the stack trace can be 
>> printed when `__terminate` calls `abort`.

As you can see, at least right now, this quite literally relies on
the existing `CodeGenFunction::getTerminateLandingPad()` handling infra,
so it is as cheap as it will be. But has the same bugs as it already has.

The obvious alternative implementation could be to, when emitting `nounwing` 
function body `F`,
emit it as a thunk with an an invoke of an actual function, but without 
`nounwind`,
but that is undesirable because we lose all source debug information.

This is UB, and it should be handled by UBSan, not somewhere else,
especially because that will result in best error messages.

> I find this comment non-welcoming and discouraging.
> I just wanted to get something posted when i had something to post already. 
> All of this needs a bit more time.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137381

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/include/clang/Basic/Sanitizers.def
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGenCXX/catch-exception-escape.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/lib/ubsan/ubsan_checks.inc
  compiler-rt/lib/ubsan/ubsan_handlers.cpp
  compiler-rt/lib/ubsan/ubsan_handlers.h
  compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
  compiler-rt/test/ubsan/TestCases/Misc/exception-escape.cpp
  compiler-rt/test/ubsan_minimal/TestCases/exception-escape.cpp

Index: compiler-rt/test/ubsan_minimal/TestCases/exception-escape.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan_minimal/TestCases/exception-escape.cpp
@@ -0,0 +1,36 @@
+// RUN: %clangxx -fsanitize=exception-escape %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="exception-escape" --check-prefixes=CHECK-ALL,CHECK-ONE
+// RUN: not --crash %run %t a 2>&1 | FileCheck %s --implicit-check-not="exception-escape" --check-prefixes=CHECK-ALL,CHECK-TWO
+// RUN: not --crash %run %t a b 2>&1 | FileCheck %s --implicit-check-not="exception-escape" --check-prefixes=CHECK-ALL,CHECK-THREE
+
+#include 
+
+void thrower() { throw 0; }
+
+

[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-11-06 Thread Zhang Haoyu via Phabricator via cfe-commits
HaoyuZhang updated this revision to Diff 473533.
HaoyuZhang added a comment.

Use a dummy file instead of cross-directory test file reference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/pgo-sample-use-profi.c


Index: clang/test/Driver/pgo-sample-use-profi.c
===
--- /dev/null
+++ clang/test/Driver/pgo-sample-use-profi.c
@@ -0,0 +1,4 @@
+/// Test if profi flat is enabled in frontend as user-facing feature.
+// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null 
-### %s 2>&1 | FileCheck %s
+
+// CHECK: "-mllvm" "-sample-profile-use-profi"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5760,6 +5760,12 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
+  if (getLastProfileSampleUseArg(Args) &&
+  Args.hasArg(options::OPT_fsample_profile_use_profi)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-sample-profile-use-profi");
+  }
+
   // Add runtime flag for PS4/PS5 when PGO, coverage, or sanitizers are 
enabled.
   if (RawTriple.isPS() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1248,6 +1248,13 @@
as cold. Otherwise, treat callsites without profile samples as 
if
we have no profile}]>,
MarshallingInfoFlag>;
+def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
+Flags<[NoXarchOption, CC1Option]>, Group,
+HelpText<"Use profi to infer block and edge counts">,
+DocBrief<[{Infer block and edge counts. If the profiles have errors or 
missing
+   blocks caused by sampling, profile inference (profi) can convert
+   basic block counts to branch probabilites to fix them by 
extended
+   and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
 def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">,
   Group, Flags<[NoXarchOption]>;
 def fauto_profile : Flag<["-"], "fauto-profile">, Group,
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -2241,6 +2241,15 @@
 
  $ clang++ -O2 -gline-tables-only -fprofile-sample-use=code.prof code.cc 
-o code
 
+  [OPTIONAL] Sampling-based profiles can have inaccuracies or missing block/
+  edge counters. The profile inference algorithm (profi) can be used to infer
+  missing blocks and edge counts, and improve the quality of profile data.
+  Enable it with ``-fsample-profile-use-profi``.
+
+  .. code-block:: console
+
+$ clang++ -O2 -gline-tables-only -fprofile-sample-use=code.prof \
+  -fsample-profile-use-profi code.cc -o code
 
 Sample Profile Formats
 ""


Index: clang/test/Driver/pgo-sample-use-profi.c
===
--- /dev/null
+++ clang/test/Driver/pgo-sample-use-profi.c
@@ -0,0 +1,4 @@
+/// Test if profi flat is enabled in frontend as user-facing feature.
+// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-mllvm" "-sample-profile-use-profi"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5760,6 +5760,12 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
+  if (getLastProfileSampleUseArg(Args) &&
+  Args.hasArg(options::OPT_fsample_profile_use_profi)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-sample-profile-use-profi");
+  }
+
   // Add runtime flag for PS4/PS5 when PGO, coverage, or sanitizers are enabled.
   if (RawTriple.isPS() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1248,6 +1248,13 @@
as cold. Otherwise, treat callsites without profile samples as if
we have no profile}]>,
MarshallingInfoFlag>;
+def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
+Flags<[NoXarchOption, CC1Option]>, Group,
+HelpText<"Use profi to infer block and edge counts">,
+DocBrief<

[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-11-06 Thread Zhang Haoyu via Phabricator via cfe-commits
HaoyuZhang added a comment.

Thanks @MaskRay and @wenlei for the reviewing.

New version for using dummy file has been updated.




Comment at: clang/test/Driver/pgo-sample-use-profi.c:2
+/// Test if profi flat is enabled in frontend as user-facing feature.
+// RUN: %clang -c -fsample-profile-use-profi 
-fprofile-sample-use=%S/../CodeGen/Inputs/pgo-sample.prof -### %s 2>&1 | 
FileCheck %s
+

MaskRay wrote:
> Such a cross-directory test file reference is generally not acceptable. Use a 
> dummy file `-fprofile-sample-use=/dev/null`
Thank you for the comments. Modified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

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


[PATCH] D137516: [TargetSupport] Move TargetParser API in a separate LLVM component.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

RFC at 
https://discourse.llvm.org/t/targetparser-auto-generation-of-riscv-cpu-definitions/66419


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137516

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


[PATCH] D137517: [TargetSupport] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

RFC at RFC at 
https://discourse.llvm.org/t/targetparser-auto-generation-of-riscv-cpu-definitions/66419


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137514: [clang-tidy] add check for capturing lambda coroutines

2022-11-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

This is helpful. I feel it is OK to add the warning in the clang too. Are you 
interested in that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137514

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


[PATCH] D137517: [TargetSupport] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-11-06 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added a comment.

Thanks! I think it's a great improvement!




Comment at: llvm/lib/Target/RISCV/RISCV.td:509
 
-def : ProcessorModel<"generic-rv32", NoSchedModel, [Feature32Bit]>;
-def : ProcessorModel<"generic-rv64", NoSchedModel, [Feature64Bit]>;
+class RISCVProcessorModelPROC {
+  string Enum = enum;

Can `EnumFeatures/DefaultMarch` string be inferred from ProcessorModel's 
SubtargetFeature if not specified and `Enum` just be the uppercase of the name 
of ProcessorModel? The implementation could be more complicated but I think 
it's worthy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D136930: [RISCV] Support -mcpu/mtune=native

2022-11-06 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136930

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


[PATCH] D137511: [PPC] Undefine __ppc64__ to match GCC

2022-11-06 Thread Sam James via Phabricator via cfe-commits
thesamesam added a comment.

This needs to go in Breaking Changes in the release notes, not least so we can 
link to it when updating upstreams.

What do you mean by "while the darwin support has been removed from 
llvm-project."? I don't think that's the case, if you mean that LLVM.org's LLVM 
lacks support for Darwin.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137511

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


[clang] 7c50bcb - [RISCV] Support -mcpu/mtune=native

2022-11-06 Thread via cfe-commits

Author: wangpc
Date: 2022-11-07T10:43:32+08:00
New Revision: 7c50bcb441707f862cd7fcd07d81fbcdc29e98dc

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

LOG: [RISCV] Support -mcpu/mtune=native

We may need hosted Clang/LLVM to compile and `getHostCpuName`
can be used for native detection.

Tests are added in riscv-cpus.c just like what AArch64/PPC
have done.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/lib/Driver/ToolChains/Arch/RISCV.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/riscv-cpus.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7bb1405c131ab..72b9a52c7cd0d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -677,6 +677,7 @@ RISC-V Support in Clang
 ---
 - ``sifive-7-rv32`` and ``sifive-7-rv64`` are no longer supported for 
``-mcpu``.
   Use ``sifive-e76``, ``sifive-s76``, or ``sifive-u74`` instead.
+- Native detections via ``-mcpu=native`` and ``-mtune=native`` are supported.
 
 X86 Support in Clang
 

diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index c845e69c14e84..081e8ff4a168f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
@@ -48,16 +49,12 @@ static bool getArchFeatures(const Driver &D, StringRef Arch,
 }
 
 // Get features except standard extension feature
-static void getRISCFeaturesFromMcpu(const Driver &D, const llvm::Triple 
&Triple,
-const llvm::opt::ArgList &Args,
-const llvm::opt::Arg *A, StringRef Mcpu,
+static bool getRISCFeaturesFromMcpu(const llvm::Triple &Triple, StringRef Mcpu,
 std::vector &Features) {
   bool Is64Bit = Triple.isRISCV64();
   llvm::RISCV::CPUKind CPUKind = llvm::RISCV::parseCPUKind(Mcpu);
-  if (!llvm::RISCV::checkCPUKind(CPUKind, Is64Bit) ||
-  !llvm::RISCV::getCPUFeaturesExceptStdExt(CPUKind, Features)) {
-D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
-  }
+  return llvm::RISCV::checkCPUKind(CPUKind, Is64Bit) &&
+ llvm::RISCV::getCPUFeaturesExceptStdExt(CPUKind, Features);
 }
 
 void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
@@ -70,8 +67,14 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 
   // If users give march and mcpu, get std extension feature from MArch
   // and other features (ex. mirco architecture feature) from mcpu
-  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
-getRISCFeaturesFromMcpu(D, Triple, Args, A, A->getValue(), Features);
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+StringRef CPU = A->getValue();
+if (CPU == "native")
+  CPU = llvm::sys::getHostCPUName();
+if (!getRISCFeaturesFromMcpu(Triple, CPU, Features))
+  D.Diag(clang::diag::err_drv_unsupported_option_argument)
+  << A->getOption().getName() << CPU;
+  }
 
   // Handle features corresponding to "-ffixed-X" options
   if (Args.hasArg(options::OPT_ffixed_x1))
@@ -260,7 +263,10 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
 
   // 2. Get march (isa string) based on `-mcpu=`
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
-StringRef MArch = llvm::RISCV::getMArchFromMcpu(A->getValue());
+StringRef CPU = A->getValue();
+if (CPU == "native")
+  CPU = llvm::sys::getHostCPUName();
+StringRef MArch = llvm::RISCV::getMArchFromMcpu(CPU);
 // Bypass if target cpu's default march is empty.
 if (MArch != "")
   return MArch;
@@ -299,3 +305,20 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
   return "rv64imafdc";
   }
 }
+
+std::string riscv::getRISCVTargetCPU(const llvm::opt::ArgList &Args,
+ const llvm::Triple &Triple) {
+  std::string CPU;
+  // If we have -mcpu, use that.
+  if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
+CPU = A->getValue();
+
+  // Handle CPU name is 'native'.
+  if (CPU == "native")
+CPU = llvm::sys::getHostCPUName();
+
+  if (!CPU.empty())
+return CPU;
+
+  return Triple.isRISCV64() ? "generic-rv64" : "generic-rv32";
+}

diff  --git a/cla

[PATCH] D136930: [RISCV] Support -mcpu/mtune=native

2022-11-06 Thread Wang Pengcheng via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c50bcb44170: [RISCV] Support -mcpu/mtune=native (authored 
by pcwang-thead).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136930

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/riscv-cpus.c

Index: clang/test/Driver/riscv-cpus.c
===
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -7,6 +7,10 @@
 // MCPU-ROCKET64: "-nostdsysteminc" "-target-cpu" "rocket-rv64"
 // MCPU-ROCKET64: "-target-feature" "+64bit"
 
+// We cannot check much for -mcpu=native, but it should be replaced by a valid CPU string.
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=native | FileCheck -check-prefix=MCPU-NATIVE %s
+// MCPU-NATIVE-NOT: "-target-cpu" "native"
+
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=rocket-rv32 | FileCheck -check-prefix=MTUNE-ROCKET32 %s
 // MTUNE-ROCKET32: "-tune-cpu" "rocket-rv32"
 
@@ -26,6 +30,10 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=rocket | FileCheck -check-prefix=MTUNE-ROCKET-64 %s
 // MTUNE-ROCKET-64: "-tune-cpu" "rocket"
 
+// We cannot check much for -mtune=native, but it should be replaced by a valid CPU string.
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=native | FileCheck -check-prefix=MTUNE-NATIVE %s
+// MTUNE-NATIVE-NOT: "-tune-cpu" "native"
+
 // mcpu with default march
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=sifive-e20 | FileCheck -check-prefix=MCPU-SIFIVE-E20 %s
 // MCPU-SIFIVE-E20: "-nostdsysteminc" "-target-cpu" "sifive-e20"
@@ -130,10 +138,10 @@
 // Check failed cases
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv321 | FileCheck -check-prefix=FAIL-MCPU-NAME %s
-// FAIL-MCPU-NAME: error: the clang compiler does not support '-mcpu=generic-rv321'
+// FAIL-MCPU-NAME: error: unsupported argument 'generic-rv321' to option '-mcpu='
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 -march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
-// MISMATCH-ARCH: error: the clang compiler does not support '-mcpu=generic-rv32'
+// MISMATCH-ARCH: error: unsupported argument 'generic-rv32' to option '-mcpu='
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv64 | FileCheck -check-prefix=MISMATCH-MCPU %s
-// MISMATCH-MCPU: error: the clang compiler does not support '-mcpu=generic-rv64'
+// MISMATCH-MCPU: error: unsupported argument 'generic-rv64' to option '-mcpu='
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -12,6 +12,7 @@
 #include "Arch/M68k.h"
 #include "Arch/Mips.h"
 #include "Arch/PPC.h"
+#include "Arch/RISCV.h"
 #include "Arch/Sparc.h"
 #include "Arch/SystemZ.h"
 #include "Arch/VE.h"
@@ -432,9 +433,7 @@
   return "ck810";
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
-  return A->getValue();
-return "";
+return riscv::getRISCVTargetCPU(Args, T);
 
   case llvm::Triple::bpfel:
   case llvm::Triple::bpfeb:
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2187,7 +2187,10 @@
 
   if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
 CmdArgs.push_back("-tune-cpu");
-CmdArgs.push_back(A->getValue());
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
   }
 }
 
Index: clang/lib/Driver/ToolChains/Arch/RISCV.h
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.h
+++ clang/lib/Driver/ToolChains/Arch/RISCV.h
@@ -26,6 +26,8 @@
   const llvm::Triple &Triple);
 StringRef getRISCVArch(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple);
+std::string getRISCVTargetCPU(const llvm::opt::ArgList &Args,
+  const llvm::Triple &Triple);
 } // end namespace riscv
 } // namespace tools
 } // end namespace driver
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Host.h"
 #include "ll

[PATCH] D137520: [AVR][Clang] Move family names into MCU list

2022-11-06 Thread Ayke via Phabricator via cfe-commits
aykevl created this revision.
aykevl added reviewers: dylanmckay, benshi001.
Herald added a subscriber: Jim.
Herald added a project: All.
aykevl requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This simplifies the code by avoiding some special cases for family names (as 
opposed to device names).

This patch is just a refactor, the next patch will have a meaningful 
improvement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137520

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/test/Misc/target-invalid-cpu-note.c

Index: clang/test/Misc/target-invalid-cpu-note.c
===
--- clang/test/Misc/target-invalid-cpu-note.c
+++ clang/test/Misc/target-invalid-cpu-note.c
@@ -77,7 +77,7 @@
 
 // RUN: not %clang_cc1 -triple avr--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AVR
 // AVR: error: unknown target CPU 'not-a-cpu'
-// AVR-NEXT: note: valid target CPU values are: avr1, avr2, avr25, avr3, avr31, avr35, avr4, avr5, avr51, avr6, avrxmega1, avrxmega2, avrxmega3, avrxmega4, avrxmega5, avrxmega6, avrxmega7, avrtiny, at90s1200, attiny11, attiny12, attiny15, attiny28, at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at86rf401, at90s4414, at90s4433, at90s4434, at90s8515, at90c8534, at90s8535, ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24, attiny24a, attiny4313, attiny44, attiny44a, attiny84, attiny84a, attiny25, attiny45, attiny85, attiny261, attiny261a, attiny441, attiny461, attiny461a, attiny841, attiny861, attiny861a, attiny87, attiny43u, attiny48, attiny88, attiny828, at43usb355, at76c711, atmega103, at43usb320, attiny167, at90usb82, at90usb162, ata5505, ata6617c, ata664251, atmega8u2, atmega16u2, atmega32u2, attiny1634, atmega8, ata6289, atmega8a, ata6285, ata6286, ata6612c, atmega48, atmega48a, atmega48pa, atmega48pb, atmega48p, atmega88, atmega88a, atmega88p, atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1, at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81, ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831, ata6613c, ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162, atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a, atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa, atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega32, atmega32a, atmega323, atmega324a, atmega324p, atmega324pa, atmega324pb, atmega325, atmega325a, atmega325p, atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328, atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa, atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega406, atmega64, atmega64a, atmega640, atmega644, atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p, atmega649, atmega649a, atmega649p, atmega6450, atmega6450a, atmega6450p, atmega6490, atmega6490a, atmega6490p, atmega64rfr2, atmega644rfr2, atmega16hva, atmega16hva2, atmega16hvb, atmega16hvbrevb, atmega32hvb, atmega32hvbrevb, atmega64hve, atmega64hve2, at90can32, at90can64, at90pwm161, at90pwm216, at90pwm316, atmega32c1, atmega64c1, atmega16m1, atmega32m1, atmega64m1, atmega16u4, atmega32u4, atmega32u6, at90usb646, at90usb647, at90scr100, at94k, m3000, atmega128, atmega128a, atmega1280, atmega1281, atmega1284, atmega1284p, atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286, at90usb1287, atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2, atxmega16a4, atxmega16a4u, atxmega16c4, atxmega16d4, atxmega32a4, atxmega32a4u, atxmega32c3, atxmega32c4, atxmega32d3, atxmega32d4, atxmega32e5, atxmega16e5, atxmega8e5, atxmega64a3, atxmega64a3u, atxmega64a4u, atxmega64b1, atxmega64b3, atxmega64c3, atxmega64d3, atxmega64d4, atxmega64a1, atxmega64a1u, atxmega128a3, atxmega128a3u, atxmega128b1, atxmega128b3, atxmega128c3, atxmega128d3, atxmega128d4, atxmega192a3, atxmega192a3u, atxmega192c3, atxmega192d3, atxmega256a3, atxmega256a3u, atxmega256a3b, atxmega256a3bu, atxmega256c3, atxmega256d3, atxmega384c3, atxmega384d3, atxmega128a1, atxmega128a1u, atxmega128a4u, attiny4, attiny5, attiny9, attiny10, attiny20, attiny40, attiny102, attiny104, attiny202, attiny402, attiny204, attiny404, attiny804, attiny1604, attiny406, attiny806, attiny1606, attiny807, attiny1607, attiny212, attiny412, attiny214, attiny414, attiny814, attiny1614, attiny416, attiny816, attiny1616, attiny3216, attiny417, attiny817, attiny1617, attiny3217, attiny1624, attiny1626, attiny1627, atmega808, atmega809, atmega1608, atmega1609, atmega3208, atmega3209, atmega4808, atmega4809
+// AVR-NEXT: note: valid target CPU values are: avr1, at90s1200, attiny11, attiny12, attiny15, attiny28, avr2, at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at86rf401, at90s4414, at90s4433, at90s4434, at90s8515, at90c8534, at90s8535, avr25, ata5272, 

[PATCH] D137511: [PPC] Undefine __ppc64__ to match GCC

2022-11-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added subscribers: Bdragon28, jhibbits, dim.
MaskRay added a comment.

In D137511#3911052 , @thesamesam 
wrote:

> This needs to go in Breaking Changes in the release notes, not least so we 
> can link to it when updating upstreams.
>
> What do you mean by "while the darwin support has been removed from 
> llvm-project."? I don't think that's the case, if you mean that LLVM.org's 
> LLVM lacks support for Darwin.

Clarified it to "The darwin ppc support has been removed from llvm-project."

In D137511#3910880 , @q66 wrote:

> The `__ppc__` macro should get the same treatment. That said, I believe there 
> are instances of both macros being used across the LLVM codebase, and those 
> cases are valid, so that should also be updated (one instance i know of is 
> the limits header of libcxx, there are likely more)

`__ppc__` is defined for FreeBSD in GCC, so perhaps we can make a separate 
change making `__ppc__` only defined for FreeBSD (@dim @Bdragon28 @jhibbits).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137511

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


[PATCH] D137521: [AVR][Clang] Implement __AVR_ARCH__ macro

2022-11-06 Thread Ayke via Phabricator via cfe-commits
aykevl created this revision.
aykevl added reviewers: dylanmckay, benshi001.
Herald added a subscriber: Jim.
Herald added a project: All.
aykevl requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This macro is defined in avr-gcc, and is very useful especially in assembly 
code to check whether particular instructions are supported. It is also the 
basis for other macros like `__AVR_HAVE_ELPM__`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137521

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/test/Preprocessor/avr-atmega328p.c
  clang/test/Preprocessor/avr-attiny104.c

Index: clang/test/Preprocessor/avr-attiny104.c
===
--- clang/test/Preprocessor/avr-attiny104.c
+++ clang/test/Preprocessor/avr-attiny104.c
@@ -2,6 +2,7 @@
 
 // CHECK: #define AVR 1
 // CHECK: #define __AVR 1
+// CHECK: #define __AVR_ARCH__ 100
 // CHECK: #define __AVR_ATtiny104__ 1
 // CHECK: #define __AVR__ 1
 // CHECK: #define __ELF__ 1
Index: clang/test/Preprocessor/avr-atmega328p.c
===
--- clang/test/Preprocessor/avr-atmega328p.c
+++ clang/test/Preprocessor/avr-atmega328p.c
@@ -2,6 +2,7 @@
 
 // CHECK: #define AVR 1
 // CHECK: #define __AVR 1
+// CHECK: #define __AVR_ARCH__ 5
 // CHECK: #define __AVR_ATmega328P__ 1
 // CHECK: #define __AVR__ 1
 // CHECK: #define __ELF__ 1
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -175,6 +175,7 @@
   std::string CPU;
   StringRef ABI;
   StringRef DefineName;
+  StringRef Arch;
   int NumFlashBanks;
 };
 
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -23,326 +23,326 @@
 struct LLVM_LIBRARY_VISIBILITY MCUInfo {
   const char *Name;
   const char *DefineName;
+  StringRef Arch; // The __AVR_ARCH__ value.
   const int NumFlashBanks; // Set to 0 for the devices do not support LPM/ELPM.
-  bool IsTiny; // Set to true for the devices belong to the avrtiny family.
 };
 
 // NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 static MCUInfo AVRMcus[] = {
-{"avr1", NULL, 0, false},
-{"at90s1200", "__AVR_AT90S1200__", 0, false},
-{"attiny11", "__AVR_ATtiny11__", 0, false},
-{"attiny12", "__AVR_ATtiny12__", 0, false},
-{"attiny15", "__AVR_ATtiny15__", 0, false},
-{"attiny28", "__AVR_ATtiny28__", 0, false},
-{"avr2", NULL, 1, false},
-{"at90s2313", "__AVR_AT90S2313__", 1, false},
-{"at90s2323", "__AVR_AT90S2323__", 1, false},
-{"at90s2333", "__AVR_AT90S2333__", 1, false},
-{"at90s2343", "__AVR_AT90S2343__", 1, false},
-{"attiny22", "__AVR_ATtiny22__", 1, false},
-{"attiny26", "__AVR_ATtiny26__", 1, false},
-{"at86rf401", "__AVR_AT86RF401__", 1, false},
-{"at90s4414", "__AVR_AT90S4414__", 1, false},
-{"at90s4433", "__AVR_AT90S4433__", 1, false},
-{"at90s4434", "__AVR_AT90S4434__", 1, false},
-{"at90s8515", "__AVR_AT90S8515__", 1, false},
-{"at90c8534", "__AVR_AT90c8534__", 1, false},
-{"at90s8535", "__AVR_AT90S8535__", 1, false},
-{"avr25", NULL, 1, false},
-{"ata5272", "__AVR_ATA5272__", 1, false},
-{"ata6616c", "__AVR_ATA6616c__", 1, false},
-{"attiny13", "__AVR_ATtiny13__", 1, false},
-{"attiny13a", "__AVR_ATtiny13A__", 1, false},
-{"attiny2313", "__AVR_ATtiny2313__", 1, false},
-{"attiny2313a", "__AVR_ATtiny2313A__", 1, false},
-{"attiny24", "__AVR_ATtiny24__", 1, false},
-{"attiny24a", "__AVR_ATtiny24A__", 1, false},
-{"attiny4313", "__AVR_ATtiny4313__", 1, false},
-{"attiny44", "__AVR_ATtiny44__", 1, false},
-{"attiny44a", "__AVR_ATtiny44A__", 1, false},
-{"attiny84", "__AVR_ATtiny84__", 1, false},
-{"attiny84a", "__AVR_ATtiny84A__", 1, false},
-{"attiny25", "__AVR_ATtiny25__", 1, false},
-{"attiny45", "__AVR_ATtiny45__", 1, false},
-{"attiny85", "__AVR_ATtiny85__", 1, false},
-{"attiny261", "__AVR_ATtiny261__", 1, false},
-{"attiny261a", "__AVR_ATtiny261A__", 1, false},
-{"attiny441", "__AVR_ATtiny441__", 1, false},
-{"attiny461", "__AVR_ATtiny461__", 1, false},
-{"attiny461a", "__AVR_ATtiny461A__", 1, false},
-{"attiny841", "__AVR_ATtiny841__", 1, false},
-{"attiny861", "__AVR_ATtiny861__", 1, false},
-{"attiny861a", "__AVR_ATtiny861A__", 1, false},
-{"attiny87", "__AVR_ATtiny87__", 1, false},
-{"attiny43u", "__AVR_ATtiny43U__", 1, false},
-{"attiny48", "__AVR_ATtiny48__", 1, false},
-{"attiny88", "__AVR_ATtiny88__", 1, false},
-{"attiny828", "__AVR_ATtiny828__", 1, false},
-{"avr3", NULL, 1, false},
-{"at43usb355", "__AVR_AT43USB355__", 1, false},
-{"at76c711", "__AVR_AT76C

[PATCH] D137517: [TargetSupport] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-11-06 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/CMakeLists.txt:18
 tablegen(LLVM RISCVGenSubtargetInfo.inc -gen-subtarget)
+tablegen(LLVM RISCVTargetParserDef.inc -gen-riscv-target-def)
 

Should not this only be in the CMakeLists for the TargetSupport library?



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:9
+//
+// This tablegen backend emits an assembly printer for the current target.
+// Note that this is currently fairly skeletal, but will grow over time.

This comment says assembly printer but that’s not what this file is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137511: [PPC] Undefine __ppc64__ to match GCC

2022-11-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 473543.
MaskRay edited the summary of this revision.
MaskRay added a comment.
Herald added a subscriber: steven.zhang.

update releasenote


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137511

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/Preprocessor/init-ppc64.c


Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -198,7 +198,6 @@
 // PPC64:#define __WCHAR_WIDTH__ 32
 // PPC64:#define __WINT_TYPE__ int
 // PPC64:#define __WINT_WIDTH__ 32
-// PPC64:#define __ppc64__ 1
 // PPC64:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-none-none 
-target-cpu pwr7 -fno-signed-char < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC64LE %s
@@ -403,7 +402,6 @@
 // PPC64LE:#define __WCHAR_WIDTH__ 32
 // PPC64LE:#define __WINT_TYPE__ int
 // PPC64LE:#define __WINT_WIDTH__ 32
-// PPC64LE:#define __ppc64__ 1
 // PPC64LE:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none 
-target-cpu 630 -fno-signed-char < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC630 %s
@@ -865,7 +863,6 @@
 // PPC64-AIX:#define __WINT_WIDTH__ 32
 // PPC64-AIX:#define __powerpc64__ 1
 // PPC64-AIX:#define __powerpc__ 1
-// PPC64-AIX:#define __ppc64__ 1
 // PPC64-AIX:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC64-LINUX %s
@@ -1064,7 +1061,6 @@
 // PPC64-LINUX:#define __WINT_WIDTH__ 32
 // PPC64-LINUX:#define __powerpc64__ 1
 // PPC64-LINUX:#define __powerpc__ 1
-// PPC64-LINUX:#define __ppc64__ 1
 // PPC64-LINUX:#define __ppc__ 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=powerpc64-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC64-ELFv1 %s
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -281,7 +281,6 @@
   if (PointerWidth == 64) {
 Builder.defineMacro("_ARCH_PPC64");
 Builder.defineMacro("__powerpc64__");
-Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
   } else if (getTriple().isOSAIX()) {
 // The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -176,6 +176,9 @@
   g(42);
 }
 
+- To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
+  ``__powerpc64__`` instead.
+
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed


Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -198,7 +198,6 @@
 // PPC64:#define __WCHAR_WIDTH__ 32
 // PPC64:#define __WINT_TYPE__ int
 // PPC64:#define __WINT_WIDTH__ 32
-// PPC64:#define __ppc64__ 1
 // PPC64:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-none-none -target-cpu pwr7 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC64LE %s
@@ -403,7 +402,6 @@
 // PPC64LE:#define __WCHAR_WIDTH__ 32
 // PPC64LE:#define __WINT_TYPE__ int
 // PPC64LE:#define __WINT_WIDTH__ 32
-// PPC64LE:#define __ppc64__ 1
 // PPC64LE:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu 630 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC630 %s
@@ -865,7 +863,6 @@
 // PPC64-AIX:#define __WINT_WIDTH__ 32
 // PPC64-AIX:#define __powerpc64__ 1
 // PPC64-AIX:#define __powerpc__ 1
-// PPC64-AIX:#define __ppc64__ 1
 // PPC64-AIX:#define __ppc__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-LINUX %s
@@ -1064,7 +1061,6 @@
 // PPC64-LINUX:#define __WINT_WIDTH__ 32
 // PPC64-LINUX:#define __powerpc64__ 1
 // PPC64-LINUX:#define __powerpc__ 1
-// PPC64-LINUX:#define __ppc64__ 1
 // PPC64-LINUX:#define __ppc__ 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -281,7 +281,6 @@
   if (PointerWidth == 64) {
   

[PATCH] D136146: [Clang][LoongArch] Handle -march/-m{single,double,soft}-float/-mfpu options

2022-11-06 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added a comment.

Sorry for the late reply.

Should we choose not to implement the `-mfpu=` option which is not mandatory?




Comment at: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp:31
+ options::OPT_msingle_float,
+ options::OPT_msoft_float)) {
+if (A->getOption().matches(options::OPT_mdouble_float))

MaskRay wrote:
> This is strange. Other architectures using -msoft-float makes it orthogonal 
> to -mdouble-float...
> 
> Instead of having -mdouble-float/-msingle-float, can you just use 
> -mfloat-abi=?
Sorry for the late reply.

Similar to @xry111's explanation below, `-m{double,single,soft}-float` are 
different from `-mfpu={64,32,0,none}`.

`-m{double,single,soft}-float` affect both codegen-ed instructions and the ABI 
while `-mfpu={64,32,0,none}` only affect the codegen-ed instructions.

That is to say:
* `-mdouble-float` implies `-mfpu=64` and `-mabi={lp64d,ilp32d}`;
* `-msingle-float` implies `-mfpu=32` and `-mabi={lp64f,ilp32f}`;
* `-msoft-float` implies `-mfpu={0,none}` and `-mabi={lp64s,ilp32s}`.

The `-mfpu={64,32,0,none}` clang option is like the `--mattr=+{d,f}` llc 
option. And the `-mabi=` clang option is like the `--target-abi=` llc option.

But I have to admit this introduce some complexity to clang implementation 
because we have to take care of the order these options appear on the command 
line.  The doc says:
> As a general rule, the effect of all LoongArch-specific compiler options that 
> are given for one compiler invocation should be as if they are processed in 
> the order they appear on the command line. The only exception to this rule is 
> -m*-float: their configuration of floating-point instruction set and calling 
> convention will not be changed by subsequent options other than -m*-float.




Comment at: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp:44
 
+  // Select abi based on -mfpu=xx.
+  if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {

xry111 wrote:
> MaskRay wrote:
> > It's better to stick with just one canonical spelling. Is there time to 
> > remove support for one set of options? When `-mfpu=64 -msoft-float` is 
> > specified, is a -Wunused-command-line-argument warning expected?
> According to the doc, the semantics of -mfpu=64 and -mdouble-float are not 
> exactly same.  `-mfpu=64 -mabi=lp64s` will allow the compiler to generate 
> 64-bit floating-point instructions but keep LP64S calling convention.  
> `-mdouble-float -mabi=lp64s` will be same as `-mdouble-float -mabi=lp64d` 
> (with a warning emitted, maybe).
The doc says that the implementation of `-mfpu` is not mandatory. So maybe we 
can choose not to implement it? But I'm not sure whether it has been used by 
any programs.

> -mdouble-float -mabi=lp64s will be same as -mdouble-float -mabi=lp64d (with a 
> warning emitted, maybe).
Yes, I think so. GCC indeed emits a warning. We also should emit one.



Comment at: clang/test/Driver/loongarch-march-error.c:1
+// RUN: not %clang --target=loongarch64 -march=loongarch -fsyntax-only %s 2>&1 
\
+// RUN:   | FileCheck --check-prefix=LOONGARCH %s

MaskRay wrote:
> The more common style is to place `|` in the end. The idea is that even 
> without `\`, after typing the first line in a shell, it will wait for the 
> second line.
OK. But seems both styles are used in the code base. -;)



Comment at: clang/test/Driver/loongarch-march.c:12
+// CC1-LOONGARCH64: "-target-feature" "+64bit"
+// CC1-LOONGARCH64-SAME: {{^}} "-target-feature" "+f"
+// CC1-LOONGARCH64-SAME: {{^}} "-target-feature" "+d"

MaskRay wrote:
> Check target-feature options on one line
OK.



Comment at: llvm/lib/Support/LoongArchTargetParser.cpp:46
+if ((A.Features & F.Kind) == F.Kind && F.Kind != FK_INVALID) {
+  Features.push_back(F.Name);
+}

MaskRay wrote:
> delete braces
OK.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136146

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


[PATCH] D137511: [PPC] Undefine __ppc64__ to match GCC

2022-11-06 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

As mentioned by @q66 above, this can't go in until usage of this macro in the 
Clang/LLVM codebase is fixed. Looks like the uses in 
`clang/lib/Headers/ppc_wrappers` and some of the uses in `libcxx` and 
`libunwind` must be fixed while others should probably also be fixed to avoid 
confusion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137511

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


[PATCH] D137511: [PPC] Undefine __ppc64__ to match GCC

2022-11-06 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai requested changes to this revision.
nemanjai added a comment.
This revision now requires changes to proceed.

I am going to block this since the uses of the macros in 
`clang/lib/Headers/ppc_wrappers` will likely cause build bot failures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137511

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


[PATCH] D137517: [TargetSupport] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-11-06 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 473545.
fpetrogalli added a comment.

I have made the dependency on `RISCVTargetSupportTableGen` explicit in the 
`RISCVCodeGen` target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Driver/CMakeLists.txt
  llvm/include/llvm/TargetSupport/RISCVTargetParser.def
  llvm/include/llvm/TargetSupport/TargetParser.h
  llvm/include/llvm/module.modulemap
  llvm/lib/Target/AArch64/AsmParser/CMakeLists.txt
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
  llvm/lib/Target/ARM/AsmParser/CMakeLists.txt
  llvm/lib/Target/ARM/CMakeLists.txt
  llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/RISCV/CMakeLists.txt
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/TargetSupport/CMakeLists.txt
  llvm/lib/TargetSupport/TargetParser.cpp
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/TargetSupport/CMakeLists.txt
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,49 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISCV CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getValueAsString("Enum") << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"}, "
+ << Record->getValueAsString("EnumFeatures") << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getValueAsString("Enum") << ", "
+ 

[PATCH] D137316: [Clang][LoongArch] Implement __builtin_loongarch_crc_w_d_w builtin and add diagnostics

2022-11-06 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsLoongArch.td:54
+def int_loongarch_crc_w_d_w : Intrinsic<[llvm_i32_ty],
+[llvm_i64_ty, llvm_i32_ty], []>;
 } // TargetPrefix = "loongarch"

Unnecessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137316

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


[PATCH] D136906: [Clang][LoongArch] Implement __builtin_loongarch_dbar builtin

2022-11-06 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsLoongArch.td:39
+
+def int_loongarch_dbar : Intrinsic<[], [llvm_i32_ty], []>;
 } // TargetPrefix = "loongarch"

Seems this arg is unnecessary because the defalut value is `[]`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136906

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


[clang] 2a67cc7 - [Sema] Use llvm::is_contained (NFC)

2022-11-06 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-11-06T20:04:53-08:00
New Revision: 2a67cc77e2c5227e81f758d22a5287af9ffe

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

LOG: [Sema] Use llvm::is_contained (NFC)

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 9906f636201c2..4f5d393209292 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -16585,9 +16585,8 @@ getListOfPossibleValues(OpenMPClauseKind K, unsigned 
First, unsigned Last,
   SmallString<256> Buffer;
   llvm::raw_svector_ostream Out(Buffer);
   unsigned Skipped = Exclude.size();
-  auto S = Exclude.begin(), E = Exclude.end();
   for (unsigned I = First; I < Last; ++I) {
-if (std::find(S, E, I) != E) {
+if (llvm::is_contained(Exclude, I)) {
   --Skipped;
   continue;
 }



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


[PATCH] D137491: [clang][NFC] Use c++17 style variable type traits

2022-11-06 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137491

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


[clang-tools-extra] a5f368a - [clang-tidy] Use structured bindings (NFC)

2022-11-06 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-11-06T20:48:55-08:00
New Revision: a5f368af6d9e469ad2a7f83ce5957776746fa0ca

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

LOG: [clang-tidy] Use structured bindings (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 67d8ccbd6cad4..f089abf69dce6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -519,9 +519,9 @@ int clangTidyMain(int argc, const char **argv) {
 std::vector
 RawOptions = OptionsProvider->getRawOptions(FilePath);
 for (const std::string &Check : EnabledChecks) {
-  for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
-if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
-  llvm::outs() << "'" << Check << "' is enabled in the " << It->second
+  for (const auto &[Opts, Source] : llvm::reverse(RawOptions)) {
+if (Opts.Checks && GlobList(*Opts.Checks).contains(Check)) {
+  llvm::outs() << "'" << Check << "' is enabled in the " << Source
<< ".\n";
   break;
 }
@@ -557,20 +557,16 @@ int clangTidyMain(int argc, const char **argv) {
 NamesAndOptions Valid =
 getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers);
 bool AnyInvalid = false;
-for (const std::pair &OptionWithSource :
- RawOptions) {
-  const ClangTidyOptions &Opts = OptionWithSource.first;
+for (const auto &[Opts, Source] : RawOptions) {
   if (Opts.Checks)
-AnyInvalid |=
-verifyChecks(Valid.Names, *Opts.Checks, OptionWithSource.second);
+AnyInvalid |= verifyChecks(Valid.Names, *Opts.Checks, Source);
 
   for (auto Key : Opts.CheckOptions.keys()) {
 if (Valid.Options.contains(Key))
   continue;
 AnyInvalid = true;
-auto &Output =
-llvm::WithColor::warning(llvm::errs(), OptionWithSource.second)
-<< "unknown check option '" << Key << '\'';
+auto &Output = llvm::WithColor::warning(llvm::errs(), Source)
+   << "unknown check option '" << Key << '\'';
 llvm::StringRef Closest = closest(Key, Valid.Options);
 if (!Closest.empty())
   Output << "; did you mean '" << Closest << '\'';



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


[clang] 9418634 - [clang] Use llvm::reverse (NFC)

2022-11-06 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-11-06T21:09:20-08:00
New Revision: 94186347a10b4bd945edaa21cfc025685e9490d7

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

LOG: [clang] Use llvm::reverse (NFC)

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7ebf6997e27ea..d455bede6babc 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7596,15 +7596,15 @@ static SourceRange nextPathEntryRange(const 
IndirectLocalPath &Path, unsigned I,
 }
 
 static bool pathOnlyInitializesGslPointer(IndirectLocalPath &Path) {
-  for (auto It = Path.rbegin(), End = Path.rend(); It != End; ++It) {
-if (It->Kind == IndirectLocalPathEntry::VarInit)
+  for (const auto &It : llvm::reverse(Path)) {
+if (It.Kind == IndirectLocalPathEntry::VarInit)
   continue;
-if (It->Kind == IndirectLocalPathEntry::AddressOf)
+if (It.Kind == IndirectLocalPathEntry::AddressOf)
   continue;
-if (It->Kind == IndirectLocalPathEntry::LifetimeBoundCall)
+if (It.Kind == IndirectLocalPathEntry::LifetimeBoundCall)
   continue;
-return It->Kind == IndirectLocalPathEntry::GslPointerInit ||
-   It->Kind == IndirectLocalPathEntry::GslReferenceInit;
+return It.Kind == IndirectLocalPathEntry::GslPointerInit ||
+   It.Kind == IndirectLocalPathEntry::GslReferenceInit;
   }
   return false;
 }

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8708c4d49f8cf..05e6c6ea7952b 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -8228,8 +8228,8 @@ namespace serialization {
 /// Add the given set of methods to the method list.
 static void addMethodsToPool(Sema &S, ArrayRef Methods,
  ObjCMethodList &List) {
-  for (auto I = Methods.rbegin(), E = Methods.rend(); I != E; ++I)
-S.addMethodToGlobalList(&List, *I);
+  for (ObjCMethodDecl *M : llvm::reverse(Methods))
+S.addMethodToGlobalList(&List, M);
 }
 
 void ASTReader::ReadMethodPool(Selector Sel) {



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


[PATCH] D137524: clang/AMDGPU: Emit atomicrmw for atomic_inc/dec builtins

2022-11-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: yaxunl, AMDGPU.
Herald added subscribers: kosarev, Anastasia, tpr, dstuttard, jvesely, kzhuravl.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

This makes the scope and ordering arguments actually do something.
Also add some new OpenCL tests since the existing HIP tests didn't
cover address spaces.


https://reviews.llvm.org/D137524

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Index: clang/test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -794,6 +794,26 @@
   __builtin_amdgcn_s_setreg(8193, val);
 }
 
+// CHECK-LABEL test_atomic_inc_dec(
+void test_atomic_inc_dec(local uint *lptr, global uint *gptr, uint val) {
+  uint res;
+
+  // CHECK: atomicrmw uinc_wrap i32 addrspace(3)* %lptr, i32 %val syncscope("workgroup") seq_cst, align 4
+  res = __builtin_amdgcn_atomic_inc32(lptr, val, __ATOMIC_SEQ_CST, "workgroup");
+
+  // CHECK: atomicrmw udec_wrap i32 addrspace(3)* %lptr, i32 %val syncscope("workgroup") seq_cst, align 4
+  res = __builtin_amdgcn_atomic_dec32(lptr, val, __ATOMIC_SEQ_CST, "workgroup");
+
+  // CHECK: atomicrmw uinc_wrap i32 addrspace(1)* %gptr, i32 %val syncscope("agent") seq_cst, align 4
+  res = __builtin_amdgcn_atomic_inc32(gptr, val, __ATOMIC_SEQ_CST, "agent");
+
+  // CHECK: atomicrmw udec_wrap i32 addrspace(1)* %gptr, i32 %val seq_cst, align 4
+  res = __builtin_amdgcn_atomic_dec32(gptr, val, __ATOMIC_SEQ_CST, "");
+
+  // CHECK: atomicrmw volatile udec_wrap i32 addrspace(1)* %gptr, i32 %val seq_cst, align 4
+  res = __builtin_amdgcn_atomic_dec32((volatile global uint*)gptr, val, __ATOMIC_SEQ_CST, "");
+}
+
 // CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
 // CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025}
 // CHECK-DAG: attributes #[[$NOUNWIND_READONLY:[0-9]+]] = { nofree nounwind memory(read) }
Index: clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
===
--- clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
+++ clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 %s -x hip -fcuda-is-device -emit-llvm -O0 -o - \
-// RUN:   -triple=amdgcn-amd-amdhsa  | opt -S | FileCheck %s
+// RUN:   -triple=amdgcn-amd-amdhsa | FileCheck %s
 
 // CHECK-LABEL: @_Z29test_non_volatile_parameter32Pj(
 // CHECK-NEXT:  entry:
@@ -13,12 +13,12 @@
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4
-// CHECK-NEXT:[[TMP3:%.*]] = call i32 @llvm.amdgcn.atomic.inc.i32.p0(ptr [[TMP0]], i32 [[TMP2]], i32 7, i32 2, i1 false)
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i32 [[TMP2]] syncscope("workgroup") seq_cst, align 4
 // CHECK-NEXT:store i32 [[TMP3]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
-// CHECK-NEXT:[[TMP7:%.*]] = call i32 @llvm.amdgcn.atomic.dec.i32.p0(ptr [[TMP4]], i32 [[TMP6]], i32 7, i32 2, i1 false)
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i32 [[TMP6]] syncscope("workgroup") seq_cst, align 4
 // CHECK-NEXT:store i32 [[TMP7]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:ret void
 //
@@ -39,12 +39,12 @@
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
-// CHECK-NEXT:[[TMP3:%.*]] = call i64 @llvm.amdgcn.atomic.inc.i64.p0(ptr [[TMP0]], i64 [[TMP2]], i32 7, i32 2, i1 false)
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i64 [[TMP2]] syncscope("workgroup") seq_cst, align 8
 // CHECK-NEXT:store i64 [[TMP3]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i64, ptr [[TMP5]], align 8
-// CHECK-NEXT:[[TMP7:%.*]] = call i64 @llvm.amdgcn.atomic.dec.i64.p0(ptr [[TMP4]], i64 [[TMP6]], i32 7, i32 2, i1 false)
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i64 [[TMP6]] syncscope("workgroup") seq_cst, align 8
 // CHECK-NEXT:store i64 [[TMP7]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:ret void
 

[PATCH] D137516: [TargetSupport] Move TargetParser API in a separate LLVM component.

2022-11-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I think this is fine, but think the name needs to be bikeshedded. "Target" and 
"Support" are already overloaded enough as it is. Is there anything else that 
would really ever go into this library?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137516

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


[clang] 27f5f33 - [clang][Interp][NFC] Remove an unused include

2022-11-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-11-07T06:34:22+01:00
New Revision: 27f5f33c81d9e253dd5caa31898baf9738a8b068

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

LOG: [clang][Interp][NFC] Remove an unused include

And an unnecessary private marker.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index 96e93dbfc48b0..feb809b69bf39 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -18,7 +18,6 @@
 
 #include "InterpStack.h"
 #include "clang/AST/APValue.h"
-#include "llvm/ADT/PointerIntPair.h"
 
 namespace clang {
 class ASTContext;
@@ -69,7 +68,6 @@ class Context final {
   /// Checks a result from the interpreter.
   bool Check(State &Parent, llvm::Expected &&R);
 
-private:
   /// Current compilation context.
   ASTContext &Ctx;
   /// Interpreter stack, shared across invocations.



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


[PATCH] D136906: [Clang][LoongArch] Implement __builtin_loongarch_dbar builtin

2022-11-06 Thread Gong LingQin via Phabricator via cfe-commits
gonglingqin added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsLoongArch.td:39
+
+def int_loongarch_dbar : Intrinsic<[], [llvm_i32_ty], []>;
 } // TargetPrefix = "loongarch"

SixWeining wrote:
> Seems this arg is unnecessary because the defalut value is `[]`.
Thanks, I will modify it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136906

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


[PATCH] D136906: [Clang][LoongArch] Implement __builtin_loongarch_dbar builtin

2022-11-06 Thread Gong LingQin via Phabricator via cfe-commits
gonglingqin updated this revision to Diff 473561.
gonglingqin added a comment.

Address @SixWeining's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136906

Files:
  clang/include/clang/Basic/BuiltinsLoongArch.def
  clang/include/clang/Basic/TargetBuiltins.h
  clang/include/clang/module.modulemap
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/larchintrin.h
  clang/test/CodeGen/LoongArch/intrinsic.c
  llvm/include/llvm/IR/IntrinsicsLoongArch.td
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
  llvm/test/CodeGen/LoongArch/intrinsic-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic.ll

Index: llvm/test/CodeGen/LoongArch/intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+
+declare void @llvm.loongarch.dbar(i32)
+
+define void @foo() nounwind {
+; CHECK-LABEL: foo:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:dbar 0
+; CHECK-NEXT:ret
+entry:
+  call void @llvm.loongarch.dbar(i32 0)
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-error.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic-error.ll
@@ -0,0 +1,10 @@
+; RUN: not llc --mtriple=loongarch64 --disable-verify < %s 2>&1 | FileCheck %s
+
+define void @foo(i32 %x) nounwind {
+; CHECK: argument to '__builtin_loongarch_dbar' must be a constant integer
+entry:
+  call void @llvm.loongarch.dbar(i32 %x)
+  ret void
+}
+
+declare void @llvm.loongarch.dbar(i32)
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -35,6 +35,8 @@
   SDTCisInt<0>, SDTCisSameAs<0, 1>, SDTCisInt<2>, SDTCisSameAs<2, 3>
 ]>;
 
+def SDT_LoongArchDBAR : SDTypeProfile<0, 1, [SDTCisVT<0, GRLenVT>]>;
+
 // TODO: Add LoongArch specific DAG Nodes
 // Target-independent nodes, but with target-specific formats.
 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_CallSeqStart,
@@ -63,6 +65,8 @@
 def loongarch_bitrev_w : SDNode<"LoongArchISD::BITREV_W", SDTUnaryOp>;
 def loongarch_clzw : SDNode<"LoongArchISD::CLZ_W", SDTIntBitCountUnaryOp>;
 def loongarch_ctzw : SDNode<"LoongArchISD::CTZ_W", SDTIntBitCountUnaryOp>;
+def loongarch_dbar : SDNode<"LoongArchISD::DBAR", SDT_LoongArchDBAR,
+ [SDNPHasChain, SDNPSideEffect]>;
 
 //===--===//
 // Operand and SDNode transformation definitions.
@@ -130,7 +134,8 @@
   let ParserMatchClass = UImmAsmOperand<14>;
 }
 
-def uimm15 : Operand {
+def uimm15 : Operand,
+ ImmLeaf (Imm);}]> {
   let ParserMatchClass = UImmAsmOperand<15>;
 }
 
@@ -1261,6 +1266,16 @@
   (PseudoAtomicLoadXor32 GPR:$incr, GPR:$addr)>;
 } // Predicates = [IsLA32]
 
+/// Intrinsics
+
+let Predicates = [IsLA32] in {
+def : Pat<(int_loongarch_dbar uimm15:$imm15), (DBAR uimm15:$imm15)>;
+} // Predicates = [IsLA32]
+
+let Predicates = [IsLA64] in {
+def : Pat<(loongarch_dbar uimm15:$imm15), (DBAR uimm15:$imm15)>;
+} // Predicates = [IsLA64]
+
 /// Other pseudo-instructions
 
 // Pessimistically assume the stack pointer will be clobbered
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.h
===
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -56,6 +56,9 @@
   REVB_2W,
   BITREV_4B,
   BITREV_W,
+
+  // Intrinsic operations
+  DBAR,
 };
 } // end namespace LoongArchISD
 
@@ -162,6 +165,7 @@
   SDValue lowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
+  SDValue lowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
 
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -87,6 +87,7 @@
 setOperationAction(ISD::ROTL, MVT::i32, Custom);
 setOperationAction(ISD::CTTZ, MVT::i32, Custom);
  

[clang] d4f884c - [clang][Interp] Add a test case for #58754

2022-11-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-11-07T07:25:37+01:00
New Revision: d4f884c550bec6b195eefb454636adc71449c041

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

LOG: [clang][Interp] Add a test case for #58754

This works in the new interpreter but is rejected by the current one.
Make sure it keeps working.

Added: 


Modified: 
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 036e7f914bbed..ec273f0713410 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -86,3 +86,27 @@ constexpr int f() {
 }
 static_assert(f());
 #endif
+
+/// Distinct literals have disctinct addresses.
+/// see https://github.com/llvm/llvm-project/issues/58754
+constexpr auto foo(const char *p) { return p; }
+constexpr auto p1 = "test1";
+constexpr auto p2 = "test2";
+
+constexpr bool b1 = foo(p1) == foo(p1);
+static_assert(b1);
+
+constexpr bool b2 = foo(p1) == foo(p2); // ref-error {{must be initialized by 
a constant expression}} \
+// ref-note {{declared here}}
+static_assert(!b2); // ref-error {{not an integral constant expression}} \
+// ref-note {{not a constant expression}}
+
+constexpr auto name1() { return "name1"; }
+constexpr auto name2() { return "name2"; }
+
+constexpr auto b3 = name1() == name1();
+static_assert(b3);
+constexpr auto b4 = name1() == name2(); // ref-error {{must be initialized by 
a constant expression}} \
+// ref-note {{declared here}}
+static_assert(!b4); // ref-error {{not an integral constant expression}} \
+// ref-note {{not a constant expression}}



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


[PATCH] D137316: [Clang][LoongArch] Implement __builtin_loongarch_crc_w_d_w builtin and add diagnostics

2022-11-06 Thread Gong LingQin via Phabricator via cfe-commits
gonglingqin added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsLoongArch.td:54
+def int_loongarch_crc_w_d_w : Intrinsic<[llvm_i32_ty],
+[llvm_i64_ty, llvm_i32_ty], []>;
 } // TargetPrefix = "loongarch"

SixWeining wrote:
> Unnecessary.
Thanks, I will modify it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137316

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


[PATCH] D137316: [Clang][LoongArch] Implement __builtin_loongarch_crc_w_d_w builtin and add diagnostics

2022-11-06 Thread Gong LingQin via Phabricator via cfe-commits
gonglingqin updated this revision to Diff 473564.
gonglingqin added a comment.

Address @SixWeining's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137316

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

Index: llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+
+declare i32 @llvm.loongarch.crc.w.d.w(i64, i32)
+
+define i32 @crc_w_d_w(i64 %a, i32 %b) nounwind {
+; CHECK-LABEL: crc_w_d_w:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:crc.w.d.w $a0, $a0, $a1
+; CHECK-NEXT:ret
+  %res = call i32 @llvm.loongarch.crc.w.d.w(i64 %a, i32 %b)
+  ret i32 %res
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
@@ -0,0 +1,10 @@
+; RUN: not llc --mtriple=loongarch32 --disable-verify < %s 2>&1 | FileCheck %s
+
+declare i32 @llvm.loongarch.crc.w.d.w(i64, i32)
+
+define i32 @crc_w_d_w(i64 %a, i32 %b) nounwind {
+; CHECK: llvm.loongarch.crc.w.d.w requires target: loongarch64
+entry:
+  %res = call i32 @llvm.loongarch.crc.w.d.w(i64 %a, i32 %b)
+  ret i32 %res
+}
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -55,6 +55,8 @@
 def loongarch_srl_w : SDNode<"LoongArchISD::SRL_W", SDT_LoongArchIntBinOpW>;
 def loongarch_rotr_w : SDNode<"LoongArchISD::ROTR_W", SDT_LoongArchIntBinOpW>;
 def loongarch_rotl_w : SDNode<"LoongArchISD::ROTL_W", SDT_LoongArchIntBinOpW>;
+def loongarch_crc_w_d_w
+: SDNode<"LoongArchISD::CRC_W_D_W", SDT_LoongArchIntBinOpW>;
 def loongarch_bstrins
 : SDNode<"LoongArchISD::BSTRINS", SDT_LoongArchBStrIns>;
 def loongarch_bstrpick
@@ -1307,6 +1309,9 @@
 
 let Predicates = [IsLA64] in {
 def : Pat<(loongarch_dbar uimm15:$imm15), (DBAR uimm15:$imm15)>;
+
+// CRC Check Instructions
+def : PatGprGpr;
 } // Predicates = [IsLA64]
 
 /// Other pseudo-instructions
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.h
===
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -59,6 +59,9 @@
 
   // Intrinsic operations
   DBAR,
+
+  // CRC check operations
+  CRC_W_D_W
 };
 } // end namespace LoongArchISD
 
@@ -177,6 +180,7 @@
   SDValue lowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
+  SDValue lowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -89,6 +89,7 @@
 setOperationAction(ISD::CTTZ, MVT::i32, Custom);
 setOperationAction(ISD::CTLZ, MVT::i32, Custom);
 setOperationAction(ISD::INTRINSIC_VOID, MVT::i32, Custom);
+setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i32, Custom);
 if (Subtarget.hasBasicF() && !Subtarget.hasBasicD())
   setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
 if (Subtarget.hasBasicF())
@@ -113,6 +114,7 @@
 setOperationAction(ISD::BITREVERSE, MVT::i64, Legal);
   } else {
 setOperationAction(ISD::BITREVERSE, MVT::i32, Legal);
+setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom);
   }
 
   static const ISD::CondCode FPCCToExpand[] = {
@@ -209,6 +211,8 @@
 return lowerGlobalTLSAddress(Op, DAG);
   case ISD::INTRINSIC_WO_CHAIN:
 return lowerINTRINSIC_WO_CHAIN(Op, DAG);
+

[clang] 10483ac - [clang][Interp] Support pointer arithmethic in binary operators

2022-11-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-11-07T07:47:19+01:00
New Revision: 10483ac743e69a6de684593565f586116b506b2e

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

LOG: [clang][Interp] Support pointer arithmethic in binary operators

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/Pointer.cpp
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 516f77cd3d60..a78758cf2e45 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -190,67 +190,120 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   // Typecheck the args.
   Optional LT = classify(LHS->getType());
   Optional RT = classify(RHS->getType());
-  if (!LT || !RT) {
+  Optional T = classify(BO->getType());
+  if (!LT || !RT || !T) {
 return this->bail(BO);
   }
 
-  if (Optional T = classify(BO->getType())) {
-if (!visit(LHS))
+  auto Discard = [this, T, BO](bool Result) {
+if (!Result)
   return false;
-if (!visit(RHS))
+return DiscardResult ? this->emitPop(*T, BO) : true;
+  };
+
+  // Pointer arithmetic special case.
+  if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
+if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))
+  return this->VisitPointerArithBinOp(BO);
+  }
+
+  if (!visit(LHS) || !visit(RHS))
+return false;
+
+  switch (BO->getOpcode()) {
+  case BO_EQ:
+return Discard(this->emitEQ(*LT, BO));
+  case BO_NE:
+return Discard(this->emitNE(*LT, BO));
+  case BO_LT:
+return Discard(this->emitLT(*LT, BO));
+  case BO_LE:
+return Discard(this->emitLE(*LT, BO));
+  case BO_GT:
+return Discard(this->emitGT(*LT, BO));
+  case BO_GE:
+return Discard(this->emitGE(*LT, BO));
+  case BO_Sub:
+return Discard(this->emitSub(*T, BO));
+  case BO_Add:
+return Discard(this->emitAdd(*T, BO));
+  case BO_Mul:
+return Discard(this->emitMul(*T, BO));
+  case BO_Rem:
+return Discard(this->emitRem(*T, BO));
+  case BO_Div:
+return Discard(this->emitDiv(*T, BO));
+  case BO_Assign:
+if (!this->emitStore(*T, BO))
   return false;
+return DiscardResult ? this->emitPopPtr(BO) : true;
+  case BO_And:
+return Discard(this->emitBitAnd(*T, BO));
+  case BO_Or:
+return Discard(this->emitBitOr(*T, BO));
+  case BO_Shl:
+return Discard(this->emitShl(*LT, *RT, BO));
+  case BO_Shr:
+return Discard(this->emitShr(*LT, *RT, BO));
+  case BO_Xor:
+return Discard(this->emitBitXor(*T, BO));
+  case BO_LAnd:
+  case BO_LOr:
+  default:
+return this->bail(BO);
+  }
 
-auto Discard = [this, T, BO](bool Result) {
-  if (!Result)
-return false;
-  return DiscardResult ? this->emitPop(*T, BO) : true;
-};
-
-switch (BO->getOpcode()) {
-case BO_EQ:
-  return Discard(this->emitEQ(*LT, BO));
-case BO_NE:
-  return Discard(this->emitNE(*LT, BO));
-case BO_LT:
-  return Discard(this->emitLT(*LT, BO));
-case BO_LE:
-  return Discard(this->emitLE(*LT, BO));
-case BO_GT:
-  return Discard(this->emitGT(*LT, BO));
-case BO_GE:
-  return Discard(this->emitGE(*LT, BO));
-case BO_Sub:
-  return Discard(this->emitSub(*T, BO));
-case BO_Add:
-  return Discard(this->emitAdd(*T, BO));
-case BO_Mul:
-  return Discard(this->emitMul(*T, BO));
-case BO_Rem:
-  return Discard(this->emitRem(*T, BO));
-case BO_Div:
-  return Discard(this->emitDiv(*T, BO));
-case BO_Assign:
-  if (!this->emitStore(*T, BO))
-return false;
-  return DiscardResult ? this->emitPopPtr(BO) : true;
-case BO_And:
-  return Discard(this->emitBitAnd(*T, BO));
-case BO_Or:
-  return Discard(this->emitBitOr(*T, BO));
-case BO_Shl:
-  return Discard(this->emitShl(*LT, *RT, BO));
-case BO_Shr:
-  return Discard(this->emitShr(*LT, *RT, BO));
-case BO_Xor:
-  return Discard(this->emitBitXor(*T, BO));
-case BO_LAnd:
-case BO_LOr:
-default:
-  return this->bail(BO);
-}
+  llvm_unreachable("Unhandled binary op");
+}
+
+/// Perform addition/subtraction of a pointer and an integer or
+/// subtraction of two pointers.
+template 
+bool ByteCodeExprGen::VisitPointerArithBinOp(const BinaryOperator *E) 
{
+  BinaryOperatorKind Op = E->getOpcode();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+
+  if ((Op != BO_Add && Op != BO_Sub) ||
+  (!LHS->getType()->isPointerType() && !RHS->getType()->isPointerType()))

[PATCH] D135858: [clang][Interp] Support pointer arithmetic in binary operators

2022-11-06 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG10483ac743e6: [clang][Interp] Support pointer arithmethic in 
binary operators (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135858

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/test/AST/Interp/arrays.cpp

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -37,6 +37,60 @@
 static_assert(getElement(1) == 4, "");
 static_assert(getElement(5) == 36, "");
 
+constexpr int data[] = {5, 4, 3, 2, 1};
+constexpr int getElement(const int *Arr, int index) {
+  return *(Arr + index);
+}
+
+static_assert(getElement(data, 1) == 4, "");
+static_assert(getElement(data, 4) == 1, "");
+
+constexpr int getElementFromEnd(const int *Arr, int size, int index) {
+  return *(Arr + size - index - 1);
+}
+static_assert(getElementFromEnd(data, 5, 0) == 1, "");
+static_assert(getElementFromEnd(data, 5, 4) == 5, "");
+
+
+constexpr static int arr[2] = {1,2};
+constexpr static int arr2[2] = {3,4};
+constexpr int *p1 = nullptr;
+constexpr int *p2 = p1 + 1; // expected-error {{must be initialized by a constant expression}} \
+// expected-note {{cannot perform pointer arithmetic on null pointer}} \
+// ref-error {{must be initialized by a constant expression}} \
+// ref-note {{cannot perform pointer arithmetic on null pointer}}
+constexpr int *p3 = p1 + 0;
+constexpr int *p4 = p1 - 0;
+constexpr int *p5 =  0 + p1;
+constexpr int *p6 =  0 - p1; // expected-error {{invalid operands to binary expression}} \
+ // ref-error {{invalid operands to binary expression}}
+
+constexpr int const * ap1 = &arr[0];
+constexpr int const * ap2 = ap1 + 3; // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{cannot refer to element 3 of array of 2}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{cannot refer to element 3 of array of 2}}
+
+constexpr auto ap3 = arr - 1; // expected-error {{must be initialized by a constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{must be initialized by a constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+constexpr int k1 = &arr[1] - &arr[0];
+static_assert(k1 == 1, "");
+static_assert((&arr[0] - &arr[1]) == -1, "");
+
+constexpr int k2 = &arr2[1] - &arr[0]; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+
+static_assert((arr + 0) == arr, "");
+static_assert(&arr[0] == arr, "");
+static_assert(*(&arr[0]) == 1, "");
+static_assert(*(&arr[1]) == 2, "");
+
+constexpr const int *OOB = (arr + 3) - 3; // expected-error {{must be initialized by a constant expression}} \
+  // expected-note {{cannot refer to element 3 of array of 2}} \
+  // ref-error {{must be initialized by a constant expression}} \
+  // ref-note {{cannot refer to element 3 of array of 2}}
 
 template
 constexpr T getElementOf(T* array, int i) {
@@ -52,7 +106,6 @@
 static_assert(getElementOfArray(foo[2], 3) == &m, "");
 
 
-constexpr int data[] = {5, 4, 3, 2, 1};
 static_assert(data[0] == 4, ""); // expected-error{{failed}} \
  // expected-note{{5 == 4}} \
  // ref-error{{failed}} \
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -202,5 +202,5 @@
 }
 
 bool Pointer::hasSameArray(const Pointer &A, const Pointer &B) {
-  return A.Base == B.Base && A.getFieldDesc()->IsArray;
+  return hasSameBase(A, B) && A.Base == B.Base && A.getFieldDesc()->IsArray;
 }
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -390,6 +390,12 @@
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
+// Pointer, Pointer] - [Integral]
+def SubPtr : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 //===

[clang] 7c0a2d9 - [clang][Interp][NFC] Use StorePop for assignments with DiscardResult

2022-11-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-11-07T07:56:25+01:00
New Revision: 7c0a2d9cda996a04c9eb55244a0ebf57545de849

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

LOG: [clang][Interp][NFC] Use StorePop for assignments with DiscardResult

If we don't need the result anyway, use StorePop, instead of a Store+Pop
combination. That way we save one instruction and not using the result
is the common case anyway.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a78758cf2e45..24b5160eafbc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -234,9 +234,9 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   case BO_Div:
 return Discard(this->emitDiv(*T, BO));
   case BO_Assign:
-if (!this->emitStore(*T, BO))
-  return false;
-return DiscardResult ? this->emitPopPtr(BO) : true;
+if (DiscardResult)
+  return this->emitStorePop(*T, BO);
+return this->emitStore(*T, BO);
   case BO_And:
 return Discard(this->emitBitAnd(*T, BO));
   case BO_Or:



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


[clang] 9a3b969 - [clang][Interp][NFC] Make InitField() not pop the pointer

2022-11-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-11-07T08:30:43+01:00
New Revision: 9a3b969d1faa77d4c629ddb797d317579fbe0555

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

LOG: [clang][Interp][NFC] Make InitField() not pop the pointer

This was confusing. InitElem peeks a pointer, while InitElemPop will
pop the pointer. However, for fields, InitField would pop the pointer
and no InitFieldPop exists. At least make InitField and InitElem behave
the same.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 24b5160eafbc..5362e9cb1ab0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -936,6 +936,9 @@ bool ByteCodeExprGen::visitRecordInitializer(const 
Expr *Initializer) {
 
 if (!this->emitInitField(*T, FieldToInit->Offset, Initializer))
   return false;
+
+if (!this->emitPopPtr(Initializer))
+  return false;
   } else {
 // Non-primitive case. Get a pointer to the field-to-initialize
 // on the stack and recurse into visitInitializer().

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index bbe4d04c8974..81243d846bc1 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -114,6 +114,9 @@ bool ByteCodeStmtGen::visitFunc(const FunctionDecl 
*F) {
 
   if (!this->emitInitField(*T, F->Offset, InitExpr))
 return false;
+
+  if (!this->emitPopPtr(InitExpr))
+return false;
 } else {
   // Non-primitive case. Get a pointer to the field-to-initialize
   // on the stack and call visitInitialzer() for it.

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c032d0985621..b7666745efd4 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -735,12 +735,12 @@ bool InitThisFieldActive(InterpState &S, CodePtr OpPC, 
uint32_t I) {
 }
 
 /// 1) Pops the value from the stack
-/// 2) Pops a pointer from the stack
+/// 2) Peeks a pointer from the stack
 /// 3) Pushes the value to field I of the pointer on the stack
 template ::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop();
-  const Pointer &Field = S.Stk.pop().atField(I);
+  const Pointer &Field = S.Stk.peek().atField(I);
   Field.deref() = Value;
   Field.activate();
   Field.initialize();



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


[clang] 70de684 - [clang-format] Handle object instansiation in if-statements

2022-11-06 Thread Tobias Hieta via cfe-commits

Author: Tobias Hieta
Date: 2022-11-07T08:34:57+01:00
New Revision: 70de684d44135b4025d92b2b36ad387cf5ab8b5a

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

LOG: [clang-format] Handle object instansiation in if-statements

Before this patch code like this:

```
if (Class* obj{getObject()}) { }
```

would be mis-formated since the * would be annotated as a
binaryoperator.

This patch changes the * to become a PointerOrReference instead
and fixes the formatting issues.

Reviewed By: HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 3d76cc171b0dc..dbfe88c531322 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -362,7 +362,8 @@ class AnnotatingParser {
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
   Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
+  CurrentToken->is(tok::identifier) &&
+  !Next->isOneOf(tok::equal, tok::l_brace)) {
 Prev->setType(TT_BinaryOperator);
 LookForDecls = false;
   }
@@ -2387,6 +2388,12 @@ class AnnotatingParser {
   return TT_PointerOrReference;
 }
 
+// if (Class* obj { function() })
+if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
+NextToken->Next && NextToken->Next->is(tok::l_brace)) {
+  return TT_PointerOrReference;
+}
+
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index fa95f6845f077..65ecb12c46cd7 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -145,6 +145,18 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
   EXPECT_TOKEN(Tokens[7], tok::star, TT_UnaryOperator);
   EXPECT_TOKEN(Tokens[12], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("if (Foo * Bar / Test)");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
+
+  Tokens = annotate("if (Class* obj {getObj()})");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("if (Foo* Bar = getObj())");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {



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


[PATCH] D137327: [clang-format] Handle object instansiation in if-statements

2022-11-06 Thread Tobias Hieta 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 rG70de684d4413: [clang-format] Handle object instansiation in 
if-statements (authored by thieta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137327

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -145,6 +145,18 @@
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
   EXPECT_TOKEN(Tokens[7], tok::star, TT_UnaryOperator);
   EXPECT_TOKEN(Tokens[12], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("if (Foo * Bar / Test)");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
+
+  Tokens = annotate("if (Class* obj {getObj()})");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("if (Foo* Bar = getObj())");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -362,7 +362,8 @@
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
   Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
+  CurrentToken->is(tok::identifier) &&
+  !Next->isOneOf(tok::equal, tok::l_brace)) {
 Prev->setType(TT_BinaryOperator);
 LookForDecls = false;
   }
@@ -2387,6 +2388,12 @@
   return TT_PointerOrReference;
 }
 
+// if (Class* obj { function() })
+if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
+NextToken->Next && NextToken->Next->is(tok::l_brace)) {
+  return TT_PointerOrReference;
+}
+
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -145,6 +145,18 @@
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionTypeLParen);
   EXPECT_TOKEN(Tokens[7], tok::star, TT_UnaryOperator);
   EXPECT_TOKEN(Tokens[12], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("if (Foo * Bar / Test)");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
+
+  Tokens = annotate("if (Class* obj {getObj()})");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("if (Foo* Bar = getObj())");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -362,7 +362,8 @@
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
   Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
+  CurrentToken->is(tok::identifier) &&
+  !Next->isOneOf(tok::equal, tok::l_brace)) {
 Prev->setType(TT_BinaryOperator);
 LookForDecls = false;
   }
@@ -2387,6 +2388,12 @@
   return TT_PointerOrReference;
 }
 
+// if (Class* obj { function() })
+if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
+NextToken->Next && NextToken->Next->is(tok::l_brace)) {
+  return TT_PointerOrReference;
+}
+
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 05a113e - [clang][Interp][NFC] Handle discarded ArraySubscriptExprs

2022-11-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-11-07T08:37:43+01:00
New Revision: 05a113e18852ab54f22516e9ec1b6aa39adc5b33

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

LOG: [clang][Interp][NFC] Handle discarded ArraySubscriptExprs

This is not exactly a common case, so just pop the pointer at the end if
necessary.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5362e9cb1ab0..f3f4ae774886 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -319,26 +319,26 @@ bool ByteCodeExprGen::VisitArraySubscriptExpr(
 const ArraySubscriptExpr *E) {
   const Expr *Base = E->getBase();
   const Expr *Index = E->getIdx();
+  PrimType IndexT = classifyPrim(Index->getType());
 
   // Take pointer of LHS, add offset from RHS, narrow result.
   // What's left on the stack after this is a pointer.
-  if (Optional IndexT = classify(Index->getType())) {
-if (!this->visit(Base))
-  return false;
+  if (!this->visit(Base))
+return false;
 
-if (!this->visit(Index))
-  return false;
+  if (!this->visit(Index))
+return false;
 
-if (!this->emitAddOffset(*IndexT, E))
-  return false;
+  if (!this->emitAddOffset(IndexT, E))
+return false;
 
-if (!this->emitNarrowPtr(E))
-  return false;
+  if (!this->emitNarrowPtr(E))
+return false;
 
-return true;
-  }
+  if (DiscardResult)
+return this->emitPopPtr(E);
 
-  return false;
+  return true;
 }
 
 template 



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


[PATCH] D137524: clang/AMDGPU: Emit atomicrmw for atomic_inc/dec builtins

2022-11-06 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

I don't recognize atomicrmw udec_wrap and can't find it in 
https://llvm.org/docs/LangRef.html#atomicrmw-instruction. I do vaguely recall 
the semantics of these builtins (well, the instructions they target) being 
surprising, Do you know where the uinc_wrao etc were introduced?


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

https://reviews.llvm.org/D137524

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Support to query separate file for P1689

2022-11-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: Bigcheese, jansvoboda11, dblaikie, iains, 
ben.boeckel.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This functionality is required by CMake since the current infrastructure is in 
this state and it is more convenient if there is source files generated in the 
fly. And this is easy to be supported.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137534

Files:
  clang/test/ClangScanDeps/P1689.cppm
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -175,6 +175,12 @@
 llvm::cl::desc("the module of which the dependencies are to be computed"),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt TargetedFileName(
+  "targeted-file-name", llvm::cl::Optional,
+  llvm::cl::desc("Only supported for P1689, the targeted file name of which the dependencies are to be computed."),
+  llvm::cl::cat(DependencyScannerCategory)
+);
+
 llvm::cl::list ModuleDepTargets(
 "dependency-target",
 llvm::cl::desc("The names of dependency targets for the dependency file"),
@@ -617,7 +623,9 @@
 WorkerTools.push_back(std::make_unique(Service));
 
   std::vector Inputs =
-  AdjustingCompilations->getAllCompileCommands();
+  TargetedFileName.empty() ?
+  AdjustingCompilations->getAllCompileCommands() :
+  AdjustingCompilations->getCompileCommands(TargetedFileName);
 
   std::atomic HadErrors(false);
   FullDeps FD;
Index: clang/test/ClangScanDeps/P1689.cppm
===
--- clang/test/ClangScanDeps/P1689.cppm
+++ clang/test/ClangScanDeps/P1689.cppm
@@ -5,6 +5,18 @@
 // RUN: sed "s|DIR|%/t|g" %t/P1689.json.in > %t/P1689.json
 // RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t
 // RUN: clang-scan-deps --mode=preprocess-dependency-directives -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t
+//
+// Check the seperated dependency format.
+// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 -targeted-file-name=%t/M.cppm \
+// RUN:   | FileCheck %t/M.cppm -DPREFIX=%/t
+// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 -targeted-file-name=%t/Impl.cpp \
+// RUN:   | FileCheck %t/Impl.cpp -DPREFIX=%/t
+// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 -targeted-file-name=%t/impl_part.cppm \
+// RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
+// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 -targeted-file-name=%t/interface_part.cppm \
+// RUN:   | FileCheck %t/interface_part.cppm -DPREFIX=%/t
+// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 -targeted-file-name=%t/User.cpp \
+// RUN:   | FileCheck %t/User.cpp -DPREFIX=%/t
 
 //--- P1689.json.in
 [
@@ -47,6 +59,31 @@
 import :impl_part;
 export void Hello();
 
+// CHECK: {
+// CHECK-NEXT:   "revision": 0,
+// CHECK-NEXT:   "rules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "primary-output": "[[PREFIX]]/M.o",
+// CHECK-NEXT:   "provides": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "is-interface": true,
+// CHECK-NEXT:   "logical-name": "M",
+// CHECK-NEXT:   "source-path": "[[PREFIX]]/M.cppm"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "requires": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "logical-name": "M:interface_part"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "logical-name": "M:impl_part"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "version": 1
+// CHECK-NEXT: }
+
 //--- Impl.cpp
 module;
 #include "header.mock"
@@ -55,6 +92,21 @@
 std::cout << "Hello ";
 }
 
+// CHECK: {
+// CHECK-NEXT:   "revision": 0,
+// CHECK-NEXT:   "rules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "primary-output": "[[PREFIX]]/Impl.o",
+// CHECK-NEXT:   "requires": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "logical-name": "M"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "version": 1
+// CHECK-NEXT: }
+
 //--- impl_part.cppm
 module;
 #include "header.mock"
@@ -66,10 +118,49 @@
 std::cout << W << std::endl;
 }
 
+// CHECK: {
+// CHECK-NEXT:   "revision": 0,
+// CHECK-NEXT:   "rules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "primary-output": "[[PREFIX]]/impl_part.o",
+// CHECK-NEXT:   "provides": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "is-interface": false,
+// CHECK-NEXT:   "logical-name": "M:impl_part",
+//