[PATCH] D77644: [clangd] Handle additional includes while parsing ASTs

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 8 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:280
 const PreambleData &Baseline) {
+  assert(llvm::sys::path::is_absolute(FileName) && "relative FileName!");
   // First scan the include directives in Baseline and Modified. These will be

sammccall wrote:
> BTW do we want to check isPreambleCompatible and bail out early if it is, or 
> is that the caller's job?
I am planning to leave it to the caller. Eventually this PreamblePatch should 
be generated by TUScheduler, in which we can check for staleness and issue 
either an unmodified patch or create a patch and use it until new preamble is 
ready or patch is invalidated.



Comment at: clang-tools-extra/clangd/Preamble.cpp:332
+  for (auto &Inc : *ModifiedIncludes) {
+auto It = ExistingIncludes.find({Inc.Directive, Inc.Written});
+// Include already present in the baseline preamble. Set resolved path and

sammccall wrote:
> This explicitly looks at the existing includes based on spelling, and not 
> whether the include was resolved during scanning or not.
> 
> One implication is that if you insert an #include that was already 
> transitively included (which IIUC will hit the preamble VFS cache and thus be 
> resolved) then we're not going to take advantage of this to record its 
> resolution now.
> 
> Instead we're going to parse it along with the mainfile, and... well, I 
> *hope* everything works out:
>  - do we pay for the stat, or is the preamble's stat cache still in effect?
>  - if the file is include-guarded, we're not going to read or parse it I 
> guess?
>  - if it's not include-guarded but #imported, then again we won't re-read or 
> re-parse it because we use the same directive?
>  - if the file isn't include-guarded, I guess we must read it (because 
> preamble doesn't contain the actual buffer) and then parse it, but such is 
> life. 
> 
> This explicitly looks at the existing includes based on spelling, and not 
> whether the include was resolved during scanning or not.

Right. Scanning won't resolve anything as we pass an empty FS to preprocessor.

> Instead we're going to parse it along with the mainfile, and... well, I 
> *hope* everything works out:
> do we pay for the stat, or is the preamble's stat cache still in effect?

It depends on the user of PreamblePatch, while building an AST we build 
preprocessor with cached fs coming from preamble.

> if the file is include-guarded, we're not going to read or parse it I guess?

Yes that's the case. We'll only see the include directive.

> if it's not include-guarded but #imported, then again we won't re-read or 
> re-parse it because we use the same directive?

Yes again.

> if the file isn't include-guarded, I guess we must read it (because preamble 
> doesn't contain the actual buffer) and then parse it, but such is life.

Unfortunately yes again, but as you said i am not sure if that's a case we 
should try and recover from as i can only see two use cases:
- You include the header in a different preprocessor state and intentionally 
want it to parse again, hopefully we'll handle this after macro patching.
- You deleted the include from a transitively included file and inserted it 
back into this file again. Well, now the hell breaks loose until we build the 
preamble again. In the worst case AST will turn into a garbage and we won't be 
able to serve anything but code completions, which is the state of the world 
without preamble patching, we are just consuming more cpu now.



Comment at: clang-tools-extra/clangd/Preamble.cpp:340
 }
 // FIXME: Traverse once
 auto LineCol = offsetToClangLineColumn(Modified.Contents, Inc.HashOffset);

sammccall wrote:
> nice to have a comment similar to the one on line 333 for this case
> ```
> // Include is new in the modified preamble.
> // Inject it into the patch and use #line to set the presumed location to 
> where it is spelled
> ```
handled in D78743


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77644



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


[PATCH] D77644: [clangd] Handle additional includes while parsing ASTs

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 261745.
kadircet marked an inline comment as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77644

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -8,6 +8,7 @@
 
 #include "Annotations.h"
 #include "Compiler.h"
+#include "Headers.h"
 #include "Preamble.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -21,6 +22,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -30,49 +32,53 @@
 namespace clangd {
 namespace {
 
+MATCHER_P2(Distance, File, D, "") {
+  return arg.first() == File && arg.second == D;
+}
+
+std::shared_ptr
+createPreamble(llvm::StringRef Contents = "") {
+  auto TU = TestTU::withCode(Contents);
+  // ms-compatibility changes meaning of #import, make sure it is turned off.
+  TU.ExtraArgs = {"-fno-ms-compatibility"};
+  TU.Filename = "preamble.cpp";
+  auto PI = TU.inputs();
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(PI, Diags);
+  if (!CI) {
+ADD_FAILURE() << "failed to build compiler invocation";
+return nullptr;
+  }
+  if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
+return Preamble;
+  ADD_FAILURE() << "failed to build preamble";
+  return nullptr;
+}
+
 // Builds a preamble for BaselineContents, patches it for ModifiedContents and
 // returns the includes in the patch.
 IncludeStructure collectPatchedIncludes(llvm::StringRef ModifiedContents,
 llvm::StringRef BaselineContents) {
-  std::string MainFile = testPath("main.cpp");
-  ParseInputs PI;
-  PI.FS = new llvm::vfs::InMemoryFileSystem;
-  MockCompilationDatabase CDB;
-  // ms-compatibility changes meaning of #import, make sure it is turned off.
-  CDB.ExtraClangFlags.push_back("-fno-ms-compatibility");
-  PI.CompileCommand = CDB.getCompileCommand(MainFile).getValue();
-  // Create invocation
-  IgnoreDiagnostics Diags;
-  auto CI = buildCompilerInvocation(PI, Diags);
-  assert(CI && "failed to create compiler invocation");
-  // Build baseline preamble.
-  PI.Contents = BaselineContents.str();
-  PI.Version = "baseline preamble";
-  auto BaselinePreamble = buildPreamble(MainFile, *CI, PI, true, nullptr);
-  assert(BaselinePreamble && "failed to build baseline preamble");
+  auto BaselinePreamble = createPreamble(BaselineContents);
   // Create the patch.
-  PI.Contents = ModifiedContents.str();
-  PI.Version = "modified contents";
-  auto PP = PreamblePatch::create(MainFile, PI, *BaselinePreamble);
+  auto TU = TestTU::withCode(ModifiedContents);
+  auto PI = TU.inputs();
+  auto PP = PreamblePatch::create(testPath(TU.Filename), PI, *BaselinePreamble);
   // Collect patch contents.
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(PI, Diags);
   PP.apply(*CI);
-  llvm::StringRef PatchContents;
-  for (const auto &Rempaped : CI->getPreprocessorOpts().RemappedFileBuffers) {
-if (Rempaped.first == testPath("__preamble_patch__.h")) {
-  PatchContents = Rempaped.second->getBuffer();
-  break;
-}
-  }
-  // Run preprocessor over the modified contents with patched Invocation to and
-  // BaselinePreamble to collect includes in the patch. We trim the input to
-  // only preamble section to not collect includes in the mainfile.
+  // Run preprocessor over the modified contents with patched Invocation. We
+  // provide a preamble and trim contents to ensure only the implicit header
+  // introduced by the patch is parsed and nothing else.
+  // We don't run PP directly over the patch cotents to test production
+  // behaviour.
   auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts());
   auto Clang =
   prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble,
   llvm::MemoryBuffer::getMemBufferCopy(
   ModifiedContents.slice(0, Bounds.Size).str()),
   PI.FS, Diags);
-  Clang->getPreprocessorOpts().ImplicitPCHInclude.clear();
   PreprocessOnlyAction Action;
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
 ADD_FAILURE() << "failed begin source file";
@@ -150,6 +156,32 @@
   Field(&Inclusion::Written, "")));
 }
 
+TEST(PreamblePatchTest, PatchesPreambleIncludes) {
+  IgnoreDiagnostics Diags;

[PATCH] D78743: [clangd] Preserve line information while build PreamblePatch

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 261744.
kadircet added a comment.

- Rebase, add comments and introduce Inclusion equality


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78743

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -10,31 +10,88 @@
 #include "Compiler.h"
 #include "Preamble.h"
 #include "TestFS.h"
+#include "TestTU.h"
+#include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 
+using testing::Field;
+
 namespace clang {
 namespace clangd {
 namespace {
 
-using testing::_;
-using testing::Contains;
-using testing::Pair;
-
-MATCHER_P(HasContents, Contents, "") { return arg->getBuffer() == Contents; }
-
-TEST(PreamblePatchTest, IncludeParsing) {
-  MockFSProvider FS;
+// Builds a preamble for BaselineContents, patches it for ModifiedContents and
+// returns the includes in the patch.
+IncludeStructure collectPatchedIncludes(llvm::StringRef ModifiedContents,
+llvm::StringRef BaselineContents) {
+  std::string MainFile = testPath("main.cpp");
+  ParseInputs PI;
+  PI.FS = new llvm::vfs::InMemoryFileSystem;
   MockCompilationDatabase CDB;
+  // ms-compatibility changes meaning of #import, make sure it is turned off.
+  CDB.ExtraClangFlags.push_back("-fno-ms-compatibility");
+  PI.CompileCommand = CDB.getCompileCommand(MainFile).getValue();
+  // Create invocation
   IgnoreDiagnostics Diags;
-  ParseInputs PI;
-  PI.FS = FS.getFileSystem();
+  auto CI = buildCompilerInvocation(PI, Diags);
+  assert(CI && "failed to create compiler invocation");
+  // Build baseline preamble.
+  PI.Contents = BaselineContents.str();
+  PI.Version = "baseline preamble";
+  auto BaselinePreamble = buildPreamble(MainFile, *CI, PI, true, nullptr);
+  assert(BaselinePreamble && "failed to build baseline preamble");
+  // Create the patch.
+  PI.Contents = ModifiedContents.str();
+  PI.Version = "modified contents";
+  auto PP = PreamblePatch::create(MainFile, PI, *BaselinePreamble);
+  // Collect patch contents.
+  PP.apply(*CI);
+  llvm::StringRef PatchContents;
+  for (const auto &Rempaped : CI->getPreprocessorOpts().RemappedFileBuffers) {
+if (Rempaped.first == testPath("__preamble_patch__.h")) {
+  PatchContents = Rempaped.second->getBuffer();
+  break;
+}
+  }
+  // Run preprocessor over the modified contents with patched Invocation to and
+  // BaselinePreamble to collect includes in the patch. We trim the input to
+  // only preamble section to not collect includes in the mainfile.
+  auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts());
+  auto Clang =
+  prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble,
+  llvm::MemoryBuffer::getMemBufferCopy(
+  ModifiedContents.slice(0, Bounds.Size).str()),
+  PI.FS, Diags);
+  Clang->getPreprocessorOpts().ImplicitPCHInclude.clear();
+  PreprocessOnlyAction Action;
+  if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
+ADD_FAILURE() << "failed begin source file";
+return {};
+  }
+  IncludeStructure Includes;
+  Clang->getPreprocessor().addPPCallbacks(
+  collectIncludeStructureCallback(Clang->getSourceManager(), &Includes));
+  if (llvm::Error Err = Action.Execute()) {
+ADD_FAILURE() << "failed to execute action: " << std::move(Err);
+return {};
+  }
+  Action.EndSourceFile();
+  return Includes;
+}
 
+// Check preamble lexing logic by building an empty preamble and patching it
+// with all the contents.
+TEST(PreamblePatchTest, IncludeParsing) {
   // We expect any line with a point to show up in the patch.
   llvm::StringRef Cases[] = {
   // Only preamble
@@ -61,69 +118,36 @@
 ^#include )cpp",
   };
 
-  // ms-compatibility changes meaning of #import, make sure it is turned off.
-  CDB.ExtraClangFlags.push_back("-fno-ms-compatibility");
-  const auto FileName = testPath("foo.cc");
   for (const auto Case : Cases) {
 Annotations Test(Case);
 const auto Code = Test.code();
-PI.CompileCommand = *CDB.getCompileCommand(FileName);
-
 SCOPED_TRACE(Code);
-// Check preamble lexing logic by building an empty preamble and patching it
-// with all the contents.
- 

[PATCH] D79293: [clang-format] [PR45218] Fix an issue where < and > and >> in a for loop gets incorrectly interpreted at a TemplateOpener/Closer

2020-05-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added a comment.

> For what is worth, with lambdas in unevaluated context (C++20), you can get a 
> semicolon between template opener/closer easily:

I actually no longer need the check for the semi if the TemplateOpener/Closer 
is correctly labelled




Comment at: clang/lib/Format/TokenAnnotator.cpp:40
 /// keyword as a potential Objective-C selector component.
 static bool canBeObjCSelectorComponent(const FormatToken &Tok) {
   return Tok.Tok.getIdentifierInfo() != nullptr;

curdeius wrote:
> I know you haven't changed this, but...
> Static function (internal linkage) in anonymous namespace?
I believe the guideline is to not use anonymous namespaces for functions

https://llvm.org/docs/CodingStandards.html#anonymous-namespaces

(not my personal preference mind)


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

https://reviews.llvm.org/D79293



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


[PATCH] D79313: [clangd] NFC: Cleanup unused headers and libraries

2020-05-04 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov, mgorny.
Herald added a project: clang.

Extended version of D78843 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79313

Files:
  clang-tools-extra/clangd/Features.inc.in
  clang-tools-extra/clangd/index/dex/dexp/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -9,12 +9,8 @@
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
 
 #include 
Index: clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
@@ -1,5 +1,4 @@
 set(LLVM_LINK_COMPONENTS
-  LineEditor
   Support
   )
 add_clang_executable(clangd-index-server
@@ -8,6 +7,7 @@
   DEPENDS
   RemoteIndexProtos
   )
+
 target_link_libraries(clangd-index-server
   PRIVATE
   clangDaemon
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
@@ -13,7 +13,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_REMOTE_MARSHALLING_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_REMOTE_MARSHALLING_H
 
-#include "Index.grpc.pb.h"
+#include "Index.pb.h"
 #include "index/Index.h"
 #include "llvm/Support/StringSaver.h"
 
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -14,7 +14,6 @@
 #include "marshalling/Marshalling.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
-#include "llvm/Support/YAMLTraits.h"
 
 namespace clang {
 namespace clangd {
Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -11,15 +11,12 @@
 //
 
//===--===//
 
-#include "Features.inc"
-#include "SourceCode.h"
 #include "index/Serialization.h"
 #include "index/dex/Dex.h"
 #include "index/remote/Client.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Signals.h"
Index: clang-tools-extra/clangd/index/dex/dexp/CMakeLists.txt
===
--- clang-tools-extra/clangd/index/dex/dexp/CMakeLists.txt
+++ clang-tools-extra/clangd/index/dex/dexp/CMakeLists.txt
@@ -1,5 +1,4 @@
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../)
 
 set(LLVM_LINK_COMPONENTS
   LineEditor
Index: clang-tools-extra/clangd/Features.inc.in
===
--- clang-tools-extra/clangd/Features.inc.in
+++ clang-tools-extra/clangd/Features.inc.in
@@ -1,2 +1 @@
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
-#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -9,12 +9,8 @@
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
 
 #include 
Index: clang-tool

[PATCH] D74051: Move update_cc_test_checks.py tests to clang

2020-05-04 Thread Michał Górny via Phabricator via cfe-commits
mgorny resigned from this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

Nevermind, I figured out good enough workaround.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74051



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


[PATCH] D79293: [clang-format] [PR45218] Fix an issue where < and > and >> in a for loop gets incorrectly interpreted at a TemplateOpener/Closer

2020-05-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 261748.
MyDeveloperDay marked 3 inline comments as done.
MyDeveloperDay added a comment.

Remove tok::semi check as its not actually needed now we label the < and > 
correctly


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

https://reviews.llvm.org/D79293

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7065,6 +7065,21 @@
   verifyFormat("static_assert(is_convertible::value, \"AAA\");");
   verifyFormat("Constructor(A... a) : a_(X{std::forward(a)}...) {}");
   verifyFormat("< < < < < < < < < < < < < < < < < < < < < < < < < < < < < <");
+
+  verifyFormat("some_templated_type");
+}
+
+TEST_F(FormatTest, UnderstandsShiftOperators) {
+  verifyFormat("if (i < x >> 1)");
+  verifyFormat("while (i < x >> 1)");
+  verifyFormat("for (unsigned i = 0; i < i; ++i, v = v >> 1)");
+  verifyFormat("for (unsigned i = 0; i < x >> 1; ++i, v = v >> 1)");
+  verifyFormat(
+  "for (std::vector::iterator i = 0; i < x >> 1; ++i, v = v >> 1)");
+  verifyFormat("Foo.call>()");
+  verifyFormat("if (Foo.call>() == 0)");
+  verifyFormat("for (std::vector>::iterator i = 0; i < x >> 1; "
+   "++i, v = v >> 1)");
 }
 
 TEST_F(FormatTest, BitshiftOperatorWidth) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -119,7 +119,16 @@
 (Style.Language == FormatStyle::LK_Proto && Left->Previous &&
  Left->Previous->isOneOf(TT_SelectorName, TT_DictLiteral)))
   CurrentToken->Type = TT_DictLiteral;
-else
+// In if/for/while  (i < x >> 1) ensure we don't see the <> as
+// TemplateOpener/Closer
+else if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
+ CurrentToken->Next->Next &&
+ !CurrentToken->Next->Next->isOneOf(tok::l_paren,
+tok::coloncolon) &&
+ Line.First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_while)) {
+  Left->Type = TT_BinaryOperator;
+  return false;
+} else
   CurrentToken->Type = TT_TemplateCloser;
 next();
 return true;
@@ -1522,8 +1531,8 @@
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (Current.is(tok::exclaim)) {
 if (Current.Previous &&
-(Keywords.IsJavaScriptIdentifier(
- *Current.Previous, /* AcceptIdentifierName= */ true) ||
+(Keywords.IsJavaScriptIdentifier(*Current.Previous,
+ /*AcceptIdentifierName=*/true) ||
  Current.Previous->isOneOf(
  tok::kw_namespace, tok::r_paren, tok::r_square, tok::r_brace,
  Keywords.kw_type, Keywords.kw_get, Keywords.kw_set) ||
@@ -2174,7 +2183,7 @@
   FormatToken *Current;
 };
 
-} // end anonymous namespace
+} // namespace
 
 void TokenAnnotator::setCommentLineLevels(
 SmallVectorImpl &Lines) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7065,6 +7065,21 @@
   verifyFormat("static_assert(is_convertible::value, \"AAA\");");
   verifyFormat("Constructor(A... a) : a_(X{std::forward(a)}...) {}");
   verifyFormat("< < < < < < < < < < < < < < < < < < < < < < < < < < < < < <");
+
+  verifyFormat("some_templated_type");
+}
+
+TEST_F(FormatTest, UnderstandsShiftOperators) {
+  verifyFormat("if (i < x >> 1)");
+  verifyFormat("while (i < x >> 1)");
+  verifyFormat("for (unsigned i = 0; i < i; ++i, v = v >> 1)");
+  verifyFormat("for (unsigned i = 0; i < x >> 1; ++i, v = v >> 1)");
+  verifyFormat(
+  "for (std::vector::iterator i = 0; i < x >> 1; ++i, v = v >> 1)");
+  verifyFormat("Foo.call>()");
+  verifyFormat("if (Foo.call>() == 0)");
+  verifyFormat("for (std::vector>::iterator i = 0; i < x >> 1; "
+   "++i, v = v >> 1)");
 }
 
 TEST_F(FormatTest, BitshiftOperatorWidth) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -119,7 +119,16 @@
 (Style.Language == FormatStyle::LK_Proto && Left->Previous &&
  Left->Previous->isOneOf(TT_SelectorName, TT_DictLiteral)))
   CurrentToken->Type = TT_DictLiteral;
-else
+// In if/for/while  (i < x >> 1) ensure we don't see the <> as
+// TemplateOpener/Closer
+else if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
+ Cu

[PATCH] D79276: [FileCheck] Support comment directives

2020-05-04 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

I hesitate to suggest this, but is it worth using `REM` as a comment prefix? 
It's the comment marker for Windows batch files, so has some precedence.




Comment at: llvm/docs/CommandGuide/FileCheck.rst:57
+ By default, FileCheck ignores any occurrence in ``match-filename`` of any 
check
+ prefix if it is preceded on the same line by "``COM:``" or "``RUN:``".  See 
the
+ section `The "COM:" directive`_ for usage details.

Nit: the rest of this document uses single spaces after full stops. Please do 
that in the new text too.



Comment at: llvm/lib/Support/FileCheck.cpp:1930
 
+bool FileCheck::ValidateCheckPrefixes() {
+  StringSet<> PrefixSet;

It looks to me like the changes related to this function could be done 
separately (perhaps first). Is that the case, and if so, could you do so? It's 
a little hard to follow what's just refactoring of the existing stuff and what 
is new, with the extra comment stuff thrown in.



Comment at: llvm/test/FileCheck/comment.txt:1
+// Comment directives successfully comment out check directives.
+//

You don't need to prefix the lines with '//' or anything else for that matter, 
since this isn't being used as an assembly/yaml/C/etc input.

If you do want to have the characters (I don't care either way), I'd prefer '#' 
for RUN/CHECK directive lines and '##' for comments (the latter so they stand 
out better from directive lines). It's fewer characters, whilst still as 
explicit ('#' is used widely in some parts of the testsuite at least).



Comment at: llvm/test/FileCheck/comment.txt:2
+// Comment directives successfully comment out check directives.
+//
+// Check all default comment prefixes.

Don't prefix empty lines.



Comment at: llvm/test/FileCheck/comment.txt:4
+// Check all default comment prefixes.
+// Check that a comment directive at the begin/end of the file is handled.
+// Check that the preceding/following line's check directive is not affected.

begin -> beginning



Comment at: llvm/test/FileCheck/comment.txt:9
+// RUN: echo 'CHECK: foo'>> %t.chk
+// RUN: echo 'RUN:echo "CHECK: baz"' >> %t.chk
+// RUN: %ProtectFileCheckOutput FileCheck -vv %t.chk < %t.in 2>&1 \

Is the lack of space after 'RUN:' deliberate?



Comment at: llvm/test/FileCheck/comment.txt:10-11
+// RUN: echo 'RUN:echo "CHECK: baz"' >> %t.chk
+// RUN: %ProtectFileCheckOutput FileCheck -vv %t.chk < %t.in 2>&1 \
+// RUN: | FileCheck -check-prefix=SUPPRESSES-CHECKS -DCHECK_LINE=2 %s
+//

I have a personal preference for multi-line commands like this to be formatted 
like this:

```
// RUN:   ... | \
// RUN: ...
```

with the `|` and `\` on the same line, to show that the next line is the start 
of a new command (as opposed to just being more arguments for that line), and 
the extra two space indentation showing that the line is a continuation of the 
previous.



Comment at: llvm/test/FileCheck/comment.txt:15
+// Check that a comment directive not at the beginning of a line is handled.
+// RUN: echo 'foo'  >  %t.in
+// RUN: echo 'CHECK: foo'   >  %t.chk

Not a big deal, but it might be easier for debugging the test in the future if 
the %t.in (and %t.chk) of each case is named differently, e.g. %t2.in, %t2.chk 
etc. That way, the later ones won't overwrite the earlier ones.



Comment at: llvm/test/FileCheck/comment.txt:38-43
+// RUN: echo 'foo COM: bar'> %t.in
+// RUN: echo 'CHECK: foo COM: bar' > %t.chk
+// RUN: %ProtectFileCheckOutput FileCheck -vv %t.chk < %t.in 2>&1 \
+// RUN: | FileCheck -check-prefix=WITHIN-CHECKS %s
+//
+// WITHIN-CHECKS: .chk:1:8: remark: CHECK: expected string found in input

I'm struggling a little with this case. Firstly, why the '8' in the column 
count in the remark? Secondly, if COM: was being treated as a genuine comment 
here, then the check directive would become `CHECK: foo` which would still be a 
match of the input, if I'm not mistaken? I guess the two might somehow be 
related, but I don't know how if so.



Comment at: llvm/test/FileCheck/comment.txt:127
+// RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
+// RUN:  -comment-prefixes= \
+// RUN: | FileCheck -check-prefix=PREFIX-EMPTY %s

Maybe worth cases like "-comment-prefixes=,FOO", "-comment-prefixes=FOO," and 
"-comment-prefixes=FOO,,BAR".



Comment at: llvm/test/FileCheck/comment.txt:133
+// RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
+// RUN:   -comment-prefixes=. \
+// RUN: | FileCheck -check-prefix=PREFIX-BAD-CHAR %s
-

[PATCH] D79315: [clangd] Get rid of Inclusion::R

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

This is only used by documentlink and go-to-definition. We are pushing
range detection logic from Inclusion creation to users. This would make using
stale preambles easier.

For document links we make use of the spelledtokens stored in tokenbuffers to
figure out file name range.

For go-to-def, we keep storing the line number we've seen the include directive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79315

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1490,7 +1490,7 @@
 
 TEST(DocumentLinks, All) {
   Annotations MainCpp(R"cpp(
-  #include $foo[["foo.h"]]
+  #/*comments*/include /*comments*/ $foo[["foo.h"]] //more comments
   int end_of_preamble = 0;
   #include $bar[["bar.h"]]
 )cpp");
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -127,7 +127,7 @@
 
 MATCHER_P(Written, Name, "") { return arg.Written == Name; }
 MATCHER_P(Resolved, Name, "") { return arg.Resolved == Name; }
-MATCHER_P(IncludeLine, N, "") { return arg.R.start.line == N; }
+MATCHER_P(IncludeLine, N, "") { return arg.HashLine == N; }
 MATCHER_P(Directive, D, "") { return arg.Directive == D; }
 
 MATCHER_P2(Distance, File, D, "") {
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -187,7 +187,7 @@
  ParsedAST &AST,
  llvm::StringRef MainFilePath) {
   for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
-if (!Inc.Resolved.empty() && Inc.R.start.line == Pos.line) {
+if (!Inc.Resolved.empty() && Inc.HashLine == Pos.line) {
   LocatedSymbol File;
   File.Name = std::string(llvm::sys::path::filename(Inc.Resolved));
   File.PreferredDeclaration = {
@@ -599,10 +599,20 @@
 
   std::vector Result;
   for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
-if (!Inc.Resolved.empty()) {
-  Result.push_back(DocumentLink(
-  {Inc.R, URIForFile::canonicalize(Inc.Resolved, *MainFilePath)}));
-}
+if (Inc.Resolved.empty())
+  continue;
+auto HashLoc = SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset);
+const auto *HashTok = AST.getTokens().spelledTokenAt(HashLoc);
+assert(HashTok && "got inclusion at wrong offset");
+const auto *IncludeTok = std::next(HashTok);
+const auto *FileTok = std::next(IncludeTok);
+auto FileRange =
+syntax::FileRange(SM, FileTok->location(), Inc.Written.length())
+.toCharRange(SM);
+
+Result.push_back(
+DocumentLink({halfOpenToRange(SM, FileRange),
+  URIForFile::canonicalize(Inc.Resolved, *MainFilePath)}));
   }
 
   return Result;
Index: clang-tools-extra/clangd/Headers.h
===
--- clang-tools-extra/clangd/Headers.h
+++ clang-tools-extra/clangd/Headers.h
@@ -52,11 +52,11 @@
 
 // An #include directive that we found in the main file.
 struct Inclusion {
-  Range R;  // Inclusion range.
   tok::PPKeywordKind Directive; // Directive used for inclusion, e.g. import
   std::string Written;  // Inclusion name as written e.g. .
   Path Resolved; // Resolved path of included file. Empty if not resolved.
   unsigned HashOffset = 0; // Byte offset from start of file to #.
+  int HashLine = 0;// Line number containing the directive, 0-indexed.
   SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion &);
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -38,11 +38,13 @@
 if (isInsideMainFile(HashLoc, SM)) {
   Out->MainFileIncludes.emplace_back();
   auto &Inc = Out->MainFileIncludes.back();
-  Inc.R = halfOpenToRange(SM, FilenameRange);
   Inc.Written =
   (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
   Inc.Resolved = std::string(File ? File->tryGetRealPathName() : 

[PATCH] D77802: [analyzer] Improved RangeSet::Negate support of unsigned ranges

2020-05-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov marked 4 inline comments as done.
ASDenysPetrov added a comment.

Thank you for the feedback. I'll update the patch soon.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:261-262
+// remove adjacent ranges
+newRanges = F.remove(newRanges, *iter1);
+newRanges = F.remove(newRanges, *iter2);
+// add united range

NoQ wrote:
> I don't remember iterator invalidation rules for these containers and it 
> gives me anxiety. Given that these containers are immutable, i wouldn't be 
> surprised if iterators are indeed never invalidated (just keep pointing to 
> the old container) but it definitely deserves a comment.
Thanks for the notice. I'm not sure about iterator invalidation, so I'll just 
replace `*iter2` with `*newRanges.begin()`.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:27-28
+  TestCase(BasicValueFactory &BVF, RangeSet::Factory &F,
+   const std::initializer_list &originalList,
+   const std::initializer_list &expectedList)
+  : original(createRangeSetFromList(BVF, F, originalList)),

NoQ wrote:
> ASDenysPetrov wrote:
> > steakhal wrote:
> > > AFAIK since `std::initializer_list` is just two pointers we should take 
> > > it by value.
> > I'm not sure about //should//, since initializer_list is a container and 
> > it'd be consistent if we handle it like any other compound object despite 
> > its implementation (IMO). But I can change it if you wish.
> > `initializer_list` is a container
> 
> No, it's a //view// :)
> No, it's a view :)
Yes, you are right. OK, I'll change it to value argument.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:51
+  // init block
+  DiagnosticsEngine Diag{new DiagnosticIDs, new DiagnosticOptions};
+  FileSystemOptions FileSystemOpts;

NoQ wrote:
> ASDenysPetrov wrote:
> > steakhal wrote:
> > > Generally, `new expressions` are a code smell. We should use something 
> > > like an `std::make_unique` to prevent memory leaks on exceptions.
> > > Though, I'm not sure if there is a similar function for 
> > > `llvm::IntrusiveRefCntPtr`s.
> > I'll make it more safe.
> I'd rather create ASTContext through tooling, like in other unittests.
I'll look into other tests and try to change to ASTContext.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:113-120
+  // c.original.print(llvm::dbgs());
+  // llvm::dbgs() << " => ";
+  // c.expected.print(llvm::dbgs());
+  // llvm::dbgs() << " => ";
+  // negatedFromOriginal.print(llvm::dbgs());
+  // llvm::dbgs() << " => ";
+  // negatedBackward.print(llvm::dbgs());

NoQ wrote:
> ASDenysPetrov wrote:
> > steakhal wrote:
> > > Should we keep this?
> > I'm not sure, but I'd better keep it, because it is useful for debugging.
> No-no, we don't do that here >.>
> 
> If you constructed an awesome debugging facility and you want to save it for 
> future generations, i'd recommend turning it into an actual facility, not 
> just comments. Like, maybe, an unused function that can be invoked for 
> debugging, or something like that.
OK, I'll move it to function.


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

https://reviews.llvm.org/D77802



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2020-05-04 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@mgehre From your comment it seems that `clang-apply-replacements` handles the 
YAML wrong and does not make the proper conversion back from "\n\n" to "\n"


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63482



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


[clang-tools-extra] 3c2c776 - Fix building with GCC5 after e64f99c51a8e

2020-05-04 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-05-04T11:12:39+02:00
New Revision: 3c2c7760d9eea0236c5c54e8939b3901f4208835

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

LOG: Fix building with GCC5 after e64f99c51a8e

It was failing with:

  /work/llvm.monorepo/clang-tools-extra/clangd/ClangdServer.cpp: In lambda 
function:
  /work/llvm.monorepo/clang-tools-extra/clangd/ClangdServer.cpp:374:75:
  error: could not convert ‘(const char*)""’ from ‘const char*’ to 
‘llvm::StringLiteral’
  trace::Metric::Distribution);
 ^

Added: 


Modified: 
clang-tools-extra/clangd/support/Trace.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Trace.h 
b/clang-tools-extra/clangd/support/Trace.h
index c027595b85ed..90a11bb1feb4 100644
--- a/clang-tools-extra/clangd/support/Trace.h
+++ b/clang-tools-extra/clangd/support/Trace.h
@@ -52,7 +52,7 @@ struct Metric {
 Distribution,
   };
   constexpr Metric(llvm::StringLiteral Name, MetricType Type,
-   llvm::StringLiteral LabelName = "")
+   llvm::StringLiteral LabelName = llvm::StringLiteral(""))
   : Name(Name), Type(Type), LabelName(LabelName) {}
 
   /// Records a measurement for this metric to active tracer.



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


[PATCH] D78429: [clangd] Metric tracking through Tracer

2020-05-04 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

For anyone running into the same problem, this broke the build with GCC 5:

  /work/llvm.monorepo/clang-tools-extra/clangd/ClangdServer.cpp:374:75: error: 
could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
  trace::Metric::Distribution);
 ^

Hopefully 3c2c7760d9eea0236c5c54e8939b3901f4208835 
 fixes it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78429



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


Re: [PATCH] D78429: [clangd] Metric tracking through Tracer

2020-05-04 Thread Kadir Çetinkaya via cfe-commits
thanks Hans!

On Mon, May 4, 2020 at 12:38 PM Hans Wennborg via Phabricator <
revi...@reviews.llvm.org> wrote:

> hans added a comment.
>
> For anyone running into the same problem, this broke the build with GCC 5:
>
>   /work/llvm.monorepo/clang-tools-extra/clangd/ClangdServer.cpp:374:75:
> error: could not convert ‘(const char*)""’ from ‘const char*’ to
> ‘llvm::StringLiteral’
>
> trace::Metric::Distribution);
>
>^
>
> Hopefully 3c2c7760d9eea0236c5c54e8939b3901f4208835 <
> https://reviews.llvm.org/rG3c2c7760d9eea0236c5c54e8939b3901f4208835>
> fixes it.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D78429/new/
>
> https://reviews.llvm.org/D78429
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79160: [AST] Preserve the type in RecoveryExprs for broken function calls.

2020-05-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 261762.
hokein marked 13 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79160

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/CodeCompletion/member-access.cpp
  clang/test/Index/getcursor-recovery.cpp
  clang/test/SemaCXX/enable_if.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp
  clang/test/SemaTemplate/instantiate-function-params.cpp

Index: clang/test/SemaTemplate/instantiate-function-params.cpp
===
--- clang/test/SemaTemplate/instantiate-function-params.cpp
+++ clang/test/SemaTemplate/instantiate-function-params.cpp
@@ -3,32 +3,32 @@
 // PR6619
 template struct if_c { };
 template struct if_ {
-  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 5{{in instantiation}}
+  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 7{{in instantiation}}
 };
 template  struct wrap_constraints { };
 template  
 inline char has_constraints_(Model* , // expected-note 3{{candidate template ignored}}
-   wrap_constraints* = 0); // expected-note 2{{in instantiation}}
+   wrap_constraints* = 0); // expected-note 4{{in instantiation}}
 
 template  struct not_satisfied {
   static const bool value = sizeof( has_constraints_((Model*)0)  == 1); // expected-error 3{{no matching function}} \
-  // expected-note 2{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
+  // expected-note 4{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
 };
 template  struct requirement_;
 template  struct instantiate {
 };
-template  struct requirement_   : if_<   not_satisfied >::type { // expected-note 5{{in instantiation}}
+template  struct requirement_   : if_<   not_satisfied >::type { // expected-error 3{{no type named 'type' in}} expected-note 7{{in instantiation}}
 };
 template  struct usage_requirements {
 };
 template < typename TT > struct InputIterator{
-typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note {{in instantiation}}
+typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}}
 };
-template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note {{in instantiation}}
-  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note {{in instantiation}}
+template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note 2{{in instantiation}}
+  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note 2{{in instantiation}}
 
 };
-typedef instantiate< &requirement_ x)>::failed> boost_concept_checkX;// expected-note 3{{in instantiation}}
+typedef instantiate< &requirement_ x)>::failed> boost_concept_checkX;// expected-note 6{{in instantiation}}
 
 template struct X0 { };
 template struct X0 { };
Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -fsyntax-only -verify
+
+namespace test0 {
+struct Indestructible {
+  // Indestructible();
+  ~Indestructible() = delete; // expected-note 2{{deleted}}
+};
+Indestructible make_indestructible();
+
+void test() {
+  // no crash.
+  int s = sizeof(make_indestructible()); // expected-error {{deleted}}
+  constexpr int ss = sizeof(make_indestructible()); // expected-error {{deleted}}
+  static_assert(ss, "");
+  int array[ss];
+}
+}
+
+namespace test1 {
+constexpr int foo() { return 1; } // expected-note {{candidate function not viable}}
+// verify the "not an integral constant expression" diagnostic is suppressed.
+static_assert(1 == foo(1), ""); // expected-error {{no matching function}}
+}
+
+namespace test2 {
+void foo(); // expected-note 3{{requires 0 arguments}}
+void func() {
+  // verify that "field has incomplete type" diagnostic is suppressed.
+  typeof(foo(42)) var; // expected-error {{no matching function}}
+
+  // FIXME: suppr

[PATCH] D78740: [clangd] Handle PresumedLocations in IncludeCollector

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 261765.
kadircet marked an inline comment as done.
kadircet added a comment.

- Perform line mapping only for includes found through built-in file.
- Drop filename range mapping.
- Make use of FileChanged events to track being in built-in file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78740

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp

Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -16,6 +16,7 @@
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -25,7 +26,9 @@
 namespace {
 
 using ::testing::AllOf;
+using ::testing::Contains;
 using ::testing::ElementsAre;
+using ::testing::Not;
 using ::testing::UnorderedElementsAre;
 
 class HeadersTest : public ::testing::Test {
@@ -302,6 +305,26 @@
 llvm::None);
 }
 
+TEST_F(HeadersTest, PresumedLocations) {
+  std::string HeaderFile = testPath("implicit_include.h");
+
+  // Line map inclusion back to main file.
+  std::string HeaderContents = llvm::formatv("#line 0 \"{0}\"", MainFile);
+  HeaderContents += R"cpp(
+#line 1
+#include )cpp";
+  FS.Files[HeaderFile] = HeaderContents;
+
+  // Including through non-builtin file has no effects.
+  FS.Files[MainFile] = "#include \"implicit_include.h\"";
+  EXPECT_THAT(collectIncludes().MainFileIncludes,
+  Not(Contains(Written("";
+
+  // Now include through built-in file.
+  CDB.ExtraClangFlags = {"-include" + HeaderFile};
+  EXPECT_THAT(collectIncludes().MainFileIncludes,
+  Contains(AllOf(IncludeLine(0), Written("";
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -10,6 +10,7 @@
 #include "Compiler.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -30,12 +31,12 @@
   // in the main file are collected.
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   llvm::StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  llvm::StringRef /*SearchPath*/,
+  CharSourceRange /*FilenameRange*/,
+  const FileEntry *File, llvm::StringRef /*SearchPath*/,
   llvm::StringRef /*RelativePath*/,
   const Module * /*Imported*/,
   SrcMgr::CharacteristicKind FileKind) override {
-if (isInsideMainFile(HashLoc, SM)) {
+auto AddMainFileInc = [&](SourceLocation HashLoc) {
   Out->MainFileIncludes.emplace_back();
   auto &Inc = Out->MainFileIncludes.back();
   Inc.Written =
@@ -47,22 +48,64 @@
   SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;
   Inc.FileKind = FileKind;
   Inc.Directive = IncludeTok.getIdentifierInfo()->getPPKeywordID();
+};
+
+auto MainFID = SM.getMainFileID();
+if (BuiltinFileInStack) {
+  // Directives included through builtin file can be mapped back to main
+  // file via line directives.
+  auto PreLoc = SM.getPresumedLoc(HashLoc);
+  if (auto FE = SM.getFileManager().getFile(PreLoc.getFilename())) {
+if (SM.getFileEntryForID(MainFID) == *FE) {
+  HashLoc = SM.translateLineCol(MainFID, PreLoc.getLine(),
+PreLoc.getColumn());
+  AddMainFileInc(HashLoc);
+}
+  }
+} else if (isInsideMainFile(HashLoc, SM)) {
+  AddMainFileInc(HashLoc);
 }
+
 if (File) {
   auto *IncludingFileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc));
   if (!IncludingFileEntry) {
 assert(SM.getBufferName(HashLoc).startswith("<") &&
"Expected #include location to be a file or ");
 // Treat as if included from the main file.
-IncludingFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+IncludingFileEntry = SM.getFileEntryForID(MainFID);
   }
   Out->recordInclude(IncludingFileEntry->getName(), File->getName(),
  File->tryGetRealPathName());
 }
   }
 
+  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+ 

[PATCH] D79160: [AST] Preserve the type in RecoveryExprs for broken function calls.

2020-05-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/AST/ComputeDependence.cpp:491
+  auto D =
+  toExprDependence(E->getType()->getDependence()) | ExprDependence::Error;
   for (auto *S : E->subExpressions())

sammccall wrote:
> Dropping type-dependence seems like the point here and is risky, doesn't 
> dropping value- and instantiation-dependence introduce unneccesary extra risk?
> 
> Probably correct and maybe useful, but splitting it into a separate change 
> and maybe delaying it might make it easier to get the principal change to 
> stick. 
> Dropping type-dependence seems like the point here and is risky, doesn't 
> dropping value- and instantiation-dependence introduce unneccesary extra risk?

maybe, but you are right, we should be conservative. 

separating this patch seems good to me:
 1) create a new patch like what we do here, 
 2) this patch just getting rid of the type bit (still set the 
value/instantiation bits)

with 1, we will get rid of the value/instantiation-depend bits (for the default 
`Ctx.DependentType` case), and we get closer to our goal. 



Comment at: clang/lib/AST/Expr.cpp:4656
 #ifndef NDEBUG
+  assert(!T.isNull());
   for (auto *E : SubExprs)

sammccall wrote:
> Why is this in ifndef?
> Actually, why is the loop in ifndef? surely the compiler can inline and 
> remove an empty loop over an arrayref?
removed.



Comment at: clang/lib/Sema/SemaDecl.cpp:16427
   QualType EltTy = Context.getBaseElementType(T);
-  if (!EltTy->isDependentType()) {
+  if (!EltTy->isDependentType() && !EltTy->containsErrors()) {
 if (RequireCompleteSizedType(Loc, EltTy,

sammccall wrote:
> why is this needed/does it help?
> I would have thought in the cases where we now don't consider the type 
> dependent, the *type* wouldn't contain errors (rather the expression owning 
> the type would).
> 
> Is this just for decltype?
yeah, decltype is the only case we have been discovered so far.
 



Comment at: clang/test/CodeCompletion/member-access.cpp:276
 
+struct S { int member; };
+S overloaded(int);

sammccall wrote:
> I think there's an interesting test of the "viable" case where you have a 
> const/non-const overload set with different return types:
> ```
> class Collection {
>   const char *find(int) const;
>   char* find(int) const;
> };
> void test1(const Collection &C, Collection &NC) {
>  C.find(); // missing arg, type const char*
>  NC.find(); // missing arg, is type NC or is it unresolved?
> }
> ```
> 
> 
> (Not sure if it's best written as a codecompletion test, I guess AST dump is 
> better)
oh, this is a good point, this patch doesn't capture the type for member 
functions, it is in a different code path (probably we should handle that in 
`BuildCallToMemberFunction`).

I'd prefer to handle it in a separate patch.



Comment at: clang/test/SemaCXX/enable_if.cpp:417
 
-constexpr int B = 10 + // the carat for the error should be pointing to the 
problematic call (on the next line), not here.
-callTemplated<0>(); // expected-error{{initialized by a constant 
expression}} expected-error@-3{{no matching function for call to 'templated'}} 
expected-note{{in instantiation of function template}} 
expected-note@-10{{candidate disabled}}
+constexpr int B = 10 + // expected-error {{initialized by a constant 
expression}}
+callTemplated<0>(); // expected-error@-3{{no matching function for call to 
'templated'}} expected-note{{in instantiation of function template}} 
expected-note@-10{{candidate disabled}} expected-note {{in call to 
'callTemplated()'}} expected-note@-3 {{subexpression not valid in a constant 
expression}}

sammccall wrote:
> hokein wrote:
> > this diagnostic is changed slightly (without `-frecovery-ast-type`). I 
> > think this is acceptable.
> > 
> > before this patch:
> > 
> > ```
> > /tmp/t5.cpp:7:10: error: no matching function for call to 'templated'
> >   return templated();  // expected-error {{no matching function for call 
> > to 'templated'}} 
> >  ^~~~
> > /tmp/t5.cpp:13:5: note: in instantiation of function template 
> > specialization 'enable_if_diags::callTemplated<0>' requested here
> > callTemplated<0>(); // expected-note {{in call to 'callTemplated()'}} 
> > expected-note@-6 {{subexpression not valid in a constant expression}}
> > ^
> > /tmp/t5.cpp:2:32: note: candidate disabled: 
> > template  constexpr int templated() __attribute__((enable_if(N, 
> > ""))) {
> >^~
> > /tmp/t5.cpp:13:5: error: constexpr variable 'B' must be initialized by a 
> > constant expression
> > callTemplated<0>(); // expected-note {{in call to 'callTemplated()'}} 
> > expected-note@-6 {{subexpression not valid in a constant expression}}
> > ^~
> > 2 errors generated.
> > ```
> > 
> > vs after this patch:

[PATCH] D78740: [clangd] Handle PresumedLocations in IncludeCollector

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 5 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Headers.cpp:44
+PreLoc.getColumn());
+  PreLoc = SM.getPresumedLoc(FilenameRange.getBegin());
+  auto FileNameBegin = SM.translateLineCol(

kadircet wrote:
> sammccall wrote:
> > This part looks a little iffy to me, with all the coordinate transforms.
> > 
> > If we're synthesizing the include, chars don't have to match 1:1 right?
> > e.g. if the original code was `#   include /* foo */ "bar.h" // baz` 
> > and we synthesize `#include "bar.h"`, how is this going to get the 
> > coordinates of "bar.h" right?
> > 
> > This seems awkward to resolve. `R` isn't actually used much though, 
> > go-to-definition looks at its line number only, and DocumentLink uses it 
> > (but it seems OK to just to do approximate re-lexing there). Maybe we can 
> > just drop it?
> > 
> > ---
> > (Original comment disregarding above problem)
> > 
> > Isn't it the case that the filename expansion location has to be in the 
> > same file as the hashloc?
> > So can we do something like:
> > 
> > ```
> > FilenameRange = SM.getExpansionRange(FilenameRange);
> > if (SM.getFileID(FilenameRange.start()) == 
> > SM.getFileID(FilenameRange.end()) == SM.getFileID(OrigHashLoc)) {
> >   // all in the same file
> >   // compute NewStart = OrigStart - OrigHashLoc + NewHashLoc, etc
> > } else {
> >   FilenameRange = CharSourceRange();
> > }
> > ```
> > This part looks a little iffy to me, with all the coordinate transforms.
> > 
> > If we're synthesizing the include, chars don't have to match 1:1 right?
> > e.g. if the original code was #   include /* foo */ "bar.h" // baz and 
> > we synthesize #include "bar.h", how is this going to get the coordinates of 
> > "bar.h" right?
> 
> well, the patching actually ensures both `#` and `"filename"` starts at the 
> correct offset, by padding them with whitespaces ignoring any comments and 
> such.
> 
> > 
> > This seems awkward to resolve. R isn't actually used much though, 
> > go-to-definition looks at its line number only, and DocumentLink uses it 
> > (but it seems OK to just to do approximate re-lexing there). Maybe we can 
> > just drop it?
> 
> I am fine with dropping it too, the padding looks really ugly in the patching 
> code :D.
> 
> Regarding go-to-def, I suppose we can keep storing the include line, since we 
> calculate it anyway while getting the presumed location for HashLoc.
> 
> For DocumentLink, I suppose we can either lex while handling the request or 
> store those separately in parsedast. I would go with the former.
> 
> WDYT?
sent out D79315.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78740



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


[PATCH] D79201: [clang-format] : Fix additional pointer alignment for overloaded operators

2020-05-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 261768.
MyDeveloperDay added a comment.

Remove extraneous cases


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

https://reviews.llvm.org/D79201

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15685,6 +15685,8 @@
   verifyFormat("Foo::operator*();", Style);
   verifyFormat("Foo::operator void *();", Style);
   verifyFormat("Foo::operator void **();", Style);
+  verifyFormat("Foo::operator void *&();", Style);
+  verifyFormat("Foo::operator void *&&();", Style);
   verifyFormat("Foo::operator()(void *);", Style);
   verifyFormat("Foo::operator*(void *);", Style);
   verifyFormat("Foo::operator*();", Style);
@@ -15698,6 +15700,10 @@
   verifyFormat("Foo::operator &();", Style);
   verifyFormat("Foo::operator &&();", Style);
   verifyFormat("Foo::operator &&();", Style);
+  verifyFormat("Foo::operator *&();", Style);
+  verifyFormat("Foo::operator *&();", Style);
+  verifyFormat("Foo::operator *&&();", Style);
+  verifyFormat("Foo::operator *&&();", Style);
   verifyFormat("operator*(int (*)(), class Foo);", Style);
 
   verifyFormat("Foo::operator&();", Style);
@@ -15721,12 +15727,15 @@
   verifyFormat("operator const FooRight &()", Style);
   verifyFormat("operator const FooRight *()", Style);
   verifyFormat("operator const FooRight **()", Style);
+  verifyFormat("operator const FooRight *&()", Style);
+  verifyFormat("operator const FooRight *&&()", Style);
 
   Style.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("Foo::operator*();", Style);
   verifyFormat("Foo::operator**();", Style);
   verifyFormat("Foo::operator void*();", Style);
   verifyFormat("Foo::operator void**();", Style);
+  verifyFormat("Foo::operator void*&();", Style);
   verifyFormat("Foo::operator/*comment*/ void*();", Style);
   verifyFormat("Foo::operator/*a*/ const /*b*/ void*();", Style);
   verifyFormat("Foo::operator/*a*/ volatile /*b*/ void*();", Style);
@@ -15737,10 +15746,13 @@
   verifyFormat("Foo::operator*();", Style);
   verifyFormat("Foo::operator**();", Style);
   verifyFormat("Foo::operator**();", Style);
+  verifyFormat("Foo::operator*&();", Style);
   verifyFormat("Foo::operator&();", Style);
   verifyFormat("Foo::operator&();", Style);
   verifyFormat("Foo::operator&&();", Style);
   verifyFormat("Foo::operator&&();", Style);
+  verifyFormat("Foo::operator*&();", Style);
+  verifyFormat("Foo::operator*&();", Style);
   verifyFormat("operator*(int (*)(), class Foo);", Style);
 
   verifyFormat("Foo::operator&();", Style);
@@ -15769,6 +15781,8 @@
   verifyFormat("operator const FooLeft&()", Style);
   verifyFormat("operator const FooLeft*()", Style);
   verifyFormat("operator const FooLeft**()", Style);
+  verifyFormat("operator const FooLeft*&()", Style);
+  verifyFormat("operator const FooLeft*&&()", Style);
 
   // PR45107
   verifyFormat("operator Vector&();", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2814,7 +2814,7 @@
 tok::l_square));
   if (Right.is(tok::star) && Left.is(tok::l_paren))
 return false;
-  if (Right.is(tok::star) && Left.is(tok::star))
+  if (Left.is(tok::star) && Right.isOneOf(tok::star, tok::amp, tok::ampamp))
 return false;
   if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
 const FormatToken *Previous = &Left;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15685,6 +15685,8 @@
   verifyFormat("Foo::operator*();", Style);
   verifyFormat("Foo::operator void *();", Style);
   verifyFormat("Foo::operator void **();", Style);
+  verifyFormat("Foo::operator void *&();", Style);
+  verifyFormat("Foo::operator void *&&();", Style);
   verifyFormat("Foo::operator()(void *);", Style);
   verifyFormat("Foo::operator*(void *);", Style);
   verifyFormat("Foo::operator*();", Style);
@@ -15698,6 +15700,10 @@
   verifyFormat("Foo::operator &();", Style);
   verifyFormat("Foo::operator &&();", Style);
   verifyFormat("Foo::operator &&();", Style);
+  verifyFormat("Foo::operator *&();", Style);
+  verifyFormat("Foo::operator *&();", Style);
+  verifyFormat("Foo::operator *&&();", Style);
+  verifyFormat("Foo::operator *&&();", Style);
   verifyFormat("operator*(int (*)(), class Foo);", Style);
 
   verifyFormat("Foo::operator&();", Style);
@@ -15721,12 +15727,15 @@
   verifyFormat("operator const FooRight &()", Style);
   verifyFormat("operator const FooRight *()", Style);
   verifyFormat("operator const FooRight **()", Style);
+  verif

[PATCH] D73951: [Clang] [Driver]Add logic to search for flang frontend

2020-05-04 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: clang/lib/Driver/ToolChains/Flang.cpp:71
   const auto& D = C.getDriver();
-  const std::string &customFortranName = D.getFFCGenericFortranName();
+  const std::string &customFortranName = D.getGenericFortranFE();
   const char *FortranName;

[nit] Could this be `customFlangName` instead? I think that it would better 
reflect the meaning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73951



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


[PATCH] D73951: [Clang] [Driver]Add logic to search for flang frontend

2020-05-04 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

@CarolineConcatto thank you for the updates!

- It looks like you accidentally pushed two commits in one patch :) Could you 
please squash and resubmit? (this should clean-up the diff). Ta!
- Perhaps  `CFCGenericFlangName` instead of `GenericFortranFE`? This would 
better correspond to the new flag and be consistent with 
https://github.com/llvm/llvm-project/blob/42a56bf63f699a620a57c34474510d9937ebf715/clang/lib/Driver/ToolChains/Gnu.cpp#L183.

Naming is hard! Otherwise, this is ready to land IMO.




Comment at: clang/include/clang/Driver/Driver.h:222
   /// Name to use when invoking flang.
-  std::string FFCGenericFortranName;
+  std::string GenericFortranFE;
 

`CFCGenericFlangName`?



Comment at: clang/include/clang/Driver/Driver.h:317
   /// Name to use when invoking flang.
-  const std::string &getFFCGenericFortranName() const { return 
FFCGenericFortranName; }
+  const std::string &getGenericFortranFE() const { return GenericFortranFE; }
 

`getCFCGenericFlangName`?



Comment at: clang/include/clang/Driver/Options.td:268
+def cfc_flang_name : Separate<["-"], "cfc-flang-name">, InternalDriverOpt,
+  HelpText<"Name for a custom frontend compiler(cfc) for flang">;
 

`custom fortran compiler` instead, right? IIUC:
* this flag is to specify _custom fortran compiler_ (`cfc`)
* we add `flang_name`at the end  because it can be interpreted as flang's 
alternative name and we want to be consistent with `ccc_gcc_name`



Comment at: clang/lib/Driver/Driver.cpp:1092
 
-  // Extract -ffc args.
-  if (const Arg *A = Args.getLastArg(options::OPT_fcc_fortran_name))
-FFCGenericFortranName = A->getValue();
+  // Extract -cfc args.
+  if (const Arg *A = Args.getLastArg(options::OPT_cfc_flang_name))

There's only one, called `cfc-flang-name` ;-)



Comment at: clang/test/Driver/flang/custom_frontend_flang.f90:5
+! The flag has preference over "flang" frontend.
+! Therefore the driver invokes the FE given by the flag.
+

`FE` is a bit enigmatic. Perhaphs `... invokes the custom fortran compiler 
given by ...`?



Comment at: clang/test/Driver/flang/custom_frontend_flang.f90:9
+
+! The invocations should begin with .tmp1 -fc1.
+! CHECK: "{{[^"]*}}alternative_fortran_frontend" "-fc1"

This comment is out of date :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73951



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


[PATCH] D77598: Integral template argument suffix printing

2020-05-04 Thread Pratyush Das via Phabricator via cfe-commits
reikdas updated this revision to Diff 261772.
reikdas added a comment.

Addresses @rsmith 's inline comment.


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

https://reviews.llvm.org/D77598

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
  clang/test/Misc/integer-literal-printing.cpp
  clang/test/SemaCXX/builtin-align-cxx.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -102,7 +102,7 @@
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
   correct<0x73>();
-  tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650LL>' requested here}}
+  tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
 
   __attribute__((address_space(1))) char *x;
   __attribute__((address_space(2))) char *y;
Index: clang/test/SemaCXX/builtin-align-cxx.cpp
===
--- clang/test/SemaCXX/builtin-align-cxx.cpp
+++ clang/test/SemaCXX/builtin-align-cxx.cpp
@@ -31,10 +31,10 @@
 void test() {
   test_templated_arguments(); // fine
   test_templated_arguments();
-  // expected-note@-1{{in instantiation of function template specialization 'test_templated_arguments'}}
+  // expected-note@-1{{in instantiation of function template specialization 'test_templated_arguments'}}
   // expected-note@-2{{forward declaration of 'fwddecl'}}
   test_templated_arguments(); // invalid alignment value
-  // expected-note@-1{{in instantiation of function template specialization 'test_templated_arguments'}}
+  // expected-note@-1{{in instantiation of function template specialization 'test_templated_arguments'}}
 }
 
 template 
Index: clang/test/Misc/integer-literal-printing.cpp
===
--- clang/test/Misc/integer-literal-printing.cpp
+++ clang/test/Misc/integer-literal-printing.cpp
@@ -2,7 +2,7 @@
 
 // PR11179
 template  class Type1 {};
-template  void Function1(Type1& x) {} // expected-note{{candidate function [with T = -42] not viable: expects an l-value for 1st argument}}
+template  void Function1(Type1& x) {} // expected-note{{candidate function [with T = (short)-42] not viable: expects an l-value for 1st argument}}
 
 template  class Type2 {};
 template  void Function2(Type2& x) {} // expected-note{{candidate function [with T = 42U] not viable: expects an l-value for 1st argument}}
Index: clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
===
--- clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
+++ clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
@@ -45,13 +45,13 @@
 namespace std { template struct tuple_element; } // expected-note 2{{here}}
 
 void no_tuple_element_2() {
-  auto [a0, a1, a2] = A(); // expected-error {{implicit instantiation of undefined template 'std::tuple_element<0ULL, A>'}} expected-note {{in implicit}}
+  auto [a0, a1, a2] = A(); // expected-error {{implicit instantiation of undefined template 'std::tuple_element<0UL, A>'}} expected-note {{in implicit}}
 }
 
 template<> struct std::tuple_element<0, A> { typedef float type; };
 
 void no_tuple_element_3() {
-  auto [a0, a1, a2] = A(); // expected-error {{implicit instantiation of undefined template 'std::tuple_element<1ULL, A>'}} expected-note {{in implicit}}
+  auto [a0, a1, a2] = A(); // expected-error {{implicit instantiation of undefined template 'std::tuple_element<1UL, A>'}} expected-note {{in implicit}}
 }
 
 template<> struct std::tuple_element<1, A> { typedef float &type; };
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -76,13 +76,32 @@
 Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true);
 Out << "'";
   } else {
-Out << Val;
 if (T->isBuiltinType()) {
-  if (Val.isUnsigned())
-Out << "U";
-  if (Val.getBitWidth() == 64)
-Out << "LL";
-}
+  switch (cast(T)->getKind()) {
+  case BuiltinType::ULongLong:
+Out << Val << "ULL";
+break;
+  case BuiltinType::LongLong:
+Out << Val << "LL";
+break;
+  case BuiltinType::ULong:
+Out << Val << "UL";
+break;
+  case BuiltinType::Long:
+Out << Val << "L";
+break;
+  case BuiltinType::Int:
+Out << Val;
+break;
+  default:
+if (T->isUnsignedIntegerType())
+  Out << Val << "U";
+else
+  Out << "(" << T->getCanonicalTypeInternal().getAsStri

[PATCH] D77598: Integral template argument suffix printing

2020-05-04 Thread Pratyush Das via Phabricator via cfe-commits
reikdas updated this revision to Diff 261774.
reikdas added a comment.

Sorry my earlier update did not include the changes from the earlier revision.


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

https://reviews.llvm.org/D77598

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p12.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/Index/print-type.cpp
  clang/test/Misc/integer-literal-printing.cpp
  clang/test/Modules/lsv-debuginfo.cpp
  clang/test/SemaCXX/builtin-align-cxx.cpp
  clang/test/SemaCXX/cxx11-ast-print.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaCXX/invalid-instantiated-field-decl.cpp
  clang/test/SemaCXX/vector.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/test/SemaTemplate/delegating-constructors.cpp
  clang/test/SemaTemplate/dependent-names.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -270,6 +270,24 @@
   void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>'; did you mean 'enable_if_char<'a'>::type'?}}
   void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>'; did you mean 'enable_if_char<'a'>::type'?}}
+  
+  template  struct enable_if_int {};
+  template <> struct enable_if_int<1> { typedef int type; }; // expected-note{{'enable_if_int<1>::type' declared here}}
+  void test_int() { enable_if_int<2>::type i; } // expected-error{{enable_if_int<2>'; did you mean 'enable_if_int<1>::type'?}}
+
+  template  struct enable_if_unsigned_int {};
+  template <> struct enable_if_unsigned_int<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_int<1>::type' declared here}}
+  void test_unsigned_int() { enable_if_unsigned_int<2>::type i; } // expected-error{{enable_if_unsigned_int<2U>'; did you mean 'enable_if_unsigned_int<1>::type'?}}
+
+
+  template  struct enable_if_unsigned_long_long {};
+  template <> struct enable_if_unsigned_long_long<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_long_long<1>::type' declared here}}
+  void test_unsigned_long_long() { enable_if_unsigned_long_long<2>::type i; } // expected-error{{enable_if_unsigned_long_long<2ULL>'; did you mean 'enable_if_unsigned_long_long<1>::type'?}}
+
+  template  struct enable_if_long_long {};
+  template <> struct enable_if_long_long<1> { typedef int type; }; // expected-note{{'enable_if_long_long<1>::type' declared here}}
+  void test_long_long() { enable_if_long_long<2>::type i; } // expected-error{{enable_if_long_long<2LL>'; did you mean 'enable_if_long_long<1>::type'?}}
+
 }
 
 namespace PR10579 {
Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3U>::Y<3U>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/delegating-constructors.cpp
===
--- clang/test/SemaTemplate/delegating-constructors.cpp
+++ clang/test/SemaTemplate/delegating-constructors.cpp
@@ -9,7 +9,7 @@
   public:
 template 
 string(const char (&str)[N])
-  : string(str) {} // expected-error{{constructor for 'string<6>' creates a delegation cycle}}
+  : string(str) {} // expected-error{{constructor for 'string<6U>' creates a delegation cycle}}
   };
 
   void f() {
Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -84,8 +84,8 @@
 template  int __attribute__((address_space(B))) *same_template();
 void test_same_template() { (void) same_template<0>(); }
 
-template  int __attribute__((address_space(A))) *different_template(); // expected-note {{candidate function [with A = 0]}}
-template  int __attribute__((address_space(B+1))) *different_template(); // expected-note {{candidate function [with B = 0]}}
+template  int __attribute__((address_space(A))) *different_template(); // expected-note {{candidate function [with A = 0U]}}
+template  int __attribute__((address_spac

[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2020-05-04 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

Could be - did it handle it correctly for your include case here?

And if this is a general yaml string thing, shouldn't the replacement of 
newlines (for both ways) happen in the yaml parser/writer instead of 
clang/Tooling?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63482



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


[PATCH] D79320: [clang-format [PR45791] BeforeLambdaBody is confused by comment inside lambda

2020-05-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: krasimir, sammccall, Wawha, duncan-llvm.
MyDeveloperDay added projects: clang, clang-format.

https://bugs.llvm.org/show_bug.cgi?id=45791

Lambda with line comment is incorrectly formatted

  auto k = []() // comment
  { return; };
  `



  auto k = []() // comment { return; };


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79320

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14576,6 +14576,30 @@
LLVMWithBeforeLambdaBody);
 }
 
+TEST_F(FormatTest, LambdaWithLineComments) {
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_All;
+
+  verifyFormat("auto k = []() { return; }", LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() // comment\n"
+   "{ return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() /* comment */ { return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() /* comment */ /* comment */ { return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() // X\n"
+   "{ return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "auto k = []() // \n"
+  "{ return; }",
+  LLVMWithBeforeLambdaBody);
+}
+
 TEST_F(FormatTest, EmptyLinesInLambdas) {
   verifyFormat("auto lambda = []() {\n"
"  x(); //\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -330,7 +330,7 @@
   const FormatToken &Current = *State.NextToken;
   const FormatToken &Previous = *Current.Previous;
   if (Style.BraceWrapping.BeforeLambdaBody && Current.CanBreakBefore &&
-  Current.is(TT_LambdaLBrace)) {
+  Current.is(TT_LambdaLBrace) && Previous.isNot(TT_LineComment)) {
 auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
 return (LambdaBodyLength > getColumnLimit(State));
   }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14576,6 +14576,30 @@
LLVMWithBeforeLambdaBody);
 }
 
+TEST_F(FormatTest, LambdaWithLineComments) {
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_All;
+
+  verifyFormat("auto k = []() { return; }", LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() // comment\n"
+   "{ return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() /* comment */ { return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() /* comment */ /* comment */ { return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto k = []() // X\n"
+   "{ return; }",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "auto k = []() // \n"
+  "{ return; }",
+  LLVMWithBeforeLambdaBody);
+}
+
 TEST_F(FormatTest, EmptyLinesInLambdas) {
   verifyFormat("auto lambda = []() {\n"
"  x(); //\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -330,7 +330,7 @@
   const FormatToken &Current = *State.NextToken;
   const FormatToken &Previous = *Current.Previous;
   if (Style.BraceWrapping.BeforeLambdaBody && Current.CanBreakBefore &&
-  Current.is(TT_LambdaLBrace)) {
+  Current.is(TT_LambdaLBrace) && Previous.isNot(TT_LineComment)) {
 auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
 return (LambdaBodyLength > getColumnLimit(State));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75430: [analyzer][NFC] Introduce CXXDeallocatorCall, deploy it in MallocChecker

2020-05-04 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Ping


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

https://reviews.llvm.org/D75430



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


[PATCH] D79322: [FEnv] Small fixes to implementation of flt.rounds

2020-05-04 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: andrew.w.kaylor, kpn, craig.topper, RKSimon, asb, 
hfinkel.
Herald added subscribers: cfe-commits, luismarques, apazos, sameer.abuasal, 
pzheng, jdoerfert, s.egerton, lenary, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, MaskRay, jrtc27, niosHD, 
sabuasal, simoncook, johnrusso, rbar, hiraditya.
Herald added projects: clang, LLVM.

This change makes assorted correction related to the intrinsic
`llvm.flt.rounds`:

- Added documentation entry in LangRef,
- Attributes of the intrinsic changed to be in line with other functions 
dependent of floating-point environment,
- The intrinsic now is lowered by default into function call rather than to a 
constant.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79322

Files:
  clang/include/clang/Basic/Builtins.def
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/RuntimeLibcalls.def
  llvm/lib/CodeGen/IntrinsicLowering.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/test/CodeGen/MSP430/flt_rounds.ll
  llvm/test/CodeGen/RISCV/flt-rounds.ll

Index: llvm/test/CodeGen/RISCV/flt-rounds.ll
===
--- llvm/test/CodeGen/RISCV/flt-rounds.ll
+++ llvm/test/CodeGen/RISCV/flt-rounds.ll
@@ -9,12 +9,20 @@
 define i32 @test_flt_rounds() nounwind {
 ; RV32I-LABEL: test_flt_rounds:
 ; RV32I:   # %bb.0:
-; RV32I-NEXT:addi a0, zero, 1
+; RV32I-NEXT:addi sp, sp, -16
+; RV32I-NEXT:sw ra, 12(sp)
+; RV32I-NEXT:call __flt_rounds
+; RV32I-NEXT:lw ra, 12(sp)
+; RV32I-NEXT:addi sp, sp, 16
 ; RV32I-NEXT:ret
 ;
 ; RV64I-LABEL: test_flt_rounds:
 ; RV64I:   # %bb.0:
-; RV64I-NEXT:addi a0, zero, 1
+; RV64I-NEXT:addi sp, sp, -16
+; RV64I-NEXT:sd ra, 8(sp)
+; RV64I-NEXT:call __flt_rounds
+; RV64I-NEXT:ld ra, 8(sp)
+; RV64I-NEXT:addi sp, sp, 16
 ; RV64I-NEXT:ret
   %1 = call i32 @llvm.flt.rounds()
   ret i32 %1
Index: llvm/test/CodeGen/MSP430/flt_rounds.ll
===
--- llvm/test/CodeGen/MSP430/flt_rounds.ll
+++ llvm/test/CodeGen/MSP430/flt_rounds.ll
@@ -1,4 +1,4 @@
-; RUN: llc -verify-machineinstrs < %s -march=msp430
+; RUN: llc -verify-machineinstrs -march=msp430 < %s | FileCheck %s
 
 define i16 @foo() {
 entry:
@@ -8,3 +8,5 @@
 }
 
 declare i32 @llvm.flt.rounds() nounwind 
+
+; CHECK: call #__flt_rounds
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -2814,10 +2814,16 @@
   FA, Offset));
 break;
   }
-  case ISD::FLT_ROUNDS_:
-Results.push_back(DAG.getConstant(1, dl, Node->getValueType(0)));
-Results.push_back(Node->getOperand(0));
+  case ISD::FLT_ROUNDS_: {
+EVT RetVT = Node->getValueType(0);
+TargetLowering::MakeLibCallOptions CallOptions;
+std::pair Tmp = TLI.makeLibCall(
+DAG, RTLIB::FLT_ROUNDS_, RetVT, None, CallOptions,
+SDLoc(Node), Node->getOperand(0));
+Results.push_back(Tmp.first);
+Results.push_back(Tmp.second);
 break;
+  }
   case ISD::EH_RETURN:
   case ISD::EH_LABEL:
   case ISD::PREFETCH:
Index: llvm/lib/CodeGen/IntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/IntrinsicLowering.cpp
+++ llvm/lib/CodeGen/IntrinsicLowering.cpp
@@ -426,10 +426,9 @@
 break;
   }
   case Intrinsic::flt_rounds:
- // Lower to "round to the nearest"
- if (!CI->getType()->isVoidTy())
-   CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
- break;
+ReplaceCallWith("__flt_rounds", CI, CI->arg_begin(), CI->arg_end(),
+Type::getInt32Ty(CI->getContext()));
+break;
   case Intrinsic::invariant_start:
   case Intrinsic::lifetime_start:
 // Discard region information.
Index: llvm/include/llvm/IR/RuntimeLibcalls.def
===
--- llvm/include/llvm/IR/RuntimeLibcalls.def
+++ llvm/include/llvm/IR/RuntimeLibcalls.def
@@ -548,6 +548,9 @@
 // Return address
 HANDLE_LIBCALL(RETURN_ADDRESS, nullptr)
 
+// Floating-point Environment
+HANDLE_LIBCALL(FLT_ROUNDS_, "__flt_rounds")
+
 HANDLE_LIBCALL(UNKNOWN_LIBCALL, nullptr)
 
 #undef HANDLE_LIBCALL
Index: llvm/include/llvm/IR/Intrinsics.td
===
--- llvm/include/llvm/IR/Intrinsics.td
+++ llvm/include/llvm/IR/Intrinsics.td
@@ -611,6 +611,14 @@
[IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<1>, ImmArg<2>, ImmArg<3>]>,
GCCBuiltin<"__builtin_object_size">;
 
+//===--- Access to Floating Point Environment -===//
+//
+
+let IntrProperties = [IntrInaccessi

[PATCH] D79087: [SVE][Codegen] Lower legal min & max operations

2020-05-04 Thread Kerry McLaughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG19f5da9c1d69: [SVE][Codegen] Lower legal min & max 
operations (authored by kmclaughlin).

Changed prior to commit:
  https://reviews.llvm.org/D79087?vs=261462&id=261787#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79087

Files:
  llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/llvm-ir-to-intrinsic.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-imm.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-imm.ll
===
--- llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-imm.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-imm.ll
@@ -1,5 +1,221 @@
 ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
 
+; SMAX
+
+define  @smax_i8( %a) {
+; CHECK-LABEL: smax_i8:
+; CHECK: smax z0.b, z0.b, #-128
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
+  %elt = insertelement  undef, i8 -128, i32 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smax.nxv16i8( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+define  @smax_i16( %a) {
+; CHECK-LABEL: smax_i16:
+; CHECK: smax z0.h, z0.h, #127
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
+  %elt = insertelement  undef, i16 127, i32 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smax.nxv8i16( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+define  @smax_i32( %a) {
+; CHECK-LABEL: smax_i32:
+; CHECK: smax z0.s, z0.s, #-128
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
+  %elt = insertelement  undef, i32 -128, i32 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smax.nxv4i32( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+define  @smax_i64( %a) {
+; CHECK-LABEL: smax_i64:
+; CHECK: smax z0.d, z0.d, #127
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv2i1(i32 31)
+  %elt = insertelement  undef, i64 127, i64 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smax.nxv2i64( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+; SMIN
+
+define  @smin_i8( %a) {
+; CHECK-LABEL: smin_i8:
+; CHECK: smin z0.b, z0.b, #127
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
+  %elt = insertelement  undef, i8 127, i32 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smin.nxv16i8( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+define  @smin_i16( %a) {
+; CHECK-LABEL: smin_i16:
+; CHECK: smin z0.h, z0.h, #-128
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
+  %elt = insertelement  undef, i16 -128, i32 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smin.nxv8i16( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+define  @smin_i32( %a) {
+; CHECK-LABEL: smin_i32:
+; CHECK: smin z0.s, z0.s, #127
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
+  %elt = insertelement  undef, i32 127, i32 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smin.nxv4i32( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+define  @smin_i64( %a) {
+; CHECK-LABEL: smin_i64:
+; CHECK: smin z0.d, z0.d, #-128
+; CHECK-NEXT: ret
+  %pg = call  @llvm.aarch64.sve.ptrue.nxv2i1(i32 31)
+  %elt = insertelement  undef, i64 -128, i64 0
+  %splat = shufflevector  %elt,  undef,  zeroinitializer
+  %out = call  @llvm.aarch64.sve.smin.nxv2i64( %pg,
+ %a,
+ %splat)
+  ret  %out
+}
+
+; UMAX
+
+define  @umax_i8( %a) {
+; CHECK

[PATCH] D77802: [analyzer] Improved RangeSet::Negate support of unsigned ranges

2020-05-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 261784.
ASDenysPetrov added a comment.

@NoQ updated the patch. Review, please.


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

https://reviews.llvm.org/D77802

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constraint_manager_negate_difference.c
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -0,0 +1,130 @@
+//===- unittests/StaticAnalyzer/RangeSetTest.cpp --===//
+//
+// 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/Basic/Builtins.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace ento {
+namespace {
+
+// TestCase contains to lists of ranges.
+// Original one has to be negated.
+// Expected one has to be compared to negated original range.
+template  struct TestCase {
+  RangeSet original;
+  RangeSet expected;
+
+  TestCase(BasicValueFactory &BVF, RangeSet::Factory &F,
+   const std::initializer_list &originalList,
+   const std::initializer_list &expectedList)
+  : original(createRangeSetFromList(BVF, F, originalList)),
+expected(createRangeSetFromList(BVF, F, expectedList)) {}
+
+private:
+  RangeSet createRangeSetFromList(BasicValueFactory &BVF, RangeSet::Factory &F,
+  const std::initializer_list rangeList) {
+llvm::APSInt from(sizeof(T) * 8, std::is_unsigned::value);
+llvm::APSInt to = from;
+RangeSet rangeSet = F.getEmptySet();
+for (auto it = rangeList.begin(); it != rangeList.end(); it += 2) {
+  from = *it;
+  to = *(it + 1);
+  rangeSet = rangeSet.addRange(
+  F, RangeSet(F, BVF.getValue(from), BVF.getValue(to)));
+}
+return rangeSet;
+  }
+
+  void printNegate(const TestCase &TestCase) {
+TestCase.original.print(llvm::dbgs());
+llvm::dbgs() << " => ";
+TestCase.expected.print(llvm::dbgs());
+  }
+};
+
+class RangeSetTest : public testing::Test {
+protected:
+  // Init block
+  std::unique_ptr AST = tooling::buildASTFromCode("struct foo;");
+  ASTContext &context = AST->getASTContext();
+  llvm::BumpPtrAllocator alloc;
+  BasicValueFactory BVF{context, alloc};
+  RangeSet::Factory F;
+  // End init block
+
+  template  void checkNegate() {
+using type = T;
+
+// Use next values of the range {MIN, A, B, MID, C, D, MAX}.
+
+// MID is a value in the middle of the range
+// which unary minus does not affect on,
+// e.g. int8/int32(0), uint8(128), uint32(2147483648).
+
+constexpr type MIN = std::numeric_limits::min();
+constexpr type MAX = std::numeric_limits::max();
+constexpr type MID = std::is_signed::value
+ ? 0
+ : ~(static_cast(-1) / static_cast(2));
+constexpr type A = MID - static_cast(42 + 42);
+constexpr type B = MID - static_cast(42);
+constexpr type C = -B;
+constexpr type D = -A;
+
+static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
+  "Values shall be in an ascending order");
+
+// Left {[x, y], [x, y]} is what shall be negated.
+// Right {[x, y], [x, y]} is what shall be compared to a negation result.
+TestCase cases[] = {
+{BVF, F, {MIN, A}, {MIN, MIN, D, MAX}},
+{BVF, F, {MIN, C}, {MIN, MIN, B, MAX}},
+{BVF, F, {MIN, MID}, {MIN, MIN, MID, MAX}},
+{BVF, F, {MIN, MAX}, {MIN, MAX}},
+{BVF, F, {A, D}, {A, D}},
+{BVF, F, {A, B}, {C, D}},
+{BVF, F, {MIN, A, D, MAX}, {MIN, A, D, MAX}},
+{BVF, F, {MIN, B, MID, D}, {MIN, MIN, A, MID, C, MAX}},
+{BVF, F, {MIN, MID, C, D}, {MIN, MIN, A, B, MID, MAX}},
+{BVF, F, {MIN, MID, C, MAX}, {MIN, B, MID, MAX}},
+{BVF, F, {A, MID, D, MAX}, {MIN + 1, A, MID, D}},
+{BVF, F, {A, A}, {D, D}},
+{BVF, F, {MID, MID}, {MID, MID}},
+{BVF, F, {MAX, MAX}, {MIN + 1, MIN + 1}},
+};
+
+for (const auto &c : cases) {
+  // Negate original and check with expected.
+  RangeSet negatedFromOriginal = c.original.Negate(BVF, F);
+  EXPECT_EQ(negatedFromOriginal, c.expected);
+  // Negate negated back and check with original.
+  RangeSet negatedBackward = negatedFromOriginal.Negate(BVF, F);
+  EXPECT_EQ(negatedBackward, c.original);
+}
+  }
+};
+

[clang] 0863e94 - [AArch64] Add NVIDIA Carmel support

2020-05-04 Thread Sander de Smalen via cfe-commits

Author: Raul Tambre
Date: 2020-05-04T13:52:30+01:00
New Revision: 0863e94ebd87f4dea7a457c8441979ec4151fedb

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

LOG: [AArch64] Add NVIDIA Carmel support

Summary:
NVIDIA's Carmel ARM64 cores are used in Tegra194 chips found in Jetson AGX 
Xavier, DRIVE AGX Xavier and DRIVE AGX Pegasus.

References:
* 
https://devblogs.nvidia.com/nvidia-jetson-agx-xavier-32-teraops-ai-robotics/#h.huq9xtg75a5e
* NVIDIA Xavier Series System-on-Chip Technical Reference Manual 1.3 
(https://developer.nvidia.com/embedded/downloads#?search=Xavier%20Series%20SoC%20Technical%20Reference%20Manual)

Reviewers: sdesmalen, paquette

Reviewed By: sdesmalen

Subscribers: llvm-commits, ianshmean, kristof.beyls, hiraditya, jfb, 
danielkiss, cfe-commits, t.p.northover

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/test/Driver/aarch64-cpus.c
clang/test/Preprocessor/aarch64-target-features.c
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/lib/Support/Host.cpp
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/test/CodeGen/AArch64/cpus.ll
llvm/unittests/Support/Host.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Driver/aarch64-cpus.c 
b/clang/test/Driver/aarch64-cpus.c
index cf12a5155689..d77ab3782838 100644
--- a/clang/test/Driver/aarch64-cpus.c
+++ b/clang/test/Driver/aarch64-cpus.c
@@ -283,6 +283,20 @@
 // ARM64-A64FX: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "a64fx"
 // ARM64-A64FX-TUNE: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" 
"generic"
 
+// RUN: %clang -target aarch64 -mcpu=carmel -### -c %s 2>&1 | FileCheck 
-check-prefix=CARMEL %s
+// RUN: %clang -target aarch64 -mlittle-endian -mcpu=carmel -### -c %s 2>&1 | 
FileCheck -check-prefix=CARMEL %s
+// RUN: %clang -target aarch64 -mtune=carmel -### -c %s 2>&1 | FileCheck 
-check-prefix=CARMEL-TUNE %s
+// RUN: %clang -target aarch64 -mlittle-endian -mtune=carmel -### -c %s 2>&1 | 
FileCheck -check-prefix=CARMEL-TUNE %s
+// CARMEL: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "carmel"
+// CARMEL-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"
+
+// RUN: %clang -target arm64 -mcpu=carmel -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-CARMEL %s
+// RUN: %clang -target arm64 -mlittle-endian -mcpu=carmel -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-CARMEL %s
+// RUN: %clang -target arm64 -mtune=carmel -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-CARMEL-TUNE %s
+// RUN: %clang -target arm64 -mlittle-endian -mtune=carmel -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-CARMEL-TUNE %s
+// ARM64-CARMEL: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "carmel"
+// ARM64-CARMEL-TUNE: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" 
"generic"
+
 // RUN: %clang -target aarch64_be -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-BE %s
 // RUN: %clang -target aarch64 -mbig-endian -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-BE %s
 // RUN: %clang -target aarch64_be -mbig-endian -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-BE %s

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 9cb12f8afb32..8ce6b8a8a45d 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -163,6 +163,7 @@
 // RUN: %clang -target aarch64 -mcpu=kryo -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-MCPU-KRYO %s
 // RUN: %clang -target aarch64 -mcpu=thunderx2t99 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-MCPU-THUNDERX2T99 %s
 // RUN: %clang -target aarch64 -mcpu=a64fx -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-MCPU-A64FX %s
+// RUN: %clang -target aarch64 -mcpu=carmel -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-MCPU-CARMEL %s
 // CHECK-MCPU-APPLE-A7: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" 
"-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" 
"+crypto" "-target-feature" "+zcm" "-target-feature" "+zcz" "-target-feature" 
"+sha2" "-target-feature" "+aes"
 // CHECK-MCPU-APPLE-A10: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" 
"-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" 
"+crc" "-target-feature" "+crypto" "-target-feature" "+rdm" "-target-feature" 
"+zcm" "-target-feature" "+zcz" "-target-feature" "+sha2" "-target-feature" 
"+aes"
 // CHECK-MCPU-APPLE-A11: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" 
"-target-feature" "+v8.2a" "-target-feature" "+fp-armv8" "-target-feature" 
"+neon" "-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" 
"+ras" "-target-feature" "+lse" "

[PATCH] D79325: [clang-format] [PR42164] Add Option to Break before While

2020-05-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: krasimir, mitchell-stellar, sammccall.
MyDeveloperDay added projects: clang, clang-format.

Its currently not possible to recreate the GNU style using the 
`BreakBeforeBraces: Custom` style due to a lack of missing `BeforeWhile` in the 
`BraceWrappingFlags`

The following request was raised to add `BeforeWhile` in a `do..while` context 
like `BeforeElse` and `BeforeCatch` to give greater control over the 
positioning of the `while`

https://bugs.llvm.org/show_bug.cgi?id=42164


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79325

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1692,6 +1692,22 @@
 format("try{foo();}catch(...){baz();}", Style));
 }
 
+TEST_F(FormatTest, BeforeWhile) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Custom;
+
+  verifyFormat("do {\n"
+   "  foo();\n"
+   "} while (1);",
+   Style);
+  Style.BraceWrapping.BeforeWhile = true;
+  verifyFormat("do {\n"
+   "  foo();\n"
+   "}\n"
+   "while (1);",
+   Style);
+}
+
 //===--===//
 // Tests for classes, namespaces, etc.
 //===--===//
@@ -13042,6 +13058,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeWhile);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2167,7 +2167,7 @@
   if (FormatTok->Tok.is(tok::l_brace)) {
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false);
-if (Style.BraceWrapping.IndentBraces)
+if (Style.BraceWrapping.IndentBraces || Style.BraceWrapping.BeforeWhile)
   addUnwrappedLine();
   } else {
 addUnwrappedLine();
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -587,6 +587,7 @@
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("BeforeLambdaBody", Wrapping.BeforeLambdaBody);
+IO.mapOptional("BeforeWhile", Wrapping.BeforeWhile);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
 IO.mapOptional("SplitEmptyFunction", Wrapping.SplitEmptyFunction);
 IO.mapOptional("SplitEmptyRecord", Wrapping.SplitEmptyRecord);
@@ -670,12 +671,24 @@
   if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
 return Style;
   FormatStyle Expanded = Style;
-  Expanded.BraceWrapping = {false, false, FormatStyle::BWACS_Never,
-false, false, false,
-false, false, false,
-false, false, false,
-false, false, true,
-true,  true};
+  Expanded.BraceWrapping = {/*AfterCaseLabel=*/false,
+/*AfterClass=*/false,
+/*AfterControlStatement=*/FormatStyle::BWACS_Never,
+/*AfterEnum=*/false,
+/*AfterFunction=*/false,
+/*AfterNamespace=*/false,
+/*AfterObjCDeclaration=*/false,
+/*AfterStruct=*/false,
+/*AfterUnion=*/false,
+/*AfterExternBlock=*/false,
+/*BeforeCatch=*/false,
+/*BeforeElse=*/false,
+/*BeforeLambdaBody=*/false,
+/*BeforeWhile=*/false,
+/*IndentBraces=*/false,
+/*SplitEmptyFunction=*/true,
+/*SplitEmptyRecord=*/true,
+/*SplitEmptyNamespace=*/true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -726,12 +739,25 @@
 

[PATCH] D79302: [clangd] Propogate context in LSPServer tests

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet abandoned this revision.
kadircet added a comment.

as discussed offline there is no real use case for this now and it is unclear 
whether there will be.

dropping it, until we've got a use case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79302



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


[PATCH] D77940: [AArch64] Add NVIDIA Carmel support

2020-05-04 Thread Sander de Smalen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0863e94ebd87: [AArch64] Add NVIDIA Carmel support (authored 
by tambre, committed by sdesmalen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77940

Files:
  clang/test/Driver/aarch64-cpus.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/test/CodeGen/AArch64/cpus.ll
  llvm/unittests/Support/Host.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -975,9 +975,15 @@
   AArch64::AEK_SIMD | AArch64::AEK_FP16 | AArch64::AEK_RAS |
   AArch64::AEK_LSE | AArch64::AEK_SVE | AArch64::AEK_RDM,
   "8.2-A"));
+  EXPECT_TRUE(testAArch64CPU(
+  "carmel", "armv8.2-a", "crypto-neon-fp-armv8",
+  AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
+  AArch64::AEK_SIMD | AArch64::AEK_FP16 | AArch64::AEK_RAS |
+  AArch64::AEK_LSE | AArch64::AEK_RDM,
+  "8.2-A"));
 }
 
-static constexpr unsigned NumAArch64CPUArchs = 37;
+static constexpr unsigned NumAArch64CPUArchs = 38;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
@@ -1126,6 +1132,10 @@
AArch64::ArchKind::INVALID, "sve"));
   EXPECT_FALSE(testAArch64Extension("a64fx",
AArch64::ArchKind::INVALID, "sve2"));
+  EXPECT_TRUE(
+  testAArch64Extension("carmel", AArch64::ArchKind::INVALID, "crypto"));
+  EXPECT_TRUE(
+  testAArch64Extension("carmel", AArch64::ArchKind::INVALID, "fp16"));
 
   EXPECT_FALSE(testAArch64Extension(
   "generic", AArch64::ArchKind::ARMV8A, "ras"));
Index: llvm/unittests/Support/Host.cpp
===
--- llvm/unittests/Support/Host.cpp
+++ llvm/unittests/Support/Host.cpp
@@ -262,6 +262,21 @@
 )";
 
   EXPECT_EQ(sys::detail::getHostCPUNameForARM(A64FXProcCpuInfo), "a64fx");
+
+  // Verify Nvidia Carmel.
+  const std::string CarmelProcCpuInfo = R"(
+processor   : 0
+model name  : ARMv8 Processor rev 0 (v8l)
+BogoMIPS: 62.50
+Features: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm dcpop
+CPU implementer : 0x4e
+CPU architecture: 8
+CPU variant : 0x0
+CPU part: 0x004
+CPU revision: 0
+)";
+
+  EXPECT_EQ(sys::detail::getHostCPUNameForARM(CarmelProcCpuInfo), "carmel");
 }
 
 #if defined(__APPLE__) || defined(_AIX)
Index: llvm/test/CodeGen/AArch64/cpus.ll
===
--- llvm/test/CodeGen/AArch64/cpus.ll
+++ llvm/test/CodeGen/AArch64/cpus.ll
@@ -2,6 +2,7 @@
 
 
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=generic 2>&1 | FileCheck %s
+; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=carmel 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=cortex-a35 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=cortex-a34 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=cortex-a53 2>&1 | FileCheck %s
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -45,6 +45,7 @@
 AppleA11,
 AppleA12,
 AppleA13,
+Carmel,
 CortexA35,
 CortexA53,
 CortexA55,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -68,6 +68,9 @@
   switch (ARMProcFamily) {
   case Others:
 break;
+  case Carmel:
+CacheLineSize = 64;
+break;
   case CortexA35:
 break;
   case CortexA53:
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -605,6 +605,14 @@
   FeatureComplxNum
   ]>;
 
+def ProcCarmel : SubtargetFeature<"carmel", "ARMProcFamily", "Carmel",
+  "Nvidia Carmel processors", [
+   HasV8_2aOps,
+   FeatureNEON,
+   FeatureCrypto,
+   FeatureFullFP16
+   ]>;
+
 // Note that cyclone does not fuse AES instructions, but newer apple chip

[PATCH] D79326: [clang-format] ensure dump_format_style.py works with Python3 correctly

2020-05-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: krasimir, mitchell-stellar, sammccall, owenpan.
MyDeveloperDay added projects: clang, clang-format.

Python2 has been removed from cygwin, this means anyone running the 
dump_format_style.py in a cygwin shell could pick up python3 instead

In Python3 all strings are unicode as the file is opened in binary mode we need 
to encode the contents string or we'll face the following error

  Traceback (most recent call last):
File "./dump_format_style.py", line 228, in 
  output.write(contents)
  TypeError: a bytes-like object is required, not 'str'


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79326

Files:
  clang/docs/tools/dump_format_style.py


Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -225,4 +225,4 @@
 contents = substitute(contents, 'FORMAT_STYLE_OPTIONS', options_text)
 
 with open(DOC_FILE, 'wb') as output:
-  output.write(contents)
+  output.write(contents.encode())


Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -225,4 +225,4 @@
 contents = substitute(contents, 'FORMAT_STYLE_OPTIONS', options_text)
 
 with open(DOC_FILE, 'wb') as output:
-  output.write(contents)
+  output.write(contents.encode())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79160: [AST] Preserve the type in RecoveryExprs for broken function calls.

2020-05-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/AST/ComputeDependence.cpp:488
 ExprDependence clang::computeDependence(RecoveryExpr *E) {
+  // Even we know the concrete type of the RecoveryExpr, we just get rid of the
+  // type-dependent bit (rather than all three bits) to avoid extra risk of

This comment is hard to understand in isolation: it describes what the patch is 
doing (compared to the baseline, and to some alternative), rather than what the 
code is doing.

I'd suggest something like:
```
Mark the expression as value- and instantiation- dependent to reuse existing 
suppressions for dependent code, e.g. avoiding constant-evaluation.
```



Comment at: clang/lib/AST/Expr.cpp:3309
 
-  if (isInstantiationDependent())
+  if (isInstantiationDependent() || containsErrors())
 return IncludePossibleEffects;

This can move into the later patch I think - we're always 
instantiation-dependent where it matters.



Comment at: clang/lib/Sema/SemaDecl.cpp:12807
 
-  if (Init && !Init->isValueDependent()) {
+  if (Init && !Init->isValueDependent() && !Init->containsErrors()) {
 if (var->isConstexpr()) {

again - can move into later patch



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:15887
   if (!AssertExpr->isTypeDependent() && !AssertExpr->isValueDependent() &&
-  !Failed) {
+  !AssertExpr->containsErrors() && !Failed) {
 // In a static_assert-declaration, the constant-expression shall be a

can defer this too



Comment at: clang/test/CodeCompletion/member-access.cpp:283
+}
+// RUN: not %clang_cc1 -fsyntax-only -frecovery-ast -frecovery-ast-type 
-code-completion-at=%s:281:16 %s -o - | FileCheck -check-prefix=CHECK-CC10 %s
+// CHECK-CC10: [#int#]member

nit: CHECK-RECOVERY or so?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79160



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


[PATCH] D79315: [clangd] Get rid of Inclusion::R

2020-05-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Headers.cpp:45
   Inc.HashOffset = SM.getFileOffset(HashLoc);
+  // Line numbers are only computed once per SM, it is cached afterwards.
+  Inc.HashLine =

I'm not sure what this comment is trying to tell me - is it just "the next line 
isn't very expensive"? I wouldn't bother in that case...



Comment at: clang-tools-extra/clangd/XRefs.cpp:610
+auto FileRange =
+syntax::FileRange(SM, FileTok->location(), Inc.Written.length())
+.toCharRange(SM);

is this just FileTok.range(SM)?



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:1493
   Annotations MainCpp(R"cpp(
-  #include $foo[["foo.h"]]
+  #/*comments*/include /*comments*/ $foo[["foo.h"]] //more comments
   int end_of_preamble = 0;

can you try an angled include too? Does the raw lexer get that right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79315



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


[PATCH] D76996: [analyzer] Improve PlacementNewChecker

2020-05-04 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.

> ... This draws a pattern that we should recursively descend down to the top 
> most base region. I.e. the different check*RegionAlign methods should call 
> into each other until we reach the top level base region.



> The observation here is that the alignment of a region can be correct only if 
> we can prove that its base region is aligned properly (and other 
> requirements, e.g. the offset is divisible). But the base region may have 
> another base region and we have to prove the alignment correctness to that as 
> well.

This could be an issue not just with alignment but maybe with the size as well, 
I am not sure if we handle the offset properly in compound cases like this: 
`Xi.b[0].a[1][6]`.

Even though the above issue is still not investigated/handled, I think this 
patch is now acceptable because seems like most of the practical cases are 
handled. We could further investigate the concern and improve in a follow-up 
patch.
I'd like to see this landed and thanks for your work!


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

https://reviews.llvm.org/D76996



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


[PATCH] D73951: [Clang] [Driver]Add logic to search for flang frontend

2020-05-04 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 261806.
CarolineConcatto marked 7 inline comments as done.
CarolineConcatto added a comment.

Rename the flag and fix reviews comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73951

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/test/Driver/flang/custom_frontend_flang.f90

Index: clang/test/Driver/flang/custom_frontend_flang.f90
===
--- /dev/null
+++ clang/test/Driver/flang/custom_frontend_flang.f90
@@ -0,0 +1,10 @@
+! Check wich compiler's name for fortran should be invoked.
+
+! The flag -cfc-flang-name is passed by the driver.
+! The flag has preference over "flang" compiler.
+! Therefore the driver invokes the compiler given by the flag.
+
+! RUN: %clang --driver-mode=flang -cfc-flang-name alternative_fortran_compiler -### %s 2>&1 | FileCheck %s
+
+! The invocations should be with alternative_fortran_compiler -fc1.
+! CHECK: "{{[^"]*}}alternative_fortran_compiler" "-fc1"
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -11,7 +11,6 @@
 #include "CommonArgs.h"
 
 #include "clang/Driver/Options.h"
-
 #include 
 
 using namespace clang::driver;
@@ -69,7 +68,13 @@
   CmdArgs.push_back(Input.getFilename());
 
   const auto& D = C.getDriver();
-  const char* Exec = Args.MakeArgString(D.GetProgramPath("flang", TC));
+  const std::string &customFlangName = D.getCFCGenericFlangName();
+  const char *FlangName;
+  if (!customFlangName.empty())
+FlangName = customFlangName.c_str();
+  else FlangName = "flang";
+
+  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(FlangName));
   C.addCommand(std::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -129,8 +129,8 @@
   CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
   CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false),
   CCLogDiagnostics(false), CCGenDiagnostics(false),
-  TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc),
-  CheckInputsExist(true), GenReproducer(false),
+  TargetTriple(TargetTriple), CCCGenericGCCName(""), CFCGenericFlangName(""),
+  Saver(Alloc), CheckInputsExist(true), GenReproducer(false),
   SuppressMissingInputWarning(false) {
   // Provide a sane fallback if no VFS is specified.
   if (!this->VFS)
@@ -1089,6 +1089,10 @@
 .Default(SaveTempsCwd);
   }
 
+  // Extract -cfc arg.
+  if (const Arg *A = Args.getLastArg(options::OPT_cfc_flang_name))
+CFCGenericFlangName = A->getValue();
+
   setLTOMode(Args);
 
   // Process -fembed-bitcode= flags.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -264,6 +264,8 @@
 def ccc_gcc_name : Separate<["-"], "ccc-gcc-name">, InternalDriverOpt,
   HelpText<"Name for native GCC compiler">,
   MetaVarName<"">;
+def cfc_flang_name : Separate<["-"], "cfc-flang-name">, InternalDriverOpt,
+  HelpText<"Name for a custom fortran compiler(cfc) for flang">;
 
 class InternalDebugOpt : Group,
   Flags<[DriverOption, HelpHidden, CoreOption]>;
Index: clang/include/clang/Driver/Driver.h
===
--- clang/include/clang/Driver/Driver.h
+++ clang/include/clang/Driver/Driver.h
@@ -218,6 +218,9 @@
   /// Name to use when invoking gcc/g++.
   std::string CCCGenericGCCName;
 
+  /// Name to use when invoking a custom fortran compiler.
+  std::string CFCGenericFlangName;
+
   /// Name of configuration file if used.
   std::string ConfigFile;
 
@@ -310,6 +313,9 @@
   /// Name to use when invoking gcc/g++.
   const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; }
 
+  /// Name to use when invoking a custom fortran compiler.
+  const std::string &getCFCGenericFlangName() const { return CFCGenericFlangName; }
+
   const std::string &getConfigFile() const { return ConfigFile; }
 
   const llvm::opt::OptTable &getOpts() const { return getDriverOptTable(); }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7cbb495 - Fix LABEL match for test case for D72841 #pragma float_control

2020-05-04 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2020-05-04T07:27:40-07:00
New Revision: 7cbb495ab452877496df270678f9b0a8d57ab7e7

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

LOG: Fix LABEL match for test case for D72841 #pragma float_control

Added: 


Modified: 
clang/test/CodeGen/fp-floatcontrol-class.cpp

Removed: 




diff  --git a/clang/test/CodeGen/fp-floatcontrol-class.cpp 
b/clang/test/CodeGen/fp-floatcontrol-class.cpp
index ce4e0eb01390..324c3cc14f6f 100644
--- a/clang/test/CodeGen/fp-floatcontrol-class.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-class.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -ffp-contract=on -triple %itanium_abi_triple -emit-llvm -o 
- %s | FileCheck %s
 // RUN: %clang_cc1 -ffp-contract=on -triple x86_64-linux-gnu -emit-llvm -o - 
%s | FileCheck %s
-// RUN: %clang_cc1 -ffp-contract=on -triple x86_64-unknown-unknown -emit-llvm 
-o - %s | FileCheck %s
 // Verify that float_control does not pertain to initializer expressions
 
 float y();
@@ -8,14 +7,14 @@ float z();
 #pragma float_control(except, on)
 class ON {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} void @_ZN2ONC2Ev{{.*}}
+  // CHECK-LABEL: define {{.*}} @_ZN2ONC2Ev{{.*}}
   //CHECK: call contract float {{.*}}llvm.fmuladd
 };
 ON on;
 #pragma float_control(except, off)
 class OFF {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} void @_ZN3OFFC2Ev{{.*}}
+  // CHECK-LABEL: define {{.*}} @_ZN3OFFC2Ev{{.*}}
   //CHECK: call contract float {{.*}}llvm.fmuladd
 };
 OFF off;



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


[PATCH] D78655: [HIP] Add -fhip-lambda-host-device

2020-05-04 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 261811.
yaxunl retitled this revision from "[HIP] Let lambda be host device by default" 
to "[HIP] Add -fhip-lambda-host-device".
yaxunl edited the summary of this revision.
yaxunl added a comment.

Revised.


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

https://reviews.llvm.org/D78655

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/lambda.cu
  clang/test/SemaCUDA/Inputs/cuda.h
  clang/test/SemaCUDA/lambda.cu

Index: clang/test/SemaCUDA/lambda.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/lambda.cu
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -x hip -verify %s -fhip-lambda-host-device
+
+#include "Inputs/cuda.h"
+
+template
+__global__ void kernel(F f) { f(); }
+// expected-error@-1 3{{no matching function for call to object of type}}
+
+constexpr __host__ __device__ void hd();
+
+int main(void) {
+  auto lambda_kernel = [&]__global__(){};
+  // expected-error@-1 {{kernel function 'operator()' must be a free function or static member function}}
+
+  int b;
+
+  kernel<<<1,1>>>([](){ hd(); });
+
+  kernel<<<1,1>>>([=](){ hd(); });
+
+  kernel<<<1,1>>>([b](){ hd(); });
+
+  kernel<<<1,1>>>([&]()constexpr{ hd(); });
+
+  kernel<<<1,1>>>([&](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ function from __global__ function}}
+
+  kernel<<<1,1>>>([=, &b](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ function from __global__ function}}
+
+  kernel<<<1,1>>>([&, b](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ function from __global__ function}}
+
+  return 0;
+}
Index: clang/test/SemaCUDA/Inputs/cuda.h
===
--- clang/test/SemaCUDA/Inputs/cuda.h
+++ clang/test/SemaCUDA/Inputs/cuda.h
@@ -17,6 +17,19 @@
   __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {}
 };
 
+#ifdef __HIP__
+typedef struct hipStream *hipStream_t;
+typedef enum hipError {} hipError_t;
+int hipConfigureCall(dim3 gridSize, dim3 blockSize, size_t sharedSize = 0,
+ hipStream_t stream = 0);
+extern "C" hipError_t __hipPushCallConfiguration(dim3 gridSize, dim3 blockSize,
+ size_t sharedSize = 0,
+ hipStream_t stream = 0);
+extern "C" hipError_t hipLaunchKernel(const void *func, dim3 gridDim,
+  dim3 blockDim, void **args,
+  size_t sharedMem,
+  hipStream_t stream);
+#else
 typedef struct cudaStream *cudaStream_t;
 typedef enum cudaError {} cudaError_t;
 
@@ -29,6 +42,7 @@
 extern "C" cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim,
 dim3 blockDim, void **args,
 size_t sharedMem, cudaStream_t stream);
+#endif
 
 // Host- and device-side placement new overloads.
 void *operator new(__SIZE_TYPE__, void *p) { return p; }
Index: clang/test/CodeGenCUDA/lambda.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/lambda.cu
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -triple x86_64-linux-gnu -fhip-lambda-host-device \
+// RUN:   | FileCheck -check-prefix=HOST %s
+// RUN: %clang_cc1 -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -fhip-lambda-host-device -triple amdgcn-amd-amdhsa -fcuda-is-device \
+// RUN:   | FileCheck -check-prefix=DEV %s
+
+#include "Inputs/cuda.h"
+
+// Device side kernel name.
+// HOST: @[[KERN_CAPTURE:[0-9]+]] = {{.*}} c"_Z1gIZ12test_capturevEUlvE_EvT_\00"
+// HOST: @[[KERN_RESOLVE:[0-9]+]] = {{.*}} c"_Z1gIZ12test_resolvevEUlvE_EvT_\00"
+
+// Check functions emitted for test_capture in host compilation.
+// Check lambda is not emitted in host compilation.
+// HOST-LABEL: define void @_Z12test_capturev
+// HOST:  call void @_Z19test_capture_helperIZ12test_capturevEUlvE_EvT_
+// HOST-LABEL: define internal void @_Z19test_capture_helperIZ12test_capturevEUlvE_EvT_
+// HOST:  call void @_Z16__device_stub__gIZ12test_capturevEUlvE_EvT_
+// HOST-NOT: define{{.*}}@_ZZ4mainENKUlvE_clEv
+
+// Check functions emitted for test_resolve in host compilati

[PATCH] D79118: Implement _ExtInt ABI for all ABIs in Clang, enable type for ABIs

2020-05-04 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 15 inline comments as done.
erichkeane added a comment.

Thanks for the review @rjmccall .  Updated patch coming momentarily.  I audited 
my 'byval' use as well.  I still have 1 open, the 'array' comment which I 
wasn't clear what you meant.




Comment at: clang/lib/CodeGen/TargetInfo.cpp:719
+ !getContext().getTargetInfo().hasInt128Type()))
+  return getNaturalAlignIndirect(Ty);
+

rjmccall wrote:
> It's very weird for 64 and 128 to be showing up as constants in the default 
> ABI rule.
Good point.  I rewrote this in terms of the Context.LongLongTy and 
Context.Int128Ty.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:1537
+  return (isPromotableIntegerType(RetTy) ? ABIArgInfo::getExtend(RetTy)
+ : ABIArgInfo::getDirect());
 }

rjmccall wrote:
> Won't this treat literally all ExtInt types as either extend or direct?
Yes it does, and I justified doing it that way at one point, but I cannot 
remember why.

NVPTX seems to pass everything by value in return anyway(including large 
structures!), so I'm doing that one on purpose.

SparcV9 actually has a 256 bit limit, so I added a test to explicitly check it.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:4938
+if (EIT->getNumBits() > 128)
+  return getNaturalAlignIndirect(Ty, /*ByVal=*/true);
+

rjmccall wrote:
> Does this need to consider the aggregate-as-array logic below?
I'm not sure what you mean by this?  Are you suggesting I could/should pass 
this as an array instead of indirectly?



Comment at: clang/lib/CodeGen/TargetInfo.cpp:5014
+if (EIT->getNumBits() > 128)
+  return getNaturalAlignIndirect(RetTy, /*ByVal=*/true);
+

rjmccall wrote:
> `byval` is not legal on return values.
Ah, neat! I didn't realize that.  Thanks.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:6658
 /// Checks if the type is unsupported directly by the current target.
 static bool isUnsupportedType(ASTContext &Context, QualType T) {
   if (!Context.getTargetInfo().hasFloat16Type() && T->isFloat16Type())

rjmccall wrote:
> Ugh.  Please go ahead and rename this to make it clear that it's an NVPTX 
> helper function.
:)  Moved to a member function.  Also, coerceToIntArrayWithLimit made sense to 
do so as well, since it was the caller of this.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:8988
 
-  uint64_t Size = getContext().getTypeSize(Ty);
+  uint64_t Size = getContext().getIntWidth(Ty);
 

rjmccall wrote:
> Why this change?
So that line 9000 will 'extend' 63 bit sizes.  getTypeSize rounds to power of 
2, getIntWidth doesn't. 

As it was unclear, I've instead added this as an explicit case below.


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

https://reviews.llvm.org/D79118



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


[PATCH] D79330: [Analyzer][VLASizeChecker] Check for VLA size overflow.

2020-05-04 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.

Variable-length array (VLA) should have a size that fits into
a size_t value. At least if the size is queried with sizeof,
but it is better (and more simple) to check it always.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79330

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c

Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -100,6 +100,21 @@
   return s;
 }
 
+#define BIGINDEX 65535U
+
+size_t check_VLA_overflow_sizeof(unsigned int x) {
+  if (x == BIGINDEX) {
+size_t s = sizeof(int[x][x][x][x]); // expected-warning{{Declared variable-length array (VLA) has too large size}}
+return s;
+  }
+  return 0;
+}
+
+void check_VLA_overflow_typedef() {
+  unsigned int x = BIGINDEX;
+  typedef int VLA[x][x][x][x]; // expected-warning{{Declared variable-length array (VLA) has too large size}}
+}
+
 // Multi-dimensional arrays.
 
 void check_zero_sized_VLA_multi1(int x) {
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -34,14 +34,18 @@
 : public Checker,
  check::PreStmt> {
   mutable std::unique_ptr BT;
-  enum VLASize_Kind { VLA_Garbage, VLA_Zero, VLA_Tainted, VLA_Negative };
+  enum VLASize_Kind {
+VLA_Garbage,
+VLA_Zero,
+VLA_Tainted,
+VLA_Negative,
+VLA_Overflow
+  };
 
   ProgramStateRef checkVLA(CheckerContext &C, ProgramStateRef State,
-   const VariableArrayType *VLA,
-   const VariableArrayType *&VLALast,
-   llvm::SmallVector &VLASizes) const;
-  ProgramStateRef checkVLASize(CheckerContext &C, ProgramStateRef State,
-   const Expr *SizeE) const;
+   const VariableArrayType *VLA, SVal &ArraySize) const;
+  ProgramStateRef checkVLAIndexSize(CheckerContext &C, ProgramStateRef State,
+const Expr *SizeE) const;
 
   void reportBug(VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
  CheckerContext &C,
@@ -54,14 +58,15 @@
 };
 } // end anonymous namespace
 
-ProgramStateRef
-VLASizeChecker::checkVLA(CheckerContext &C, ProgramStateRef State,
- const VariableArrayType *VLA,
- const VariableArrayType *&VLALast,
- llvm::SmallVector &VLASizes) const {
+ProgramStateRef VLASizeChecker::checkVLA(CheckerContext &C,
+ ProgramStateRef State,
+ const VariableArrayType *VLA,
+ SVal &ArraySize) const {
   assert(VLA && "Function should be called with non-null VLA argument.");
 
-  VLALast = nullptr;
+  const VariableArrayType *VLALast = nullptr;
+  llvm::SmallVector VLASizes;
+
   // Walk over the VLAs for every dimension until a non-VLA is found.
   // Collect the sizes in VLASizes, put the most inner VLA to `VLALast`.
   // In "vla[x][2][y][3]" this will be the array for index "y".
@@ -69,7 +74,7 @@
   // until a non-vla is found.
   while (VLA) {
 const Expr *SizeE = VLA->getSizeExpr();
-State = checkVLASize(C, State, SizeE);
+State = checkVLAIndexSize(C, State, SizeE);
 if (!State)
   return nullptr;
 VLASizes.push_back(SizeE);
@@ -79,12 +84,61 @@
   assert(VLALast &&
  "Array should have at least one variably-modified dimension.");
 
+  ASTContext &Ctx = C.getASTContext();
+  SValBuilder &SVB = C.getSValBuilder();
+  CanQualType SizeTy = Ctx.getSizeType();
+  uint64_t SizeMax =
+  SVB.getBasicValueFactory().getMaxValue(SizeTy).getZExtValue();
+
+  // Get the element size.
+  CharUnits EleSize = Ctx.getTypeSizeInChars(VLALast->getElementType());
+  NonLoc ArrSize =
+  SVB.makeIntVal(EleSize.getQuantity(), SizeTy).castAs();
+
+  // Try to calculate the known real size of the array in KnownSize.
+  uint64_t KnownSize = 0;
+  if (const llvm::APSInt *KV = SVB.getKnownValue(State, ArrSize))
+KnownSize = KV->getZExtValue();
+
+  for (const Expr *SizeE : VLASizes) {
+auto SizeD = C.getSVal(SizeE).castAs();
+// Convert the array length to size_t.
+NonLoc IndexLength =
+SVB.evalCast(SizeD, SizeTy, SizeE->getType()).castAs();
+// Multiply the array length by the element size.
+SVal Mul = SVB.evalBinOpNN(State, BO_Mul, ArrSize, IndexLength, SizeTy);
+if (auto MulNonLoc = Mul.getAs())
+   

[PATCH] D77229: [Analyzer][WIP] Avoid handling of LazyCompundVals in IteratorModeling

2020-05-04 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 261826.
baloghadamsoftware added a comment.

Only 4 tests failing, but still lot to do.


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

https://reviews.llvm.org/D77229

Files:
  clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Regions.def
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/Store.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/container-modeling.cpp
  clang/test/Analysis/explain-svals.cpp
  clang/test/Analysis/iterator-modeling.cpp
  clang/test/Analysis/temporaries.cpp

Index: clang/test/Analysis/temporaries.cpp
===
--- clang/test/Analysis/temporaries.cpp
+++ clang/test/Analysis/temporaries.cpp
@@ -56,7 +56,7 @@
 }
 
 namespace rdar13265460 {
-  struct TrivialSubclass : public Trivial {
+struct TrivialSubclass : public Trivial {
 TrivialSubclass(int x) : Trivial(x), anotherValue(-x) {}
 int anotherValue;
   };
@@ -890,12 +890,9 @@
 public:
   ~C() {
 glob = 1;
-// FIXME: Why is destructor not inlined in C++17
 clang_analyzer_checkInlined(true);
 #ifdef TEMPORARY_DTORS
-#if __cplusplus < 201703L
-// expected-warning@-3{{TRUE}}
-#endif
+// expected-warning@-2{{TRUE}}
 #endif
   }
 };
@@ -914,16 +911,11 @@
   // temporaries returned from functions, so we took the wrong branch.
   coin && is(get()); // no-crash
   if (coin) {
-// FIXME: Why is destructor not inlined in C++17
 clang_analyzer_eval(glob);
 #ifdef TEMPORARY_DTORS
-#if __cplusplus < 201703L
-// expected-warning@-3{{TRUE}}
+// expected-warning@-2{{TRUE}}
 #else
-// expected-warning@-5{{UNKNOWN}}
-#endif
-#else
-// expected-warning@-8{{UNKNOWN}}
+// expected-warning@-4{{UNKNOWN}}
 #endif
   } else {
 // The destructor is not called on this branch.
@@ -1237,7 +1229,7 @@
 struct S {
   S() {}
   S(const S &) {}
-};
+  };
 
 void test() {
   int x = 0;
Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -1862,7 +1862,7 @@
 void clang_analyzer_printState();
 
 void print_state(std::vector &V) {
-  const auto i0 = V.cbegin();
+  auto i0 = V.cbegin();
   clang_analyzer_printState();
 
 // CHECK:  "checker_messages": [
@@ -1871,7 +1871,8 @@
 // CHECK-NEXT: "i0 : Valid ; Container == SymRegion{reg_$[[#]] & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
 // CHECK-NEXT:   ]}
 
-  const auto i1 = V.cend();
+  ++i0;
+  auto i1 = V.cend();
   clang_analyzer_printState();
   
 // CHECK:  "checker_messages": [
@@ -1879,4 +1880,6 @@
 // CHECK-NEXT: "Iterator Positions :",
 // CHECK-NEXT: "i1 : Valid ; Container == SymRegion{reg_$[[#]] & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
 // CHECK-NEXT:   ]}
+
+  --i1;
 }
Index: clang/test/Analysis/explain-svals.cpp
===
--- clang/test/Analysis/explain-svals.cpp
+++ clang/test/Analysis/explain-svals.cpp
@@ -93,6 +93,6 @@
 } // end of anonymous namespace
 
 void test_6() {
-  clang_analyzer_explain(conjure_S()); // expected-warning-re^lazily frozen compound value of temporary object constructed at statement 'conjure_S\(\)'$
+  clang_analyzer_explain(conjure_S()); // expected-warning-re^lazily frozen compound value of parameter 0 of function 'clang_analyzer_explain\(\)'$
   clang_analyzer_explain(conjure_S().z); // expected-warning-re^value derived from \(symbol of type 'int' conjured at statement 'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 'conjure_S\(\)'$
 }
Ind

[PATCH] D79276: [FileCheck] Support comment directives

2020-05-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked 4 inline comments as done.
jdenny added a comment.

Thanks for the review.  I've replied to a few comments, and I'll address the 
rest later.

In D79276#2017101 , @jhenderson wrote:

> I hesitate to suggest this, but is it worth using `REM` as a comment prefix? 
> It's the comment marker for Windows batch files, so has some precedence.


I don't have a strong preference.  Does anyone else following this have a 
preference?

Some data about existing usage:

  $ cd llvm.git
  $ git grep '\ You don't need to prefix the lines with '//' or anything else for that 
> matter, since this isn't being used as an assembly/yaml/C/etc input.
> 
> If you do want to have the characters (I don't care either way), I'd prefer 
> '#' for RUN/CHECK directive lines and '##' for comments (the latter so they 
> stand out better from directive lines). It's fewer characters, whilst still 
> as explicit ('#' is used widely in some parts of the testsuite at least).
I don't much care either. The FileCheck test suite is not consistent in this 
regard.

What about the following style, making use of `COM:` (or `REM:` or whatever we 
choose) for comments as that's it's purpose:

```
COM: -
COM: Comment directives successfully comment out check directives.
COM: -

COM: Check all default comment prefixes.
COM: Check that a comment directive at the begin/end of the file is handled.
COM: Check that the preceding/following line's check directive is not affected.
RUN: echo 'foo'   >  %t.in
RUN: echo 'COM: CHECK: bar'   >  %t.chk
RUN: echo 'CHECK: foo'>> %t.chk
RUN: echo 'RUN:echo "CHECK: baz"' >> %t.chk
RUN: %ProtectFileCheckOutput FileCheck -vv %t.chk < %t.in 2>&1 \
RUN: | FileCheck -check-prefix=SUPPRESSES-CHECKS -DCHECK_LINE=2 %s

COM: Check the case of one user-specified comment prefix.
COM: Check that a comment directive not at the beginning of a line is handled.
RUN: echo 'foo'  >  %t.in
RUN: echo 'CHECK: foo'   >  %t.chk
RUN: echo 'letters then space MY-PREFIX: CHECK: bar' >> %t.chk
RUN: %ProtectFileCheckOutput \
RUN: FileCheck -vv %t.chk -comment-prefixes=MY-PREFIX < %t.in 2>&1 \
RUN: | FileCheck -check-prefix=SUPPRESSES-CHECKS -DCHECK_LINE=1 %s

COM: Check the case of multiple user-specified comment prefixes.
RUN: echo 'foo'   >  %t.in
RUN: echo 'Bar_2: CHECK: Bar' >  %t.chk
RUN: echo 'CHECK: foo'>> %t.chk
RUN: echo 'Foo_1: CHECK: Foo' >> %t.chk
RUN: echo 'Baz_3: CHECK: Baz' >> %t.chk
RUN: %ProtectFileCheckOutput \
RUN: FileCheck -vv %t.chk -comment-prefixes=Foo_1,Bar_2 \
RUN:   -comment-prefixes=Baz_3 < %t.in 2>&1 \
RUN: | FileCheck -check-prefix=SUPPRESSES-CHECKS -DCHECK_LINE=2 %s

SUPPRESSES-CHECKS: .chk:[[CHECK_LINE]]:8: remark: CHECK: expected string found 
in input
```



Comment at: llvm/test/FileCheck/comment.txt:2
+// Comment directives successfully comment out check directives.
+//
+// Check all default comment prefixes.

jhenderson wrote:
> Don't prefix empty lines.
I was doing that to keep related lines together in a block, but I can use 
"-" lines to separate blocks instead, as shown in my reply above.



Comment at: llvm/test/FileCheck/comment.txt:10-11
+// RUN: echo 'RUN:echo "CHECK: baz"' >> %t.chk
+// RUN: %ProtectFileCheckOutput FileCheck -vv %t.chk < %t.in 2>&1 \
+// RUN: | FileCheck -check-prefix=SUPPRESSES-CHECKS -DCHECK_LINE=2 %s
+//

jhenderson wrote:
> I have a personal preference for multi-line commands like this to be 
> formatted like this:
> 
> ```
> // RUN:   ... | \
> // RUN: ...
> ```
> 
> with the `|` and `\` on the same line, to show that the next line is the 
> start of a new command (as opposed to just being more arguments for that 
> line), and the extra two space indentation showing that the line is a 
> continuation of the previous.
Has the community ever discussed a preferred style for the LLVM coding 
standards?  I don't have strong feelings about what we choose, but settling on 
one standard would be nice.



Comment at: llvm/test/FileCheck/comment.txt:143-147
+// Check user-supplied check prefix that duplicates a default comment prefix.
+// RUN: %ProtectFileCheckOutput not FileCheck /dev/null < /dev/null 2>&1 \
+// RUN:  -check-prefixes=FOO,COM \
+// RUN: | FileCheck -check-prefix=CHECK-PREFIX-DUP-COMMENT %s
+// CHECK-PREFIX-DUP-COMMENT: error: supplied check prefix must be unique among 
check prefixes and comment prefixes: 'COM'

jhenderson wrote:
> I would naively expect --check-prefixes=FOO,COM to work, and disable the 
> comment prefix. Is that complicated to implement?
It's probably not complicated to implement.

However, there can alr

[PATCH] D79330: [Analyzer][VLASizeChecker] Check for VLA size overflow.

2020-05-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/vla.c:107
+  if (x == BIGINDEX) {
+size_t s = sizeof(int[x][x][x][x]); // expected-warning{{Declared 
variable-length array (VLA) has too large size}}
+return s;

I think we could make the arithmetic more clear here:
x = BIGINDEX 65536 (2^16) and `char[x][x][x][x]` would be the first to overflow.
And `char[x][x][x][x-1]` should not overflow.

And if we are at it, then `size_t`'s range is target dependent, so I think we 
must extend the `RUN` line with `-target`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79330



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


[PATCH] D79232: [analyzer] Refactor range inference for symbolic expressions

2020-05-04 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 261833.
vsavchenko marked an inline comment as done.
vsavchenko added a comment.

Now `getRange` is more likely to return unfeasible range.  Calling `Intersect` 
and `pin` methods from such ranges might cause a crash.
Check for unfeasible ranges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79232

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -115,7 +115,16 @@
 #endif
 
   // Check that dynamically computed constants also work.
-  int constant = 1 << 3;
+  unsigned int constant = 1 << 3;
   unsigned int d = a | constant;
-  clang_analyzer_eval(constant > 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(d >= constant); // expected-warning{{TRUE}}
+
+  // Check that nested expressions also work.
+  clang_analyzer_eval(((a | 10) | 5) >= 10); // expected-warning{{TRUE}}
+
+  // Check correct processing of unfeasible ranges
+  if (a > 10) {
+clang_analyzer_eval((a & 1) <= 1); // expected-warning{{FALSE}}
+clang_analyzer_eval((a & 1) > 1);  // expected-warning{{FALSE}}
+  }
 }
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -16,6 +16,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableSet.h"
 #include "llvm/Support/raw_ostream.h"
@@ -23,10 +24,16 @@
 using namespace clang;
 using namespace ento;
 
+//===--===//
+//   RangeSet implementation
+//===--===//
+
 void RangeSet::IntersectInRange(BasicValueFactory &BV, Factory &F,
-  const llvm::APSInt &Lower, const llvm::APSInt &Upper,
-  PrimRangeSet &newRanges, PrimRangeSet::iterator &i,
-  PrimRangeSet::iterator &e) const {
+const llvm::APSInt &Lower,
+const llvm::APSInt &Upper,
+PrimRangeSet &newRanges,
+PrimRangeSet::iterator &i,
+PrimRangeSet::iterator &e) const {
   // There are six cases for each range R in the set:
   //   1. R is entirely before the intersection range.
   //   2. R is entirely after the intersection range.
@@ -66,6 +73,11 @@
 }
 
 bool RangeSet::pin(llvm::APSInt &Lower, llvm::APSInt &Upper) const {
+  if (isEmpty()) {
+// This range is already unfeasible.
+return false;
+  }
+
   // This function has nine cases, the cartesian product of range-testing
   // both the upper and lower bounds against the symbol's type.
   // Each case requires a different pinning operation.
@@ -238,6 +250,190 @@
 }
 
 namespace {
+
+/// A little component aggregating all of the reasoning we have about
+/// the ranges of symbolic expressions.
+///
+/// Even when we don't know the exact values of the operands, we still
+/// can get a pretty good estimate of the result's range.
+class SymbolicRangeInferrer
+: public SymExprVisitor {
+public:
+  static RangeSet inferRange(BasicValueFactory &BV, RangeSet::Factory &F,
+ ProgramStateRef State, SymbolRef Sym) {
+SymbolicRangeInferrer Inferrer(BV, F, State);
+return Inferrer.infer(Sym);
+  }
+
+  RangeSet VisitSymExpr(SymbolRef Sym) {
+// If we got to this function, the actual type of the symbolic
+// expression is not supported for advanced inference.
+// In this case, we simply backoff to the default "let's simply
+// infer the range from the expression's type".
+return infer(Sym->getType());
+  }
+
+  RangeSet VisitSymIntExpr(const SymIntExpr *Sym) {
+return VisitBinaryOperator(Sym);
+  }
+
+  RangeSet VisitIntSymExpr(const IntSymExpr *Sym) {
+return VisitBinaryOperator(Sym);
+  }
+
+  RangeSet VisitSymSymExpr(const SymSymExpr *Sym) {
+return VisitBinaryOperator(Sym);
+  }
+
+private:
+  SymbolicRangeInferrer(BasicValueFactory &BV, RangeSet::Factory &F,
+ProgramStateRef S)
+  : ValueFactory(BV), RangeFactory(F), State(S) {}
+
+  /// Infer range information from 

[PATCH] D79276: [FileCheck] Support comment directives

2020-05-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D79276#2017742 , @jdenny wrote:

> Thanks for the review.  I've replied to a few comments, and I'll address the 
> rest later.
>
> In D79276#2017101 , @jhenderson 
> wrote:
>
> > I hesitate to suggest this, but is it worth using `REM` as a comment 
> > prefix? It's the comment marker for Windows batch files, so has some 
> > precedence.
>
>
> I don't have a strong preference.  Does anyone else following this have a 
> preference?


One reason not to choose `REM:` is that it looks much more like `RUN:` than 
`COM:`.  For example, imagine the long code sample I wrote in my last comment 
, but with `COM:` replaced by 
`REM:`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79276



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


[PATCH] D66831: [ObjC] Fix type checking for qualified id block parameters.

2020-05-04 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

Hi, it seems that this change is incompatible with the `[NSItemProvider 
loadItemForTypeIdentifier:options:completionHandler:]` method's expected (but 
extremely weird and unusual!) usage.

Per 
https://developer.apple.com/documentation/foundation/nsitemprovider/1403900-loaditemfortypeidentifier?language=objc
 it takes an argument of type `NSItemProviderCompletionHandler` aka `void 
(^)(id item, NSError *error);`. However, 
`loadItemForTypeIdentifier:options:completionHandler` expects users to provide 
blocks of other types, e.g. `^(NSURL *url, NSError *error) { ... }` and 
introspects at runtime the resulting block object to determine the declared 
signature, and then provides the expected type.

This is, of course, an extremely weird API (who'd ever expect a function to do 
runtime introspection of the callback's function signature and change the types 
passed to the function accordingly?). But, the expected usage previously 
type-checked, because of the bug fixed in this change (`NSURL*` is a subtype of 
`id`, so it was accepted before), and now throws an error.

Should this change be reverted? Or have an exemption added for that one weird 
API? Or maybe that API needs to be modified to say it takes an argument of type 
"id" instead of NSItemProviderCompletionHandler?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66831



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


[PATCH] D79334: [clang-tidy]: Add cert-str34-c alias for bugprone-signed-char-misuse.

2020-05-04 Thread Tamás Zolnai via Phabricator via cfe-commits
ztamas created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
ztamas edited the summary of this revision.
ztamas edited the summary of this revision.
ztamas edited the summary of this revision.
ztamas added a reviewer: aaron.ballman.

Added CertSTR34C option to filter out unrelated use cases.
The SEI cert catches explicit integer casts (two use cases),
while in the case of `signed char` \ `unsigned char`
comparison, we have an implicit conversion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79334

Files:
  clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-signed-char-misuse.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-str34-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-str34-c.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-str34-c.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-str34-c.cpp
@@ -0,0 +1,18 @@
+// RUN: %check_clang_tidy %s cert-str34-c %t
+
+// Check whether alias is actually working.
+int SimpleVarDeclaration() {
+  signed char CCharacter = -5;
+  int NCharacter = CCharacter;
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [cert-str34-c]
+
+  return NCharacter;
+}
+
+// Check whether bugprone-signed-char-misuse.CertSTR34C option is set correctly.
+int SignedUnsignedCharEquality(signed char SCharacter) {
+  unsigned char USCharacter = 'a';
+  if (SCharacter == USCharacter) // no warning
+return 1;
+  return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -320,6 +320,7 @@
`cert-oop11-cpp `_, `performance-move-constructor-init `_, "Yes"
`cert-oop54-cpp `_, `bugprone-unhandled-self-assignment `_,
`cert-pos44-c `_, `bugprone-bad-signal-to-kill-thread `_,
+   `cert-str34-c `_, `bugprone-signed-char-misuse `_,
`clang-analyzer-core.CallAndMessage `_, `Clang Static Analyzer `_,
`clang-analyzer-core.DivideZero `_, `Clang Static Analyzer `_,
`clang-analyzer-core.NonNullParamChecker `_, `Clang Static Analyzer `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cert-str34-c.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cert-str34-c.rst
@@ -0,0 +1,10 @@
+.. title:: clang-tidy - cert-str34-c
+.. meta::
+   :http-equiv=refresh: 5;URL=bugprone-signed-char-misuse.html
+
+cert-str34-c
+==
+
+The cert-str34-c check is an alias, please see
+`bugprone-signed-char-misuse `_
+for more information.
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-signed-char-misuse.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone-signed-char-misuse.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-signed-char-misuse.rst
@@ -3,6 +3,9 @@
 bugprone-signed-char-misuse
 ===
 
+`cert-str34-c` redirects here as an alias for this check. For the CERT alias,
+the `CertSTR34C` option is set to `1`.
+
 Finds those ``signed char`` -> integer conversions which might indicate a
 programming error. The basic problem with the ``signed char``, that it might
 store the non-ASCII characters as negative values. This behavior can cause a
@@ -108,3 +111,9 @@
   check. This is useful when a typedef introduces an integer alias like
   ``sal_Int8`` or ``int8_t``. In this case, human misinterpretation is not
   an issue.
+
+.. option:: CertSTR34C
+
+  When non-zero, the check will warn only in the cases described by the
+  STR34-C SEI cert rule. This check covers more use cases, which can be
+  limited with this option.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -168,6 +168,11 @@
   :doc:`bugprone-reserved-identifier
   ` was added.
 
+- New alias :doc:`cert-str34-c
+  ` to
+  :doc:`bugprone-signed-char-misuse
+  ` was added.
+
 Changes in existing checks
 ^^
 
Index: clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ clang-tools-

[PATCH] D69088: [Lex] #pragma clang transform

2020-05-04 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69088



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


[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-05-04 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 261837.
ZarkoCA edited the summary of this revision.
ZarkoCA added a comment.

Rebased patch to include latest changes in trunk.  Removed that it depended on 
https://reviews.llvm.org/D73290 in the summary, as that patch has been landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76360

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-vararg.c
  clang/test/CodeGen/ppc-dwarf.c
  clang/test/CodeGen/ppc32-struct-return.c
  clang/test/CodeGen/ppc64-dwarf.c

Index: clang/test/CodeGen/ppc64-dwarf.c
===
--- clang/test/CodeGen/ppc64-dwarf.c
+++ /dev/null
@@ -1,128 +0,0 @@
-// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
-static unsigned char dwarf_reg_size_table[1024];
-
-int test() {
-  __builtin_init_dwarf_reg_size_table(dwarf_reg_size_table);
-
-  return __builtin_dwarf_sp_column();
-}
-
-// CHECK-LABEL: define signext i32 @test()
-// CHECK:  store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 0), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 1), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 2), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 3), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 4), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 5), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 6), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 7), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 8), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 9), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 10), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 11), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 12), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 13), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 14), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 15), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 16), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 17), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 18), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 19), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 20), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 21), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 22), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 23), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 24), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 25), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 26), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 27), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 28), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 29), align 1
-// CHECK-NEXT: store i8 8, i8* getelementptr inboun

[PATCH] D79330: [Analyzer][VLASizeChecker] Check for VLA size overflow.

2020-05-04 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Question: Is there a way to check for overflow in the symbolic domain (that is 
the `ArrSize` value)? Or get the maximal possible value of a `SVal` if it is 
constrained? (The `ArrSize` that is a multiplication of every dimension size 
can not be checked simply for too big value symbolically because calculation 
overflows are not detected.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79330



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


[PATCH] D76342: [OpenMP] Implement '#pragma omp tile'

2020-05-04 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76342



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


[clang] 6604118 - Let clang print registered targets for --version

2020-05-04 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-05-04T12:26:18-04:00
New Revision: 66041187c9028f730c41597fe5ea6a63fda1ccad

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

LOG: Let clang print registered targets for --version

We need a way to know supported targets by clang since
people may use clang as assembler and they want to
choose the clang which supports their target.

This patch let clang print registered targets when
--version option is passed to clang.

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 7d82c8faa573..80a2d202efa1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1569,6 +1569,9 @@ void Driver::PrintVersion(const Compilation &C, 
raw_ostream &OS) const {
   // If configuration file was used, print its path.
   if (!ConfigFile.empty())
 OS << "Configuration file: " << ConfigFile << '\n';
+
+  // Print the registered targets.
+  llvm::TargetRegistry::printRegisteredTargetsForVersion(OS);
 }
 
 /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories



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


[PATCH] D79315: [clangd] Get rid of Inclusion::R

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 261845.
kadircet marked an inline comment as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79315

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1490,14 +1490,15 @@
 
 TEST(DocumentLinks, All) {
   Annotations MainCpp(R"cpp(
-  #include $foo[["foo.h"]]
+  #/*comments*/include /*comments*/ $foo[["foo.h"]] //more comments
   int end_of_preamble = 0;
-  #include $bar[["bar.h"]]
+  #include $bar[[]]
 )cpp");
 
   TestTU TU;
   TU.Code = std::string(MainCpp.code());
   TU.AdditionalFiles = {{"foo.h", ""}, {"bar.h", ""}};
+  TU.ExtraArgs = {"-isystem."};
   auto AST = TU.build();
 
   EXPECT_THAT(
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -127,7 +127,7 @@
 
 MATCHER_P(Written, Name, "") { return arg.Written == Name; }
 MATCHER_P(Resolved, Name, "") { return arg.Resolved == Name; }
-MATCHER_P(IncludeLine, N, "") { return arg.R.start.line == N; }
+MATCHER_P(IncludeLine, N, "") { return arg.HashLine == N; }
 MATCHER_P(Directive, D, "") { return arg.Directive == D; }
 
 MATCHER_P2(Distance, File, D, "") {
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -187,7 +187,7 @@
  ParsedAST &AST,
  llvm::StringRef MainFilePath) {
   for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
-if (!Inc.Resolved.empty() && Inc.R.start.line == Pos.line) {
+if (!Inc.Resolved.empty() && Inc.HashLine == Pos.line) {
   LocatedSymbol File;
   File.Name = std::string(llvm::sys::path::filename(Inc.Resolved));
   File.PreferredDeclaration = {
@@ -599,10 +599,23 @@
 
   std::vector Result;
   for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
-if (!Inc.Resolved.empty()) {
-  Result.push_back(DocumentLink(
-  {Inc.R, URIForFile::canonicalize(Inc.Resolved, *MainFilePath)}));
-}
+if (Inc.Resolved.empty())
+  continue;
+auto HashLoc = SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset);
+const auto *HashTok = AST.getTokens().spelledTokenAt(HashLoc);
+assert(HashTok && "got inclusion at wrong offset");
+const auto *IncludeTok = std::next(HashTok);
+const auto *FileTok = std::next(IncludeTok);
+// FileTok->range is not sufficient here, as raw lexing wouldn't yield
+// correct tokens for angled filenames. Hence we explicitly use
+// Inc.Written's length.
+auto FileRange =
+syntax::FileRange(SM, FileTok->location(), Inc.Written.length())
+.toCharRange(SM);
+
+Result.push_back(
+DocumentLink({halfOpenToRange(SM, FileRange),
+  URIForFile::canonicalize(Inc.Resolved, *MainFilePath)}));
   }
 
   return Result;
Index: clang-tools-extra/clangd/Headers.h
===
--- clang-tools-extra/clangd/Headers.h
+++ clang-tools-extra/clangd/Headers.h
@@ -52,11 +52,11 @@
 
 // An #include directive that we found in the main file.
 struct Inclusion {
-  Range R;  // Inclusion range.
   tok::PPKeywordKind Directive; // Directive used for inclusion, e.g. import
   std::string Written;  // Inclusion name as written e.g. .
   Path Resolved; // Resolved path of included file. Empty if not resolved.
   unsigned HashOffset = 0; // Byte offset from start of file to #.
+  int HashLine = 0;// Line number containing the directive, 0-indexed.
   SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion &);
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -38,11 +38,12 @@
 if (isInsideMainFile(HashLoc, SM)) {
   Out->MainFileIncludes.emplace_back();
   auto &Inc = Out->MainFileIncludes.back();
-  Inc.R = halfOpenToRange(SM, FilenameRange);
   Inc.Written =
   (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
   Inc.Resolved = std::string

[PATCH] D79315: [clangd] Get rid of Inclusion::R

2020-05-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 4 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:610
+auto FileRange =
+syntax::FileRange(SM, FileTok->location(), Inc.Written.length())
+.toCharRange(SM);

sammccall wrote:
> is this just FileTok.range(SM)?
unfortunately it is not. as raw lexing doesn't parse angled filename tokens(it 
will just point to the `lessthan` token). Adding a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79315



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


[PATCH] D78655: [HIP] Add -fhip-lambda-host-device

2020-05-04 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

Is it possible to add a test like this?

  kernel<<<1,1>>>([=](){ 
  auto f = [&]{ hd(); };
  f(); 
  });

That should not have a compiler error.


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

https://reviews.llvm.org/D78655



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


[PATCH] D79232: [analyzer] Refactor range inference for symbolic expressions

2020-05-04 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/test/Analysis/constant-folding.c:127-128
+  if (a > 10) {
+clang_analyzer_eval((a & 1) <= 1); // expected-warning{{FALSE}}
+clang_analyzer_eval((a & 1) > 1);  // expected-warning{{FALSE}}
+  }

How can both of these be false? o.o


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79232



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


[PATCH] D78658: [clang][Frontend] Add missing error handling

2020-05-04 Thread LemonBoy via Phabricator via cfe-commits
LemonBoy added a comment.

Ping?


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

https://reviews.llvm.org/D78658



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


[PATCH] D78979: OpenCL: Include builtin header by default

2020-05-04 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D78979#2015214 , @arsenm wrote:

> In D78979#2010739 , @Anastasia wrote:
>
> > In D78979#2010527 , @svenvh wrote:
> >
> > > In D78979#2007643 , @Anastasia 
> > > wrote:
> > >
> > > > > Would it not become confusing since the builtins are going to be 
> > > > > included by default? Should we rename the flag at least? Also ideally 
> > > > > it should be documented in 
> > > > > https://clang.llvm.org/docs/UsersManual.html#opencl-header
> > > >
> > > > ah I guess if we leave it under `-cc1 ` we will have the command line 
> > > > interface as follows:
> > > >
> > > > - Driver (without `-cc1`) adds OpenCL header by default that can be 
> > > > overridden by the flag added in this patch.
> > > > - Frontend (with `-cc1`) doesn't add the header by default but there 
> > > > are two flags `-fdeclare-opencl-builtins` or `-finclude-default-header` 
> > > > that allow to include the header.
> > >
> > >
> > > The name of `-fdeclare-opencl-builtins` becomes a bit non-intuitive, a 
> > > more intuitive name would be something like `-fopencl-tablegen-builtins` 
> > > perhaps or `-fopencl-fast-builtins` if we don't want to mention TableGen. 
> > >  But since it is still an experimental option, I have no objections 
> > > against postponing the renaming until the option has reached maturity.
> >
> >
> > I vote for `-fopencl-fast-builtins`.
>
>
> The main problem I'm trying to solve is that users shouldn't need to concern 
> themselves with including any header, much less a choice between two internal 
> implementation details. Switching the two internal header implementations 
> seems OK to leave as a cc1 flag. The main question I think is what the 
> spelling of how to disable whatever default header was chosen, and what the 
> internal flags to switch the implementation look like.
>
> So what's the agreement on spelling? Use -nostdinc/-nostdlib? Have 2 
> different cc1 flags for the header implementation switch? Surface/invert 
> -fno-include-default-header?


I like the idea of reusing -nostdinc/-nostdlib, although we don't link to libs 
by default so I guess -nostdlib is useless? Then do we want to keep 
`-finclude-default-header` to be used for the frontend? As for the TableGen 
header I guess we can leave it under frontend only flag for now but I would 
suggest to rename to something more distinct i.e. `-fopencl-fast-builtins`?


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

https://reviews.llvm.org/D78979



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


[PATCH] D79210: Let clang print registered targets for --version

2020-05-04 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG66041187c902: Let clang print registered targets for 
--version (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79210

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1569,6 +1569,9 @@
   // If configuration file was used, print its path.
   if (!ConfigFile.empty())
 OS << "Configuration file: " << ConfigFile << '\n';
+
+  // Print the registered targets.
+  llvm::TargetRegistry::printRegisteredTargetsForVersion(OS);
 }
 
 /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1569,6 +1569,9 @@
   // If configuration file was used, print its path.
   if (!ConfigFile.empty())
 OS << "Configuration file: " << ConfigFile << '\n';
+
+  // Print the registered targets.
+  llvm::TargetRegistry::printRegisteredTargetsForVersion(OS);
 }
 
 /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] cb78376 - Test commit. Modified comment to add a period at the end.

2020-05-04 Thread via cfe-commits

Author: Zarko
Date: 2020-05-04T13:06:21-04:00
New Revision: cb7837643389d5f314cc27cbcb7863daeee8ec84

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

LOG: Test commit. Modified comment to add a period at the end.

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index d737130d4c3f..237ef7c9ff95 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -4252,7 +4252,7 @@ class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
 }
 
 CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
-  // Complex types are passed just like their elements
+  // Complex types are passed just like their elements.
   if (const ComplexType *CTy = Ty->getAs())
 Ty = CTy->getElementType();
 



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


[PATCH] D76077: [ARM] Add __bf16 as new Bfloat16 C Type

2020-05-04 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 261851.
stuij added a comment.

I've amended this patch to conform to the general Bfloat -> BFloat convention
changes requested in the dependent BFloat IR patch (D78190 
).

I also folded in two other downstream patches, which allow for the ?: operator
on bf16 values and prohibit conversions between integer and __bf16.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76077

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/BuiltinTypes.def
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TargetBuiltins.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypeCache.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/arm-mangle-16bit-float.cpp
  clang/test/Sema/arm-bf16-forbidden-ops.c
  clang/test/Sema/arm-bf16-forbidden-ops.cpp
  clang/test/Sema/arm-bfloat.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -608,6 +608,7 @@
 TKIND(Elaborated);
 TKIND(Pipe);
 TKIND(Attributed);
+TKIND(BFloat16);
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
 #include "clang/Basic/OpenCLImageTypes.def"
 #undef IMAGE_TYPE
Index: clang/test/Sema/arm-bfloat.cpp
===
--- /dev/null
+++ clang/test/Sema/arm-bfloat.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 \
+// RUN: -triple aarch64-arm-none-eabi -target-cpu cortex-a75 \
+// RUN: -target-feature +bf16 -target-feature +neon %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 \
+// RUN: -triple arm-arm-none-eabi -target-cpu cortex-a53 \
+// RUN: -target-feature +bf16 -target-feature +neon %s
+
+void test(bool b) {
+  __bf16 bf16;
+
+  bf16 + bf16; // expected-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
+  bf16 - bf16; // expected-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
+  bf16 * bf16; // expected-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
+  bf16 / bf16; // expected-error {{invalid operands to binary expression ('__bf16' and '__bf16')}}
+
+  __fp16 fp16;
+
+  bf16 + fp16; // expected-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
+  fp16 + bf16; // expected-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
+  bf16 - fp16; // expected-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
+  fp16 - bf16; // expected-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
+  bf16 * fp16; // expected-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
+  fp16 * bf16; // expected-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
+  bf16 / fp16; // expected-error {{invalid operands to binary expression ('__bf16' and '__fp16')}}
+  fp16 / bf16; // expected-error {{invalid operands to binary expression ('__fp16' and '__bf16')}}
+  bf16 = fp16; // expected-error {{assigning to '__bf16' from incompatible type '__fp16'}}
+  fp16 = bf16; // expected-error {{assigning to '__fp16' from incompatible type '__bf16'}}
+  bf16 + (b ? fp16 : bf16); // expected-error {{incompatible operand types ('__fp16' and '__bf16')}}
+}
Index: clang/test/Sema/arm-bf16-forbidden-ops.cpp

[PATCH] D79336: [analyzer] Generalize bitwise OR rules for ranges

2020-05-04 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, dcoughlin.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a project: clang.
vsavchenko added a comment.

Here is a little proof I've put together (using Z3): 
https://gist.github.com/SavchenkoValeriy/9ad6ca72e7420fd5612e618187bd4f76


Previously the current solver started reasoning about bitwise OR
expressions only when one of the operands is a constant.  However,
very similar logic could be applied to ranges.  This commit addresses
this shortcoming.  Additionally, it refines how we deal with negative
operands.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79336

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -77,7 +77,7 @@
   clang_analyzer_eval(a != b); // expected-warning{{TRUE}}
 }
 
-void testBitwiseRules(unsigned int a, int b) {
+void testBitwiseRules(unsigned int a, int b, int c) {
   clang_analyzer_eval((a | 1) >= 1); // expected-warning{{TRUE}}
   clang_analyzer_eval((a | -1) >= -1); // expected-warning{{TRUE}}
   clang_analyzer_eval((a | 2) >= 2); // expected-warning{{TRUE}}
@@ -96,9 +96,9 @@
   // Again, check for different argument order.
   clang_analyzer_eval((1 & a) <= 1); // expected-warning{{TRUE}}
 
-  unsigned int c = a;
-  c |= 1;
-  clang_analyzer_eval((c | 0) == 0); // expected-warning{{FALSE}}
+  unsigned int d = a;
+  d |= 1;
+  clang_analyzer_eval((d | 0) == 0); // expected-warning{{FALSE}}
 
   // Rules don't apply to signed typed, as the values might be negative.
   clang_analyzer_eval((b | 1) > 0); // expected-warning{{UNKNOWN}}
@@ -108,16 +108,39 @@
   clang_analyzer_eval((b | -2) == 0); // expected-warning{{FALSE}}
   clang_analyzer_eval((b | 10) == 0); // expected-warning{{FALSE}}
   clang_analyzer_eval((b | 0) == 0); // expected-warning{{UNKNOWN}}
-#ifdef ANALYZER_CM_Z3
   clang_analyzer_eval((b | -2) >= 0); // expected-warning{{FALSE}}
-#else
-  clang_analyzer_eval((b | -2) >= 0); // expected-warning{{UNKNOWN}}
-#endif
+
+  // Check that we can operate with negative ranges
+  if (b < 0) {
+clang_analyzer_eval((b | -1) == -1);   // expected-warning{{TRUE}}
+clang_analyzer_eval((b | -10) >= -10); // expected-warning{{TRUE}}
+
+int e = (b | -5);
+clang_analyzer_eval(e >= -5 && e <= -1); // expected-warning{{TRUE}}
+
+if (b < -20) {
+  clang_analyzer_eval((b | e) >= -5); // expected-warning{{TRUE}}
+}
+
+// Check that we can reason about the result even if know nothing
+// about one of the operands.
+clang_analyzer_eval((b | c) != 0); // expected-warning{{TRUE}}
+  }
+
+  if (a <= 30 && b >= 10 && c >= 20) {
+// Check that we can reason about non-constant operands.
+clang_analyzer_eval((b | c) >= 20); // expected-warning{{TRUE}}
+
+// Check that we can reason about the resulting range even if
+// the types are not the same, but we still can convert operand
+// ranges.
+clang_analyzer_eval((a | b) >= 10); // expected-warning{{TRUE}}
+  }
 
   // Check that dynamically computed constants also work.
   unsigned int constant = 1 << 3;
-  unsigned int d = a | constant;
-  clang_analyzer_eval(d >= constant); // expected-warning{{TRUE}}
+  unsigned int f = a | constant;
+  clang_analyzer_eval(f >= constant); // expected-warning{{TRUE}}
 
   // Check that nested expressions also work.
   clang_analyzer_eval(((a | 10) | 5) >= 10); // expected-warning{{TRUE}}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -69,7 +69,19 @@
 
 const llvm::APSInt &RangeSet::getMinValue() const {
   assert(!isEmpty());
-  return ranges.begin()->From();
+  return begin()->From();
+}
+
+const llvm::APSInt &RangeSet::getMaxValue() const {
+  assert(!isEmpty());
+  // NOTE: It's a shame that we can't implement 'getMaxValue' without scanning
+  //   the whole tree to get to the last element.
+  //   llvm::ImmutableSet should support decrement for 'end' iterators
+  //   or reverse order iteration.
+  auto It = begin();
+  for (auto End = end(); std::next(It) != End; ++It) {
+  }
+  return It->To();
 }
 
 bool RangeSet::pin(llvm::APSInt &Lower, llvm::APSInt &Upper) const {
@@ -364,22 +376,103 @@
 }
   }
 
+  //===--===//
+  //

[PATCH] D78190: Add Bfloat IR type

2020-05-04 Thread Ties Stuij via Phabricator via cfe-commits
stuij added a comment.

Hi all. Are you OK for me to commit this change?

It was about a week ago since we resolved the last outstanding issues, and in 
general it looks like our noses have been pointing in the same direction on 
this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78190



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


[PATCH] D79232: [analyzer] Refactor range inference for symbolic expressions

2020-05-04 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:340-345
+// TODO #2: We didn't go into the nested expressions before, so it
+// might cause us spending much more time doing the inference.
+// This can be a problem for deeply nested expressions that are
+// involved in conditions and get tested continuously.  We definitely
+// need to address this issue and introduce some sort of caching
+// in here.

NoQ wrote:
> vsavchenko wrote:
> > NoQ wrote:
> > > I think this is a must-have, at least in some form. We've been exploding 
> > > like this before on real-world code, well, probably not with bitwise ops 
> > > but i'm still worried.
> > It will be pretty easy to introduce a limit on how deep we go into a tree 
> > of the given symbolic expression. That can also be a solution.
> I mean, doing something super trivial, like defining a map from symexprs to 
> ranges in `SymbolicRangeInferrer` itself and find-or-inserting into it, will 
> probably not be harder than counting depth(?)
I am a bit ignorant of this topic, but I wonder what a good caching mechanism 
would look like.
A simple `symexpr -> range` mapping does not feel right as the same symexpr 
might have a different range in a different program state (e.g., we might learn 
new ranges for our symbols). But having a separate map for each state state 
might do relatively little caching?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79232



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


[PATCH] D79336: [analyzer] Generalize bitwise OR rules for ranges

2020-05-04 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Here is a little proof I've put together (using Z3): 
https://gist.github.com/SavchenkoValeriy/9ad6ca72e7420fd5612e618187bd4f76


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79336



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


[PATCH] D78750: [SveEmitter] Add builtins for svdupq and svdupq_lane

2020-05-04 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 261853.
sdesmalen added a comment.

- Use CreateTempAlloca instead of CreateAlloca
- Added checks for alignment to the stores.
- Added test with control-flow to check the alloca is added to the entry-block.


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

https://reviews.llvm.org/D78750

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -94,7 +94,9 @@
   bool isDefault() const { return DefaultType; }
   bool isFloat() const { return Float; }
   bool isInteger() const { return !Float && !Predicate; }
-  bool isScalarPredicate() const { return !Float && ElementBitwidth == 1; }
+  bool isScalarPredicate() const {
+return !Float && Predicate && NumVectors == 0;
+  }
   bool isPredicateVector() const { return Predicate; }
   bool isPredicatePattern() const { return PredicatePattern; }
   bool isPrefetchOp() const { return PrefetchOp; }
@@ -407,12 +409,12 @@
 
 if (Float)
   S += "float";
-else if (isScalarPredicate())
+else if (isScalarPredicate() || isPredicateVector())
   S += "bool";
 else
   S += "int";
 
-if (!isScalarPredicate())
+if (!isScalarPredicate() && !isPredicateVector())
   S += utostr(ElementBitwidth);
 if (!isScalableVector() && isVector())
   S += "x" + utostr(getNumElements());
@@ -433,7 +435,6 @@
 switch (I) {
 case 'P':
   Predicate = true;
-  ElementBitwidth = 1;
   break;
 case 'U':
   Signed = false;
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
@@ -0,0 +1,389 @@
+// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+svint8_t test_svdupq_lane_s8(svint8_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_s8
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv16i8( %data, i64 %index)
+  // CHECK: ret  %[[INTRINSIC]]
+  return SVE_ACLE_FUNC(svdupq_lane,_s8,,)(data, index);
+}
+
+svint16_t test_svdupq_lane_s16(svint16_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_s16
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv8i16( %data, i64 %index)
+  // CHECK: ret  %[[INTRINSIC]]
+  return SVE_ACLE_FUNC(svdupq_lane,_s16,,)(data, index);
+}
+
+svint32_t test_svdupq_lane_s32(svint32_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_s32
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv4i32( %data, i64 %index)
+  // CHECK: ret  %[[INTRINSIC]]
+  return SVE_ACLE_FUNC(svdupq_lane,_s32,,)(data, index);
+}
+
+svint64_t test_svdupq_lane_s64(svint64_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_s64
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv2i64( %data, i64 %index)
+  // CHECK: ret  %[[INTRINSIC]]
+  return SVE_ACLE_FUNC(svdupq_lane,_s64,,)(data, index);
+}
+
+svuint8_t test_svdupq_lane_u8(svuint8_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_u8
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv16i8( %data, i64 %index)
+  // CHECK: ret  %[[INTRINSIC]]
+  return SVE_ACLE_FUNC(svdupq_lane,_u8,,)(data, index);
+}
+
+svuint16_t test_svdupq_lane_u16(svuint16_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_u16
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv8i16( %data, i64 %index)
+  // CHECK: ret  %[[INTRINSIC]]
+  return SVE_ACLE_FUNC(svdupq_lane,_u16,,)(data, index);
+}
+
+svuint32_t test_svdupq_lane_u32(svuint32_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_u32
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv4i32( %data, i64 %index)
+  // CHECK: ret  %[[INTRINSIC]]
+  return SVE_ACLE_FUNC(svdupq_lane,_u32,,)(data, index);
+}
+
+svuint64_t test_svdupq_lane_u64(svuint64_t data, uint64_t index)
+{
+  // CHECK-LABEL: test_svdupq_lane_u64
+  // CHECK: %[[INTRINSIC:.*]] = call  @llvm.aarch64.sve.dupq.lane.nxv2i64( %data, i64 %index)
+  // CHECK:

[PATCH] D79232: [analyzer] Refactor range inference for symbolic expressions

2020-05-04 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:385
+
+  RangeSet VisitAndOperator(RangeSet LHS, RangeSet RHS, QualType T) {
+// TODO: generalize for the ranged RHS.

I always get surprised when I read code like the one above seeing that only RHS 
is tested for being a concerte value. Later on, I vaguely start to remember 
that we only produce `SymIntExpr`s (is that correct?). I wonder if we should 
add an assert so this code blows up when someone is trying to add 
`IntSymExpr`s, so she will know what code needs modification. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79232



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


[PATCH] D77658: [analyzer] StdLibraryFunctionsChecker: Add sanity checks for constraints

2020-05-04 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 7 inline comments as done.
martong added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:234-236
+  // The signature of a function we want to describe with a summary. This is a
+  // concessive signature, meaning there may be irrelevant types in the
+  // signature which we do not check against a function with concrete types.

Szelethus wrote:
> It might be worth putting a `TODO` here to not forget the constness methods 
> :^)
Two types do not match if one of them is a const and the other is non-const. Is 
this what you're referring for?



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:697
 if (auto *FD = dyn_cast(D)) {
-  if (S.matchesSignature(FD)) {
+  if (S.Sign.matches(FD) && S.validate(FD)) {
 auto Res = Map.insert({FD->getCanonicalDecl(), S});

Szelethus wrote:
> This looks a bit odd, we're checking whether the function matches, and than 
> we validate right after? Shouldn't we just not match the `FD` if it isn't 
> valid?
Yeah, ok, I moved the validation back into `matchesSignature`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77658



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


[PATCH] D77658: [analyzer] StdLibraryFunctionsChecker: Add sanity checks for constraints

2020-05-04 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 261855.
martong marked 2 inline comments as done.
martong added a comment.

- Better encapsulate the data in a 'Summary'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77658

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -66,7 +66,7 @@
   /// Below is a series of typedefs necessary to define function specs.
   /// We avoid nesting types here because each additional qualifier
   /// would need to be repeated in every function spec.
-  struct Summary;
+  class Summary;
 
   /// Specify how much the analyzer engine should entrust modeling this function
   /// to us. If he doesn't, he performs additional invalidations.
@@ -112,10 +112,23 @@
 virtual ValueConstraintPtr negate() const {
   llvm_unreachable("Not implemented");
 };
+
+/// Do sanity check on the constraint.
+bool validate(const FunctionDecl *FD) const {
+  const bool ValidArg = ArgN == Ret || ArgN < FD->getNumParams();
+  assert(ValidArg && "Arg out of range!");
+  if (!ValidArg)
+return false;
+  // Subclasses may further refine the validation.
+  return sanityCheck(FD);
+}
 ArgNo getArgNo() const { return ArgN; }
 
   protected:
 ArgNo ArgN; // Argument to which we apply the constraint.
+
+/// Do polymorphic sanity check on the constraint.
+virtual bool sanityCheck(const FunctionDecl *FD) const { return true; }
   };
 
   /// Given a range, should the argument stay inside or outside this range?
@@ -165,6 +178,14 @@
   }
   return std::make_shared(Tmp);
 }
+
+bool sanityCheck(const FunctionDecl *FD) const override {
+  const bool ValidArg =
+  getArgType(FD, ArgN)->isIntegralType(FD->getASTContext());
+  assert(ValidArg &&
+ "This constraint should be applied on an integral type");
+  return ValidArg;
+}
   };
 
   class ComparisonConstraint : public ValueConstraint {
@@ -205,12 +226,61 @@
   Tmp.CannotBeNull = !this->CannotBeNull;
   return std::make_shared(Tmp);
 }
+
+bool sanityCheck(const FunctionDecl *FD) const override {
+  const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
+  assert(ValidArg &&
+ "This constraint should be applied only on a pointer type");
+  return ValidArg;
+}
   };
 
   /// The complete list of constraints that defines a single branch.
   typedef std::vector ConstraintSet;
 
   using ArgTypes = std::vector;
+
+  // A placeholder type, we use it whenever we do not care about the concrete
+  // type in a Signature.
+  const QualType Irrelevant{};
+  bool static isIrrelevant(QualType T) { return T.isNull(); }
+
+  // The signature of a function we want to describe with a summary. This is a
+  // concessive signature, meaning there may be irrelevant types in the
+  // signature which we do not check against a function with concrete types.
+  struct Signature {
+const ArgTypes ArgTys;
+const QualType RetTy;
+Signature(ArgTypes ArgTys, QualType RetTy) : ArgTys(ArgTys), RetTy(RetTy) {
+  assertRetTypeSuitableForSignature(RetTy);
+  for (size_t I = 0, E = ArgTys.size(); I != E; ++I) {
+QualType ArgTy = ArgTys[I];
+assertArgTypeSuitableForSignature(ArgTy);
+  }
+}
+bool matches(const FunctionDecl *FD) const;
+
+  private:
+static void assertArgTypeSuitableForSignature(QualType T) {
+  assert((T.isNull() || !T->isVoidType()) &&
+ "We should have no void types in the spec");
+  assert((T.isNull() || T.isCanonical()) &&
+ "We should only have canonical types in the spec");
+}
+static void assertRetTypeSuitableForSignature(QualType T) {
+  assert((T.isNull() || T.isCanonical()) &&
+ "We should only have canonical types in the spec");
+}
+  };
+
+  static QualType getArgType(const FunctionDecl *FD, ArgNo ArgN) {
+assert(FD && "Function must be set");
+QualType T = (ArgN == Ret)
+ ? FD->getReturnType().getCanonicalType()
+ : FD->getParamDecl(ArgN)->getType().getCanonicalType();
+return T;
+  }
+
   using Cases = std::vector;
 
   /// Includes information about
@@ -232,15 +302,19 @@
   ///   * a list of argument constraints, that must be true on every branch.
   /// If these constraints are not satisfied that means a fatal error
   /// usually resulting in undefined behaviour.
-  struct Summary {
-const ArgTypes ArgTys;
-const QualType RetTy;
+  class Summary {
+const Signature Sign;
 const InvalidationKind InvalidationKd;
 Cases CaseConstraints;
 

[PATCH] D79337: Silence warnings when compiling x86 with latest MSVC

2020-05-04 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea created this revision.
aganea added reviewers: bkramer, john.brawn, vsk.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

When using Visual Studio 2019 16.5.4, and targetting 32-bit, before this patch 
we were seeing:

  [1378/3007] Building CXX object 
lib\ProfileData\CMakeFiles\LLVMProfileData.dir\InstrProfReader.cpp.obj
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(426): warning C4018: 
'>': signed/unsigned mismatch
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(415): note: while 
compiling class template member function 'llvm::Error 
llvm::RawInstrProfReader::readRawCounts(llvm::InstrProfRecord &)'
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(491): note: see 
reference to function template instantiation 'llvm::Error 
llvm::RawInstrProfReader::readRawCounts(llvm::InstrProfRecord &)' 
being compiled
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(78): note: see 
reference to class template instantiation 'llvm::RawInstrProfReader' 
being compiled
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(430): warning C4018: 
'>': signed/unsigned mismatch

And:

  [2060/3007] Building CXX object 
tools\clang\lib\Sema\CMakeFiles\obj.clangSema.dir\ParsedAttr.cpp.obj
  F:\llvm-project\clang\lib\Sema\ParsedAttr.cpp(114): warning C4018: '<': 
signed/unsigned mismatch

I can commit the two files independently if you prefer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79337

Files:
  clang/lib/Sema/ParsedAttr.cpp
  llvm/lib/ProfileData/InstrProfReader.cpp


Index: llvm/lib/ProfileData/InstrProfReader.cpp
===
--- llvm/lib/ProfileData/InstrProfReader.cpp
+++ llvm/lib/ProfileData/InstrProfReader.cpp
@@ -423,11 +423,11 @@
 
   // Check bounds. Note that the counter pointer embedded in the data record
   // may itself be corrupt.
-  if (NumCounters > MaxNumCounters)
+  if (MaxNumCounters < 0 || NumCounters > (uint32_t)MaxNumCounters)
 return error(instrprof_error::malformed);
   ptrdiff_t CounterOffset = getCounterOffset(CounterPtr);
   if (CounterOffset < 0 || CounterOffset > MaxNumCounters ||
-  (CounterOffset + NumCounters) > MaxNumCounters)
+  ((uint32_t)CounterOffset + NumCounters) > (uint32_t)MaxNumCounters)
 return error(instrprof_error::malformed);
 
   auto RawCounts = makeArrayRef(getCounter(CounterOffset), NumCounters);
Index: clang/lib/Sema/ParsedAttr.cpp
===
--- clang/lib/Sema/ParsedAttr.cpp
+++ clang/lib/Sema/ParsedAttr.cpp
@@ -111,7 +111,7 @@
 
 const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
   // If we have a ParsedAttrInfo for this ParsedAttr then return that.
-  if (A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
+  if ((size_t)A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
 return *AttrInfoMap[A.getParsedKind()];
 
   // If this is an ignored attribute then return an appropriate ParsedAttrInfo.


Index: llvm/lib/ProfileData/InstrProfReader.cpp
===
--- llvm/lib/ProfileData/InstrProfReader.cpp
+++ llvm/lib/ProfileData/InstrProfReader.cpp
@@ -423,11 +423,11 @@
 
   // Check bounds. Note that the counter pointer embedded in the data record
   // may itself be corrupt.
-  if (NumCounters > MaxNumCounters)
+  if (MaxNumCounters < 0 || NumCounters > (uint32_t)MaxNumCounters)
 return error(instrprof_error::malformed);
   ptrdiff_t CounterOffset = getCounterOffset(CounterPtr);
   if (CounterOffset < 0 || CounterOffset > MaxNumCounters ||
-  (CounterOffset + NumCounters) > MaxNumCounters)
+  ((uint32_t)CounterOffset + NumCounters) > (uint32_t)MaxNumCounters)
 return error(instrprof_error::malformed);
 
   auto RawCounts = makeArrayRef(getCounter(CounterOffset), NumCounters);
Index: clang/lib/Sema/ParsedAttr.cpp
===
--- clang/lib/Sema/ParsedAttr.cpp
+++ clang/lib/Sema/ParsedAttr.cpp
@@ -111,7 +111,7 @@
 
 const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
   // If we have a ParsedAttrInfo for this ParsedAttr then return that.
-  if (A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
+  if ((size_t)A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
 return *AttrInfoMap[A.getParsedKind()];
 
   // If this is an ignored attribute then return an appropriate ParsedAttrInfo.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78750: [SveEmitter] Add builtins for svdupq and svdupq_lane

2020-05-04 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen marked 4 inline comments as done.
sdesmalen added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:8054
+
+Value *Alloca = Builder.CreateAlloca(EltTy, Builder.getInt32(NumOpnds));
+for (unsigned I = 0; I < NumOpnds; ++I)

efriedma wrote:
> Please use something like `CreateTempAlloca(llvm::ArrayType::get(EltTy, 
> NumOpnds), CharUnits::fromQuantity(16))`.
> 
> (In particular, the way you've written it, the code allocates stack memory 
> dynamically.  Might want to add a test with some control flow to demonstrate 
> that you're putting the alloca into the entry block.)
Good shout, I didn't realise that. I've fixed that in the latest revision.


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

https://reviews.llvm.org/D78750



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


[PATCH] D79274: Fix template class debug info for Visual Studio visualizers

2020-05-04 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

This should be testable with a -emit-llvm test FileChecking the generated IR?


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

https://reviews.llvm.org/D79274



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


[PATCH] D79059: Fix and re-submit D78534 - [libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON

2020-05-04 Thread Han Zhu via Phabricator via cfe-commits
zhuhan0 updated this revision to Diff 261866.
zhuhan0 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79059

Files:
  clang/cmake/modules/AddClang.cmake

Index: clang/cmake/modules/AddClang.cmake
===
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -45,7 +45,7 @@
 
 macro(add_clang_library name)
   cmake_parse_arguments(ARG
-"SHARED;INSTALL_WITH_TOOLCHAIN"
+"SHARED;STATIC;INSTALL_WITH_TOOLCHAIN"
 ""
 "ADDITIONAL_HEADERS"
 ${ARGN})
@@ -81,7 +81,10 @@
   ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
   )
   endif()
-  if(ARG_SHARED)
+
+  if(ARG_SHARED AND ARG_STATIC)
+set(LIBTYPE SHARED STATIC)
+  elseif(ARG_SHARED)
 set(LIBTYPE SHARED)
   else()
 # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
@@ -99,39 +102,46 @@
   endif()
   llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
-  if(TARGET ${name})
-target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
-
-if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
-  set(export_to_clangtargets)
-  if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
-  "clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
-  NOT LLVM_DISTRIBUTION_COMPONENTS)
-set(export_to_clangtargets EXPORT ClangTargets)
-set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
-  endif()
-
-  install(TARGETS ${name}
-COMPONENT ${name}
-${export_to_clangtargets}
-LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
-ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
-RUNTIME DESTINATION bin)
-
-  if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(install-${name}
- DEPENDS ${name}
- COMPONENT ${name})
-  endif()
-
-  set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${name})
-endif()
-set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
-  else()
-# Add empty "phony" target
-add_custom_target(${name})
+  set(libs ${name})
+  if(ARG_SHARED AND ARG_STATIC)
+set(libs ${name} ${name}_static)
   endif()
 
+  foreach(lib ${libs})
+if(TARGET ${lib})
+  target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS})
+
+  if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
+set(export_to_clangtargets)
+if(${lib} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
+"clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
+NOT LLVM_DISTRIBUTION_COMPONENTS)
+  set(export_to_clangtargets EXPORT ClangTargets)
+  set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
+endif()
+
+install(TARGETS ${lib}
+  COMPONENT ${lib}
+  ${export_to_clangtargets}
+  LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+  ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+  RUNTIME DESTINATION bin)
+
+if (NOT LLVM_ENABLE_IDE)
+  add_llvm_install_targets(install-${lib}
+   DEPENDS ${lib}
+   COMPONENT ${lib})
+endif()
+
+set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${lib})
+  endif()
+  set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${lib})
+else()
+  # Add empty "phony" target
+  add_custom_target(${lib})
+endif()
+  endforeach()
+
   set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
   set_clang_windows_version_resource_properties(${name})
 endmacro(add_clang_library)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79336: [analyzer] Generalize bitwise OR rules for ranges

2020-05-04 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:77
+  assert(!isEmpty());
+  // NOTE: It's a shame that we can't implement 'getMaxValue' without scanning
+  //   the whole tree to get to the last element.

Yeah, this is quite unfortunate. But you might end up calling this a lot for 
bitwise operations. I wonder if it is worth to solve this problem before 
commiting this patch. I do not insist though. 



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:388
+  /// it will return the range [x_0, y_N].
+  static Range roughen(RangeSet Origin) {
+assert(!Origin.isEmpty());

Is `roughen` part of a nomenclature? If not, what about something like `cover`?



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:418
+
+auto ConvertedCoarseLHS = convert(CoarseLHS, ResultType);
+auto ConvertedCoarseRHS = convert(CoarseRHS, ResultType);

Why do we need this conversion?
Do we want to model a cast in the code somewhere?
If so, I think this is more like a workaround and in the future we would need 
an explicit way to represent those cast operations. It might be worth to have a 
TODO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79336



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


[PATCH] D78655: [HIP] Add -fhip-lambda-host-device

2020-05-04 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 261869.
yaxunl added a comment.

add one more test


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

https://reviews.llvm.org/D78655

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/lambda.cu
  clang/test/SemaCUDA/Inputs/cuda.h
  clang/test/SemaCUDA/lambda.cu

Index: clang/test/SemaCUDA/lambda.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/lambda.cu
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -x hip -verify %s -fhip-lambda-host-device
+
+#include "Inputs/cuda.h"
+
+template
+__global__ void kernel(F f) { f(); }
+// expected-error@-1 3{{no matching function for call to object of type}}
+
+constexpr __host__ __device__ void hd();
+
+int main(void) {
+  auto lambda_kernel = [&]__global__(){};
+  // expected-error@-1 {{kernel function 'operator()' must be a free function or static member function}}
+
+  int b;
+
+  kernel<<<1,1>>>([](){ hd(); });
+
+  kernel<<<1,1>>>([=](){ hd(); });
+
+  kernel<<<1,1>>>([b](){ hd(); });
+
+  kernel<<<1,1>>>([&]()constexpr{ hd(); });
+
+  kernel<<<1,1>>>([&](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ function from __global__ function}}
+
+  kernel<<<1,1>>>([=, &b](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ function from __global__ function}}
+
+  kernel<<<1,1>>>([&, b](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ function from __global__ function}}
+
+  kernel<<<1,1>>>([=](){
+  auto f = [&]{ hd(); };
+  f();
+  });
+
+  return 0;
+}
Index: clang/test/SemaCUDA/Inputs/cuda.h
===
--- clang/test/SemaCUDA/Inputs/cuda.h
+++ clang/test/SemaCUDA/Inputs/cuda.h
@@ -17,6 +17,19 @@
   __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {}
 };
 
+#ifdef __HIP__
+typedef struct hipStream *hipStream_t;
+typedef enum hipError {} hipError_t;
+int hipConfigureCall(dim3 gridSize, dim3 blockSize, size_t sharedSize = 0,
+ hipStream_t stream = 0);
+extern "C" hipError_t __hipPushCallConfiguration(dim3 gridSize, dim3 blockSize,
+ size_t sharedSize = 0,
+ hipStream_t stream = 0);
+extern "C" hipError_t hipLaunchKernel(const void *func, dim3 gridDim,
+  dim3 blockDim, void **args,
+  size_t sharedMem,
+  hipStream_t stream);
+#else
 typedef struct cudaStream *cudaStream_t;
 typedef enum cudaError {} cudaError_t;
 
@@ -29,6 +42,7 @@
 extern "C" cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim,
 dim3 blockDim, void **args,
 size_t sharedMem, cudaStream_t stream);
+#endif
 
 // Host- and device-side placement new overloads.
 void *operator new(__SIZE_TYPE__, void *p) { return p; }
Index: clang/test/CodeGenCUDA/lambda.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/lambda.cu
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -triple x86_64-linux-gnu -fhip-lambda-host-device \
+// RUN:   | FileCheck -check-prefix=HOST %s
+// RUN: %clang_cc1 -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -fhip-lambda-host-device -triple amdgcn-amd-amdhsa -fcuda-is-device \
+// RUN:   | FileCheck -check-prefix=DEV %s
+
+#include "Inputs/cuda.h"
+
+// Device side kernel name.
+// HOST: @[[KERN_CAPTURE:[0-9]+]] = {{.*}} c"_Z1gIZ12test_capturevEUlvE_EvT_\00"
+// HOST: @[[KERN_RESOLVE:[0-9]+]] = {{.*}} c"_Z1gIZ12test_resolvevEUlvE_EvT_\00"
+
+// Check functions emitted for test_capture in host compilation.
+// Check lambda is not emitted in host compilation.
+// HOST-LABEL: define void @_Z12test_capturev
+// HOST:  call void @_Z19test_capture_helperIZ12test_capturevEUlvE_EvT_
+// HOST-LABEL: define internal void @_Z19test_capture_helperIZ12test_capturevEUlvE_EvT_
+// HOST:  call void @_Z16__device_stub__gIZ12test_capturevEUlvE_EvT_
+// HOST-NOT: define{{.*}}@_ZZ4mainENKUlvE_clEv
+
+// Check functions emitted for test_resolve in host compilation.
+// Check host version of template function 'overloaded' is emitted and call

[PATCH] D79320: [clang-format [PR45791] BeforeLambdaBody is confused by comment inside lambda

2020-05-04 Thread Francois JEAN via Phabricator via cfe-commits
Wawha accepted this revision.
Wawha added a comment.
This revision is now accepted and ready to land.

Thanks for the patch !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79320



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


[PATCH] D73307: Unique Names for Functions with Internal Linkage

2020-05-04 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram added a comment.

@rnk Ping.


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

https://reviews.llvm.org/D73307



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


[PATCH] D78655: [HIP] Add -fhip-lambda-host-device

2020-05-04 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.

LGTM. Thank you for adding the checks for capturing lambdas and for putting 
this behind the flag.
I've asked @rsmith  to chime in in case there's anything else about the lambdas 
we need to deal with. Please wait a day or two before landing the patch to give 
him a chance to reply.




Comment at: clang/test/SemaCUDA/lambda.cu:25-35
+  kernel<<<1,1>>>([&](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 
'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ 
function from __global__ function}}
+
+  kernel<<<1,1>>>([=, &b](){ hd(); });
+  // expected-note@-1 {{in instantiation of function template specialization 
'kernel<(lambda at}}
+  // expected-note@-2 {{candidate function not viable: call to __host__ 
function from __global__ function}}

We may need a better diagnostic for this. Here we've correctly rejected 
captured lambdas, but the diagnostic is a generic 'can't use that'.
If would be helpful to let user know that we can't use that because of the 
capturing lambdas.


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

https://reviews.llvm.org/D78655



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


[PATCH] D78827: Add support for #pragma clang fp reassociate(on|off) -- floating point control of associative math transformations

2020-05-04 Thread Melanie Blower via Phabricator via cfe-commits
mibintc marked 4 inline comments as done.
mibintc added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:186
+FPM_Fast
   };
 

rjmccall wrote:
> I'm not sure I think this fusion was an improvement; the net effect was to 
> remove a few lines from this header and make a bunch of switches 
> unnecessarily non-exhaustive.
I dropped the on/off enumeration and just using boolean, where needed, to show 
the setting, do you like this better? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78827



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


[PATCH] D78827: Add support for #pragma clang fp reassociate(on|off) -- floating point control of associative math transformations

2020-05-04 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 261875.
mibintc retitled this revision from "Add support for #pragma clang fp 
reassoc(on|off) -- floating point control of associative math transformations" 
to "Add support for #pragma clang fp reassociate(on|off) -- floating point 
control of associative math transformations".
mibintc added a comment.

Responded to @rjmccall 's review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78827

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/test/CodeGen/fp-reassoc-pragma.cpp
  clang/test/Parser/pragma-fp-contract.c
  clang/test/Parser/pragma-fp.cpp

Index: clang/test/Parser/pragma-fp.cpp
===
--- clang/test/Parser/pragma-fp.cpp
+++ clang/test/Parser/pragma-fp.cpp
@@ -1,14 +1,14 @@
 // RUN: %clang_cc1 -std=c++11 -verify %s
 
 void test_0(int *List, int Length) {
-/* expected-error@+1 {{missing option; expected contract}} */
+/* expected-error@+1 {{missing option; expected 'contract' or 'reassociate'}} */
 #pragma clang fp
   for (int i = 0; i < Length; i++) {
 List[i] = i;
   }
 }
 void test_1(int *List, int Length) {
-/* expected-error@+1 {{invalid option 'blah'; expected contract}} */
+/* expected-error@+1 {{invalid option 'blah'; expected 'contract' or 'reassociate'}} */
 #pragma clang fp blah
   for (int i = 0; i < Length; i++) {
 List[i] = i;
@@ -24,7 +24,7 @@
 }
 
 void test_4(int *List, int Length) {
-/* expected-error@+1 {{unexpected argument 'while' to '#pragma clang fp contract'; expected 'on', 'fast' or 'off'}} */
+/* expected-error@+1 {{unexpected argument 'while' to '#pragma clang fp contract'; expected 'fast' or 'on' or 'off'}} */
 #pragma clang fp contract(while)
   for (int i = 0; i < Length; i++) {
 List[i] = i;
@@ -32,7 +32,7 @@
 }
 
 void test_5(int *List, int Length) {
-/* expected-error@+1 {{unexpected argument 'maybe' to '#pragma clang fp contract'; expected 'on', 'fast' or 'off'}} */
+/* expected-error@+1 {{unexpected argument 'maybe' to '#pragma clang fp contract'; expected 'fast' or 'on' or 'off'}} */
 #pragma clang fp contract(maybe)
   for (int i = 0; i < Length; i++) {
 List[i] = i;
Index: clang/test/Parser/pragma-fp-contract.c
===
--- clang/test/Parser/pragma-fp-contract.c
+++ clang/test/Parser/pragma-fp-contract.c
@@ -23,3 +23,18 @@
 // expected-error@+1 {{this pragma cannot appear in union declaration}}
 #pragma STDC FP_CONTRACT ON
 };
+
+float fp_reassoc_fail(float a, float b) {
+  // CHECK-LABEL: fp_reassoc_fail
+  // expected-error@+2{{'#pragma clang fp' can only appear at file scope or at the start of a compound statement}}
+  float c = a + b;
+#pragma clang fp reassociate(on)
+  return c - b;
+}
+
+float fp_reassoc_no_fast(float a, float b) {
+// CHECK-LABEL: fp_reassoc_no_fast
+// expected-error@+1{{unexpected argument 'fast' to '#pragma clang fp reassociate'; expected 'on' or 'off'}}
+#pragma clang fp reassociate(fast)
+  return a - b;
+}
Index: clang/test/CodeGen/fp-reassoc-pragma.cpp
===
--- /dev/null
+++ clang/test/CodeGen/fp-reassoc-pragma.cpp
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
+// Simple case
+float fp_reassoc_simple(float a, float b, float c) {
+// CHECK: _Z17fp_reassoc_simplefff
+// CHECK: %[[M:.+]] = fmul reassoc float %a, %b
+// CHECK-NEXT: fadd reassoc float %[[M]], %c
+#pragma clang fp reassociate(on)
+  return a * b + c;
+}
+
+// Reassoc pragma should only apply to its scope
+float fp_reassoc_scoped(float a, float b, float c) {
+  // CHECK: _Z17fp_reassoc_scopedfff
+  // CHECK: %[[M:.+]] = fmul float %a, %b
+  // CHECK-NEXT: fadd float %[[M]], %c
+  {
+#pragma clang fp reassociate(on)
+  }
+  return a * b + c;
+}
+
+// Reassoc pragma should apply to templates as well
+class Foo {};
+Foo operator+(Foo, Foo);
+template 
+T template_reassoc(T a, T b, T c) {
+#pragma clang fp reassociate(on)
+  return ((a + b) - c) + c;
+}
+
+float fp_reassoc_template(float a, float b, float c) {
+  // CHECK: _Z19fp_reassoc_templatefff
+  // CHECK: %[[A1:.+]] = fadd reassoc float %a, %b
+  // CHECK-NEXT: %[[A2:.+]] = fsub reassoc float %[[A1]], %c
+  // CHECK-NEXT: fadd reassoc float %[[A2]], %c
+  return template_reassoc(a, b, c);
+}
+
+// File Scoping should work across functions
+#pragma clang fp reassociate(on)
+float fp_file_scope_on(float a, float b, float c) {
+  // CHECK: _Z16fp_file_scope_onfff
+  // CHECK: %[[M1:.+]] = fmul reassoc float %a, %c
+  // CHECK-NEXT: %[[M

[PATCH] D79343: [libc++][test] Adjust move_iterator tests to allow C++20

2020-05-04 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.
CaseyCarter added reviewers: ldionne, EricWF, mclow.lists.
Herald added subscribers: libcxx-commits, broadwaylamb, dexonsmith.
Herald added a project: libc++.
Herald added a reviewer: libc++.

These tests fail due to a couple of changes to `move_iterator` for C++20:

1. `move_iterator::operator++(int)` returns `void` in C++20 if `I` doesn't 
model `forward_iterator`.
2. `move_iterator::reference` is calculated in C++20, so `I` must actually 
have an `operator*() const`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79343

Files:
  
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
  
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp


Index: 
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
===
--- 
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
+++ 
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
@@ -30,11 +30,13 @@
 
 template 
 struct DummyIt {
-  typedef std::forward_iterator_tag iterator_category;
-  typedef ValueType value_type;
-  typedef std::ptrdiff_t difference_type;
-  typedef ValueType* pointer;
-  typedef Reference reference;
+typedef std::forward_iterator_tag iterator_category;
+typedef ValueType value_type;
+typedef std::ptrdiff_t difference_type;
+typedef ValueType* pointer;
+typedef Reference reference;
+
+Reference operator*() const;
 };
 
 template 
@@ -92,5 +94,5 @@
 }
 #endif
 
-  return 0;
+return 0;
 }
Index: 
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
===
--- 
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
+++ 
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
@@ -16,10 +16,22 @@
 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+template 
+void
+test_single_pass(It i, It x)
+{
+std::move_iterator r(std::move(i));
+r++;
+assert(std::move(r).base() == x);
+}
+#endif
+
 template 
 void
 test(It i, It x)
@@ -33,7 +45,11 @@
 int main(int, char**)
 {
 char s[] = "123";
+#if TEST_STD_VER > 17
+test_single_pass(input_iterator(s), input_iterator(s+1));
+#else
 test(input_iterator(s), input_iterator(s+1));
+#endif
 test(forward_iterator(s), forward_iterator(s+1));
 test(bidirectional_iterator(s), bidirectional_iterator(s+1));
 test(random_access_iterator(s), random_access_iterator(s+1));
@@ -52,5 +68,5 @@
 }
 #endif
 
-  return 0;
+return 0;
 }


Index: libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
===
--- libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
@@ -30,11 +30,13 @@
 
 template 
 struct DummyIt {
-  typedef std::forward_iterator_tag iterator_category;
-  typedef ValueType value_type;
-  typedef std::ptrdiff_t difference_type;
-  typedef ValueType* pointer;
-  typedef Reference reference;
+typedef std::forward_iterator_tag iterator_category;
+typedef ValueType value_type;
+typedef std::ptrdiff_t difference_type;
+typedef ValueType* pointer;
+typedef Reference reference;
+
+Reference operator*() const;
 };
 
 template 
@@ -92,5 +94,5 @@
 }
 #endif
 
-  return 0;
+return 0;
 }
Index: libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
===
--- libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
+++ libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
@@ -16,10 +16,22 @@
 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+template 
+void
+test_single_pass(It i, It x)
+{
+std::move_iterator r(std::move(i));
+r++;
+assert(std::move(r).base() == x);
+}
+#endif
+
 template 
 void
 test(It i, It x)
@@ -33,7 +45,11 @@
 int main(int, char**)
 {
 char s[] = "123";
+#if TEST_STD_VER > 17
+test_single_pass(input_iterator(s), input_iterator(s+1));
+#else
 test(input_iterator(s), input_iterator(s+1));
+#endif
 test(forward_iterator(s), forward_iterator(s+1));
 test(bidirectional_iterator(s), bidirectional_iterator(s+1));
 test(random_access_iterator(s), random_access_iterator(s+1));
@@ -52,5 +68,5 @@
 }
 #endif
 
-  return 0;
+

[PATCH] D79236: [docs] Regenerate DiagnosticsReference.rst

2020-05-04 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm abandoned this revision.
rsandifo-arm added a comment.

OK, I'll leave the file as-is in that case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79236



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


[PATCH] D54881: [clang-format] Prevent Clang-Format from editing leading whitespace on lines outside of the format range

2020-05-04 Thread Russell McClellan via Phabricator via cfe-commits
russellmcc added a comment.

Still waiting for feedback on this change!  We've been happily using this patch 
at my company for some time.


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

https://reviews.llvm.org/D54881



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


[clang] f01ac8c - A test commit as a new contributor to verify commit access is OK.

2020-05-04 Thread Denys Petrov via cfe-commits

Author: Denys Petrov
Date: 2020-05-04T21:36:18+03:00
New Revision: f01ac8c6574344e9bc30fdf9aa357a51bb607961

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

LOG: A test commit as a new contributor to verify commit access is OK.

Added: 


Modified: 
clang/test/Analysis/a_flaky_crash.cpp

Removed: 




diff  --git a/clang/test/Analysis/a_flaky_crash.cpp 
b/clang/test/Analysis/a_flaky_crash.cpp
index 04bd57883fce..f350c1e1280c 100644
--- a/clang/test/Analysis/a_flaky_crash.cpp
+++ b/clang/test/Analysis/a_flaky_crash.cpp
@@ -1,6 +1,6 @@
 // This code used to crash but unpredictably and rarely.
-// Even with the current set of run-lines, if a buildbot tells you that
-// you broke this test there's a chance that someone else broke it
+// Even with the current set of run-lines, if a buildbot tells you
+// that you broke this test there's a chance that someone else broke it
 // a few commits ago.
 
 struct S {



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


[PATCH] D78750: [SveEmitter] Add builtins for svdupq and svdupq_lane

2020-05-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D78750



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


[PATCH] D78756: [SveEmitter] Add builtins for svreinterpret

2020-05-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:7880
+return Builder.CreateBitCast(Val, Ty);
+  }
+

efriedma wrote:
> sdesmalen wrote:
> > efriedma wrote:
> > > sdesmalen wrote:
> > > > efriedma wrote:
> > > > > I'm vaguely suspicious this might be wrong for big-endian targets.  I 
> > > > > mean, this isn't unreasonable, but users might be surprised if 
> > > > > svreinterpret isn't a no-op.
> > > > For SVE the loads and stores (svld1 and svst1) are all endian safe, so 
> > > > no special consideration needs to be taken for big endian targets.
> > > > 
> > > > The ACLE specifies that:
> > > > > The svreinterpret functions simply reinterpret a vector of one type 
> > > > > as a vector of another type, without changing any of the bits.
> > > "bitcast" is specified to mean "reinterpret the bits like a store+load".  
> > > On big-endian NEON (and, I assume, SVE), that isn't a no-op.  See 
> > > http://llvm.org/docs/BigEndianNEON.html .
> > > 
> > > I mean, if the answer here is "yes, svreinterpret is supposed to lower to 
> > > a REV", then that's fine.  But I'd like to see some explciit 
> > > acknowledgement that that's intentional.
> > Thanks for pointing out that page, but for SVE I don't think the 
> > svreinterpret should lower to a REV.
> > 
> > This is probably where things are different from Neon. The ACLE SVE vectors 
> > such as `svint32_t` are opaque vector types and the only way to load/store 
> > them from/to memory is through the use of the svld1 and svst1 intrinsics 
> > which are endian safe (in that they use the ld1/st1 instructions that do 
> > endianess conversion on big endian targets). The ACLE does not expose any 
> > full-vector load/store (ldr/str) operations.
> Like that page describes, we use ld1/st1 for big-endian NEON, to match the 
> LLVM IR rules for laying out a vector.  If you use ld1/st1 to load/store 
> vectors on big-endian NEON, a bitcast is not a no-op.  As far as I know, SVE 
> ld1/st1 is equivalent to NEON ld1/st1 in the case where vscale=1.  Therefore, 
> on big-endian SVE, a bitcast is not a no-op.
> 
> That leaves the following options:
> 
> 1. svreinterpret is not a no-op.
> 2. svreinterpret is not equivalent to an LLVM IR bitcast, so this patch needs 
> to be changed.
(If you don't care about big-endian SVE right now, that's fine, but please at 
least leave a FIXME.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78756



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


[PATCH] D79236: [docs] Regenerate DiagnosticsReference.rst

2020-05-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D79236#2018190 , @rsandifo-arm 
wrote:

> OK, I'll leave the file as-is in that case.


I think it's preferable to commit the file in its updated state so that the 
public documentation is kept up to date rather than being left stale. However, 
we should also work to move this file to be built on demand like the attribute 
reference already is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79236



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


[PATCH] D79121: Add nomerge function attribute to clang

2020-05-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2755-2756
+def warn_nomerge_attribute_ignored_in_stmt: Warning<
+  "%0 attribute is ignored because there exists no call expression inside the "
+  "statement">;
 def err_nsobject_attribute : Error<

I think this should be in the `IgnoredAttributes` group as well.



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:173
+static bool hasCallExpr(Stmt *S) {
+  if (S->getStmtClass() == Stmt::CallExprClass)
+return true;

You'll need to check that `S` is nonnull, `children()` can return null children 
in some cases. Also, `S` should be a `const Stmt*` and I wouldn't mind a 
newline before the function definition.



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:175-179
+  for (Stmt *SubStmt : S->children()) {
+if (hasCallExpr(SubStmt))
+  return true;
+  }
+  return false;

I think you could replace this with: `llvm::any_of(S->children(), hasCallExpr);`



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:184
+   SourceRange Range) {
+  NoMergeAttr attribute(S.Context, A);
+  if (S.CheckAttrNoArgs(A))

`attribute` doesn't meet the usual naming conventions. Can probably just go 
with `NMA` or something lame like that.



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:189
+S.Diag(St->getBeginLoc(), diag::warn_nomerge_attribute_ignored_in_stmt)
+<< attribute.getSpelling();
+return nullptr;

You should be able to just pass `A` directly here instead.



Comment at: clang/test/CodeGen/attr-nomerge.cpp:6
+
+void foo(int i) {
+  [[clang::nomerge]] bar();

I'd appreciate seeing some more complex tests showing the behavior of the 
attribute. As some examples:
```
// Does this work on dynamically initialized global statics?
[[clang::nomerge]] static int i = foo() + bar();

void func() {
  // Is the lambda function call operator nomerge, the contained calls within 
the lambda, or none of the above?
  [[clang::nomerge]] [] { foo(); bar(); }(); 

  // Do we mark the implicit function calls to begin()/end() as nomerge?
  [[clang::nomerge]] for (auto foo : some_container) {}

  // Does it apply to builtins as well?
  [[clang::nomerge]] foo(__builtin_strlen("bar"), __builtin_strlen("bar"));

  // Does it apply to the substatement of a label?
  [[clang::nomerge]] how_about_this: f(bar(), bar());

  // Does it apply across the components of a for statement?
  for (foo(); bar(); baz()) {}
}
```


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

https://reviews.llvm.org/D79121



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


[PATCH] D78827: Add support for #pragma clang fp reassociate(on|off) -- floating point control of associative math transformations

2020-05-04 Thread Steve Canon via Phabricator via cfe-commits
scanon added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:3182
+enabled for the translation unit with the ``-fassociative-math`` flag.
+The pragma can take two values: ``on`` and ``off``.
+

rjmccall wrote:
> Do you want to add an example here?
Is the intention that this allows reassociation only within statements (like fp 
contract on)? Based on the ir in the tests, I think the answer is "no".

If so, should "on" be called "fast" instead, since its semantics match the 
"fast" semantics for contract, and reserve "on" for reassociation within a 
statement (that seems like it would also be useful, potentially)?

Otherwise, please add some tests with multiple statements.

I agree with John that `pragma clang fp reassociate` is a reasonable spelling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78827



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


[PATCH] D79344: [cuda] Start diagnosing variables with bad target.

2020-05-04 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
hliao added reviewers: tra, rjmccall, yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hliao added a comment.

That test code just passed compilation on clang trunk if only assembly code is 
generated, https://godbolt.org/z/XYjRcT. But NVCC generates errors on all cases.


- Non-local variables on the host side are generally not accessible from the 
device side. Without proper diagnostic messages, the compilation may pass until 
the final linking stage. That link error may not be intuitive enough for 
developers, especially for relocatable code compilation. For certain cases like 
assembly output only, it is even worse that the compilation just passes.
- This patch addresses that issue by checking the use of non-local variables 
and issuing errors on bad target references. For references through default 
argumennts, a warning is generated on the function declaration as, at that 
point, that variables are just bound. No real code would be generated if that 
function won't be used.
- The oppose direction, i.e. accessing device variables from the host side, is 
NOT addressed in this patch as the host code allows the access those device 
variables by using runtime interface on their shadow variables. It needs more 
support to identify how that variable is used on the host side for simple 
cases. The comprehensive diagnosing would be so expensive that alternative 
analysis tools like clang-tidy should be used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79344

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaInternal.h
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/function-overload.cu
  clang/test/SemaCUDA/variable-target.cu

Index: clang/test/SemaCUDA/variable-target.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/variable-target.cu
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcuda-is-device -verify %s
+
+#include "Inputs/cuda.h"
+
+static int gvar;
+// expected-note@-1{{'gvar' declared here}}
+// expected-note@-2{{'gvar' declared here}}
+// expected-note@-3{{'gvar' declared here}}
+// expected-note@-4{{'gvar' declared here}}
+// expected-note@-5{{'gvar' declared here}}
+// expected-note@-6{{'gvar' declared here}}
+
+__device__ int d0() {
+  // expected-error@+1{{reference to __host__ variable 'gvar' in __device__ function}}
+  return gvar;
+}
+__device__ int d1() {
+  // expected-error@+1{{reference to __host__ variable 'gvar' in __device__ function}}
+  return []() -> int { return gvar; }();
+}
+
+// expected-warning@+1{{reference to __host__ variable 'gvar' as default argument in __device__ function}}
+__device__ int d2(int arg = gvar) {
+  return arg;
+}
+__device__ int d3() {
+  // expected-error@+1{{reference to __host__ variable 'gvar' in __device__ function}}
+  return d2();
+}
+
+template
+__global__ void g0(F f) {
+  // expected-error@+1{{reference to __host__ variable 'gvar' in __global__ function}}
+  f();
+}
+int h0() {
+  // expected-warning@+1{{reference to __host__ variable 'gvar' as default argument in __device__ function}}
+  g0<<<1, 1>>>([] __device__(int arg = gvar) -> int { return arg; });
+  // expected-note-re@-1{{in instantiation of function template specialization 'g0<(lambda at {{.*}})>' requested here}}
+  return 0;
+}
Index: clang/test/CodeGenCUDA/function-overload.cu
===
--- clang/test/CodeGenCUDA/function-overload.cu
+++ clang/test/CodeGenCUDA/function-overload.cu
@@ -12,13 +12,15 @@
 #include "Inputs/cuda.h"
 
 // Check constructors/destructors for D/H functions
-int x;
+__device__ int x;
 struct s_cd_dh {
+// TODO: Need to generate warning on direct accesses on shadow variables.
   __host__ s_cd_dh() { x = 11; }
   __device__ s_cd_dh() { x = 12; }
 };
 
 struct s_cd_hd {
+// TODO: Need to generate warning on direct accesses on shadow variables.
   __host__ __device__ s_cd_hd() { x = 31; }
   __host__ __device__ ~s_cd_hd() { x = 32; }
 };
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -976,8 +976,6 @@
   startLambdaDefinition(Class, Intro.Range, MethodTyInfo, EndLoc, Params,
 ParamInfo.getDeclSpec().getConstexprSpecifier(),
 ParamInfo.getTrailingRequiresClause());
-  if (ExplicitParams)
-CheckCXXDefaultArguments(Method);
 
   // This represents the function body for the lambda function, check if we
   // have to apply optnone due to a pragma.
@@ -995,6 +993,10 @@
   if (getLangOpts().CUDA)
  

[PATCH] D77542: [PowerPC] Treat 'Z' inline asm constraint as a true memory constraint

2020-05-04 Thread Lei Huang via Phabricator via cfe-commits
lei accepted this revision as: lei.
lei 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/D77542/new/

https://reviews.llvm.org/D77542



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


[PATCH] D78827: Add support for #pragma clang fp reassociate(on|off) -- floating point control of associative math transformations

2020-05-04 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Just minor requests now.




Comment at: clang/docs/LanguageExtensions.rst:3177
+Both floating point reassociation and floating point contraction can be
+controlled with this pragma.
+``#pragma clang fp reassoc`` allows control over the reassociation

rjmccall wrote:
> Let's go ahead and word this as if arbitrary things will be controllable in 
> the future.  So:
> 
> > Currently, the following things can be controlled by this pragma:
Thanks.  Please put the first sentence in its own paragraph and end it with a 
colon so that it logically leads into both of the following blocks.



Comment at: clang/docs/LanguageExtensions.rst:3182
+enabled for the translation unit with the ``-fassociative-math`` flag.
+The pragma can take two values: ``on`` and ``off``.
+

Do you want to add an example here?



Comment at: clang/docs/LanguageExtensions.rst:3192
 in cases when the language standard does not make this possible (e.g. across
 statements in C)
 

Oh, and there's a missing period here.



Comment at: clang/include/clang/Basic/LangOptions.h:186
+FPM_Fast
   };
 

mibintc wrote:
> rjmccall wrote:
> > I'm not sure I think this fusion was an improvement; the net effect was to 
> > remove a few lines from this header and make a bunch of switches 
> > unnecessarily non-exhaustive.
> I dropped the on/off enumeration and just using boolean, where needed, to 
> show the setting, do you like this better? 
Yeah, thanks.



Comment at: clang/include/clang/Sema/Sema.h:9624
+  /// \#pragma clang fp reassociate
+  void ActOnPragmaFPAllowReassociation(bool IsEnabled);
 

Please name this the same as the language feature.



Comment at: clang/lib/Parse/ParsePragma.cpp:2900
   return;
 }
 PP.Lex(Tok);

Please make this a single block by making the condition something like `if 
(!FlagValue || (FlagKind == TokFPAnnotValue::Reassociate && FlagValue == 
TokFPAnnotValue::Fast))`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78827



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


[PATCH] D79344: [cuda] Start diagnosing variables with bad target.

2020-05-04 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

That test code just passed compilation on clang trunk if only assembly code is 
generated, https://godbolt.org/z/XYjRcT. But NVCC generates errors on all cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79344



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


[clang] 54fa46a - [SveEmitter] Add builtins for Int & FP reductions

2020-05-04 Thread Sander de Smalen via cfe-commits

Author: Sander de Smalen
Date: 2020-05-04T19:50:16+01:00
New Revision: 54fa46aa0a82bd281d0ba31fad69a227de4a622c

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

LOG: [SveEmitter] Add builtins for Int & FP reductions

This patch adds integer builtins for:
- svaddv, svandv, sveorv,
  svmaxv, svminv, svorv.

And FP builtins for:
- svadda, svaddv, svmaxv, svmaxnmv,
  svminv, svminnmv

Added: 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adda.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_addv.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_andv.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_eorv.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_maxnmv.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_maxv.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_minnmv.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_minv.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_orv.c

Modified: 
clang/include/clang/Basic/arm_sve.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 013357c3de9b..bde26aed43f6 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -705,6 +705,19 @@ defm SVLSR : SInst_SHIFT<"svlsr", "aarch64_sve_lsr", 
"UcUsUiUl", "UcUsUi">;
 
 def SVASRD_M : SInst<"svasrd[_n_{d}]", "dPdi", "csil",MergeOp1,  
"aarch64_sve_asrd", [], [ImmCheck<2, ImmCheckShiftRight, 1>]>;
 
+
+// Integer reductions
+
+def SVADDV_S : SInst<"svaddv[_{d}]", "lPd", "csil", MergeNone, 
"aarch64_sve_saddv">;
+def SVADDV_U : SInst<"svaddv[_{d}]", "nPd", "UcUsUiUl", MergeNone, 
"aarch64_sve_uaddv">;
+def SVANDV   : SInst<"svandv[_{d}]", "sPd", "csilUcUsUiUl", MergeNone, 
"aarch64_sve_andv">;
+def SVEORV   : SInst<"sveorv[_{d}]", "sPd", "csilUcUsUiUl", MergeNone, 
"aarch64_sve_eorv">;
+def SVMAXV_S : SInst<"svmaxv[_{d}]", "sPd", "csil", MergeNone, 
"aarch64_sve_smaxv">;
+def SVMAXV_U : SInst<"svmaxv[_{d}]", "sPd", "UcUsUiUl", MergeNone, 
"aarch64_sve_umaxv">;
+def SVMINV_S : SInst<"svminv[_{d}]", "sPd", "csil", MergeNone, 
"aarch64_sve_sminv">;
+def SVMINV_U : SInst<"svminv[_{d}]", "sPd", "UcUsUiUl", MergeNone, 
"aarch64_sve_uminv">;
+def SVORV: SInst<"svorv[_{d}]",  "sPd", "csilUcUsUiUl", MergeNone, 
"aarch64_sve_orv">;
+
 

 // Integer comparisons
 
@@ -876,6 +889,15 @@ def SVRECPS  : SInst<"svrecps[_{d}]",  "ddd", "hfd", 
MergeNone, "aarch64_sve_fre
 def SVRSQRTE : SInst<"svrsqrte[_{d}]", "dd",  "hfd", MergeNone, 
"aarch64_sve_frsqrte_x">;
 def SVRSQRTS : SInst<"svrsqrts[_{d}]", "ddd", "hfd", MergeNone, 
"aarch64_sve_frsqrts_x">;
 
+
+// Floating-point reductions
+
+def SVFADDA   : SInst<"svadda[_{d}]",   "sPsd", "hfd", MergeNone, 
"aarch64_sve_fadda">;
+def SVFADDV   : SInst<"svaddv[_{d}]",   "sPd",  "hfd", MergeNone, 
"aarch64_sve_faddv">;
+def SVFMAXV   : SInst<"svmaxv[_{d}]",   "sPd",  "hfd", MergeNone, 
"aarch64_sve_fmaxv">;
+def SVFMAXNMV : SInst<"svmaxnmv[_{d}]", "sPd",  "hfd", MergeNone, 
"aarch64_sve_fmaxnmv">;
+def SVFMINV   : SInst<"svminv[_{d}]",   "sPd",  "hfd", MergeNone, 
"aarch64_sve_fminv">;
+def SVFMINNMV : SInst<"svminnmv[_{d}]", "sPd",  "hfd", MergeNone, 
"aarch64_sve_fminnmv">;
 
 

 // Floating-point comparisons

diff  --git a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adda.c 
b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adda.c
new file mode 100644
index ..6ac6e5d0d618
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adda.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns 
-S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+float16_t test_svadda_f16(svbool_t pg, float16_t initial, svfloat16_t op)
+{
+  // CHECK-LABEL: test_svadda_f16
+  // CHECK: %[[PG:.*]] = call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( %pg)
+  // CHECK: %[[INTRINSIC:.*]] = call half

[PATCH] D79113: Revert "Remove false positive in AvoidNonConstGlobalVariables."

2020-05-04 Thread Kim Viggedal via Phabricator via cfe-commits
vingeldal added a comment.

In D79113#2016294 , @aaron.ballman 
wrote:

> I only see a comment on the issue, but not that the issue was resolved in 
> favor of that comment (unless I've missed something). If the issue gets 
> resolved in the direction that comment is going, then the revert makes sense 
> (though we should add an explicit test case showing that we want the 
> diagnostic).


No, your not missing anything. The issue isn't actually closed yet. I'll 
remember to update tests as appropriate if the issue is resolved in favor of 
this revert. Until the issue is resolved I'll just wait.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79113



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


[PATCH] D78827: Add support for #pragma clang fp reassociate(on|off) -- floating point control of associative math transformations

2020-05-04 Thread Melanie Blower via Phabricator via cfe-commits
mibintc marked an inline comment as done.
mibintc added a comment.

A reply to @scanon




Comment at: clang/docs/LanguageExtensions.rst:3182
+enabled for the translation unit with the ``-fassociative-math`` flag.
+The pragma can take two values: ``on`` and ``off``.
+

scanon wrote:
> rjmccall wrote:
> > Do you want to add an example here?
> Is the intention that this allows reassociation only within statements (like 
> fp contract on)? Based on the ir in the tests, I think the answer is "no".
> 
> If so, should "on" be called "fast" instead, since its semantics match the 
> "fast" semantics for contract, and reserve "on" for reassociation within a 
> statement (that seems like it would also be useful, potentially)?
> 
> Otherwise, please add some tests with multiple statements.
> 
> I agree with John that `pragma clang fp reassociate` is a reasonable spelling.
The intention is that the pragma can be placed at either file scope or at the 
start of a compound statement, if at file scope it affects the functions 
following the pragma.  If at compound statement it is effective for the 
compound statement, i can modify the test to have multiple statements.  I 
disagree with the suggestion of "fast" instead of on/off.  at the command line 
you can use -f[no-]associative-math; of course that command line option isn't 
specific to floating point, but the point is it's on/off ; i can't speak to 
whether "fast" would be a useful setting.  Thanks for your review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78827



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


[PATCH] D78756: [SveEmitter] Add builtins for svreinterpret

2020-05-04 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 261892.
sdesmalen added a comment.

- Added FIXME in CGBuiltins for big-endian svreinterpret.
- Added diagnostic in arm_sve.h that big-endian is not yet supported.


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

https://reviews.llvm.org/D78756

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret.c
  clang/test/CodeGen/aarch64-sve-intrinsics/negative/big_endian.c
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -237,6 +237,23 @@
 
 class SVEEmitter {
 private:
+  // The reinterpret builtins are generated separately because they
+  // need the cross product of all types (121 functions in total),
+  // which is inconvenient to specify in the arm_sve.td file or
+  // generate in CGBuiltin.cpp.
+  struct ReinterpretTypeInfo {
+const char *Suffix;
+const char *Type;
+const char *BuiltinType;
+  };
+  SmallVector Reinterprets = {
+  {"s8", "svint8_t", "q16Sc"},   {"s16", "svint16_t", "q8Ss"},
+  {"s32", "svint32_t", "q4Si"},  {"s64", "svint64_t", "q2SWi"},
+  {"u8", "svuint8_t", "q16Uc"},  {"u16", "svuint16_t", "q8Us"},
+  {"u32", "svuint32_t", "q4Ui"}, {"u64", "svuint64_t", "q2UWi"},
+  {"f16", "svfloat16_t", "q8h"}, {"f32", "svfloat32_t", "q4f"},
+  {"f64", "svfloat64_t", "q2d"}};
+
   RecordKeeper &Records;
   llvm::StringMap EltTypes;
   llvm::StringMap MemEltTypes;
@@ -1008,6 +1025,10 @@
   OS << "#error \"SVE support not enabled\"\n";
   OS << "#else\n\n";
 
+  OS << "#if !defined(__LITTLE_ENDIAN__)\n";
+  OS << "#error \"Big endian is currently not supported for arm_sve.h\"\n";
+  OS << "#endif\n";
+
   OS << "#include \n\n";
   OS << "#ifdef  __cplusplus\n";
   OS << "extern \"C\" {\n";
@@ -1074,6 +1095,22 @@
   OS << "#define __aio static inline __attribute__((__always_inline__, "
 "__nodebug__, __overloadable__))\n\n";
 
+  // Add reinterpret functions.
+  for (auto ShortForm : { false, true } )
+for (const ReinterpretTypeInfo &From : Reinterprets)
+  for (const ReinterpretTypeInfo &To : Reinterprets) {
+if (ShortForm) {
+  OS << "__aio " << From.Type << " svreinterpret_" << From.Suffix;
+  OS << "(" << To.Type << " op) {\n";
+  OS << "  return __builtin_sve_reinterpret_" << From.Suffix << "_"
+ << To.Suffix << "(op);\n";
+  OS << "}\n\n";
+} else
+  OS << "#define svreinterpret_" << From.Suffix << "_" << To.Suffix
+ << "(...) __builtin_sve_reinterpret_" << From.Suffix << "_"
+ << To.Suffix << "(__VA_ARGS__)\n";
+  }
+
   SmallVector, 128> Defs;
   std::vector RV = Records.getAllDerivedDefinitions("Inst");
   for (auto *R : RV)
@@ -1148,8 +1185,16 @@
   OS << "BUILTIN(__builtin_sve_" << Def->getMangledName() << ", \""
  << Def->getBuiltinTypeStr() << "\", \"n\")\n";
   }
+
+  // Add reinterpret builtins
+  for (const ReinterpretTypeInfo &From : Reinterprets)
+for (const ReinterpretTypeInfo &To : Reinterprets)
+  OS << "BUILTIN(__builtin_sve_reinterpret_" << From.Suffix << "_"
+ << To.Suffix << +", \"" << From.BuiltinType << To.BuiltinType
+ << "\", \"n\")\n";
+
   OS << "#endif\n\n";
-}
+  }
 
 void SVEEmitter::createCodeGenMap(raw_ostream &OS) {
   std::vector RV = Records.getAllDerivedDefinitions("Inst");
Index: clang/test/CodeGen/aarch64-sve-intrinsics/negative/big_endian.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-intrinsics/negative/big_endian.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -triple aarch64_be-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -fsyntax-only -verify %s
+
+// expected-error@* {{Big endian is currently not supported for arm_sve.h}}
+#include 
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret.c
@@ -0,0 +1,960 @@
+// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+svint8_t test_svreinterpret_s8_s8(svint8_t op)
+{
+  // CHECK-LABEL: test_svreinterpret_s8_s8

[PATCH] D79354: [clang-format] [PR34574] Handle [[nodiscard]] attribute in class declaration

2020-05-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: krasimir, sammccall, marejde, mitchell-stellar.
MyDeveloperDay added projects: clang, clang-format.

https://bugs.llvm.org/show_bug.cgi?id=34574
https://bugs.llvm.org/show_bug.cgi?id=38401

  template 
  class [[nodiscard]] result
  {
public:
  result(T&&)
  {
  }
  };

formats incorrectly to

  template 
  class [[nodiscard]] result{public : result(T &&){}};


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79354

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7636,6 +7636,10 @@
   verifyFormat("void f() [[deprecated(\"so sorry\")]];");
   verifyFormat("aa\n"
"[[unused]] aaa(int i);");
+  verifyFormat("[[nodiscard]] bool f() { return false; }");
+  verifyFormat("class [[nodiscard]] f {\npublic:\n  f() {}\n}");
+  verifyFormat("class [[deprecated(\"so sorry\")]] f {\npublic:\n  f() {}\n}");
+  verifyFormat("class [[gnu::unused]] f {\npublic:\n  f() {}\n}");
 
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2401,10 +2401,14 @@
   // it is often token-pasted.
   while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash,
 tok::kw___attribute, tok::kw___declspec,
-tok::kw_alignas) ||
+tok::kw_alignas, tok::l_square) ||
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+
+if (FormatTok->is(tok::l_square)) {
+  parseSquare();
+}
 if (Style.Language == FormatStyle::LK_JavaScript &&
 FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
   // JavaScript/TypeScript supports inline object types in


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7636,6 +7636,10 @@
   verifyFormat("void f() [[deprecated(\"so sorry\")]];");
   verifyFormat("aa\n"
"[[unused]] aaa(int i);");
+  verifyFormat("[[nodiscard]] bool f() { return false; }");
+  verifyFormat("class [[nodiscard]] f {\npublic:\n  f() {}\n}");
+  verifyFormat("class [[deprecated(\"so sorry\")]] f {\npublic:\n  f() {}\n}");
+  verifyFormat("class [[gnu::unused]] f {\npublic:\n  f() {}\n}");
 
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2401,10 +2401,14 @@
   // it is often token-pasted.
   while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash,
 tok::kw___attribute, tok::kw___declspec,
-tok::kw_alignas) ||
+tok::kw_alignas, tok::l_square) ||
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+
+if (FormatTok->is(tok::l_square)) {
+  parseSquare();
+}
 if (Style.Language == FormatStyle::LK_JavaScript &&
 FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
   // JavaScript/TypeScript supports inline object types in
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >