[PATCH] D144620: [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR

2023-02-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/AVR.cpp:549
+// '-mrelax' is default unless '-mno-relax' is specified.
+if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
+  CmdArgs.push_back("--relax");

If the linker defaults to `--no-relax`, we don't need 
`CmdArgs.push_back("--no-relax");`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144620

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


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 499754.
cor3ntin added a comment.

Address Aaron's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1366,7 +1366,7 @@
 
   Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3";>P2036R3
-  No
+  Clang 17
 
 
   https://wg21.link/P2579R0";>P2579R0
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -95,7 +95,7 @@
 #ifdef AVOID
   auto l4 = [var = param] (int param) { ; }; // no warning
 #else
-  auto l4 = [var = param] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+  auto l4 = [var = param](int param) { ; }; // expected-warning 2{{declaration shadows a local variable}}
 #endif
 
   // Make sure that inner lambdas work as well.
Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -665,3 +665,27 @@
 // expected-note@-2 2 {{default capture by}}
 }
 };
+
+namespace GH60518 {
+// Lambdas should not try to capture
+// function parameters that are used in enable_if
+struct StringLiteral {
+template 
+StringLiteral(const char (&array)[N])
+__attribute__((enable_if(__builtin_strlen(array) == 2,
+  "invalid string literal")));
+};
+
+namespace cpp_attribute {
+struct StringLiteral {
+template 
+StringLiteral(const char (&array)[N]) [[clang::annotate_type("test", array)]];
+};
+}
+
+void Func1() {
+  [[maybe_unused]] auto y = [&](decltype(StringLiteral("xx"))) {};
+  [[maybe_unused]] auto z = [&](decltype(cpp_attribute::StringLiteral("xx"))) {};
+}
+
+}
Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -0,0 +1,243 @@
+// RUN: %clang_cc1 -std=c++2b -verify -fsyntax-only %s
+
+template 
+constexpr bool is_same = false;
+
+template 
+constexpr bool is_same = true;
+
+void f() {
+
+  int y;
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  auto ref = [&x = y](
+ decltype([&](decltype(x)) { return 0; }) y) {
+return x;
+  };
+}
+
+void test_noexcept() {
+
+  int y;
+
+  static_assert(noexcept([x = 1] noexcept(is_same) {}()));
+  static_assert(noexcept([x = 1] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([y] noexcept(is_same) {}()));
+  static_assert(noexcept([y] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([=] noexcept(is_same) {}()));
+  static_assert(noexcept([=] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([&] noexcept(is_same) {}()));
+  static_assert(noexcept([&] mutable noexcept(is_same) {}()));
+}
+
+void test_requires() {
+
+  int x;
+
+  [x = 1]() requires is_same {}
+  ();
+  [x = 1]() mutable requires is_same {}
+  ();
+  [x]() requires is_same {}
+  ();
+  [x]() mutable requires is_same {}
+  ();
+  [=]() requires is_same {}
+  ();
+  [=]() mutable requires is_same {}
+  ();
+  [&]() requires is_same {}
+  ();
+  [&]() mutable requires is_same {}
+  ();
+  [&x]() requires is_same {}
+  ();
+  [&x]() mutable requires is_same {}
+  ();
+
+  [x = 1]() requires is_same {} ();
+  [x = 1]() mutable requires is_same {} ();
+}
+
+void err() {
+  int y, z;
+  (void)[x = 1]
+  requires(is_same) {};
+
+  (void)[x = 1]{};
+
+  (void)[=]{};
+
+  (

[PATCH] D144179: [Clang] Added functionality to provide config file name via env variable

2023-02-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

This looks like introducing a footgun (when something behaves differently from 
an upstream Clang, it would be difficult for toolchain maintainers to know why).
Why can't your user specify `CLANG_CONFIG_FILE_SYSTEM_DIR`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144179

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


[PATCH] D144622: [clang[[ASTImporter] Import TemplateName correctly

2023-02-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a fix for a problem when multiple template
specializations are created by ASTImporter, with similar template arguments.
I think with same arguments ony a single specialization should exist, the
problem needs more investigation, but the TemplateName objects
(where a pointer to the specialization is used as identifier and key in a map)
should have all the same pointer to the same specialization, otherwise they
may compare as different even if the template that they refer to is the same.
In the wrong case some redundant AST nodes may be created by ASTImporter.
When these appear in type alias declaration the assertion
`assert(hasSameType(Decl->getUnderlyingType(), Underlying))` 
(ASTContext.cpp:4786)
may fail.

This is a work-in-progress fix, tests are not added yet.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144622

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -9376,7 +9376,7 @@
   switch (From.getKind()) {
   case TemplateName::Template:
 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
-  return TemplateName(cast(*ToTemplateOrErr));
+  return 
TemplateName(cast((*ToTemplateOrErr)->getCanonicalDecl()));
 else
   return ToTemplateOrErr.takeError();
 


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -9376,7 +9376,7 @@
   switch (From.getKind()) {
   case TemplateName::Template:
 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
-  return TemplateName(cast(*ToTemplateOrErr));
+  return TemplateName(cast((*ToTemplateOrErr)->getCanonicalDecl()));
 else
   return ToTemplateOrErr.takeError();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144579: [include-cleaner] Check macros against stdlib database

2023-02-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, good catch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144579

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


[PATCH] D144620: [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR

2023-02-23 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 499757.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144620

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Driver/avr-ld.c
  clang/test/Driver/avr-toolchain.c


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -67,7 +67,7 @@
 // LLD-NOT: "-mavr5"
 
 // RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree 
-mmcu=atmega328 %s -T avr.lds 2>&1 | FileCheck --check-prefix=LDS0 %s
-// LDS0: "-T" "avr.lds" "-mavr5"
+// LDS0: "-T" "avr.lds" "--relax" "-mavr5"
 
 // RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree 
-mmcu=atmega328 %s -fuse-ld=%S/Inputs/basic_avr_tree/usr/bin/ld.lld -T avr.lds 
2>&1 | FileCheck --check-prefix=LDS1 %s
 // LDS1: "-T" "avr.lds"
Index: clang/test/Driver/avr-ld.c
===
--- clang/test/Driver/avr-ld.c
+++ clang/test/Driver/avr-ld.c
@@ -1,44 +1,45 @@
 // RUN: %clang -### --target=avr -mmcu=at90s2313 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKA %s
-// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "-mavr2"
+// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "--relax" "-mavr2"
 
-// RUN: %clang -### --target=avr -mmcu=at90s8515 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKB %s
-// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "-mavr2"
+// RUN: %clang -### --target=avr -mmcu=at90s8515 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s -mrelax 2>&1 | FileCheck -check-prefix LINKB %s
+// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "--relax" "-mavr2"
 
-// RUN: %clang -### --target=avr -mmcu=attiny13 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKC %s
+// RUN: %clang -### --target=avr -mmcu=attiny13 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s -mno-relax 2>&1 | FileCheck -check-prefix LINKC %s
 // LINKC: {{".*ld.*"}} {{.*}} {{"-L.*avr25/tiny-stack"}} {{.*}} 
"-Tdata=0x800060" "--start-group" {{.*}} "-lattiny13" {{.*}} "--end-group" 
"-mavr25"
+// LINLC-NOT: "--relax"
 
 // RUN: %clang -### --target=avr -mmcu=attiny44 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKD %s
-// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "-mavr25"
+// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "--relax" "-mavr25"
 
 // RUN: %clang -### --target=avr -mmcu=atmega103 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKE %s
-// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "-mavr31"
+// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "--relax" "-mavr31"
 
 // RUN: %clang -### --target=avr -mmcu=atmega8u2 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKF %s
-// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "-mavr35"
+// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "--relax" "-mavr35"
 
 // RUN: %clang -### --target=avr -mmcu=atmega48pa --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKG %s
-// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" {{.*}} "--end-group" "-mavr4"
+// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" {{.*}} "--end-group" "--relax" "-mavr4"
 
 // RUN: %clang -### --target=avr -mmcu=atmega328 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKH %s
-// LINKH: {{".*ld.*"}} {{.*}} {{"-L.*avr5"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega328" {{.*}} "--end-group" "-mavr5"
+// LINKH: {{".*ld.*"}} {{.*}} {{"-L.*avr5"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega328" {{.*}} "--end-group" "--relax" "-mavr5"
 
 // RUN: %clang -### --target=avr -mmcu=atmega1281 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKI %s
-// LINKI: {{".*ld.*"}} {{.*}} {{"-L.*avr51"}} {{.*}} "-Tdata=0

[clang-tools-extra] 961e32c - [include-cleaner] Check macros against stdlib database

2023-02-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-02-23T09:34:37+01:00
New Revision: 961e32c587cb2289e8c2873848b660a153ed5618

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

LOG: [include-cleaner] Check macros against stdlib database

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp 
b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
index 60b18c2fe94fb..78e783a62eb27 100644
--- a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -53,6 +54,12 @@ std::vector> locateDecl(const Decl 
&D) {
   return Result;
 }
 
+std::vector> locateMacro(const Macro &M) {
+  // FIXME: Should we also provide physical locations?
+  if (auto SS = tooling::stdlib::Symbol::named("", M.Name->getName()))
+return {{*SS, Hints::CompleteSymbol}};
+  return {{M.Definition, Hints::CompleteSymbol}};
+}
 } // namespace
 
 std::vector> locateSymbol(const Symbol &S) {
@@ -60,7 +67,7 @@ std::vector> locateSymbol(const Symbol 
&S) {
   case Symbol::Declaration:
 return locateDecl(S.declaration());
   case Symbol::Macro:
-return {{S.macro().Definition, Hints::CompleteSymbol}};
+return locateMacro(S.macro());
   }
   llvm_unreachable("Unknown Symbol::Kind enum");
 }

diff  --git a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
index 16a185269b5d9..9961b013b24d8 100644
--- a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -122,9 +122,17 @@ TEST(LocateSymbol, Decl) {
 }
 
 TEST(LocateSymbol, Stdlib) {
-  LocateExample Test("namespace std { struct vector; }");
-  EXPECT_THAT(locateSymbol(Test.findDecl("vector")),
-  ElementsAre(*tooling::stdlib::Symbol::named("std::", "vector")));
+  {
+LocateExample Test("namespace std { struct vector; }");
+EXPECT_THAT(
+locateSymbol(Test.findDecl("vector")),
+ElementsAre(*tooling::stdlib::Symbol::named("std::", "vector")));
+  }
+  {
+LocateExample Test("#define assert(x)\nvoid foo() { assert(true); }");
+EXPECT_THAT(locateSymbol(Test.findMacro("assert")),
+ElementsAre(*tooling::stdlib::Symbol::named("", "assert")));
+  }
 }
 
 TEST(LocateSymbol, Macros) {



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


[PATCH] D144579: [include-cleaner] Check macros against stdlib database

2023-02-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG961e32c587cb: [include-cleaner] Check macros against stdlib 
database (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144579

Files:
  clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
  clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -122,9 +122,17 @@
 }
 
 TEST(LocateSymbol, Stdlib) {
-  LocateExample Test("namespace std { struct vector; }");
-  EXPECT_THAT(locateSymbol(Test.findDecl("vector")),
-  ElementsAre(*tooling::stdlib::Symbol::named("std::", "vector")));
+  {
+LocateExample Test("namespace std { struct vector; }");
+EXPECT_THAT(
+locateSymbol(Test.findDecl("vector")),
+ElementsAre(*tooling::stdlib::Symbol::named("std::", "vector")));
+  }
+  {
+LocateExample Test("#define assert(x)\nvoid foo() { assert(true); }");
+EXPECT_THAT(locateSymbol(Test.findMacro("assert")),
+ElementsAre(*tooling::stdlib::Symbol::named("", "assert")));
+  }
 }
 
 TEST(LocateSymbol, Macros) {
Index: clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
===
--- clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -53,6 +54,12 @@
   return Result;
 }
 
+std::vector> locateMacro(const Macro &M) {
+  // FIXME: Should we also provide physical locations?
+  if (auto SS = tooling::stdlib::Symbol::named("", M.Name->getName()))
+return {{*SS, Hints::CompleteSymbol}};
+  return {{M.Definition, Hints::CompleteSymbol}};
+}
 } // namespace
 
 std::vector> locateSymbol(const Symbol &S) {
@@ -60,7 +67,7 @@
   case Symbol::Declaration:
 return locateDecl(S.declaration());
   case Symbol::Macro:
-return {{S.macro().Definition, Hints::CompleteSymbol}};
+return locateMacro(S.macro());
   }
   llvm_unreachable("Unknown Symbol::Kind enum");
 }


Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -122,9 +122,17 @@
 }
 
 TEST(LocateSymbol, Stdlib) {
-  LocateExample Test("namespace std { struct vector; }");
-  EXPECT_THAT(locateSymbol(Test.findDecl("vector")),
-  ElementsAre(*tooling::stdlib::Symbol::named("std::", "vector")));
+  {
+LocateExample Test("namespace std { struct vector; }");
+EXPECT_THAT(
+locateSymbol(Test.findDecl("vector")),
+ElementsAre(*tooling::stdlib::Symbol::named("std::", "vector")));
+  }
+  {
+LocateExample Test("#define assert(x)\nvoid foo() { assert(true); }");
+EXPECT_THAT(locateSymbol(Test.findMacro("assert")),
+ElementsAre(*tooling::stdlib::Symbol::named("", "assert")));
+  }
 }
 
 TEST(LocateSymbol, Macros) {
Index: clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
===
--- clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -53,6 +54,12 @@
   return Result;
 }
 
+std::vector> locateMacro(const Macro &M) {
+  // FIXME: Should we also provide physical locations?
+  if (auto SS = tooling::stdlib::Symbol::named("", M.Name->getName()))
+return {{*SS, Hints::CompleteSymbol}};
+  return {{M.Definition, Hints::CompleteSymbol}};
+}
 } // namespace
 
 std::vector> locateSymbol(const Symbol &S) {
@@ -60,7 +67,7 @@
   case Symbol::Declaration:
 return locateDecl(S.declaration());
   case Symbol::Macro:
-return {{S.macro().Definition, Hints::CompleteSymbol}};
+return locateMacro(S.macro());
   }
   llvm_unreachable("Unknown Symbol::Kind enum");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142905: [Driver] Change multilib selection algorithm

2023-02-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/include/clang/Driver/Multilib.h:41
+  flag_set Flags;
+  arg_list PrintArgs;
 

This is just a suggestion, but GCC documentation refers to these as either 
"options" or "switches", not "args" so I think it might be helpful to use the 
same nomenclature. This would also avoid confusion since the term "args" is 
used extensively throughout the driver but refers to input arguments.



Comment at: clang/lib/Driver/MultilibBuilder.cpp:90-93
+  for (StringRef Flag : Flags) {
+if (Flag.front() == '+')
+  Args.push_back(("-" + Flag.substr(1)).str());
+  }

If I understand this correctly, we might end up with duplicate arguments in the 
case when `Flags` contains duplicate elements. Is that desirable? Wouldn't it 
be better to construct the list of arguments from the set of fags inside 
`Multilib`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142905

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:291
   }
   for (auto &Filter : Cfg.Diagnostics.Includes.IgnoreHeader) {
 // Convert the path to Unix slashes and try to match against the filter.

can you also change the logic here to use `isFilteredByConfig` (we need the 
`native` call inside `isFilteredByConfig` as well to make sure it works on 
windows)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:373
+include_cleaner::Header Provider) {
+  std::string SpelledHeader;
+  if (Provider.kind() == include_cleaner::Header::Physical) {

nit: you can directly define `SpelledHeader` at line 377



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:408
+
+bool isFilteredByConfig(const Config &Cfg, llvm::StringRef HeaderSpelling) {
+  for (auto &Filter : Cfg.Diagnostics.Includes.IgnoreHeader) {

this shouldn't be spelling, it should be the resolved path of the include.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:433
+if (isFilteredByConfig(Cfg, Spelling)) {
+  dlog("{0} header is filtered out by the configuration", Spelling);
+  continue;

can you prefix this with `IncludeCleaner: ` and rather say `not diagnosing 
missing include {0}, filtered by config` to add a bit more context about what 
specific interaction the log is coming from



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:461
+ SymbolWithMissingInclude.SymRefRange.endOffset())};
+D.Fixes.emplace_back();
+D.Fixes.back().Message = "#include " + Spelling;

nit:
```
auto &F = D.Fixes.emplace_back();
F.Message = ...;
F.Edits.push_back(replacementToEdit(...));
```



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:465
+D.Fixes.back().Edits.emplace_back(std::move(Edit));
+D.InsideMainFile = true;
+  }

nit: it'd put this next to `D.File` above



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:695
+auto Range = syntax::Token::range(
+AST.getSourceManager(), (*SpelledForExpanded)[0],
+(*SpelledForExpanded)[(*SpelledForExpanded).size() - 1]);

`auto Range = syntax::Token::range(SM, SpelledForExpanded->front(), 
SpelledForExpanded->back());`



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:697
+(*SpelledForExpanded)[(*SpelledForExpanded).size() - 1]);
+std::string SymbolName;
+switch (Ref.Target.kind()) {

as mentioned elsewhere, i think we should delay this symbol name spelling to 
diagnostic generation. to make sure core analysis we perform don't do work that 
might not get re-used (e.g. if we're not going to diagnose missing includes, or 
in the future when we don't care about spelling of all the symbols)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:712
+  getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
+  return {std::move(UnusedIncludes), std::move(MissingIncludes)};
 }

nit: I think logically it makes more sense for us to return set of `Used` 
includes here, and let the interaction that issues unused include diagnostics 
to derive this information from the set of used includes, and change the the 
missingincludes to a `vector< tuple >` (not only the 
unsatisfied ones) would represent the analysis better and make it more usable 
in the future (i.e. when we want to augment Hover responses, we can't re-use 
all the logic in here, we really need to implement another call to `walkUsed` 
because the analysis we get out of this call won't contain information for 
`satisfied` symbols.

no need to do it now though, we can perform that kind of refactoring as we're 
adding the features too (or maybe it'll actually look neater to just have 
another call in those features rather than try and re-use the logic here)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:359
+TransformedInc.Angled = WrittenRef.starts_with("<");
+auto FE = SM.getFileManager().getFile(Inc.Resolved);
+if (!FE)

VitaNuo wrote:
> kadircet wrote:
> > unfortunately `getFile` returns an `llvm::Expected` which requires explicit 
> > error handling (or it'll trigger a crash). you can simply `elog` the issue:
> > ```
> > if (!FE) {
> >   elog("IncludeCleaner: Failed to get an entry for resolved path {0}: {1}", 
> > Inc.Resolved, FE.takeError());
> >   continue;
> > }
> > ```
> It returns `llvm::ErrorOr`, if I am not mistaken. There was explicit error 
> handling already (`if (!FE) continue` below), just without the `elog`. Are 
> you trying to say it will crash without the logging? Not sure that's feasible 
> :)
> Added the logging.
> It returns llvm::ErrorOr, if I am not mistaken. 

Ah you're right,

[clang-tools-extra] 279b498 - [include-cleaner] Always treat constructor calls as implicit

2023-02-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-02-23T10:00:50+01:00
New Revision: 279b4985ed4f62eb8e9a71e79379c2adfa8d8b99

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

LOG: [include-cleaner] Always treat constructor calls as implicit

Treating constructor calls when the type name isn't explicitly spelled
can cause spurious results, so turn them into implicit references.
This doesn't change the behaviour for constructor calls that explicitly spell
the type name, as we should see a reference through the typeloc.

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

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index f317b0dc2d07..0ca84145721a 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -102,9 +102,12 @@ class ASTWalker : public RecursiveASTVisitor {
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+// Always treat consturctor calls as implicit. We'll have an explicit
+// reference for the constructor calls that mention the type-name (through
+// TypeLocs). This reference only matters for cases where there's no
+// explicit syntax at all or there're only braces.
 report(E->getLocation(), getMemberProvider(E->getType()),
-   E->getParenOrBraceRange().isValid() ? RefType::Explicit
-   : RefType::Implicit);
+   RefType::Implicit);
 return true;
   }
 

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 3b97cc8cdfd5..7dcbf475e986 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -111,6 +111,9 @@ TEST(WalkAST, TagType) {
   testWalk("struct $explicit^S {};", "^S *y;");
   testWalk("enum $explicit^E {};", "^E *y;");
   testWalk("struct $explicit^S { static int x; };", "int y = ^S::x;");
+  // One explicit call from the TypeLoc in constructor spelling, another
+  // implicit reference through the constructor call.
+  testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = 
^S();");
 }
 
 TEST(WalkAST, Alias) {
@@ -241,7 +244,7 @@ TEST(WalkAST, MemberExprs) {
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct $implicit^S { S(); };", "S ^t;");
-  testWalk("struct $explicit^S { S(int); };", "S ^t(42);");
+  testWalk("struct $implicit^S { S(int); };", "S ^t(42);");
   testWalk("struct $implicit^S { S(int); };", "S t = ^42;");
   testWalk("namespace ns { struct S{}; } using ns::$implicit^S;", "S ^t;");
 }



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


[PATCH] D144582: [include-cleaner] Always treat constructor calls as implicit

2023-02-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG279b4985ed4f: [include-cleaner] Always treat constructor 
calls as implicit (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144582

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -111,6 +111,9 @@
   testWalk("struct $explicit^S {};", "^S *y;");
   testWalk("enum $explicit^E {};", "^E *y;");
   testWalk("struct $explicit^S { static int x; };", "int y = ^S::x;");
+  // One explicit call from the TypeLoc in constructor spelling, another
+  // implicit reference through the constructor call.
+  testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = 
^S();");
 }
 
 TEST(WalkAST, Alias) {
@@ -241,7 +244,7 @@
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct $implicit^S { S(); };", "S ^t;");
-  testWalk("struct $explicit^S { S(int); };", "S ^t(42);");
+  testWalk("struct $implicit^S { S(int); };", "S ^t(42);");
   testWalk("struct $implicit^S { S(int); };", "S t = ^42;");
   testWalk("namespace ns { struct S{}; } using ns::$implicit^S;", "S ^t;");
 }
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -102,9 +102,12 @@
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+// Always treat consturctor calls as implicit. We'll have an explicit
+// reference for the constructor calls that mention the type-name (through
+// TypeLocs). This reference only matters for cases where there's no
+// explicit syntax at all or there're only braces.
 report(E->getLocation(), getMemberProvider(E->getType()),
-   E->getParenOrBraceRange().isValid() ? RefType::Explicit
-   : RefType::Implicit);
+   RefType::Implicit);
 return true;
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -111,6 +111,9 @@
   testWalk("struct $explicit^S {};", "^S *y;");
   testWalk("enum $explicit^E {};", "^E *y;");
   testWalk("struct $explicit^S { static int x; };", "int y = ^S::x;");
+  // One explicit call from the TypeLoc in constructor spelling, another
+  // implicit reference through the constructor call.
+  testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();");
 }
 
 TEST(WalkAST, Alias) {
@@ -241,7 +244,7 @@
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct $implicit^S { S(); };", "S ^t;");
-  testWalk("struct $explicit^S { S(int); };", "S ^t(42);");
+  testWalk("struct $implicit^S { S(int); };", "S ^t(42);");
   testWalk("struct $implicit^S { S(int); };", "S t = ^42;");
   testWalk("namespace ns { struct S{}; } using ns::$implicit^S;", "S ^t;");
 }
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -102,9 +102,12 @@
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+// Always treat consturctor calls as implicit. We'll have an explicit
+// reference for the constructor calls that mention the type-name (through
+// TypeLocs). This reference only matters for cases where there's no
+// explicit syntax at all or there're only braces.
 report(E->getLocation(), getMemberProvider(E->getType()),
-   E->getParenOrBraceRange().isValid() ? RefType::Explicit
-   : RefType::Implicit);
+   RefType::Implicit);
 return true;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 48027f0 - [include-cleaner] Dont pass llvm::StringRef to gtest APIs

2023-02-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-02-23T10:04:03+01:00
New Revision: 48027f03f2d5fef884ebe118c42f800b90fae2f9

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

LOG: [include-cleaner] Dont pass llvm::StringRef to gtest APIs

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index 967ae829e778..c34c6c0a29a8 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -367,7 +367,7 @@ TEST(WalkUsed, FilterRefsNotSpelledInMainFile) {
 if (RefLoc.isValid()) {
   EXPECT_THAT(RefLoc, AllOf(expandedAt(MainFID, Main.point("expand"), &SM),
 spelledAt(MainFID, Main.point("spell"), &SM)))
-  << T.Main;
+  << T.Main.str();
 } else {
   EXPECT_THAT(Main.points(), testing::IsEmpty());
 }



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


[clang] 74565c3 - [Modules] Don't check [temp.friend]p9 in ASTContext::isSameEntity

2023-02-23 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-02-23T17:09:38+08:00
New Revision: 74565c3add6d683559618973863e78a5e6836e48

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

LOG: [Modules] Don't check [temp.friend]p9 in ASTContext::isSameEntity

[temp.friend]p9 says

> Such a constrained friend function or function template declaration does
not declare the same function or function template as a declaration in
any other scope.

But the friend declaration in the same scope shouldn't fall into this
catagory. Although the logic is handled in 'FriendsDifferByConstraints',
the compiler may haven't merged the lexcial declcontext in time.
Also the code removed is not covered by test too.

Let's handle the logic in sema as we've done now.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d852ac52ce8c..11c07043c984 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6687,10 +6687,6 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
   FuncY->getTrailingRequiresClause()))
   return false;
 
-// Constrained friends are 
diff erent in certain cases, see: [temp.friend]p9.
-if (FriendsDifferByConstraints(FuncX, FuncY))
-  return false;
-
 auto GetTypeAsWritten = [](const FunctionDecl *FD) {
   // Map to the first declaration that we've already merged into this one.
   // The TSI of redeclarations might not match (due to calling conventions



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


[PATCH] D144457: [clang][Interp] Handle global composite temporaries

2023-02-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Thinking about this some more, the new `Pointer::toRValue()` is probably just 
the same thing we're already doing in `EvalEmitter::emtiRetValue()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144457

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


[PATCH] D144599: [clangd/index/remote]NFC: Adapt code to newer grpc/protobuf versions

2023-02-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, indeed the protobuf version used by grpc-1.36.3 has these available, 
https://github.com/protocolbuffers/protobuf/blob/19fb89416f3fdc2d6668f3738f444885575285bc/src/google/protobuf/stubs/status.h.

if you don't mind me asking, are you deliberately building remote-index 
components? i.e. do you have an internal remote-index server/deployment ? 
Asking as it'd be great to know that we've adoption here, outside of ourselves.

OTOH, if you're not actually using it, this shouldn't be built unless 
`-DCLANGD_ENABLE_REMOTE=1 ` is part of the build config, hence we might have a 
bug in the build configuration and I'd like to make sure it's fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144599

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


[PATCH] D143436: [clangd] Move standard options adaptor to CommandMangler

2023-02-23 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 499766.
DmitryPolukhin added a comment.

Failing tests seems to be just flacky, I was not able to reprocuce any issue 
with them locally in stress runs and under ASan and TSan


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143436

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/Inputs/did-change-configuration-params.args
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp

Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -299,6 +300,31 @@
   }
 }
 
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS) {
+  bool SeenRSPFile = false;
+  llvm::SmallVector Argv;
+  Argv.reserve(CommandLine.size());
+  for (auto &Arg : CommandLine) {
+Argv.push_back(Arg.c_str());
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
+  }
+  if (!SeenRSPFile)
+return;
+  llvm::BumpPtrAllocator Alloc;
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  llvm::Error Err =
+  ECtx.setVFS(&FS).setCurrentDir(WorkingDir).expandResponseFiles(Argv);
+  if (Err)
+llvm::errs() << Err;
+  // Don't assign directly, Argv aliases CommandLine.
+  std::vector ExpandedArgv(Argv.begin(), Argv.end());
+  CommandLine = std::move(ExpandedArgv);
+}
+
 } // namespace tooling
 } // namespace clang
 
@@ -684,7 +710,7 @@
 
   if (!Invocation.run())
 return nullptr;
- 
+
   assert(ASTs.size() == 1);
   return std::move(ASTs[0]);
 }
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -48,28 +49,9 @@
 
 private:
   std::vector expand(std::vector Cmds) const {
-for (auto &Cmd : Cmds) {
-  bool SeenRSPFile = false;
-  llvm::SmallVector Argv;
-  Argv.reserve(Cmd.CommandLine.size());
-  for (auto &Arg : Cmd.CommandLine) {
-Argv.push_back(Arg.c_str());
-if (!Arg.empty())
-  SeenRSPFile |= Arg.front() == '@';
-  }
-  if (!SeenRSPFile)
-continue;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
-  // Don't assign directly, Argv aliases CommandLine.
-  std::vector ExpandedArgv(Argv.begin(), Argv.end());
-  Cmd.CommandLine = std::move(ExpandedArgv);
-}
+for (auto &Cmd : Cmds)
+  tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory,
+Tokenizer, *FS);
 return Cmds;
   }
 
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -506,6 +506,12 @@
 void addTargetAndModeForProgramName(std::vector &CommandLine,
 StringRef InvokedAs);
 
+/// Helper function that expands response files in command line.
+void addExpandedResponseFiles(std::vector &CommandLine,
+  llvm::StringRef WorkingDir,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::vfs::FileSystem &FS);
+
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
   ArrayRef CC1Args,
Index: clang-tools-ext

[clang-tools-extra] cbcb3ee - [Tooling/Inclusion] Handle std::get symbol.

2023-02-23 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-02-23T10:26:26+01:00
New Revision: cbcb3eef70def3509bdffd4fe1ebfb6422afeaa2

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

LOG: [Tooling/Inclusion] Handle std::get symbol.

Currently, we handle it as a symbol without a header. In general, for
the include-cleaner case, the std::get comes with the type header, it is
safe to ignore it.

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

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
clang/unittests/Tooling/StandardLibraryTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index 0c61a7bd7e92..4311eb9f481f 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -717,7 +717,8 @@ llvm::StringRef 
CanonicalIncludes::mapSymbol(llvm::StringRef Scope,
   if (Scope == "std::" && Name == "move")
 return "";
   if (auto StdSym = tooling::stdlib::Symbol::named(Scope, Name, Lang))
-return StdSym->header().name();
+if (auto Header = StdSym->header())
+  return Header->name();
   return "";
 }
 

diff  --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h 
b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index 9d45d84a429b..a39ceb520dcf 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -81,7 +81,7 @@ class Symbol {
   llvm::StringRef name() const;
   llvm::StringRef qualifiedName() const;
   // The preferred header for this symbol (e.g. the suggested insertion).
-  Header header() const;
+  std::optional header() const;
   // Some symbols may be provided by multiple headers.
   llvm::SmallVector headers() const;
 

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 416b53117d16..cfcb955831ad 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -120,7 +121,8 @@ static int initialize(Lang Language) {
 }
 Mapping->SymbolNames[SymIndex] = {
 QName.data(), NSLen, static_cast(QName.size() - NSLen)};
-Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
+if (!HeaderName.empty())
+   Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
 
 NSSymbolMap &NSSymbols = AddNS(QName.take_front(NSLen));
 NSSymbols.try_emplace(QName.drop_front(NSLen), SymIndex);
@@ -205,8 +207,11 @@ std::optional Symbol::named(llvm::StringRef Scope, 
llvm::StringRef Name,
   }
   return std::nullopt;
 }
-Header Symbol::header() const {
-  return Header(getMappingPerLang(Language)->SymbolHeaderIDs[ID][0], Language);
+std::optional Symbol::header() const {
+  const auto& Headers = getMappingPerLang(Language)->SymbolHeaderIDs[ID];
+  if (Headers.empty())
+return std::nullopt;
+  return Header(Headers.front(), Language);
 }
 llvm::SmallVector Symbol::headers() const {
   llvm::SmallVector Results;

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index 3d2ea91a94d3..c9632bee1cbe 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -218,3 +218,8 @@ SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
+
+// std::get has a few variants for 
diff erent types (tuple, array, pair etc)
+// which is tricky to disambiguate without type information.
+// Don't set any header for it, as it comes with the type header.
+SYMBOL(get, std::, /*no headers*/)

diff  --git a/clang/unittests/Tooling/StandardLibraryTest.cpp 
b/clang/unittests/Tooling/StandardLibraryTest.cpp
index 47d064bdd2a9..6d90bbdf3b6e 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -58,6 +58,9 @@ TEST(StdlibTest, All) {
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
+  EXPECT_TRUE(stdlib::Symbol::named("std::", "get"));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "get")->header());
+
   EXPECT_THAT(stdlib::Symbol::named("std::", "basic_iostream")->headers(),

[PATCH] D144484: [Tooling/Inclusion] Handle std::get symbol.

2023-02-23 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcbcb3eef70de: [Tooling/Inclusion] Handle std::get symbol. 
(authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144484

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
  clang/unittests/Tooling/StandardLibraryTest.cpp


Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -58,6 +58,9 @@
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
+  EXPECT_TRUE(stdlib::Symbol::named("std::", "get"));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "get")->header());
+
   EXPECT_THAT(stdlib::Symbol::named("std::", "basic_iostream")->headers(),
   ElementsAre(stdlib::Header::named(""),
   stdlib::Header::named(""),
Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -218,3 +218,8 @@
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
+
+// std::get has a few variants for different types (tuple, array, pair etc)
+// which is tricky to disambiguate without type information.
+// Don't set any header for it, as it comes with the type header.
+SYMBOL(get, std::, /*no headers*/)
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -120,7 +121,8 @@
 }
 Mapping->SymbolNames[SymIndex] = {
 QName.data(), NSLen, static_cast(QName.size() - NSLen)};
-Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
+if (!HeaderName.empty())
+   Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
 
 NSSymbolMap &NSSymbols = AddNS(QName.take_front(NSLen));
 NSSymbols.try_emplace(QName.drop_front(NSLen), SymIndex);
@@ -205,8 +207,11 @@
   }
   return std::nullopt;
 }
-Header Symbol::header() const {
-  return Header(getMappingPerLang(Language)->SymbolHeaderIDs[ID][0], Language);
+std::optional Symbol::header() const {
+  const auto& Headers = getMappingPerLang(Language)->SymbolHeaderIDs[ID];
+  if (Headers.empty())
+return std::nullopt;
+  return Header(Headers.front(), Language);
 }
 llvm::SmallVector Symbol::headers() const {
   llvm::SmallVector Results;
Index: clang/include/clang/Tooling/Inclusions/StandardLibrary.h
===
--- clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -81,7 +81,7 @@
   llvm::StringRef name() const;
   llvm::StringRef qualifiedName() const;
   // The preferred header for this symbol (e.g. the suggested insertion).
-  Header header() const;
+  std::optional header() const;
   // Some symbols may be provided by multiple headers.
   llvm::SmallVector headers() const;
 
Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -717,7 +717,8 @@
   if (Scope == "std::" && Name == "move")
 return "";
   if (auto StdSym = tooling::stdlib::Symbol::named(Scope, Name, Lang))
-return StdSym->header().name();
+if (auto Header = StdSym->header())
+  return Header->name();
   return "";
 }
 


Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -58,6 +58,9 @@
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
+  EXPECT_TRUE(stdlib::Symbol::named("std::", "get"));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "get")->header());
+
   EXPECT_THAT(stdlib::Symbol::named("std::", "basic_iostream")->headers(),
   ElementsAre(stdlib::Header::named(""),
   stdlib::Header::named(""),
Index: cla

[PATCH] D144599: [clangd/index/remote]NFC: Adapt code to newer grpc/protobuf versions

2023-02-23 Thread Kugan Vivekanandarajah via Phabricator via cfe-commits
kuganv added a comment.



> if you don't mind me asking, are you deliberately building remote-index 
> components? i.e. do you have an internal remote-index server/deployment ? 
> Asking as it'd be great to know that we've adoption here, outside of 
> ourselves.
>
> OTOH, if you're not actually using it, this shouldn't be built unless 
> `-DCLANGD_ENABLE_REMOTE=1 ` is part of the build config, hence we might have 
> a bug in the build configuration and I'd like to make sure it's fixed.

Thanks for looking into it. Yes, we use -DCLANGD_ENABLE_REMOTE=On and provide 
grpc path with -DGRPC_INSTALL_PATH.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144599

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


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-23 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

In D142914#4145224 , @TIFitis wrote:

> In D142914#4144475 , 
> @kiranchandramohan wrote:
>
>> Please add tests for the MLIR portion.
>
> Can you please tell me where to add these?

In `mlir/test/Target/LLVMIR/openmp-llvm.mlir`. You can also consider starting a 
new file for target constructs in that directory.




Comment at: mlir/lib/Target/LLVMIR/Dialect/Utils.cpp:1
+//===- Utils.cpp - General Utils for translating MLIR dialect to LLVM 
IR---===//
+//

TIFitis wrote:
> kiranchandramohan wrote:
> > Nit: I would prefer the OpenMPCommon.cpp name suggested in 
> > https://discourse.llvm.org/t/rfc-adding-new-util-file-to-mlir-dialect-translation/68221.
> >  
> Would you also like me to move the file inside OpenMP ( 
> `mlir/lib/Target/LLVMIR/Dialect/OpenMP` ) ?
No, the current location is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142914

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


[PATCH] D144626: [C++20] [Modules] Provide OriginalTrailingRequiresClause for serializer to perform ODR-Checking correctly

2023-02-23 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: erichkeane, cor3ntin, royjacobson, clang-language-wg.
ChuanqiXu added a project: clang-modules.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Close https://github.com/llvm/llvm-project/issues/60890.

For the following example:

  cpp
  export module a;
   
  export template
  struct a {
friend void aa(a) requires(true) {
}
  };



  cpp
  export module b;
  
  import a;
  
  struct b {
a m;
  };



  cpp
  export module c;
  
  import a;
  
  struct c {
void f() const {
aa(a());
}
  };



  cpp
  import a;
  import b;
  import c;
  
  void d() {
aa(a());
  }

The current clang will reject this incorrectly. The reason is that the require 
clause  will be replaced with the evaluated version 
(https://github.com/llvm/llvm-project/blob/efae3174f09560353fb0f3d528bcbffe060d5438/clang/lib/Sema/SemaConcept.cpp#L664-L665).
 In module 'b', the friend function is instantiated but not used so the require 
clause of the friend function is `(true)`. However, in module 'c', the friend 
function is used so the require clause is `true`. So deserializer classify 
these two function to two different functions instead of one. Then here is the 
bug report.

The proposed solution is to provide an original require clause which wouldn't 
change during the semantic analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144626

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/pr60890.cppm

Index: clang/test/Modules/pr60890.cppm
===
--- /dev/null
+++ clang/test/Modules/pr60890.cppm
@@ -0,0 +1,53 @@
+// https://github.com/llvm/llvm-project/issues/60890
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/a.cppm -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/b.cppm -fprebuilt-module-path=%t -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/c.cppm -fprebuilt-module-path=%t -o %t/c.pcm
+// RUN: %clang_cc1 -std=c++20 %t/d.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+
+//--- a.cppm
+export module a;
+ 
+export template
+struct a {
+	friend void aa(a x) requires(true) {}
+	void aaa() requires(true) {}
+};
+
+//--- b.cppm
+export module b;
+
+import a;
+
+void b() {
+a _;
+}
+
+//--- c.cppm
+export module c;
+
+import a;
+
+struct c {
+	void f() const {
+		a _;
+		aa(_);
+		_.aaa();
+	}
+};
+
+//--- d.cpp
+// expected-no-diagnostics
+import a;
+import b;
+import c;
+
+void d() {
+	a _;
+	aa(_);
+	_.aaa();
+}
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -551,6 +551,7 @@
 DeclaratorDecl::ExtInfo *Info = D->getExtInfo();
 Record.AddQualifierInfo(*Info);
 Record.AddStmt(Info->TrailingRequiresClause);
+Record.AddStmt(Info->OriginalTrailingRequiresClause);
   }
   // The location information is deferred until the end of the record.
   Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -885,6 +885,7 @@
 auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
 Record.readQualifierInfo(*Info);
 Info->TrailingRequiresClause = Record.readExpr();
+Info->OriginalTrailingRequiresClause = Record.readExpr();
 DD->DeclInfo = Info;
   }
   QualType TSIType = Record.readType();
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1954,6 +1954,8 @@
 DeclInfo = new (getASTContext()) ExtInfo;
 // Restore savedTInfo into (extended) decl info.
 getExtInfo()->TInfo = savedTInfo;
+// We should only store TrailingRequiresClause once.
+getExtInfo()->OriginalTrailingRequiresClause = TrailingRequiresClause;
   }
   // Set requires clause info.
   getExtInfo()->TrailingRequiresClause = TrailingRequiresClause;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6683,8 +6683,8 @@
 return false;
 }
 
-if (!isSameConstraintExpr(FuncX->getTrailingRequiresClause(),
-  FuncY->getTrailingRequiresClause()))
+if (!isSameConstraintExpr(FuncX->getOriginalTrailingRequi

[PATCH] D144170: [clang-format] Add simple macro replacements in formatting.

2023-02-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 499771.
klimek marked 9 inline comments as done.
klimek added a comment.

Address reviewer comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144170

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/MacroExpander.cpp
  clang/lib/Format/Macros.h
  clang/lib/Format/TokenAnalyzer.cpp
  clang/lib/Format/TokenAnalyzer.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/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TestLexer.h

Index: clang/unittests/Format/TestLexer.h
===
--- clang/unittests/Format/TestLexer.h
+++ clang/unittests/Format/TestLexer.h
@@ -72,7 +72,8 @@
   TokenList annotate(llvm::StringRef Code) {
 FormatTokenLexer Lex = getNewLexer(Code);
 auto Tokens = Lex.lex();
-UnwrappedLineParser Parser(Style, Lex.getKeywords(), 0, Tokens, *this);
+UnwrappedLineParser Parser(SourceMgr.get(), Style, Lex.getKeywords(), 0,
+   Tokens, *this, Allocator, IdentTable);
 Parser.parse();
 TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (auto &Line : UnwrappedLines) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22568,6 +22568,230 @@
"llvm::outs()\n<<");
 }
 
+TEST_F(FormatTest, UnexpandConfiguredMacros) {
+  FormatStyle Style = getLLVMStyle();
+  Style.Macros.push_back("CLASS=class C {");
+  Style.Macros.push_back("SEMI=;");
+  Style.Macros.push_back("STMT=f();");
+  Style.Macros.push_back("ID(x)=x");
+  Style.Macros.push_back("ID3(x, y, z)=x y z");
+  Style.Macros.push_back("CALL(x)=f([] { x })");
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a = (b) || (c)");
+  Style.Macros.push_back("MOCK_METHOD(r, n, a, s)=r n a s");
+
+  verifyFormat("ID(nested(a(b, c), d))", Style);
+  verifyFormat("CLASS\n"
+   "  a *b;\n"
+   "};",
+   Style);
+  verifyFormat("SEMI\n"
+   "SEMI\n"
+   "SEMI",
+   Style);
+  verifyFormat("STMT\n"
+   "STMT\n"
+   "STMT",
+   Style);
+  verifyFormat("void f() { ID(a *b); }", Style);
+  verifyFormat(R"(ID(
+{ ID(a *b); });
+)",
+   Style);
+  verifyIncompleteFormat(R"(ID3({, ID(a *b),
+  ;
+  });
+)",
+ Style);
+
+  verifyFormat("ID(CALL(CALL(return a * b;)));", Style);
+
+  verifyFormat("ASSIGN_OR_RETURN(MySomewhatLongType *variable,\n"
+   " MySomewhatLongFunction(SomethingElse()));\n",
+   Style);
+
+  verifyFormat(R"(
+#define MACRO(a, b) ID(a + b)
+)",
+   Style);
+  EXPECT_EQ(R"(
+int a;
+int b;
+int c;
+int d;
+int e;
+int f;
+ID(
+namespace foo {
+int a;
+}
+) // namespace k
+)",
+format(R"(
+int a;
+int b;
+int c;
+int d;
+int e;
+int f;
+ID(namespace foo { int a; })  // namespace k
+)",
+   Style));
+  verifyFormat(R"(ID(
+//
+({ ; }))
+)",
+   Style);
+
+  Style.ColumnLimit = 35;
+  // FIXME: Arbitrary formatting of macros where the end of the logical
+  // line is in the middle of a macro call are not working yet.
+  verifyFormat(R"(ID(
+void f();
+void)
+ID(g) ID(()) ID(
+;
+void g();)
+)",
+   Style);
+
+  Style.ColumnLimit = 10;
+  verifyFormat("STMT\n"
+   "STMT\n"
+   "STMT",
+   Style);
+
+  EXPECT_EQ(R"(
+ID(CALL(CALL(
+a *b)));
+)",
+format(R"(
+ID(CALL(CALL(a * b)));
+)",
+   Style));
+
+  // FIXME: If we want to support unbalanced braces or parens from macro
+  // expansions we need to re-think how we propagate errors in
+  // TokenAnnotator::parseLine; for investigation, switching the inner loop of
+  // TokenAnnotator::parseLine to return LT_Other instead of LT_Invalid in case
+  // of !consumeToken() changes the formatting of the test below and makes it
+  // believe it has a fully correct formatting.
+  EXPECT_EQ(R"(
+ID3(
+{
+CLASS
+a *b;
+};
+},
+ID(x *y);
+,
+STMT
+STMT
+STMT)
+void f();
+)",
+format(R"(
+ID3({CLASS a*b; };}, ID(x*y);, STMT STMT STMT)
+void f();
+)",
+   Style));
+
+  verifyFormat("ID(a(\n"
+   "#ifdef A\n"
+   "b, c\n"
+   "#else\n"
+   "d(e)\n"
+   "#endif\n"
+   "))",
+   

[PATCH] D144170: [clang-format] Add simple macro replacements in formatting.

2023-02-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:744
+  // Align following lines within parenthesis / brackets if configured.
+  // For a line of macro parents, the commas that follow the opening 
parenthesis
+  // in the line come after the opening parenthesis' children - we want to 
align

sammccall wrote:
> This is a bit hard to follow without context, I had to look up 
> MacroCallReconstructor::takeResult() to recall the structure it's referring 
> to, and there's no obvious breadcrumb to point you there. And if you don't 
> follow the details, it's hard to understand what the relevance is.
> 
> Maybe something like: this doesn't apply to macro expansion lines, which are 
> `MACRO( , , )` with args as children of `(` and `,`. It does not make sense 
> to align the commas with the opening paren.
> 
> (I think describing here how the alignment ends up working in that case might 
> just add confusion: it's not handled by this code, right?)
Excellent wording, applied. And yes, alignment in the macro case is not handled 
here.



Comment at: clang/lib/Format/TokenAnnotator.h:68
 FormatToken *Current = First;
+addChildren(Line.Tokens.front(), Current);
 for (const UnwrappedLineNode &Node : llvm::drop_begin(Line.Tokens)) {

sammccall wrote:
> this seems like a separate bugfix: previously if the first node in 
> Line.Tokens had children, we wouldn't be adding them.
> 
> Is this true? Was there some reason the first node could never have children 
> before?
I think the main problem is that it's impossible to write C++ code that has a 
child in the first node based on how this worked. That is, previously we only 
added children for blocks within one line, that is, within a function or 
lambda. Those need intro tokens. So I really couldn't make this trigger, or I 
would have fixed it in a separate patch.



Comment at: clang/lib/Format/TokenAnnotator.h:76
+  addChildren(Node, Current);
+  // FIXME: if we add children, previous will point to the token before
+  // the children; changing this requires significant changes across

sammccall wrote:
> does "add children" here refer to the procedure in addChildren(), or to the 
> token insertion idea introduced in the previous patch?
> 
> (i.e. is this just describing that previous/next skip over trees of children 
> rather than including them in the chain, or is there something new going on?)
It's about adding children in general.
When fixing this I realized this is in principle wrong, but then noticed that 
we have code that depends on this behavior.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:926
+} else {
+  Tok->Finalized = true;
+}

sammccall wrote:
> why do we no longer finalize the child tree?
We do - markFinalized() is called for the child tree again. Previously we 
marked multiple times, which doesn't work with the new algorithm, as it would 
move ExpandedArg -> UnexpandedArg -> Finalized in one go.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:225
+  }
+  Callback.finishRun();
+}

sammccall wrote:
> I'm sure you got this right, but it's hard for me to evaluate this code 
> because I don't know what `UnwrappedLineConsumer::finishRun()` is for - it's 
> not documented and the implementation is mysterious.
> 
> You might consider adding a comment to that interface/method, it's not really 
> related to this change though.
Done. Not sure I've put too much info about how it's going to be used into the 
interface, where it doesn't really belong.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:4564
+  // We parse the macro call into a new line.
+  auto Args = parseMacroCall();
+  InExpansion = OldInExpansion;

sammccall wrote:
> it looks like you go into parsing the macro call including parens and 
> arguments regardless of whether the macro is object-like or function-like.
> 
> So given
> ```
> #define DEBUG puts
> DEBUG("foo");
> ```
> you're going to expand to `puts;` instead of `puts("foo");`
Excellent find. Completely invalidated the way I was doing formatting of 
expanded lines, but fixed the problem with the line indices needing resetting 
\o/

Now we're formatting all lines in the first round with the macro calls replaced 
with expanded lines, and then again format everything including the macro 
calls. That is more in line with clang-format's assumptions anyway.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:4660
+}
+  } while (!eof());
+  return {};

sammccall wrote:
> hitting eof is an error condition here, so it seems more natural to handle it 
> as a case in the switch as a kind of early-return, and maybe it's worth 
> adding an LLVM_DEBUG() for that case. If anything it'd be nice to have 
> r

[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

2023-02-23 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp added a comment.

@steakhal, @NoQ

thanks for your reviews.

Please note that I am not extending `TaintBugVisitor`. On the contrary I 
removed it.
Instead I use NoteTag to generate the "Taint Originated here" text (see 
GenericTaintChecker.cpp:156).

I can also add additional NoteTags for generating propagation messages "Taint 
was propagated here" easily.

> The challenging part with note tags is how do you figure out whether your bug 
> report is taint-related.

I solved this by checking if the report is an instance of `TaintBugReport` a 
new BugReport type, which should be used by all taint related reports 
(ArrayBoundCheckerV2 checker and divisionbyzero checker 
was changed to use this new report type for taint related reports).

The tricky part was is to how to show only that single "Taint originated here" 
note tag at the taint source only which is relevant to the report. This is done 
by remembering the unique flowid in the
NoteTag in the forward analysis direction (see GenericTaintChecker:cpp:859) 
`InjectionTag = createTaintOriginTag(C, TaintFlowId);` and then filtering out 
the irrelevant 
NoteTags when the the report is generated (when the lamdba callback is called). 
See that flowid which reaches the sink is backpropagated in the 
PathSensitiveBugreport (see GenericTaintCHekcer.cpp:167).

FlowIds are unique and increased at every taint source 
(GenericTaintChecker:869) and it is stored as an additional simple `int` in the 
program state along with the already existing (Taint.cpp:22) TaintTagType.

My fear with the interestingness is that it may propagating backwards according 
to different "rules" than whot the taintedness is popagating in the foward 
direction even with the "extensions" pointed out by steakhal.
So the two types of propagation may be or can get out of sync.

So if the above is not a concern and you think implementing this with 
interestingness is more elegant, idiomatic and causes less maintenance burden, 
I am happy to create an alternative patch with that solution.


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

https://reviews.llvm.org/D144269

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


[PATCH] D144627: [Clang] Fix a crash when taking the address of a consteval lambda

2023-02-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The `_invoke` function of lambdas was not respecting
the constexpr/consteval specifier of the call operator, so it was possible
to take its address in a non-immmediately invoked context,
even if the call operator was itself consteval.

In addition, we improve the diagnostic emmited in the lambda case
not to show that `invoke` method.

Fixes #57682


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144627

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1029,3 +1029,24 @@
int x = A{};
 }
 }
+
+namespace GH57682 {
+void test() {
+  constexpr auto l1 = []() consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \
+   // expected-note  2{{declared here}}
+return 3;
+  };
+  constexpr int (*f1)(void) = l1; // expected-error {{constexpr variable 'f1' must be initialized by a constant expression}} \
+  // expected-note  {{pointer to a consteval declaration is not a constant expression}}
+
+
+  constexpr auto lstatic = []() static consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \
+   // expected-note  2{{declared here}} \
+   // expected-warning {{extension}}
+return 3;
+  };
+  constexpr int (*f2)(void) = lstatic; // expected-error {{constexpr variable 'f2' must be initialized by a constant expression}} \
+   // expected-note  {{pointer to a consteval declaration is not a constant expression}}
+
+}
+}
Index: clang/test/AST/ast-dump-lambda.cpp
===
--- clang/test/AST/ast-dump-lambda.cpp
+++ clang/test/AST/ast-dump-lambda.cpp
@@ -246,7 +246,7 @@
 // CHECK-NEXT:| | |-CXXMethodDecl {{.*}}  col:3{{( imported)?}} constexpr operator() 'auto () const' inline
 // CHECK-NEXT:| | | `-CompoundStmt {{.*}} 
 // CHECK-NEXT:| | |-CXXConversionDecl {{.*}}  col:3{{( imported)?}} implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
-// CHECK-NEXT:| | `-CXXMethodDecl {{.*}}  col:3{{( imported)?}} implicit __invoke 'auto ()' static inline
+// CHECK-NEXT:| | `-CXXMethodDecl {{.*}}  col:3{{( imported)?}} implicit constexpr __invoke 'auto ()' static inline
 // CHECK-NEXT:| `-CompoundStmt {{.*}} 
 // CHECK-NEXT:|-LambdaExpr {{.*}}  '(lambda at {{.*}}ast-dump-lambda.cpp:33:3)'
 // CHECK-NEXT:| |-CXXRecordDecl {{.*}}  col:3{{( imported)?}} implicit{{( )?}} class definition
Index: clang/test/AST/ast-dump-expr.cpp
===
--- clang/test/AST/ast-dump-expr.cpp
+++ clang/test/AST/ast-dump-expr.cpp
@@ -464,7 +464,7 @@
   // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 constexpr operator() 'auto () const' inline
   // CHECK-NEXT: CompoundStmt
   // CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}}  col:3 implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
-  // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 implicit __invoke 'auto ()' static inline
+  // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 implicit constexpr __invoke 'auto ()' static inline
   // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
 
   []() mutable {};
Index: clang/test/AST/ast-dump-expr-json.cpp
===
--- clang/test/AST/ast-dump-expr-json.cpp
+++ clang/test/AST/ast-dump-expr-json.cpp
@@ -6867,7 +6867,8 @@
 // CHECK-NEXT: "qualType": "auto ()"
 // CHECK-NEXT:},
 // CHECK-NEXT:"storageClass": "static",
-// CHECK-NEXT:"inline": true
+// CHECK-NEXT:"inline": true,
+// CHECK-NEXT:"constexpr": true
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: },
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1529,7 +1529,7 @@
 S.Context, Class, Loc, DeclarationNameInfo(InvokerName, Loc),
 InvokerFunctionTy, CallOperator->getTypeSourceInfo(), SC_Static,
 S.getCurFPFeatures().isFPConstrained(),
-/*isInline=*/true, ConstexprSpecKind::Unspecified,
+/*isInline=*/true, CallOperator->getConstexprKind(),

[PATCH] D144627: [Clang] Fix a crash when taking the address of a consteval lambda

2023-02-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 499773.
cor3ntin added a comment.

Release notes + formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144627

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1029,3 +1029,24 @@
int x = A{};
 }
 }
+
+namespace GH57682 {
+void test() {
+  constexpr auto l1 = []() consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \
+   // expected-note  2{{declared here}}
+return 3;
+  };
+  constexpr int (*f1)(void) = l1; // expected-error {{constexpr variable 'f1' must be initialized by a constant expression}} \
+  // expected-note  {{pointer to a consteval declaration is not a constant expression}}
+
+
+  constexpr auto lstatic = []() static consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \
+   // expected-note  2{{declared here}} \
+   // expected-warning {{extension}}
+return 3;
+  };
+  constexpr int (*f2)(void) = lstatic; // expected-error {{constexpr variable 'f2' must be initialized by a constant expression}} \
+   // expected-note  {{pointer to a consteval declaration is not a constant expression}}
+
+}
+}
Index: clang/test/AST/ast-dump-lambda.cpp
===
--- clang/test/AST/ast-dump-lambda.cpp
+++ clang/test/AST/ast-dump-lambda.cpp
@@ -246,7 +246,7 @@
 // CHECK-NEXT:| | |-CXXMethodDecl {{.*}}  col:3{{( imported)?}} constexpr operator() 'auto () const' inline
 // CHECK-NEXT:| | | `-CompoundStmt {{.*}} 
 // CHECK-NEXT:| | |-CXXConversionDecl {{.*}}  col:3{{( imported)?}} implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
-// CHECK-NEXT:| | `-CXXMethodDecl {{.*}}  col:3{{( imported)?}} implicit __invoke 'auto ()' static inline
+// CHECK-NEXT:| | `-CXXMethodDecl {{.*}}  col:3{{( imported)?}} implicit constexpr __invoke 'auto ()' static inline
 // CHECK-NEXT:| `-CompoundStmt {{.*}} 
 // CHECK-NEXT:|-LambdaExpr {{.*}}  '(lambda at {{.*}}ast-dump-lambda.cpp:33:3)'
 // CHECK-NEXT:| |-CXXRecordDecl {{.*}}  col:3{{( imported)?}} implicit{{( )?}} class definition
Index: clang/test/AST/ast-dump-expr.cpp
===
--- clang/test/AST/ast-dump-expr.cpp
+++ clang/test/AST/ast-dump-expr.cpp
@@ -464,7 +464,7 @@
   // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 constexpr operator() 'auto () const' inline
   // CHECK-NEXT: CompoundStmt
   // CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}}  col:3 implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
-  // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 implicit __invoke 'auto ()' static inline
+  // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 implicit constexpr __invoke 'auto ()' static inline
   // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
 
   []() mutable {};
Index: clang/test/AST/ast-dump-expr-json.cpp
===
--- clang/test/AST/ast-dump-expr-json.cpp
+++ clang/test/AST/ast-dump-expr-json.cpp
@@ -6867,7 +6867,8 @@
 // CHECK-NEXT: "qualType": "auto ()"
 // CHECK-NEXT:},
 // CHECK-NEXT:"storageClass": "static",
-// CHECK-NEXT:"inline": true
+// CHECK-NEXT:"inline": true,
+// CHECK-NEXT:"constexpr": true
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: },
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1529,7 +1529,7 @@
 S.Context, Class, Loc, DeclarationNameInfo(InvokerName, Loc),
 InvokerFunctionTy, CallOperator->getTypeSourceInfo(), SC_Static,
 S.getCurFPFeatures().isFPConstrained(),
-/*isInline=*/true, ConstexprSpecKind::Unspecified,
+/*isInline=*/true, CallOperator->getConstexprKind(),
 CallOperator->getBody()->getEndLoc());
 for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I)
   InvokerParams[I]->setOwningFunction(Invoke);
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/S

[PATCH] D144170: [clang-format] Add simple macro replacements in formatting.

2023-02-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 499777.
klimek added a comment.

Add comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144170

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/MacroExpander.cpp
  clang/lib/Format/Macros.h
  clang/lib/Format/TokenAnalyzer.cpp
  clang/lib/Format/TokenAnalyzer.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/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TestLexer.h

Index: clang/unittests/Format/TestLexer.h
===
--- clang/unittests/Format/TestLexer.h
+++ clang/unittests/Format/TestLexer.h
@@ -72,7 +72,8 @@
   TokenList annotate(llvm::StringRef Code) {
 FormatTokenLexer Lex = getNewLexer(Code);
 auto Tokens = Lex.lex();
-UnwrappedLineParser Parser(Style, Lex.getKeywords(), 0, Tokens, *this);
+UnwrappedLineParser Parser(SourceMgr.get(), Style, Lex.getKeywords(), 0,
+   Tokens, *this, Allocator, IdentTable);
 Parser.parse();
 TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (auto &Line : UnwrappedLines) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22568,6 +22568,230 @@
"llvm::outs()\n<<");
 }
 
+TEST_F(FormatTest, UnexpandConfiguredMacros) {
+  FormatStyle Style = getLLVMStyle();
+  Style.Macros.push_back("CLASS=class C {");
+  Style.Macros.push_back("SEMI=;");
+  Style.Macros.push_back("STMT=f();");
+  Style.Macros.push_back("ID(x)=x");
+  Style.Macros.push_back("ID3(x, y, z)=x y z");
+  Style.Macros.push_back("CALL(x)=f([] { x })");
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a = (b) || (c)");
+  Style.Macros.push_back("MOCK_METHOD(r, n, a, s)=r n a s");
+
+  verifyFormat("ID(nested(a(b, c), d))", Style);
+  verifyFormat("CLASS\n"
+   "  a *b;\n"
+   "};",
+   Style);
+  verifyFormat("SEMI\n"
+   "SEMI\n"
+   "SEMI",
+   Style);
+  verifyFormat("STMT\n"
+   "STMT\n"
+   "STMT",
+   Style);
+  verifyFormat("void f() { ID(a *b); }", Style);
+  verifyFormat(R"(ID(
+{ ID(a *b); });
+)",
+   Style);
+  verifyIncompleteFormat(R"(ID3({, ID(a *b),
+  ;
+  });
+)",
+ Style);
+
+  verifyFormat("ID(CALL(CALL(return a * b;)));", Style);
+
+  verifyFormat("ASSIGN_OR_RETURN(MySomewhatLongType *variable,\n"
+   " MySomewhatLongFunction(SomethingElse()));\n",
+   Style);
+
+  verifyFormat(R"(
+#define MACRO(a, b) ID(a + b)
+)",
+   Style);
+  EXPECT_EQ(R"(
+int a;
+int b;
+int c;
+int d;
+int e;
+int f;
+ID(
+namespace foo {
+int a;
+}
+) // namespace k
+)",
+format(R"(
+int a;
+int b;
+int c;
+int d;
+int e;
+int f;
+ID(namespace foo { int a; })  // namespace k
+)",
+   Style));
+  verifyFormat(R"(ID(
+//
+({ ; }))
+)",
+   Style);
+
+  Style.ColumnLimit = 35;
+  // FIXME: Arbitrary formatting of macros where the end of the logical
+  // line is in the middle of a macro call are not working yet.
+  verifyFormat(R"(ID(
+void f();
+void)
+ID(g) ID(()) ID(
+;
+void g();)
+)",
+   Style);
+
+  Style.ColumnLimit = 10;
+  verifyFormat("STMT\n"
+   "STMT\n"
+   "STMT",
+   Style);
+
+  EXPECT_EQ(R"(
+ID(CALL(CALL(
+a *b)));
+)",
+format(R"(
+ID(CALL(CALL(a * b)));
+)",
+   Style));
+
+  // FIXME: If we want to support unbalanced braces or parens from macro
+  // expansions we need to re-think how we propagate errors in
+  // TokenAnnotator::parseLine; for investigation, switching the inner loop of
+  // TokenAnnotator::parseLine to return LT_Other instead of LT_Invalid in case
+  // of !consumeToken() changes the formatting of the test below and makes it
+  // believe it has a fully correct formatting.
+  EXPECT_EQ(R"(
+ID3(
+{
+CLASS
+a *b;
+};
+},
+ID(x *y);
+,
+STMT
+STMT
+STMT)
+void f();
+)",
+format(R"(
+ID3({CLASS a*b; };}, ID(x*y);, STMT STMT STMT)
+void f();
+)",
+   Style));
+
+  verifyFormat("ID(a(\n"
+   "#ifdef A\n"
+   "b, c\n"
+   "#else\n"
+   "d(e)\n"
+   "#endif\n"
+   "))",
+   Style);
+  Style.ColumnLimit = 80;
+  verifyFormat(

[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-02-23 Thread Sunil K via Phabricator via cfe-commits
koops created this revision.
koops added reviewers: soumitra, RitanyaB, dreachem, ABataev, jdoerfert, 
sandoval, tianshilei1992.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
koops requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Support for Code Generation of "#pragma loop bind" clause.

1. bind(parallel)
2. bind(teams)
3. bind(thread)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144634

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp

Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -7785,6 +7785,49 @@
   CGF.EmitStmt(CS);
 }
   };
+  /* Bind */
+  for (const auto *C : S.getClausesOfKind()) {
+OpenMPBindClauseKind bindParam = C->getBindKind();
+switch (bindParam) {
+case OMPC_BIND_parallel: {
+  OMPForDirective *ompForD = OMPForDirective::Create(
+  *(S.LoopDirCrParmV->C), S.LoopDirCrParmV->StartLoc,
+  S.LoopDirCrParmV->EndLoc, S.LoopDirCrParmV->CollapsedNum,
+  S.LoopDirCrParmV->Clauses, S.LoopDirCrParmV->AssociatedStmt,
+  S.LoopDirCrParmV->Exprs, NULL, 0);
+  EmitOMPForDirective(*ompForD);
+  return;
+  break;
+}
+case OMPC_BIND_teams: {
+  OMPDistributeDirective *ompDistD = OMPDistributeDirective::Create(
+  *(S.LoopDirCrParmV->C), S.LoopDirCrParmV->StartLoc,
+  S.LoopDirCrParmV->EndLoc, S.LoopDirCrParmV->CollapsedNum,
+  S.LoopDirCrParmV->Clauses, S.LoopDirCrParmV->AssociatedStmt,
+  S.LoopDirCrParmV->Exprs);
+  EmitOMPDistributeDirective(*ompDistD);
+  return;
+  break;
+}
+case OMPC_BIND_thread: {
+  /*
+OMPSimdDirective *ompSimdD = OMPSimdDirective::Create(
+   *(S.LoopDirCrParmV->C),
+   S.LoopDirCrParmV->StartLoc,
+   S.LoopDirCrParmV->EndLoc,
+   S.LoopDirCrParmV->CollapsedNum,
+   S.LoopDirCrParmV->Clauses,
+   S.LoopDirCrParmV->AssociatedStmt,
+   S.LoopDirCrParmV->Exprs);
+EmitOMPSimdDirective(*ompSimdD);
+return;
+  */
+  break;
+}
+case OMPC_BIND_unknown:
+  return;
+}
+  }
   OMPLexicalScope Scope(*this, S, OMPD_unknown);
   CGM.getOpenMPRuntime().emitInlinedDirective(*this, OMPD_loop, CodeGen);
 }
Index: clang/lib/AST/StmtOpenMP.cpp
===
--- clang/lib/AST/StmtOpenMP.cpp
+++ clang/lib/AST/StmtOpenMP.cpp
@@ -2340,6 +2340,10 @@
   Dir->setDependentInits(Exprs.DependentInits);
   Dir->setFinalsConditions(Exprs.FinalsConditions);
   Dir->setPreInits(Exprs.PreInits);
+
+  Dir->LoopParamInit(C, StartLoc, EndLoc, CollapsedNum, Clauses, AssociatedStmt,
+ Exprs);
+
   return Dir;
 }
 
@@ -2351,6 +2355,14 @@
   numLoopChildren(CollapsedNum, OMPD_loop), CollapsedNum);
 }
 
+void OMPGenericLoopDirective::LoopParamInit(
+const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt,
+const HelperExprs &Exprs) {
+  this->LoopDirCrParmV = new LoopDirCrParam(C, StartLoc, EndLoc, CollapsedNum,
+Clauses, AssociatedStmt, Exprs);
+}
+
 OMPTeamsGenericLoopDirective *OMPTeamsGenericLoopDirective::Create(
 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
 unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt,
Index: clang/include/clang/AST/StmtOpenMP.h
===
--- clang/include/clang/AST/StmtOpenMP.h
+++ clang/include/clang/AST/StmtOpenMP.h
@@ -5945,6 +5945,30 @@
  unsigned CollapsedNum, ArrayRef Clauses,
  Stmt *AssociatedStmt, const HelperExprs &Exprs);
 
+  struct LoopDirCrParam {
+const ASTContext *C;
+SourceLocation StartLoc;
+SourceLocation EndLoc;
+unsigned CollapsedNum;
+ArrayRef Clauses;
+Stmt *AssociatedStmt;
+const HelperExprs Exprs;
+
+LoopDirCrParam(const ASTContext &C, SourceLocation StartLoc,
+   SourceLocation EndLoc, unsigned CollapsedNum,
+   ArrayRef Clauses, Stmt *AssociatedStmt,
+   const HelperExprs &Exprs)
+: C(&C), StartLoc(StartLoc), EndLoc(EndLoc), CollapsedNum(CollapsedNum),
+  Clauses(Clauses), AssociatedStmt(AssociatedStmt), Exprs(Exprs) {}
+  };
+
+  void LoopParamInit(const ASTContext &C, SourceLocation StartLoc,
+ SourceLocation EndLoc, unsigned

[PATCH] D143052: [CMake] Replace llvm_check_linker_flag and llvm_check_compiler_linker_flag

2023-02-23 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.

https://cmake.org/cmake/help/v3.18/module/CheckLinkerFlag.html

Looks equivalent to me, good timing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143052

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-02-23 Thread Sunil K via Phabricator via cfe-commits
koops added a comment.

bind(thread) is not working at present. I have uploaded this patch to obtain 
feedback mainly on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144634

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


[PATCH] D142905: [Driver] Change multilib selection algorithm

2023-02-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 499791.
michaelplatings marked 2 inline comments as done.
michaelplatings added a comment.

- Rename args to options as suggested by @phosek
- Add more comments to hopefully make the difference between flags and options 
clearer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142905

Files:
  clang/include/clang/Driver/Multilib.h
  clang/include/clang/Driver/MultilibBuilder.h
  clang/lib/Driver/Multilib.cpp
  clang/lib/Driver/MultilibBuilder.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/MultilibBuilderTest.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -33,14 +33,14 @@
 }
 
 TEST(MultilibTest, OpEqReflexivity3) {
-  Multilib M1({}, {}, {}, 0, {"+foo"});
-  Multilib M2({}, {}, {}, 0, {"+foo"});
+  Multilib M1({}, {}, {}, {"+foo"});
+  Multilib M2({}, {}, {}, {"+foo"});
   ASSERT_TRUE(M1 == M2) << "Multilibs with the same flag should be the same";
 }
 
 TEST(MultilibTest, OpEqInequivalence1) {
-  Multilib M1({}, {}, {}, 0, {"+foo"});
-  Multilib M2({}, {}, {}, 0, {"-foo"});
+  Multilib M1({}, {}, {}, {"+foo"});
+  Multilib M2({}, {}, {}, {"-foo"});
   ASSERT_FALSE(M1 == M2) << "Multilibs with conflicting flags are not the same";
   ASSERT_FALSE(M2 == M1)
   << "Multilibs with conflicting flags are not the same (commuted)";
@@ -48,7 +48,7 @@
 
 TEST(MultilibTest, OpEqInequivalence2) {
   Multilib M1;
-  Multilib M2({}, {}, {}, 0, {"+foo"});
+  Multilib M2({}, {}, {}, {"+foo"});
   ASSERT_FALSE(M1 == M2) << "Flags make Multilibs different";
 }
 
@@ -124,9 +124,9 @@
 }
 
 TEST(MultilibTest, Construction3) {
-  Multilib M({}, {}, {}, 0, {"+f1", "+f2", "-f3"});
-  for (Multilib::flags_list::const_iterator I = M.flags().begin(),
-E = M.flags().end();
+  Multilib M({}, {}, {}, {"+f1", "+f2", "-f3"});
+  for (Multilib::flag_set::const_iterator I = M.flags().begin(),
+  E = M.flags().end();
I != E; ++I) {
 ASSERT_TRUE(llvm::StringSwitch(*I)
 .Cases("+f1", "+f2", "-f3", true)
@@ -149,20 +149,41 @@
 
 TEST(MultilibTest, SetPriority) {
   MultilibSet MS({
-  Multilib("/foo", {}, {}, 1, {"+foo"}),
-  Multilib("/bar", {}, {}, 2, {"+bar"}),
+  Multilib("/foo", {}, {}, {"+foo"}),
+  Multilib("/bar", {}, {}, {"+bar"}),
   });
-  Multilib::flags_list Flags1 = {"+foo", "-bar"};
+  Multilib::flag_set Flags1 = {"+foo", "-bar"};
   Multilib Selection1;
   ASSERT_TRUE(MS.select(Flags1, Selection1))
   << "Flag set was {\"+foo\"}, but selection not found";
   ASSERT_TRUE(Selection1.gccSuffix() == "/foo")
   << "Selection picked " << Selection1 << " which was not expected";
 
-  Multilib::flags_list Flags2 = {"+foo", "+bar"};
+  Multilib::flag_set Flags2 = {"+foo", "+bar"};
   Multilib Selection2;
   ASSERT_TRUE(MS.select(Flags2, Selection2))
   << "Flag set was {\"+bar\"}, but selection not found";
   ASSERT_TRUE(Selection2.gccSuffix() == "/bar")
   << "Selection picked " << Selection2 << " which was not expected";
 }
+
+TEST(MultilibTest, SelectMultiple) {
+  MultilibSet MS({
+  Multilib("/a", {}, {}, {"x"}),
+  Multilib("/b", {}, {}, {"y"}),
+  });
+  std::vector Selection;
+
+  Selection = MS.select({"x"});
+  ASSERT_EQ(1u, Selection.size());
+  EXPECT_EQ("/a", Selection[0].gccSuffix());
+
+  Selection = MS.select({"y"});
+  ASSERT_EQ(1u, Selection.size());
+  EXPECT_EQ("/b", Selection[0].gccSuffix());
+
+  Selection = MS.select({"y", "x"});
+  ASSERT_EQ(2u, Selection.size());
+  EXPECT_EQ("/a", Selection[0].gccSuffix());
+  EXPECT_EQ("/b", Selection[1].gccSuffix());
+}
Index: clang/unittests/Driver/MultilibBuilderTest.cpp
===
--- clang/unittests/Driver/MultilibBuilderTest.cpp
+++ clang/unittests/Driver/MultilibBuilderTest.cpp
@@ -157,14 +157,14 @@
 .Maybe(MultilibBuilder("64").flag("+m64"))
 .makeMultilibSet();
 
-  Multilib::flags_list FlagM64 = {"+m64"};
+  Multilib::flag_set FlagM64 = {"+m64"};
   Multilib SelectionM64;
   ASSERT_TRUE(MS1.select(FlagM64, SelectionM64))
   << "Flag set was {\"+m64\"}, but selection not found";
   ASSERT_TRUE(SelectionM64.gccSuffix() == "/64")
   << "Selection picked " << SelectionM64 << " which was not expected";
 
-  Multilib::flags_list FlagNoM64 = {"-m64"};
+  Multilib::flag_set FlagNoM64 = {"-m64"};
   Multilib SelectionNoM64;
   ASSERT_TRUE(MS1.select(FlagNoM64, SelectionNoM64))
   << 

[PATCH] D142905: [Driver] Change multilib selection algorithm

2023-02-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added inline comments.



Comment at: clang/include/clang/Driver/Multilib.h:41
+  flag_set Flags;
+  arg_list PrintArgs;
 

phosek wrote:
> This is just a suggestion, but GCC documentation refers to these as either 
> "options" or "switches", not "args" so I think it might be helpful to use the 
> same nomenclature. This would also avoid confusion since the term "args" is 
> used extensively throughout the driver but refers to input arguments.
OK, I've gone with "options" just because `switch_list` would be an unintuitive 
name.



Comment at: clang/lib/Driver/MultilibBuilder.cpp:90-93
+  for (StringRef Flag : Flags) {
+if (Flag.front() == '+')
+  Args.push_back(("-" + Flag.substr(1)).str());
+  }

phosek wrote:
> If I understand this correctly, we might end up with duplicate arguments in 
> the case when `Flags` contains duplicate elements. Is that desirable? 
> Wouldn't it be better to construct the list of arguments from the set of fags 
> inside `Multilib`?
Yes, you can have duplicate options if you write code to do that. The Multilib 
class has never previously had any functionality to remove duplicate options so 
I'd rather not change that. Previously if you wrote code that added the same 
option twice then `clang -print-multi-lib` would reflect that. This behaviour 
remains unchanged.

No, you can't construct the list of options from the set of flags inside 
`Multilib` because `Multilib`'s flags are not command line options. (They will 
typically look similar to command line options but there's no requirement for 
that to be the case). I've added comments here and for the flags() method to 
hopefully make this clearer. Hopefully the docs in D143587 will also make 
things clearer for anyone else trying to reason about the multilib system.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142905

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


[PATCH] D144170: [clang-format] Add simple macro replacements in formatting.

2023-02-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks, this all looks good, at least as far as I understand it! The 
two-passes-over-the-whole-file approach is easier for me to follow, too.

Mostly just comment nits, but I have one annoying question left about using 
macros with the wrong arity - I thought this was just an implementation 
limitation, but it sounds like you want it to be a feature, so I'd like to nail 
it down a little...




Comment at: clang/include/clang/Format/Format.h:2750
+  ///
+  /// Code will be parsed with macros expanded, and formatting will try to best
+  /// match the structure of the expanded call.

I find "try to match the structure of the expanded call" a bit hard to follow 
from a user perspective.

Maybe "Code will be parsed with macros expanded, in order to determine how to 
interpret and format the macro arguments"?



Comment at: clang/include/clang/Format/Format.h:2753
+  ///
+  /// For example, with the macro "A(x)=x", the code
+  /// \code

This is a good example. I think you should spell out both sides, and probably 
start with the simpler case (no macro definition) to motivate the problem.

```
For example, the code:
  A(a*b);
will usually be interpreted as a call to a function A, and the multiplication 
expression will be formatted as `a * b`.

If we specify the macro definition:
  Macros:
- A(x)=x

the code will now be parsed as a declaration of the variable b of type a*,
and formatted as `a* b` (depending on pointer-binding rules).
```



Comment at: clang/include/clang/Format/Format.h:2757
+  /// \endcode
+  /// will be formatted as a declaration of the variable \c b of type \c A*
+  /// (depending on pointer-binding rules)

type a*, not A*



Comment at: clang/include/clang/Format/Format.h:2762
+  /// \endcode
+  /// instead of as multiplication.
+  std::vector Macros;

I think the restrictions should be spelled out here: object-like and 
function-like macros are both supported, macro args should be used exactly 
once, macros should not reference other macros.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:225
+  }
+  Callback.finishRun();
+}

klimek wrote:
> sammccall wrote:
> > I'm sure you got this right, but it's hard for me to evaluate this code 
> > because I don't know what `UnwrappedLineConsumer::finishRun()` is for - 
> > it's not documented and the implementation is mysterious.
> > 
> > You might consider adding a comment to that interface/method, it's not 
> > really related to this change though.
> Done. Not sure I've put too much info about how it's going to be used into 
> the interface, where it doesn't really belong.
Thanks, comment seems just right to me.



Comment at: clang/lib/Format/UnwrappedLineParser.h:88
+/// - for different combinations of #if blocks
+/// - for code where macros are expanded and the code with the original
+///   macro calls.

this is a bit of a garden path sentence: `for code where ((macros are expanded) 
and (the code with (the original macro calls) ... ERR_MISSING_PREDICATE))`

maybe `when macros are involved, for the expanded code and the as-written code`?



Comment at: clang/lib/Format/UnwrappedLineParser.h:260
+  // was expanded from a macro call.
+  bool containsExpansion(const UnwrappedLine &Line);
+

nit: should these added functions be const?

(maybe this class doesn't bother with const - computePPHash is const though)



Comment at: clang/unittests/Format/FormatTest.cpp:22584
+  Style.Macros.push_back("CALL(x)=f([] { x })");
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a = (b) || (c)");
+

klimek wrote:
> sammccall wrote:
> > If this is assign_or_return, the treatment of "c" is fairly strange. Also 
> > you are mostly calling this with only two args. Maybe drop C and use a 
> > different macro for the 3-arg case?
> ASSIGN_OR_RETURN allows 3 args, though; this is basically the thing I'd 
> propose to configure for ASSIGN_OR_RETURN in general; is there anything 
> specific you don't like about this?
OK, this is a bit sticky.
 - `ASSIGN_OR_RETURN` is almost always called with two args
 - some versions of `ASSIGN_OR_RETURN` support an optional third arg (there's 
no canonical public version)
 - these emulate overloading using variadic macro tricks
 - this patch doesn't claim to support either variadic macros or overloading

So the principled options seem to be:
 - macros have fixed arity: clang-format can support the two-arg version of 
`ASSIGN_OR_RETURN` but not the three-arg version. (This is what I was assuming)
 - macros have variable arity: the public docs need to describe how passing too 
many/too few args is treated, because this isn't obvious and it sounds like we 
want people to rely on it. This feels like stretching "principled" to me - 

[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

One more thing I noticed, this check can be in conflict with 
performance-move-const-arg.

  warning: std::move of the variable 'xyz' of the trivially-copyable type 
'types::xyz' has no effect; remove std::move() [performance-move-const-arg]

so would be nice to make sure that  trivially-copyable types are ignored.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D142934: clang: Use ptrmask for pointer alignment

2023-02-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 499797.
arsenm added a comment.

Test updates


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

https://reviews.llvm.org/D142934

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/PowerPC/ppc-varargs-struct.c
  clang/test/CodeGen/arm-abi-vector.c
  clang/test/CodeGen/arm-varargs.c
  clang/test/CodeGen/arm64-abi-vector.c
  clang/test/CodeGen/x86_32-align-linux.c

Index: clang/test/CodeGen/x86_32-align-linux.c
===
--- clang/test/CodeGen/x86_32-align-linux.c
+++ clang/test/CodeGen/x86_32-align-linux.c
@@ -9,10 +9,8 @@
 
 // CHECK-LABEL: define dso_local void @testm128
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 15
-// CHECK-NEXT:  %2 = and i32 %1, -16
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 15
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -16)
 void testm128(int argCount, ...) {
   __m128 res;
   __builtin_va_list args;
@@ -23,10 +21,8 @@
 
 // CHECK-LABEL: define dso_local void @testm256
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 31
-// CHECK-NEXT:  %2 = and i32 %1, -32
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 31
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -32)
 void testm256(int argCount, ...) {
   __m256 res;
   __builtin_va_list args;
@@ -37,10 +33,8 @@
 
 // CHECK-LABEL: define dso_local void @testm512
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 63
-// CHECK-NEXT:  %2 = and i32 %1, -64
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 63
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -64)
 void testm512(int argCount, ...) {
   __m512 res;
   __builtin_va_list args;
Index: clang/test/CodeGen/arm64-abi-vector.c
===
--- clang/test/CodeGen/arm64-abi-vector.c
+++ clang/test/CodeGen/arm64-abi-vector.c
@@ -94,8 +94,9 @@
 double varargs_vec_9c(int fixed, ...) {
 // CHECK: varargs_vec_9c
 // CHECK: alloca <9 x i8>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -153,8 +154,9 @@
 double varargs_vec_5s(int fixed, ...) {
 // CHECK: varargs_vec_5s
 // CHECK: alloca <5 x i16>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -174,8 +176,9 @@
 double varargs_vec_3i(int fixed, ...) {
 // CHECK: varargs_vec_3i
 // CHECK: alloca <3 x i32>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -244,8 +247,11 @@
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_CUR:%.*]], i64 8
   sum = sum + c5.x + c5.y;
   __char9 c9 = va_arg(ap, __char9);
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+
+
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   sum = sum + c9.x + c9.y;
   __char19 c19 = va_arg(ap, __char19);
@@ -256,13 +262,17 @@
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_CUR:%.*]], i64 8
   sum = sum + s3.x + s3.y;
   __short5 s5 = va_arg(ap, __short5);
-// CHECK: [[ALIGN:%.*]] = and i64 {

[PATCH] D142934: clang: Use ptrmask for pointer alignment

2023-02-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 499798.

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

https://reviews.llvm.org/D142934

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/PowerPC/ppc-varargs-struct.c
  clang/test/CodeGen/arm-abi-vector.c
  clang/test/CodeGen/arm-varargs.c
  clang/test/CodeGen/arm64-abi-vector.c
  clang/test/CodeGen/x86_32-align-linux.c

Index: clang/test/CodeGen/x86_32-align-linux.c
===
--- clang/test/CodeGen/x86_32-align-linux.c
+++ clang/test/CodeGen/x86_32-align-linux.c
@@ -9,10 +9,8 @@
 
 // CHECK-LABEL: define dso_local void @testm128
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 15
-// CHECK-NEXT:  %2 = and i32 %1, -16
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 15
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -16)
 void testm128(int argCount, ...) {
   __m128 res;
   __builtin_va_list args;
@@ -23,10 +21,8 @@
 
 // CHECK-LABEL: define dso_local void @testm256
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 31
-// CHECK-NEXT:  %2 = and i32 %1, -32
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 31
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -32)
 void testm256(int argCount, ...) {
   __m256 res;
   __builtin_va_list args;
@@ -37,10 +33,8 @@
 
 // CHECK-LABEL: define dso_local void @testm512
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 63
-// CHECK-NEXT:  %2 = and i32 %1, -64
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 63
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -64)
 void testm512(int argCount, ...) {
   __m512 res;
   __builtin_va_list args;
Index: clang/test/CodeGen/arm64-abi-vector.c
===
--- clang/test/CodeGen/arm64-abi-vector.c
+++ clang/test/CodeGen/arm64-abi-vector.c
@@ -94,8 +94,9 @@
 double varargs_vec_9c(int fixed, ...) {
 // CHECK: varargs_vec_9c
 // CHECK: alloca <9 x i8>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -153,8 +154,9 @@
 double varargs_vec_5s(int fixed, ...) {
 // CHECK: varargs_vec_5s
 // CHECK: alloca <5 x i16>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -174,8 +176,9 @@
 double varargs_vec_3i(int fixed, ...) {
 // CHECK: varargs_vec_3i
 // CHECK: alloca <3 x i32>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -244,8 +247,11 @@
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_CUR:%.*]], i64 8
   sum = sum + c5.x + c5.y;
   __char9 c9 = va_arg(ap, __char9);
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+
+
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   sum = sum + c9.x + c9.y;
   __char19 c19 = va_arg(ap, __char19);
@@ -256,13 +262,17 @@
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_CUR:%.*]], i64 8
   sum = sum + s3.x + s3.y;
   __short5 s5 = va_arg(ap, __short5);
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]]

[PATCH] D142934: clang: Use ptrmask for pointer alignment

2023-02-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 499799.

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

https://reviews.llvm.org/D142934

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/PowerPC/ppc-varargs-struct.c
  clang/test/CodeGen/arm-abi-vector.c
  clang/test/CodeGen/arm-vaarg-align.c
  clang/test/CodeGen/arm-varargs.c
  clang/test/CodeGen/arm64-abi-vector.c
  clang/test/CodeGen/x86_32-align-linux.c

Index: clang/test/CodeGen/x86_32-align-linux.c
===
--- clang/test/CodeGen/x86_32-align-linux.c
+++ clang/test/CodeGen/x86_32-align-linux.c
@@ -9,10 +9,8 @@
 
 // CHECK-LABEL: define dso_local void @testm128
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 15
-// CHECK-NEXT:  %2 = and i32 %1, -16
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 15
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -16)
 void testm128(int argCount, ...) {
   __m128 res;
   __builtin_va_list args;
@@ -23,10 +21,8 @@
 
 // CHECK-LABEL: define dso_local void @testm256
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 31
-// CHECK-NEXT:  %2 = and i32 %1, -32
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 31
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -32)
 void testm256(int argCount, ...) {
   __m256 res;
   __builtin_va_list args;
@@ -37,10 +33,8 @@
 
 // CHECK-LABEL: define dso_local void @testm512
 // CHECK-LABEL: %argp.cur = load ptr, ptr %args, align 4
-// CHECK-NEXT:  %0 = ptrtoint ptr %argp.cur to i32
-// CHECK-NEXT:  %1 = add i32 %0, 63
-// CHECK-NEXT:  %2 = and i32 %1, -64
-// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to ptr
+// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %argp.cur, i32 63
+// CHECK-NEXT: %argp.cur.aligned = call ptr @llvm.ptrmask.p0.i32(ptr %0, i32 -64)
 void testm512(int argCount, ...) {
   __m512 res;
   __builtin_va_list args;
Index: clang/test/CodeGen/arm64-abi-vector.c
===
--- clang/test/CodeGen/arm64-abi-vector.c
+++ clang/test/CodeGen/arm64-abi-vector.c
@@ -94,8 +94,9 @@
 double varargs_vec_9c(int fixed, ...) {
 // CHECK: varargs_vec_9c
 // CHECK: alloca <9 x i8>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -153,8 +154,9 @@
 double varargs_vec_5s(int fixed, ...) {
 // CHECK: varargs_vec_5s
 // CHECK: alloca <5 x i16>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -174,8 +176,9 @@
 double varargs_vec_3i(int fixed, ...) {
 // CHECK: varargs_vec_3i
 // CHECK: alloca <3 x i32>, align 16
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   va_list ap;
   double sum = fixed;
@@ -244,8 +247,11 @@
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_CUR:%.*]], i64 8
   sum = sum + c5.x + c5.y;
   __char9 c9 = va_arg(ap, __char9);
-// CHECK: [[ALIGN:%.*]] = and i64 {{%.*}}, -16
-// CHECK: [[AP_ALIGN:%.*]] = inttoptr i64 [[ALIGN]] to ptr
+
+
+// CHECK: [[AP:%.*]] = load ptr, ptr %ap, align 8
+// CHECK: [[AP_ADD:%.*]] = getelementptr inbounds i8, ptr [[AP]], i32 15
+// CHECK: [[AP_ALIGN:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[AP_ADD]], i64 -16)
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_ALIGN]], i64 16
   sum = sum + c9.x + c9.y;
   __char19 c19 = va_arg(ap, __char19);
@@ -256,13 +262,17 @@
 // CHECK: [[AP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[AP_CUR:%.*]], i64 8
   sum = sum + s3.x + s3.y;
   __short5 s5 = va_arg(ap, __short5);
-// CHECK: [[ALIGN:%.*]] = and i64 {

[PATCH] D141215: [clang-repl][WIP] Implement pretty printing

2023-02-23 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 499801.
junaire added a comment.

Update tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -18,6 +19,8 @@
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h" // llvm_shutdown
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h" // llvm::Initialize*
@@ -66,6 +69,29 @@
   return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+static void DeclareMagicFunctions(clang::Interpreter &Interp) {
+  std::vector MagicFunctions = {
+  "void __InterpreterCreateValue(void*, void*, bool);",
+  "void __InterpreterCreateValue(void*, void*, char);",
+  "void __InterpreterCreateValue(void*, void*, signed char);",
+  "void __InterpreterCreateValue(void*, void*, short);",
+  "void __InterpreterCreateValue(void*, void*, int);",
+  "void __InterpreterCreateValue(void*, void*, long);",
+  "void __InterpreterCreateValue(void*, void*, long long);",
+  "void __InterpreterCreateValue(void*, void*, unsigned char);",
+  "void __InterpreterCreateValue(void*, void*, unsigned short);",
+  "void __InterpreterCreateValue(void*, void*, unsigned int);",
+  "void __InterpreterCreateValue(void*, void*, unsigned long);",
+  "void __InterpreterCreateValue(void*, void*, unsigned long long);",
+  "void __InterpreterCreateValue(void*, void*, float);",
+  "void __InterpreterCreateValue(void*, void*, double);",
+  "void __InterpreterCreateValue(void*, void*, void*);"};
+
+  for (llvm::StringRef Function : MagicFunctions) {
+llvm::cantFail(Interp.ParseAndExecute(Function));
+  }
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -110,6 +136,7 @@
 
   bool HasError = false;
 
+  DeclareMagicFunctions(*Interp);
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) a
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.21
+
+%quit
+
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -154,10 +154,20 @@
   return true;
 }
 
-bool Parser::ExpectAndConsumeSemi(unsigned DiagID, StringRef TokenUsed) {
+bool Parser::ExpectAndConsumeSemi(unsigned DiagID, StringRef TokenUsed,
+  bool IsTopExpr) {
   if (TryConsumeToken(tok::semi))
 return false;
 
+  // If this is in the incremental C++ mode, then it means we need to pretty
+  // print this expression. Thus, let's pretend we have this semi and continue
+  // parsing.
+  if (PP.isIncrementalProcessingEnabled() && IsTopExpr &&
+  DiagID == diag::err_expected_semi_after_expr) {
+setPrettyPrintMode();
+return false;
+  }
+
   if (Tok.is(tok::code_completion)) 

[PATCH] D140992: clang: Add __builtin_elementwise_fma

2023-02-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm marked an inline comment as done.
arsenm added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:2615
 QualType ArgTy = TheCall->getArg(0)->getType();
-QualType EltTy = ArgTy;
-
-if (auto *VecTy = EltTy->getAs())
-  EltTy = VecTy->getElementType();
-if (!EltTy->isFloatingType()) {
-  Diag(TheCall->getArg(0)->getBeginLoc(),
-   diag::err_builtin_invalid_arg_type)
-  << 1 << /* float ty*/ 5 << ArgTy;
-
+if (checkFPMathBuiltinElementType(*this, TheCall->getArg(0)->getBeginLoc(),
+  ArgTy, 1))

aaron.ballman wrote:
> arsenm wrote:
> > bob80905 wrote:
> > > This change appears to allow more types (such as integers) as args for 
> > > this set of builtins in the above cases, where before the behavior was to 
> > > just allow floats.
> > > Is this intended behavior?
> > > 
> > No? test/Sema/builtins-elementwise-math.c already checks all of these 
> > reject integers and passes
> As best I can tell, it actually allows *less* types. The old code was calling 
> `!EltTy->isFloatingType()` and the new code is calling 
> `!EltTy->isRealFloatingType()`, so the old code would allow a complex float 
> while the new code prohibits it. Is that intentional?
> 
> We should add some explicit test coverage for how these builtins work with 
> complex types.
There already are complex tests for these. For some reason the type check was 
split between here and checkMathBuiltinElementType through 
PrepareBuiltinElementwiseMathOneArgCall



Comment at: clang/lib/Sema/SemaChecking.cpp:17761-17766
+  for (int I = 0; I < 3; ++I) {
+ExprResult Converted = UsualUnaryConversions(TheCall->getArg(I));
+if (Converted.isInvalid())
+  return true;
+Args[I] = Converted.get();
+  }

aaron.ballman wrote:
> This will cause conversions to happen *before* we check whether the types are 
> the same; is that expected? e.g., it seems like this would allow you to pass 
> a float and a double and thanks to the magic of usual unary conversions they 
> both come out as double and thus don't get diagnosed.
The tests say that isn't happening, e.g. here:


```

  f32 = __builtin_elementwise_fma(f64, f32, f32);
  // expected-error@-1 {{arguments are of different types ('double' vs 
'float')}}

  f32 = __builtin_elementwise_fma(f32, f64, f32);
  // expected-error@-1 {{arguments are of different types ('float' vs 
'double')}}

```


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

https://reviews.llvm.org/D140992

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


[PATCH] D141215: [clang-repl][WIP] Implement pretty printing

2023-02-23 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 499804.
junaire added a comment.

Rename the interface.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -18,6 +19,8 @@
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h" // llvm_shutdown
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h" // llvm::Initialize*
@@ -66,6 +69,29 @@
   return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+static void DeclareMagicFunctions(clang::Interpreter &Interp) {
+  std::vector MagicFunctions = {
+  "void __InterpreterSetValueNoAlloc(void*, void*, bool);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, signed char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, long long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, unsigned char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, unsigned short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, unsigned int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, unsigned long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, unsigned long long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, float);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, double);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*);"};
+
+  for (llvm::StringRef Function : MagicFunctions) {
+llvm::cantFail(Interp.ParseAndExecute(Function));
+  }
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -110,6 +136,7 @@
 
   bool HasError = false;
 
+  DeclareMagicFunctions(*Interp);
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) a
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.21
+
+%quit
+
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -154,10 +154,20 @@
   return true;
 }
 
-bool Parser::ExpectAndConsumeSemi(unsigned DiagID, StringRef TokenUsed) {
+bool Parser::ExpectAndConsumeSemi(unsigned DiagID, StringRef TokenUsed,
+  bool IsTopExpr) {
   if (TryConsumeToken(tok::semi))
 return false;
 
+  // If this is in the incremental C++ mode, then it means we need to pretty
+  // print this expression. Thus, let's pretend we have this semi and continue
+  // parsing.
+  if (PP.isIncrementalProcessingEnabled() && IsTopExpr &&
+  DiagID == diag::err_expected_semi_after_expr) {
+setPrettyPrintMod

[PATCH] D140992: clang: Add __builtin_elementwise_fma

2023-02-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 499805.
arsenm added a comment.

Loop merge, documentation


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

https://reviews.llvm.org/D140992

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

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -4,6 +4,8 @@
 typedef double double4 __attribute__((ext_vector_type(4)));
 typedef float float2 __attribute__((ext_vector_type(2)));
 typedef float float4 __attribute__((ext_vector_type(4)));
+
+typedef int int2 __attribute__((ext_vector_type(2)));
 typedef int int3 __attribute__((ext_vector_type(3)));
 typedef unsigned unsigned3 __attribute__((ext_vector_type(3)));
 typedef unsigned unsigned4 __attribute__((ext_vector_type(4)));
@@ -572,3 +574,84 @@
   float2 tmp9 = __builtin_elementwise_copysign(v4f32, v4f32);
   // expected-error@-1 {{initializing 'float2' (vector of 2 'float' values) with an expression of incompatible type 'float4' (vector of 4 'float' values)}}
 }
+
+void test_builtin_elementwise_fma(int i32, int2 v2i32, short i16,
+  double f64, double2 v2f64, double2 v3f64,
+  float f32, float2 v2f32, float v3f32, float4 v4f32,
+  const float4 c_v4f32,
+  int3 v3i32, int *ptr) {
+
+  f32 = __builtin_elementwise_fma();
+  // expected-error@-1 {{too few arguments to function call, expected 3, have 0}}
+
+  f32 = __builtin_elementwise_fma(f32);
+  // expected-error@-1 {{too few arguments to function call, expected 3, have 1}}
+
+  f32 = __builtin_elementwise_fma(f32, f32);
+  // expected-error@-1 {{too few arguments to function call, expected 3, have 2}}
+
+  f32 = __builtin_elementwise_fma(f32, f32, f32, f32);
+  // expected-error@-1 {{too many arguments to function call, expected 3, have 4}}
+
+  f32 = __builtin_elementwise_fma(f64, f32, f32);
+  // expected-error@-1 {{arguments are of different types ('double' vs 'float')}}
+
+  f32 = __builtin_elementwise_fma(f32, f64, f32);
+  // expected-error@-1 {{arguments are of different types ('float' vs 'double')}}
+
+  f32 = __builtin_elementwise_fma(f32, f32, f64);
+  // expected-error@-1 {{arguments are of different types ('float' vs 'double')}}
+
+  f32 = __builtin_elementwise_fma(f32, f32, f64);
+  // expected-error@-1 {{arguments are of different types ('float' vs 'double')}}
+
+  f64 = __builtin_elementwise_fma(f64, f32, f32);
+  // expected-error@-1 {{arguments are of different types ('double' vs 'float')}}
+
+  f64 = __builtin_elementwise_fma(f64, f64, f32);
+  // expected-error@-1 {{arguments are of different types ('double' vs 'float')}}
+
+  f64 = __builtin_elementwise_fma(f64, f32, f64);
+  // expected-error@-1 {{arguments are of different types ('double' vs 'float')}}
+
+  v2f64 = __builtin_elementwise_fma(v2f32, f64, f64);
+  // expected-error@-1 {{arguments are of different types ('float2' (vector of 2 'float' values) vs 'double'}}
+
+  v2f64 = __builtin_elementwise_fma(v2f32, v2f64, f64);
+  // expected-error@-1 {{arguments are of different types ('float2' (vector of 2 'float' values) vs 'double2' (vector of 2 'double' values)}}
+
+  v2f64 = __builtin_elementwise_fma(v2f32, f64, v2f64);
+  // expected-error@-1 {{arguments are of different types ('float2' (vector of 2 'float' values) vs 'double'}}
+
+  v2f64 = __builtin_elementwise_fma(f64, v2f32, v2f64);
+  // expected-error@-1 {{arguments are of different types ('double' vs 'float2' (vector of 2 'float' values)}}
+
+  v2f64 = __builtin_elementwise_fma(f64, v2f64, v2f64);
+  // expected-error@-1 {{arguments are of different types ('double' vs 'double2' (vector of 2 'double' values)}}
+
+  i32 = __builtin_elementwise_fma(i32, i32, i32);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  v2i32 = __builtin_elementwise_fma(v2i32, v2i32, v2i32);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int2' (vector of 2 'int' values))}}
+
+  f32 = __builtin_elementwise_fma(f32, f32, i32);
+  // expected-error@-1 {{3rd argument must be a floating point type (was 'int')}}
+
+  f32 = __builtin_elementwise_fma(f32, i32, f32);
+  // expected-error@-1 {{2nd argument must be a floating point type (was 'int')}}
+
+  f32 = __builtin_elementwise_fma(f32, f32, i32);
+  // expected-error@-1 {{3rd argument must be a floating point type (was 'int')}}
+
+
+  _Complex float c1, c2, c3;
+  c1 = __builtin_elementwise_fma(c1, f32, f32);
+  // expected-error@-1 {{1st argument must be a floating point type (was '_Complex float')}}
+
+  c2 = __builtin_

[PATCH] D144638: [lit] Detect Consistent File Access Times

2023-02-23 Thread Sam Elliott via Phabricator via cfe-commits
lenary created this revision.
Herald added subscribers: pmatos, asb, ormris, steven_wu, delcypher, hiraditya, 
sbc100, emaste.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: jhenderson.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
lenary requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay, aheejin.
Herald added projects: clang, LLVM.

I was seeing flaky tests in my builds due to another process (in my
case, antivirus) modifying the access time of files during the tests,
so those tests using `touch -a` were failing.

This change modifies how we check if a system has consistent atime.
Instead of a list of platforms where we know things might not work, we
instead perform a check similar to the ones used in the tests, but on a
temporary file. If the check is successful, then you get a
`consistent-atime` feature which you can make your test REQUIRE.

This updates all existing tests which mention atime or use `touch -a` to
`REQUIRE: consistent-atime`, fixing their flakiness.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144638

Files:
  clang/test/Modules/prune.m
  lld/test/COFF/lto-cache.ll
  lld/test/ELF/lto/cache.ll
  lld/test/MachO/lto-cache.ll
  lld/test/wasm/lto/cache.ll
  llvm/test/ThinLTO/X86/cache.ll
  llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
  llvm/utils/lit/lit/llvm/config.py

Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -5,6 +5,7 @@
 import subprocess
 import sys
 import errno
+import tempfile
 
 import lit.util
 from lit.llvm.subst import FindTool
@@ -155,6 +156,30 @@
 self.with_environment(
 'DYLD_INSERT_LIBRARIES', gmalloc_path_str)
 
+if self._has_consistent_atime():
+features.add('consistent-atime')
+
+# - NetBSD: noatime mounts currently inhibit 'touch -a' updates.
+# - Windows: the last access time is disabled by default in the OS.
+#
+# This check hopefully detects both cases, and disables tests that require
+# consistent atime.
+def _has_consistent_atime(self):
+with tempfile.NamedTemporaryFile() as f:
+# Specific date in the past on purpose, based on what is attempted
+# in the tests that do the same thing.
+(_, try_touch_err) = self.get_process_output(["touch", "-a", "-t", "199505050555.55", f.name])
+if try_touch_err != "":
+return False
+
+(touch_res_out, touch_res_err) = self.get_process_output(["ls", "-lu", f.name])
+if touch_res_err != "":
+return False
+if "1995" not in touch_res_out:
+return False
+
+return True
+
 def _find_git_windows_unix_tools(self, tools_needed):
 assert(sys.platform == 'win32')
 if sys.version_info.major >= 3:
Index: llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
===
--- llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
+++ llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
@@ -1,7 +1,5 @@
 # Note: ls -lu prints the accessed timestamp
-# NetBSD: noatime mounts currently inhibit 'touch -a' updates
-# Windows: the last access time is disabled by default in the OS
-# UNSUPPORTED: system-netbsd, system-windows
+# REQUIRES: consistent-atime
 
 # Preserve dates when stripping to an output file.
 # RUN: yaml2obj %s -o %t.1.o
Index: llvm/test/ThinLTO/X86/cache.ll
===
--- llvm/test/ThinLTO/X86/cache.ll
+++ llvm/test/ThinLTO/X86/cache.ll
@@ -1,5 +1,4 @@
-; NetBSD: noatime mounts currently inhibit 'touch -a' updates
-; UNSUPPORTED: system-netbsd
+; REQUIRES: consistent-atime
 
 ; The .noindex suffix for output dir is to prevent Spotlight on macOS from
 ; indexing it.
Index: lld/test/wasm/lto/cache.ll
===
--- lld/test/wasm/lto/cache.ll
+++ lld/test/wasm/lto/cache.ll
@@ -1,8 +1,6 @@
 ; RUN: opt -module-hash -module-summary %s -o %t.o
 ; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
-; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
-; Windows: no 'touch' command.
-; UNSUPPORTED: system-netbsd, system-windows
+; REQUIRES: consistent-atime
 
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; Create two files that would be removed by cache pruning due to age.
Index: lld/test/MachO/lto-cache.ll
===
--- lld/test/MachO/lto-cache.ll
+++ lld/test/MachO/lto-cache.ll
@@ -1,6 +1,5 @@
 ; REQUIRES: x86
-; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
-; UNSUPPORTED: system-netbsd
+; REQUIRES: consistent-atime
 
 ; RUN: rm -r

[PATCH] D144638: [lit] Detect Consistent File Access Times

2023-02-23 Thread Sam Elliott via Phabricator via cfe-commits
lenary added reviewers: simonwallis2, mgorny.
lenary added a subscriber: mgorny.
lenary added a comment.

Adding more reviewers. @mgorny you disabled some tests on NetBSD in the past 
for the same reason (rG92dc7dce4a6f117a497ced1650bc48e5b658f0ea 
), this 
just updates how they were disabled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144638

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


[PATCH] D144638: [lit] Detect Consistent File Access Times

2023-02-23 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

This looks reasonable to me, with the caveat that I don't know a huge amount 
about how the different OSes access time systems work. One question though: if 
your antivirus was causing flakiness (as opposed to outright always-fails), 
won't it just move that flakiness into whether the REQUIRES calculation returns 
true or not (i.e. it could spuriously do so, causing the tests to be enabled 
but then potential still be flaky?




Comment at: llvm/utils/lit/lit/llvm/config.py:165
+#
+# This check hopefully detects both cases, and disables tests that require
+# consistent atime.

Is "hopefully" really needed here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144638

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


[PATCH] D143984: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-02-23 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez added inline comments.



Comment at: llvm/lib/IR/DIBuilder.cpp:789
+  return createLocalVariable(
+  VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
+  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);

krisb wrote:
> jmmartinez wrote:
> > I'll be tempted to move the call to 
> > `getSubprogramNodesTrackingVector(Scope)` into `createLocalVariable`. It 
> > seems that every time `createLocalVariable` is called, 
> > `getSubprogramNodesTrackingVector(Scope)` is passed as value for 
> > `PreservedNodes`.
> > 
> > (I've just started reviewing so I may be missing some other modifications)
> That's right, but the problem is in the fact that `createLocalVariable()` is 
> static while `getSubprogramNodesTrackingVector()` is a DIBuilder's member. To 
> move the call inside `createLocalVariable()` we need either to make it a 
> member of DIBuilder or to pass DIBuilder object to it. None of these options 
> looks much better to me, honestly. 
You're right. I didn't realize createLocalVariable was not a member of 
DIBuilder.

Ok for me to keep it as it .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143984

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


[PATCH] D144572: [C++20] Stop claiming full support for consteval (for the moment!)

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D144572#4145634 , @royjacobson 
wrote:

> In D144572#4145614 , @cor3ntin 
> wrote:
>
>> @aaron.ballman is the plan to backport that to clang 16? I think it probably 
>> should.
>> We ought to try to improve the situation for clang 17
>
> cxx_status.html is always updated from trunk, no? I don't think we need to 
> bother with backporting if that's the case

Correct, that only reflects what's happening on trunk, so the only thing we 
could backport from this is the extra test coverage (doesn't seem worth 
porting, IMO).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144572

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


[clang] e328d68 - [C++20] Stop claiming full support for consteval (for the moment!)

2023-02-23 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-02-23T07:41:35-05:00
New Revision: e328d68d5ba1fe365c36655b8ae287928da6d3ed

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

LOG: [C++20] Stop claiming full support for consteval (for the moment!)

During Clang 15, 3d2629dd3aab17098813c68b5b76bb864bc5e285 claimed we
achieved full support for consteval in C++20. However, further testing
shows that Clang doesn't correctly handle all of the examples from
https://wg21.link/P1073R3 and has several other known issues that are
preventing us from defining the `__cpp_consteval` macro.

I think we should only claim Partial support for the moment. Once we
correct the major outstanding issues, then I think we should change the
status back to full support and define __cpp_consteval at the same time
(even if it's only to the 201811L value instead of the latest value
from C++2b). This helps users understand the support situation more
clearly.

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

Added: 
clang/test/CXX/expr/expr.const/p8-2a.cpp

Modified: 
clang/test/CXX/expr/expr.const/p6-2a.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/test/CXX/expr/expr.const/p6-2a.cpp 
b/clang/test/CXX/expr/expr.const/p6-2a.cpp
index 312c28354188d..2ef067c549003 100644
--- a/clang/test/CXX/expr/expr.const/p6-2a.cpp
+++ b/clang/test/CXX/expr/expr.const/p6-2a.cpp
@@ -41,3 +41,16 @@ struct Temporary {
   }
 };
 constexpr Temporary t = {3}; // expected-error {{must have constant 
destruction}} expected-note {{created here}} expected-note {{in call}}
+
+namespace P1073R3 {
+consteval int f() { return 42; } // expected-note 3 {{declared here}}
+consteval auto g() { return f; }
+// FIXME: there should be no diagnostics associated with either h() or r.
+consteval int h(int (*p)() = g()) { return p(); } // expected-error {{call to 
consteval function 'P1073R3::g' is not a constant expression}} \
+ expected-note {{declared 
here}} \
+ expected-note {{pointer 
to a consteval declaration is not a constant expression}}
+constexpr int r = h();   // expected-note {{in the default initalizer of 'p'}}
+constexpr auto e = g();  // expected-error {{call to consteval function 
'P1073R3::g' is not a constant expression}} \
+expected-error {{constexpr variable 'e' must be 
initialized by a constant expression}} \
+expected-note 2 {{pointer to a consteval 
declaration is not a constant expression}}
+} // namespace P1073R3

diff  --git a/clang/test/CXX/expr/expr.const/p8-2a.cpp 
b/clang/test/CXX/expr/expr.const/p8-2a.cpp
new file mode 100644
index 0..b8bee64b0aae2
--- /dev/null
+++ b/clang/test/CXX/expr/expr.const/p8-2a.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+// expected-no-diagnostics
+
+namespace P1073R3 {
+struct N {
+  constexpr N() {}
+  N(N const&) = delete;
+};
+
+template constexpr void bad_assert_copyable() { T t; T t2 = t; }
+using ineffective = decltype(bad_assert_copyable());
+
+// bad_assert_copyable is not needed for constant evaluation
+// (and thus not instantiated)
+template consteval void assert_copyable() { T t; T t2 = t; }
+using check = decltype(assert_copyable());
+// FIXME: this should give an error because assert_copyable is instantiated
+// (because it is needed for constant evaluation), but the attempt to copy t is
+// ill-formed.
+} // namespace P1073R3
+

diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index f93a788aa0d7a..c397b2ba25da1 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1120,7 +1120,14 @@ C++20 implementation status
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  Clang 15
+  
+Clang 15 (Partial)
+  Clang still incorrectly defers some consteval executions to runtime,
+  resulting in CodeGen crashes. Additionally, Clang does not properly
+  handle default arguments in consteval functions under all
+  circumstances.
+
+  
 

 https://wg21.link/p1937r2";>P1937R2



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


[PATCH] D144572: [C++20] Stop claiming full support for consteval (for the moment!)

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe328d68d5ba1: [C++20] Stop claiming full support for 
consteval (for the moment!) (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144572

Files:
  clang/test/CXX/expr/expr.const/p6-2a.cpp
  clang/test/CXX/expr/expr.const/p8-2a.cpp
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1120,7 +1120,14 @@
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  Clang 15
+  
+Clang 15 (Partial)
+  Clang still incorrectly defers some consteval executions to runtime,
+  resulting in CodeGen crashes. Additionally, Clang does not properly
+  handle default arguments in consteval functions under all
+  circumstances.
+
+  
 

 https://wg21.link/p1937r2";>P1937R2
Index: clang/test/CXX/expr/expr.const/p8-2a.cpp
===
--- /dev/null
+++ clang/test/CXX/expr/expr.const/p8-2a.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+// expected-no-diagnostics
+
+namespace P1073R3 {
+struct N {
+  constexpr N() {}
+  N(N const&) = delete;
+};
+
+template constexpr void bad_assert_copyable() { T t; T t2 = t; }
+using ineffective = decltype(bad_assert_copyable());
+
+// bad_assert_copyable is not needed for constant evaluation
+// (and thus not instantiated)
+template consteval void assert_copyable() { T t; T t2 = t; }
+using check = decltype(assert_copyable());
+// FIXME: this should give an error because assert_copyable is instantiated
+// (because it is needed for constant evaluation), but the attempt to copy t is
+// ill-formed.
+} // namespace P1073R3
+
Index: clang/test/CXX/expr/expr.const/p6-2a.cpp
===
--- clang/test/CXX/expr/expr.const/p6-2a.cpp
+++ clang/test/CXX/expr/expr.const/p6-2a.cpp
@@ -41,3 +41,16 @@
   }
 };
 constexpr Temporary t = {3}; // expected-error {{must have constant 
destruction}} expected-note {{created here}} expected-note {{in call}}
+
+namespace P1073R3 {
+consteval int f() { return 42; } // expected-note 3 {{declared here}}
+consteval auto g() { return f; }
+// FIXME: there should be no diagnostics associated with either h() or r.
+consteval int h(int (*p)() = g()) { return p(); } // expected-error {{call to 
consteval function 'P1073R3::g' is not a constant expression}} \
+ expected-note {{declared 
here}} \
+ expected-note {{pointer 
to a consteval declaration is not a constant expression}}
+constexpr int r = h();   // expected-note {{in the default initalizer of 'p'}}
+constexpr auto e = g();  // expected-error {{call to consteval function 
'P1073R3::g' is not a constant expression}} \
+expected-error {{constexpr variable 'e' must be 
initialized by a constant expression}} \
+expected-note 2 {{pointer to a consteval 
declaration is not a constant expression}}
+} // namespace P1073R3


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1120,7 +1120,14 @@
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  Clang 15
+  
+Clang 15 (Partial)
+  Clang still incorrectly defers some consteval executions to runtime,
+  resulting in CodeGen crashes. Additionally, Clang does not properly
+  handle default arguments in consteval functions under all
+  circumstances.
+
+  
 

 https://wg21.link/p1937r2";>P1937R2
Index: clang/test/CXX/expr/expr.const/p8-2a.cpp
===
--- /dev/null
+++ clang/test/CXX/expr/expr.const/p8-2a.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+// expected-no-diagnostics
+
+namespace P1073R3 {
+struct N {
+  constexpr N() {}
+  N(N const&) = delete;
+};
+
+template constexpr void bad_assert_copyable() { T t; T t2 = t; }
+using ineffective = decltype(bad_assert_copyable());
+
+// bad_assert_copyable is not needed for constant evaluation
+// (and thus not instantiated)
+template consteval void assert_copyable() { T t; T t2 = t; }
+using check = decltype(assert_copyable());
+// FIXME: this should give an error because assert_copyable is instantiated
+// (because it is needed for constant evaluation), but the attempt to copy t is
+// ill-formed.
+} // namespace P1073R3
+
Index: clang/test/CXX/expr/expr.const/p6-2a.cpp
===

[PATCH] D140562: [clang][ASTImporter] Improve import of InjectedClassNameType.

2023-02-23 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy accepted this revision.
donat.nagy added a comment.
This revision is now accepted and ready to land.

We reviewed this commit together with @gamesh411 and it looks good to us; we 
see that it eliminates a possibility where a type object could "acquire" 
multiple aliases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140562

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


[PATCH] D144613: [RISCV] Properly diagnose mixing RVV scalable vectors with GNU vectors.

2023-02-23 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes accepted this revision.
c-rhodes added a comment.
This revision is now accepted and ready to land.

One minor nit but otherwise LGTM




Comment at: clang/lib/Sema/SemaExpr.cpp:10769-10770
 
   // Expressions containing GNU and SVE (fixed or sizeless) vectors are invalid
   // since the ambiguity can affect the ABI.
+  auto IsSveRVVGnuConversion = [](QualType FirstType, QualType SecondType,

nit: update comment?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144613

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


[PATCH] D144218: [Clang] [AVR] Fix USHRT_MAX for 16-bit int.

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Headers/limits.h:55
 #define UCHAR_MAX (__SCHAR_MAX__*2  +1)
-#define USHRT_MAX (__SHRT_MAX__ *2  +1)
+#define USHRT_MAX (__SHRT_MAX__ * 2U + 1U)
 #define UINT_MAX  (__INT_MAX__  *2U +1U)

mysterymath wrote:
> aaron.ballman wrote:
> > It's worth double-checking that this still gives the correct type for the 
> > macro:
> > 
> > C2x 5.2.4.2.1p2: For all unsigned integer types for which  or 
> >  define a macro with suffix _WIDTH holding its width N, there is 
> > a macro with suffix _MAX holding the maximal value 2N − 1 that is 
> > representable by the type and that has the same type as would an expression 
> > that is an object of the corresponding type converted according to the 
> > integer promotions. ...
> Ah, thanks; it hadn't occurred to me that the type of the expression would be 
> specified in the standard. It could be either `unsigned int` or `int`, 
> depending on the target.
> 
> The most straightforward approach I could think of to produce the right type 
> is:
> 1) Perform the arithmetic in `unsigned int` to produce the right value
> 2) Cast to `unsigned short` to produce the right type
> 3) Directly perform integer promotion using unary plus
> 
> The use of unary plus is a bit odd here, but it seems like the most direct 
> way to express the logic, and the overall expression seems less fragile than 
> the `#if` alternative. I've added a comment to explain this as well.
Now the trouble is with the cast operation, because that runs afoul of 
5.2.4.2.1p1: The values given below shall be replaced by constant expressions 
suitable for use in conditional expression inclusion preprocessing directives. 
...

https://godbolt.org/z/K9cs66sdK

I'm almost wondering if the most direct solution is for `__SHRT_MAX__` to be 
generated with or without the `U` suffix depending on target.

We should probably use this as an opportunity to add more exhaustive testing 
for all the _MIN and _MAX macros to ensure the type properties hold. I was 
playing around with something like this: https://godbolt.org/z/o7KjY3asW


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144218

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


[PATCH] D144586: [PS4/PS5] Specify no or

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for double-checking on the atomics question!


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

https://reviews.llvm.org/D144586

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


[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

2023-02-23 Thread joanahalili via Phabricator via cfe-commits
joanahalili added a comment.

Heads up: We are experiencing a series of clang crashes because of this commit.

What we already have so far:

  Unhandled DeclRefExpr
  UNREACHABLE executed at clang/lib/CodeGen/CGExpr.cpp:2958!

We are now working on a reproducer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143840

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


[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

2023-02-23 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D144269#4143066 , @NoQ wrote:

> The challenging part with note tags is how do you figure out whether your bug 
> report is taint-related. The traditional solution is to check the `BugType` 
> but in this case an indeterminate amount of checkers may emit taint-related 
> reports.

Yeah, this is why we created a new type. Not sure what is the better 
infrastructure design, whether to create a subtype of `BugType` or `BugReport`, 
but it fundamentally achieves the same thing.

In D144269#4146809 , @dkrupp wrote:

> My fear with the interestingness is that it may propagating backwards 
> according to different "rules" than whot the taintedness is popagating in the 
> foward direction even with the "extensions" pointed out by steakhal.
> So the two types of propagation may be or can get out of sync.
>
> So if the above is not a concern and you think implementing this with 
> interestingness is more elegant, idiomatic and causes less maintenance 
> burden, I am happy to create an alternative patch with that solution.

@dkrupp and I discussed in detail whether to use FlowID's (what is currently 
implemented in the patch) or something similar, or reuse interestingness. 
Here's why we decided against reusing interestiness as is.

Interestingness, as it stands now, mostly expresses data-dependency, and is 
propageted with using the analyzers usualy somewhat conservative approach. 
While the length of a string is strictly speaking data dependent on the actual 
string, I don't think analyzer currently understand that. We approach taint 
very differently, and propagete it in some sense more liberally.

As I best recall, however, interestingness may be propagated through other 
means as well. If we reused interestingness, I fear that the interestiness set 
could actually be greater than the actual //interesting tainted// set, causing 
more notes to be emitted than needed.

For these reasons, which I admit are a result of some speculation, we concluded 
that interstingness as it is and taint are two different properties that are 
best separated.

In D144269#4143066 , @NoQ wrote:

> I think now's a good time to include a "generic data map"-like data structure 
> in `PathSensitiveBugReport` objects, so that checkers could put some data 
> there during `emitReport()`, which can be picked up by note tags and 
> potentially mutated in the process.

Maybe a new interestingness kind (D65723 )? 
Not sure how this design aged, but we don't really need to store an ID for 
this, so a simple interestingness flag (just not the default `Thorough` 
interestiness) is good enough.

In D144269#4146809 , @dkrupp wrote:

> The tricky part was is to how to show only that single "Taint originated 
> here" note tag at the taint source only which is relevant to the report. This 
> is done by remembering the unique flowid in the
> NoteTag in the forward analysis direction (see GenericTaintChecker:cpp:859) 
> `InjectionTag = createTaintOriginTag(C, TaintFlowId);` and then filtering out 
> the irrelevant 
> NoteTags when the the report is generated (when the lamdba callback is 
> called). See that flowid which reaches the sink is backpropagated in the 
> PathSensitiveBugreport (see GenericTaintCHekcer.cpp:167).
>
> FlowIds are unique and increased at every taint source 
> (GenericTaintChecker:869) and it is stored as an additional simple `int` in 
> the program state along with the already existing (Taint.cpp:22) TaintTagType.

If you propagate this property during analysis, those IDs may be needed, but a 
simple flag should suffice when BugReporter does it.


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

https://reviews.llvm.org/D144269

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


[PATCH] D144641: [clangd] Set diag data before emitting

2023-02-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Also fixes a benign use-after-free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144641

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1012,6 +1013,7 @@
   D.Severity = DiagnosticsEngine::Error;
   D.File = "foo/bar/main.cpp";
   D.AbsFile = std::string(MainFile.file());
+  D.OpaqueData["test"] = "bar";
 
   clangd::Note NoteInMain;
   NoteInMain.Message = "declared somewhere in the main file";
@@ -1050,6 +1052,7 @@
 ../foo/baz/header.h:10:11:
 note: declared somewhere in the header file)";
   MainLSP.tags = {DiagnosticTag::Unnecessary};
+  MainLSP.data = D.OpaqueData;
 
   clangd::Diagnostic NoteInMainLSP;
   NoteInMainLSP.range = NoteInMain.Range;
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -526,6 +526,9 @@
 }
   }
   Main.tags = D.Tags;
+  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
+  for (auto &Entry : D.OpaqueData)
+Main.data.insert({Entry.first, Entry.second});
   OutFn(std::move(Main), D.Fixes);
 
   // If we didn't emit the notes as relatedLocations, emit separate diagnostics
@@ -540,10 +543,6 @@
   Res.message = noteMessage(D, Note, Opts);
   OutFn(std::move(Res), llvm::ArrayRef());
 }
-
-  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
-  for (auto &Entry : D.OpaqueData)
-Main.data.insert({Entry.first, Entry.second});
 }
 
 int getSeverity(DiagnosticsEngine::Level L) {


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1012,6 +1013,7 @@
   D.Severity = DiagnosticsEngine::Error;
   D.File = "foo/bar/main.cpp";
   D.AbsFile = std::string(MainFile.file());
+  D.OpaqueData["test"] = "bar";
 
   clangd::Note NoteInMain;
   NoteInMain.Message = "declared somewhere in the main file";
@@ -1050,6 +1052,7 @@
 ../foo/baz/header.h:10:11:
 note: declared somewhere in the header file)";
   MainLSP.tags = {DiagnosticTag::Unnecessary};
+  MainLSP.data = D.OpaqueData;
 
   clangd::Diagnostic NoteInMainLSP;
   NoteInMainLSP.range = NoteInMain.Range;
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -526,6 +526,9 @@
 }
   }
   Main.tags = D.Tags;
+  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
+  for (auto &Entry : D.OpaqueData)
+Main.data.insert({Entry.first, Entry.second});
   OutFn(std::move(Main), D.Fixes);
 
   // If we didn't emit the notes as relatedLocations, emit separate diagnostics
@@ -540,10 +543,6 @@
   Res.message = noteMessage(D, Note, Opts);
   OutFn(std::move(Res), llvm::ArrayRef());
 }
-
-  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
-  for (auto &Entry : D.OpaqueData)
-Main.data.insert({Entry.first, Entry.second});
 }
 
 int getSeverity(DiagnosticsEngine::Level L) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144627: [Clang] Fix a crash when taking the address of a consteval lambda

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM with a minor cleanup.




Comment at: clang/lib/Sema/SemaExpr.cpp:17976-17983
 auto *FD = cast(DR->getDecl());
-SemaRef.Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)
-<< FD;
+if (auto *MD = llvm::dyn_cast(FD);
+MD && (MD->isLambdaStaticInvoker() || isLambdaCallOperator(MD)))
+  SemaRef.Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)
+  << MD->getParent() << 1;
+else
+  SemaRef.Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)

Minor simplification, NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144627

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


[PATCH] D144616: Skip generating this[:1] map info for non-member variable.

2023-02-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144616

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-23 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

Trivial types should not be passed by rvalue reference, but by value per the 
diagram under 
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#fcall-parameter-passing.
 I feel like adding an option to opt-out of this is missing the point of this 
check, and rvalue references of trivial type should just be fixed rather than 
adding an option to permit them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D142934: clang: Use ptrmask for pointer alignment

2023-02-23 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

The `__builtin_align_{up,down}` code generation could also make use of this 
IIRC. I think the reason I didn't do this initially was concerns about ptrmask 
not being optimized as well.


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

https://reviews.llvm.org/D142934

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


[PATCH] D144638: [lit] Detect Consistent File Access Times

2023-02-23 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

In D144638#4147133 , @jhenderson 
wrote:

> This looks reasonable to me, with the caveat that I don't know a huge amount 
> about how the different OSes access time systems work. One question though: 
> if your antivirus was causing flakiness (as opposed to outright 
> always-fails), won't it just move that flakiness into whether the REQUIRES 
> calculation returns true or not (i.e. it could spuriously do so, causing the 
> tests to be enabled but then potential still be flaky?

I'm definitely not an expert in OS atimes either, beyond the comments that have 
accumulated in the repo so far, and knowing that some filesystems prefer to 
have it switched off for performance reasons.

The flakiness I (and colleagues) have seen seems to correspond to computer 
load. In my case, I think the underlying issue is a race between the `touch -a 
-t  ` (which in these test creates ``), then the `ls -ul 
`, and the antivirus, which is watching for file creation, and will also 
access the file. This is also one reason why I put "hopefully" in the comment - 
we're hoping to get the same race during lit configuration. One reason I think 
we're more likely to is that this code is run before we spin up lots of 
parallel threads to start testing, so the test machine should be under less 
load for this check, which should allow the antivirus to get in before the `ls 
-ul`, if all goes to plan (it's a race, so this is hard to be sure about).

I can see your point about this moving the flakiness, but I think that this 
check is more likely to fail in the other direction: marking the tests as 
unsupported when they might be ok. In that case, we lose coverage when we 
didn't need to.




Comment at: llvm/utils/lit/lit/llvm/config.py:165
+#
+# This check hopefully detects both cases, and disables tests that require
+# consistent atime.

jhenderson wrote:
> Is "hopefully" really needed here?
I'm hedging in this comment, in part because we're trying to find a race 
condition experimentally, and also because this will cause lit to fatal error 
before running any tests if `touch` exits non-zero for any reason. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144638

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


[PATCH] D142932: Multilib YAML parsing

2023-02-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 499824.
michaelplatings added a comment.

PrintArgs -> PrintOptions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142932

Files:
  clang/include/clang/Driver/Multilib.h
  clang/lib/Driver/Multilib.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/Driver/Multilib.h"
 #include "../../lib/Driver/ToolChains/CommonArgs.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/Version.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -187,3 +188,408 @@
   EXPECT_EQ("/a", Selection[0].gccSuffix());
   EXPECT_EQ("/b", Selection[1].gccSuffix());
 }
+
+static void diagnosticCallback(const llvm::SMDiagnostic &D, void *Out) {
+  *reinterpret_cast(Out) = D.getMessage();
+}
+
+static bool parse(MultilibSet &MS, std::string &Diagnostic, const char *Data) {
+  return MS.parse(llvm::MemoryBufferRef(Data, "TEST"), diagnosticCallback,
+  &Diagnostic);
+}
+
+static bool parse(MultilibSet &MS, std::string &Diagnostic,
+  const std::string &Data) {
+  return MS.parse(llvm::MemoryBufferRef(Data, "TEST"), diagnosticCallback,
+  &Diagnostic);
+}
+
+static bool parse(MultilibSet &MS, const char *Data) {
+  return MS.parse(llvm::MemoryBufferRef(Data, "TEST"));
+}
+
+#define _STRINGIFY(x) #x
+#define STRINGIFY(x) _STRINGIFY(x)
+// Avoid using MULTILIB_CLANG_VERSION in case it has extra non-numeric parts.
+#define MULTILIB_CLANG_VERSION \
+  STRINGIFY(CLANG_VERSION_MAJOR)   \
+  "." STRINGIFY(CLANG_VERSION_MINOR) "." STRINGIFY(CLANG_VERSION_PATCHLEVEL)
+#define YAML_PREAMBLE "ClangMinimumVersion: " MULTILIB_CLANG_VERSION "\n"
+
+TEST(MultilibTest, ParseInvalid) {
+  std::string Diagnostic;
+
+  MultilibSet MS;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, R"(
+Variants: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic)
+  .contains("missing required key 'ClangMinimumVersion'"))
+  << Diagnostic;
+
+  // Require all 3 major.minor.patch version components
+  EXPECT_FALSE(parse(MS, Diagnostic, R"(
+ClangMinimumVersion: )" STRINGIFY(CLANG_VERSION_MAJOR) R"(.0
+Variants: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic)
+  .contains("not a valid version string. Expected "
+"MAJOR.MINOR.PATCHLEVEL but got \"" STRINGIFY(
+CLANG_VERSION_MAJOR) ".0\""))
+  << Diagnostic;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, R"(
+ClangMinimumVersion: )" MULTILIB_CLANG_VERSION R"(a
+Variants: []
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic)
+  .contains("not a valid version string. Expected "
+"MAJOR.MINOR.PATCHLEVEL where all components are decimal "
+"integers but got \"" MULTILIB_CLANG_VERSION "a\""))
+  << Diagnostic;
+
+  // Reject configurations that require a later clang version
+  EXPECT_FALSE(parse(MS, Diagnostic,
+ R"(
+ClangMinimumVersion: )" + std::to_string(CLANG_VERSION_MAJOR + 1) +
+ R"(.0.0
+Variants: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic)
+  .contains("clang version " MULTILIB_CLANG_VERSION
+" is less than ClangMinimumVersion: " +
+std::to_string(CLANG_VERSION_MAJOR + 1) + ".0.0"))
+  << Diagnostic;
+
+  // but accept configurations that only need an earlier clang version
+  EXPECT_TRUE(parse(MS, Diagnostic, R"(
+ClangMinimumVersion: 16.0.0
+Variants: []
+)")) << Diagnostic;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, YAML_PREAMBLE));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("missing required key 'Variants'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Dir: /abc
+  Flags: []
+  PrintOptions: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("paths must be relative"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Flags: []
+  PrintOptions: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("missing required key 'Dir'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Dir: .
+  PrintOptions: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("missing required key 'Flags'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Dir: .
+  Flags: []
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic).contains("missing required key 'PrintOptions'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parse(MS, Diagnostic, YAML_PREAMBLE R"(

[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-02-23 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

Gentle ping for review. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

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


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM




Comment at: clang/test/SemaCXX/lambda-expressions.cpp:675-676
+StringLiteral(const char (&array)[N])
+__attribute__((enable_if(__builtin_strlen(array) == 2,
+  "invalid string literal")));
+};

cor3ntin wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > aaron.ballman wrote:
> > > > 1) This code already compiles today without issue 
> > > > (https://godbolt.org/z/q6hPxoWq9), so are you sure this is testing what 
> > > > needs to be tested?
> > > > 
> > > > 2) What about for non-GNU-style attributes ([[]] attributes that 
> > > > appertain to the function type)? e.g.,
> > > > ```
> > > > template 
> > > > void foo(const char (&array)[N]) [[clang::annotate_type("test", 
> > > > array)]];
> > > > ```
> > > Yes, this is something that was broken by this patch.
> > > enable_if did create odr uses (incorrectly). I can add a test for 
> > > annotate_type but I don't think it would run into the same issue at all. 
> > So I'm not certain what's being tested then -- how are you validating that 
> > `array` is no longer ODR used?
> > 
> > In terms of `annotate_type`, that attribute accepts a string literal 
> > followed by a variable number of expression arguments, so I think it should 
> > have the same issues as a GNU-style attribute accepting an expression 
> > argument. I was mostly trying to wrap my head around whether `[[]]` and 
> > `__attribute__` are expected to have different behaviors when written in 
> > that position.
> Context https://reviews.llvm.org/D124351#4101611
I talked to @cor3ntin off-list to get a better understanding of the test 
situation, and I realized the issue was that this code used to give a 
diagnostic that it shouldn't have, so this is demonstrating we accept the code 
rather than reject it. That makes a lot more sense now!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D144447: [Clang] Teach buildFMulAdd to peek through fneg to find fmul.

2023-02-23 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn accepted this revision.
kpn 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/D17/new/

https://reviews.llvm.org/D17

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


[clang] 34abc5b - [Clang] Fix a crash when taking the address of a consteval lambda

2023-02-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-02-23T15:26:37+01:00
New Revision: 34abc5b75d9d995ded56a9534c230300b06f1439

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

LOG: [Clang] Fix a crash when taking the address of a consteval lambda

The `_invoke` function of lambdas was not respecting
the constexpr/consteval specifier of the call operator, so it was possible
to take its address in a non-immmediately invoked context,
even if the call operator was itself consteval.

In addition, we improve the diagnostic emmited in the lambda case
not to show that `invoke` method.

Fixes #57682

Reviewed By: aaron.ballman, #clang-language-wg

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLambda.cpp
clang/test/AST/ast-dump-expr-json.cpp
clang/test/AST/ast-dump-expr.cpp
clang/test/AST/ast-dump-lambda.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index be3ea5ff63cde..0c8d3d9411b12 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -153,6 +153,8 @@ Bug Fixes in This Version
 - Fix __VA_OPT__ implementation so that it treats the concatenation of a
   non-placemaker token and placemaker token as a non-placemaker token.
   (`#60268 `_)
+- Fix crash when taking the address of a consteval lambda call operator.
+  (`#57682 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b69920b001cc9..86c5c4e288c99 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2648,7 +2648,7 @@ def warn_cxx14_compat_constexpr_not_const : Warning<
   "in C++14; add 'const' to avoid a change in behavior">,
   InGroup>;
 def err_invalid_consteval_take_address : Error<
-  "cannot take address of consteval function %0 outside"
+  "cannot take address of consteval %select{function|call operator of}1 %0 
outside"
   " of an immediate invocation">;
 def err_invalid_consteval_call : Error<
   "call to consteval function %q0 is not a constant expression">;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index a5e8e664ab160..922f102f29872 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17985,10 +17985,13 @@ HandleImmediateInvocations(Sema &SemaRef,
 if (!CE.getInt())
   EvaluateAndDiagnoseImmediateInvocation(SemaRef, CE);
   for (auto *DR : Rec.ReferenceToConsteval) {
-auto *FD = cast(DR->getDecl());
+NamedDecl *ND = cast(DR->getDecl());
+if (auto *MD = llvm::dyn_cast(ND);
+MD && (MD->isLambdaStaticInvoker() || isLambdaCallOperator(MD)))
+  ND = MD->getParent();
 SemaRef.Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)
-<< FD;
-SemaRef.Diag(FD->getLocation(), diag::note_declared_at);
+<< ND << isa(ND);
+SemaRef.Diag(ND->getLocation(), diag::note_declared_at);
   }
 }
 

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 00ab6ba580bfe..e3614b254737e 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1529,7 +1529,7 @@ static void addFunctionPointerConversion(Sema &S, 
SourceRange IntroducerRange,
 S.Context, Class, Loc, DeclarationNameInfo(InvokerName, Loc),
 InvokerFunctionTy, CallOperator->getTypeSourceInfo(), SC_Static,
 S.getCurFPFeatures().isFPConstrained(),
-/*isInline=*/true, ConstexprSpecKind::Unspecified,
+/*isInline=*/true, CallOperator->getConstexprKind(),
 CallOperator->getBody()->getEndLoc());
 for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I)
   InvokerParams[I]->setOwningFunction(Invoke);

diff  --git a/clang/test/AST/ast-dump-expr-json.cpp 
b/clang/test/AST/ast-dump-expr-json.cpp
index f166698556acc..eac0346d64319 100644
--- a/clang/test/AST/ast-dump-expr-json.cpp
+++ b/clang/test/AST/ast-dump-expr-json.cpp
@@ -6867,7 +6867,8 @@ void TestNonADLCall3() {
 // CHECK-NEXT: "qualType": "auto ()"
 // CHECK-NEXT:},
 // CHECK-NEXT:"storageClass": "static",
-// CHECK-NEXT:"inline": true
+// CHECK-NEXT:"inline": true,
+// CHECK-NEXT:"constexpr": true
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: },

diff  --git a/clang/test/AST/ast-dump-expr.cpp 
b/clang/test/AST/ast-dump-exp

[PATCH] D144627: [Clang] Fix a crash when taking the address of a consteval lambda

2023-02-23 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG34abc5b75d9d: [Clang] Fix a crash when taking the address of 
a consteval lambda (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D144627?vs=499773&id=499831#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144627

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1029,3 +1029,24 @@
int x = A{};
 }
 }
+
+namespace GH57682 {
+void test() {
+  constexpr auto l1 = []() consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \
+   // expected-note  2{{declared here}}
+return 3;
+  };
+  constexpr int (*f1)(void) = l1; // expected-error {{constexpr variable 'f1' must be initialized by a constant expression}} \
+  // expected-note  {{pointer to a consteval declaration is not a constant expression}}
+
+
+  constexpr auto lstatic = []() static consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \
+   // expected-note  2{{declared here}} \
+   // expected-warning {{extension}}
+return 3;
+  };
+  constexpr int (*f2)(void) = lstatic; // expected-error {{constexpr variable 'f2' must be initialized by a constant expression}} \
+   // expected-note  {{pointer to a consteval declaration is not a constant expression}}
+
+}
+}
Index: clang/test/AST/ast-dump-lambda.cpp
===
--- clang/test/AST/ast-dump-lambda.cpp
+++ clang/test/AST/ast-dump-lambda.cpp
@@ -246,7 +246,7 @@
 // CHECK-NEXT:| | |-CXXMethodDecl {{.*}}  col:3{{( imported)?}} constexpr operator() 'auto () const' inline
 // CHECK-NEXT:| | | `-CompoundStmt {{.*}} 
 // CHECK-NEXT:| | |-CXXConversionDecl {{.*}}  col:3{{( imported)?}} implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
-// CHECK-NEXT:| | `-CXXMethodDecl {{.*}}  col:3{{( imported)?}} implicit __invoke 'auto ()' static inline
+// CHECK-NEXT:| | `-CXXMethodDecl {{.*}}  col:3{{( imported)?}} implicit constexpr __invoke 'auto ()' static inline
 // CHECK-NEXT:| `-CompoundStmt {{.*}} 
 // CHECK-NEXT:|-LambdaExpr {{.*}}  '(lambda at {{.*}}ast-dump-lambda.cpp:33:3)'
 // CHECK-NEXT:| |-CXXRecordDecl {{.*}}  col:3{{( imported)?}} implicit{{( )?}} class definition
Index: clang/test/AST/ast-dump-expr.cpp
===
--- clang/test/AST/ast-dump-expr.cpp
+++ clang/test/AST/ast-dump-expr.cpp
@@ -464,7 +464,7 @@
   // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 constexpr operator() 'auto () const' inline
   // CHECK-NEXT: CompoundStmt
   // CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}}  col:3 implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
-  // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 implicit __invoke 'auto ()' static inline
+  // CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}}  col:3 implicit constexpr __invoke 'auto ()' static inline
   // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
 
   []() mutable {};
Index: clang/test/AST/ast-dump-expr-json.cpp
===
--- clang/test/AST/ast-dump-expr-json.cpp
+++ clang/test/AST/ast-dump-expr-json.cpp
@@ -6867,7 +6867,8 @@
 // CHECK-NEXT: "qualType": "auto ()"
 // CHECK-NEXT:},
 // CHECK-NEXT:"storageClass": "static",
-// CHECK-NEXT:"inline": true
+// CHECK-NEXT:"inline": true,
+// CHECK-NEXT:"constexpr": true
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: },
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1529,7 +1529,7 @@
 S.Context, Class, Loc, DeclarationNameInfo(InvokerName, Loc),
 InvokerFunctionTy, CallOperator->getTypeSourceInfo(), SC_Static,
 S.getCurFPFeatures().isFPConstrained(),
-/*isInline=*/true, ConstexprSpecKind::Unspecified,
+/*isInline=*/true, CallOperator->getConstexprKind(),
 CallOperator->getBody()->getEndLoc());
 for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I)
   InvokerParams[I]->s

[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D144285#4135807 , @erichkeane 
wrote:

> In D144285#4135775 , @Endill wrote:
>
>> Thank you for the patch.
>> Any plans to backport this to 16.x branch?
>
> I would not really want us to do that, the breaking change here is 
> concerning, and I'd like this to spend time in trunk 'baking' a while.

+1, at this point the only things we should be backporting to 16.x are fixes 
for regressions or fixes for security concerns.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16824-16841
   if (InnerCond && isa(InnerCond)) {
 // Drill down into concept specialization expressions to see why they
 // weren't satisfied.
 Diag(StaticAssertLoc, diag::err_static_assert_failed)
   << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
 ConstraintSatisfaction Satisfaction;
 if (!CheckConstraintSatisfaction(InnerCond, Satisfaction))

cor3ntin wrote:
> rsmith wrote:
> > I wonder if it's worth adding a custom diagnostic (eg, "this template 
> > cannot be instantiated: %0") for the case where we're in template 
> > instantiation and the expression is the bool literal `false`.
> I'm not sure i see the motivation. Why would we want to special case `false`? 
> The expression could also be an always false, never dependent expression
Richard may have different ideas in mind, but the motivation to me is code 
like: 
```
template 
struct S {
  static_assert(false, "you have to use one of the valid specializations, not 
the primary template");
};

template <>
struct S {
};

template <>
struct S {
};

int main() {
  S s1;
  S s2;
  S s3;
}
```
Rather than telling the user the static_assert failed because false is not 
true, having a custom diagnostic might read better for users. GCC doesn't 
produce a custom diagnostic -- the behavior isn't terrible, but the "false 
evaluates to false" note is effectively just noise, too: 
https://godbolt.org/z/456bzWG7c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16824-16841
   if (InnerCond && isa(InnerCond)) {
 // Drill down into concept specialization expressions to see why they
 // weren't satisfied.
 Diag(StaticAssertLoc, diag::err_static_assert_failed)
   << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
 ConstraintSatisfaction Satisfaction;
 if (!CheckConstraintSatisfaction(InnerCond, Satisfaction))

aaron.ballman wrote:
> cor3ntin wrote:
> > rsmith wrote:
> > > I wonder if it's worth adding a custom diagnostic (eg, "this template 
> > > cannot be instantiated: %0") for the case where we're in template 
> > > instantiation and the expression is the bool literal `false`.
> > I'm not sure i see the motivation. Why would we want to special case 
> > `false`? The expression could also be an always false, never dependent 
> > expression
> Richard may have different ideas in mind, but the motivation to me is code 
> like: 
> ```
> template 
> struct S {
>   static_assert(false, "you have to use one of the valid specializations, not 
> the primary template");
> };
> 
> template <>
> struct S {
> };
> 
> template <>
> struct S {
> };
> 
> int main() {
>   S s1;
>   S s2;
>   S s3;
> }
> ```
> Rather than telling the user the static_assert failed because false is not 
> true, having a custom diagnostic might read better for users. GCC doesn't 
> produce a custom diagnostic -- the behavior isn't terrible, but the "false 
> evaluates to false" note is effectively just noise, too: 
> https://godbolt.org/z/456bzWG7c
OH. That makes sense now,  thanks. I think I agree.
Interestingly, in gcc immediate calls are really immediate :) 
https://godbolt.org/z/b3vrzf4sj 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

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


[clang] 3b6c883 - Revert "[Clang] Implement fix for DR2628"

2023-02-23 Thread Tobias Hieta via cfe-commits

Author: Tobias Hieta
Date: 2023-02-23T16:07:35+01:00
New Revision: 3b6c88331bcd0531d627fe27de5dbd0ac3165300

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

LOG: Revert "[Clang] Implement fix for DR2628"

This reverts commit 368b6832de33b366d4eb155f940e7476daace6a8.

See https://github.com/llvm/llvm-project/issues/60777 for details

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/drs/dr26xx.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 8df8eadad3fef..c3338e4eaed28 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2540,8 +2540,6 @@ struct ConvertConstructorToDeductionGuideTransform {
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
-if (Ctor && Ctor->getTrailingRequiresClause())
-  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
index 36aea39824740..e69a151b9d029 100644
--- a/clang/test/CXX/drs/dr26xx.cpp
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -14,17 +14,23 @@ using enum E; // expected-error {{unknown type name E}}
 }
 }
 
-namespace dr2628 { // dr2628: yes open
+namespace dr2628 { // dr2628: no, this was reverted for the 16.x release
+   // due to regressions, see the issue for more details:
+   // https://github.com/llvm/llvm-project/issues/60777
 
 template 
 struct foo {
-  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
-  constexpr foo() requires (A || B) = delete;
+  // The expected notes below should be removed when dr2628 is fully 
implemented again
+  constexpr foo() requires (!A && !B) = delete; // expected-note {{candidate 
function [with A = false, B = false]}} #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete; // expected-note {{candidate 
function [with A = false, B = false]}}
 };
 
 void f() {
-  foo fooable; // expected-error {{call to deleted}}
-  // expected-note@#DR2628_CTOR {{marked deleted here}}
+  // The FIXME's below should be the expected errors when dr2628 is
+  // fully implemented again.
+  // FIXME-expected-error {{call to deleted}}
+  foo fooable; // expected-error {{ambiguous deduction for template arguments 
of 'foo'}}
+  // FIXME-expected-note@#DR2628_CTOR {{marked deleted here}}
 }
 
 }



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


[PATCH] D144586: [PS4/PS5] Specify no or

2023-02-23 Thread Paul Robinson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32d441bfb4f3: [PS4/PS5] Specify no  or 
 (authored by probinson).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144586

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/C/C11/n1460.c


Index: clang/test/C/C11/n1460.c
===
--- clang/test/C/C11/n1460.c
+++ clang/test/C/C11/n1460.c
@@ -7,9 +7,15 @@
 // If we claim to not support the feature then we expect diagnostics when
 // using that feature. Otherwise, we expect no diagnostics.
 #ifdef __STDC_NO_COMPLEX__
-  // We do not have any targets which do not support complex, so we don't
-  // expect to get into this block.
-  #error "it's unexpected that we don't support complex"
+  // PS4/PS5 set this to indicate no  but still support the
+  // _Complex syntax.
+  #ifdef __SCE__
+#define HAS_COMPLEX
+  #else
+// We do not have any other targets which do not support complex, so we
+// don't expect to get into this block.
+#error "it's unexpected that we don't support complex"
+  #endif
   float _Complex fc;
   double _Complex dc;
   long double _Complex ldc;
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -535,6 +535,8 @@
 DefineStd(Builder, "unix", Opts);
 Builder.defineMacro("__ELF__");
 Builder.defineMacro("__SCE__");
+Builder.defineMacro("__STDC_NO_COMPLEX__");
+Builder.defineMacro("__STDC_NO_THREADS__");
   }
 
 public:


Index: clang/test/C/C11/n1460.c
===
--- clang/test/C/C11/n1460.c
+++ clang/test/C/C11/n1460.c
@@ -7,9 +7,15 @@
 // If we claim to not support the feature then we expect diagnostics when
 // using that feature. Otherwise, we expect no diagnostics.
 #ifdef __STDC_NO_COMPLEX__
-  // We do not have any targets which do not support complex, so we don't
-  // expect to get into this block.
-  #error "it's unexpected that we don't support complex"
+  // PS4/PS5 set this to indicate no  but still support the
+  // _Complex syntax.
+  #ifdef __SCE__
+#define HAS_COMPLEX
+  #else
+// We do not have any other targets which do not support complex, so we
+// don't expect to get into this block.
+#error "it's unexpected that we don't support complex"
+  #endif
   float _Complex fc;
   double _Complex dc;
   long double _Complex ldc;
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -535,6 +535,8 @@
 DefineStd(Builder, "unix", Opts);
 Builder.defineMacro("__ELF__");
 Builder.defineMacro("__SCE__");
+Builder.defineMacro("__STDC_NO_COMPLEX__");
+Builder.defineMacro("__STDC_NO_THREADS__");
   }
 
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 32d441b - [PS4/PS5] Specify no or

2023-02-23 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2023-02-23T07:09:30-08:00
New Revision: 32d441bfb4f302e02736dc922b0388c7594fd90e

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

LOG: [PS4/PS5] Specify no  or 

We've never provided these headers so set the preprocessor
toggles to reflect that.

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

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h
clang/test/C/C11/n1460.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index fd372cb12df2b..0280129b3c950 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -535,6 +535,8 @@ class LLVM_LIBRARY_VISIBILITY PSOSTargetInfo : public 
OSTargetInfo {
 DefineStd(Builder, "unix", Opts);
 Builder.defineMacro("__ELF__");
 Builder.defineMacro("__SCE__");
+Builder.defineMacro("__STDC_NO_COMPLEX__");
+Builder.defineMacro("__STDC_NO_THREADS__");
   }
 
 public:

diff  --git a/clang/test/C/C11/n1460.c b/clang/test/C/C11/n1460.c
index c52ea22d99277..388b905a5ed41 100644
--- a/clang/test/C/C11/n1460.c
+++ b/clang/test/C/C11/n1460.c
@@ -7,9 +7,15 @@
 // If we claim to not support the feature then we expect diagnostics when
 // using that feature. Otherwise, we expect no diagnostics.
 #ifdef __STDC_NO_COMPLEX__
-  // We do not have any targets which do not support complex, so we don't
-  // expect to get into this block.
-  #error "it's unexpected that we don't support complex"
+  // PS4/PS5 set this to indicate no  but still support the
+  // _Complex syntax.
+  #ifdef __SCE__
+#define HAS_COMPLEX
+  #else
+// We do not have any other targets which do not support complex, so we
+// don't expect to get into this block.
+#error "it's unexpected that we don't support complex"
+  #endif
   float _Complex fc;
   double _Complex dc;
   long double _Complex ldc;



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


[PATCH] D144115: [clang] Extend pragma dump to support expressions

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for this! You should add test coverage for the changes, especially 
around things like dependent expressions, ADL use, etc. Also, the changes need 
a release note and the new functionality should be explicitly documented.




Comment at: clang/lib/Parse/ParsePragma.cpp:724-728
+ExprResult E = ParseExpression();
+if (!E.isInvalid()) {
+  E.get()->dump();
+}
+SkipUntil(tok::eod, StopBeforeMatch);

I think you should have another variant of `ActOnPragmaDump` that does the 
actual dumping, instead of doing it from the parser. I think we should not try 
to dump a dependent expression (to support those, I think we need to create a 
new AST node for the pragma so that we can transform it from TreeTransform.h 
and perform the dump on the non-dependent expression -- not certain if we want 
to handle that now, or if we want it to be an error to use this pragma with a 
dependent expression).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144115

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


[clang-tools-extra] 981e3a3 - [clangd] Set diag data before emitting

2023-02-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-02-23T16:10:11+01:00
New Revision: 981e3a35a14541afc6fa338abf3f31895b80eed9

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

LOG: [clangd] Set diag data before emitting

Also fixes a benign use-after-free.

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

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 26b0047951b51..12a865fcf9e50 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -526,6 +526,9 @@ void toLSPDiags(
 }
   }
   Main.tags = D.Tags;
+  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
+  for (auto &Entry : D.OpaqueData)
+Main.data.insert({Entry.first, Entry.second});
   OutFn(std::move(Main), D.Fixes);
 
   // If we didn't emit the notes as relatedLocations, emit separate diagnostics
@@ -540,10 +543,6 @@ void toLSPDiags(
   Res.message = noteMessage(D, Note, Opts);
   OutFn(std::move(Res), llvm::ArrayRef());
 }
-
-  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
-  for (auto &Entry : D.OpaqueData)
-Main.data.insert({Entry.first, Entry.second});
 }
 
 int getSeverity(DiagnosticsEngine::Level L) {

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 610a290f834aa..a20be39722ec3 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1012,6 +1013,7 @@ TEST(DiagnosticsTest, ToLSP) {
   D.Severity = DiagnosticsEngine::Error;
   D.File = "foo/bar/main.cpp";
   D.AbsFile = std::string(MainFile.file());
+  D.OpaqueData["test"] = "bar";
 
   clangd::Note NoteInMain;
   NoteInMain.Message = "declared somewhere in the main file";
@@ -1050,6 +1052,7 @@ main.cpp:6:7: remark: declared somewhere in the main file
 ../foo/baz/header.h:10:11:
 note: declared somewhere in the header file)";
   MainLSP.tags = {DiagnosticTag::Unnecessary};
+  MainLSP.data = D.OpaqueData;
 
   clangd::Diagnostic NoteInMainLSP;
   NoteInMainLSP.range = NoteInMain.Range;



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


[PATCH] D144641: [clangd] Set diag data before emitting

2023-02-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG981e3a35a145: [clangd] Set diag data before emitting 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144641

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1012,6 +1013,7 @@
   D.Severity = DiagnosticsEngine::Error;
   D.File = "foo/bar/main.cpp";
   D.AbsFile = std::string(MainFile.file());
+  D.OpaqueData["test"] = "bar";
 
   clangd::Note NoteInMain;
   NoteInMain.Message = "declared somewhere in the main file";
@@ -1050,6 +1052,7 @@
 ../foo/baz/header.h:10:11:
 note: declared somewhere in the header file)";
   MainLSP.tags = {DiagnosticTag::Unnecessary};
+  MainLSP.data = D.OpaqueData;
 
   clangd::Diagnostic NoteInMainLSP;
   NoteInMainLSP.range = NoteInMain.Range;
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -526,6 +526,9 @@
 }
   }
   Main.tags = D.Tags;
+  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
+  for (auto &Entry : D.OpaqueData)
+Main.data.insert({Entry.first, Entry.second});
   OutFn(std::move(Main), D.Fixes);
 
   // If we didn't emit the notes as relatedLocations, emit separate diagnostics
@@ -540,10 +543,6 @@
   Res.message = noteMessage(D, Note, Opts);
   OutFn(std::move(Res), llvm::ArrayRef());
 }
-
-  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
-  for (auto &Entry : D.OpaqueData)
-Main.data.insert({Entry.first, Entry.second});
 }
 
 int getSeverity(DiagnosticsEngine::Level L) {


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1012,6 +1013,7 @@
   D.Severity = DiagnosticsEngine::Error;
   D.File = "foo/bar/main.cpp";
   D.AbsFile = std::string(MainFile.file());
+  D.OpaqueData["test"] = "bar";
 
   clangd::Note NoteInMain;
   NoteInMain.Message = "declared somewhere in the main file";
@@ -1050,6 +1052,7 @@
 ../foo/baz/header.h:10:11:
 note: declared somewhere in the header file)";
   MainLSP.tags = {DiagnosticTag::Unnecessary};
+  MainLSP.data = D.OpaqueData;
 
   clangd::Diagnostic NoteInMainLSP;
   NoteInMainLSP.range = NoteInMain.Range;
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -526,6 +526,9 @@
 }
   }
   Main.tags = D.Tags;
+  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
+  for (auto &Entry : D.OpaqueData)
+Main.data.insert({Entry.first, Entry.second});
   OutFn(std::move(Main), D.Fixes);
 
   // If we didn't emit the notes as relatedLocations, emit separate diagnostics
@@ -540,10 +543,6 @@
   Res.message = noteMessage(D, Note, Opts);
   OutFn(std::move(Res), llvm::ArrayRef());
 }
-
-  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
-  for (auto &Entry : D.OpaqueData)
-Main.data.insert({Entry.first, Entry.second});
 }
 
 int getSeverity(DiagnosticsEngine::Level L) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144004: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-02-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 499848.
krisb marked 2 inline comments as done.
krisb added a comment.

Apply review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144004

Files:
  clang/test/CodeGenCXX/debug-info-namespace.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Linker/IRMover.cpp
  llvm/test/CodeGen/Generic/DbgValueAggregate.ll
  llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
  llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
  llvm/test/DebugInfo/X86/fission-inline.ll
  llvm/test/DebugInfo/X86/fission-local-import.ll
  llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
  llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
  llvm/test/DebugInfo/X86/namelist2.ll
  llvm/test/DebugInfo/omit-empty.ll
  llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Index: llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
===
--- llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
+++ llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
@@ -5,15 +5,13 @@
 ; RUN: opt -module-summary %p/Inputs/debuginfo-cu-import.ll -o %t2.bc
 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
 
-; Don't import enums, macros, retainedTypes or globals lists.
-; Only import local scope imported entities.
+; Don't import enums, macros, retainedTypes, globals or imports lists.
 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s
 ; CHECK-NOT: DICompileUnit{{.*}} enums:
 ; CHECK-NOT: DICompileUnit{{.*}} macros:
 ; CHECK-NOT: DICompileUnit{{.*}} retainedTypes:
 ; CHECK-NOT: DICompileUnit{{.*}} globals:
-; CHECK: DICompileUnit{{.*}} imports: ![[IMP:[0-9]+]]
-; CHECK: ![[IMP]] = !{!{{[0-9]+}}}
+; CHECK-NOT: DICompileUnit{{.*}} imports:
 
 ; ModuleID = 'debuginfo-cu-import.c'
 source_filename = "debuginfo-cu-import.c"
@@ -50,14 +48,14 @@
 !8 = !{!9}
 !9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
 !10 = !DIGlobalVariable(name: "version", scope: !4, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true)
-!11 = !{!12, !16}
+!11 = !{!12}
 !12 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !4, entity: !13, file: !1, line: 8)
 !13 = distinct !DISubprogram(name: "a", linkageName: "_ZN1A1aEv", scope: !4, file: !1, line: 7, type: !14, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !14 = !DISubroutineType(types: !15)
 !15 = !{null}
 !16 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !17, entity: !19, file: !1, line: 8)
 !17 = distinct !DILexicalBlock(scope: !18, file: !1, line: 9, column: 8)
-!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
+!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !33)
 !19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 10, column: 8)
 !20 = distinct !DISubprogram(name: "d", linkageName: "_ZN1A1dEv", scope: !4, file: !1, line: 10, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !21 = !{!22}
@@ -72,4 +70,4 @@
 !30 = !DILocation(line: 7, column: 12, scope: !13)
 !31 = distinct !DISubprogram(name: "b", linkageName: "_ZN1A1bEv", scope: !4, file: !1, line: 8, type: !14, isLocal: true, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !32 = !DILocation(line: 8, column: 24, scope: !31)
-
+!33 = !{!16}
Index: llvm/test/DebugInfo/omit-empty.ll
===
--- llvm/test/DebugInfo/omit-empty.ll
+++ llvm/test/DebugInfo/omit-empty.ll
@@ -6,15 +6,15 @@
 !llvm.dbg.cu = !{!0, !5}
 !llvm.module.flags = !{!3, !4}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C

[PATCH] D144004: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-02-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll:17-36
+; CHECK:   DW_TAG_subprogram
+; CHECK: DW_AT_name("foo")
+; CHECK: DW_TAG_imported_declaration
+; CHECK: NULL
+
+; CHECK:   DW_TAG_base_type
+; CHECK: DW_AT_name("int")

jmmartinez wrote:
> I'd be tempted to match the offset of the abstract subprogram and of the 
> imported declaration too.
> At least for me, it makes clear the intention of the test without running it.
> 
> What do you think ?
Good point, thank  you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144004

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


[PATCH] D144638: [lit] Detect Consistent File Access Times

2023-02-23 Thread Jez Ng via Phabricator via cfe-commits
int3 added inline comments.



Comment at: llvm/utils/lit/lit/llvm/config.py:165
+#
+# This check hopefully detects both cases, and disables tests that require
+# consistent atime.

lenary wrote:
> jhenderson wrote:
> > Is "hopefully" really needed here?
> I'm hedging in this comment, in part because we're trying to find a race 
> condition experimentally, and also because this will cause lit to fatal error 
> before running any tests if `touch` exits non-zero for any reason. 
if we know for sure that NetBSD and Windows don't support this, why not 
hardcode those values in, and only try the experimental check otherwise?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144638

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


[PATCH] D144646: [Tooling][Inclusions] Add c-header and global namespace alternatives for size_t

2023-02-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144646

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -22,6 +22,20 @@
 SYMBOL(size_t, std::, )
 SYMBOL(size_t, std::, )
 SYMBOL(size_t, std::, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
 SYMBOL(unwrap_ref_decay, std::, )
 SYMBOL(unwrap_ref_decay, std::, )
 SYMBOL(unwrap_reference, std::, )


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -22,6 +22,20 @@
 SYMBOL(size_t, std::, )
 SYMBOL(size_t, std::, )
 SYMBOL(size_t, std::, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
+SYMBOL(size_t, None, )
 SYMBOL(unwrap_ref_decay, std::, )
 SYMBOL(unwrap_ref_decay, std::, )
 SYMBOL(unwrap_reference, std::, )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141690: [clang] fix consteval ctor code generation assert

2023-02-23 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google abandoned this revision.
luken-google added a comment.

seems to have fixed itself..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141690

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


[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-02-23 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

@gamesh411 and I tried to understand the consequences of this change. We think 
it might be problematic that calling `ASTContext::getVaListTagDecl` [1] creates 
the VaList declaration (and on certain platforms, the declaration of `std`) 
even in the cases when these declarations do not appear in the translation 
units and wouldn't be imported. (This is analogous to the issues caused by 
https://reviews.llvm.org/D142822, but more limited in scope. That commit 
modified Sema, so it "leaked" these declarations practically everywhere; I fear 
that this change might analogously leak these declarations into the ASTs that 
are affected by import operations.)

Following the example of the testcase p2-nodef.cpp 

 I'd suggest adding 1-2 testcases to check that the ASTImporter machinery does 
not leak superfluous declarations. For example, the presence of  `int std = 
20;` (in either the source or the target of the AST import) should not cause 
name collisions even on architectures (e.g. AArch64) where the VaList type is 
defined in the `std` namespace.

These testcases would be a valuable addition even if they'd pass with the 
current implementation, because they'd safeguard against leaks introduced by 
later changes of this logic. However, I'd guess that there is a significant 
chance (>30%) that this test would fail; in that case we should look for a 
different solution that acts in the moment when a va_list is actually imported 
instead of trying to "prepare the ground" by prematurely adding some 
declarations.

[1] Note that this isn't a pure getter, it mutates the `ASTContext` object in 
the case when `__va_list_tag` isn't declared yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144273

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


[PATCH] D143418: [libclang] Add API to set preferred temp dir path

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D143418#4131156 , @vedgy wrote:

> In D143418#4125756 , @aaron.ballman 
> wrote:
>
>>> 3. `clang_createIndex()` initializes global options based on environment 
>>> variable values:
>>>
>>>   if (getenv("LIBCLANG_BGPRIO_INDEX"))
>>>   CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
>>>  
>>> CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
>>> if (getenv("LIBCLANG_BGPRIO_EDIT"))
>>>   CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
>>>  
>>> CXGlobalOpt_ThreadBackgroundPriorityForEditing);
>>>
>>> The recommended in documentation usage of `clang_CXIndex_setGlobalOptions` 
>>> is:
>>>
>>>   * \code
>>>   * CXIndex idx = ...;
>>>   * clang_CXIndex_setGlobalOptions(idx,
>>>   * clang_CXIndex_getGlobalOptions(idx) |
>>>   * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
>>>   * \endcode
>>>
>>> So making these options part of `struct CXIndexOptions` and deprecating 
>>> `clang_CXIndex_setGlobalOptions` requires introducing another global 
>>> function that would read the environment variables:
>>>
>>>   CINDEX_LINKAGE unsigned clang_getDefaultGlobalOptions();
>>>
>>> Is this the right approach?
>>
>> Hmm, to make this patch easier, I think we might want to leave the 
>> environment variable behavior alone and not shift these into the options 
>> structure (yet?). Naively, I think it makes sense for these to eventually 
>> live in the options structure, but we could expose them in a few different 
>> ways (an option to prefer the env variable over a manual value as it is 
>> today or an option to prefer the manual value over the env variable for 
>> folks who want more hermetic behavior). WDYT? My opinion here isn't super 
>> strong, so if you have a strong desire to deprecate and add a replacement 
>> API, I think that's a defensible course to take.
>
> On second thought, the proposed `clang_getDefaultGlobalOptions()` API already 
> offers users a choice to either prefer or override each option value from the 
> env. variables, just like the existing `clang_CXIndex_[gs]etGlobalOptions` 
> API. The environment variables are binary options: an existence, not value, 
> of an env. variable determines an initial option value. So I don't understand 
> what are the two different ways to expose these options.

I was thinking of the env variable as determining the initial option value, so 
the two options I saw were "the the env variable provides the final resulting 
value used by the program" and "the env variable provides the default value 
used by the program". But you're right, the current behavior is that the 
presence of the env variable determines the behavior, not the value of the env 
variable.

The question really boils down to: if the user passes in an option which says 
"don't use thread background priority" to the call to create index, AND there 
is an environment variable saying "use thread background priority", who should 
win? And does the answer differ if the option says "use thread background 
priority" and the environment variable does not exist?

> Sounds good. Here is my current WIP API version:

This looks sensible to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143418

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


[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

2023-02-23 Thread joanahalili via Phabricator via cfe-commits
joanahalili added a comment.

In D143840#4147234 , @joanahalili 
wrote:

> Heads up: We are experiencing a series of clang crashes because of this 
> commit.
>
> What we already have so far:
>
>   Unhandled DeclRefExpr
>   UNREACHABLE executed at clang/lib/CodeGen/CGExpr.cpp:2958!
>
> We are now working on a reproducer.

Here is our reproducer:

  struct a {
enum { b };
  };
  struct c {
void *d;
  };
  struct e {
void f(void *);
  };
  template  struct h : g {
h(short, int);
virtual void i();
  };
  template  void h::i() { e().f(c::d); }
  struct j : h {
j();
  };
  int k;
  j::j() : h(a::b, k) {}




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143840

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


[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

2023-02-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D143840#4147582 , @joanahalili 
wrote:

> In D143840#4147234 , @joanahalili 
> wrote:
>
>> Heads up: We are experiencing a series of clang crashes because of this 
>> commit.
>>
>> What we already have so far:
>>
>>   Unhandled DeclRefExpr
>>   UNREACHABLE executed at clang/lib/CodeGen/CGExpr.cpp:2958!
>>
>> We are now working on a reproducer.
>
> Here is our reproducer:
>
>   struct a {
> enum { b };
>   };
>   struct c {
> void *d;
>   };
>   struct e {
> void f(void *);
>   };
>   template  struct h : g {
> h(short, int);
> virtual void i();
>   };
>   template  void h::i() { e().f(c::d); }
>   struct j : h {
> j();
>   };
>   int k;
>   j::j() : h(a::b, k) {}

Thanks! This looks like a real problem. I'm going to revert the commit.

BTW, I managed to reduce your test case slightly more:

  struct f {
void *g;
  };
  template  struct k : j {
virtual void l(){ (void)f::g; }
  };
  k q;

https://gcc.godbolt.org/z/fa33GYf9K


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143840

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


[PATCH] D143996: [clang-tidy][doc] Remove unused variable

2023-02-23 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@bjosv Are you able to land the land yourself, or should we do it for you? If 
so, please provide user and email for Github attribution.


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

https://reviews.llvm.org/D143996

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


[clang] 25d23b1 - [Clang][NFC] Remove pointless defines from test command lines

2023-02-23 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-02-23T16:18:24Z
New Revision: 25d23b1970ea023d83d462402fd43038b41c13a3

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

LOG: [Clang][NFC] Remove pointless defines from test command lines

A few tests use -D on the command line to define macros that are
already predefined. Remove these pointless defines, as an upcoming
patch will cause this to be a warning.

Added: 


Modified: 
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
clang/test/Rewriter/objc-modern-fast-enumeration.mm

Removed: 




diff  --git 
a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c 
b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
index a775a13c7bb5f..78e47e07d2225 100644
--- a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
+++ b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
@@ -1,8 +1,8 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
 
 // REQUIRES: aarch64-registered-target
 

diff  --git 
a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c 
b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
index 3c59b2c9f3538..d7969f3fd6d85 100644
--- a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
+++ b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
@@ -1,8 +1,8 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-g

[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-02-23 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D144216#4135395 , @mikecrowe wrote:

>> If you're suggesting that I could use the new  header to replace 
>> declarations of basic_string etc. in other tests then I think that would be 
>> possible with some careful checking to make sure it include the necessary 
>> functionality. I think that would easier to review separately rather than in 
>> a single patch though.
>
> I had a quick look at likely candidates:
>
> - `abseil/redundant-strcat-calls.cpp` appears to declare `basic_string` 
> outside the `std` namespace and inside it, and does some strange stuff with a 
> base class. If I rip all that out, and replace uses of `string` with 
> `std::string` then the tests pass using ``.
> - `readability/string-compare.cpp` and 
> `readability/container-data-pointer.cpp` require some tweaks to `` 
> but are straightforward.
> - There may be complications if MSVC differs in its `std::basic_string` 
> implementation in ways that the `-msvc` tests care about, but I didn't spot 
> any.
>
> So, it looks like the use of this new `` header could be extended. Do 
> you have a preference for one big patch, one patch per directory (abseil, 
> readability), or one patch per check? Do you require all to be complete 
> before even this patch can be accepted?

If it's possible to re-use this new string header into the other checks that 
would be ideal. After all, in the real world there's only one `string` header. 
If it's a drop-in replacement I think it's fine to do multiple checks in one 
patch. Otherwise if the check / string header needs tweak it's probably better 
to do one check at a time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144216

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


[PATCH] D140992: clang: Add __builtin_elementwise_fma

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/lib/Sema/SemaChecking.cpp:17761-17766
+  for (int I = 0; I < 3; ++I) {
+ExprResult Converted = UsualUnaryConversions(TheCall->getArg(I));
+if (Converted.isInvalid())
+  return true;
+Args[I] = Converted.get();
+  }

arsenm wrote:
> aaron.ballman wrote:
> > This will cause conversions to happen *before* we check whether the types 
> > are the same; is that expected? e.g., it seems like this would allow you to 
> > pass a float and a double and thanks to the magic of usual unary 
> > conversions they both come out as double and thus don't get diagnosed.
> The tests say that isn't happening, e.g. here:
> 
> 
> ```
> 
>   f32 = __builtin_elementwise_fma(f64, f32, f32);
>   // expected-error@-1 {{arguments are of different types ('double' vs 
> 'float')}}
> 
>   f32 = __builtin_elementwise_fma(f32, f64, f32);
>   // expected-error@-1 {{arguments are of different types ('float' vs 
> 'double')}}
> 
> ```
Oh, excellent, thank you!


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

https://reviews.llvm.org/D140992

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


[clang] 1812e13 - Revert "[clang] Add the check of membership for the issue #58674 and improve the lookup process"

2023-02-23 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2023-02-23T17:31:04+01:00
New Revision: 1812e13a3d6be9a838672ff74b3d9d383f5a83b5

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

LOG: Revert "[clang] Add the check of membership for the issue #58674 and 
improve the lookup process"

The commit causes clang to crash. See https://reviews.llvm.org/D143840#4147234

This reverts commit 8498ba6c2860c838183f9951b63df26ab5f02265.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/CXXInheritance.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/decltype.cpp

Removed: 
clang/test/CodeGenCXX/decl-ref-inheritance.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8d3d9411b12..2a636ebb00f79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -171,9 +171,6 @@ Bug Fixes to C++ Support
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
-- Fix an issue about ``decltype`` in the members of class templates derived 
from
-  templates with related parameters.
-  (`#58674 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 8909acc71c0a3..11276c77490ce 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1546,11 +1546,8 @@ class CXXRecordDecl : public RecordDecl {
   ///
   /// \param Base the base class we are searching for.
   ///
-  /// \param LookupInDependentTypes whether to look up in dependent types.
-  ///
   /// \returns true if this class is derived from Base, false otherwise.
-  bool isDerivedFrom(const CXXRecordDecl *Base,
- bool LookupInDependentTypes = false) const;
+  bool isDerivedFrom(const CXXRecordDecl *Base) const;
 
   /// Determine whether this class is derived from the type \p Base.
   ///
@@ -1564,14 +1561,11 @@ class CXXRecordDecl : public RecordDecl {
   /// \param Paths will contain the paths taken from the current class to the
   /// given \p Base class.
   ///
-  /// \param LookupInDependentTypes whether to look up independent types.
-  ///
   /// \returns true if this class is derived from \p Base, false otherwise.
   ///
   /// \todo add a separate parameter to configure IsDerivedFrom, rather than
   /// tangling input and output in \p Paths
-  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths,
- bool LookupInDependentTypes = false) const;
+  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
 
   /// Determine whether this class is virtually derived from
   /// the class \p Base.

diff  --git a/clang/lib/AST/CXXInheritance.cpp 
b/clang/lib/AST/CXXInheritance.cpp
index 32b17fc64a463..25de2a20a7f3b 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -64,16 +64,14 @@ void CXXBasePaths::swap(CXXBasePaths &Other) {
   std::swap(DetectedVirtual, Other.DetectedVirtual);
 }
 
-bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
-  bool LookupInDependentTypes) const {
+bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base) const {
   CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/false,
  /*DetectVirtual=*/false);
-  return isDerivedFrom(Base, Paths, LookupInDependentTypes);
+  return isDerivedFrom(Base, Paths);
 }
 
 bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
-  CXXBasePaths &Paths,
-  bool LookupInDependentTypes) const {
+  CXXBasePaths &Paths) const {
   if (getCanonicalDecl() == Base->getCanonicalDecl())
 return false;
 
@@ -85,7 +83,7 @@ bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
 return Specifier->getType()->getAsRecordDecl() &&
FindBaseClass(Specifier, Path, BaseDecl);
   },
-  Paths, LookupInDependentTypes);
+  Paths);
 }
 
 bool CXXRecordDecl::isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const {
@@ -248,16 +246,17 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 } else if (VisitBase) {
   CXXRecordDecl *BaseRecord;
   if (LookupInDependent) {
-BaseRecord = cast_if_present(
-BaseSpec.getType()->getAsRecordDecl());
-if (!BaseRecord) {
-  if (const TemplateSpecializationType *TST =
-  BaseSpec.getType()->getAs()) {
-TemplateName TN = TST->getTemplateName();
-if (auto *TD =
-

[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 499879.
VitaNuo marked 18 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp

Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -49,8 +49,8 @@
   }
 }
 
-static std::string spellHeader(const Header &H, HeaderSearch &HS,
-   const FileEntry *Main) {
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
 bool IsSystem = false;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -73,6 +73,8 @@
 std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main);
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -8,26 +8,57 @@
 
 #include "Annotations.h"
 #include "Config.h"
+#include "Diagnostics.h"
 #include "IncludeCleaner.h"
+#include "ParsedAST.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "support/Context.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
+using ::testing::Matcher;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
+Matcher withFix(::testing::Matcher FixMatcher) {
+  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+}
+
+MATCHER_P2(Diag, Range, Message,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
+  return arg.Range == Range && arg.Message == Message;
+}
+
+MATCHER_P3(Fix, Range, Replacement, Message,
+   "Fix " + llvm::to_string(Range) + " => " +
+   ::testing::PrintToString(Replacement) + " = [" + Message + "]") {
+  return arg.Message == Message && arg.Edits.size() == 1 &&
+ arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
+}
+
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
 }
@@ -342,7 +373,8 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes,
   ElementsAre(Pointee(writtenInclusion("";
 }
 
@@ -379,12 +411,98 @@
   computeUnusedIncludes(AST),
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
+
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
   EXPECT_THAT(
-  computeUnusedIncludesExperimental(AST),
+  Findings.UnusedIncludes,
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenIn

[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the comments!




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:408
+
+bool isFilteredByConfig(const Config &Cfg, llvm::StringRef HeaderSpelling) {
+  for (auto &Filter : Cfg.Diagnostics.Includes.IgnoreHeader) {

kadircet wrote:
> this shouldn't be spelling, it should be the resolved path of the include.
Ok thanks.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:697
+(*SpelledForExpanded)[(*SpelledForExpanded).size() - 1]);
+std::string SymbolName;
+switch (Ref.Target.kind()) {

kadircet wrote:
> as mentioned elsewhere, i think we should delay this symbol name spelling to 
> diagnostic generation. to make sure core analysis we perform don't do work 
> that might not get re-used (e.g. if we're not going to diagnose missing 
> includes, or in the future when we don't care about spelling of all the 
> symbols)
Ok should be done now.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:712
+  getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
+  return {std::move(UnusedIncludes), std::move(MissingIncludes)};
 }

kadircet wrote:
> nit: I think logically it makes more sense for us to return set of `Used` 
> includes here, and let the interaction that issues unused include diagnostics 
> to derive this information from the set of used includes, and change the the 
> missingincludes to a `vector< tuple >` (not only the 
> unsatisfied ones) would represent the analysis better and make it more usable 
> in the future (i.e. when we want to augment Hover responses, we can't re-use 
> all the logic in here, we really need to implement another call to `walkUsed` 
> because the analysis we get out of this call won't contain information for 
> `satisfied` symbols.
> 
> no need to do it now though, we can perform that kind of refactoring as we're 
> adding the features too (or maybe it'll actually look neater to just have 
> another call in those features rather than try and re-use the logic here)
Thanks. This might very well be the case, but this comment also seems to 
suggest some premature optimization (in a way). It totally makes sense to 
re-use what's re-usable, but this sort of refactoring really only makes sense 
once we have a clear use case (and get there :)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:359
+TransformedInc.Angled = WrittenRef.starts_with("<");
+auto FE = SM.getFileManager().getFile(Inc.Resolved);
+if (!FE)

kadircet wrote:
> VitaNuo wrote:
> > kadircet wrote:
> > > unfortunately `getFile` returns an `llvm::Expected` which requires 
> > > explicit error handling (or it'll trigger a crash). you can simply `elog` 
> > > the issue:
> > > ```
> > > if (!FE) {
> > >   elog("IncludeCleaner: Failed to get an entry for resolved path {0}: 
> > > {1}", Inc.Resolved, FE.takeError());
> > >   continue;
> > > }
> > > ```
> > It returns `llvm::ErrorOr`, if I am not mistaken. There was explicit error 
> > handling already (`if (!FE) continue` below), just without the `elog`. Are 
> > you trying to say it will crash without the logging? Not sure that's 
> > feasible :)
> > Added the logging.
> > It returns llvm::ErrorOr, if I am not mistaken. 
> 
> Ah you're right, I confused it with `getFileRef`. So in theory `ErrorOr` 
> doesn't require explicit checking hence it won't trigger a crash if destroyed 
> while containing an error.
> 
> > Are you trying to say it will crash without the logging? Not sure that's 
> > feasible :)
> 
> Right, it isn't the logging that'll prevent the crash but rather a 
> combination of the call to `takeError` and the way `elog` consumes `Error` 
> objects. But it isn't relevant here, as `ErrorOr` doesn't require mandatory 
> handling.
thanks for the explanation.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:596
+generateUnusedIncludeDiagnostics(PathRef FileName,
+ std::vector UnusedIncludes,
+ llvm::StringRef Code) {

kadircet wrote:
> VitaNuo wrote:
> > kadircet wrote:
> > > no need to copy the vector by taking a `std::vector` here, you can take 
> > > an `llvm::ArrayRef` instead.
> > Oh this isn't even my code, but as long as it's a small change, sure :)
> well, this is `our` code in the end :D
Sorry, wrong wording. I meant to say that this is not the code that has been 
touched in this patch. It might sometimes get annoying when comments on the 
patch dig too deep into code that's not in the diff.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:691
+  getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
+  return {UnusedIncludes, MissingIncludes};
+}

kadircet wrote:
> kadircet wrote:
> > nit: you'd want `std::move`s here, around both of them
> oops, i forgot to put the surrounding 

[PATCH] D143996: [clang-tidy][doc] Remove unused variable

2023-02-23 Thread Björn Svensson via Phabricator via cfe-commits
bjosv added a comment.

@carlosgalvezp Sorry, I should have mentioned that I don't have push rights and 
that this is my first contribution.
My GitHub user is:  bjosv   and email:  bjorn.a.svens...@est.tech
Thanks.


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

https://reviews.llvm.org/D143996

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


[clang] dbf149c - [RISCV] Properly diagnose mixing RVV scalable vectors with GNU vectors.

2023-02-23 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-02-23T09:00:32-08:00
New Revision: dbf149c91b7bdf08b2d4dd94ab76f3209af4c6d4

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

LOG: [RISCV] Properly diagnose mixing RVV scalable vectors with GNU vectors.

This case was being picked up by SVE code and printing an SVE
specific message.

This patch distinquishes RVV from SVE and provides a correct error
message for RVV.

The use of the generic isSizelessBuiltinType was also picking up
WebAssembly reference types which was probably an accident so I've
removed that.

I've named the test similar to SVE's test that contains this check.
Their test also tests the arm_sve_vector_bits attribute. I plan to
add something similar for RISC-V soon so I've adopted this naming.

Reviewed By: c-rhodes

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

Added: 
clang/test/Sema/attr-riscv-rvv-vector-bits.c

Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 7dd058b9c53c..10cb4c819d7c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2029,6 +2029,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// Returns true for SVE scalable vector types.
   bool isSVESizelessBuiltinType() const;
 
+  /// Returns true for RVV scalable vector types.
+  bool isRVVSizelessBuiltinType() const;
+
   /// Check if this is a WebAssembly Reference Type.
   bool isWebAssemblyReferenceType() const;
   bool isWebAssemblyExternrefType() const;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 86c5c4e288c9..81e3f5e2d062 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3165,8 +3165,8 @@ def err_attribute_zero_size : Error<"zero %0 size">;
 def err_attribute_size_too_large : Error<"%0 size too large">;
 def err_typecheck_sve_ambiguous : Error<
   "cannot combine fixed-length and sizeless SVE vectors in expression, result 
is ambiguous (%0 and %1)">;
-def err_typecheck_sve_gnu_ambiguous : Error<
-  "cannot combine GNU and SVE vectors in expression, result is ambiguous (%0 
and %1)">;
+def err_typecheck_sve_rvv_gnu_ambiguous : Error<
+  "cannot combine GNU and %select{SVE|RVV}0 vectors in expression, result is 
ambiguous (%1 and %2)">;
 def err_typecheck_vector_not_convertable_implict_truncation : Error<
"cannot convert between %select{scalar|vector}0 type %1 and vector type"
" %2 as implicit conversion would cause truncation">;

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 04359c7d82cb..7710adbb274a 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2372,6 +2372,19 @@ bool Type::isSVESizelessBuiltinType() const {
   return false;
 }
 
+bool Type::isRVVSizelessBuiltinType() const {
+  if (const BuiltinType *BT = getAs()) {
+switch (BT->getKind()) {
+#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/RISCVVTypes.def"
+  return true;
+default:
+  return false;
+}
+  }
+  return false;
+}
+
 bool Type::isVLSTBuiltinType() const {
   if (const BuiltinType *BT = getAs()) {
 switch (BT->getKind()) {

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3b8c8a4def51..817eed986e08 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10750,12 +10750,14 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, 
ExprResult &RHS,
 return QualType();
   }
 
-  // Expressions containing GNU and SVE (fixed or sizeless) vectors are invalid
-  // since the ambiguity can affect the ABI.
-  auto IsSveGnuConversion = [](QualType FirstType, QualType SecondType) {
+  // Expressions containing GNU and SVE or RVV (fixed or sizeless) vectors are
+  // invalid since the ambiguity can affect the ABI.
+  auto IsSveRVVGnuConversion = [](QualType FirstType, QualType SecondType,
+  unsigned &SVEorRVV) {
 const VectorType *FirstVecType = FirstType->getAs();
 const VectorType *SecondVecType = SecondType->getAs();
 
+SVEorRVV = 0;
 if (FirstVecType && SecondVecType)
   return FirstVecType->getVectorKind() == VectorType::GenericVector &&
  (SecondVecType->getVectorKind() ==
@@ -10763,13 +10765,24 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, 
ExprResult &RHS,
   SecondVecType->getVectorKind() ==
   VectorType::SveFixedLengthPredicateVector);
 
-return FirstType->isSizelessBuiltinType() && SecondVecType &&
-   SecondVecType-

[PATCH] D144613: [RISCV] Properly diagnose mixing RVV scalable vectors with GNU vectors.

2023-02-23 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdbf149c91b7b: [RISCV] Properly diagnose mixing RVV scalable 
vectors with GNU vectors. (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D144613?vs=499711&id=499882#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144613

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/attr-riscv-rvv-vector-bits.c

Index: clang/test/Sema/attr-riscv-rvv-vector-bits.c
===
--- /dev/null
+++ clang/test/Sema/attr-riscv-rvv-vector-bits.c
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +zve64x -ffreestanding -fsyntax-only -verify %s
+
+// TODO: Support for a arm_sve_vector_bits like attribute will come in the future.
+
+#include 
+
+#define N 64
+
+typedef __rvv_int8m1_t vint8m1_t;
+typedef __rvv_uint8m1_t vuint8m1_t;
+typedef __rvv_int16m1_t vint16m1_t;
+typedef __rvv_uint16m1_t vuint16m1_t;
+typedef __rvv_int32m1_t vint32m1_t;
+typedef __rvv_uint32m1_t vuint32m1_t;
+typedef __rvv_int64m1_t vint64m1_t;
+typedef __rvv_uint64m1_t vuint64m1_t;
+typedef __rvv_float32m1_t vfloat32m1_t;
+typedef __rvv_float64m1_t vfloat64m1_t;
+
+// GNU vector types
+typedef int8_t gnu_int8_t __attribute__((vector_size(N / 8)));
+typedef int16_t gnu_int16_t __attribute__((vector_size(N / 8)));
+typedef int32_t gnu_int32_t __attribute__((vector_size(N / 8)));
+typedef int64_t gnu_int64_t __attribute__((vector_size(N / 8)));
+
+typedef uint8_t gnu_uint8_t __attribute__((vector_size(N / 8)));
+typedef uint16_t gnu_uint16_t __attribute__((vector_size(N / 8)));
+typedef uint32_t gnu_uint32_t __attribute__((vector_size(N / 8)));
+typedef uint64_t gnu_uint64_t __attribute__((vector_size(N / 8)));
+
+typedef float gnu_float32_t __attribute__((vector_size(N / 8)));
+typedef double gnu_float64_t __attribute__((vector_size(N / 8)));
+
+
+void f(int c) {
+  vint8m1_t ss8;
+  gnu_int8_t gs8;
+
+  // Check conditional expressions where the result is ambiguous are
+  // ill-formed.
+  void *sel __attribute__((unused));
+
+  sel = c ? gs8 : ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+  sel = c ? ss8 : gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  // Check binary expressions where the result is ambiguous are ill-formed.
+  ss8 = ss8 + gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  gs8 = gs8 + ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  ss8 += gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  gs8 += ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  ss8 = ss8 == gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  gs8 = gs8 == ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  ss8 = ss8 & gs8; // expected-error {{invalid operands to binary expression ('vint8m1_t' (aka '__rvv_int8m1_t') and 'gnu_int8_t' (vector of 8 'int8_t' values))}}
+
+  gs8 = gs8 & ss8; // expected-error {{invalid operands to binary expression ('gnu_int8_t' (vector of 8 'int8_t' values) and 'vint8m1_t' (aka '__rvv_int8m1_t'))}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10750,12 +10750,14 @@
 return QualType();
   }
 
-  // Expressions containing GNU and SVE (fixed or sizeless) vectors are invalid
-  // since the ambiguity can affect the ABI.
-  auto IsSveGnuConversion = [](QualType FirstType, QualType SecondType) {
+  // Expressions containing GNU and SVE or RVV (fixed or sizeless) vectors are
+  // invalid since the ambiguity can affect the ABI.
+  auto IsSveRVVGnuConversion = [](QualType FirstType, QualType SecondType,
+  unsigned &SVEorRVV) {
 const VectorType *FirstVecType = FirstType->getAs();
 const VectorType *SecondVecType = SecondType->getAs();
 
+SVEorRVV = 0;
 if (FirstVecType && SecondVecType)
   return FirstVecType->getVectorKind() == VectorType::GenericVector &&
  (SecondVecType->getVectorKind() ==
@@ -10763,13 +10765,24 @@
   SecondVecType->getVectorKind() ==
   VectorType::SveFixedLengthPredicateVector);
 
-return FirstType->isSizelessBuiltinType() && SecondVecType &&
-   SecondVecType->getVectorKind() == VectorType::GenericVector;
+if (SecondVecType &&
+SecondVecType->getVectorKind() == VectorType:

[clang] 83cd4be - [Clang] Teach buildFMulAdd to peek through fneg to find fmul.

2023-02-23 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-02-23T09:05:59-08:00
New Revision: 83cd4bea015feb5729871832784c424b0743a803

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

LOG: [Clang] Teach buildFMulAdd to peek through fneg to find fmul.

Allows us to handle expressions like -(a * b) + c

Based on the examples from D144366 that gcc seems to get.

Reviewed By: kpn

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

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/constrained-math-builtins.c
clang/test/CodeGen/fp-contract-pragma.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index a0dcb978b1ac..2243c75ed260 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -3734,8 +3734,6 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
 static Value* buildFMulAdd(llvm::Instruction *MulOp, Value *Addend,
const CodeGenFunction &CGF, CGBuilderTy &Builder,
bool negMul, bool negAdd) {
-  assert(!(negMul && negAdd) && "Only one of negMul and negAdd should be 
set.");
-
   Value *MulOp0 = MulOp->getOperand(0);
   Value *MulOp1 = MulOp->getOperand(1);
   if (negMul)
@@ -3780,31 +3778,70 @@ static Value* tryEmitFMulAdd(const BinOpInfo &op,
   if (!op.FPFeatures.allowFPContractWithinStatement())
 return nullptr;
 
+  Value *LHS = op.LHS;
+  Value *RHS = op.RHS;
+
+  // Peek through fneg to look for fmul. Make sure fneg has no users, and that
+  // it is the only use of its operand.
+  bool NegLHS = false;
+  if (auto *LHSUnOp = dyn_cast(LHS)) {
+if (LHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+LHSUnOp->use_empty() && LHSUnOp->getOperand(0)->hasOneUse()) {
+  LHS = LHSUnOp->getOperand(0);
+  NegLHS = true;
+}
+  }
+
+  bool NegRHS = false;
+  if (auto *RHSUnOp = dyn_cast(RHS)) {
+if (RHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+RHSUnOp->use_empty() && RHSUnOp->getOperand(0)->hasOneUse()) {
+  RHS = RHSUnOp->getOperand(0);
+  NegRHS = true;
+}
+  }
+
   // We have a potentially fusable op. Look for a mul on one of the operands.
   // Also, make sure that the mul result isn't used directly. In that case,
   // there's no point creating a muladd operation.
-  if (auto *LHSBinOp = dyn_cast(op.LHS)) {
+  if (auto *LHSBinOp = dyn_cast(LHS)) {
 if (LHSBinOp->getOpcode() == llvm::Instruction::FMul &&
-LHSBinOp->use_empty())
-  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, false, isSub);
+(LHSBinOp->use_empty() || NegLHS)) {
+  // If we looked through fneg, erase it.
+  if (NegLHS)
+cast(op.LHS)->eraseFromParent();
+  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, NegLHS, isSub);
+}
   }
-  if (auto *RHSBinOp = dyn_cast(op.RHS)) {
+  if (auto *RHSBinOp = dyn_cast(RHS)) {
 if (RHSBinOp->getOpcode() == llvm::Instruction::FMul &&
-RHSBinOp->use_empty())
-  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub, false);
+(RHSBinOp->use_empty() || NegRHS)) {
+  // If we looked through fneg, erase it.
+  if (NegRHS)
+cast(op.RHS)->eraseFromParent();
+  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub ^ NegRHS, 
false);
+}
   }
 
-  if (auto *LHSBinOp = dyn_cast(op.LHS)) {
+  if (auto *LHSBinOp = dyn_cast(LHS)) {
 if (LHSBinOp->getIntrinsicID() ==
 llvm::Intrinsic::experimental_constrained_fmul &&
-LHSBinOp->use_empty())
-  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, false, isSub);
+(LHSBinOp->use_empty() || NegLHS)) {
+  // If we looked through fneg, erase it.
+  if (NegLHS)
+cast(op.LHS)->eraseFromParent();
+  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, NegLHS, isSub);
+}
   }
-  if (auto *RHSBinOp = dyn_cast(op.RHS)) {
+  if (auto *RHSBinOp = dyn_cast(RHS)) {
 if (RHSBinOp->getIntrinsicID() ==
 llvm::Intrinsic::experimental_constrained_fmul &&
-RHSBinOp->use_empty())
-  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub, false);
+(RHSBinOp->use_empty() || NegRHS)) {
+  // If we looked through fneg, erase it.
+  if (NegRHS)
+cast(op.RHS)->eraseFromParent();
+  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub ^ NegRHS, 
false);
+}
   }
 
   return nullptr;

diff  --git a/clang/test/CodeGen/constrained-math-builtins.c 
b/clang/test/CodeGen/constrained-math-builtins.c
index d817cce33679..cccfd8bc7746 100644
--- a/clang/test/CodeGen/constrained-math-builtins.c
+++ b/clang/test/CodeGen/constrained-math-builtins.c
@@ -300,10 +300,17 @@ void bar(float f) {
   f * f + f;
   (double)f * f - f;
   (long dou

[PATCH] D144447: [Clang] Teach buildFMulAdd to peek through fneg to find fmul.

2023-02-23 Thread Craig Topper 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 rG83cd4bea015f: [Clang] Teach buildFMulAdd to peek through 
fneg to find fmul. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D17

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/constrained-math-builtins.c
  clang/test/CodeGen/fp-contract-pragma.cpp

Index: clang/test/CodeGen/fp-contract-pragma.cpp
===
--- clang/test/CodeGen/fp-contract-pragma.cpp
+++ clang/test/CodeGen/fp-contract-pragma.cpp
@@ -89,3 +89,54 @@
   #pragma STDC FP_CONTRACT ON
   return c - a * b;
 }
+
+float fp_contract_10(float a, float b, float c) {
+// CHECK: _Z14fp_contract_10fff
+// CHECK: fneg float %a
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return -(a * b) + c;
+}
+
+float fp_contract_11(float a, float b, float c) {
+// CHECK: _Z14fp_contract_11fff
+// CHECK: fneg float %a
+// CHECK: fneg float %c
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return -(a * b) - c;
+}
+
+float fp_contract_12(float a, float b, float c) {
+// CHECK: _Z14fp_contract_12fff
+// CHECK: fneg float %a
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return c + -(a * b);
+}
+
+float fp_contract_13(float a, float b, float c) {
+// CHECK: _Z14fp_contract_13fff
+// CHECK-NOT: fneg float %a
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return c - -(a * b);
+}
+
+float fp_contract_14(float a, float b, float c) {
+// CHECK: _Z14fp_contract_14fff
+// CHECK: %[[M:.+]] = fmul float %a, %b
+// CHECK-NEXT: %add = fsub float %c, %[[M]]
+  #pragma STDC FP_CONTRACT ON
+  float d;
+  return (d = -(a * b)) + c;
+}
+
+float fp_contract_15(float a, float b, float c) {
+// CHECK: _Z14fp_contract_15fff
+// CHECK: %[[M:.+]] = fmul float %a, %b
+// CHECK-NEXT: %add = fsub float %c, %[[M]]
+  #pragma STDC FP_CONTRACT ON
+  float d;
+  return -(d = (a * b)) + c;
+}
Index: clang/test/CodeGen/constrained-math-builtins.c
===
--- clang/test/CodeGen/constrained-math-builtins.c
+++ clang/test/CodeGen/constrained-math-builtins.c
@@ -300,10 +300,17 @@
   f * f + f;
   (double)f * f - f;
   (long double)-f * f + f;
+  -(f * f) - f;
+  f + -(f * f);
 
   // CHECK: call float @llvm.experimental.constrained.fmuladd.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
   // CHECK: fneg
   // CHECK: call double @llvm.experimental.constrained.fmuladd.f64(double %{{.*}}, double %{{.*}}, double %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
   // CHECK: fneg
   // CHECK: call x86_fp80 @llvm.experimental.constrained.fmuladd.f80(x86_fp80 %{{.*}}, x86_fp80 %{{.*}}, x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // CHECK: fneg
+  // CHECK: fneg
+  // CHECK: call float @llvm.experimental.constrained.fmuladd.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // CHECK: fneg
+  // CHECK: call float @llvm.experimental.constrained.fmuladd.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
 };
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -3734,8 +3734,6 @@
 static Value* buildFMulAdd(llvm::Instruction *MulOp, Value *Addend,
const CodeGenFunction &CGF, CGBuilderTy &Builder,
bool negMul, bool negAdd) {
-  assert(!(negMul && negAdd) && "Only one of negMul and negAdd should be set.");
-
   Value *MulOp0 = MulOp->getOperand(0);
   Value *MulOp1 = MulOp->getOperand(1);
   if (negMul)
@@ -3780,31 +3778,70 @@
   if (!op.FPFeatures.allowFPContractWithinStatement())
 return nullptr;
 
+  Value *LHS = op.LHS;
+  Value *RHS = op.RHS;
+
+  // Peek through fneg to look for fmul. Make sure fneg has no users, and that
+  // it is the only use of its operand.
+  bool NegLHS = false;
+  if (auto *LHSUnOp = dyn_cast(LHS)) {
+if (LHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+LHSUnOp->use_empty() && LHSUnOp->getOperand(0)->hasOneUse()) {
+  LHS = LHSUnOp->getOperand(0);
+  NegLHS = true;
+}
+  }
+
+  bool NegRHS = false;
+  if (auto *RHSUnOp = dyn_cast(RHS)) {
+if (RHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+RHSUnOp->use_empty() && RHSUnOp->getOperand(0)->hasOneUse()) {
+  RHS = RHSUnOp->getOperand(0);
+  NegRHS = true;
+}
+  }
+
   // We have a potentially fusable op. Look for a mul on one of the operands.
   // Also, make sure that 

[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-02-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: mstorsjo, jansvoboda11, DHowett-MSFT, sammccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix two problems happening during deserialization causing command line defines 
to be reported as being built-in defines:

- When deserializing SM_SLOC_BUFFER_ENTRY we need to call setHasLineDirectives 
in the same way as we do for SM_SLOC_FILE_ENTRY.
- When created suggested predefines based on the current command line options 
we need to add line markers in the same way that InitializePreprocessor does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144651

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c


Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header 
('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd 
on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in 
precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in 
precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | 
FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  SrcMgr::FileInfo &FileInfo =
+const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 


Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTReader.cpp

[PATCH] D144626: [C++20] [Modules] Provide OriginalTrailingRequiresClause for serializer to perform ODR-Checking correctly

2023-02-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I think the problem is more that we are modifying the expression in the AST.  I 
don't think now that we have the 'deferred concepts instantiation' that we 
should be storing/saving the updated requires clause back to the AST, right?  
We should be re-evaluating it (with a cache!).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144626

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 499886.
VitaNuo added a comment.

Upload once again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp

Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -49,8 +49,8 @@
   }
 }
 
-static std::string spellHeader(const Header &H, HeaderSearch &HS,
-   const FileEntry *Main) {
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
 bool IsSystem = false;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -73,6 +73,8 @@
 std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main);
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -8,26 +8,57 @@
 
 #include "Annotations.h"
 #include "Config.h"
+#include "Diagnostics.h"
 #include "IncludeCleaner.h"
+#include "ParsedAST.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "support/Context.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
+using ::testing::Matcher;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
+Matcher withFix(::testing::Matcher FixMatcher) {
+  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+}
+
+MATCHER_P2(Diag, Range, Message,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
+  return arg.Range == Range && arg.Message == Message;
+}
+
+MATCHER_P3(Fix, Range, Replacement, Message,
+   "Fix " + llvm::to_string(Range) + " => " +
+   ::testing::PrintToString(Replacement) + " = [" + Message + "]") {
+  return arg.Message == Message && arg.Edits.size() == 1 &&
+ arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
+}
+
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
 }
@@ -342,7 +373,8 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes,
   ElementsAre(Pointee(writtenInclusion("";
 }
 
@@ -379,12 +411,98 @@
   computeUnusedIncludes(AST),
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
+
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
   EXPECT_THAT(
-  computeUnusedIncludesExperimental(AST),
+  Findings.UnusedIncludes,
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
 }
 
+TEST(Includ

[PATCH] D144626: [C++20] [Modules] Provide OriginalTrailingRequiresClause for serializer to perform ODR-Checking correctly

2023-02-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Woops, I just saw my fixme :D  I forgot we needed to do that for comparison of 
constraints.  That said I dont think you need to store it, I think we can just 
pick up the 'original' one from the primary template.  I did work at one point 
to make sure that the get-instantiated-from-template stuff worked correctly for 
friends like that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144626

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


  1   2   >