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

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

Rename.


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/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -0,0 +1,136 @@
+//===--- IncludeCleanerTests.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 "IncludeCleaner.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  // DeclRefExpr
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  // RecordDecl
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  // TypedefType and UsingDecls
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "namespace ns { struct ^X; struct ^X {}; }",
+  "using ns::X;",
+  },
+  {
+  "namespace ns { struct X; struct X {}; }",
+  "using namespace ns;",
+  },
+  {
+  "struct ^A {}; using B = A; using ^C = B;",
+  "C a;",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  "struct Foo; struct ^Foo{}; typedef Foo ^Bar;",
+  "Bar b;",
+  },
+  // MemberExpr
+  {
+  "struct ^X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  // Expr (type is traversed)
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  // Redecls
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  // Constructor
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  // Static function
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  // TemplateRecordDecl
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  // Type name not spelled out in code
+  {
+  "class ^X{}; X ^getX();",
+  "auto x = getX();",
+  },
+  // Enums
+  {
+  "enum ^Color { ^Red = 42, Green = 9000};",
+  "int MyColor = Red;",
+  },
+  {
+  "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
+  "int Lang = X::CXX;",
+  },
+  {
+  // When a type is resolved via a using declaration, the
+  // UsingShadowDecl is not referenced in the AST.
+  // Compare to TypedefType, or DeclRefExpr::getFoundDecl().
+  // ^
+  "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
@@ -58,6 +58,7 @@
   HeadersTests.cpp
   HeaderSourceSwitchTests.cpp
   HoverTests.cpp
+  IncludeCleanerTests.cpp
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -0,0 +1,58 @@
+//===---

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-10 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 365370.
kuhnel added a comment.

tried to fix Windows build failure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,60 @@
+//===-- StdLibIndexTests.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 "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  auto UmbrellaHeader = SLI.generateIncludeHeader();
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = SLI.indexHeaders(HeaderMock);
+  EXPECT_THAT_EXPECTED(Index, llvm::Succeeded());
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+
+  EXPECT_THAT(match(**Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),
+   llvm::StringRef("otherfunc")));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // 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
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,70 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library. Right now hardcoded to one verison.
+// FIXME: add feature to detect this version somehow (magically).
+enum StandardLibraryVersion { cxx14 = 0 };
+
+// external interface for getting a standard library index.
+Expected>
+indexStandardLibrary(const ThreadsafeFS &TFS,
+ 

[PATCH] D100810: Use `GNUInstallDirs` to support custom installation dirs. -- LLVM

2021-08-10 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added inline comments.



Comment at: llvm/CMakeLists.txt:589
 CACHE STRING "Doxygen-generated HTML documentation install directory")
-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html"
+set(LLVM_INSTALL_OCAMLDOC_HTML_DIR 
"${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html"
 CACHE STRING "OCamldoc-generated HTML documentation install directory")

Ericson2314 wrote:
> compnerd wrote:
> > Why the change from `llvm` -> `${project}`?  (not that it really makes a 
> > difference)
> To be honest, I forgot. I might have just been OCD deduping on the fly. Happy 
> to change back,
Which would you like me to do, @compnerd?



Comment at: llvm/tools/llvm-config/llvm-config.cpp:361
+{
+  SmallString<256> Path(StringRef(LLVM_INSTALL_INCLUDEDIR));
+  sys::fs::make_absolute(ActivePrefix, Path);

Ericson2314 wrote:
> compnerd wrote:
> > Why the temporary `StringRef`?  Can you not just initialize `Path` with the 
> > literal?
> I'm not sure. I would think so too, but the old code was also using 
> `StringRef` so I just followed cargo culted and went with it.
Should I, say, submit a separate patch trying to remove the existing one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100810

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


[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-08-10 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 365381.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,46 @@
 
 namespace {
 
+std::string ModuleMapFilePathForModule(ModuleMap &Map, Module *GivenModule) {
+  if (!GivenModule->PresumedModuleMapFile.empty()) {
+return GivenModule->PresumedModuleMapFile;
+  }
+  auto *ModuleMapFile = Map.getModuleMapFileForUniquing(GivenModule);
+  if (!ModuleMapFile) {
+return std::string();
+  }
+  return std::string(ModuleMapFile->getName());
+}
+
+std::set GetAllModulemaps(ModuleMap &Map, Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  std::set ModulesToProcess{RootModule};
+  while (!ModulesToProcess.empty()) {
+auto CurrentModule = ModulesToProcess.begin();
+ProcessedModules.insert(*CurrentModule);
+
+const std::string CurrentModuleMapFile =
+ModuleMapFilePathForModule(Map, *CurrentModule);
+if (CurrentModuleMapFile.empty()) {
+  ModulesToProcess.erase(CurrentModule);
+  continue;
+}
+
+ModuleMaps.insert(CurrentModuleMapFile);
+
+for (auto *ImportedModule : (*CurrentModule)->Imports) {
+  if (!ImportedModule ||
+  ProcessedModules.find(ImportedModule) != ProcessedModules.end()) {
+continue;
+  }
+  ModulesToProcess.insert(ImportedModule);
+}
+ModulesToProcess.erase(CurrentModule);
+  }
+  return ModuleMaps;
+}
+
 class ASTTypeWriter {
   ASTWriter &Writer;
   ASTWriter::RecordData Record;
@@ -1396,9 +1436,15 @@
 Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
   }
 
+  std::set AffectingModulemaps;
+  if (WritingModule) {
+AffectingModulemaps = GetAllModulemaps(
+PP.getHeaderSearchInfo().getModuleMap(), WritingModule);
+  }
+
   WriteInputFiles(Context.SourceMgr,
   PP.getHeaderSearchInfo().getHeaderSearchOpts(),
-  PP.getLangOpts().Modules);
+  AffectingModulemaps);
   Stream.ExitBlock();
 }
 
@@ -1418,7 +1464,7 @@
 
 void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
 HeaderSearchOptions &HSOpts,
-bool Modules) {
+std::set &AffectingModuleMaps) {
   using namespace llvm;
 
   Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
@@ -1458,6 +1504,15 @@
 if (!Cache->OrigEntry)
   continue;
 
+if (isModuleMap(File.getFileCharacteristic()) &&
+!isSystem(File.getFileCharacteristic()) &&
+!AffectingModuleMaps.empty() &&
+AffectingModuleMaps.find(std::string(Cache->OrigEntry->getName())) ==
+AffectingModuleMaps.end()) {
+  // Do not emit modulemaps that do not affect current module.
+  continue;
+}
+
 InputFileEntry Entry;
 Entry.File = Cache->OrigEntry;
 Entry.IsSystemFile = isSystem(File.getFileCharacteristic());
@@ -1971,11 +2026,15 @@
 Record.push_back(SLoc->getOffset() - 2);
 if (SLoc->isFile()) {
   const SrcMgr::FileInfo &File = SLoc->getFile();
+  const SrcMgr::ContentCache *Content = &File.getContentCache();
+  if (Content->OrigEntry && InputFileIDs[Content->OrigEntry] == 0) {
+// Do not emit files that were not listed as inputs.
+continue;
+  }
   AddSourceLocation(File.getIncludeLoc(), Record);
   Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
   Record.push_back(File.hasLineDirectives());
 
-  const SrcMgr::ContentCache *Content = &File.getContentCache();
   bool EmitBlob = false;
   if (Content->OrigEntry) {
 assert(Content->OrigEntry == Content->ContentsEntry &&
Index: clang/include/clang/Serialization/ASTWriter.h
===
--- clang/include/clang/Serialization/ASTWriter.h
+++ clang/include/clang/Serialization/ASTWriter.h
@@ -475,7 +475,7 @@
   createSignature(StringRef AllBytes, StringRef ASTBlockBytes);
 
   void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
-   bool Modules);
+   std::set &AffectingModuleMaps);
   void WriteSourceManagerBlock(SourceManager &SourceMgr,
const Preprocessor &PP);
   void WritePreprocessor(const Preprocessor &PP, bool IsModule);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106137: [flang][driver] Add support for Frontend Plugins

2021-08-10 Thread Stuart Ellis via Phabricator via cfe-commits
stuartellis updated this revision to Diff 365411.
stuartellis marked an inline comment as done.
stuartellis added a comment.

Address review comments
Small changes due to rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106137

Files:
  clang/include/clang/Driver/Options.td
  flang/CMakeLists.txt
  flang/examples/CMakeLists.txt
  flang/examples/HelloWorld/CMakeLists.txt
  flang/examples/HelloWorld/HelloWorldPlugin.cpp
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/Frontend/FrontendPluginRegistry.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendAction.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/driver-help.f90
  flang/test/Driver/plugin-example.f90
  flang/test/lit.cfg.py
  flang/test/lit.site.cfg.py.in
  flang/tools/flang-driver/CMakeLists.txt

Index: flang/tools/flang-driver/CMakeLists.txt
===
--- flang/tools/flang-driver/CMakeLists.txt
+++ flang/tools/flang-driver/CMakeLists.txt
@@ -27,4 +27,11 @@
   clangBasic
 )
 
+option(FLANG_PLUGIN_SUPPORT "Build Flang with plugin support." ON)
+
+# Enable support for plugins, which need access to symbols from flang-new
+if(FLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(flang-new)
+endif()
+
 install(TARGETS flang-new DESTINATION bin)
Index: flang/test/lit.site.cfg.py.in
===
--- flang/test/lit.site.cfg.py.in
+++ flang/test/lit.site.cfg.py.in
@@ -3,6 +3,8 @@
 import sys
 
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
+config.llvm_shlib_dir = path(r"@SHLIBDIR@")
+config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
 config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
 config.flang_obj_root = "@FLANG_BINARY_DIR@"
 config.flang_src_dir = "@FLANG_SOURCE_DIR@"
@@ -10,8 +12,10 @@
 config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@"
 config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin"
 config.flang_lib_dir = "@CMAKE_BINARY_DIR@/lib"
+config.flang_examples = @FLANG_BUILD_EXAMPLES@
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.flang_standalone_build = @FLANG_STANDALONE_BUILD@
+config.has_plugins = @LLVM_ENABLE_PLUGINS@
 config.cc = "@CMAKE_C_COMPILER@"
 
 # Support substitution of the tools_dir with user parameters. This is
@@ -19,6 +23,7 @@
 try:
 config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
 config.flang_tools_dir = config.flang_tools_dir % lit_config.params
+config.llvm_shlib_dir = config.llvm_shlib_dir % lit_config.params
 except KeyError:
 e = sys.exc_info()[1]
 key, = e.args
Index: flang/test/lit.cfg.py
===
--- flang/test/lit.cfg.py
+++ flang/test/lit.cfg.py
@@ -30,6 +30,8 @@
'.CUF', '.f18', '.F18', '.fir', '.f03', '.F03', '.f08', '.F08']
 
 config.substitutions.append(('%PATH%', config.environment['PATH']))
+config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
+config.substitutions.append(('%pluginext', config.llvm_plugin_ext))
 
 llvm_config.use_default_substitutions()
 
@@ -42,6 +44,14 @@
 # config.
 config.available_features.add('new-flang-driver')
 
+# If the flang examples are built, add examples to the config
+if config.flang_examples:
+config.available_features.add('examples')
+
+# Plugins (loadable modules)
+if config.has_plugins:
+config.available_features.add('plugins')
+
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
 
Index: flang/test/Driver/plugin-example.f90
===
--- /dev/null
+++ flang/test/Driver/plugin-example.f90
@@ -0,0 +1,11 @@
+! Check that loading and running the Hello World plugin example results in the correct print statement
+! Also check that when a plugin name isn't found, the error diagnostic is correct
+! This requires that the examples are built (FLANG_BUILD_EXAMPLES=ON)
+
+! REQUIRES: new-flang-driver, plugins, examples, shell
+
+! RUN: %flang_fc1 -load %llvmshlibdir/flangHelloWorldPlugin%pluginext -plugin -hello-world %s 2>&1 | FileCheck %s
+! CHECK: Hello World from your new Flang plugin
+
+! RUN: not %flang_fc1 -load %llvmshlibdir/flangHelloWorldPlugin%pluginext -plugin -wrong-name %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! ERROR: error: unable to find plugin '-wrong-name'
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -123,11 +123,13 @@
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -init-only Only execute frontend initial

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-10 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 365415.
kuhnel added a comment.

fixed a couple of bugs

- wrong usage of llvm::unique
- wrong usage of static pointer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,60 @@
+//===-- StdLibIndexTests.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 "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  auto UmbrellaHeader = SLI.generateIncludeHeader();
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = SLI.indexHeaders(HeaderMock);
+  EXPECT_THAT_EXPECTED(Index, llvm::Succeeded());
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+
+  EXPECT_THAT(match(**Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),
+   llvm::StringRef("otherfunc")));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // 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
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,70 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library. Right now hardcoded to one verison.
+// FIXME: add feature to detect this version somehow (magically).
+enum StandardLibraryVersion { cxx14 = 0 };
+
+// external interface for getting a standard library index.
+Expected>
+indexStandard

[PATCH] D97753: [clang-tidy] Add a check for enforcing minimum length for variable names

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



Comment at: 
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp:136
+CheckFactories.registerCheck(
+"readability-variable-length");
   }

0x8000- wrote:
> aaron.ballman wrote:
> > 0x8000- wrote:
> > > aaron.ballman wrote:
> > > > Is there a reason this should be restricted to variables? For example, 
> > > > wouldn't the same functionality be useful for type names, or dare I say 
> > > > it, even macro names? I'm wondering if this should be 
> > > > `readability-identifier-length` to be more generic.
> > > I consider those to be in separate namespaces. I suppose we could have a 
> > > single checker with multiple rules, but on the other hand I don't want to 
> > > combine too many things into one, just because they share the "compare 
> > > length" dimension.
> > I see where you're coming from, but I come down on the other side. Running 
> > a check is expensive (especially on Windows where process creation can be 
> > really slow), so having multiple checks that traverse the AST gives worse 
> > performance than having a single check that only traverses the AST once. 
> > I'd rather see related functionality grouped together and use options to 
> > control behavior when it's a natural fit to do so.
> > 
> > I should note that I don't mean *you* have to implement this other 
> > functionality (as part of this patch or otherwise). Just that I think we 
> > should leave the check name ambiguous enough that we could grow it to do 
> > that work in the future.
> > 
> > WDYT?
> Right - that's a good point. But I'm wondering the other way; maybe the 
> bigger check will subsume this one, and this one will become just an alias 
> for the bigger check?
> 
> So I'm -0.1 on using the "bigger name" for the limited functionality, but if 
> one more vote comes in saying to go readability-identifier-length I'll rename 
> this (and add explicitly the scope limits in the documentation.)
> Right - that's a good point. But I'm wondering the other way; maybe the 
> bigger check will subsume this one, and this one will become just an alias 
> for the bigger check?

The downside to that approach is that the alias is a bit confusing until its 
deprecation period ends and we remove it. However, that's not a huge downside., 
so I don't insist on the name change if you're resistant to it.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-variable-length.cpp:44
+
+void longEnoughVariableNames(int n) // argument 'n' ignored by configuration
+{

0x8000- wrote:
> aaron.ballman wrote:
> > What in the configuration causes `n` to be ignored?
> It is ignored by the default configuration. Search for 
> "DefaultIgnoredParameterNames" above.
Ah, the comment tripped me up -- can you say `ignored via default 
configuration` like below to make it more clear?


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

https://reviews.llvm.org/D97753

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


[PATCH] D107667: [clang/test] Run thinlto-clang-diagnostic-handler-in-be.c on x86

2021-08-10 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre updated this revision to Diff 365425.
thopre added a comment.

Use x86_64-linux-gnu as triplet


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107667

Files:
  clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c


Index: clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
===
--- clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
+++ clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
@@ -3,11 +3,11 @@
 // REQUIRES: x86-registered-target
 
 // RUN: llvm-profdata merge -o %t1.profdata %S/Inputs/thinlto_expect1.proftext
-// RUN: %clang -O2 -fexperimental-new-pass-manager -flto=thin -g 
-fprofile-use=%t1.profdata -c -o %t1.bo %s
+// RUN: %clang -target x86_64-linux-gnu -O2 -fexperimental-new-pass-manager 
-flto=thin -g -fprofile-use=%t1.profdata -c -o %t1.bo %s
 // RUN: llvm-lto -thinlto -o %t %t1.bo
-// RUN: %clang -cc1 -O2 -fexperimental-new-pass-manager -x ir %t1.bo 
-fthinlto-index=%t.thinlto.bc -emit-obj -Rpass-analysis=info 2>&1 | FileCheck 
%s -check-prefix=CHECK-REMARK
+// RUN: %clang -cc1 -triple x86_64-linux-gnu -O2 
-fexperimental-new-pass-manager -x ir %t1.bo -fthinlto-index=%t.thinlto.bc 
-emit-obj -Rpass-analysis=info 2>&1 | FileCheck %s -check-prefix=CHECK-REMARK
 // RUN: llvm-profdata merge -o %t2.profdata %S/Inputs/thinlto_expect2.proftext
-// RUN: %clang -cc1 -O2 -fexperimental-new-pass-manager -x ir %t1.bo 
-fthinlto-index=%t.thinlto.bc -fprofile-instrument-use-path=%t2.profdata 
-emit-obj 2>&1 | FileCheck %s -allow-empty -check-prefix=CHECK-NOWARNING
+// RUN: %clang -cc1 -triple x86_64-linux-gnu -O2 
-fexperimental-new-pass-manager -x ir %t1.bo -fthinlto-index=%t.thinlto.bc 
-fprofile-instrument-use-path=%t2.profdata -emit-obj 2>&1 | FileCheck %s 
-allow-empty -check-prefix=CHECK-NOWARNING
 
 int sum;
 __attribute__((noinline)) void bar() {


Index: clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
===
--- clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
+++ clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
@@ -3,11 +3,11 @@
 // REQUIRES: x86-registered-target
 
 // RUN: llvm-profdata merge -o %t1.profdata %S/Inputs/thinlto_expect1.proftext
-// RUN: %clang -O2 -fexperimental-new-pass-manager -flto=thin -g -fprofile-use=%t1.profdata -c -o %t1.bo %s
+// RUN: %clang -target x86_64-linux-gnu -O2 -fexperimental-new-pass-manager -flto=thin -g -fprofile-use=%t1.profdata -c -o %t1.bo %s
 // RUN: llvm-lto -thinlto -o %t %t1.bo
-// RUN: %clang -cc1 -O2 -fexperimental-new-pass-manager -x ir %t1.bo -fthinlto-index=%t.thinlto.bc -emit-obj -Rpass-analysis=info 2>&1 | FileCheck %s -check-prefix=CHECK-REMARK
+// RUN: %clang -cc1 -triple x86_64-linux-gnu -O2 -fexperimental-new-pass-manager -x ir %t1.bo -fthinlto-index=%t.thinlto.bc -emit-obj -Rpass-analysis=info 2>&1 | FileCheck %s -check-prefix=CHECK-REMARK
 // RUN: llvm-profdata merge -o %t2.profdata %S/Inputs/thinlto_expect2.proftext
-// RUN: %clang -cc1 -O2 -fexperimental-new-pass-manager -x ir %t1.bo -fthinlto-index=%t.thinlto.bc -fprofile-instrument-use-path=%t2.profdata -emit-obj 2>&1 | FileCheck %s -allow-empty -check-prefix=CHECK-NOWARNING
+// RUN: %clang -cc1 -triple x86_64-linux-gnu -O2 -fexperimental-new-pass-manager -x ir %t1.bo -fthinlto-index=%t.thinlto.bc -fprofile-instrument-use-path=%t2.profdata -emit-obj 2>&1 | FileCheck %s -allow-empty -check-prefix=CHECK-NOWARNING
 
 int sum;
 __attribute__((noinline)) void bar() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107095: Implement #pragma clang header_unsafe

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



Comment at: clang/test/Lexer/Inputs/unsafe-macro-2.h:23-26
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#define UNSAFE_MACRO_2 2

beanz wrote:
> aaron.ballman wrote:
> > Why do we not expect warnings for these cases? I would have expected that 
> > undefining a macro is just as unsafe for ABI reasons as defining a macro is.
> I kinda waffled on this myself. My thought was to treat this similarly to how 
> we handle the macro redefinition warning. If you `undef`, you're kind of 
> claiming the macro as your own and all bets are off...
> 
> That said, my next clang extension closes that loop hole too:
> https://github.com/llvm-beanz/llvm-project/commit/f0a5216e18f5ee0883039095169bd380295b1de0
So `header_unsafe` is "diagnose if someone expands this macro from outside the 
main source file" and `final` is "diagnose if someone defines or undefines this 
macro anywhere", correct? Would it make sense to have a shorthand to combine 
these effects for a "fully reserved" macro identifier (`#pragma clang 
reserve_macro(IDENT[, msg])` as a strawman)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

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


[PATCH] D107095: Implement #pragma clang header_unsafe

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



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:535
+def note_pp_macro_annotation :
+  Note<"macro marked %select{deprecated|header_unsafe}0 here">;
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

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


[clang] 5de6b1a - [OpenCL] Make pipes and workgroup optional for -fdeclare-opencl-builtins

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

Author: Sven van Haastregt
Date: 2021-08-10T13:01:47+01:00
New Revision: 5de6b1acb5900be80515cf9fa253f8698fc57dca

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

LOG: [OpenCL] Make pipes and workgroup optional for -fdeclare-opencl-builtins

Align guards of these builtins with opencl-c.h.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index f2ab4169efec8..8de7632deb503 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -83,6 +83,9 @@ def FuncExtKhrMipmapImage: 
FunctionExtension<"cl_khr_mipmap_imag
 def FuncExtKhrMipmapImageWrites  : 
FunctionExtension<"cl_khr_mipmap_image_writes">;
 def FuncExtKhrGlMsaaSharing  : 
FunctionExtension<"cl_khr_gl_msaa_sharing">;
 
+def FuncExtOpenCLCPipes  : 
FunctionExtension<"__opencl_c_pipes">;
+def FuncExtOpenCLCWGCollectiveFunctions  : 
FunctionExtension<"__opencl_c_work_group_collective_functions">;
+
 // Not a real extension, but a workaround to add C++ for OpenCL specific 
builtins.
 def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">;
 
@@ -1292,7 +1295,7 @@ foreach aQual = ["WO", "RW"] in {
 //
 // OpenCL v2.0 s6.13.15 - Work-group Functions
 // --- Table 26 ---
-let MinVersion = CL20 in {
+let Extension = FuncExtOpenCLCWGCollectiveFunctions in {
   foreach name = ["work_group_all", "work_group_any"] in {
 def : Builtin;
   }
@@ -1317,7 +1320,9 @@ let MinVersion = CL20 in {
 
 // --- Table 28 ---
 // Builtins taking pipe arguments are defined in Builtins.def
-def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
+let Extension = FuncExtOpenCLCPipes in {
+  def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
+}
 
 // --- Table 29 ---
 // Defined in Builtins.def



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


[PATCH] D106137: [flang][driver] Add support for Frontend Plugins

2021-08-10 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski 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/D106137/new/

https://reviews.llvm.org/D106137

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


[PATCH] D105264: [X86] AVX512FP16 instructions enabling 2/6

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



Comment at: clang/include/clang/Basic/BuiltinsX86.def:1860
+TARGET_BUILTIN(__builtin_ia32_minph512,  "V32xV32xV32xIi", "ncV:512:", 
"avx512fp16")
+
+TARGET_BUILTIN(__builtin_ia32_minph256,  "V16xV16xV16x", "ncV:256:", 
"avx512fp16,avx512vl")

Why there is no 256 and 128 version for addph, subph, mulph, divph?



Comment at: clang/lib/Headers/avx512fp16intrin.h:312
+   __m128h B) {
+  return __builtin_ia32_vcomish((__v8hf)A, (__v8hf)B, _CMP_NEQ_US,
+_MM_FROUND_CUR_DIRECTION);

_CMP_NEQ_OS?



Comment at: clang/lib/Headers/avx512fp16intrin.h:318
+   __m128h B) {
+  return __builtin_ia32_vcomish((__v8hf)A, (__v8hf)B, _CMP_EQ_OQ,
+_MM_FROUND_CUR_DIRECTION);

Why it is OQ not UQ? Ditto for all other ucomi intrinsics.



Comment at: clang/lib/Headers/avx512fp16intrin.h:516
+  return (__m512h)__builtin_ia32_maxph512((__v32hf)__A, (__v32hf)__B,
+  _MM_FROUND_CUR_DIRECTION);
+}

Why there is rounding control for max/min operation?



Comment at: clang/lib/Headers/avx512fp16intrin.h:669
+  __A = _mm_div_sh(__A, __B);
+  return __builtin_ia32_selectsh_128(__U, __A, __W);
+}

Will it be combined to one instruction? If __B[0] is 0, and mask[0] is 0, there 
is no exception? 



Comment at: clang/lib/Headers/avx512fp16intrin.h:698
+  (__v8hf)__A, (__v8hf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)-1,
+  _MM_FROUND_CUR_DIRECTION);
+}

Do we have rounding control for min?



Comment at: clang/lib/Headers/avx512fp16intrin.h:757
+
+#define _mm_max_round_sh(A, B, R)  
\
+  (__m128h) __builtin_ia32_maxsh_round_mask(   
\

This name may be misleading, it means suppress exception. Right?



Comment at: clang/lib/Headers/avx512fp16intrin.h:952
 
+#define _mm512_mask_reduce_operator(op)
\
+  __m256h __t1 = (__m256h)_mm512_extractf64x4_pd((__m512d)__W, 0); 
\

It seems there is no mask for reduce operation.



Comment at: clang/lib/Headers/avx512fp16intrin.h:963
+  __m128h __t9 = (__m128h)__builtin_shufflevector((__m128)__t8, (__m128)__t8,  
\
+  1, 0, 2, 3); 
\
+  __m128h __t10 = __t8 op __t9;
\

Not sure if there is any room to optimize. The operation for element 2, 3 is 
unnecessary.



Comment at: clang/lib/Headers/avx512vlfp16intrin.h:366
 
+#define _mm256_mask_reduce_operator(op)
\
+  __m128h __t1 = (__m128h)_mm256_extracti128_si256((__m256i)__W, 0);   
\

Ditto



Comment at: clang/lib/Headers/avx512vlfp16intrin.h:394
+
+#define _mm256_mask_reduce_operator(op)
\
+  __m128h __t1 = (__m128h)_mm256_extracti128_si256((__m256i)__V, 0);   
\

Ditto.



Comment at: clang/test/CodeGen/X86/avx512fp16-builtins.c:639
+  return _mm512_max_round_ph(__A, __B, _MM_FROUND_NO_EXC);
+}
+__m512h test_mm512_mask_max_round_ph(__m512h __W, __mmask32 __U, __m512h __A, 
__m512h __B) {

Need a blank line?



Comment at: clang/test/CodeGen/X86/avx512fp16-builtins.c:645
+  return _mm512_mask_max_round_ph(__W, __U, __A, __B, _MM_FROUND_NO_EXC);
+}
+__m512h test_mm512_maskz_max_round_ph(__mmask32 __U, __m512h __A, __m512h __B) 
{

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105264

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


[PATCH] D107450: [clang-tidy] Fix wrong and missing warnings in performance-move-const-arg

2021-08-10 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 365448.
Sockke added a comment.

update!


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

https://reviews.llvm.org/D107450

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
  clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
@@ -70,7 +70,11 @@
   // CHECK-FIXES: return x3;
 }
 
-A f4(A x4) { return std::move(x4); }
+A f4(A x4) { 
+  return std::move(x4); 
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: it's superfluous; a move will happen, with or without the std::move
+  // CHECK-FIXES: return x4;
+}
 
 A f5(const A x5) {
   return std::move(x5);
@@ -246,3 +250,73 @@
   };
   f(MoveSemantics());
 }
+
+void showInt(int &&) {}
+int testInt() {
+  int a = 10;
+  int b = std::move(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; remove std::move()
+  // CHECK-FIXES: int b = a;
+  showInt(std::move(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; consider changing showInt's parameter from 'int'&& to 'int'&
+  return std::move(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; remove std::move()
+  // CHECK-FIXES: return a;
+}
+
+struct Tmp {};
+void showTmp(Tmp &&) {}
+Tmp testTmp() {
+  Tmp t;
+  Tmp t1 = std::move(t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the variable 't' of the trivially-copyable type 'Tmp' has no effect; remove std::move()
+  // CHECK-FIXES: Tmp t1 = t;
+  Tmp t2 = std::move(Tmp());
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the expression of the trivially-copyable type 'Tmp' has no effect; remove std::move()
+  // CHECK-FIXES: Tmp t2 = Tmp();
+  showTmp(std::move(t));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 't' of the trivially-copyable type 'Tmp' has no effect; consider changing showTmp's parameter from 'Tmp'&& to 'Tmp'&
+  return std::move(t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 't' of the trivially-copyable type 'Tmp' has no effect; remove std::move()
+  // CHECK-FIXES: return t;
+}
+
+struct Tmp_UnTriviallyC {
+  Tmp_UnTriviallyC() {}
+  Tmp_UnTriviallyC(const Tmp_UnTriviallyC &) {}
+};
+void showTmp_UnTriviallyC(Tmp_UnTriviallyC &&) {}
+Tmp_UnTriviallyC testTmp_UnTriviallyC() {
+  Tmp_UnTriviallyC tn;
+  Tmp_UnTriviallyC tn1 = std::move(tn);
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: passing result of std::move() as a const reference argument; no move will actually happen
+  // CHECK-FIXES: Tmp_UnTriviallyC tn1 = tn;
+  Tmp_UnTriviallyC tn2 = std::move(Tmp_UnTriviallyC());
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: passing result of std::move() as a const reference argument; no move will actually happen
+  // CHECK-FIXES: Tmp_UnTriviallyC tn2 = Tmp_UnTriviallyC();
+  showTmp_UnTriviallyC(std::move(tn));
+  // Expect no warning given here.
+  return std::move(tn);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: passing result of std::move() as a const reference argument; no move will actually happen 
+  // CHECK-FIXES: return tn;
+}
+
+struct Tmp_UnTriviallyCR {
+  Tmp_UnTriviallyCR() {}
+  Tmp_UnTriviallyCR(const Tmp_UnTriviallyCR &) {}
+  Tmp_UnTriviallyCR(Tmp_UnTriviallyCR &&) {}
+};
+void showTmp_UnTriviallyCR(Tmp_UnTriviallyCR &&) {}
+Tmp_UnTriviallyCR testTmp_UnTriviallyCR() {
+  Tmp_UnTriviallyCR tnr;
+  Tmp_UnTriviallyCR tnr1 = std::move(tnr);
+  // Expect no warning given here.
+  Tmp_UnTriviallyCR tnr2 = std::move(Tmp_UnTriviallyCR());
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: it's superfluous; a move will happen, with or without the std::move
+  // CHECK-FIXES: Tmp_UnTriviallyCR tnr2 = Tmp_UnTriviallyCR();
+  showTmp_UnTriviallyCR(std::move(tnr));
+  // Expect no warning given here.
+  return std::move(tnr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: it's superfluous; a move will happen, with or without the std::move
+  // CHECK-FIXES: return tnr;
+}
Index: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
===
--- clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
+++ clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "llvm/ADT/DenseSet.h"
 
 namespace clang {
 namespace tidy {
@@ -36,6 +37,7 @@
 
 pr

[clang] bd63977 - [Parser] Fix attr infloop on "int x [[c"

2021-08-10 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-08-10T15:03:08+02:00
New Revision: bd63977ca96acc7db2a546f56a5c0ed1fc93e22a

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

LOG: [Parser] Fix attr infloop on "int x [[c"

Similar to ad2d6bbb1435cef0a048c9aed3dcf9617640f222

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

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/cxx-attributes.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 23d22c7b99e9d..bf01099f5f5ce 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4385,7 +4385,7 @@ void 
Parser::ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
   llvm::SmallDenseMap SeenAttrs;
 
   bool AttrParsed = false;
-  while (!Tok.isOneOf(tok::r_square, tok::semi)) {
+  while (!Tok.isOneOf(tok::r_square, tok::semi, tok::eof)) {
 if (AttrParsed) {
   // If we parsed an attribute, a comma is required before parsing any
   // additional attributes.

diff  --git a/clang/test/Parser/cxx-attributes.cpp 
b/clang/test/Parser/cxx-attributes.cpp
index d445e42bfe08e..bb222f91f3cb9 100644
--- a/clang/test/Parser/cxx-attributes.cpp
+++ b/clang/test/Parser/cxx-attributes.cpp
@@ -42,3 +42,6 @@ void fn() {
 [[,,maybe_unused,]] int Commas4; // ok
 [[foo bar]] int NoComma; // expected-error {{expected ','}} \
  // expected-warning {{unknown attribute 'foo' 
ignored}}
+// expected-error@+2 2 {{expected ']'}}
+// expected-error@+1 {{expected external declaration}}
+[[foo



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


[PATCH] D107693: [Parser] Fix attr infloop on "int x [[c"

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd63977ca96a: [Parser] Fix attr infloop on "int x 
[[c" (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107693

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/cxx-attributes.cpp


Index: clang/test/Parser/cxx-attributes.cpp
===
--- clang/test/Parser/cxx-attributes.cpp
+++ clang/test/Parser/cxx-attributes.cpp
@@ -42,3 +42,6 @@
 [[,,maybe_unused,]] int Commas4; // ok
 [[foo bar]] int NoComma; // expected-error {{expected ','}} \
  // expected-warning {{unknown attribute 'foo' 
ignored}}
+// expected-error@+2 2 {{expected ']'}}
+// expected-error@+1 {{expected external declaration}}
+[[foo
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -4385,7 +4385,7 @@
   llvm::SmallDenseMap SeenAttrs;
 
   bool AttrParsed = false;
-  while (!Tok.isOneOf(tok::r_square, tok::semi)) {
+  while (!Tok.isOneOf(tok::r_square, tok::semi, tok::eof)) {
 if (AttrParsed) {
   // If we parsed an attribute, a comma is required before parsing any
   // additional attributes.


Index: clang/test/Parser/cxx-attributes.cpp
===
--- clang/test/Parser/cxx-attributes.cpp
+++ clang/test/Parser/cxx-attributes.cpp
@@ -42,3 +42,6 @@
 [[,,maybe_unused,]] int Commas4; // ok
 [[foo bar]] int NoComma; // expected-error {{expected ','}} \
  // expected-warning {{unknown attribute 'foo' ignored}}
+// expected-error@+2 2 {{expected ']'}}
+// expected-error@+1 {{expected external declaration}}
+[[foo
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -4385,7 +4385,7 @@
   llvm::SmallDenseMap SeenAttrs;
 
   bool AttrParsed = false;
-  while (!Tok.isOneOf(tok::r_square, tok::semi)) {
+  while (!Tok.isOneOf(tok::r_square, tok::semi, tok::eof)) {
 if (AttrParsed) {
   // If we parsed an attribute, a comma is required before parsing any
   // additional attributes.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107450: [clang-tidy] Fix wrong and missing warnings in performance-move-const-arg

2021-08-10 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 365455.

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

https://reviews.llvm.org/D107450

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
  clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp
@@ -70,7 +70,11 @@
   // CHECK-FIXES: return x3;
 }
 
-A f4(A x4) { return std::move(x4); }
+A f4(A x4) { 
+  return std::move(x4); 
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: it's superfluous; a move will happen, with or without the std::move
+  // CHECK-FIXES: return x4;
+}
 
 A f5(const A x5) {
   return std::move(x5);
@@ -246,3 +250,82 @@
   };
   f(MoveSemantics());
 }
+
+void showInt(int &&) {}
+int testInt() {
+  int a = 10;
+  int b = std::move(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; remove std::move()
+  // CHECK-FIXES: int b = a;
+  showInt(std::move(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; consider changing showInt's parameter from 'int'&& to 'int'&
+  return std::move(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; remove std::move()
+  // CHECK-FIXES: return a;
+}
+template 
+void forwardToShowInt(T &&t) {
+  showInt(static_cast(t));
+}
+void testTemplate() {
+  int a = 10;
+  forwardToShowInt(std::move(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; consider changing forwardToShowInt's parameter from 'int'&& to 'int'&
+}
+
+struct Tmp {};
+void showTmp(Tmp &&) {}
+Tmp testTmp() {
+  Tmp t;
+  Tmp t1 = std::move(t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the variable 't' of the trivially-copyable type 'Tmp' has no effect; remove std::move()
+  // CHECK-FIXES: Tmp t1 = t;
+  Tmp t2 = std::move(Tmp());
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the expression of the trivially-copyable type 'Tmp' has no effect; remove std::move()
+  // CHECK-FIXES: Tmp t2 = Tmp();
+  showTmp(std::move(t));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 't' of the trivially-copyable type 'Tmp' has no effect; consider changing showTmp's parameter from 'Tmp'&& to 'Tmp'&
+  return std::move(t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 't' of the trivially-copyable type 'Tmp' has no effect; remove std::move()
+  // CHECK-FIXES: return t;
+}
+
+struct Tmp_UnTriviallyC {
+  Tmp_UnTriviallyC() {}
+  Tmp_UnTriviallyC(const Tmp_UnTriviallyC &) {}
+};
+void showTmp_UnTriviallyC(Tmp_UnTriviallyC &&) {}
+Tmp_UnTriviallyC testTmp_UnTriviallyC() {
+  Tmp_UnTriviallyC tn;
+  Tmp_UnTriviallyC tn1 = std::move(tn);
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: passing result of std::move() as a const reference argument; no move will actually happen
+  // CHECK-FIXES: Tmp_UnTriviallyC tn1 = tn;
+  Tmp_UnTriviallyC tn2 = std::move(Tmp_UnTriviallyC());
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: passing result of std::move() as a const reference argument; no move will actually happen
+  // CHECK-FIXES: Tmp_UnTriviallyC tn2 = Tmp_UnTriviallyC();
+  showTmp_UnTriviallyC(std::move(tn));
+  // Expect no warning given here.
+  return std::move(tn);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: passing result of std::move() as a const reference argument; no move will actually happen 
+  // CHECK-FIXES: return tn;
+}
+
+struct Tmp_UnTriviallyCR {
+  Tmp_UnTriviallyCR() {}
+  Tmp_UnTriviallyCR(const Tmp_UnTriviallyCR &) {}
+  Tmp_UnTriviallyCR(Tmp_UnTriviallyCR &&) {}
+};
+void showTmp_UnTriviallyCR(Tmp_UnTriviallyCR &&) {}
+Tmp_UnTriviallyCR testTmp_UnTriviallyCR() {
+  Tmp_UnTriviallyCR tnr;
+  Tmp_UnTriviallyCR tnr1 = std::move(tnr);
+  // Expect no warning given here.
+  Tmp_UnTriviallyCR tnr2 = std::move(Tmp_UnTriviallyCR());
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: it's superfluous; a move will happen, with or without the std::move
+  // CHECK-FIXES: Tmp_UnTriviallyCR tnr2 = Tmp_UnTriviallyCR();
+  showTmp_UnTriviallyCR(std::move(tnr));
+  // Expect no warning given here.
+  return std::move(tnr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: it's superfluous; a move will happen, with or without the std::move
+  // CHECK-FIXES: return tnr;
+}
Index: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
===
--- clang-tools-extra/clang-tidy/per

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

2021-08-10 Thread gehry via Phabricator via cfe-commits
Sockke marked 2 inline comments as done.
Sockke added a comment.

Any thoughts?


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

https://reviews.llvm.org/D107641

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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-08-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 365456.
MyDeveloperDay marked 2 inline comments as done.
MyDeveloperDay added a comment.

- Add support for both const and volatile alignment
- change `ConstPlacement` to `CVQualifierAlignment`
- add `CVQualifierOrder` to allow control over `const volatile


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/LeftRightConstFixer.cpp
  clang/lib/Format/LeftRightConstFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18277,6 +18277,14 @@
   CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
 
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+  CHECK_PARSE("CVQualifierAlignment: Leave", CVQualifierAlignment,
+  FormatStyle::CVQAS_Leave);
+  CHECK_PARSE("CVQualifierAlignment: Right", CVQualifierAlignment,
+  FormatStyle::CVQAS_Right);
+  CHECK_PARSE("CVQualifierAlignment: Left", CVQualifierAlignment,
+  FormatStyle::CVQAS_Left);
+
   Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
   CHECK_PARSE("AlignConsecutiveAssignments: None", AlignConsecutiveAssignments,
   FormatStyle::ACS_None);
@@ -0,6 +8,373 @@
   "}";
   EXPECT_EQ(Code, format(Code, Style));
 }
+
+TEST_F(FormatTest, LeftRightConst) {
+  FormatStyle Style = getLLVMStyle();
+
+  // keep the const style unaltered
+  verifyFormat("const int a;", Style);
+  verifyFormat("const int *a;", Style);
+  verifyFormat("const int &a;", Style);
+  verifyFormat("const int &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("const Foo a;", Style);
+  verifyFormat("const Foo *a;", Style);
+  verifyFormat("const Foo &a;", Style);
+  verifyFormat("const Foo &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+
+  verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
+  verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
+
+  verifyFormat("volatile const int *restrict;", Style);
+  verifyFormat("const volatile int *restrict;", Style);
+  verifyFormat("const int volatile *restrict;", Style);
+}
+
+TEST_F(FormatTest, RightConst) {
+  FormatStyle Style = getLLVMStyle();
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+
+  verifyFormat("int const a;", Style);
+  verifyFormat("int const *a;", Style);
+  verifyFormat("int const &a;", Style);
+  verifyFormat("int const &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("Foo const a;", Style);
+  verifyFormat("Foo const *a;", Style);
+  verifyFormat("Foo const &a;", Style);
+  verifyFormat("Foo const &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo *const b;", Style);
+  verifyFormat("Foo const *const b;", Style);
+  verifyFormat("auto const v = get_value();", Style);
+  verifyFormat("long long const &a;", Style);
+  verifyFormat("unsigned char const *a;", Style);
+  verifyFormat("int main(int const argc, char const *const *const argv)",
+   Style);
+
+  verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
+  verifyFormat("SourceRange getSourceRange() const override LLVM_READONLY",
+   Style);
+  verifyFormat("void foo() const override;", Style);
+  verifyFormat("void foo() const override LLVM_READONLY;", Style);
+  verifyFormat("void foo() const final;", Style);
+  verifyFormat("void foo() const final LLVM_READONLY;", Style);
+  verifyFormat("void foo() const LLVM_READONLY;", Style);
+
+  verifyFormat(
+  "template  explicit Action(Action const &action);",
+  Style);
+  verifyFormat(
+  "template  explicit Action(Action const &action);",
+  "template  explicit Action(const Action& action);",
+  Style);
+  verifyFormat(
+  "template  e

[clang] 13a86c2 - [Sema] Preserve invalid CXXCtorInitializers using RecoveryExpr in initializer

2021-08-10 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-08-10T15:16:52+02:00
New Revision: 13a86c2bb465edf315ecbac622d73d39abe7

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

LOG: [Sema] Preserve invalid CXXCtorInitializers using RecoveryExpr in 
initializer

Before this patch, CXXCtorInitializers that don't typecheck get discarded in
most cases. In particular:

 - typos that can't be corrected don't turn into RecoveryExpr. The full expr
   disappears instead, and without an init expr we discard the node.
 - initializers that fail initialization (e.g. constructor overload resolution)
   are discarded too.

This patch addresses both these issues (a bit clunkily and repetitively, for
member/base/delegating initializers)

It does not preserve any AST nodes when the member/base can't be resolved or
other problems of that nature. That breaks invariants of CXXCtorInitializer
itself, and we don't have a "weak" RecoveryCtorInitializer like we do for Expr.

I believe the changes to diagnostics in existing tests are improvements.
(We're able to do some analysis on the non-broken parts of the initializer)

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

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 708b5cd8cb76d..112722be2fa1e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -4162,7 +4162,8 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
   SourceLocation IdLoc,
   Expr *Init,
   SourceLocation EllipsisLoc) {
-  ExprResult Res = CorrectDelayedTyposInExpr(Init);
+  ExprResult Res = CorrectDelayedTyposInExpr(Init, /*InitDecl=*/nullptr,
+ /*RecoverUncorrectedTypos=*/true);
   if (!Res.isUsable())
 return true;
   Init = Res.get();
@@ -4375,18 +4376,25 @@ Sema::BuildMemberInitializer(ValueDecl *Member, Expr 
*Init,
 InitializationSequence InitSeq(*this, MemberEntity, Kind, Args);
 ExprResult MemberInit = InitSeq.Perform(*this, MemberEntity, Kind, Args,
 nullptr);
-if (MemberInit.isInvalid())
-  return true;
-
-// C++11 [class.base.init]p7:
-//   The initialization of each base and member constitutes a
-//   full-expression.
-MemberInit = ActOnFinishFullExpr(MemberInit.get(), InitRange.getBegin(),
- /*DiscardedValue*/ false);
-if (MemberInit.isInvalid())
-  return true;
-
-Init = MemberInit.get();
+if (!MemberInit.isInvalid()) {
+  // C++11 [class.base.init]p7:
+  //   The initialization of each base and member constitutes a
+  //   full-expression.
+  MemberInit = ActOnFinishFullExpr(MemberInit.get(), InitRange.getBegin(),
+   /*DiscardedValue*/ false);
+}
+
+if (MemberInit.isInvalid()) {
+  // Args were sensible expressions but we couldn't initialize the member
+  // from them. Preserve them in a RecoveryExpr instead.
+  Init = CreateRecoveryExpr(InitRange.getBegin(), InitRange.getEnd(), Args,
+Member->getType())
+ .get();
+  if (!Init)
+return true;
+} else {
+  Init = MemberInit.get();
+}
   }
 
   if (DirectMember) {
@@ -4428,29 +4436,35 @@ Sema::BuildDelegatingInitializer(TypeSourceInfo *TInfo, 
Expr *Init,
   InitializationSequence InitSeq(*this, DelegationEntity, Kind, Args);
   ExprResult DelegationInit = InitSeq.Perform(*this, DelegationEntity, Kind,
   Args, nullptr);
-  if (DelegationInit.isInvalid())
-return true;
-
-  assert(cast(DelegationInit.get())->getConstructor() &&
- "Delegating constructor with no target?");
+  if (!DelegationInit.isInvalid()) {
+assert(DelegationInit.get()->containsErrors() ||
+   cast(DelegationInit.get())->getConstructor() &&
+   "Delegating constructor with no target?");
 
-  // C++11 [class.base.init]p7:
-  //   The initialization of each base and member constitutes a
-  //   full-expression.
-  DelegationInit = ActOnFinishFullExpr(
-  DelegationInit.get(), InitRange.getBegin(), /*DiscardedValue*/ false);
-  if (DelegationInit.isInvalid())
-return true;
+// C++11 [class.base.init]p7:
+//   The initialization of each base and member constitutes a
+//   full-expression.
+DelegationInit = ActOnFinishFullExpr(
+DelegationInit.get(), InitRange.getBegin(), /*DiscardedValue*/ false);
+  }
 
-  // If we are 

[PATCH] D101641: [Sema] Preserve invalid CXXCtorInitializers using RecoveryExpr in initializer

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13a86c2bb465: [Sema] Preserve invalid CXXCtorInitializers 
using RecoveryExpr in initializer (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D101641?vs=364846&id=365457#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101641

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp

Index: clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
@@ -102,7 +102,9 @@
 struct A { }; // expected-note{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A' for 1st argument}} \
 // expected-note{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A' for 1st argument}} \
 // expected-note{{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
-struct B { };
+struct B { }; // expected-note{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const B' for 1st argument}} \
+// expected-note{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'B' for 1st argument}} \
+// expected-note{{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
 struct C { };
 struct D { };
 
@@ -123,7 +125,9 @@
 HasMixins::HasMixins(const HasMixins &other): Mixins(other)... { }
 
 template
-HasMixins::HasMixins(int i): Mixins(i)... { } // expected-error{{no matching constructor for initialization of 'A'}}
+HasMixins::HasMixins(int i): Mixins(i)... { }
+// expected-error@-1 {{no matching constructor for initialization of 'A'}}
+// expected-error@-2 {{no matching constructor for initialization of 'B'}}
 
 void test_has_mixins() {
   HasMixins ab;
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -606,11 +606,13 @@
 
 namespace dr655 { // dr655: yes
   struct A { A(int); }; // expected-note 2-3{{not viable}}
+// expected-note@-1 {{'dr655::A' declared here}}
   struct B : A {
-A a;
+A a; // expected-note {{member is declared here}}
 B();
 B(int) : B() {} // expected-error 0-1 {{C++11}}
 B(int*) : A() {} // expected-error {{no matching constructor}}
+ // expected-error@-1 {{must explicitly initialize the member 'a'}}
   };
 }
 
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -296,3 +296,58 @@
   // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 2
   invalid() ? 1 : 2;
 }
+
+void CtorInitializer() {
+  struct S{int m};
+  class MemberInit {
+int x, y, z;
+S s;
+MemberInit() : x(invalid), y(invalid, invalid), z(invalid()), s(1,2) {}
+// CHECK:  CXXConstructorDecl {{.*}} MemberInit 'void ()'
+// CHECK-NEXT: |-CXXCtorInitializer Field {{.*}} 'x' 'int'
+// CHECK-NEXT: | `-ParenListExpr
+// CHECK-NEXT: |   `-RecoveryExpr {{.*}} ''
+// CHECK-NEXT: |-CXXCtorInitializer Field {{.*}} 'y' 'int'
+// CHECK-NEXT: | `-ParenListExpr
+// CHECK-NEXT: |   |-RecoveryExpr {{.*}} ''
+// CHECK-NEXT: |   `-RecoveryExpr {{.*}} ''
+// CHECK-NEXT: |-CXXCtorInitializer Field {{.*}} 'z' 'int'
+// CHECK-NEXT: | `-ParenListExpr
+// CHECK-NEXT: |   `-RecoveryExpr {{.*}} ''
+// CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} ''
+// CHECK-NEXT: |-CXXCtorInitializer Field {{.*}} 's' 'S'
+// CHECK-NEXT: | `-RecoveryExpr {{.*}} 'S' contains-errors
+// CHECK-NEXT: |   |-IntegerLiteral {{.*}} 1
+// CHECK-NEXT: |   `-IntegerLiteral {{.*}} 2
+  };
+  class BaseInit : S {
+BaseInit(float) : S("no match") {}
+// CHECK:  CXXConstructorDecl {{.*}} BaseInit 'void (float)'
+// CHECK-NEXT: |-ParmVarDecl
+// CHECK-NEXT: |-CXXCtorInitializer 'S'
+// CHECK-NEXT: | `-RecoveryExpr {{.*}} 'S'
+// CHECK-NEXT: |   `-StringLiteral
+
+BaseInit(double) : S(invalid) {}
+// CHECK:  CXXConstructorDecl {{.*}} BaseInit 'void (double)'
+// CHECK-NEXT: |-ParmVarDecl
+// CHECK-NEXT: |-CXXCtorInitializer 'S'
+// CHECK-NEXT: | `-ParenListExpr
+// CHECK-NEXT: |   `-RecoveryExpr {{.*}} ''
+  };
+  class DelegatingInit {
+DelegatingInit(float) : DelegatingInit("no match") {}
+// CHECK:  CXXConstructorDecl {{.*}} DelegatingInit 'void (float)'
+/

[clang-tools-extra] 45abbaf - Revert "[clangd] Support `#pragma mark` in the outline"

2021-08-10 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2021-08-10T14:25:52+01:00
New Revision: 45abbaf2e5fbdf27c9f8ba01b34018b0be45b7c9

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

LOG: Revert "[clangd] Support `#pragma mark` in the outline"

This reverts commit ba06ac8b45ca2ad047131fb9cc9af922cb913ea1.

Added: 


Modified: 
clang-tools-extra/clangd/CollectMacros.cpp
clang-tools-extra/clangd/CollectMacros.h
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/ParsedAST.h
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/Preamble.h
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang/include/clang/Lex/PPCallbacks.h

Removed: 




diff  --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
index 9bcc3c1995415..0e89b35d9d56d 100644
--- a/clang-tools-extra/clangd/CollectMacros.cpp
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -30,33 +30,5 @@ void CollectMainFileMacros::add(const Token &MacroNameTok, 
const MacroInfo *MI,
   else
 Out.UnknownMacros.push_back({Range, IsDefinition});
 }
-
-class CollectPragmaMarks : public PPCallbacks {
-public:
-  explicit CollectPragmaMarks(const SourceManager &SM,
-  std::vector &Out)
-  : SM(SM), Out(Out) {}
-
-  void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
-if (isInsideMainFile(Loc, SM)) {
-  // FIXME: This range should just cover `XX` in `#pragma mark XX` and
-  // `- XX` in `#pragma mark - XX`.
-  Position Start = sourceLocToPosition(SM, Loc);
-  Position End = {Start.line + 1, 0};
-  Out.emplace_back(clangd::PragmaMark{{Start, End}, Trivia.str()});
-}
-  }
-
-private:
-  const SourceManager &SM;
-  std::vector &Out;
-};
-
-std::unique_ptr
-collectPragmaMarksCallback(const SourceManager &SM,
-   std::vector &Out) {
-  return std::make_unique(SM, Out);
-}
-
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index 2167ebe2e3560..3240111e5a33d 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -99,18 +99,6 @@ class CollectMainFileMacros : public PPCallbacks {
   MainFileMacros &Out;
 };
 
-/// Represents a `#pragma mark` in the main file.
-///
-/// There can be at most one pragma mark per line.
-struct PragmaMark {
-  Range Rng;
-  std::string Trivia;
-};
-
-/// Collect all pragma marks from the main file.
-std::unique_ptr
-collectPragmaMarksCallback(const SourceManager &, std::vector 
&Out);
-
 } // namespace clangd
 } // namespace clang
 

diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp 
b/clang-tools-extra/clangd/FindSymbols.cpp
index edbeeed9e2ca6..e4846ac7a59d3 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -523,135 +523,9 @@ class DocumentOutline {
   ParsedAST &AST;
 };
 
-struct PragmaMarkSymbol {
-  DocumentSymbol DocSym;
-  bool IsGroup;
-};
-
-/// Merge in `PragmaMarkSymbols`, sorted ascending by range, into the given
-/// `DocumentSymbol` tree.
-void mergePragmas(DocumentSymbol &Root, ArrayRef Pragmas) {
-  while (!Pragmas.empty()) {
-// We'll figure out where the Pragmas.front() should go.
-PragmaMarkSymbol P = std::move(Pragmas.front());
-Pragmas = Pragmas.drop_front();
-DocumentSymbol *Cur = &Root;
-while (Cur->range.contains(P.DocSym.range)) {
-  bool Swapped = false;
-  for (auto &C : Cur->children) {
-// We assume at most 1 child can contain the pragma (as pragmas are on
-// a single line, and children have disjoint ranges).
-if (C.range.contains(P.DocSym.range)) {
-  Cur = &C;
-  Swapped = true;
-  break;
-}
-  }
-  // Cur is the parent of P since none of the children contain P.
-  if (!Swapped)
-break;
-}
-// Pragma isn't a group so we can just insert it and we are done.
-if (!P.IsGroup) {
-  Cur->children.emplace_back(std::move(P.DocSym));
-  continue;
-}
-// Pragma is a group, so we need to figure out where it terminates:
-// - If the next Pragma is not contained in Cur, P owns all of its
-//   parent's children which occur after P.
-// - If the next pragma is contained in Cur but actually belongs to one
-//   of the parent's children, we temporarily skip over it and look at
-//   the next pragma to decide where we end.
-// - Otherwise nest all of its parent's children which occur after P

[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-08-10 Thread Florian Mayer via Phabricator via cfe-commits
fmayer reopened this revision.
fmayer added a comment.
This revision is now accepted and ready to land.

This broke the UBsan buildbot: 
https://lab.llvm.org/buildbot/#/builders/85/builds/6103/steps/10/logs/stdio


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

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


[PATCH] D107450: [clang-tidy] Fix wrong and missing warnings in performance-move-const-arg

2021-08-10 Thread liushuai wang via Phabricator via cfe-commits
MTC added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp:261
+  showInt(std::move(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'a' 
of the trivially-copyable type 'int' has no effect; consider changing showInt's 
parameter from 'int'&& to 'int'&
+  return std::move(a);

Change **'int'&&**  -> **'int&&'** and **'int&'** -> **int**. 

Make `consider changing showInt's parameter from 'int'&& to 'int'&` as a note 
instead of a warning. And I don't have a strong preference for the position of 
the note, but I personally want to put it in the source location of the 
function definition. and 


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

https://reviews.llvm.org/D107450

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


[PATCH] D106737: [clang] [hexagon] Add resource include dir

2021-08-10 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 365459.
bcain added a comment.

Suggestions from Fangrui: override the resource-dir with an explicit arg, 
disable for windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106737

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-linux.c


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -1,3 +1,5 @@
+// UNSUPPORTED: system-windows
+
 // 
-
 // Passing --musl
 // 
-
@@ -94,4 +96,26 @@
 // RUN:   -mcpu=hexagonv60 \
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK007 %s
-// CHECK007:  "-internal-isystem" 
"{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
+// CHECK007:   "-internal-isystem" 
"{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
+// 
-
+// internal-isystem for linux with and without musl
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -resource-dir=%S/Inputs/resource_dir \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK008 %s
+// CHECK008:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK008:   "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK008-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// CHECK008-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -### -target hexagon-unknown-linux \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -resource-dir=%S/Inputs/resource_dir \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK009 %s
+// CHECK009:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// CHECK009-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -588,21 +588,43 @@
 
 void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
  ArgStringList &CC1Args) const 
{
-  if (DriverArgs.hasArg(options::OPT_nostdinc) ||
-  DriverArgs.hasArg(options::OPT_nostdlibinc))
+  if (DriverArgs.hasArg(options::OPT_nostdinc))
 return;
 
+  const bool IsELF = !getTriple().isMusl() && !getTriple().isOSLinux();
+  const bool IsLinuxMusl = getTriple().isMusl() && getTriple().isOSLinux();
+
   const Driver &D = getDriver();
-  if (!D.SysRoot.empty()) {
+  SmallString<128> ResourceDirInclude(D.ResourceDir);
+  if (!IsELF) {
+llvm::sys::path::append(ResourceDirInclude, "include");
+if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
+(!IsLinuxMusl || DriverArgs.hasArg(options::OPT_nostdlibinc)))
+  addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
+  }
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  const bool HasSysRoot = !D.SysRoot.empty();
+  if (HasSysRoot) {
 SmallString<128> P(D.SysRoot);
-if (getTriple().isMusl())
+if (IsLinuxMusl)
   llvm::sys::path::append(P, "usr/include");
 else
   llvm::sys::path::append(P, "include");
+
 addExternCSystemInclude(DriverArgs, CC1Args, P.str());
-return;
+// LOCAL_INCLUDE_DIR
+addSystemInclude(DriverArgs, CC1Args, P + "/usr/local/include");
+// TOOL_INCLUDE_DIR
+AddMultilibIncludeArgs(DriverArgs, CC1Args);
   }
 
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && IsLinuxMusl)
+addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
+
+  if (HasSysRoot)
+return;
   std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
   D.PrefixDirs);
   addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include");


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -1,3 +1,5 @@
+// UNSUPPORTED: system-windows
+
 // -
 // Passing --musl
 // -
@@ -94,4 +96,26 @@
 // RUN:   -mcpu=hexagonv60 \
 // RUN:   %s 2>&1 \
 // 

[clang] 888876b - [clang] [hexagon] Add resource include dir

2021-08-10 Thread Brian Cain via cfe-commits

Author: Brian Cain
Date: 2021-08-10T08:37:58-05:00
New Revision: 76ba272baf68ff38fcfc36c15ac2510bdea7

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

LOG: [clang] [hexagon] Add resource include dir

Added: 


Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/test/Driver/hexagon-toolchain-linux.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 828bfdbb05a3c..314d0efce4414 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -588,21 +588,43 @@ void HexagonToolChain::addClangTargetOptions(const 
ArgList &DriverArgs,
 
 void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
  ArgStringList &CC1Args) const 
{
-  if (DriverArgs.hasArg(options::OPT_nostdinc) ||
-  DriverArgs.hasArg(options::OPT_nostdlibinc))
+  if (DriverArgs.hasArg(options::OPT_nostdinc))
 return;
 
+  const bool IsELF = !getTriple().isMusl() && !getTriple().isOSLinux();
+  const bool IsLinuxMusl = getTriple().isMusl() && getTriple().isOSLinux();
+
   const Driver &D = getDriver();
-  if (!D.SysRoot.empty()) {
+  SmallString<128> ResourceDirInclude(D.ResourceDir);
+  if (!IsELF) {
+llvm::sys::path::append(ResourceDirInclude, "include");
+if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
+(!IsLinuxMusl || DriverArgs.hasArg(options::OPT_nostdlibinc)))
+  addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
+  }
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  const bool HasSysRoot = !D.SysRoot.empty();
+  if (HasSysRoot) {
 SmallString<128> P(D.SysRoot);
-if (getTriple().isMusl())
+if (IsLinuxMusl)
   llvm::sys::path::append(P, "usr/include");
 else
   llvm::sys::path::append(P, "include");
+
 addExternCSystemInclude(DriverArgs, CC1Args, P.str());
-return;
+// LOCAL_INCLUDE_DIR
+addSystemInclude(DriverArgs, CC1Args, P + "/usr/local/include");
+// TOOL_INCLUDE_DIR
+AddMultilibIncludeArgs(DriverArgs, CC1Args);
   }
 
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && IsLinuxMusl)
+addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
+
+  if (HasSysRoot)
+return;
   std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
   D.PrefixDirs);
   addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include");

diff  --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 354a924f12098..da59590371b90 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -1,3 +1,5 @@
+// UNSUPPORTED: system-windows
+
 // 
-
 // Passing --musl
 // 
-
@@ -94,4 +96,26 @@
 // RUN:   -mcpu=hexagonv60 \
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK007 %s
-// CHECK007:  "-internal-isystem" 
"{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
+// CHECK007:   "-internal-isystem" 
"{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
+// 
-
+// internal-isystem for linux with and without musl
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -resource-dir=%S/Inputs/resource_dir \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK008 %s
+// CHECK008:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK008:   "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK008-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// CHECK008-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -### -target hexagon-unknown-linux \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -resource-dir=%S/Inputs/resource_dir \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK009 %s
+// CHECK009:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// CHECK009-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"



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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-08-10 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

First off, I think it should be configured in a different way, to prepare the 
path for also formatting static, inline, etc.

If this is kept there should be tests on what happens if there is const or 
volatile more than once in the string list, and when there are typos. Should 
there be a command line warning on a typo or an unsupported identifier is in 
the list?




Comment at: clang/lib/Format/Format.cpp:2890-2892
+if (Style.CVQualifierAlignment == FormatStyle::CVQAS_Left) {
+  std::reverse(Order.begin(), Order.end());
+}





Comment at: clang/lib/Format/Format.cpp:2896
+// will be out of scope at construction.
+for (std::string CVQualifier : Order) {
+  if (CVQualifier == "const") {

I don't know if we should remove the braces here too.

But the loop should use references or StringRef, not copied strings.


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

https://reviews.llvm.org/D69764

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


[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 365461.
sammccall marked an inline comment as done.
sammccall added a comment.

Change assertion to defensive check


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/Attr.h
  clang/lib/AST/CMakeLists.txt
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -61,6 +61,7 @@
llvm::raw_ostream &OS);
 void EmitClangAttrNodeTraverse(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
+void EmitClangAttrDocTable(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 
 void EmitClangDiagsDefs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS,
 const std::string &Component);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -30,6 +30,7 @@
   GenClangAttrSubjectMatchRulesParserStringSwitches,
   GenClangAttrImpl,
   GenClangAttrList,
+  GenClangAttrDocTable,
   GenClangAttrSubjectMatchRuleList,
   GenClangAttrPCHRead,
   GenClangAttrPCHWrite,
@@ -115,6 +116,8 @@
"Generate clang attribute implementations"),
 clEnumValN(GenClangAttrList, "gen-clang-attr-list",
"Generate a clang attribute list"),
+clEnumValN(GenClangAttrDocTable, "gen-clang-attr-doc-table",
+   "Generate a table of attribute documentation"),
 clEnumValN(GenClangAttrSubjectMatchRuleList,
"gen-clang-attr-subject-match-rule-list",
"Generate a clang attribute subject match rule list"),
@@ -280,6 +283,9 @@
   case GenClangAttrList:
 EmitClangAttrList(Records, OS);
 break;
+  case GenClangAttrDocTable:
+EmitClangAttrDocTable(Records, OS);
+break;
   case GenClangAttrSubjectMatchRuleList:
 EmitClangAttrSubjectMatchRuleList(Records, OS);
 break;
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4210,6 +4210,42 @@
   getPragmaAttributeSupport(Records).generateParsingHelpers(OS);
 }
 
+void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
+  emitSourceFileHeader("Clang attribute documentation", OS);
+
+  OS << R"cpp(
+  #include "clang/AST/Attr.h"
+  #include "llvm/ADT/StringRef.h"
+  )cpp";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+if (!A->getValueAsBit("ASTNode"))
+  continue;
+std::vector Docs = A->getValueAsListOfDefs("Documentation");
+for (const auto *D : Docs) {
+  OS << "\nstatic const char AttrDoc_" << A->getName() << "[] = "
+ << "R\"reST("
+ << D->getValueAsOptionalString("Content").getValueOr("").trim()
+ << ")reST\";\n";
+  // Only look at the first documentation if there are several.
+  // (As of now, only one attribute has multiple documentation entries).
+  break;
+}
+  }
+  OS << R"cpp(
+  static const llvm::StringRef AttrDoc[] = {
+  #define ATTR(NAME) AttrDoc_##NAME,
+  #include "clang/Basic/AttrList.inc"
+  };
+
+  llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
+if(K < llvm::array_lengthof(AttrDoc))
+  return AttrDoc[K];
+return "";
+  }
+  )cpp";
+}
+
 enum class SpellingKind {
   GNU,
   CXX11,
Index: clang/lib/AST/CMakeLists.txt
===
--- clang/lib/AST/CMakeLists.txt
+++ clang/lib/AST/CMakeLists.txt
@@ -13,6 +13,11 @@
   SOURCE Interp/Opcodes.td
   TARGET Opcodes)
 
+clang_tablegen(AttrDocTable.cpp -gen-clang-attr-doc-table
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../include/
+  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../include/clang/Basic/Attr.td
+  TARGET ClangAttrDocTable)
+
 add_clang_library(clangAST
   APValue.cpp
   ASTConcept.cpp
@@ -24,6 +29,7 @@
   ASTImporterLookupTable.cpp
   ASTStructuralEquivalence.cpp
   ASTTypeTraits.cpp
+  AttrDocTable.cpp
   AttrImpl.cpp
   Comment.cpp
   CommentBriefParser.cpp
Index: clang/include/clang/AST/Attr.h
===
--- clang/include/clang/AST/Attr.h
+++ clang/include/clang/AST/Attr.h
@@ -109,6 +109,8 @@
 
   // Pretty print this attribute.
   void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const;
+
+  static StringRef getDocumentation(attr::Kind);
 };
 
 class T

[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:4220
+  )cpp";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {

aaron.ballman wrote:
> FWIW, this will miss `omp::sequence` and `omp::directive`, but that's not the 
> end of the world. May be worth a fixme comment in case we want to solve it 
> someday.
Well, those
 - don't themselves have Attr nodes or AttrKinds, so the API couldn't query for 
them
 - don't actually have any documentation as far as I can tell
So I'm not sure there's much to fix.

---

The ParsedAttr-kind vs Attr-kind distinction, and the fact that many attributes 
don't leave any AST nodes at all, mean this method doesn't seem "universal". 
But the goal is to show docs in clangd when hovering on an attribute (which we 
only support for those with AST nodes).

If we want to do something different (like show documenation while 
code-completing) we'll probably have to add a second ParsedAttrKind-based API.



Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:4242
+  llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
+assert(K < llvm::array_lengthof(AttrDoc));
+return AttrDoc[K];

aaron.ballman wrote:
> H, I am not 100% certain this assertion is correct -- the user may have 
> plugin attributes, which I believe are given a "kind" that's larger than the 
> last-known builtin attribute kind.
Thanks, changed it to an if() instead.
(I don't think it's particularly pressing to allow them to be documented)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

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


[PATCH] D107095: Implement #pragma clang header_unsafe

2021-08-10 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/Lexer/Inputs/unsafe-macro-2.h:23-26
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#define UNSAFE_MACRO_2 2

aaron.ballman wrote:
> beanz wrote:
> > aaron.ballman wrote:
> > > Why do we not expect warnings for these cases? I would have expected that 
> > > undefining a macro is just as unsafe for ABI reasons as defining a macro 
> > > is.
> > I kinda waffled on this myself. My thought was to treat this similarly to 
> > how we handle the macro redefinition warning. If you `undef`, you're kind 
> > of claiming the macro as your own and all bets are off...
> > 
> > That said, my next clang extension closes that loop hole too:
> > https://github.com/llvm-beanz/llvm-project/commit/f0a5216e18f5ee0883039095169bd380295b1de0
> So `header_unsafe` is "diagnose if someone expands this macro from outside 
> the main source file" and `final` is "diagnose if someone defines or 
> undefines this macro anywhere", correct? Would it make sense to have a 
> shorthand to combine these effects for a "fully reserved" macro identifier 
> (`#pragma clang reserve_macro(IDENT[, msg])` as a strawman)?
My thought process for implementing them separately was that final would be 
useful independent of header_unsafe. I could, for example, see applying final 
to macros like MIN and MAX, where they can be safely used anywhere, but you 
really don’t want multiple definitions floating around. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

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


[PATCH] D97803: [clangd] Overload bundles are only deprecated if each overloads is.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.
Herald added a project: clang-tools-extra.

Whoops, lost this patch...

In D97803#2602787 , @kbobyrev wrote:

> So, if my understanding is correct, this will make the whole bundle 
> non-deprecated if at least one overload is not deprecated?  This is probably 
> an improvement over the existing behaviour.

Yes, exactly.

> However, do we maybe want to split the bundles into deprecated and 
> non-deprecated groups?

I don't think splitting bundles over this is worthwhile.

- it's a distraction. The point of bundling is to hide some differences within 
an overload set, to let you see all the methods more clearly.
- the "deprecated" signal means "you don't want this". This is well-defined, 
and false, for a mixed bundle.




Comment at: clang-tools-extra/clangd/CodeComplete.cpp:410
+if (Completion.Deprecated) {
+  Completion.Deprecated =
+  (C.SemaResult &&

kbobyrev wrote:
> The comment you added says "cleared" which means this should probably be `|=` 
> rather than `=`, right?
> 
> Also, I this looks longer but probably more readable at least for me.
> 
> Also, the sources might be `SemaResult`, `IndexResult` or `IdentifierResult`, 
> right? :( Otherwise could've been `Completion.Deprecated |= C.SemaResult ? 
> C.SemaResult->Availability == CXAvailability_Deprecated : 
> C.IndexResult->Flags & Symbol::Deprecated;`
> The comment you added says "cleared" which means this should probably be |= 
> rather than =, right?

No, `Deprecated` *starts out true* and gets set to false (cleared) if we see 
any non-deprecated entry. (computes AND)

Your version assumes it starts out false and sets it if we see any deprecated 
entry. (computes OR).

I agree the OR version reads better - it's wrong though :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97803

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


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

2021-08-10 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre updated this revision to Diff 365465.
thopre added a comment.

Remove REQUIRES


Repository:
  rG LLVM Github Monorepo

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

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,8 @@
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// 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,8 @@
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// 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] D107633: Set supported target for asan-use-callbacks test

2021-08-10 Thread Thomas Preud'homme 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 rG1397e19129ef: Set supported target for asan-use-callbacks 
test (authored by thopre).

Repository:
  rG LLVM Github Monorepo

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

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,8 @@
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// 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,8 @@
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// 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


[clang] 1397e19 - Set supported target for asan-use-callbacks test

2021-08-10 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2021-08-10T15:01:44+01:00
New Revision: 1397e19129ef7aa6c2ba6f6018ff172a5022a1eb

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

LOG: Set supported target for asan-use-callbacks test

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.

Reviewed By: vitalybuka

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

Added: 


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

Removed: 




diff  --git a/clang/test/CodeGen/asan-use-callbacks.cpp 
b/clang/test/CodeGen/asan-use-callbacks.cpp
index 280b51701e07..5805507e0a5c 100644
--- a/clang/test/CodeGen/asan-use-callbacks.cpp
+++ b/clang/test/CodeGen/asan-use-callbacks.cpp
@@ -1,7 +1,8 @@
-// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// 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] D107825: Define __HOS_AIX__ only for AIX target

2021-08-10 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan created this revision.
Herald added subscribers: kbarton, nemanjai.
Jake-Egan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107825

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


Index: clang/test/Preprocessor/not-host-aix.c
===
--- clang/test/Preprocessor/not-host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -432,6 +432,7 @@
 // PPC-AIX:#define __FLT_MIN_EXP__ (-125)
 // PPC-AIX:#define __FLT_MIN__ 1.17549435e-38F
 // PPC-AIX:#define __FLT_RADIX__ 2
+// PPC-AIX:#define __HOS_AIX__ 1
 // PPC-AIX:#define __INT16_C_SUFFIX__
 // PPC-AIX:#define __INT16_FMTd__ "hd"
 // PPC-AIX:#define __INT16_FMTi__ "hi"
Index: clang/test/Preprocessor/host-aix.c
===
--- clang/test/Preprocessor/host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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,7 +14,6 @@
 #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;
@@ -308,11 +307,6 @@
 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/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -677,6 +677,7 @@
 
 Builder.defineMacro("_AIX");
 Builder.defineMacro("__TOS_AIX__");
+Builder.defineMacro("__HOS_AIX__");
 
 if (Opts.C11) {
   Builder.defineMacro("__STDC_NO_ATOMICS__");


Index: clang/test/Preprocessor/not-host-aix.c
===
--- clang/test/Preprocessor/not-host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -432,6 +432,7 @@
 // PPC-AIX:#define __FLT_MIN_EXP__ (-125)
 // PPC-AIX:#define __FLT_MIN__ 1.17549435e-38F
 // PPC-AIX:#define __FLT_RADIX__ 2
+// PPC-AIX:#define __HOS_AIX__ 1
 // PPC-AIX:#define __INT16_C_SUFFIX__
 // PPC-AIX:#define __INT16_FMTd__ "hd"
 // PPC-AIX:#define __INT16_FMTi__ "hi"
Index: clang/test/Preprocessor/host-aix.c
===
--- clang/test/Preprocessor/host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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,7 +14,6 @@
 #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;
@@ -308,11 +307,6 @@
 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 

[PATCH] D107450: [clang-tidy] Fix wrong and missing warnings in performance-move-const-arg

2021-08-10 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

I'm not at all convinced that any of this complexity is worth it. Have you run 
this check on any large codebase to see how many false positives it has? Does 
it catch any true positives?




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp:284
+  Tmp t2 = std::move(Tmp());
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the expression of 
the trivially-copyable type 'Tmp' has no effect; remove std::move()
+  // CHECK-FIXES: Tmp t2 = Tmp();

Here, the more immediate red flag is that the programmer is using `std::move` 
on an rvalue expression.
```
std::string&& a();
std::string& b();
std::string c();
auto aa = std::move(a());  // not great, moving an xvalue
auto bb = std::move(b());  // OK, moving an lvalue
auto cc = std::move(c());  // not great, moving a prvalue
```
However, the more complicated and guess-worky these diagnostics get, the more I 
want to see how they interact with templates and generic code.
```
template
auto w(F f) {
return std::move(f());
}
std::string callw1() { std::string s; return w([&]() -> std::string { return s; 
});
std::string callw2() { std::string s; return w([&]() -> std::string& { return 
s; });
```
`callw1` ends up applying `std::move` to a prvalue inside `w`, but when 
`callw2` calls `w`, the `std::move` actually does something. Possible 
strategies here include "Warn on code that's only sometimes correct," "Don't 
warn on code that's only sometimes wrong," and "Don't implement the diagnostic 
at all because it's too icky."



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp:287
+  showTmp(std::move(t));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 't' 
of the trivially-copyable type 'Tmp' has no effect; consider changing showTmp's 
parameter from 'Tmp'&& to 'Tmp'&
+  return std::move(t);

This suggestion seems bad. If `Tmp&&` was originally a typo, then the machine 
can't know what the programmer might have meant. If `Tmp&&` was trying to 
indicate "take ownership of," then the right fix would probably be to pass 
`Tmp` by value.


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

https://reviews.llvm.org/D107450

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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-08-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 365472.
MyDeveloperDay added a comment.

- elide the braces
- use references


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/LeftRightConstFixer.cpp
  clang/lib/Format/LeftRightConstFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18277,6 +18277,14 @@
   CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
 
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+  CHECK_PARSE("CVQualifierAlignment: Leave", CVQualifierAlignment,
+  FormatStyle::CVQAS_Leave);
+  CHECK_PARSE("CVQualifierAlignment: Right", CVQualifierAlignment,
+  FormatStyle::CVQAS_Right);
+  CHECK_PARSE("CVQualifierAlignment: Left", CVQualifierAlignment,
+  FormatStyle::CVQAS_Left);
+
   Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
   CHECK_PARSE("AlignConsecutiveAssignments: None", AlignConsecutiveAssignments,
   FormatStyle::ACS_None);
@@ -0,6 +8,373 @@
   "}";
   EXPECT_EQ(Code, format(Code, Style));
 }
+
+TEST_F(FormatTest, LeftRightConst) {
+  FormatStyle Style = getLLVMStyle();
+
+  // keep the const style unaltered
+  verifyFormat("const int a;", Style);
+  verifyFormat("const int *a;", Style);
+  verifyFormat("const int &a;", Style);
+  verifyFormat("const int &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("const Foo a;", Style);
+  verifyFormat("const Foo *a;", Style);
+  verifyFormat("const Foo &a;", Style);
+  verifyFormat("const Foo &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+
+  verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
+  verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
+
+  verifyFormat("volatile const int *restrict;", Style);
+  verifyFormat("const volatile int *restrict;", Style);
+  verifyFormat("const int volatile *restrict;", Style);
+}
+
+TEST_F(FormatTest, RightConst) {
+  FormatStyle Style = getLLVMStyle();
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+
+  verifyFormat("int const a;", Style);
+  verifyFormat("int const *a;", Style);
+  verifyFormat("int const &a;", Style);
+  verifyFormat("int const &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("Foo const a;", Style);
+  verifyFormat("Foo const *a;", Style);
+  verifyFormat("Foo const &a;", Style);
+  verifyFormat("Foo const &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo *const b;", Style);
+  verifyFormat("Foo const *const b;", Style);
+  verifyFormat("auto const v = get_value();", Style);
+  verifyFormat("long long const &a;", Style);
+  verifyFormat("unsigned char const *a;", Style);
+  verifyFormat("int main(int const argc, char const *const *const argv)",
+   Style);
+
+  verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
+  verifyFormat("SourceRange getSourceRange() const override LLVM_READONLY",
+   Style);
+  verifyFormat("void foo() const override;", Style);
+  verifyFormat("void foo() const override LLVM_READONLY;", Style);
+  verifyFormat("void foo() const final;", Style);
+  verifyFormat("void foo() const final LLVM_READONLY;", Style);
+  verifyFormat("void foo() const LLVM_READONLY;", Style);
+
+  verifyFormat(
+  "template  explicit Action(Action const &action);",
+  Style);
+  verifyFormat(
+  "template  explicit Action(Action const &action);",
+  "template  explicit Action(const Action& action);",
+  Style);
+  verifyFormat(
+  "template  explicit Action(Action const &action);",
+  "template \nexplicit Action(const Action& action);",
+  Style);
+
+  verifyFormat("int const a;", "const int a;", Style);
+  veri

[PATCH] D107095: Implement #pragma clang header_unsafe

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



Comment at: clang/test/Lexer/Inputs/unsafe-macro-2.h:23-26
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#define UNSAFE_MACRO_2 2

beanz wrote:
> aaron.ballman wrote:
> > beanz wrote:
> > > aaron.ballman wrote:
> > > > Why do we not expect warnings for these cases? I would have expected 
> > > > that undefining a macro is just as unsafe for ABI reasons as defining a 
> > > > macro is.
> > > I kinda waffled on this myself. My thought was to treat this similarly to 
> > > how we handle the macro redefinition warning. If you `undef`, you're kind 
> > > of claiming the macro as your own and all bets are off...
> > > 
> > > That said, my next clang extension closes that loop hole too:
> > > https://github.com/llvm-beanz/llvm-project/commit/f0a5216e18f5ee0883039095169bd380295b1de0
> > So `header_unsafe` is "diagnose if someone expands this macro from outside 
> > the main source file" and `final` is "diagnose if someone defines or 
> > undefines this macro anywhere", correct? Would it make sense to have a 
> > shorthand to combine these effects for a "fully reserved" macro identifier 
> > (`#pragma clang reserve_macro(IDENT[, msg])` as a strawman)?
> My thought process for implementing them separately was that final would be 
> useful independent of header_unsafe. I could, for example, see applying final 
> to macros like MIN and MAX, where they can be safely used anywhere, but you 
> really don’t want multiple definitions floating around. 
FWIW, I agree that having separation is useful -- I think these serve 
orthogonal (but related) purposes: macros which can only be used by "user 
code", and macros which cannot be redefined or undefined. I was thinking that 
would be an additional pragma instead of a replacement for the two proposed.

I should probably tell you my use cases so we're both on the same page. One of 
the most frustrating problems with trying to write a highly portable library is 
the fact that I have to worry about users defining macros that may conflict 
with my identifiers (like function names, structure names, template names, 
etc), but I have no way to reserve those identifiers. I'm hopeful we can find a 
way that I can "protect" those identifiers in a library with an extension that 
basically says "you can't use these identifiers for macro purposes without 
breaking me". I think that's a combination of `header_unsafe` and `final` -- I 
don't want other libraries to start using macros with the names of my library's 
functions if my header has been included somewhere, and I don't want user code 
defining macros that may conflict with my library.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

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


[PATCH] D107095: Implement #pragma clang header_unsafe

2021-08-10 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/Lexer/Inputs/unsafe-macro-2.h:23-26
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#define UNSAFE_MACRO_2 2

aaron.ballman wrote:
> beanz wrote:
> > aaron.ballman wrote:
> > > beanz wrote:
> > > > aaron.ballman wrote:
> > > > > Why do we not expect warnings for these cases? I would have expected 
> > > > > that undefining a macro is just as unsafe for ABI reasons as defining 
> > > > > a macro is.
> > > > I kinda waffled on this myself. My thought was to treat this similarly 
> > > > to how we handle the macro redefinition warning. If you `undef`, you're 
> > > > kind of claiming the macro as your own and all bets are off...
> > > > 
> > > > That said, my next clang extension closes that loop hole too:
> > > > https://github.com/llvm-beanz/llvm-project/commit/f0a5216e18f5ee0883039095169bd380295b1de0
> > > So `header_unsafe` is "diagnose if someone expands this macro from 
> > > outside the main source file" and `final` is "diagnose if someone defines 
> > > or undefines this macro anywhere", correct? Would it make sense to have a 
> > > shorthand to combine these effects for a "fully reserved" macro 
> > > identifier (`#pragma clang reserve_macro(IDENT[, msg])` as a strawman)?
> > My thought process for implementing them separately was that final would be 
> > useful independent of header_unsafe. I could, for example, see applying 
> > final to macros like MIN and MAX, where they can be safely used anywhere, 
> > but you really don’t want multiple definitions floating around. 
> FWIW, I agree that having separation is useful -- I think these serve 
> orthogonal (but related) purposes: macros which can only be used by "user 
> code", and macros which cannot be redefined or undefined. I was thinking that 
> would be an additional pragma instead of a replacement for the two proposed.
> 
> I should probably tell you my use cases so we're both on the same page. One 
> of the most frustrating problems with trying to write a highly portable 
> library is the fact that I have to worry about users defining macros that may 
> conflict with my identifiers (like function names, structure names, template 
> names, etc), but I have no way to reserve those identifiers. I'm hopeful we 
> can find a way that I can "protect" those identifiers in a library with an 
> extension that basically says "you can't use these identifiers for macro 
> purposes without breaking me". I think that's a combination of 
> `header_unsafe` and `final` -- I don't want other libraries to start using 
> macros with the names of my library's functions if my header has been 
> included somewhere, and I don't want user code defining macros that may 
> conflict with my library.
Ah! That makes perfect sense. I think I misunderstood your comment. Totally 
agree, having a shorthand that groups both together would be super useful. I 
suspect we'll have some uses where we will want both `final` and 
`header_unsafe` too!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-08-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D69764#2936827 , 
@HazardyKnusperkeks wrote:

> First off, I think it should be configured in a different way, to prepare the 
> path for also formatting static, inline, etc.

To be honest I think if we wanted to do that we could do so by extending the 
"CVQualifierOrder" to support more keywords (To be honest I think the original 
requirement is mainly for const, I concede on the volatile as for the others I 
think I'd want to see how we get on in order to reduce the complexity. but it 
would be fun to try I guess!)

> If this is kept there should be tests on what happens if there is const or 
> volatile more than once in the string list, and when there are typos. Should 
> there be a command line warning on a typo or an unsupported identifier is in 
> the list?

Typos would be ignored by the "if", duplicates  well that would impact because 
the keywords push though themselves hence the reversing based on direction.

I guess we COULD validate the options, but I think that would make the 
.clang-format file not very future proof if I check that it only contains 
"const volatile", let me check if other options every validate themselves in 
quite the same way.

(but I take your point), as always , thank you for the quick review 
@HazardyKnusperkeks


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

https://reviews.llvm.org/D69764

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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-08-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

> In D69764#2936827 , 
> @HazardyKnusperkeks wrote:
>
>> First off, I think it should be configured in a different way, to prepare 
>> the path for also formatting static, inline, etc.

I'm wondering if I'm gravitating more and more to what @aaron.ballman said way 
back, maybe I don't even need Left and Right but instead just

  CVQualifierOrder: [ "static", "inline", "constexpr", "" ,"const", 
"volatile"] 

I wonder if I could simply split out the individual keywords as being "Left" or 
"Right" of the "" and apply different alignments to different keywords at 
the same time


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

https://reviews.llvm.org/D69764

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


[PATCH] D107095: Implement #pragma clang header_unsafe

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



Comment at: clang/docs/LanguageExtensions.rst:3916
+processed by the preprocessor after the ``#pragma`` annotation will log a
+a warning. For example:
+

May want to put something in here along the lines of: Redefining the macro or 
undefining the macro will not be diagnosed, nor will expansion of the macro 
within the main source file.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:531
+  "%select{|: %2}1">,
+  InGroup;
+

Should this get its own warning flag within the pedantic macros group? 
(Otherwise, it's awkward to try to silence this diagnostic while retaining some 
of the other ones like deprecated pragma.)



Comment at: clang/test/Lexer/Inputs/unsafe-macro-2.h:23-26
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe 
for use in headers}}
+#define UNSAFE_MACRO_2 2

beanz wrote:
> aaron.ballman wrote:
> > beanz wrote:
> > > aaron.ballman wrote:
> > > > beanz wrote:
> > > > > aaron.ballman wrote:
> > > > > > Why do we not expect warnings for these cases? I would have 
> > > > > > expected that undefining a macro is just as unsafe for ABI reasons 
> > > > > > as defining a macro is.
> > > > > I kinda waffled on this myself. My thought was to treat this 
> > > > > similarly to how we handle the macro redefinition warning. If you 
> > > > > `undef`, you're kind of claiming the macro as your own and all bets 
> > > > > are off...
> > > > > 
> > > > > That said, my next clang extension closes that loop hole too:
> > > > > https://github.com/llvm-beanz/llvm-project/commit/f0a5216e18f5ee0883039095169bd380295b1de0
> > > > So `header_unsafe` is "diagnose if someone expands this macro from 
> > > > outside the main source file" and `final` is "diagnose if someone 
> > > > defines or undefines this macro anywhere", correct? Would it make sense 
> > > > to have a shorthand to combine these effects for a "fully reserved" 
> > > > macro identifier (`#pragma clang reserve_macro(IDENT[, msg])` as a 
> > > > strawman)?
> > > My thought process for implementing them separately was that final would 
> > > be useful independent of header_unsafe. I could, for example, see 
> > > applying final to macros like MIN and MAX, where they can be safely used 
> > > anywhere, but you really don’t want multiple definitions floating around. 
> > FWIW, I agree that having separation is useful -- I think these serve 
> > orthogonal (but related) purposes: macros which can only be used by "user 
> > code", and macros which cannot be redefined or undefined. I was thinking 
> > that would be an additional pragma instead of a replacement for the two 
> > proposed.
> > 
> > I should probably tell you my use cases so we're both on the same page. One 
> > of the most frustrating problems with trying to write a highly portable 
> > library is the fact that I have to worry about users defining macros that 
> > may conflict with my identifiers (like function names, structure names, 
> > template names, etc), but I have no way to reserve those identifiers. I'm 
> > hopeful we can find a way that I can "protect" those identifiers in a 
> > library with an extension that basically says "you can't use these 
> > identifiers for macro purposes without breaking me". I think that's a 
> > combination of `header_unsafe` and `final` -- I don't want other libraries 
> > to start using macros with the names of my library's functions if my header 
> > has been included somewhere, and I don't want user code defining macros 
> > that may conflict with my library.
> Ah! That makes perfect sense. I think I misunderstood your comment. Totally 
> agree, having a shorthand that groups both together would be super useful. I 
> suspect we'll have some uses where we will want both `final` and 
> `header_unsafe` too!
Excellent! FWIW, I don't think the combined pragma has any impact on the 
behavior of this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

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


[PATCH] D107002: [PowerPC] Implement XL compatibility builtin __addex

2021-08-10 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 365480.
lei marked 2 inline comments as done.
lei added a comment.

update sema check condition and remove duplicate tc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107002

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-64bit.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/P9InstrResources.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
@@ -29,3 +29,14 @@
   ret double %0
 }
 declare double @llvm.ppc.insert.exp(double, i64)
+
+declare i64 @llvm.ppc.addex(i64, i64, i32 immarg)
+define dso_local i64 @call_addex_0(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_0:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
Index: llvm/lib/Target/PowerPC/PPCInstr64Bit.td
===
--- llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+++ llvm/lib/Target/PowerPC/PPCInstr64Bit.td
@@ -1670,6 +1670,13 @@
  "hashchkp $RB, $D_RA_XD", IIC_IntGeneral, []>;
 }
 
+let Interpretation64Bit = 1, isCodeGenOnly = 1, hasSideEffects = 1 in
+def ADDEX8 : Z23Form_RTAB5_CY2<31, 170, (outs g8rc:$rT),
+  (ins g8rc:$rA, g8rc:$rB, u2imm:$CY),
+  "addex $rT, $rA, $rB, $CY", IIC_IntGeneral,
+  [(set i64:$rT, (int_ppc_addex i64:$rA, i64:$rB,
+timm:$CY))]>;
+
 //===--===//
 // Instruction Patterns
 //
Index: llvm/lib/Target/PowerPC/P9InstrResources.td
===
--- llvm/lib/Target/PowerPC/P9InstrResources.td
+++ llvm/lib/Target/PowerPC/P9InstrResources.td
@@ -1430,5 +1430,6 @@
   DCBI,
   DCCCI,
   ICCCI,
-  ADDEX
+  ADDEX,
+  ADDEX8
 )> { let Unsupported = 1; }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1706,7 +1706,10 @@
   def int_ppc_fres
   : GCCBuiltin<"__builtin_ppc_fres">,
 Intrinsic <[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
-  
+  def int_ppc_addex
+  : GCCBuiltin<"__builtin_ppc_addex">,
+Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i32_ty],
+  [IntrNoMem, IntrHasSideEffects, ImmArg>]>;
   def int_ppc_fsel : GCCBuiltin<"__builtin_ppc_fsel">,
  Intrinsic<[llvm_double_ty], [llvm_double_ty, llvm_double_ty, 
   llvm_double_ty], [IntrNoMem]>;
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
@@ -0,0 +1,11 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -target-cpu pwr9 \
+// RUN:   -verify %s
+
+extern unsigned long long ull;
+extern long long ll;
+
+void test_builtin_ppc_addex() {
+  long long res = __builtin_ppc_addex(ll, ll, 1); // expected-warning {{argument value 1 will result in undefined behaviour}}
+  unsigned long long res2 = __builtin_ppc_addex(ull, ull, 3); // expected-warning {{argument value 3 will result in undefined behaviour}}
+}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
@@ -9,7 +9,18 @@
 // RUN:   -fsyntax-only -Wall -Werror -verify %s
 
 extern unsigned int ui;
+extern unsigned long long ull;
+extern long long ll;
 
 void test_builtin_ppc_cmprb() {
   int res = __builtin_ppc_cmprb(3, ui, ui); // expected-error {{argument value 3 is outside the valid range [0, 1]}}
 }
+
+#ifdef __PPC64__
+
+void test_builtin_ppc_addex() {
+  long long res = __builtin_ppc_addex(ll, ll, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  unsigned long long res2 = __builtin_ppc_addex(ull, ull, -1); // expected-err

[PATCH] D107825: [AIX] Define __HOS_AIX__ macro only for AIX target

2021-08-10 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg accepted this revision.
joerg added a comment.
This revision is now accepted and ready to land.

LGTM. Maybe include a small hint in the commit message that xlC never shipped 
cross-compiling support and the difference is therefore not observable anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107825

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


[PATCH] D107002: [PowerPC] Implement XL compatibility builtin __addex

2021-08-10 Thread Lei Huang via Phabricator via cfe-commits
lei added inline comments.



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c:4
+// RUN:   -verify %s
+
+extern unsigned long long ull;

NeHuang wrote:
> can we also add the run lines for 64 bit LE Linux, 64 bit AIX and 32 bit AIX? 
>  Will also need `#ifdef __PPC64__` for the test case. 
AFAIK there is no difference between LE and BE for sema checking and it'll be 
overkill to add the `ifdef` since the only run line in here is for 64bit 
compilation.  I think that can be added later if there are needs for 32bit 
testcases later?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107002

___
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-10 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm added a comment.

> Given that we have a legacy XL macro with no legacy cross compiler I think 
> it's fine if we set this according to the target only.  It's fully redundant 
> to `_AIX ` but we'll define it for any working use-case with the current xlC 
> compiler.  If IBM has a compelling use case for a host-specific macro we can 
> always revive this discussion.  For now, you're probably making us from 
> making a mistake ;)

follow up in https://reviews.llvm.org/D107825


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] 638dcea - [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-08-10 Thread Alex Orlov via cfe-commits

Author: Alex Orlov
Date: 2021-08-10T19:20:50+04:00
New Revision: 638dcea010cfc280f428d0cc13f4aa8578a1d69d

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

LOG: [clang] Implement P0692R1 from C++20 (access checking on specializations 
and instantiations)

This patch implements paper P0692R1 from the C++20 standard. Disable usual 
access checking rules to template argument names in a declaration of partial 
specializations, explicit instantiation or explicit specialization (C++20 
13.7.5/10, 13.9.1/6).
Fixes: https://llvm.org/PR37424
This patch also implements option *A* from this paper P0692R1 from the C++20 
standard.
This patch follows the @rsmith suggestion from D78404.

Reviewed By: krisb

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

Added: 
clang/test/CXX/temp/temp.spec/func.spec.cpp
clang/test/CXX/temp/temp.spec/part.spec.cpp

Modified: 
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/test/CXX/class.access/class.friend/p1.cpp
clang/test/CXX/drs/dr1xx.cpp
clang/test/CXX/temp/temp.spec/temp.explicit/p12.cpp

Removed: 
clang/test/CXX/temp/temp.spec/temp.explicit/p11.cpp



diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 939323517b4d5..2b19ade185af4 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3091,6 +3091,12 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
   return true;
 };
 
+// Turn off usual access checking for template specializations and
+// instantiations.
+bool IsTemplateSpecOrInst =
+(TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
+ TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
+
 switch (Tok.getKind()) {
 default:
 DoneWithDeclSpec:
@@ -3261,6 +3267,12 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
   isConstructorDeclarator(/*Unqualified*/ false))
 goto DoneWithDeclSpec;
 
+  // C++20 [temp.spec] 13.9/6.
+  // This disables the access checking rules for function template explicit
+  // instantiation and explicit specialization:
+  // - `return type`.
+  SuppressAccessChecks SAC(*this, IsTemplateSpecOrInst);
+
   ParsedType TypeRep =
   Actions.getTypeName(*Next.getIdentifierInfo(), Next.getLocation(),
   getCurScope(), &SS, false, false, nullptr,
@@ -3268,6 +3280,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
   /*WantNontrivialTypeSourceInfo=*/true,
   isClassTemplateDeductionContext(DSContext));
 
+  if (IsTemplateSpecOrInst)
+SAC.done();
+
   // If the referenced identifier is not a type, then this declspec is
   // erroneous: We already checked about that it has no type specifier, and
   // C++ doesn't have implicit int.  Diagnose it as a typo w.r.t. to the
@@ -3377,10 +3392,24 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
   // In C++, check to see if this is a scope specifier like foo::bar::, if
   // so handle it as such.  This is important for ctor parsing.
   if (getLangOpts().CPlusPlus) {
-if (TryAnnotateCXXScopeToken(EnteringContext)) {
+// C++20 [temp.spec] 13.9/6.
+// This disables the access checking rules for function template
+// explicit instantiation and explicit specialization:
+// - `return type`.
+SuppressAccessChecks SAC(*this, IsTemplateSpecOrInst);
+
+const bool Success = TryAnnotateCXXScopeToken(EnteringContext);
+
+if (IsTemplateSpecOrInst)
+  SAC.done();
+
+if (Success) {
+  if (IsTemplateSpecOrInst)
+SAC.redelay();
   DS.SetTypeSpecError();
   goto DoneWithDeclSpec;
 }
+
 if (!Tok.is(tok::identifier))
   continue;
   }

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index bf01099f5f5ce..a4bfb0d6f4e25 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1474,19 +1474,15 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
 return;
   }
 
-  // C++03 [temp.explicit] 14.7.2/8:
-  //   The usual access checking rules do not apply to names used to specify
-  //   explicit instantiations.
-  //
-  // As an extension we do not perform access checking on the names used to
-  // specify explicit specializations either. This is important to allow
-  // specializing traits classes for private types.
-  //
-  // Note that we don't suppress if this turns out to be an elaborated
-  // type specifier.
-  bool shouldDelayDiagsInTag =
-(TemplateInfo.Kind == ParsedTemplateI

[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-08-10 Thread Alex Orlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG638dcea010cf: [clang] Implement P0692R1 from C++20 (access 
checking on specializations and… (authored by aorlov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/CXX/class.access/class.friend/p1.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/temp/temp.spec/func.spec.cpp
  clang/test/CXX/temp/temp.spec/part.spec.cpp
  clang/test/CXX/temp/temp.spec/temp.explicit/p11.cpp
  clang/test/CXX/temp/temp.spec/temp.explicit/p12.cpp

Index: clang/test/CXX/temp/temp.spec/temp.explicit/p12.cpp
===
--- clang/test/CXX/temp/temp.spec/temp.explicit/p12.cpp
+++ clang/test/CXX/temp/temp.spec/temp.explicit/p12.cpp
@@ -43,7 +43,14 @@
 Temp(int x) {}
   };
 
-  template <> class Temp Temp::make() { // expected-error {{'Private' is a private member of 'test2::A'}}
+  template <> class Temp Temp::make() {
 return Temp(0);
   }
+
+  template <>
+  class Temp {
+static Temp make() { // expected-error {{is a private member}}
+  return Temp(0);
+}
+  };
 }
Index: clang/test/CXX/temp/temp.spec/temp.explicit/p11.cpp
===
--- clang/test/CXX/temp/temp.spec/temp.explicit/p11.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
-
-class X {
-  template  class Y {};
-};
-
-class A {
-  class B {};
-  class C {};
-};
-
-// C++0x [temp.explicit] 14.7.2/11:
-//   The usual access checking rules do not apply to names used to specify
-//   explicit instantiations.
-template class X::Y;
-
-// As an extension, this rule is applied to explicit specializations as well.
-template <> class X::Y {};
Index: clang/test/CXX/temp/temp.spec/part.spec.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.spec/part.spec.cpp
@@ -0,0 +1,481 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// C++20 [temp.class.spec] 13.7.5/10
+//   The usual access checking rules do not apply to non-dependent names
+//   used to specify template arguments of the simple-template-id of the
+//   partial specialization.
+//
+// C++20 [temp.spec] 13.9/6:
+//   The usual access checking rules do not apply to names in a declaration
+//   of an explicit instantiation or explicit specialization...
+
+// TODO: add test cases for `enum`
+
+// class for tests
+class TestClass {
+public:
+  class PublicClass {};
+  template  class TemplatePublicClass {};
+
+  using AliasPublicClass = unsigned char;
+
+  void publicFunc();
+  void publicFuncOverloaded();
+  void publicFuncOverloaded(int);
+
+  static void publicStaticFunc();
+  static void publicStaticFuncOverloaded();
+  static void publicStaticFuncOverloaded(int);
+
+  static constexpr int publicStaticInt = 42;
+
+protected:
+  // expected-note@+1 8{{declared protected here}}
+  class ProtectedClass {};
+  template  class TemplateProtectedClass {};
+
+  // expected-note@+1 2{{declared protected here}}
+  using AliasProtectedClass = const char;
+
+  // expected-note@+1 3{{declared protected here}}
+  void protectedFunc();
+  void protectedFuncOverloaded();
+  void protectedFuncOverloaded(int);
+
+  // expected-note@+1 2{{declared protected here}}
+  static void protectedStaticFunc();
+  // expected-note@+1 2{{declared protected here}}
+  static void protectedStaticFuncOverloaded();
+  static void protectedStaticFuncOverloaded(int);
+
+  // expected-note@+1 2{{declared protected here}}
+  static constexpr int protectedStaticInt = 43;
+
+private:
+  // expected-note@+1 10{{declared private here}}
+  class PrivateClass {};
+  // expected-note@+1 {{declared private here}}
+  template  class TemplatePrivateClass {};
+
+  using AliasPrivateClass = char *;
+
+  void privateFunc();
+  void privateFuncOverloaded();
+  void privateFuncOverloaded(int);
+
+  static void privateStaticFunc();
+  static void privateStaticFuncOverloaded();
+  static void privateStaticFuncOverloaded(int);
+
+  static constexpr int privateStaticInt = 44;
+};
+
+void globalFunction() {}
+
+//--//
+
+// template declarations for explicit instantiations
+template  class IT1 {};
+template  class IT2 {};
+template  class IT3 {};
+template  class IT4 {};
+template  class IT5 {};
+template  class IT6 {
+  template  class NIT1 {};
+};
+template  class IT7 {};
+template  class IT8 {};
+template  class IT9 {};
+
+// explicit instantiations
+
+// public
+template class IT1;
+template struct IT1>;
+template class IT1;
+template struct IT2;
+template class IT3;
+template struct IT4<&TestClass::publicFunc>;
+template class IT4<&TestClass::publicFuncOverloaded>;
+templ

[PATCH] D107095: Implement #pragma clang header_unsafe

2021-08-10 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 365487.
beanz added a comment.

Updated docs, added header-unsafe-macro diag group, and added test case to 
verify that the -Wpedantic-macros warnings don't trip on eachother.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/Inputs/pedantic-macro-interplay.h
  clang/test/Lexer/Inputs/unsafe-macro-2.h
  clang/test/Lexer/Inputs/unsafe-macro.h
  clang/test/Lexer/pedantic-macro-interplay.c
  clang/test/Lexer/unsafe-macro.c

Index: clang/test/Lexer/unsafe-macro.c
===
--- /dev/null
+++ clang/test/Lexer/unsafe-macro.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Wheader-unsafe-macro %s -fsyntax-only -verify
+#include "Inputs/unsafe-macro.h"
+#include "Inputs/unsafe-macro-2.h"
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
Index: clang/test/Lexer/pedantic-macro-interplay.c
===
--- /dev/null
+++ clang/test/Lexer/pedantic-macro-interplay.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wpedantic-macros %s -fsyntax-only -verify
+
+// This test verifies that the -Wpedantic-macros warnings don't fire in the
+// annotation pragmas themselves. This ensures you can annotate macros with
+// more than one of the pragmas without spewing warnings all over the code.
+
+#include "Inputs/pedantic-macro-interplay.h"
+
+#define UNSAFE_MACRO_2 1
+#pragma clang deprecated(UNSAFE_MACRO_2, "Don't use this!")
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as deprecated: Don't use this!}}
+#pragma clang header_unsafe(UNSAFE_MACRO_2, "Don't use this!")
+
+// expected-no-diagnostics
Index: clang/test/Lexer/Inputs/unsafe-macro.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro.h
@@ -0,0 +1,27 @@
+// expected-error@+1{{expected (}}
+#pragma clang header_unsafe
+
+// expected-error@+1{{expected identifier}}
+#pragma clang header_unsafe(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang header_unsafe(foo)
+
+
+#define UNSAFE_MACRO 1
+// expected-note@+8{{macro marked 'header_unsafe' here}}
+// expected-note@+7{{macro marked 'header_unsafe' here}}
+// expected-note@+6{{macro marked 'header_unsafe' here}}
+// expected-note@+5{{macro marked 'header_unsafe' here}}
+// expected-note@+4{{macro marked 'header_unsafe' here}}
+// expected-note@+3{{macro marked 'header_unsafe' here}}
+// expected-note@+2{{macro marked 'header_unsafe' here}}
+// expected-note@+1{{macro marked 'header_unsafe' here}} 
+#pragma clang header_unsafe(UNSAFE_MACRO, "Don't use this!")
+
+#define UNSAFE_MACRO_2 2
+// expected-note@+1{{macro marked 'header_unsafe' here}}
+#pragma clang header_unsafe(UNSAFE_MACRO_2)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(UNSAFE_MACRO
Index: clang/test/Lexer/Inputs/unsafe-macro-2.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro-2.h
@@ -0,0 +1,70 @@
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if defined(UNSAFE_MACRO)
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifdef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifndef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+const int x = UNSAFE_MACRO;
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int y = UNSAFE_MACRO_2;
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#define UNSAFE_MACRO_2 2
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int z = UNSAFE_MACRO_2;
+
+
+// Test that we diagnose on #elif.
+#if 0
+#elif UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef UNSAFE_MACRO
+// expected-war

[PATCH] D107696: [CodeComplete] Basic code completion for attribute names.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 365490.
sammccall added a comment.
Herald added subscribers: sstefan1, krytarowski.
Herald added a reviewer: jdoerfert.

Add support and tests for underscore-guarding.
Add tests that omp attributes are not supported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107696

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/attr.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp

Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -541,6 +541,7 @@
 case CodeCompletionContext::CCC_MacroName:
 case CodeCompletionContext::CCC_PreprocessorExpression:
 case CodeCompletionContext::CCC_PreprocessorDirective:
+case CodeCompletionContext::CCC_Attribute:
 case CodeCompletionContext::CCC_TypeQualifiers: {
   //Only Clang results should be accepted, so we'll set all of the other
   //context bits to 0 (i.e. the empty set)
Index: clang/test/CodeCompletion/attr.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/attr.cpp
@@ -0,0 +1,88 @@
+int a [[gnu::used]];
+// RUN: %clang_cc1 -code-completion-at=%s:1:9 %s | FileCheck --check-prefix=STD %s
+// STD: COMPLETION: __carries_dependency__
+// STD-NOT: COMPLETION: __convergent__
+// STD: COMPLETION: __gnu__::__used__
+// STD-NOT: COMPLETION: __gnu__::used
+// STD-NOT: COMPLETION: __used__
+// STD: COMPLETION: _Clang::__convergent__
+// STD: COMPLETION: carries_dependency
+// STD: COMPLETION: clang::convergent
+// STD-NOT: COMPLETION: convergent
+// STD-NOT: COMPLETION: gnu::__used__
+// STD: COMPLETION: gnu::used
+// STD-NOT: COMPLETION: used
+// RUN: %clang_cc1 -code-completion-at=%s:1:14 %s | FileCheck --check-prefix=STD-NS %s
+// STD-NS-NOT: COMPLETION: __used__
+// STD-NS-NOT: COMPLETION: carries_dependency
+// STD-NS-NOT: COMPLETION: clang::convergent
+// STD-NS-NOT: COMPLETION: convergent
+// STD-NS-NOT: COMPLETION: gnu::used
+// STD-NS: COMPLETION: used
+int b [[__gnu__::used]];
+// RUN: %clang_cc1 -code-completion-at=%s:22:18 %s | FileCheck --check-prefix=STD-NSU %s
+// STD-NSU: COMPLETION: __used__
+// STD-NSU-NOT: COMPLETION: used
+
+int c [[using gnu: used]];
+// RUN: %clang_cc1 -code-completion-at=%s:27:15 %s | FileCheck --check-prefix=STD-USING %s
+// STD-USING: COMPLETION: __gnu__
+// STD-USING: COMPLETION: _Clang
+// STD-USING-NOT: COMPLETION: carries_dependency
+// STD-USING: COMPLETION: clang
+// STD-USING-NOT: COMPLETION: clang::
+// STD-USING-NOT: COMPLETION: gnu::
+// STD-USING: COMPLETION: gnu
+// RUN: %clang_cc1 -code-completion-at=%s:27:20 %s | FileCheck --check-prefix=STD-NS %s
+
+int d __attribute__((used));
+// RUN: %clang_cc1 -code-completion-at=%s:38:22 %s | FileCheck --check-prefix=GNU %s
+// GNU: COMPLETION: __carries_dependency__
+// GNU: COMPLETION: __convergent__
+// GNU-NOT: COMPLETION: __gnu__::__used__
+// GNU: COMPLETION: __used__
+// GNU-NOT: COMPLETION: _Clang::__convergent__
+// GNU: COMPLETION: carries_dependency
+// GNU-NOT: COMPLETION: clang::convergent
+// GNU: COMPLETION: convergent
+// GNU-NOT: COMPLETION: gnu::used
+// GNU: COMPLETION: used
+
+#pragma clang attribute push (__attribute__((internal_linkage)), apply_to=variable)
+int e;
+#pragma clang attribute pop
+// RUN: %clang_cc1 -code-completion-at=%s:51:46 %s | FileCheck --check-prefix=PRAGMA %s
+// PRAGMA: internal_linkage
+
+#ifdef MS_EXT
+int __declspec(thread) f;
+// RUN: %clang_cc1 -fms-extensions -DMS_EXT -code-completion-at=%s:58:16 %s | FileCheck --check-prefix=DS %s
+// DS-NOT: COMPLETION: __convergent__
+// DS-NOT: COMPLETION: __used__
+// DS-NOT: COMPLETION: clang::convergent
+// DS-NOT: COMPLETION: convergent
+// DS: COMPLETION: thread
+// DS-NOT: COMPLETION: used
+// DS: COMPLETION: uuid
+
+[uuid("123e4567-e89b-12d3-a456-426614174000")] struct g;
+// RUN: %clang_cc1 -fms-extensions -DMS_EXT -code-completion-at=%s:68:2 %s | FileCheck --check-prefix=MS %s
+// MS-NOT: COMPLETION: __uuid__
+// MS-NOT: COMPLETION: clang::convergent
+// MS-NOT: COMPLETION: convergent
+// MS-NOT: COMPLETION: thread
+// MS-NOT: COMPLETION: used
+// MS: COMPLETION: uuid
+#endif // MS_EXT
+
+void foo() {
+  [[omp::sequence(directive(parallel), directive(critical))]]
+  {}
+}
+// FIXME: support 

[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

2021-08-10 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.

This generally LGTM but the only other thing I'm wondering is whether there 
should be any clang-specific testing for this functionality. Right now, it 
relies on running the clangd unit tests to notice failures and that's not ideal 
because not everyone builds clang-tools-extra as part of their usual Clang 
development. However, given that this functionality isn't really *used* by 
Clang, I'm not certain there's much to test and there's not a whole lot of 
failure mode beyond "the file didn't get generated".

So giving this my LGTM, but if you think of a way to introduce clang-specific 
tests for this, I'm happy to do further review.




Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:4220
+  )cpp";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {

sammccall wrote:
> aaron.ballman wrote:
> > FWIW, this will miss `omp::sequence` and `omp::directive`, but that's not 
> > the end of the world. May be worth a fixme comment in case we want to solve 
> > it someday.
> Well, those
>  - don't themselves have Attr nodes or AttrKinds, so the API couldn't query 
> for them
>  - don't actually have any documentation as far as I can tell
> So I'm not sure there's much to fix.
> 
> ---
> 
> The ParsedAttr-kind vs Attr-kind distinction, and the fact that many 
> attributes don't leave any AST nodes at all, mean this method doesn't seem 
> "universal". But the goal is to show docs in clangd when hovering on an 
> attribute (which we only support for those with AST nodes).
> 
> If we want to do something different (like show documenation while 
> code-completing) we'll probably have to add a second ParsedAttrKind-based API.
> So I'm not sure there's much to fix.

The big reason they're not documented is because I've not thought of a good way 
to expose the documentation via AttrDocs.td. Currently, that documentation 
needs the attributes to live in Attr.td, and we don't expose the attributes 
there because we have no way to express their arguments.

At some point in the future, I expect we'll make these two attributes "more 
normal" by getting them into Attr.td and AttrDocs.td, and at that point this 
probably fixes itself? So I think you're right, maybe not much to fix *here*.





Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:4242
+  llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
+assert(K < llvm::array_lengthof(AttrDoc));
+return AttrDoc[K];

sammccall wrote:
> aaron.ballman wrote:
> > H, I am not 100% certain this assertion is correct -- the user may have 
> > plugin attributes, which I believe are given a "kind" that's larger than 
> > the last-known builtin attribute kind.
> Thanks, changed it to an if() instead.
> (I don't think it's particularly pressing to allow them to be documented)
Agreed that we can figure out how to let plugin attributes add documentation at 
a later date.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

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


[PATCH] D107717: [LLVM][CMake][NFC] Resolve FIXME: Rename LLVM_CMAKE_PATH to LLVM_CMAKE_DIR throughout the project

2021-08-10 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit added a comment.

So does that mean this is ready to land?


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

https://reviews.llvm.org/D107717

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


[PATCH] D107836: [Attributes]: refactor to expose ParsedAttrInfo::acceptsLangOpts. NFC

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: aaron.ballman.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We will use this function to filter code completion of attributes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107836

Files:
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Sema/ParsedAttr.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3803,14 +3803,8 @@
   if (LangOpts.empty())
 return;
 
-  OS << "bool diagLangOpts(Sema &S, const ParsedAttr &Attr) ";
-  OS << "const override {\n";
-  OS << "  auto &LangOpts = S.LangOpts;\n";
-  OS << "  if (" << GenerateTestExpression(LangOpts) << ")\n";
-  OS << "return true;\n\n";
-  OS << "  S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) ";
-  OS << "<< Attr;\n";
-  OS << "  return false;\n";
+  OS << "bool acceptsLangOpts(const LangOptions &LangOpts) const override {\n";
+  OS << "  return " << GenerateTestExpression(LangOpts) << ";\n";
   OS << "}\n\n";
 }
 
Index: clang/lib/Sema/ParsedAttr.cpp
===
--- clang/lib/Sema/ParsedAttr.cpp
+++ clang/lib/Sema/ParsedAttr.cpp
@@ -180,7 +180,10 @@
 }
 
 bool ParsedAttr::diagnoseLangOpts(Sema &S) const {
-  return getInfo().diagLangOpts(S, *this);
+  if (getInfo().acceptsLangOpts(S.getLangOpts()))
+return true;
+  S.Diag(getLoc(), diag::warn_attribute_ignored) << *this;
+  return false;
 }
 
 bool ParsedAttr::isTargetSpecificAttr() const {
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -92,11 +92,9 @@
const Decl *D) const {
 return true;
   }
-  /// Check if this attribute is allowed by the language we are compiling, and
-  /// issue a diagnostic if not.
-  virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
-return true;
-  }
+  /// Check if this attribute is allowed by the language we are compiling.
+  virtual bool acceptsLangOpts(const LangOptions &LO) const { return true; }
+
   /// Check if this attribute is allowed when compiling for the given target.
   virtual bool existsInTarget(const TargetInfo &Target) const {
 return true;


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3803,14 +3803,8 @@
   if (LangOpts.empty())
 return;
 
-  OS << "bool diagLangOpts(Sema &S, const ParsedAttr &Attr) ";
-  OS << "const override {\n";
-  OS << "  auto &LangOpts = S.LangOpts;\n";
-  OS << "  if (" << GenerateTestExpression(LangOpts) << ")\n";
-  OS << "return true;\n\n";
-  OS << "  S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) ";
-  OS << "<< Attr;\n";
-  OS << "  return false;\n";
+  OS << "bool acceptsLangOpts(const LangOptions &LangOpts) const override {\n";
+  OS << "  return " << GenerateTestExpression(LangOpts) << ";\n";
   OS << "}\n\n";
 }
 
Index: clang/lib/Sema/ParsedAttr.cpp
===
--- clang/lib/Sema/ParsedAttr.cpp
+++ clang/lib/Sema/ParsedAttr.cpp
@@ -180,7 +180,10 @@
 }
 
 bool ParsedAttr::diagnoseLangOpts(Sema &S) const {
-  return getInfo().diagLangOpts(S, *this);
+  if (getInfo().acceptsLangOpts(S.getLangOpts()))
+return true;
+  S.Diag(getLoc(), diag::warn_attribute_ignored) << *this;
+  return false;
 }
 
 bool ParsedAttr::isTargetSpecificAttr() const {
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -92,11 +92,9 @@
const Decl *D) const {
 return true;
   }
-  /// Check if this attribute is allowed by the language we are compiling, and
-  /// issue a diagnostic if not.
-  virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
-return true;
-  }
+  /// Check if this attribute is allowed by the language we are compiling.
+  virtual bool acceptsLangOpts(const LangOptions &LO) const { return true; }
+
   /// Check if this attribute is allowed when compiling for the given target.
   virtual bool existsInTarget(const TargetInfo &Target) const {
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107837: abseil-string-find-str-contains should not propose an edit for the three-parameter version of find().

2021-08-10 Thread Tom Lokovic via Phabricator via cfe-commits
tdl-g created this revision.
tdl-g added a reviewer: ymandel.
tdl-g requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

std::string, std::string_view, and absl::string_view all have a three-parameter 
version of find()
which has a "count" (or "n") paremeter limiting the size of the substring to 
search.  We don't want
to propose changing to absl::StrContains in those cases.  This change fixes 
that and adds unit tests
to confirm.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107837

Files:
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
@@ -15,6 +15,7 @@
   ~basic_string();
   int find(basic_string s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -30,6 +31,7 @@
   ~basic_string_view();
   int find(basic_string_view s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -48,6 +50,7 @@
   ~string_view();
   int find(string_view s, int pos = 0);
   int find(const char *s, int pos = 0);
+  int find(const char *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -263,6 +266,18 @@
   asv.find("a", 3) == std::string_view::npos;
 }
 
+// Confirms that it does not match when the count parameter is present.
+void no_count() {
+  std::string ss;
+  ss.find("a", 0, 1) == std::string::npos;
+
+  std::string_view ssv;
+  ssv.find("a", 0, 1) == std::string_view::npos;
+
+  absl::string_view asv;
+  asv.find("a", 0, 1) == std::string_view::npos;
+}
+
 // Confirms that it does not match when it's compared to something other than
 // npos, even if the value is the same as npos.
 void no_non_npos() {
Index: clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
@@ -53,7 +53,7 @@
   to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass;
   auto StringFind = cxxMemberCallExpr(
   callee(cxxMethodDecl(
-  hasName("find"),
+  hasName("find"), parameterCountIs(2),
   hasParameter(
   0, parmVarDecl(anyOf(hasType(StringType), hasType(CharStarType),
hasType(CharType)),


Index: clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
@@ -15,6 +15,7 @@
   ~basic_string();
   int find(basic_string s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -30,6 +31,7 @@
   ~basic_string_view();
   int find(basic_string_view s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -48,6 +50,7 @@
   ~string_view();
   int find(string_view s, int pos = 0);
   int find(const char *s, int pos = 0);
+  int find(const char *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -263,6 +266,18 @@
   asv.find("a", 3) == std::string_view::npos;
 }
 
+// Confirms that it does not match when the count parameter is present.
+void no_count() {
+  std::string ss;
+  ss.find("a", 0, 1) == std::string::npos;
+
+  std::string_view ssv;
+  ssv.find("a", 0, 1) == std::string_view::npos;
+
+  absl::string_view asv;
+  asv.find("a", 0, 1) == std::string_view::npos;
+}
+
 // Confirms that it does not match when it's compared to something other than
 // npos, even if the value is the same as npos.
 void no_non_npos() {
Index: clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
@@ -53,7 +53,7 @@
   to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass;
   auto StringFind = cxxMemberCallExpr(
   c

[PATCH] D107668: [OpenMP]Fix PR50336: Remove temporary files in the offload bundler tool

2021-08-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Why the else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107668

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


[PATCH] D107668: [OpenMP]Fix PR50336: Remove temporary files in the offload bundler tool

2021-08-10 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D107668#2937230 , @jdoerfert wrote:

> Why the else?

If this input isn't an OffloadingAction then it is a `.o` file which we already 
list as a temporary file. If it was an OffloadingAction then we have an extra 
device-specific filename like `.cubin` that we don't automatically list as a 
temporary file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107668

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


[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

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

In D107703#2937183 , @aaron.ballman 
wrote:

> This generally LGTM but the only other thing I'm wondering is whether there 
> should be any clang-specific testing

Makes sense. Here the "clang feature" is just the API, so I've added a very 
basic unittest for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

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


[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 365499.
sammccall added a comment.

add unit test for getDocumentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/Attr.h
  clang/lib/AST/CMakeLists.txt
  clang/unittests/AST/CMakeLists.txt
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -61,6 +61,7 @@
llvm::raw_ostream &OS);
 void EmitClangAttrNodeTraverse(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
+void EmitClangAttrDocTable(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 
 void EmitClangDiagsDefs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS,
 const std::string &Component);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -30,6 +30,7 @@
   GenClangAttrSubjectMatchRulesParserStringSwitches,
   GenClangAttrImpl,
   GenClangAttrList,
+  GenClangAttrDocTable,
   GenClangAttrSubjectMatchRuleList,
   GenClangAttrPCHRead,
   GenClangAttrPCHWrite,
@@ -115,6 +116,8 @@
"Generate clang attribute implementations"),
 clEnumValN(GenClangAttrList, "gen-clang-attr-list",
"Generate a clang attribute list"),
+clEnumValN(GenClangAttrDocTable, "gen-clang-attr-doc-table",
+   "Generate a table of attribute documentation"),
 clEnumValN(GenClangAttrSubjectMatchRuleList,
"gen-clang-attr-subject-match-rule-list",
"Generate a clang attribute subject match rule list"),
@@ -280,6 +283,9 @@
   case GenClangAttrList:
 EmitClangAttrList(Records, OS);
 break;
+  case GenClangAttrDocTable:
+EmitClangAttrDocTable(Records, OS);
+break;
   case GenClangAttrSubjectMatchRuleList:
 EmitClangAttrSubjectMatchRuleList(Records, OS);
 break;
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4210,6 +4210,42 @@
   getPragmaAttributeSupport(Records).generateParsingHelpers(OS);
 }
 
+void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
+  emitSourceFileHeader("Clang attribute documentation", OS);
+
+  OS << R"cpp(
+  #include "clang/AST/Attr.h"
+  #include "llvm/ADT/StringRef.h"
+  )cpp";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+if (!A->getValueAsBit("ASTNode"))
+  continue;
+std::vector Docs = A->getValueAsListOfDefs("Documentation");
+for (const auto *D : Docs) {
+  OS << "\nstatic const char AttrDoc_" << A->getName() << "[] = "
+ << "R\"reST("
+ << D->getValueAsOptionalString("Content").getValueOr("").trim()
+ << ")reST\";\n";
+  // Only look at the first documentation if there are several.
+  // (As of now, only one attribute has multiple documentation entries).
+  break;
+}
+  }
+  OS << R"cpp(
+  static const llvm::StringRef AttrDoc[] = {
+  #define ATTR(NAME) AttrDoc_##NAME,
+  #include "clang/Basic/AttrList.inc"
+  };
+
+  llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
+if(K < llvm::array_lengthof(AttrDoc))
+  return AttrDoc[K];
+return "";
+  }
+  )cpp";
+}
+
 enum class SpellingKind {
   GNU,
   CXX11,
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -15,6 +15,7 @@
   ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
   ASTVectorTest.cpp
+  AttrTest.cpp
   CommentLexer.cpp
   CommentParser.cpp
   CommentTextTest.cpp
Index: clang/lib/AST/CMakeLists.txt
===
--- clang/lib/AST/CMakeLists.txt
+++ clang/lib/AST/CMakeLists.txt
@@ -13,6 +13,11 @@
   SOURCE Interp/Opcodes.td
   TARGET Opcodes)
 
+clang_tablegen(AttrDocTable.cpp -gen-clang-attr-doc-table
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../include/
+  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../include/clang/Basic/Attr.td
+  TARGET ClangAttrDocTable)
+
 add_clang_library(clangAST
   APValue.cpp
   ASTConcept.cpp
@@ -24,6 +29,7 @@
   ASTImporterLookupTable.cpp
   ASTStructuralEquivalence.cpp
   ASTTypeTraits.cpp
+  AttrDocTable.cpp
   AttrImpl.cpp
   Comment.cpp
   CommentBriefParser.cpp
Index: clang/include/clan

[PATCH] D107775: [Clang][AST] Resolve FIXME: Remove ObjCObjectPointer from isSpecifierType

2021-08-10 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365501.
gAlfonso-bit added a comment.

Rebased to main


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

https://reviews.llvm.org/D107775

Files:
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2785,7 +2785,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2785,7 +2785,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-08-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 365502.
MyDeveloperDay added a comment.

- Add CVQualifierOrder configuration validation and unit tests


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/LeftRightConstFixer.cpp
  clang/lib/Format/LeftRightConstFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18180,6 +18180,11 @@
   EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
   EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
 
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
@@ -18277,6 +18282,24 @@
   CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
 
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+  CHECK_PARSE("CVQualifierAlignment: Leave", CVQualifierAlignment,
+  FormatStyle::CVQAS_Leave);
+  CHECK_PARSE("CVQualifierAlignment: Right", CVQualifierAlignment,
+  FormatStyle::CVQAS_Right);
+  CHECK_PARSE("CVQualifierAlignment: Left", CVQualifierAlignment,
+  FormatStyle::CVQAS_Left);
+
+  CHECK_PARSE("CVQualifierOrder: [ const, volatile]", CVQualifierOrder,
+  std::vector({"const", "volatile"}));
+  Style.CVQualifierOrder.clear();
+  CHECK_PARSE("CVQualifierOrder: [const]", CVQualifierOrder,
+  std::vector{"const"});
+  CHECK_PARSE("CVQualifierOrder: [volatile]", CVQualifierOrder,
+  std::vector{"volatile"});
+  CHECK_PARSE("CVQualifierOrder: [const, volatile]", CVQualifierOrder,
+  std::vector({"const", "volatile"}));
+
   Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
   CHECK_PARSE("AlignConsecutiveAssignments: None", AlignConsecutiveAssignments,
   FormatStyle::ACS_None);
@@ -0,6 +22243,387 @@
   "}";
   EXPECT_EQ(Code, format(Code, Style));
 }
+
+TEST_F(FormatTest, LeftRightConst) {
+  FormatStyle Style = getLLVMStyle();
+
+  // keep the const style unaltered
+  verifyFormat("const int a;", Style);
+  verifyFormat("const int *a;", Style);
+  verifyFormat("const int &a;", Style);
+  verifyFormat("const int &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("const Foo a;", Style);
+  verifyFormat("const Foo *a;", Style);
+  verifyFormat("const Foo &a;", Style);
+  verifyFormat("const Foo &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+
+  verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
+  verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
+
+  verifyFormat("volatile const int *restrict;", Style);
+  verifyFormat("const volatile int *restrict;", Style);
+  verifyFormat("const int volatile *restrict;", Style);
+}
+
+TEST_F(FormatTest, RightConst) {
+  FormatStyle Style = getLLVMStyle();
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+
+  verifyFormat("int const a;", Style);
+  verifyFormat("int const *a;", Style);
+  verifyFormat("int const &a;", Style);
+  verifyFormat("int const &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("Foo const a;", Style);
+  verifyFormat("Foo const *a;", Style);
+  verifyFormat("Foo const &a;", Style);
+  verifyFormat("Foo const &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo *const b;", Style);
+  verifyFormat("Foo const *const b;", Style);
+  verifyFormat("auto const v = get_val

[PATCH] D106152: [analyzer] Move test case to existing test file and remove duplicated test file.

2021-08-10 Thread Denys Petrov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG497b1b95e606: [analyzer] Move test case to existing test 
file and remove duplicated test file. (authored by ASDenysPetrov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106152

Files:
  clang/test/Analysis/PR46264.cpp
  clang/test/Analysis/diagnostics/PR46264.cpp


Index: clang/test/Analysis/diagnostics/PR46264.cpp
===
--- clang/test/Analysis/diagnostics/PR46264.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text 
-verify %s
-
-// PR46264
-// This case shall not crash with an assertion failure about void* 
dereferening.
-// The crash has been last seen on commit
-// `3ed8ebc2f6b8172bed48cc5986d3b7af4cfca1bc` from 24.05.2020.
-namespace ns1 {
-namespace a {
-class b {
-public:
-  typedef int b::*c;
-  operator c() { return d ? &b::d : 0; }
-  // expected-note@-1{{'?' condition is true}}
-  // expected-note@-2{{Assuming field 'd' is not equal to 0}}
-  // expected-note@-3{{Returning value, which participates in a condition 
later}}
-  int d;
-};
-} // namespace a
-using a::b;
-class e {
-  void f();
-  void g();
-  b h;
-};
-void e::f() {
-  e *i;
-  // expected-note@-1{{'i' declared without an initial value}}
-  if (h)
-// expected-note@-1{{Taking true branch}}
-// expected-note@-2{{'b::operator int ns1::a::b::*'}}
-// expected-note@-3{{Returning from 'b::operator int ns1::a::b::*'}}
-i->g();
-  // expected-note@-1{{Called C++ object pointer is uninitialized}}
-  // expected-warning@-2{{Called C++ object pointer is uninitialized}}
-}
-} // namespace ns1
Index: clang/test/Analysis/PR46264.cpp
===
--- clang/test/Analysis/PR46264.cpp
+++ clang/test/Analysis/PR46264.cpp
@@ -33,3 +33,27 @@
 
   return 10;
 }
+
+// PR46264
+// This case shall not crash with an assertion failure about void* 
dereferening.
+namespace ns1 {
+namespace a {
+class b {
+public:
+  typedef int b::*c;
+  operator c() { return d ? &b::d : 0; }
+  int d;
+};
+} // namespace a
+using a::b;
+class e {
+  void f();
+  void g();
+  b h;
+};
+void e::f() {
+  e *i;
+  if (h)
+i->g(); // expected-warning{{Called C++ object pointer is uninitialized}}
+}
+} // namespace ns1


Index: clang/test/Analysis/diagnostics/PR46264.cpp
===
--- clang/test/Analysis/diagnostics/PR46264.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
-
-// PR46264
-// This case shall not crash with an assertion failure about void* dereferening.
-// The crash has been last seen on commit
-// `3ed8ebc2f6b8172bed48cc5986d3b7af4cfca1bc` from 24.05.2020.
-namespace ns1 {
-namespace a {
-class b {
-public:
-  typedef int b::*c;
-  operator c() { return d ? &b::d : 0; }
-  // expected-note@-1{{'?' condition is true}}
-  // expected-note@-2{{Assuming field 'd' is not equal to 0}}
-  // expected-note@-3{{Returning value, which participates in a condition later}}
-  int d;
-};
-} // namespace a
-using a::b;
-class e {
-  void f();
-  void g();
-  b h;
-};
-void e::f() {
-  e *i;
-  // expected-note@-1{{'i' declared without an initial value}}
-  if (h)
-// expected-note@-1{{Taking true branch}}
-// expected-note@-2{{'b::operator int ns1::a::b::*'}}
-// expected-note@-3{{Returning from 'b::operator int ns1::a::b::*'}}
-i->g();
-  // expected-note@-1{{Called C++ object pointer is uninitialized}}
-  // expected-warning@-2{{Called C++ object pointer is uninitialized}}
-}
-} // namespace ns1
Index: clang/test/Analysis/PR46264.cpp
===
--- clang/test/Analysis/PR46264.cpp
+++ clang/test/Analysis/PR46264.cpp
@@ -33,3 +33,27 @@
 
   return 10;
 }
+
+// PR46264
+// This case shall not crash with an assertion failure about void* dereferening.
+namespace ns1 {
+namespace a {
+class b {
+public:
+  typedef int b::*c;
+  operator c() { return d ? &b::d : 0; }
+  int d;
+};
+} // namespace a
+using a::b;
+class e {
+  void f();
+  void g();
+  b h;
+};
+void e::f() {
+  e *i;
+  if (h)
+i->g(); // expected-warning{{Called C++ object pointer is uninitialized}}
+}
+} // namespace ns1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-08-10 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:6964
+return DAG.getSetCC(DL, ResultVT, Op, DAG.getConstantFP(0.0, DL, 
OperandVT),
+ISD::SETUO);
+

nemanjai wrote:
> sepavloff wrote:
> > nemanjai wrote:
> > > sepavloff wrote:
> > > > efriedma wrote:
> > > > > Maybe we want to consider falling back to the integer path if SETCC 
> > > > > isn't legal for the given operand type?  We could do that as a 
> > > > > followup, though.
> > > > It makes sense, it could be beneficial for targets that have limited 
> > > > set of floating point comparisons. However straightforward check like:
> > > > 
> > > > if (Flags.hasNoFPExcept() && isOperationLegalOrCustom(ISD::SETCC, 
> > > > OperandVT))
> > > > 
> > > > results in worse code, mainly for vector types. It should be more 
> > > > complex check.
> > > >  
> > > Out of curiosity, why was this added when you recognized that it results 
> > > in worse code? This is certainly part of the reason for the regression 
> > > for `ppc_fp128`.
> > > 
> > > It would appear that before this patch, we would emit a comparison for 
> > > all types that are not IEEE FP types (such as `ppc_fp128`). Those 
> > > semantics do not seem to have carried over.
> > > Out of curiosity, why was this added when you recognized that it results 
> > > in worse code? This is certainly part of the reason for the regression 
> > > for ppc_fp128.
> > 
> > It is my mistake. After experiments I forgot to remove this change. I am 
> > sorry.
> > 
> > For x86 and AArch64 I used modified `test-suite`, with changes from 
> > D106804. Without proper tests it is hard to reveal why one intrinsic starts 
> > to fail.
> > 
> > > It would appear that before this patch, we would emit a comparison for 
> > > all types that are not IEEE FP types (such as ppc_fp128). Those semantics 
> > > do not seem to have carried over.
> > 
> > The previous behavior is not correct in non-default FP environment. 
> > Unordered comparison raises Invalid exception if an operand is signaling 
> > NaN. On the other hand, `isnan` must never raise exceptions.
> Well, if the **must never raise exceptions** is an IEEE-754 requirement (i.e. 
> as noted in 5.7.2), I think it is reasonable that operations on types that do 
> not conform to IEEE-754 are not bound by it.
C standard defines macro `isnan`, of which the recent draft 
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2596.pdf, F.3p6) states:

The C classification macros fpclassify, iscanonical, isfinite, isinf, 
isnan, isnormal,
issignaling, issubnormal, and iszero provide the IEC 60559 operations 
indicated in the table above 
provided their arguments are in the format of their semantic type. Then 
these macros
raise no floating-point exceptions, even if an argument is a signaling NaN.

This statement is not restricted to IEEE-compatible types, so any floating 
point type must behave according to this statement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D107696: [CodeComplete] Basic code completion for attribute names.

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



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4390
+  auto AddCompletions = [&](const ParsedAttrInfo &A) {
+if (A.IsTargetSpecific && !A.existsInTarget(Context.getTargetInfo()))
+  return;

Should we also early return if the attribute is ignored? (See `IgnoredAttr` in 
`Attr.td`) I'm assuming that attributes which do nothing are unlikely to be 
high-value attributes to autocomplete (so maybe they'd go at the end of the 
list if we wanted to keep them).



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4436-4446
+llvm::SmallString<32> Guarded;
+if (!Scope.empty()) {
+  const char *GuardedScope = underscoreAttrScope(Scope);
+  if (!GuardedScope)
+continue;
+  Guarded.append(GuardedScope);
+  Guarded.append("::");

This could probably use a `Twine` and save some typing, but I don't insist.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4357
+continue;
+  llvm::StringRef Name = S.NormalizedFullName;
+  if (Completion == AttributeCompletion::Scope) {

sammccall wrote:
> aaron.ballman wrote:
> > sammccall wrote:
> > > aaron.ballman wrote:
> > > > Should we also add some special handling for attributes optionally 
> > > > starting with double underscores? e.g., `__attribute__((const))` and 
> > > > `__attribute__((__const__))`` are both equally useful to complete.
> > > > 
> > > > Also, we should add some explicit testing for `omp::sequence` and 
> > > > `omp::directive` as those are handled very specially and won't appear 
> > > > in the parsed attribute map. I think the OpenMP code completion would 
> > > > be super useful, but can be handled in a follow-up if you want.
> > > > Should we also add some special handling for attributes optionally 
> > > > starting with double underscores?
> > > 
> > > I think so. Two questions:
> > >  - Do I understand right that this is "just" a matter of adding 
> > > leading/trailing `__` as a second option, for AS_GNU?
> > >  - are there similar rules for other syntaxes I've missed?
> > > 
> > > Offering both seems potentially confusing for users who don't care 
> > > (especially in the case of const!). But I guess enough users will care 
> > > about macros. At least in clangd the underscore versions will get ranked 
> > > lower for having "internal" names though.
> > > 
> > > FWIW The no-underscores version appears to be ~3x more common (87k vs 27k 
> > > hits in third-party code in google's repo). Among headers, no-underscores 
> > > is "only" 2x more common (40k vs 21k). 
> > > 
> > > ---
> > > 
> > > > Also, we should add some explicit testing for omp::sequence and 
> > > > omp::directive as those are handled very specially and won't appear in 
> > > > the parsed attribute map. 
> > > 
> > > Yeah, I punted on these because it seems they will need special case 
> > > logic, I'll add some tests that they don't do anything.
> > > Do I understand right that this is "just" a matter of adding 
> > > leading/trailing __ as a second option, for AS_GNU?
> > > are there similar rules for other syntaxes I've missed?
> > 
> > Clang supports GNU attributes in either `__attribute__((foo))` or 
> > `__attribute__((__foo__))` forms. So I'd say that autocompleting after the 
> > second `(` should either suggest attributes (preferred) or `__` (for the 
> > poor folks writing libraries). If the user wants to autocomplete after 
> > `__attribute__((__`, I think it should suggest `foo__` as the rest of the 
> > attribute name. (Basically, if the user looks like they want underscores, 
> > give them all the underscores.)
> > 
> > Clang also supports `[[]]` attributes but with somewhat different rules. We 
> > support `[[gnu::attr]]`, `[[__gnu__::attr]]`, `[[gnu::__attr__]]`, and 
> > `[[__gnu__::__attr__]]` for GCC attributes. We support `[[clang::attr]]`, 
> > `[[_Clang::attr]]`, `[[clang::__attr__]]`, and `[[_Clang::__attr__]]` for 
> > Clang attributes. For vendors other than Clang and GCC, we don't support 
> > any additional underscores for either the scope or the attribute name. I 
> > would say that if the user asked for underscores for the vendor scope, they 
> > likely want the underscores for the attribute as well.
> > 
> > I suppose there's a third case. That horrible `using` syntax that I've 
> > never really seen used in the wild. e.g., ``[[using clang: attr]``. We do 
> > support the underscore behavior there as well.
> > 
> > > Offering both seems potentially confusing for users who don't care 
> > > (especially in the case of const!). But I guess enough users will care 
> > > about macros.
> > 
> > Yeah, users who are writing portable libraries are far more likely to care 
> > than users writing typical application code.
> > So I'd say that autocompleting after the second ( should either suggest 
> > attributes (preferred) or __ (for the poor folks writing

[clang] 497b57a - revert test commit

2021-08-10 Thread Denys Petrov via cfe-commits

Author: Denys Petrov
Date: 2021-08-10T19:19:27+03:00
New Revision: 497b57ad0b9ee34aeb8c56e9f47332912b50d58c

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

LOG: revert test commit

Added: 


Modified: 
clang/test/Analysis/PR47511.cpp

Removed: 




diff  --git a/clang/test/Analysis/PR47511.cpp b/clang/test/Analysis/PR47511.cpp
index a9f2d592b6f59..d42799f4fbde5 100644
--- a/clang/test/Analysis/PR47511.cpp
+++ b/clang/test/Analysis/PR47511.cpp
@@ -14,6 +14,6 @@ constexpr strong_ordering strong_ordering::less = {-1};
 } // namespace std
 
 void test() {
-  // No crash 
+  // no crash
   (void)(0 <=> 0);
 }



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


[PATCH] D107841: CodeGen: No need to check for isExternC if HasStrictReturn is already false

2021-08-10 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer created this revision.
aschwaighofer added a reviewer: rjmccall.
aschwaighofer requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

NFC intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107841

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2241,7 +2241,7 @@
   // C++ explicitly makes returning undefined values UB. C's rule only applies
   // to used values, so we never mark them noundef for now.
   bool HasStrictReturn = getLangOpts().CPlusPlus;
-  if (TargetDecl) {
+  if (TargetDecl && HasStrictReturn) {
 if (const FunctionDecl *FDecl = dyn_cast(TargetDecl))
   HasStrictReturn &= !FDecl->isExternC();
 else if (const VarDecl *VDecl = dyn_cast(TargetDecl))


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2241,7 +2241,7 @@
   // C++ explicitly makes returning undefined values UB. C's rule only applies
   // to used values, so we never mark them noundef for now.
   bool HasStrictReturn = getLangOpts().CPlusPlus;
-  if (TargetDecl) {
+  if (TargetDecl && HasStrictReturn) {
 if (const FunctionDecl *FDecl = dyn_cast(TargetDecl))
   HasStrictReturn &= !FDecl->isExternC();
 else if (const VarDecl *VDecl = dyn_cast(TargetDecl))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107837: abseil-string-find-str-contains should not propose an edit for the three-parameter version of find().

2021-08-10 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1fdb3e36ff37: abseil-string-find-str-contains should not 
propose an edit for the three… (authored by tdl-g, committed by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107837

Files:
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
@@ -15,6 +15,7 @@
   ~basic_string();
   int find(basic_string s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -30,6 +31,7 @@
   ~basic_string_view();
   int find(basic_string_view s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -48,6 +50,7 @@
   ~string_view();
   int find(string_view s, int pos = 0);
   int find(const char *s, int pos = 0);
+  int find(const char *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -263,6 +266,18 @@
   asv.find("a", 3) == std::string_view::npos;
 }
 
+// Confirms that it does not match when the count parameter is present.
+void no_count() {
+  std::string ss;
+  ss.find("a", 0, 1) == std::string::npos;
+
+  std::string_view ssv;
+  ssv.find("a", 0, 1) == std::string_view::npos;
+
+  absl::string_view asv;
+  asv.find("a", 0, 1) == std::string_view::npos;
+}
+
 // Confirms that it does not match when it's compared to something other than
 // npos, even if the value is the same as npos.
 void no_non_npos() {
Index: clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
@@ -53,7 +53,7 @@
   to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass;
   auto StringFind = cxxMemberCallExpr(
   callee(cxxMethodDecl(
-  hasName("find"),
+  hasName("find"), parameterCountIs(2),
   hasParameter(
   0, parmVarDecl(anyOf(hasType(StringType), hasType(CharStarType),
hasType(CharType)),


Index: clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
@@ -15,6 +15,7 @@
   ~basic_string();
   int find(basic_string s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -30,6 +31,7 @@
   ~basic_string_view();
   int find(basic_string_view s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -48,6 +50,7 @@
   ~string_view();
   int find(string_view s, int pos = 0);
   int find(const char *s, int pos = 0);
+  int find(const char *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -263,6 +266,18 @@
   asv.find("a", 3) == std::string_view::npos;
 }
 
+// Confirms that it does not match when the count parameter is present.
+void no_count() {
+  std::string ss;
+  ss.find("a", 0, 1) == std::string::npos;
+
+  std::string_view ssv;
+  ssv.find("a", 0, 1) == std::string_view::npos;
+
+  absl::string_view asv;
+  asv.find("a", 0, 1) == std::string_view::npos;
+}
+
 // Confirms that it does not match when it's compared to something other than
 // npos, even if the value is the same as npos.
 void no_non_npos() {
Index: clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
@@ -53,7 +53,7 @@
   to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass;
   auto StringFind = cxxMemberCallExpr(
   callee(cxxMethodDecl(
-  hasName("find"),
+  hasName("find"), parameterCountIs(2),
   hasParameter(
   0, parmVarDecl(a

[PATCH] D107647: [PowerPC] MMA - Remove deprecated built-ins and add new built-ins

2021-08-10 Thread Lei Huang via Phabricator via cfe-commits
lei added a comment.

LGTM
Can we update the title and description to be more specific though?

  [PowerPC] MMA - Rename deprecated builtins mma_assemble_acc, vsx_assemble_pair
  
  Rename deprecated builtins :
   __builtin_mma_assemble_acc
   __builtin_vsx_assemble_pair
  
  To:
   __builtin_mma_build_acc
   __builtin_vsx_build_pair


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107647

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


[clang-tools-extra] 1fdb3e3 - abseil-string-find-str-contains should not propose an edit for the three-parameter version of find().

2021-08-10 Thread Yitzhak Mandelbaum via cfe-commits

Author: Tom Lokovic
Date: 2021-08-10T16:39:17Z
New Revision: 1fdb3e36ff379e5b3b05a00d49b6081435df727a

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

LOG: abseil-string-find-str-contains should not propose an edit for the 
three-parameter version of find().

std::string, std::string_view, and absl::string_view all have a three-parameter 
version of find()
which has a "count" (or "n") paremeter limiting the size of the substring to 
search.  We don't want
to propose changing to absl::StrContains in those cases.  This change fixes 
that and adds unit tests
to confirm.

Reviewed By: ymandel

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
index f4a519c15b92f..601b987d332b6 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
@@ -53,7 +53,7 @@ makeRewriteRule(const std::vector 
&StringLikeClassNames,
   to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass;
   auto StringFind = cxxMemberCallExpr(
   callee(cxxMethodDecl(
-  hasName("find"),
+  hasName("find"), parameterCountIs(2),
   hasParameter(
   0, parmVarDecl(anyOf(hasType(StringType), hasType(CharStarType),
hasType(CharType)),

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
index 81a3fc4d3b971..ba9a72a60bab0 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
@@ -15,6 +15,7 @@ class basic_string {
   ~basic_string();
   int find(basic_string s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -30,6 +31,7 @@ class basic_string_view {
   ~basic_string_view();
   int find(basic_string_view s, int pos = 0);
   int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -48,6 +50,7 @@ class string_view {
   ~string_view();
   int find(string_view s, int pos = 0);
   int find(const char *s, int pos = 0);
+  int find(const char *s, int pos, int n);
   int find(char c, int pos = 0);
   static constexpr size_t npos = -1;
 };
@@ -263,6 +266,18 @@ void no_nonzero_pos() {
   asv.find("a", 3) == std::string_view::npos;
 }
 
+// Confirms that it does not match when the count parameter is present.
+void no_count() {
+  std::string ss;
+  ss.find("a", 0, 1) == std::string::npos;
+
+  std::string_view ssv;
+  ssv.find("a", 0, 1) == std::string_view::npos;
+
+  absl::string_view asv;
+  asv.find("a", 0, 1) == std::string_view::npos;
+}
+
 // Confirms that it does not match when it's compared to something other than
 // npos, even if the value is the same as npos.
 void no_non_npos() {



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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-08-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 365519.
MyDeveloperDay added a comment.

- Rename the ConstFixer to QualifierAligmentFixer (as now we handle more than 
just const) and in preparation for handling others


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18180,6 +18180,11 @@
   EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
   EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
 
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
@@ -18277,6 +18282,24 @@
   CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
 
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+  CHECK_PARSE("CVQualifierAlignment: Leave", CVQualifierAlignment,
+  FormatStyle::CVQAS_Leave);
+  CHECK_PARSE("CVQualifierAlignment: Right", CVQualifierAlignment,
+  FormatStyle::CVQAS_Right);
+  CHECK_PARSE("CVQualifierAlignment: Left", CVQualifierAlignment,
+  FormatStyle::CVQAS_Left);
+
+  CHECK_PARSE("CVQualifierOrder: [ const, volatile]", CVQualifierOrder,
+  std::vector({"const", "volatile"}));
+  Style.CVQualifierOrder.clear();
+  CHECK_PARSE("CVQualifierOrder: [const]", CVQualifierOrder,
+  std::vector{"const"});
+  CHECK_PARSE("CVQualifierOrder: [volatile]", CVQualifierOrder,
+  std::vector{"volatile"});
+  CHECK_PARSE("CVQualifierOrder: [const, volatile]", CVQualifierOrder,
+  std::vector({"const", "volatile"}));
+
   Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
   CHECK_PARSE("AlignConsecutiveAssignments: None", AlignConsecutiveAssignments,
   FormatStyle::ACS_None);
@@ -0,6 +22243,387 @@
   "}";
   EXPECT_EQ(Code, format(Code, Style));
 }
+
+TEST_F(FormatTest, LeftRightConst) {
+  FormatStyle Style = getLLVMStyle();
+
+  // keep the const style unaltered
+  verifyFormat("const int a;", Style);
+  verifyFormat("const int *a;", Style);
+  verifyFormat("const int &a;", Style);
+  verifyFormat("const int &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("const Foo a;", Style);
+  verifyFormat("const Foo *a;", Style);
+  verifyFormat("const Foo &a;", Style);
+  verifyFormat("const Foo &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+
+  verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
+  verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
+
+  verifyFormat("volatile const int *restrict;", Style);
+  verifyFormat("const volatile int *restrict;", Style);
+  verifyFormat("const int volatile *restrict;", Style);
+}
+
+TEST_F(FormatTest, RightConst) {
+  FormatStyle Style = getLLVMStyle();
+  Style.CVQualifierAlignment = FormatStyle::CVQAS_Right;
+
+  verifyFormat("int const a;", Style);
+  verifyFormat("int const *a;", Style);
+  verifyFormat("int const &a;", Style);
+  verifyFormat("int const &&a;", Style);
+  verifyFormat("int const b;", Style);
+  verifyFormat("int const *b;", Style);
+  verifyFormat("int const &b;", Style);
+  verifyFormat("int const &&b;", Style);
+  verifyFormat("int const *b const;", Style);
+  verifyFormat("int *const c;", Style);
+
+  verifyFormat("Foo const a;", Style);
+  verifyFormat("Foo const *a;", Style);
+  verifyFormat("Foo const &a;", Style);
+  verifyFormat("Foo const &&a;", Style);
+  verifyFormat("Foo const b;", Style);
+  verifyFormat("Foo const *b;", Style);
+  verifyFormat("Foo const &b;", Style);
+  verifyFormat("Foo const &&b;", Style);
+  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo *const b;", Style);
+  verifyFo

[PATCH] D107717: [LLVM][CMake][NFC] Resolve FIXME: Rename LLVM_CMAKE_PATH to LLVM_CMAKE_DIR throughout the project

2021-08-10 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365507.
gAlfonso-bit added a comment.

Rebase


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

https://reviews.llvm.org/D107717

Files:
  clang/CMakeLists.txt
  clang/lib/Basic/CMakeLists.txt
  compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  flang/CMakeLists.txt
  libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
  libunwind/CMakeLists.txt
  lld/CMakeLists.txt
  lld/Common/CMakeLists.txt
  lldb/cmake/modules/LLDBStandalone.cmake
  lldb/source/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/include/llvm/Support/CMakeLists.txt
  runtimes/CMakeLists.txt

Index: runtimes/CMakeLists.txt
===
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -65,7 +65,7 @@
 
 # This variable makes sure that e.g. llvm-lit is found.
 set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
-set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
+set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)
 
 # This variable is used by individual runtimes to locate LLVM files.
 set(LLVM_PATH ${LLVM_BUILD_MAIN_SRC_DIR})
Index: llvm/include/llvm/Support/CMakeLists.txt
===
--- llvm/include/llvm/Support/CMakeLists.txt
+++ llvm/include/llvm/Support/CMakeLists.txt
@@ -3,7 +3,7 @@
 # The VC revision include that we want to generate.
 set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h")
 
-set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
+set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
 
 if(LLVM_APPEND_VC_REV)
   set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -295,8 +295,8 @@
 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
 set(LLVM_BINARY_DIR   ${CMAKE_CURRENT_BINARY_DIR}  ) # --prefix
 
-# Note: LLVM_CMAKE_PATH does not include generated files
-set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
+# Note: LLVM_CMAKE_DIR does not include generated files
+set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)
 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
 
Index: lldb/source/CMakeLists.txt
===
--- lldb/source/CMakeLists.txt
+++ lldb/source/CMakeLists.txt
@@ -8,7 +8,7 @@
 find_first_existing_vc_file("${LLDB_SOURCE_DIR}" lldb_vc)
 
 set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
-set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
+set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
 
 if(lldb_vc AND LLVM_APPEND_VC_REV)
   set(lldb_source_dir ${LLDB_SOURCE_DIR})
Index: lldb/cmake/modules/LLDBStandalone.cmake
===
--- lldb/cmake/modules/LLDBStandalone.cmake
+++ lldb/cmake/modules/LLDBStandalone.cmake
@@ -3,8 +3,8 @@
 find_package(LLVM REQUIRED CONFIG HINTS ${LLVM_DIR} NO_CMAKE_FIND_ROOT_PATH)
 find_package(Clang REQUIRED CONFIG HINTS ${Clang_DIR} ${LLVM_DIR}/../clang NO_CMAKE_FIND_ROOT_PATH)
 
-# We set LLVM_CMAKE_PATH so that GetSVN.cmake is found correctly when building SVNVersion.inc
-set(LLVM_CMAKE_PATH ${LLVM_CMAKE_DIR} CACHE PATH "Path to LLVM CMake modules")
+# We set LLVM_CMAKE_DIR so that GetSVN.cmake is found correctly when building SVNVersion.inc
+set(LLVM_CMAKE_DIR ${LLVM_CMAKE_DIR} CACHE PATH "Path to LLVM CMake modules")
 
 set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
Index: lld/Common/CMakeLists.txt
===
--- lld/Common/CMakeLists.txt
+++ lld/Common/CMakeLists.txt
@@ -8,7 +8,7 @@
 find_first_existing_vc_file("${LLD_SOURCE_DIR}" lld_vc)
 
 set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
-set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
+set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
 
 if(lld_vc AND LLVM_APPEND_VC_REV)
   set(lld_source_dir ${LLD_SOURCE_DIR})
Index: lld/CMakeLists.txt
===
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -27,7 +27,7 @@
 
   list(GET LLVM_CONFIG_OUTPUT 0 OBJ_ROOT)
   list(GET LLVM_CONFIG_OUTPUT 1 MAIN_INCLUDE_DIR)
-  list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_PATH)
+  list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_DIR)
   list(GET LLVM_CONFIG_OUTPUT 3 MAIN_SRC_DIR)
 
   set(LLVM_OBJ_ROOT ${OBJ_ROOT} CACHE PATH "path to LLVM build tree")
@@ -35,14 +35,14 @@
   set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to 

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

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

- restricting remarks emission on AMDGPU targets only


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:  

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

2021-08-10 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 added a comment.

@rampitec comments?


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


[clang] 3b39fa3 - [AIX] Define __HOS_AIX__ macro only for AIX target

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

Author: Jake Egan
Date: 2021-08-10T13:03:17-04:00
New Revision: 3b39fa3e2815538187ed8928549a9f27c6a71ef6

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

LOG: [AIX] Define __HOS_AIX__ macro only for AIX target

%%%
This patch defines the macro __HOS_AIX__ when the target is AIX and without any 
dependency on the host. The macro indicates that the host is AIX. Defining the 
macro will help minimize porting pain for existing code compiled with xlc/xlC. 
xlC never shipped cross-compiling support, so the difference is not observable 
anyway.
%%%
This is a follow up to the discussion in https://reviews.llvm.org/D107242.

Reviewed By: cebowleratibm, joerg

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

Added: 


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

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



diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 28d4c77d47ca..440ec63f9cef 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -677,6 +677,7 @@ class AIXTargetInfo : public OSTargetInfo {
 
 Builder.defineMacro("_AIX");
 Builder.defineMacro("__TOS_AIX__");
+Builder.defineMacro("__HOS_AIX__");
 
 if (Opts.C11) {
   Builder.defineMacro("__STDC_NO_ATOMICS__");

diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 711ba2837a9b..33f266f02b69 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -14,7 +14,6 @@
 #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;
@@ -308,11 +307,6 @@ 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
deleted file mode 100644
index 81d594ba5803..
--- a/clang/test/Preprocessor/host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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/init-ppc.c 
b/clang/test/Preprocessor/init-ppc.c
index fedc1b6c9140..ca61143e8dc9 100644
--- a/clang/test/Preprocessor/init-ppc.c
+++ b/clang/test/Preprocessor/init-ppc.c
@@ -432,6 +432,7 @@
 // PPC-AIX:#define __FLT_MIN_EXP__ (-125)
 // PPC-AIX:#define __FLT_MIN__ 1.17549435e-38F
 // PPC-AIX:#define __FLT_RADIX__ 2
+// PPC-AIX:#define __HOS_AIX__ 1
 // PPC-AIX:#define __INT16_C_SUFFIX__
 // PPC-AIX:#define __INT16_FMTd__ "hd"
 // PPC-AIX:#define __INT16_FMTi__ "hi"

diff  --git a/clang/test/Preprocessor/not-host-aix.c 
b/clang/test/Preprocessor/not-host-aix.c
deleted file mode 100644
index d6a2d22a7d25..
--- a/clang/test/Preprocessor/not-host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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] D107825: [AIX] Define __HOS_AIX__ macro only for AIX target

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107825

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


Index: clang/test/Preprocessor/not-host-aix.c
===
--- clang/test/Preprocessor/not-host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -432,6 +432,7 @@
 // PPC-AIX:#define __FLT_MIN_EXP__ (-125)
 // PPC-AIX:#define __FLT_MIN__ 1.17549435e-38F
 // PPC-AIX:#define __FLT_RADIX__ 2
+// PPC-AIX:#define __HOS_AIX__ 1
 // PPC-AIX:#define __INT16_C_SUFFIX__
 // PPC-AIX:#define __INT16_FMTd__ "hd"
 // PPC-AIX:#define __INT16_FMTi__ "hi"
Index: clang/test/Preprocessor/host-aix.c
===
--- clang/test/Preprocessor/host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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,7 +14,6 @@
 #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;
@@ -308,11 +307,6 @@
 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/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -677,6 +677,7 @@
 
 Builder.defineMacro("_AIX");
 Builder.defineMacro("__TOS_AIX__");
+Builder.defineMacro("__HOS_AIX__");
 
 if (Opts.C11) {
   Builder.defineMacro("__STDC_NO_ATOMICS__");


Index: clang/test/Preprocessor/not-host-aix.c
===
--- clang/test/Preprocessor/not-host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -432,6 +432,7 @@
 // PPC-AIX:#define __FLT_MIN_EXP__ (-125)
 // PPC-AIX:#define __FLT_MIN__ 1.17549435e-38F
 // PPC-AIX:#define __FLT_RADIX__ 2
+// PPC-AIX:#define __HOS_AIX__ 1
 // PPC-AIX:#define __INT16_C_SUFFIX__
 // PPC-AIX:#define __INT16_FMTd__ "hd"
 // PPC-AIX:#define __INT16_FMTi__ "hi"
Index: clang/test/Preprocessor/host-aix.c
===
--- clang/test/Preprocessor/host-aix.c
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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,7 +14,6 @@
 #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;
@@ -308,11 +307,6 @@
 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

[PATCH] D107843: [X86] Add parentheses around casts in some of the X86 intrinsic headers.

2021-08-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, pengfei.
craig.topper requested review of this revision.
Herald added a project: clang.

This covers the SSE and AVX/AVX2 headers. AVX512 has a lot more macros
due to rounding mode.

Fixes part of PR51324.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107843

Files:
  clang/lib/Headers/__wmmintrin_aes.h
  clang/lib/Headers/avx2intrin.h
  clang/lib/Headers/avxintrin.h
  clang/lib/Headers/emmintrin.h
  clang/lib/Headers/smmintrin.h
  clang/lib/Headers/tmmintrin.h
  clang/lib/Headers/xmmintrin.h

Index: clang/lib/Headers/xmmintrin.h
===
--- clang/lib/Headers/xmmintrin.h
+++ clang/lib/Headers/xmmintrin.h
@@ -2181,7 +2181,7 @@
 ///3: Bits [63:48] are copied to the destination.
 /// \returns A 16-bit integer containing the extracted 16 bits of packed data.
 #define _mm_extract_pi16(a, n) \
-  (int)__builtin_ia32_vec_ext_v4hi((__v4hi)a, (int)n)
+  ((int)__builtin_ia32_vec_ext_v4hi((__v4hi)a, (int)n))
 
 /// Copies data from the 64-bit vector of [4 x i16] to the destination,
 ///and inserts the lower 16-bits of an integer operand at the 16-bit offset
@@ -2212,7 +2212,7 @@
 /// \returns A 64-bit integer vector containing the copied packed data from the
 ///operands.
 #define _mm_insert_pi16(a, d, n) \
-  (__m64)__builtin_ia32_vec_set_v4hi((__v4hi)a, (int)d, (int)n)
+  ((__m64)__builtin_ia32_vec_set_v4hi((__v4hi)a, (int)d, (int)n))
 
 /// Compares each of the corresponding packed 16-bit integer values of
 ///the 64-bit integer vectors, and writes the greater value to the
@@ -2359,7 +2359,7 @@
 ///11: assigned from bits [63:48] of \a a.
 /// \returns A 64-bit integer vector containing the shuffled values.
 #define _mm_shuffle_pi16(a, n) \
-  (__m64)__builtin_ia32_pshufw((__v4hi)(__m64)(a), (n))
+  ((__m64)__builtin_ia32_pshufw((__v4hi)(__m64)(a), (n)))
 
 /// Conditionally copies the values from each 8-bit element in the first
 ///64-bit integer vector operand to the specified memory location, as
@@ -2601,8 +2601,8 @@
 ///11: Bits [127:96] copied from the specified operand.
 /// \returns A 128-bit vector of [4 x float] containing the shuffled values.
 #define _mm_shuffle_ps(a, b, mask) \
-  (__m128)__builtin_ia32_shufps((__v4sf)(__m128)(a), (__v4sf)(__m128)(b), \
-(int)(mask))
+  ((__m128)__builtin_ia32_shufps((__v4sf)(__m128)(a), (__v4sf)(__m128)(b), \
+ (int)(mask)))
 
 /// Unpacks the high-order (index 2,3) values from two 128-bit vectors of
 ///[4 x float] and interleaves them into a 128-bit vector of [4 x float].
Index: clang/lib/Headers/tmmintrin.h
===
--- clang/lib/Headers/tmmintrin.h
+++ clang/lib/Headers/tmmintrin.h
@@ -145,8 +145,8 @@
 /// \returns A 128-bit integer vector containing the concatenated right-shifted
 ///value.
 #define _mm_alignr_epi8(a, b, n) \
-  (__m128i)__builtin_ia32_palignr128((__v16qi)(__m128i)(a), \
- (__v16qi)(__m128i)(b), (n))
+  ((__m128i)__builtin_ia32_palignr128((__v16qi)(__m128i)(a), \
+  (__v16qi)(__m128i)(b), (n)))
 
 /// Concatenates the two 64-bit integer vector operands, and right-shifts
 ///the result by the number of bytes specified in the immediate operand.
@@ -168,7 +168,7 @@
 /// \returns A 64-bit integer vector containing the concatenated right-shifted
 ///value.
 #define _mm_alignr_pi8(a, b, n) \
-  (__m64)__builtin_ia32_palignr((__v8qi)(__m64)(a), (__v8qi)(__m64)(b), (n))
+  ((__m64)__builtin_ia32_palignr((__v8qi)(__m64)(a), (__v8qi)(__m64)(b), (n)))
 
 /// Horizontally adds the adjacent pairs of values contained in 2 packed
 ///128-bit vectors of [8 x i16].
Index: clang/lib/Headers/smmintrin.h
===
--- clang/lib/Headers/smmintrin.h
+++ clang/lib/Headers/smmintrin.h
@@ -231,7 +231,7 @@
 ///  11: Truncated
 /// \returns A 128-bit vector of [4 x float] containing the rounded values.
 #define _mm_round_ps(X, M) \
-  (__m128)__builtin_ia32_roundps((__v4sf)(__m128)(X), (M))
+  ((__m128)__builtin_ia32_roundps((__v4sf)(__m128)(X), (M)))
 
 /// Copies three upper elements of the first 128-bit vector operand to
 ///the corresponding three upper elements of the 128-bit result vector of
@@ -272,8 +272,8 @@
 /// \returns A 128-bit vector of [4 x float] containing the copied and rounded
 ///values.
 #define _mm_round_ss(X, Y, M) \
-  (__m128)__builtin_ia32_roundss((__v4sf)(__m128)(X), \
- (__v4sf)(__m128)(Y), (M))
+  ((__m128)__builtin_ia32_roundss((__v4sf)(__m128)(X), \
+  (__v4sf)(__m128)(Y), (M)))
 
 /// Rounds each element of the 128-bit vector of [2 x double] to an
 ///integer value according to the rounding control specified

[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-08-10 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

@aprantl @dblaikie Can I get a review soon to avoid merge conflicts on these 
tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107024

___
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-10 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/CodeGen/AtomicExpandPass.cpp:628
+  AI, Kind,
+  Remark << "A hardware CAS loop generated: if the memory is "
+"known to be coarse-grain allocated then a hardware "

Still the same problem.


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


[clang] e2ff880 - [clang][cache] Update Fuchsia-stage2.cmake to create hwasan multilibs

2021-08-10 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2021-08-10T10:52:24-07:00
New Revision: e2ff880a7ed464f0649c47132603562312fff102

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

LOG: [clang][cache] Update Fuchsia-stage2.cmake to create hwasan multilibs

This is a reland of commit a9d1970384aa3908adbf6f50f110c375def58947.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index aa45c1549340b..e58ae3ac247aa 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -226,11 +226,30 @@ if(FUCHSIA_SDK)
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;compat;asan+noexcept" CACHE STRING 
"")
+  # HWAsan
+  set(RUNTIMES_aarch64-unknown-fuchsia+hwasan_LLVM_BUILD_COMPILER_RT OFF CACHE 
BOOL "")
+  set(RUNTIMES_aarch64-unknown-fuchsia+hwasan_LLVM_USE_SANITIZER "HWAddress" 
CACHE STRING "")
+  
set(RUNTIMES_aarch64-unknown-fuchsia+hwasan_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+  
set(RUNTIMES_aarch64-unknown-fuchsia+hwasan_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+  set(RUNTIMES_aarch64-unknown-fuchsia+hwasan_CMAKE_CXX_FLAGS 
"${FUCHSIA_aarch64-unknown-fuchsia_COMPILER_FLAGS} -mllvm --hwasan-globals=0" 
CACHE STRING "")
+
+  # HWASan+noexcept
+  set(RUNTIMES_aarch64-unknown-fuchsia+hwasan+noexcept_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
+  set(RUNTIMES_aarch64-unknown-fuchsia+hwasan+noexcept_LLVM_USE_SANITIZER 
"HWAddress" CACHE STRING "")
+  
set(RUNTIMES_aarch64-unknown-fuchsia+hwasan+noexcept_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+  
set(RUNTIMES_aarch64-unknown-fuchsia+hwasan+noexcept_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+  
set(RUNTIMES_aarch64-unknown-fuchsia+hwasan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+  
set(RUNTIMES_aarch64-unknown-fuchsia+hwasan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
+  set(RUNTIMES_aarch64-unknown-fuchsia+hwasan+noexcept_CMAKE_CXX_FLAGS 
"${FUCHSIA_aarch64-unknown-fuchsia_COMPILER_FLAGS} -mllvm --hwasan-globals=0" 
CACHE STRING "")
+
+  set(LLVM_RUNTIME_MULTILIBS 
"asan;noexcept;compat;asan+noexcept;hwasan;hwasan+noexcept" CACHE STRING "")
+
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_compat_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_hwasan_TARGETS "aarch64-unknown-fuchsia" CACHE 
STRING "")
+  set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS "aarch64-unknown-fuchsia" 
CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")



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


[libunwind] 08a5ac3 - libunwind: add missing break statements in EHABI

2021-08-10 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2021-08-10T17:53:31Z
New Revision: 08a5ac36b956edeb989b4a65269a829eac26a5a2

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

LOG: libunwind: add missing break statements in EHABI

Add missing break statements identified by static analysis tools.

Patch by Andrii Kurdiumov!

Reviewed By: compnerd, danielkiss

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

Added: 


Modified: 
libunwind/src/Unwind-EHABI.cpp

Removed: 




diff  --git a/libunwind/src/Unwind-EHABI.cpp b/libunwind/src/Unwind-EHABI.cpp
index 32b5cbc3be92e..8843db7f54c3e 100644
--- a/libunwind/src/Unwind-EHABI.cpp
+++ b/libunwind/src/Unwind-EHABI.cpp
@@ -97,9 +97,11 @@ _Unwind_Reason_Code ProcessDescriptors(
   case Descriptor::LU32:
 descriptor = getNextWord(descriptor, &length);
 descriptor = getNextWord(descriptor, &offset);
+break;
   case Descriptor::LU16:
 descriptor = getNextNibble(descriptor, &length);
 descriptor = getNextNibble(descriptor, &offset);
+break;
   default:
 assert(false);
 return _URC_FAILURE;



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


[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

2021-08-10 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 365546.
vabridgers added a comment.

add test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107720

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/solver-sym-simplification-bool.cpp
  clang/test/Analysis/solver-sym-simplification-bool2.cpp


Index: clang/test/Analysis/solver-sym-simplification-bool2.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool2.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -Wno-unused-value -verify %s
+
+void clang_analyzer_dump(bool);
+
+void fee(int *p) {
+  int *q = p - 1;
+  q &&q;
+  q &&q;
+  clang_analyzer_dump(q && q);
+  // expected-warning@-1{{((reg_$0) != 0U) != 0U}}}
+  // expected-warning@-2{{0 U1b}}
+  (void)q;
+}
Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt &Zero = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);


Index: clang/test/Analysis/solver-sym-simplification-bool2.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool2.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -Wno-unused-value -verify %s
+
+void clang_analyzer_dump(bool);
+
+void fee(int *p) {
+  int *q = p - 1;
+  q &&q;
+  q &&q;
+  clang_analyzer_dump(q && q);
+  // expected-warning@-1{{((reg_$0) != 0U) != 0U}}}
+  // expected-warning@-2{{0 U1b}}
+  (void)q;
+}
Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt &Zero = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, Basi

[PATCH] D99517: Implemented [[clang::musttail]] attribute for guaranteed tail calls.

2021-08-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

It's not generically true that "anything can be tail-called if it's 
`noreturn`".  For one, `noreturn` doesn't imply that the function doesn't exit 
by e.g. throwing or calling `longjmp`.  For another, the most important user 
expectation of tail calls is that a long series of tail calls will exhibit zero 
overall stack growth; in a caller-pop calling convention, calling a function 
with more parameters may require growing the argument area in a way that cannot 
be reversed, so e.g. a long sequence of tail calls alternating between 
1-argument and 2-argument functions will eventually exhaust the stack, which 
violates that user expectation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

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


[PATCH] D107841: CodeGen: No need to check for isExternC if HasStrictReturn is already false

2021-08-10 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall 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/D107841/new/

https://reviews.llvm.org/D107841

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


[PATCH] D107647: [PowerPC] MMA - Remove deprecated built-ins and add new built-ins

2021-08-10 Thread Lei Huang via Phabricator via cfe-commits
lei requested changes to this revision.
lei added a comment.
This revision now requires changes to proceed.

Actually we should not be removing the deprecated bultins.  Just need to add 
the new ones.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107647

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


[PATCH] D107647: [PowerPC] MMA - Remove deprecated built-ins and add new built-ins

2021-08-10 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D107647#2937706 , @lei wrote:

> Actually we should not be removing the deprecated bultins.  Just need to add 
> the new ones.

Yes, and also the semantics are different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107647

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


[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

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



Comment at: clang/unittests/AST/CMakeLists.txt:18
   ASTVectorTest.cpp
+  AttrTest.cpp
   CommentLexer.cpp

I don't think this new file got attached to the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

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


[PATCH] D107791: [InlineAdvisor] Add single quotes around caller/callee names

2021-08-10 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG76093b17394a: [InlineAdvisor] Add single quotes around 
caller/callee names (authored by MaskRay).
Herald added a subscriber: emaste.

Changed prior to commit:
  https://reviews.llvm.org/D107791?vs=365332&id=365570#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107791

Files:
  clang/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll
  clang/test/Frontend/optimization-remark-line-directive.c
  clang/test/Frontend/optimization-remark-new-pm.c
  clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
  clang/test/Frontend/optimization-remark-with-hotness.c
  clang/test/Frontend/optimization-remark.c
  clang/test/Frontend/remarks-hotness.cpp
  lld/test/ELF/lto/opt-remarks.ll
  llvm/lib/Analysis/InlineAdvisor.cpp
  llvm/lib/Analysis/ReplayInlineAdvisor.cpp
  llvm/test/LTO/Resolution/X86/diagnostic-handler-remarks-with-hotness.ll
  llvm/test/LTO/Resolution/X86/diagnostic-handler-remarks.ll
  llvm/test/LTO/X86/diagnostic-handler-remarks-with-hotness.ll
  llvm/test/LTO/X86/diagnostic-handler-remarks.ll
  llvm/test/Other/optimization-remarks-auto.ll
  llvm/test/Other/optimization-remarks-inline.ll
  llvm/test/ThinLTO/X86/diagnostic-handler-remarks-with-hotness.ll
  llvm/test/ThinLTO/X86/diagnostic-handler-remarks.ll
  llvm/test/Transforms/Inline/ARM/inline-fp.ll
  llvm/test/Transforms/Inline/Inputs/cgscc-inline-replay.txt
  llvm/test/Transforms/Inline/cgscc-inline-replay.ll
  llvm/test/Transforms/Inline/inline_noprofile.ll
  llvm/test/Transforms/Inline/inline_nossp.ll
  llvm/test/Transforms/Inline/optimization-remarks-hotness-threshold.ll
  llvm/test/Transforms/Inline/optimization-remarks-passed-yaml.ll
  llvm/test/Transforms/Inline/optimization-remarks-with-hotness.ll
  llvm/test/Transforms/Inline/optimization-remarks.ll
  llvm/test/Transforms/SampleProfile/Inputs/inline-replay.txt
  llvm/test/Transforms/SampleProfile/csspgo-inline-icall.ll
  llvm/test/Transforms/SampleProfile/csspgo-inline.ll
  llvm/test/Transforms/SampleProfile/inline-replay.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-inline.ll
  llvm/test/Transforms/SampleProfile/remarks-hotness.ll
  llvm/test/Transforms/SampleProfile/remarks.ll
  llvm/test/tools/gold/X86/opt-remarks.ll
  llvm/test/tools/gold/X86/remarks.ll

Index: llvm/test/tools/gold/X86/remarks.ll
===
--- llvm/test/tools/gold/X86/remarks.ll
+++ llvm/test/tools/gold/X86/remarks.ll
@@ -7,7 +7,7 @@
 ; RUN:   %t.o -o %t2.o 2>&1 | FileCheck -allow-empty --check-prefix=NO-REMARK %s
 
 
-; CHECK: f inlined into _start
+; CHECK: 'f' inlined into '_start'
 ; NO-REMARK-NOT: inlined
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
Index: llvm/test/tools/gold/X86/opt-remarks.ll
===
--- llvm/test/tools/gold/X86/opt-remarks.ll
+++ llvm/test/tools/gold/X86/opt-remarks.ll
@@ -49,9 +49,11 @@
 ; YAML-NEXT: Name:Inlined
 ; YAML-NEXT: Function:_start
 ; YAML-NEXT: Args:
+; YAML-NEXT:   - String:  
 ; YAML-NEXT:   - Callee:  f
-; YAML-NEXT:   - String:  ' inlined into '
+; YAML-NEXT:   - String:  ''' inlined into '''
 ; YAML-NEXT:   - Caller:  _start
+; YAML-NEXT:   - String:  
 ; YAML-NEXT:   - String:  ' with '
 ; YAML-NEXT:   - String:  '(cost='
 ; YAML-NEXT:   - Cost:'0'
@@ -66,9 +68,11 @@
 ; YAML-HOT-NEXT: Function:_start
 ; YAML-HOT-NEXT: Hotness: 300
 ; YAML-HOT-NEXT: Args:
+; YAML-HOT-NEXT:   - String:  
 ; YAML-HOT-NEXT:   - Callee:  f
-; YAML-HOT-NEXT:   - String:  ' inlined into '
+; YAML-HOT-NEXT:   - String:  ''' inlined into '''
 ; YAML-HOT-NEXT:   - Caller:  _start
+; YAML-HOT-NEXT:   - String:  
 ; YAML-HOT-NEXT:   - String:  ' with '
 ; YAML-HOT-NEXT:   - String:  '(cost='
 ; YAML-HOT-NEXT:   - Cost:'0'
Index: llvm/test/Transforms/SampleProfile/remarks.ll
===
--- llvm/test/Transforms/SampleProfile/remarks.ll
+++ llvm/test/Transforms/SampleProfile/remarks.ll
@@ -21,8 +21,8 @@
 
 ; We are expecting foo() to be inlined in main() (almost all the cycles are
 ; spent inside foo).
-; CHECK: remark: remarks.cc:13:21: _Z3foov inlined into main to match profiling context with (cost=130, threshold=2147483647) at callsite main:0:21;
-; CHECK: remark: remarks.cc:9:19: rand inlined into main to match profiling context with (cost=always): always inline attribute at callsite _Z3foov:6:19 @ main:0:21;
+; CHECK: remark: remarks.cc:13:21: '_Z3foov' inlined into 'main' to match profiling context with (cost=13

[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

2021-08-10 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 365582.
vabridgers added a comment.

only need the one test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107720

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/solver-sym-simplification-bool.cpp


Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt &Zero = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);


Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt &Zero = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107843: [X86] Add parentheses around casts in some of the X86 intrinsic headers.

2021-08-10 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

Hard to see through all of the lint noise, but seems like a mechanical fix.
Can we add a test like the one in the bug report?
https://godbolt.org/z/sPT8e9vx9


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107843

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


[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 365585.
sammccall added a comment.

Oops, forgot test file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/Attr.h
  clang/lib/AST/CMakeLists.txt
  clang/unittests/AST/CMakeLists.txt
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -61,6 +61,7 @@
llvm::raw_ostream &OS);
 void EmitClangAttrNodeTraverse(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
+void EmitClangAttrDocTable(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 
 void EmitClangDiagsDefs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS,
 const std::string &Component);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -30,6 +30,7 @@
   GenClangAttrSubjectMatchRulesParserStringSwitches,
   GenClangAttrImpl,
   GenClangAttrList,
+  GenClangAttrDocTable,
   GenClangAttrSubjectMatchRuleList,
   GenClangAttrPCHRead,
   GenClangAttrPCHWrite,
@@ -115,6 +116,8 @@
"Generate clang attribute implementations"),
 clEnumValN(GenClangAttrList, "gen-clang-attr-list",
"Generate a clang attribute list"),
+clEnumValN(GenClangAttrDocTable, "gen-clang-attr-doc-table",
+   "Generate a table of attribute documentation"),
 clEnumValN(GenClangAttrSubjectMatchRuleList,
"gen-clang-attr-subject-match-rule-list",
"Generate a clang attribute subject match rule list"),
@@ -280,6 +283,9 @@
   case GenClangAttrList:
 EmitClangAttrList(Records, OS);
 break;
+  case GenClangAttrDocTable:
+EmitClangAttrDocTable(Records, OS);
+break;
   case GenClangAttrSubjectMatchRuleList:
 EmitClangAttrSubjectMatchRuleList(Records, OS);
 break;
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4210,6 +4210,42 @@
   getPragmaAttributeSupport(Records).generateParsingHelpers(OS);
 }
 
+void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
+  emitSourceFileHeader("Clang attribute documentation", OS);
+
+  OS << R"cpp(
+  #include "clang/AST/Attr.h"
+  #include "llvm/ADT/StringRef.h"
+  )cpp";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+if (!A->getValueAsBit("ASTNode"))
+  continue;
+std::vector Docs = A->getValueAsListOfDefs("Documentation");
+for (const auto *D : Docs) {
+  OS << "\nstatic const char AttrDoc_" << A->getName() << "[] = "
+ << "R\"reST("
+ << D->getValueAsOptionalString("Content").getValueOr("").trim()
+ << ")reST\";\n";
+  // Only look at the first documentation if there are several.
+  // (As of now, only one attribute has multiple documentation entries).
+  break;
+}
+  }
+  OS << R"cpp(
+  static const llvm::StringRef AttrDoc[] = {
+  #define ATTR(NAME) AttrDoc_##NAME,
+  #include "clang/Basic/AttrList.inc"
+  };
+
+  llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
+if(K < llvm::array_lengthof(AttrDoc))
+  return AttrDoc[K];
+return "";
+  }
+  )cpp";
+}
+
 enum class SpellingKind {
   GNU,
   CXX11,
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -15,6 +15,7 @@
   ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
   ASTVectorTest.cpp
+  AttrTest.cpp
   CommentLexer.cpp
   CommentParser.cpp
   CommentTextTest.cpp
Index: clang/lib/AST/CMakeLists.txt
===
--- clang/lib/AST/CMakeLists.txt
+++ clang/lib/AST/CMakeLists.txt
@@ -13,6 +13,11 @@
   SOURCE Interp/Opcodes.td
   TARGET Opcodes)
 
+clang_tablegen(AttrDocTable.cpp -gen-clang-attr-doc-table
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../include/
+  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../include/clang/Basic/Attr.td
+  TARGET ClangAttrDocTable)
+
 add_clang_library(clangAST
   APValue.cpp
   ASTConcept.cpp
@@ -24,6 +29,7 @@
   ASTImporterLookupTable.cpp
   ASTStructuralEquivalence.cpp
   ASTTypeTraits.cpp
+  AttrDocTable.cpp
   AttrImpl.cpp
   Comment.cpp
   CommentBriefParser.cpp
Index: clang/include/clang/AST/Attr.h

[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

2021-08-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Awesome, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107720

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


[PATCH] D107690: [Modules] Do not remove failed modules after the control block phase

2021-08-10 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Made the first review pass and `return Failure` makes sense to me as recovery 
isn't the best idea at this point. Still want to check more thoroughly if the 
removed code for `SUBMODULE_UMBRELLA_HEADER` and `SUBMODULE_UMBRELLA_DIR` has 
any load-bearing side-effects.

Have no opinion on updating post-control-block functions to llvm::Error.




Comment at: clang/test/VFS/module-header-mismatches.m:2
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s;TEST_DIR;%/t;g" %t/sed-overlay.yaml > %t/overlay.yaml

Didn't know about `split-file`, that's nice.



Comment at: clang/test/VFS/umbrella-mismatch.m:4
-
-// RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -ivfsoverlay %t.yaml -F %S/Inputs -fsyntax-only %s 
-Wno-atimport-in-framework-header -verify
-// RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -F %S/Inputs -fsyntax-only %s 
-Wno-atimport-in-framework-header -verify

Are you deleting this test case because it is subsumed by 
module-header-mismatches.m?

Also if it makes sense to delete this test, need to do more cleanup because 
UsesFoo.framework and Foo.framework seem to be used only from this test. Though 
I'm not 100% sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107690

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


[PATCH] D107696: [CodeComplete] Basic code completion for attribute names.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4390
+  auto AddCompletions = [&](const ParsedAttrInfo &A) {
+if (A.IsTargetSpecific && !A.existsInTarget(Context.getTargetInfo()))
+  return;

aaron.ballman wrote:
> Should we also early return if the attribute is ignored? (See `IgnoredAttr` 
> in `Attr.td`) I'm assuming that attributes which do nothing are unlikely to 
> be high-value attributes to autocomplete (so maybe they'd go at the end of 
> the list if we wanted to keep them).
Hmm, I'm not sure about that.
They do nothing *in clang*, but using clang-based code completion doesn't 
particularly mean we'll use clang to build the code.
Something must care about the attribute, even if it's just a doc generator or 
something.

In practice, there are 6 attrs with Ignored = 1:
 - `bounded` is an openbsd-gcc extension
 - 3 are cuda-specific and probably only used by cuda stdlib headers
 - `__w64` is a keyword so not relevant here
 - `property` is actually supported by clang, it seems `Ignored` is lying!

So none of these are *terribly* important, but they also don't seem so 
worthless that it's important to exclude them. (There are other attributes that 
aren't important too!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107696

___
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-10 Thread Victor Huang via Phabricator via cfe-commits
NeHuang updated this revision to Diff 365470.
NeHuang added a comment.

Address review comments on the test case.


Repository:
  rG LLVM Github Monorepo

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

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,140 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux \
+; RUN:   -mcpu=pwr8 | FileCheck %s -check-prefix=CHECK-64B-LE
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64-unknown-linux \
+; RUN:   -mcpu=pwr7 | FileCheck %s -check-prefix=CHECK-64B-BE
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr7 | FileCheck %s -check-prefix=CHECK-64B-BE
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr7 | FileCheck %s -check-prefix=CHECK-32B-BE
+
+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-32B-BE-LABEL: test0:
+; CHECK-32B-BE:   # %bb.0: # %entry
+; CHECK-32B-BE-NEXT:mflr 0
+; CHECK-32B-BE-NEXT:stw 0, 8(1)
+; CHECK-32B-BE-NEXT:stwu 1, -32(1)
+; CHECK-32B-BE-NEXT:lwz 3, 40(1)
+; CHECK-32B-BE-NEXT:addi 1, 1, 32
+; CHECK-32B-BE-NEXT:lwz 0, 8(1)
+; CHECK-32B-BE-NEXT:mtlr 0
+; CHECK-32B-BE-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-32B-BE-LABEL: test1:
+; CHECK-32B-BE:   # %bb.0: # %entry
+; CHECK-32B-BE-NEXT:mflr 0
+; CHECK-32B-BE-NEXT:stw 0, 8(1)
+; CHECK-32B-BE-NEXT:stwu 1, -32(1)
+; CHECK-32B-BE-NEXT:lwz 3, 0(1)
+; CHECK-32B-BE-NEXT:lwz 3, 0(3)
+; CHECK-32B-BE-NEXT:lwz 3, 8(3)
+; CHECK-32B-BE-NEXT:addi 1, 1, 32
+; CHECK-32B-BE-NEXT:lwz 0, 8(1)
+; CHECK-32B-BE-NEXT:mtlr 0
+; CHECK-32B-BE-NEXT:blr
+entry:
+  %0 = tail call i8* @llvm.returnaddress(i32 1);
+  ret i8* %0
+}
+
+define i8* @test2() nounwind readnone {
+; CHECK-64B-LE-LABEL: test2:
+; 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, 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: test2:
+; 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, 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-32B-BE-LABEL: test2:
+; CHECK-32B-BE:   # %bb.0: # %entry
+; CHECK-32B-BE-NEXT:mflr 0
+; CHECK-32B-BE-NEXT:

[PATCH] D107138: [PowerPC] Implement cmplxl builtins

2021-08-10 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 365596.
Conanap added a comment.

Removed unintended change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107138

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-cmplx.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat-cmplx.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-cmplx.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-cmplx.c
@@ -226,3 +226,115 @@
 float _Complex testcmplxf(float real, float imag) {
   return __cmplxf(real, imag);
 }
+
+// 64BIT-LABEL: @test_xl_cmplxl(
+// 64BIT-NEXT:  entry:
+// 64BIT-NEXT:[[RETVAL:%.*]] = alloca { ppc_fp128, ppc_fp128 }, align 16
+// 64BIT-NEXT:[[LDA_ADDR:%.*]] = alloca ppc_fp128, align 16
+// 64BIT-NEXT:[[LDB_ADDR:%.*]] = alloca ppc_fp128, align 16
+// 64BIT-NEXT:store ppc_fp128 [[LDA:%.*]], ppc_fp128* [[LDA_ADDR]], align 16
+// 64BIT-NEXT:store ppc_fp128 [[LDB:%.*]], ppc_fp128* [[LDB_ADDR]], align 16
+// 64BIT-NEXT:[[TMP0:%.*]] = load ppc_fp128, ppc_fp128* [[LDA_ADDR]], align 16
+// 64BIT-NEXT:[[TMP1:%.*]] = load ppc_fp128, ppc_fp128* [[LDB_ADDR]], align 16
+// 64BIT-NEXT:[[RETVAL_REALP:%.*]] = getelementptr inbounds { ppc_fp128, ppc_fp128 }, { ppc_fp128, ppc_fp128 }* [[RETVAL]], i32 0, i32 0
+// 64BIT-NEXT:[[RETVAL_IMAGP:%.*]] = getelementptr inbounds { ppc_fp128, ppc_fp128 }, { ppc_fp128, ppc_fp128 }* [[RETVAL]], i32 0, i32 1
+// 64BIT-NEXT:store ppc_fp128 [[TMP0]], ppc_fp128* [[RETVAL_REALP]], align 16
+// 64BIT-NEXT:store ppc_fp128 [[TMP1]], ppc_fp128* [[RETVAL_IMAGP]], align 16
+// 64BIT-NEXT:[[TMP2:%.*]] = load { ppc_fp128, ppc_fp128 }, { ppc_fp128, ppc_fp128 }* [[RETVAL]], align 16
+// 64BIT-NEXT:ret { ppc_fp128, ppc_fp128 } [[TMP2]]
+//
+// 64BITLE-LABEL: @test_xl_cmplxl(
+// 64BITLE-NEXT:  entry:
+// 64BITLE-NEXT:[[RETVAL:%.*]] = alloca { ppc_fp128, ppc_fp128 }, align 16
+// 64BITLE-NEXT:[[LDA_ADDR:%.*]] = alloca ppc_fp128, align 16
+// 64BITLE-NEXT:[[LDB_ADDR:%.*]] = alloca ppc_fp128, align 16
+// 64BITLE-NEXT:store ppc_fp128 [[LDA:%.*]], ppc_fp128* [[LDA_ADDR]], align 16
+// 64BITLE-NEXT:store ppc_fp128 [[LDB:%.*]], ppc_fp128* [[LDB_ADDR]], align 16
+// 64BITLE-NEXT:[[TMP0:%.*]] = load ppc_fp128, ppc_fp128* [[LDA_ADDR]], align 16
+// 64BITLE-NEXT:[[TMP1:%.*]] = load ppc_fp128, ppc_fp128* [[LDB_ADDR]], align 16
+// 64BITLE-NEXT:[[RETVAL_REALP:%.*]] = getelementptr inbounds { ppc_fp128, ppc_fp128 }, { ppc_fp128, ppc_fp128 }* [[RETVAL]], i32 0, i32 0
+// 64BITLE-NEXT:[[RETVAL_IMAGP:%.*]] = getelementptr inbounds { ppc_fp128, ppc_fp128 }, { ppc_fp128, ppc_fp128 }* [[RETVAL]], i32 0, i32 1
+// 64BITLE-NEXT:store ppc_fp128 [[TMP0]], ppc_fp128* [[RETVAL_REALP]], align 16
+// 64BITLE-NEXT:store ppc_fp128 [[TMP1]], ppc_fp128* [[RETVAL_IMAGP]], align 16
+// 64BITLE-NEXT:[[TMP2:%.*]] = load { ppc_fp128, ppc_fp128 }, { ppc_fp128, ppc_fp128 }* [[RETVAL]], align 16
+// 64BITLE-NEXT:ret { ppc_fp128, ppc_fp128 } [[TMP2]]
+//
+// 64BITAIX-LABEL: @test_xl_cmplxl(
+// 64BITAIX-NEXT:  entry:
+// 64BITAIX-NEXT:[[RETVAL:%.*]] = alloca { double, double }, align 4
+// 64BITAIX-NEXT:[[LDA_ADDR:%.*]] = alloca double, align 8
+// 64BITAIX-NEXT:[[LDB_ADDR:%.*]] = alloca double, align 8
+// 64BITAIX-NEXT:store double [[LDA:%.*]], double* [[LDA_ADDR]], align 8
+// 64BITAIX-NEXT:store double [[LDB:%.*]], double* [[LDB_ADDR]], align 8
+// 64BITAIX-NEXT:[[TMP0:%.*]] = load double, double* [[LDA_ADDR]], align 8
+// 64BITAIX-NEXT:[[TMP1:%.*]] = load double, double* [[LDB_ADDR]], align 8
+// 64BITAIX-NEXT:[[RETVAL_REALP:%.*]] = getelementptr inbounds { double, double }, { double, double }* [[RETVAL]], i32 0, i32 0
+// 64BITAIX-NEXT:[[RETVAL_IMAGP:%.*]] = getelementptr inbounds { double, double }, { double, double }* [[RETVAL]], i32 0, i32 1
+// 64BITAIX-NEXT:store double [[TMP0]], double* [[RETVAL_REALP]], align 4
+// 64BITAIX-NEXT:store double [[TMP1]], double* [[RETVAL_IMAGP]], align 4
+// 64BITAIX-NEXT:[[TMP2:%.*]] = load { double, double }, { double, double }* [[RETVAL]], align 4
+// 64BITAIX-NEXT:ret { double, double } [[TMP2]]
+//
+// 32BIT-LABEL: @test_xl_cmplxl(
+// 32BIT-NEXT:  entry:
+// 32BIT-NEXT:[[LDA_ADDR:%.*]] = alloca ppc_fp128, align 16
+// 32BIT-NEXT:[[LDB_ADDR:%.*]] = alloca ppc_fp128, align 16
+// 32BIT-NEXT:store ppc_fp128 [[LDA:%.*]], ppc_fp128* [[LDA_ADDR]], align 16
+// 32BIT-NEXT:store ppc_fp128 [[LDB:%.*]], ppc_fp128* [[LDB_ADDR]], align 16
+// 32BIT-NEXT:[[TMP0:%.*]] = load ppc_fp128, ppc_fp128* [[LDA_ADDR]], align 16
+// 32BIT-NEXT:[[TMP1:%.*]] = load ppc_fp128, ppc_fp128* [[LDB_ADDR]], align 16
+// 32BIT-NEXT:[[AGG_RESULT_REALP:%.*]] = getelementptr inbounds { ppc_fp128, ppc_fp128 }, { ppc_fp128, ppc_fp128 }* [[AGG_RESULT:%.*]], i32 0, i32 0
+// 32BIT-NE

[PATCH] D107703: [AST][clangd] Expose documentation of Attrs on hover.

2021-08-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 365601.
sammccall added a comment.

Oops, I'm just bad at git. Here's the test file!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107703

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/Attr.h
  clang/lib/AST/CMakeLists.txt
  clang/unittests/AST/AttrTest.cpp
  clang/unittests/AST/CMakeLists.txt
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -61,6 +61,7 @@
llvm::raw_ostream &OS);
 void EmitClangAttrNodeTraverse(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
+void EmitClangAttrDocTable(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 
 void EmitClangDiagsDefs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS,
 const std::string &Component);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -30,6 +30,7 @@
   GenClangAttrSubjectMatchRulesParserStringSwitches,
   GenClangAttrImpl,
   GenClangAttrList,
+  GenClangAttrDocTable,
   GenClangAttrSubjectMatchRuleList,
   GenClangAttrPCHRead,
   GenClangAttrPCHWrite,
@@ -115,6 +116,8 @@
"Generate clang attribute implementations"),
 clEnumValN(GenClangAttrList, "gen-clang-attr-list",
"Generate a clang attribute list"),
+clEnumValN(GenClangAttrDocTable, "gen-clang-attr-doc-table",
+   "Generate a table of attribute documentation"),
 clEnumValN(GenClangAttrSubjectMatchRuleList,
"gen-clang-attr-subject-match-rule-list",
"Generate a clang attribute subject match rule list"),
@@ -280,6 +283,9 @@
   case GenClangAttrList:
 EmitClangAttrList(Records, OS);
 break;
+  case GenClangAttrDocTable:
+EmitClangAttrDocTable(Records, OS);
+break;
   case GenClangAttrSubjectMatchRuleList:
 EmitClangAttrSubjectMatchRuleList(Records, OS);
 break;
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4210,6 +4210,42 @@
   getPragmaAttributeSupport(Records).generateParsingHelpers(OS);
 }
 
+void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
+  emitSourceFileHeader("Clang attribute documentation", OS);
+
+  OS << R"cpp(
+  #include "clang/AST/Attr.h"
+  #include "llvm/ADT/StringRef.h"
+  )cpp";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+if (!A->getValueAsBit("ASTNode"))
+  continue;
+std::vector Docs = A->getValueAsListOfDefs("Documentation");
+for (const auto *D : Docs) {
+  OS << "\nstatic const char AttrDoc_" << A->getName() << "[] = "
+ << "R\"reST("
+ << D->getValueAsOptionalString("Content").getValueOr("").trim()
+ << ")reST\";\n";
+  // Only look at the first documentation if there are several.
+  // (As of now, only one attribute has multiple documentation entries).
+  break;
+}
+  }
+  OS << R"cpp(
+  static const llvm::StringRef AttrDoc[] = {
+  #define ATTR(NAME) AttrDoc_##NAME,
+  #include "clang/Basic/AttrList.inc"
+  };
+
+  llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
+if(K < llvm::array_lengthof(AttrDoc))
+  return AttrDoc[K];
+return "";
+  }
+  )cpp";
+}
+
 enum class SpellingKind {
   GNU,
   CXX11,
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -15,6 +15,7 @@
   ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
   ASTVectorTest.cpp
+  AttrTest.cpp
   CommentLexer.cpp
   CommentParser.cpp
   CommentTextTest.cpp
Index: clang/unittests/AST/AttrTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/AttrTest.cpp
@@ -0,0 +1,24 @@
+//===- unittests/AST/AttrTests.cpp --- Attribute tests ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/Attr.h"
+#include "clang/Basic/AttrKinds.h"
+#include "gmock/gmock.h"
+#include "gtest/gt

[clang-tools-extra] 0cecb42 - [Sema] Include full range of the switch condition in -Wswitch diagnostic

2021-08-10 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-08-10T22:50:40+02:00
New Revision: 0cecb42e4e13e1ce55a3568958ad104bbe6b6d6e

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

LOG: [Sema] Include full range of the switch condition in -Wswitch diagnostic

Added: 


Modified: 
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 870402588e763..d4450b31e5f38 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -191,6 +191,26 @@ o]]();
 "change 'fod' to 'foo'");
 }
 
+// Verify that the -Wswitch case-not-covered diagnostic range covers the
+// whole expression. This is important because the "populate-switch" tweak
+// fires for the full expression range (see tweaks/PopulateSwitchTests.cpp).
+// The quickfix flow only works end-to-end if the tweak can be triggered on
+// the diagnostic's range.
+TEST(DiagnosticsTest, WSwitch) {
+  Annotations Test(R"cpp(
+enum A { X };
+struct B { A a; };
+void foo(B b) {
+  switch ([[b.a]]) {}
+}
+  )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ExtraArgs = {"-Wswitch"};
+  EXPECT_THAT(*TU.build().getDiagnostics(),
+  ElementsAre(Diag(Test.range(),
+   "enumeration value 'X' not handled in 
switch")));
+}
+
 TEST(DiagnosticsTest, FlagsMatter) {
   Annotations Test("[[void]] main() {} // error-ok");
   auto TU = TestTU::withCode(Test.code());

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 3baccec2d7bb4..f4f7e353a2c17 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -1563,7 +1563,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 
Stmt *Switch,
 auto DB = Diag(CondExpr->getExprLoc(), TheDefaultStmt
? 
diag::warn_def_missing_case
: diag::warn_missing_case)
-  << (int)UnhandledNames.size();
+  << CondExpr->getSourceRange() << (int)UnhandledNames.size();
 
 for (size_t I = 0, E = std::min(UnhandledNames.size(), (size_t)3);
  I != E; ++I)



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


[clang] d39ebda - [analyzer] Cleanup a FIXME in SValBuilder.cpp

2021-08-10 Thread via cfe-commits

Author: Vince Bridgers
Date: 2021-08-10T16:12:52-05:00
New Revision: d39ebdae674c8efc84ebe8dc32716ec353220530

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

LOG: [analyzer] Cleanup a FIXME in SValBuilder.cpp

This change follows up on a FIXME submitted with D105974. This change simply 
let's the reference case fall through to return a concrete 'true'
instead of a nonloc pointer of appropriate length set to NULL.

Reviewed By: NoQ

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

Added: 
clang/test/Analysis/solver-sym-simplification-bool.cpp

Modified: 
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index b459b5adb5110..8d27ba3e65c46 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@ SVal SValBuilder::evalCastSubKind(loc::MemRegionVal V, 
QualType CastTy,
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt &Zero = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);

diff  --git a/clang/test/Analysis/solver-sym-simplification-bool.cpp 
b/clang/test/Analysis/solver-sym-simplification-bool.cpp
new file mode 100644
index 0..0e7633dfb87e0
--- /dev/null
+++ b/clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}



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


[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

2021-08-10 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd39ebdae674c: [analyzer] Cleanup a FIXME in SValBuilder.cpp 
(authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107720

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/solver-sym-simplification-bool.cpp


Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt &Zero = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);


Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt &Zero = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107850: [WIP][asan] Implemented custom calling convention similar used by HWASan for X86. The feature should be code complete. The tests are coming in a later revision.

2021-08-10 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 365608.
kstoimenov added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Added an IR test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107850

Files:
  clang/test/CodeGen/asan-use-callbacks.cpp
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Target/X86/X86AsmPrinter.cpp
  llvm/lib/Target/X86/X86AsmPrinter.h
  llvm/lib/Target/X86/X86InstrCompiler.td
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86RegisterInfo.td
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
cl::Hidden, cl::init(true));
 
+static cl::opt ClOptimizeCallbacks("asan-optimize-callbacks",
+ cl::desc("Optimize callbacks"),
+ cl::Hidden, cl::init(false));
+
 static cl::opt ClOptSameTemp(
 "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
 cl::Hidden, cl::init(true));
@@ -623,6 +627,7 @@
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
+Int8PtrTy = Type::getInt8PtrTy(*C);
 TargetTriple = Triple(M.getTargetTriple());
 
 Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -673,6 +678,7 @@
  Value *SizeArgument, uint32_t Exp);
   void instrumentMemIntrinsic(MemIntrinsic *MI);
   Value *memToShadow(Value *Shadow, IRBuilder<> &IRB);
+  void encodeMemToShadowInfo(int64_t *AccessInfo);
   bool suppressInstrumentationSiteForDebug(int &Instrumented);
   bool instrumentFunction(Function &F, const TargetLibraryInfo *TLI);
   bool maybeInsertAsanInitAtFunctionEntry(Function &F);
@@ -713,6 +719,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+  Type *Int8PtrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
   FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction;
@@ -1361,6 +1368,15 @@
 return IRB.CreateAdd(Shadow, ShadowBase);
 }
 
+void AddressSanitizer::encodeMemToShadowInfo(int64_t *AccessInfo) {
+  *AccessInfo +=
+  (Mapping.Scale << AsanAccessInfo::MappingScaleShift) +
+  (Mapping.OrShadowOffset << AsanAccessInfo::OrShadowOffsetShift);
+  if (LocalDynamicShadow || Mapping.InGlobal) {
+// TODO(kstoimenov): for now fail.
+  }
+}
+
 // Instrument memset/memmove/memcpy
 void AddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI) {
   IRBuilder<> IRB(MI);
@@ -1742,12 +1758,25 @@
   size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
 
   if (UseCalls) {
-if (Exp == 0)
-  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
- AddrLong);
-else
-  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
- {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
+if (ClOptimizeCallbacks) {
+  Value *Ptr8 = IRB.CreatePointerCast(Addr, Int8PtrTy);
+  Module *M = IRB.GetInsertBlock()->getParent()->getParent();
+  int64_t AccessInfo =
+  (IsWrite << AsanAccessInfo::IsWriteShift) +
+  (AccessSizeIndex << AsanAccessInfo::AccessSizeIndexShift);
+  encodeMemToShadowInfo(&AccessInfo);
+  IRB.CreateCall(
+  Intrinsic::getDeclaration(M, Intrinsic::asan_check_memaccess),
+  {Ptr8, ConstantInt::get(IRB.getInt64Ty(), Mapping.Offset),
+   ConstantInt::get(IRB.getInt32Ty(), AccessInfo)});
+} else {
+  if (Exp == 0)
+IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
+   AddrLong);
+  else
+IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
+   {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
+}
 return;
   }
 
Index: llvm/lib/Target/X86/X86RegisterInfo.td
===
--- llvm/lib/Target/X86/X86RegisterInfo.td
+++ llvm/lib/Target/X86/X86RegisterInfo.td
@@ -436,6 +436,12 @@
  (add RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
   RBX, R14, R15, R12, R13, RBP, RSP, RIP)>;
 
+// GR64 - 64-bit GPRs without RAX and RIP. Could be used when emitting code for
+// intrinsics, which use implict input registers.
+def GR64NoRAX : RegisterClass<"X86", [i64], 64,
+  (add RCX, RDX, RSI, RDI, R8, R9, R10, R11,
+  

[PATCH] D107138: [PowerPC] Implement cmplxl builtins

2021-08-10 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai 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/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


  1   2   >