[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

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

> I also see that the typedef constitutes a `DeclStmt` in the AST. Can we 
> include that in the CFG as well? In the static analyzer that'll be the place 
> where we actually start tracking that typedef, because without it the size 
> expression value will be quickly cleaned up.

This is the point where I am not sure, how to add the `DeclStmt` itself? Simply 
call `addStmt` or call `autoCreateBlock` and `appendStmt` as it is done later 
in the function?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2020-04-16 Thread Thibault North via Phabricator via cfe-commits
tnorth updated this revision to Diff 257970.
tnorth added a comment.

Sorry.


Repository:
  rC Clang

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

https://reviews.llvm.org/D72326

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15204,6 +15204,61 @@
   auto StyleTd = getStyle("file", "x.td", "llvm", "", &FS);
   ASSERT_TRUE((bool)StyleTd);
   ASSERT_EQ(*StyleTd, getLLVMStyle(FormatStyle::LK_TableGen));
+
+  // Test 9: explicit format file in parent directory.
+  ASSERT_TRUE(
+  FS.addFile("/e/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: LLVM")));
+  ASSERT_TRUE(
+  FS.addFile("/e/explicit.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google")));
+  ASSERT_TRUE(FS.addFile("/e/sub/sub/sub/test.cpp", 0,
+ llvm::MemoryBuffer::getMemBuffer("int i;")));
+  auto Style8 = getStyle("file:/e/explicit.clang-format",
+ "/e/sub/sub/sub/test.cpp", "LLVM", "", &FS);
+  ASSERT_TRUE((bool)Style8);
+  ASSERT_EQ(*Style8, getGoogleStyle());
+
+  // Test 10: relative pah to a format file
+  ASSERT_TRUE(
+  FS.addFile("../../e/explicit.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google")));
+  auto Style9 = getStyle("file:../../e/explicit.clang-format",
+ "/e/sub/sub/sub/test.cpp", "LLVM", "", &FS);
+  ASSERT_TRUE((bool)Style9);
+  ASSERT_EQ(*Style9, getGoogleStyle());
+
+  // Test 11: missing explicit format file
+  auto Style10 = getStyle("file:/e/missing.clang-format",
+  "/e/sub/sub/sub/test.cpp", "LLVM", "", &FS);
+  ASSERT_FALSE((bool)Style10);
+  llvm::consumeError(Style10.takeError());
+
+  // Test 12: format file from the filesystem
+  SmallString<128> FormatFilePath;
+  std::error_code ECF = llvm::sys::fs::createTemporaryFile(
+  "FormatFileTest", "tpl", FormatFilePath);
+  EXPECT_FALSE((bool)ECF);
+  llvm::raw_fd_ostream FormatFileTest(FormatFilePath, ECF);
+  EXPECT_FALSE((bool)ECF);
+  FormatFileTest << "BasedOnStyle: Google\n";
+  FormatFileTest.close();
+
+  SmallString<128> TestFilePath;
+  std::error_code ECT =
+  llvm::sys::fs::createTemporaryFile("CodeFileTest", "cc", TestFilePath);
+  EXPECT_FALSE((bool)ECT);
+  llvm::raw_fd_ostream CodeFileTest(TestFilePath, ECT);
+  CodeFileTest << "int i;\n";
+  CodeFileTest.close();
+
+  std::string format_file_arg = std::string("file:") + FormatFilePath.c_str();
+  auto Style11 = getStyle(format_file_arg, TestFilePath, "LLVM", "", nullptr);
+
+  llvm::sys::fs::remove(FormatFilePath.c_str());
+  llvm::sys::fs::remove(TestFilePath.c_str());
+  ASSERT_TRUE((bool)Style11);
+  ASSERT_EQ(*Style11, getGoogleStyle());
 }
 
 TEST_F(ReplacementTest, FormatCodeAfterReplacements) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2640,6 +2640,8 @@
 ".clang-format file located in one of the parent\n"
 "directories of the source file (or current\n"
 "directory for stdin).\n"
+"Use -style=file: to explicitly specify"
+"the configuration file.\n"
 "Use -style=\"{key: value, ...}\" to set specific\n"
 "parameters, e.g.:\n"
 "  -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
@@ -2685,6 +2687,30 @@
   return GuessedLanguage;
 }
 
+/// Attempts to load a format file
+llvm::Expected LoadConfigFile(StringRef ConfigFile,
+   llvm::vfs::FileSystem *FS,
+   bool *IsSuitable) {
+  FormatStyle Style = getLLVMStyle();
+  *IsSuitable = false;
+
+  llvm::ErrorOr> Text =
+  FS->getBufferForFile(ConfigFile.str());
+  if (std::error_code EC = Text.getError())
+return make_string_error(EC.message());
+  std::error_code ParserErrorCode =
+  parseConfiguration(Text.get()->getBuffer(), &Style);
+  if (ParserErrorCode == ParseError::Unsuitable) {
+*IsSuitable = false;
+return Style;
+  } else if (ParserErrorCode != ParseError::Success) {
+return make_string_error("Error reading " + ConfigFile + ": " +
+ ParserErrorCode.message());
+  }
+  *IsSuitable = true;
+  return Style;
+}
+
 const char *DefaultFormatStyle = "file";
 
 const char *DefaultFallbackStyle = "LLVM";
@@ -2709,6 +2735,21 @@
 return Style;
   }
 
+  llvm::SmallVector FilesToLookFor;
+  // User provided clang-format file using -style=file:/path/to/format/file
+  // Check for explicit config filename
+  if (StyleName.startswith_lower("file:")) {
+

[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/lib/Analysis/CFG.cpp:2855
+
   VarDecl *VD = dyn_cast(DS->getSingleDecl());
 

Szelethus wrote:
> How about `using`? How about some other shenanigans that obscure the size of 
> the VLA? Can't we just retrieve the size from 
> `VariableArrayType::getSizeExpr` after seeing this `VarDecl`, and add that to 
> the block?
The current code does that, it gets the size with `getSizeExpr` and adds it. 
The loop is needed to support multiple array dimensions.

To support every other type that can contain VLA a similar code is needed as in 
`CodeGenFunction::EmitVariablyModifiedType` (go over the type chain and look 
not only for `VariableArrayType`). The current code works only if there is 
typedef (or type alias) with a plain VLA, maybe embedded into another.
If support for every other case is needed, it is a change on its own because 
the code that generates CFG for VLA declaration is wrong too (later in the same 
function, the new code is copied from that). For example `void (*vla)(int[x]);` 
does not work now (`x` is not included in CFG). This is better to do in a later 
patch, for now this more restricted functionality is better than nothing (it is 
not wrong, only do not support all, probably seldom used, cases).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


[PATCH] D77936: [Windows SEH] Fix abnormal-exits in _try

2020-04-16 Thread Ten Tzen via Phabricator via cfe-commits
tentzen updated this revision to Diff 257977.
tentzen added a comment.

remade a patch after re-sync


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77936

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/EHScopeStack.h
  clang/test/CodeGen/windows-seh-abnormal-exits.c

Index: clang/test/CodeGen/windows-seh-abnormal-exits.c
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-abnormal-exits.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fms-extensions -Wno-implicit-function-declaration -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: %[[src:[0-9-]+]] = call i8* @llvm.localaddress()
+// CHECK-NEXT: %cleanup.dest = load i32, i32* %cleanup.dest.slot, align 4
+// CHECK-NEXT: %[[src2:[0-9-]+]] = icmp ne i32 %cleanup.dest, 0
+// CHECK-NEXT: %[[src3:[0-9-]+]] = zext i1 %[[src2]] to i8
+// CHECK-NEXT: call void @"?fin$0@0@seh_abnormal_exits@@"(i8 %[[src3]], i8* %[[src]])
+
+void seh_abnormal_exits(int *Counter) {
+  for (int i = 0; i < 5; i++) {
+__try {
+  if (i == 0)
+continue;   // abnormal termination
+  else if (i == 1)
+goto t10;   // abnormal termination
+  else if (i == 2)
+__leave;  // normal execution
+  else if (i == 4)
+return;  // abnormal termination
+}
+__finally {
+  if (AbnormalTermination()) {
+*Counter += 1;
+  }
+}
+  t10:;
+  }
+  return; // *Counter == 3
+}
+
Index: clang/lib/CodeGen/EHScopeStack.h
===
--- clang/lib/CodeGen/EHScopeStack.h
+++ clang/lib/CodeGen/EHScopeStack.h
@@ -158,9 +158,10 @@
 /// Generation flags.
 class Flags {
   enum {
-F_IsForEH = 0x1,
+F_IsForEH = 0x1,
 F_IsNormalCleanupKind = 0x2,
-F_IsEHCleanupKind = 0x4
+F_IsEHCleanupKind = 0x4,
+F_HasExitSwitch = 0x8,
   };
   unsigned flags;
 
@@ -179,8 +180,10 @@
   /// cleanup.
   bool isEHCleanupKind() const { return flags & F_IsEHCleanupKind; }
   void setIsEHCleanupKind() { flags |= F_IsEHCleanupKind; }
-};
 
+  bool hasExitSwitch() const { return flags & F_HasExitSwitch; }
+  void setHasExitSwitch() { flags |= F_HasExitSwitch; }
+};
 
 /// Emit the cleanup.  For normal cleanups, this is run in the
 /// same EH context as when the cleanup was pushed, i.e. the
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -1639,6 +1639,19 @@
 
 llvm::Value *IsForEH =
 llvm::ConstantInt::get(CGF.ConvertType(ArgTys[0]), F.isForEHCleanup());
+
+// Except _leave and fall-through at the end, all other exits in a _try
+//   (return/goto/continue/break) are considered as abnormal terminations
+//   since _leave/fall-through is always Indexed 0,
+//   just use NormalCleanupDestSlot (>= 1 for goto/return/..),
+//   as 1st Arg to indicate abnormal termination
+if (!F.isForEHCleanup() && F.hasExitSwitch()) {
+  Address Addr = CGF.getNormalCleanupDestSlot();
+  llvm::Value *Load = CGF.Builder.CreateLoad(Addr, "cleanup.dest");
+  llvm::Value *Zero = llvm::Constant::getNullValue(CGM.Int32Ty);
+  IsForEH = CGF.Builder.CreateICmpNE(Load, Zero);
+}
+
 Args.add(RValue::get(IsForEH), ArgTys[0]);
 Args.add(RValue::get(FP), ArgTys[1]);
 
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -860,6 +860,9 @@
 // TODO: base this on the number of branch-afters and fixups
 const unsigned SwitchCapacity = 10;
 
+// pass the abnormal exit flag to Fn (SEH cleanup)
+cleanupFlags.setHasExitSwitch();
+
 llvm::LoadInst *Load =
   createLoadInstBefore(getNormalCleanupDestSlot(), "cleanup.dest",
nullptr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77880: get scan-view executable from environment

2020-04-16 Thread Oliver Tušla via Phabricator via cfe-commits
asmar added a comment.

Rather than globbing I would check whether there's a `scan-view` directory with 
the same version suffix as in the `scan-build`'s one. Getting "random" version 
from other directories doesn't seem transparent to me. When this fails, `which` 
for the system version is expected behaviour I suppose.

I believe that Perl error is sufficient. It emits the correct error code, helps 
to spot the root of the error right away and custom error will not have any 
other benefits.

I am not sure about reporting `$PATH` though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77880



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


[PATCH] D78280: [Analyzer][StreamChecker] Track streams that were not found to be opened.

2020-04-16 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.

If a stream operation is encountered with unknown stream (to the checker)
the stream is recognized and added to the data structure.
(Instead of ignoring the call.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78280

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

Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -8,30 +8,50 @@
   fclose(fp);
 }
 
+void check_feread_noopen(FILE *fp) {
+  fread(0, 0, 0, fp);
+}
+
 void check_fwrite() {
   FILE *fp = tmpfile();
   fwrite(0, 0, 0, fp); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_fwrite_noopen(FILE *fp) {
+  fwrite(0, 0, 0, fp);
+}
+
 void check_fseek() {
   FILE *fp = tmpfile();
   fseek(fp, 0, 0); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_fseek_noopen(FILE *fp) {
+  fseek(fp, 0, 0);
+}
+
 void check_ftell() {
   FILE *fp = tmpfile();
   ftell(fp); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_ftell_noopen(FILE *fp) {
+  ftell(fp);
+}
+
 void check_rewind() {
   FILE *fp = tmpfile();
   rewind(fp); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_rewind_noopen(FILE *fp) {
+  rewind(fp);
+}
+
 void check_fgetpos() {
   FILE *fp = tmpfile();
   fpos_t pos;
@@ -39,6 +59,11 @@
   fclose(fp);
 }
 
+void check_fgetpos_noopen(FILE *fp) {
+  fpos_t pos;
+  fgetpos(fp, &pos);
+}
+
 void check_fsetpos() {
   FILE *fp = tmpfile();
   fpos_t pos;
@@ -46,30 +71,51 @@
   fclose(fp);
 }
 
+void check_fsetpos_noopen(FILE *fp) {
+  fpos_t pos;
+  fsetpos(fp, &pos);
+}
+
 void check_clearerr() {
   FILE *fp = tmpfile();
   clearerr(fp); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_clearerr_noopen(FILE *fp) {
+  clearerr(fp);
+}
+
 void check_feof() {
   FILE *fp = tmpfile();
   feof(fp); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_feof_noopen(FILE *fp) {
+  feof(fp);
+}
+
 void check_ferror() {
   FILE *fp = tmpfile();
   ferror(fp); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_ferror_noopen(FILE *fp) {
+  ferror(fp);
+}
+
 void check_fileno() {
   FILE *fp = tmpfile();
   fileno(fp); // expected-warning {{Stream pointer might be NULL}}
   fclose(fp);
 }
 
+void check_fileno_noopen(FILE *fp) {
+  fileno(fp);
+}
+
 void f_open(void) {
   FILE *p = fopen("foo", "r");
   char buf[1024];
Index: clang/test/Analysis/stream-error.c
===
--- clang/test/Analysis/stream-error.c
+++ clang/test/Analysis/stream-error.c
@@ -3,6 +3,7 @@
 #include "Inputs/system-header-simulator.h"
 
 void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
 void StreamTesterChecker_make_feof_stream(FILE *);
 void StreamTesterChecker_make_ferror_stream(FILE *);
 
@@ -15,16 +16,12 @@
   fclose(F);
 }
 
-void error_freopen() {
-  FILE *F = fopen("file", "r");
-  if (!F)
-return;
+void error_freopen(FILE *F) {
   F = freopen(0, "w", F);
   if (!F)
 return;
   clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
   clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
-  fclose(F);
 }
 
 void stream_error_feof() {
@@ -40,6 +37,15 @@
   fclose(F);
 }
 
+void stream_error_feof_noopen(FILE *F) {
+  if (feof(F))
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  else if (ferror(F))
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
 void stream_error_ferror() {
   FILE *F = fopen("file", "r");
   if (!F)
@@ -53,10 +59,16 @@
   fclose(F);
 }
 
-void error_fseek() {
-  FILE *F = fopen("file", "r");
-  if (!F)
-return;
+void stream_error_ferror_noopen(FILE *F) {
+  if (ferror(F))
+clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+  else if (feof(F))
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void error_fseek(FILE *F) {
   int rc = fseek(F, 0, SEEK_SET);
   if (rc) {
 int IsFEof = feof(F), IsFError = ferror(F);
@@ -81,5 +93,4 @@
 clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
 clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
   }
-  fclose(F);
 }
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
=

[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Awesome, ship it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794



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


[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-04-16 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 257985.
gamesh411 marked an inline comment as done.
gamesh411 added a comment.

Rebase and update the number of analyzer options


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/CrossTU/CMakeLists.txt
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/Inputs/ctu-other.c
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/ctu-different-triples.cpp
  clang/test/Analysis/ctu-main.c
  clang/test/Analysis/ctu-main.cpp
  clang/test/Analysis/ctu-on-demand-parsing.c
  clang/test/Analysis/ctu-on-demand-parsing.cpp
  clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -7,10 +7,11 @@
 //===--===//
 
 #include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/Frontend/CompilerInstance.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ToolOutputFile.h"
@@ -162,7 +163,7 @@
   IndexFile.os().flush();
   EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
   llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "");
+  parseCrossTUIndex(IndexFileName);
   EXPECT_TRUE((bool)IndexOrErr);
   llvm::StringMap ParsedIndex = IndexOrErr.get();
   for (const auto &E : Index) {
@@ -173,25 +174,5 @@
 EXPECT_TRUE(Index.count(E.getKey()));
 }
 
-TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
-  llvm::StringMap Index;
-  Index["a"] = "/b/c/d";
-  std::string IndexText = createCrossTUIndexString(Index);
-
-  int IndexFD;
-  llvm::SmallString<256> IndexFileName;
-  ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
-  IndexFileName));
-  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
-  IndexFile.os() << IndexText;
-  IndexFile.os().flush();
-  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "/ctudir");
-  EXPECT_TRUE((bool)IndexOrErr);
-  llvm::StringMap ParsedIndex = IndexOrErr.get();
-  EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
-}
-
 } // end namespace cross_tu
 } // end namespace clang
Index: clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
===
--- clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
+++ clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
@@ -5,7 +5,7 @@
 // RUN: mkdir -p %t/ctudir
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
 // RUN:   -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
-// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.txt %t/ctudir/externalDefMap.txt
+// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-linux-gnu \
 // RUN:   -analyzer-checker=core,debug.ExprInspection \
 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
Index: clang/test/Analysis/ctu-on-demand-parsing.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-on-demand-parsing.cpp
@@ -0,0 +1,102 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/ctudir
+// RUN: cp %s %t/ctu-on-demand-parsing.cpp
+// RUN: cp %S/ctu-hdr.h %t/ctu-hdr.h
+// RUN: cp %S/Inputs/ctu-chain.cpp %t/ctudir/ctu-chain.cpp
+// RUN: cp %S/Inputs/ctu-other.cpp %t/ctudir/ctu-other.cpp
+// Path substitutions on Windows platform could contain backslashes. These are escaped in the json file.
+// RUN: echo '[{"directory":"%t/ctudir","command":"clang++ -c ctu-chain.cpp","file":"ctu-chain.cpp"},{"directory":"%t/ctudir","command":"clang++ -c ctu-other.cpp","file":"ctu-other.cpp"}]' | sed -e 's/\\//g' > %t/compile_commands.json
+// RUN: cd "%t/ctudir" && %clang_extdef_map ctu-chain.cpp ctu-other.cpp > externalDefMap.txt
+// RUN: cd "%t" && %clang_analyze_cc1 -triple x86_64-pc-linux-gn

[PATCH] D78162: [CodeGen] Mark inline definitions of builtins as nobuiltin only if we plan to emit them.

2020-04-16 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

This triggers failed asserts:

  $ cat dcpdecrypt.cpp
  extern "C" __inline__ __attribute__((__gnu_inline__)) void *
  memcpy(void *, const void *, unsigned) {}
  void *memcpy(void *, const void *, unsigned);
  void a() { memcpy; }
  $ clang++ -c dcpdecrypt.cpp -target i686-linux-gnu
  clang++: ../tools/clang/lib/AST/Decl.cpp:3436: bool 
clang::FunctionDecl::isInlineDefinitionExternallyVisible() const: Assertion 
`(doesThisDeclarationHaveABody() || willHaveBody() || hasAttr()) && 
"Must be
  a function definition"' failed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78162



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


[PATCH] D75479: [clangd] go-to-def on names in comments etc that are used nearby.

2020-04-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 257989.
sammccall added a comment.

rebase - finally getting back to this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75479

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  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
@@ -985,6 +985,88 @@
   ElementsAre(Sym("foo", FooWithoutHeader.range(;
 }
 
+TEST(LocateSymbol, NearbyTokenSmoke) {
+  auto T = Annotations(R"cpp(
+// prints e^rr and crashes
+void die(const char* [[err]]);
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  // We don't pass an index, so can't hit index-based fallback.
+  EXPECT_THAT(locateSymbolAt(AST, T.point()),
+  ElementsAre(Sym("err", T.range(;
+}
+
+TEST(LocateSymbol, NearbyIdentifier) {
+  const char *Tests[] = {
+  R"cpp(
+  // regular identifiers (won't trigger)
+  int hello;
+  int y = he^llo;
+)cpp",
+  R"cpp(
+  // disabled preprocessor sections
+  int [[hello]];
+  #if 0
+  int y = ^hello;
+  #endif
+)cpp",
+  R"cpp(
+  // comments
+  // he^llo, world
+  int [[hello]];
+)cpp",
+  R"cpp(
+  // string literals
+  int [[hello]];
+  const char* greeting = "h^ello, world";
+)cpp",
+
+  R"cpp(
+  // can refer to macro invocations (even if they expand to nothing)
+  #define INT int
+  [[INT]] x;
+  // I^NT
+)cpp",
+
+  R"cpp(
+  // prefer nearest occurrence
+  int hello;
+  int x = hello;
+  // h^ello
+  int y = [[hello]];
+  int z = hello;
+)cpp",
+
+  R"cpp(
+  // short identifiers find near results
+  int [[hi]];
+  // h^i
+)cpp",
+  R"cpp(
+  // short identifiers don't find far results
+  int hi;
+
+
+
+  // h^i
+)cpp",
+  };
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto AST = TestTU::withCode(T.code()).build();
+const auto &SM = AST.getSourceManager();
+llvm::Optional Nearby;
+if (const auto *Tok = findNearbyIdentifier(
+cantFail(sourceLocationInMainFile(SM, T.point())), AST.getTokens()))
+  Nearby = halfOpenToRange(SM, CharSourceRange::getCharRange(
+   Tok->location(), Tok->endLocation()));
+if (T.ranges().empty())
+  EXPECT_THAT(Nearby, Eq(llvm::None)) << Test;
+else
+  EXPECT_THAT(Nearby, T.range()) << Test;
+  }
+}
+
 TEST(FindReferences, WithinAST) {
   const char *Tests[] = {
   R"cpp(// Local variable
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -26,6 +26,10 @@
 #include 
 
 namespace clang {
+namespace syntax {
+class Token;
+class TokenBuffer;
+} // namespace syntax
 namespace clangd {
 class ParsedAST;
 
@@ -64,6 +68,13 @@
  SourceLocation Loc,
  const std::string &MainFilePath);
 
+// If SpellingLoc points at a "word" that does not correspond to an expanded
+// token (e.g. in a comment, a string, or a PP disabled region), then try to
+// find a close occurrence of that word that does.
+// (This is for internal use by locateSymbolAt, and is exposed for testing).
+const syntax::Token *findNearbyIdentifier(SourceLocation SpellingLoc,
+  const syntax::TokenBuffer &TB);
+
 /// Get all document links
 std::vector getDocumentLinks(ParsedAST &AST);
 
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -48,6 +48,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -315,6 +316,12 @@
   return Result;
 }
 
+bool tokenSpelledAt(SourceLocation SpellingLoc, const syntax::TokenBuffer &TB) {
+  auto ExpandedTokens = TB.expandedTokens(
+  TB.sourceManager().getMacroArgExpandedLocation(SpellingLoc));
+  return !ExpandedTokens.empty();
+}
+
 llvm::StringRef wordTouching(llvm::StringRef Code, unsigned Offset) {
   unsigned B = Offset, E = Offset;
   while (B > 0 && isIdentifierBody(Code[B - 1]))
@@ -481,6 +488,84 @@
   return Results;
 }
 
+const syntax::Token *findNearbyIdentifier(SourceLocation SpellingLoc,
+  const syntax::TokenBuffer &TB) {
+  const SourceManager &SM = TB.sourceManager();
+  auto Pos = SM.getDecomposedLoc(SpellingLoc)

[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

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



Comment at: clang/lib/Analysis/CFG.cpp:2855
+
   VarDecl *VD = dyn_cast(DS->getSingleDecl());
 

balazske wrote:
> Szelethus wrote:
> > How about `using`? How about some other shenanigans that obscure the size 
> > of the VLA? Can't we just retrieve the size from 
> > `VariableArrayType::getSizeExpr` after seeing this `VarDecl`, and add that 
> > to the block?
> The current code does that, it gets the size with `getSizeExpr` and adds it. 
> The loop is needed to support multiple array dimensions.
> 
> To support every other type that can contain VLA a similar code is needed as 
> in `CodeGenFunction::EmitVariablyModifiedType` (go over the type chain and 
> look not only for `VariableArrayType`). The current code works only if there 
> is typedef (or type alias) with a plain VLA, maybe embedded into another.
> If support for every other case is needed, it is a change on its own because 
> the code that generates CFG for VLA declaration is wrong too (later in the 
> same function, the new code is copied from that). For example `void 
> (*vla)(int[x]);` does not work now (`x` is not included in CFG). This is 
> better to do in a later patch, for now this more restricted functionality is 
> better than nothing (it is not wrong, only do not support all, probably 
> seldom used, cases).
I'd prefer to have some FIXME comments in this patch to document what is 
missing. Moreover, it would be great to have a test case for `void 
(*vla)(int[x]);` with a similar FIXME comment of the expected behavior. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


[PATCH] D78284: [AST] Fix an undefine behavior when creating an empty recovery expr.

2020-04-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

We forgot to initialize the NumExpr member in one of the constructors,
which leads crashes in preamble serialization.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78284

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/test/PCH/cxx-recovery-expr.cpp


Index: clang/test/PCH/cxx-recovery-expr.cpp
===
--- /dev/null
+++ clang/test/PCH/cxx-recovery-expr.cpp
@@ -0,0 +1,13 @@
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -frecovery-ast -fallow-pch-with-compiler-errors 
-o %t %s
+// RUN: %clang_cc1 -include-pch %t -fno-validate-pch -emit-llvm -o - %s
+
+#ifndef HEADER
+#define HEADER
+
+int func(int);
+int s = func();
+
+#else
+
+#endif
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4574,7 +4574,7 @@
 RecoveryExpr *RecoveryExpr::CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs) 
{
   void *Mem = Ctx.Allocate(totalSizeToAlloc(NumSubExprs),
alignof(RecoveryExpr));
-  return new (Mem) RecoveryExpr(EmptyShell());
+  return new (Mem) RecoveryExpr(EmptyShell(), NumSubExprs);
 }
 
 void OMPArrayShapingExpr::setDimensions(ArrayRef Dims) {
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -6034,7 +6034,8 @@
 private:
   RecoveryExpr(ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc,
ArrayRef SubExprs);
-  RecoveryExpr(EmptyShell Empty) : Expr(RecoveryExprClass, Empty) {}
+  RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
+  : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
 
   size_t numTrailingObjects(OverloadToken) const { return NumExprs; }
 


Index: clang/test/PCH/cxx-recovery-expr.cpp
===
--- /dev/null
+++ clang/test/PCH/cxx-recovery-expr.cpp
@@ -0,0 +1,13 @@
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -frecovery-ast -fallow-pch-with-compiler-errors -o %t %s
+// RUN: %clang_cc1 -include-pch %t -fno-validate-pch -emit-llvm -o - %s
+
+#ifndef HEADER
+#define HEADER
+
+int func(int);
+int s = func();
+
+#else
+
+#endif
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4574,7 +4574,7 @@
 RecoveryExpr *RecoveryExpr::CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs) {
   void *Mem = Ctx.Allocate(totalSizeToAlloc(NumSubExprs),
alignof(RecoveryExpr));
-  return new (Mem) RecoveryExpr(EmptyShell());
+  return new (Mem) RecoveryExpr(EmptyShell(), NumSubExprs);
 }
 
 void OMPArrayShapingExpr::setDimensions(ArrayRef Dims) {
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -6034,7 +6034,8 @@
 private:
   RecoveryExpr(ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc,
ArrayRef SubExprs);
-  RecoveryExpr(EmptyShell Empty) : Expr(RecoveryExprClass, Empty) {}
+  RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
+  : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
 
   size_t numTrailingObjects(OverloadToken) const { return NumExprs; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2020-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/Format.cpp:2704
+  if (ParserErrorCode == ParseError::Unsuitable) {
+*IsSuitable = false;
+return Style;

I think this isn't needed won't it already be false from line @2695


Repository:
  rC Clang

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

https://reviews.llvm.org/D72326



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


[clang] 7b9c6c1 - Also look for devtoolset-9 gcc toolchain

2020-04-16 Thread Benjamin Kramer via cfe-commits

Author: Stephan Dollberg
Date: 2020-04-16T11:17:39+02:00
New Revision: 7b9c6c16c33deb52e7081f94ad51e3910ca592c9

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

LOG: Also look for devtoolset-9 gcc toolchain

devtoolset-9 has been out for a while so also look for it.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index d20d62987589..0ea33fc20e86 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1977,6 +1977,7 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   // Non-Solaris is much simpler - most systems just go with "/usr".
   if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux) {
 // Yet, still look for RHEL devtoolsets.
+Prefixes.push_back("/opt/rh/devtoolset-9/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-8/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-6/root/usr");



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


[clang] 3ee1ec0 - LangOptions cannot depend on ASTContext, make it not use ASTContext directly

2020-04-16 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2020-04-16T11:46:35+02:00
New Revision: 3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf

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

LOG: LangOptions cannot depend on ASTContext, make it not use ASTContext 
directly

Fixes a layering violation introduced in 
2ba4e3a4598b165245c581c506a813cd4a7dce33.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Expr.cpp
clang/lib/Basic/LangOptions.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 1fdfe926eb71..fab84f6a6ecd 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3494,19 +3494,7 @@ class BinaryOperator : public Expr {
   /// allocated for the trailing objects when needed.
   BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
  QualType ResTy, ExprValueKind VK, ExprObjectKind OK,
- SourceLocation opLoc, FPOptions FPFeatures)
-  : Expr(BinaryOperatorClass, ResTy, VK, OK) {
-BinaryOperatorBits.Opc = opc;
-assert(!isCompoundAssignmentOp() &&
-   "Use CompoundAssignOperator for compound assignments");
-BinaryOperatorBits.OpLoc = opLoc;
-SubExprs[LHS] = lhs;
-SubExprs[RHS] = rhs;
-BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(Ctx);
-if (BinaryOperatorBits.HasFPFeatures)
-  *getTrailingFPFeatures() = FPFeatures;
-setDependence(computeDependence(this));
-  }
+ SourceLocation opLoc, FPOptions FPFeatures);
 
   /// Construct an empty binary operator.
   explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) 
{
@@ -3678,40 +3666,28 @@ class BinaryOperator : public Expr {
 
   // Get the FP features status of this operator. Only meaningful for
   // operations on floating point types.
-  FPOptions getFPFeatures(const ASTContext &C) const {
+  FPOptions getFPFeatures(const LangOptions &LO) const {
 if (BinaryOperatorBits.HasFPFeatures)
   return getStoredFPFeatures();
-return FPOptions::defaultWithoutTrailingStorage(C);
+return FPOptions::defaultWithoutTrailingStorage(LO);
   }
 
   // Get the FP contractability status of this operator. Only meaningful for
   // operations on floating point types.
-  bool isFPContractableWithinStatement(const ASTContext &C) const {
-return getFPFeatures(C).allowFPContractWithinStatement();
+  bool isFPContractableWithinStatement(const LangOptions &LO) const {
+return getFPFeatures(LO).allowFPContractWithinStatement();
   }
 
   // Get the FENV_ACCESS status of this operator. Only meaningful for
   // operations on floating point types.
-  bool isFEnvAccessOn(const ASTContext &C) const {
-return getFPFeatures(C).allowFEnvAccess();
+  bool isFEnvAccessOn(const LangOptions &LO) const {
+return getFPFeatures(LO).allowFEnvAccess();
   }
 
 protected:
   BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
  QualType ResTy, ExprValueKind VK, ExprObjectKind OK,
- SourceLocation opLoc, FPOptions FPFeatures, bool dead2)
-  : Expr(CompoundAssignOperatorClass, ResTy, VK, OK) {
-BinaryOperatorBits.Opc = opc;
-assert(isCompoundAssignmentOp() &&
-   "Use CompoundAssignOperator for compound assignments");
-BinaryOperatorBits.OpLoc = opLoc;
-SubExprs[LHS] = lhs;
-SubExprs[RHS] = rhs;
-BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(Ctx);
-if (BinaryOperatorBits.HasFPFeatures)
-  *getTrailingFPFeatures() = FPFeatures;
-setDependence(computeDependence(this));
-  }
+ SourceLocation opLoc, FPOptions FPFeatures, bool dead2);
 
   /// Construct an empty BinaryOperator, SC is CompoundAssignOperator.
   BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index c33f8bf8c8ef..76ddd7051fd3 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -27,8 +27,6 @@
 
 namespace clang {
 
-class ASTContext;
-
 /// Bitfields of LangOptions, split out from LangOptions in order to ensure 
that
 /// this large collection of bitfields is a trivial class type.
 class LangOptionsBase {
@@ -403,11 +401,11 @@ class FPOptions {
 
   /// Return the default value of FPOptions that's used when trailing
   /// storage isn't required.
-  static FPOptions defaultWithoutTrailingStorage(const ASTContext &C);
+  static FPOptions defaultWithoutTrailingStorage(c

[PATCH] D77420: Also look for devtoolset-9 gcc toolchain

2020-04-16 Thread Benjamin Kramer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7b9c6c16c33d: Also look for devtoolset-9 gcc toolchain 
(authored by stephan.dollberg, committed by bkramer).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77420

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1977,6 +1977,7 @@
   // Non-Solaris is much simpler - most systems just go with "/usr".
   if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux) {
 // Yet, still look for RHEL devtoolsets.
+Prefixes.push_back("/opt/rh/devtoolset-9/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-8/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-6/root/usr");


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1977,6 +1977,7 @@
   // Non-Solaris is much simpler - most systems just go with "/usr".
   if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux) {
 // Yet, still look for RHEL devtoolsets.
+Prefixes.push_back("/opt/rh/devtoolset-9/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-8/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
 Prefixes.push_back("/opt/rh/devtoolset-6/root/usr");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78286: [analyzer] Track runtime types represented by Obj-C Class objects

2020-04-16 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.

Objective-C Class objects can be used to do a dynamic dispatch on
class methods. The analyzer had a few places where we tried to overcome
the dynamic nature of it and still guess the actual function that
is being called. That was done mostly using some simple heuristics
covering the most widespread cases (e.g. [[self class] classmethod]).
This solution introduces a way to track types represented by Class
objects and work with that instead of direct AST matching.

rdar://problem/50739539


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78286

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/DynamicType.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/class-object-state-dump.m
  clang/test/Analysis/inlining/InlineObjCClassMethod.m
  clang/test/Analysis/inlining/ObjCDynTypePopagation.m
  clang/test/Analysis/inlining/ObjCDynTypePropagation.m
  clang/test/Analysis/retain-release-inline.m

Index: clang/test/Analysis/retain-release-inline.m
===
--- clang/test/Analysis/retain-release-inline.m
+++ clang/test/Analysis/retain-release-inline.m
@@ -13,6 +13,7 @@
 // It includes the basic definitions for the test cases below.
 //===--===//
 #define NULL 0
+#define nil ((id)0)
 typedef unsigned int __darwin_natural_t;
 typedef unsigned long uintptr_t;
 typedef unsigned int uint32_t;
@@ -21,14 +22,14 @@
 typedef signed long CFIndex;
 typedef CFIndex CFByteOrder;
 typedef struct {
-CFIndex location;
-CFIndex length;
+  CFIndex location;
+  CFIndex length;
 } CFRange;
 static __inline__ __attribute__((always_inline)) CFRange CFRangeMake(CFIndex loc, CFIndex len) {
-CFRange range;
-range.location = loc;
-range.length = len;
-return range;
+  CFRange range;
+  range.location = loc;
+  range.length = len;
+  return range;
 }
 typedef const void * CFTypeRef;
 typedef const struct __CFString * CFStringRef;
@@ -91,6 +92,7 @@
 - (BOOL)isEqual:(id)object;
 - (id)retain;
 - (oneway void)release;
+- (Class)class;
 - (id)autorelease;
 - (id)init;
 @end  @protocol NSCopying  - (id)copyWithZone:(NSZone *)zone;
@@ -100,6 +102,7 @@
 @interface NSObject  {}
 + (id)allocWithZone:(NSZone *)zone;
 + (id)alloc;
++ (Class)class;
 - (void)dealloc;
 @end
 @interface NSObject (NSCoderMethods)
@@ -481,3 +484,33 @@
   [self test_inline_tiny_when_reanalyzing];
 }
 @end
+
+// Original problem: rdar://problem/50739539
+@interface MyClassThatLeaksDuringInit : NSObject
+
++ (MyClassThatLeaksDuringInit *)getAnInstance1;
++ (MyClassThatLeaksDuringInit *)getAnInstance2;
+
+@end
+
+@implementation MyClassThatLeaksDuringInit
+
++ (MyClassThatLeaksDuringInit *)getAnInstance1 {
+  return [[[MyClassThatLeaksDuringInit alloc] init] autorelease]; // expected-warning{{leak}}
+}
+
++ (MyClassThatLeaksDuringInit *)getAnInstance2 {
+  return self class] alloc] init] autorelease]; // expected-warning{{leak}}
+}
+
+- (instancetype)init {
+  if (1) {
+return nil;
+  }
+
+  if (nil != (self = [super init])) {
+  }
+  return self;
+}
+
+@end
Index: clang/test/Analysis/inlining/ObjCDynTypePropagation.m
===
--- clang/test/Analysis/inlining/ObjCDynTypePropagation.m
+++ clang/test/Analysis/inlining/ObjCDynTypePropagation.m
@@ -7,68 +7,67 @@
 PublicSubClass2 *getObj();
 
 @implementation PublicParent
-- (int) getZeroOverridden {
-   return 1;
+- (int)getZeroOverridden {
+  return 1;
 }
-- (int) getZero {
-   return 0;
+- (int)getZero {
+  return 0;
 }
 @end
 
 @implementation PublicSubClass2
-- (int) getZeroOverridden {
-   return 0;
+- (int)getZeroOverridden {
+  return 0;
 }
 
 /* Test that we get the right type from call to alloc. */
-+ (void) testAllocSelf {
++ (void)testAllocSelf {
   id a = [self alloc];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-
-+ (void) testAllocClass {
++ (void)testAllocClass {
   id a = [PublicSubClass2 alloc];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-+ (void) testAllocSuperOverriden {
++ (void)testAllocSuperOverriden {
   id a = [super alloc];
   // Evaluates to 1 in the parent.
-  clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{FALSE}} 
+  clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{FALSE}}
 }
 
-+ (void) testAllocSuper {
++ (void)t

[clang] 61b9670 - [clang] Const correct ComputePreambleBounds

2020-04-16 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-04-16T12:10:40+02:00
New Revision: 61b96704564b121210a3b83107f7867c9f2d89b3

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

LOG: [clang] Const correct ComputePreambleBounds

Added: 


Modified: 
clang/include/clang/Frontend/PrecompiledPreamble.h
clang/lib/Frontend/PrecompiledPreamble.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/PrecompiledPreamble.h 
b/clang/include/clang/Frontend/PrecompiledPreamble.h
index 5ae77735576c..0d95ee683eee 100644
--- a/clang/include/clang/Frontend/PrecompiledPreamble.h
+++ b/clang/include/clang/Frontend/PrecompiledPreamble.h
@@ -38,7 +38,7 @@ class PCHContainerOperations;
 
 /// Runs lexer to compute suggested preamble bounds.
 PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts,
- llvm::MemoryBuffer *Buffer,
+ const llvm::MemoryBuffer *Buffer,
  unsigned MaxLines);
 
 class PreambleCallbacks;

diff  --git a/clang/lib/Frontend/PrecompiledPreamble.cpp 
b/clang/lib/Frontend/PrecompiledPreamble.cpp
index 3657ccf8ecea..442ad63cee0e 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -228,7 +228,7 @@ template  bool moveOnNoError(llvm::ErrorOr Val, 
T &Output) {
 } // namespace
 
 PreambleBounds clang::ComputePreambleBounds(const LangOptions &LangOpts,
-llvm::MemoryBuffer *Buffer,
+const llvm::MemoryBuffer *Buffer,
 unsigned MaxLines) {
   return Lexer::ComputePreamble(Buffer->getBuffer(), LangOpts, MaxLines);
 }



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


[PATCH] D78289: [analyzer] Stability improvements for IteratorModeling functions

2020-04-16 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: baloghadamsoftware, NoQ.
ASDenysPetrov added a project: clang.
Herald added subscribers: cfe-commits, martong, Charusso, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun.

Some functions paths may lead to crash.
Fixed ignoring check for nullptr before dereferencing.
Fixed using local variable outside the scope  through a pointer.
Fixed minor misspellings.

This patch covers a bug https://bugs.llvm.org/show_bug.cgi?id=41485


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78289

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


Index: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
@@ -402,7 +402,7 @@
   if (!Cont)
 return;
 
-  // At least one of the iterators have recorded positions. If one of them has
+  // At least one of the iterators has recorded positions. If one of them does
   // not then create a new symbol for the offset.
   SymbolRef Sym;
   if (!LPos || !RPos) {
@@ -422,9 +422,14 @@
 RPos = getIteratorPosition(State, RVal);
   }
 
-  // We cannot make assumpotions on `UnknownVal`. Let us conjure a symbol
+  if (!LPos || !RPos)
+return;
+
+  // We cannot make assumptions on `UnknownVal`. Let us conjure a symbol
   // instead.
   if (RetVal.isUnknown()) {
+if (!State)
+  return;
 auto &SymMgr = C.getSymbolManager();
 auto *LCtx = C.getLocationContext();
 RetVal = nonloc::SymbolVal(SymMgr.conjureSymbol(
@@ -532,8 +537,9 @@
 return;
 
   const auto *value = &RHS;
+  SVal val;
   if (auto loc = RHS.getAs()) {
-const auto val = State->getRawSVal(*loc);
+val = State->getRawSVal(*loc);
 value = &val;
   }
 


Index: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
@@ -402,7 +402,7 @@
   if (!Cont)
 return;
 
-  // At least one of the iterators have recorded positions. If one of them has
+  // At least one of the iterators has recorded positions. If one of them does
   // not then create a new symbol for the offset.
   SymbolRef Sym;
   if (!LPos || !RPos) {
@@ -422,9 +422,14 @@
 RPos = getIteratorPosition(State, RVal);
   }
 
-  // We cannot make assumpotions on `UnknownVal`. Let us conjure a symbol
+  if (!LPos || !RPos)
+return;
+
+  // We cannot make assumptions on `UnknownVal`. Let us conjure a symbol
   // instead.
   if (RetVal.isUnknown()) {
+if (!State)
+  return;
 auto &SymMgr = C.getSymbolManager();
 auto *LCtx = C.getLocationContext();
 RetVal = nonloc::SymbolVal(SymMgr.conjureSymbol(
@@ -532,8 +537,9 @@
 return;
 
   const auto *value = &RHS;
+  SVal val;
   if (auto loc = RHS.getAs()) {
-const auto val = State->getRawSVal(*loc);
+val = State->getRawSVal(*loc);
 value = &val;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78286: [analyzer] Track runtime types represented by Obj-C Class objects

2020-04-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 258003.
vsavchenko added a comment.

Fix unfinished comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78286

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/DynamicType.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/class-object-state-dump.m
  clang/test/Analysis/inlining/InlineObjCClassMethod.m
  clang/test/Analysis/inlining/ObjCDynTypePopagation.m
  clang/test/Analysis/inlining/ObjCDynTypePropagation.m
  clang/test/Analysis/retain-release-inline.m

Index: clang/test/Analysis/retain-release-inline.m
===
--- clang/test/Analysis/retain-release-inline.m
+++ clang/test/Analysis/retain-release-inline.m
@@ -13,6 +13,7 @@
 // It includes the basic definitions for the test cases below.
 //===--===//
 #define NULL 0
+#define nil ((id)0)
 typedef unsigned int __darwin_natural_t;
 typedef unsigned long uintptr_t;
 typedef unsigned int uint32_t;
@@ -21,14 +22,14 @@
 typedef signed long CFIndex;
 typedef CFIndex CFByteOrder;
 typedef struct {
-CFIndex location;
-CFIndex length;
+  CFIndex location;
+  CFIndex length;
 } CFRange;
 static __inline__ __attribute__((always_inline)) CFRange CFRangeMake(CFIndex loc, CFIndex len) {
-CFRange range;
-range.location = loc;
-range.length = len;
-return range;
+  CFRange range;
+  range.location = loc;
+  range.length = len;
+  return range;
 }
 typedef const void * CFTypeRef;
 typedef const struct __CFString * CFStringRef;
@@ -91,6 +92,7 @@
 - (BOOL)isEqual:(id)object;
 - (id)retain;
 - (oneway void)release;
+- (Class)class;
 - (id)autorelease;
 - (id)init;
 @end  @protocol NSCopying  - (id)copyWithZone:(NSZone *)zone;
@@ -100,6 +102,7 @@
 @interface NSObject  {}
 + (id)allocWithZone:(NSZone *)zone;
 + (id)alloc;
++ (Class)class;
 - (void)dealloc;
 @end
 @interface NSObject (NSCoderMethods)
@@ -481,3 +484,33 @@
   [self test_inline_tiny_when_reanalyzing];
 }
 @end
+
+// Original problem: rdar://problem/50739539
+@interface MyClassThatLeaksDuringInit : NSObject
+
++ (MyClassThatLeaksDuringInit *)getAnInstance1;
++ (MyClassThatLeaksDuringInit *)getAnInstance2;
+
+@end
+
+@implementation MyClassThatLeaksDuringInit
+
++ (MyClassThatLeaksDuringInit *)getAnInstance1 {
+  return [[[MyClassThatLeaksDuringInit alloc] init] autorelease]; // expected-warning{{leak}}
+}
+
++ (MyClassThatLeaksDuringInit *)getAnInstance2 {
+  return self class] alloc] init] autorelease]; // expected-warning{{leak}}
+}
+
+- (instancetype)init {
+  if (1) {
+return nil;
+  }
+
+  if (nil != (self = [super init])) {
+  }
+  return self;
+}
+
+@end
Index: clang/test/Analysis/inlining/ObjCDynTypePropagation.m
===
--- clang/test/Analysis/inlining/ObjCDynTypePropagation.m
+++ clang/test/Analysis/inlining/ObjCDynTypePropagation.m
@@ -7,68 +7,67 @@
 PublicSubClass2 *getObj();
 
 @implementation PublicParent
-- (int) getZeroOverridden {
-   return 1;
+- (int)getZeroOverridden {
+  return 1;
 }
-- (int) getZero {
-   return 0;
+- (int)getZero {
+  return 0;
 }
 @end
 
 @implementation PublicSubClass2
-- (int) getZeroOverridden {
-   return 0;
+- (int)getZeroOverridden {
+  return 0;
 }
 
 /* Test that we get the right type from call to alloc. */
-+ (void) testAllocSelf {
++ (void)testAllocSelf {
   id a = [self alloc];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-
-+ (void) testAllocClass {
++ (void)testAllocClass {
   id a = [PublicSubClass2 alloc];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-+ (void) testAllocSuperOverriden {
++ (void)testAllocSuperOverriden {
   id a = [super alloc];
   // Evaluates to 1 in the parent.
-  clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{FALSE}} 
+  clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{FALSE}}
 }
 
-+ (void) testAllocSuper {
++ (void)testAllocSuper {
   id a = [super alloc];
   clang_analyzer_eval([a getZero] == 0); // expected-warning{{TRUE}}
 }
 
-+ (void) testAllocInit {
++ (void)testAllocInit {
   id a = [[self alloc] init];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-+ (void) testNewSelf {
++ (void)testNewSelf {
   id a = [self new];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-// Casting to parent should not pessimize the dynamic type. 
-+ (void) testCastToParent {
- id a = [[self alloc] init];
- PublicParent *p = a;  
+// Casting to parent sho

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

2020-04-16 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@baloghadamsoftware
Please, review my changes. If you think they are OK, could you, please, commit 
the patch on by behalf as an author:
`git commit --amend --author="Denys Petrov "`


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


[clang] 03a9526 - [CGExprAgg] Fix infinite loop in `findPeephole`

2020-04-16 Thread Ehud Katz via cfe-commits

Author: Ehud Katz
Date: 2020-04-16T13:26:23+03:00
New Revision: 03a9526fe5adae909f1d5fd2736703e69fc46e09

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

LOG: [CGExprAgg] Fix infinite loop in `findPeephole`

Simplify the function using IgnoreParenNoopCasts.

Fix PR45476

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

Added: 
clang/test/CodeGen/pr45476.cpp

Modified: 
clang/lib/CodeGen/CGExprAgg.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index fa2d228b7eeb..90d4f7e4e096 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -677,17 +677,13 @@ 
AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
 
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
-static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-op = op->IgnoreParens();
-if (CastExpr *castE = dyn_cast(op)) {
-  if (castE->getCastKind() == kind)
-return castE->getSubExpr();
-  if (castE->getCastKind() == CK_NoOp)
-continue;
-}
-return nullptr;
+static Expr *findPeephole(Expr *op, CastKind kind, const ASTContext &ctx) {
+  op = op->IgnoreParenNoopCasts(ctx);
+  if (auto castE = dyn_cast(op)) {
+if (castE->getCastKind() == kind)
+  return castE->getSubExpr();
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {
@@ -776,7 +772,8 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
   (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
 
 // These two cases are reverses of each other; try to peephole them.
-if (Expr *op = findPeephole(E->getSubExpr(), peepholeTarget)) {
+if (Expr *op =
+findPeephole(E->getSubExpr(), peepholeTarget, CGF.getContext())) {
   assert(CGF.getContext().hasSameUnqualifiedType(op->getType(),
  E->getType()) &&
"peephole significantly changed types?");

diff  --git a/clang/test/CodeGen/pr45476.cpp b/clang/test/CodeGen/pr45476.cpp
new file mode 100644
index ..61f3f3649986
--- /dev/null
+++ b/clang/test/CodeGen/pr45476.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// PR45476
+
+// This test used to get into an infinite loop,
+// which, in turn, caused clang to never finish execution.
+
+struct s3 {
+  char a, b, c;
+};
+
+_Atomic struct s3 a;
+
+extern "C" void foo() {
+  // CHECK-LABEL: @foo
+  // CHECK: store atomic i32
+
+  a = s3{1, 2, 3};
+}
+



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


[clang] 94d6dd0 - [AST] Fix an undefine behavior when creating an empty recovery expr.

2020-04-16 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-04-16T12:35:45+02:00
New Revision: 94d6dd01ba439ffcef7f7873622cf6ae99bcf5cb

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

LOG: [AST] Fix an undefine behavior when creating an empty recovery expr.

Summary:
We forgot to initialize the NumExpr member in one of the constructors,
which leads crashes in preamble serialization.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 
clang/test/PCH/cxx-recovery-expr.cpp

Modified: 
clang/include/clang/AST/Expr.h
clang/lib/AST/Expr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index fab84f6a6ecd..4d89234b0da7 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -6080,7 +6080,8 @@ class RecoveryExpr final : public Expr,
 private:
   RecoveryExpr(ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc,
ArrayRef SubExprs);
-  RecoveryExpr(EmptyShell Empty) : Expr(RecoveryExprClass, Empty) {}
+  RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
+  : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
 
   size_t numTrailingObjects(OverloadToken) const { return NumExprs; }
 

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index bc6fadc71609..f108b49ceac1 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4652,7 +4652,7 @@ RecoveryExpr *RecoveryExpr::Create(ASTContext &Ctx, 
SourceLocation BeginLoc,
 RecoveryExpr *RecoveryExpr::CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs) 
{
   void *Mem = Ctx.Allocate(totalSizeToAlloc(NumSubExprs),
alignof(RecoveryExpr));
-  return new (Mem) RecoveryExpr(EmptyShell());
+  return new (Mem) RecoveryExpr(EmptyShell(), NumSubExprs);
 }
 
 void OMPArrayShapingExpr::setDimensions(ArrayRef Dims) {

diff  --git a/clang/test/PCH/cxx-recovery-expr.cpp 
b/clang/test/PCH/cxx-recovery-expr.cpp
new file mode 100644
index ..e0d58c119c54
--- /dev/null
+++ b/clang/test/PCH/cxx-recovery-expr.cpp
@@ -0,0 +1,13 @@
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -frecovery-ast -fallow-pch-with-compiler-errors 
-o %t %s
+// RUN: %clang_cc1 -include-pch %t -fno-validate-pch -emit-llvm -o - %s
+
+#ifndef HEADER
+#define HEADER
+
+int func(int);
+int s = func();
+
+#else
+
+#endif



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


[PATCH] D78286: [analyzer] Track runtime types represented by Obj-C Class objects

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



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:135
+  if (MsgE->getReceiverKind() == ObjCMessageExpr::Class) {
+return {MsgE->getClassReceiver()->getAs(), true};
+  }

Let's explain what `true` means here, i.e. `/*Precise=*/true`.



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:163
+
+  // Check if the receiver is 'self'.
+  if (const DeclRefExpr *DRE =

I suspect that `self`, unlike `this`, can be reassigned in the middle of the 
method.



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:164-165
+  // Check if the receiver is 'self'.
+  if (const DeclRefExpr *DRE =
+  dyn_cast(RecE->IgnoreParenImpCasts())) {
+const StackFrameContext *SFCtx = C.getStackFrame();

That's a good place for `const auto *`.



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:208-211
+  if (const auto *ReceiverInferredType =
+  dyn_cast(InferredType)) {
+return {ReceiverInferredType->getObjectType()};
+  }

When exactly does this situation happen? Can we predict it during 
pattern-matching instead of patching it up after the fact?



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:217-218
 
 void DynamicTypePropagation::checkDeadSymbols(SymbolReaper &SR,
   CheckerContext &C) const {
   ProgramStateRef State = removeDeadTypes(C.getState(), SR);

This needs to be filled in for the new trait as well! It's very important :3



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:324-325
+// We used to assume that whatever type we got from inferring the
+// type is actually precise (which is not exactly correct), and some
+// the features of the analyzer depend directly on this.
+//

Looks like a missed word somewhere.



Comment at: clang/lib/StaticAnalyzer/Core/DynamicType.cpp:37
 
+// A map from Class object symbols to the most likely contained type.
+REGISTER_MAP_WITH_PROGRAMSTATE(DynamicClassObjectMap, clang::ento::SymbolRef,

I'd rather word this as "pointed-to type".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78286



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


[PATCH] D78139: [clang-tidy] modernize-use-using: Fix broken fixit with 'template' keyword

2020-04-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks for fixing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78139



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


[PATCH] D78286: [analyzer] Track runtime types represented by Obj-C Class objects

2020-04-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko marked 6 inline comments as done.
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:135
+  if (MsgE->getReceiverKind() == ObjCMessageExpr::Class) {
+return {MsgE->getClassReceiver()->getAs(), true};
+  }

NoQ wrote:
> Let's explain what `true` means here, i.e. `/*Precise=*/true`.
Sure



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:163
+
+  // Check if the receiver is 'self'.
+  if (const DeclRefExpr *DRE =

NoQ wrote:
> I suspect that `self`, unlike `this`, can be reassigned in the middle of the 
> method.
That's true, and we didn't account for that in here. I'll try to make a test on 
that (and maybe re-order how we handle these cases a bit



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:164-165
+  // Check if the receiver is 'self'.
+  if (const DeclRefExpr *DRE =
+  dyn_cast(RecE->IgnoreParenImpCasts())) {
+const StackFrameContext *SFCtx = C.getStackFrame();

NoQ wrote:
> That's a good place for `const auto *`.
Right, didn't pay much attention to this moved code



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:217-218
 
 void DynamicTypePropagation::checkDeadSymbols(SymbolReaper &SR,
   CheckerContext &C) const {
   ProgramStateRef State = removeDeadTypes(C.getState(), SR);

NoQ wrote:
> This needs to be filled in for the new trait as well! It's very important :3
Whoops! I forgot!
Good catch!



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:324-325
+// We used to assume that whatever type we got from inferring the
+// type is actually precise (which is not exactly correct), and some
+// the features of the analyzer depend directly on this.
+//

NoQ wrote:
> Looks like a missed word somewhere.
OK, I'll try to re-write to make it more clear



Comment at: clang/lib/StaticAnalyzer/Core/DynamicType.cpp:37
 
+// A map from Class object symbols to the most likely contained type.
+REGISTER_MAP_WITH_PROGRAMSTATE(DynamicClassObjectMap, clang::ento::SymbolRef,

NoQ wrote:
> I'd rather word this as "pointed-to type".
Sure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78286



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


[PATCH] D78284: [AST] Fix an undefine behavior when creating an empty recovery expr.

2020-04-16 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG94d6dd01ba43: [AST] Fix an undefine behavior when creating 
an empty recovery expr. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78284

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/test/PCH/cxx-recovery-expr.cpp


Index: clang/test/PCH/cxx-recovery-expr.cpp
===
--- /dev/null
+++ clang/test/PCH/cxx-recovery-expr.cpp
@@ -0,0 +1,13 @@
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -frecovery-ast -fallow-pch-with-compiler-errors 
-o %t %s
+// RUN: %clang_cc1 -include-pch %t -fno-validate-pch -emit-llvm -o - %s
+
+#ifndef HEADER
+#define HEADER
+
+int func(int);
+int s = func();
+
+#else
+
+#endif
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4652,7 +4652,7 @@
 RecoveryExpr *RecoveryExpr::CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs) 
{
   void *Mem = Ctx.Allocate(totalSizeToAlloc(NumSubExprs),
alignof(RecoveryExpr));
-  return new (Mem) RecoveryExpr(EmptyShell());
+  return new (Mem) RecoveryExpr(EmptyShell(), NumSubExprs);
 }
 
 void OMPArrayShapingExpr::setDimensions(ArrayRef Dims) {
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -6080,7 +6080,8 @@
 private:
   RecoveryExpr(ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc,
ArrayRef SubExprs);
-  RecoveryExpr(EmptyShell Empty) : Expr(RecoveryExprClass, Empty) {}
+  RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
+  : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
 
   size_t numTrailingObjects(OverloadToken) const { return NumExprs; }
 


Index: clang/test/PCH/cxx-recovery-expr.cpp
===
--- /dev/null
+++ clang/test/PCH/cxx-recovery-expr.cpp
@@ -0,0 +1,13 @@
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -frecovery-ast -fallow-pch-with-compiler-errors -o %t %s
+// RUN: %clang_cc1 -include-pch %t -fno-validate-pch -emit-llvm -o - %s
+
+#ifndef HEADER
+#define HEADER
+
+int func(int);
+int s = func();
+
+#else
+
+#endif
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4652,7 +4652,7 @@
 RecoveryExpr *RecoveryExpr::CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs) {
   void *Mem = Ctx.Allocate(totalSizeToAlloc(NumSubExprs),
alignof(RecoveryExpr));
-  return new (Mem) RecoveryExpr(EmptyShell());
+  return new (Mem) RecoveryExpr(EmptyShell(), NumSubExprs);
 }
 
 void OMPArrayShapingExpr::setDimensions(ArrayRef Dims) {
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -6080,7 +6080,8 @@
 private:
   RecoveryExpr(ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc,
ArrayRef SubExprs);
-  RecoveryExpr(EmptyShell Empty) : Expr(RecoveryExprClass, Empty) {}
+  RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
+  : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
 
   size_t numTrailingObjects(OverloadToken) const { return NumExprs; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78098: [CGExprAgg] Fix infinite loop in `findPeephole`

2020-04-16 Thread Ehud Katz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG03a9526fe5ad: [CGExprAgg] Fix infinite loop in 
`findPeephole` (authored by ekatz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78098

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGen/pr45476.cpp


Index: clang/test/CodeGen/pr45476.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr45476.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// PR45476
+
+// This test used to get into an infinite loop,
+// which, in turn, caused clang to never finish execution.
+
+struct s3 {
+  char a, b, c;
+};
+
+_Atomic struct s3 a;
+
+extern "C" void foo() {
+  // CHECK-LABEL: @foo
+  // CHECK: store atomic i32
+
+  a = s3{1, 2, 3};
+}
+
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -677,17 +677,13 @@
 
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
-static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-op = op->IgnoreParens();
-if (CastExpr *castE = dyn_cast(op)) {
-  if (castE->getCastKind() == kind)
-return castE->getSubExpr();
-  if (castE->getCastKind() == CK_NoOp)
-continue;
-}
-return nullptr;
+static Expr *findPeephole(Expr *op, CastKind kind, const ASTContext &ctx) {
+  op = op->IgnoreParenNoopCasts(ctx);
+  if (auto castE = dyn_cast(op)) {
+if (castE->getCastKind() == kind)
+  return castE->getSubExpr();
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {
@@ -776,7 +772,8 @@
   (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
 
 // These two cases are reverses of each other; try to peephole them.
-if (Expr *op = findPeephole(E->getSubExpr(), peepholeTarget)) {
+if (Expr *op =
+findPeephole(E->getSubExpr(), peepholeTarget, CGF.getContext())) {
   assert(CGF.getContext().hasSameUnqualifiedType(op->getType(),
  E->getType()) &&
"peephole significantly changed types?");


Index: clang/test/CodeGen/pr45476.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr45476.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// PR45476
+
+// This test used to get into an infinite loop,
+// which, in turn, caused clang to never finish execution.
+
+struct s3 {
+  char a, b, c;
+};
+
+_Atomic struct s3 a;
+
+extern "C" void foo() {
+  // CHECK-LABEL: @foo
+  // CHECK: store atomic i32
+
+  a = s3{1, 2, 3};
+}
+
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -677,17 +677,13 @@
 
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
-static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-op = op->IgnoreParens();
-if (CastExpr *castE = dyn_cast(op)) {
-  if (castE->getCastKind() == kind)
-return castE->getSubExpr();
-  if (castE->getCastKind() == CK_NoOp)
-continue;
-}
-return nullptr;
+static Expr *findPeephole(Expr *op, CastKind kind, const ASTContext &ctx) {
+  op = op->IgnoreParenNoopCasts(ctx);
+  if (auto castE = dyn_cast(op)) {
+if (castE->getCastKind() == kind)
+  return castE->getSubExpr();
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {
@@ -776,7 +772,8 @@
   (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
 
 // These two cases are reverses of each other; try to peephole them.
-if (Expr *op = findPeephole(E->getSubExpr(), peepholeTarget)) {
+if (Expr *op =
+findPeephole(E->getSubExpr(), peepholeTarget, CGF.getContext())) {
   assert(CGF.getContext().hasSameUnqualifiedType(op->getType(),
  E->getType()) &&
"peephole significantly changed types?");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 258011.
balazske added a comment.

- Adding tests.
- Type alias is supported.
- Updated comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/cfg.cpp

Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -568,6 +568,71 @@
   return 2;
 }
 
+// CHECK-LABEL: void vla_simple(int x)
+// CHECK: [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: int vla[x];
+void vla_simple(int x) {
+  int vla[x];
+}
+
+// CHECK-LABEL: void vla_typedef(int x)
+// CHECK: [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: typedef int VLA[x];
+void vla_typedef(int x) {
+  typedef int VLA[x];
+}
+
+// CHECK-LABEL: void vla_typealias(int x)
+// CHECK: [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: using VLA = int [x];
+void vla_typealias(int x) {
+  using VLA = int[x];
+}
+
+// CHECK-LABEL: void vla_typedef_multi(int x, int y)
+// CHECK:  [B1]
+// CHECK-NEXT:   1: y
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: x
+// CHECK-NEXT:   4: [B1.3] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   5: typedef int VLA[x][y];
+void vla_typedef_multi(int x, int y) {
+  typedef int VLA[x][y];
+}
+
+// CHECK-LABEL: void vla_typedefname_multi(int x, int y)
+// CHECK:  [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: typedef int VLA[x];
+// CHECK-NEXT:   4: y
+// CHECK-NEXT:   5: [B1.4] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   6: typedef VLA VLA1[y];
+// CHECK-NEXT:   7: 3
+// CHECK-NEXT:   8: using VLA2 = VLA1 [3];
+// CHECK-NEXT:   9: 4
+// CHECK-NEXT:  10: VLA2 vla[4];
+void vla_typedefname_multi(int x, int y) {
+  typedef int VLA[x];
+  typedef VLA VLA1[y];
+  using VLA2 = VLA1[3];
+  VLA2 vla[4];
+}
+
+// CHECK-LABEL: void vla_embedded(int x)
+// CHECK:  [B1]
+// CHECK-NEXT:   1: void (*vla)(int *);
+void vla_embedded(int x) {
+  // FIXME: 'x' is not generated but should be.
+  void (*vla)(int[x]);
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2839,11 +2839,30 @@
 /// DeclStmts and initializers in them.
 CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
   assert(DS->isSingleDecl() && "Can handle single declarations only.");
+
+  if (const auto *TND = dyn_cast(DS->getSingleDecl())) {
+// If we encounter a VLA, process its size expressions.
+const Type *T = TND->getUnderlyingType().getTypePtr();
+if (!T->isVariablyModifiedType())
+  return Block;
+
+autoCreateBlock();
+appendStmt(Block, DS);
+
+CFGBlock *LastBlock = Block;
+for (const VariableArrayType *VA = FindVA(T); VA != nullptr;
+ VA = FindVA(VA->getElementType().getTypePtr())) {
+  if (CFGBlock *newBlock = addStmt(VA->getSizeExpr()))
+LastBlock = newBlock;
+}
+return LastBlock;
+  }
+
   VarDecl *VD = dyn_cast(DS->getSingleDecl());
 
   if (!VD) {
-// Of everything that can be declared in a DeclStmt, only VarDecls impact
-// runtime semantics.
+// Of everything that can be declared in a DeclStmt, only VarDecls and the
+// exceptions above impact runtime semantics.
 return Block;
   }
 
@@ -2905,6 +2924,8 @@
   }
 
   // If the type of VD is a VLA, then we must process its size expressions.
+  // FIXME: This does not find the VLA if it is embedded in other types,
+  // like here: `void (*vla)(int[x]);`
   for (const VariableArrayType* VA = FindVA(VD->getType().getTypePtr());
VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) {
 if (CFGBlock *newBlock = addStmt(VA->getSizeExpr()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78189: [analyzer] StdLibraryFunctionsChecker: Add statistics

2020-04-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:67
+#define DEBUG_TYPE "StdLibraryFunctionsChecker"
+STATISTIC(NumCall, "The # of calls handled by the checker");
+STATISTIC(NumFoundSummary, "The # of calls with associated summary");

This may be misleading: It is every call event that is encountered, even if not 
handled specially (because no summary). (I would not call a function "handled" 
if we do nothing with it beneath a check if it needs to be handled really.) 
Probably "found" is better.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:68
+STATISTIC(NumCall, "The # of calls handled by the checker");
+STATISTIC(NumFoundSummary, "The # of calls with associated summary");
+STATISTIC(NumArgConstraintViolated,

//The # of calls with summary// or //The # of handled calls with associated 
summary// ?
Probably only for me but I had difficulty to understand what this means.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:72
+STATISTIC(NumArgConstrained,
+  "The # of calls with applied argumentum constraints");
+STATISTIC(NumCaseApplied, "The # of calls with applied cases");

Change "argumentum" to "argument"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78189



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


[clang-tools-extra] cee80c0 - [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-16 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-04-16T13:55:08+02:00
New Revision: cee80c0489e96c36269388b2aacd4da1c5714a66

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

LOG: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

Summary:
This patch allows using installed gRPC to build two simple tools which
currently provide the functionality of looking up the symbol by name.
remote-index-client is a simplified version of dexp which connects to
remote-index-server passes lookup requests.

I also significantly reduced the scope of this patch to prevent large changelist
and more bugs. The next steps would be:

* Extending Protocol for deep copies of Symbol and inherit RemoteIndex from
  Index to unify the interfaces
* Make remote-index-server more generic and merge the remote index client with
  dexp
* Modify Clangd to allow using remote index instead of the local one for all
  global index requests

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, 
usaxena95, cfe-commits

Tags: #clang

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

Added: 
clang-tools-extra/clangd/index/remote/CMakeLists.txt
clang-tools-extra/clangd/index/remote/Index.proto
clang-tools-extra/clangd/index/remote/README.md
clang-tools-extra/clangd/index/remote/client/CMakeLists.txt
clang-tools-extra/clangd/index/remote/client/Client.cpp
clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
clang-tools-extra/clangd/index/remote/server/Server.cpp
llvm/cmake/modules/FindGRPC.cmake

Modified: 
clang-tools-extra/clangd/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 7a9a4f7932ae..1c2cbf398b77 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -153,3 +153,12 @@ if(CLANG_INCLUDE_TESTS)
 add_subdirectory(test)
 add_subdirectory(unittests)
 endif()
+
+# FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is 
stable.
+option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support 
for Clangd" OFF)
+set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual 
installation.")
+
+if (CLANGD_ENABLE_REMOTE)
+  include(FindGRPC)
+  add_subdirectory(index/remote)
+endif()

diff  --git a/clang-tools-extra/clangd/index/remote/CMakeLists.txt 
b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
new file mode 100644
index ..b946958f3c5f
--- /dev/null
+++ b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -0,0 +1,7 @@
+generate_grpc_protos(RemoteIndexProtos "Index.proto")
+
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
+
+add_subdirectory(client)
+add_subdirectory(server)

diff  --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
new file mode 100644
index ..399036ed72b7
--- /dev/null
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -0,0 +1,19 @@
+//===--- Index.proto - Remote index Protocol Buffers definition 
---===//
+//
+// 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
+//
+//===--===//
+
+syntax = "proto3";
+
+package clang.clangd.remote;
+
+service Index {
+  rpc Lookup(LookupRequest) returns (stream LookupReply) {}
+}
+
+message LookupRequest { string id = 1; }
+
+message LookupReply { string symbol_yaml = 1; }

diff  --git a/clang-tools-extra/clangd/index/remote/README.md 
b/clang-tools-extra/clangd/index/remote/README.md
new file mode 100644
index ..b56b2fc1011e
--- /dev/null
+++ b/clang-tools-extra/clangd/index/remote/README.md
@@ -0,0 +1,59 @@
+# Clangd remote index
+
+Clangd uses a global index for project-wide code completion, navigation and
+other features.  For large projects, building this can take many hours and
+keeping it loaded uses a lot of memory.
+
+To relieve that burden, we're building remote index — a global index
+served on a 
diff erent machine and shared between developers. This directory
+contains code that is used as Proof of Concept for the upcoming remote index
+feature.
+
+## Building
+
+This feature uses gRPC and Protobuf libraries, so you will need to install 
them.
+There are two ways of doing that.
+
+However you install dependencies, to enable this feature and build remote index
+tools you will need to set this CMake flag — `-DCLANGD_ENABLE_REMOTE=On`.
+
+### System-installed libraries
+
+On Debian-like s

[clang] 65a2de7 - [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.

2020-04-16 Thread Georgii Rymar via cfe-commits

Author: Georgii Rymar
Date: 2020-04-16T15:00:50+03:00
New Revision: 65a2de7e6c986193a630e691686c527b08f292d5

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

LOG: [FileCheck] - Fix the false positive when -implicit-check-not is used with 
an unknown -check-prefix.

Imagine we have the following invocation:

`FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=something`

When the check prefix does not exist it does not fail.
This patch fixes the issue.

Differential revision: https://reviews.llvm.org/D78024

Added: 


Modified: 
clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
llvm/include/llvm/Support/FileCheck.h
llvm/lib/Support/FileCheck.cpp
llvm/test/FileCheck/implicit-check-not.txt
llvm/test/tools/llvm-objcopy/MachO/strip-debug.test

Removed: 




diff  --git a/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c 
b/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
index 2e060cfcddef..e8f09975a26e 100644
--- a/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
+++ b/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 
-fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change
 
-fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change
 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s 
-implicit-check-not="call void @__ubsan_handle_implicit_conversion" 
--check-prefixes=CHECK
+// RUN: %clang_cc1 
-fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change
 
-fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change
 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s 
-implicit-check-not="call void @__ubsan_handle_implicit_conversion"
 
 // If we have an enum, it will be promoted to an unsigned integer.
 // But both types are unsigned, and have same bitwidth.

diff  --git a/llvm/include/llvm/Support/FileCheck.h 
b/llvm/include/llvm/Support/FileCheck.h
index 429e36cfcbb5..d218ef042257 100644
--- a/llvm/include/llvm/Support/FileCheck.h
+++ b/llvm/include/llvm/Support/FileCheck.h
@@ -31,6 +31,7 @@ struct FileCheckRequest {
   bool AllowEmptyInput = false;
   bool MatchFullLines = false;
   bool IgnoreCase = false;
+  bool IsDefaultCheckPrefix = false;
   bool EnableVarScope = false;
   bool AllowDeprecatedDagOverlap = false;
   bool Verbose = false;

diff  --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp
index 0913b97fcdd0..71b1e8356137 100644
--- a/llvm/lib/Support/FileCheck.cpp
+++ b/llvm/lib/Support/FileCheck.cpp
@@ -1305,6 +1305,7 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef 
Buffer,
   // found.
   unsigned LineNumber = 1;
 
+  bool FoundUsedPrefix = false;
   while (1) {
 Check::FileCheckType CheckTy;
 
@@ -1315,6 +1316,8 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef 
Buffer,
 FindFirstMatchingPrefix(PrefixRE, Buffer, LineNumber, CheckTy);
 if (UsedPrefix.empty())
   break;
+FoundUsedPrefix = true;
+
 assert(UsedPrefix.data() == Buffer.data() &&
"Failed to move Buffer's start forward, or pointed prefix outside "
"of the buffer!");
@@ -1398,16 +1401,10 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef 
Buffer,
 DagNotMatches = ImplicitNegativeChecks;
   }
 
-  // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
-  // and use the first prefix as a filler for the error message.
-  if (!DagNotMatches.empty()) {
-CheckStrings->emplace_back(
-Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
-*Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
-std::swap(DagNotMatches, CheckStrings->back().DagNotStrings);
-  }
-
-  if (CheckStrings->empty()) {
+  // When there are no used prefixes we report an error except in the case that
+  // no prefix is specified explicitly but -implicit-check-not is specified.
+  if (!FoundUsedPrefix &&
+  (ImplicitNegativeChecks.empty() || !Req.IsDefaultCheckPrefix)) {
 errs() << "error: no check strings found with prefix"
<< (Req.CheckPrefixes.size() > 1 ? "es " : " ");
 auto I = Req.CheckPrefixes.begin();
@@ -1423,6 +1420,15 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef 
Buffer,
 return true;
   }
 
+  // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
+  // and use the first prefix as a filler for the error message.
+  if (!DagNotMatches.empty()) {
+CheckStrings->emplace_back(
+Pattern(Check::CheckEOF, PatternContext.ge

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

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

changes: depend on bfloat IR type, and resolve some conflicts that crept in


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78194

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/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/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/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.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-bfloat.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -607,6 +607,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/CodeGen/arm-mangle-16bit-float.cpp
===
--- /dev/null
+++ clang/test/CodeGen/arm-mangle-16bit-float.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +bf16 -target-feature +fullfp16 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK64
+// RUN: %clang_cc1 -triple arm-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +bf16 -target-feature +fullfp16 -emit-llvm -o - %s | FileCheck %s --

[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

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



Comment at: clang/test/Analysis/cfg.cpp:570
 }
 
+// CHECK-LABEL: void vla_simple(int x)

Can you also add tests for:
```
int vla_unevaluated(int x) {
  // Evaluates the ++x
  sizeof(int[++x]);
  // Does not evaluate the ++x
  _Alignof(int[++x]);
  _Generic((int(*)[++x])0, default : 0);
  
  return x;
}
```

Also, it's a bit strange to find these VLA tests in a .cpp file. VLAs are a C++ 
extension and we should have some testing for them for constructs that are 
C++-specific, but I would have expected many of these tests to be in a C file 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



___
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-04-16 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 258018.
stuij added a comment.

changes: depend on bfloat IR type, and resolve some conflicts that crept in


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/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/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/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.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-bfloat.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -607,6 +607,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/CodeGen/arm-mangle-16bit-float.cpp
===
--- /dev/null
+++ clang/test/CodeGen/arm-mangle-16bit-float.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +bf16 -target-feature +fullfp16 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK64
+// RUN: %clang_cc1 -triple arm-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +bf16 -target-feature +fullfp16 -emit-llvm -o - %s | FileCheck %s --

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

2020-04-16 Thread Ties Stuij via Phabricator via cfe-commits
stuij abandoned this revision.
stuij added a comment.

This should not have been it's own revision. I wrongly trusted arc to update 
https://reviews.llvm.org/D76077.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78194



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-16 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcee80c0489e9: [clangd] Pull installed gRPC and introduce 
clangd-remote-(server|client) (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/README.md
  clang-tools-extra/clangd/index/remote/client/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/client/Client.cpp
  clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  llvm/cmake/modules/FindGRPC.cmake

Index: llvm/cmake/modules/FindGRPC.cmake
===
--- /dev/null
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -0,0 +1,50 @@
+# This setup requires gRPC to be built from sources using CMake and installed to
+# ${GRPC_INSTALL_PATH} via -DCMAKE_INSTALL_PREFIX=${GRPC_INSTALL_PATH}.
+if (GRPC_INSTALL_PATH)
+  set(protobuf_MODULE_COMPATIBLE TRUE)
+  find_package(Protobuf CONFIG REQUIRED HINTS ${GRPC_INSTALL_PATH})
+  message(STATUS "Using protobuf ${protobuf_VERSION}")
+  find_package(gRPC CONFIG REQUIRED HINTS ${GRPC_INSTALL_PATH})
+  message(STATUS "Using gRPC ${gRPC_VERSION}")
+
+  include_directories(${Protobuf_INCLUDE_DIRS})
+
+  # gRPC CMake CONFIG gives the libraries slightly odd names, make them match
+  # the conventional system-installed names.
+  set_target_properties(protobuf::libprotobuf PROPERTIES IMPORTED_GLOBAL TRUE)
+  add_library(protobuf ALIAS protobuf::libprotobuf)
+  set_target_properties(gRPC::grpc++ PROPERTIES IMPORTED_GLOBAL TRUE)
+  add_library(grpc++ ALIAS gRPC::grpc++)
+
+  set(GRPC_CPP_PLUGIN $)
+  set(PROTOC ${Protobuf_PROTOC_EXECUTABLE})
+else()
+  find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
+  find_program(PROTOC protoc)
+endif()
+
+# Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
+# Libraries that use these headers should adjust the include path.
+# FIXME(kirillbobyrev): Allow optional generation of gRPC code and give callers
+# control over it via additional parameters.
+function(generate_grpc_protos LibraryName ProtoFile)
+  get_filename_component(ProtoSourceAbsolutePath "${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
+  get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
+
+  set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.cc")
+  set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.h")
+  set(GeneratedGRPCSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
+  set(GeneratedGRPCHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+  add_custom_command(
+OUTPUT "${GeneratedProtoSource}" "${GeneratedProtoHeader}" "${GeneratedGRPCSource}" "${GeneratedGRPCHeader}"
+COMMAND ${PROTOC}
+ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
+  --cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
+  --proto_path="${ProtoSourcePath}"
+  --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}"
+  "${ProtoSourceAbsolutePath}"
+  DEPENDS "${ProtoSourceAbsolutePath}")
+
+  add_library(${LibraryName} ${GeneratedProtoSource} ${GeneratedGRPCSource})
+  target_link_libraries(${LibraryName} grpc++ protobuf)
+endfunction()
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -0,0 +1,102 @@
+//===--- Server.cpp - gRPC-based Remote Index Server  -===//
+//
+// 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 "index/Index.h"
+#include "index/Serialization.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 "grpcpp/grpcpp.h"
+#include "grpcpp/health_check_service_interface.h"
+
+#include "Index.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental remote index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc(""),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::Stri

[PATCH] D78024: [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.

2020-04-16 Thread George Rimar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65a2de7e6c98: [FileCheck] - Fix the false positive when 
-implicit-check-not is used with an… (authored by grimar).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D78024?vs=257671&id=258021#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78024

Files:
  clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
  llvm/include/llvm/Support/FileCheck.h
  llvm/lib/Support/FileCheck.cpp
  llvm/test/FileCheck/implicit-check-not.txt
  llvm/test/tools/llvm-objcopy/MachO/strip-debug.test

Index: llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
===
--- llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
+++ llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
@@ -3,7 +3,7 @@
 # RUN: yaml2obj %p/Inputs/strip-all-with-dwarf.yaml -o %t
 
 # RUN: llvm-objcopy --strip-debug %t %t.stripped
-# RUN: llvm-readobj --sections %t.stripped | FileCheck /dev/null --check-prefix=NODWARF \
+# RUN: llvm-readobj --sections %t.stripped | FileCheck /dev/null \
 # RUN:   --implicit-check-not='Name: __debug' --implicit-check-not='Name: __apple'
 
 ## Make sure that all symbols are kept.
Index: llvm/test/FileCheck/implicit-check-not.txt
===
--- llvm/test/FileCheck/implicit-check-not.txt
+++ llvm/test/FileCheck/implicit-check-not.txt
@@ -1,4 +1,16 @@
 ; RUN: sed 's#^;.*##' %s | FileCheck -check-prefix=CHECK-PASS -implicit-check-not=warning: %s
+
+; Check we report an error when an unknown prefix is used together with `-implicit-check-not`.
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=abc %s 2>&1 | FileCheck %s -DPREFIX=UNKNOWN-PREFIX -check-prefix CHECK-PREFIX-ERROR
+; CHECK-PREFIX-ERROR: error: no check strings found with prefix '[[PREFIX]]:'
+
+; Check we report an error when the "CHECK" prefix is used explicitly with `-implicit-check-not`, but not present in the input.
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK -implicit-check-not=abc %s 2>&1 | FileCheck %s -DPREFIX=CHECK -check-prefix CHECK-PREFIX-ERROR
+
+; Check we allow using `-implicit-check-not` when there is no `-check-prefix` specified and there
+; is no default `CHECK` line in an input.
+; RUN: sed 's#^;.*##' %s | FileCheck -implicit-check-not="unique_string" %s
+
 ; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR1
 ; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL2 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR2
 ; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL3 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR3
Index: llvm/lib/Support/FileCheck.cpp
===
--- llvm/lib/Support/FileCheck.cpp
+++ llvm/lib/Support/FileCheck.cpp
@@ -1305,6 +1305,7 @@
   // found.
   unsigned LineNumber = 1;
 
+  bool FoundUsedPrefix = false;
   while (1) {
 Check::FileCheckType CheckTy;
 
@@ -1315,6 +1316,8 @@
 FindFirstMatchingPrefix(PrefixRE, Buffer, LineNumber, CheckTy);
 if (UsedPrefix.empty())
   break;
+FoundUsedPrefix = true;
+
 assert(UsedPrefix.data() == Buffer.data() &&
"Failed to move Buffer's start forward, or pointed prefix outside "
"of the buffer!");
@@ -1398,16 +1401,10 @@
 DagNotMatches = ImplicitNegativeChecks;
   }
 
-  // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
-  // and use the first prefix as a filler for the error message.
-  if (!DagNotMatches.empty()) {
-CheckStrings->emplace_back(
-Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
-*Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
-std::swap(DagNotMatches, CheckStrings->back().DagNotStrings);
-  }
-
-  if (CheckStrings->empty()) {
+  // When there are no used prefixes we report an error except in the case that
+  // no prefix is specified explicitly but -implicit-check-not is specified.
+  if (!FoundUsedPrefix &&
+  (ImplicitNegativeChecks.empty() || !Req.IsDefaultCheckPrefix)) {
 errs() << "error: no check strings found with prefix"
<< (Req.CheckPrefixes.size() > 1 ? "es " : " ");
 auto I = Req.CheckPrefixes.begin();
@@ -1423,6 +1420,15 @@
 return true;
   }
 
+  // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
+  // and use the first prefix as a filler for the error message.
+  if (!DagNotMatches.empty()) {
+   

[clang] 38ca7b1 - Expose AtomicType in the libclang C API.

2020-04-16 Thread Aaron Ballman via cfe-commits

Author: Henry Jen
Date: 2020-04-16T08:06:58-04:00
New Revision: 38ca7b11db2d22e0fdfbff3f19276f9796f747d3

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

LOG: Expose AtomicType in the libclang C API.

Added: 


Modified: 
clang/include/clang-c/Index.h
clang/test/Index/print-type.c
clang/tools/c-index-test/c-index-test.c
clang/tools/libclang/CXType.cpp
clang/tools/libclang/libclang.exports

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 0acd50021ed8..8e367b617bd3 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -33,7 +33,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 59
+#define CINDEX_VERSION_MINOR 60
 
 #define CINDEX_VERSION_ENCODE(major, minor) (((major)*1) + ((minor)*1))
 
@@ -3342,7 +3342,8 @@ enum CXTypeKind {
 
   CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175,
 
-  CXType_ExtVector = 176
+  CXType_ExtVector = 176,
+  CXType_Atomic = 177
 };
 
 /**
@@ -3932,6 +3933,13 @@ CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType 
T, const char *S);
  */
 CINDEX_LINKAGE CXType clang_Type_getModifiedType(CXType T);
 
+/**
+ * Gets the type contained by this atomic type.
+ *
+ * If a non-atomic type is passed in, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_Type_getValueType(CXType CT);
+
 /**
  * Return the offset of the field represented by the Cursor.
  *

diff  --git a/clang/test/Index/print-type.c b/clang/test/Index/print-type.c
index 9bf058840825..b58a76937626 100644
--- a/clang/test/Index/print-type.c
+++ b/clang/test/Index/print-type.c
@@ -22,13 +22,15 @@ struct {
 
 struct {
   struct {
-int x;
+_Atomic int x;
 int y;
   };
 } bar;
 
 void fun(struct { int x; int y; } *param);
 
+_Atomic(unsigned long) aul;
+
 // RUN: c-index-test -test-print-type %s | FileCheck %s
 // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, 
int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, 
char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] 
[resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] 
[Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] 
[Pointer]] [isPOD=0]
 // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] 
[isPOD=1] [pointeetype=int] [pointeekind=Int]
@@ -70,4 +72,7 @@ void fun(struct { int x; int y; } *param);
 // CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=0]
 // CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] 
[isAnonRecDecl=0]
 // CHECK: StructDecl=:24:3 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=1]
+// CHECK: FieldDecl=x:25:17 (Definition) [type=_Atomic(int)] [typekind=Atomic] 
[valuetype=int] [valuetypekind=Int] [isPOD=0] [isAnonRecDecl=0]
+// CHECK: FieldDecl=y:26:9 (Definition) [type=int] [typekind=Int] [isPOD=1] 
[isAnonRecDecl=0]
 // CHECK: StructDecl=:30:10 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=0]
+// CHECK: VarDecl=aul:32:24 [type=_Atomic(unsigned long)] [typekind=Atomic] 
[valuetype=unsigned long] [valuetypekind=ULong] [isPOD=0] [isAnonRecDecl=0]

diff  --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index d4de743f2e38..6e82bff6 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1579,6 +1579,12 @@ static enum CXChildVisitResult PrintType(CXCursor 
cursor, CXCursor p,
 PrintTypeTemplateArgs(CT, " [canonicaltemplateargs/%d=");
   }
 }
+/* Print the value type if it exists. */
+{
+  CXType VT = clang_Type_getValueType(T);
+  if (VT.kind != CXType_Invalid)
+PrintTypeAndTypeKind(VT, " [valuetype=%s] [valuetypekind=%s]");
+}
 /* Print the modified type if it exists. */
 {
   CXType MT = clang_Type_getModifiedType(T);

diff  --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index acecf87d0cda..42da867ac4af 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -115,6 +115,7 @@ static CXTypeKind GetTypeKind(QualType T) {
 TKCASE(Elaborated);
 TKCASE(Pipe);
 TKCASE(Attributed);
+TKCASE(Atomic);
 default:
   return CXType_Unexposed;
   }
@@ -616,6 +617,7 @@ CXString clang_getTypeKindSpelling

[PATCH] D61716: [libclang] Expose AtomicType

2020-04-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit on your behalf in 38ca7b11db2d22e0fdfbff3f19276f9796f747d3 
, thank 
you for the patch!


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

https://reviews.llvm.org/D61716



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


[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2020-04-16 Thread Thibault North via Phabricator via cfe-commits
tnorth updated this revision to Diff 258029.

Repository:
  rC Clang

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

https://reviews.llvm.org/D72326

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15204,6 +15204,61 @@
   auto StyleTd = getStyle("file", "x.td", "llvm", "", &FS);
   ASSERT_TRUE((bool)StyleTd);
   ASSERT_EQ(*StyleTd, getLLVMStyle(FormatStyle::LK_TableGen));
+
+  // Test 9: explicit format file in parent directory.
+  ASSERT_TRUE(
+  FS.addFile("/e/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: LLVM")));
+  ASSERT_TRUE(
+  FS.addFile("/e/explicit.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google")));
+  ASSERT_TRUE(FS.addFile("/e/sub/sub/sub/test.cpp", 0,
+ llvm::MemoryBuffer::getMemBuffer("int i;")));
+  auto Style8 = getStyle("file:/e/explicit.clang-format",
+ "/e/sub/sub/sub/test.cpp", "LLVM", "", &FS);
+  ASSERT_TRUE((bool)Style8);
+  ASSERT_EQ(*Style8, getGoogleStyle());
+
+  // Test 10: relative pah to a format file
+  ASSERT_TRUE(
+  FS.addFile("../../e/explicit.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google")));
+  auto Style9 = getStyle("file:../../e/explicit.clang-format",
+ "/e/sub/sub/sub/test.cpp", "LLVM", "", &FS);
+  ASSERT_TRUE((bool)Style9);
+  ASSERT_EQ(*Style9, getGoogleStyle());
+
+  // Test 11: missing explicit format file
+  auto Style10 = getStyle("file:/e/missing.clang-format",
+  "/e/sub/sub/sub/test.cpp", "LLVM", "", &FS);
+  ASSERT_FALSE((bool)Style10);
+  llvm::consumeError(Style10.takeError());
+
+  // Test 12: format file from the filesystem
+  SmallString<128> FormatFilePath;
+  std::error_code ECF = llvm::sys::fs::createTemporaryFile(
+  "FormatFileTest", "tpl", FormatFilePath);
+  EXPECT_FALSE((bool)ECF);
+  llvm::raw_fd_ostream FormatFileTest(FormatFilePath, ECF);
+  EXPECT_FALSE((bool)ECF);
+  FormatFileTest << "BasedOnStyle: Google\n";
+  FormatFileTest.close();
+
+  SmallString<128> TestFilePath;
+  std::error_code ECT =
+  llvm::sys::fs::createTemporaryFile("CodeFileTest", "cc", TestFilePath);
+  EXPECT_FALSE((bool)ECT);
+  llvm::raw_fd_ostream CodeFileTest(TestFilePath, ECT);
+  CodeFileTest << "int i;\n";
+  CodeFileTest.close();
+
+  std::string format_file_arg = std::string("file:") + FormatFilePath.c_str();
+  auto Style11 = getStyle(format_file_arg, TestFilePath, "LLVM", "", nullptr);
+
+  llvm::sys::fs::remove(FormatFilePath.c_str());
+  llvm::sys::fs::remove(TestFilePath.c_str());
+  ASSERT_TRUE((bool)Style11);
+  ASSERT_EQ(*Style11, getGoogleStyle());
 }
 
 TEST_F(ReplacementTest, FormatCodeAfterReplacements) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2640,6 +2640,8 @@
 ".clang-format file located in one of the parent\n"
 "directories of the source file (or current\n"
 "directory for stdin).\n"
+"Use -style=file: to explicitly specify"
+"the configuration file.\n"
 "Use -style=\"{key: value, ...}\" to set specific\n"
 "parameters, e.g.:\n"
 "  -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
@@ -2685,6 +2687,29 @@
   return GuessedLanguage;
 }
 
+/// Attempts to load a format file
+llvm::Expected LoadConfigFile(StringRef ConfigFile,
+   llvm::vfs::FileSystem *FS,
+   bool *IsSuitable) {
+  FormatStyle Style = getLLVMStyle();
+  *IsSuitable = false;
+
+  llvm::ErrorOr> Text =
+  FS->getBufferForFile(ConfigFile.str());
+  if (std::error_code EC = Text.getError())
+return make_string_error(EC.message());
+  std::error_code ParserErrorCode =
+  parseConfiguration(Text.get()->getBuffer(), &Style);
+  if (ParserErrorCode == ParseError::Unsuitable) {
+return Style;
+  } else if (ParserErrorCode != ParseError::Success) {
+return make_string_error("Error reading " + ConfigFile + ": " +
+ ParserErrorCode.message());
+  }
+  *IsSuitable = true;
+  return Style;
+}
+
 const char *DefaultFormatStyle = "file";
 
 const char *DefaultFallbackStyle = "LLVM";
@@ -2709,6 +2734,21 @@
 return Style;
   }
 
+  llvm::SmallVector FilesToLookFor;
+  // User provided clang-format file using -style=file:/path/to/format/file
+  // Check for explicit config filename
+  if (StyleName.startswith_lower("file:")) {
+auto StyleNameFile = StyleName.substr(5);
+bool IsS

[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-04-16 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

@rjmccall Can you check the patch added last night here, commit 
3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf 

Author: Benjamin Kramer 
Date:   Thu Apr 16 11:45:02 2020 +0200

  LangOptions cannot depend on ASTContext, make it not use ASTContext directly
  
  Fixes a layering violation introduced in 
2ba4e3a4598b165245c581c506a813cd4a7dce33.
   


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384



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


[PATCH] D77491: [Sema] Fix incompatible builtin redeclarations in non-global scope

2020-04-16 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

rsmith: ping 2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491



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


[PATCH] D78294: [Fixed Point] Move the compassign LHS type correction a bit further down. NFCI.

2020-04-16 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added a reviewer: leonardchan.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We can simplify the LHSTy correction for
fixed-point compassign by moving it below
the point where we know we have a compound
assignment.

Also, we shouldn't look at the LHS and RHS
separately; look at the computation result
type instead.

Looking at the LHS and RHS is also wrong
for compassigns with fixed and floating
point (though this does not work upstream
yet).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78294

Files:
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13639,14 +13639,6 @@
   if (ResultTy.isNull() || LHS.isInvalid() || RHS.isInvalid())
 return ExprError();
 
-  // The LHS is not converted to the result type for fixed-point compound
-  // assignment as the common type is computed on demand. Reset the CompLHSTy
-  // to the LHS type we would have gotten after unary conversions.
-  if (!CompLHSTy.isNull() &&
-  (LHS.get()->getType()->isFixedPointType() ||
-   RHS.get()->getType()->isFixedPointType()))
-CompLHSTy = UsualUnaryConversions(LHS.get()).get()->getType();
-
   if (ResultTy->isRealFloatingType() &&
   (getLangOpts().getFPRoundingMode() != RoundingMode::NearestTiesToEven ||
getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore))
@@ -13705,6 +13697,12 @@
 OK = LHS.get()->getObjectKind();
   }
 
+  // The LHS is not converted to the result type for fixed-point compound
+  // assignment as the common type is computed on demand. Reset the CompLHSTy
+  // to the LHS type we would have gotten after unary conversions.
+  if (CompResultTy->isFixedPointType())
+CompLHSTy = UsualUnaryConversions(LHS.get()).get()->getType();
+
   if (ConvertHalfVec)
 return convertHalfVecBinOp(*this, LHS, RHS, Opc, ResultTy, VK, OK, true,
OpLoc, FPFeatures);


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13639,14 +13639,6 @@
   if (ResultTy.isNull() || LHS.isInvalid() || RHS.isInvalid())
 return ExprError();
 
-  // The LHS is not converted to the result type for fixed-point compound
-  // assignment as the common type is computed on demand. Reset the CompLHSTy
-  // to the LHS type we would have gotten after unary conversions.
-  if (!CompLHSTy.isNull() &&
-  (LHS.get()->getType()->isFixedPointType() ||
-   RHS.get()->getType()->isFixedPointType()))
-CompLHSTy = UsualUnaryConversions(LHS.get()).get()->getType();
-
   if (ResultTy->isRealFloatingType() &&
   (getLangOpts().getFPRoundingMode() != RoundingMode::NearestTiesToEven ||
getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore))
@@ -13705,6 +13697,12 @@
 OK = LHS.get()->getObjectKind();
   }
 
+  // The LHS is not converted to the result type for fixed-point compound
+  // assignment as the common type is computed on demand. Reset the CompLHSTy
+  // to the LHS type we would have gotten after unary conversions.
+  if (CompResultTy->isFixedPointType())
+CompLHSTy = UsualUnaryConversions(LHS.get()).get()->getType();
+
   if (ConvertHalfVec)
 return convertHalfVecBinOp(*this, LHS, RHS, Opc, ResultTy, VK, OK, true,
OpLoc, FPFeatures);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77872: [AArch32] Armv8.6-a Matrix Mult Assembly + Intrinsics

2020-04-16 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson marked 3 inline comments as done.
LukeGeeson added inline comments.



Comment at: clang/test/CodeGen/arm-v8.6a-neon-intrinsics.c:3
+// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -emit-llvm 
-o - %s \
+// RUN: | opt -S -mem2reg \
+// RUN: | FileCheck %s

miyuki wrote:
> Can you try -sroa after -mem2reg? I think it should eliminate some more 
> useless stores and loads.
added, test updated



Comment at: llvm/lib/Target/ARM/ARMInstrNEON.td:4839
   let Constraints = "$dst = $Vd";
+  let hasNoSchedulingInfo = 1;
 }

miyuki wrote:
> Why was this added?
Added a vusdot class to handle this


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

https://reviews.llvm.org/D77872



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


[PATCH] D77872: [AArch32] Armv8.6-a Matrix Mult Assembly + Intrinsics

2020-04-16 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson updated this revision to Diff 258030.
LukeGeeson added a comment.

- added -sroa to arm-v8.6a-neon-intrinsics test, updated test to remove 
redundant memory accesses
- made class vusdot for new vusdot instructions with hasNoSchedulinginfo for 
new instructions. Existing instructions retain scheduling via use of VDOT class


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

https://reviews.llvm.org/D77872

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/arm-v8.6a-neon-intrinsics.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMInstrNEON.td
  llvm/lib/Target/ARM/ARMPredicates.td
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/test/CodeGen/ARM/arm-matmul.ll

Index: llvm/test/CodeGen/ARM/arm-matmul.ll
===
--- /dev/null
+++ llvm/test/CodeGen/ARM/arm-matmul.ll
@@ -0,0 +1,83 @@
+; RUN: llc -mtriple=arm-none-linux-gnu -mattr=+neon,+i8mm -float-abi=hard < %s -o -| FileCheck %s
+
+define <4 x i32> @smmla.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <16 x i8> %b) {
+entry:
+; CHECK-LABEL: smmla.v4i32.v16i8
+; CHECK:vsmmla.s8   q0, q1, q2
+  %vmmla1.i = tail call <4 x i32> @llvm.arm.neon.smmla.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <16 x i8> %b) #3
+  ret <4 x i32> %vmmla1.i
+}
+
+define <4 x i32> @ummla.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <16 x i8> %b) {
+entry:
+; CHECK-LABEL: ummla.v4i32.v16i8
+; CHECK:vummla.u8   q0, q1, q2
+  %vmmla1.i = tail call <4 x i32> @llvm.arm.neon.ummla.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <16 x i8> %b) #3
+  ret <4 x i32> %vmmla1.i
+}
+
+define <4 x i32> @usmmla.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <16 x i8> %b) {
+entry:
+; CHECK-LABEL: usmmla.v4i32.v16i8
+; CHECK:vusmmla.s8   q0, q1, q2
+  %vusmmla1.i = tail call <4 x i32> @llvm.arm.neon.usmmla.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <16 x i8> %b) #3
+  ret <4 x i32> %vusmmla1.i
+}
+
+define <2 x i32> @usdot.v2i32.v8i8(<2 x i32> %r, <8 x i8> %a, <8 x i8> %b) {
+entry:
+; CHECK-LABEL: usdot.v2i32.v8i8
+; CHECK:vusdot.s8   d0, d1, d2
+  %vusdot1.i = tail call <2 x i32> @llvm.arm.neon.usdot.v2i32.v8i8(<2 x i32> %r, <8 x i8> %a, <8 x i8> %b) #3
+  ret <2 x i32> %vusdot1.i
+}
+
+define <2 x i32> @usdot_lane.v2i32.v8i8(<2 x i32> %r, <8 x i8> %a, <8 x i8> %b) {
+entry:
+; CHECK-LABEL: usdot_lane.v2i32.v8i8
+; CHECK:vusdot.s8   d0, d1, d2[0]
+  %0 = bitcast <8 x i8> %b to <2 x i32>
+  %shuffle = shufflevector <2 x i32> %0, <2 x i32> undef, <2 x i32> zeroinitializer
+  %1 = bitcast <2 x i32> %shuffle to <8 x i8>
+  %vusdot1.i = tail call <2 x i32> @llvm.arm.neon.usdot.v2i32.v8i8(<2 x i32> %r, <8 x i8> %a, <8 x i8> %1) #3
+  ret <2 x i32> %vusdot1.i
+}
+
+define <2 x i32> @sudot_lane.v2i32.v8i8(<2 x i32> %r, <8 x i8> %a, <8 x i8> %b) {
+entry:
+; CHECK-LABEL: sudot_lane.v2i32.v8i8
+; CHECK:vsudot.u8   d0, d1, d2[0]
+  %0 = bitcast <8 x i8> %b to <2 x i32>
+  %shuffle = shufflevector <2 x i32> %0, <2 x i32> undef, <2 x i32> zeroinitializer
+  %1 = bitcast <2 x i32> %shuffle to <8 x i8>
+  %vusdot1.i = tail call <2 x i32> @llvm.arm.neon.usdot.v2i32.v8i8(<2 x i32> %r, <8 x i8> %1, <8 x i8> %a) #3
+  ret <2 x i32> %vusdot1.i
+}
+
+define <4 x i32> @usdotq_lane.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <8 x i8> %b) {
+entry:
+; CHECK-LABEL: usdotq_lane.v4i32.v16i8
+; CHECK:vusdot.s8   q0, q1, d4[0]
+  %0 = bitcast <8 x i8> %b to <2 x i32>
+  %shuffle = shufflevector <2 x i32> %0, <2 x i32> undef, <4 x i32> zeroinitializer
+  %1 = bitcast <4 x i32> %shuffle to <16 x i8>
+  %vusdot1.i = tail call <4 x i32> @llvm.arm.neon.usdot.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <16 x i8> %1) #3
+  ret <4 x i32> %vusdot1.i
+}
+
+define <4 x i32> @sudotq_lane.v4i32.v16i8(<4 x i32> %r, <16 x i8> %a, <8 x i8> %b) {
+entry:
+; CHECK-LABEL: sudotq_lane.v4i32.v16i8
+; CHECK:vsudot.u8   q0, q1, d4[0]
+  %0 = bitcast <8 x i8> %b to <2 x i32>
+  %shuffle = shufflevector <2 x i32> %0, <2 x i32> undef, <4 x i32> zeroinitializer
+  %1 = bitcast <4 x i32> %shuffle to <16 x i8>
+  %vusdot1.i = tail call <4 x i32> @llvm.arm.neon.usdot.v4i32.v16i8(<4 x i32> %r, <16 x i8> %1, <16 x i8> %a) #3
+  ret <4 x i32> %vusdot1.i
+}
+
+declare <4 x i32> @llvm.arm.neon.smmla.v4i32.v16i8(<4 x i32>, <16 x i8>, <16 x i8>) #2
+declare <4 x i32> @llvm.arm.neon.ummla.v4i32.v16i8(<4 x i32>, <16 x i8>, <16 x i8>) #2
+declare <4 x i32> @llvm.arm.neon.usmmla.v4i32.v16i8(<4 x i32>, <16 x i8>, <16 x i8>) #2
+declare <2 x i32> @llvm.arm.neon.usdot.v2i32.v8i8(<2 x i32>, <8 x i8>, <8 x i8>) #2
+declare <4 x i32> @llvm.arm.neon.usdot.v4i32.v16i8(<4 x i32>, <16 x i8>, <16 x i8>) #2
Index: llvm/lib/Target/ARM/ARMSubtarget.h
===
--- llvm/lib/Target/ARM/ARMSubtarget.h
+++ llvm/lib/Target/ARM/ARMSubtarget.h
@@ -260,6 +260,9 @@
   /// HasBF16 

[PATCH] D78295: [clang-format] Do not interpret C# deconstruction in a foreach as a cast

2020-04-16 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe created this revision.
jbcoe added a reviewer: krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78295

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -624,6 +624,7 @@
   Style.SpaceBeforeCpp11BracedList = true;
   Style.Cpp11BracedListStyle = false;
   Style.SpacesInContainerLiterals = false;
+  Style.SpaceAfterCStyleCast = false;
 
   verifyFormat(R"(new Car { "Door", 0.1 })", Style);
   verifyFormat(R"(new Car { 0.1, "Door" })", Style);
@@ -642,6 +643,11 @@
 
   verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
 
+  // Not seen as a C-style cast.
+  verifyFormat(R"(//
+foreach ((A a, B b) in someList) {
+})", Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1775,6 +1775,10 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// `foreach((A a, B b) in someList)` should not be seen as a cast.
+if (Tok.Next->is(Keywords.kw_in) && Style.isCSharp())
+  return false;
+
 // Functions which end with decorations like volatile, noexcept are 
unlikely
 // to be casts.
 if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -624,6 +624,7 @@
   Style.SpaceBeforeCpp11BracedList = true;
   Style.Cpp11BracedListStyle = false;
   Style.SpacesInContainerLiterals = false;
+  Style.SpaceAfterCStyleCast = false;
 
   verifyFormat(R"(new Car { "Door", 0.1 })", Style);
   verifyFormat(R"(new Car { 0.1, "Door" })", Style);
@@ -642,6 +643,11 @@
 
   verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
 
+  // Not seen as a C-style cast.
+  verifyFormat(R"(//
+foreach ((A a, B b) in someList) {
+})", Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1775,6 +1775,10 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// `foreach((A a, B b) in someList)` should not be seen as a cast.
+if (Tok.Next->is(Keywords.kw_in) && Style.isCSharp())
+  return false;
+
 // Functions which end with decorations like volatile, noexcept are unlikely
 // to be casts.
 if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78295: [clang-format] Do not interpret C# deconstruction in a foreach as a cast

2020-04-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78295



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


[clang] 07c1978 - [clang-format] Do not interpret C# deconstruction in a foreach as a cast

2020-04-16 Thread Jonathan Coe via cfe-commits

Author: Jonathan Coe
Date: 2020-04-16T14:22:34+01:00
New Revision: 07c1978b15b4e9daefbf358e6fd185b5aa269f98

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

LOG: [clang-format] Do not interpret C# deconstruction in a foreach as a cast

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 8204623645a4..6532f8108f08 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1775,6 +1775,10 @@ class AnnotatingParser {
 if (Tok.Next->is(tok::question))
   return false;
 
+// `foreach((A a, B b) in someList)` should not be seen as a cast.
+if (Tok.Next->is(Keywords.kw_in) && Style.isCSharp())
+  return false;
+
 // Functions which end with decorations like volatile, noexcept are 
unlikely
 // to be casts.
 if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index b0e4e76cefe7..67571d3909bf 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -624,6 +624,7 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
   Style.SpaceBeforeCpp11BracedList = true;
   Style.Cpp11BracedListStyle = false;
   Style.SpacesInContainerLiterals = false;
+  Style.SpaceAfterCStyleCast = false;
 
   verifyFormat(R"(new Car { "Door", 0.1 })", Style);
   verifyFormat(R"(new Car { 0.1, "Door" })", Style);
@@ -642,6 +643,12 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
 
   verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
 
+  // Not seen as a C-style cast.
+  verifyFormat(R"(//
+foreach ((A a, B b) in someList) {
+})",
+   Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);



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


[clang] 2ec5520 - Disallow [[nodiscard]] on a function pointer declaration.

2020-04-16 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2020-04-16T09:28:49-04:00
New Revision: 2ec5520a54ef9b359c6154adf857ba690bc117f1

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

LOG: Disallow [[nodiscard]] on a function pointer declaration.

This is not allowed by [dcl.attr.nodiscard]p1 for the standard attribute, but
is still supported for the [[clang::warn_unused_result]] spelling.

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
clang/test/SemaCXX/warn-unused-result.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1a8a73660cf4..3205b4472db2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2826,6 +2826,12 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
   StringRef Str;
   if ((AL.isCXX11Attribute() || AL.isC2xAttribute()) && !AL.getScopeName()) {
+// The standard attribute cannot be applied to variable declarations such
+// as a function pointer.
+if (isa(D))
+  S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type_str)
+  << AL << "functions, classes, or enumerations";
+
 // If this is spelled as the standard C++17 attribute, but not in C++17,
 // warn about using it as an extension. If there are attribute arguments,
 // then claim it's a C++2a extension instead.

diff  --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
index 3d3223cda756..e2397c12e2e9 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -26,7 +26,7 @@ void f() {
   (void)get_e();
 }
 
-[[nodiscard]] volatile char &(*fp)();
+[[nodiscard]] volatile char &(*fp)(); // expected-warning {{'nodiscard' 
attribute only applies to functions, classes, or enumerations}}
 void g() {
   fp(); // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
 

diff  --git a/clang/test/SemaCXX/warn-unused-result.cpp 
b/clang/test/SemaCXX/warn-unused-result.cpp
index f1de4618a741..d0bb4c9317dd 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -246,3 +246,11 @@ void g() {
 f(b); // expected-warning {{ignoring return value}}
 }
 } // namespace PR39837
+
+namespace PR45520 {
+[[nodiscard]] bool (*f)(); // expected-warning {{'nodiscard' attribute only 
applies to functions, classes, or enumerations}}
+[[clang::warn_unused_result]] bool (*g)();
+__attribute__((warn_unused_result)) bool (*h)();
+
+void i([[nodiscard]] bool (*fp)()); // expected-warning {{'nodiscard' 
attribute only applies to functions, classes, or enumerations}}
+}



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


[PATCH] D78123: [analyzer][NSOrCFError] Don't emit diagnostics under the name osx.NSOrCFErrorDerefChecker

2020-04-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske accepted this revision.
balazske added a comment.
This revision is now accepted and ready to land.

I am not familiar with ObjC but the code change looks OK if the tests pass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78123



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


[PATCH] D73967: Implement _ExtInt as an extended int type specifier.

2020-04-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Ping again!


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

https://reviews.llvm.org/D73967



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


[PATCH] D77474: [analyzer][MallocChecker] Make NewDeleteLeaks depend on DynamicMemoryModeling rather than NewDelete

2020-04-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:195
+// Say this 3 times fast.
+State = State ? State : getState();
+addTransition(State, generateSink(State, getPredecessor()));

```
if (!State)
  State = getState();
```
is better? (I put the same comment into some (other?) patch already but maybe 
it disappeared?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77474



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


[PATCH] D78295: [clang-format] Do not interpret C# deconstruction in a foreach as a cast

2020-04-16 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 258035.
jbcoe added a comment.

Format patch


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

https://reviews.llvm.org/D78295

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -624,6 +624,7 @@
   Style.SpaceBeforeCpp11BracedList = true;
   Style.Cpp11BracedListStyle = false;
   Style.SpacesInContainerLiterals = false;
+  Style.SpaceAfterCStyleCast = false;
 
   verifyFormat(R"(new Car { "Door", 0.1 })", Style);
   verifyFormat(R"(new Car { 0.1, "Door" })", Style);
@@ -642,6 +643,12 @@
 
   verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
 
+  // Not seen as a C-style cast.
+  verifyFormat(R"(//
+foreach ((A a, B b) in someList) {
+})",
+   Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1775,6 +1775,10 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// `foreach((A a, B b) in someList)` should not be seen as a cast.
+if (Tok.Next->is(Keywords.kw_in) && Style.isCSharp())
+  return false;
+
 // Functions which end with decorations like volatile, noexcept are 
unlikely
 // to be casts.
 if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -624,6 +624,7 @@
   Style.SpaceBeforeCpp11BracedList = true;
   Style.Cpp11BracedListStyle = false;
   Style.SpacesInContainerLiterals = false;
+  Style.SpaceAfterCStyleCast = false;
 
   verifyFormat(R"(new Car { "Door", 0.1 })", Style);
   verifyFormat(R"(new Car { 0.1, "Door" })", Style);
@@ -642,6 +643,12 @@
 
   verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
 
+  // Not seen as a C-style cast.
+  verifyFormat(R"(//
+foreach ((A a, B b) in someList) {
+})",
+   Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1775,6 +1775,10 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// `foreach((A a, B b) in someList)` should not be seen as a cast.
+if (Tok.Next->is(Keywords.kw_in) && Style.isCSharp())
+  return false;
+
 // Functions which end with decorations like volatile, noexcept are unlikely
 // to be casts.
 if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78190: Add Bfloat IR type

2020-04-16 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 258036.
stuij marked 2 inline comments as done.
stuij added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

addressing review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78190

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  llvm/docs/BitCodeFormat.rst
  llvm/docs/LangRef.rst
  llvm/include/llvm-c/Core.h
  llvm/include/llvm/ADT/APFloat.h
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/MIRParser/MILexer.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/LLVMContextImpl.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/lib/IR/Type.cpp
  llvm/lib/Support/APFloat.cpp
  llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/Assembler/bfloat-constprop.ll
  llvm/test/Assembler/bfloat-conv.ll
  llvm/test/Assembler/bfloat.ll
  llvm/tools/llvm-c-test/echo.cpp

Index: llvm/tools/llvm-c-test/echo.cpp
===
--- llvm/tools/llvm-c-test/echo.cpp
+++ llvm/tools/llvm-c-test/echo.cpp
@@ -72,6 +72,8 @@
 return LLVMVoidTypeInContext(Ctx);
   case LLVMHalfTypeKind:
 return LLVMHalfTypeInContext(Ctx);
+  case LLVMBfloatTypeKind:
+return LLVMHalfTypeInContext(Ctx);
   case LLVMFloatTypeKind:
 return LLVMFloatTypeInContext(Ctx);
   case LLVMDoubleTypeKind:
Index: llvm/test/Assembler/bfloat.ll
===
--- /dev/null
+++ llvm/test/Assembler/bfloat.ll
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+; RUN: verify-uselistorder %s
+; Basic smoke test for bfloat type.
+
+; CHECK: define bfloat @check_bfloat
+define bfloat @check_bfloat(bfloat %A) {
+; CHECK: ret bfloat %A
+ret bfloat %A
+}
+
+; CHECK: define bfloat @check_bfloat_literal
+define bfloat @check_bfloat_literal() {
+; CHECK: ret bfloat 0xR3149
+ret bfloat 0xR3149
+}
Index: llvm/test/Assembler/bfloat-conv.ll
===
--- /dev/null
+++ llvm/test/Assembler/bfloat-conv.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -O3 -S | FileCheck %s
+; RUN: verify-uselistorder %s
+; Testing bfloat to float conversion.
+
+define float @abc() nounwind {
+entry:
+  %a = alloca bfloat, align 2
+  %.compoundliteral = alloca float, align 4
+  store bfloat 0xR4C8D, bfloat* %a, align 2
+  %tmp = load bfloat, bfloat* %a, align 2
+  %conv = fpext bfloat %tmp to float
+; CHECK: 0x4191A000
+  ret float %conv
+}
Index: llvm/test/Assembler/bfloat-constprop.ll
===
--- /dev/null
+++ llvm/test/Assembler/bfloat-constprop.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -O3 -S | FileCheck %s
+; RUN: verify-uselistorder %s
+; Testing bfloat constant propagation.
+
+define bfloat @abc() nounwind {
+entry:
+  %a = alloca bfloat, align 2
+  %b = alloca bfloat, align 2
+  %.compoundliteral = alloca float, align 4
+  store bfloat 0xR40C0, bfloat* %a, align 2
+  store bfloat 0xR40C0, bfloat* %b, align 2
+  %tmp = load bfloat, bfloat* %a, align 2
+  %tmp1 = load bfloat, bfloat* %b, align 2
+  %add = fadd bfloat %tmp, %tmp1
+; CHECK: 0xR4140
+  ret bfloat %add
+}
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -11438,8 +11438,9 @@
   MVT LogicVT = VT;
   if (EltVT == MVT::f32 || EltVT == MVT::f64) {
 Zero = DAG.getConstantFP(0.0, DL, EltVT);
-AllOnes = DAG.getConstantFP(
-APFloat::getAllOnesValue(EltVT.getSizeInBits(), true), DL, EltVT);
+APFloat AllOnesValue = APFloat::getAllOnesValue(
+SelectionDAG::EVTToAPFloatSemantics(EltVT), EltVT.getSizeInBits());
+AllOnes = DAG.getConstantFP(AllOnesValue, DL, EltVT);
 LogicVT =
 MVT::getVectorVT(EltVT == MVT::f64 ? MVT::i64 : MVT::i32, Mask.size());
   } else {
Index: llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
===
--- llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
+++ llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
@@ -322,6 +322,7 @@
   }
   case Type::FunctionTyID:
   case Type::VoidTyID:
+  case Type::BfloatTyID:
   case Type::X86_FP80TyID:
   case Type::FP128TyID:
   case Type::PPC_FP128TyID:
Index: llvm/lib/Support/APFloat.cpp
===
--- llvm/lib/Support/APFloat.cpp
+++ l

[PATCH] D78190: Add Bfloat IR type

2020-04-16 Thread Ties Stuij via Phabricator via cfe-commits
stuij marked an inline comment as done.
stuij added a comment.

@craig.topper : Yes, I thought to keep this patch confined to IR. Codegen and 
intrinsics patches are still to come.




Comment at: llvm/docs/LangRef.rst:2896
+   * - ``bfloat``
+ - 16-bit brain floating-point value (10-bit mantissa)
+

craig.topper wrote:
> bfloat doesn't have 10-bits of mantissa. its 1 bit of sign, 8-bits of 
> exponent and 7-bits of mantissa.
Ai, such a fail. Thanks!



Comment at: llvm/lib/Support/APFloat.cpp:4837
 
 APFloat APFloat::getAllOnesValue(unsigned BitWidth, bool isIEEE) {
   if (isIEEE) {

craig.topper wrote:
> This is a bit of strange interace. I wonder if it wouldn't be possible to 
> have the callers pass the semantics instead of the bitwidth and then this 
> function could get the bitwidth from the semantics. It looks like there 
> aren't many callers. I believe the one in Constants.cpp could get the 
> semantics from getFltSemantics on the Type. Probably similar could be done at 
> other callers?
Yes, I wholeheartedly concur. Turns out the function was also used in both 
front- and backend, but luckily there were already similar getters available 
for FltSemantics. I hoped to get also get rid of the BitWidth argument, but it 
turns out that it's not guaranteed that that FltSemantics has that filled in 
properly. Hardcoding exceptions didn't feel very nice and would make this a fn 
that can easily be overlooked to update for new types.


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] D78295: [clang-format] Do not interpret C# deconstruction in a foreach as a cast

2020-04-16 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07c1978b15b4: [clang-format] Do not interpret C# 
deconstruction in a foreach as a cast (authored by Jonathan Coe 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78295

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -624,6 +624,7 @@
   Style.SpaceBeforeCpp11BracedList = true;
   Style.Cpp11BracedListStyle = false;
   Style.SpacesInContainerLiterals = false;
+  Style.SpaceAfterCStyleCast = false;
 
   verifyFormat(R"(new Car { "Door", 0.1 })", Style);
   verifyFormat(R"(new Car { 0.1, "Door" })", Style);
@@ -642,6 +643,12 @@
 
   verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
 
+  // Not seen as a C-style cast.
+  verifyFormat(R"(//
+foreach ((A a, B b) in someList) {
+})",
+   Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1775,6 +1775,10 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// `foreach((A a, B b) in someList)` should not be seen as a cast.
+if (Tok.Next->is(Keywords.kw_in) && Style.isCSharp())
+  return false;
+
 // Functions which end with decorations like volatile, noexcept are 
unlikely
 // to be casts.
 if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -624,6 +624,7 @@
   Style.SpaceBeforeCpp11BracedList = true;
   Style.Cpp11BracedListStyle = false;
   Style.SpacesInContainerLiterals = false;
+  Style.SpaceAfterCStyleCast = false;
 
   verifyFormat(R"(new Car { "Door", 0.1 })", Style);
   verifyFormat(R"(new Car { 0.1, "Door" })", Style);
@@ -642,6 +643,12 @@
 
   verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
 
+  // Not seen as a C-style cast.
+  verifyFormat(R"(//
+foreach ((A a, B b) in someList) {
+})",
+   Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1775,6 +1775,10 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// `foreach((A a, B b) in someList)` should not be seen as a cast.
+if (Tok.Next->is(Keywords.kw_in) && Style.isCSharp())
+  return false;
+
 // Functions which end with decorations like volatile, noexcept are unlikely
 // to be casts.
 if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e033ec2 - [ASTImporter] Fix bug introduced in 2ba4e3a4598b

2020-04-16 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-04-16T16:03:27+02:00
New Revision: e033ec291a1b72f307ab14569ca99822c127610b

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

LOG: [ASTImporter] Fix bug introduced in 2ba4e3a4598b

2ba4e3a4598b (Move FPFeatures from BinaryOperator bitfields to Trailing
storage, D76384) introduced an assertion failure during CTU analysis.
The reason is that in ASTNodeImporter::VisitCompoundAssignOperator the
LHSType and the ResultType have been imported twice.

Details:
clang: ../../git/llvm-project/clang/lib/Basic/SourceManager.cpp:918: 
clang::FileID clang::SourceManager::getFileIDLoaded(unsigned int) const: 
Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.
clang::SourceManager::getDecomposedExpansionLoc(clang::SourceLocation) const
clang::SourceManager::getPresumedLoc(clang::SourceLocation, bool) const
clang::ASTImporter::Import(clang::SourceLocation)
llvm::Error 
clang::ASTImporter::importInto(clang::SourceLocation&, 
clang::SourceLocation const&)
clang::ASTNodeImporter::ImportDeclParts(clang::NamedDecl*, 
clang::DeclContext*&, clang::DeclContext*&, clang::DeclarationName&, 
clang::NamedDecl*&, clang::SourceLocation&)
clang::ASTNodeImporter::VisitRecordDecl(clang::RecordDecl*)
clang::declvisitor::Base >::Visit(clang::Decl*)
clang::ASTImporter::Import(clang::Decl*)
clang::ASTNodeImporter::VisitRecordType(clang::RecordType const*)
clang::TypeVisitor 
>::Visit(clang::Type const*)
clang::ASTImporter::Import(clang::QualType)
clang::ASTNodeImporter::VisitElaboratedType(clang::ElaboratedType const*)
clang::TypeVisitor 
>::Visit(clang::Type const*)
clang::ASTImporter::Import(clang::QualType)
clang::ASTNodeImporter::VisitPointerType(clang::PointerType const*)
clang::TypeVisitor 
>::Visit(clang::Type const*)
clang::ASTImporter::Import(clang::QualType)
clang::QualType 
clang::ASTNodeImporter::importChecked(llvm::Error&, 
clang::QualType const&)
clang::ASTNodeImporter::VisitCompoundAssignOperator(clang::CompoundAssignOperator*)

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 5cdf1de4c96a..afd35e0137b6 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6818,8 +6818,7 @@ 
ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
   Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
   E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
   E->getFPFeatures(Importer.getFromContext().getLangOpts()),
-  importChecked(Err, ToComputationLHSType),
-  importChecked(Err, ToComputationResultType));
+  ToComputationLHSType, ToComputationResultType);
 }
 
 Expected



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


[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

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



Comment at: clang/lib/AST/ASTImporter.cpp:6821
+  E->getFPFeatures(Importer.getFromContext()),
+  importChecked(Err, ToComputationLHSType),
+  importChecked(Err, ToComputationResultType));

This introduced an assertion failure during CTU analysis. The reason is that 
the LHSType and the ResultType have been imported twice.

The fix is in e033ec291a1b72f307ab14569ca99822c127610b

Details:
```
clang: ../../git/llvm-project/clang/lib/Basic/SourceManager.cpp:918: 
clang::FileID clang::SourceManager::getFileIDLoaded(unsigned int) const: 
Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.
clang::SourceManager::getDecomposedExpansionLoc(clang::SourceLocation) const
clang::SourceManager::getPresumedLoc(clang::SourceLocation, bool) const
clang::ASTImporter::Import(clang::SourceLocation)
llvm::Error 
clang::ASTImporter::importInto(clang::SourceLocation&, 
clang::SourceLocation const&)
clang::ASTNodeImporter::ImportDeclParts(clang::NamedDecl*, 
clang::DeclContext*&, clang::DeclContext*&, clang::DeclarationName&, 
clang::NamedDecl*&, clang::SourceLocation&)
clang::ASTNodeImporter::VisitRecordDecl(clang::RecordDecl*)
clang::declvisitor::Base >::Visit(clang::Decl*)
clang::ASTImporter::Import(clang::Decl*)
clang::ASTNodeImporter::VisitRecordType(clang::RecordType const*)
clang::TypeVisitor 
>::Visit(clang::Type const*)
clang::ASTImporter::Import(clang::QualType)
clang::ASTNodeImporter::VisitElaboratedType(clang::ElaboratedType const*)
clang::TypeVisitor 
>::Visit(clang::Type const*)
clang::ASTImporter::Import(clang::QualType)
clang::ASTNodeImporter::VisitPointerType(clang::PointerType const*)
clang::TypeVisitor 
>::Visit(clang::Type const*)
clang::ASTImporter::Import(clang::QualType)
clang::QualType 
clang::ASTNodeImporter::importChecked(llvm::Error&, 
clang::QualType const&)
  
 
clang::ASTNodeImporter::VisitCompoundAssignOperator(clang::CompoundAssignOperator*)
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384



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


[PATCH] D77872: [AArch32] Armv8.6-a Matrix Mult Assembly + Intrinsics

2020-04-16 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki accepted this revision.
miyuki added a comment.
This revision is now accepted and ready to land.

LGTM, but please wait a couple more days before committing to see if anyone 
wants to chime in (I guess one week since the upload date should be enough).


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

https://reviews.llvm.org/D77872



___
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-04-16 Thread Raul Tambre via Phabricator via cfe-commits
tambre added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64.td:607
+   FeatureSVE
+   ]>;
+

sdesmalen wrote:
> Not sure how accurate the link you referenced is, but it doesn't mention SVE 
> or Crypto extensions. Is that an omission in the blog post?
All the ARM vector extensions are a bit confusing. SVE indeed isn't supported, 
I've removed it.
I confirmed that AES, SHA1 and SHA2 extensions work on a real machine.



Comment at: llvm/unittests/Support/Host.cpp:271
+BogoMIPS: 62.50
+Features: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp 
asimdhp cpuid asimdrdm dcpop
+CPU implementer : 0x4e

sdesmalen wrote:
> nit: it probably doesn't matter much for the function `getHostCPUNameForARM`, 
> but the feature list seems incomplete.
The output is from a Xavier system running the Linux variant provided by Nvidia.



Comment at: llvm/unittests/Support/TargetParserTest.cpp:980
+  AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
+  AArch64::AEK_SIMD | AArch64::AEK_FP16 | AArch64::AEK_RAS |
+  AArch64::AEK_LSE | AArch64::AEK_SVE | AArch64::AEK_RDM,

sdesmalen wrote:
> nit: odd indentation here, have you used clang-format?
Fixed manually. Using clang-format results in unpleasant formatting similar to 
"apple-a10" and "apple-a11" above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77940



___
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-04-16 Thread Raul Tambre via Phabricator via cfe-commits
tambre updated this revision to Diff 258045.
tambre marked 6 inline comments as done.
tambre added a comment.

Remove SVE, fix formatting


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
@@ -974,9 +974,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;
@@ -1125,6 +1131,8 @@
AArch64::ArchKind::INVALID, "sve"));
   EXPECT_FALSE(testAArch64Extension("a64fx",
AArch64::ArchKind::INVALID, "sve2"));
+  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
@@ -44,6 +44,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
@@ -66,6 +66,7 @@
   // this in the future so we can specify it together with the subtarget
   // features.
   switch (ARMProcFamily) {
+  case Carmel:
   case Others:
 break;
   case CortexA35:
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -597,6 +597,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 chips do
 // perform the fusion and cyclone is used by default when targetting apple OSes.
 def ProcAppleA7 : SubtargetFeature<"

[clang] 30d5946 - [clang][AST] Support AST files larger than 512M

2020-04-16 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-04-16T07:27:43-07:00
New Revision: 30d5946db95fa465d7ee6caceb2b1ff191e3727c

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

LOG: [clang][AST] Support AST files larger than 512M

Summary:
Clang uses 32-bit integers for storing bit offsets from the beginning of
the file that results in 512M limit on AST file. This diff replaces
absolute offsets with relative offsets from the beginning of
corresponding data structure when it is possible. And uses 64-bit
offsets for DeclOffests and TypeOffssts because these coder AST
section may easily exceeds 512M alone.

This diff breaks AST file format compatibility so VERSION_MAJOR bumped.

Test Plan:
Existing clang AST serialization tests
Tested on clangd with ~700M and ~900M preamble files

Reviewers: rsmith, dexonsmith

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 323edfbf8126..198d8e3b4fed 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires that the version control branch 
and
 /// revision match exactly, since there is no backward compatibility of
 /// AST files at this time.
-const unsigned VERSION_MAJOR = 9;
+const unsigned VERSION_MAJOR = 10;
 
 /// AST file minor version number supported by this version of
 /// Clang.
@@ -181,7 +181,7 @@ namespace serialization {
   /// Raw source location of end of range.
   unsigned End;
 
-  /// Offset in the AST file.
+  /// Offset in the AST file relative to ModuleFile::MacroOffsetsBase.
   uint32_t BitOffset;
 
   PPEntityOffset(SourceRange R, uint32_t BitOffset)
@@ -221,12 +221,18 @@ namespace serialization {
   /// Raw source location.
   unsigned Loc = 0;
 
-  /// Offset in the AST file.
-  uint32_t BitOffset = 0;
+  /// Offset in the AST file. Split 64-bit integer into low/high parts
+  /// to keep structure alignment 32-bit and don't have padding gap.
+  /// This structure is serialized "as is" to the AST file and undefined
+  /// value in the padding affects AST hash.
+  uint32_t BitOffsetLow = 0;
+  uint32_t BitOffsetHigh = 0;
 
   DeclOffset() = default;
-  DeclOffset(SourceLocation Loc, uint32_t BitOffset)
-: Loc(Loc.getRawEncoding()), BitOffset(BitOffset) {}
+  DeclOffset(SourceLocation Loc, uint64_t BitOffset) {
+setLocation(Loc);
+setBitOffset(BitOffset);
+  }
 
   void setLocation(SourceLocation L) {
 Loc = L.getRawEncoding();
@@ -235,6 +241,15 @@ namespace serialization {
   SourceLocation getLocation() const {
 return SourceLocation::getFromRawEncoding(Loc);
   }
+
+  void setBitOffset(uint64_t Offset) {
+BitOffsetLow = Offset;
+BitOffsetHigh = Offset >> 32;
+  }
+
+  uint64_t getBitOffset() const {
+return BitOffsetLow | (uint64_t(BitOffsetHigh) << 32);
+  }
 };
 
 /// The number of predefined preprocessed entity IDs.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 94645fff9f93..11a537fad5d5 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -723,9 +723,10 @@ class ASTReader
 
   struct PendingMacroInfo {
 ModuleFile *M;
-uint64_t MacroDirectivesOffset;
+/// Offset relative to ModuleFile::MacroOffsetsBase.
+uint32_t MacroDirectivesOffset;
 
-PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
+PendingMacroInfo(ModuleFile *M, uint32_t MacroDirectivesOffset)
 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
   };
 
@@ -2205,7 +2206,7 @@ class ASTReader
   /// \param MacroDirectivesOffset Offset of the serialized macro directive
   /// history.
   void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
-   uint64_t MacroDirectivesOffset);
+   uint32_t MacroDirectivesOffset);
 
   /// Read the set of macros defined by this external macro source.
   void ReadDefinedMacros() ov

[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-04-16 Thread Melanie Blower via Phabricator via cfe-commits
mibintc marked an inline comment as done.
mibintc added a subscriber: martong.
mibintc added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:6821
+  E->getFPFeatures(Importer.getFromContext()),
+  importChecked(Err, ToComputationLHSType),
+  importChecked(Err, ToComputationResultType));

martong wrote:
> This introduced an assertion failure during CTU analysis. The reason is that 
> the LHSType and the ResultType have been imported twice.
> 
> The fix is in e033ec291a1b72f307ab14569ca99822c127610b
> 
> Details:
> ```
> clang: ../../git/llvm-project/clang/lib/Basic/SourceManager.cpp:918: 
> clang::FileID clang::SourceManager::getFileIDLoaded(unsigned int) const: 
> Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.
> clang::SourceManager::getDecomposedExpansionLoc(clang::SourceLocation) 
> const
> clang::SourceManager::getPresumedLoc(clang::SourceLocation, bool) const
> clang::ASTImporter::Import(clang::SourceLocation)
> llvm::Error 
> clang::ASTImporter::importInto(clang::SourceLocation&, 
> clang::SourceLocation const&)
> clang::ASTNodeImporter::ImportDeclParts(clang::NamedDecl*, 
> clang::DeclContext*&, clang::DeclContext*&, clang::DeclarationName&, 
> clang::NamedDecl*&, clang::SourceLocation&)
> clang::ASTNodeImporter::VisitRecordDecl(clang::RecordDecl*)
> clang::declvisitor::Base llvm::Expected >::Visit(clang::Decl*)
> clang::ASTImporter::Import(clang::Decl*)
> clang::ASTNodeImporter::VisitRecordType(clang::RecordType const*)
> clang::TypeVisitor llvm::Expected >::Visit(clang::Type const*)
> clang::ASTImporter::Import(clang::QualType)
> clang::ASTNodeImporter::VisitElaboratedType(clang::ElaboratedType const*)
> clang::TypeVisitor llvm::Expected >::Visit(clang::Type const*)
> clang::ASTImporter::Import(clang::QualType)
> clang::ASTNodeImporter::VisitPointerType(clang::PointerType const*)
> clang::TypeVisitor llvm::Expected >::Visit(clang::Type const*)
> clang::ASTImporter::Import(clang::QualType)
> clang::QualType 
> clang::ASTNodeImporter::importChecked(llvm::Error&, 
> clang::QualType const&)
>   
>  
> clang::ASTNodeImporter::VisitCompoundAssignOperator(clang::CompoundAssignOperator*)
> ```
@martong Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384



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


[PATCH] D78030: [TimeProfiler] Emit clock synchronization point

2020-04-16 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
broadwaylamb marked an inline comment as done.
broadwaylamb added inline comments.



Comment at: llvm/lib/Support/TimeProfiler.cpp:266
+  const auto BeginningOfTimeUs = SystemTime - ProcessLocalTime;
+  J.attribute("beginningOfTime",
+  BeginningOfTimeUs.time_since_epoch().count());

MaskRay wrote:
> broadwaylamb wrote:
> > broadwaylamb wrote:
> > > MaskRay wrote:
> > > > What is the logic here?
> > > > 
> > > > Two events in the same process may have different `beginningOfTime`. Is 
> > > > that intended?
> > > > 
> > > > Noe that `system_clock::now()` and `steady_clock::now()` are not 
> > > > measured at the same time.
> > > >Two events in the same process may have different beginningOfTime. Is 
> > > >that intended?
> > > 
> > > How would that be possible? We only compute `beginningOfTime` when 
> > > writing the data of the time profiler to a JSON file. AFAICT it happens 
> > > only once. So, this code is only called once.
> > > 
> > > >Noe that system_clock::now() and steady_clock::now() are not measured at 
> > > >the same time.
> > > I understand. But the difference should be very small (certainly less 
> > > than a microsecond), since there are only a few arithmetic operations in 
> > > between.
> > Although we could set the beginning of time in `TimeProfiler`'s constructor 
> > and assign it to a field. That would be a lot simpler, I guess. What do you 
> > think?
> OK, but I am still confused by the logic and the comment. Does the code just 
> want to compute the start time in system_clock?
Exactly, yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78030



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


[PATCH] D76594: [clang][AST] Support AST files larger than 512M

2020-04-16 Thread Dmitry Polukhin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30d5946db95f: [clang][AST] Support AST files larger than 
512M (authored by DmitryPolukhin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76594

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp

Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2434,12 +2434,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.push_back(DeclOffset(Loc, Offset));
+DeclOffsets.emplace_back(Loc, Offset);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].BitOffset = Offset;
+DeclOffsets[Index].setBitOffset(Offset);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1893,6 +1893,7 @@
   // Write out the source location entry table. We skip the first
   // entry, which is always the same dummy entry.
   std::vector SLocEntryOffsets;
+  uint64_t SLocEntryOffsetsBase = Stream.GetCurrentBitNo();
   RecordData PreloadSLocs;
   SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
   for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
@@ -1903,7 +1904,9 @@
 assert(&SourceMgr.getSLocEntry(FID) == SLoc);
 
 // Record the offset of this source-location entry.
-SLocEntryOffsets.push_back(Stream.GetCurrentBitNo());
+uint64_t Offset = Stream.GetCurrentBitNo() - SLocEntryOffsetsBase;
+assert((Offset >> 32) == 0 && "SLocEntry offset too large");
+SLocEntryOffsets.push_back(Offset);
 
 // Figure out which record code to use.
 unsigned Code;
@@ -2011,12 +2014,14 @@
   Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS));
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
   unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
   {
 RecordData::value_type Record[] = {
 SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(),
-SourceMgr.getNextLocalOffset() - 1 /* skip dummy */};
+SourceMgr.getNextLocalOffset() - 1 /* skip dummy */,
+SLocEntryOffsetsBase};
 Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
   bytes(SLocEntryOffsets));
   }
@@ -2093,9 +2098,11 @@
 /// Writes the block containing the serialized form of the
 /// preprocessor.
 void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
+  uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo();
+
   PreprocessingRecord *PPRec = PP.getPreprocessingRecord();
   if (PPRec)
-WritePreprocessorDetail(*PPRec);
+WritePreprocessorDetail(*PPRec, MacroOffsetsBase);
 
   RecordData Record;
   RecordData ModuleMacroRecord;
@@ -2156,7 +2163,8 @@
   // identifier they belong to.
   for (const IdentifierInfo *Name : MacroIdentifiers) {
 MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name);
-auto StartOffset = Stream.GetCurrentBitNo();
+uint64_t StartOffset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
+assert((StartOffset >> 32) == 0 && "Macro identifiers offset too large");
 
 // Emit the macro directives in reverse source order.
 for (; MD; MD = MD->getPrevious()) {
@@ -2229,14 +2237,12 @@
 
 // Record the local offset of this macro.
 unsigned Index = ID - FirstMacroID;
-if (Index == MacroOffsets.size())
-  MacroOffsets.push_back(Stream.GetCurrentBitNo());
-else {
-  if (Index > MacroOffsets.size())
-MacroOffsets.resize(Index + 1);
+if (Index >= MacroOffsets.size())
+  MacroOffsets.resize(Index + 1);
 
-  MacroOffsets[Index] = Stream.GetCurrentBitNo();
-}
+uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
+assert((Offset >> 32) == 0 && "Macro offset too large");
+MacroOffsets[Index] = Offset;
 
 AddIdentifierRef(Name, Record);
 AddSourceLocation(MI->getDefinitionLoc(), Record);
@@ -2287,17 +2293,20 @@
 

[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-04-16 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

In D76384#1986525 , @mibintc wrote:

> @rjmccall Can you check the patch added last night here, commit 
> 3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf 
> 
>  Author: Benjamin Kramer 
>  Date:   Thu Apr 16 11:45:02 2020 +0200
>
>   LangOptions cannot depend on ASTContext, make it not use ASTContext directly
>   
>   Fixes a layering violation introduced in 
> 2ba4e3a4598b165245c581c506a813cd4a7dce33.
>


I checked Benny's patch and it seems to have all the right semantics. The lit 
tests pass and the trailing storage is only created in the pragma case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384



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


[PATCH] D78024: [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.

2020-04-16 Thread George Rimar via Phabricator via cfe-commits
grimar marked an inline comment as done.
grimar added inline comments.



Comment at: llvm/lib/Support/FileCheck.cpp:1375-1377
+  // We do not allow using -implicit-check-not when an explicitly specified
+  // check prefix is not present in the input buffer.
+  if ((Req.IsDefaultCheckPrefix || FoundUsedPrefix) && !DagNotMatches.empty()) 
{

jdenny wrote:
> grimar wrote:
> > jdenny wrote:
> > > I find this logic confusing.  Its goal appears to be to constrain when 
> > > `DagNotMatches` are added to `CheckStrings`.  However, the real goal is 
> > > to constrain when FileCheck complains that there are no used prefixes.  
> > > Would the following logic work?
> > > 
> > > ```
> > > if (!FoundUsedPrefix && (ImplicitNegativeChecks.empty() || 
> > > !Req.IsDefaultCheckPrefix)) {
> > >   errs() << "error: no check strings found with prefix"
> > >   . . .
> > > }
> > > if (!DagNotMatches.empty()) {
> > >   CheckStrings->emplace_back(
> > >   . . .
> > > }
> > > ```
> > This looks better and works, thanks!
> > 
> > (The code above has `DagNotMatches = ImplicitNegativeChecks;` line which is 
> > also a bit confusing probably)
> > This looks better and works, thanks!
> 
> Thanks for making that change.
> 
> > (The code above has DagNotMatches = ImplicitNegativeChecks; line which is 
> > also a bit confusing probably)
> 
> I'm fine with that one.  DagNotMatches starts out as ImplicitNegativeChecks, 
> and CHECK-NOTs might be added later.
> 
> I think the second sentence in the following comment still reflects the old 
> logic:
> 
> ```
>   // When there are no used prefixes we report an error.
>   // We do not allow using -implicit-check-not when an explicitly specified
>   // check prefix is not present in the input buffer.
> ```
> 
> Something like the following seems better to me:
> 
> ```
>   // When there are no used prefixes we report an error except in the case 
> that
>   // no prefix is specified explicitly but -implicit-check-not is specified.
> ```
> 
> the real goal is to constrain when FileCheck complains that there are no used 
> prefixes

btw, do you know why FileCheck seems intentionally allows the case when 
`--check-prefixes=KNOWN,UNKNOWN`?
I've mentioned in the description of D78110 that there are about 1000 tests 
that have this. but is it a feature or a something that we might want to fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78024



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


[PATCH] D78027: [TimeProfiler] Emit real process ID and thread names

2020-04-16 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
broadwaylamb updated this revision to Diff 258059.
broadwaylamb added a comment.

Fix coding style


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

https://reviews.llvm.org/D78027

Files:
  clang/test/Driver/check-time-trace.cpp
  lld/test/ELF/time-trace.s
  llvm/lib/Support/TimeProfiler.cpp

Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -16,6 +16,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Threading.h"
 #include 
 #include 
@@ -75,7 +76,10 @@
 struct llvm::TimeTraceProfiler {
   TimeTraceProfiler(unsigned TimeTraceGranularity = 0, StringRef ProcName = "")
   : StartTime(steady_clock::now()), ProcName(ProcName),
-Tid(llvm::get_threadid()), TimeTraceGranularity(TimeTraceGranularity) {}
+Pid(sys::Process::getProcessId()), Tid(llvm::get_threadid()),
+TimeTraceGranularity(TimeTraceGranularity) {
+llvm::get_thread_name(ThreadName);
+  }
 
   void begin(std::string Name, llvm::function_ref Detail) {
 Stack.emplace_back(steady_clock::now(), TimePointType(), std::move(Name),
@@ -138,8 +142,8 @@
   auto StartUs = E.getFlameGraphStartUs(StartTime);
   auto DurUs = E.getFlameGraphDurUs();
 
-  J.object([&]{
-J.attribute("pid", 1);
+  J.object([&] {
+J.attribute("pid", Pid);
 J.attribute("tid", int64_t(Tid));
 J.attribute("ph", "X");
 J.attribute("ts", StartUs);
@@ -194,8 +198,8 @@
   auto DurUs = duration_cast(Total.second.second).count();
   auto Count = AllCountAndTotalPerName[Total.first].first;
 
-  J.object([&]{
-J.attribute("pid", 1);
+  J.object([&] {
+J.attribute("pid", Pid);
 J.attribute("tid", int64_t(TotalTid));
 J.attribute("ph", "X");
 J.attribute("ts", 0);
@@ -210,16 +214,23 @@
   ++TotalTid;
 }
 
-// Emit metadata event with process name.
-J.object([&] {
-  J.attribute("cat", "");
-  J.attribute("pid", 1);
-  J.attribute("tid", 0);
-  J.attribute("ts", 0);
-  J.attribute("ph", "M");
-  J.attribute("name", "process_name");
-  J.attributeObject("args", [&] { J.attribute("name", ProcName); });
-});
+auto writeMetadataEvent = [&](const char *Name, uint64_t Tid,
+  StringRef arg) {
+  J.object([&] {
+J.attribute("cat", "");
+J.attribute("pid", Pid);
+J.attribute("tid", int64_t(Tid));
+J.attribute("ts", 0);
+J.attribute("ph", "M");
+J.attribute("name", Name);
+J.attributeObject("args", [&] { J.attribute("name", arg); });
+  });
+};
+
+writeMetadataEvent("process_name", Tid, ProcName);
+writeMetadataEvent("thread_name", Tid, ThreadName);
+for (const TimeTraceProfiler *TTP : ThreadTimeTraceProfilerInstances)
+  writeMetadataEvent("thread_name", TTP->Tid, TTP->ThreadName);
 
 J.arrayEnd();
 J.attributeEnd();
@@ -231,6 +242,8 @@
   StringMap CountAndTotalPerName;
   const TimePointType StartTime;
   const std::string ProcName;
+  const sys::Process::Pid Pid;
+  SmallString<0> ThreadName;
   const uint64_t Tid;
 
   // Minimum time granularity (in microseconds)
Index: lld/test/ELF/time-trace.s
===
--- lld/test/ELF/time-trace.s
+++ lld/test/ELF/time-trace.s
@@ -34,6 +34,7 @@
 # Check process_name entry field
 # CHECK: "name": "ld.lld{{(.exe)?}}"
 # CHECK: "name": "process_name"
+# CHECK: "name": "thread_name"
 
 .globl _start
 _start:
Index: clang/test/Driver/check-time-trace.cpp
===
--- clang/test/Driver/check-time-trace.cpp
+++ clang/test/Driver/check-time-trace.cpp
@@ -14,6 +14,7 @@
 // CHECK-NEXT: "ts":
 // CHECK: "name": "clang{{.*}}"
 // CHECK: "name": "process_name"
+// CHECK: "name": "thread_name"
 
 template 
 struct Struct {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78190: Add Bfloat IR type

2020-04-16 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: llvm/include/llvm/IR/Constants.h:790
+  static Constant *getFP(Type *ElementType, ArrayRef Elts);
 
   /// Return a ConstantVector with the specified constant in each element.

Drive by: The documentation of these functions need to be changed and it needs 
to be clarified what would happen if you pass `double` to the `uint16_y` 
version.


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] D78030: [TimeProfiler] Emit clock synchronization point

2020-04-16 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
broadwaylamb updated this revision to Diff 258061.
broadwaylamb added a comment.

A simpler generation of the beginning of time.


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

https://reviews.llvm.org/D78030

Files:
  clang/test/Driver/check-time-trace-sections.py
  clang/test/Driver/check-time-trace.cpp
  lld/test/ELF/time-trace.s
  llvm/lib/Support/TimeProfiler.cpp

Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -75,9 +75,9 @@
 
 struct llvm::TimeTraceProfiler {
   TimeTraceProfiler(unsigned TimeTraceGranularity = 0, StringRef ProcName = "")
-  : StartTime(steady_clock::now()), ProcName(ProcName),
-Pid(sys::Process::getProcessId()), Tid(llvm::get_threadid()),
-TimeTraceGranularity(TimeTraceGranularity) {
+  : BeginningOfTime(system_clock::now()), StartTime(steady_clock::now()),
+ProcName(ProcName), Pid(sys::Process::getProcessId()),
+Tid(llvm::get_threadid()), TimeTraceGranularity(TimeTraceGranularity) {
 llvm::get_thread_name(ThreadName);
   }
 
@@ -234,12 +234,22 @@
 
 J.arrayEnd();
 J.attributeEnd();
+
+// Emit the absolute time of the moment when this TimeProfiler started
+// measurements. This can be used to combine the profiling data from
+// multiple processes and preserve actual time intervals.
+J.attribute("beginningOfTime",
+time_point_cast(BeginningOfTime)
+.time_since_epoch()
+.count());
+
 J.objectEnd();
   }
 
   SmallVector Stack;
   SmallVector Entries;
   StringMap CountAndTotalPerName;
+  const time_point BeginningOfTime;
   const TimePointType StartTime;
   const std::string ProcName;
   const sys::Process::Pid Pid;
Index: lld/test/ELF/time-trace.s
===
--- lld/test/ELF/time-trace.s
+++ lld/test/ELF/time-trace.s
@@ -18,7 +18,8 @@
 # RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 # RUN:   | FileCheck %s
 
-# CHECK: "traceEvents": [
+# CHECK:  "beginningOfTime": {{[0-9]{16},}}
+# CHECK-NEXT: "traceEvents": [
 
 # Check one event has correct fields
 # CHECK:  "dur":
Index: clang/test/Driver/check-time-trace.cpp
===
--- clang/test/Driver/check-time-trace.cpp
+++ clang/test/Driver/check-time-trace.cpp
@@ -3,18 +3,19 @@
 // RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
 
-// CHECK: "traceEvents": [
-// CHECK: "args":
-// CHECK: "detail":
-// CHECK: "dur":
-// CHECK: "name":
+// CHECK:  "beginningOfTime": {{[0-9]{16},}}
+// CHECK-NEXT: "traceEvents": [
+// CHECK:  "args":
+// CHECK:  "detail":
+// CHECK:  "dur":
+// CHECK:  "name":
 // CHECK-NEXT: "ph":
 // CHECK-NEXT: "pid":
 // CHECK-NEXT: "tid":
 // CHECK-NEXT: "ts":
-// CHECK: "name": "clang{{.*}}"
-// CHECK: "name": "process_name"
-// CHECK: "name": "thread_name"
+// CHECK:  "name": "clang{{.*}}"
+// CHECK:  "name": "process_name"
+// CHECK:  "name": "thread_name"
 
 template 
 struct Struct {
Index: clang/test/Driver/check-time-trace-sections.py
===
--- clang/test/Driver/check-time-trace-sections.py
+++ clang/test/Driver/check-time-trace-sections.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import json, sys
+import json, sys, time
 
 def is_inside(range1, range2):
 a = range1["ts"]; b = a + range1["dur"]
@@ -11,11 +11,20 @@
 b = range1["ts"] + range1["dur"]; c = range2["ts"]
 return b <= c
 
-events = json.loads(sys.stdin.read())["traceEvents"]
+log_contents = json.loads(sys.stdin.read())
+events = log_contents["traceEvents"]
 codegens = [event for event in events if event["name"] == "CodeGen Function"]
 frontends = [event for event in events if event["name"] == "Frontend"]
 backends = [event for event in events if event["name"] == "Backend"]
 
+beginning_of_time = log_contents["beginningOfTime"] / 100
+seconds_since_epoch = time.time()
+
+# Make sure that the 'beginningOfTime' is not earlier than 10 seconds ago.
+if seconds_since_epoch - beginning_of_time > 10:
+sys.exit("'beginningOfTime' should represent the absolute time when the "
+ "process has started")
+
 if not all([any([is_inside(codegen, frontend) for frontend in frontends])
 for codegen in codegens]):
 sys.exit("Not all CodeGen sections are inside any Frontend section!")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8812b0c - [NFC] Rename Sema.FPFeatures to CurFPFeatures and accessor to getCurFPFeatures

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

Author: Melanie Blower
Date: 2020-04-16T08:50:14-07:00
New Revision: 8812b0cc5cc09f350d8e89bff99f185c5e1a5d4d

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

LOG: [NFC] Rename Sema.FPFeatures to CurFPFeatures and accessor to 
getCurFPFeatures

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaPseudoObject.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 889f4ee9031e..a1a0b854a85b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -392,7 +392,7 @@ class Sema final {
   typedef OpaquePtr TypeTy;
 
   OpenCLOptions OpenCLFeatures;
-  FPOptions FPFeatures;
+  FPOptions CurFPFeatures;
 
   const LangOptions &LangOpts;
   Preprocessor &PP;
@@ -1354,8 +1354,8 @@ class Sema final {
   /// statements.
   class FPFeaturesStateRAII {
   public:
-FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
-~FPFeaturesStateRAII() { S.FPFeatures = OldFPFeaturesState; }
+FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.CurFPFeatures) {}
+~FPFeaturesStateRAII() { S.CurFPFeatures = OldFPFeaturesState; }
 
   private:
 Sema& S;
@@ -1378,7 +1378,7 @@ class Sema final {
 
   const LangOptions &getLangOpts() const { return LangOpts; }
   OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
-  FPOptions &getFPOptions() { return FPFeatures; }
+  FPOptions &getCurFPFeatures() { return CurFPFeatures; }
 
   DiagnosticsEngine &getDiagnostics() const { return Diags; }
   SourceManager &getSourceManager() const { return SourceMgr; }

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 5e5a90ad0143..405b6c33d280 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -150,7 +150,7 @@ const unsigned Sema::MaximumAlignment;
 Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter)
 : ExternalSource(nullptr), isMultiplexExternalSource(false),
-  FPFeatures(pp.getLangOpts()), LangOpts(pp.getLangOpts()), PP(pp),
+  CurFPFeatures(pp.getLangOpts()), LangOpts(pp.getLangOpts()), PP(pp),
   Context(ctxt), Consumer(consumer), Diags(PP.getDiagnostics()),
   SourceMgr(PP.getSourceManager()), CollectStats(false),
   CodeCompleter(CodeCompleter), CurContext(nullptr),

diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 9141a28381ad..8633581b6880 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -929,32 +929,32 @@ void Sema::ActOnPragmaVisibility(const IdentifierInfo* 
VisType,
 void Sema::ActOnPragmaFPContract(LangOptions::FPContractModeKind FPC) {
   switch (FPC) {
   case LangOptions::FPC_On:
-FPFeatures.setAllowFPContractWithinStatement();
+CurFPFeatures.setAllowFPContractWithinStatement();
 break;
   case LangOptions::FPC_Fast:
-FPFeatures.setAllowFPContractAcrossStatement();
+CurFPFeatures.setAllowFPContractAcrossStatement();
 break;
   case LangOptions::FPC_Off:
-FPFeatures.setDisallowFPContract();
+CurFPFeatures.setDisallowFPContract();
 break;
   }
 }
 
 void Sema::setRoundingMode(llvm::RoundingMode FPR) {
-  FPFeatures.setRoundingMode(FPR);
+  CurFPFeatures.setRoundingMode(FPR);
 }
 
 void Sema::setExceptionMode(LangOptions::FPExceptionModeKind FPE) {
-  FPFeatures.setExceptionMode(FPE);
+  CurFPFeatures.setExceptionMode(FPE);
 }
 
 void Sema::ActOnPragmaFEnvAccess(LangOptions::FEnvAccessModeKind FPC) {
   switch (FPC) {
   case LangOptions::FEA_On:
-FPFeatures.setAllowFEnvAccess();
+CurFPFeatures.setAllowFEnvAccess();
 break;
   case LangOptions::FEA_Off:
-FPFeatures.setDisallowFEnvAccess();
+CurFPFeatures.setDisallowFEnvAccess();
 break;
   }
 }

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 381db055afae..8f04f5ae5dea 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -13698,7 +13698,7 @@ buildSingleCopyAssignRecursively(Sema &S, 
SourceLocation Loc, QualType T,
   Expr *Comparison = BinaryOperator::Create(
   S.Context, IterationVarRefRVal.build(S, Loc),
   IntegerLiteral::Create(S.Context, Upper, SizeType, Loc), BO_NE,
-  S.Context.BoolTy, VK_RValue, OK_Ordinary, Loc, S.FPFeatures);
+  S.Context.BoolTy, VK_RValue, OK_Ordinary, Loc, S.CurFPFeatures);
 
   // Create the pre-increment of the iteration variable. We can de

[PATCH] D78030: [TimeProfiler] Emit clock synchronization point

2020-04-16 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
broadwaylamb added a comment.

Since we're adding a new attribute here that we won't ever be able to remove in 
the future, I'd still like to get a LGTM from some of the folks that are 
familiar with the time profiler. @russell.gallop @anton-afanasyev?


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

https://reviews.llvm.org/D78030



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


[PATCH] D78190: Add Bfloat IR type

2020-04-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/test/Assembler/bfloat-constprop.ll:1
+; RUN: opt < %s -O3 -S | FileCheck %s
+; RUN: verify-uselistorder %s

This test is doing way too much. You can reduce the to just ret fadd K0, K1



Comment at: llvm/test/Assembler/bfloat-conv.ll:1
+; RUN: opt < %s -O3 -S | FileCheck %s
+; RUN: verify-uselistorder %s

Ditto



Comment at: llvm/test/Assembler/bfloat.ll:6
+; CHECK: define bfloat @check_bfloat
+define bfloat @check_bfloat(bfloat %A) {
+; CHECK: ret bfloat %A

Ditto, all of these assembler tests can be in one file


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] D77392: [WIP][clangd] Make signatureHelp work with stale preambles

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

- Use preprocessor instead of raw lexer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77392

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -246,66 +246,6 @@
   EXPECT_EQ(2, CallbackCount);
 }
 
-static std::vector includes(const PreambleData *Preamble) {
-  std::vector Result;
-  if (Preamble)
-for (const auto &Inclusion : Preamble->Includes.MainFileIncludes)
-  Result.push_back(Inclusion.Written);
-  return Result;
-}
-
-TEST_F(TUSchedulerTests, PreambleConsistency) {
-  std::atomic CallbackCount(0);
-  {
-Notification InconsistentReadDone; // Must live longest.
-TUScheduler S(CDB, optsForTest());
-auto Path = testPath("foo.cpp");
-// Schedule two updates (A, B) and two preamble reads (stale, consistent).
-// The stale read should see A, and the consistent read should see B.
-// (We recognize the preambles by their included files).
-auto Inputs = getInputs(Path, "#include ");
-Inputs.Version = "A";
-updateWithCallback(S, Path, Inputs, WantDiagnostics::Yes, [&]() {
-  // This callback runs in between the two preamble updates.
-
-  // This blocks update B, preventing it from winning the race
-  // against the stale read.
-  // If the first read was instead consistent, this would deadlock.
-  InconsistentReadDone.wait();
-  // This delays update B, preventing it from winning a race
-  // against the consistent read. The consistent read sees B
-  // only because it waits for it.
-  // If the second read was stale, it would usually see A.
-  std::this_thread::sleep_for(std::chrono::milliseconds(100));
-});
-Inputs.Contents = "#include ";
-Inputs.Version = "B";
-S.update(Path, Inputs, WantDiagnostics::Yes);
-
-S.runWithPreamble("StaleRead", Path, TUScheduler::Stale,
-  [&](Expected Pre) {
-ASSERT_TRUE(bool(Pre));
-ASSERT_TRUE(Pre->Preamble);
-EXPECT_EQ(Pre->Preamble->Version, "A");
-EXPECT_THAT(includes(Pre->Preamble),
-ElementsAre(""));
-InconsistentReadDone.notify();
-++CallbackCount;
-  });
-S.runWithPreamble("ConsistentRead", Path, TUScheduler::Consistent,
-  [&](Expected Pre) {
-ASSERT_TRUE(bool(Pre));
-ASSERT_TRUE(Pre->Preamble);
-EXPECT_EQ(Pre->Preamble->Version, "B");
-EXPECT_THAT(includes(Pre->Preamble),
-ElementsAre(""));
-++CallbackCount;
-  });
-S.blockUntilIdle(timeoutSeconds(10));
-  }
-  EXPECT_EQ(2, CallbackCount);
-}
-
 TEST_F(TUSchedulerTests, Cancellation) {
   // We have the following update/read sequence
   //   U0
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -0,0 +1,123 @@
+//===--- PreambleTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "Compiler.h"
+#include "Preamble.h"
+#include "TestFS.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+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;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics Diags;
+  ParseInputs PI;
+  PI.FS = FS.getFileSyst

[PATCH] D78305: [NFC] Rename Sema.FPFeatures to CurFPFeatures and accessor to getCurFPFeatures

2020-04-16 Thread Melanie Blower via Phabricator via cfe-commits
mibintc created this revision.
Herald added a project: clang.

Companion patch to reviews.llvm.org/D76384  
this patch renames 2 identifiers


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78305

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaPseudoObject.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4727,7 +4727,7 @@
   WriteReferencedSelectorsPool(SemaRef);
   WriteLateParsedTemplates(SemaRef);
   WriteIdentifierTable(PP, SemaRef.IdResolver, isModule);
-  WriteFPPragmaOptions(SemaRef.getFPOptions());
+  WriteFPPragmaOptions(SemaRef.getCurFPFeatures());
   WriteOpenCLExtensions(SemaRef);
   WriteOpenCLExtensionTypes(SemaRef);
   WriteCUDAPragmas(SemaRef);
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7773,7 +7773,7 @@
   // FIXME: What happens if these are changed by a module import?
   if (!FPPragmaOptions.empty()) {
 assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS");
-SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]);
+SemaObj->CurFPFeatures = FPOptions(FPPragmaOptions[0]);
   }
 
   SemaObj->OpenCLFeatures.copy(OpenCLExtensions);
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10267,7 +10267,7 @@
 return getDerived().RebuildBinaryOperator(
 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
   Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
-  getSema().FPFeatures = E->getFPFeatures(getSema().getLangOpts());
+  getSema().CurFPFeatures = E->getFPFeatures(getSema().getLangOpts());
 
   return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
 LHS.get(), RHS.get());
@@ -10322,7 +10322,7 @@
 TreeTransform::TransformCompoundAssignOperator(
   CompoundAssignOperator *E) {
   Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
-  getSema().FPFeatures = E->getFPFeatures(getSema().getLangOpts());
+  getSema().CurFPFeatures = E->getFPFeatures(getSema().getLangOpts());
   return getDerived().TransformBinaryOperator(E);
 }
 
@@ -10797,7 +10797,7 @@
 return SemaRef.MaybeBindToTemporary(E);
 
   Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
-  getSema().FPFeatures = E->getFPFeatures();
+  getSema().CurFPFeatures = E->getFPFeatures();
 
   return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
  E->getOperatorLoc(),
Index: clang/lib/Sema/SemaPseudoObject.cpp
===
--- clang/lib/Sema/SemaPseudoObject.cpp
+++ clang/lib/Sema/SemaPseudoObject.cpp
@@ -450,7 +450,7 @@
 result = semanticRHS;
 syntactic = BinaryOperator::Create(
 S.Context, syntacticLHS, capturedRHS, opcode, capturedRHS->getType(),
-capturedRHS->getValueKind(), OK_Ordinary, opcLoc, S.FPFeatures);
+capturedRHS->getValueKind(), OK_Ordinary, opcLoc, S.CurFPFeatures);
 
   } else {
 ExprResult opLHS = buildGet();
@@ -464,7 +464,7 @@
 
 syntactic = CompoundAssignOperator::Create(
 S.Context, syntacticLHS, capturedRHS, opcode, result.get()->getType(),
-result.get()->getValueKind(), OK_Ordinary, opcLoc, S.FPFeatures,
+result.get()->getValueKind(), OK_Ordinary, opcLoc, S.CurFPFeatures,
 opLHS.get()->getType(), result.get()->getType());
   }
 
@@ -1583,7 +1583,7 @@
   if (LHS->isTypeDependent() || RHS->isTypeDependent())
 return BinaryOperator::Create(Context, LHS, RHS, opcode,
   Context.DependentTy, VK_RValue, OK_Ordinary,
-  opcLoc, FPFeatures);
+  opcLoc, CurFPFeatures);
 
   // Filter out non-overload placeholder types in the RHS.
   if (RHS->getType()->isNonOverloadPlaceholderType()) {
@@ -1646,7 +1646,7 @@
 return CompoundAssignOperator::Create(
 Context, lhs, rhs, cop->getOpcode(), cop->getType(),
 cop->getValueKind(), cop->getObjectKind(), cop->getOperatorLoc(),
-FPFeatures, cop->getComputationLHSType(),
+CurFPFeatures, cop->getComputationLHSType(),
 cop->getComputationResultType());
 
   } else if (BinaryOperator *bop = dyn_cast(syntax)) {
@@ -1655,7 +1655,7 @@
 re

[PATCH] D78286: [analyzer] Track runtime types represented by Obj-C Class objects

2020-04-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp:217-218
 
 void DynamicTypePropagation::checkDeadSymbols(SymbolReaper &SR,
   CheckerContext &C) const {
   ProgramStateRef State = removeDeadTypes(C.getState(), SR);

vsavchenko wrote:
> NoQ wrote:
> > This needs to be filled in for the new trait as well! It's very important :3
> Whoops! I forgot!
> Good catch!
But it looks like that info was not removed from the state neither for 
**dynamic types**, nor for **dynamic casts** (see the diff)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78286



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


[PATCH] D78286: [analyzer] Track runtime types represented by Obj-C Class objects

2020-04-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 258065.
vsavchenko marked 8 inline comments as done.
vsavchenko added a comment.

Fix issues pointed by @NoQ.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78286

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/DynamicType.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/class-object-state-dump.m
  clang/test/Analysis/inlining/InlineObjCClassMethod.m
  clang/test/Analysis/inlining/ObjCDynTypePopagation.m
  clang/test/Analysis/inlining/ObjCDynTypePropagation.m
  clang/test/Analysis/retain-release-inline.m

Index: clang/test/Analysis/retain-release-inline.m
===
--- clang/test/Analysis/retain-release-inline.m
+++ clang/test/Analysis/retain-release-inline.m
@@ -13,6 +13,7 @@
 // It includes the basic definitions for the test cases below.
 //===--===//
 #define NULL 0
+#define nil ((id)0)
 typedef unsigned int __darwin_natural_t;
 typedef unsigned long uintptr_t;
 typedef unsigned int uint32_t;
@@ -21,14 +22,14 @@
 typedef signed long CFIndex;
 typedef CFIndex CFByteOrder;
 typedef struct {
-CFIndex location;
-CFIndex length;
+  CFIndex location;
+  CFIndex length;
 } CFRange;
 static __inline__ __attribute__((always_inline)) CFRange CFRangeMake(CFIndex loc, CFIndex len) {
-CFRange range;
-range.location = loc;
-range.length = len;
-return range;
+  CFRange range;
+  range.location = loc;
+  range.length = len;
+  return range;
 }
 typedef const void * CFTypeRef;
 typedef const struct __CFString * CFStringRef;
@@ -91,6 +92,7 @@
 - (BOOL)isEqual:(id)object;
 - (id)retain;
 - (oneway void)release;
+- (Class)class;
 - (id)autorelease;
 - (id)init;
 @end  @protocol NSCopying  - (id)copyWithZone:(NSZone *)zone;
@@ -100,6 +102,7 @@
 @interface NSObject  {}
 + (id)allocWithZone:(NSZone *)zone;
 + (id)alloc;
++ (Class)class;
 - (void)dealloc;
 @end
 @interface NSObject (NSCoderMethods)
@@ -481,3 +484,33 @@
   [self test_inline_tiny_when_reanalyzing];
 }
 @end
+
+// Original problem: rdar://problem/50739539
+@interface MyClassThatLeaksDuringInit : NSObject
+
++ (MyClassThatLeaksDuringInit *)getAnInstance1;
++ (MyClassThatLeaksDuringInit *)getAnInstance2;
+
+@end
+
+@implementation MyClassThatLeaksDuringInit
+
++ (MyClassThatLeaksDuringInit *)getAnInstance1 {
+  return [[[MyClassThatLeaksDuringInit alloc] init] autorelease]; // expected-warning{{leak}}
+}
+
++ (MyClassThatLeaksDuringInit *)getAnInstance2 {
+  return self class] alloc] init] autorelease]; // expected-warning{{leak}}
+}
+
+- (instancetype)init {
+  if (1) {
+return nil;
+  }
+
+  if (nil != (self = [super init])) {
+  }
+  return self;
+}
+
+@end
Index: clang/test/Analysis/inlining/ObjCDynTypePropagation.m
===
--- clang/test/Analysis/inlining/ObjCDynTypePropagation.m
+++ clang/test/Analysis/inlining/ObjCDynTypePropagation.m
@@ -7,68 +7,67 @@
 PublicSubClass2 *getObj();
 
 @implementation PublicParent
-- (int) getZeroOverridden {
-   return 1;
+- (int)getZeroOverridden {
+  return 1;
 }
-- (int) getZero {
-   return 0;
+- (int)getZero {
+  return 0;
 }
 @end
 
 @implementation PublicSubClass2
-- (int) getZeroOverridden {
-   return 0;
+- (int)getZeroOverridden {
+  return 0;
 }
 
 /* Test that we get the right type from call to alloc. */
-+ (void) testAllocSelf {
++ (void)testAllocSelf {
   id a = [self alloc];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-
-+ (void) testAllocClass {
++ (void)testAllocClass {
   id a = [PublicSubClass2 alloc];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-+ (void) testAllocSuperOverriden {
++ (void)testAllocSuperOverriden {
   id a = [super alloc];
   // Evaluates to 1 in the parent.
-  clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{FALSE}} 
+  clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{FALSE}}
 }
 
-+ (void) testAllocSuper {
++ (void)testAllocSuper {
   id a = [super alloc];
   clang_analyzer_eval([a getZero] == 0); // expected-warning{{TRUE}}
 }
 
-+ (void) testAllocInit {
++ (void)testAllocInit {
   id a = [[self alloc] init];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-+ (void) testNewSelf {
++ (void)testNewSelf {
   id a = [self new];
   clang_analyzer_eval([a getZeroOverridden] == 0); // expected-warning{{TRUE}}
 }
 
-// Casting to parent should not pessimize the dynamic type. 
-+

[PATCH] D76594: [clang][AST] Support AST files larger than 512M

2020-04-16 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

I am not sure, but maybe this patch causes an undefined behavior?
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/40472/steps/check-clang%20ubsan/logs/stdio

  
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28:
 runtime error: load of misaligned address 0x7feac40a55bc for type 'const 
uint64_t' (aka 'const unsigned long'), which requires 8 byte alignment
  0x7feac40a55bc: note: pointer points here
00 00 00 00 a3 c7 01 00  00 00 00 00 0c c8 01 00  00 00 00 00 29 c8 01 00  
00 00 00 00 7a cc 01 00
^ 
  #0 0x3be2fe4 in clang::ASTReader::TypeCursorForIndex(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28
  #1 0x3be30a0 in clang::ASTReader::readTypeRecord(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6348:24
  #2 0x3bd3d4a in clang::ASTReader::GetType(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6985:26
  ...

(I am in the blamelist too of that build, so that's why I am sniffing.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76594



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


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

2020-04-16 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

The unit test you added is very welcome. However, please still extend the 
current tests (which are for the signed) also for the unsigned as well. Since 
this is a core change in the analyzer, let us wait for @NoQ as well before 
accepting it.


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] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-04-16 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

I also added this patch which is a companion to this.
commit 8812b0cc5cc09f350d8e89bff99f185c5e1a5d4d 

Author: Melanie Blower 
Date:   Thu Apr 16 08:45:26 2020 -0700

  [NFC] Rename Sema.FPFeatures to CurFPFeatures and accessor to getCurFPFeatures


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384



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


[PATCH] D77392: [WIP][clangd] Make signatureHelp work with stale preambles

2020-04-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

This is ready for another round. To summarize the current state:

- `PreamblePatch` can be create from a `ParseInput` and a `PreambleData`,
  - It will preprocessor preamble section of current file contents using a 
dummy FS to reduce cost of stat/realpaths
  - It won't populate `Resolved` path for inclusions, as we don't need them at 
this stage, and even later on. As we'll run the real preprocessor when building 
the ParsedAST, and we can collect resolved paths at that stage instead.
  - Afterwards it will diff the includes found in current contents with 
includes found in the PreambleData, and create a patch containing all the new 
includes
- `PreamblePatch` can be applied to a `CompilerInvocation`:
  - It is a no-op if contents are empty, i.e it was default constructed or 
there were no new includes.
  - Otherwise it will create an implicit include which contains patch created 
with new includes.

Things that I don't like about current state:

- We'll run processor to collect includes even when the preamble section of 
current file hasn't changed.
  - `PrecompiledPreamble` contains the contents of the preamble but it is not 
exposed, I suppose we can either expose that to get rid of extra preprocessor 
creation overhead.
- We create an extra `CompilerInvocation` and `CompilerInstance` just to run 
preprocessor and throw them away later on. I am not sure what to do about this 
:/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77392



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


[clang] a8f85da - Revert "[clang][AST] Support AST files larger than 512M"

2020-04-16 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-04-16T09:09:38-07:00
New Revision: a8f85da9f538a400dfea00e4954e403bf5f3269c

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

LOG: Revert "[clang][AST] Support AST files larger than 512M"

Bitcode file alignment is only 32-bit so 64-bit offsets need
special handling.
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28:
 runtime error: load of misaligned address 0x7fca2bcfe54c for type 'const 
uint64_t' (aka 'const unsigned long'), which requires 8 byte alignment
0x7fca2bcfe54c: note: pointer points here
  00 00 00 00 5a a6 01 00  00 00 00 00 19 a7 01 00  00 00 00 00 48 a7 01 00  00 
00 00 00 7d a7 01 00
  ^
#0 0x3be2fe4 in clang::ASTReader::TypeCursorForIndex(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28
#1 0x3be30a0 in clang::ASTReader::readTypeRecord(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6348:24
#2 0x3bd3d4a in clang::ASTReader::GetType(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6985:26
#3 0x3c5d9ae in clang::ASTDeclReader::Visit(clang::Decl*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp:533:31
#4 0x3c91cac in clang::ASTReader::ReadDeclRecord(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp:4045:10
#5 0x3bd4fb1 in clang::ASTReader::GetDecl(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:7352:5
#6 0x3bce2f9 in 
clang::ASTReader::ReadASTBlock(clang::serialization::ModuleFile&, unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:3625:22
#7 0x3bd6d75 in clang::ASTReader::ReadAST(llvm::StringRef, 
clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, 
llvm::SmallVectorImpl*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:4230:32
#8 0x3a6b415 in 
clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, 
llvm::StringRef, bool, bool, clang::Preprocessor&, clang::InMemoryModuleCache&, 
clang::ASTContext&, clang::PCHContainerReader const&, 
llvm::ArrayRef >, 
llvm::ArrayRef >, void*, bool, 
bool, bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:539:19
#9 0x3a6b00e in 
clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, bool, 
bool, void*, bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:501:18
#10 0x3abac80 in 
clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, 
clang::FrontendInputFile const&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/FrontendAction.cpp:865:12
#11 0x3a6e61c in 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:972:13
#12 0x3ba74bf in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:282:25
#13 0xa3f753 in cc1_main(llvm::ArrayRef, char const*, void*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/cc1_main.cpp:240:15
#14 0xa3a68a in ExecuteCC1Tool(llvm::SmallVectorImpl&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/driver.cpp:330:12
#15 0xa37f31 in main 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/driver.cpp:407:12
#16 0x7fca2a7032e0 in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#17 0xa21029 in _start 
(/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/clang-11+0xa21029)

This reverts commit 30d5946db95fa465d7ee6caceb2b1ff191e3727c.

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 198d8e3b4fed..323edfbf8126 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires tha

[PATCH] D76594: [clang][AST] Support AST files larger than 512M

2020-04-16 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

In D76594#1986846 , @martong wrote:

> I am not sure, but maybe this patch causes an undefined behavior?
>  
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/40472/steps/check-clang%20ubsan/logs/stdio
>
>   
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28:
>  runtime error: load of misaligned address 0x7feac40a55bc for type 'const 
> uint64_t' (aka 'const unsigned long'), which requires 8 byte alignment
>   0x7feac40a55bc: note: pointer points here
> 00 00 00 00 a3 c7 01 00  00 00 00 00 0c c8 01 00  00 00 00 00 29 c8 01 00 
>  00 00 00 00 7a cc 01 00
> ^ 
>   #0 0x3be2fe4 in clang::ASTReader::TypeCursorForIndex(unsigned int) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28
>   #1 0x3be30a0 in clang::ASTReader::readTypeRecord(unsigned int) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6348:24
>   #2 0x3bd3d4a in clang::ASTReader::GetType(unsigned int) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6985:26
>   ...
>
>
> (I am in the blamelist too of that build, so that's why I am sniffing.)


Temporary reverted in a8f85da9f538a400dfea00e4954e403bf5f3269c 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76594



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


[PATCH] D78308: [NFC][PowerPC] Refactor ppcUserFeaturesCheck()

2020-04-16 Thread Lei Huang via Phabricator via cfe-commits
lei created this revision.
lei added reviewers: nemanjai, stefanp.
Herald added subscribers: shchenz, kbarton.
Herald added a project: clang.

This function keeps growing, refactor to use lambda.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78308

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


Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -228,33 +228,23 @@
 static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
  const std::vector &FeaturesVec) {
 
-  if (llvm::find(FeaturesVec, "-vsx") != FeaturesVec.end()) {
-if (llvm::find(FeaturesVec, "+power8-vector") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower8-vector"
- << "-mno-vsx";
-  return false;
-}
+  if (llvm::find(FeaturesVec, "-vsx") == FeaturesVec.end())
+return true;
 
-if (llvm::find(FeaturesVec, "+direct-move") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mdirect-move"
- << "-mno-vsx";
+  auto CheckVSXSubfeature = [&](StringRef Feature, StringRef Option) {
+if (llvm::find(FeaturesVec, Feature) != FeaturesVec.end()) {
+  Diags.Report(diag::err_opt_not_valid_with_opt) << Option << "-mno-vsx";
   return false;
 }
+return true;
+  };
 
-if (llvm::find(FeaturesVec, "+float128") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfloat128"
- << "-mno-vsx";
-  return false;
-}
+  bool Passed = CheckVSXSubfeature("+power8-vector", "-mpower8-vector");
+  Passed |= CheckVSXSubfeature("+direct-move", "-mdirect-move");
+  Passed |= CheckVSXSubfeature("+direct-move", "-mfloat128");
+  Passed |= CheckVSXSubfeature("+direct-move", "-mpower9-vector");
 
-if (llvm::find(FeaturesVec, "+power9-vector") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower9-vector"
- << "-mno-vsx";
-  return false;
-}
-  }
-
-  return true;
+  return Passed;
 }
 
 bool PPCTargetInfo::initFeatureMap(


Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -228,33 +228,23 @@
 static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
  const std::vector &FeaturesVec) {
 
-  if (llvm::find(FeaturesVec, "-vsx") != FeaturesVec.end()) {
-if (llvm::find(FeaturesVec, "+power8-vector") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower8-vector"
- << "-mno-vsx";
-  return false;
-}
+  if (llvm::find(FeaturesVec, "-vsx") == FeaturesVec.end())
+return true;
 
-if (llvm::find(FeaturesVec, "+direct-move") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mdirect-move"
- << "-mno-vsx";
+  auto CheckVSXSubfeature = [&](StringRef Feature, StringRef Option) {
+if (llvm::find(FeaturesVec, Feature) != FeaturesVec.end()) {
+  Diags.Report(diag::err_opt_not_valid_with_opt) << Option << "-mno-vsx";
   return false;
 }
+return true;
+  };
 
-if (llvm::find(FeaturesVec, "+float128") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfloat128"
- << "-mno-vsx";
-  return false;
-}
+  bool Passed = CheckVSXSubfeature("+power8-vector", "-mpower8-vector");
+  Passed |= CheckVSXSubfeature("+direct-move", "-mdirect-move");
+  Passed |= CheckVSXSubfeature("+direct-move", "-mfloat128");
+  Passed |= CheckVSXSubfeature("+direct-move", "-mpower9-vector");
 
-if (llvm::find(FeaturesVec, "+power9-vector") != FeaturesVec.end()) {
-  Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower9-vector"
- << "-mno-vsx";
-  return false;
-}
-  }
-
-  return true;
+  return Passed;
 }
 
 bool PPCTargetInfo::initFeatureMap(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77872: [AArch32] Armv8.6-a Matrix Mult Assembly + Intrinsics

2020-04-16 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added a comment.

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

https://reviews.llvm.org/D77872



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


[PATCH] D78027: [TimeProfiler] Emit real process ID and thread names

2020-04-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/lib/Support/TimeProfiler.cpp:222
+J.attribute("pid", Pid);
+J.attribute("tid", int64_t(Tid));
+J.attribute("ts", 0);

This is not great but I guess it is ok...


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

https://reviews.llvm.org/D78027



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


[PATCH] D78162: [CodeGen] Mark inline definitions of builtins as nobuiltin only if we plan to emit them.

2020-04-16 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

Thanks for the report! Looking now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78162



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


[PATCH] D78024: [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.

2020-04-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> btw, do you know why FileCheck seems intentionally allows the case when 
> --check-prefixes=KNOWN,UNKNOWN? I've mentioned in the description of D78110 
>  that there are about 1000 tests that have 
> this. but is it a feature or a something that we might want to fix?

Confirmed. Both `FileCheck --check-prefix=KNOWN --check-prefix=UNKNOWN` and 
`FileCheck --check-prefixes=KNOWN,UNKNOWN` are allowed. This looks to me 
another bug-prone area which we should clean up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78024



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


[PATCH] D78000: [ASTImporter] Fix handling of not defined FromRecord in ImportContext(...)

2020-04-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 258084.
shafik added a comment.

- Added unit test
- Modified condition for defining `FromRecord` to  whether it has an 
`ExternalSource`


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

https://reviews.llvm.org/D78000

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/commands/expression/import_base_class_when_class_has_derived_member/TestImportBaseClassWhenClassHasDerivedMember.py
  
lldb/test/API/commands/expression/import_base_class_when_class_has_derived_member/main.cpp

Index: lldb/test/API/commands/expression/import_base_class_when_class_has_derived_member/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/import_base_class_when_class_has_derived_member/main.cpp
@@ -0,0 +1,35 @@
+struct B {
+  int dump() const;
+};
+
+int B::dump() const { return 42; }
+
+// Derived class D obtains dump() method from base class B
+struct D : public B {
+  // Introduce a TypedefNameDecl
+  using Iterator = D *;
+};
+
+struct C {
+  // This will cause use to invoke VisitTypedefNameDecl(...) when Importing
+  // the DeclContext of C.
+  // We will invoke ImportContext(...) which should force the From Decl to
+  // be defined if it not already defined. We will then Import the definition
+  // to the To Decl.
+  // This will force processing of the base class of D which allows us to see
+  // base class methods such as dump().
+  D::Iterator iter;
+
+  bool f(D *DD) {
+return true; //%self.expect_expr("DD->dump()", result_type="int", result_value="42")
+  }
+};
+
+int main() {
+  C c;
+  D d;
+
+  c.f(&d);
+
+  return 0;
+}
Index: lldb/test/API/commands/expression/import_base_class_when_class_has_derived_member/TestImportBaseClassWhenClassHasDerivedMember.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/import_base_class_when_class_has_derived_member/TestImportBaseClassWhenClassHasDerivedMember.py
@@ -0,0 +1,4 @@
+from lldbsuite.test import lldbinline
+from lldbsuite.test import decorators
+
+lldbinline.MakeInlineTest(__file__, globals())
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5922,6 +5922,72 @@
   EXPECT_TRUE(ToA);
 }
 
+struct ImportWithExternalSource : ASTImporterOptionSpecificTestBase {
+  ImportWithExternalSource() {
+Creator = [](ASTContext &ToContext, FileManager &ToFileManager,
+ ASTContext &FromContext, FileManager &FromFileManager,
+ bool MinimalImport,
+ const std::shared_ptr &SharedState) {
+  return new ASTImporter(ToContext, ToFileManager, FromContext,
+ FromFileManager, MinimalImport,
+ // We use the regular lookup.
+ /*SharedState=*/nullptr);
+};
+  }
+};
+
+/// An ExternalASTSource that keeps track of the tags is completed.
+struct SourceWithCompletedTagList : clang::ExternalASTSource {
+  std::vector &CompletedTags;
+  SourceWithCompletedTagList(std::vector &CompletedTags)
+  : CompletedTags(CompletedTags) {}
+  void CompleteType(TagDecl *Tag) override {
+auto *Record = cast(Tag);
+Record->startDefinition();
+Record->completeDefinition();
+CompletedTags.push_back(Tag);
+  }
+  void
+  FindExternalLexicalDecls(const DeclContext *DC,
+   llvm::function_ref IsKindWeWant,
+   SmallVectorImpl &Result) override {
+DC->setHasExternalLexicalStorage(true);
+  }
+};
+
+TEST_P(ImportWithExternalSource, CompleteRecordBeforeImporting) {
+  // Create an empty TU.
+  TranslationUnitDecl *FromTU = getTuDecl("", Lang_CXX, "input.cpp");
+
+  // Create and add the test ExternalASTSource.
+  std::vector CompletedTags;
+  IntrusiveRefCntPtr source =
+  new SourceWithCompletedTagList(CompletedTags);
+  clang::ASTContext &context = FromTU->getASTContext();
+  context.setExternalSource(std::move(source));
+
+  // Create a dummy class by hand with external lexical storage.
+  IdentifierInfo &Ident = context.Idents.get("test_class");
+  auto *Record = CXXRecordDecl::Create(
+  context, TTK_Class, FromTU, SourceLocation(), SourceLocation(), &Ident);
+  Record->setHasExternalLexicalStorage();
+  FromTU->addDecl(Record);
+
+  // Do a minimal import of the created class.
+  EXPECT_EQ(0U, CompletedTags.size());
+  Decl *Imported = Import(Record, Lang_CXX);
+  EXPECT_EQ(0U, CompletedTags.size());
+
+  // Import the definition of the created class.
+  llvm::Error err = findFromTU(Record)->Importer->ImportDefinition(Record);
+  EXPECT_FALSE((bool)err);
+  consumeError(std::move(err));
+
+  // Make sure the class was completed once.
+  EXPECT_EQ(1U, CompletedTags.size());
+  EXPECT_EQ(Record, Compl

[PATCH] D78000: [ASTImporter] Fix handling of not defined FromRecord in ImportContext(...)

2020-04-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik marked an inline comment as done.
shafik added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8173
+  // If a RecordDecl has base classes they won't be imported and we will
+  // be missing anything that we inherit from those bases.
+  if (FromRecord->hasExternalLexicalStorage() &&

teemperor wrote:
> I'm not sure how it can be that ASTImporter::CompleteDecl starts but never 
> finishes the decl as it does both things at once unconditionally?
> ```
> lang=c++
>   TD->startDefinition();
>   TD->setCompleteDefinition(true);
> ```
> 
> FWIW, this whole comment could just be `Ask the external source if this is 
> actually a complete record that just hasn't been completed yet` or something 
> like this. I think if we reach this point then it makes a complete sense to 
> ask the external source for more info. The explanation about the base classes 
> seems to be just a smaller detail of the whole picture here.
`TD->setCompleteDefinition(true);` just sets a flag but it does not import the 
bases, which it can not do since From is not defined. See 
`ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, 
ImportDefinitionKind Kind)` which does this after it does 
`To->startDefinition();`. So we can't really consider the definition finished 
if we don't do this. 

Do you have a better way of describing this situation?

I think it is important to describe why we don't use `CompleteDecl` since the 
other cases do.



Comment at: clang/lib/AST/ASTImporter.cpp:8173
+  // If a RecordDecl has base classes they won't be imported and we will
+  // be missing anything that we inherit from those bases.
+  if (FromRecord->hasExternalLexicalStorage() &&

martong wrote:
> shafik wrote:
> > teemperor wrote:
> > > I'm not sure how it can be that ASTImporter::CompleteDecl starts but 
> > > never finishes the decl as it does both things at once unconditionally?
> > > ```
> > > lang=c++
> > >   TD->startDefinition();
> > >   TD->setCompleteDefinition(true);
> > > ```
> > > 
> > > FWIW, this whole comment could just be `Ask the external source if this 
> > > is actually a complete record that just hasn't been completed yet` or 
> > > something like this. I think if we reach this point then it makes a 
> > > complete sense to ask the external source for more info. The explanation 
> > > about the base classes seems to be just a smaller detail of the whole 
> > > picture here.
> > `TD->setCompleteDefinition(true);` just sets a flag but it does not import 
> > the bases, which it can not do since From is not defined. See 
> > `ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, 
> > ImportDefinitionKind Kind)` which does this after it does 
> > `To->startDefinition();`. So we can't really consider the definition 
> > finished if we don't do this. 
> > 
> > Do you have a better way of describing this situation?
> > 
> > I think it is important to describe why we don't use `CompleteDecl` since 
> > the other cases do.
> > Ask the external source if this is actually a complete record that just 
> > hasn't been completed yet
> 
> FWIW this seems to be a recurring pattern, so maybe it would be worth to do 
> this not just with `RecordDecl`s but with other kind of decls. E.g. an 
> `EnumDecl` could have an external source and not  completed, couldn't it?
This is definitely more costly, for the `EnumDecl` case I don't see how we 
could get in a similar situation since we don't have inheritance. I looked over 
the `EnumDecl` members and I don't see anything that would require it be 
defined.


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

https://reviews.llvm.org/D78000



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


[PATCH] D78027: [TimeProfiler] Emit real process ID and thread names

2020-04-16 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
broadwaylamb marked an inline comment as done.
broadwaylamb added inline comments.



Comment at: llvm/lib/Support/TimeProfiler.cpp:222
+J.attribute("pid", Pid);
+J.attribute("tid", int64_t(Tid));
+J.attribute("ts", 0);

MaskRay wrote:
> This is not great but I guess it is ok...
What is?


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

https://reviews.llvm.org/D78027



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


[PATCH] D78162: [CodeGen] Mark inline definitions of builtins as nobuiltin only if we plan to emit them.

2020-04-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

The same failing assertion is tripping up Linaro's TCWG Linux kernel builds:

- 
https://ci.linaro.org/job/tcwg_kernel-bisect-llvm-master-arm-mainline-allmodconfig/33/artifact/artifacts/build-2dd17ff08165e6118e70f00e22b2c36d2d4e0a9a/03-build_linux/console.log
- 
https://ci.linaro.org/job/tcwg_kernel-bisect-llvm-master-aarch64-lts-allyesconfig/30/artifact/artifacts/build-2dd17ff08165e6118e70f00e22b2c36d2d4e0a9a/03-build_linux/console.log

Funny enough, I think I touched that assertion last as one of the final bug 
fixes to the clang-9 release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78162



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


[PATCH] D76594: [clang][AST] Support AST files larger than 512M

2020-04-16 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 258088.
DmitryPolukhin added a comment.

Split TypeOffsets to low/high parts too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76594

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp

Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2434,12 +2434,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.push_back(DeclOffset(Loc, Offset));
+DeclOffsets.emplace_back(Loc, Offset);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].BitOffset = Offset;
+DeclOffsets[Index].setBitOffset(Offset);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1893,6 +1893,7 @@
   // Write out the source location entry table. We skip the first
   // entry, which is always the same dummy entry.
   std::vector SLocEntryOffsets;
+  uint64_t SLocEntryOffsetsBase = Stream.GetCurrentBitNo();
   RecordData PreloadSLocs;
   SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
   for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
@@ -1903,7 +1904,9 @@
 assert(&SourceMgr.getSLocEntry(FID) == SLoc);
 
 // Record the offset of this source-location entry.
-SLocEntryOffsets.push_back(Stream.GetCurrentBitNo());
+uint64_t Offset = Stream.GetCurrentBitNo() - SLocEntryOffsetsBase;
+assert((Offset >> 32) == 0 && "SLocEntry offset too large");
+SLocEntryOffsets.push_back(Offset);
 
 // Figure out which record code to use.
 unsigned Code;
@@ -2011,12 +2014,14 @@
   Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS));
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
   unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
   {
 RecordData::value_type Record[] = {
 SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(),
-SourceMgr.getNextLocalOffset() - 1 /* skip dummy */};
+SourceMgr.getNextLocalOffset() - 1 /* skip dummy */,
+SLocEntryOffsetsBase};
 Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
   bytes(SLocEntryOffsets));
   }
@@ -2093,9 +2098,11 @@
 /// Writes the block containing the serialized form of the
 /// preprocessor.
 void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
+  uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo();
+
   PreprocessingRecord *PPRec = PP.getPreprocessingRecord();
   if (PPRec)
-WritePreprocessorDetail(*PPRec);
+WritePreprocessorDetail(*PPRec, MacroOffsetsBase);
 
   RecordData Record;
   RecordData ModuleMacroRecord;
@@ -2156,7 +2163,8 @@
   // identifier they belong to.
   for (const IdentifierInfo *Name : MacroIdentifiers) {
 MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name);
-auto StartOffset = Stream.GetCurrentBitNo();
+uint64_t StartOffset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
+assert((StartOffset >> 32) == 0 && "Macro identifiers offset too large");
 
 // Emit the macro directives in reverse source order.
 for (; MD; MD = MD->getPrevious()) {
@@ -2229,14 +2237,12 @@
 
 // Record the local offset of this macro.
 unsigned Index = ID - FirstMacroID;
-if (Index == MacroOffsets.size())
-  MacroOffsets.push_back(Stream.GetCurrentBitNo());
-else {
-  if (Index > MacroOffsets.size())
-MacroOffsets.resize(Index + 1);
+if (Index >= MacroOffsets.size())
+  MacroOffsets.resize(Index + 1);
 
-  MacroOffsets[Index] = Stream.GetCurrentBitNo();
-}
+uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
+assert((Offset >> 32) == 0 && "Macro offset too large");
+MacroOffsets[Index] = Offset;
 
 AddIdentifierRef(Name, Record);
 AddSourceLocation(MI->getDefinitionLoc(), Record);
@@ -2287,17 +2293,20 @@
   Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET));
   Abbrev->Ad

[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

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

In D76384#1986761 , @mibintc wrote:

> In D76384#1986525 , @mibintc wrote:
>
> > @rjmccall Can you check the patch added last night here, commit 
> > 3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf 
> > 
> >  Author: Benjamin Kramer 
> >  Date:   Thu Apr 16 11:45:02 2020 +0200
> >
> >   LangOptions cannot depend on ASTContext, make it not use ASTContext 
> > directly
> >   
> >   Fixes a layering violation introduced in 
> > 2ba4e3a4598b165245c581c506a813cd4a7dce33.
> >
>
>
> I checked Benny's patch and it seems to have all the right semantics. The lit 
> tests pass and the trailing storage is only created in the pragma case.


Looks good to me, too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384



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


[PATCH] D75479: [clangd] go-to-def on names in comments etc that are used nearby.

2020-04-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 258097.
sammccall added a comment.

Merge with existing heuristic, extracting SpelledWord struct for the analysis.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75479

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  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
@@ -685,10 +685,15 @@
 
 auto AST = TU.build();
 auto Index = TU.index();
-auto Results = locateSymbolNamedTextuallyAt(
-AST, Index.get(),
+auto Word = SpelledWord::touching(
 cantFail(sourceLocationInMainFile(AST.getSourceManager(), T.point())),
-testPath(TU.Filename));
+AST.getTokens(), AST.getLangOpts());
+if (!Word) {
+  ADD_FAILURE() << "No word touching point!" << Test;
+  continue;
+}
+auto Results =
+locateSymbolTextually(*Word, AST, Index.get(), testPath(TU.Filename));
 
 if (!WantDecl) {
   EXPECT_THAT(Results, IsEmpty()) << Test;
@@ -788,10 +793,12 @@
   auto TU = TestTU::withCode(T.code());
   auto AST = TU.build();
   auto Index = TU.index();
-  auto Results = locateSymbolNamedTextuallyAt(
-  AST, Index.get(),
+  auto Word = SpelledWord::touching(
   cantFail(sourceLocationInMainFile(AST.getSourceManager(), T.point())),
-  testPath(TU.Filename));
+  AST.getTokens(), AST.getLangOpts());
+  ASSERT_TRUE(Word);
+  auto Results =
+  locateSymbolTextually(*Word, AST, Index.get(), testPath(TU.Filename));
   EXPECT_THAT(Results,
   UnorderedElementsAre(Sym("uniqueMethodName", T.range("FooLoc")),
Sym("uniqueMethodName", T.range("BarLoc";
@@ -985,6 +992,94 @@
   ElementsAre(Sym("foo", FooWithoutHeader.range(;
 }
 
+TEST(LocateSymbol, NearbyTokenSmoke) {
+  auto T = Annotations(R"cpp(
+// prints e^rr and crashes
+void die(const char* [[err]]);
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  // We don't pass an index, so can't hit index-based fallback.
+  EXPECT_THAT(locateSymbolAt(AST, T.point()),
+  ElementsAre(Sym("err", T.range(;
+}
+
+TEST(LocateSymbol, NearbyIdentifier) {
+  const char *Tests[] = {
+  R"cpp(
+  // regular identifiers (won't trigger)
+  int hello;
+  int y = he^llo;
+)cpp",
+  R"cpp(
+  // disabled preprocessor sections
+  int [[hello]];
+  #if 0
+  int y = ^hello;
+  #endif
+)cpp",
+  R"cpp(
+  // comments
+  // he^llo, world
+  int [[hello]];
+)cpp",
+  R"cpp(
+  // string literals
+  int [[hello]];
+  const char* greeting = "h^ello, world";
+)cpp",
+
+  R"cpp(
+  // can refer to macro invocations (even if they expand to nothing)
+  #define INT int
+  [[INT]] x;
+  // I^NT
+)cpp",
+
+  R"cpp(
+  // prefer nearest occurrence
+  int hello;
+  int x = hello;
+  // h^ello
+  int y = [[hello]];
+  int z = hello;
+)cpp",
+
+  R"cpp(
+  // short identifiers find near results
+  int [[hi]];
+  // h^i
+)cpp",
+  R"cpp(
+  // short identifiers don't find far results
+  int hi;
+
+
+
+  // h^i
+)cpp",
+  };
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto AST = TestTU::withCode(T.code()).build();
+const auto &SM = AST.getSourceManager();
+llvm::Optional Nearby;
+auto Word =
+SpelledWord::touching(cantFail(sourceLocationInMainFile(SM, T.point())),
+  AST.getTokens(), AST.getLangOpts());
+if (!Word) {
+  ADD_FAILURE() << "No word at point! " << Test;
+  continue;
+}
+if (const auto *Tok = findNearbyIdentifier(*Word, AST.getTokens()))
+  Nearby = halfOpenToRange(SM, CharSourceRange::getCharRange(
+   Tok->location(), Tok->endLocation()));
+if (T.ranges().empty())
+  EXPECT_THAT(Nearby, Eq(llvm::None)) << Test;
+else
+  EXPECT_THAT(Nearby, T.range()) << Test;
+  }
+}
+
 TEST(FindReferences, WithinAST) {
   const char *Tests[] = {
   R"cpp(// Local variable
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -16,6 +16,7 @@
 #include "FormattedString.h"
 #include "Path.h"
 #include "Protocol.h"
+#include "SourceCode.h"
 #include "index/Index.h"
 #include "index/SymbolLocation.h"
 #include "clang/AST/Type.h"
@@ -26,6 +27,10 @@
 #include 
 
 namespace clang {
+namespace syntax {
+class Token;
+class TokenBuffer;
+

[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-04-16 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 258092.
gamesh411 added a comment.

Add ambiguous compilation database test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/CrossTU/CMakeLists.txt
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/Inputs/ctu-other.c
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/ctu-different-triples.cpp
  clang/test/Analysis/ctu-main.c
  clang/test/Analysis/ctu-main.cpp
  clang/test/Analysis/ctu-on-demand-parsing-ambigous-compilation-database.c
  clang/test/Analysis/ctu-on-demand-parsing.c
  clang/test/Analysis/ctu-on-demand-parsing.cpp
  clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -7,10 +7,11 @@
 //===--===//
 
 #include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/Frontend/CompilerInstance.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ToolOutputFile.h"
@@ -162,7 +163,7 @@
   IndexFile.os().flush();
   EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
   llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "");
+  parseCrossTUIndex(IndexFileName);
   EXPECT_TRUE((bool)IndexOrErr);
   llvm::StringMap ParsedIndex = IndexOrErr.get();
   for (const auto &E : Index) {
@@ -173,25 +174,5 @@
 EXPECT_TRUE(Index.count(E.getKey()));
 }
 
-TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
-  llvm::StringMap Index;
-  Index["a"] = "/b/c/d";
-  std::string IndexText = createCrossTUIndexString(Index);
-
-  int IndexFD;
-  llvm::SmallString<256> IndexFileName;
-  ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
-  IndexFileName));
-  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
-  IndexFile.os() << IndexText;
-  IndexFile.os().flush();
-  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "/ctudir");
-  EXPECT_TRUE((bool)IndexOrErr);
-  llvm::StringMap ParsedIndex = IndexOrErr.get();
-  EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
-}
-
 } // end namespace cross_tu
 } // end namespace clang
Index: clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
===
--- clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
+++ clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
@@ -5,7 +5,7 @@
 // RUN: mkdir -p %t/ctudir
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
 // RUN:   -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
-// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.txt %t/ctudir/externalDefMap.txt
+// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-linux-gnu \
 // RUN:   -analyzer-checker=core,debug.ExprInspection \
 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
Index: clang/test/Analysis/ctu-on-demand-parsing.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-on-demand-parsing.cpp
@@ -0,0 +1,102 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/ctudir
+// RUN: cp %s %t/ctu-on-demand-parsing.cpp
+// RUN: cp %S/ctu-hdr.h %t/ctu-hdr.h
+// RUN: cp %S/Inputs/ctu-chain.cpp %t/ctudir/ctu-chain.cpp
+// RUN: cp %S/Inputs/ctu-other.cpp %t/ctudir/ctu-other.cpp
+// Path substitutions on Windows platform could contain backslashes. These are escaped in the json file.
+// RUN: echo '[{"directory":"%t/ctudir","command":"clang++ -c ctu-chain.cpp","file":"ctu-chain.cpp"},{"directory":"%t/ctudir","command":"clang++ -c ctu-other.cpp","file":"ctu-other.cpp"}]' | sed -e 's/\\//g' > %t/compile_commands.json
+// RUN: cd "%t/ctudir" && %clang_extdef_map ctu-chain.cpp ctu-other.cpp > externalDefMap.txt
+// RUN: cd "%t" && %clang_analyze_cc

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

2020-04-16 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I'm impressed.
Though, I had some nits, please don't take it to heart :)

And consider joining the to the pre-merge beta testing 
 project to benefit from buildbots 
and much more - for free.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:217
+
+  const llvm::APSInt sampleValue = getMinValue();
+  const bool isUnsigned = sampleValue.isUnsigned();

Should we take it as `const ref` to prevent copying?



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:235
+// handle a special case for MIN value
+if (isFromMinValue) {
+  // if [from, to] are [MIN, MAX], then just return the same [MIN, MAX]

AFAIK in a `RangeSet` the ranges are sorted by the `From` point in ascending 
order.
We should not check it for each range, only for the first.

Also, note that small and flat loops are more readable.
Consider using //pure// lambdas to reduce the body of the loop and of course to 
bind algorithms to names.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:572-573
   if (const RangeSet *negV = State->get(negSym)) {
-// Unsigned range set cannot be negated, unless it is [0, 0].
-if ((negV->getConcreteValue() &&
- (*negV->getConcreteValue() == 0)) ||
+if (T->isUnsignedIntegerOrEnumerationType() ||
 T->isSignedIntegerOrEnumerationType())
   return negV;

Couldn't we simplify the disjunction to single `T->isEnumerationType()` or to 
something similar?



Comment at: clang/test/Analysis/constraint_manager_negate_difference.c:114-118
+void negated_unsigned_range(unsigned x, unsigned y) {
+  clang_analyzer_eval(x - y != 0); // expected-warning{{FALSE}} 
expected-warning{{TRUE}}
+  clang_analyzer_eval(y - x != 0); // expected-warning{{FALSE}} 
expected-warning{{TRUE}}
+  clang_analyzer_eval(x - y != 0); // expected-warning{{FALSE}} 
expected-warning{{TRUE}}
+}

What does this test case demonstrate? Could you elaborate on that?
Why do you evaluate the `x - y != 0` here twice?



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:23
+template  struct TestCase {
+  RangeSet original;
+  RangeSet expected;

According to the [LLVM coding 
style](https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)
 we should use UpperCamelCase for variable names for new code.

Note that the Analyzer Core was written in a different style, we should follow 
that there instead (at least IMO).



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)),

AFAIK since `std::initializer_list` is just two pointers we should take it by 
value.



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

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.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:66
+  template  void checkNegate() {
+using type = T;
+

To be honest, I'm not sure if `type` is more descriptive than `T`.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:68
+
+// use next values of the range {MIN, A, B, MID, C, D, MAX}
+

AFAIK full sentences are required for comments.
https://llvm.org/docs/CodingStandards.html#commenting



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());

Should we keep this?


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] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-04-16 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 258110.
ZarkoCA added a comment.

Added a TODO to remove the error for `msvr4-struct-return` on AIX when we 
verify it works as expected.


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 inbounds ([1024 x i8], [1024 x i8]* @dwarf_reg_size_table, i64 0, i64 30), align 1
-// CHECK-NEXT: store i

[PATCH] D78294: [Fixed Point] Move the compassign LHS type correction a bit further down. NFCI.

2020-04-16 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan accepted this revision.
leonardchan 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/D78294/new/

https://reviews.llvm.org/D78294



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


  1   2   >