Re: r324419 - [Lex] Fix handling numerical literals ending with ' and signed exponent.

2018-02-08 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r324579.

On Tue, Feb 6, 2018 at 11:39 PM, Volodymyr Sapsai via cfe-commits
 wrote:
> Author: vsapsai
> Date: Tue Feb  6 14:39:25 2018
> New Revision: 324419
>
> URL: http://llvm.org/viewvc/llvm-project?rev=324419&view=rev
> Log:
> [Lex] Fix handling numerical literals ending with ' and signed exponent.
>
> For input `0'e+1` lexer tokenized as numeric constant only `0'e`. Later
> NumericLiteralParser skipped 0 and ' as digits and parsed `e+1` as valid
> exponent going past the end of the token. Because it didn't mark numeric
> literal as having an error, it continued parsing and tried to expandUCNs
> with StringRef of length -2.
>
> The fix is not to parse exponent when we reached the end of token.
>
> Discovered by OSS-Fuzz:
> https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4588
>
> rdar://problem/36076719
>
> Reviewers: rsmith, t.p.northover
>
> Reviewed By: rsmith
>
> Subscribers: cfe-commits, jkorous-apple
>
> Differential Revision: https://reviews.llvm.org/D41834
>
> Modified:
> cfe/trunk/lib/Lex/LiteralSupport.cpp
> cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp
>
> Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=324419&r1=324418&r2=324419&view=diff
> ==
> --- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
> +++ cfe/trunk/lib/Lex/LiteralSupport.cpp Tue Feb  6 14:39:25 2018
> @@ -738,15 +738,17 @@ void NumericLiteralParser::ParseDecimalO
>  s++;
>  radix = 10;
>  saw_exponent = true;
> -if (*s == '+' || *s == '-')  s++; // sign
> +if (s != ThisTokEnd && (*s == '+' || *s == '-'))  s++; // sign
>  const char *first_non_digit = SkipDigits(s);
>  if (containsDigits(s, first_non_digit)) {
>checkSeparator(TokLoc, s, CSK_BeforeDigits);
>s = first_non_digit;
>  } else {
> -  PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
> -  diag::err_exponent_has_no_digits);
> -  hadError = true;
> +  if (!hadError) {
> +PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
> +diag::err_exponent_has_no_digits);
> +hadError = true;
> +  }
>return;
>  }
>}
> @@ -787,10 +789,12 @@ void NumericLiteralParser::checkSeparato
>} else if (Pos == ThisTokEnd)
>  return;
>
> -  if (isDigitSeparator(*Pos))
> +  if (isDigitSeparator(*Pos)) {
>  PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Pos - ThisTokBegin),
>  diag::err_digit_separator_not_between_digits)
><< IsAfterDigits;
> +hadError = true;
> +  }
>  }
>
>  /// ParseNumberStartingWithZero - This method is called when the first 
> character
> @@ -840,12 +844,14 @@ void NumericLiteralParser::ParseNumberSt
>const char *Exponent = s;
>s++;
>saw_exponent = true;
> -  if (*s == '+' || *s == '-')  s++; // sign
> +  if (s != ThisTokEnd && (*s == '+' || *s == '-'))  s++; // sign
>const char *first_non_digit = SkipDigits(s);
>if (!containsDigits(s, first_non_digit)) {
> -PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
> -diag::err_exponent_has_no_digits);
> -hadError = true;
> +if (!hadError) {
> +  PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
> +  diag::err_exponent_has_no_digits);
> +  hadError = true;
> +}
>  return;
>}
>checkSeparator(TokLoc, s, CSK_BeforeDigits);
>
> Modified: cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp?rev=324419&r1=324418&r2=324419&view=diff
> ==
> --- cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp (original)
> +++ cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp Tue Feb  6 14:39:25 2018
> @@ -51,6 +51,8 @@ namespace floating {
>float u = 0x.'p1f; // expected-error {{hexadecimal floating literal 
> requires a significand}}
>float v = 0e'f; // expected-error {{exponent has no digits}}
>float w = 0x0p'f; // expected-error {{exponent has no digits}}
> +  float x = 0'e+1; // expected-error {{digit separator cannot appear at end 
> of digit sequence}}
> +  float y = 0x0'p+1; // expected-error {{digit separator cannot appear at 
> end of digit sequence}}
>  }
>
>  #line 123'456
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42987: [libc++abi] fix compilation in C++17 mode

2018-02-08 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

@rsmith. Sorry, you're right. I didn't notice that we already used 
`_LIBCPP_BUILDING_LIBRARY` in libc++abi.  I wasn't sure if `_BUILDING_LIBRARY` 
changed the linkage or of any symbols, or changed their explicit instantiation.
And, indeed, on Windows there's a problem with DLL import/export macros. I'll 
fix and cleanup the usage of `_BUILDING_LIBRARY` in the next couple days.


Repository:
  rL LLVM

https://reviews.llvm.org/D42987



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


[PATCH] D42957: [clang-format] Do not break before long string literals in protos

2018-02-08 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D42957



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


[PATCH] D43065: [clangd] Remove threading-related code from ClangdUnit.h

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: sammccall, hokein, ioeric.
Herald added subscribers: jkorous-apple, klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43065

Files:
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/TUScheduler.cpp

Index: clangd/TUScheduler.cpp
===
--- clangd/TUScheduler.cpp
+++ clangd/TUScheduler.cpp
@@ -48,6 +48,7 @@
 #include "llvm/Support/Errc.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -66,16 +67,16 @@
 /// worker.
 class ASTWorker {
   friend class ASTWorkerHandle;
-  ASTWorker(Semaphore &Barrier, std::shared_ptr AST, bool RunSync);
+  ASTWorker(Semaphore &Barrier, CppFile AST, bool RunSync);
 
 public:
   /// Create a new ASTWorker and return a handle to it.
   /// The processing thread is spawned using \p Tasks. However, when \p Tasks
   /// is null, all requests will be processed on the calling thread
   /// synchronously instead. \p Barrier is acquired when processing each
   /// request, it is be used to limit the number of actively running threads.
   static ASTWorkerHandle Create(AsyncTaskRunner *Tasks, Semaphore &Barrier,
-std::shared_ptr AST);
+CppFile AST);
   ~ASTWorker();
 
   void update(ParseInputs Inputs,
@@ -102,11 +103,14 @@
   const bool RunSync;
   Semaphore &Barrier;
   // AST and FileInputs are only accessed on the processing thread from run().
-  const std::shared_ptr AST;
+  CppFile AST;
   // Inputs, corresponding to the current state of AST.
   ParseInputs FileInputs;
   // Guards members used by both TUScheduler and the worker thread.
   mutable std::mutex Mutex;
+  std::shared_ptr LastBuiltPreamble; /* GUARDED_BY(Mutex) */
+  // Result of getUsedBytes() after the last rebuild or read of AST.
+  std::size_t LastASTSize; /* GUARDED_BY(Mutex) */
   // Set to true to signal run() to finish processing.
   bool Done;   /* GUARDED_BY(Mutex) */
   std::queue Requests; /* GUARDED_BY(Mutex) */
@@ -159,17 +163,16 @@
 };
 
 ASTWorkerHandle ASTWorker::Create(AsyncTaskRunner *Tasks, Semaphore &Barrier,
-  std::shared_ptr AST) {
+  CppFile AST) {
   std::shared_ptr Worker(
   new ASTWorker(Barrier, std::move(AST), /*RunSync=*/!Tasks));
   if (Tasks)
 Tasks->runAsync([Worker]() { Worker->run(); });
 
   return ASTWorkerHandle(std::move(Worker));
 }
 
-ASTWorker::ASTWorker(Semaphore &Barrier, std::shared_ptr AST,
- bool RunSync)
+ASTWorker::ASTWorker(Semaphore &Barrier, CppFile AST, bool RunSync)
 : RunSync(RunSync), Barrier(Barrier), AST(std::move(AST)), Done(false) {
   if (RunSync)
 return;
@@ -193,7 +196,14 @@
   return;
 }
 FileInputs = Inputs;
-auto Diags = AST->rebuild(std::move(Inputs));
+auto Diags = AST.rebuild(std::move(Inputs));
+
+{
+  std::lock_guard Lock(Mutex);
+  if (AST.getPreamble())
+LastBuiltPreamble = AST.getPreamble();
+  LastASTSize = AST.getUsedBytes();
+}
 // We want to report the diagnostics even if this update was cancelled.
 // It seems more useful than making the clients wait indefinitely if they
 // spam us with updates.
@@ -208,33 +218,33 @@
 void ASTWorker::runWithAST(
 UniqueFunction)> Action) {
   auto Task = [=](decltype(Action) Action) {
-auto ASTWrapper = this->AST->getAST().get();
-// FIXME: no need to lock here, cleanup the CppFile interface to get rid of
-// them.
-ASTWrapper->runUnderLock([&](ParsedAST *AST) {
-  if (!AST) {
-Action(llvm::make_error(
-"invalid AST", llvm::errc::invalid_argument));
-return;
-  }
-  Action(InputsAndAST{FileInputs, *AST});
-});
+ParsedAST *ActualAST = AST.getAST();
+if (!ActualAST) {
+  Action(llvm::make_error("invalid AST",
+ llvm::errc::invalid_argument));
+  return;
+}
+Action(InputsAndAST{FileInputs, *ActualAST});
+
+// Size of the AST might have changed after reads too, e.g. if some decls
+// were deserialized from preamble.
+std::lock_guard Lock(Mutex);
+LastASTSize = ActualAST->getUsedBytes();
   };
 
   startTask(BindWithForward(Task, std::move(Action)), /*isUpdate=*/false,
 llvm::None);
 }
 
 std::shared_ptr
 ASTWorker::getPossiblyStalePreamble() const {
-  return AST->getPossiblyStalePreamble();
+  std::lock_guard Lock(Mutex);
+  return LastBuiltPreamble;
 }
 
 std::size_t ASTWorker::getUsedBytes() const {
-  // FIXME(ibiryukov): we'll need to take locks here after we remove
-  // thread-safety from CppFile. For now, CppFile is thread-safe and we can
-  // safely call methods on it without acquiring a lock.
-  return AST->getUsedBytes();
+  std::lock_guard Lock(Mutex);
+  return LastASTSize;
 }
 
 void AS

[PATCH] D43013: ASan+operator new[]: Fix operator new[] cookie poisoning

2018-02-08 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added a comment.

In https://reviews.llvm.org/D43013#1001006, @rjmccall wrote:

> I don't understand why your description of this patch mentions the void* 
> placement new[] operator.  There's no cookie to poison for that operator.


Hah, sorry. In writing this commit log I used parts of the old patch one. I'll 
update with a better commit log.


Repository:
  rC Clang

https://reviews.llvm.org/D43013



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


[PATCH] D43013: ASan+operator new[]: Fix operator new[] cookie poisoning

2018-02-08 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab updated this revision to Diff 133389.
filcab added a comment.

Update commit message.


Repository:
  rC Clang

https://reviews.llvm.org/D43013

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/address-sanitizer-and-array-cookie.cpp


Index: test/CodeGen/address-sanitizer-and-array-cookie.cpp
===
--- test/CodeGen/address-sanitizer-and-array-cookie.cpp
+++ test/CodeGen/address-sanitizer-and-array-cookie.cpp
@@ -1,13 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - %s | FileCheck %s 
-check-prefix=PLAIN
 // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address 
%s | FileCheck %s -check-prefix=ASAN
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address 
-fsanitize-address-poison-class-member-array-new-cookie %s | FileCheck %s 
-check-prefix=ASAN-POISON-ALL-NEW-ARRAY
 
 typedef __typeof__(sizeof(0)) size_t;
 namespace std {
   struct nothrow_t {};
   std::nothrow_t nothrow;
 }
 void *operator new[](size_t, const std::nothrow_t &) throw();
 void *operator new[](size_t, char *);
+void *operator new[](size_t, int, int);
 
 struct C {
   int x;
@@ -53,3 +55,10 @@
 }
 // ASAN-LABEL: CallPlacementNew
 // ASAN-NOT: __asan_poison_cxx_array_cookie
+
+C *CallNewWithArgs() {
+// ASAN-LABEL: CallNewWithArgs
+// ASAN-NOT: call void @__asan_poison_cxx_array_cookie
+// ASAN-POISON-ALL-NEW-ARRAY: call void @__asan_poison_cxx_array_cookie
+  return new (123, 456) C[20];
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -890,6 +890,13 @@
   Opts.SanitizeCfiICallGeneralizePointers =
   Args.hasArg(OPT_fsanitize_cfi_icall_generalize_pointers);
   Opts.SanitizeStats = Args.hasArg(OPT_fsanitize_stats);
+  if (Arg *A = Args.getLastArg(
+  OPT_fsanitize_address_poison_class_member_array_new_cookie,
+  OPT_fno_sanitize_address_poison_class_member_array_new_cookie)) {
+Opts.SanitizeAddressPoisonClassMemberArrayNewCookie =
+A->getOption().getID() ==
+OPT_fsanitize_address_poison_class_member_array_new_cookie;
+  }
   if (Arg *A = Args.getLastArg(OPT_fsanitize_address_use_after_scope,
OPT_fno_sanitize_address_use_after_scope)) {
 Opts.SanitizeAddressUseAfterScope =
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1848,7 +1848,8 @@
 
   // Handle the array cookie specially in ASan.
   if (CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) && AS == 0 &&
-  expr->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
+  (expr->getOperatorNew()->isReplaceableGlobalAllocationFunction() ||
+   CGM.getCodeGenOpts().SanitizeAddressPoisonClassMemberArrayNewCookie)) {
 // The store to the CookiePtr does not need to be instrumented.
 CGM.getSanitizerMetadata()->disableSanitizerForInstruction(SI);
 llvm::FunctionType *FTy =
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -159,6 +159,9 @@
 CODEGENOPT(SaveTempLabels, 1, 0) ///< Save temporary labels.
 CODEGENOPT(SanitizeAddressUseAfterScope , 1, 0) ///< Enable use-after-scope 
detection
 ///< in AddressSanitizer
+CODEGENOPT(SanitizeAddressPoisonClassMemberArrayNewCookie, 1,
+   0) ///< Enable poisoning operator new[] which is not a replaceable
+  ///< global allocation function in AddressSanitizer
 CODEGENOPT(SanitizeAddressGlobalsDeadStripping, 1, 0) ///< Enable linker dead 
stripping
   ///< of globals in 
AddressSanitizer
 CODEGENOPT(SanitizeMemoryTrackOrigins, 2, 0) ///< Enable tracking origins in
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -895,6 +895,14 @@
Group,
Flags<[CoreOption, DriverOption]>,
HelpText<"Disable use-after-scope 
detection in AddressSanitizer">;
+def fsanitize_address_poison_class_member_array_new_cookie
+: Flag<[ "-" ], "fsanitize-address-poison-class-member-array-new-cookie">,
+  Group,
+  HelpText<"Enable poisoning array cookies when using class member 
operator new[] in AddressSanitizer">;
+def fno_sanitize_address_poison_class_member_array_new_cookie
+: Flag<[ "-" ], 
"fno-san

r324591 - [clang-format] Do not break before long string literals in protos

2018-02-08 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Feb  8 02:47:12 2018
New Revision: 324591

URL: http://llvm.org/viewvc/llvm-project?rev=324591&view=rev
Log:
[clang-format] Do not break before long string literals in protos

Summary:
This patch is a follow-up to r323319 (which disables string literal breaking for
text protos) and it disables breaking before long string literals.

For example this:
```
key: "long string literal"
```
used to get broken into:
```
key:
"long string literal"
```

While at it, I also enabled it for LK_Proto and fixed a bug in the mustBreak 
code.

Reviewers: djasper, sammccall

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=324591&r1=324590&r2=324591&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Feb  8 02:47:12 2018
@@ -1992,7 +1992,7 @@ bool ContinuationIndenter::nextIsMultili
   if (Current.getNextNonComment() &&
   Current.getNextNonComment()->isStringLiteral())
 return true; // Implicit concatenation.
-  if (Style.ColumnLimit != 0 &&
+  if (Style.ColumnLimit != 0 && Style.BreakStringLiterals &&
   State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
   Style.ColumnLimit)
 return true; // String will be split.

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=324591&r1=324590&r2=324591&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Feb  8 02:47:12 2018
@@ -686,11 +686,6 @@ FormatStyle getGoogleStyle(FormatStyle::
 FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_Proto);
 GoogleStyle.Language = FormatStyle::LK_TextProto;
 
-// Text protos are currently mostly formatted inside C++ raw string 
literals
-// and often the current breaking behavior of string literals is not
-// beneficial there. Investigate turning this on once proper string reflow
-// has been implemented.
-GoogleStyle.BreakStringLiterals = false;
 return GoogleStyle;
   }
 
@@ -762,6 +757,12 @@ FormatStyle getGoogleStyle(FormatStyle::
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
 GoogleStyle.Cpp11BracedListStyle = false;
+// This affects protocol buffer options specifications and text protos.
+// Text protos are currently mostly formatted inside C++ raw string 
literals
+// and often the current breaking behavior of string literals is not
+// beneficial there. Investigate turning this on once proper string reflow
+// has been implemented.
+GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
   }

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=324591&r1=324590&r2=324591&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Feb  8 02:47:12 2018
@@ -2830,11 +2830,17 @@ bool TokenAnnotator::canBreakBefore(cons
   if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) &&
   Left.isNot(TT_SelectorName))
 return true;
+
   if (Right.is(tok::colon) &&
   !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon))
 return false;
-  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr))
+  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
+if ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+Right.isStringLiteral())
+  return false;
 return true;
+  }
   if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next &&
 Right.Next->is(TT_ObjCMethodExpr)))
 return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=324591&r1=324590&r2=324591&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/tr

[PATCH] D42957: [clang-format] Do not break before long string literals in protos

2018-02-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324591: [clang-format] Do not break before long string 
literals in protos (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42957

Files:
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -306,5 +306,12 @@
   "  }\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "foo: {\n"
+  "  text: \"aaasaa\"\n"
+  "}");
+}
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -412,5 +412,14 @@
"}");
 }
 
+TEST_F(FormatTestProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "option (MyProto.options) = {\n"
+  "  foo: {\n"
+  "text: \"aaas\"\n"
+  "  }\n"
+  "}");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2830,11 +2830,17 @@
   if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) &&
   Left.isNot(TT_SelectorName))
 return true;
+
   if (Right.is(tok::colon) &&
   !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon))
 return false;
-  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr))
+  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
+if ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+Right.isStringLiteral())
+  return false;
 return true;
+  }
   if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next &&
 Right.Next->is(TT_ObjCMethodExpr)))
 return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -1992,7 +1992,7 @@
   if (Current.getNextNonComment() &&
   Current.getNextNonComment()->isStringLiteral())
 return true; // Implicit concatenation.
-  if (Style.ColumnLimit != 0 &&
+  if (Style.ColumnLimit != 0 && Style.BreakStringLiterals &&
   State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
   Style.ColumnLimit)
 return true; // String will be split.
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -686,11 +686,6 @@
 FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_Proto);
 GoogleStyle.Language = FormatStyle::LK_TextProto;
 
-// Text protos are currently mostly formatted inside C++ raw string literals
-// and often the current breaking behavior of string literals is not
-// beneficial there. Investigate turning this on once proper string reflow
-// has been implemented.
-GoogleStyle.BreakStringLiterals = false;
 return GoogleStyle;
   }
 
@@ -762,6 +757,12 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
 GoogleStyle.Cpp11BracedListStyle = false;
+// This affects protocol buffer options specifications and text protos.
+// Text protos are currently mostly formatted inside C++ raw string literals
+// and often the current breaking behavior of string literals is not
+// beneficial there. Investigate turning this on once proper string reflow
+// has been implemented.
+GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43016: Fix for #31362 - ms_abi is implemented incorrectly for larger values (>=16 bytes).

2018-02-08 Thread Alexander Ivchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324594: Fix for #31362 - ms_abi is implemented incorrectly 
for values >=16 bytes. (authored by aivchenk, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43016

Files:
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/test/CodeGen/ms_abi.c


Index: cfe/trunk/test/CodeGen/ms_abi.c
===
--- cfe/trunk/test/CodeGen/ms_abi.c
+++ cfe/trunk/test/CodeGen/ms_abi.c
@@ -146,3 +146,16 @@
   // WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
   // WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
 }
+
+// This test checks if structs are passed according to Win64 calling convention
+// when it's enforced by __attribute((ms_abi)).
+struct i128 {
+  unsigned long long a;
+  unsigned long long b;
+};
+
+__attribute__((ms_abi)) struct i128 f7(struct i128 a) {
+  // WIN64: define void @f7(%struct.i128* noalias sret %agg.result, 
%struct.i128* %a)
+  // FREEBSD: define win64cc void @f7(%struct.i128* noalias sret %agg.result, 
%struct.i128* %a)
+  return a;
+}
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -3529,7 +3529,17 @@
 
 void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
 
-  bool IsRegCall = FI.getCallingConvention() == llvm::CallingConv::X86_RegCall;
+  const unsigned CallingConv = FI.getCallingConvention();
+  // It is possible to force Win64 calling convention on any x86_64 target by
+  // using __attribute__((ms_abi)). In such case to correctly emit Win64
+  // compatible code delegate this call to WinX86_64ABIInfo::computeInfo.
+  if (CallingConv == llvm::CallingConv::Win64) {
+WinX86_64ABIInfo Win64ABIInfo(CGT);
+Win64ABIInfo.computeInfo(FI);
+return;
+  }
+
+  bool IsRegCall = CallingConv == llvm::CallingConv::X86_RegCall;
 
   // Keep track of the number of assigned registers.
   unsigned FreeIntRegs = IsRegCall ? 11 : 6;


Index: cfe/trunk/test/CodeGen/ms_abi.c
===
--- cfe/trunk/test/CodeGen/ms_abi.c
+++ cfe/trunk/test/CodeGen/ms_abi.c
@@ -146,3 +146,16 @@
   // WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
   // WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
 }
+
+// This test checks if structs are passed according to Win64 calling convention
+// when it's enforced by __attribute((ms_abi)).
+struct i128 {
+  unsigned long long a;
+  unsigned long long b;
+};
+
+__attribute__((ms_abi)) struct i128 f7(struct i128 a) {
+  // WIN64: define void @f7(%struct.i128* noalias sret %agg.result, %struct.i128* %a)
+  // FREEBSD: define win64cc void @f7(%struct.i128* noalias sret %agg.result, %struct.i128* %a)
+  return a;
+}
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -3529,7 +3529,17 @@
 
 void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
 
-  bool IsRegCall = FI.getCallingConvention() == llvm::CallingConv::X86_RegCall;
+  const unsigned CallingConv = FI.getCallingConvention();
+  // It is possible to force Win64 calling convention on any x86_64 target by
+  // using __attribute__((ms_abi)). In such case to correctly emit Win64
+  // compatible code delegate this call to WinX86_64ABIInfo::computeInfo.
+  if (CallingConv == llvm::CallingConv::Win64) {
+WinX86_64ABIInfo Win64ABIInfo(CGT);
+Win64ABIInfo.computeInfo(FI);
+return;
+  }
+
+  bool IsRegCall = CallingConv == llvm::CallingConv::X86_RegCall;
 
   // Keep track of the number of assigned registers.
   unsigned FreeIntRegs = IsRegCall ? 11 : 6;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43016: Fix for #31362 - ms_abi is implemented incorrectly for larger values (>=16 bytes).

2018-02-08 Thread Alexander Ivchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC324594: Fix for #31362 - ms_abi is implemented incorrectly 
for values >=16 bytes. (authored by aivchenk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43016?vs=133198&id=133395#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43016

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/ms_abi.c


Index: test/CodeGen/ms_abi.c
===
--- test/CodeGen/ms_abi.c
+++ test/CodeGen/ms_abi.c
@@ -146,3 +146,16 @@
   // WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
   // WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
 }
+
+// This test checks if structs are passed according to Win64 calling convention
+// when it's enforced by __attribute((ms_abi)).
+struct i128 {
+  unsigned long long a;
+  unsigned long long b;
+};
+
+__attribute__((ms_abi)) struct i128 f7(struct i128 a) {
+  // WIN64: define void @f7(%struct.i128* noalias sret %agg.result, 
%struct.i128* %a)
+  // FREEBSD: define win64cc void @f7(%struct.i128* noalias sret %agg.result, 
%struct.i128* %a)
+  return a;
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -3529,7 +3529,17 @@
 
 void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
 
-  bool IsRegCall = FI.getCallingConvention() == llvm::CallingConv::X86_RegCall;
+  const unsigned CallingConv = FI.getCallingConvention();
+  // It is possible to force Win64 calling convention on any x86_64 target by
+  // using __attribute__((ms_abi)). In such case to correctly emit Win64
+  // compatible code delegate this call to WinX86_64ABIInfo::computeInfo.
+  if (CallingConv == llvm::CallingConv::Win64) {
+WinX86_64ABIInfo Win64ABIInfo(CGT);
+Win64ABIInfo.computeInfo(FI);
+return;
+  }
+
+  bool IsRegCall = CallingConv == llvm::CallingConv::X86_RegCall;
 
   // Keep track of the number of assigned registers.
   unsigned FreeIntRegs = IsRegCall ? 11 : 6;


Index: test/CodeGen/ms_abi.c
===
--- test/CodeGen/ms_abi.c
+++ test/CodeGen/ms_abi.c
@@ -146,3 +146,16 @@
   // WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
   // WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
 }
+
+// This test checks if structs are passed according to Win64 calling convention
+// when it's enforced by __attribute((ms_abi)).
+struct i128 {
+  unsigned long long a;
+  unsigned long long b;
+};
+
+__attribute__((ms_abi)) struct i128 f7(struct i128 a) {
+  // WIN64: define void @f7(%struct.i128* noalias sret %agg.result, %struct.i128* %a)
+  // FREEBSD: define win64cc void @f7(%struct.i128* noalias sret %agg.result, %struct.i128* %a)
+  return a;
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -3529,7 +3529,17 @@
 
 void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
 
-  bool IsRegCall = FI.getCallingConvention() == llvm::CallingConv::X86_RegCall;
+  const unsigned CallingConv = FI.getCallingConvention();
+  // It is possible to force Win64 calling convention on any x86_64 target by
+  // using __attribute__((ms_abi)). In such case to correctly emit Win64
+  // compatible code delegate this call to WinX86_64ABIInfo::computeInfo.
+  if (CallingConv == llvm::CallingConv::Win64) {
+WinX86_64ABIInfo Win64ABIInfo(CGT);
+Win64ABIInfo.computeInfo(FI);
+return;
+  }
+
+  bool IsRegCall = CallingConv == llvm::CallingConv::X86_RegCall;
 
   // Keep track of the number of assigned registers.
   unsigned FreeIntRegs = IsRegCall ? 11 : 6;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41992: [libcxx] Avoid spurious construction of valarray elements

2018-02-08 Thread Mikhail Maltsev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX324596: [libcxx] Avoid spurious construction of valarray 
elements (authored by miyuki, committed by ).

Repository:
  rCXX libc++

https://reviews.llvm.org/D41992

Files:
  include/valarray
  
test/std/numerics/numarray/template.valarray/valarray.assign/copy_assign.pass.cpp
  
test/std/numerics/numarray/template.valarray/valarray.assign/initializer_list_assign.pass.cpp
  test/std/numerics/numarray/template.valarray/valarray.cons/default.pass.cpp
  test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp

Index: include/valarray
===
--- include/valarray
+++ include/valarray
@@ -1053,6 +1053,9 @@
 friend
 const _Up*
 end(const valarray<_Up>& __v);
+
+void __clear();
+valarray& __assign_range(const value_type* __f, const value_type* __l);
 };
 
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray::valarray(size_t))
@@ -2750,7 +2753,24 @@
 : __begin_(0),
   __end_(0)
 {
-resize(__n);
+if (__n)
+{
+__begin_ = __end_ = static_cast(_VSTD::__allocate(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+try
+{
+#endif  // _LIBCPP_NO_EXCEPTIONS
+for (; __n; --__n, ++__end_)
+::new (__end_) value_type();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+}
+catch (...)
+{
+__clear();
+throw;
+}
+#endif  // _LIBCPP_NO_EXCEPTIONS
+}
 }
 
 template 
@@ -2780,7 +2800,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2805,7 +2825,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2842,7 +2862,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2870,7 +2890,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2899,7 +2919,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2928,7 +2948,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2957,7 +2977,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2968,30 +2988,43 @@
 inline
 valarray<_Tp>::~valarray()
 {
-resize(0);
+__clear();
 }
 
 template 
 valarray<_Tp>&
-valarray<_Tp>::operator=(const valarray& __v)
+valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
 {
-if (this != &__v)
+size_t __n = __l - __f;
+if (size() != __n)
 {
-if (size() != __v.size())
-resize(__v.size());
-_VSTD::copy(__v.__begin_, __v.__end_, __begin_);
+__clear();
+__begin_ = static_cast(_VSTD::__allocate(__n * sizeof(value_type)));
+__end_ = __begin_ + __n;
+_VSTD::uninitialized_copy(__f, __l, __begin_);
+} else {
+_VSTD::copy(__f, __l, __begin_);
 }
 return *this;
 }
 
+template 
+valarray<_Tp>&
+valarray<_Tp>::operator=(const valarray& __v)
+{
+if (this != &__v)
+return __assign_range(__v.__begin_, __v.__end_);
+return *this;
+}
+
 #ifndef _LIBCPP_CXX03_LANG
 
 template 
 inline
 valarray<_Tp>&
 valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
 {
-resize(0);
+__clear();
 __begin_ = __v.__begin_;
 __end_ = __v.__end_;
 __v.__begin_ = nullptr;
@@ -3004,10 +3037,7 @@
 valarray<_Tp>&
 valarray<_Tp>::operator=(initializer_list __il)
 {
-if (size() != __il.size())
-resize(__il.size());
-_VSTD::copy(__il.begin(), __il.end(), __begin_);
-return *this;
+return __assign_range(__il.begin(), __il.end());
 }
 
 #endif  // _LIBCPP_CXX03_LANG
@@ -3680,15 +3710,22 @@
 
 template 
 void
-valarray<_Tp>::resize(size_t __n, value_type __x)
+valarray<_Tp>::__clear()
 {
 if (__begin_ != nullptr)
 {
 while (__end_ != __begin_)
 (--__end_)->~value_type();
 _VSTD::__libcpp_deallocate(__begin_);
 __begin_ = __end_ = nullptr;
 }
+}
+
+template 
+void
+valarray<_Tp>::resize(size_t __n, value_type __x)
+{
+__clear();
 if (__n)
 {
 __begin_ = __end_ = static_cast(_VSTD::__allocate(__n * sizeof(value_type)));
@@ -3702,7 +3739,7 @@
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
Inde

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang-c/Index.h:6159
+   */
+  CXSymbolRole role;
 } CXIdxEntityRefInfo;

MaskRay wrote:
> ilya-biryukov wrote:
> > Why do we need to store both `CXIdxEntityRefKind` and `CXSymbolRole`? Can 
> > we store just `CXSymbolRole`?
> > Is this for compatibility with existing clients?
> > 
> > If so, maybe we could:
> > - remove `Implicit` and `Direct` from the `CXSymbolRole`
> > - keep it only in `CXIdxEntityRefKind`
> > - not deprecate the `CXIdxEntityRefKind`
> I think `CXIdxEntityRefKind` should be deprecated but for compatibility we do 
> not remove the field for this minor version upgrade. But they can be removed 
> after a major version upgrade.
> 
> For what I have observed, `Implicit` is only used by Objective-C
We should definitely loop the owners of libclang in if we want to deprecate the 
API, I'm not familiar with the contract of libclang regarding the API 
deprecation.
I'm not sure who's responsible for that, asking at the cfe-dev mailing list 
could be your best bet for that.

The alternative I suggest is removing `Implicit` from `CXSymbolRole`, making 
this change an extension of existing API. I expect that this could be done 
without more through discussion.



Comment at: tools/libclang/CXIndexDataConsumer.cpp:154
+  // CXSymbolRole is synchronized with clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role));
+}

MaskRay wrote:
> ilya-biryukov wrote:
> > `SymbolRoleSet` seems to have more roles not covered by `CXSymbolRole`.
> > Should they be accepted by this function? 
> > If yes, maybe zero those bits?
> > If no, maybe add an assert?
> > 
> > 
> > The extra roles are:
> > ```
> >   RelationChildOf = 1 << 9,
> >   RelationBaseOf  = 1 << 10,
> >   RelationOverrideOf  = 1 << 11,
> >   RelationReceivedBy  = 1 << 12,
> >   RelationCalledBy= 1 << 13,
> >   RelationExtendedBy  = 1 << 14,
> >   RelationAccessorOf  = 1 << 15,
> >   RelationContainedBy = 1 << 16,
> >   RelationIBTypeOf= 1 << 17,
> >   RelationSpecializationOf = 1 << 18,
> > ```
> Yes, it has more relations, but most are only used by Objective-C. In all 
> test/Index tests, I have only seen `RelationContainedBy` used for .cpp files. 
> Many have not occurred in .m files. So I do not want to expose them, at least 
> for now.
> 
> 
It's fine, but let's add a comment and zero those bits out.

Could you also a comments to both `SymbolRoleSet` and `CXSymbolRole` that they 
mirror each other and need to be updated together?


Repository:
  rC Clang

https://reviews.llvm.org/D42895



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


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2018-02-08 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

Ok, I've found my issue. inttypes.h in libcxx include_next's , 
which on my debian linux systems has the include chain , , 
.  "helpfully" provides #defines of the various _ABIXXX 
macros, which normally the compiler defines depending on the ABI. The include 
chain for other parts of libunwind differ which means 
src/UnwindLevel1-gcc-ext.c had a different definition of the stuct 
unw_context_t, which was the version defined for O32. As GCC and clang laid out 
the stack differently for each ABI differently the bug was masked. However for 
N32 at https://reviews.llvm.org/owners/package/3/, the layout was such that the 
unwind context in the locals area was right below the saved registers for 
_Unwind_Backtrace which trashed older saved values, then triggered a SIGSEGV on 
return due to reloading the saved contents of the $lo  into $ra in my case.

The fix is fairly simple. Change the ABI #ifdef defined() checks to be:

  #ifdef _defined(_ABIO32) && _MIPS_SIM == _ABIO32

for O32 or similar for a single ABI. For N32 and N64 together, it's sufficient 
to test for the presence of __mips64.




Comment at: include/__libunwind_config.h:74
 # elif defined(__mips__)
 #  if defined(_ABIO32) && defined(__mips_soft_float)
 #define _LIBUNWIND_TARGET_MIPS_O32 1

See my comment about the N32 abi check.



Comment at: include/__libunwind_config.h:78
 #define _LIBUNWIND_CURSOR_SIZE 24
+#  elif defined(_ABIN32) && defined(__mips_soft_float)
+#define _LIBUNWIND_TARGET_MIPS_NEWABI 1

This needs to be:

 
```
   #elif defined(_ABIN32) && _MIPS_SIM == _ABIN32
```



Comment at: include/__libunwind_config.h:82
+#define _LIBUNWIND_CURSOR_SIZE 42
 #  elif defined(_ABI64) && defined(__mips_soft_float)
 #define _LIBUNWIND_TARGET_MIPS_NEWABI 1

Same here.



Comment at: src/AddressSpace.hpp:233
+inline uint64_t LocalAddressSpace::getRegister(pint_t addr) {
+#if __SIZEOF_POINTER__ == 8 || (defined(__mips__) && defined(_ABIN32))
+  return get64(addr);

Change that mips check to defined(__mips64) which covers the target being mips 
and it being n64 or n32.



Comment at: src/UnwindRegistersRestore.S:688
 
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32)) &&
\
+defined(__mips_soft_float)

Rather checking that the _ABI64 or _ABIN32 are defined, check that __mips64 is 
defined.



Comment at: src/UnwindRegistersSave.S:175
 
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32)) &&
\
+defined(__mips_soft_float)

See my comment on register restore file.



Comment at: src/libunwind.cpp:66
 # define REGISTER_KIND Registers_mips_o32
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABIN32) || defined(_ABI64)) &&
\
+defined(__mips_soft_float)

Check that __mips64 is defined rather than the specific _ABI macros.


https://reviews.llvm.org/D39074



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


[PATCH] D5767: Template Instantiation Observer + a few other templight-related changes

2018-02-08 Thread Ábel Sinkovics via Phabricator via cfe-commits
sabel83 updated this revision to Diff 133400.
sabel83 marked an inline comment as done.

https://reviews.llvm.org/D5767

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendActions.h
  include/clang/Frontend/FrontendOptions.h
  include/clang/FrontendTool/Utils.h
  include/clang/Sema/Sema.h
  include/clang/Sema/TemplateInstCallback.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/FrontendActions.cpp
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  lib/Parse/ParseAST.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/SemaType.cpp
  test/Templight/templight-deduced-func.cpp
  test/Templight/templight-default-arg-inst.cpp
  test/Templight/templight-default-func-arg.cpp
  test/Templight/templight-default-template-arg.cpp
  test/Templight/templight-exception-spec-func.cpp
  test/Templight/templight-explicit-template-arg.cpp
  test/Templight/templight-memoization.cpp
  test/Templight/templight-nested-memoization.cpp
  test/Templight/templight-nested-template-instantiation.cpp
  test/Templight/templight-one-instantiation.cpp
  test/Templight/templight-prior-template-arg.cpp

Index: test/Templight/templight-prior-template-arg.cpp
===
--- test/Templight/templight-prior-template-arg.cpp
+++ test/Templight/templight-prior-template-arg.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -templight-dump %s 2>&1 | FileCheck %s
+template
+class A {};
+
+template  class Outer>
+class B {};
+
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B::Outer'$}}
+// CHECK: {{^kind:[ ]+PriorTemplateArgumentSubstitution$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:5:40'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:1'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B::Outer'$}}
+// CHECK: {{^kind:[ ]+PriorTemplateArgumentSubstitution$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:5:40'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:1'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^orig:[ ]+'.*templight-prior-template-arg.cpp:6:7'}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:72:6'$}}
+B b;
Index: test/Templight/templight-one-instantiation.cpp
===
--- test/Templight/templight-one-instantiation.cpp
+++ test/Templight/templight-one-instantiation.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -templight-dump %s 2>&1 | FileCheck %s
+
+template 
+struct foo {};
+
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'foo'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^orig:[ ]+'.*templight-one-instantiation.cpp:4:8'}}
+// CHECK: {{^poi:[ ]+'.*templight-one-instantiation.cpp:18:10'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'foo'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^eve

[PATCH] D43068: [clangd] Remove codeComplete that returns std::future<>

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: hokein, ioeric, sammccall.
Herald added subscribers: jkorous-apple, klimek.

It was deprecated and callback version and is used everywhere.
Only changes to the testing code were needed.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43068

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/SyncAPI.h

Index: unittests/clangd/SyncAPI.h
===
--- /dev/null
+++ unittests/clangd/SyncAPI.h
@@ -0,0 +1,34 @@
+//===--- SyncAPI.h - Sync version of ClangdServer's API --*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H
+
+#include "ClangdServer.h"
+#include 
+
+namespace clang {
+namespace clangd {
+inline Tagged
+runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
+clangd::CodeCompleteOptions Opts,
+llvm::Optional OverridenContents = llvm::None) {
+  std::promise> Promise;
+  auto Future = Promise.get_future();
+  auto SetResult = [](decltype(Promise) Promise, Tagged Value) {
+Promise.set_value(std::move(Value));
+  };
+  Server.codeComplete(File, Pos, Opts,
+  BindWithForward(SetResult, std::move(Promise)),
+  OverridenContents);
+  return Future.get();
+}
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -14,6 +14,7 @@
 #include "Matchers.h"
 #include "Protocol.h"
 #include "SourceCode.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "index/MemIndex.h"
 #include "gmock/gmock.h"
@@ -121,8 +122,7 @@
   auto File = getVirtualTestFilePath("foo.cpp");
   Annotations Test(Text);
   Server.addDocument(File, Test.code()).wait();
-  auto CompletionList =
-  Server.codeComplete(File, Test.point(), Opts).get().Value;
+  auto CompletionList = runCodeComplete(Server, File, Test.point(), Opts).Value;
   // Sanity-check that filterText is valid.
   EXPECT_THAT(CompletionList.items, Each(NameContainsFilter()));
   return CompletionList;
@@ -348,10 +348,8 @@
 
   Annotations Example("int cbc; int b = ^;");
   auto Results =
-  Server
-  .codeComplete(File, Example.point(), clangd::CodeCompleteOptions(),
-StringRef(Example.code()))
-  .get()
+  runCodeComplete(Server, File, Example.point(),
+  clangd::CodeCompleteOptions(), StringRef(Example.code()))
   .Value;
   EXPECT_THAT(Results.items, Contains(Named("cbc")));
 }
@@ -556,17 +554,17 @@
   Server.addDocument(File, Test.code()).wait();
   clangd::CodeCompleteOptions Opts = {};
 
-  auto WithoutIndex = Server.codeComplete(File, Test.point(), Opts).get().Value;
+  auto WithoutIndex = runCodeComplete(Server, File, Test.point(), Opts).Value;
   EXPECT_THAT(WithoutIndex.items,
   UnorderedElementsAre(Named("local"), Named("preamble")));
 
   auto I = memIndex({var("ns::index")});
   Opts.Index = I.get();
-  auto WithIndex = Server.codeComplete(File, Test.point(), Opts).get().Value;
+  auto WithIndex = runCodeComplete(Server, File, Test.point(), Opts).Value;
   EXPECT_THAT(WithIndex.items,
   UnorderedElementsAre(Named("local"), Named("index")));
   auto ClassFromPreamble =
-  Server.codeComplete(File, Test.point("2"), Opts).get().Value;
+  runCodeComplete(Server, File, Test.point("2"), Opts).Value;
   EXPECT_THAT(ClassFromPreamble.items, Contains(Named("member")));
 }
 
@@ -595,7 +593,7 @@
   )cpp");
   Server.addDocument(File, Test.code()).wait();
 
-  auto Results = Server.codeComplete(File, Test.point(), {}).get().Value;
+  auto Results = runCodeComplete(Server, File, Test.point(), {}).Value;
   // "XYZ" and "foo" are not included in the file being completed but are still
   // visible through the index.
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -9,6 +9,7 @@
 
 #include "ClangdLSPServer.h"
 #include "ClangdServer.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "clang/Config/config.h"
 #include "llvm/ADT/SmallVector.h"
@@ -301,14 +302,14 @@
   // thread.
   FS.Tag = "123";
   Server.addDocument(FooCpp, SourceContents);
-  EXPECT_EQ(Server.codeComplete(FooCpp, Pos

[clang-tools-extra] r324599 - [clangd] Update include guard in Annotations.h. NFC

2018-02-08 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Feb  8 04:46:34 2018
New Revision: 324599

URL: http://llvm.org/viewvc/llvm-project?rev=324599&view=rev
Log:
[clangd] Update include guard in Annotations.h. NFC

Modified:
clang-tools-extra/trunk/unittests/clangd/Annotations.h

Modified: clang-tools-extra/trunk/unittests/clangd/Annotations.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/Annotations.h?rev=324599&r1=324598&r2=324599&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/Annotations.h (original)
+++ clang-tools-extra/trunk/unittests/clangd/Annotations.h Thu Feb  8 04:46:34 
2018
@@ -27,8 +27,8 @@
 // to define general overlapping ranges.
 //
 //===-===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_ANNOTATIONS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_ANNOTATIONS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_ANNOTATIONS_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_ANNOTATIONS_H
 #include "Protocol.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"


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


[PATCH] D42530: Clang permits assignment to vector/extvector elements in a const method

2018-02-08 Thread Andrew V. Tischenko via Phabricator via cfe-commits
avt77 updated this revision to Diff 133404.
avt77 added a comment.

I propagated qualifiers accordingly to rjmccall's suggestion. But I changed the 
diagnostic: now it's more realistic from my point of view.


https://reviews.llvm.org/D42530

Files:
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprMember.cpp
  test/Sema/assign.c
  test/Sema/typedef-retain.c
  test/SemaCXX/err_typecheck_assign_const.cpp

Index: test/SemaCXX/err_typecheck_assign_const.cpp
===
--- test/SemaCXX/err_typecheck_assign_const.cpp
+++ test/SemaCXX/err_typecheck_assign_const.cpp
@@ -129,3 +129,23 @@
   Func &bar();
   bar()() = 0; // expected-error {{read-only variable is not assignable}}
 }
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+struct OhNo {
+  float4 v;
+  void AssignMe() const { v.x = 1; } // expected-error {{cannot assign to non-static data member within const member function 'AssignMe'}} \
+expected-note {{member function 'OhNo::AssignMe' is declared const here}}
+};
+
+typedef float float4_2 __attribute__((__vector_size__(16)));
+struct OhNo2 {
+  float4_2 v;
+  void AssignMe() const { v[0] = 1; } // expected-error {{cannot assign to non-static data member within const member function 'AssignMe'}} \
+expected-note {{member function 'OhNo2::AssignMe' is declared const here}}
+};
+
+struct OhNo3 {
+  float v[4];
+  void AssignMe() const { v[0] = 1; } // expected-error {{cannot assign to non-static data member within const member function 'AssignMe'}} \
+expected-note {{member function 'OhNo3::AssignMe' is declared const here}}
+};
Index: test/Sema/typedef-retain.c
===
--- test/Sema/typedef-retain.c
+++ test/Sema/typedef-retain.c
@@ -16,8 +16,8 @@
 typedef int a[5];
 void test3() {
   typedef const a b;
-  b r;
-  r[0]=10;  // expected-error {{read-only variable is not assignable}}
+  b r;   // expected-note {{variable 'r' declared const here}}
+  r[0] = 10; // expected-error {{cannot assign to variable 'r' with const-qualified type 'b' (aka 'int const[5]')}}
 }
 
 int test4(const a y) {
Index: test/Sema/assign.c
===
--- test/Sema/assign.c
+++ test/Sema/assign.c
@@ -11,10 +11,10 @@
 
 typedef int arr[10];
 void test3() {
-  const arr b;
-  const int b2[10]; 
-  b[4] = 1; // expected-error {{read-only variable is not assignable}}
-  b2[4] = 1; // expected-error {{read-only variable is not assignable}}
+  const arr b;  // expected-note {{variable 'b' declared const here}}
+  const int b2[10]; // expected-note {{variable 'b2' declared const here}}
+  b[4] = 1; // expected-error {{cannot assign to variable 'b' with const-qualified type 'const arr' (aka 'int const[10]')}}
+  b2[4] = 1;// expected-error {{cannot assign to variable 'b2' with const-qualified type 'const int [10]'}}
 }
 
 typedef struct I {
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -1623,10 +1623,14 @@
   else
 VK = BaseExpr.get()->getValueKind();
 }
+
 QualType ret = CheckExtVectorComponent(S, BaseType, VK, OpLoc,
Member, MemberLoc);
 if (ret.isNull())
   return ExprError();
+Qualifiers BaseQ =
+S.Context.getCanonicalType(BaseExpr.get()->getType()).getQualifiers();
+ret = S.Context.getQualifiedType(ret, BaseQ);
 
 return new (S.Context)
 ExtVectorElementExpr(ret, VK, BaseExpr.get(), *Member, MemberLoc);
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -4395,8 +4395,14 @@
 if (VK != VK_RValue)
   OK = OK_VectorComponent;
 
-// FIXME: need to deal with const...
 ResultType = VTy->getElementType();
+QualType BaseType = BaseExpr->getType();
+Qualifiers BaseQuals = BaseType.getQualifiers();
+Qualifiers MemberQuals =
+Context.getCanonicalType(ResultType).getQualifiers();
+Qualifiers Combined = BaseQuals + MemberQuals;
+if (Combined != MemberQuals)
+  ResultType = Context.getQualifiedType(ResultType, Combined);
   } else if (LHSTy->isArrayType()) {
 // If we see an array that wasn't promoted by
 // DefaultFunctionArrayLvalueConversion, it must be an array that
@@ -10434,8 +10440,16 @@
 // Static fields do not inherit constness from parents.
 break;
   }
-  break;
-} // End MemberExpr
+  break; // End MemberExpr
+} else if (const ArraySubscriptExpr *ASE =
+   dyn_cast(E)) {
+  E = ASE->getBase()->IgnoreParenImpCasts();
+  continue;
+} else if (const ExtVectorElementExpr *EVE =
+

[PATCH] D42978: Make march/target-cpu print a note with the list of valid values for ARM

2018-02-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 133276.
erichkeane retitled this revision from "Make march/target-cpu print a note with 
the list of valid values" to "Make march/target-cpu print a note with the list 
of valid values for ARM".
erichkeane edited the summary of this revision.

https://reviews.llvm.org/D42978

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets.cpp
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/AArch64.h
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/ARM.h
  test/Misc/target-invalid-cpu-note.c

Index: test/Misc/target-invalid-cpu-note.c
===
--- /dev/null
+++ test/Misc/target-invalid-cpu-note.c
@@ -0,0 +1,8 @@
+// RUN: not %clang_cc1 -triple armv5--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix ARM
+// ARM: error: unknown target CPU 'not-a-cpu'
+// ARM: note: valid target CPU values are: arm2, arm3, arm6, arm7m, arm8, arm810, strongarm, strongarm110, strongarm1100, strongarm1110, arm7tdmi, arm7tdmi-s, arm710t, arm720t, arm9, arm9tdmi, arm920, arm920t, arm922t, arm9312, arm940t, ep9312, arm10tdmi, arm1020t, arm9e, arm946e-s, arm966e-s, arm968e-s, arm10e, arm1020e, arm1022e, arm926ej-s, arm1136j-s, arm1136jf-s, arm1136jz-s, arm1176j-s, arm1176jz-s, mpcore, mpcorenovfp, arm1176jzf-s, arm1156t2-s, arm1156t2f-s, cortex-m0, cortex-m0plus, cortex-m1, sc000, cortex-a5, cortex-a7, cortex-a8, cortex-a9, cortex-a12, cortex-a15, cortex-a17, krait, cortex-r4, cortex-r4f, cortex-r5, cortex-r7, cortex-r8, cortex-r52, sc300, cortex-m3, cortex-m4, cortex-m7, cortex-m23, cortex-m33, cortex-a32, cortex-a35, cortex-a53, cortex-a55, cortex-a57, cortex-a72, cortex-a73, cortex-a75, cyclone, exynos-m1, exynos-m2, exynos-m3, kryo, iwmmxt, xscale, swift
+
+// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AARCH64
+// AARCH64: error: unknown target CPU 'not-a-cpu'
+// AARCH64: note: valid target CPU values are: cortex-a35, cortex-a53, cortex-a55, cortex-a57, cortex-a72, cortex-a73, cortex-a75, cyclone, exynos-m1, exynos-m2, exynos-m3, falkor, saphira, kryo, thunderx2t99, thunderx, thunderxt88, thunderxt81, thunderxt83
+
Index: lib/Basic/Targets/ARM.h
===
--- lib/Basic/Targets/ARM.h
+++ lib/Basic/Targets/ARM.h
@@ -122,6 +122,8 @@
   bool hasFeature(StringRef Feature) const override;
 
   bool isValidCPUName(StringRef Name) const override;
+  void fillValidCPUList(SmallVectorImpl &Values) const override;
+
   bool setCPU(const std::string &Name) override;
 
   bool setFPMath(StringRef Name) override;
Index: lib/Basic/Targets/ARM.cpp
===
--- lib/Basic/Targets/ARM.cpp
+++ lib/Basic/Targets/ARM.cpp
@@ -478,6 +478,10 @@
  llvm::ARM::parseCPUArch(Name) != llvm::ARM::ArchKind::INVALID;
 }
 
+void ARMTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const {
+  llvm::ARM::fillValidCPUArchList(Values);
+}
+
 bool ARMTargetInfo::setCPU(const std::string &Name) {
   if (Name != "generic")
 setArchInfo(llvm::ARM::parseCPUArch(Name));
Index: lib/Basic/Targets/AArch64.h
===
--- lib/Basic/Targets/AArch64.h
+++ lib/Basic/Targets/AArch64.h
@@ -46,6 +46,7 @@
   bool setABI(const std::string &Name) override;
 
   bool isValidCPUName(StringRef Name) const override;
+  void fillValidCPUList(SmallVectorImpl &Values) const override;
   bool setCPU(const std::string &Name) override;
 
   bool useFP16ConversionIntrinsics() const override {
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -101,6 +101,11 @@
   return isValidCPUName(Name);
 }
 
+void AArch64TargetInfo::fillValidCPUList(
+SmallVectorImpl &Values) const {
+  llvm::AArch64::fillValidCPUArchList(Values);
+}
+
 void AArch64TargetInfo::getTargetDefinesARMV81A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -38,6 +38,7 @@
 #include "Targets/X86.h"
 #include "Targets/XCore.h"
 #include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Triple.h"
 
 using namespace clang;
@@ -607,6 +608,10 @@
   // Set the target CPU if specified.
   if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
 Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
+SmallVector ValidList;
+Target->fillValidCPUList(ValidList);
+if (!ValidList.empty())
+  Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", ");
 return nullptr;
   

[PATCH] D42978: Make march/target-cpu print a note with the list of valid values for ARM

2018-02-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

I think this means that the Clang test needs to be updated whenever somebody 
adds an architecture to LLVM? Maybe just test that Clang emits a note and don't 
check which values it prints? These should be checked in the backend...


https://reviews.llvm.org/D42978



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


[PATCH] D42978: Make march/target-cpu print a note with the list of valid values for ARM

2018-02-08 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In https://reviews.llvm.org/D42978#1001616, @Hahnfeld wrote:

> I think this means that the Clang test needs to be updated whenever somebody 
> adds an architecture to LLVM? Maybe just test that Clang emits a note and 
> don't check which values it prints? These should be checked in the backend...


Yes, I agree checking all  CPUs names is too fragile and not necessary for 
AArch64 or ARM, as the list of CPUs is provided by llvm.

It is probably enough to check if we emit the note for AArch64 and ARM and 
maybe check that it is non-empty or checking that it contains a CPU we know 
should always be there. Checking the full list may make sense for other 
backends, as we have to modify Clang directly to add support.


https://reviews.llvm.org/D42978



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


r324594 - Fix for #31362 - ms_abi is implemented incorrectly for values >=16 bytes.

2018-02-08 Thread Alexander Ivchenko via cfe-commits
Author: aivchenk
Date: Thu Feb  8 03:15:21 2018
New Revision: 324594

URL: http://llvm.org/viewvc/llvm-project?rev=324594&view=rev
Log:
Fix for #31362 - ms_abi is implemented incorrectly for values >=16 bytes.

Summary:
This patch is a fix for following issue:
https://bugs.llvm.org/show_bug.cgi?id=31362 The problem was caused by front end
lowering C calling conventions without taking into account calling conventions
enforced by attribute. In this case win64cc was no correctly lowered on targets
other than Windows.

Reviewed By: rnk (Reid Kleckner)

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

Author: belickim 



Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGen/ms_abi.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=324594&r1=324593&r2=324594&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Feb  8 03:15:21 2018
@@ -3529,7 +3529,17 @@ ABIArgInfo X86_64ABIInfo::classifyRegCal
 
 void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
 
-  bool IsRegCall = FI.getCallingConvention() == llvm::CallingConv::X86_RegCall;
+  const unsigned CallingConv = FI.getCallingConvention();
+  // It is possible to force Win64 calling convention on any x86_64 target by
+  // using __attribute__((ms_abi)). In such case to correctly emit Win64
+  // compatible code delegate this call to WinX86_64ABIInfo::computeInfo.
+  if (CallingConv == llvm::CallingConv::Win64) {
+WinX86_64ABIInfo Win64ABIInfo(CGT);
+Win64ABIInfo.computeInfo(FI);
+return;
+  }
+
+  bool IsRegCall = CallingConv == llvm::CallingConv::X86_RegCall;
 
   // Keep track of the number of assigned registers.
   unsigned FreeIntRegs = IsRegCall ? 11 : 6;

Modified: cfe/trunk/test/CodeGen/ms_abi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms_abi.c?rev=324594&r1=324593&r2=324594&view=diff
==
--- cfe/trunk/test/CodeGen/ms_abi.c (original)
+++ cfe/trunk/test/CodeGen/ms_abi.c Thu Feb  8 03:15:21 2018
@@ -146,3 +146,16 @@ void __attribute__((sysv_abi)) f6(__buil
   // WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
   // WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
 }
+
+// This test checks if structs are passed according to Win64 calling convention
+// when it's enforced by __attribute((ms_abi)).
+struct i128 {
+  unsigned long long a;
+  unsigned long long b;
+};
+
+__attribute__((ms_abi)) struct i128 f7(struct i128 a) {
+  // WIN64: define void @f7(%struct.i128* noalias sret %agg.result, 
%struct.i128* %a)
+  // FREEBSD: define win64cc void @f7(%struct.i128* noalias sret %agg.result, 
%struct.i128* %a)
+  return a;
+}


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


[libcxx] r324596 - [libcxx] Avoid spurious construction of valarray elements

2018-02-08 Thread Mikhail Maltsev via cfe-commits
Author: miyuki
Date: Thu Feb  8 03:33:48 2018
New Revision: 324596

URL: http://llvm.org/viewvc/llvm-project?rev=324596&view=rev
Log:
[libcxx] Avoid spurious construction of valarray elements

Summary:
Currently libc++ implements some operations on valarray by using the
resize method. This method has a parameter with a default value.
Because of this, valarray may spuriously construct and destruct
objects of valarray's element type.

This patch fixes this issue and adds corresponding test cases.


Reviewers: EricWF, mclow.lists

Reviewed By: mclow.lists

Subscribers: rogfer01, cfe-commits

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

Modified:
libcxx/trunk/include/valarray

libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.assign/copy_assign.pass.cpp

libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.assign/initializer_list_assign.pass.cpp

libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.cons/default.pass.cpp

libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp

Modified: libcxx/trunk/include/valarray
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/valarray?rev=324596&r1=324595&r2=324596&view=diff
==
--- libcxx/trunk/include/valarray (original)
+++ libcxx/trunk/include/valarray Thu Feb  8 03:33:48 2018
@@ -1053,6 +1053,9 @@ private:
 friend
 const _Up*
 end(const valarray<_Up>& __v);
+
+void __clear();
+valarray& __assign_range(const value_type* __f, const value_type* __l);
 };
 
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray::valarray(size_t))
@@ -2750,7 +2753,24 @@ valarray<_Tp>::valarray(size_t __n)
 : __begin_(0),
   __end_(0)
 {
-resize(__n);
+if (__n)
+{
+__begin_ = __end_ = static_cast(_VSTD::__allocate(__n * 
sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+try
+{
+#endif  // _LIBCPP_NO_EXCEPTIONS
+for (; __n; --__n, ++__end_)
+::new (__end_) value_type();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+}
+catch (...)
+{
+__clear();
+throw;
+}
+#endif  // _LIBCPP_NO_EXCEPTIONS
+}
 }
 
 template 
@@ -2780,7 +2800,7 @@ valarray<_Tp>::valarray(const value_type
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2805,7 +2825,7 @@ valarray<_Tp>::valarray(const valarray&
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2842,7 +2862,7 @@ valarray<_Tp>::valarray(initializer_list
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2870,7 +2890,7 @@ valarray<_Tp>::valarray(const slice_arra
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2899,7 +2919,7 @@ valarray<_Tp>::valarray(const gslice_arr
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2928,7 +2948,7 @@ valarray<_Tp>::valarray(const mask_array
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2957,7 +2977,7 @@ valarray<_Tp>::valarray(const indirect_a
 }
 catch (...)
 {
-resize(0);
+__clear();
 throw;
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2968,22 +2988,35 @@ template 
 inline
 valarray<_Tp>::~valarray()
 {
-resize(0);
+__clear();
 }
 
 template 
 valarray<_Tp>&
-valarray<_Tp>::operator=(const valarray& __v)
+valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
 {
-if (this != &__v)
+size_t __n = __l - __f;
+if (size() != __n)
 {
-if (size() != __v.size())
-resize(__v.size());
-_VSTD::copy(__v.__begin_, __v.__end_, __begin_);
+__clear();
+__begin_ = static_cast(_VSTD::__allocate(__n * 
sizeof(value_type)));
+__end_ = __begin_ + __n;
+_VSTD::uninitialized_copy(__f, __l, __begin_);
+} else {
+_VSTD::copy(__f, __l, __begin_);
 }
 return *this;
 }
 
+template 
+valarray<_Tp>&
+valarray<_Tp>::operator=(const valarray& __v)
+{
+if (this != &__v)
+return __assign_range(__v.__begin_, __v.__end_);
+return *this;
+}
+
 #ifndef _LIBCPP_CXX03_LANG
 
 template 
@@ -2991,7 +3024,7 @@ inline
 valarray<_Tp>&
 valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
 {
-resize(0);
+__clear();
 __begin_ = __v.__begin_;
 __end_ = __v.__end_;
 __v.__be

[PATCH] D41629: [libcxx] Improve accuracy of complex asinh and acosh

2018-02-08 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki updated this revision to Diff 133408.
miyuki added a comment.

Added a test for __sqr


https://reviews.llvm.org/D41629

Files:
  include/complex
  test/libcxx/numerics/complex.number/__sqr.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp

Index: test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp
===
--- test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp
+++ test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp
@@ -44,6 +44,15 @@
 assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
 }
+else if (testcases[i].real() == 0 && std::abs(testcases[i].imag()) == 1)
+{
+assert(r.real() == 0);
+assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
+if (std::signbit(testcases[i].imag()))
+is_about(r.imag(), -pi/2);
+else
+is_about(r.imag(),  pi/2);
+}
 else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
 {
 assert(std::isinf(r.real()));
Index: test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp
===
--- test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp
+++ test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp
@@ -54,6 +54,15 @@
 assert(r.imag() == 0);
 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
 }
+else if (testcases[i].real() == -1 && testcases[i].imag() == 0)
+{
+assert(r.real() == 0);
+assert(!std::signbit(r.real()));
+if (std::signbit(testcases[i].imag()))
+is_about(r.imag(), -pi);
+else
+is_about(r.imag(),  pi);
+}
 else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
 {
 assert(std::isinf(r.real()));
Index: test/libcxx/numerics/complex.number/__sqr.pass.cpp
===
--- /dev/null
+++ test/libcxx/numerics/complex.number/__sqr.pass.cpp
@@ -0,0 +1,81 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template
+//   complex
+//   __sqr(const complex& x);
+
+#include 
+#include 
+
+template 
+void
+test()
+{
+const T tolerance = std::is_same::value ? 1.e-6 : 1.e-14;
+
+typedef std::complex cplx;
+struct test_case
+{
+cplx value;
+cplx expected;
+};
+
+const test_case cases[] = {
+{cplx( 0,  0), cplx( 0,  0)},
+{cplx( 1,  0), cplx( 1,  0)},
+{cplx( 2,  0), cplx( 4,  0)},
+{cplx(-1,  0), cplx( 1,  0)},
+{cplx( 0,  1), cplx(-1,  0)},
+{cplx( 0,  2), cplx(-4,  0)},
+{cplx( 0, -1), cplx(-1,  0)},
+{cplx( 1,  1), cplx( 0,  2)},
+{cplx( 1, -1), cplx( 0, -2)},
+{cplx(-1, -1), cplx( 0,  2)},
+{cplx(0.5, 0), cplx(0.25, 0)},
+};
+
+const unsigned num_cases = sizeof(cases) / sizeof(test_case);
+for (unsigned i = 0; i < num_cases; ++i)
+{
+const test_case& test = cases[i];
+const std::complex actual = std::__sqr(test.value);
+assert(std::abs(actual.real() - test.expected.real()) < tolerance);
+assert(std::abs(actual.imag() - test.expected.imag()) < tolerance);
+}
+
+const cplx nan1 = std::__sqr(cplx(NAN, 0));
+assert(std::isnan(nan1.real()));
+assert(std::isnan(nan1.imag()));
+
+const cplx nan2 = std::__sqr(cplx(0, NAN));
+assert(std::isnan(nan2.real()));
+assert(std::isnan(nan2.imag()));
+
+const cplx nan3 = std::__sqr(cplx(NAN, NAN));
+assert(std::isnan(nan3.real()));
+assert(std::isnan(nan3.imag()));
+
+const cplx inf1 = std::__sqr(cplx(INFINITY, 0));
+assert(std::isinf(inf1.real()));
+assert(inf1.real() > 0);
+
+const cplx inf2 = std::__sqr(cplx(0, INFINITY));
+assert(std::isinf(inf2.real()));
+assert(inf2.real() < 0);
+}
+
+int main()
+{
+test();
+test();
+test();
+}
Index: include/complex
===
--- include/complex
+++ include/complex
@@ -1125,6 +1125,17 @@
 return _VSTD::pow(result_type(__x), result_type(__y));
 }
 
+// __sqr, computes pow(x, 2)
+
+template
+inline _LIBCPP_I

[PATCH] D42640: [clangd] Prototype: collect symbol #include & insert #include in global code completion.

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 133411.
ioeric marked 13 inline comments as done.
ioeric added a comment.

- Added tests for all components; more cleanup; s/IncludeURI/IncludeHeader/


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42640

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CodeComplete.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/clients/clangd-vscode/package.json
  clangd/global-symbol-builder/CMakeLists.txt
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clangd/index/CanonicalIncludes.cpp
  clangd/index/CanonicalIncludes.h
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/Merge.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  clangd/index/SymbolYAML.cpp
  clangd/tool/ClangdMain.cpp
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/insert-include.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -47,6 +47,12 @@
 }
 MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
 MATCHER_P(DeclURI, P, "") { return arg.CanonicalDeclaration.FileURI == P; }
+MATCHER(HasIncludeHeader, "") {
+  return arg.Detail && !arg.Detail->IncludeHeader.empty();
+}
+MATCHER_P(IncludeHeader, P, "") {
+  return arg.Detail && arg.Detail->IncludeHeader == P;
+}
 MATCHER_P(LocationOffsets, Offsets, "") {
   // Offset range in SymbolLocation is [start, end] while in Clangd is [start,
   // end).
@@ -60,41 +66,62 @@
 namespace {
 class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
 public:
-  SymbolIndexActionFactory(SymbolCollector::Options COpts)
-  : COpts(std::move(COpts)) {}
+  SymbolIndexActionFactory(SymbolCollector::Options COpts,
+   CommentHandler *PragmaHandler)
+  : COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}
 
   clang::FrontendAction *create() override {
+class WrappedIndexAction : public WrapperFrontendAction {
+public:
+  WrappedIndexAction(std::shared_ptr C,
+ const index::IndexingOptions &Opts,
+ CommentHandler *PragmaHandler)
+  : WrapperFrontendAction(
+index::createIndexingAction(C, Opts, nullptr)),
+PragmaHandler(PragmaHandler) {}
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+if (PragmaHandler)
+  CI.getPreprocessor().addCommentHandler(PragmaHandler);
+return WrapperFrontendAction::CreateASTConsumer(CI, InFile);
+  }
+
+private:
+  index::IndexingOptions IndexOpts;
+  CommentHandler *PragmaHandler;
+};
 index::IndexingOptions IndexOpts;
 IndexOpts.SystemSymbolFilter =
 index::IndexingOptions::SystemSymbolFilterKind::All;
 IndexOpts.IndexFunctionLocals = false;
 Collector = std::make_shared(COpts);
-FrontendAction *Action =
-index::createIndexingAction(Collector, IndexOpts, nullptr).release();
-return Action;
+return new WrappedIndexAction(Collector, std::move(IndexOpts),
+  PragmaHandler);
   }
 
   std::shared_ptr Collector;
   SymbolCollector::Options COpts;
+  CommentHandler *PragmaHandler;
 };
 
 class SymbolCollectorTest : public ::testing::Test {
 public:
   SymbolCollectorTest()
-  : TestHeaderName(getVirtualTestFilePath("symbol.h").str()),
+  : InMemoryFileSystem(new vfs::InMemoryFileSystem),
+TestHeaderName(getVirtualTestFilePath("symbol.h").str()),
 TestFileName(getVirtualTestFilePath("symbol.cc").str()) {
 TestHeaderURI = URI::createFile(TestHeaderName).toString();
 TestFileURI = URI::createFile(TestFileName).toString();
   }
 
   bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode,
   const std::vector &ExtraArgs = {}) {
-llvm::IntrusiveRefCntPtr InMemoryFileSystem(
-new vfs::InMemoryFileSystem);
 llvm::IntrusiveRefCntPtr Files(
 new FileManager(FileSystemOptions(), InMemoryFileSystem));
 
-auto Factory = llvm::make_unique(CollectorOpts);
+auto Factory = llvm::make_unique(
+CollectorOpts, PragmaHandler.get());
 
 std::vector Args = {"symbol_collector", "-fsyntax-only",
  "-std=c++11", TestFileName};
@@ -120,12 +147,14 @@
   }
 
 protected:
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem;
   std::string TestHeaderName;
   std::string TestHeaderURI;
   std::string TestFileName;
   std::string TestFileURI;
   SymbolSlab Symbols;
   SymbolCollector::Options CollectorOpts;
+  std::unique_ptr PragmaHandler;
 };
 
 TEST_F(SymbolCollectorTest, CollectSymbols) {
@@ 

[PATCH] D42640: [clangd] Prototype: collect symbol #include & insert #include in global code completion.

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Thanks for the comments!

Sorry that I didn't clean up the code before sending out the prototype. I 
planned to deal with code structure and style issues after getting some early 
feedback, but I think the patch is ready for review now.




Comment at: clangd/ClangdServer.cpp:445
+CI->getFrontendOpts().DisableFree = false;
+CI->getPreprocessorOpts().SingleFileParseMode = true;
+

sammccall wrote:
> explain why? (this has implications for direct vs transitive includes I think)
Since we only need predecessor for HeaderSearch and don't really care about the 
actual code, I set this to false in the hope of speeding up the code. But in 
the latest revision, I simply use an empty file (as we only care about header 
search), so this option is no longer necessary. 



Comment at: clangd/ClangdServer.cpp:447
+
+auto Clang = prepareCompilerInstance(
+std::move(CI), /*Preamble=*/nullptr,

sammccall wrote:
> hmm, why are we actually going to run the compiler/preprocessor?
> It looks like we just get HeaderMapping out - can we "just" call 
> ApplyHeaderSearchOptions instead?
I couldn't find an easy way to use `ApplyHeaderSearchOptions`... It requires an 
instance of HeaderSearch, which needs a preprocessor and a bunch of other 
objects (SourceManager, Target etc). And these objects are mostly initialized 
in `BeginSourceFile`. We could probably pull out the code that only initializes 
up to proprocessor,  but this is not very trivial :(



Comment at: clangd/ClangdServer.cpp:465
+auto &HeaderSearchInfo = Clang->getPreprocessor().getHeaderSearchInfo();
+std::string Suggested = HeaderSearchInfo.suggestPathToFileForDiagnostics(
+*Resolved, CompileCommand.Directory);

sammccall wrote:
> do we handle the case that the suggestion is already included?
> (including the case where it's included by a different name)
Yes and no. The current implementation only does textual matching against 
existing #includes in the current file and inserts the header if no same header 
was found. This complies with IWYU. But we are not handling the case where the 
same header is included by different names. I added a `FIXME` for this.



Comment at: clangd/CodeComplete.cpp:836
if (Recorder.CCSema)
- Output = runWithSema();
+ Output = runWithSema(SemaCCInput.FileName,
+  SemaCCInput.Contents);

sammccall wrote:
> What do you think about (redundantly) passing filename to the constructor, 
> and stashing it in a member, instead of passing to all the methods here?
> I think main purpose of having this class is not having the *primary* data 
> flow obscured by all the various context variables.
> 
> If you don't like that, we could also pass the SemaCCInput struct to the 
> constructor itself. The distinction between constrcutor params and run() 
> params is pretty artificial.
> 
> (as noted above, I think/hope Contents is unused in any case)
Passing filename to the constructor sounds good.  Thanks!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42640



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


r324607 - [Parser][FixIt] Better diagnostics for "typedef" instead of "typename" typo

2018-02-08 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Thu Feb  8 06:37:58 2018
New Revision: 324607

URL: http://llvm.org/viewvc/llvm-project?rev=324607&view=rev
Log:
[Parser][FixIt] Better diagnostics for "typedef" instead of "typename" typo

rdar://problem/10214588

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

Added:
cfe/trunk/test/FixIt/fixit-typedef-instead-of-typename-typo.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/test/CXX/temp/temp.param/p2.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=324607&r1=324606&r2=324607&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Thu Feb  8 06:37:58 
2018
@@ -1162,6 +1162,9 @@ def err_objc_parameterized_implementatio
 
 def err_objc_type_args_after_protocols : Error<
   "protocol qualifiers must precede type arguments">;
+
+def note_meant_to_use_typename : Note<
+  "did you mean to use 'typename'?">;
 }
 
 let CategoryName = "Coroutines Issue" in {

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=324607&r1=324606&r2=324607&view=diff
==
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Thu Feb  8 06:37:58 2018
@@ -488,6 +488,20 @@ NamedDecl *Parser::ParseTemplateParamete
   if (Tok.is(tok::kw_template))
 return ParseTemplateTemplateParameter(Depth, Position);
 
+  // Is there just a typo in the input code? ('typedef' instead of 'typename')
+  if (Tok.is(tok::kw_typedef)) {
+Diag(Tok.getLocation(), diag::err_expected_template_parameter);
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+<< FixItHint::CreateReplacement(CharSourceRange::getCharRange(
+Tok.getLocation(), 
Tok.getEndLoc()),
+"typename");
+
+Tok.setKind(tok::kw_typename);
+
+return ParseTypeParameter(Depth, Position);
+  }
+
   // If it's none of the above, then it must be a parameter declaration.
   // NOTE: This will pick up errors in the closure of the template parameter
   // list (e.g., template < ; Check here to implement >> style closures.

Modified: cfe/trunk/test/CXX/temp/temp.param/p2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.param/p2.cpp?rev=324607&r1=324606&r2=324607&view=diff
==
--- cfe/trunk/test/CXX/temp/temp.param/p2.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.param/p2.cpp Thu Feb  8 06:37:58 2018
@@ -15,29 +15,29 @@ template::type
 
 // A storage class shall not be specified in a template-parameter declaration.
 template struct Z; //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error2{{invalid 
declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
-template struct Z0;  //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
+template struct Z0; //expected-error{{expected template 
parameter}} expected-error{{expected identifier}} expected-error{{extraneous 
'template<>' in declaration of struct 'Z0'}} expected-note{{did you mean to use 
'typename'?}}
+template struct Z1; //expected-error2{{invalid 
declaration specifier}}
+template struct Z2; //expected-error{{invalid declaration 
specifier}}
+template struct Z3; //expected-error{{invalid declaration 
specifier}}
+template struct Z4; //expected-error{{invalid declaration 
specifier}}
+template struct Z5; //expected-error{{invalid declaration 
specifier}}
+template struct Z6;  //expected-error{{invalid declaration 
specifier}}
+template struct Z7; //expected-error{{invalid declaration 
specifier}}
+template struct Z8; //expected-error{{invalid declaration 
specifier}}
 
-template struct Z0; // OK 
-template struct Z0; // OK
+template struct Z9; // OK
+template struct Z10; // OK
 
 
 
 #ifdef CPP11
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
-template struct Z0; //expected-error{{invalid declaration 
specifier}}
+template struct Z11; //expected-error{{invalid declaration 
specifier}}
+template struct Z12; //expected-error{{invalid declara

[PATCH] D41968: [libunwind][MIPS] Support MIPS floating-point registers for hard-float ABIs.

2018-02-08 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a reviewer: compnerd.
sdardis added a comment.

I am not sure what the answer is. There's a slightly different issue in that 
returning the contents of a floating point register on MIPS and expecting it to 
be a double is not necessarily correct. For a 64bit FPU, the result of 
lwc1/mtc1 leaves the upper 32bits of an floating point register as 
**UNPREDICTABLE** by the architecture definition. It's entirely possible for 
the application being unwound to be operating on single precision values, but 
the contents of the register in it's entirety are a signalling nan.

I think the least worst option for registers is to always present the data as 
double values and to only permit access to the sets of double registers for 
O32, and leave the API user to determine how to proceed.

Unfortunately this complicates unwinding in the case of 
https://reviews.llvm.org/source/compiler-rt/ in strict fp32 mode as that 
doesn't have double precision at all. But there's more work to be done for 
https://reviews.llvm.org/source/compiler-rt/ support anyway, so it can be 
deferred. Some nits inlined. Also, watch out for ABI guards such as 
(defined(_ABIN32) || defined(_ABI64), these can be replaced with __mips64.




Comment at: src/Registers.hpp:2659
+  uint32_t _padding;
+  double _floats[32];
+#endif

bsdjhb wrote:
> I chose to always use double here to avoid having different context sizes for 
> the 32-bit vs 64-bit FPR cases.
Add a comment highlighting that design choice.



Comment at: src/UnwindRegistersRestore.S:647
+#if __mips_fpr == 32
+  l.d   $f0, (4 * 36 + 8 * 0)($4)
+  l.d   $f2, (4 * 36 + 8 * 2)($4)

Use ldc1 instead of l.d . l.d is an alias of ldc1.



Comment at: src/UnwindRegistersRestore.S:755
+#ifdef __mips_hard_float
+  l.d   $f0, (8 * 35)($4)
+  l.d   $f1, (8 * 36)($4)

ldc1 here too.



Comment at: src/UnwindRegistersSave.S:119
 
-#elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float)
+#elif defined(__mips__) && defined(_ABIO32)
 

&& _MIPS_SIM == _ABIO32



Comment at: src/UnwindRegistersSave.S:172
+#if __mips_fpr == 32
+  s.d   $f0, (4 * 36 + 8 * 0)($4)
+  s.d   $f2, (4 * 36 + 8 * 2)($4)

Use sdc1 rather than s.d.



Comment at: src/UnwindRegistersSave.S:228
 
-#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32)) &&
\
-defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32))
 

defined(__mips64) rather than the checking if the ABI names are defined.



Comment at: src/UnwindRegistersSave.S:280
+#ifdef __mips_hard_float
+  s.d   $f0, (8 * 35)($4)
+  s.d   $f1, (8 * 36)($4)

sdc1 rather s.d



Comment at: src/libunwind.cpp:64
 # define REGISTER_KIND Registers_or1k
-#elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float)
+#elif defined(__mips__) && defined(_ABIO32)
 # define REGISTER_KIND Registers_mips_o32

Check for that _MIPS_SIM == _ABIO32 as well.



Comment at: src/libunwind.cpp:66
 # define REGISTER_KIND Registers_mips_o32
-#elif defined(__mips__) && (defined(_ABIN32) || defined(_ABI64)) &&
\
-defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABIN32) || defined(_ABI64))
 # define REGISTER_KIND Registers_mips_newabi

Check for __mips64 rather than defined(_ABIXXX).


https://reviews.llvm.org/D41968



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


[PATCH] D41005: Reuse preamble even if an unsaved file does not exist

2018-02-08 Thread Cameron via Phabricator via cfe-commits
cameron314 added a comment.

@yvvan: The clang frontend tests (`PCHPreambleTest` and friends) are disabled 
on Windows in the makefile (I think because the VFS tests depend on linux-like 
paths). So running the tests on Windows without failures is encouraging but not 
the whole story.


Repository:
  rC Clang

https://reviews.llvm.org/D41005



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


[PATCH] D42170: Fixit for 'typedef' instead of 'typename' typo

2018-02-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC324607: [Parser][FixIt] Better diagnostics for 
"typedef" instead of "typename" typo (authored by jkorous, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42170?vs=132135&id=133412#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42170

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  lib/Parse/ParseTemplate.cpp
  test/CXX/temp/temp.param/p2.cpp
  test/FixIt/fixit-typedef-instead-of-typename-typo.cpp

Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -1162,6 +1162,9 @@
 
 def err_objc_type_args_after_protocols : Error<
   "protocol qualifiers must precede type arguments">;
+
+def note_meant_to_use_typename : Note<
+  "did you mean to use 'typename'?">;
 }
 
 let CategoryName = "Coroutines Issue" in {
Index: test/CXX/temp/temp.param/p2.cpp
===
--- test/CXX/temp/temp.param/p2.cpp
+++ test/CXX/temp/temp.param/p2.cpp
@@ -15,29 +15,29 @@
 
 // A storage class shall not be specified in a template-parameter declaration.
 template struct Z; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error2{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0;  //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
+template struct Z0; //expected-error{{expected template parameter}} expected-error{{expected identifier}} expected-error{{extraneous 'template<>' in declaration of struct 'Z0'}} expected-note{{did you mean to use 'typename'?}}
+template struct Z1; //expected-error2{{invalid declaration specifier}}
+template struct Z2; //expected-error{{invalid declaration specifier}}
+template struct Z3; //expected-error{{invalid declaration specifier}}
+template struct Z4; //expected-error{{invalid declaration specifier}}
+template struct Z5; //expected-error{{invalid declaration specifier}}
+template struct Z6;  //expected-error{{invalid declaration specifier}}
+template struct Z7; //expected-error{{invalid declaration specifier}}
+template struct Z8; //expected-error{{invalid declaration specifier}}
 
-template struct Z0; // OK 
-template struct Z0; // OK
+template struct Z9; // OK
+template struct Z10; // OK
 
 
 
 #ifdef CPP11
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
+template struct Z11; //expected-error{{invalid declaration specifier}}
+template struct Z12; //expected-error{{invalid declaration specifier}}
 
 #endif
 
 #ifdef CPP17
-template struct Z1; // OK
+template struct Z13; // OK
 #endif
 
 // Make sure that we properly disambiguate non-type template parameters that
Index: test/FixIt/fixit-typedef-instead-of-typename-typo.cpp
===
--- test/FixIt/fixit-typedef-instead-of-typename-typo.cpp
+++ test/FixIt/fixit-typedef-instead-of-typename-typo.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  struct Foo {
+  // expected-error@-1 {{expected template parameter}} expected-note@-1 {{did you mean to use 'typename'?}}
+
+  // Check that we are speculatively (with fixit applied) trying to parse the rest.
+
+  // Should not produce error about type since parsing speculatively with fixit applied.
+  B member;
+
+  a // expected-error {{unknown type name 'a'}} // expected-error@+1 {{expected member name or ';' after declaration specifiers}}
+};
+
+
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// CHECK: fix-it:{{.*}}:{3:23-3:30}:"typename"
Index: lib/Parse/ParseTemplate.cpp
===
--- lib/Parse/ParseTemplate.cpp
+++ lib/Parse/ParseTemplate.cpp
@@ -488,6 +488,20 @@
   if (Tok.is(tok::kw_template))
 return ParseTemplateTemplateParameter(Depth, Position);
 
+  // Is there just a typo in the input code? ('typedef' instead of 'typename')
+  if (Tok.is(tok::kw_typedef)) {
+Diag(Tok.getLocation(), diag::err_expected_template_parameter);
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+<< FixItHint::CreateReplacement(CharSourceRange::getCharRange(
+Tok.getLocation(), Tok.getEndLoc()),
+  

[PATCH] D42170: Fixit for 'typedef' instead of 'typename' typo

2018-02-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324607: [Parser][FixIt] Better diagnostics for 
"typedef" instead of "typename" typo (authored by jkorous, 
committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42170?vs=132135&id=133413#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42170

Files:
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/lib/Parse/ParseTemplate.cpp
  cfe/trunk/test/CXX/temp/temp.param/p2.cpp
  cfe/trunk/test/FixIt/fixit-typedef-instead-of-typename-typo.cpp

Index: cfe/trunk/lib/Parse/ParseTemplate.cpp
===
--- cfe/trunk/lib/Parse/ParseTemplate.cpp
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp
@@ -488,6 +488,20 @@
   if (Tok.is(tok::kw_template))
 return ParseTemplateTemplateParameter(Depth, Position);
 
+  // Is there just a typo in the input code? ('typedef' instead of 'typename')
+  if (Tok.is(tok::kw_typedef)) {
+Diag(Tok.getLocation(), diag::err_expected_template_parameter);
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+<< FixItHint::CreateReplacement(CharSourceRange::getCharRange(
+Tok.getLocation(), Tok.getEndLoc()),
+"typename");
+
+Tok.setKind(tok::kw_typename);
+
+return ParseTypeParameter(Depth, Position);
+  }
+
   // If it's none of the above, then it must be a parameter declaration.
   // NOTE: This will pick up errors in the closure of the template parameter
   // list (e.g., template < ; Check here to implement >> style closures.
Index: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
@@ -1162,6 +1162,9 @@
 
 def err_objc_type_args_after_protocols : Error<
   "protocol qualifiers must precede type arguments">;
+
+def note_meant_to_use_typename : Note<
+  "did you mean to use 'typename'?">;
 }
 
 let CategoryName = "Coroutines Issue" in {
Index: cfe/trunk/test/FixIt/fixit-typedef-instead-of-typename-typo.cpp
===
--- cfe/trunk/test/FixIt/fixit-typedef-instead-of-typename-typo.cpp
+++ cfe/trunk/test/FixIt/fixit-typedef-instead-of-typename-typo.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  struct Foo {
+  // expected-error@-1 {{expected template parameter}} expected-note@-1 {{did you mean to use 'typename'?}}
+
+  // Check that we are speculatively (with fixit applied) trying to parse the rest.
+
+  // Should not produce error about type since parsing speculatively with fixit applied.
+  B member;
+
+  a // expected-error {{unknown type name 'a'}} // expected-error@+1 {{expected member name or ';' after declaration specifiers}}
+};
+
+
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// CHECK: fix-it:{{.*}}:{3:23-3:30}:"typename"
Index: cfe/trunk/test/CXX/temp/temp.param/p2.cpp
===
--- cfe/trunk/test/CXX/temp/temp.param/p2.cpp
+++ cfe/trunk/test/CXX/temp/temp.param/p2.cpp
@@ -15,29 +15,29 @@
 
 // A storage class shall not be specified in a template-parameter declaration.
 template struct Z; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error2{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0;  //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
-template struct Z0; //expected-error{{invalid declaration specifier}}
+template struct Z0; //expected-error{{expected template parameter}} expected-error{{expected identifier}} expected-error{{extraneous 'template<>' in declaration of struct 'Z0'}} expected-note{{did you mean to use 'typename'?}}
+template struct Z1; //expected-error2{{invalid declaration specifier}}
+template struct Z2; //expected-error{{invalid declaration specifier}}
+template struct Z3; //expected-error{{invalid declaration specifier}}
+template struct Z4; //expected-error{{invalid declaration specifier}}
+template struct Z5; //expected-error{{invalid declaration specifier}}
+template struct Z6;  //expected-error{{invalid declaration specifier}}
+template struct Z7; //expected-error{{invalid declaration specifier}}
+template struct Z8; //expected-error{{invalid declaration specifier}}
 
-template struct Z0; // 

[PATCH] D43065: [clangd] Remove threading-related code from ClangdUnit.h

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Nice! The code looks much simpler!

Just some drive-by nits. I don't know the threading work well enough to give 
useful comments. Will leave the approval to others.




Comment at: clangd/ClangdUnit.cpp:399
+  std::unique_ptr CI;
+  {
+// FIXME(ibiryukov): store diagnostics from CommandLine when we start

Do we still need this block?



Comment at: clangd/ClangdUnit.cpp:434
+// Collect diagnostics from both the preamble and the AST.
 if (NewPreamble) {
   Diagnostics.insert(Diagnostics.begin(), NewPreamble->Diags.begin(),

nit: no braces



Comment at: clangd/ClangdUnit.h:161
 
-  /// Mutex protects all fields, declared below it, FileName and Command are 
not
-  /// mutated.
-  mutable std::mutex Mutex;
-  /// A counter to cancel old rebuilds.
-  unsigned RebuildCounter;
-  /// Used to wait when rebuild is finished before starting another one.
-  bool RebuildInProgress;
-  /// Condition variable to indicate changes to RebuildInProgress.
-  std::condition_variable RebuildCond;
-
-  /// Size of the last built AST, in bytes.
-  std::size_t ASTMemUsage;
-  /// Size of the last build Preamble, in bytes.
-  std::size_t PreambleMemUsage;
-
-  /// Promise and future for the latests AST. Fulfilled during rebuild.
-  /// We use std::shared_ptr here because MVSC fails to compile non-copyable
-  /// classes as template arguments of promise/future.
-  std::promise> ASTPromise;
-  std::shared_future> ASTFuture;
-
-  /// Promise and future for the latests Preamble. Fulfilled during rebuild.
-  std::promise> PreamblePromise;
-  std::shared_future> PreambleFuture;
-  /// Latest preamble that was built. May be stale, but always available 
without
-  /// waiting for rebuild to finish.
-  std::shared_ptr LatestAvailablePreamble;
-  /// Utility class, required by clang.
+  /// The latest parsed AST.
+  llvm::Optional AST;

`s/latest/last/`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43065



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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks for picking this up!
I have just one major comment related to how we generate the hover text.

Current implementation tries to get the actual source code for every 
declaration and then patch it up to look nice on in the output.
It is quite a large piece of code (spanning most of the patch) and tries to mix 
and match source code and output from the AST when there's not enough 
information in the AST (e.g. `tryFixupIndentation` and `stripOpeningBracket`). 
This approach is really complex as we'll inevitably try to parse "parts" of C++ 
and figure out how to deal with macros, etc.
Worse than that, I would expect this code to grow uncontrollably with time and 
be very hard to maintain.
Moreover, in presence of macros it arguably gives non-useful results. For 
example, consider this:

  #define DEFINITIONS int foo(); int bar(); int baz();
  
  // somewhere else
  DEFINITIONS
  
  // somewhere else
  int test() {
foo(); // <-- hover currently doesn't work here. And even if it did, 
showing a line with just DEFINITIONS is not that useful.
  }

I suggest we move to a different approach of pretty-printing the relevant parts 
of the AST. It is already implemented in clang, handles all the cases in the 
AST (and will be updated along when AST is changed), shows useful information 
in presence of macros and is much easier to implement.
The version of `getHoverContents` using this is just a few lines of code:

  static std::string getHoverContents(const Decl *D) {
if (TemplateDecl *TD = D->getDescribedTemplate())
  D = TD; // we want to see the template bits.
  
std::string Result;
llvm::raw_string_ostream OS(Result);
  
PrintingPolicy Policy(D->getASTContext().getLangOpts());
Policy.TerseOutput = true;
D->print(OS, Policy);
  
OS.flush();
return Result;
  }

It doesn't add the `"Defined in ..."` piece, but illustrates the APIs we can 
use. We should use the same APIs for the scope as well, avoiding fallbacks to 
manual printing if we can.
If there's something missing/wrong in the upstream pretty printers, it's fine 
and we can fix them (e.g., the thing that I've immediately noticed is that 
namespaces are always printed with curly braces).




Comment at: clangd/ClangdLSPServer.cpp:325
+void ClangdLSPServer::onHover(TextDocumentPositionParams &Params) {
+
+  llvm::Expected> H =

NIT: remove the empty line at the start of function



Comment at: clangd/Protocol.cpp:324
+json::Expr toJSON(const MarkupContent &MC) {
+  const char *KindStr = NULL;
+

NIT: use nullptr instead of NULL
(irrelevant if we use `StringRef`, see other comment below)



Comment at: clangd/Protocol.cpp:331
+
+  switch (MC.kind) {
+  case MarkupKind::PlainText:

- `StringRef` is a nicer abstraction, maybe use it instead of `const char*`?
- Maybe move declaration of `KindStr` closer to its usage?
- Maybe extract a helper function to mark the code path for invalid kinds as 
unreachable? I.e.
```
static StringRef toTextKind(MarkupKind Kind) {
  switch (Kind) {
case MarkupKind::PlainText:
  return "plaintext";
case MarkupKind::Markdown:
  return "markdown";
  }
  llvm_unreachable("Invalid MarkupKind");
}
```



Comment at: clangd/XRefs.cpp:326
+  if (const TagDecl *TD = dyn_cast(ND)) {
+switch (TD->getTagKind()) {
+case TTK_Class:

Same suggestion as before. Could we extract a helper function to mark invalid 
enum values unreachable?




Comment at: clangd/XRefs.cpp:552
+  if (!Decls.empty()) {
+assert(Decls[0] != nullptr);
+if (Decls[0] != nullptr)

This assert seems rather unlikely and just makes the code more complex. Let's 
assume it's true and remove it (along with the subsequent if statement)



Comment at: clangd/XRefs.cpp:560
+assert(Macros[0] != nullptr);
+if (Macros[0] != nullptr)
+  return getHoverContents(Macros[0], AST);

This assert seems rather unlikely and just makes the code more complex. Let's 
assume it's true and remove it (along with the subsequent if statement)





Comment at: test/clangd/hover.test:2
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#

We have a more readable format for the lit-tests now. Could we update this test 
to use it?
(see other tests in test/clangd for example)



Comment at: unittests/clangd/XRefsTests.cpp:231
+TEST(Hover, All) {
+
+  struct OneTest {

NIT: remove empty line at the start of the function



Comment at: unittests/clangd/XRefsTests.cpp:233
+  struct OneTest {
+const char *input;
+const char *expectedHover;

NIT: Use `StringRef` instead of `const char*`


Repository:
  rCTE Clang Tools Extra

https://reviews.l

[PATCH] D5767: Template Instantiation Observer + a few other templight-related changes

2018-02-08 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: lib/Sema/Sema.cpp:40
 #include "clang/Sema/TemplateDeduction.h"
+#include "clang/Sema/TemplateInstCallback.h"
 #include "llvm/ADT/DenseMap.h"

xazax.hun wrote:
> Do you need to add this include?
Yes, in `Sema.h` the class `TemplateInstantiationCallback` is only forward 
declared. That headers contains the definition.


https://reviews.llvm.org/D5767



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


[PATCH] D41005: Reuse preamble even if an unsaved file does not exist

2018-02-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In https://reviews.llvm.org/D41005#1001854, @cameron314 wrote:

> @yvvan: The clang frontend tests (`PCHPreambleTest` and friends) are disabled 
> on Windows in the makefile (I think because the VFS tests depend on 
> linux-like paths). So running the tests on Windows without failures is 
> encouraging but not the whole story.


Nice to know. But the bad thing is that it is not obvious at all from the code. 
And another bad thing is that tests are platform dependent.


Repository:
  rC Clang

https://reviews.llvm.org/D41005



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


[PATCH] D43068: [clangd] Remove codeComplete that returns std::future<>

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: unittests/clangd/SyncAPI.h:8
+//
+//===-===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H

Any reason not to put sync APIs in ClangdServer by their async versions, so 
that they are easier to find? I might be missing context. But if there is a 
good reason, please explain in the file doc.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43068



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


[libcxx] r324609 - Update the status of removed components

2018-02-08 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  8 06:51:22 2018
New Revision: 324609

URL: http://llvm.org/viewvc/llvm-project?rev=324609&view=rev
Log:
Update the status of removed components

Modified:
libcxx/trunk/www/TS_deprecation.html

Modified: libcxx/trunk/www/TS_deprecation.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/TS_deprecation.html?rev=324609&r1=324608&r2=324609&view=diff
==
--- libcxx/trunk/www/TS_deprecation.html (original)
+++ libcxx/trunk/www/TS_deprecation.html Thu Feb  8 06:51:22 2018
@@ -48,22 +48,22 @@
 
 SectionFeatureshipped instdTo 
be removed fromstd::experimentalNotes
 2.1uses_allocator 
construction5.07.0
-3.1.2erased_typen/aNot
 part of C++17
-3.2.1tuple_size_v5.07.0
-3.2.2apply5.07.0
-3.3.1All of the '_v' traits in 
5.07.0
+3.1.2erased_typen/aNot
 part of C++17
+3.2.1tuple_size_v5.07.0Removed
+3.2.2apply5.07.0Removed
+3.3.1All of the '_v' traits in 
5.07.0Removed
 3.3.2invocation_type and 
raw_invocation_typen/aNot
 part of C++17
-3.3.3Logical operator 
traits5.07.0
+3.3.3Logical operator 
traits5.07.0Removed
 3.3.3Detection 
Idiom5.0Only partially in 
C++17
-3.4.1All of the '_v' traits in 
5.07.0
-3.5.1All of the '_v' traits in 
5.07.0
-3.6.1All of the '_v' traits in 
5.07.0
+3.4.1All of the '_v' traits in 
5.07.0Removed
+3.5.1All of the '_v' traits in 
5.07.0Removed
+3.6.1All of the '_v' traits in 
5.07.0Removed
 
3.7propagate_constn/aNot
 part of C++17
 4.2Enhancements to functionNot 
yet
 
4.3searchers7.09.0
-5optional5.07.0
-6any5.07.0
-7string_view5.07.0
+5optional5.07.0Removed
+6any5.07.0Removed
+7string_view5.07.0Removed
 8.2.1shared_ptr enhancementsNot 
yetNever added
 8.2.2weak_ptr enhancementsNot 
yetNever added
 8.5memory_resourceNot 
yet
@@ -77,9 +77,9 @@
 
11.2promisen/aNot
 part of C++17
 
11.3packaged_taskn/aNot
 part of C++17
 
12.2search7.09.0
-12.3sample5.07.0
+12.3sample5.07.0Removed
 12.4shuffleNot part of 
C++17
-13.1gcd and 
lcm5.07.0
+13.1gcd and 
lcm5.07.0Removed
 13.2Random number generationNot part 
of C++17
 14Reflection LibraryNot part of 
C++17
 
@@ -132,7 +132,7 @@
 
 
   
-  Last Updated: 8-Jan-2018
+  Last Updated: 8-Feb-2018
 
 
 


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


[PATCH] D43065: [clangd] Remove threading-related code from ClangdUnit.h

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks for the NITs :-)




Comment at: clangd/ClangdUnit.cpp:399
+  std::unique_ptr CI;
+  {
+// FIXME(ibiryukov): store diagnostics from CommandLine when we start

ioeric wrote:
> Do we still need this block?
I added it to avoid referencing local variables declared there.

I would move this to be a separate function rather than removing the braces 
here, but other may have different opinions :-)
WDYT? Does a separate function sound ok?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43065



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


[PATCH] D43065: [clangd] Remove threading-related code from ClangdUnit.h

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 133416.
ilya-biryukov marked 2 inline comments as done.
ilya-biryukov added a comment.

- Removed braces
- s/latest/last/


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43065

Files:
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/TUScheduler.cpp

Index: clangd/TUScheduler.cpp
===
--- clangd/TUScheduler.cpp
+++ clangd/TUScheduler.cpp
@@ -48,6 +48,7 @@
 #include "llvm/Support/Errc.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -66,16 +67,16 @@
 /// worker.
 class ASTWorker {
   friend class ASTWorkerHandle;
-  ASTWorker(Semaphore &Barrier, std::shared_ptr AST, bool RunSync);
+  ASTWorker(Semaphore &Barrier, CppFile AST, bool RunSync);
 
 public:
   /// Create a new ASTWorker and return a handle to it.
   /// The processing thread is spawned using \p Tasks. However, when \p Tasks
   /// is null, all requests will be processed on the calling thread
   /// synchronously instead. \p Barrier is acquired when processing each
   /// request, it is be used to limit the number of actively running threads.
   static ASTWorkerHandle Create(AsyncTaskRunner *Tasks, Semaphore &Barrier,
-std::shared_ptr AST);
+CppFile AST);
   ~ASTWorker();
 
   void update(ParseInputs Inputs,
@@ -102,11 +103,14 @@
   const bool RunSync;
   Semaphore &Barrier;
   // AST and FileInputs are only accessed on the processing thread from run().
-  const std::shared_ptr AST;
+  CppFile AST;
   // Inputs, corresponding to the current state of AST.
   ParseInputs FileInputs;
   // Guards members used by both TUScheduler and the worker thread.
   mutable std::mutex Mutex;
+  std::shared_ptr LastBuiltPreamble; /* GUARDED_BY(Mutex) */
+  // Result of getUsedBytes() after the last rebuild or read of AST.
+  std::size_t LastASTSize; /* GUARDED_BY(Mutex) */
   // Set to true to signal run() to finish processing.
   bool Done;   /* GUARDED_BY(Mutex) */
   std::queue Requests; /* GUARDED_BY(Mutex) */
@@ -159,17 +163,16 @@
 };
 
 ASTWorkerHandle ASTWorker::Create(AsyncTaskRunner *Tasks, Semaphore &Barrier,
-  std::shared_ptr AST) {
+  CppFile AST) {
   std::shared_ptr Worker(
   new ASTWorker(Barrier, std::move(AST), /*RunSync=*/!Tasks));
   if (Tasks)
 Tasks->runAsync([Worker]() { Worker->run(); });
 
   return ASTWorkerHandle(std::move(Worker));
 }
 
-ASTWorker::ASTWorker(Semaphore &Barrier, std::shared_ptr AST,
- bool RunSync)
+ASTWorker::ASTWorker(Semaphore &Barrier, CppFile AST, bool RunSync)
 : RunSync(RunSync), Barrier(Barrier), AST(std::move(AST)), Done(false) {
   if (RunSync)
 return;
@@ -193,7 +196,14 @@
   return;
 }
 FileInputs = Inputs;
-auto Diags = AST->rebuild(std::move(Inputs));
+auto Diags = AST.rebuild(std::move(Inputs));
+
+{
+  std::lock_guard Lock(Mutex);
+  if (AST.getPreamble())
+LastBuiltPreamble = AST.getPreamble();
+  LastASTSize = AST.getUsedBytes();
+}
 // We want to report the diagnostics even if this update was cancelled.
 // It seems more useful than making the clients wait indefinitely if they
 // spam us with updates.
@@ -208,33 +218,33 @@
 void ASTWorker::runWithAST(
 UniqueFunction)> Action) {
   auto Task = [=](decltype(Action) Action) {
-auto ASTWrapper = this->AST->getAST().get();
-// FIXME: no need to lock here, cleanup the CppFile interface to get rid of
-// them.
-ASTWrapper->runUnderLock([&](ParsedAST *AST) {
-  if (!AST) {
-Action(llvm::make_error(
-"invalid AST", llvm::errc::invalid_argument));
-return;
-  }
-  Action(InputsAndAST{FileInputs, *AST});
-});
+ParsedAST *ActualAST = AST.getAST();
+if (!ActualAST) {
+  Action(llvm::make_error("invalid AST",
+ llvm::errc::invalid_argument));
+  return;
+}
+Action(InputsAndAST{FileInputs, *ActualAST});
+
+// Size of the AST might have changed after reads too, e.g. if some decls
+// were deserialized from preamble.
+std::lock_guard Lock(Mutex);
+LastASTSize = ActualAST->getUsedBytes();
   };
 
   startTask(BindWithForward(Task, std::move(Action)), /*isUpdate=*/false,
 llvm::None);
 }
 
 std::shared_ptr
 ASTWorker::getPossiblyStalePreamble() const {
-  return AST->getPossiblyStalePreamble();
+  std::lock_guard Lock(Mutex);
+  return LastBuiltPreamble;
 }
 
 std::size_t ASTWorker::getUsedBytes() const {
-  // FIXME(ibiryukov): we'll need to take locks here after we remove
-  // thread-safety from CppFile. For now, CppFile is thread-safe and we can
-  // safely call methods on it without acquiring a lock.
-  return AST->getUsedBytes();
+  std::lock_guard Lock(Mutex);
+  return Las

[PATCH] D43065: [clangd] Remove threading-related code from ClangdUnit.h

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/ClangdUnit.cpp:399
+  std::unique_ptr CI;
+  {
+// FIXME(ibiryukov): store diagnostics from CommandLine when we start

ilya-biryukov wrote:
> ioeric wrote:
> > Do we still need this block?
> I added it to avoid referencing local variables declared there.
> 
> I would move this to be a separate function rather than removing the braces 
> here, but other may have different opinions :-)
> WDYT? Does a separate function sound ok?
I don't think it's necessary though? But up to you :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43065



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


[PATCH] D41792: [AArch64] Add ARMv8.2-A FP16 scalar intrinsics

2018-02-08 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer closed this revision.
SjoerdMeijer added a comment.
Herald added a subscriber: hintonda.

Committed as r323005


https://reviews.llvm.org/D41792



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


[PATCH] D43074: [Analyzer] Fix a typo about `categories::MemoryError` in `MallocChecker.cpp`

2018-02-08 Thread Henry Wong via Phabricator via cfe-commits
MTC created this revision.
MTC added reviewers: NoQ, xazax.hun.
Herald added subscribers: cfe-commits, a.sidorin, rnkovacs, szepet.
Herald added a reviewer: george.karpenkov.

It should be an omission when committing https://reviews.llvm.org/rL302016.


Repository:
  rC Clang

https://reviews.llvm.org/D43074

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp


Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2075,8 +2075,8 @@
 
   if (ExplodedNode *N = C.generateErrorNode()) {
 if (!BT_BadFree[*CheckKind])
-  BT_BadFree[*CheckKind].reset(
-  new BugType(CheckNames[*CheckKind], "Bad free", "Memory Error"));
+  BT_BadFree[*CheckKind].reset(new BugType(
+  CheckNames[*CheckKind], "Bad free", categories::MemoryError));
 
 SmallString<100> Buf;
 llvm::raw_svector_ostream Os(Buf);


Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2075,8 +2075,8 @@
 
   if (ExplodedNode *N = C.generateErrorNode()) {
 if (!BT_BadFree[*CheckKind])
-  BT_BadFree[*CheckKind].reset(
-  new BugType(CheckNames[*CheckKind], "Bad free", "Memory Error"));
+  BT_BadFree[*CheckKind].reset(new BugType(
+  CheckNames[*CheckKind], "Bad free", categories::MemoryError));
 
 SmallString<100> Buf;
 llvm::raw_svector_ostream Os(Buf);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43075: [clang-move] Don't dump macro symbols.

2018-02-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ioeric.
Herald added a subscriber: klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43075

Files:
  clang-move/ClangMove.cpp
  unittests/clang-move/ClangMoveTests.cpp


Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -391,6 +391,21 @@
   }
 }
 
+TEST(ClangMove, IgnoreMacroSymbolsAndMoveAll) {
+  const char TestCode[] = "#include \"foo.h\"";
+  const char TestHeader[] =
+  "#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n";
+  move::MoveDefinitionSpec Spec;
+  Spec.Names.push_back("Bar");
+  Spec.OldHeader = "foo.h";
+  Spec.OldCC = "foo.cc";
+  Spec.NewHeader = "new_foo.h";
+  Spec.NewCC = "new_foo.cc";
+  auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
+  EXPECT_EQ("", Results[Spec.OldHeader]);
+  EXPECT_EQ(TestHeader, Results[Spec.NewHeader]);
+}
+
 TEST(ClangMove, MacroInFunction) {
   const char TestHeader[] = "#define INT int\n"
 "class A {\npublic:\n  int f();\n};\n"
@@ -570,7 +585,9 @@
 "extern int kGlobalInt;\n"
 "extern const char* const kGlobalStr;\n"
 "} // namespace b\n"
-"} // namespace a\n";
+"} // namespace a\n"
+"#define DEFINE_FOO class Foo {};\n"
+"DEFINE_FOO\n";
   const char TestCode[] = "#include \"foo.h\"\n";
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("B");
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -523,6 +523,7 @@
   auto AllDeclsInHeader = namedDecl(
   unless(ForwardClassDecls), unless(namespaceDecl()),
   unless(usingDirectiveDecl()), // using namespace decl.
+  notInMacro(),
   InOldHeader,
   hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(,
   hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl();
@@ -905,10 +906,9 @@
 
   if (RemovedDecls.empty())
 return;
-  // Ignore symbols that are not supported (e.g. typedef and enum) when
-  // checking if there is unremoved symbol in old header. This makes sure that
-  // we always move old files to new files when all symbols produced from
-  // dump_decls are moved.
+  // Ignore symbols that are not supported when checking if there is unremoved
+  // symbol in old header. This makes sure that we always move old files to new
+  // files when all symbols produced from dump_decls are moved.
   auto IsSupportedKind = [](const clang::NamedDecl *Decl) {
 switch (Decl->getKind()) {
 case Decl::Kind::Function:


Index: unittests/clang-move/ClangMoveTests.cpp
===
--- unittests/clang-move/ClangMoveTests.cpp
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -391,6 +391,21 @@
   }
 }
 
+TEST(ClangMove, IgnoreMacroSymbolsAndMoveAll) {
+  const char TestCode[] = "#include \"foo.h\"";
+  const char TestHeader[] =
+  "#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n";
+  move::MoveDefinitionSpec Spec;
+  Spec.Names.push_back("Bar");
+  Spec.OldHeader = "foo.h";
+  Spec.OldCC = "foo.cc";
+  Spec.NewHeader = "new_foo.h";
+  Spec.NewCC = "new_foo.cc";
+  auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
+  EXPECT_EQ("", Results[Spec.OldHeader]);
+  EXPECT_EQ(TestHeader, Results[Spec.NewHeader]);
+}
+
 TEST(ClangMove, MacroInFunction) {
   const char TestHeader[] = "#define INT int\n"
 "class A {\npublic:\n  int f();\n};\n"
@@ -570,7 +585,9 @@
 "extern int kGlobalInt;\n"
 "extern const char* const kGlobalStr;\n"
 "} // namespace b\n"
-"} // namespace a\n";
+"} // namespace a\n"
+"#define DEFINE_FOO class Foo {};\n"
+"DEFINE_FOO\n";
   const char TestCode[] = "#include \"foo.h\"\n";
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("B");
Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -523,6 +523,7 @@
   auto AllDeclsInHeader = namedDecl(
   unless(ForwardClassDecls), unless(namespaceDecl()),
   unless(usingDirectiveDecl()), // using namespace decl.
+  notInMacro(),
   InOldHeader,
   hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(,
   hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl();
@@ -905,10 +906,9 @@
 
   if (RemovedDecls.empty())
 return;
-  // Ignore symbols that are not supported 

[PATCH] D42300: [Analyzer] Add PreStmt and PostStmt callbacks for OffsetOfExpr

2018-02-08 Thread Henry Wong via Phabricator via cfe-commits
MTC updated this revision to Diff 133421.
MTC added a comment.
Herald added a reviewer: george.karpenkov.

rebase


Repository:
  rC Clang

https://reviews.llvm.org/D42300

Files:
  lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/Inputs/system-header-simulator.h
  test/Analysis/offsetofexpr-callback.c


Index: test/Analysis/offsetofexpr-callback.c
===
--- /dev/null
+++ test/Analysis/offsetofexpr-callback.c
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.AnalysisOrder 
-analyzer-config 
debug.AnalysisOrder:PreStmtOffsetOfExpr=true,debug.AnalysisOrder:PostStmtOffsetOfExpr=true
 %s 2>&1 | FileCheck %s
+#include "Inputs/system-header-simulator.h"
+
+struct S {
+  char c;
+};
+
+void test() {
+  offsetof(struct S, c); 
+}
+
+// CHECK: PreStmt
+// CHECK-NEXT: PostStmt
\ No newline at end of file
Index: test/Analysis/Inputs/system-header-simulator.h
===
--- test/Analysis/Inputs/system-header-simulator.h
+++ test/Analysis/Inputs/system-header-simulator.h
@@ -110,4 +110,6 @@
 #ifndef NULL
 #define __DARWIN_NULL 0
 #define NULL __DARWIN_NULL
-#endif
\ No newline at end of file
+#endif
+
+#define offsetof(t, d) __builtin_offsetof(t, d)
\ No newline at end of file
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1488,12 +1488,19 @@
   Bldr.addNodes(Dst);
   break;
 
-case Stmt::OffsetOfExprClass:
+case Stmt::OffsetOfExprClass: {
   Bldr.takeNodes(Pred);
-  VisitOffsetOfExpr(cast(S), Pred, Dst);
+  ExplodedNodeSet PreVisit;
+  getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
+
+  ExplodedNodeSet PostVisit;
+  for (ExplodedNode *Node : PreVisit)
+VisitOffsetOfExpr(cast(S), Node, PostVisit);
+
+  getCheckerManager().runCheckersForPostStmt(Dst, PostVisit, S, *this);
   Bldr.addNodes(Dst);
   break;
-
+}
 case Stmt::UnaryExprOrTypeTraitExprClass:
   Bldr.takeNodes(Pred);
   VisitUnaryExprOrTypeTraitExpr(cast(S),
Index: lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
+++ lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
@@ -33,6 +33,8 @@
  check::PostStmt,
  check::PreStmt,
  check::PostStmt,
+ check::PreStmt,
+ check::PostStmt,
  check::PreCall,
  check::PostCall,
  check::NewAllocator,
@@ -91,6 +93,16 @@
   llvm::errs() << "PostStmt\n";
   }
 
+  void checkPreStmt(const OffsetOfExpr *OOE, CheckerContext &C) const {
+if (isCallbackEnabled(C, "PreStmtOffsetOfExpr"))
+  llvm::errs() << "PreStmt\n";
+  }
+
+  void checkPostStmt(const OffsetOfExpr *OOE, CheckerContext &C) const {
+if (isCallbackEnabled(C, "PostStmtOffsetOfExpr"))
+  llvm::errs() << "PostStmt\n";
+  }
+
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
 if (isCallbackEnabled(C, "PreCall")) {
   llvm::errs() << "PreCall";


Index: test/Analysis/offsetofexpr-callback.c
===
--- /dev/null
+++ test/Analysis/offsetofexpr-callback.c
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.AnalysisOrder -analyzer-config debug.AnalysisOrder:PreStmtOffsetOfExpr=true,debug.AnalysisOrder:PostStmtOffsetOfExpr=true %s 2>&1 | FileCheck %s
+#include "Inputs/system-header-simulator.h"
+
+struct S {
+  char c;
+};
+
+void test() {
+  offsetof(struct S, c); 
+}
+
+// CHECK: PreStmt
+// CHECK-NEXT: PostStmt
\ No newline at end of file
Index: test/Analysis/Inputs/system-header-simulator.h
===
--- test/Analysis/Inputs/system-header-simulator.h
+++ test/Analysis/Inputs/system-header-simulator.h
@@ -110,4 +110,6 @@
 #ifndef NULL
 #define __DARWIN_NULL 0
 #define NULL __DARWIN_NULL
-#endif
\ No newline at end of file
+#endif
+
+#define offsetof(t, d) __builtin_offsetof(t, d)
\ No newline at end of file
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1488,12 +1488,19 @@
   Bldr.addNodes(Dst);
   break;
 
-case Stmt::OffsetOfExprClass:
+case Stmt::OffsetOfExprClass: {
   Bldr.takeNodes(Pred);
-  VisitOffsetOfExpr(cast(S), Pred, Dst);
+  ExplodedNodeSet PreVisit;
+  getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
+
+  ExplodedNodeSet PostVisit;
+  fo

[PATCH] D43074: [Analyzer] Fix a typo about `categories::MemoryError` in `MallocChecker.cpp`

2018-02-08 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin accepted this revision.
a.sidorin added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D43074



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


[PATCH] D42844: [OpenCL] Add test for atomic pointers.

2018-02-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Sorry for delay... Does this test anything OpenCL specific? As far as I 
remember we don't have any changes to `PointerType` with an atomic pointee type.


Repository:
  rC Clang

https://reviews.llvm.org/D42844



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


[PATCH] D43075: [clang-move] Don't dump macro symbols.

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Lg. Thanks for the change!




Comment at: clang-move/ClangMove.cpp:526
   unless(usingDirectiveDecl()), // using namespace decl.
+  notInMacro(),
   InOldHeader,

I'd probably relax the condition a bit; theoretically tools would be able to 
handle entire identifiers that are either spelled in macro or passed in by 
users. But it's probably rare. Might worth a `FIXME` though?



Comment at: unittests/clang-move/ClangMoveTests.cpp:397
+  const char TestHeader[] =
+  "#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n";
+  move::MoveDefinitionSpec Spec;

Could you add a test case where the identifier is composed of macro and user 
parameter? Something like `#define Foo(x) void func_##x()`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43075



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


[PATCH] D42841: [docs] Improve help for OpenMP options

2018-02-08 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea accepted this revision.
gtbercea added a comment.

LG


https://reviews.llvm.org/D42841



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


r324618 - [clang-format] Do not break Objective-C string literals inside array literals

2018-02-08 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Thu Feb  8 08:07:25 2018
New Revision: 324618

URL: http://llvm.org/viewvc/llvm-project?rev=324618&view=rev
Log:
[clang-format] Do not break Objective-C string literals inside array literals

Summary:
Concatenating Objective-C string literals inside an array literal
raises the warning -Wobjc-string-concatenation (which is enabled by default).

clang-format currently splits and concatenates string literals like
the following:

  NSArray *myArray = @[ @"a" ];

into:

  NSArray *myArray =
@[ @""
   @"a" ];

which raises the warning. This is https://bugs.llvm.org/show_bug.cgi?id=36153 .

The options I can think of to fix this are:

1) Have clang-format disable Wobjc-string-concatenation by emitting
pragmas around the formatted code
2) Have clang-format wrap the string literals in a macro (which
disables the warning)
3) Disable string splitting for Objective-C string literals inside
array literals

I think 1) has no precedent, and I couldn't find a good
identity() macro for 2). So, this diff implements 3).

Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: jolesiak, stephanemoore, djasper

Reviewed By: jolesiak

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=324618&r1=324617&r2=324618&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Feb  8 08:07:25 2018
@@ -1285,6 +1285,9 @@ void ContinuationIndenter::moveStatePast
   State.Stack.back().NestedBlockIndent = NestedBlockIndent;
   State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
   State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 1;
+  State.Stack.back().IsInsideObjCArrayLiteral =
+  Current.is(TT_ArrayInitializerLSquare) && Current.Previous &&
+  Current.Previous->is(tok::at);
 }
 
 void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
@@ -1578,6 +1581,11 @@ std::unique_ptr Continua
 // likely want to terminate the string before any line breaking is done.
 if (Current.IsUnterminatedLiteral)
   return nullptr;
+// Don't break string literals inside Objective-C array literals (doing so
+// raises the warning -Wobjc-string-concatenation).
+if (State.Stack.back().IsInsideObjCArrayLiteral) {
+  return nullptr;
+}
 
 StringRef Text = Current.TokenText;
 StringRef Prefix;

Modified: cfe/trunk/lib/Format/ContinuationIndenter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.h?rev=324618&r1=324617&r2=324618&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.h (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.h Thu Feb  8 08:07:25 2018
@@ -208,7 +208,8 @@ struct ParenState {
 NoLineBreakInOperand(false), LastOperatorWrapped(true),
 ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
 AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false) {}
+HasMultipleNestedBlocks(false), NestedBlockInlined(false),
+IsInsideObjCArrayLiteral(false) {}
 
   /// \brief The position to which a specific parenthesis level needs to be
   /// indented.
@@ -318,6 +319,10 @@ struct ParenState {
   /// "function" in JavaScript) is not wrapped to a new line.
   bool NestedBlockInlined : 1;
 
+  /// \brief \c true if the current \c ParenState represents an Objective-C
+  /// array literal.
+  bool IsInsideObjCArrayLiteral : 1;
+
   bool operator<(const ParenState &Other) const {
 if (Indent != Other.Indent)
   return Indent < Other.Indent;

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=324618&r1=324617&r2=324618&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Thu Feb  8 08:07:25 2018
@@ -975,6 +975,12 @@ TEST_F(FormatTestObjC, ObjCArrayLiterals
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 20;
+  // We can't break string literals inside NSArray literals
+  // (that raises -Wobjc-string-concatenation).
+  verifyFormat("NSArray *foo 

[PATCH] D42704: [clang-format] Do not break Objective-C string literals inside array literals

2018-02-08 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC324618: [clang-format] Do not break Objective-C string 
literals inside array literals (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42704?vs=132031&id=133428#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42704

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  unittests/Format/FormatTestObjC.cpp


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1285,6 +1285,9 @@
   State.Stack.back().NestedBlockIndent = NestedBlockIndent;
   State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
   State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 1;
+  State.Stack.back().IsInsideObjCArrayLiteral =
+  Current.is(TT_ArrayInitializerLSquare) && Current.Previous &&
+  Current.Previous->is(tok::at);
 }
 
 void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
@@ -1578,6 +1581,11 @@
 // likely want to terminate the string before any line breaking is done.
 if (Current.IsUnterminatedLiteral)
   return nullptr;
+// Don't break string literals inside Objective-C array literals (doing so
+// raises the warning -Wobjc-string-concatenation).
+if (State.Stack.back().IsInsideObjCArrayLiteral) {
+  return nullptr;
+}
 
 StringRef Text = Current.TokenText;
 StringRef Prefix;
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -208,7 +208,8 @@
 NoLineBreakInOperand(false), LastOperatorWrapped(true),
 ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
 AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false) {}
+HasMultipleNestedBlocks(false), NestedBlockInlined(false),
+IsInsideObjCArrayLiteral(false) {}
 
   /// \brief The position to which a specific parenthesis level needs to be
   /// indented.
@@ -318,6 +319,10 @@
   /// "function" in JavaScript) is not wrapped to a new line.
   bool NestedBlockInlined : 1;
 
+  /// \brief \c true if the current \c ParenState represents an Objective-C
+  /// array literal.
+  bool IsInsideObjCArrayLiteral : 1;
+
   bool operator<(const ParenState &Other) const {
 if (Indent != Other.Indent)
   return Indent < Other.Indent;
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -975,6 +975,12 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 20;
+  // We can't break string literals inside NSArray literals
+  // (that raises -Wobjc-string-concatenation).
+  verifyFormat("NSArray *foo = @[\n"
+   "  @\"aa\"\n"
+   "];\n");
 }
 } // end namespace
 } // end namespace format


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1285,6 +1285,9 @@
   State.Stack.back().NestedBlockIndent = NestedBlockIndent;
   State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
   State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 1;
+  State.Stack.back().IsInsideObjCArrayLiteral =
+  Current.is(TT_ArrayInitializerLSquare) && Current.Previous &&
+  Current.Previous->is(tok::at);
 }
 
 void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
@@ -1578,6 +1581,11 @@
 // likely want to terminate the string before any line breaking is done.
 if (Current.IsUnterminatedLiteral)
   return nullptr;
+// Don't break string literals inside Objective-C array literals (doing so
+// raises the warning -Wobjc-string-concatenation).
+if (State.Stack.back().IsInsideObjCArrayLiteral) {
+  return nullptr;
+}
 
 StringRef Text = Current.TokenText;
 StringRef Prefix;
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -208,7 +208,8 @@
 NoLineBreakInOperand(false), LastOperatorWrapped(true),
 ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
 AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false) {}
+HasMultipleNestedBlocks(false), NestedBlockInlined(false),
+IsInsideObjCArrayLiteral(fa

[PATCH] D37057: [clang] Require address space to be specified when creating functions (3/3)

2018-02-08 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

Looks good to me but I guess someone else should approve the change.

I added a bunch of hacks in our fork to ensure that functions end up being in 
address space 200 but this would be much better.


Repository:
  rC Clang

https://reviews.llvm.org/D37057



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


[libcxx] r324619 - Clean up string's deduction guides tests. Mark old versions of clang as unsupported, b/c they don't have deduction guides, even in C++17 mode

2018-02-08 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  8 08:25:57 2018
New Revision: 324619

URL: http://llvm.org/viewvc/llvm-project?rev=324619&view=rev
Log:
Clean up string's deduction guides tests. Mark old versions of clang as 
unsupported, b/c they don't have deduction guides, even in C++17 mode

Added:

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
  - copied, changed from r324618, 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.fail.cpp

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
Removed:
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.fail.cpp
Modified:
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp

Removed: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.fail.cpp?rev=324618&view=auto
==
--- libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.fail.cpp 
(original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.fail.cpp 
(removed)
@@ -1,55 +0,0 @@
-//===--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-
-// 
-// UNSUPPORTED: c++98, c++03, c++11, c++14
-// XFAIL: c++17
-
-// template::value_type>>
-//  basic_string(InputIterator, InputIterator, Allocator = Allocator())
-//-> basic_string::value_type,
-// char_traits::value_type>,
-// Allocator>;
-//
-//  The deduction guide shall not participate in overload resolution if 
InputIterator
-//  is a type that does not qualify as an input iterator, or if Allocator is a 
type
-//  that does not qualify as an allocator.
-
-
-#include 
-#include 
-#include 
-#include 
-
-#include "test_macros.h"
-
-class NotAnItertor {};
-
-template 
-struct NotAnAllocator { typedef T value_type; };
-
-int main()
-{
-{ // Not an iterator at all
-std::basic_string s1{NotAnItertor{}, NotAnItertor{}, 
std::allocator{}}; // expected-error {{no viable constructor or deduction 
guide for deduction of template arguments of 'basic_string'}}
-}
-{ // Not an input iterator
-const char16_t* s = u"12345678901234";
-std::basic_string s0;
-std::basic_string s1{std::back_insert_iterator(s0), //  expected-error 
{{no viable constructor or deduction guide for deduction of template arguments 
of 'basic_string'}}
- std::back_insert_iterator(s0),
- std::allocator{}};
-}
-{ // Not an allocator
-const wchar_t* s = L"12345678901234";
-std::basic_string s1{s, s+10, NotAnAllocator{}}; // 
expected-error {{no viable constructor or deduction guide for deduction of 
template arguments of 'basic_string'}}
-}
-
-}

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp?rev=324619&r1=324618&r2=324619&view=diff
==
--- libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp 
(original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp 
Thu Feb  8 08:25:57 2018
@@ -13,17 +13,6 @@
 //   basic_string(InputIterator begin, InputIterator end,
 //   const Allocator& a = Allocator());
 
-// template::value_type>>
-//  basic_string(InputIterator, InputIterator, Allocator = Allocator())
-//-> basic_string::value_type,
-// char_traits::value_type>,
-// Allocator>;
-//
-// The deduction guide shall not participate in overload resolution if 
InputIterator
-//  is a type that does not qualify as an input iterator, or if Allocator is a 
type
-//  that does not qualify as an allocator.
-
 
 #include 
 #include 
@@ -128,50 +117,4 @@ int main()
 test(input_iterator(s), input_iterator(s+50), 
A());
 }
 #endif
-
-#if 0
-//  Test deduction guides
-#if TEST_STD_VER > 14
-{
-const char* s = "12345678901234";
-std::basic_string s1{s, s+10, std::allocator{}};
-using S = decltype(s1); // what type did we get?
-static_assert(std::is_same_v,  
"");
-static_assert(std::is_same_v>, 
"");
-static_assert(std::is_same_v>, 
"");
-assert(s1.size() == 10);
-assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
-}
-{
-const wchar_t* s = L"12345678901234";
-std::basic_string s1{s, s+10, test_allocator{}};
-using S = decltype(s1); // what type did we get?
-

[PATCH] D43068: [clangd] Remove codeComplete that returns std::future<>

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: unittests/clangd/SyncAPI.h:8
+//
+//===-===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H

ioeric wrote:
> Any reason not to put sync APIs in ClangdServer by their async versions, so 
> that they are easier to find? I might be missing context. But if there is a 
> good reason, please explain in the file doc.
That's a good question. I don't think we want anyone using the sync versions of 
the API. The tests are somewhat special, though, as they'll get really 
complicated if we move everything to callbacks and we don't want that.

This probably deserves a comment.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43068



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


[libcxx] r324624 - Once more, with feeling. Spell 'clang-4.0' correctly this time

2018-02-08 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  8 09:06:08 2018
New Revision: 324624

URL: http://llvm.org/viewvc/llvm-project?rev=324624&view=rev
Log:
Once more, with feeling. Spell 'clang-4.0' correctly this time

Modified:

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp?rev=324624&r1=324623&r2=324624&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 Thu Feb  8 09:06:08 2018
@@ -9,7 +9,7 @@
 
 // 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
-// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang.4-0
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang-4.0
 
 // template::value_type>>

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp?rev=324624&r1=324623&r2=324624&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
 Thu Feb  8 09:06:08 2018
@@ -9,7 +9,7 @@
 
 // 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
-// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang.4-0
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang-4.0
 
 // template
 //   basic_string(InputIterator begin, InputIterator end,


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


[PATCH] D43078: Fix crash on array initializer with non-0 alloca addrspace

2018-02-08 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added a reviewer: yaxunl.
Herald added a subscriber: wdng.

https://reviews.llvm.org/D43078

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenOpenCL/address-space-constant-initializers.cl
  test/CodeGenOpenCL/private-array-initialization.cl


Index: test/CodeGenOpenCL/private-array-initialization.cl
===
--- test/CodeGenOpenCL/private-array-initialization.cl
+++ test/CodeGenOpenCL/private-array-initialization.cl
@@ -1,9 +1,33 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | 
FileCheck -check-prefix=PRIVATE0 %s
+// RUN: %clang_cc1 %s -triple amdgcn-amd-amdhsa-unknown -O0 -emit-llvm -o - | 
FileCheck -check-prefix=PRIVATE5 %s
 
 // CHECK: @test.arr = private unnamed_addr addrspace(2) constant [3 x i32] 
[i32 1, i32 2, i32 3], align 4
 
 void test() {
   __private int arr[] = {1, 2, 3};
-// CHECK:  %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
-// CHECK:  call void @llvm.memcpy.p0i8.p2i8.i32(i8* align 4 %[[arr_i8_ptr]], 
i8 addrspace(2)* align 4 bitcast ([3 x i32] addrspace(2)* @test.arr to i8 
addrspace(2)*), i32 12, i1 false)
+// PRIVATE0:  %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
+// PRIVATE0:  call void @llvm.memcpy.p0i8.p2i8.i32(i8* align 4 
%[[arr_i8_ptr]], i8 addrspace(2)* align 4 bitcast ([3 x i32] addrspace(2)* 
@test.arr to i8 addrspace(2)*), i32 12, i1 false)
+
+// PRIVATE5: %arr = alloca [3 x i32], align 4, addrspace(5)
+// PRIVATE5: %0 = bitcast [3 x i32] addrspace(5)* %arr to i8 addrspace(5)*
+// PRIVATE5: call void @llvm.memcpy.p5i8.p2i8.i64(i8 addrspace(5)* align 4 %0, 
i8 addrspace(2)* align 4 bitcast ([3 x i32] addrspace(2)* @test.arr to i8 
addrspace(2)*), i64 12, i1 false)
+}
+
+__kernel void initializer_cast_is_valid_crash() {
+// PRIVATE0: %v512 = alloca [64 x i8], align 1
+// PRIVATE0: %0 = bitcast [64 x i8]* %v512 to i8*
+// PRIVATE0: call void @llvm.memset.p0i8.i32(i8* align 1 %0, i8 0, i32 64, i1 
false)
+// PRIVATE0: %1 = bitcast i8* %0 to [64 x i8]*
+
+
+// PRIVATE5: %v512 = alloca [64 x i8], align 1, addrspace(5)
+// PRIVATE5: %0 = bitcast [64 x i8] addrspace(5)* %v512 to i8 addrspace(5)*
+// PRIVATE5: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* align 1 %0, i8 
0, i64 64, i1 false)
+// PRIVATE5: %1 = bitcast i8 addrspace(5)* %0 to [64 x i8] addrspace(5)*
+  unsigned char v512[64] = {
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00
+  };
 }
Index: test/CodeGenOpenCL/address-space-constant-initializers.cl
===
--- test/CodeGenOpenCL/address-space-constant-initializers.cl
+++ test/CodeGenOpenCL/address-space-constant-initializers.cl
@@ -20,3 +20,13 @@
 &constant_array_struct.f
 };
 
+__kernel void initializer_cast_is_valid_crash()
+{
+  unsigned char v512[64] = {
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00
+  };
+
+}
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1337,7 +1337,8 @@
  isVolatile);
 // Zero and undef don't require a stores.
 if (!constant->isNullValue() && !isa(constant)) {
-  Loc = Builder.CreateBitCast(Loc, constant->getType()->getPointerTo());
+  Loc = Builder.CreateBitCast(Loc,
+constant->getType()->getPointerTo(Loc.getAddressSpace()));
   emitStoresForInitAfterMemset(constant, Loc.getPointer(),
isVolatile, Builder);
 }


Index: test/CodeGenOpenCL/private-array-initialization.cl
===
--- test/CodeGenOpenCL/private-array-initialization.cl
+++ test/CodeGenOpenCL/private-array-initialization.cl
@@ -1,9 +1,33 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | FileCheck -check-prefix=PRIVATE0 %s
+// RUN: %clang_cc1 %s -triple amdgcn-amd-amdhsa-unknown -O0 -emit-llvm -o - | FileCheck -check-prefix=PRIVATE5 %s
 
 // CHECK: @test.arr = private unnamed_addr addrspace(2) constant [3 x i32] [i32 1, i32 2, i32 3], align 4
 
 void test() {
   __private int arr[] = {1, 2, 3};
-// CHECK:  %[[arr_i8_pt

[PATCH] D43068: [clangd] Remove codeComplete that returns std::future<>

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: unittests/clangd/SyncAPI.h:8
+//
+//===-===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H

ilya-biryukov wrote:
> ioeric wrote:
> > Any reason not to put sync APIs in ClangdServer by their async versions, so 
> > that they are easier to find? I might be missing context. But if there is a 
> > good reason, please explain in the file doc.
> That's a good question. I don't think we want anyone using the sync versions 
> of the API. The tests are somewhat special, though, as they'll get really 
> complicated if we move everything to callbacks and we don't want that.
> 
> This probably deserves a comment.
If these are expected to be used by tests only, I'd suggest moving the file to 
the test directory.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43068



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


[PATCH] D40284: [Sema] Improve diagnostics for template arg deduction

2018-02-08 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes updated this revision to Diff 133440.
jtbandes added a comment.

Using a slightly more invasive fix. I haven't come up with any other test cases 
that exhibit the problem, which makes me unsure this fix is needed in all these 
locations. Maybe someone with more knowledge of this function can advise.


Repository:
  rC Clang

https://reviews.llvm.org/D40284

Files:
  lib/Sema/SemaTemplateDeduction.cpp
  test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp

Index: test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp
===
--- test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp
+++ test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp
@@ -45,3 +45,11 @@
 func(foo()); // expected-error {{no matching function}}
   }
 }
+
+namespace test4 {
+  // expected-note@+1 {{candidate template ignored: could not match 'int [N]' against 'int []'}}
+  template void f1(int (&arr)[N]);
+  template void f2(int (&arr)[]) {
+f1(arr); // expected-error {{no matching function}}
+  }
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -1289,27 +1289,34 @@
 return Sema::TDK_Success;
   }
 
-  // Set up the template argument deduction information for a failure.
-  Info.FirstArg = TemplateArgument(ParamIn);
-  Info.SecondArg = TemplateArgument(ArgIn);
-
   // If the parameter is an already-substituted template parameter
   // pack, do nothing: we don't know which of its arguments to look
   // at, so we have to wait until all of the parameter packs in this
   // expansion have arguments.
   if (isa(Param))
 return Sema::TDK_Success;
 
+  // Use this when returning a failure result in order to fill in the
+  // corresponding failure info. Don't use this when returning the
+  // result of a recursive call, as the callee will have already set
+  // their own failure info.
+  const auto WithFailureInfo =
+[&Info, &ParamIn, &ArgIn](Sema::TemplateDeductionResult Result) {
+  Info.FirstArg = TemplateArgument(ParamIn);
+  Info.SecondArg = TemplateArgument(ArgIn);
+  return Result;
+};
+
   // Check the cv-qualifiers on the parameter and argument types.
   CanQualType CanParam = S.Context.getCanonicalType(Param);
   CanQualType CanArg = S.Context.getCanonicalType(Arg);
   if (!(TDF & TDF_IgnoreQualifiers)) {
 if (TDF & TDF_ParamWithReferenceType) {
   if (hasInconsistentOrSupersetQualifiersOf(Param, Arg))
-return Sema::TDK_NonDeducedMismatch;
+return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
 } else if (!IsPossiblyOpaquelyQualifiedType(Param)) {
   if (Param.getCVRQualifiers() != Arg.getCVRQualifiers())
-return Sema::TDK_NonDeducedMismatch;
+return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
 }
 
 // If the parameter type is not dependent, there is nothing to deduce.
@@ -1319,9 +1326,8 @@
 (TDF & TDF_AllowCompatibleFunctionType)
 ? !S.isSameOrCompatibleFunctionType(CanParam, CanArg)
 : Param != Arg;
-if (NonDeduced) {
-  return Sema::TDK_NonDeducedMismatch;
-}
+if (NonDeduced)
+  return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
   }
   return Sema::TDK_Success;
 }
@@ -1366,7 +1372,10 @@
 Arg = Arg.getUnqualifiedType();
   }
 
-  return Param == Arg? Sema::TDK_Success : Sema::TDK_NonDeducedMismatch;
+  if (Param == Arg)
+return Sema::TDK_Success;
+
+  return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
 }
 
 // _Complex T   [placeholder extension]
@@ -1377,7 +1386,7 @@
 ComplexArg->getElementType(),
 Info, Deduced, TDF);
 
-  return Sema::TDK_NonDeducedMismatch;
+  return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
 
 // _Atomic T   [extension]
 case Type::Atomic:
@@ -1387,7 +1396,7 @@
AtomicArg->getValueType(),
Info, Deduced, TDF);
 
-  return Sema::TDK_NonDeducedMismatch;
+  return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
 
 // T *
 case Type::Pointer: {
@@ -1398,7 +1407,7 @@
= Arg->getAs()) {
 PointeeType = PointerArg->getPointeeType();
   } else {
-return Sema::TDK_NonDeducedMismatch;
+return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
   }
 
   unsigned SubTDF = TDF & (TDF_IgnoreQualifiers | TDF_DerivedClass);
@@ -1413,7 +1422,7 @@
   const LValueReferenceType *ReferenceArg =
   Arg->getAs();
   if (!ReferenceArg)
-return Sema::TDK_NonDeducedMismatch;
+return WithFailureInfo(Sema::TDK_NonDeducedMismatch);
 
   return DeduceTemplateArgumentsByT

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133441.
MaskRay added a comment.

Don't deprecate CXIdxEntityRefInfo


Repository:
  rC Clang

https://reviews.llvm.org/D42895

Files:
  include/clang-c/Index.h
  include/clang/Index/IndexSymbol.h
  test/Index/index-decls.m
  test/Index/index-refs.cpp
  test/Index/index-subscripting-literals.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -436,13 +436,15 @@
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -148,6 +148,11 @@
 return true;
   }
 };
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
+  // CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role) & ((1 << 9) - 1));
+}
 }
 
 bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
@@ -184,6 +189,7 @@
 if (Roles & (unsigned)SymbolRole::Implicit) {
   Kind = CXIdxEntityRef_Implicit;
 }
+CXSymbolRole CXRole = getSymbolRole(Roles);
 
 CXCursor Cursor;
 if (ASTNode.OrigE) {
@@ -202,7 +208,7 @@
 }
 handleReference(ND, Loc, Cursor,
 dyn_cast_or_null(ASTNode.Parent),
-ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
 
   } else {
 const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -889,21 +895,23 @@
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
   : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!CB.indexEntityReference)
 return false;
 
@@ -939,7 +947,8 @@
   getIndexLoc(Loc),
   &RefEntity,
   Parent ? &ParentEntity : nullptr,
-  &Container };
+  &Container,
+  Role };
   CB.indexEntityReference(ClientData, &Info);
   return true;
 }
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -3326,6 +3326,27 @@
   }
 }
 
+static void printSymbolRole(CXSymbolRole role) {
+  if (role & CXSymbolRole_Declaration)
+printf(" decl");
+  if (role & CXSymbolRole_Definition)
+printf(" def");
+  if (role & CXSymbolRole_Reference)
+printf(" ref");
+  if (role & CXSymbolRole_Read)
+printf(" read");
+  if (role & CXSymbolRole_Write)
+printf(" write");
+  if (role & CXSymbolRole_Call)
+printf(" call");
+  if (role & CXSymbolRole_Dynamic)
+printf(" dyn");
+  if (role & CXSymbolRole_AddressOf)
+printf(" addr");
+  if (role & CXSymbolRole_Implicit)
+printf(" implicit");
+}
+
 static void index_diagnostic(CXClientData clien

[PATCH] D41597: Driver: ignore -mbig-obj like /bigobj

2018-02-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm

This works even though we pass -Wa,-mbig-obj?


Repository:
  rC Clang

https://reviews.llvm.org/D41597



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


[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 4 inline comments as done.
MaskRay added inline comments.



Comment at: include/clang-c/Index.h:6159
+   */
+  CXSymbolRole role;
 } CXIdxEntityRefInfo;

ilya-biryukov wrote:
> MaskRay wrote:
> > ilya-biryukov wrote:
> > > Why do we need to store both `CXIdxEntityRefKind` and `CXSymbolRole`? Can 
> > > we store just `CXSymbolRole`?
> > > Is this for compatibility with existing clients?
> > > 
> > > If so, maybe we could:
> > > - remove `Implicit` and `Direct` from the `CXSymbolRole`
> > > - keep it only in `CXIdxEntityRefKind`
> > > - not deprecate the `CXIdxEntityRefKind`
> > I think `CXIdxEntityRefKind` should be deprecated but for compatibility we 
> > do not remove the field for this minor version upgrade. But they can be 
> > removed after a major version upgrade.
> > 
> > For what I have observed, `Implicit` is only used by Objective-C
> We should definitely loop the owners of libclang in if we want to deprecate 
> the API, I'm not familiar with the contract of libclang regarding the API 
> deprecation.
> I'm not sure who's responsible for that, asking at the cfe-dev mailing list 
> could be your best bet for that.
> 
> The alternative I suggest is removing `Implicit` from `CXSymbolRole`, making 
> this change an extension of existing API. I expect that this could be done 
> without more through discussion.
I'll keep `CXSymbolRole_Implicit` and make it duplicate the functionality 
provided by CXIdxEntityRefKind, with a comment that CXIdxEntityRefKind may be 
deprecated in a future version.

Thanks, I'll also ask the cfe-dev mailing list.



Comment at: tools/libclang/CXIndexDataConsumer.cpp:154
+  // CXSymbolRole is synchronized with clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role));
+}

ilya-biryukov wrote:
> MaskRay wrote:
> > ilya-biryukov wrote:
> > > `SymbolRoleSet` seems to have more roles not covered by `CXSymbolRole`.
> > > Should they be accepted by this function? 
> > > If yes, maybe zero those bits?
> > > If no, maybe add an assert?
> > > 
> > > 
> > > The extra roles are:
> > > ```
> > >   RelationChildOf = 1 << 9,
> > >   RelationBaseOf  = 1 << 10,
> > >   RelationOverrideOf  = 1 << 11,
> > >   RelationReceivedBy  = 1 << 12,
> > >   RelationCalledBy= 1 << 13,
> > >   RelationExtendedBy  = 1 << 14,
> > >   RelationAccessorOf  = 1 << 15,
> > >   RelationContainedBy = 1 << 16,
> > >   RelationIBTypeOf= 1 << 17,
> > >   RelationSpecializationOf = 1 << 18,
> > > ```
> > Yes, it has more relations, but most are only used by Objective-C. In all 
> > test/Index tests, I have only seen `RelationContainedBy` used for .cpp 
> > files. Many have not occurred in .m files. So I do not want to expose them, 
> > at least for now.
> > 
> > 
> It's fine, but let's add a comment and zero those bits out.
> 
> Could you also a comments to both `SymbolRoleSet` and `CXSymbolRole` that 
> they mirror each other and need to be updated together?
zeroed high bits of CXSymbolRole and left comments.


Repository:
  rC Clang

https://reviews.llvm.org/D42895



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


[PATCH] D43041: Add X86 Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 133443.
erichkeane added a comment.

removed careless newline, also rebases off ARM patch.


https://reviews.llvm.org/D43041

Files:
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  test/Misc/target-invalid-cpu-note.c


Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -5,3 +5,11 @@
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
 // AARCH64: note: valid target CPU values are: cortex-a35,
+
+// RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X86
+// X86: error: unknown target CPU 'not-a-cpu'
+// X86: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, 
c3, i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pentium3, 
pentium3m, pentium-m, c3-2, yonah, pentium4, pentium4m, prescott, nocona, 
core2, penryn, bonnell, atom, silvermont, slm, goldmont, nehalem, corei7, 
westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, 
broadwell, skylake, skylake-avx512, skx, cannonlake, icelake, knl, knm, 
lakemont, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, 
k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, 
amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, 
x86-64, geode
+
+// RUN: not %clang_cc1 -triple x86_64--- -target-cpu not-a-cpu -fsyntax-only 
%s 2>&1 | FileCheck %s --check-prefix X86_64
+// X86_64: error: unknown target CPU 'not-a-cpu'
+// X86_64: note: valid target CPU values are: nocona, core2, penryn, bonnell, 
atom, silvermont, slm, goldmont, nehalem, corei7, westmere, sandybridge, 
corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, 
skylake-avx512, skx, cannonlake, icelake, knl, knm, k8, athlon64, athlon-fx, 
opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, 
btver2, bdver1, bdver2, bdver3, bdver4, znver1, x86-64
Index: lib/Basic/Targets/X86.h
===
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -264,6 +264,8 @@
 return checkCPUKind(getCPUKind(Name));
   }
 
+  void fillValidCPUList(SmallVectorImpl &Values) const override;
+
   bool setCPU(const std::string &Name) override {
 return checkCPUKind(CPU = getCPUKind(Name));
   }
Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/TargetParser.h"
@@ -1648,8 +1649,6 @@
 bool X86TargetInfo::checkCPUKind(CPUKind Kind) const {
   // Perform any per-CPU checks necessary to determine if this CPU is
   // acceptable.
-  // FIXME: This results in terrible diagnostics. Clang just says the CPU is
-  // invalid without explaining *why*.
   switch (Kind) {
   case CK_Generic:
 // No processor selected!
@@ -1662,6 +1661,18 @@
   llvm_unreachable("Unhandled CPU kind");
 }
 
+void X86TargetInfo::fillValidCPUList(SmallVectorImpl &Values) const 
{
+#define PROC(ENUM, STRING, IS64BIT)
\
+  if (IS64BIT || getTriple().getArch() == llvm::Triple::x86)   
\
+Values.emplace_back(STRING);
+  // Go through CPUKind checking to ensure that the alias is de-aliased and 
+  // 64 bit-ness is checked.
+#define PROC_ALIAS(ENUM, ALIAS)
\
+  if (checkCPUKind(getCPUKind(ALIAS))) 
\
+Values.emplace_back(ALIAS);
+#include "clang/Basic/X86Target.def"
+}
+
 X86TargetInfo::CPUKind X86TargetInfo::getCPUKind(StringRef CPU) const {
   return llvm::StringSwitch(CPU)
 #define PROC(ENUM, STRING, IS64BIT) .Case(STRING, CK_##ENUM)


Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -5,3 +5,11 @@
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
 // AARCH64: note: valid target CPU values are: cortex-a35,
+
+// RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix X86
+// X86: error: unknown target CPU 'not-a-cpu'
+// X86: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, c3, i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pen

[PATCH] D43068: [clangd] Remove codeComplete that returns std::future<>

2018-02-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: unittests/clangd/SyncAPI.h:8
+//
+//===-===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H

ioeric wrote:
> ilya-biryukov wrote:
> > ioeric wrote:
> > > Any reason not to put sync APIs in ClangdServer by their async versions, 
> > > so that they are easier to find? I might be missing context. But if there 
> > > is a good reason, please explain in the file doc.
> > That's a good question. I don't think we want anyone using the sync 
> > versions of the API. The tests are somewhat special, though, as they'll get 
> > really complicated if we move everything to callbacks and we don't want 
> > that.
> > 
> > This probably deserves a comment.
> If these are expected to be used by tests only, I'd suggest moving the file 
> to the test directory.
I think it's in the unittest directory already, so we're covered here :-)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43068



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


[PATCH] D43068: [clangd] Remove codeComplete that returns std::future<>

2018-02-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: unittests/clangd/SyncAPI.h:8
+//
+//===-===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H

ilya-biryukov wrote:
> ioeric wrote:
> > ilya-biryukov wrote:
> > > ioeric wrote:
> > > > Any reason not to put sync APIs in ClangdServer by their async 
> > > > versions, so that they are easier to find? I might be missing context. 
> > > > But if there is a good reason, please explain in the file doc.
> > > That's a good question. I don't think we want anyone using the sync 
> > > versions of the API. The tests are somewhat special, though, as they'll 
> > > get really complicated if we move everything to callbacks and we don't 
> > > want that.
> > > 
> > > This probably deserves a comment.
> > If these are expected to be used by tests only, I'd suggest moving the file 
> > to the test directory.
> I think it's in the unittest directory already, so we're covered here :-)
Sorry! My bad!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43068



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


[PATCH] D43041: Add X86 Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D43041



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


[PATCH] D43041: Add X86 Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/Basic/Targets/X86.cpp:1670-1672
+#define PROC_ALIAS(ENUM, ALIAS)
\
+  if (checkCPUKind(getCPUKind(ALIAS))) 
\
+Values.emplace_back(ALIAS);

`checkCPUKind()` doesn't define `PROC_ALIAS` so I don't think it can handle the 
values?



Comment at: test/Misc/target-invalid-cpu-note.c:11
+// X86: error: unknown target CPU 'not-a-cpu'
+// X86: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, 
c3, i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pentium3, 
pentium3m, pentium-m, c3-2, yonah, pentium4, pentium4m, prescott, nocona, 
core2, penryn, bonnell, atom, silvermont, slm, goldmont, nehalem, corei7, 
westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, 
broadwell, skylake, skylake-avx512, skx, cannonlake, icelake, knl, knm, 
lakemont, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, 
k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, 
amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, 
x86-64, geode
+

If we really want to check all these values (does any other test do it? I don't 
really get the value) this line needs to be split, it's way too long.


https://reviews.llvm.org/D43041



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


[PATCH] D43041: Add X86 Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/Basic/Targets/X86.cpp:1670-1672
+#define PROC_ALIAS(ENUM, ALIAS)
\
+  if (checkCPUKind(getCPUKind(ALIAS))) 
\
+Values.emplace_back(ALIAS);

Hahnfeld wrote:
> `checkCPUKind()` doesn't define `PROC_ALIAS` so I don't think it can handle 
> the values?
Never mind, the enum value is enough. Silly me :-/


https://reviews.llvm.org/D43041



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


[PATCH] D42745: [analyzer] Add support for __builtin_constant_p to BuiltinFunctionChecker

2018-02-08 Thread Felix Kostenzer via Phabricator via cfe-commits
sp4r74n-117 updated this revision to Diff 133447.
sp4r74n-117 added a comment.

Thanks for the explanation, seems like I was on the wrong track.
I now do realize that my initial approach was in fact duplicating the logic of 
'BI__builtin_object_size'.
I've removed most of the changes applied to the checker and extended the 'case' 
instead.
What remains is the regression test tho.


https://reviews.llvm.org/D42745

Files:
  lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  test/Analysis/builtin-functions.cpp


Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -64,3 +64,20 @@
 // We give up the analysis on this path.
   }
 }
+
+void test_constant_p() {
+  int i = 1;
+  const int j = 2;
+  constexpr int k = 3;
+  clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // 
expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning 
{{FALSE}}
+  clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning 
{{TRUE}}
+}
Index: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -97,7 +97,8 @@
 return true;
   }
 
-  case Builtin::BI__builtin_object_size: {
+  case Builtin::BI__builtin_object_size:
+  case Builtin::BI__builtin_constant_p: {
 // This must be resolvable at compile time, so we defer to the constant
 // evaluator for a value.
 SVal V = UnknownVal();


Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -64,3 +64,20 @@
 // We give up the analysis on this path.
   }
 }
+
+void test_constant_p() {
+  int i = 1;
+  const int j = 2;
+  constexpr int k = 3;
+  clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning {{FALSE}}
+  clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning {{TRUE}}
+}
Index: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -97,7 +97,8 @@
 return true;
   }
 
-  case Builtin::BI__builtin_object_size: {
+  case Builtin::BI__builtin_object_size:
+  case Builtin::BI__builtin_constant_p: {
 // This must be resolvable at compile time, so we defer to the constant
 // evaluator for a value.
 SVal V = UnknownVal();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43013: ASan+operator new[]: Fix operator new[] cookie poisoning

2018-02-08 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Okay, thanks.  LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D43013



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133455.
MaskRay added a comment.

Add option `Enabled` which defaults to 0.
Suggest std::simd (-std=c++2a) or std::experimental::std (-std=c++11) only if 
enabled.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+In C++11 mode, if the option ``Enabled`` is turned on, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,40 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHEC

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 9 inline comments as done.
MaskRay added a comment.

The check must be manually enabled now:

  % clang-tidy -checks='-*,readability-simd-intrinsics' a.cc -- -std=c++2a
  # Not enabled by default
  
  % clang-tidy -checks='-*,readability-simd-intrinsics' -config='{CheckOptions: 
[{key: readability-simd-intrinsics.Enabled, value: 1}]}' a.cc -- -std=c++11
  # warn and suggest std::experimental::simd
  
  % clang-tidy -checks='-*,readability-simd-intrinsics' -config='{CheckOptions: 
[{key: readability-simd-intrinsics.Enabled, value: 1}]}' a.cc -- -std=c++2a
  # warn and suggest std::simd


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D43078: Fix crash on array initializer with non-0 alloca addrspace

2018-02-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


https://reviews.llvm.org/D43078



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


[PATCH] D43041: Add X86 Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 133456.
erichkeane added a comment.

Cleaned up the test as suggested.


https://reviews.llvm.org/D43041

Files:
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  test/Misc/target-invalid-cpu-note.c


Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -7,3 +7,27 @@
 // AARCH64: error: unknown target CPU 'not-a-cpu'
 // AARCH64: note: valid target CPU values are:
 // AARCH64-SAME: cortex-a35
+
+// RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X86
+// X86: error: unknown target CPU 'not-a-cpu'
+// X86: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, 
c3,
+// X86-SAME: i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pentium3,
+// X86-SAME: pentium3m, pentium-m, c3-2, yonah, pentium4, pentium4m, prescott,
+// X86-SAME: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont,
+// X86-SAME: nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge,
+// X86-SAME: core-avx-i, haswell, core-avx2, broadwell, skylake, 
skylake-avx512,
+// X86-SAME: skx, cannonlake, icelake, knl, knm, lakemont, k6, k6-2, k6-3,
+// X86-SAME: athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, 
athlon64,
+// X86-SAME: athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, 
amdfam10,
+// X86-SAME: barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1,
+// X86-SAME: x86-64, geode
+
+// RUN: not %clang_cc1 -triple x86_64--- -target-cpu not-a-cpu -fsyntax-only 
%s 2>&1 | FileCheck %s --check-prefix X86_64
+// X86_64: error: unknown target CPU 'not-a-cpu'
+// X86_64: note: valid target CPU values are: nocona, core2, penryn, bonnell,
+// X86_64-SAME: atom, silvermont, slm, goldmont, nehalem, corei7, westmere,
+// X86_64-SAME: sandybridge, corei7-avx, ivybridge, core-avx-i, haswell,
+// X86_64-SAME: core-avx2, broadwell, skylake, skylake-avx512, skx, cannonlake,
+// X86_64-SAME: icelake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3,
+// X86_64-SAME: athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1,
+// X86_64-SAME: btver2, bdver1, bdver2, bdver3, bdver4, znver1, x86-64
Index: lib/Basic/Targets/X86.h
===
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -264,6 +264,8 @@
 return checkCPUKind(getCPUKind(Name));
   }
 
+  void fillValidCPUList(SmallVectorImpl &Values) const override;
+
   bool setCPU(const std::string &Name) override {
 return checkCPUKind(CPU = getCPUKind(Name));
   }
Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/TargetParser.h"
@@ -1648,8 +1649,6 @@
 bool X86TargetInfo::checkCPUKind(CPUKind Kind) const {
   // Perform any per-CPU checks necessary to determine if this CPU is
   // acceptable.
-  // FIXME: This results in terrible diagnostics. Clang just says the CPU is
-  // invalid without explaining *why*.
   switch (Kind) {
   case CK_Generic:
 // No processor selected!
@@ -1662,6 +1661,18 @@
   llvm_unreachable("Unhandled CPU kind");
 }
 
+void X86TargetInfo::fillValidCPUList(SmallVectorImpl &Values) const 
{
+#define PROC(ENUM, STRING, IS64BIT)
\
+  if (IS64BIT || getTriple().getArch() == llvm::Triple::x86)   
\
+Values.emplace_back(STRING);
+  // Go through CPUKind checking to ensure that the alias is de-aliased and 
+  // 64 bit-ness is checked.
+#define PROC_ALIAS(ENUM, ALIAS)
\
+  if (checkCPUKind(getCPUKind(ALIAS))) 
\
+Values.emplace_back(ALIAS);
+#include "clang/Basic/X86Target.def"
+}
+
 X86TargetInfo::CPUKind X86TargetInfo::getCPUKind(StringRef CPU) const {
   return llvm::StringSwitch(CPU)
 #define PROC(ENUM, STRING, IS64BIT) .Case(STRING, CK_##ENUM)


Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -7,3 +7,27 @@
 // AARCH64: error: unknown target CPU 'not-a-cpu'
 // AARCH64: note: valid target CPU values are:
 // AARCH64-SAME: cortex-a35
+
+// RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix X86
+// X86: error: unknown target CPU 'not-a-cpu'
+// X86: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, c3,
+// X86-SAME: i586, pentium, pentium-mmx, pentiumpro, i686, 

[PATCH] D42530: Clang permits assignment to vector/extvector elements in a const method

2018-02-08 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, that looks a lot better.  One minor piece of feedback, but otherwise 
LGTM.




Comment at: lib/Sema/SemaExpr.cpp:4402
+Qualifiers MemberQuals =
+Context.getCanonicalType(ResultType).getQualifiers();
+Qualifiers Combined = BaseQuals + MemberQuals;

You shouldn't have to get the canonical type here.



Comment at: test/Sema/assign.c:17
+  b[4] = 1; // expected-error {{cannot assign to variable 'b' with 
const-qualified type 'const arr' (aka 'int const[10]')}}
+  b2[4] = 1;// expected-error {{cannot assign to variable 'b2' with 
const-qualified type 'const int [10]'}}
 }

These are nice improvements, thanks.  There's still room for getting ever 
better, but this is already nice progress.


https://reviews.llvm.org/D42530



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


[PATCH] D42549: [CodeGen] Use the zero initializer instead of storing an all zero representation.

2018-02-08 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I'm somewhat surprised LLVM doesn't already canonicalize this, but ok.

Should we also do this when building a constant struct?




Comment at: lib/CodeGen/CGExprConstant.cpp:873
   Elts.push_back(C);
+  if (!C->isNullValue())
+AllNullValues = false;

Please short-circuit this if AllNullValues is already false.


https://reviews.llvm.org/D42549



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133457.
MaskRay added a comment.

Set `Enabled` to 1 in test/clang-tidy/readability-simd-intrinsics.cpp


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -std=c++2a
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+In C++11 mode, if the option ``Enabled`` is turned on, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,40 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H

[PATCH] D43045: Add NVPTX Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 133458.
erichkeane added a comment.

rebased, reflowed tests.


https://reviews.llvm.org/D43045

Files:
  include/clang/Basic/Cuda.h
  lib/Basic/Cuda.cpp
  lib/Basic/Targets/NVPTX.cpp
  lib/Basic/Targets/NVPTX.h
  test/Misc/target-invalid-cpu-note.c


Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -31,3 +31,8 @@
 // X86_64-SAME: icelake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3,
 // X86_64-SAME: athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1,
 // X86_64-SAME: btver2, bdver1, bdver2, bdver3, bdver4, znver1, x86-64
+
+// RUN: not %clang_cc1 -triple nvptx--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix NVPTX
+// NVPTX: error: unknown target CPU 'not-a-cpu'
+// NVPTX: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35,
+// NVPTX-SAME: sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72
Index: lib/Basic/Targets/NVPTX.h
===
--- lib/Basic/Targets/NVPTX.h
+++ lib/Basic/Targets/NVPTX.h
@@ -98,6 +98,12 @@
 return StringToCudaArch(Name) != CudaArch::UNKNOWN;
   }
 
+  void fillValidCPUList(SmallVectorImpl &Values) const override {
+for (int i = static_cast(CudaArch::SM_20);
+ i < static_cast(CudaArch::LAST); ++i)
+  Values.emplace_back(CudaArchToString(static_cast(i)));
+  }
+
   bool setCPU(const std::string &Name) override {
 GPU = StringToCudaArch(Name);
 return GPU != CudaArch::UNKNOWN;
Index: lib/Basic/Targets/NVPTX.cpp
===
--- lib/Basic/Targets/NVPTX.cpp
+++ lib/Basic/Targets/NVPTX.cpp
@@ -157,6 +157,8 @@
 // Set __CUDA_ARCH__ for the GPU specified.
 std::string CUDAArchCode = [this] {
   switch (GPU) {
+  case CudaArch::LAST:
+break;
   case CudaArch::UNKNOWN:
 assert(false && "No GPU arch when compiling CUDA device code.");
 return "";
Index: lib/Basic/Cuda.cpp
===
--- lib/Basic/Cuda.cpp
+++ lib/Basic/Cuda.cpp
@@ -26,6 +26,8 @@
 
 const char *CudaArchToString(CudaArch A) {
   switch (A) {
+  case CudaArch::LAST:
+break;
   case CudaArch::UNKNOWN:
 return "unknown";
   case CudaArch::SM_20:
@@ -133,6 +135,8 @@
 
 CudaVirtualArch VirtualArchForCudaArch(CudaArch A) {
   switch (A) {
+  case CudaArch::LAST:
+break;
   case CudaArch::UNKNOWN:
 return CudaVirtualArch::UNKNOWN;
   case CudaArch::SM_20:
@@ -168,6 +172,8 @@
 
 CudaVersion MinVersionForCudaArch(CudaArch A) {
   switch (A) {
+  case CudaArch::LAST:
+break;
   case CudaArch::UNKNOWN:
 return CudaVersion::UNKNOWN;
   case CudaArch::SM_20:
Index: include/clang/Basic/Cuda.h
===
--- include/clang/Basic/Cuda.h
+++ include/clang/Basic/Cuda.h
@@ -46,6 +46,7 @@
   SM_62,
   SM_70,
   SM_72,
+  LAST,
 };
 const char *CudaArchToString(CudaArch A);
 


Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -31,3 +31,8 @@
 // X86_64-SAME: icelake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3,
 // X86_64-SAME: athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1,
 // X86_64-SAME: btver2, bdver1, bdver2, bdver3, bdver4, znver1, x86-64
+
+// RUN: not %clang_cc1 -triple nvptx--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix NVPTX
+// NVPTX: error: unknown target CPU 'not-a-cpu'
+// NVPTX: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35,
+// NVPTX-SAME: sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72
Index: lib/Basic/Targets/NVPTX.h
===
--- lib/Basic/Targets/NVPTX.h
+++ lib/Basic/Targets/NVPTX.h
@@ -98,6 +98,12 @@
 return StringToCudaArch(Name) != CudaArch::UNKNOWN;
   }
 
+  void fillValidCPUList(SmallVectorImpl &Values) const override {
+for (int i = static_cast(CudaArch::SM_20);
+ i < static_cast(CudaArch::LAST); ++i)
+  Values.emplace_back(CudaArchToString(static_cast(i)));
+  }
+
   bool setCPU(const std::string &Name) override {
 GPU = StringToCudaArch(Name);
 return GPU != CudaArch::UNKNOWN;
Index: lib/Basic/Targets/NVPTX.cpp
===
--- lib/Basic/Targets/NVPTX.cpp
+++ lib/Basic/Targets/NVPTX.cpp
@@ -157,6 +157,8 @@
 // Set __CUDA_ARCH__ for the GPU specified.
 std::string CUDAArchCode = [this] {
   switch (GPU) {
+  case CudaArch::LAST:
+break;
   case CudaArch::UNKNOWN:
 assert(false && "No GPU arch when compiling CUDA device code.");
 return "";
Index: 

[PATCH] D43057: Add Rest of Targets Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 133459.
erichkeane added a comment.

rebased, reflowed tests.


https://reviews.llvm.org/D43057

Files:
  lib/Basic/Targets/AMDGPU.cpp
  lib/Basic/Targets/AMDGPU.h
  lib/Basic/Targets/AVR.cpp
  lib/Basic/Targets/AVR.h
  lib/Basic/Targets/BPF.cpp
  lib/Basic/Targets/BPF.h
  lib/Basic/Targets/Hexagon.cpp
  lib/Basic/Targets/Hexagon.h
  lib/Basic/Targets/Lanai.cpp
  lib/Basic/Targets/Lanai.h
  lib/Basic/Targets/Mips.cpp
  lib/Basic/Targets/Mips.h
  lib/Basic/Targets/Nios2.h
  lib/Basic/Targets/PPC.cpp
  lib/Basic/Targets/PPC.h
  lib/Basic/Targets/Sparc.cpp
  lib/Basic/Targets/Sparc.h
  lib/Basic/Targets/SystemZ.cpp
  lib/Basic/Targets/SystemZ.h
  lib/Basic/Targets/WebAssembly.cpp
  lib/Basic/Targets/WebAssembly.h
  test/Misc/target-invalid-cpu-note.c

Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -6,7 +6,7 @@
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
 // AARCH64: note: valid target CPU values are:
-// AARCH64-SAME: cortex-a35
+// AARCH64-SAME: cortex-a35,
 
 // RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix X86
 // X86: error: unknown target CPU 'not-a-cpu'
@@ -36,3 +36,127 @@
 // NVPTX: error: unknown target CPU 'not-a-cpu'
 // NVPTX: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35,
 // NVPTX-SAME: sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72
+
+// RUN: not %clang_cc1 -triple r600--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix R600
+// R600: error: unknown target CPU 'not-a-cpu'
+// R600: note: valid target CPU values are: r600, rv610, rv620, rv630, rv635,
+// R600-SAME: rs780, rs880, rv670, rv710, rv730, rv740, rv770, palm, cedar,
+// R600-SAME: sumo, sumo2, redwood, juniper, hemlock, cypress, barts, turks,
+// R600-SAME: caicos, cayman, aruba
+
+
+// RUN: not %clang_cc1 -triple amdgcn--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AMDGCN
+// AMDGCN: error: unknown target CPU 'not-a-cpu'
+// AMDGCN: note: valid target CPU values are: gfx600, tahiti, gfx601, pitcairn,
+// AMDGCN-SAME: verde, oland, hainan, gfx700, bonaire, kaveri, gfx701, hawaii,
+// AMDGCN-SAME: gfx702, gfx703, kabini, mullins, gfx800, iceland, gfx801,
+// AMDGCN-SAME: carrizo, gfx802, tonga, gfx803, fiji, polaris10, polaris11,
+// AMDGCN-SAME: gfx804, gfx810, stoney, gfx900, gfx901, gfx902, gfx903
+
+// RUN: not %clang_cc1 -triple wasm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix WEBASM
+// WEBASM: error: unknown target CPU 'not-a-cpu'
+// WEBASM: note: valid target CPU values are: mvp, bleeding-edge, generic
+
+// RUN: not %clang_cc1 -triple systemz--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix SYSTEMZ
+// SYSTEMZ: error: unknown target CPU 'not-a-cpu'
+// SYSTEMZ: note: valid target CPU values are: arch8, z10, arch9, z196, arch10,
+// SYSTEMZ-SAME: zEC12, arch11, z13, arch12, z14
+
+// RUN: not %clang_cc1 -triple sparc--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix SPARC
+// SPARC: error: unknown target CPU 'not-a-cpu'
+// SPARC: note: valid target CPU values are: v8, supersparc, sparclite, f934,
+// SPARC-SAME: hypersparc, sparclite86x, sparclet, tsc701, v9, ultrasparc,
+// SPARC-SAME: ultrasparc3, niagara, niagara2, niagara3, niagara4, ma2100,
+// SPARC-SAME: ma2150, ma2155, ma2450, ma2455, ma2x5x, ma2080, ma2085, ma2480,
+// SPARC-SAME: ma2485, ma2x8x, myriad2, myriad2.1, myriad2.2, myriad2.3, leon2,
+// SPARC-SAME: at697e, at697f, leon3, ut699, gr712rc, leon4, gr740
+
+// RUN: not %clang_cc1 -triple sparcv9--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix SPARCV9
+// SPARCV9: error: unknown target CPU 'not-a-cpu'
+// SPARCV9: note: valid target CPU values are: v9, ultrasparc, ultrasparc3, niagara, niagara2, niagara3, niagara4
+
+// RUN: not %clang_cc1 -triple powerpc--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix PPC
+// PPC: error: unknown target CPU 'not-a-cpu'
+// PPC: note: valid target CPU values are: generic, 440, 450, 601, 602, 603,
+// PPC-SAME: 603e, 603ev, 604, 604e, 620, 630, g3, 7400, g4, 7450, g4+, 750,
+// PPC-SAME: 970, g5, a2, a2q, e500mc, e5500, power3, pwr3, power4, pwr4,
+// PPC-SAME: power5, pwr5, power5x, pwr5x, power6, pwr6, power6x, pwr6x, power7,
+// PPC-SAME: pwr7, power8, pwr8, power9, pwr9, powerpc, ppc, powerpc64, ppc64,
+// PPC-SAME: powerpc64le, ppc64le
+
+// RUN: not %clang_cc1 -triple nios2--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix NIOS
+// NIOS: error: unknown target CPU 'not-a-cpu'
+// NIOS: note: valid target CPU values are: nios2r1, nios2r2

[PATCH] D43045: Add NVPTX Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

LGTM with an inline comment.




Comment at: include/clang/Basic/Cuda.h:49
   SM_72,
+  LAST,
 };

We have last, invalid, etc... maybe we should pick one among all the targets? :)



https://reviews.llvm.org/D43045



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


[libcxx] r324640 - The apple versions of clang don't support deduction guides yet.

2018-02-08 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  8 11:33:03 2018
New Revision: 324640

URL: http://llvm.org/viewvc/llvm-project?rev=324640&view=rev
Log:
The apple versions of clang don't support deduction guides yet.

Modified:

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp?rev=324640&r1=324639&r2=324640&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 Thu Feb  8 11:33:03 2018
@@ -10,6 +10,7 @@
 // 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang-4.0
+// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
 
 // template::value_type>>

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp?rev=324640&r1=324639&r2=324640&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp
 Thu Feb  8 11:33:03 2018
@@ -10,6 +10,7 @@
 // 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang-4.0
+// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
 
 // template
 //   basic_string(InputIterator begin, InputIterator end,


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


[PATCH] D43057: Add Rest of Targets Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

I've glanced at this and didn't notice anything. I think any problems can be 
fixed in post-commit review if necessary.


https://reviews.llvm.org/D43057



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


r324641 - Fix crash on array initializer with non-0 alloca addrspace

2018-02-08 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Thu Feb  8 11:37:09 2018
New Revision: 324641

URL: http://llvm.org/viewvc/llvm-project?rev=324641&view=rev
Log:
Fix crash on array initializer with non-0 alloca addrspace

Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenOpenCL/address-space-constant-initializers.cl
cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=324641&r1=324640&r2=324641&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Feb  8 11:37:09 2018
@@ -1337,7 +1337,8 @@ void CodeGenFunction::EmitAutoVarInit(co
  isVolatile);
 // Zero and undef don't require a stores.
 if (!constant->isNullValue() && !isa(constant)) {
-  Loc = Builder.CreateBitCast(Loc, constant->getType()->getPointerTo());
+  Loc = Builder.CreateBitCast(Loc,
+constant->getType()->getPointerTo(Loc.getAddressSpace()));
   emitStoresForInitAfterMemset(constant, Loc.getPointer(),
isVolatile, Builder);
 }

Modified: cfe/trunk/test/CodeGenOpenCL/address-space-constant-initializers.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/address-space-constant-initializers.cl?rev=324641&r1=324640&r2=324641&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/address-space-constant-initializers.cl 
(original)
+++ cfe/trunk/test/CodeGenOpenCL/address-space-constant-initializers.cl Thu Feb 
 8 11:37:09 2018
@@ -20,3 +20,13 @@ __constant ConstantArrayPointerStruct co
 &constant_array_struct.f
 };
 
+__kernel void initializer_cast_is_valid_crash()
+{
+  unsigned char v512[64] = {
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00
+  };
+
+}

Modified: cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl?rev=324641&r1=324640&r2=324641&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl Thu Feb  8 
11:37:09 2018
@@ -1,9 +1,33 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | 
FileCheck -check-prefix=PRIVATE0 %s
+// RUN: %clang_cc1 %s -triple amdgcn-amd-amdhsa-unknown -O0 -emit-llvm -o - | 
FileCheck -check-prefix=PRIVATE5 %s
 
 // CHECK: @test.arr = private unnamed_addr addrspace(2) constant [3 x i32] 
[i32 1, i32 2, i32 3], align 4
 
 void test() {
   __private int arr[] = {1, 2, 3};
-// CHECK:  %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
-// CHECK:  call void @llvm.memcpy.p0i8.p2i8.i32(i8* align 4 %[[arr_i8_ptr]], 
i8 addrspace(2)* align 4 bitcast ([3 x i32] addrspace(2)* @test.arr to i8 
addrspace(2)*), i32 12, i1 false)
+// PRIVATE0:  %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
+// PRIVATE0:  call void @llvm.memcpy.p0i8.p2i8.i32(i8* align 4 
%[[arr_i8_ptr]], i8 addrspace(2)* align 4 bitcast ([3 x i32] addrspace(2)* 
@test.arr to i8 addrspace(2)*), i32 12, i1 false)
+
+// PRIVATE5: %arr = alloca [3 x i32], align 4, addrspace(5)
+// PRIVATE5: %0 = bitcast [3 x i32] addrspace(5)* %arr to i8 addrspace(5)*
+// PRIVATE5: call void @llvm.memcpy.p5i8.p2i8.i64(i8 addrspace(5)* align 4 %0, 
i8 addrspace(2)* align 4 bitcast ([3 x i32] addrspace(2)* @test.arr to i8 
addrspace(2)*), i64 12, i1 false)
+}
+
+__kernel void initializer_cast_is_valid_crash() {
+// PRIVATE0: %v512 = alloca [64 x i8], align 1
+// PRIVATE0: %0 = bitcast [64 x i8]* %v512 to i8*
+// PRIVATE0: call void @llvm.memset.p0i8.i32(i8* align 1 %0, i8 0, i32 64, i1 
false)
+// PRIVATE0: %1 = bitcast i8* %0 to [64 x i8]*
+
+
+// PRIVATE5: %v512 = alloca [64 x i8], align 1, addrspace(5)
+// PRIVATE5: %0 = bitcast [64 x i8] addrspace(5)* %v512 to i8 addrspace(5)*
+// PRIVATE5: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* align 1 %0, i8 
0, i64 64, i1 false)
+// PRIVATE5: %1 = bitcast i8 addrspace(5)* %0 to [64 x i8] addrspace(5)*
+  unsigned char v512[64] = {
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  
0x

[PATCH] D43078: Fix crash on array initializer with non-0 alloca addrspace

2018-02-08 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

r324641


https://reviews.llvm.org/D43078



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


[PATCH] D43045: Add NVPTX Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: test/Misc/target-invalid-cpu-note.c:38
+// NVPTX: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35,
+// NVPTX-SAME: sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72

Nit: Generally speaking this note is false. For any given version of CUDA, some 
of the listed GPU variants will not be accepted. E.g. CUDA versions before 9.1 
do not know anything about sm_72, but CUDA-9.1  does not supports sm_20. 


https://reviews.llvm.org/D43045



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


Re: [PATCH] D43045: Add NVPTX Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Eric Christopher via cfe-commits
Fair. Did you want to handle this a different way? I thought the list at
least seemed reasonable for spelling.

On Thu, Feb 8, 2018, 11:44 AM Artem Belevich via Phabricator <
revi...@reviews.llvm.org> wrote:

> tra added inline comments.
>
>
> 
> Comment at: test/Misc/target-invalid-cpu-note.c:38
> +// NVPTX: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32,
> sm_35,
> +// NVPTX-SAME: sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70,
> sm_72
> 
> Nit: Generally speaking this note is false. For any given version of CUDA,
> some of the listed GPU variants will not be accepted. E.g. CUDA versions
> before 9.1 do not know anything about sm_72, but CUDA-9.1  does not
> supports sm_20.
>
>
> https://reviews.llvm.org/D43045
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42581: [NVPTX] Emit debug info in DWARF-2 by default for Cuda devices.

2018-02-08 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D42581



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


[PATCH] D43045: Add NVPTX Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: test/Misc/target-invalid-cpu-note.c:38
+// NVPTX: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35,
+// NVPTX-SAME: sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72

tra wrote:
> Nit: Generally speaking this note is false. For any given version of CUDA, 
> some of the listed GPU variants will not be accepted. E.g. CUDA versions 
> before 9.1 do not know anything about sm_72, but CUDA-9.1  does not supports 
> sm_20. 
Is there somewhere else that this is checked?  It seems that the 'setCPU' 
function here checks against this same list.  


https://reviews.llvm.org/D43045



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


[PATCH] D43045: Add NVPTX Support to ValidCPUList (enabling march notes)

2018-02-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: test/Misc/target-invalid-cpu-note.c:38
+// NVPTX: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35,
+// NVPTX-SAME: sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72

erichkeane wrote:
> tra wrote:
> > Nit: Generally speaking this note is false. For any given version of CUDA, 
> > some of the listed GPU variants will not be accepted. E.g. CUDA versions 
> > before 9.1 do not know anything about sm_72, but CUDA-9.1  does not 
> > supports sm_20. 
> Is there somewhere else that this is checked?  It seems that the 'setCPU' 
> function here checks against this same list.  
We have CheckCudaVersionSupportsArch() in lib/Driver/ToolChains/Cuda.cpp.
I'm not sure if CUDA version is already known at the time we check -target-cpu, 
though.

I'm OK with the ful list for now if it's hard to get to the CUDA version.




https://reviews.llvm.org/D43045



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


r324644 - Fix improper indentation issue in CodeGenModule [NFC]

2018-02-08 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Feb  8 12:04:22 2018
New Revision: 324644

URL: http://llvm.org/viewvc/llvm-project?rev=324644&view=rev
Log:
Fix improper indentation issue in CodeGenModule [NFC]

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=324644&r1=324643&r2=324644&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Feb  8 12:04:22 2018
@@ -1264,8 +1264,8 @@ void CodeGenModule::setNonAliasAttribute
 
 if (auto *F = dyn_cast(GO)) {
   if (auto *SA = D->getAttr())
-   if (!D->getAttr())
- F->addFnAttr("implicit-section-name", SA->getName());
+if (!D->getAttr())
+  F->addFnAttr("implicit-section-name", SA->getName());
 }
 
 if (const SectionAttr *SA = D->getAttr())


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


r324647 - [X86] Replace kortest intrinsics with native IR.

2018-02-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Feb  8 12:16:17 2018
New Revision: 324647

URL: http://llvm.org/viewvc/llvm-project?rev=324647&view=rev
Log:
[X86] Replace kortest intrinsics with native IR.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=324647&r1=324646&r2=324647&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Feb  8 12:16:17 2018
@@ -8710,6 +8710,18 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 return EmitX86MaskedCompare(*this, CC, false, Ops);
   }
 
+  case X86::BI__builtin_ia32_kortestchi:
+  case X86::BI__builtin_ia32_kortestzhi: {
+Value *Or = EmitX86MaskLogic(*this, Instruction::Or, 16, Ops);
+Value *C;
+if (BuiltinID == X86::BI__builtin_ia32_kortestchi)
+  C = llvm::Constant::getAllOnesValue(Builder.getInt16Ty());
+else
+  C = llvm::Constant::getNullValue(Builder.getInt16Ty());
+Value *Cmp = Builder.CreateICmpEQ(Or, C);
+return Builder.CreateZExt(Cmp, ConvertType(E->getType()));
+  }
+
   case X86::BI__builtin_ia32_kandhi:
 return EmitX86MaskLogic(*this, Instruction::And, 16, Ops);
   case X86::BI__builtin_ia32_kandnhi:

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=324647&r1=324646&r2=324647&view=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Thu Feb  8 12:16:17 2018
@@ -6247,16 +6247,28 @@ __mmask16 test_mm512_kor(__m512i __A, __
   __E, __F);
 }
 
-int test_mm512_kortestc(__mmask16 __A, __mmask16 __B) {
+int test_mm512_kortestc(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
   // CHECK-LABEL: @test_mm512_kortestc
-  // CHECK: @llvm.x86.avx512.kortestc.w
-  return _mm512_kortestc(__A, __B); 
+  // CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
+  // CHECK: [[RHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
+  // CHECK: [[OR:%.*]] = or <16 x i1> [[LHS]], [[RHS]]
+  // CHECK: [[CAST:%.*]] = bitcast <16 x i1> [[OR]] to i16
+  // CHECK: [[CMP:%.*]] = icmp eq i16 [[CAST]], -1
+  // CHECK: zext i1 [[CMP]] to i32
+  return _mm512_kortestc(_mm512_cmpneq_epu32_mask(__A, __B),
+ _mm512_cmpneq_epu32_mask(__C, __D));
 }
 
-int test_mm512_kortestz(__mmask16 __A, __mmask16 __B) {
+int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
   // CHECK-LABEL: @test_mm512_kortestz
-  // CHECK: @llvm.x86.avx512.kortestz.w
-  return _mm512_kortestz(__A, __B); 
+  // CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
+  // CHECK: [[RHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
+  // CHECK: [[OR:%.*]] = or <16 x i1> [[LHS]], [[RHS]]
+  // CHECK: [[CAST:%.*]] = bitcast <16 x i1> [[OR]] to i16
+  // CHECK: [[CMP:%.*]] = icmp eq i16 [[CAST]], 0
+  // CHECK: zext i1 [[CMP]] to i32
+  return _mm512_kortestz(_mm512_cmpneq_epu32_mask(__A, __B),
+ _mm512_cmpneq_epu32_mask(__C, __D));
 }
 
 __mmask16 test_mm512_kunpackb(__m512i __A, __m512i __B, __m512i __C, __m512i 
__D, __m512i __E, __m512i __F) {


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


[PATCH] D42300: [Analyzer] Add PreStmt and PostStmt callbacks for OffsetOfExpr

2018-02-08 Thread Henry Wong via Phabricator via cfe-commits
MTC added a comment.

@NoQ Sorry to bother you again. It seems that this patch is useless to analyzer 
temporarily, if you think so, I will abandon it : ).


Repository:
  rC Clang

https://reviews.llvm.org/D42300



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133474.
MaskRay added a comment.
Herald added subscribers: kbarton, nemanjai.

Split test/clang-tidy/readability-simd-intrinsics.cpp to x86 and ppc


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++2a
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++2a
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+In C++11 mode, if the option ``Enabled`` is turned on, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readabi

[PATCH] D43062: [analyzer] Support CXXTemporaryObjectExpr constructors that have destructors.

2018-02-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 133475.
NoQ added a comment.

Add a simple test for a class with no destructor.


https://reviews.llvm.org/D43062

Files:
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -607,22 +607,37 @@
   clang_analyzer_eval(c3.getY() == 2); // expected-warning{{TRUE}}
 
   C c4 = returnTemporaryWithConstruction();
-  // Should be TRUE under TEMPORARY_DTORS once this sort of construction
-  // in the inlined function is supported.
-  clang_analyzer_eval(c4.getX() == 1); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(c4.getY() == 2); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(c4.getX() == 1);
+  clang_analyzer_eval(c4.getY() == 2);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-3{{TRUE}}
+  // expected-warning@-3{{TRUE}}
+#else
+  // expected-warning@-6{{UNKNOWN}}
+  // expected-warning@-6{{UNKNOWN}}
+#endif
 
   C c5 = returnTemporaryWithAnotherFunctionWithConstruction();
-  // Should be TRUE under TEMPORARY_DTORS once this sort of construction
-  // in the inlined function is supported.
-  clang_analyzer_eval(c5.getX() == 1); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(c5.getY() == 2); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(c5.getX() == 1);
+  clang_analyzer_eval(c5.getY() == 2);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-3{{TRUE}}
+  // expected-warning@-3{{TRUE}}
+#else
+  // expected-warning@-6{{UNKNOWN}}
+  // expected-warning@-6{{UNKNOWN}}
+#endif
 
   C c6 = returnTemporaryWithCopyConstructionWithConstruction();
-  // Should be TRUE under TEMPORARY_DTORS once this sort of construction
-  // in the inlined function is supported.
-  clang_analyzer_eval(c5.getX() == 1); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(c5.getY() == 2); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(c5.getX() == 1);
+  clang_analyzer_eval(c5.getY() == 2);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-3{{TRUE}}
+  // expected-warning@-3{{TRUE}}
+#else
+  // expected-warning@-6{{UNKNOWN}}
+  // expected-warning@-6{{UNKNOWN}}
+#endif
 
 #if __cplusplus >= 201103L
 
@@ -683,10 +698,84 @@
   // expected-warning@-6{{UNKNOWN}}
 #endif
 
-  // Should be TRUE under TEMPORARY_DTORS once this sort of construction
-  // in the inlined function is supported.
   D d3 = returnTemporaryWithCopyConstructionWithVariableAndNonTrivialCopy();
-  clang_analyzer_eval(d3.getX() == 1); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(d3.getY() == 2); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(d3.getX() == 1);
+  clang_analyzer_eval(d3.getY() == 2);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-3{{TRUE}}
+  // expected-warning@-3{{TRUE}}
+#else
+  // expected-warning@-6{{UNKNOWN}}
+  // expected-warning@-6{{UNKNOWN}}
+#endif
 }
 } // namespace test_return_temporary
+
+
+namespace test_temporary_object_expr_without_dtor {
+class C {
+  int x;
+public:
+  C(int x) : x(x) {}
+  int getX() const { return x; }
+};
+
+void test() {
+  clang_analyzer_eval(C(3).getX() == 3); // expected-warning{{TRUE}}
+};
+}
+
+namespace test_temporary_object_expr_with_dtor {
+class C {
+  int x;
+
+public:
+  C(int x) : x(x) {}
+  ~C() {}
+  int getX() const { return x; }
+};
+
+void test(int coin) {
+  clang_analyzer_eval(C(3).getX() == 3);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+
+  const C &c1 = coin ? C(1) : C(2);
+  if (coin) {
+clang_analyzer_eval(c1.getX() == 1);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+  } else {
+clang_analyzer_eval(c1.getX() == 2);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+  }
+
+  C c2 = coin ? C(1) : C(2);
+  if (coin) {
+clang_analyzer_eval(c2.getX() == 1);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+  } else {
+clang_analyzer_eval(c2.getX() == 2);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+  }
+}
+
+} // namespace test_temporary_object_expr
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -137,6 +137,9 @@
   } else if (auto *RS = dyn_cast(TriggerStmt)) {
 CallOpts.IsTemporaryCtorOrDtor = true;
 return MRMgr.getCXXTempObjectRegion(CE, LCtx);
+  } else if (auto *BTE = dyn_cast(TriggerStmt)) {
+CallOpts.IsTemporaryCtorOrDtor = true;
+return MRMgr.getCXXTempObjectRegion(CE, LCtx);
   }
   // TODO: Consider other directly initialized elements.
 } else if (const CXXCtorInitializ

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133476.
MaskRay added a comment.

.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++2a
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++2a
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,41 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``Enabled`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects // -std=c++11
+  operator+ on std::simd objects   // -std=c++2a
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will be enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/r

[PATCH] D42300: [Analyzer] Add PreStmt and PostStmt callbacks for OffsetOfExpr

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

All right, i guess we already do have a pair of callbacks for `IntegerLiteral` 
and it doesn't hurt, especially because here they'd eventually be actually 
useful. I think it should land, just to make it easier to add the actual 
support later.


Repository:
  rC Clang

https://reviews.llvm.org/D42300



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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-08 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

In https://reviews.llvm.org/D35894#1001875, @ilya-biryukov wrote:

> Thanks for picking this up!
>  I have just one major comment related to how we generate the hover text.
>
> Current implementation tries to get the actual source code for every 
> declaration and then patch it up to look nice on in the output.
>  It is quite a large piece of code (spanning most of the patch) and tries to 
> mix and match source code and output from the AST when there's not enough 
> information in the AST (e.g. `tryFixupIndentation` and 
> `stripOpeningBracket`). This approach is really complex as we'll inevitably 
> try to parse "parts" of C++ and figure out how to deal with macros, etc.
>  Worse than that, I would expect this code to grow uncontrollably with time 
> and be very hard to maintain.
>  Moreover, in presence of macros it arguably gives non-useful results. For 
> example, consider this:
>
>   #define DEFINITIONS int foo(); int bar(); int baz();
>  
>   // somewhere else
>   DEFINITIONS
>  
>   // somewhere else
>   int test() {
> foo(); // <-- hover currently doesn't work here. And even if it did, 
> showing a line with just DEFINITIONS is not that useful.
>   }
>
>
> I suggest we move to a different approach of pretty-printing the relevant 
> parts of the AST. It is already implemented in clang, handles all the cases 
> in the AST (and will be updated along when AST is changed), shows useful 
> information in presence of macros and is much easier to implement.
>  The version of `getHoverContents` using this is just a few lines of code:
>
>   static std::string getHoverContents(const Decl *D) {
> if (TemplateDecl *TD = D->getDescribedTemplate())
>   D = TD; // we want to see the template bits.
>  
> std::string Result;
> llvm::raw_string_ostream OS(Result);
>  
> PrintingPolicy Policy(D->getASTContext().getLangOpts());
> Policy.TerseOutput = true;
> D->print(OS, Policy);
>  
> OS.flush();
> return Result;
>   }
>
>
> It doesn't add the `"Defined in ..."` piece, but illustrates the APIs we can 
> use. We should use the same APIs for the scope as well, avoiding fallbacks to 
> manual printing if we can.
>  If there's something missing/wrong in the upstream pretty printers, it's 
> fine and we can fix them (e.g., the thing that I've immediately noticed is 
> that namespaces are always printed with curly braces).


I thought it would be nice to show in the hover the declaration formatted as it 
is written in the source file, because that's how the developer is used to read 
it.  But on the other hand, I completely agree that trying to do string 
formatting ourselves is opening a can of worms.  I'll try the approach you 
suggest.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



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


[PATCH] D42645: New simple Checker for mmap calls

2018-02-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Hmm, maybe it'd also be a good idea to disable the check completely when a 
likely-correct value for the macro cannot be determined.




Comment at: lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp:74-75
+  mgr.registerChecker();
+  Mwec->ProtExecOv =
+mgr.getAnalyzerOptions().getOptionAsInteger("MmapProtExec", 0x04, Mwec);
+}

You'd probably want to be able to set both `PROT_READ` and `PROT_EXEC`, to be 
fully flexible.



Comment at: test/Analysis/mmap-writeexec.c:1
+// RUN: %clang_analyze_cc1 -triple i686-unknown-linux 
-analyzer-checker=security.MmapWriteExec -analyzer-config 
security.MmapWriteExec:MmapProtExec=1 -DPROT_EXEC=1 -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-apple-darwin10 
-analyzer-checker=security.MmapWriteExec -verify %s

I think you should use an unrelated macro, eg. `-analyzer-config 
security.MmapWriteExec:MmapProtExec=1 -DUSE_ALTERNATIVE_PROT_EXEC_DEFINITION`, 
to trigger different definitions in the tests, i.e.
```
#ifndef USE_ALTERNATIVE_PROT_EXEC_DEFINITION
#define PROT_READ   0x01
#define PROT_EXEC   0x04
#else
#define PROT_READ   0x04
#define PROT_EXEC   0x01
#endif
```


Repository:
  rC Clang

https://reviews.llvm.org/D42645



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


[PATCH] D42745: [analyzer] Add support for __builtin_constant_p to BuiltinFunctionChecker

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

Tests look good. You can't test deadcode :)


https://reviews.llvm.org/D42745



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


r324651 - PR36307: Consume the #pragma options align annotation token after

2018-02-08 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Thu Feb  8 13:20:43 2018
New Revision: 324651

URL: http://llvm.org/viewvc/llvm-project?rev=324651&view=rev
Log:
PR36307: Consume the #pragma options align annotation token after
semantic analysis to prevent incorrect -Wpragma-pack warning for an included
file

rdar://37354951

Added:
cfe/trunk/test/Sema/Inputs/pragma-align-no-header-change-warning.h
cfe/trunk/test/Sema/pragma-align-no-header-change-warning.c
Modified:
cfe/trunk/lib/Parse/ParsePragma.cpp

Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=324651&r1=324650&r2=324651&view=diff
==
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Thu Feb  8 13:20:43 2018
@@ -509,8 +509,10 @@ void Parser::HandlePragmaAlign() {
   Sema::PragmaOptionsAlignKind Kind =
 static_cast(
 reinterpret_cast(Tok.getAnnotationValue()));
-  SourceLocation PragmaLoc = ConsumeAnnotationToken();
-  Actions.ActOnPragmaOptionsAlign(Kind, PragmaLoc);
+  Actions.ActOnPragmaOptionsAlign(Kind, Tok.getLocation());
+  // Consume the token after processing the pragma to enable pragma-specific
+  // #include warnings.
+  ConsumeAnnotationToken();
 }
 
 void Parser::HandlePragmaDump() {

Added: cfe/trunk/test/Sema/Inputs/pragma-align-no-header-change-warning.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/Inputs/pragma-align-no-header-change-warning.h?rev=324651&view=auto
==
--- cfe/trunk/test/Sema/Inputs/pragma-align-no-header-change-warning.h (added)
+++ cfe/trunk/test/Sema/Inputs/pragma-align-no-header-change-warning.h Thu Feb  
8 13:20:43 2018
@@ -0,0 +1,5 @@
+#pragma options align=mac68k
+
+struct S { int x; };
+
+#pragma options align=reset

Added: cfe/trunk/test/Sema/pragma-align-no-header-change-warning.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-align-no-header-change-warning.c?rev=324651&view=auto
==
--- cfe/trunk/test/Sema/pragma-align-no-header-change-warning.c (added)
+++ cfe/trunk/test/Sema/pragma-align-no-header-change-warning.c Thu Feb  8 
13:20:43 2018
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack -I 
%S/Inputs -verify %s
+// expected-no-diagnostics
+
+#include "pragma-align-no-header-change-warning.h"
+


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


r324652 - [analyzer] [tests] Test different projects concurrently

2018-02-08 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Feb  8 13:22:42 2018
New Revision: 324652

URL: http://llvm.org/viewvc/llvm-project?rev=324652&view=rev
Log:
[analyzer] [tests] Test different projects concurrently

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

Modified:
cfe/trunk/utils/analyzer/SATestBuild.py
cfe/trunk/utils/analyzer/SATestUtils.py

Modified: cfe/trunk/utils/analyzer/SATestBuild.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/SATestBuild.py?rev=324652&r1=324651&r2=324652&view=diff
==
--- cfe/trunk/utils/analyzer/SATestBuild.py (original)
+++ cfe/trunk/utils/analyzer/SATestBuild.py Thu Feb  8 13:22:42 2018
@@ -45,32 +45,55 @@ variable. It should contain a comma sepa
 import CmpRuns
 import SATestUtils
 
-import os
+from subprocess import CalledProcessError, check_call
+import argparse
 import csv
-import sys
 import glob
+import logging
 import math
+import multiprocessing
+import os
+import plistlib
 import shutil
+import sys
+import threading
 import time
-import plistlib
-import argparse
-from subprocess import check_call, CalledProcessError
-import multiprocessing
+import Queue
 
 #--
 # Helper functions.
 #--
 
+Local = threading.local()
+Local.stdout = sys.stdout
+Local.stderr = sys.stderr
+logging.basicConfig(
+level=logging.DEBUG,
+format='%(asctime)s:%(levelname)s:%(name)s: %(message)s')
+
+class StreamToLogger(object):
+def __init__(self, logger, log_level=logging.INFO):
+self.logger = logger
+self.log_level = log_level
+
+def write(self, buf):
+# Rstrip in order not to write an extra newline.
+self.logger.log(self.log_level, buf.rstrip())
 
-sys.stdout = SATestUtils.flushfile(sys.stdout)
+def flush(self):
+pass
+
+def fileno(self):
+return 0
 
 
 def getProjectMapPath():
 ProjectMapPath = os.path.join(os.path.abspath(os.curdir),
   ProjectMapFile)
 if not os.path.exists(ProjectMapPath):
-print "Error: Cannot find the Project Map file " + ProjectMapPath +\
-  "\nRunning script for the wrong directory?"
+Local.stdout.write("Error: Cannot find the Project Map file "
+   + ProjectMapPath
+   + "\nRunning script for the wrong directory?\n")
 sys.exit(1)
 return ProjectMapPath
 
@@ -100,7 +123,7 @@ if not Clang:
 sys.exit(1)
 
 # Number of jobs.
-Jobs = int(math.ceil(multiprocessing.cpu_count() * 0.75))
+MaxJobs = int(math.ceil(multiprocessing.cpu_count() * 0.75))
 
 # Project map stores info about all the "registered" projects.
 ProjectMapFile = "projectMap.csv"
@@ -170,7 +193,8 @@ def runCleanupScript(Dir, PBuildLogFile)
 """
 Cwd = os.path.join(Dir, PatchedSourceDirName)
 ScriptPath = os.path.join(Dir, CleanupScript)
-SATestUtils.runScript(ScriptPath, PBuildLogFile, Cwd)
+SATestUtils.runScript(ScriptPath, PBuildLogFile, Cwd,
+  Stdout=Local.stdout, Stderr=Local.stderr)
 
 
 def runDownloadScript(Dir, PBuildLogFile):
@@ -178,7 +202,8 @@ def runDownloadScript(Dir, PBuildLogFile
 Run the script to download the project, if it exists.
 """
 ScriptPath = os.path.join(Dir, DownloadScript)
-SATestUtils.runScript(ScriptPath, PBuildLogFile, Dir)
+SATestUtils.runScript(ScriptPath, PBuildLogFile, Dir,
+  Stdout=Local.stdout, Stderr=Local.stderr)
 
 
 def downloadAndPatch(Dir, PBuildLogFile):
@@ -192,8 +217,8 @@ def downloadAndPatch(Dir, PBuildLogFile)
 if not os.path.exists(CachedSourceDirPath):
 runDownloadScript(Dir, PBuildLogFile)
 if not os.path.exists(CachedSourceDirPath):
-print "Error: '%s' not found after download." % (
-  CachedSourceDirPath)
+Local.stderr.write("Error: '%s' not found after download.\n" % (
+   CachedSourceDirPath))
 exit(1)
 
 PatchedSourceDirPath = os.path.join(Dir, PatchedSourceDirName)
@@ -211,10 +236,10 @@ def applyPatch(Dir, PBuildLogFile):
 PatchfilePath = os.path.join(Dir, PatchfileName)
 PatchedSourceDirPath = os.path.join(Dir, PatchedSourceDirName)
 if not os.path.exists(PatchfilePath):
-print "  No local patches."
+Local.stdout.write("  No local patches.\n")
 return
 
-print "  Applying patch."
+Local.stdout.write("  Applying patch.\n")
 try:
 check_call("patch -p1 < '%s'" % (PatchfilePath),
cwd=PatchedSourceDirPath,
@@ -222,7 +247,8 @@ def applyPatch(Dir, PBuildLogFile):
stdout=PBuildLogFile,
shell=True)
 except:
-print "Error: Patch failed. See %s for details." % (PBuildLogFile.name)
+

[PATCH] D42672: [CFG] [analyzer] Heavier CFGConstructor elements.

2018-02-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

All right, so this change is indeed safe, i.e. no crashes or changes in 
analyzer behavior so far on my large codebase run. Will commit now.


https://reviews.llvm.org/D42672



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


[PATCH] D43074: [Analyzer] Fix a typo about `categories::MemoryError` in `MallocChecker.cpp`

2018-02-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Woohoo thanks nice.


Repository:
  rC Clang

https://reviews.llvm.org/D43074



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


  1   2   >