[PATCH] D105426: [clangd] IWYU as a library: Find all references to symbols in the file

2021-08-06 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 364709.
kbobyrev added a comment.

Improve comments, refactor some pieces, add more tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IWYU.cpp
  clang-tools-extra/clangd/IWYU.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IWYUTests.cpp

Index: clang-tools-extra/clangd/unittests/IWYUTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IWYUTests.cpp
@@ -0,0 +1,127 @@
+//===--- IWYUTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "IWYU.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAreArray;
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "struct ^X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  "struct Foo; struct ^Foo{}; typedef Foo ^Bar;",
+  "Bar b;",
+  },
+  {
+  "class ^X{}; X ^getX();",
+  "auto x = getX();",
+  },
+  {
+  "namespace ns { struct ^X; struct ^X {}; }",
+  "using ns::X;",
+  },
+  {
+  "namespace ns { struct X; struct X {}; }",
+  "using namespace ns;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should B also be marked as used?
+  "struct ^A {}; using B = A; using ^C = B;",
+  "C a;",
+  },
+  {
+  "enum ^Color { ^Red = 42, Green = 9000};",
+  "int MyColor = Red;",
+  },
+  {
+  "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
+  "int Lang = X::CXX;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should report the UsingDecl.
+  // This information is not preserved in the AST.
+  // ^
+  "namespace ns { class ^X; }; using ns::X;",
+  "X *y;",
+  }};
+  for (const TestCase &T : Cases) {
+TestTU TU;
+TU.Code = T.MainCode;
+Annotations Header(T.HeaderCode);
+TU.HeaderCode = Header.code().str();
+auto AST = TU.build();
+
+std::vector Points;
+for (const auto &Loc : findReferencedLocations(AST)) {
+  if (AST.getSourceManager().getBufferName(Loc).endswith(
+  TU.HeaderFilename)) {
+Points.push_back(offsetToPosition(
+TU.HeaderCode, AST.getSourceManager().getFileOffset(Loc)));
+  }
+}
+llvm::sort(Points);
+
+EXPECT_EQ(Points, Header.points()) << T.HeaderCode << "\n---\n"
+   << T.MainCode;
+  }
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -61,6 +61,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
+  IWYUTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
   LSPBinderTests.cpp
Index: clang-tools-extra/clangd/IWYU.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IWYU.h
@@ -0,0 +1,55 @@
+//===--- IWYU.h - include-what-you-use analysis -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH

[PATCH] D96324: [clangd] Rename references to function arguments within the same file

2021-08-06 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.
Herald added a project: clang-tools-extra.

Ping! Do you think this is a reasonable idea? I think if we just check whether 
there aren't any references to the function outside of the main file we should 
be safe enough to rename args.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96324

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


[PATCH] D106401: [CUDA, MemCpyOpt] Add a flag to force-enable memcpyopt and use it for CUDA.

2021-08-06 Thread Alina Sbirlea via Phabricator via cfe-commits
asbirlea accepted this revision.
asbirlea 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/D106401/new/

https://reviews.llvm.org/D106401

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


[PATCH] D105426: [clangd] IWYU as a library: Find all references to symbols in the file

2021-08-06 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 364714.
kbobyrev added a comment.

Remove some code from the next chunk of IWYU work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/IWYU.cpp
  clang-tools-extra/clangd/IWYU.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IWYUTests.cpp

Index: clang-tools-extra/clangd/unittests/IWYUTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IWYUTests.cpp
@@ -0,0 +1,127 @@
+//===--- IWYUTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "IWYU.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAreArray;
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "struct ^X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  "struct Foo; struct ^Foo{}; typedef Foo ^Bar;",
+  "Bar b;",
+  },
+  {
+  "class ^X{}; X ^getX();",
+  "auto x = getX();",
+  },
+  {
+  "namespace ns { struct ^X; struct ^X {}; }",
+  "using ns::X;",
+  },
+  {
+  "namespace ns { struct X; struct X {}; }",
+  "using namespace ns;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should B also be marked as used?
+  "struct ^A {}; using B = A; using ^C = B;",
+  "C a;",
+  },
+  {
+  "enum ^Color { ^Red = 42, Green = 9000};",
+  "int MyColor = Red;",
+  },
+  {
+  "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
+  "int Lang = X::CXX;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should report the UsingDecl.
+  // This information is not preserved in the AST.
+  // ^
+  "namespace ns { class ^X; }; using ns::X;",
+  "X *y;",
+  }};
+  for (const TestCase &T : Cases) {
+TestTU TU;
+TU.Code = T.MainCode;
+Annotations Header(T.HeaderCode);
+TU.HeaderCode = Header.code().str();
+auto AST = TU.build();
+
+std::vector Points;
+for (const auto &Loc : findReferencedLocations(AST)) {
+  if (AST.getSourceManager().getBufferName(Loc).endswith(
+  TU.HeaderFilename)) {
+Points.push_back(offsetToPosition(
+TU.HeaderCode, AST.getSourceManager().getFileOffset(Loc)));
+  }
+}
+llvm::sort(Points);
+
+EXPECT_EQ(Points, Header.points()) << T.HeaderCode << "\n---\n"
+   << T.MainCode;
+  }
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -61,6 +61,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
+  IWYUTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
   LSPBinderTests.cpp
Index: clang-tools-extra/clangd/IWYU.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IWYU.h
@@ -0,0 +1,55 @@
+//===--- IWYU.h - include-what-you-use analysis -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===

[PATCH] D107624: [clangd] Rename Features.h -> Feature.h to avoid confilct with libstdc++

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

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107624

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/Feature.cpp
  clang-tools-extra/clangd/Feature.h
  clang-tools-extra/clangd/Features.cpp
  clang-tools-extra/clangd/Features.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Transport.h
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.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
@@ -9,8 +9,8 @@
 #include "Annotations.h"
 #include "Config.h"
 #include "Diagnostics.h"
+#include "Feature.h"
 #include "FeatureModule.h"
-#include "Features.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -9,7 +9,7 @@
 #include "Config.h"
 #include "ConfigFragment.h"
 #include "ConfigTesting.h"
-#include "Features.h"
+#include "Feature.h"
 #include "TestFS.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/ADT/None.h"
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -10,7 +10,7 @@
 #include "CodeComplete.h"
 #include "Config.h"
 #include "ConfigProvider.h"
-#include "Features.h"
+#include "Feature.h"
 #include "PathMapping.h"
 #include "Protocol.h"
 #include "TidyProvider.h"
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "Features.h"
+#include "Feature.h"
 #include "Index.pb.h"
 #include "MonitoringService.grpc.pb.h"
 #include "MonitoringService.pb.h"
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -9,7 +9,7 @@
 #include 
 
 #include "Client.h"
-#include "Features.h"
+#include "Feature.h"
 #include "Service.grpc.pb.h"
 #include "index/Index.h"
 #include "marshalling/Marshalling.h"
Index: clang-tools-extra/clangd/Transport.h
===
--- clang-tools-extra/clangd/Transport.h
+++ clang-tools-extra/clangd/Transport.h
@@ -18,7 +18,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
 
-#include "Features.h"
+#include "Feature.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -14,8 +14,8 @@
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
+#include "Feature.h"
 #include "FeatureModule.h"
-#include "Features.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
 #include "IncludeFixer.h"
Index: clang-tools-extra/clangd/Feature.h
===
--- clang-tools-extra/clangd/Feature.h
+++ clang-tools-extra/clangd/Feature.h
@@ -1,13 +1,16 @@
-//===--- Features.h - Compile-time configuration --*-C++-*-===//
+//===--- Feature.h - Compile-time configuration --*-C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
+// This file is not named "Features.h" because of a

[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-06 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/tools/libclang/libclang.map:1
-/* If you add a symbol to this file, make sure to add it with the correct
- * version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
- * symbols with the version LLVM_14.
- * On platforms where versions scripts are not used, this file will be used to
- * generate a list of exports for libclang.so
- */
-
+# If you add a symbol to this file, make sure to add it with the correct
+# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new

MaskRay wrote:
> MaskRay wrote:
> > ro wrote:
> > > MaskRay wrote:
> > > > GNU ld doesn't support `#` comments. ld.lld supports it.
> > > Drats, I'd have sworn they supported `#' comments, too,
> > > especially since the version script syntax originated with
> > > Sun and was later adopted by GNU `ld`.
> > Confirmed that GNU ld and gold support `#` in version scripts, but not in 
> > linker scripts.
> > 
> > ld.lld supports both.
> > 
> > Using `#` is fine to me if Solaris ld doesn't support `/*` in GNU version 
> > scripts.
> Correction: only GNU ld doesn't support `#` in linker scripts.
> 
> ld.lld and gold support `#` everywhere.
> 
> Filed a GNU ld feature request 
> https://sourceware.org/bugzilla/show_bug.cgi?id=28198
I'd only checked `ld.texi` and didn't even think of trying it when it wasn't 
documented there.

I can ask about C-style comments being added to Solaris `ld`, but I've never 
encountered the need before.

So the original patch is ok after all?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-06 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

Ah, I forgot: I've meanwhile tested the patch on `x86-64-pc-linux-gnu` (Ubuntu 
20.04) where `/usr/bin/ld` is from binutils 2.34: `libclang.so` was versioned 
just the same without and with the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D106216: Disallow narrowing conversions to bool in noexcept specififers.

2021-08-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 364719.
cor3ntin added a comment.

Remove whitespace only change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106216

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/except/except.spec/p1.cpp
  clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  Clang 13
+  Clang 13
 
 
   Trimming whitespaces before line splicing
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -876,7 +876,7 @@
   EXPECT_TRUE(
   matches("void foo() noexcept; bool bar = noexcept(foo());", NoExcept));
   EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept));
-  EXPECT_TRUE(notMatches("void foo() noexcept(1+1);", NoExcept));
+  EXPECT_TRUE(notMatches("void foo() noexcept(0+1);", NoExcept));
   EXPECT_TRUE(matches("void foo() noexcept(noexcept(1+1));", NoExcept));
 }
 
Index: clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
===
--- clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -151,7 +151,7 @@
 void (*q[])() = { p... };
 consume((p(),0)...);
   }
-  template void g(void (*...p)() noexcept (B)) {
+  template  void g(void (*...p)() noexcept(B)) {
 consume((p(),0)...);
 check();
   }
Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -727,3 +727,18 @@
 Str b = "not so short";// expected-error {{no viable conversion}}
 
 }
+
+namespace P1401 {
+
+const int *ptr;
+
+struct S {
+  explicit(sizeof(char[2])) S(char); // expected-error {{explicit specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
+  explicit(ptr) S(long); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
+  explicit(nullptr) S(int);  // expected-error {{conversion from 'nullptr_t' to 'bool' is not allowed in a converted constant expression}}
+  explicit(42L) S(int, int); // expected-error {{explicit specifier argument evaluates to 42, which cannot be narrowed to type 'bool'}}
+  explicit(sizeof(char)) S();
+  explicit(0) S(char, char);
+  explicit(1L) S(char, char, char);
+};
+} // namespace P1401
Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -77,6 +77,17 @@
 }
 
 struct pr_44514 {
-  // expected-error@+1{{value of type 'void' is not contextually convertible to 'bool'}}
+  // expected-error@+1{{value of type 'void' is not implicitly convertible to 'bool'}}
   void foo(void) const &noexcept(f());
 };
+
+namespace P1401 {
+const int *ptr = nullptr;
+void f() noexcept(sizeof(char[2])); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
+void g() noexcept(sizeof(char));
+void h() noexcept(ptr); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
+void i() noexcept(nullptr); // expected-error {{conversion from 'nullptr_t' to 'bool' is not allowed in a converted constant expression}}
+void j() noexcept(0);
+void k() noexcept(1);
+void l() noexcept(2); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
+} // namespace P1401
Index: clang/test/CXX/except/except.spec/p1.cpp
===
--- clang/test/CXX/except/except.spec/p1.cpp
+++ clang/test/CXX/except/except.spec/p1.cpp
@@ -54,9 +54,8 @@
 
   struct A {};
 
-  void g1() noexcept(A()); // expected-error {{not contextually convertible}}
-  void g2(bool b) noexcept(b); // expected-error {{argument to noexcept specifier must be a constant expression}} expected-note {{function parameter 'b' with unknown value}} expected-note {{here}}
-
+  void g1() noexc

[PATCH] D106262: [clang][analyzer] Use generic note tag in alpha.unix.Stream .

2021-08-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 364730.
balazske added a comment.

Using "joined" note tag messages to have bugtype independent note tag functions.
New note tags at `ferror` and `feof`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106262

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -33,12 +33,12 @@
 // expected-note@-2 {{Opened stream never closed. Potential resource leak}}
 
 void check_note_freopen() {
-  FILE *F = fopen("file", "r"); // expected-note {{Stream opened here}}
+  FILE *F = fopen("file", "r");
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}
 return;
-  F = freopen(0, "w", F); // expected-note {{Stream reopened here}}
+  F = freopen(0, "w", F); // expected-note {{Stream opened here}}
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -47,6 +47,33 @@
 // expected-warning@-1 {{Opened stream never closed. Potential resource leak}}
 // expected-note@-2 {{Opened stream never closed. Potential resource leak}}
 
+void check_note_fopen_fail() {
+  FILE *F = fopen("file", "r"); // expected-note {{Stream open fails here}} expected-note {{Assuming pointer value is null}} expected-note {{'F' initialized here}}
+  fclose(F);// expected-warning {{Stream pointer might be NULL}}
+  // expected-note@-1 {{Stream pointer might be NULL}}
+}
+
+void check_note_freopen_fail() {
+  FILE *F = fopen("file", "r");
+  if (!F) // expected-note {{'F' is non-null}} expected-note {{Taking false branch}}
+return;
+  freopen(0, "w", F); // expected-note {{Stream reopen fails here}}
+  fclose(F);  // expected-warning {{Stream might be invalid after (re-)opening it has failed. Can cause undefined behaviour}}
+  // expected-note@-1 {{Stream might be invalid after (re-)opening it has failed. Can cause undefined behaviour}}
+}
+
+void check_note_freopen_fail_null() {
+  // FIXME: The following note should not be here.
+  FILE *F = fopen("file", "r"); // expected-note {{Stream opened here}}
+  if (!F) // expected-note {{'F' is non-null}} expected-note {{Taking false branch}}
+return;
+  // FIXME: Note about failing 'freopen' belongs here.
+  // Why is a note at 'fopen'?
+  F = freopen(0, "w", F); // expected-note {{Null pointer value stored to 'F'}}
+  fclose(F);  // expected-warning {{Stream pointer might be NULL}}
+  // expected-note@-1 {{Stream pointer might be NULL}}
+}
+
 void check_note_leak_2(int c) {
   FILE *F1 = fopen("foo1.c", "r"); // expected-note {{Stream opened here}}
   if (!F1)
@@ -80,7 +107,7 @@
 
 void check_track_null() {
   FILE *F;
-  F = fopen("foo1.c", "r"); // expected-note {{Value assigned to 'F'}} expected-note {{Assuming pointer value is null}}
+  F = fopen("foo1.c", "r"); // expected-note {{Value assigned to 'F'}} expected-note {{Assuming pointer value is null}} expected-note {{Stream open fails here}}
   if (F != NULL) {  // expected-note {{Taking false branch}} expected-note {{'F' is equal to NULL}}
 fclose(F);
 return;
@@ -99,8 +126,8 @@
   fread(Buf, 1, 1, F);
   if (feof(F)) { // expected-note {{Taking true branch}}
 clearerr(F);
-fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file here}}
-if (feof(F)) { // expected-note {{Taking true branch}}
+fread(Buf, 1, 1, F);   // expected-note {{Stream reaches end-of-file or operation fails here}}
+if (feof(F)) { // expected-note {{Assuming the end-of-file flag is set on the stream}} expected-note {{Taking true branch}}
   fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
   // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
 }
@@ -123,8 +150,8 @@
 fclose(F);
 return;
   }
-  fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file here}}
-  if (feof(F)) { // expected-note {{Taking true branch}}
+  fread(Buf, 1, 1, F);   // expected-note {{Stream reaches end-of-file or operation fails here}}
+  if (feof(F)) { // expected-note {{Assuming the end-of-file flag is set on the stream}} expected-note {{Taking true branch}}
 fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
 // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
   }
@@ -137,11 +164,71 @@
   F = fopen("foo1.c", "r");
   if (F == NULL) // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
-  int RRet = 

[clang] 22fdf61 - [OpenCL][Docs] Adding builtins requires adding to both now

2021-08-06 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-06T10:21:26+01:00
New Revision: 22fdf617b6103df30ffae6cf469b78036e4ba615

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

LOG: [OpenCL][Docs] Adding builtins requires adding to both now

As we are trying to reach parity between opencl-c.h and
-fdeclare-opencl-builtins, ensure the documentation mentions that new
builtins should be added to both.

Reviewed by: Anastasia Stulova

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 047c73f2834a5..2067596954916 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -252,7 +252,7 @@ with :ref:`-cl-ext ` command-line flags.
 **Library functionality**
 
 If an extension adds functionality that does not modify standard language
-parsing it should not require modifying anything other than header files or
+parsing it should not require modifying anything other than header files and
 ``OpenCLBuiltins.td`` detailed in :ref:`OpenCL builtins `.
 Most commonly such extensions add functionality via libraries (by adding
 non-native types or functions) parsed regularly. Similar to other languages 
this



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


[clang] a5a2f05 - [C++4OpenCL] Introduces __remove_address_space utility

2021-08-06 Thread Justas Janickas via cfe-commits

Author: Justas Janickas
Date: 2021-08-06T10:40:22+01:00
New Revision: a5a2f05dcc803e79a797fb82dc0932a1a00ac46f

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

LOG: [C++4OpenCL] Introduces __remove_address_space utility

This change provides a way to conveniently declare types that have
address space qualifiers removed.

Since OpenCL adds address spaces implicitly even when they are not
specified in source, it is useful to allow deriving address space
unqualified types.

Fixes llvm.org/PR45326

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

Added: 
clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp

Modified: 
clang/docs/LanguageExtensions.rst
clang/lib/Headers/opencl-c-base.h

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index aaee136530fef..6ced38dd2faef 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1961,6 +1961,30 @@ between the host and device is known to be compatible.
 global OnlySL *d,
   );
 
+Remove address space builtin function
+-
+
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. This utility only affects
+address space qualifiers, therefore, other type qualifiers such as
+``const`` or ``volatile`` remain unchanged.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  template
+  void foo(T *par){
+T var1; // error - local function variable with global address space
+__private T var2; // error - conflicting address space qualifiers
+__private __remove_address_space var3; // var3 is __private int
+  }
+
+  void bar(){
+__global int* ptr;
+foo(ptr);
+  }
+
 Legacy 1.x atomics with generic address space
 -
 

diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 3c5e2c9739368..a9b2364e7457d 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -572,6 +572,26 @@ typedef struct {
 #define as_intptr_t(x) __builtin_astype((x), intptr_t)
 #define as_uintptr_t(x) __builtin_astype((x), uintptr_t)
 
+// C++ for OpenCL - __remove_address_space
+#if defined(__OPENCL_CPP_VERSION__)
+template  struct __remove_address_space { using type = _Tp; };
+template  struct __remove_address_space<__generic _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__global _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__private _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__local _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__constant _Tp> {
+  using type = _Tp;
+};
+#endif
+
 // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers
 
 #define __kernel_exec(X, typen) __kernel \

diff  --git a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp 
b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
new file mode 100644
index 0..f6f0c3290aa66
--- /dev/null
+++ b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins 
-finclude-default-header
+
+template
+struct is_same {
+  static const bool value = false;
+};
+
+template
+struct is_same {
+  static const bool value = true;
+};
+
+void test_is_same() {
+  static_assert(is_same::value);
+  static_assert(!is_same::value);
+  static_assert(!is_same<__private int, int>::value);
+}
+
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space::type, int>::value,
+"type without an address space unexpectedly modified by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space<__generic int>::type, 
int>::value,
+"__generic address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space<__global char>::type, 
char>::value,
+"__global address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space<__private ulong>::type, 
ulong>::value,
+"__private address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space<__local short>::type, 
short>::value,
+"__local address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__constant int3>::type, 
int3>::value,
+"__constant address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space::type, const volatile int>::value,
+"non-address-space qualifiers inappropriately removed by 
__remove_address_space");
+}


 

[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-08-06 Thread Justas Janickas 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 rGa5a2f05dcc80: [C++4OpenCL] Introduces __remove_address_space 
utility (authored by Topotuna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106785

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/Headers/opencl-c-base.h
  clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp

Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header
+
+template
+struct is_same {
+  static const bool value = false;
+};
+
+template
+struct is_same {
+  static const bool value = true;
+};
+
+void test_is_same() {
+  static_assert(is_same::value);
+  static_assert(!is_same::value);
+  static_assert(!is_same<__private int, int>::value);
+}
+
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space::type, int>::value,
+"type without an address space unexpectedly modified by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__generic int>::type, int>::value,
+"__generic address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__global char>::type, char>::value,
+"__global address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value,
+"__private address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__local short>::type, short>::value,
+"__local address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__constant int3>::type, int3>::value,
+"__constant address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space::type, const volatile int>::value,
+"non-address-space qualifiers inappropriately removed by __remove_address_space");
+}
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -572,6 +572,26 @@
 #define as_intptr_t(x) __builtin_astype((x), intptr_t)
 #define as_uintptr_t(x) __builtin_astype((x), uintptr_t)
 
+// C++ for OpenCL - __remove_address_space
+#if defined(__OPENCL_CPP_VERSION__)
+template  struct __remove_address_space { using type = _Tp; };
+template  struct __remove_address_space<__generic _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__global _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__private _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__local _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__constant _Tp> {
+  using type = _Tp;
+};
+#endif
+
 // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers
 
 #define __kernel_exec(X, typen) __kernel \
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1961,6 +1961,30 @@
 global OnlySL *d,
   );
 
+Remove address space builtin function
+-
+
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. This utility only affects
+address space qualifiers, therefore, other type qualifiers such as
+``const`` or ``volatile`` remain unchanged.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  template
+  void foo(T *par){
+T var1; // error - local function variable with global address space
+__private T var2; // error - conflicting address space qualifiers
+__private __remove_address_space var3; // var3 is __private int
+  }
+
+  void bar(){
+__global int* ptr;
+foo(ptr);
+  }
+
 Legacy 1.x atomics with generic address space
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105426: [clangd] IWYU as a library: Find all references to symbols in the file

2021-08-06 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 364735.
kbobyrev added a comment.

Rebase on top of main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/IWYU.cpp
  clang-tools-extra/clangd/IWYU.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IWYUTests.cpp

Index: clang-tools-extra/clangd/unittests/IWYUTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IWYUTests.cpp
@@ -0,0 +1,127 @@
+//===--- IWYUTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "IWYU.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAreArray;
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "struct ^X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  "struct Foo; struct ^Foo{}; typedef Foo ^Bar;",
+  "Bar b;",
+  },
+  {
+  "class ^X{}; X ^getX();",
+  "auto x = getX();",
+  },
+  {
+  "namespace ns { struct ^X; struct ^X {}; }",
+  "using ns::X;",
+  },
+  {
+  "namespace ns { struct X; struct X {}; }",
+  "using namespace ns;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should B also be marked as used?
+  "struct ^A {}; using B = A; using ^C = B;",
+  "C a;",
+  },
+  {
+  "enum ^Color { ^Red = 42, Green = 9000};",
+  "int MyColor = Red;",
+  },
+  {
+  "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
+  "int Lang = X::CXX;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should report the UsingDecl.
+  // This information is not preserved in the AST.
+  // ^
+  "namespace ns { class ^X; }; using ns::X;",
+  "X *y;",
+  }};
+  for (const TestCase &T : Cases) {
+TestTU TU;
+TU.Code = T.MainCode;
+Annotations Header(T.HeaderCode);
+TU.HeaderCode = Header.code().str();
+auto AST = TU.build();
+
+std::vector Points;
+for (const auto &Loc : findReferencedLocations(AST)) {
+  if (AST.getSourceManager().getBufferName(Loc).endswith(
+  TU.HeaderFilename)) {
+Points.push_back(offsetToPosition(
+TU.HeaderCode, AST.getSourceManager().getFileOffset(Loc)));
+  }
+}
+llvm::sort(Points);
+
+EXPECT_EQ(Points, Header.points()) << T.HeaderCode << "\n---\n"
+   << T.MainCode;
+  }
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -61,6 +61,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
+  IWYUTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
   LSPBinderTests.cpp
Index: clang-tools-extra/clangd/IWYU.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IWYU.h
@@ -0,0 +1,55 @@
+//===--- IWYU.h - include-what-you-use analysis -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===

[PATCH] D107632: [clangd] Avoid "expected one compiler job" by picking the first eligible job.

2021-08-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added projects: clang, clang-tools-extra.

This happens in createInvocationWithCommandLine but only clangd currently passes
ShouldRecoverOnErorrs (sic).

One cause of this (with correct command) is several -arch arguments for mac
multi-arch support.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107632

Files:
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp


Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -79,22 +79,24 @@
   }
 }
   }
-  if (Jobs.size() == 0 || !isa(*Jobs.begin()) ||
-  (Jobs.size() > 1 && !OffloadCompilation)) {
+
+  bool PickFirstOfMany = OffloadCompilation || ShouldRecoverOnErorrs;
+  if (Jobs.size() == 0 || (Jobs.size() > 1 && !PickFirstOfMany)) {
 SmallString<256> Msg;
 llvm::raw_svector_ostream OS(Msg);
 Jobs.Print(OS, "; ", true);
 Diags->Report(diag::err_fe_expected_compiler_job) << OS.str();
 return nullptr;
   }
-
-  const driver::Command &Cmd = cast(*Jobs.begin());
-  if (StringRef(Cmd.getCreator().getName()) != "clang") {
+  auto Cmd = llvm::find_if(Jobs, [](const driver::Command &Cmd) {
+return StringRef(Cmd.getCreator().getName()) == "clang";
+  });
+  if (Cmd == Jobs.end()) {
 Diags->Report(diag::err_fe_expected_clang_command);
 return nullptr;
   }
 
-  const ArgStringList &CCArgs = Cmd.getArguments();
+  const ArgStringList &CCArgs = Cmd->getArguments();
   if (CC1Args)
 *CC1Args = {CCArgs.begin(), CCArgs.end()};
   auto CI = std::make_unique();
Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -18,6 +18,7 @@
 namespace clangd {
 namespace {
 
+using testing::ElementsAre;
 using testing::IsEmpty;
 
 TEST(BuildCompilerInvocation, DropsPCH) {
@@ -53,6 +54,22 @@
   IsEmpty());
 }
 
+MATCHER_P(Named, Name, "") { return arg.Name == Name; }
+
+TEST(BuildCompilerInvocation, MultiArch) {
+  TestTU TU = TestTU::withHeaderCode(R"cpp(
+#ifdef __x86_64__
+bool is64;
+#elifdef __i386__
+bool is32;
+#endif
+  )cpp");
+  TU.ExtraArgs = {
+  "--target=x86_64-apple-darwin20", // Needed for driver multi-arch.
+  "-arch", "i386", "-arch", "x86_64"};
+  EXPECT_THAT(TU.headerSymbols(), ElementsAre(Named("is32")));
+}
+
 TEST(BuildCompilerInvocation, PragmaDebugCrash) {
   TestTU TU = TestTU::withCode("#pragma clang __debug parser_crash");
   TU.build(); // no-crash
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -624,10 +624,8 @@
   ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer);
 
   auto FooCpp = testPath("foo.cpp");
-  // clang cannot create CompilerInvocation if we pass two files in the
-  // CompileCommand. We pass the file in ExtraFlags once and CDB adds another
-  // one in getCompileCommand().
-  CDB.ExtraClangFlags.push_back(FooCpp);
+  // clang cannot create CompilerInvocation in this case.
+  CDB.ExtraClangFlags.push_back("-###");
 
   // Clang can't parse command args in that case, but we shouldn't crash.
   runAddDocument(Server, FooCpp, "int main() {}");
@@ -1080,7 +1078,7 @@
   Opts.RunParser = CodeCompleteOptions::ParseIfReady;
 
   // This will make compile command broken and preamble absent.
-  CDB.ExtraClangFlags = {"yolo.cc"};
+  CDB.ExtraClangFlags = {"-###"};
   Server.addDocument(FooCpp, Code.code());
   ASSERT_TRUE(Server.blockUntilIdleForTest());
   auto Res = cantFail(runCodeComplete(Server, FooCpp, Code.point(), Opts));


Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -79,22 +79,24 @@
   }
 }
   }
-  if (Jobs.size() == 0 || !isa(*Jobs.begin()) ||
-  (Jobs.size() > 1 && !OffloadCompilation)) {
+
+  bool PickFirstOfMany = OffloadCompilation || ShouldRecoverOnErorrs;
+  if (Jobs.size() == 0 || (Jobs.size() > 1 && !PickFirstOfMany)) {
 SmallString<256> Msg;
 llvm::raw_svector_ostream OS(Msg);
 Jobs.Print(OS, "; ", true);
 Diags->Report(diag

[PATCH] D107633: Set supported target for asan-use-callbacks test

2021-08-06 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre created this revision.
thopre added reviewers: kstoimenov, vitalybuka.
Herald added subscribers: pengfei, krytarowski.
thopre requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Explicitely set x86_64-linux-gnu as a target for asan-use-callbacks
clang test since some target do not support -fsanitize=address (e.g.
i386-pc-openbsd). Also remove redundant -fsanitize=address and move
-emit-llvm right after -S.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107633

Files:
  clang/test/CodeGen/asan-use-callbacks.cpp


Index: clang/test/CodeGen/asan-use-callbacks.cpp
===
--- clang/test/CodeGen/asan-use-callbacks.cpp
+++ clang/test/CodeGen/asan-use-callbacks.cpp
@@ -1,7 +1,10 @@
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// REQUIRES: x86-registered-target
+//
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -fsanitize=address \
+// RUN: -o - %s \
 // RUN: | FileCheck %s --check-prefixes=CHECK-NO-OUTLINE
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
-// RUN: -fsanitize-address-outline-instrumentation \
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - \
+// RUN: -fsanitize=address %s -fsanitize-address-outline-instrumentation \
 // RUN: | FileCheck %s --check-prefixes=CHECK-OUTLINE
 
 // CHECK-NO-OUTLINE-NOT: call{{.*}}@__asan_load4


Index: clang/test/CodeGen/asan-use-callbacks.cpp
===
--- clang/test/CodeGen/asan-use-callbacks.cpp
+++ clang/test/CodeGen/asan-use-callbacks.cpp
@@ -1,7 +1,10 @@
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// REQUIRES: x86-registered-target
+//
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -fsanitize=address \
+// RUN: -o - %s \
 // RUN: | FileCheck %s --check-prefixes=CHECK-NO-OUTLINE
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
-// RUN: -fsanitize-address-outline-instrumentation \
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - \
+// RUN: -fsanitize=address %s -fsanitize-address-outline-instrumentation \
 // RUN: | FileCheck %s --check-prefixes=CHECK-OUTLINE
 
 // CHECK-NO-OUTLINE-NOT: call{{.*}}@__asan_load4
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107595: [clang] fix transformation of template arguments for concept specializations

2021-08-06 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 364742.
mizvekov added a comment.

- Better naming
- Stop casting `SmallString` to `StringRef`, use `.str()` method instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107595

Files:
  clang/include/clang/AST/ASTConcept.h
  clang/include/clang/AST/ExprConcepts.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTConcept.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -169,3 +169,24 @@
   template void f(T, U) = delete;
   void g() { f(0, 0); }
 }
+
+namespace PR50864 {
+  template  concept Valid = T::valid; // expected-note {{evaluated to false}}
+  template  struct A {
+template  void f(U) requires Valid;
+// expected-note@-1 {{candidate template ignored: constraints not satisfied [with U = int]}}
+// expected-note@-2 {{because 'typename T::type' does not satisfy 'Valid'}}
+// expected-note@-3 {{because substituted constraint expression is ill-formed: type 'int' cannot be used prior to '::' because it has no members}}
+template  void f(U) requires Valid;
+// expected-note@-1 {{candidate template ignored: constraints not satisfied [with U = int]}}
+// expected-note@-2 {{does not satisfy 'Valid'}}
+  };
+
+  template struct X { static constexpr bool valid = V; };
+
+  struct T1 : X {};
+  void t1() { A().f(1); } // expected-error {{no matching member function for call to 'f'}}
+
+  struct T2 : X {};
+  void t2() { A().f(1); }
+}
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -409,10 +409,9 @@
   if (E)
 Record.AddStmt(E);
   else {
-auto *Diag = DetailRecord.second.get *>();
-Record.AddSourceLocation(Diag->first);
-Record.AddString(Diag->second);
+auto *Diag = DetailRecord.second.get();
+Record.AddSourceLocation(Diag->Loc);
+Record.AddString(Diag->Msg);
   }
 }
   }
@@ -423,8 +422,8 @@
 ASTRecordWriter &Record,
 const concepts::Requirement::SubstitutionDiagnostic *D) {
   Record.AddString(D->SubstitutedEntity);
-  Record.AddSourceLocation(D->DiagLoc);
-  Record.AddString(D->DiagMessage);
+  Record.AddSourceLocation(D->Diag.Loc);
+  Record.AddString(D->Diag.Msg);
 }
 
 void ASTStmtWriter::VisitConceptSpecializationExpr(
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3357,25 +3357,6 @@
 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
   }
 
-  /// Build a new Objective-C boxed expression.
-  ///
-  /// By default, performs semantic analysis to build the new expression.
-  /// Subclasses may override this routine to provide different behavior.
-  ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS,
-  SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
-  NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
-  TemplateArgumentListInfo *TALI) {
-CXXScopeSpec SS;
-SS.Adopt(NNS);
-ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
- ConceptNameInfo,
- FoundDecl,
- NamedConcept, TALI);
-if (Result.isInvalid())
-  return ExprError();
-return Result;
-  }
-
   /// \brief Build a new requires expression.
   ///
   /// By default, performs semantic analysis to build the new expression.
@@ -12271,20 +12252,10 @@
E->getEndLoc());
 }
 
-template
-ExprResult
-TreeTransform::TransformConceptSpecializationExpr(
- ConceptSpecializationExpr *E) {
-  const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
-  TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
-  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
-  Old->NumTemplateArgs, TransArgs))
-return ExprError();
-
-  return getDerived().RebuildConceptSpecializationExpr(
-  E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
-  E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
-  &TransArgs);
+template 
+ExprResult TreeTransform::TransformConceptSpecializati

[PATCH] D107624: [clangd] Rename Features.h -> Feature.h to avoid confilct with libstdc++

2021-08-06 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, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107624

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


[PATCH] D105426: [clangd] IWYU as a library: Find all references to symbols in the file

2021-08-06 Thread Thorsten via Phabricator via cfe-commits
tschuett added a subscriber: kimgr.
tschuett added a comment.

@kimgr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

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


[PATCH] D107632: [clangd] Avoid "expected one compiler job" by picking the first eligible job.

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/CompilerTests.cpp:59
+
+TEST(BuildCompilerInvocation, MultiArch) {
+  TestTU TU = TestTU::withHeaderCode(R"cpp(

maybe move this test to `clang/unittests/Frontend/ASTUnitTest.cpp`? someone 
might send a patch to handle `-arch` specifically in clangd and it would no 
longer be possible to test this behaviour :)

(another option would be to test this through some other flags that'll trigger 
multiple compiler invocations, but I don't have any on top of my head)



Comment at: clang-tools-extra/clangd/unittests/CompilerTests.cpp:68
+  TU.ExtraArgs = {
+  "--target=x86_64-apple-darwin20", // Needed for driver multi-arch.
+  "-arch", "i386", "-arch", "x86_64"};

nit: `--target=macho` is enough. and AFAICT root reason to support multiple 
architectures is mach object type.



Comment at: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp:92
-  const driver::Command &Cmd = cast(*Jobs.begin());
-  if (StringRef(Cmd.getCreator().getName()) != "clang") {
 Diags->Report(diag::err_fe_expected_clang_command);

hmm, this looks like a subtle behaviour change. I definitely like the behaviour 
you proposed better, but maybe do it in a separate patch for making the revert 
easier if need be?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107632

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


[PATCH] D107634: [clangd] Strip mutliple arch options

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman, mgrang.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This patch strips all the arch options in case of multiple ones. As it
results in multiple compiler jobs, which clangd cannot handle.

It doesn't pick any over the others as it is unclear which one the user wants
and defaulting to host architecture seems less surprising. Users also have the
ability to explicitly specify the architecture they want via clangd config
files.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107634

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -13,8 +13,10 @@
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -377,6 +379,23 @@
 testing::AllOf(Not(Contains("foo.cc")), Not(Contains("bar.cc";
   }
 }
+
+TEST(CommandMangler, StripsMultipleArch) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {"clang", "-arch", "foo",
+   "-arch", "bar",   "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  0);
+
+  // Single arch option is preserved.
+  Args = {"clang", "-arch", "foo", "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  1);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -222,22 +222,36 @@
   /*FlagsToExclude=*/driver::options::NoDriverOption |
   (IsCLMode ? 0 : driver::options::CLOption));
 
+  llvm::SmallVector IndicesToDrop;
+  // Having multiple architecture options (e.g. when building FAT binaries)
+  // results in multiple compiler jobs, which clangd cannot handle. In such
+  // cases strip all the `-arch` options and fallback to host architecture. As
+  // there are no signals to figure out which one user actually wants. They can
+  // explicitly specify one through `CompileFlags.Add` if need be.
+  unsigned ArchOptCount = 0;
+  for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
+++ArchOptCount;
+for (auto I = 0U; I <= Input->getNumValues(); ++I)
+  IndicesToDrop.push_back(Input->getIndex() + I);
+  }
+  // If there is a single `-arch` option, keep it.
+  if (ArchOptCount < 2)
+IndicesToDrop.clear();
   // Move the inputs to the end, separated via `--` from flags. This ensures
   // modifications done in the following steps apply in more cases (like 
setting
   // -x, which only affects inputs that come after it).
   if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
 // Drop all the inputs and only add one for the current file.
-llvm::SmallVector IndicesToDrop;
 for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
   IndicesToDrop.push_back(Input->getIndex());
-llvm::sort(IndicesToDrop);
-llvm::for_each(llvm::reverse(IndicesToDrop),
-   // +1 to account for the executable name in Cmd[0] that
-   // doesn't exist in ArgList.
-   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 Cmd.push_back("--");
 Cmd.push_back(File.str());
   }
+  llvm::sort(IndicesToDrop);
+  llvm::for_each(llvm::reverse(IndicesToDrop),
+ // +1 to account for the executable name in Cmd[0] that
+ // doesn't exist in ArgList.
+ [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -13,8 +13,10 @@
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLE

[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-08-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:227-236
+  for (Decl *D : LookupRes) {
+D = D->getCanonicalDecl();
+if (!C.getSourceManager().isInSystemHeader(D->getLocation()))
+  continue;
+if (auto *VD = dyn_cast(D)) {
+  if (FILEType && !ACtx.hasSameType(*FILEType, VD->getType()))
+continue;

steakhal wrote:
> It will early return and uses one fewer `continue`.
The intent was that if no `FILEType` is found we find just the first `VarDecl` 
and do not check the type. This recommended change returns always null if no 
`FILEType` is found.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:504
+
+  OrigStdin = findStdStream("stdin", C);
+  OrigStdout = findStdStream("stdout", C);

steakhal wrote:
> martong wrote:
> > We should be careful, to cache the results (either here, or deeper in the 
> > call stack).
> > I mean, we certainly don't want to do a lookup of "stdin" every time a 
> > function is evaluated. We should do this lazily, only once.
> I agree. We should do this only for the first top-level function, instead of 
> doing this for every top-level function.
I am not sure if the `SymbolRef` values are safe to store between top-level 
function analyses. The `FILE` type and std stream declarations are safe to 
cache, but the SymbolRef values of these variables probably not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[clang] 6385abd - Split 'qualifier on reference type has no effect' out into a new flag

2021-08-06 Thread Aaron Ballman via cfe-commits

Author: Luna Kirkby
Date: 2021-08-06T07:09:16-04:00
New Revision: 6385abd0c4490e0516cb31c0b86c0fbcc052f815

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

LOG: Split 'qualifier on reference type has no effect' out into a new flag

This introduces a new flag ignored-reference-qualifiers for the
existing "'A' qualifier on reference type B has no effect" diagnostic,
as a child of ignored-qualifiers.

Rationale:
This particular diagnostic is enabled by default, but other parts of
ignored-qualifiers are not. Anecdotally, a user may encounter this
diagnostic in the wild, and, seeing it to be valuable, might try to
raise it to error with -Werror=ignored-qualifiers, whereupon the other
diagnostics the flag covers will also be raised, to the user's surprise
and confusion. By splitting this diagnostic out into a separate flag,
and marking it as a child of ignored-qualifiers, we allow the user more
granular control of the diagnostics they care about, while maintaining
backwards compatibility with existing build scripts.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6857c889b72b6..1555a9ee24650 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -402,7 +402,8 @@ def IncrementBool : DiagGroup<"increment-bool", 
[DeprecatedIncrementBool]>;
 def InfiniteRecursion : DiagGroup<"infinite-recursion">;
 def PureVirtualCallFromCtorDtor: 
DiagGroup<"call-to-pure-virtual-from-ctor-dtor">;
 def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
-def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">;
+def IgnoredReferenceQualifiers : DiagGroup<"ignored-reference-qualifiers">;
+def IgnoredQualifiers : DiagGroup<"ignored-qualifiers", 
[IgnoredReferenceQualifiers]>;
 def : DiagGroup<"import">;
 def GNUIncludeNext : DiagGroup<"gnu-include-next">;
 def IncompatibleMSStruct : DiagGroup<"incompatible-ms-struct">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 247f9d715b846..4ed561fb57b09 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5735,7 +5735,7 @@ def warn_typecheck_function_qualifiers_unspecified : 
Warning<
   "'%0' qualifier on function type %1 has unspecified behavior">;
 def warn_typecheck_reference_qualifiers : Warning<
   "'%0' qualifier on reference type %1 has no effect">,
-  InGroup;
+  InGroup;
 def err_typecheck_invalid_restrict_not_pointer : Error<
   "restrict requires a pointer or reference (%0 is invalid)">;
 def err_typecheck_invalid_restrict_not_pointer_noarg : Error<



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


[PATCH] D107125: [Diagnostic] Split 'qualifier on reference type has no effect' out into a new flag

2021-08-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit on your behalf in 6385abd0c4490e0516cb31c0b86c0fbcc052f815 
, thank 
you for the patch!


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

https://reviews.llvm.org/D107125

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


[PATCH] D107636: [analyzer][solver] Compute adjustment for unsupported symbols as well

2021-08-06 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, xazax.hun, martong, steakhal, Szelethus, 
ASDenysPetrov, manas, RedDocMD.
Herald added subscribers: dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, 
rnkovacs, szepet, baloghadamsoftware.
vsavchenko requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When the solver sees conditions like `a +/- INT cmp INT`, it disassembles
such expressions and uses the first integer constant as a so-called 
"Adjustment".
So it's easier later on to reason about the range of the symbol (`a`
in this case).

However, conditions of form `a +/- INT` are not treated the same way,
and we might end up with contradictory constraints.

This patch resolves this issue and extracts "Adjustment" for the
latter case as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107636

Files:
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/infeasible_paths.c


Index: clang/test/Analysis/infeasible_paths.c
===
--- /dev/null
+++ clang/test/Analysis/infeasible_paths.c
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+// expected-no-diagnostics
+
+void clang_analyzer_warnIfReached();
+
+void unsupportedSymAssumption_1(int a) {
+  int b = a + 1;
+  if (b + 1)
+return;
+  // At this point, b == -1, a == -2
+  // and this condition is always true.
+  if (b < 1)
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+}
+
+void unsupportedSymAssumption_2(int a) {
+  int b = a - 1;
+  if (!b)
+return;
+  if (b)
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -137,10 +137,13 @@
 
   // Reverse the operation and add directly to state.
   const llvm::APSInt &Zero = BVF.getValue(0, T);
+  llvm::APSInt Adjustment = Zero;
+  computeAdjustment(Sym, Adjustment);
+
   if (Assumption)
-return assumeSymNE(State, Sym, Zero, Zero);
-  else
-return assumeSymEQ(State, Sym, Zero, Zero);
+return assumeSymNE(State, Sym, Zero, Adjustment);
+
+  return assumeSymEQ(State, Sym, Zero, Adjustment);
 }
 
 ProgramStateRef RangedConstraintManager::assumeSymRel(ProgramStateRef State,


Index: clang/test/Analysis/infeasible_paths.c
===
--- /dev/null
+++ clang/test/Analysis/infeasible_paths.c
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+// expected-no-diagnostics
+
+void clang_analyzer_warnIfReached();
+
+void unsupportedSymAssumption_1(int a) {
+  int b = a + 1;
+  if (b + 1)
+return;
+  // At this point, b == -1, a == -2
+  // and this condition is always true.
+  if (b < 1)
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+}
+
+void unsupportedSymAssumption_2(int a) {
+  int b = a - 1;
+  if (!b)
+return;
+  if (b)
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -137,10 +137,13 @@
 
   // Reverse the operation and add directly to state.
   const llvm::APSInt &Zero = BVF.getValue(0, T);
+  llvm::APSInt Adjustment = Zero;
+  computeAdjustment(Sym, Adjustment);
+
   if (Assumption)
-return assumeSymNE(State, Sym, Zero, Zero);
-  else
-return assumeSymEQ(State, Sym, Zero, Zero);
+return assumeSymNE(State, Sym, Zero, Adjustment);
+
+  return assumeSymEQ(State, Sym, Zero, Adjustment);
 }
 
 ProgramStateRef RangedConstraintManager::assumeSymRel(ProgramStateRef State,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107613: [Clang][DiagnosticSemaKinds] combine diagnostic texts

2021-08-06 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 some minor tweaks to avoid `hasAttr` followed by `getAttr`. Thanks!




Comment at: clang/lib/Sema/SemaDecl.cpp:3356-3359
   if (New->hasAttr() &&
   !Old->hasAttr()) {
-Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
-<< New->getDeclName();
+Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl)
+<< New->getAttr();





Comment at: clang/lib/Sema/SemaDecl.cpp:4170-4173
   if (New->hasAttr() &&
   !Old->hasAttr()) {
-Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
-<< New->getDeclName();
+Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl)
+<< New->getAttr();




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107613

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


[PATCH] D96324: [clangd] Rename references to function arguments within the same file

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

I think this is a great use case for pseudo parser actually (unfortunately 
requires some multi-file interactions). In theory we can just fetch all the 
references, pseudo-parse the files, and update all the declarations & 
definitions to have the same parameter name.

My 2 cents for limiting to single-file cases initially;
It sounds like a better option to make the functionality less surprising, but I 
think we'll still end up confusing the users, so I am not sure if it is worth.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96324

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I think getting too specific as to why in the messages may confuse people. 
Especially "might not update memory" is not super helpful. It sounds like the 
instruction is just entirely unreliable




Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12212
+"A floating-point atomic instruction will generate an unsafe"
+" hardware instruction which may not follow denorm mode");
+  }

Should not abbreviate denormal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-06 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364608.
gandhi21299 marked 2 inline comments as done.
gandhi21299 added a comment.

- code formatting
- @arsenm Being specific can be useful to some users. I don't see generating 
optimization remarks as a popular thing that every user will trigger so only 
those who care about it can trigger it and make something out of the info.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/fp-atomics-remarks-gfx90a.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Constructi

[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-06 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364609.
gandhi21299 added a comment.

- removed unnecessary header includes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/fp-atomics-remarks-gfx90a.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:  Natural Loop Information
+; GCN-O1-OPTS-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-OPTS-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-OPTS-NEXT:  Optimization Remark Emitter
 ; GCN-O1-OPTS-NEXT:  Expand A

[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-06 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364619.
gandhi21299 added a comment.

- eliminated trailing whitespaces in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/fp-atomics-remarks-gfx90a.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction
+; CHECK-NEXT:   Natural Loop Information
+; CHECK-NEXT:   Lazy Branch Probability Analysis
+; CHECK-NEXT:   Lazy Block Frequency Analysis
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction
+; CHECK-NEXT:   Natural Loop Information
+; CHECK-NEXT:   Lazy Branch Probability Analysis
+; CHECK-NEXT:   Lazy Block Frequency Analysis
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:  Natural Loop Information
+; GCN-O1-OPTS-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-OPTS-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-OPTS-NEXT:  Optimization Remark Emitter
 ; GCN-O1-OPTS-NEXT:  Expand Atom

[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-06 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl:23
+
+// GFX90A-HW: A floating-point atomic instruction will generate an unsafe 
hardware instruction which may fail to update memory [-Rpass=si-lower]
+// GFX90A-HW-LABEL: test_atomic_add

Should check other cases too. Essentially a check per every distinct emitted 
remark.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12120
+   OptimizationRemarkEmitter *ORE,
+   OptimizationRemark OptRemark) {
+  ORE->emit([&]() { return OptRemark; });

Why OptRemark and not just StringRef? I really want to see as little churn as 
possible at the call site.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12173
+  if (RMW->use_empty()) {
+if (RMW->getFunction()
+->getFnAttribute("amdgpu-unsafe-fp-atomics")

No need to check attribute. Everything below amdgpu-unsafe-fp-atomics check to 
the end of the block is unsafe. Just revert to original return and call 
reportAtomicExpand() for the AtomicExpansionKind::None case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-06 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12120
+   OptimizationRemarkEmitter *ORE,
+   OptimizationRemark OptRemark) {
+  ORE->emit([&]() { return OptRemark; });

rampitec wrote:
> Why OptRemark and not just StringRef? I really want to see as little churn as 
> possible at the call site.
With only StringRef, we would also have to pass in RMW since OptimizationRemark 
constructor depends on that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-06 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364687.
gandhi21299 added a comment.

- changed remarks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/fp-atomics-remarks-gfx90a.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction
+; CHECK-NEXT:   Natural Loop Information
+; CHECK-NEXT:   Lazy Branch Probability Analysis
+; CHECK-NEXT:   Lazy Block Frequency Analysis
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction
+; CHECK-NEXT:   Natural Loop Information
+; CHECK-NEXT:   Lazy Branch Probability Analysis
+; CHECK-NEXT:   Lazy Block Frequency Analysis
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:  Natural Loop Information
+; GCN-O1-OPTS-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-OPTS-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-OPTS-NEXT:  Optimization Remark Emitter
 ; GCN-O1-OPTS-NEXT:  Expand Atomic instructions
 ; GCN-O1

[PATCH] D107637: [clangd] Canonicalize inputs provided with `--`

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

We already strip all the inputs provided without `--`, this patch also
handles the cases with `--`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107637

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,7 +45,7 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
   Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -237,21 +237,28 @@
   // If there is a single `-arch` option, keep it.
   if (ArchOptCount < 2)
 IndicesToDrop.clear();
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like 
setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+
+  // Strip all the inputs and `--`. We'll put the input for the requested file
+  // explicitly at the end of the flags. This ensures modifications done in the
+  // following steps apply in more cases (like setting -x, which only affects
+  // inputs that come after it).
+  for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
+IndicesToDrop.push_back(Input->getIndex());
+  // Anything after `--` is also treated as input, drop them as well.
+  if (auto *DashDash =
+  ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
+for (auto I = 0U; I <= DashDash->getNumValues(); ++I)
+  IndicesToDrop.push_back(DashDash->getIndex() + I);
   }
   llvm::sort(IndicesToDrop);
   llvm::for_each(llvm::reverse(IndicesToDrop),
  // +1 to account for the executable name in Cmd[0] that
  // doesn't exist in ArgList.
  [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
+  // All the inputs are stripped, append the name for the requested file. Rest
+  // of the modifications should respect `--`.
+  Cmd.push_back("--");
+  Cmd.push_back(File.str());
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,7 +45,7 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
   Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -237,21 +237,28 @@
   // If there is a single `-arch` option, keep it.
   if (ArchOptCount < 2)
 IndicesToDrop.clear();
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+
+  // Strip all the inputs and `--`. We'll put 

[PATCH] D104351: [HeaderSearch] Use `isImport` only for imported headers and not for `#pragma once`.

2021-08-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

Ok, this makes sense. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104351

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-08-06 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 364758.
kito-cheng marked an inline comment as done.
kito-cheng added a comment.

Changes:

- Forbid copy ctor and operator= for RISCVISAInfo.
- Move RISCVISAInfo's constructor to private.
- Refine RISCVISAInfo::parse* and made they become static function.
- Address @jrtc27's comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-abi.c
  clang/test/Driver/riscv-arch.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/attribute-with-insts.s
  llvm/test/MC/RISCV/invalid-attribute.s

Index: llvm/test/MC/RISCV/invalid-attribute.s
===
--- llvm/test/MC/RISCV/invalid-attribute.s
+++ llvm/test/MC/RISCV/invalid-attribute.s
@@ -7,10 +7,10 @@
 # RUN: not llvm-mc %s -triple=riscv64 -filetype=asm 2>&1 | FileCheck %s
 
 .attribute arch, "foo"
-# CHECK: [[@LINE-1]]:18: error: bad arch string foo
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,g}
 
 .attribute arch, "rv32i2p0_y2p0"
-# CHECK: [[@LINE-1]]:18: error: bad arch string y2p0
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'rv32i2p0_y2p0', invalid standard user-level extension 'y'
 
 .attribute stack_align, "16"
 # CHECK: [[@LINE-1]]:25: error: expected numeric constant
Index: llvm/test/MC/RISCV/attribute-with-insts.s
===
--- llvm/test/MC/RISCV/attribute-with-insts.s
+++ llvm/test/MC/RISCV/attribute-with-insts.s
@@ -10,7 +10,7 @@
 # RUN:   | llvm-objdump --triple=riscv64 -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefix=CHECK-INST %s
 
-.attribute arch, "rv64i2p0_m2p0_a2p0_d2p0_c2p0"
+.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 # CHECK-INST: lr.w t0, (t1)
 lr.w t0, (t1)
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -9,9 +9,6 @@
 .attribute arch, "rv32i2"
 # CHECK: attribute  5, "rv32i2p0"
 
-.attribute arch, "rv32i2p"
-# CHECK: attribute  5, "rv32i2p0"
-
 .attribute arch, "rv32i2p0"
 # CHECK: attribute  5, "rv32i2p0"
 
@@ -33,14 +30,14 @@
 .attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
-.attribute arch, "rv32ima2p_fdc"
+.attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32ib"
 # CHECK: attribute  5, "rv32i2p0_b0p93_zba0p93_zbb0p93_zbc0p93_zbe0p93_zbf0p93_zbm0p93_zbp0p93_zbr0p93_zbs0p93_zbt0p93"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba0p93"
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
@@ -11,9 +11,11 @@
 //===--===//
 
 #include "RISCVTargetStreamer.h"
+#include "RISCVBaseInfo.h"
 #include "RISCVMCTargetDesc.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/RISCVAttributes.h"
+#include "llvm/Support/RISCVISAInfo.h"
 
 using namespace llvm;
 
@@ -43,57 +45,13 @@
   else
 emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_16);
 
-  std::string Arch = "rv32";
-  if (STI.hasFeature(RISCV::Feature64Bit))
-Arch = "rv64";
-  if (STI.hasFeature(RISCV::FeatureRV32E))
-Arch += "e1p9";
-  else
-Arch += "i2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtM))
-Arch += "_m2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtA))
-Arch += "_a2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtF))
-Arch += "_f2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtD))
-Arch += "_d2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtC))
-Arch += "_c2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtB))
-Arch += "_b0p93";
-  if (STI.hasFeature(RISCV::FeatureStdExtV))
-Arch += "_v0p10";
-  if (STI.hasFeature(RISCV::FeatureExtZfh))
-Arch += "_zfh0p1";
-  if (STI.hasFeature(RISCV::FeatureExtZba))
-Arch += "_zba0p93";
-  if (STI.hasFeature(RISCV::FeatureExtZbb))
-Arch += "_zbb0p93";
-  if (STI.ha

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-08-06 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:31
+public:
+  RISCVISAInfo() : XLen(0), FLen(0) {}
+

jrtc27 wrote:
> Does Exts need initialising to be empty here? I can never remember
std::map has default construct that will construct an empty map.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:194
+  switch (ExtClass) {
+  case 's':
+HighOrder = 0;

jrtc27 wrote:
> I imagine this needs to change to the new Sm-/Ss- scheme, but I don't know 
> which way round those are intended to go
I would prefer submit another patch to make this parser up to date, and keep 
this patch as a refactor patch as possible:

e.g.:
- Full implication info, e.g. `d` implied `f`, `f` implied `zicsr`...
- Prefix `zxm`.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:197
+break;
+  case 'h':
+HighOrder = 1;

jrtc27 wrote:
> Do we know if this is still the case? Ss- is being used for S-mode extensions 
> and Sm- for M-mode extensions, so I'd expect Sh- (or maybe just Ss-) for 
> HS-mode extensions, not H-.
Like above reply, prefer another patch to fix that.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:225-229
+  if (LHSLen == 1 && RHSLen != 1)
+return true;
+
+  if (LHSLen != 1 && RHSLen == 1)
+return false;

jrtc27 wrote:
> Don't know if this is better or not, but this is the more compact way to 
> write it
It's more compact but it's hard to read the rule to me, so I would prefer keep 
that as it is


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-08-06 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:49-50
+  /// Parse RISCV ISA info from arch string.
+  static std::unique_ptr
+  parseArchString(llvm::Error &Error, StringRef Arch,
+  bool EnableExperimentalExtension,

Use llvm::Expected<...> as the return value to avoid a separate error out param



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:40
+
+static const RISCVSupportedExtensionInfo SupportedExtensionInfos[] = {
+{"i", RISCVExtensionVersion{2, 0}}, {"e", RISCVExtensionVersion{1, 9}},

Is the "Infos" suffix on the variable name really needed?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:41
+static const RISCVSupportedExtensionInfo SupportedExtensionInfos[] = {
+{"i", RISCVExtensionVersion{2, 0}}, {"e", RISCVExtensionVersion{1, 9}},
+{"m", RISCVExtensionVersion{2, 0}}, {"a", RISCVExtensionVersion{2, 0}},

I'd keep these all one per line



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:107
+struct FindByName {
+  FindByName(StringRef Ext) : Ext(Ext){};
+  StringRef Ext;





Comment at: llvm/lib/Support/RISCVISAInfo.cpp:378
+llvm::find_if(ExtensionInfos, FindByName(ExtName));
+if (ExtensionInfoIterator == ExtensionInfos.end())
+  continue;

No error?..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D107634: [clangd] Strip mutliple arch options

2021-08-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:225
 
+  llvm::SmallVector IndicesToDrop;
+  // Having multiple architecture options (e.g. when building FAT binaries)

nit: llvm::SmallVector unless you're very sure about the 1



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:226
+  llvm::SmallVector IndicesToDrop;
+  // Having multiple architecture options (e.g. when building FAT binaries)
+  // results in multiple compiler jobs, which clangd cannot handle. In such

nit: fat isn't an acronym here



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:228
+  // results in multiple compiler jobs, which clangd cannot handle. In such
+  // cases strip all the `-arch` options and fallback to host architecture. As
+  // there are no signals to figure out which one user actually wants. They can

s/host/default/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107634

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


[PATCH] D107637: [clangd] Canonicalize inputs provided with `--`

2021-08-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:250
+  ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
+for (auto I = 0U; I <= DashDash->getNumValues(); ++I)
+  IndicesToDrop.push_back(DashDash->getIndex() + I);

iterate from dashdash->getIndex() + 1 to Cmd.size() instead?

Or just Cmd.resize(dashdash->getIndex() + 2)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107637

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


[PATCH] D107365: clangd: Make documentation property of completion items more similar

2021-08-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

LG but could you please add a test showing this difference?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107365

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


[clang] 4aafd5f - [clang] Remove misleading assertion in FullSourceLoc

2021-08-06 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-08-06T14:48:28+02:00
New Revision: 4aafd5f00c2a772337ec065d4542ef158453a343

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

LOG: [clang] Remove misleading assertion in FullSourceLoc

D31709 added an assertion was added to `FullSourceLoc::hasManager()` that 
ensured a valid `SourceLocation` is always paired with a `SourceManager`, and 
missing `SourceManager` is always paired with an invalid `SourceLocation`.

This appears to be incorrect, since clients never cared about constructing 
`FullSourceLoc` to uphold that invariant, or always checking `isValid()` before 
calling `hasManager()`.

The assertion started failing when serializing diagnostics pointing into an 
explicit module. Explicit modules don't have valid `SourceLocation` for the 
`import` statement, since they are "imported" from the command-line argument 
`-fmodule-name=x.pcm`.

This patch removes the assertion, since `FullSourceLoc` was never intended to 
uphold any kind of invariants between the validity of `SourceLocation` and 
presence of `SourceManager`.

Reviewed By: arphaman

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

Added: 
clang/test/Modules/Inputs/explicit-build-diags/a.h
clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
clang/test/Modules/explicit-build-diags.cpp

Modified: 
clang/include/clang/Basic/SourceLocation.h

Removed: 




diff  --git a/clang/include/clang/Basic/SourceLocation.h 
b/clang/include/clang/Basic/SourceLocation.h
index 540de23b9f55e..ba2e9156a2b12 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -363,6 +363,10 @@ class FileEntry;
 /// A SourceLocation and its associated SourceManager.
 ///
 /// This is useful for argument passing to functions that expect both objects.
+///
+/// This class does not guarantee the presence of either the SourceManager or
+/// a valid SourceLocation. Clients should use `isValid()` and `hasManager()`
+/// before calling the member functions.
 class FullSourceLoc : public SourceLocation {
   const SourceManager *SrcMgr = nullptr;
 
@@ -373,13 +377,10 @@ class FullSourceLoc : public SourceLocation {
   explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
   : SourceLocation(Loc), SrcMgr(&SM) {}
 
-  bool hasManager() const {
-  bool hasSrcMgr =  SrcMgr != nullptr;
-  assert(hasSrcMgr == isValid() && "FullSourceLoc has location but no 
manager");
-  return hasSrcMgr;
-  }
+  /// Checks whether the SourceManager is present.
+  bool hasManager() const { return SrcMgr != nullptr; }
 
-  /// \pre This FullSourceLoc has an associated SourceManager.
+  /// \pre hasManager()
   const SourceManager &getManager() const {
 assert(SrcMgr && "SourceManager is NULL.");
 return *SrcMgr;

diff  --git a/clang/test/Modules/Inputs/explicit-build-diags/a.h 
b/clang/test/Modules/Inputs/explicit-build-diags/a.h
new file mode 100644
index 0..486941dde83b1
--- /dev/null
+++ b/clang/test/Modules/Inputs/explicit-build-diags/a.h
@@ -0,0 +1 @@
+void a() __attribute__((deprecated));

diff  --git a/clang/test/Modules/Inputs/explicit-build-diags/module.modulemap 
b/clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
new file mode 100644
index 0..bb00c840ce39d
--- /dev/null
+++ b/clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
@@ -0,0 +1 @@
+module a { header "a.h" }

diff  --git a/clang/test/Modules/explicit-build-diags.cpp 
b/clang/test/Modules/explicit-build-diags.cpp
new file mode 100644
index 0..4a37dc108a688
--- /dev/null
+++ b/clang/test/Modules/explicit-build-diags.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -fmodules -x c++ 
%S/Inputs/explicit-build-diags/module.modulemap -fmodule-name=a -emit-module -o 
%t/a.pcm
+// RUN: %clang_cc1 -fmodules -Wdeprecated-declarations 
-fdiagnostics-show-note-include-stack -serialize-diagnostic-file %t/tu.dia \
+// RUN:   -I %S/Inputs/explicit-build-diags -fmodule-file=%t/a.pcm 
-fsyntax-only %s
+
+#include "a.h"
+
+void foo() { a(); }



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


[PATCH] D106862: [clang] Remove misleading assertion in FullSourceLoc

2021-08-06 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4aafd5f00c2a: [clang] Remove misleading assertion in 
FullSourceLoc (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106862

Files:
  clang/include/clang/Basic/SourceLocation.h
  clang/test/Modules/Inputs/explicit-build-diags/a.h
  clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
  clang/test/Modules/explicit-build-diags.cpp


Index: clang/test/Modules/explicit-build-diags.cpp
===
--- /dev/null
+++ clang/test/Modules/explicit-build-diags.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -fmodules -x c++ 
%S/Inputs/explicit-build-diags/module.modulemap -fmodule-name=a -emit-module -o 
%t/a.pcm
+// RUN: %clang_cc1 -fmodules -Wdeprecated-declarations 
-fdiagnostics-show-note-include-stack -serialize-diagnostic-file %t/tu.dia \
+// RUN:   -I %S/Inputs/explicit-build-diags -fmodule-file=%t/a.pcm 
-fsyntax-only %s
+
+#include "a.h"
+
+void foo() { a(); }
Index: clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
@@ -0,0 +1 @@
+module a { header "a.h" }
Index: clang/test/Modules/Inputs/explicit-build-diags/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/a.h
@@ -0,0 +1 @@
+void a() __attribute__((deprecated));
Index: clang/include/clang/Basic/SourceLocation.h
===
--- clang/include/clang/Basic/SourceLocation.h
+++ clang/include/clang/Basic/SourceLocation.h
@@ -363,6 +363,10 @@
 /// A SourceLocation and its associated SourceManager.
 ///
 /// This is useful for argument passing to functions that expect both objects.
+///
+/// This class does not guarantee the presence of either the SourceManager or
+/// a valid SourceLocation. Clients should use `isValid()` and `hasManager()`
+/// before calling the member functions.
 class FullSourceLoc : public SourceLocation {
   const SourceManager *SrcMgr = nullptr;
 
@@ -373,13 +377,10 @@
   explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
   : SourceLocation(Loc), SrcMgr(&SM) {}
 
-  bool hasManager() const {
-  bool hasSrcMgr =  SrcMgr != nullptr;
-  assert(hasSrcMgr == isValid() && "FullSourceLoc has location but no 
manager");
-  return hasSrcMgr;
-  }
+  /// Checks whether the SourceManager is present.
+  bool hasManager() const { return SrcMgr != nullptr; }
 
-  /// \pre This FullSourceLoc has an associated SourceManager.
+  /// \pre hasManager()
   const SourceManager &getManager() const {
 assert(SrcMgr && "SourceManager is NULL.");
 return *SrcMgr;


Index: clang/test/Modules/explicit-build-diags.cpp
===
--- /dev/null
+++ clang/test/Modules/explicit-build-diags.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -fmodules -x c++ %S/Inputs/explicit-build-diags/module.modulemap -fmodule-name=a -emit-module -o %t/a.pcm
+// RUN: %clang_cc1 -fmodules -Wdeprecated-declarations -fdiagnostics-show-note-include-stack -serialize-diagnostic-file %t/tu.dia \
+// RUN:   -I %S/Inputs/explicit-build-diags -fmodule-file=%t/a.pcm -fsyntax-only %s
+
+#include "a.h"
+
+void foo() { a(); }
Index: clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
@@ -0,0 +1 @@
+module a { header "a.h" }
Index: clang/test/Modules/Inputs/explicit-build-diags/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/a.h
@@ -0,0 +1 @@
+void a() __attribute__((deprecated));
Index: clang/include/clang/Basic/SourceLocation.h
===
--- clang/include/clang/Basic/SourceLocation.h
+++ clang/include/clang/Basic/SourceLocation.h
@@ -363,6 +363,10 @@
 /// A SourceLocation and its associated SourceManager.
 ///
 /// This is useful for argument passing to functions that expect both objects.
+///
+/// This class does not guarantee the presence of either the SourceManager or
+/// a valid SourceLocation. Clients should use `isValid()` and `hasManager()`
+/// before calling the member functions.
 class FullSourceLoc : public SourceLocation {
   const SourceManager *SrcMgr = nullptr;
 
@@ -373,13 +377,10 @@
   explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
   : SourceLocation(Loc), SrcMgr(&SM) {}
 
-  bool hasManager() const {
-  bool hasSrcMgr =  SrcMgr != nullptr;

[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp:53-62
+consteval T *make_t() { return new T; }
+
+void func() {
+  (void)typeid(*null_s());
+  (void)typeid(*make_s());
+  (void)typeid(*null_t()); // expected-warning {{expression with side effects 
will be evaluated despite being used as an operand to 'typeid'}}
+  (void)typeid(*make_t()); // expected-error {{call to consteval function 
'unevaluated::make_t' is not a constant expression}}

Cleaning up the test a bit to not use relative locations, should be NFC.



Comment at: clang/test/SemaCXX/cxx2a-consteval.cpp:11
 
-consteval constexpr int f2(int i) { 
+consteval constexpr int f2(int i) {
   //expected-error@-1 {{cannot combine}}

Looks like a bunch of unintended whitespace changes snuck in.



Comment at: clang/test/SemaCXX/cxx2a-consteval.cpp:608-609
+
+auto e = g(f()); // expected-error {{is not a constant expression}}
+ // expected-note@-1 {{non-constexpr function 'f' cannot be 
used in a constant expression}}
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

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


[PATCH] D107634: [clangd] Strip mutliple arch options

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 3 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:225
 
+  llvm::SmallVector IndicesToDrop;
+  // Having multiple architecture options (e.g. when building FAT binaries)

sammccall wrote:
> nit: llvm::SmallVector unless you're very sure about the 1
I think we'll still have just the single filename in the most common case and 
will only have `-arch` or multiple filenames rarely. so keeping it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107634

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


[PATCH] D107634: [clangd] Strip mutliple arch options

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 364763.
kadircet marked an inline comment as done.
kadircet added a comment.

- Update comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107634

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -13,8 +13,10 @@
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -377,6 +379,23 @@
 testing::AllOf(Not(Contains("foo.cc")), Not(Contains("bar.cc";
   }
 }
+
+TEST(CommandMangler, StripsMultipleArch) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {"clang", "-arch", "foo",
+   "-arch", "bar",   "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  0);
+
+  // Single arch option is preserved.
+  Args = {"clang", "-arch", "foo", "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  1);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -222,22 +222,36 @@
   /*FlagsToExclude=*/driver::options::NoDriverOption |
   (IsCLMode ? 0 : driver::options::CLOption));
 
+  llvm::SmallVector IndicesToDrop;
+  // Having multiple architecture options (e.g. when building fat binaries)
+  // results in multiple compiler jobs, which clangd cannot handle. In such
+  // cases strip all the `-arch` options and fallback to default architecture.
+  // As there are no signals to figure out which one user actually wants. They
+  // can explicitly specify one through `CompileFlags.Add` if need be.
+  unsigned ArchOptCount = 0;
+  for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
+++ArchOptCount;
+for (auto I = 0U; I <= Input->getNumValues(); ++I)
+  IndicesToDrop.push_back(Input->getIndex() + I);
+  }
+  // If there is a single `-arch` option, keep it.
+  if (ArchOptCount < 2)
+IndicesToDrop.clear();
   // Move the inputs to the end, separated via `--` from flags. This ensures
   // modifications done in the following steps apply in more cases (like 
setting
   // -x, which only affects inputs that come after it).
   if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
 // Drop all the inputs and only add one for the current file.
-llvm::SmallVector IndicesToDrop;
 for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
   IndicesToDrop.push_back(Input->getIndex());
-llvm::sort(IndicesToDrop);
-llvm::for_each(llvm::reverse(IndicesToDrop),
-   // +1 to account for the executable name in Cmd[0] that
-   // doesn't exist in ArgList.
-   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 Cmd.push_back("--");
 Cmd.push_back(File.str());
   }
+  llvm::sort(IndicesToDrop);
+  llvm::for_each(llvm::reverse(IndicesToDrop),
+ // +1 to account for the executable name in Cmd[0] that
+ // doesn't exist in ArgList.
+ [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -13,8 +13,10 @@
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -377,6 +379,23 @@
 testing::AllOf(Not(Contains("foo.cc")), Not(Contains("bar.cc";
   }
 }
+
+TEST(CommandMangler, StripsMultipleArch) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {"clang", "-arch", "foo",
+ 

[PATCH] D107637: [clangd] Canonicalize inputs provided with `--`

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 364764.
kadircet marked an inline comment as done.
kadircet added a comment.

- Cmd.resize instead of dropping arguments trailing `--` one by one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107637

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,7 +45,7 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
   Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -237,21 +237,27 @@
   // If there is a single `-arch` option, keep it.
   if (ArchOptCount < 2)
 IndicesToDrop.clear();
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like 
setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+
+  // Strip all the inputs and `--`. We'll put the input for the requested file
+  // explicitly at the end of the flags. This ensures modifications done in the
+  // following steps apply in more cases (like setting -x, which only affects
+  // inputs that come after it).
+  for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
+IndicesToDrop.push_back(Input->getIndex());
+  // Anything after `--` is also treated as input, drop them as well.
+  if (auto *DashDash =
+  ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
+Cmd.resize(DashDash->getIndex() + 1); // +1 to account for Cmd[0].
   }
   llvm::sort(IndicesToDrop);
   llvm::for_each(llvm::reverse(IndicesToDrop),
  // +1 to account for the executable name in Cmd[0] that
  // doesn't exist in ArgList.
  [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
+  // All the inputs are stripped, append the name for the requested file. Rest
+  // of the modifications should respect `--`.
+  Cmd.push_back("--");
+  Cmd.push_back(File.str());
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,7 +45,7 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
   Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -237,21 +237,27 @@
   // If there is a single `-arch` option, keep it.
   if (ArchOptCount < 2)
 IndicesToDrop.clear();
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+
+  // Strip all the inputs and `--`. We'll put the input for the requested file
+  // explicitly at the end of the flags. This ensures modifications done in the
+  // following steps apply in more cases (lik

[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 364765.
cor3ntin added a comment.

Remove WS changes and cleanup tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1103,10 +1103,11 @@
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  No
+  Partial
 

 https://wg21.link/p1937r2";>P1937R2
+Clang 13
   
 
   std::is_constant_evaluated
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -594,3 +594,21 @@
 }
 
 } // namespace special_ctor
+
+namespace unevaluated {
+
+template  struct is_same { static const bool value = false; };
+template  struct is_same { static const bool value = true; };
+
+long f(); // expected-note {{declared here}}
+auto consteval g(auto a) {
+  return a;
+}
+
+auto e = g(f()); // expected-error {{is not a constant expression}}
+ // expected-note@-1 {{non-constexpr function 'f' cannot be used in a constant expression}}
+
+using T = decltype(g(f()));
+static_assert(is_same::value);
+
+} // namespace unevaluated
Index: clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
===
--- clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
+++ clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // C++ [basic.def.odr]p2:
 //   An expression is potentially evaluated unless it [...] is the
@@ -16,7 +17,7 @@
 
 struct NonPoly { };
 
-template 
+template
 struct X {
   Result f(T t) { return t + t; } // expected-error{{invalid operands}}
 
@@ -34,3 +35,33 @@
   // Triggers an error (as it should);
   xpr.g(Poly()); // expected-note{{instantiation of member function}}
 }
+
+#if __cplusplus >= 202002L
+
+namespace unevaluated {
+
+struct S {
+  void f();
+};
+struct T {
+  virtual void f();
+};
+
+consteval S *null_s() { return nullptr; }
+consteval S *make_s() { return new S; }
+consteval T *null_t() { return nullptr; }
+consteval T *make_t() { return new T; } // #alloc
+
+void func() {
+  (void)typeid(*null_s());
+  (void)typeid(*make_s());
+  (void)typeid(*null_t()); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
+  (void)typeid(*make_t()); // expected-error {{call to consteval function 'unevaluated::make_t' is not a constant expression}} \
+  expected-note {{pointer to heap-allocated object is not a constant expression}} \
+  expected-note@#alloc {{heap allocation performed here}} \
+  expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
+}
+
+} // namespace unevaluated
+
+#endif
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16585,7 +16585,8 @@
 }
 
 ExprResult Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {
-  if (!E.isUsable() || !Decl || !Decl->isConsteval() || isConstantEvaluated() ||
+  if (isUnevaluatedContext() || !E.isUsable() || !Decl ||
+  !Decl->isConsteval() || isConstantEvaluated() ||
   RebuildingImmediateInvocation)
 return E;
 
@@ -18702,8 +18703,8 @@
   OdrUse = false;
 
   if (auto *FD = dyn_cast(E->getDecl()))
-if (!isConstantEvaluated() && FD->isConsteval() &&
-!RebuildingImmediateInvocation)
+if (!isUnevaluatedContext() && !isConstantEvaluated() &&
+FD->isConsteval() && !RebuildingImmediateInvocation)
   ExprEvalContexts.back().ReferenceToConsteval.insert(E);
   MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E, OdrUse,
  RefsMinusAssignments);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105426: [clangd] IWYU as a library: Find all references to symbols in the file

2021-08-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

First some thoughts on names... (hopefully to avoid some confusion)

IWYU might be used here to mean three things:

- the IWYU coding style/policy that says you should `#include` headers for the 
symbols you make use of, and no others
- the IWYU  tool 
which applies IWYU style to files
- more generally, features that encourage hygiene policies for `#includes` 
("IWYU functionality")

This work is about the last of these: putting header hygiene features in 
clangd. (Specifically, likely unused-include and missing-include warnings).
I think we should avoid the name "IWYU as a library" or "IWYU functionality" as 
it's ambiguous and also misleading:

- policy: we're likely to support policies other than the IWYU style
- tool: it's not likely to match the design or feature set of the IWYU tool

IncludeHygiene would be an ok name I think but a bit of a mouthful.  WDYT?

(This work is definitely inspired by the IWYU tool and I'd used the name in 
discussions/prototypes, so this confusion is largely my fault! We also did this 
with clang-include-fixer which ended up as clangd/IncludeFixer.h, though the 
designs are much more similar)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

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


[PATCH] D107244: [AIX] Define _ARCH_PPC64 macro for 32-bit

2021-08-06 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan updated this revision to Diff 364766.
Jake-Egan added a comment.

Updated the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107244

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


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -391,6 +391,7 @@
 // PPC-AIX-NOT:#define __64BIT__ 1
 // PPC-AIX:#define _AIX 1
 // PPC-AIX:#define _ARCH_PPC 1
+// PPC-AIX:#define _ARCH_PPC64 1
 // PPC-AIX:#define _BIG_ENDIAN 1
 // PPC-AIX:#define _IBMR2 1
 // PPC-AIX:#define _LONG_LONG 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -256,6 +256,9 @@
 Builder.defineMacro("__powerpc64__");
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
+  } else if (getTriple().isOSAIX()) {
+// The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.
+Builder.defineMacro("_ARCH_PPC64");
   }
 
   // Target properties.


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -391,6 +391,7 @@
 // PPC-AIX-NOT:#define __64BIT__ 1
 // PPC-AIX:#define _AIX 1
 // PPC-AIX:#define _ARCH_PPC 1
+// PPC-AIX:#define _ARCH_PPC64 1
 // PPC-AIX:#define _BIG_ENDIAN 1
 // PPC-AIX:#define _IBMR2 1
 // PPC-AIX:#define _LONG_LONG 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -256,6 +256,9 @@
 Builder.defineMacro("__powerpc64__");
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
+  } else if (getTriple().isOSAIX()) {
+// The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.
+Builder.defineMacro("_ARCH_PPC64");
   }
 
   // Target properties.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 3bf7798 - [clangd] Strip mutliple arch options

2021-08-06 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-08-06T15:04:04+02:00
New Revision: 3bf77980d934c4aa383e4ea9a9a5de86598bea9b

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

LOG: [clangd] Strip mutliple arch options

This patch strips all the arch options in case of multiple ones. As it
results in multiple compiler jobs, which clangd cannot handle.

It doesn't pick any over the others as it is unclear which one the user wants
and defaulting to host architecture seems less surprising. Users also have the
ability to explicitly specify the architecture they want via clangd config
files.

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

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 032bf7354d770..76c92a0bac735 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -222,22 +222,36 @@ void CommandMangler::adjust(std::vector &Cmd,
   /*FlagsToExclude=*/driver::options::NoDriverOption |
   (IsCLMode ? 0 : driver::options::CLOption));
 
+  llvm::SmallVector IndicesToDrop;
+  // Having multiple architecture options (e.g. when building fat binaries)
+  // results in multiple compiler jobs, which clangd cannot handle. In such
+  // cases strip all the `-arch` options and fallback to default architecture.
+  // As there are no signals to figure out which one user actually wants. They
+  // can explicitly specify one through `CompileFlags.Add` if need be.
+  unsigned ArchOptCount = 0;
+  for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
+++ArchOptCount;
+for (auto I = 0U; I <= Input->getNumValues(); ++I)
+  IndicesToDrop.push_back(Input->getIndex() + I);
+  }
+  // If there is a single `-arch` option, keep it.
+  if (ArchOptCount < 2)
+IndicesToDrop.clear();
   // Move the inputs to the end, separated via `--` from flags. This ensures
   // modifications done in the following steps apply in more cases (like 
setting
   // -x, which only affects inputs that come after it).
   if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
 // Drop all the inputs and only add one for the current file.
-llvm::SmallVector IndicesToDrop;
 for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
   IndicesToDrop.push_back(Input->getIndex());
-llvm::sort(IndicesToDrop);
-llvm::for_each(llvm::reverse(IndicesToDrop),
-   // +1 to account for the executable name in Cmd[0] that
-   // doesn't exist in ArgList.
-   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 Cmd.push_back("--");
 Cmd.push_back(File.str());
   }
+  llvm::sort(IndicesToDrop);
+  llvm::for_each(llvm::reverse(IndicesToDrop),
+ // +1 to account for the executable name in Cmd[0] that
+ // doesn't exist in ArgList.
+ [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp 
b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index 175ceb4552740..d1f97233fa672 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -13,8 +13,10 @@
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -377,6 +379,23 @@ TEST(CommandMangler, InputsAfterDashDash) {
 testing::AllOf(Not(Contains("foo.cc")), Not(Contains("bar.cc";
   }
 }
+
+TEST(CommandMangler, StripsMultipleArch) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {"clang", "-arch", "foo",
+   "-arch", "bar",   "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  0);
+
+  // Single arch option is preserved.
+  Args = {"clang", "-arch", "foo", "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  1);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang




[clang-tools-extra] 79c2616 - [clangd] Canonicalize inputs provided with `--`

2021-08-06 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-08-06T15:04:04+02:00
New Revision: 79c2616d315f54d72bcdeebb6576c84be7b585d8

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

LOG: [clangd] Canonicalize inputs provided with `--`

We already strip all the inputs provided without `--`, this patch also
handles the cases with `--`.

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 76c92a0bac73..57933169f911 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -237,21 +237,27 @@ void CommandMangler::adjust(std::vector &Cmd,
   // If there is a single `-arch` option, keep it.
   if (ArchOptCount < 2)
 IndicesToDrop.clear();
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like 
setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+
+  // Strip all the inputs and `--`. We'll put the input for the requested file
+  // explicitly at the end of the flags. This ensures modifications done in the
+  // following steps apply in more cases (like setting -x, which only affects
+  // inputs that come after it).
+  for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
+IndicesToDrop.push_back(Input->getIndex());
+  // Anything after `--` is also treated as input, drop them as well.
+  if (auto *DashDash =
+  ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
+Cmd.resize(DashDash->getIndex() + 1); // +1 to account for Cmd[0].
   }
   llvm::sort(IndicesToDrop);
   llvm::for_each(llvm::reverse(IndicesToDrop),
  // +1 to account for the executable name in Cmd[0] that
  // doesn't exist in ArgList.
  [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
+  // All the inputs are stripped, append the name for the requested file. Rest
+  // of the modifications should respect `--`.
+  Cmd.push_back("--");
+  Cmd.push_back(File.str());
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp 
b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index d1f97233fa67..c8749ec7f487 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,7 +45,7 @@ TEST(CommandMangler, Everything) {
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
   Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),



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


[PATCH] D107634: [clangd] Strip mutliple arch options

2021-08-06 Thread Kadir Cetinkaya 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 rG3bf77980d934: [clangd] Strip mutliple arch options (authored 
by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107634

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -13,8 +13,10 @@
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -377,6 +379,23 @@
 testing::AllOf(Not(Contains("foo.cc")), Not(Contains("bar.cc";
   }
 }
+
+TEST(CommandMangler, StripsMultipleArch) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector Args = {"clang", "-arch", "foo",
+   "-arch", "bar",   "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  0);
+
+  // Single arch option is preserved.
+  Args = {"clang", "-arch", "foo", "/Users/foo.cc"};
+  Mangler.adjust(Args, "/Users/foo.cc");
+  EXPECT_EQ(
+  llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
+  1);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -222,22 +222,36 @@
   /*FlagsToExclude=*/driver::options::NoDriverOption |
   (IsCLMode ? 0 : driver::options::CLOption));
 
+  llvm::SmallVector IndicesToDrop;
+  // Having multiple architecture options (e.g. when building fat binaries)
+  // results in multiple compiler jobs, which clangd cannot handle. In such
+  // cases strip all the `-arch` options and fallback to default architecture.
+  // As there are no signals to figure out which one user actually wants. They
+  // can explicitly specify one through `CompileFlags.Add` if need be.
+  unsigned ArchOptCount = 0;
+  for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
+++ArchOptCount;
+for (auto I = 0U; I <= Input->getNumValues(); ++I)
+  IndicesToDrop.push_back(Input->getIndex() + I);
+  }
+  // If there is a single `-arch` option, keep it.
+  if (ArchOptCount < 2)
+IndicesToDrop.clear();
   // Move the inputs to the end, separated via `--` from flags. This ensures
   // modifications done in the following steps apply in more cases (like 
setting
   // -x, which only affects inputs that come after it).
   if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
 // Drop all the inputs and only add one for the current file.
-llvm::SmallVector IndicesToDrop;
 for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
   IndicesToDrop.push_back(Input->getIndex());
-llvm::sort(IndicesToDrop);
-llvm::for_each(llvm::reverse(IndicesToDrop),
-   // +1 to account for the executable name in Cmd[0] that
-   // doesn't exist in ArgList.
-   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 Cmd.push_back("--");
 Cmd.push_back(File.str());
   }
+  llvm::sort(IndicesToDrop);
+  llvm::for_each(llvm::reverse(IndicesToDrop),
+ // +1 to account for the executable name in Cmd[0] that
+ // doesn't exist in ArgList.
+ [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -13,8 +13,10 @@
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -377,6 +379,23 @@
 testing::AllOf(Not(Contains("foo.cc")), Not(Contains("bar.cc";
   }
 }
+
+TEST(CommandMangler, StripsMultipleArch) {
+  const auto Mangler = CommandMangler::f

[PATCH] D107637: [clangd] Canonicalize inputs provided with `--`

2021-08-06 Thread Kadir Cetinkaya 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 rG79c2616d315f: [clangd] Canonicalize inputs provided with 
`--` (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107637

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,7 +45,7 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
   Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -237,21 +237,27 @@
   // If there is a single `-arch` option, keep it.
   if (ArchOptCount < 2)
 IndicesToDrop.clear();
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like 
setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+
+  // Strip all the inputs and `--`. We'll put the input for the requested file
+  // explicitly at the end of the flags. This ensures modifications done in the
+  // following steps apply in more cases (like setting -x, which only affects
+  // inputs that come after it).
+  for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
+IndicesToDrop.push_back(Input->getIndex());
+  // Anything after `--` is also treated as input, drop them as well.
+  if (auto *DashDash =
+  ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
+Cmd.resize(DashDash->getIndex() + 1); // +1 to account for Cmd[0].
   }
   llvm::sort(IndicesToDrop);
   llvm::for_each(llvm::reverse(IndicesToDrop),
  // +1 to account for the executable name in Cmd[0] that
  // doesn't exist in ArgList.
  [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
+  // All the inputs are stripped, append the name for the requested file. Rest
+  // of the modifications should respect `--`.
+  Cmd.push_back("--");
+  Cmd.push_back(File.str());
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);


Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,7 +45,7 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
   Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -237,21 +237,27 @@
   // If there is a single `-arch` option, keep it.
   if (ArchOptCount < 2)
 IndicesToDrop.clear();
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+
+  // Strip all the inputs and `--`. We'll put the input for the requested file
+  // explicitly at the end of the flags. This ensures modifications done in t

[PATCH] D107637: [clangd] Canonicalize inputs provided with `--`

2021-08-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:250
+  ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
+for (auto I = 0U; I <= DashDash->getNumValues(); ++I)
+  IndicesToDrop.push_back(DashDash->getIndex() + I);

sammccall wrote:
> iterate from dashdash->getIndex() + 1 to Cmd.size() instead?
> 
> Or just Cmd.resize(dashdash->getIndex() + 2)?
ah yes, resize looks a lot better. but we deliberately drop `--` too. so that 
we can always append it without checking again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107637

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


[PATCH] D107641: [clang-tidy] fix duplicate '{}' in cppcoreguidelines-pro-type-member-init

2021-08-06 Thread gehry via Phabricator via cfe-commits
Sockke created this revision.
Sockke added reviewers: aaron.ballman, gribozavr, flx, whisperity, 
steven.zhang, MTC.
Herald added subscribers: shchenz, rnkovacs, kbarton, xazax.hun, nemanjai.
Sockke requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The overload of the constructor will repeatedly fix the member variables that 
need to be initialized.
Removed the duplicate '{}'.

  struct A {
A() {}
A(int) {}
int _var;  // int _var{}{};  <--  wrong fix
  };


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107641

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -210,7 +210,7 @@
 
   // FIXME: The fix-its here collide providing an erroneous fix
   int A, B;
-  // CHECK-FIXES: int A{}{}{}, B{}{}{};
+  // CHECK-FIXES: int A{}, B{};
 };
 
 typedef struct {
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -10,6 +10,7 @@
 #define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
 
 #include "../ClangTidyCheck.h"
+#include "llvm/ADT/DenseSet.h"
 
 namespace clang {
 namespace tidy {
@@ -72,6 +73,10 @@
   // instead of brace initialization. Only effective in C++11 mode. Default is
   // false.
   bool UseAssignment;
+
+  // Record the member variables that have been initialized to prevent repeated
+  // initialization.
+  llvm::DenseSet HasRecordClasMemberSet;
 };
 
 } // namespace cppcoreguidelines
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -435,15 +435,24 @@
   // Collect all the fields we need to initialize, including indirect fields.
   SmallPtrSet AllFieldsToInit;
   forEachField(ClassDecl, FieldsToInit,
-   [&](const FieldDecl *F) { AllFieldsToInit.insert(F); });
-  if (AllFieldsToInit.empty())
+   [&](const FieldDecl *F) { 
+if (!HasRecordClasMemberSet.count(F))
+{
+  AllFieldsToInit.insert(F);
+  HasRecordClasMemberSet.insert(F);
+}
+  });
+  if (FieldsToInit.empty())
 return;
 
   DiagnosticBuilder Diag =
   diag(Ctor ? Ctor->getBeginLoc() : ClassDecl.getLocation(),
"%select{|union }0constructor %select{does not|should}0 initialize "
"%select{|one of }0these fields: %1")
-  << IsUnion << toCommaSeparatedString(OrderedFields, AllFieldsToInit);
+  << IsUnion << toCommaSeparatedString(OrderedFields, FieldsToInit);
+
+  if (AllFieldsToInit.empty())
+return;
 
   // Do not propose fixes for constructors in macros since we cannot place them
   // correctly.


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -210,7 +210,7 @@
 
   // FIXME: The fix-its here collide providing an erroneous fix
   int A, B;
-  // CHECK-FIXES: int A{}{}{}, B{}{}{};
+  // CHECK-FIXES: int A{}, B{};
 };
 
 typedef struct {
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
 
 #include "../ClangTidyCheck.h"
+#include "llvm/ADT/DenseSet.h"
 
 namespace clang {
 namespace tidy {
@@ -72,6 +73,10 @@
   // instead of brace initialization. Only effective in C++11 mode. Default is
   // false.
   bool UseAssignment;
+
+  // Record the member variables that have been initialized to prevent repeated
+  // initialization.
+  llvm::DenseSet HasRecordClasMemberSet;
 };
 
 } // namespace cppcoreguidelines
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeM

[PATCH] D106216: Disallow narrowing conversions to bool in noexcept specififers.

2021-08-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExceptionSpec.cpp:81
 
-ExprResult Sema::ActOnNoexceptSpec(SourceLocation NoexceptLoc,
-   Expr *NoexceptExpr,
+ExprResult Sema::ActOnNoexceptSpec(SourceLocation, Expr *NoexceptExpr,
ExceptionSpecificationType &EST) {

You should just get rid of this parameter entirely if it's no longer going to 
be used.



Comment at: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp:879
   EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept));
-  EXPECT_TRUE(notMatches("void foo() noexcept(1+1);", NoExcept));
+  EXPECT_TRUE(notMatches("void foo() noexcept(0+1);", NoExcept));
   EXPECT_TRUE(matches("void foo() noexcept(noexcept(1+1));", NoExcept));

Was there a reason this test needed to change?



Comment at: clang/www/cxx_status.html:1299
   https://wg21.link/P1401R5";>P1401R5
-  Clang 13
+  Clang 13
 

We're on Clang 14 now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106216

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


[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 364778.
cor3ntin added a comment.

Changing release version to clang 14 in cxx_status


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1103,10 +1103,11 @@
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  No
+  Partial
 

 https://wg21.link/p1937r2";>P1937R2
+Clang 14
   
 
   std::is_constant_evaluated
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -594,3 +594,21 @@
 }
 
 } // namespace special_ctor
+
+namespace unevaluated {
+
+template  struct is_same { static const bool value = false; };
+template  struct is_same { static const bool value = true; };
+
+long f(); // expected-note {{declared here}}
+auto consteval g(auto a) {
+  return a;
+}
+
+auto e = g(f()); // expected-error {{is not a constant expression}}
+ // expected-note@-1 {{non-constexpr function 'f' cannot be used in a constant expression}}
+
+using T = decltype(g(f()));
+static_assert(is_same::value);
+
+} // namespace unevaluated
Index: clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
===
--- clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
+++ clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // C++ [basic.def.odr]p2:
 //   An expression is potentially evaluated unless it [...] is the
@@ -16,7 +17,7 @@
 
 struct NonPoly { };
 
-template 
+template
 struct X {
   Result f(T t) { return t + t; } // expected-error{{invalid operands}}
 
@@ -34,3 +35,33 @@
   // Triggers an error (as it should);
   xpr.g(Poly()); // expected-note{{instantiation of member function}}
 }
+
+#if __cplusplus >= 202002L
+
+namespace unevaluated {
+
+struct S {
+  void f();
+};
+struct T {
+  virtual void f();
+};
+
+consteval S *null_s() { return nullptr; }
+consteval S *make_s() { return new S; }
+consteval T *null_t() { return nullptr; }
+consteval T *make_t() { return new T; } // #alloc
+
+void func() {
+  (void)typeid(*null_s());
+  (void)typeid(*make_s());
+  (void)typeid(*null_t()); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
+  (void)typeid(*make_t()); // expected-error {{call to consteval function 'unevaluated::make_t' is not a constant expression}} \
+  expected-note {{pointer to heap-allocated object is not a constant expression}} \
+  expected-note@#alloc {{heap allocation performed here}} \
+  expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
+}
+
+} // namespace unevaluated
+
+#endif
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16585,7 +16585,8 @@
 }
 
 ExprResult Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {
-  if (!E.isUsable() || !Decl || !Decl->isConsteval() || isConstantEvaluated() ||
+  if (isUnevaluatedContext() || !E.isUsable() || !Decl ||
+  !Decl->isConsteval() || isConstantEvaluated() ||
   RebuildingImmediateInvocation)
 return E;
 
@@ -18702,8 +18703,8 @@
   OdrUse = false;
 
   if (auto *FD = dyn_cast(E->getDecl()))
-if (!isConstantEvaluated() && FD->isConsteval() &&
-!RebuildingImmediateInvocation)
+if (!isUnevaluatedContext() && !isConstantEvaluated() &&
+FD->isConsteval() && !RebuildingImmediateInvocation)
   ExprEvalContexts.back().ReferenceToConsteval.insert(E);
   MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E, OdrUse,
  RefsMinusAssignments);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-06 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

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


[PATCH] D107242: [AIX] Define __HOS_AIX__ macro

2021-08-06 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan updated this revision to Diff 364779.
Jake-Egan added a comment.

Use a temp rather than a local var.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107242

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/Preprocessor/host-aix.c
  clang/test/Preprocessor/not-host-aix.c


Index: clang/test/Preprocessor/not-host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/not-host-aix.c
@@ -0,0 +1,3 @@
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX %s
+// PPC-AIX-NOT:#define __HOS_AIX__ 1
Index: clang/test/Preprocessor/host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/host-aix.c
@@ -0,0 +1,3 @@
+// REQUIRES: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX %s
+// PPC-AIX:#define __HOS_AIX__ 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -301,6 +302,11 @@
 Builder.defineMacro("__LONGDOUBLE64");
   }
 
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSAIX() &&
+  getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");
+  }
+
   // Define this for elfv2 (64-bit only) or 64-bit darwin.
   if (ABI == "elfv2" ||
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))


Index: clang/test/Preprocessor/not-host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/not-host-aix.c
@@ -0,0 +1,3 @@
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX %s
+// PPC-AIX-NOT:#define __HOS_AIX__ 1
Index: clang/test/Preprocessor/host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/host-aix.c
@@ -0,0 +1,3 @@
+// REQUIRES: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX %s
+// PPC-AIX:#define __HOS_AIX__ 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -301,6 +302,11 @@
 Builder.defineMacro("__LONGDOUBLE64");
   }
 
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSAIX() &&
+  getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");
+  }
+
   // Define this for elfv2 (64-bit only) or 64-bit darwin.
   if (ABI == "elfv2" ||
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106216: Disallow narrowing conversions to bool in noexcept specififers.

2021-08-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp:879
   EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept));
-  EXPECT_TRUE(notMatches("void foo() noexcept(1+1);", NoExcept));
+  EXPECT_TRUE(notMatches("void foo() noexcept(0+1);", NoExcept));
   EXPECT_TRUE(matches("void foo() noexcept(noexcept(1+1));", NoExcept));

aaron.ballman wrote:
> Was there a reason this test needed to change?
yup, 2 is not convertible to bool here. I use 0+1 to keep the kind of 
expression the same


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106216

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


[PATCH] D107506: [PowerPC][AIX] Warn when using pragma align(packed) on AIX.

2021-08-06 Thread Sean Fertile via Phabricator via cfe-commits
sfertile updated this revision to Diff 364782.
sfertile added a comment.

Moved the diagnostic emission to ` Sema::ActOnTagFinishDefinition` as suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107506

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/aix-pragma-align-packed-warn.c


Index: clang/test/Sema/aix-pragma-align-packed-warn.c
===
--- /dev/null
+++ clang/test/Sema/aix-pragma-align-packed-warn.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff  -fxl-pragma-pack -verify 
-fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff  -fxl-pragma-pack -verify 
-fsyntax-only %s
+
+#pragma align(packed)
+struct A {  // expected-warning {{#pragma align(packed) may not be compatible 
with objects generated with AIX XL C/C++}}
+  short s1;
+  int   : 0;
+  short s2;
+};
+
+struct B {  // expected-warning {{#pragma align(packed) may not be compatible 
with objects generated with AIX XL C/C++}}
+  short a : 8;
+  short b : 8;
+  int c;
+};
+#pragma align(reset)
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16573,6 +16573,15 @@
   // Notify the consumer that we've defined a tag.
   if (!Tag->isInvalidDecl())
 Consumer.HandleTagDeclDefinition(Tag);
+
+  // Clangs implementation of #pragma align(pack) differs in bitfield layout
+  // from XLs and instead matches the XL #pragma pack(1) behavior.
+  if (Context.getTargetInfo().getTriple().isOSAIX() &&
+  AlignPackStack.hasValue()) {
+AlignPackInfo APInfo = AlignPackStack.CurrentValue;
+if (APInfo.IsAlignAttr() && APInfo.getAlignMode() == AlignPackInfo::Packed)
+  Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
+  }
 }
 
 void Sema::ActOnObjCContainerFinishDefinition() {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -913,6 +913,9 @@
   InGroup;
 def err_pragma_options_align_mac68k_target_unsupported : Error<
   "mac68k alignment pragma is not supported on this target">;
+def warn_pragma_align_not_xl_compatible : Warning<
+  "#pragma align(packed) may not be compatible with objects generated with AIX 
XL C/C++">,
+  InGroup;
 def warn_pragma_pack_invalid_alignment : Warning<
   "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">,
   InGroup;


Index: clang/test/Sema/aix-pragma-align-packed-warn.c
===
--- /dev/null
+++ clang/test/Sema/aix-pragma-align-packed-warn.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff  -fxl-pragma-pack -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff  -fxl-pragma-pack -verify -fsyntax-only %s
+
+#pragma align(packed)
+struct A {  // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}}
+  short s1;
+  int   : 0;
+  short s2;
+};
+
+struct B {  // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}}
+  short a : 8;
+  short b : 8;
+  int c;
+};
+#pragma align(reset)
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16573,6 +16573,15 @@
   // Notify the consumer that we've defined a tag.
   if (!Tag->isInvalidDecl())
 Consumer.HandleTagDeclDefinition(Tag);
+
+  // Clangs implementation of #pragma align(pack) differs in bitfield layout
+  // from XLs and instead matches the XL #pragma pack(1) behavior.
+  if (Context.getTargetInfo().getTriple().isOSAIX() &&
+  AlignPackStack.hasValue()) {
+AlignPackInfo APInfo = AlignPackStack.CurrentValue;
+if (APInfo.IsAlignAttr() && APInfo.getAlignMode() == AlignPackInfo::Packed)
+  Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
+  }
 }
 
 void Sema::ActOnObjCContainerFinishDefinition() {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -913,6 +913,9 @@
   InGroup;
 def err_pragma_options_align_mac68k_target_unsupported : Error<
   "mac68k alignment pragma is not supported on this target">;
+def warn_pragma_align_not_xl_compatible : Warning<
+  "#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++">,
+  InGroup;
 def warn_pragma_pack_invalid_alignment : Warning<
   "expected #pragma pack parameter to be '1', '2', '4'

[PATCH] D106216: Disallow narrowing conversions to bool in noexcept specififers.

2021-08-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp:879
   EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept));
-  EXPECT_TRUE(notMatches("void foo() noexcept(1+1);", NoExcept));
+  EXPECT_TRUE(notMatches("void foo() noexcept(0+1);", NoExcept));
   EXPECT_TRUE(matches("void foo() noexcept(noexcept(1+1));", NoExcept));

cor3ntin wrote:
> aaron.ballman wrote:
> > Was there a reason this test needed to change?
> yup, 2 is not convertible to bool here. I use 0+1 to keep the kind of 
> expression the same
I kinda figured that was the case, thanks for confirming!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106216

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


[PATCH] D106216: Disallow narrowing conversions to bool in noexcept specififers.

2021-08-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 364783.
cor3ntin added a comment.

- Update the release version to Clang 14 in cxx_status
- Remove unused parameter
- Remove WS only changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106216

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/except/except.spec/p1.cpp
  clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  Clang 13
+  Clang 14
 
 
   Trimming whitespaces before line splicing
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -876,7 +876,7 @@
   EXPECT_TRUE(
   matches("void foo() noexcept; bool bar = noexcept(foo());", NoExcept));
   EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept));
-  EXPECT_TRUE(notMatches("void foo() noexcept(1+1);", NoExcept));
+  EXPECT_TRUE(notMatches("void foo() noexcept(0+1);", NoExcept));
   EXPECT_TRUE(matches("void foo() noexcept(noexcept(1+1));", NoExcept));
 }
 
Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -727,3 +727,18 @@
 Str b = "not so short";// expected-error {{no viable conversion}}
 
 }
+
+namespace P1401 {
+
+const int *ptr;
+
+struct S {
+  explicit(sizeof(char[2])) S(char); // expected-error {{explicit specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
+  explicit(ptr) S(long); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
+  explicit(nullptr) S(int);  // expected-error {{conversion from 'nullptr_t' to 'bool' is not allowed in a converted constant expression}}
+  explicit(42L) S(int, int); // expected-error {{explicit specifier argument evaluates to 42, which cannot be narrowed to type 'bool'}}
+  explicit(sizeof(char)) S();
+  explicit(0) S(char, char);
+  explicit(1L) S(char, char, char);
+};
+} // namespace P1401
Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -77,6 +77,17 @@
 }
 
 struct pr_44514 {
-  // expected-error@+1{{value of type 'void' is not contextually convertible to 'bool'}}
+  // expected-error@+1{{value of type 'void' is not implicitly convertible to 'bool'}}
   void foo(void) const &noexcept(f());
 };
+
+namespace P1401 {
+const int *ptr = nullptr;
+void f() noexcept(sizeof(char[2])); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
+void g() noexcept(sizeof(char));
+void h() noexcept(ptr); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
+void i() noexcept(nullptr); // expected-error {{conversion from 'nullptr_t' to 'bool' is not allowed in a converted constant expression}}
+void j() noexcept(0);
+void k() noexcept(1);
+void l() noexcept(2); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
+} // namespace P1401
Index: clang/test/CXX/except/except.spec/p1.cpp
===
--- clang/test/CXX/except/except.spec/p1.cpp
+++ clang/test/CXX/except/except.spec/p1.cpp
@@ -54,9 +54,8 @@
 
   struct A {};
 
-  void g1() noexcept(A()); // expected-error {{not contextually convertible}}
-  void g2(bool b) noexcept(b); // expected-error {{argument to noexcept specifier must be a constant expression}} expected-note {{function parameter 'b' with unknown value}} expected-note {{here}}
-
+  void g1() noexcept(A()); // expected-error {{value of type 'noex::A' is not implicitly convertible to 'bool'}}
+  void g2(bool b) noexcept(b); // expected-error {{noexcept specifier argument is not a constant expression}} expected-note {{function parameter 'b' with unknown value}} expected-note {{here}}
 }
 
 namespace noexcept_unevaluated {
@@ -73,12 +72,12 @@
 }
 
 namespace PR11084 {
-  template struct A { 
-stat

[clang] 420e1d4 - [AIX] Define __THW_BIG_ENDIAN__ macro

2021-08-06 Thread Jake Egan via cfe-commits

Author: Jake Egan
Date: 2021-08-06T09:46:59-04:00
New Revision: 420e1d4cf45d78a6f9edb935f44dfa4249de16f4

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

LOG: [AIX] Define __THW_BIG_ENDIAN__ macro

%%%
This patch defines the macro __THW_BIG_ENDIAN__ for AIX.
%%%

Tested with SPEC.

Reviewed By: cebowleratibm

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

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h
clang/test/Preprocessor/init-ppc.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 9780d5036aa23..28d4c77d47caf 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -673,6 +673,7 @@ class AIXTargetInfo : public OSTargetInfo {
 DefineStd(Builder, "unix", Opts);
 Builder.defineMacro("_IBMR2");
 Builder.defineMacro("_POWER");
+Builder.defineMacro("__THW_BIG_ENDIAN__");
 
 Builder.defineMacro("_AIX");
 Builder.defineMacro("__TOS_AIX__");

diff  --git a/clang/test/Preprocessor/init-ppc.c 
b/clang/test/Preprocessor/init-ppc.c
index 6ebc80717dbc3..ac72e6cb027b0 100644
--- a/clang/test/Preprocessor/init-ppc.c
+++ b/clang/test/Preprocessor/init-ppc.c
@@ -538,6 +538,7 @@
 // PPC-AIX:#define __SIZE_MAX__ 4294967295UL
 // PPC-AIX:#define __SIZE_TYPE__ long unsigned int
 // PPC-AIX:#define __SIZE_WIDTH__ 32
+// PPC-AIX:#define __THW_BIG_ENDIAN__ 1
 // PPC-AIX:#define __TOS_AIX__ 1
 // PPC-AIX:#define __UINT16_C_SUFFIX__
 // PPC-AIX:#define __UINT16_MAX__ 65535



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


[PATCH] D107241: [AIX] Define __THW_BIG_ENDIAN__ macro

2021-08-06 Thread Jake Egan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG420e1d4cf45d: [AIX] Define __THW_BIG_ENDIAN__ macro 
(authored by Jake-Egan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107241

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init-ppc.c


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -538,6 +538,7 @@
 // PPC-AIX:#define __SIZE_MAX__ 4294967295UL
 // PPC-AIX:#define __SIZE_TYPE__ long unsigned int
 // PPC-AIX:#define __SIZE_WIDTH__ 32
+// PPC-AIX:#define __THW_BIG_ENDIAN__ 1
 // PPC-AIX:#define __TOS_AIX__ 1
 // PPC-AIX:#define __UINT16_C_SUFFIX__
 // PPC-AIX:#define __UINT16_MAX__ 65535
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -673,6 +673,7 @@
 DefineStd(Builder, "unix", Opts);
 Builder.defineMacro("_IBMR2");
 Builder.defineMacro("_POWER");
+Builder.defineMacro("__THW_BIG_ENDIAN__");
 
 Builder.defineMacro("_AIX");
 Builder.defineMacro("__TOS_AIX__");


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -538,6 +538,7 @@
 // PPC-AIX:#define __SIZE_MAX__ 4294967295UL
 // PPC-AIX:#define __SIZE_TYPE__ long unsigned int
 // PPC-AIX:#define __SIZE_WIDTH__ 32
+// PPC-AIX:#define __THW_BIG_ENDIAN__ 1
 // PPC-AIX:#define __TOS_AIX__ 1
 // PPC-AIX:#define __UINT16_C_SUFFIX__
 // PPC-AIX:#define __UINT16_MAX__ 65535
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -673,6 +673,7 @@
 DefineStd(Builder, "unix", Opts);
 Builder.defineMacro("_IBMR2");
 Builder.defineMacro("_POWER");
+Builder.defineMacro("__THW_BIG_ENDIAN__");
 
 Builder.defineMacro("_AIX");
 Builder.defineMacro("__TOS_AIX__");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106216: Disallow narrowing conversions to bool in noexcept specififers.

2021-08-06 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106216

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


[PATCH] D107506: [PowerPC][AIX] Warn when using pragma align(packed) on AIX.

2021-08-06 Thread Sean Fertile via Phabricator via cfe-commits
sfertile added a comment.

In D107506#2931095 , @sfertile wrote:

> Moved the diagnostic emission to ` Sema::ActOnTagFinishDefinition` as 
> suggested.

Sorry, uploaded wrong diff. Will updated again shortly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107506

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


[PATCH] D107244: [AIX] Define _ARCH_PPC64 macro for 32-bit

2021-08-06 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm accepted this revision.
cebowleratibm 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/D107244/new/

https://reviews.llvm.org/D107244

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


[clang] 3189dd2 - [AIX] Define __THW_PPC__ macro

2021-08-06 Thread Jake Egan via cfe-commits

Author: Jake Egan
Date: 2021-08-06T09:52:26-04:00
New Revision: 3189dd205a581272b9a0cfc614e8f341495fc716

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

LOG: [AIX] Define __THW_PPC__ macro

%%%
This patch defines the macro __THW_PPC__ for AIX.
%%%

Tested with SPEC.

Reviewed By: cebowleratibm

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

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.cpp
clang/test/Preprocessor/init-ppc.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 59656888e25f9..a888e22697de9 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -257,6 +257,9 @@ void PPCTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
   }
+  if (getTriple().isOSAIX()) {
+Builder.defineMacro("__THW_PPC__");
+  }
 
   // Target properties.
   if (getTriple().getArch() == llvm::Triple::ppc64le ||

diff  --git a/clang/test/Preprocessor/init-ppc.c 
b/clang/test/Preprocessor/init-ppc.c
index ac72e6cb027b0..abf2e919cff68 100644
--- a/clang/test/Preprocessor/init-ppc.c
+++ b/clang/test/Preprocessor/init-ppc.c
@@ -539,6 +539,7 @@
 // PPC-AIX:#define __SIZE_TYPE__ long unsigned int
 // PPC-AIX:#define __SIZE_WIDTH__ 32
 // PPC-AIX:#define __THW_BIG_ENDIAN__ 1
+// PPC-AIX:#define __THW_PPC__ 1
 // PPC-AIX:#define __TOS_AIX__ 1
 // PPC-AIX:#define __UINT16_C_SUFFIX__
 // PPC-AIX:#define __UINT16_MAX__ 65535



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


[PATCH] D107243: [AIX] Define __THW_PPC__ macro

2021-08-06 Thread Jake Egan 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 rG3189dd205a58: [AIX] Define __THW_PPC__ macro (authored by 
Jake-Egan).

Changed prior to commit:
  https://reviews.llvm.org/D107243?vs=363354&id=364785#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107243

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


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -539,6 +539,7 @@
 // PPC-AIX:#define __SIZE_TYPE__ long unsigned int
 // PPC-AIX:#define __SIZE_WIDTH__ 32
 // PPC-AIX:#define __THW_BIG_ENDIAN__ 1
+// PPC-AIX:#define __THW_PPC__ 1
 // PPC-AIX:#define __TOS_AIX__ 1
 // PPC-AIX:#define __UINT16_C_SUFFIX__
 // PPC-AIX:#define __UINT16_MAX__ 65535
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -257,6 +257,9 @@
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
   }
+  if (getTriple().isOSAIX()) {
+Builder.defineMacro("__THW_PPC__");
+  }
 
   // Target properties.
   if (getTriple().getArch() == llvm::Triple::ppc64le ||


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -539,6 +539,7 @@
 // PPC-AIX:#define __SIZE_TYPE__ long unsigned int
 // PPC-AIX:#define __SIZE_WIDTH__ 32
 // PPC-AIX:#define __THW_BIG_ENDIAN__ 1
+// PPC-AIX:#define __THW_PPC__ 1
 // PPC-AIX:#define __TOS_AIX__ 1
 // PPC-AIX:#define __UINT16_C_SUFFIX__
 // PPC-AIX:#define __UINT16_MAX__ 65535
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -257,6 +257,9 @@
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
   }
+  if (getTriple().isOSAIX()) {
+Builder.defineMacro("__THW_PPC__");
+  }
 
   // Target properties.
   if (getTriple().getArch() == llvm::Triple::ppc64le ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-08-06 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added inline comments.



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:82
+  PatFrags ScalarIntMemFrags = !if (!eq (EltTypeName, "f16"),
+   !cast("sse_load_f16"),
+   !if (!eq (EltTypeName, "f32"),

indent



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:3878
+}
+let Predicates = [HasFP16, HasVLX] in {
+  def : Pat<(v16f16 (vselect VK16WM:$mask, (v16f16 VR256X:$src1), (v16f16 
VR256X:$src0))),

Not sure this can be merged to 512 version load/store pattern with muticlass by 
abstract type info.



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:4159
+defm VMOVSHZ : avx512_move_scalar<"vmovsh", X86Movsh, X86vzload16, f16x_info,
+  [HasFP16]>,
+  VEX_LIG, T_MAP5XS, EVEX_CD8<16, CD8VT1>;

Why there is no OptForSize for vmovsh?



Comment at: llvm/lib/Target/X86/X86InstrAVX512.td:4478
+  let Predicates = [HasFP16] in {
+def VMOVSHZrr_REV: AVX512<0x11, MRMDestReg, (outs VR128X:$dst),
+(ins VR128X:$src1, VR128X:$src2),

Sorry, I forgot what REV stand for. Do you know it?
Is this just encoding difference for register operand compared with VMOVSHZrr? 
What is it used for?



Comment at: llvm/lib/Target/X86/X86RegisterInfo.td:570
 def VR64: RegisterClass<"X86", [x86mmx], 64, (sequence "MM%u", 0, 7)>;
-def VR128 : RegisterClass<"X86", [v4f32, v2f64, v16i8, v8i16, v4i32, v2i64, 
f128],
+def VR128 : RegisterClass<"X86", [v4f32, v2f64, v8f16, v16i8, v8i16, v4i32, 
v2i64, f128],
   128, (add FR32)>;

Given there is only EVEX instructions for fp16, is it necessary to add f16 type 
to it?



Comment at: llvm/lib/Target/X86/X86RegisterInfo.td:572
   128, (add FR32)>;
-def VR256 : RegisterClass<"X86", [v8f32, v4f64, v32i8, v16i16, v8i32, v4i64],
+def VR256 : RegisterClass<"X86", [v8f32, v4f64, v16f16, v32i8, v16i16, v8i32, 
v4i64],
   256, (sequence "YMM%u", 0, 15)>;

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-08-06 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added inline comments.



Comment at: llvm/test/CodeGen/X86/vector-reduce-fmax-nnan.ll:374
+; SSE-NEXT:movl %edi, %ebp
+; SSE-NEXT:movzwl %bx, %edi
 ; SSE-NEXT:callq __gnu_h2f_ieee@PLT

Why this test case changes? Shall we add -mattr=+avx512fp16 to run?



Comment at: llvm/test/CodeGen/X86/vector-reduce-fmin-nnan.ll:373
+; SSE-NEXT:movl %edi, %ebp
+; SSE-NEXT:movzwl %bx, %edi
 ; SSE-NEXT:callq __gnu_h2f_ieee@PLT

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-08-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 364787.
balazske added a comment.

Init std declarations and FILE type only once.
Make a lambda not operate on captured data.
Simplify test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

Files:
  clang/lib/StaticAnalyzer/Checkers/ASTLookup.cpp
  clang/lib/StaticAnalyzer/Checkers/ASTLookup.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream.c

Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -1,7 +1,9 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify %s
 
 #include "Inputs/system-header-simulator.h"
 
+void clang_analyzer_eval(int);
+
 void check_fread() {
   FILE *fp = tmpfile();
   fread(0, 0, 0, fp); // expected-warning {{Stream pointer might be NULL}}
@@ -267,3 +269,23 @@
 } // expected-warning {{Opened stream never closed. Potential resource leak}}
 // FIXME: This warning should be placed at the `return` above.
 // See https://reviews.llvm.org/D83120 about details.
+
+void check_fopen_is_not_std() {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  clang_analyzer_eval(F != stdin);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(F != stdout); // expected-warning{{TRUE}}
+  clang_analyzer_eval(F != stderr); // expected-warning{{TRUE}}
+  fclose(F);
+}
+
+void check_tmpfile_is_not_std() {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  clang_analyzer_eval(F != stdin);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(F != stdout); // expected-warning{{TRUE}}
+  clang_analyzer_eval(F != stderr); // expected-warning{{TRUE}}
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -10,6 +10,8 @@
 //
 //===--===//
 
+#include "ASTLookup.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -157,6 +159,11 @@
 // StreamChecker class and utility functions.
 //===--===//
 
+// This map holds the state of a stream.
+// The stream is identified with a SymbolRef that is created when a stream
+// opening function is modeled by the checker.
+REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
+
 namespace {
 
 class StreamChecker;
@@ -206,8 +213,9 @@
   return State;
 }
 
-class StreamChecker : public Checker {
+class StreamChecker
+: public Checker {
   BugType BT_FileNull{this, "NULL stream pointer", "Stream handling error"};
   BugType BT_UseAfterClose{this, "Closed stream", "Stream handling error"};
   BugType BT_UseAfterOpenFailed{this, "Invalid stream",
@@ -221,6 +229,7 @@
   /*SuppressOnSink =*/true};
 
 public:
+  void checkBeginFunction(CheckerContext &C) const;
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
@@ -285,6 +294,15 @@
 0}},
   };
 
+  mutable bool StdStreamsInitialized = false;
+  mutable Optional FILEType;
+  mutable const VarDecl *StdinDecl;
+  mutable const VarDecl *StdoutDecl;
+  mutable const VarDecl *StderrDecl;
+  mutable SymbolRef StdinSym;
+  mutable SymbolRef StdoutSym;
+  mutable SymbolRef StderrSym;
+
   void evalFopen(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const;
 
@@ -410,20 +428,23 @@
   static const ExplodedNode *getAcquisitionSite(const ExplodedNode *N,
 SymbolRef StreamSym,
 CheckerContext &C);
+
+  const VarDecl *findStdStreamDecl(StringRef StdName, CheckerContext &C) const;
+
+  SymbolRef getStdStreamSym(const VarDecl *StdDecl, CheckerContext &C) const;
 };
 
 } // end anonymous namespace
 
-// This map holds the state of a stream.
-// The stream is identified with a SymbolRef that is created when a stream
-// opening function is modeled by the checker.
-REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
-
 inline void assertStreamStateOpened(const StreamState *SS) {
   assert(SS->isOpened() &&
  "Previous create of error node for non-opened stream failed

[PATCH] D107242: [AIX] Define __HOS_AIX__ macro

2021-08-06 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm accepted this revision.
cebowleratibm 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/D107242/new/

https://reviews.llvm.org/D107242

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


[clang] 3c8e94b - Disallow narrowing conversions to bool in noexcept specififers

2021-08-06 Thread Aaron Ballman via cfe-commits

Author: Corentin Jabot
Date: 2021-08-06T10:26:39-04:00
New Revision: 3c8e94bc20e5829ab5167d21d242b6b624dd934e

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

LOG: Disallow narrowing conversions to bool in noexcept specififers

Completes the support for P1401R5.

Added: 
clang/test/SemaCXX/ignored-reference-qualifiers-disabled.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/except/except.spec/p1.cpp
clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
clang/test/SemaCXX/cxx2a-explicit-bool.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4ed561fb57b09..6cfb8b89eb903 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -82,11 +82,11 @@ def err_typecheck_converted_constant_expression_indirect : 
Error<
   "bind reference to a temporary">;
 def err_expr_not_cce : Error<
   "%select{case value|enumerator value|non-type template argument|"
-  "array size|explicit specifier argument}0 "
+  "array size|explicit specifier argument|noexcept specifier argument}0 "
   "is not a constant expression">;
 def ext_cce_narrowing : ExtWarn<
   "%select{case value|enumerator value|non-type template argument|"
-  "array size|explicit specifier argument}0 "
+  "array size|explicit specifier argument|noexcept specifier argument}0 "
   "%select{cannot be narrowed from type %2 to %3|"
   "evaluates to %2, which cannot be narrowed to type %3}1">,
   InGroup, DefaultError, SFINAEFailure;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 854070aee428b..441c928ac4f20 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3499,11 +3499,12 @@ class Sema final {
 
   /// Contexts in which a converted constant expression is required.
   enum CCEKind {
-CCEK_CaseValue,   ///< Expression in a case label.
-CCEK_Enumerator,  ///< Enumerator value with fixed underlying type.
-CCEK_TemplateArg, ///< Value of a non-type template parameter.
-CCEK_ArrayBound,  ///< Array bound in array declarator or new-expression.
-CCEK_ExplicitBool ///< Condition in an explicit(bool) specifier.
+CCEK_CaseValue,///< Expression in a case label.
+CCEK_Enumerator,   ///< Enumerator value with fixed underlying type.
+CCEK_TemplateArg,  ///< Value of a non-type template parameter.
+CCEK_ArrayBound,   ///< Array bound in array declarator or new-expression.
+CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier.
+CCEK_Noexcept  ///< Condition in a noexcept(bool) specifier.
   };
   ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
   llvm::APSInt &Value, CCEKind 
CCE);
@@ -5904,7 +5905,7 @@ class Sema final {
 
   /// Check the given noexcept-specifier, convert its expression, and compute
   /// the appropriate ExceptionSpecificationType.
-  ExprResult ActOnNoexceptSpec(SourceLocation NoexceptLoc, Expr *NoexceptExpr,
+  ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr,
ExceptionSpecificationType &EST);
 
   /// Check the given exception-specification and update the

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 760600a3ea3ca..23d22c7b99e9d 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3837,7 +3837,7 @@ Parser::tryParseExceptionSpecification(bool Delayed,
 NoexceptExpr = ParseConstantExpression();
 T.consumeClose();
 if (!NoexceptExpr.isInvalid()) {
-  NoexceptExpr = Actions.ActOnNoexceptSpec(KeywordLoc, NoexceptExpr.get(),
+  NoexceptExpr = Actions.ActOnNoexceptSpec(NoexceptExpr.get(),
NoexceptType);
   NoexceptRange = SourceRange(KeywordLoc, T.getCloseLocation());
 } else {

diff  --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index 8816c9c1fea02..0d40b47b24da4 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -78,14 +78,21 @@ bool Sema::isLibstdcxxEagerExceptionSpecHack(const 
Declarator &D) {
   .Default(false);
 }
 
-ExprResult Sema::ActOnNoexceptSpec(SourceLocation NoexceptLoc,
-   Expr *NoexceptExpr,
+ExprResult Sema::ActOnNoexceptSpec(Expr *NoexceptExpr,
 

[PATCH] D106216: Disallow narrowing conversions to bool in noexcept specififers.

2021-08-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've committed on your behalf in 3c8e94bc20e5829ab5167d21d242b6b624dd934e 
, thank 
you for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106216

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


[PATCH] D107365: clangd: Make documentation property of completion items more similar

2021-08-06 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 364790.
ckandeler added a comment.

Added test coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107365

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -907,7 +907,7 @@
   auto Results = completions(
   R"cpp(
   // Non-doxygen comment.
-  int foo();
+  __attribute__((annotate("custom_annotation"))) int foo();
   /// Doxygen comment.
   /// \param int a
   int bar(int a);
@@ -919,7 +919,8 @@
   int x = ^
  )cpp");
   EXPECT_THAT(Results.Completions,
-  Contains(AllOf(Named("foo"), Doc("Non-doxygen comment.";
+  Contains(AllOf(Named("foo"),
+  Doc("Annotation: custom_annotation\nNon-doxygen comment.";
   EXPECT_THAT(
   Results.Completions,
   Contains(AllOf(Named("bar"), Doc("Doxygen comment.\n\\param int a";
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -405,8 +405,9 @@
   if (C.IndexResult) {
 SetDoc(C.IndexResult->Documentation);
   } else if (C.SemaResult) {
-SetDoc(getDocComment(*ASTCtx, *C.SemaResult,
- /*CommentsFromHeader=*/false));
+const auto DocComment = getDocComment(*ASTCtx, *C.SemaResult,
+  /*CommentsFromHeader=*/false);
+SetDoc(formatDocumentation(*SemaCCS, DocComment));
   }
 }
   }


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -907,7 +907,7 @@
   auto Results = completions(
   R"cpp(
   // Non-doxygen comment.
-  int foo();
+  __attribute__((annotate("custom_annotation"))) int foo();
   /// Doxygen comment.
   /// \param int a
   int bar(int a);
@@ -919,7 +919,8 @@
   int x = ^
  )cpp");
   EXPECT_THAT(Results.Completions,
-  Contains(AllOf(Named("foo"), Doc("Non-doxygen comment.";
+  Contains(AllOf(Named("foo"),
+  Doc("Annotation: custom_annotation\nNon-doxygen comment.";
   EXPECT_THAT(
   Results.Completions,
   Contains(AllOf(Named("bar"), Doc("Doxygen comment.\n\\param int a";
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -405,8 +405,9 @@
   if (C.IndexResult) {
 SetDoc(C.IndexResult->Documentation);
   } else if (C.SemaResult) {
-SetDoc(getDocComment(*ASTCtx, *C.SemaResult,
- /*CommentsFromHeader=*/false));
+const auto DocComment = getDocComment(*ASTCtx, *C.SemaResult,
+  /*CommentsFromHeader=*/false);
+SetDoc(formatDocumentation(*SemaCCS, DocComment));
   }
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 131b462 - Implement P1937 consteval in unevaluated contexts

2021-08-06 Thread Aaron Ballman via cfe-commits

Author: Corentin Jabot
Date: 2021-08-06T10:29:28-04:00
New Revision: 131b4620ee7847102479f399ce3e35a3c1cb5461

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

LOG: Implement P1937 consteval in unevaluated contexts

In an unevaluated contexts, consteval functions should not be
immediately evaluated.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d316687c4cd8e..8ef4a9d96320b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16641,7 +16641,8 @@ void Sema::CheckUnusedVolatileAssignment(Expr *E) {
 }
 
 ExprResult Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) 
{
-  if (!E.isUsable() || !Decl || !Decl->isConsteval() || isConstantEvaluated() 
||
+  if (isUnevaluatedContext() || !E.isUsable() || !Decl ||
+  !Decl->isConsteval() || isConstantEvaluated() ||
   RebuildingImmediateInvocation)
 return E;
 
@@ -18758,8 +18759,8 @@ void Sema::MarkDeclRefReferenced(DeclRefExpr *E, const 
Expr *Base) {
   OdrUse = false;
 
   if (auto *FD = dyn_cast(E->getDecl()))
-if (!isConstantEvaluated() && FD->isConsteval() &&
-!RebuildingImmediateInvocation)
+if (!isUnevaluatedContext() && !isConstantEvaluated() &&
+FD->isConsteval() && !RebuildingImmediateInvocation)
   ExprEvalContexts.back().ReferenceToConsteval.insert(E);
   MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E, OdrUse,
  RefsMinusAssignments);

diff  --git a/clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp 
b/clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
index 55debe3ca731d..fafcd127feec2 100644
--- a/clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
+++ b/clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // C++ [basic.def.odr]p2:
 //   An expression is potentially evaluated unless it [...] is the
@@ -16,7 +17,7 @@ struct Poly {
 
 struct NonPoly { };
 
-template 
+template
 struct X {
   Result f(T t) { return t + t; } // expected-error{{invalid operands}}
 
@@ -34,3 +35,33 @@ void test(X xp, X xpr, X xnp, 
X x
   // Triggers an error (as it should);
   xpr.g(Poly()); // expected-note{{instantiation of member function}}
 }
+
+#if __cplusplus >= 202002L
+
+namespace unevaluated {
+
+struct S {
+  void f();
+};
+struct T {
+  virtual void f();
+};
+
+consteval S *null_s() { return nullptr; }
+consteval S *make_s() { return new S; }
+consteval T *null_t() { return nullptr; }
+consteval T *make_t() { return new T; } // #alloc
+
+void func() {
+  (void)typeid(*null_s());
+  (void)typeid(*make_s());
+  (void)typeid(*null_t()); // expected-warning {{expression with side effects 
will be evaluated despite being used as an operand to 'typeid'}}
+  (void)typeid(*make_t()); // expected-error {{call to consteval function 
'unevaluated::make_t' is not a constant expression}} \
+  expected-note {{pointer to heap-allocated object 
is not a constant expression}} \
+  expected-note@#alloc {{heap allocation performed 
here}} \
+  expected-warning {{expression with side effects 
will be evaluated despite being used as an operand to 'typeid'}}
+}
+
+} // namespace unevaluated
+
+#endif

diff  --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index ecf8c1e0f5bd7..04c8898aa5bad 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -594,3 +594,21 @@ void test() {
 }
 
 } // namespace special_ctor
+
+namespace unevaluated {
+
+template  struct is_same { static const bool value = 
false; };
+template  struct is_same { static const bool value = true; };
+
+long f(); // expected-note {{declared here}}
+auto consteval g(auto a) {
+  return a;
+}
+
+auto e = g(f()); // expected-error {{is not a constant expression}}
+ // expected-note@-1 {{non-constexpr function 'f' cannot be 
used in a constant expression}}
+
+using T = decltype(g(f()));
+static_assert(is_same::value);
+
+} // namespace unevaluated

diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 60ce69db99225..3cbee7026c5c2 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1105,10 +1105,11 @@ C++20 implementation status
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  No
+  Partial
 

 https://wg21.link/p1937r2";>P1937R2
+Clang 14
   
 

[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I have commit on your behalf in 131b4620ee7847102479f399ce3e35a3c1cb5461 
, thank 
you for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

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


[PATCH] D107138: [PowerPC] Implement cmplxl builtins

2021-08-06 Thread Victor Huang via Phabricator via cfe-commits
NeHuang added inline comments.



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat-complex.c:45
+  // CHECK-AIX-NEXT: ret { double, double } %.fca.1.insert
+  return __cmplxl(lda, ldb);
+}

nemanjai wrote:
> We really only need this test case and we should be able to just add it to 
> one of the existing XL-compat clang test cases.
As suggest above, can we add the test case `__cmplxl` to one of the existing 
clang test file `builtins-ppc-xlcompat-cmplx.c`? You can auto generate the 
`CHECKS` using `utils/update_cc_test_checks.py` to avoid hardcoding the 
variable names. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107138

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


[PATCH] D107646: [PowerPC] Fix the frame addresss computing return address for `__builtin_return_address`

2021-08-06 Thread Victor Huang via Phabricator via cfe-commits
NeHuang created this revision.
NeHuang added reviewers: nemanjai, stefanp, PowerPC.
NeHuang added a project: LLVM.
Herald added subscribers: shchenz, kbarton, hiraditya.
NeHuang requested review of this revision.

When depth > 0, callee frame address is used to compute the return address of 
callee producing improper return address. This patch adds the fix to use caller 
frame address to compute the return address of callee.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107646

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/2010-05-03-retaddr1.ll
  llvm/test/CodeGen/PowerPC/retaddr_multi_levels.ll

Index: llvm/test/CodeGen/PowerPC/retaddr_multi_levels.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/retaddr_multi_levels.ll
@@ -0,0 +1,174 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux -mcpu=pwr8 | FileCheck %s -check-prefix=CHECK-64B-LE
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64-unknown-linux -mcpu=pwr7 | FileCheck %s -check-prefix=CHECK-64B-BE
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64-unknown-aix -mcpu=pwr7 | FileCheck %s -check-prefix=CHECK-64B-AIX
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc-unknown-aix -mcpu=pwr7 | FileCheck %s -check-prefix=CHECK-32B-AIX
+
+declare i8* @llvm.returnaddress(i32) nounwind readnone
+
+define i8* @test0() nounwind readnone {
+; CHECK-64B-LE-LABEL: test0:
+; CHECK-64B-LE:   # %bb.0: # %entry
+; CHECK-64B-LE-NEXT:mflr 0
+; CHECK-64B-LE-NEXT:std 0, 16(1)
+; CHECK-64B-LE-NEXT:stdu 1, -32(1)
+; CHECK-64B-LE-NEXT:ld 3, 48(1)
+; CHECK-64B-LE-NEXT:addi 1, 1, 32
+; CHECK-64B-LE-NEXT:ld 0, 16(1)
+; CHECK-64B-LE-NEXT:mtlr 0
+; CHECK-64B-LE-NEXT:blr
+;
+; CHECK-64B-BE-LABEL: test0:
+; CHECK-64B-BE:   # %bb.0: # %entry
+; CHECK-64B-BE-NEXT:mflr 0
+; CHECK-64B-BE-NEXT:std 0, 16(1)
+; CHECK-64B-BE-NEXT:stdu 1, -48(1)
+; CHECK-64B-BE-NEXT:ld 3, 64(1)
+; CHECK-64B-BE-NEXT:addi 1, 1, 48
+; CHECK-64B-BE-NEXT:ld 0, 16(1)
+; CHECK-64B-BE-NEXT:mtlr 0
+; CHECK-64B-BE-NEXT:blr
+;
+; CHECK-64B-AIX-LABEL: test0:
+; CHECK-64B-AIX:   # %bb.0: # %entry
+; CHECK-64B-AIX-NEXT:mflr 0
+; CHECK-64B-AIX-NEXT:std 0, 16(1)
+; CHECK-64B-AIX-NEXT:stdu 1, -48(1)
+; CHECK-64B-AIX-NEXT:ld 3, 64(1)
+; CHECK-64B-AIX-NEXT:addi 1, 1, 48
+; CHECK-64B-AIX-NEXT:ld 0, 16(1)
+; CHECK-64B-AIX-NEXT:mtlr 0
+; CHECK-64B-AIX-NEXT:blr
+;
+; CHECK-32B-AIX-LABEL: test0:
+; CHECK-32B-AIX:   # %bb.0: # %entry
+; CHECK-32B-AIX-NEXT:mflr 0
+; CHECK-32B-AIX-NEXT:stw 0, 8(1)
+; CHECK-32B-AIX-NEXT:stwu 1, -32(1)
+; CHECK-32B-AIX-NEXT:lwz 3, 40(1)
+; CHECK-32B-AIX-NEXT:addi 1, 1, 32
+; CHECK-32B-AIX-NEXT:lwz 0, 8(1)
+; CHECK-32B-AIX-NEXT:mtlr 0
+; CHECK-32B-AIX-NEXT:blr
+entry:
+  %0 = tail call i8* @llvm.returnaddress(i32 0);
+  ret i8* %0
+}
+
+define i8* @test1() nounwind readnone {
+; CHECK-64B-LE-LABEL: test1:
+; CHECK-64B-LE:   # %bb.0: # %entry
+; CHECK-64B-LE-NEXT:mflr 0
+; CHECK-64B-LE-NEXT:std 0, 16(1)
+; CHECK-64B-LE-NEXT:stdu 1, -32(1)
+; CHECK-64B-LE-NEXT:ld 3, 0(1)
+; CHECK-64B-LE-NEXT:ld 3, 0(3)
+; CHECK-64B-LE-NEXT:ld 3, 16(3)
+; CHECK-64B-LE-NEXT:addi 1, 1, 32
+; CHECK-64B-LE-NEXT:ld 0, 16(1)
+; CHECK-64B-LE-NEXT:mtlr 0
+; CHECK-64B-LE-NEXT:blr
+;
+; CHECK-64B-BE-LABEL: test1:
+; CHECK-64B-BE:   # %bb.0: # %entry
+; CHECK-64B-BE-NEXT:mflr 0
+; CHECK-64B-BE-NEXT:std 0, 16(1)
+; CHECK-64B-BE-NEXT:stdu 1, -48(1)
+; CHECK-64B-BE-NEXT:ld 3, 0(1)
+; CHECK-64B-BE-NEXT:ld 3, 0(3)
+; CHECK-64B-BE-NEXT:ld 3, 16(3)
+; CHECK-64B-BE-NEXT:addi 1, 1, 48
+; CHECK-64B-BE-NEXT:ld 0, 16(1)
+; CHECK-64B-BE-NEXT:mtlr 0
+; CHECK-64B-BE-NEXT:blr
+;
+; CHECK-64B-AIX-LABEL: test1:
+; CHECK-64B-AIX:   # %bb.0: # %entry
+; CHECK-64B-AIX-NEXT:mflr 0
+; CHECK-64B-AIX-NEXT:std 0, 16(1)
+; CHECK-64B-AIX-NEXT:stdu 1, -48(1)
+; CHECK-64B-AIX-NEXT:ld 3, 0(1)
+; CHECK-64B-AIX-NEXT:ld 3, 0(3)
+; CHECK-64B-AIX-NEXT:ld 3, 16(3)
+; CHECK-64B-AIX-NEXT:addi 1, 1, 48
+; CHECK-64B-AIX-NEXT:ld 0, 16(1)
+; CHECK-64B-AIX-NEXT:mtlr 0
+; CHECK-64B-AIX-NEXT:blr
+;
+; CHECK-32B-AIX-LABEL: test1:
+; CHECK-32B-AIX:   # %bb.0: # %entry
+; CHECK-32B-AIX-NEXT:mflr 0
+; CHECK-32B-AIX-NEXT:stw 0, 8(1)
+; CHECK-32B-AIX-NEXT:stwu 1, -32(1)
+; CHECK-32B-AIX-NEXT:lwz 3, 0(1)
+; CHECK-32B-AIX-NEXT:lwz 3, 0(3)
+; CHECK-32B-AIX-NEXT:lwz 3, 8(3)
+; CHECK-32B-AIX-NEXT:addi 1, 1, 32
+; CHECK-32B-AIX-NEXT:lwz 0, 8(1)
+; CHECK-32B-AIX-NEXT:mtlr 0
+; CHECK-32B-AIX-NEXT:blr
+entry:
+  %0 = tail call i8* @llvm.returnaddress(i32 1);
+  ret i8* %0
+}
+
+define i8* @test2() nounwind readnone {
+; CHECK-64B-LE-LABEL:

[clang] 869d07e - [AIX] Define __HOS_AIX__ macro

2021-08-06 Thread Jake Egan via cfe-commits

Author: Jake Egan
Date: 2021-08-06T10:40:13-04:00
New Revision: 869d07ee88a4355f5954ef9e2b2e79ceff225ddb

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

LOG: [AIX] Define __HOS_AIX__ macro

%%%
This patch defines __HOS_AIX__ macro for AIX in case of a cross compiler 
implementation.
%%%
Tested with SPEC.

Reviewed By: cebowleratibm

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

Added: 
clang/test/Preprocessor/host-aix.c
clang/test/Preprocessor/not-host-aix.c

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

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index a888e22697de..4ee7282c06ce 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -304,6 +305,11 @@ void PPCTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__LONGDOUBLE64");
   }
 
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSAIX() &&
+  getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");
+  }
+
   // Define this for elfv2 (64-bit only) or 64-bit darwin.
   if (ABI == "elfv2" ||
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))

diff  --git a/clang/test/Preprocessor/host-aix.c 
b/clang/test/Preprocessor/host-aix.c
new file mode 100644
index ..81d594ba5803
--- /dev/null
+++ b/clang/test/Preprocessor/host-aix.c
@@ -0,0 +1,3 @@
+// REQUIRES: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX %s
+// PPC-AIX:#define __HOS_AIX__ 1

diff  --git a/clang/test/Preprocessor/not-host-aix.c 
b/clang/test/Preprocessor/not-host-aix.c
new file mode 100644
index ..d6a2d22a7d25
--- /dev/null
+++ b/clang/test/Preprocessor/not-host-aix.c
@@ -0,0 +1,3 @@
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX %s
+// PPC-AIX-NOT:#define __HOS_AIX__ 1



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


[PATCH] D107242: [AIX] Define __HOS_AIX__ macro

2021-08-06 Thread Jake Egan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG869d07ee88a4: [AIX] Define __HOS_AIX__ macro (authored by 
Jake-Egan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107242

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/Preprocessor/host-aix.c
  clang/test/Preprocessor/not-host-aix.c


Index: clang/test/Preprocessor/not-host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/not-host-aix.c
@@ -0,0 +1,3 @@
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX %s
+// PPC-AIX-NOT:#define __HOS_AIX__ 1
Index: clang/test/Preprocessor/host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/host-aix.c
@@ -0,0 +1,3 @@
+// REQUIRES: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX %s
+// PPC-AIX:#define __HOS_AIX__ 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -304,6 +305,11 @@
 Builder.defineMacro("__LONGDOUBLE64");
   }
 
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSAIX() &&
+  getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");
+  }
+
   // Define this for elfv2 (64-bit only) or 64-bit darwin.
   if (ABI == "elfv2" ||
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))


Index: clang/test/Preprocessor/not-host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/not-host-aix.c
@@ -0,0 +1,3 @@
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX %s
+// PPC-AIX-NOT:#define __HOS_AIX__ 1
Index: clang/test/Preprocessor/host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/host-aix.c
@@ -0,0 +1,3 @@
+// REQUIRES: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX %s
+// PPC-AIX:#define __HOS_AIX__ 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -304,6 +305,11 @@
 Builder.defineMacro("__LONGDOUBLE64");
   }
 
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSAIX() &&
+  getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");
+  }
+
   // Define this for elfv2 (64-bit only) or 64-bit darwin.
   if (ABI == "elfv2" ||
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 41bcfe8 - [AIX] Define _ARCH_PPC64 macro for 32-bit

2021-08-06 Thread Jake Egan via cfe-commits

Author: Jake Egan
Date: 2021-08-06T10:42:44-04:00
New Revision: 41bcfe81742ed6462096ccb42aa5f2b9d67027fc

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

LOG: [AIX] Define _ARCH_PPC64 macro for 32-bit

%%%
The macro _ARCH_PPC64 is already defined for 64-bit, but this patch defines it 
for 32-bit on AIX to follow xlc. See: 
https://www.ibm.com/docs/en/xl-c-and-cpp-aix/13.1.0?topic=features-macros-related-architecture-settings

Note: This change creates a discrepancy between GCC, which defines _ARCH_PPC64 
only for 64-bit mode.

Tested with SPEC.
%%%

Reviewed By: cebowleratibm

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

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.cpp
clang/test/Preprocessor/init-ppc.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 4ee7282c06ce..711ba2837a9b 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -257,6 +257,9 @@ void PPCTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__powerpc64__");
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
+  } else if (getTriple().isOSAIX()) {
+// The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.
+Builder.defineMacro("_ARCH_PPC64");
   }
   if (getTriple().isOSAIX()) {
 Builder.defineMacro("__THW_PPC__");

diff  --git a/clang/test/Preprocessor/init-ppc.c 
b/clang/test/Preprocessor/init-ppc.c
index abf2e919cff6..fedc1b6c9140 100644
--- a/clang/test/Preprocessor/init-ppc.c
+++ b/clang/test/Preprocessor/init-ppc.c
@@ -391,6 +391,7 @@
 // PPC-AIX-NOT:#define __64BIT__ 1
 // PPC-AIX:#define _AIX 1
 // PPC-AIX:#define _ARCH_PPC 1
+// PPC-AIX:#define _ARCH_PPC64 1
 // PPC-AIX:#define _BIG_ENDIAN 1
 // PPC-AIX:#define _IBMR2 1
 // PPC-AIX:#define _LONG_LONG 1



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


[PATCH] D107244: [AIX] Define _ARCH_PPC64 macro for 32-bit

2021-08-06 Thread Jake Egan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41bcfe81742e: [AIX] Define _ARCH_PPC64 macro for 32-bit 
(authored by Jake-Egan).

Changed prior to commit:
  https://reviews.llvm.org/D107244?vs=364766&id=364793#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107244

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


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -391,6 +391,7 @@
 // PPC-AIX-NOT:#define __64BIT__ 1
 // PPC-AIX:#define _AIX 1
 // PPC-AIX:#define _ARCH_PPC 1
+// PPC-AIX:#define _ARCH_PPC64 1
 // PPC-AIX:#define _BIG_ENDIAN 1
 // PPC-AIX:#define _IBMR2 1
 // PPC-AIX:#define _LONG_LONG 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -257,6 +257,9 @@
 Builder.defineMacro("__powerpc64__");
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
+  } else if (getTriple().isOSAIX()) {
+// The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.
+Builder.defineMacro("_ARCH_PPC64");
   }
   if (getTriple().isOSAIX()) {
 Builder.defineMacro("__THW_PPC__");


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -391,6 +391,7 @@
 // PPC-AIX-NOT:#define __64BIT__ 1
 // PPC-AIX:#define _AIX 1
 // PPC-AIX:#define _ARCH_PPC 1
+// PPC-AIX:#define _ARCH_PPC64 1
 // PPC-AIX:#define _BIG_ENDIAN 1
 // PPC-AIX:#define _IBMR2 1
 // PPC-AIX:#define _LONG_LONG 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -257,6 +257,9 @@
 Builder.defineMacro("__powerpc64__");
 Builder.defineMacro("__ppc64__");
 Builder.defineMacro("__PPC64__");
+  } else if (getTriple().isOSAIX()) {
+// The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.
+Builder.defineMacro("_ARCH_PPC64");
   }
   if (getTriple().isOSAIX()) {
 Builder.defineMacro("__THW_PPC__");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107647: Remove depracated built-ins for MMA and replace with new built-ins

2021-08-06 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir created this revision.
Herald added subscribers: kbarton, hiraditya, nemanjai, qcolombet, MatzeB.
saghir requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107647

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/test/CodeGen/builtins-ppc-pair-mma.c
  clang/test/Sema/ppc-pair-mma-types.c
  clang/test/SemaCXX/ppc-pair-mma-types.cpp
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/mma-acc-spill.ll
  llvm/test/CodeGen/PowerPC/mma-intrinsics.ll
  llvm/test/CodeGen/PowerPC/mma-outer-product.ll
  llvm/test/CodeGen/PowerPC/mma-phi-accs.ll
  llvm/test/CodeGen/PowerPC/paired-vector-intrinsics.ll
  llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc-bugfix.ll
  llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc.ll

Index: llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc.ll
@@ -254,17 +254,17 @@
   %i48 = bitcast <2 x double> %i44 to <16 x i8>
   %i49 = bitcast <2 x double> %i40 to <16 x i8>
   %i50 = bitcast <2 x double> %i38 to <16 x i8>
-  %i51 = tail call <512 x i1> @llvm.ppc.mma.assemble.acc(<16 x i8> zeroinitializer, <16 x i8> %i48, <16 x i8> %i49, <16 x i8> %i50)
+  %i51 = tail call <512 x i1> @llvm.ppc.mma.build.acc(<16 x i8> zeroinitializer, <16 x i8> %i48, <16 x i8> %i49, <16 x i8> %i50)
   %i52 = bitcast <2 x double> %i45 to <16 x i8>
   %i53 = bitcast <2 x double> %i41 to <16 x i8>
   %i54 = bitcast <2 x double> %i39 to <16 x i8>
-  %i55 = tail call <512 x i1> @llvm.ppc.mma.assemble.acc(<16 x i8> zeroinitializer, <16 x i8> %i52, <16 x i8> %i53, <16 x i8> %i54)
+  %i55 = tail call <512 x i1> @llvm.ppc.mma.build.acc(<16 x i8> zeroinitializer, <16 x i8> %i52, <16 x i8> %i53, <16 x i8> %i54)
   %i56 = bitcast <2 x double> %i46 to <16 x i8>
   %i57 = bitcast <2 x double> %i42 to <16 x i8>
-  %i58 = tail call <512 x i1> @llvm.ppc.mma.assemble.acc(<16 x i8> zeroinitializer, <16 x i8> %i56, <16 x i8> %i57, <16 x i8> %i56)
+  %i58 = tail call <512 x i1> @llvm.ppc.mma.build.acc(<16 x i8> zeroinitializer, <16 x i8> %i56, <16 x i8> %i57, <16 x i8> %i56)
   %i59 = bitcast <2 x double> %i47 to <16 x i8>
   %i60 = bitcast <2 x double> %i43 to <16 x i8>
-  %i61 = tail call <512 x i1> @llvm.ppc.mma.assemble.acc(<16 x i8> zeroinitializer, <16 x i8> %i59, <16 x i8> %i60, <16 x i8> %i59)
+  %i61 = tail call <512 x i1> @llvm.ppc.mma.build.acc(<16 x i8> zeroinitializer, <16 x i8> %i59, <16 x i8> %i60, <16 x i8> %i59)
   %i62 = tail call <512 x i1> @llvm.ppc.mma.xvf64gerpp(<512 x i1> %i51, <256 x i1> undef, <16 x i8> undef)
   %i63 = tail call <512 x i1> @llvm.ppc.mma.xvf64gerpp(<512 x i1> %i55, <256 x i1> undef, <16 x i8> undef)
   %i64 = tail call <512 x i1> @llvm.ppc.mma.xvf64gerpp(<512 x i1> %i58, <256 x i1> undef, <16 x i8> undef)
@@ -327,7 +327,7 @@
 }
 
 declare <2 x double> @llvm.fma.v2f64(<2 x double>, <2 x double>, <2 x double>)
-declare <512 x i1> @llvm.ppc.mma.assemble.acc(<16 x i8>, <16 x i8>, <16 x i8>, <16 x i8>)
+declare <512 x i1> @llvm.ppc.mma.build.acc(<16 x i8>, <16 x i8>, <16 x i8>, <16 x i8>)
 declare <512 x i1> @llvm.ppc.mma.xvf64gerpp(<512 x i1>, <256 x i1>, <16 x i8>)
 declare { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } @llvm.ppc.mma.disassemble.acc(<512 x i1>)
 
Index: llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc-bugfix.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc-bugfix.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-acc-regalloc-bugfix.ll
@@ -11,12 +11,12 @@
 ; CHECK-NEXT:xxlor vs3, v2, v2
 ; CHECK-NEXT:stxv vs1, 0(0)
 dmblvi_entry:
-  %0 = tail call <512 x i1> @llvm.ppc.mma.assemble.acc(<16 x i8> zeroinitializer, <16 x i8> undef, <16 x i8> undef, <16 x i8> zeroinitializer)
+  %0 = tail call <512 x i1> @llvm.ppc.mma.build.acc(<16 x i8> zeroinitializer, <16 x i8> undef, <16 x i8> undef, <16 x i8> zeroinitializer)
   %1 = tail call { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } @llvm.ppc.mma.disassemble.acc(<512 x i1> %0)
   %2 = extractvalue { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } %1, 2
   store <16 x i8> %2, <16 x i8>* null, align 1
   unreachable
 }
 
-declare <512 x i1> @llvm.ppc.mma.assemble.acc(<16 x i8>, <16 x i8>, <16 x i8>, <16 x i8>)
+declare <512 x i1> @llvm.ppc.mma.build.acc(<16 x i8>, <16 x i8>, <16 x i8>, <16 x i8>)
 declare { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } @llvm.ppc.mma.disassemble.acc(<512 x i1>)
Index: llvm/test/CodeGen/PowerPC/paired-vector-intrinsics.ll
===
--- llvm/test/CodeGen/PowerPC/paired-vector-intrinsics.ll
+++ llvm/test/CodeGen/PowerPC/paired-vector-intrinsics.ll
@@ -16,7 +16,7 @@
 ; when MMA is disabled.
 
 ; assemble_pair
-declare <256 x i1> @l

[PATCH] D107648: [OpenCL] Clang diagnostics allow reporting C++ for OpenCL version.

2021-08-06 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna created this revision.
Topotuna added a reviewer: Anastasia.
Herald added subscribers: ldrumm, yaxunl.
Herald added a reviewer: aaron.ballman.
Topotuna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Some Clang diagnostics could only report OpenCL C version. Because
C++ for OpenCL can be used as an alternative to OpenCL C, the text
for diagnostics should reflect that.

Output text modified for these diagnostics:
`warn_option_invalid_ocl_version`
`err_attribute_requires_opencl_version`
`warn_opencl_attr_deprecated_ignored`
`ext_opencl_ext_vector_type_rgba_selector`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107648

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/Frontend/opencl.cl
  clang/test/SemaOpenCL/ext_vectors.cl
  clang/test/SemaOpenCL/nosvm.cl

Index: clang/test/SemaOpenCL/nosvm.cl
===
--- clang/test/SemaOpenCL/nosvm.cl
+++ clang/test/SemaOpenCL/nosvm.cl
@@ -1,13 +1,14 @@
 // RUN: %clang_cc1 -verify %s
 // RUN: %clang_cc1 -verify -cl-std=CL2.0 -D CL20 %s
+// RUN: %clang_cc1 -verify -cl-std=clc++1.0 %s
 // RUN: %clang_cc1 -verify -x c -D NOCL %s
 
 #ifndef NOCL
 kernel void f(__attribute__((nosvm)) global int* a);
 #ifndef CL20
-// expected-error@-2 {{'nosvm' attribute requires OpenCL version 2.0}}
+// expected-error@-2 {{'nosvm' attribute requires OpenCL C version 2.0}}
 #else
-// expected-warning@-4 {{'nosvm' attribute is deprecated and ignored in OpenCL version 2.0}}
+// expected-warning@-4 {{'nosvm' attribute is deprecated and ignored in OpenCL C version 2.0}}
 #endif
 
 __attribute__((nosvm)) void g(); // expected-warning {{'nosvm' attribute only applies to variables}}
Index: clang/test/SemaOpenCL/ext_vectors.cl
===
--- clang/test/SemaOpenCL/ext_vectors.cl
+++ clang/test/SemaOpenCL/ext_vectors.cl
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++1.0
 
 typedef float float4 __attribute__((ext_vector_type(4)));
 
Index: clang/test/Frontend/opencl.cl
===
--- clang/test/Frontend/opencl.cl
+++ clang/test/Frontend/opencl.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -DSYNTAX
-// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=clc++ -DSYNTAX
+// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=clc++1.0 -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks -DBLOCKS -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -fblocks -DBLOCKS -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -fblocks -DBLOCKS -DSYNTAX
@@ -10,6 +10,7 @@
 // RUN: %clang_cc1 -cl-std=CL1.1 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION11 %s
 // RUN: %clang_cc1 -cl-std=CL1.2 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION12 %s
 // RUN: %clang_cc1 -cl-std=CL2.0 -cl-strict-aliasing %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION20 %s
+// RUN: %clang_cc1 -cl-std=clc++1.0 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCLCPP-VERSION10 %s
 
 #ifdef SYNTAX
 class test{
@@ -30,6 +31,7 @@
   // expected-error@-6{{blocks support disabled - compile with -fblocks or pick a deployment target that supports them}}
 #endif
 
-// CHECK-INVALID-OPENCL-VERSION11: warning: OpenCL version 1.1 does not support the option '-cl-strict-aliasing'
-// CHECK-INVALID-OPENCL-VERSION12: warning: OpenCL version 1.2 does not support the option '-cl-strict-aliasing'
-// CHECK-INVALID-OPENCL-VERSION20: warning: OpenCL version 2.0 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCL-VERSION11: warning: OpenCL C version 1.1 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCL-VERSION12: warning: OpenCL C version 1.2 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCL-VERSION20: warning: OpenCL C version 2.0 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCLCPP-VERSION10: warning: C++ for OpenCL version 1.0 does not support the option '-cl-strict-aliasing'
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMemb

[PATCH] D107648: [OpenCL] Clang diagnostics allow reporting C++ for OpenCL version.

2021-08-06 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna updated this revision to Diff 364796.
Topotuna added a comment.

Diagnostic argument index updated (from `%1` to `%2`)


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

https://reviews.llvm.org/D107648

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/Frontend/opencl.cl
  clang/test/SemaOpenCL/ext_vectors.cl
  clang/test/SemaOpenCL/nosvm.cl

Index: clang/test/SemaOpenCL/nosvm.cl
===
--- clang/test/SemaOpenCL/nosvm.cl
+++ clang/test/SemaOpenCL/nosvm.cl
@@ -1,13 +1,14 @@
 // RUN: %clang_cc1 -verify %s
 // RUN: %clang_cc1 -verify -cl-std=CL2.0 -D CL20 %s
+// RUN: %clang_cc1 -verify -cl-std=clc++1.0 %s
 // RUN: %clang_cc1 -verify -x c -D NOCL %s
 
 #ifndef NOCL
 kernel void f(__attribute__((nosvm)) global int* a);
 #ifndef CL20
-// expected-error@-2 {{'nosvm' attribute requires OpenCL version 2.0}}
+// expected-error@-2 {{'nosvm' attribute requires OpenCL C version 2.0}}
 #else
-// expected-warning@-4 {{'nosvm' attribute is deprecated and ignored in OpenCL version 2.0}}
+// expected-warning@-4 {{'nosvm' attribute is deprecated and ignored in OpenCL C version 2.0}}
 #endif
 
 __attribute__((nosvm)) void g(); // expected-warning {{'nosvm' attribute only applies to variables}}
Index: clang/test/SemaOpenCL/ext_vectors.cl
===
--- clang/test/SemaOpenCL/ext_vectors.cl
+++ clang/test/SemaOpenCL/ext_vectors.cl
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++1.0
 
 typedef float float4 __attribute__((ext_vector_type(4)));
 
Index: clang/test/Frontend/opencl.cl
===
--- clang/test/Frontend/opencl.cl
+++ clang/test/Frontend/opencl.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -DSYNTAX
-// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=clc++ -DSYNTAX
+// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=clc++1.0 -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks -DBLOCKS -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -fblocks -DBLOCKS -DSYNTAX
 // RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -fblocks -DBLOCKS -DSYNTAX
@@ -10,6 +10,7 @@
 // RUN: %clang_cc1 -cl-std=CL1.1 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION11 %s
 // RUN: %clang_cc1 -cl-std=CL1.2 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION12 %s
 // RUN: %clang_cc1 -cl-std=CL2.0 -cl-strict-aliasing %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION20 %s
+// RUN: %clang_cc1 -cl-std=clc++1.0 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCLCPP-VERSION10 %s
 
 #ifdef SYNTAX
 class test{
@@ -30,6 +31,7 @@
   // expected-error@-6{{blocks support disabled - compile with -fblocks or pick a deployment target that supports them}}
 #endif
 
-// CHECK-INVALID-OPENCL-VERSION11: warning: OpenCL version 1.1 does not support the option '-cl-strict-aliasing'
-// CHECK-INVALID-OPENCL-VERSION12: warning: OpenCL version 1.2 does not support the option '-cl-strict-aliasing'
-// CHECK-INVALID-OPENCL-VERSION20: warning: OpenCL version 2.0 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCL-VERSION11: warning: OpenCL C version 1.1 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCL-VERSION12: warning: OpenCL C version 1.2 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCL-VERSION20: warning: OpenCL C version 2.0 does not support the option '-cl-strict-aliasing'
+// CHECK-INVALID-OPENCLCPP-VERSION10: warning: C++ for OpenCL version 1.0 does not support the option '-cl-strict-aliasing'
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -343,7 +343,7 @@
   if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion < 300) {
 const char *DiagBegin = HasRGBA ? CompName->getNameStart() : compStr;
 S.Diag(OpLoc, diag::ext_opencl_ext_vector_type_rgba_selector)
-<< StringRef(DiagBegin, 1) << SourceRange(CompLoc);
+<< StringRef(DiagBegin, 1) << SourceRange(CompLoc) << 0 << "3.0";
   }
 }
   } else {
Index: clang/lib/Sema/SemaDeclAttr.cpp
===

[PATCH] D107649: [OpenMP]Fix PR51349: Remove AlwaysInline for if regions.

2021-08-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, mikerice.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

After D94315  we add the `NoInline` attribute 
to the outlined function to handle
data environments in the OpenMP if clause. This conflicted with the 
`AlwaysInline`
attribute added to the outlined function. for better performance in D106799 
.
The data environments should ideally not require NoInline, but for now this
fixes PR51349.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107649

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp


Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2120,11 +2120,12 @@
 OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end());
 
 // Ensure we do not inline the function. This is trivially true for the 
ones
-// passed to __kmpc_fork_call but the ones calles in serialized regions
+// passed to __kmpc_fork_call but the ones called in serialized regions
 // could be inlined. This is not a perfect but it is closer to the 
invariant
 // we want, namely, every data environment starts with a new function.
 // TODO: We should pass the if condition to the runtime function and do the
 //   handling there. Much cleaner code.
+OutlinedFn->removeFnAttr(llvm::Attribute::AlwaysInline);
 OutlinedFn->addFnAttr(llvm::Attribute::NoInline);
 RT.emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs);
 


Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2120,11 +2120,12 @@
 OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end());
 
 // Ensure we do not inline the function. This is trivially true for the ones
-// passed to __kmpc_fork_call but the ones calles in serialized regions
+// passed to __kmpc_fork_call but the ones called in serialized regions
 // could be inlined. This is not a perfect but it is closer to the invariant
 // we want, namely, every data environment starts with a new function.
 // TODO: We should pass the if condition to the runtime function and do the
 //   handling there. Much cleaner code.
+OutlinedFn->removeFnAttr(llvm::Attribute::AlwaysInline);
 OutlinedFn->addFnAttr(llvm::Attribute::NoInline);
 RT.emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-08-06 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Let's see if we can cache the stream symbols across top-level analyses.




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:476
+
+  for (Decl *D : LookupRes) {
+D = D->getCanonicalDecl();





Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:480
+  continue;
+if (auto *VD = dyn_cast(D)) {
+  if (FILEType && !ACtx.hasSameType(*FILEType, VD->getType()))





Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:521
+
+  // These can be nullptr if not found.
+  StdinSym = getStdStreamSym(StdinDecl, C);

This should be probably at the definition of `StdinSym` and `getStdStreamSym()`.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:227-236
+  for (Decl *D : LookupRes) {
+D = D->getCanonicalDecl();
+if (!C.getSourceManager().isInSystemHeader(D->getLocation()))
+  continue;
+if (auto *VD = dyn_cast(D)) {
+  if (FILEType && !ACtx.hasSameType(*FILEType, VD->getType()))
+continue;

balazske wrote:
> steakhal wrote:
> > It will early return and uses one fewer `continue`.
> The intent was that if no `FILEType` is found we find just the first 
> `VarDecl` and do not check the type. This recommended change returns always 
> null if no `FILEType` is found.
Hm, it was not immediately clear to me.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:504
+
+  OrigStdin = findStdStream("stdin", C);
+  OrigStdout = findStdStream("stdout", C);

balazske wrote:
> steakhal wrote:
> > martong wrote:
> > > We should be careful, to cache the results (either here, or deeper in the 
> > > call stack).
> > > I mean, we certainly don't want to do a lookup of "stdin" every time a 
> > > function is evaluated. We should do this lazily, only once.
> > I agree. We should do this only for the first top-level function, instead 
> > of doing this for every top-level function.
> I am not sure if the `SymbolRef` values are safe to store between top-level 
> function analyses. The `FILE` type and std stream declarations are safe to 
> cache, but the SymbolRef values of these variables probably not.
I think it should be safe. But place there an assert and run the test suite. If 
it won't trigger, that means that we have high confidentiality that this is 
safe. I know it's not 100%, but pretty close.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D107636: [analyzer][solver] Compute adjustment for unsupported symbols as well

2021-08-06 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Seems reasonable to me. Let's wait for someone else as well.
This is a really elegant patch, I should tell!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107636

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


[PATCH] D107636: [analyzer][solver] Compute adjustment for unsupported symbols as well

2021-08-06 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D107636#2931302 , @steakhal wrote:

> Seems reasonable to me. Let's wait for someone else as well.

Sure, NP.

> This is a really elegant patch, I should tell!

Thanks!  I guess my take on this, that this path to the solver just got 
forgotten and that's what produced this inconsistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107636

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


[PATCH] D107611: [ARC] Add codegen for llvm.ctlz intrinsic for the ARC backend

2021-08-06 Thread Thomas Johnson via Phabricator via cfe-commits
thomasjohns updated this revision to Diff 364806.
thomasjohns added a comment.

llvm clang-tidy rule: prefer `Register` over `unsinged int`.


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

https://reviews.llvm.org/D107611

Files:
  clang/lib/Basic/Targets/ARC.h
  llvm/lib/Target/ARC/ARCExpandPseudos.cpp
  llvm/lib/Target/ARC/ARCISelLowering.cpp
  llvm/lib/Target/ARC/ARCInstrInfo.td
  llvm/test/CodeGen/ARC/ctlz.ll

Index: llvm/test/CodeGen/ARC/ctlz.ll
===
--- /dev/null
+++ llvm/test/CodeGen/ARC/ctlz.ll
@@ -0,0 +1,14 @@
+; RUN: llc -march=arc < %s | FileCheck %s
+
+target triple = "arc"
+
+declare i32 @llvm.ctlz.i32(i32, i1)
+
+; CHECK-LABEL: clz32:
+; CHECK: fls.f   %r0, %r0
+; CHECK: mov.eq  [[R:%r[01]]], 32
+; CHECK: rsub.ne [[R]], [[R]], 31
+define i32 @clz32(i32 %x) {
+  %a = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
+  ret i32 %a
+}
Index: llvm/lib/Target/ARC/ARCInstrInfo.td
===
--- llvm/lib/Target/ARC/ARCInstrInfo.td
+++ llvm/lib/Target/ARC/ARCInstrInfo.td
@@ -133,6 +133,14 @@
  "STB_FAR $dst, $addr",
  [(truncstorei8 GPR32:$dst, AddrModeFar:$addr)]>;
 
+// TODO: Add `Requires<[HasBitScan]>` predicate when available.
+def CTLZ : PseudoInstARC<(outs GPR32:$A),
+ (ins GPR32:$B),
+ "error.fls $A, $B",
+ [(set GPR32:$A, (ctlz i32:$B))]> {
+  let Defs = [STATUS32];
+}
+
 //===--===//
 // Instruction Generation multiclasses.
 // Generate many variants of a single instruction with a single defining
Index: llvm/lib/Target/ARC/ARCISelLowering.cpp
===
--- llvm/lib/Target/ARC/ARCISelLowering.cpp
+++ llvm/lib/Target/ARC/ARCISelLowering.cpp
@@ -135,6 +135,10 @@
 
   // Sign extend inreg
   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Custom);
+
+  // TODO: Predicate with `options.hasBitScan() ? Legal : Expand` when
+  //   the HasBitScan predicate is available.
+  setOperationAction(ISD::CTLZ, MVT::i32, Legal);
 }
 
 const char *ARCTargetLowering::getTargetNodeName(unsigned Opcode) const {
Index: llvm/lib/Target/ARC/ARCExpandPseudos.cpp
===
--- llvm/lib/Target/ARC/ARCExpandPseudos.cpp
+++ llvm/lib/Target/ARC/ARCExpandPseudos.cpp
@@ -13,6 +13,7 @@
 #include "ARCInstrInfo.h"
 #include "ARCRegisterInfo.h"
 #include "ARCSubtarget.h"
+#include "MCTargetDesc/ARCInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -35,6 +36,7 @@
 
 private:
   void ExpandStore(MachineFunction &, MachineBasicBlock::iterator);
+  void ExpandCTLZ(MachineFunction &, MachineBasicBlock::iterator);
 
   const ARCInstrInfo *TII;
 };
@@ -59,8 +61,8 @@
 void ARCExpandPseudos::ExpandStore(MachineFunction &MF,
MachineBasicBlock::iterator SII) {
   MachineInstr &SI = *SII;
-  unsigned AddrReg = MF.getRegInfo().createVirtualRegister(&ARC::GPR32RegClass);
-  unsigned AddOpc =
+  Register AddrReg = MF.getRegInfo().createVirtualRegister(&ARC::GPR32RegClass);
+  Register AddOpc =
   isUInt<6>(SI.getOperand(2).getImm()) ? ARC::ADD_rru6 : ARC::ADD_rrlimm;
   BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(AddOpc), AddrReg)
   .addReg(SI.getOperand(1).getReg())
@@ -73,10 +75,45 @@
   SI.eraseFromParent();
 }
 
+void ARCExpandPseudos::ExpandCTLZ(MachineFunction &MF,
+  MachineBasicBlock::iterator SII) {
+  // Expand:
+  //	%R2 = CTLZ %R0, %STATUS
+  // To:
+  //	%R2 = FLS_f_rr %R0, %STATUS
+  //	%R2 = MOV_cc_ru6 %R2, 32, pred:1, %STATUS
+  //	%R2 = RSUB_cc_rru6 %R2, 31, pred:2, %STATUS
+  MachineInstr &SI = *SII;
+  const MachineOperand &Dest = SI.getOperand(0);
+  assert(Dest.isReg());
+  const MachineOperand &Src = SI.getOperand(1);
+  assert(Src.isReg());
+  Register DestReg = Dest.getReg();
+
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::FLS_f_rr),
+  DestReg)
+  .add(Src)
+  .addReg(ARC::STATUS32, RegState::ImplicitDefine);
+
+  Register Ra = MF.getRegInfo().createVirtualRegister(&ARC::GPR32RegClass);
+  Register Rb = MF.getRegInfo().createVirtualRegister(&ARC::GPR32RegClass);
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::MOV_cc_ru6), Ra)
+  .addImm(32)
+  .addImm(ARCCC::EQ)
+  .addReg(DestReg);
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::RSUB_cc_rru6),
+  Rb)
+  .addImm(31)
+  .addImm(ARCCC::NE)
+  .addReg(Ra);
+
+  SI.eraseFromParent();
+}
+
 bool ARCExpandPseudos::runOnMachineFunction(MachineFunction &MF) {
   const ARCSubtarget *STI = &MF.getSubtarget();
   TII = STI->getInstrInfo();
-  bool ExpandedStore = 

[PATCH] D107539: [OpenCL] opencl-c.h: add __opencl_c_images and __opencl_c_read_write_images

2021-08-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a subscriber: svenvh.
Anastasia added a comment.

LGTM! Thanks.

CC to @azabaznov for any final feedback.

FYI this has not been officially announced but in `clang-14` we would like to 
transition away from using the huge hard to maintain `opencl-c.h` in favour of 
a more concise and fast to parse Tablegen based approach to declare builtin 
functions: https://clang.llvm.org/docs/OpenCLSupport.html#opencl-builtins. As a 
matter of fact to mature Tablegen-based solution it has been enabled by default 
in `clang-13` without any extra flags 
https://clang.llvm.org/docs/UsersManual.html#opencl-header. And it is therefore 
now a primary header exposed to the application developer in upstream clang.

Since there has not been an announcement yet we don't make it a hard 
requirement yet but it is highly encouraged to mirror any new functionality 
into `OpenCLBuiltins.td`. Conditioning functions as in this patch is usually 
quite straightforward, it just needs an extra clause around builtin 
declarations:

  let Extension =  in {
   ...
  }

And new features/extensions can be registered with:

  def  : FunctionExtension<"macro_name1 macro_name2 ...">;

Here is one example that illustrates the idea https://reviews.llvm.org/D106434

Tablegen-header has full functionality of OpenCL 2.0 so it should be possible 
to extend it to OpenCL 3.0 without significant effort.

Both me and @svenvh would be happy to provide more information and review 
should you decide to help mantaining Tablegen-header in sync with new changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107539

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-08-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:504
+
+  OrigStdin = findStdStream("stdin", C);
+  OrigStdout = findStdStream("stdout", C);

steakhal wrote:
> balazske wrote:
> > steakhal wrote:
> > > martong wrote:
> > > > We should be careful, to cache the results (either here, or deeper in 
> > > > the call stack).
> > > > I mean, we certainly don't want to do a lookup of "stdin" every time a 
> > > > function is evaluated. We should do this lazily, only once.
> > > I agree. We should do this only for the first top-level function, instead 
> > > of doing this for every top-level function.
> > I am not sure if the `SymbolRef` values are safe to store between top-level 
> > function analyses. The `FILE` type and std stream declarations are safe to 
> > cache, but the SymbolRef values of these variables probably not.
> I think it should be safe. But place there an assert and run the test suite. 
> If it won't trigger, that means that we have high confidentiality that this 
> is safe. I know it's not 100%, but pretty close.
I tried to check if these `SymbolRef`'s are the same at `checkBeginFunction` 
after initialized once. The assertion for equality failed sometimes, or other 
crash happened when `dump` was called on the value. So it looks not safe to 
cache these. And should we add assumptions about that these `StdinSym`, 
`StdoutSym`, `StderrSym` are not equal to each other?



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:555
+C.getSValBuilder().makeSymbolVal(StdStream),
+C.getASTContext().getLogicalOperationType());
+Optional NotEqDef =

steakhal wrote:
> `SValBuilder::getConditionType()`, oh they are the same under the hood. We 
> should still probably prefer this one instead.
> It might worth hoisting `C.getSValBuilder()` to a local variable though.
> The symbol for `StdStream` also deserves a separate variable IMO.
This lambda is possible to improve.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-08-06 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:504
+
+  OrigStdin = findStdStream("stdin", C);
+  OrigStdout = findStdStream("stdout", C);

balazske wrote:
> steakhal wrote:
> > balazske wrote:
> > > steakhal wrote:
> > > > martong wrote:
> > > > > We should be careful, to cache the results (either here, or deeper in 
> > > > > the call stack).
> > > > > I mean, we certainly don't want to do a lookup of "stdin" every time 
> > > > > a function is evaluated. We should do this lazily, only once.
> > > > I agree. We should do this only for the first top-level function, 
> > > > instead of doing this for every top-level function.
> > > I am not sure if the `SymbolRef` values are safe to store between 
> > > top-level function analyses. The `FILE` type and std stream declarations 
> > > are safe to cache, but the SymbolRef values of these variables probably 
> > > not.
> > I think it should be safe. But place there an assert and run the test 
> > suite. If it won't trigger, that means that we have high confidentiality 
> > that this is safe. I know it's not 100%, but pretty close.
> I tried to check if these `SymbolRef`'s are the same at `checkBeginFunction` 
> after initialized once. The assertion for equality failed sometimes, or other 
> crash happened when `dump` was called on the value. So it looks not safe to 
> cache these. And should we add assumptions about that these `StdinSym`, 
> `StdoutSym`, `StderrSym` are not equal to each other?
Good to know. I don't think it's necessary to add assertions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D105426: [clangd] IWYU as a library: Find all references to symbols in the file

2021-08-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks, this scope looks good for a first patch!




Comment at: clang-tools-extra/clangd/IWYU.cpp:18
+
+/// Main "driver" of the IWYU symbol usage discovery mechanism. Crawler
+/// traverses the AST and feeds in the locations of (sometimes implicitly) used

The first sentence doesn't mean much to me, I think we could just drop it?



Comment at: clang-tools-extra/clangd/IWYU.cpp:63
+  // This is helpful in getFoo().bar(), where Foo must be complete.
+  // FIXME(kirillbobyrev): This is a tricky case that raises a question - 
should
+  // we consider implicit types to be "used"? With auto's it's not so clear.

Is this just "FIXME: should this behavior be configurable or tweaked?"

I think it's clear enough what "this behavior" is in context.
Whereas the rest of the comment adds some confusion (e.g. what's an "implicit 
type", what usage of auto are you talking about etc. And I think it's *way* too 
soon to say that it *should* be configurable - remember the application is 
unused-include, turning this off only grants the ability for headers to be 
marked unused even if they define the type of a subexpression.

I think it's more likely we'd tweak the heuristic in the future, e.g. only do 
this if it's a type that can be incomplete.



Comment at: clang-tools-extra/clangd/IWYU.cpp:73
+if (shouldAdd(T.getTypePtrOrNull())) { // don't care about quals
+  RecursiveASTVisitor::TraverseType(T);
+}

i usually add a private `using Base = ...` and refer to `Base::TraverseType(T)` 
- intent is clearer and often we end up with several of these



Comment at: clang-tools-extra/clangd/IWYU.cpp:95
+
+  bool shouldAdd(const void *P) { return P && Visited.insert(P).second; }
+

this name is a bit vague (why wouldn't we add it?), maybe isNew?



Comment at: clang-tools-extra/clangd/IWYU.h:10
+/// \file
+/// This defines functionality modeled after Include-What-You-Use
+/// (https://include-what-you-use.org/). The variant we implement is not

Related to the naming discussion, this should first say what the functionality 
is (warnings about header hygiene: misuse of transitive headers and unused 
includes).
Then definitely credit the IWYU tool and mention the differences.



Comment at: clang-tools-extra/clangd/IWYU.h:17
+/// FIXME(kirillbobyrev): Add support for IWYU pragmas.
+/// FIXME(kirillbobyrev): Add support for mapping files.
+/// FIXME(kirillbobyrev): Add support for standard library headers.

I'm not sure we want to do this (or plan to do this) unless we have some idea 
of how discovery would work.



Comment at: clang-tools-extra/clangd/IWYU.h:34
+using ReferencedLocations = llvm::DenseSet;
+/// Goes through main file AST and computes all the locations used symbols are
+/// coming from. These locations are later used to determine which headers

Maybe just "Finds locations of all symbols used in the main file"?

If you want to talk about traversal/impl strategy, that's OK but not in the 
first paragraph.



Comment at: clang-tools-extra/clangd/IWYU.h:35
+/// Goes through main file AST and computes all the locations used symbols are
+/// coming from. These locations are later used to determine which headers
+/// should be marked as "used" and "directly used".

I'd be explicit that the returned locations may be macro expansions, and are 
not resolved to their spelling/expansion location.



Comment at: clang-tools-extra/clangd/IWYU.h:38
+///
+/// Because of the clangd limitations, this should be efficient,
+/// hence there is only one AST traversal for the whole process.

I'm not quite sure what this is saying/who the audience for the comment is.
Maybe it's interesting to say something like

We use this to compute unused headers, so:
 - we cover the whole file in a single traversal for efficiency
 - we don't attempt to describe where symbols were referenced from
 - in ambiguous cases (e.g. implicitly used symbols, multiple declarations) we 
err on the side of reporting all possible locations



Comment at: clang-tools-extra/clangd/IWYU.h:41
+///
+/// NOTE: The balance is currently shifted towards considering some of the
+/// implicitly used symbols as "used" for the sake of providing less noisy

It's a bit more general than this (e.g. multiple declaration). See previous 
comment for a wording suggestion



Comment at: clang-tools-extra/clangd/IWYU.h:43
+/// implicitly used symbols as "used" for the sake of providing less noisy
+/// "unused header" diagnostics. However, this should be re-evalated once we
+/// also want to surface "missing header" diagnostics.

I actually don't think we'd use the same entrypoint for missing include, but 

[PATCH] D107611: [ARC] Add codegen for llvm.ctlz intrinsic for the ARC backend

2021-08-06 Thread Mark Schimmel via Phabricator via cfe-commits
marksl added inline comments.



Comment at: llvm/lib/Target/ARC/ARCExpandPseudos.cpp:86
+  //   %R2 = RSUB_cc_rru6 %R2, 31, pred:2, %STATUS
+  MachineInstr &SI = *SII;
+  const MachineOperand &Dest = SI.getOperand(0);

I know you're following ExpandStore above in using "SI" here, but let's switch 
to "MI" as that is the most common practice. I think he used "SI" because it 
was a store instruction. All your readers will recognize MI as a MachineInstr, 
but they will have no such association to SI.



Comment at: llvm/lib/Target/ARC/ARCExpandPseudos.cpp:93
+
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::FLS_f_rr),
+  DestReg)

This is not right. The final instruction of the sequence must write to DestReg.


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

https://reviews.llvm.org/D107611

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


[PATCH] D107553: [C++4OpenCL] Initialize temporaries in the private address space

2021-08-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Sema/Initialization.h:341
+QualType Type = TypeInfo->getType();
+if (Context.getLangOpts().OpenCL && !Type.hasAddressSpace())
+  Type = Context.getAddrSpaceQualType(Type, LangAS::opencl_private);

I wonder if we should instead change the check:

`!Type.hasAddressSpace()`

into an assert?

I also wonder if it makes sense to assert that if it has an address space it 
should be private?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107553

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


  1   2   >