[PATCH] D61664: [NewPM] Setup Passes for KASan and KMSan

2019-05-08 Thread Philip Pfaffe via Phabricator via cfe-commits
philip.pfaffe accepted this revision.
philip.pfaffe added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61664



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


Re: r360109 - Recommit r359859 "[Attribute/Diagnostics] Print macro if definition is an attribute declaration"

2019-05-08 Thread Leonard Chan via cfe-commits
Just wanted to update. My latest revision (r360225) seems to have fixed the
bots. 🎉

On Tue, May 7, 2019 at 3:50 PM Jonas Devlieghere 
wrote:

> Hi Leonard,
>
> My personal rule of thumb is that if I can fix it in something like 30
> minutes or less, I'll leave the bot red and commit a fix. Otherwise I'll
> revert my change. The problem with leaving the bot red is that if something
> else breaks, that person doesn't get a signal, and issue start to pile up.
>
> When I see a bot is red and it's blocking me, I will usually send an
> e-mail and wait about the same time for a reply, before reverting the
> change myself.
>
> Cheers,
> Jonas
>
> On Tue, May 7, 2019 at 11:20 AM Leonard Chan 
> wrote:
>
>> Thanks! It turns out that we weren't running debuginfo-tests. Trying to
>> find a mac I can ssh into to reproduce this.
>>
>> Another side question: is there usually an etiquette for how long a
>> greendragon bot is allowed to stay broken? I don't want to leave it that
>> way for too long while working on my fix if it bothers others too much.
>>
>> Thanks,
>> Leonard
>>
>> On Tue, May 7, 2019 at 10:13 AM Jonas Devlieghere 
>> wrote:
>>
>>> Hi Leonard,
>>>
>>> The test that is asserting is part of the debuginfo test. (
>>> https://github.com/llvm-project/debuginfo-tests)
>>> The reason that it's only failing on the non-incremental bot is because
>>> the incremental one isn't running those, I believe.
>>>
>>> RA stands for Release/Asserts.
>>>
>>> Hope that helps!
>>>
>>> Cheers,
>>> Jonas
>>>
>>> On Tue, May 7, 2019 at 9:44 AM Leonard Chan 
>>> wrote:
>>>
 Yup, sorry for the delay. I submitted it overnight thinking it would be
 fixed this time. I have one more way that I think should fix it, but before
 trying it out, do you know any tips on how I can try to reproduce this
 locally? I see that you're running these on an x64 mac, but I can't seem to
 trigger this on our own mac builders. Also as a side question, do you what
 RA stands for in "Clang Stage 1: cmake, incremental RA, using system
 compiler
 "?
 It seems that I'm only breaking the non-incremental RA jobs, bit the
 incremental one still works fine with my change.

 Thanks,
 Leonard

 On Tue, May 7, 2019, 09:26 Jonas Devlieghere 
 wrote:

> Hi Leonard,
>
> It appears that your patch is still triggering an assertion on
> GreenDragon:
> http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/56255/consoleFull#312501878d489585b-5106-414a-ac11-3ff90657619c
>
> Can you please have a look?
>
> Thanks,
> Jonas
>
>
> On Mon, May 6, 2019 at 8:17 PM Leonard Chan via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: leonardchan
>> Date: Mon May  6 20:20:17 2019
>> New Revision: 360109
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=360109&view=rev
>> Log:
>> Recommit r359859 "[Attribute/Diagnostics] Print macro if definition
>> is an attribute declaration"
>>
>> Updated with fix for read of uninitialized memory.
>>
>> Added:
>> cfe/trunk/test/Frontend/macro_defined_type.cpp
>> cfe/trunk/test/Sema/address_space_print_macro.c
>> Modified:
>> cfe/trunk/include/clang/AST/ASTContext.h
>> cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/include/clang/AST/TypeLoc.h
>> cfe/trunk/include/clang/AST/TypeNodes.def
>> cfe/trunk/include/clang/Parse/Parser.h
>> cfe/trunk/include/clang/Sema/ParsedAttr.h
>> cfe/trunk/include/clang/Sema/Sema.h
>> cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>> cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp
>> cfe/trunk/lib/AST/ASTContext.cpp
>> cfe/trunk/lib/AST/ASTDiagnostic.cpp
>> cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
>> cfe/trunk/lib/AST/ItaniumMangle.cpp
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/AST/TypePrinter.cpp
>> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
>> cfe/trunk/lib/Parse/ParseDecl.cpp
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>> cfe/trunk/lib/Sema/SemaStmt.cpp
>> cfe/trunk/lib/Sema/SemaType.cpp
>> cfe/trunk/lib/Sema/TreeTransform.h
>> cfe/trunk/lib/Serialization/ASTReader.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/test/Sema/address_spaces.c
>> cfe/trunk/test/SemaObjC/externally-retained.m
>> cfe/trunk/test/SemaObjC/gc-attributes.m
>> cfe/trunk/test/SemaObjC/mrc-weak.m
>> cfe/trunk/test/SemaObjCXX/gc-attributes.mm
>> cfe/trunk/tools/libclang/CIndex.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/ASTContext.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/

[PATCH] D61642: [clang-tidy] Do not show incorrect fix in modernize-make-unique

2019-05-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360231: [clang-tidy] Do not show incorrect fix in 
modernize-make-unique (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61642?vs=198497&id=198594#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61642

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
@@ -273,6 +273,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead
   // CHECK-FIXES: std::make_unique(APair{T, 1});
 
+  // Check aggregate init with intermediate temporaries.
+  std::unique_ptr PAggrTemp = std::unique_ptr(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PAggrTemp = 
std::unique_ptr(new APair({T, 1}));
+  PAggrTemp.reset(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
+  // CHECK-FIXES: PAggrTemp.reset(new APair({T, 1}));
+
   // Test different kinds of initialization of the pointee, when the unique_ptr
   // is initialized with braces.
 
Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -292,12 +292,13 @@
   //   Foo{1} => false
   auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
 for (const auto *Arg : CE->arguments()) {
+  Arg = Arg->IgnoreImplicit();
+
   if (isa(Arg) || isa(Arg))
 return true;
   // Check whether we implicitly construct a class from a
   // std::initializer_list.
-  if (const auto *ImplicitCE =
-  dyn_cast(Arg->IgnoreImplicit())) {
+  if (const auto *ImplicitCE = dyn_cast(Arg)) {
 if (ImplicitCE->isStdInitListInitialization())
   return true;
   }


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
@@ -273,6 +273,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead
   // CHECK-FIXES: std::make_unique(APair{T, 1});
 
+  // Check aggregate init with intermediate temporaries.
+  std::unique_ptr PAggrTemp = std::unique_ptr(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PAggrTemp = std::unique_ptr(new APair({T, 1}));
+  PAggrTemp.reset(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
+  // CHECK-FIXES: PAggrTemp.reset(new APair({T, 1}));
+
   // Test different kinds of initialization of the pointee, when the unique_ptr
   // is initialized with braces.
 
Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -292,12 +292,13 @@
   //   Foo{1} => false
   auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
 for (const auto *Arg : CE->arguments()) {
+  Arg = Arg->IgnoreImplicit();
+
   if (isa(Arg) || isa(Arg))
 return true;
   // Check whether we implicitly construct a class from a
   // std::initializer_list.
-  if (const auto *ImplicitCE =
-  dyn_cast(Arg->IgnoreImplicit())) {
+  if (const auto *ImplicitCE = dyn_cast(Arg)) {
 if (ImplicitCE->isStdInitListInitialization())
   return true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r360231 - [clang-tidy] Do not show incorrect fix in modernize-make-unique

2019-05-08 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed May  8 01:52:18 2019
New Revision: 360231

URL: http://llvm.org/viewvc/llvm-project?rev=360231&view=rev
Log:
[clang-tidy] Do not show incorrect fix in modernize-make-unique

Summary:
The case when initialize_list hides behind an implicit case was not
handled before.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=360231&r1=360230&r2=360231&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Wed May  
8 01:52:18 2019
@@ -292,12 +292,13 @@ bool MakeSmartPtrCheck::replaceNew(Diagn
   //   Foo{1} => false
   auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
 for (const auto *Arg : CE->arguments()) {
+  Arg = Arg->IgnoreImplicit();
+
   if (isa(Arg) || isa(Arg))
 return true;
   // Check whether we implicitly construct a class from a
   // std::initializer_list.
-  if (const auto *ImplicitCE =
-  dyn_cast(Arg->IgnoreImplicit())) {
+  if (const auto *ImplicitCE = dyn_cast(Arg)) {
 if (ImplicitCE->isStdInitListInitialization())
   return true;
   }

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=360231&r1=360230&r2=360231&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Wed May  
8 01:52:18 2019
@@ -273,6 +273,14 @@ void initialization(int T, Base b) {
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead
   // CHECK-FIXES: std::make_unique(APair{T, 1});
 
+  // Check aggregate init with intermediate temporaries.
+  std::unique_ptr PAggrTemp = std::unique_ptr(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PAggrTemp = 
std::unique_ptr(new APair({T, 1}));
+  PAggrTemp.reset(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
+  // CHECK-FIXES: PAggrTemp.reset(new APair({T, 1}));
+
   // Test different kinds of initialization of the pointee, when the unique_ptr
   // is initialized with braces.
 


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


[PATCH] D61667: Assume `__cxa_allocate_exception` returns an under-aligned memory on Darwin if the version of libc++abi isn't new enough to include the fix in r319123

2019-05-08 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: rjmccall, ldionne.
ahatanak added a project: clang.
Herald added a reviewer: EricWF.
Herald added subscribers: dexonsmith, jkorous.

This patch resurrects r264998, which was committed to work around a bug in 
libc++abi that was causing `_cxa_allocate_exception` to return a memory that 
wasn't double-word aligned.

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160328/154332.html

I reverted r264998 after fixing the bug in libc++abi in r319123 (see the link 
below), but didn't really realize that doing so could break projects using 
older versions of libc++abi that don't have the fix committed in r319123.

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20171127/210878.html

In addition, this patch makes clang issue a warning if the type of the thrown 
object requires an alignment that is larger than the minimum alignment the 
libc++abi runtime guarantees.


Repository:
  rC Clang

https://reviews.llvm.org/D61667

Files:
  include/clang/Basic/AlignedExceptionObject.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets/OSTargets.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Sema/SemaExprCXX.cpp
  test/CodeGenCXX/eh.cpp
  test/SemaCXX/warn-overaligned-type-thrown.cpp

Index: test/SemaCXX/warn-overaligned-type-thrown.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-overaligned-type-thrown.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.99 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions -DUNDERALIGNED %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions -Wno-underaligned-exception-object -DNODIAG %s
+
+struct S0 {
+  S0();
+  int m;
+};
+
+struct Overaligned1 {
+  Overaligned1();
+  int __attribute__((aligned(16))) m;
+};
+
+struct __attribute__((aligned(16))) Overaligned2 {
+  Overaligned2();
+  int m;
+};
+
+struct Overaligned3 {
+  Overaligned3();
+  int __attribute__((aligned(64))) m;
+};
+
+void test0() {
+  throw S0();
+}
+
+void test1() {
+  throw Overaligned1();
+}
+
+void test2() {
+  throw Overaligned2();
+}
+
+void test3() {
+  throw Overaligned3();
+}
+
+#if defined(NODIAG)
+// expected-no-diagnostics
+#elif defined(UNDERALIGNED)
+// expected-warning@-14 {{underaligned exception object thrown}}
+// expected-note@-15 {{(16-bytes) is larger than the guaranteed alignment of the memory Itanium C++ runtime returns (8-bytes)}}
+// expected-warning@-12 {{underaligned exception object thrown}}
+// expected-note@-13 {{(16-bytes) is larger than the guaranteed alignment of the memory Itanium C++ runtime returns (8-bytes)}}
+// expected-warning@-10 {{underaligned exception object thrown}}
+// expected-note@-11 {{(64-bytes) is larger than the guaranteed alignment of the memory Itanium C++ runtime returns (8-bytes)}}
+#else
+// expected-warning@-13 {{underaligned exception object thrown}}
+// expected-note@-14 {{(64-bytes) is larger than the guaranteed alignment of the memory Itanium C++ runtime returns (16-bytes)}}
+#endif
Index: test/CodeGenCXX/eh.cpp
===
--- test/CodeGenCXX/eh.cpp
+++ test/CodeGenCXX/eh.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o - \
-// RUN:   | FileCheck %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-macosx10.13.99 -std=c++11 -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=UNALIGNED %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-macosx10.14 -std=c++11 -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ALIGNED %s
 
 struct test1_D {
   double d;
@@ -13,7 +13,8 @@
 // CHECK:   [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 8)
 // CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
 // CHECK-NEXT:  [[EXN2:%.*]] = bitcast [[DSTAR]] [[EXN]] to i8*
-// CHECK-NEXT:  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[EXN2]], i8* align 8 bitcast ([[DSTAR]] @d1 to i8*), i64 8, i1 false)
+// UNALIGNED-NEXT:  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[EXN2]], i8* align 8 bitcast ([[DSTAR]] @d1 to i8*), i64 8, i1 false)
+// ALIGNED-NEXT:  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[EXN2]], i8* align 8 bitcast ([[DSTAR]] @d1 to i8*), i64 8, i1 false)
 // CHECK-NEXT:  call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8* }* @_ZTI7test1_D to i8*), i8* null) [[NR:#[0-9]+]]
 // CHECK-NEXT:  unreachable
 
@@ -466,7 +467,8 @@
   // CHECK: [[T0:%.*]] = call i8* @__cxa_allocate_exception(i64 16)
   // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to %"class.test17::DerivedException"*
   //

[PATCH] D61522: Added an assertion to constant evaluation enty points that prohibits dependent expressions

2019-05-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 198603.
gribozavr added a comment.

Addressed review comments:

- Simplified error handling in SemaOpenMP,

- Only check isValueDependent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61522

Files:
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp

Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -6366,7 +6366,8 @@
 APValue Result;
 // FIXME: This doesn't consider value-dependent cases, because doing so is
 // very difficult. Ideally, we should handle them more gracefully.
-if (!EIA->getCond()->EvaluateWithSubstitution(
+if (EIA->getCond()->isValueDependent() ||
+!EIA->getCond()->EvaluateWithSubstitution(
 Result, Context, Function, llvm::makeArrayRef(ConvertedArgs)))
   return EIA;
 
@@ -9547,7 +9548,8 @@
 const FunctionDecl *FD) {
   for (auto *EnableIf : FD->specific_attrs()) {
 bool AlwaysTrue;
-if (!EnableIf->getCond()->EvaluateAsBooleanCondition(AlwaysTrue, Ctx))
+if (EnableIf->getCond()->isValueDependent() ||
+!EnableIf->getCond()->EvaluateAsBooleanCondition(AlwaysTrue, Ctx))
   return false;
 if (!AlwaysTrue)
   return false;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5880,14 +5880,21 @@
   if (CollapseLoopCountExpr) {
 // Found 'collapse' clause - calculate collapse number.
 Expr::EvalResult Result;
-if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
+if (!CollapseLoopCountExpr->isValueDependent() &&
+CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) {
   NestedLoopCount = Result.Val.getInt().getLimitedValue();
+} else {
+  Built.clear(/*size=*/1);
+  return 1;
+}
   }
   unsigned OrderedLoopCount = 1;
   if (OrderedLoopCountExpr) {
 // Found 'ordered' clause - calculate collapse number.
 Expr::EvalResult EVResult;
-if (OrderedLoopCountExpr->EvaluateAsInt(EVResult, SemaRef.getASTContext())) {
+if (!OrderedLoopCountExpr->isValueDependent() &&
+OrderedLoopCountExpr->EvaluateAsInt(EVResult,
+SemaRef.getASTContext())) {
   llvm::APSInt Result = EVResult.Val.getInt();
   if (Result.getLimitedValue() < NestedLoopCount) {
 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
@@ -5898,6 +5905,9 @@
 << CollapseLoopCountExpr->getSourceRange();
   }
   OrderedLoopCount = Result.getLimitedValue();
+} else {
+  Built.clear(/*size=*/1);
+  return 1;
 }
   }
   // This is helper routine for loop directives (e.g., 'for', 'simd',
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11100,6 +11100,8 @@
 /// will be applied to the result.
 bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx,
 bool InConstantContext) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
   Info.InConstantContext = InConstantContext;
   return ::EvaluateAsRValue(this, Result, Ctx, Info);
@@ -11107,6 +11109,8 @@
 
 bool Expr::EvaluateAsBooleanCondition(bool &Result,
   const ASTContext &Ctx) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalResult Scratch;
   return EvaluateAsRValue(Scratch, Ctx) &&
  HandleConversionToBool(Scratch.Val, Result);
@@ -4,18 +8,25 @@
 
 bool Expr::EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
  SideEffectsKind AllowSideEffects) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
   return ::EvaluateAsInt(this, Result, Ctx, AllowSideEffects, Info);
 }
 
 bool Expr::EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx,
 SideEffectsKind AllowSideEffects) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
   return ::EvaluateAsFixedPoint(this, Result, Ctx, AllowSideEffects, Info);
 }
 
 bool Expr::EvaluateAsFloat(APFloat &Result, const ASTContext &Ctx,
SideEff

[PATCH] D61522: Added an assertion to constant evaluation enty points that prohibits dependent expressions

2019-05-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr marked an inline comment as done.
gribozavr added a comment.

In D61522#1494155 , @rsmith wrote:

> The right thing to check in all of these cases should be only 
> `isValueDependent()`. Every type-dependent expression should generally also 
> be value-dependent (because the type is part of the value), but 
> value-dependent exactly means "dependent in a way that prevents constant 
> evaluation", so that's all that we should be checking.


Done.  PTAL.




Comment at: clang/lib/Sema/SemaOpenMP.cpp:5784
 Expr::EvalResult Result;
-if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
+if (!CollapseLoopCountExpr->isValueDependent() &&
+!CollapseLoopCountExpr->isTypeDependent() &&

ABataev wrote:
> gribozavr wrote:
> > ABataev wrote:
> > > I would suggest to modify the code of this function if we cannot get the 
> > > value of the loops.
> > > ```
> > > if (CollapseLoopCountExpr->isValueDependent() || 
> > > CollapseLoopCountExpr->isTypeDependent() || 
> > > OrderedLoopCountExpr->isValueDependent() || 
> > > OrderedLoopCountExpr->isTypeDependent()) {
> > >   Built.clear(/* size */0);
> > >   return 1;
> > > }
> > > ```
> > > at the beginning of the function.
> > I tried doing that, and a lot of tests started crashing with:
> > 
> > llvm-project/clang/lib/Sema/SemaOpenMP.cpp:9024: clang::StmtResult 
> > clang::Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective(ArrayRef >  *>, clang::Stmt *, clang::SourceLoc
> > ation, clang::SourceLocation, clang::Sema::VarsWithInheritedDSAType &): 
> > Assertion `(CurContext->isDependentContext() || B.builtAll()) && "omp 
> > target teams distribute simd loop exprs were not built"' failed.
> > 
> > Also, I wanted to note that if I were to make this change, then if 
> > `EvaluateAsInt` fails, we should apply the same recovery (`Built.clear(); 
> > return`).
> The just try to use `Built.clear(/* size */1);`, I assume it must fix the 
> problems. 
Yes, this works!  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61522



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


[PATCH] D61485: Added an assert in `isConstantInitializer`: initializer lists must be in semantic form

2019-05-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

@rsmith Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61485



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


[PATCH] D61668: [ARM] Fix the extensions implied by a cpu name

2019-05-08 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio created this revision.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar.
Herald added a project: clang.
dnsampaio added reviewers: keith.walker.arm, DavidSpickett, carwil.

When using `clang -mcpu=CPUNAME+FEATURELIST`,
the intrinsic features defined by CPUNAME are
not obtained, as the entire string is passed.
This fixes that by spiting the cpuname
string in the first `+`, if any.

For example, when using

  clang -### --target=arm-arm-none-eabi -march=armv7-a -mcpu=cortex-a8+nocrc

the intrinsic

  "target-feature" "+dsp"

implied by `cortex-a8` is missing.


Repository:
  rC Clang

https://reviews.llvm.org/D61668

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-cortex-cpus.c

Index: test/Driver/arm-cortex-cpus.c
===
--- test/Driver/arm-cortex-cpus.c
+++ test/Driver/arm-cortex-cpus.c
@@ -340,30 +340,31 @@
 // RUN: %clang -target armv8a-linux-eabi -mcpu=cortex-a53+fp16 -### -c %s 2>&1 | FileCheck --check-prefix CHECK-CORTEX-A53-FP16 %s
 // RUN: %clang -target armv8a-linux-eabi -mcpu=cortex-a53+nofp16 -### -c %s 2>&1 | FileCheck --check-prefix CHECK-CORTEX-A53-NOFP16 %s
 // CHECK-CORTEX-A53-FP16: "-cc1" {{.*}}"-target-cpu" "cortex-a53" {{.*}}"-target-feature" "+fullfp16"
-// CHECK-CORTEX-A53-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
-// CHECK-CORTEX-A53-NOFP16: "-cc1" {{.*}}"-target-cpu" "cortex-a53" {{.*}}"-target-feature" "-fullfp16" "-target-feature" "-fp16fml"
+// CHECK-CORTEX-A53-FP16-NOT: "-target-feature" "+fp16fml"
+// CHECK-CORTEX-A53-NOFP16-NOT: "+fullfp16"
+// CHECK-CORTEX-A53-NOFP16-NOT: "+fp16fml"
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V8A-NOFP16FML %s
-// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
-// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fullfp16"
+// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "+fp16fml"
+// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "+fullfp16"
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V8A-FP16 %s
-// CHECK-V8A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
+// CHECK-V8A-FP16-NOT: "-target-feature" "+fp16fml"
 // CHECK-V8A-FP16: "-target-feature" "+fullfp16"
-// CHECK-V8A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
+// CHECK-V8A-FP16-NOT: "-target-feature" "+fp16fml"
 // CHECK-V8A-FP16-SAME: {{$}}
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8-a+fp16fml -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V8A-FP16FML %s
 // CHECK-V8A-FP16FML: "-target-feature" "+fp16fml" "-target-feature" "+fullfp16"
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V82A-NOFP16FML %s
-// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
-// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fullfp16"
+// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "+fp16fml"
+// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "+fullfp16"
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V82A-FP16 %s
-// CHECK-V82A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
+// CHECK-V82A-FP16-NOT: "-target-feature" "+fp16fml"
 // CHECK-V82A-FP16: "-target-feature" "+fullfp16"
-// CHECK-V82A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
+// CHECK-V82A-FP16-NOT: "-target-feature" "+fp16fml"
 // CHECK-V82A-FP16-SAME: {{$}}
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8.2-a+fp16fml -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V82A-FP16FML %s
@@ -382,13 +383,13 @@
 // CHECK-V82A-NOFP16-FP16FML: "-target-feature" "+fp16fml" "-target-feature" "+fullfp16"
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8.3-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V83A-NOFP16FML %s
-// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
-// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fullfp16"
+// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "+fp16fml"
+// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "+fullfp16"
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8.3-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V83A-FP16 %s
-// CHECK-V83A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
+// CHECK-V83A-FP16-NOT: "-target-feature" "+fp16fml"
 // CHECK-V83A-FP16: "-target-feature" "+fullfp16"
-// CHECK-V83A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
+// CHECK-V83A-FP16-NOT: "-target-feature" "+fp16fml"
 // CHECK-V83A-FP16-SAME: {{$}}
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8.3-a+fp16fml -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V83A-FP16FML %s
@@ -407,8 +408,8 @@
 // CHECK-V83A-NOFP16-FP16FML: "-target-feature" "+fp16fml" "-target-feature" "+fullfp16"
 
 // RUN: %clang -target armv8a-linux-eabi -march=armv8.4-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V84A-NOFP16FML %s
-// CHECK-V84A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
-// CHECK-V84A-NOFP16F

[PATCH] D61637: [Syntax] Introduce syntax trees

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Corpus.h:23
+/// token buffers, source manager, etc.
+class Corpus {
+public:

sammccall wrote:
> I think plain SyntaxArena might be a better name here :-/
> Corpus refers to texts (the use in dex is by analogy, as we call symbols 
> "documents" from search).
> 
Went with Arena



Comment at: clang/include/clang/Tooling/Syntax/Corpus.h:26
+  Corpus(SourceManager &SourceMgr, const LangOptions &LangOpts,
+ TokenBuffer MainFile);
+

sammccall wrote:
> MainFile is presumably the whole TU, name might need a tweak.
> Can it be empty?
> The relationship between Corpus and TokenBuffer seems a little weird. Why is 
> it needed?
Operations on the trees sometimes need to know anything about underlying tokens 
- they have access to `TokenBuffer` that produced them.

More specifically, this can be used to map between spelled and expanded tokens 
and check the mappings are possible.



Comment at: clang/include/clang/Tooling/Syntax/Corpus.h:38
+  std::pair>
+  tokenizeBuffer(std::unique_ptr Buffer);
+

sammccall wrote:
> Are you planning to have a way to add tokens directly? Having to turn them 
> into text and re-lex them seems like it might be inconvenient.
The tokens have source locations and refer to a text in some buffer. 
`tokenizeBuffer` makes is easier, not harder, to mock tokens.



Comment at: clang/include/clang/Tooling/Syntax/Corpus.h:40
+
+  /// Construct a new syntax node of a specified kind. The memory for a node is
+  /// owned by the corpus and will be freed when the corpus is destroyed.

sammccall wrote:
> Now there's two ways to do this: `new (C.allocator()) T(...)` or 
> `C.construct(...)`. Do we need both?
> 
> (If we do, is the syntax `new (C) T(...)` more natural?)
I think `C.construct()` read better than `new (C) T(...)`. Not a big fan of 
placement new exprs.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:34
+
+/// Build a syntax tree for the main file.
+TranslationUnit *buildSyntaxTree(Corpus &C,

sammccall wrote:
> for a translation unit? or for only decls within the main file?
For a translation unit. We will add versions that built for a subtree of the 
AST later.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:40
+/// node.
+void traverse(Node *N, llvm::function_ref Visit);
+void traverse(const Node *N, llvm::function_ref Visit);

ilya-biryukov wrote:
> sammccall wrote:
> > I've been burned with adding these APIs without use cases.
> > 
> > It seems likely you want a way to:
> >  - skip traversal of children
> >  - abort the traversal entirely
> Not having an option to abort traversal protects us against timing attacks...
> 
> Agree with both, will address in this patch.
> 
Removed from the public API, we seem to have different ideas on how it should 
look like and I'd prefer to focus on storage model in this patch.



Comment at: clang/include/clang/Tooling/Syntax/Tree/Cascade.h:1
+//===- Tree.h - cascade of the syntax tree *- C++ 
-*-=//
+//

sammccall wrote:
> sammccall wrote:
> > sammccall wrote:
> > > this is Cascade.h, not tree.h
> > why "cascade"?
> The Tree/ subdirectory seems superfluous - why are these separate from 
> Syntax/?
Cascade defines a few base nodes: a composite node (`TreeNode`) and a leaf node 
that holds tokens.
I'd really like to isolate them from language-specific nodes, so 
language-specific nodes live in a separate file (`Nodes.h`).
However, they need to see the definition of a composite node, hence the split.

Users are advised to use an umbrella header, `Tree.h`. The extra directory is 
to minimize the number of headers in the top-level directory, having too many 
is confusing.



Comment at: clang/include/clang/Tooling/Syntax/Tree/Cascade.h:74
+/// A composite tree node that has children.
+class TreeNode : public Node {
+public:

sammccall wrote:
> This use of "tree node" to mean specifically internal node seems confusing - 
> is it common?
I don't think it's common, can use `CompositeNode` - seems like a better 
alternative


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61637



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


[PATCH] D61637: [Syntax] Introduce syntax trees

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 198609.
ilya-biryukov added a comment.

- s/corpus/arena
- Remove an accidental cmake change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61637

Files:
  clang/include/clang/Tooling/Syntax/Arena.h
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/include/clang/Tooling/Syntax/Tree/Cascade.h
  clang/include/clang/Tooling/Syntax/Tree/NodeKind.h
  clang/include/clang/Tooling/Syntax/Tree/NodeList.h
  clang/include/clang/Tooling/Syntax/Tree/Nodes.h
  clang/lib/Tooling/Syntax/Arena.cpp
  clang/lib/Tooling/Syntax/BuildFromAST.cpp
  clang/lib/Tooling/Syntax/CMakeLists.txt
  clang/lib/Tooling/Syntax/Cascade.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -0,0 +1,155 @@
+//===- TreeTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tree.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/Decl.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Syntax/Arena.h"
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "clang/Tooling/Syntax/Tree/Nodes.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace clang;
+
+namespace {
+class SyntaxTreeTest : public ::testing::Test {
+protected:
+  // Build a syntax tree for the code.
+  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+// FIXME: this code is almost the identical to the one in TokensTest. Share
+//it.
+class BuildSyntaxTree : public ASTConsumer {
+public:
+  BuildSyntaxTree(syntax::TranslationUnit *&Root,
+  std::unique_ptr &Arena,
+  std::unique_ptr Tokens)
+  : Root(Root), Arena(Arena), Tokens(std::move(Tokens)) {
+assert(this->Tokens);
+  }
+
+  void HandleTranslationUnit(ASTContext &Ctx) override {
+Arena = llvm::make_unique(Ctx.getSourceManager(),
+ Ctx.getLangOpts(),
+ std::move(*Tokens).consume());
+Tokens = nullptr; // make sure we fail if this gets called twice.
+Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl());
+  }
+
+private:
+  syntax::TranslationUnit *&Root;
+  std::unique_ptr &Arena;
+  std::unique_ptr Tokens;
+};
+
+class BuildSyntaxTreeAction : public ASTFrontendAction {
+public:
+  BuildSyntaxTreeAction(syntax::TranslationUnit *&Root,
+std::unique_ptr &Arena)
+  : Root(Root), Arena(Arena) {}
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+// We start recording the tokens, ast consumer will take on the result.
+auto Tokens =
+llvm::make_unique(CI.getPreprocessor());
+return llvm::make_unique(Root, Arena,
+  std::move(Tokens));
+  }
+
+private:
+  syntax::TranslationUnit *&Root;
+  std::unique_ptr &Arena;
+};
+
+constexpr const char *FileName = "./input.cpp";
+FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+// Prepare to run a compiler.
+std::vector Args = {"tok-test", "-std=c++03", "-fsyntax-only",
+  FileName};
+auto CI = createInvocationFromCommandLine(Args, Diags, FS);
+assert(CI);
+CI->getFrontendOpts().DisableFree = false;
+CI->getPreprocessorOpts().addRemappedFile(
+FileName, llvm::MemoryBuffer::getMemBufferCopy(Code).release());
+CompilerInstance Compiler;
+Compiler.setInvocation(std::move(CI));
+if (!Diags->getClient())
+  Diags->setClient(new IgnoringDiagConsumer);
+Compiler.setDiagnostics(Diags.get());
+Compiler.setFileManager(FileMgr.get());
+Compiler.setSourceManager(SourceMgr.get());
+
+syntax::TranslationUnit *Root = nullptr;
+BuildSyntaxTreeAction Recorder(Root, this->Arena);
+if (!Compiler.ExecuteAction(Recorder)) {
+  ADD_FAILURE() << "failed to run the frontend";
+  std::abort();
+}
+return Root;
+  }
+
+  // Adds a file to the t

[PATCH] D61637: [Syntax] Introduce syntax trees

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 198606.
ilya-biryukov marked 5 inline comments as done.
ilya-biryukov added a comment.

- Make traverse() internal to its only use-site.
- s/Corpus/Arena.
- Address some other comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61637

Files:
  clang/include/clang/Tooling/Syntax/Arena.h
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/include/clang/Tooling/Syntax/Tree/Cascade.h
  clang/include/clang/Tooling/Syntax/Tree/NodeKind.h
  clang/include/clang/Tooling/Syntax/Tree/NodeList.h
  clang/include/clang/Tooling/Syntax/Tree/Nodes.h
  clang/lib/Tooling/Syntax/Arena.cpp
  clang/lib/Tooling/Syntax/BuildFromAST.cpp
  clang/lib/Tooling/Syntax/CMakeLists.txt
  clang/lib/Tooling/Syntax/Cascade.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/tools/CMakeLists.txt
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -0,0 +1,155 @@
+//===- TreeTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tree.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/Decl.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Syntax/Arena.h"
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "clang/Tooling/Syntax/Tree/Nodes.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace clang;
+
+namespace {
+class SyntaxTreeTest : public ::testing::Test {
+protected:
+  // Build a syntax tree for the code.
+  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+// FIXME: this code is almost the identical to the one in TokensTest. Share
+//it.
+class BuildSyntaxTree : public ASTConsumer {
+public:
+  BuildSyntaxTree(syntax::TranslationUnit *&Root,
+  std::unique_ptr &Arena,
+  std::unique_ptr Tokens)
+  : Root(Root), Arena(Arena), Tokens(std::move(Tokens)) {
+assert(this->Tokens);
+  }
+
+  void HandleTranslationUnit(ASTContext &Ctx) override {
+Arena = llvm::make_unique(Ctx.getSourceManager(),
+ Ctx.getLangOpts(),
+ std::move(*Tokens).consume());
+Tokens = nullptr; // make sure we fail if this gets called twice.
+Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl());
+  }
+
+private:
+  syntax::TranslationUnit *&Root;
+  std::unique_ptr &Arena;
+  std::unique_ptr Tokens;
+};
+
+class BuildSyntaxTreeAction : public ASTFrontendAction {
+public:
+  BuildSyntaxTreeAction(syntax::TranslationUnit *&Root,
+std::unique_ptr &Arena)
+  : Root(Root), Arena(Arena) {}
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+// We start recording the tokens, ast consumer will take on the result.
+auto Tokens =
+llvm::make_unique(CI.getPreprocessor());
+return llvm::make_unique(Root, Arena,
+  std::move(Tokens));
+  }
+
+private:
+  syntax::TranslationUnit *&Root;
+  std::unique_ptr &Arena;
+};
+
+constexpr const char *FileName = "./input.cpp";
+FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+// Prepare to run a compiler.
+std::vector Args = {"tok-test", "-std=c++03", "-fsyntax-only",
+  FileName};
+auto CI = createInvocationFromCommandLine(Args, Diags, FS);
+assert(CI);
+CI->getFrontendOpts().DisableFree = false;
+CI->getPreprocessorOpts().addRemappedFile(
+FileName, llvm::MemoryBuffer::getMemBufferCopy(Code).release());
+CompilerInstance Compiler;
+Compiler.setInvocation(std::move(CI));
+if (!Diags->getClient())
+  Diags->setClient(new IgnoringDiagConsumer);
+Compiler.setDiagnostics(Diags.get());
+Compiler.setFileManager(FileMgr.get());
+Compiler.setSourceManager(SourceMgr.get());
+
+syntax::TranslationUnit *Root = nullptr;
+BuildSyntaxTreeAction Recorder(Root, this->Arena);
+if (!Compiler.ExecuteAction(Recorder)) {
+  ADD_

[PATCH] D61668: [ARM] Fix the extensions implied by a cpu name

2019-05-08 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

LGTM but the use of "intrinsic" in the commit message is confusing. Do you mean 
feature/implied feature, as in "the implied features defined by"?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61668



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


[PATCH] D61664: [NewPM] Setup Passes for KASan and KMSan

2019-05-08 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added a comment.

Rubberstamp LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61664



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


[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2019-05-08 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added a reviewer: rnk.
Herald added a project: clang.

In GCC, the .refptr stubs are only generated for x86_64, and only for code 
models medium and larger (and medium is the default for x86_64 since this was 
introduced). They can be omitted (for projects that are conscious about 
performance and size, and don't need automatically importing dll data members), 
by passing -mcmodel=small.

Within LLVM, the default code model is small, but within clang we can 
distinguish between nothing being specified at all (where CodeModel is equal to 
"default") and when the small (and tiny) models have been explicitly requested.

I'm not very pleased with the form of it (in splitting hairs between default 
which implies small, and explicit small), but it has the upside of achieving 
the same effect when the same option is passed as to GCC. Is there some other 
option that would be more suitable for controlling it (with the downside of 
needing different options wrt to GCC)? Or perhaps it's not worth the mess at 
all? The actual savings from omitting it are miniscule.

For reference, the whole refptr business was introduced in GCC in this commit, 
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=5496fac88af2009a2c4d5cfec0e722d5f962d80e,
 to fix this issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52790


Repository:
  rC Clang

https://reviews.llvm.org/D61670

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/dso-local-executable.c


Index: test/CodeGen/dso-local-executable.c
===
--- test/CodeGen/dso-local-executable.c
+++ test/CodeGen/dso-local-executable.c
@@ -9,8 +9,10 @@
 // COFF-DAG: @import_var = external dllimport global i32
 // COFF-DAG: declare dllimport void @import_func()
 
-// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck 
-allow-deprecated-dag-overlap --check-prefix=MINGW %s
-// MINGW-DAG: @bar = external global i32
+// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck 
-allow-deprecated-dag-overlap --check-prefixes=MINGW,MINGW-DEFAULT %s
+// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -mcode-model small -emit-llvm %s 
-o - | FileCheck -allow-deprecated-dag-overlap 
--check-prefixes=MINGW,MINGW-SMALL %s
+// MINGW-DEFAULT-DAG: @bar = external global i32
+// MINGW-SMALL-DAG: @bar = external dso_local global i32
 // MINGW-DAG: @weak_bar = extern_weak global i32
 // MINGW-DAG: declare dso_local void @foo()
 // MINGW-DAG: @baz = dso_local global i32 42
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -755,12 +755,16 @@
 return false;
 
   const llvm::Triple &TT = CGM.getTriple();
+  const auto &CGOpts = CGM.getCodeGenOpts();
   if (TT.isWindowsGNUEnvironment()) {
 // In MinGW, variables without DLLImport can still be automatically
 // imported from a DLL by the linker; don't mark variables that
 // potentially could come from another DLL as DSO local.
+// If the small or tiny code model has been explicitly requested,
+// mark everything as DSO local.
 if (GV->isDeclarationForLinker() && isa(GV) &&
-!GV->isThreadLocal())
+!GV->isThreadLocal() && CGOpts.CodeModel != "small" &&
+CGOpts.CodeModel != "tiny")
   return false;
   }
 
@@ -783,7 +787,6 @@
 return false;
 
   // If this is not an executable, don't assume anything is local.
-  const auto &CGOpts = CGM.getCodeGenOpts();
   llvm::Reloc::Model RM = CGOpts.RelocationModel;
   const auto &LOpts = CGM.getLangOpts();
   if (RM != llvm::Reloc::Static && !LOpts.PIE)


Index: test/CodeGen/dso-local-executable.c
===
--- test/CodeGen/dso-local-executable.c
+++ test/CodeGen/dso-local-executable.c
@@ -9,8 +9,10 @@
 // COFF-DAG: @import_var = external dllimport global i32
 // COFF-DAG: declare dllimport void @import_func()
 
-// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=MINGW %s
-// MINGW-DAG: @bar = external global i32
+// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefixes=MINGW,MINGW-DEFAULT %s
+// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -mcode-model small -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefixes=MINGW,MINGW-SMALL %s
+// MINGW-DEFAULT-DAG: @bar = external global i32
+// MINGW-SMALL-DAG: @bar = external dso_local global i32
 // MINGW-DAG: @weak_bar = extern_weak global i32
 // MINGW-DAG: declare dso_local void @foo()
 // MINGW-DAG: @baz = dso_local global i32 42
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -755,12 +755,16 @@
 return false;
 
   c

[PATCH] D61506: [OpenCL] Switch to C++17

2019-05-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D61506#1493953 , @keryell wrote:

> In D61506#1490555 , @rsmith wrote:
>
> > Per the OpenCL C++ 1.0 specification, section 2:
> >
> > > The OpenCL C++ programming language is based on the ISO/IEC JTC1 SC22 
> > > WG21 N 3690 language specification (a.k.a. C++14 specification).
> >
> > I think it would be reasonable to permit changing the base C++ standard in 
> > OpenCL C++ mode
>
>
> Indeed! There should be an option to pick the version of C++ the user wants 
> for OpenCL.


Unfortunately, this is not easy to do. We document changes on top of other spec 
and we need to provide references. It would be a lot more work to refer to all 
different spec versions of C++. Also the development becomes more complicated 
as it needs testing and fixing against all different C++ versions. It makes 
sense to focus on one version and potentially provide an upgrade in the future. 
Also C++17 is a reasonable target most of developers should be happy with at 
this point.


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

https://reviews.llvm.org/D61506



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


[PATCH] D58236: Make address space conversions a bit stricter.

2019-05-08 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

This was accepted a while ago, but never landed. I don't have commit access; 
could someone commit it?


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

https://reviews.llvm.org/D58236



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


[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-08 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 198618.
martong added a comment.

- Add braces to 'true' cases when 'false' case has braces
- Simplify logging and error handling with LLDB_LOG_ERROR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61438

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExternalASTMerger.cpp
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/ASTMerge.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Symbol/ClangASTContext.cpp
  lldb/source/Symbol/ClangASTImporter.cpp
  lldb/source/Symbol/CxxModuleHandler.cpp

Index: lldb/source/Symbol/CxxModuleHandler.cpp
===
--- lldb/source/Symbol/CxxModuleHandler.cpp
+++ lldb/source/Symbol/CxxModuleHandler.cpp
@@ -9,6 +9,7 @@
 #include "lldb/Symbol/CxxModuleHandler.h"
 
 #include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Utility/Log.h"
 #include "clang/Sema/Lookup.h"
 #include "llvm/Support/Error.h"
 
@@ -214,13 +215,15 @@
   // Import the foreign template arguments.
   llvm::SmallVector imported_args;
 
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+
   // If this logic is changed, also update templateArgsAreSupported.
   for (const TemplateArgument &arg : foreign_args.asArray()) {
 switch (arg.getKind()) {
 case TemplateArgument::Type: {
-  llvm::Expected type = m_importer->Import_New(arg.getAsType());
+  llvm::Expected type = m_importer->Import(arg.getAsType());
   if (!type) {
-llvm::consumeError(type.takeError());
+LLDB_LOG_ERROR(log, type.takeError(), "Couldn't import type: {0}");
 return {};
   }
   imported_args.push_back(TemplateArgument(*type));
@@ -229,9 +232,9 @@
 case TemplateArgument::Integral: {
   llvm::APSInt integral = arg.getAsIntegral();
   llvm::Expected type =
-  m_importer->Import_New(arg.getIntegralType());
+  m_importer->Import(arg.getIntegralType());
   if (!type) {
-llvm::consumeError(type.takeError());
+LLDB_LOG_ERROR(log, type.takeError(), "Couldn't import type: {0}");
 return {};
   }
   imported_args.push_back(
Index: lldb/source/Symbol/ClangASTImporter.cpp
===
--- lldb/source/Symbol/ClangASTImporter.cpp
+++ lldb/source/Symbol/ClangASTImporter.cpp
@@ -62,8 +62,16 @@
 
   ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
 
-  if (delegate_sp)
-return delegate_sp->Import(type);
+  if (delegate_sp) {
+if (llvm::Expected ret_or_error = delegate_sp->Import(type)) {
+  return *ret_or_error;
+} else {
+  Log *log =
+  lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+  LLDB_LOG_ERROR(log, ret_or_error.takeError(),
+ "Couldn't import type: {0}");
+}
+  }
 
   return QualType();
 }
@@ -106,7 +114,7 @@
   ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
 
   if (delegate_sp) {
-clang::Decl *result = delegate_sp->Import(decl);
+llvm::Expected result = delegate_sp->Import(decl);
 
 if (!result) {
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
@@ -127,9 +135,13 @@
   "metadata 0x%" PRIx64,
   decl->getDeclKindName(), user_id);
   }
+
+  llvm::consumeError(result.takeError());
+
+  return nullptr;
 }
 
-return result;
+return *result;
   }
 
   return nullptr;
@@ -624,6 +636,8 @@
   if (!RequireCompleteType(type))
 return false;
 
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+
   if (const TagType *tag_type = type->getAs()) {
 TagDecl *tag_decl = tag_type->getDecl();
 
@@ -641,7 +655,12 @@
 TagDecl *origin_tag_decl = llvm::dyn_cast(decl_origin.decl);
 
 for (Decl *origin_child_decl : origin_tag_decl->decls()) {
-  delegate_sp->Import(origin_child_decl);
+  llvm::Expected imported_or_err =
+  delegate_sp->Import(origin_child_decl);
+  if (!imported_or_err)
+// FIXME return with false?
+LLDB_LOG_ERROR(log, imported_or_err.takeError(),
+   "Couldn't import decl: {0}");
 }
 
 if (RecordDecl *record_decl = dyn_cast(origin_tag_decl)) {
@@ -666,7 +685,12 @@
   llvm::dyn_cast(decl_origin.decl);
 
   for (Decl *origin_child_decl : origin_interface_decl->decls()) {
-delegate_sp->Import(origin_child_decl);
+llvm::Expected imported_or_err =
+delegate_sp->Import(origin_child_decl);
+if (!imported_or_err)
+  // FIXME return with false?
+  LLDB_LOG_ERROR(log, imported_or_err.takeError(),
+ 

[PATCH] D58236: Make address space conversions a bit stricter.

2019-05-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D58236#1494722 , @ebevhan wrote:

> This was accepted a while ago, but never landed. I don't have commit access; 
> could someone commit it?


Sure!


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

https://reviews.llvm.org/D58236



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


[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-08 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 198623.
martong added a comment.

- Use LLDB_LOG_ERROR in ImportDefinitionTo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61438

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExternalASTMerger.cpp
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/ASTMerge.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Symbol/ClangASTContext.cpp
  lldb/source/Symbol/ClangASTImporter.cpp
  lldb/source/Symbol/CxxModuleHandler.cpp

Index: lldb/source/Symbol/CxxModuleHandler.cpp
===
--- lldb/source/Symbol/CxxModuleHandler.cpp
+++ lldb/source/Symbol/CxxModuleHandler.cpp
@@ -9,6 +9,7 @@
 #include "lldb/Symbol/CxxModuleHandler.h"
 
 #include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Utility/Log.h"
 #include "clang/Sema/Lookup.h"
 #include "llvm/Support/Error.h"
 
@@ -214,13 +215,15 @@
   // Import the foreign template arguments.
   llvm::SmallVector imported_args;
 
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+
   // If this logic is changed, also update templateArgsAreSupported.
   for (const TemplateArgument &arg : foreign_args.asArray()) {
 switch (arg.getKind()) {
 case TemplateArgument::Type: {
-  llvm::Expected type = m_importer->Import_New(arg.getAsType());
+  llvm::Expected type = m_importer->Import(arg.getAsType());
   if (!type) {
-llvm::consumeError(type.takeError());
+LLDB_LOG_ERROR(log, type.takeError(), "Couldn't import type: {0}");
 return {};
   }
   imported_args.push_back(TemplateArgument(*type));
@@ -229,9 +232,9 @@
 case TemplateArgument::Integral: {
   llvm::APSInt integral = arg.getAsIntegral();
   llvm::Expected type =
-  m_importer->Import_New(arg.getIntegralType());
+  m_importer->Import(arg.getIntegralType());
   if (!type) {
-llvm::consumeError(type.takeError());
+LLDB_LOG_ERROR(log, type.takeError(), "Couldn't import type: {0}");
 return {};
   }
   imported_args.push_back(
Index: lldb/source/Symbol/ClangASTImporter.cpp
===
--- lldb/source/Symbol/ClangASTImporter.cpp
+++ lldb/source/Symbol/ClangASTImporter.cpp
@@ -62,8 +62,16 @@
 
   ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
 
-  if (delegate_sp)
-return delegate_sp->Import(type);
+  if (delegate_sp) {
+if (llvm::Expected ret_or_error = delegate_sp->Import(type)) {
+  return *ret_or_error;
+} else {
+  Log *log =
+  lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+  LLDB_LOG_ERROR(log, ret_or_error.takeError(),
+ "Couldn't import type: {0}");
+}
+  }
 
   return QualType();
 }
@@ -106,7 +114,7 @@
   ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
 
   if (delegate_sp) {
-clang::Decl *result = delegate_sp->Import(decl);
+llvm::Expected result = delegate_sp->Import(decl);
 
 if (!result) {
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
@@ -127,9 +135,13 @@
   "metadata 0x%" PRIx64,
   decl->getDeclKindName(), user_id);
   }
+
+  llvm::consumeError(result.takeError());
+
+  return nullptr;
 }
 
-return result;
+return *result;
   }
 
   return nullptr;
@@ -624,6 +636,8 @@
   if (!RequireCompleteType(type))
 return false;
 
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+
   if (const TagType *tag_type = type->getAs()) {
 TagDecl *tag_decl = tag_type->getDecl();
 
@@ -641,7 +655,12 @@
 TagDecl *origin_tag_decl = llvm::dyn_cast(decl_origin.decl);
 
 for (Decl *origin_child_decl : origin_tag_decl->decls()) {
-  delegate_sp->Import(origin_child_decl);
+  llvm::Expected imported_or_err =
+  delegate_sp->Import(origin_child_decl);
+  if (!imported_or_err)
+// FIXME return with false?
+LLDB_LOG_ERROR(log, imported_or_err.takeError(),
+   "Couldn't import decl: {0}");
 }
 
 if (RecordDecl *record_decl = dyn_cast(origin_tag_decl)) {
@@ -666,7 +685,12 @@
   llvm::dyn_cast(decl_origin.decl);
 
   for (Decl *origin_child_decl : origin_interface_decl->decls()) {
-delegate_sp->Import(origin_child_decl);
+llvm::Expected imported_or_err =
+delegate_sp->Import(origin_child_decl);
+if (!imported_or_err)
+  // FIXME return with false?
+  LLDB_LOG_ERROR(log, imported_or_err.takeError(),
+ "Couldn't import decl: {0}");
   }
 
   r

[PATCH] D61644: Documentation for bugprone-inaccurate-erase: added an example of a bug that this checker catches

2019-05-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61644



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


[PATCH] D61424: [ASTImporter] Fix inequivalence of unresolved exception spec

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

- Improve and fix typo in comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61424

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp


Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -322,6 +322,36 @@
   return true;
 }
 
+/// Check the equivalence of exception specifications.
+static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,
+  const FunctionProtoType *Proto1,
+  const FunctionProtoType *Proto2) {
+
+  auto Spec1 = Proto1->getExceptionSpecType();
+  auto Spec2 = Proto2->getExceptionSpecType();
+
+  if (isUnresolvedExceptionSpec(Spec1) || isUnresolvedExceptionSpec(Spec2))
+return true;
+
+  if (Spec1 != Spec2)
+return false;
+  if (Spec1 == EST_Dynamic) {
+if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
+  return false;
+for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
+  if (!IsStructurallyEquivalent(Context, Proto1->getExceptionType(I),
+Proto2->getExceptionType(I)))
+return false;
+}
+  } else if (isComputedNoexcept(Spec1)) {
+if (!IsStructurallyEquivalent(Context, Proto1->getNoexceptExpr(),
+  Proto2->getNoexceptExpr()))
+  return false;
+  }
+
+  return true;
+}
+
 /// Determine structural equivalence of two types.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  QualType T1, QualType T2) {
@@ -536,24 +566,8 @@
 cast(OrigT1.getDesugaredType(Context.FromCtx));
 const auto *OrigProto2 =
 cast(OrigT2.getDesugaredType(Context.ToCtx));
-auto Spec1 = OrigProto1->getExceptionSpecType();
-auto Spec2 = OrigProto2->getExceptionSpecType();
-
-if (Spec1 != Spec2)
+if (!IsEquivalentExceptionSpec(Context, OrigProto1, OrigProto2))
   return false;
-if (Spec1 == EST_Dynamic) {
-  if (OrigProto1->getNumExceptions() != OrigProto2->getNumExceptions())
-return false;
-  for (unsigned I = 0, N = OrigProto1->getNumExceptions(); I != N; ++I) {
-if (!IsStructurallyEquivalent(Context, OrigProto1->getExceptionType(I),
-  OrigProto2->getExceptionType(I)))
-  return false;
-  }
-} else if (isComputedNoexcept(Spec1)) {
-  if (!IsStructurallyEquivalent(Context, OrigProto1->getNoexceptExpr(),
-OrigProto2->getNoexceptExpr()))
-return false;
-}
 
 // Fall through to check the bits common with FunctionNoProtoType.
 LLVM_FALLTHROUGH;
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3101,6 +3101,11 @@
 auto *Recent = const_cast(
   FoundByLookup->getMostRecentDecl());
 ToFunction->setPreviousDecl(Recent);
+// FIXME Probably we should merge exception specifications.  E.g. In the
+// "To" context the existing function may have exception specification with
+// noexcept-unevaluated, while the newly imported function may have an
+// evaluated noexcept.  A call to adjustExceptionSpec() on the imported
+// decl and its redeclarations may be required.
   }
 
   // Import Ctor initializers.


Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -322,6 +322,36 @@
   return true;
 }
 
+/// Check the equivalence of exception specifications.
+static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,
+  const FunctionProtoType *Proto1,
+  const FunctionProtoType *Proto2) {
+
+  auto Spec1 = Proto1->getExceptionSpecType();
+  auto Spec2 = Proto2->getExceptionSpecType();
+
+  if (isUnresolvedExceptionSpec(Spec1) || isUnresolvedExceptionSpec(Spec2))
+return true;
+
+  if (Spec1 != Spec2)
+return false;
+  if (Spec1 == EST_Dynamic) {
+if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
+  return false;
+for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
+  if (!IsStructurallyEquivalent(Context, Proto1->getExceptionType(I),
+Proto2->getExceptionType(I)))
+return false;
+}
+  } else if (isComputedNoexcept(Spec1)) {
+if (!IsStructurallyEquivalent(Context, Proto1->get

[clang-tools-extra] r360247 - Documentation for bugprone-inaccurate-erase: added an example of a bug that this checker catches

2019-05-08 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed May  8 05:02:31 2019
New Revision: 360247

URL: http://llvm.org/viewvc/llvm-project?rev=360247&view=rev
Log:
Documentation for bugprone-inaccurate-erase: added an example of a bug that 
this checker catches

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst?rev=360247&r1=360246&r2=360247&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst 
Wed May  8 05:02:31 2019
@@ -11,3 +11,19 @@ container but return an iterator to the
 of the container. These redundant elements must be removed using the
 ``erase()`` method. This check warns when not all of the elements will be
 removed due to using an inappropriate overload.
+
+For example, the following code erases only one element:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10));
+
+Call the two-argument overload of ``erase()`` to remove the subrange:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10), xs.end());


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


[PATCH] D61506: [OpenCL] Switch to C++17

2019-05-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 198627.
Anastasia added a comment.

Added `HexFloat`!


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

https://reviews.llvm.org/D61506

Files:
  include/clang/Frontend/LangStandards.def
  test/CodeGenOpenCLCXX/addrspace-of-this.cl


Index: test/CodeGenOpenCLCXX/addrspace-of-this.cl
===
--- test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -109,15 +109,9 @@
 // IMPL: call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* 
{{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
 
 // Test the address space of 'this' when invoking the operator+
-// COMMON: [[C3GEN:%[0-9]+]] = addrspacecast %class.C* %c3 to %class.C 
addrspace(4)*
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
 // COMMON: [[C2GEN:%[0-9]+]] = addrspacecast %class.C* %c2 to %class.C 
addrspace(4)*
-// COMMON: call void @_ZNU3AS41CplERU3AS4KS_(%class.C* sret %ref.tmp, %class.C 
addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[C2GEN]])
-// COMMON: [[REFGEN:%[0-9]+]] = addrspacecast %class.C* %ref.tmp to %class.C 
addrspace(4)*
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* [[C3GEN]], 
%class.C addrspace(4)* dereferenceable(4) [[REFGEN]])
-// IMPL: [[C3VOID:%[0-9]+]] = bitcast %class.C* %c3 to i8*
-// IMPL: [[REFGENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[REFGEN]] to 
i8 addrspace(4)*
-// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C3VOID]], i8 
addrspace(4)* {{.*}}[[REFGENVOID]]
+// COMMON: call void @_ZNU3AS41CplERU3AS4KS_(%class.C* sret %c3, %class.C 
addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[C2GEN]])
 
 // Test the address space of 'this' when invoking the move constructor
 // COMMON: [[C4GEN:%[0-9]+]] = addrspacecast %class.C* %c4 to %class.C 
addrspace(4)*
Index: include/clang/Frontend/LangStandards.def
===
--- include/clang/Frontend/LangStandards.def
+++ include/clang/Frontend/LangStandards.def
@@ -159,7 +159,8 @@
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
 LANGSTANDARD(openclcpp, "c++",
  OpenCL, "OpenCL C++ 1.0",
- LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs | 
OpenCL)
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 
|
+ Digraphs | HexFloat | OpenCL)
 
 LANGSTANDARD_ALIAS_DEPR(opencl10, "CL")
 LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")


Index: test/CodeGenOpenCLCXX/addrspace-of-this.cl
===
--- test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -109,15 +109,9 @@
 // IMPL: call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* {{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
 
 // Test the address space of 'this' when invoking the operator+
-// COMMON: [[C3GEN:%[0-9]+]] = addrspacecast %class.C* %c3 to %class.C addrspace(4)*
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
 // COMMON: [[C2GEN:%[0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
-// COMMON: call void @_ZNU3AS41CplERU3AS4KS_(%class.C* sret %ref.tmp, %class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[C2GEN]])
-// COMMON: [[REFGEN:%[0-9]+]] = addrspacecast %class.C* %ref.tmp to %class.C addrspace(4)*
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* [[C3GEN]], %class.C addrspace(4)* dereferenceable(4) [[REFGEN]])
-// IMPL: [[C3VOID:%[0-9]+]] = bitcast %class.C* %c3 to i8*
-// IMPL: [[REFGENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[REFGEN]] to i8 addrspace(4)*
-// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C3VOID]], i8 addrspace(4)* {{.*}}[[REFGENVOID]]
+// COMMON: call void @_ZNU3AS41CplERU3AS4KS_(%class.C* sret %c3, %class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[C2GEN]])
 
 // Test the address space of 'this' when invoking the move constructor
 // COMMON: [[C4GEN:%[0-9]+]] = addrspacecast %class.C* %c4 to %class.C addrspace(4)*
Index: include/clang/Frontend/LangStandards.def
===
--- include/clang/Frontend/LangStandards.def
+++ include/clang/Frontend/LangStandards.def
@@ -159,7 +159,8 @@
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
 LANGSTANDARD(openclcpp, "c++",
  OpenCL, "OpenCL C++ 1.0",
- LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs | OpenCL)
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 |
+ Digraphs | HexFloat | OpenCL)
 
 LANGSTANDARD_ALIAS_DEPR(opencl10, "CL")
 LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")
___
cfe-commits mailing list
cfe-commits@lists.l

[PATCH] D61644: Documentation for bugprone-inaccurate-erase: added an example of a bug that this checker catches

2019-05-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE360247: Documentation for bugprone-inaccurate-erase: added 
an example of a bug that… (authored by gribozavr, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61644?vs=198492&id=198628#toc

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61644

Files:
  docs/clang-tidy/checks/bugprone-inaccurate-erase.rst


Index: docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
===
--- docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
+++ docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
@@ -11,3 +11,19 @@
 of the container. These redundant elements must be removed using the
 ``erase()`` method. This check warns when not all of the elements will be
 removed due to using an inappropriate overload.
+
+For example, the following code erases only one element:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10));
+
+Call the two-argument overload of ``erase()`` to remove the subrange:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10), xs.end());


Index: docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
===
--- docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
+++ docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
@@ -11,3 +11,19 @@
 of the container. These redundant elements must be removed using the
 ``erase()`` method. This check warns when not all of the elements will be
 removed due to using an inappropriate overload.
+
+For example, the following code erases only one element:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10));
+
+Call the two-argument overload of ``erase()`` to remove the subrange:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10), xs.end());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60910: [WIP] Dumping the AST to JSON

2019-05-08 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno marked an inline comment as done.
riccibruno added inline comments.



Comment at: include/clang/AST/JSONNodeDumper.h:55
+  }
+
+  /// Add a child of the current node with an optional label.

aaron.ballman wrote:
> riccibruno wrote:
> > Perhaps you should perfect-forward `DoAddChild` ?
> Hmm, if I was doing that, I'd probably prefer to use `std::invoke()` to call 
> the function, but we can't use that because it's C++17. Do you have concerns 
> if I don't make that change just yet (we don't do it from `TextNodeDumper` 
> either).
Sounds good!


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

https://reviews.llvm.org/D60910



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


[PATCH] D60956: [Sema] Fix the lookup for a declaration conflicting with an enumerator

2019-05-08 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 198629.
riccibruno marked 4 inline comments as done.
riccibruno added a comment.

Address Aaron's comments.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60956

Files:
  lib/Sema/SemaDecl.cpp
  test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp

Index: test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp
===
--- test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp
+++ test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp
@@ -6,36 +6,29 @@
 // enumerator is declared in the scope of the enumeration. These names obey
 // the scope rules defined for all names in 6.3 and 6.4.
 
-// FIXME: Actually implement the redeclaration lookup properly.
 // FIXME: Improve the wording of the error messages (definition vs declaration).
-// FIXME: Only emit the Wshadow warning when the declaration of the
-//enumerator does not conflict with another declaration.
 
-// We also test for -Wshadow since the functionality is closely related,
-// and we don't want to mess up Wshadow by fixing the redeclaration lookup.
+// We also test for -Wshadow since the functionality is closely related.
 
 struct S_function {
   void f(); // expected-note 2{{previous definition}}
-// FIXME: Don't emit shadow-note@-1 2{{previous declaration}}
   enum { f };   // expected-error {{redefinition of 'f'}}
-// FIXME: Don't emit shadow-warning@-1 {{declaration shadows}}
   enum E1 { f };// expected-error {{redefinition of 'f'}}
-// FIXME: Don't emit shadow-warning@-1 {{declaration shadows}}
   enum class E2 { f };  // ok
 };
 
 struct S_overloaded_function {
   void f();
-  void f(int);
-  enum { f };   // FIXME: Reject.
-  enum E1 { f };// FIXME: Reject.
+  void f(int);  // expected-note 2{{previous definition}}
+  enum { f };   // expected-error {{redefinition of 'f'}}
+  enum E1 { f };// expected-error {{redefinition of 'f'}}
   enum class E2 { f };  // ok
 };
 
 struct S_function_template {
-  template  void f();
-  enum { f };  // FIXME: Reject.
-  enum E1 { f };   // FIXME: Reject.
+  template  void f(); // expected-note 2{{previous definition}}
+  enum { f };  // expected-error {{redefinition of 'f'}}
+  enum E1 { f };   // expected-error {{redefinition of 'f'}}
   enum class E2 { f }; // ok
 };
 
@@ -51,12 +44,9 @@
 struct S_member {
   struct f;
   int f;  // expected-note {{previous definition}}
-  // FIXME: Don't emit shadow-note@-1 {{previous declaration}}
   static int g;   // expected-note {{previous definition}}
-  // FIXME: Don't emit shadow-note@-1 {{previous declaration}}
   enum { f, g };  // expected-error {{redefinition of 'f'}}
   // expected-error@-1 {{redefinition of 'g'}}
-  // FIXME: Don't emit shadow-warning@-2 2{{declaration shadows}}
 };
 
 namespace S_out_of_line_definition {
@@ -77,17 +67,16 @@
 namespace S_using_decl {
 
 struct Base {
-  int f; // FIXME: Don't emit shadow-note {{previous declaration}}
+  int f;  // expected-note {{target of using declaration}}
   int g;
 
   struct s;
-  typedef struct s t;
+  typedef struct s t; // expected-note {{target of using declaration}}
 };
 struct OtherBase {};
 struct Der : Base, OtherBase {
-  using Base::f;
-  enum { f }; // FIXME: Reject.
-  // FIXME: Don't emit shadow-warning@-1 {{declaration shadows}}
+  using Base::f; // expected-note {{using declaration}}
+  enum { f }; // expected-error {{declaration conflicts with target of using declaration already in scope}}
   enum { g }; // ok
 
   using OtherBase::OtherBase;
@@ -96,8 +85,8 @@
   using Base::s;
   enum { s }; // ok
 
-  using Base::t;
-  enum { t }; // FIXME: Reject.
+  using Base::t;  // expected-note {{using declaration}}
+  enum { t }; // expected-error {{declaration conflicts with target of using declaration already in scope}}
 };
 
 } // namespace S_using_decl
@@ -111,8 +100,8 @@
 };
 
 template  struct Der : Base {
-  using Base::t;
-  enum { t }; // FIXME: Reject.
+  using Base::t; // expected-note {{previous definition}}
+  enum { t };   // expected-error {{redefinition of 't'}}
   // [namespace.udecl]p20:
   //   If a using-declarator uses the keyword typename and specifies a
   //   dependent name (17.6.2), the name introduced by the using-declaration
@@ -131,26 +120,23 @@
 
 namespace N_function {
   void f(); // expected-note 2{{previous definition}}
-// FIXME: Don't emit shadow-note@-1 2{{previous declaration}}
   enum { f };   // expected-error {{redefinition of 'f'}}
-// FIXME: Don't emit shadow-warning@-1 {{declaration shadows}}
   enum E1 { f };// expected-error {{redefinition of 'f'}}
-   

[PATCH] D61506: [OpenCL] Switch to C++17

2019-05-08 Thread Kévin Petit via Phabricator via cfe-commits
kpet accepted this revision.
kpet added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D61506



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


[PATCH] D61497: [clangd] Introduce a structured hover response

2019-05-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 198630.
kadircet marked 23 inline comments as done.
kadircet added a comment.

- Address comments
- Make little modifications to existing tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61497

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -937,7 +937,7 @@
   ^auto i = {1,2};
 }
   )cpp",
-  "class std::initializer_list",
+  "template<> class initializer_list {}",
   },
   {
   R"cpp(// User defined conversion to auto
@@ -1012,7 +1012,7 @@
   return Bar();
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// trailing return type
@@ -1021,7 +1021,7 @@
   return Bar();
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// auto in function return
@@ -1030,7 +1030,7 @@
   return Bar();
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// auto& in function return
@@ -1039,7 +1039,7 @@
   return Bar();
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// auto* in function return
@@ -1049,7 +1049,7 @@
   return bar;
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// const auto& in function return
@@ -1058,7 +1058,7 @@
   return Bar();
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// decltype(auto) in function return
@@ -1067,7 +1067,7 @@
   return Bar();
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// decltype(auto) reference in function return
@@ -1136,7 +1136,7 @@
   ^decltype(test()) i = test();
 }
   )cpp",
-  "struct Bar",
+  "struct Bar {}",
   },
   {
   R"cpp(// decltype of var with decltype.
@@ -1185,7 +1185,8 @@
 auto AST = TU.build();
 if (auto H = getHover(AST, T.point())) {
   EXPECT_NE("", Test.ExpectedHover) << Test.Input;
-  EXPECT_EQ(H->contents.value, Test.ExpectedHover.str()) << Test.Input;
+  EXPECT_EQ(H->render().contents.value, Test.ExpectedHover.str())
+  << Test.Input;
 } else
   EXPECT_EQ("", Test.ExpectedHover.str()) << Test.Input;
   }
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -16,7 +16,10 @@
 #include "ClangdUnit.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/SymbolLocation.h"
+#include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 
 namespace clang {
@@ -46,8 +49,53 @@
 std::vector findDocumentHighlights(ParsedAST &AST,
   Position Pos);
 
+/// Contains detailed information about a Symbol. Especially useful when
+/// generating hover responses. It is not serialized so that embedding clients
+/// can choose to serialize it w.r.t their UI capabilities.
+struct HoverInfo {
+  /// Represents parameters of a function, a template or a macro.
+  /// For example:
+  /// - void foo(ParamType Name = DefaultValue)
+  /// - #define FOO(Name)
+  /// - template  class Foo {};
+  struct Param {
+/// The pretty-printed parameter type, e.g. "int", or "typename" (in
+/// TemplateParameters)
+llvm::Optional Type;
+/// None for unnamed parameters.
+llvm::Optional Name;
+/// None if no default is provided.
+llvm::Optional Default;
+  };
+
+  std::string Name;
+  std::string Scope;
+  llvm::Optional SymRange;
+  /// Scope containing the symbol. e.g, "global namespace", "function x::Y"
+  /// - None for deduced types, e.g "auto", "decltype" keywords.
+  llvm::Optional ContainedIn;
+  SymbolKind Kind;
+  std::string Documentation;
+  /// Source code containing the definition of the symbol.
+  std::string Definition;
+
+  /// Pretty-printed variable type.
+  /// Set only for variables.
+  llvm::Optional Type;
+  /// Set for functions and lambadas.
+  llvm::Optional ReturnType;
+  /// S

[PATCH] D61497: [clangd] Introduce a structured hover response

2019-05-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:574
 
-  // We want to include the template in the Hover.
-  if (TemplateDecl *TD = D->getDescribedTemplate())
-D = TD;
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+  const std::vector &Params) {

sammccall wrote:
> I don't think it's reasonable to define this private helper as an overload of 
> operator<<.
> Make it a function, or inline it? (I think used only once)
it is also used within render, making it a function



Comment at: clang-tools-extra/clangd/XRefs.h:65
+  /// Fully qualiffied name for the scope containing the Sym.
+  std::string Scope;
+  std::string ParentScope;

sammccall wrote:
> what's the difference between Scope and ParentScope?
> Can we give them more obvious names, or a comment?
> (The current comment doesn't really say anything)
We've been using Name and Scope to represent two parts of qualified names 
across the codebase.
Comment was unfortunately misplaced :/ LMK if you have any other choices for 
the name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61497



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


[PATCH] D61497: [clangd] Introduce a structured hover response

2019-05-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 6 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:539
 
-/// Generate a \p Hover object given the declaration \p D.
-static Hover getHoverContents(const Decl *D) {
-  Hover H;
-  llvm::Optional NamedScope = getScopeName(D);
+static QualType getDeclType(const Decl *D) {
+  if (const TypedefNameDecl *TDD = dyn_cast(D))

sammccall wrote:
> I think this is basically ASTContext::getTypeDeclType()?
No longer needed



Comment at: clang-tools-extra/clangd/XRefs.cpp:549
 
-  // Generate the "Declared in" section.
-  if (NamedScope) {
-assert(!NamedScope->empty());
+static llvm::Optional getDeclLoc(const SourceLocation &SL,
+   ASTContext &AST) {

sammccall wrote:
> what does this have to do with decls?
No longer needed



Comment at: clang-tools-extra/clangd/XRefs.cpp:1214
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const HoverInfo &HI) {
+  OS << HI.Definition << '\n';
+  OS << HI.Documentation << '\n';

sammccall wrote:
> This doesn't seem sufficiently self-documenting.
No longer needed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61497



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


[PATCH] D56160: [clang-tidy] modernize-use-trailing-return-type check

2019-05-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from a formatting issue, this LGTM, thank you!




Comment at: clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:93
+DeclarationName Name = S->getNameInfo().getName();
+return S->getQualifierLoc() || !Name.isIdentifier() || 
!VisitUnqualName(Name.getAsIdentifierInfo()->getName());
+  }

80-col limit.


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

https://reviews.llvm.org/D56160



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


[PATCH] D60629: [clang-tidy] Change the namespace for llvm checkers from 'llvm' to 'llvm_check'

2019-05-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

This LGTM, but you may want to wait a day or so to see if @alexfh has any 
remaining concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60629



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


[PATCH] D59481: [clangd] Count number of references while merging RefSlabs inside FileIndex

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/index/Background.cpp:482
 FileDigest Digest;
+bool IsMainFile;
   };

NIT: maybe initialize with `=false` to avoid potential UB.
`Digest` seems uninitialized too, could also `={}` for it.

Sorry if this was discussed before and I'm repeating myself, I vaguely remember 
something similar but not sure what the conclusion was.



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:116
+  RefSlabs.push_back(FileAndRefs.second.first);
+  if (FileAndRefs.second.second)
+MainFileRefs.push_back(RefSlabs.back().get());

Let's use a named struct here? `.second.second` is super-hard to read



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:125
+// Keeps index to symbol in SymsStorage.
+llvm::DenseMap Merged;
 for (const auto &Slab : SymbolSlabs) {

Could we avoid changing the merge logic?
I.e. the proposal is to keep the merging code the same and add a loop that 
counts references at the end.



Comment at: clang-tools-extra/clangd/index/FileIndex.h:60
+///
+/// Will count Symbol::References based on number of references in the main
+/// files, while building the index with DuplicateHandling::Merge option.

NIT: this comment seems more appropriate at `buildIndex`, maybe move it there?
(It has the `DuplicateHandle` parameter, so it's closer to the context.



Comment at: clang-tools-extra/clangd/index/FileIndex.h:66
   /// If either is nullptr, corresponding data for \p Path will be removed.
+  /// If IsMainFile is true, Refs will be used for counting References during
+  /// merging.

Maybe call the parameter `CountReferences`?
It would narrow down what the code can do with it and make the code easier to 
understand



Comment at: clang-tools-extra/clangd/unittests/FileIndexTests.cpp:49
+MATCHER_P(NumReferences, N, "") {
+  return arg.References == static_cast(N);
+}

NIT: to avoid warnings, we could use the corresponding suffix at the callsite 
(e.g. `1u`) instead of casts
It's probably ok either way here, but having casts can lead to surprises if one 
passes negative numbers there


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59481



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


[PATCH] D61487: [clang-tidy] Make the plugin honor NOLINT

2019-05-08 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik updated this revision to Diff 198637.
nik added a comment.

The plugin makes use of ClangTidyDiagnosticConsumer and forwards diagnostics to
the external diagnostic engine.

@alexfh: What do you think? If that looks roughly OK for you, I'll finish it.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61487

Files:
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tidy/plugin/ClangTidyPlugin.cpp
  test/clang-tidy/nolint-plugin.cpp
  test/clang-tidy/nolintnextline-plugin.cpp

Index: test/clang-tidy/nolintnextline-plugin.cpp
===
--- /dev/null
+++ test/clang-tidy/nolintnextline-plugin.cpp
@@ -0,0 +1,47 @@
+class A { A(int i); };
+// CHECK: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+// NOLINTNEXTLINE
+class B { B(int i); };
+
+// NOLINTNEXTLINE(for-some-other-check)
+class C { C(int i); };
+// CHECK: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+// NOLINTNEXTLINE(*)
+class C1 { C1(int i); };
+
+// NOLINTNEXTLINE(not-closed-bracket-is-treated-as-skip-all
+class C2 { C2(int i); };
+
+// NOLINTNEXTLINE(google-explicit-constructor)
+class C3 { C3(int i); };
+
+// NOLINTNEXTLINE(some-check, google-explicit-constructor)
+class C4 { C4(int i); };
+
+// NOLINTNEXTLINE without-brackets-skip-all, another-check
+class C5 { C5(int i); };
+
+
+// NOLINTNEXTLINE
+
+class D { D(int i); };
+// CHECK: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+// NOLINTNEXTLINE
+//
+class E { E(int i); };
+// CHECK: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+#define MACRO(X) class X { X(int i); };
+MACRO(F)
+// CHECK: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit
+// NOLINTNEXTLINE
+MACRO(G)
+
+#define MACRO_NOARG class H { H(int i); };
+// NOLINTNEXTLINE
+MACRO_NOARG
+
+// RUN: c-index-test -test-load-source-reparse 2 all %s -Xclang -add-plugin -Xclang clang-tidy -Xclang -plugin-arg-clang-tidy -Xclang -checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
Index: test/clang-tidy/nolint-plugin.cpp
===
--- /dev/null
+++ test/clang-tidy/nolint-plugin.cpp
@@ -0,0 +1,50 @@
+// REQUIRES: static-analyzer
+// RUN: c-index-test -test-load-source-reparse 2 all %s -Xclang -add-plugin -Xclang clang-tidy -Xclang -plugin-arg-clang-tidy -Xclang -checks='-*,google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult' -Wunused-variable -I%S/Inputs/nolint 2>&1 | FileCheck %s
+
+#include "trigger_warning.h"
+void I(int& Out) {
+  int In;
+  A1(In, Out);
+}
+// CHECK-NOT: trigger_warning.h:{{.*}} warning
+// CHECK-NOT: :[[@LINE-4]]:{{.*}} note
+
+class A { A(int i); };
+// CHECK-DAG: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+class B { B(int i); }; // NOLINT
+
+class C { C(int i); }; // NOLINT(for-some-other-check)
+// CHECK-DAG: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+class C1 { C1(int i); }; // NOLINT(*)
+
+class C2 { C2(int i); }; // NOLINT(not-closed-bracket-is-treated-as-skip-all
+
+class C3 { C3(int i); }; // NOLINT(google-explicit-constructor)
+
+class C4 { C4(int i); }; // NOLINT(some-check, google-explicit-constructor)
+
+class C5 { C5(int i); }; // NOLINT without-brackets-skip-all, another-check
+
+void f() {
+  int i;
+// CHECK-DAG: :[[@LINE-1]]:7: warning: unused variable 'i' [-Wunused-variable]
+//  31:7: warning: unused variable 'i' [-Wunused-variable]
+//  int j; // NOLINT
+//  int k; // NOLINT(clang-diagnostic-unused-variable)
+}
+
+#define MACRO(X) class X { X(int i); };
+MACRO(D)
+// CHECK-DAG: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit
+MACRO(E) // NOLINT
+
+#define MACRO_NOARG class F { F(int i); };
+MACRO_NOARG // NOLINT
+
+#define MACRO_NOLINT class G { G(int i); }; // NOLINT
+MACRO_NOLINT
+
+#define DOUBLE_MACRO MACRO(H) // NOLINT
+DOUBLE_MACRO
Index: clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "../ClangTidy.h"
+#include "../ClangTidyDiagnosticConsumer.h"
 #include "../ClangTidyForceLinker.h"
 #include "../ClangTidyModule.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -33,8 +34,13 @@
 public:
   std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler,
  StringRef File) override {
-// Insert the current diagnostics engine.
-Context->setDiagnosticsEngine(&Compiler.getDiagnostics());
+// Create a

r360249 - [libclang] PR41649: Remove pointless duplicate flag. NFC.

2019-05-08 Thread Nikolai Kosjar via cfe-commits
Author: nik
Date: Wed May  8 06:19:29 2019
New Revision: 360249

URL: http://llvm.org/viewvc/llvm-project?rev=360249&view=rev
Log:
[libclang] PR41649: Remove pointless duplicate flag. NFC.

Modified:
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=360249&r1=360248&r2=360249&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed May  8 06:19:29 2019
@@ -7249,15 +7249,14 @@ void AnnotateTokensWorker::HandlePostPon
 
 void AnnotateTokensWorker::HandlePostPonedChildCursor(
 CXCursor Cursor, unsigned StartTokenIndex) {
-  const auto flags = CXNameRange_WantQualifier | CXNameRange_WantQualifier;
   unsigned I = StartTokenIndex;
 
   // The bracket tokens of a Call or Subscript operator are mapped to
   // CallExpr/CXXOperatorCallExpr because we skipped visiting the corresponding
   // DeclRefExpr. Remap these tokens to the DeclRefExpr cursors.
   for (unsigned RefNameRangeNr = 0; I < NumTokens; RefNameRangeNr++) {
-const CXSourceRange CXRefNameRange =
-clang_getCursorReferenceNameRange(Cursor, flags, RefNameRangeNr);
+const CXSourceRange CXRefNameRange = clang_getCursorReferenceNameRange(
+Cursor, CXNameRange_WantQualifier, RefNameRangeNr);
 if (clang_Range_isNull(CXRefNameRange))
   break; // All ranges handled.
 


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


r360250 - Allow 'static' storage specifier on an out-of-line class member template declaration in MSVCCompat mode.

2019-05-08 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed May  8 06:24:36 2019
New Revision: 360250

URL: http://llvm.org/viewvc/llvm-project?rev=360250&view=rev
Log:
Allow 'static' storage specifier on an out-of-line class member template 
declaration in MSVCCompat mode.

Patch by Soumi Manna.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=360250&r1=360249&r2=360250&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May  8 06:24:36 2019
@@ -8673,9 +8673,12 @@ Sema::ActOnFunctionDeclarator(Scope *S,
   // member function definition.
 
   // MSVC permits the use of a 'static' storage specifier on an out-of-line
-  // member function template declaration, warn about this.
+  // member function template declaration and class member template
+  // declaration (MSVC versions before 2015), warn about this.
   Diag(D.getDeclSpec().getStorageClassSpecLoc(),
-   NewFD->getDescribedFunctionTemplate() && getLangOpts().MSVCCompat
+   ((!getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015) &&
+ cast(DC)->getDescribedClassTemplate()) ||
+   (getLangOpts().MSVCCompat && NewFD->getDescribedFunctionTemplate()))
? diag::ext_static_out_of_line : diag::err_static_out_of_line)
 << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc());
 }

Modified: cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp?rev=360250&r1=360249&r2=360250&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp Wed May  8 
06:24:36 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only 
-fms-compatibility-version=12.0 -verify %s
 
 struct C {
   template  static int foo(T);
@@ -9,3 +10,13 @@ template  static int C::foo(
   return 0;
 }
 
+template  struct S { 
+  void f();
+};
+
+template  static void S::f() {}
+#if _MSC_VER >= 1900
+  //expected-error@-2 {{'static' can only be specified inside the class 
definition}}
+#else
+  //expected-warning@-4 {{'static' can only be specified inside the class 
definition}}
+#endif


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


[PATCH] D52967: Extend shelf-life by 70 years

2019-05-08 Thread Bernhard M. Wiedemann via Phabricator via cfe-commits
bmwiedemann accepted this revision.
bmwiedemann added a comment.
Herald added a subscriber: dexonsmith.
Herald added a project: clang.

Can someone please merge this change?


Repository:
  rC Clang

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

https://reviews.llvm.org/D52967



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


r360254 - Allow test to pass after 2030.

2019-05-08 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed May  8 06:42:44 2019
New Revision: 360254

URL: http://llvm.org/viewvc/llvm-project?rev=360254&view=rev
Log:
Allow test to pass after 2030.

Patch by Bernhard M. Wiedemann.

Modified:
cfe/trunk/test/Modules/fmodules-validate-once-per-build-session.c

Modified: cfe/trunk/test/Modules/fmodules-validate-once-per-build-session.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/fmodules-validate-once-per-build-session.c?rev=360254&r1=360253&r2=360254&view=diff
==
--- cfe/trunk/test/Modules/fmodules-validate-once-per-build-session.c (original)
+++ cfe/trunk/test/Modules/fmodules-validate-once-per-build-session.c Wed May  
8 06:42:44 2019
@@ -51,8 +51,8 @@
 // RUN: not diff %t/modules-to-compare/Foo-before-user.pcm 
%t/modules-to-compare/Foo-after-user.pcm
 
 // ===
-// Recompile the module if the today's date is before 01 January 2030.
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fbuild-session-timestamp=1893456000 -fmodules-validate-once-per-build-session 
%s
+// Recompile the module if the today's date is before 01 January 2100.
+// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fbuild-session-timestamp=4102441200 -fmodules-validate-once-per-build-session 
%s
 // RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
 // RUN: cp %t/modules-cache/Foo.pcm %t/modules-to-compare/Foo-after.pcm
 


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


[PATCH] D52967: Extend shelf-life by 70 years

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

In D52967#1494969 , @bmwiedemann wrote:

> Can someone please merge this change?


I commit the change in r360254, thank you for the patch!


Repository:
  rC Clang

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

https://reviews.llvm.org/D52967



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


r360256 - [clang] Fix a bug that reports UTF32 (LE) files as UTF16 (LE) ones

2019-05-08 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Wed May  8 06:49:17 2019
New Revision: 360256

URL: http://llvm.org/viewvc/llvm-project?rev=360256&view=rev
Log:
[clang] Fix a bug that reports UTF32 (LE) files as UTF16 (LE) ones

Also fix a typo for the SCSU byte order mark.

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

Modified:
cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=360256&r1=360255&r2=360256&view=diff
==
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Wed May  8 06:49:17 2019
@@ -167,16 +167,16 @@ const llvm::MemoryBuffer *ContentCache::
   // http://en.wikipedia.org/wiki/Byte_order_mark for more information.
   StringRef BufStr = Buffer.getPointer()->getBuffer();
   const char *InvalidBOM = llvm::StringSwitch(BufStr)
-.StartsWith("\xFE\xFF", "UTF-16 (BE)")
-.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
   "UTF-32 (BE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
   "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith("\x2B\x2F\x76", "UTF-7")
 .StartsWith("\xF7\x64\x4C", "UTF-1")
 .StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
-.StartsWith("\x0E\xFE\xFF", "SDSU")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
 .StartsWith("\xFB\xEE\x28", "BOCU-1")
 .StartsWith("\x84\x31\x95\x33", "GB-18030")
 .Default(nullptr);


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


[PATCH] D61628: Fix a bug that reports UTF16 (LE) files as UTF32 (LE) ones

2019-05-08 Thread Owen Pan via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360256: [clang] Fix a bug that reports UTF32 (LE) files as 
UTF16 (LE) ones (authored by owenpan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61628?vs=198404&id=198641#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61628

Files:
  cfe/trunk/lib/Basic/SourceManager.cpp


Index: cfe/trunk/lib/Basic/SourceManager.cpp
===
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -167,16 +167,16 @@
   // http://en.wikipedia.org/wiki/Byte_order_mark for more information.
   StringRef BufStr = Buffer.getPointer()->getBuffer();
   const char *InvalidBOM = llvm::StringSwitch(BufStr)
-.StartsWith("\xFE\xFF", "UTF-16 (BE)")
-.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
   "UTF-32 (BE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
   "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith("\x2B\x2F\x76", "UTF-7")
 .StartsWith("\xF7\x64\x4C", "UTF-1")
 .StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
-.StartsWith("\x0E\xFE\xFF", "SDSU")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
 .StartsWith("\xFB\xEE\x28", "BOCU-1")
 .StartsWith("\x84\x31\x95\x33", "GB-18030")
 .Default(nullptr);


Index: cfe/trunk/lib/Basic/SourceManager.cpp
===
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -167,16 +167,16 @@
   // http://en.wikipedia.org/wiki/Byte_order_mark for more information.
   StringRef BufStr = Buffer.getPointer()->getBuffer();
   const char *InvalidBOM = llvm::StringSwitch(BufStr)
-.StartsWith("\xFE\xFF", "UTF-16 (BE)")
-.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
   "UTF-32 (BE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
   "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith("\x2B\x2F\x76", "UTF-7")
 .StartsWith("\xF7\x64\x4C", "UTF-1")
 .StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
-.StartsWith("\x0E\xFE\xFF", "SDSU")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
 .StartsWith("\xFB\xEE\x28", "BOCU-1")
 .StartsWith("\x84\x31\x95\x33", "GB-18030")
 .Default(nullptr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60672: [libclang] visit c++14 lambda capture init expressions

2019-05-08 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added a comment.

Tests do not pass on current trunk:

  /d2/llvm/trunk/builds/DebugShared % bin/llvm-lit -a 
/d2/llvm/trunk/source/tools/clang/test/Index/cxx14-lambdas.cpp
  llvm-lit: /d2/llvm/trunk/source/utils/lit/lit/llvm/config.py:341: note: using 
clang: /d2/llvm/trunk/builds/DebugShared/bin/clang
  -- Testing: 1 tests, single process --
  FAIL: Clang :: Index/cxx14-lambdas.cpp (1 of 1)
   TEST 'Clang :: Index/cxx14-lambdas.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 13';   /d2/llvm/trunk/builds/DebugShared/bin/c-index-test 
-test-load-source all -std=c++14 
/d2/llvm/trunk/source/tools/clang/test/Index/cxx14-lambdas.cpp | 
/d2/llvm/trunk/builds/DebugShared/bin/FileCheck -check-prefix=CHECK-LOAD 
/d2/llvm/trunk/source/tools/clang/test/Index/cxx14-lambdas.cpp
  : 'RUN: at line 30';   env CINDEXTEST_INDEXLOCALSYMBOLS=1 
/d2/llvm/trunk/builds/DebugShared/bin/c-index-test -index-file -std=c++14 
/d2/llvm/trunk/source/tools/clang/test/Index/cxx14-lambdas.cpp | 
/d2/llvm/trunk/builds/DebugShared/bin/FileCheck -check-prefix=CHECK-INDEX 
/d2/llvm/trunk/source/tools/clang/test/Index/cxx14-lambdas.cpp
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  /d2/llvm/trunk/source/tools/clang/test/Index/cxx14-lambdas.cpp:22:16: error: 
CHECK-LOAD: expected string not found in input
  // CHECK-LOAD: cxx14-lambdas.cpp:7:27: DeclRefExpr=localA:6:9 Extent=[7:27 - 
7:33]
 ^
  :390:1: note: scanning from here
  // CHECK: cxx14-lambdas.cpp:7:59: ParmDecl=x:7:59 (Definition) Extent=[7:51 - 
7:60]
  ^
  :402:11: note: possible intended match here
  // CHECK: cxx14-lambdas.cpp:8:21: DeclRefExpr=copy:7:35 Extent=[8:21 - 8:25]
^
  
  --
  
  
  Testing Time: 0.13s
  
  Failing Tests (1):
  Clang :: Index/cxx14-lambdas.cpp
  
Unexpected Failures: 1
  zsh: exit 1 bin/llvm-lit -a 
/d2/llvm/trunk/source/tools/clang/test/Index/cxx14-lambdas.cp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60672



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


[PATCH] D61559: Fix the crash when formatting unsupported encodings

2019-05-08 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 198652.
owenpan added a comment.

Fixed the typo for SCSU.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61559

Files:
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -257,6 +257,36 @@
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
+  // for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -257,6 +257,36 @@
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
+  // for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53866: [Preamble] Stop circular inclusion of main file when building preamble

2019-05-08 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik updated this revision to Diff 198654.
nik edited the summary of this revision.
nik added a comment.

Rebased for current trunk.

If I miss something obvious, please tell me. Otherwise I'm waiting.


Repository:
  rC Clang

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

https://reviews.llvm.org/D53866

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  lib/Basic/SourceManager.cpp
  lib/Lex/PPDirectives.cpp
  test/Index/preamble-cyclic-include.cpp


Index: test/Index/preamble-cyclic-include.cpp
===
--- /dev/null
+++ test/Index/preamble-cyclic-include.cpp
@@ -0,0 +1,9 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test 
-test-annotate-tokens=%s:5:1:10:1 %s 2>&1 | FileCheck %s
+// CHECK-NOT: error: unterminated conditional directive
+// CHECK-NOT: Skipping: [4:1 - 8:7]
+// CHECK: error: main file cannot be included recursively when building a 
preamble
+#ifndef A_H
+#define A_H
+#  include "preamble-cyclic-include.cpp"
+int bar();
+#endif
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1871,6 +1871,18 @@
 return {ImportAction::None};
   }
 
+  // Check for circular inclusion of the main file.
+  // We can't generate a consistent preamble with regard to the conditional
+  // stack if the main file is included again as due to the preamble bounds
+  // some directives (e.g. #endif of a header guard) will never be seen.
+  // Since this will lead to confusing errors, avoid the inclusion.
+  if (File && PreambleConditionalStack.isRecording() &&
+  SourceMgr.translateFile(File) == SourceMgr.getMainFileID()) {
+Diag(FilenameTok.getLocation(),
+ diag::err_pp_including_mainfile_for_preamble);
+return {ImportAction::None};
+  }
+
   // Should we enter the source file? Set to Skip if either the source file is
   // known to have no effect beyond its effect on module visibility -- that is,
   // if it's got an include guard that is already defined, set to Import if it
Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1591,7 +1591,7 @@
 // as the main file.
 const FileEntry *MainFile = MainContentCache->OrigEntry;
 SourceFileName = llvm::sys::path::filename(SourceFile->getName());
-if (*SourceFileName == llvm::sys::path::filename(MainFile->getName())) 
{
+if (MainFile && *SourceFileName == 
llvm::sys::path::filename(MainFile->getName())) {
   SourceFileUID = getActualFileUID(SourceFile);
   if (SourceFileUID) {
 if (Optional MainFileUID =
Index: include/clang/Basic/DiagnosticLexKinds.td
===
--- include/clang/Basic/DiagnosticLexKinds.td
+++ include/clang/Basic/DiagnosticLexKinds.td
@@ -426,6 +426,8 @@
   "did not find header '%0' in framework '%1' (loaded from '%2')">;
 def err_pp_error_opening_file : Error<
   "error opening file '%0': %1">, DefaultFatal;
+def err_pp_including_mainfile_for_preamble : Error<
+  "main file cannot be included recursively when building a preamble">;
 def err_pp_empty_filename : Error<"empty filename">;
 def err_pp_include_too_deep : Error<"#include nested too deeply">;
 def err_pp_expects_filename : Error<"expected \"FILENAME\" or ">;


Index: test/Index/preamble-cyclic-include.cpp
===
--- /dev/null
+++ test/Index/preamble-cyclic-include.cpp
@@ -0,0 +1,9 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-annotate-tokens=%s:5:1:10:1 %s 2>&1 | FileCheck %s
+// CHECK-NOT: error: unterminated conditional directive
+// CHECK-NOT: Skipping: [4:1 - 8:7]
+// CHECK: error: main file cannot be included recursively when building a preamble
+#ifndef A_H
+#define A_H
+#  include "preamble-cyclic-include.cpp"
+int bar();
+#endif
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1871,6 +1871,18 @@
 return {ImportAction::None};
   }
 
+  // Check for circular inclusion of the main file.
+  // We can't generate a consistent preamble with regard to the conditional
+  // stack if the main file is included again as due to the preamble bounds
+  // some directives (e.g. #endif of a header guard) will never be seen.
+  // Since this will lead to confusing errors, avoid the inclusion.
+  if (File && PreambleConditionalStack.isRecording() &&
+  SourceMgr.translateFile(File) == SourceMgr.getMainFileID()) {
+Diag(FilenameTok.getLocation(),
+ diag::err_pp_including_mainfile_for_preamble);
+return {ImportAction::None};
+  }
+
   // Should we enter the source file? Set to Skip if either the source file is
   // known to have no effect beyond its effect

[PATCH] D61559: Fix the crash when formatting unsupported encodings

2019-05-08 Thread Owen Pan via Phabricator via cfe-commits
owenpan marked an inline comment as done.
owenpan added inline comments.



Comment at: clang/tools/clang-format/ClangFormat.cpp:273
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")

sammccall wrote:
> Seems unlikely we'll ever see any of these other than UTF{16,32}.
> I'd suggest dropping them, but up to you.
I will keep the rare BOM cases to keep it in sync with D61628.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61559



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


r360257 - [clang-format] Fix the crash when formatting unsupported encodings

2019-05-08 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Wed May  8 07:11:12 2019
New Revision: 360257

URL: http://llvm.org/viewvc/llvm-project?rev=360257&view=rev
Log:
[clang-format] Fix the crash when formatting unsupported encodings

Fixes PR33946

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

Modified:
cfe/trunk/tools/clang-format/ClangFormat.cpp

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=360257&r1=360256&r2=360257&view=diff
==
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Wed May  8 07:11:12 2019
@@ -257,6 +257,36 @@ static bool format(StringRef FileName) {
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
+  // for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;


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


[PATCH] D61559: Fix the crash when formatting unsupported encodings

2019-05-08 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360257: [clang-format] Fix the crash when formatting 
unsupported encodings (authored by owenpan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61559?vs=198652&id=198655#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61559

Files:
  cfe/trunk/tools/clang-format/ClangFormat.cpp


Index: cfe/trunk/tools/clang-format/ClangFormat.cpp
===
--- cfe/trunk/tools/clang-format/ClangFormat.cpp
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp
@@ -257,6 +257,36 @@
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
+  // for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;


Index: cfe/trunk/tools/clang-format/ClangFormat.cpp
===
--- cfe/trunk/tools/clang-format/ClangFormat.cpp
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp
@@ -257,6 +257,36 @@
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
+  // for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53866: [Preamble] Stop circular inclusion of main file when building preamble

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Sorry for losing this.
Neat change, minimal and focused, thanks!

Just wanted to clarify why we need the change in `SourceManager.cpp`, will LGTM 
as soon as we resolve this




Comment at: lib/Basic/SourceManager.cpp:1594
 SourceFileName = llvm::sys::path::filename(SourceFile->getName());
-if (*SourceFileName == llvm::sys::path::filename(MainFile->getName())) 
{
+if (MainFile && *SourceFileName == 
llvm::sys::path::filename(MainFile->getName())) {
   SourceFileUID = getActualFileUID(SourceFile);

Can this actually be`null`? 


Repository:
  rC Clang

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

https://reviews.llvm.org/D53866



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


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

2019-05-08 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik updated this revision to Diff 198656.
nik added a comment.
Herald added a subscriber: dexonsmith.

Minor diff update fixing indentation and removing not needed include.

Ping.


Repository:
  rC Clang

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

https://reviews.llvm.org/D41005

Files:
  include/clang/Frontend/ASTUnit.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/PrecompiledPreamble.cpp
  unittests/Frontend/PCHPreambleTest.cpp

Index: unittests/Frontend/PCHPreambleTest.cpp
===
--- unittests/Frontend/PCHPreambleTest.cpp
+++ unittests/Frontend/PCHPreambleTest.cpp
@@ -52,7 +52,10 @@
   FileSystemOptions FSOpts;
 
 public:
-  void SetUp() override {
+  void SetUp() override { ResetVFS(); }
+  void TearDown() override {}
+
+  void ResetVFS() {
 VFS = new ReadCountingInMemoryFileSystem();
 // We need the working directory to be set to something absolute,
 // otherwise it ends up being inadvertently set to the current
@@ -63,9 +66,6 @@
 VFS->setCurrentWorkingDirectory("//./");
   }
 
-  void TearDown() override {
-  }
-
   void AddFile(const std::string &Filename, const std::string &Contents) {
 ::time_t now;
 ::time(&now);
@@ -123,6 +123,72 @@
   }
 };
 
+TEST_F(PCHPreambleTest, ReparseReusesPreambleWithUnsavedFileNotExistingOnDisk) {
+  std::string Header1 = "//./header1.h";
+  std::string MainName = "//./main.cpp";
+  AddFile(MainName, R"cpp(
+#include "//./header1.h"
+int main() { return ZERO; }
+)cpp");
+  RemapFile(Header1, "#define ZERO 0\n");
+
+  // Parse with header file provided as unsaved file, which does not exist on
+  // disk.
+  std::unique_ptr AST(ParseAST(MainName));
+  ASSERT_TRUE(AST.get());
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  // Reparse and check that the preamble was reused.
+  ASSERT_TRUE(ReparseAST(AST));
+  ASSERT_EQ(AST->getPreambleCounterForTests(), 1U);
+}
+
+TEST_F(PCHPreambleTest, ReparseReusesPreambleAfterUnsavedFileWasCreatedOnDisk) {
+  std::string Header1 = "//./header1.h";
+  std::string MainName = "//./main.cpp";
+  AddFile(MainName, R"cpp(
+#include "//./header1.h"
+int main() { return ZERO; }
+)cpp");
+  RemapFile(Header1, "#define ZERO 0\n");
+
+  // Parse with header file provided as unsaved file, which does not exist on
+  // disk.
+  std::unique_ptr AST(ParseAST(MainName));
+  ASSERT_TRUE(AST.get());
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  // Create the unsaved file also on disk and check that preamble was reused.
+  AddFile(Header1, "#define ZERO 0\n");
+  ASSERT_TRUE(ReparseAST(AST));
+  ASSERT_EQ(AST->getPreambleCounterForTests(), 1U);
+}
+
+TEST_F(PCHPreambleTest,
+   ReparseReusesPreambleAfterUnsavedFileWasRemovedFromDisk) {
+  std::string Header1 = "//./foo/header1.h";
+  std::string MainName = "//./main.cpp";
+  std::string MainFileContent = R"cpp(
+#include "//./foo/header1.h"
+int main() { return ZERO; }
+)cpp";
+  AddFile(MainName, MainFileContent);
+  AddFile(Header1, "#define ZERO 0\n");
+  RemapFile(Header1, "#define ZERO 0\n");
+
+  // Parse with header file provided as unsaved file, which exists on disk.
+  std::unique_ptr AST(ParseAST(MainName));
+  ASSERT_TRUE(AST.get());
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+  ASSERT_EQ(AST->getPreambleCounterForTests(), 1U);
+
+  // Remove the unsaved file from disk and check that the preamble was reused.
+  ResetVFS();
+  AddFile(MainName, MainFileContent);
+  ASSERT_TRUE(ReparseAST(AST));
+  ASSERT_EQ(AST->getPreambleCounterForTests(), 1U);
+}
+
 TEST_F(PCHPreambleTest, ReparseWithOverriddenFileDoesNotInvalidatePreamble) {
   std::string Header1 = "//./header1.h";
   std::string Header2 = "//./header2.h";
Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -454,20 +454,32 @@
 Status.getSize(), llvm::sys::toTimeT(Status.getLastModificationTime()));
   }
 
+  llvm::StringMap OverridenFileBuffers;
   for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) {
-llvm::vfs::Status Status;
-if (!moveOnNoError(VFS->status(RB.first), Status))
-  return false;
-
-OverriddenFiles[Status.getUniqueID()] =
+const PrecompiledPreamble::PreambleFileHash PreambleHash =
 PreambleFileHash::createForMemoryBuffer(RB.second);
+llvm::vfs::Status Status;
+if (moveOnNoError(VFS->status(RB.first), Status))
+  OverriddenFiles[Status.getUniqueID()] = PreambleHash;
+else
+  OverridenFileBuffers[RB.first] = PreambleHash;
   }
 
   // Check whether anything has changed.
   for (const auto &F : FilesInPreamble) {
+auto OverridenFileBuffer = OverridenFileBuffers.find(F.first());
+if (OverridenFileBuffer != OverridenFileBuffers.end()) {
+  // The file's buffer was remapped; check whether it matches up
+  // with the previous mapping.
+  if (Overrid

r360258 - [Sema][OpenCL] Make address space conversions a bit stricter.

2019-05-08 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed May  8 07:23:49 2019
New Revision: 360258

URL: http://llvm.org/viewvc/llvm-project?rev=360258&view=rev
Log:
[Sema][OpenCL] Make address space conversions a bit stricter.

The semantics for converting nested pointers between address
spaces are not very well defined. Some conversions which do not
really carry any meaning only produce warnings, and in some cases
warnings hide invalid conversions, such as 'global int*' to
'local float*'!

This patch changes the logic in checkPointerTypesForAssignment
and checkAddressSpaceCast to fail properly on implicit conversions
that should definitely not be permitted. We also dig deeper into the
pointer types and warn on explicit conversions where the address
space in a nested pointer changes, regardless of whether the address
space is compatible with the corresponding pointer nesting level
on the destination type.

Fixes PR39674!

Patch by ebevhan (Bevin Hansson)!

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGenOpenCL/numbered-address-space.cl
cfe/trunk/test/SemaOpenCL/address-spaces.cl
cfe/trunk/test/SemaOpenCL/event_t_overload.cl
cfe/trunk/test/SemaOpenCL/numbered-address-space.cl
cfe/trunk/test/SemaOpenCL/queue_t_overload.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=360258&r1=360257&r2=360258&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May  8 07:23:49 
2019
@@ -7005,6 +7005,19 @@ def err_typecheck_incompatible_address_s
   "sending to parameter of different type}0,1"
   "|%diff{casting $ to type $|casting between types}0,1}2"
   " changes address space of pointer">;
+def err_typecheck_incompatible_nested_address_space : Error<
+  "%select{%diff{assigning $ to $|assigning to different types}1,0"
+  "|%diff{passing $ to parameter of type $|"
+  "passing to parameter of different type}0,1"
+  "|%diff{returning $ from a function with result type $|"
+  "returning from function with different return type}0,1"
+  "|%diff{converting $ to type $|converting between types}0,1"
+  "|%diff{initializing $ with an expression of type $|"
+  "initializing with expression of different type}0,1"
+  "|%diff{sending $ to parameter of type $|"
+  "sending to parameter of different type}0,1"
+  "|%diff{casting $ to type $|casting between types}0,1}2"
+  " changes address space of nested pointer">;
 def err_typecheck_incompatible_ownership : Error<
   "%select{%diff{assigning $ to $|assigning to different types}1,0"
   "|%diff{passing $ to parameter of type $|"

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=360258&r1=360257&r2=360258&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed May  8 07:23:49 2019
@@ -9726,6 +9726,12 @@ public:
 /// like address spaces.
 IncompatiblePointerDiscardsQualifiers,
 
+/// IncompatibleNestedPointerAddressSpaceMismatch - The assignment
+/// changes address spaces in nested pointer types which is not allowed.
+/// For instance, converting __private int ** to __generic int ** is
+/// illegal even though __private could be converted to __generic.
+IncompatibleNestedPointerAddressSpaceMismatch,
+
 /// IncompatibleNestedPointerQualifiers - The assignment is between two
 /// nested pointer types, and the qualifiers other than the first two
 /// levels differ e.g. char ** -> const char **, but we accept them as an

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=360258&r1=360257&r2=360258&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Wed May  8 07:23:49 2019
@@ -2323,19 +2323,41 @@ void CastOperation::checkAddressSpaceCas
   // In OpenCL only conversions between pointers to objects in overlapping
   // addr spaces are allowed. v2.0 s6.5.5 - Generic addr space overlaps
   // with any named one, except for constant.
+
+  // Converting the top level pointee addrspace is permitted for compatible
+  // addrspaces (such as 'generic int *' to 'local int *' or vice versa), but
+  // if any of the nested pointee addrspaces differ, we emit a warning
+  // regardless of addrspace compatibility. This makes
+  //   local int ** p;
+  //   return (generic int **) p;
+  // warn even though loc

[PATCH] D58236: Make address space conversions a bit stricter.

2019-05-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360258: [Sema][OpenCL] Make address space conversions a bit 
stricter. (authored by stulova, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58236?vs=195520&id=198657#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58236

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaCast.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/CodeGenOpenCL/numbered-address-space.cl
  cfe/trunk/test/SemaOpenCL/address-spaces.cl
  cfe/trunk/test/SemaOpenCL/event_t_overload.cl
  cfe/trunk/test/SemaOpenCL/numbered-address-space.cl
  cfe/trunk/test/SemaOpenCL/queue_t_overload.cl

Index: cfe/trunk/test/SemaOpenCL/numbered-address-space.cl
===
--- cfe/trunk/test/SemaOpenCL/numbered-address-space.cl
+++ cfe/trunk/test/SemaOpenCL/numbered-address-space.cl
@@ -26,6 +26,6 @@
 
 void test_generic_as_to_builtin_parameterimplicit_cast_numeric(__attribute__((address_space(3))) int *as3_ptr, float src) {
   generic int* generic_ptr = as3_ptr;
-  volatile float result = __builtin_amdgcn_ds_fmaxf(generic_ptr, src, 0, 0, false); // expected-warning {{incompatible pointer types passing '__generic int *' to parameter of type '__local float *'}}
+  volatile float result = __builtin_amdgcn_ds_fmaxf(generic_ptr, src, 0, 0, false); // expected-error {{passing '__generic int *' to parameter of type '__local float *' changes address space of pointer}}
 }
 
Index: cfe/trunk/test/SemaOpenCL/queue_t_overload.cl
===
--- cfe/trunk/test/SemaOpenCL/queue_t_overload.cl
+++ cfe/trunk/test/SemaOpenCL/queue_t_overload.cl
@@ -7,6 +7,6 @@
   queue_t q;
   foo(q, src1);
   foo(0, src2);
-  foo(q, src3); // expected-error {{call to 'foo' is ambiguous}}
+  foo(q, src3); // expected-error {{no matching function for call to 'foo'}}
   foo(1, src3); // expected-error {{no matching function for call to 'foo'}}
 }
Index: cfe/trunk/test/SemaOpenCL/address-spaces.cl
===
--- cfe/trunk/test/SemaOpenCL/address-spaces.cl
+++ cfe/trunk/test/SemaOpenCL/address-spaces.cl
@@ -124,6 +124,106 @@
   p = (__private int *)p2;
 }
 
+#if !__OPENCL_CPP_VERSION__
+void nested(__global int *g, __global int * __private *gg, __local int *l, __local int * __private *ll, __global float * __private *gg_f) {
+  g = gg;// expected-error {{assigning '__global int **' to '__global int *' changes address space of pointer}}
+  g = l; // expected-error {{assigning '__local int *' to '__global int *' changes address space of pointer}}
+  g = ll;// expected-error {{assigning '__local int **' to '__global int *' changes address space of pointer}}
+  g = gg_f;  // expected-error {{assigning '__global float **' to '__global int *' changes address space of pointer}}
+  g = (__global int *)gg_f; // expected-error {{casting '__global float **' to type '__global int *' changes address space of pointer}}
+
+  gg = g;// expected-error {{assigning '__global int *' to '__global int **' changes address space of pointer}}
+  gg = l;// expected-error {{assigning '__local int *' to '__global int **' changes address space of pointer}}
+  gg = ll;   // expected-error {{assigning '__local int **' to '__global int **' changes address space of nested pointer}}
+  gg = gg_f; // expected-warning {{incompatible pointer types assigning to '__global int **' from '__global float **'}}
+  gg = (__global int * __private *)gg_f;
+
+  l = g; // expected-error {{assigning '__global int *' to '__local int *' changes address space of pointer}}
+  l = gg;// expected-error {{assigning '__global int **' to '__local int *' changes address space of pointer}}
+  l = ll;// expected-error {{assigning '__local int **' to '__local int *' changes address space of pointer}}
+  l = gg_f;  // expected-error {{assigning '__global float **' to '__local int *' changes address space of pointer}}
+  l = (__local int *)gg_f; // expected-error {{casting '__global float **' to type '__local int *' changes address space of pointer}}
+
+  ll = g;// expected-error {{assigning '__global int *' to '__local int **' changes address space of pointer}}
+  ll = gg;   // expected-error {{assigning '__global int **' to '__local int **' changes address space of nested pointer}}
+  ll = l;// expected-error {{assigning '__local int *' to '__local int **' changes address space of pointer}}
+  ll = gg_f; // expected-error {{assigning '__global float **' to '__local int **' changes address space of nested pointer}}
+  ll = (__local int * __private *)gg_f; // expected-warning {{casting '__global float **' to type '__l

[PATCH] D61681: [clangd] A code tweak to expand a macro

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, mgorny.
Herald added a project: clang.
ilya-biryukov added a parent revision: D59887: [Syntax] Introduce TokenBuffer, 
start clangToolingSyntax library.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61681

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/ClangdUnit.h
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -38,6 +38,27 @@
   assert(!T.isAnnotation());
 }
 
+llvm::Optional syntax::Token::range(const SourceManager &SM) const {
+  if (!location().isFileID())
+return llvm::None;
+
+  FileRange R;
+  std::tie(R.File, R.Begin) = SM.getDecomposedLoc(location());
+  R.End = R.Begin + length();
+  return R;
+}
+
+llvm::Optional syntax::Token::range(const SourceManager &SM,
+   const syntax::Token &First,
+   const syntax::Token &Last) {
+  auto F = First.range(SM);
+  auto L = Last.range(SM);
+  if (!F || !L || F->File != L->File || L->Begin < F->Begin)
+return llvm::None;
+  F->End = L->End;
+  return F;
+}
+
 llvm::StringRef syntax::Token::text(const SourceManager &SM) const {
   bool Invalid = false;
   const char *Start = SM.getCharacterData(location(), &Invalid);
@@ -167,6 +188,32 @@
   : LastSpelled + 1);
 }
 
+llvm::Optional
+TokenBuffer::findExpansion(const syntax::Token *Spelled) const {
+  assert(Spelled);
+  assert(Spelled->location().isFileID() && "not a spelled token");
+  auto FileIt = Files.find(SourceMgr->getFileID(Spelled->location()));
+  assert(FileIt != Files.end());
+
+  auto &File = FileIt->second;
+  assert(File.SpelledTokens.data() <= Spelled &&
+ Spelled < (File.SpelledTokens.data() + File.SpelledTokens.size()));
+
+  unsigned SpelledI = Spelled - File.SpelledTokens.data();
+  auto M = llvm::bsearch(File.Mappings, [&](const Mapping &M) {
+return SpelledI <= M.BeginSpelled;
+  });
+  if (M == File.Mappings.end() || M->BeginSpelled != SpelledI)
+return llvm::None;
+
+  Expansion E;
+  E.Spelled = llvm::makeArrayRef(File.SpelledTokens.data() + M->BeginSpelled,
+ File.SpelledTokens.data() + M->EndSpelled);
+  E.Expanded = llvm::makeArrayRef(ExpandedTokens.data() + M->BeginExpanded,
+  ExpandedTokens.data() + M->EndExpanded);
+  return E;
+}
+
 std::vector syntax::tokenize(FileID FID, const SourceManager &SM,
 const LangOptions &LO) {
   std::vector Tokens;
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -46,6 +46,31 @@
 
 namespace syntax {
 
+/// A half-open range inside a particular file, the start offset is included and
+/// the end offset is excluded from the range.
+struct FileRange {
+  FileID File;
+  /// Start offset (inclusive) in a corresponding file.
+  unsigned Begin = 0;
+  /// End offset (exclusive) in a corresponding file.
+  unsigned End = 0;
+
+  unsigned length() const { return End - Begin; }
+  bool contains(unsigned Offset) const {
+return Begin <= Offset && Offset < End;
+  }
+  /// Gets the substring that this FileRange refers to.
+  llvm::StringRef text(const SourceManager &SM) const;
+};
+inline bool operator==(const FileRange &L, const FileRange &R) {
+  return std::tie(L.File, L.Begin, L.End) == std::tie(R.File, R.Begin, R.End);
+}
+inline bool operator!=(const FileRange &L, const FileRange &R) {
+  return !(L == R);
+}
+/// For debugging purposes.
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FileRange &R);
+
 /// A token coming directly from a file or from a macro invocation. Has just
 /// enough information to locate the token in the source code.
 /// Can represent both expanded and spelled tokens.
@@ -65,6 +90,18 @@
   }
   unsigned length() const { return Length; }
 
+  /// Gets a range of this token. Returns llvm::None for tokens from a macro
+  /// expansion.
+  llvm::Optional range(const SourceManager &SM) const;
+
+  /// Given two tokens inside the same file, returns a file range that starts at
+  /// \p First and ends at \p Last.
+  /// Returns llvm::None if any of the tokens is from a macro expansion, tokens
+  /// 

[PATCH] D61681: [clangd] A code tweak to expand a macro

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This actually works, but still far from landing.
Notable problems:

- this adds a dependency on `TokenBuffer`, so we need to land it first.
- this change is too big, planning to split into multiple changes: (1) 
collecting tokens when building the AST for clangd, (2) add helpers into 
`TokenBuffer`
- it currently tries to replace any "mapping", not just preprocessor 
expansions. E.g. will attempt to replace `#define FOO ...` with an empty string.
- needs more tests.

Will get back to it after `TokenBuffer` lands.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61681



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


[PATCH] D61667: Assume `__cxa_allocate_exception` returns an under-aligned memory on Darwin if the version of libc++abi isn't new enough to include the fix in r319123

2019-05-08 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: include/clang/Basic/AlignedExceptionObject.h:15
+
+#ifndef LLVM_CLANG_BASIC_ALIGNED_ALLOCATION_H
+#define LLVM_CLANG_BASIC_ALIGNED_ALLOCATION_H

The guards look wrong.



Comment at: include/clang/Basic/AlignedExceptionObject.h:31
+  case llvm::Triple::MacOSX: // Earliest supporting version is 10.14.
+return llvm::VersionTuple(10U, 14U);
+  case llvm::Triple::IOS:

Would it make more sense to return the alignment directly here?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61667



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


[PATCH] D61475: Update an information about ReSharper C++ and clang-tidy custom binary integration

2019-05-08 Thread Alexander Zaitsev via Phabricator via cfe-commits
ZaMaZaN4iK added a subscriber: Szelethus.
ZaMaZaN4iK added a comment.

@JonasToth @NoQ @Szelethus can anyone merge it?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61475



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


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

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Again, sorry for the delay. This looks good, just a few NITs from me before I 
stamp it




Comment at: lib/Frontend/PrecompiledPreamble.cpp:457
 
+  llvm::StringMap OverridenFileBuffers;
   for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) {

Could you add a comment that this contains only the files there were not found 
on disk (i.e. the vfs call failed and we couldn't get a `UniqueID`)



Comment at: lib/Frontend/PrecompiledPreamble.cpp:472
+if (OverridenFileBuffer != OverridenFileBuffers.end()) {
+  // The file's buffer was remapped; check whether it matches up
+  // with the previous mapping.

NIT: change to: The file's buffer was remapped **and the file was not found in 
VFS**


Repository:
  rC Clang

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

https://reviews.llvm.org/D41005



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


[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 198662.
ilya-biryukov added a comment.
Herald added subscribers: jsji, kbarton, nemanjai.

- Propagate whether the token came from a token stream through CachingLex.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/TokenLexer.h
  clang/lib/Lex/PPCaching.cpp
  clang/lib/Lex/Preprocessor.cpp

Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -636,7 +636,8 @@
   break;
 case CLK_CachingLexer:
   bool IsNewToken;
-  CachingLex(Tok, IsNewToken);
+  bool Report;
+  CachingLex(Tok, IsNewToken, Report);
   break;
 case CLK_LexAfterModuleImport:
   LexAfterModuleImport(Tok);
@@ -877,6 +878,11 @@
 }
 
 void Preprocessor::Lex(Token &Result) {
+  bool Report;
+  Lex(Result, Report);
+}
+
+void Preprocessor::Lex(Token &Result, bool &Report) {
   ++LexLevel;
 
   // We loop here until a lex function returns a token; this avoids recursion.
@@ -885,17 +891,21 @@
   do {
 switch (CurLexerKind) {
 case CLK_Lexer:
+  Report = true;
   ReturnedToken = CurLexer->Lex(Result);
   break;
 case CLK_TokenLexer:
+  Report = CurTokenLexer->isMacroExpansion();
   ReturnedToken = CurTokenLexer->Lex(Result);
   break;
 case CLK_CachingLexer:
-  CachingLex(Result, IsNewToken);
+  CachingLex(Result, IsNewToken, Report);
   ReturnedToken = true;
   break;
 case CLK_LexAfterModuleImport:
-  ReturnedToken = LexAfterModuleImport(Result);
+  LexAfterModuleImport(Result);
+  Report = true;
+  ReturnedToken = true;
   break;
 }
   } while (!ReturnedToken);
@@ -952,6 +962,8 @@
 
   LastTokenWasAt = Result.is(tok::at);
   --LexLevel;
+  if (OnToken && LexLevel == 0 && Report)
+OnToken(Result);
 }
 
 /// Lex a header-name token (including one formed from header-name-tokens if
Index: clang/lib/Lex/PPCaching.cpp
===
--- clang/lib/Lex/PPCaching.cpp
+++ clang/lib/Lex/PPCaching.cpp
@@ -45,7 +45,7 @@
   recomputeCurLexerKind();
 }
 
-void Preprocessor::CachingLex(Token &Result, bool &IsNewToken) {
+void Preprocessor::CachingLex(Token &Result, bool &IsNewToken, bool &Report) {
   if (!InCachingLexMode())
 return;
 
@@ -56,11 +56,12 @@
   if (CachedLexPos < CachedTokens.size()) {
 Result = CachedTokens[CachedLexPos++];
 IsNewToken = false;
+Report = false;
 return;
   }
 
   ExitCachingLexMode();
-  Lex(Result);
+  Lex(Result, Report);
 
   if (isBacktrackEnabled()) {
 // Cache the lexed token.
Index: clang/include/clang/Lex/TokenLexer.h
===
--- clang/include/clang/Lex/TokenLexer.h
+++ clang/include/clang/Lex/TokenLexer.h
@@ -147,6 +147,10 @@
   /// preprocessor directive.
   bool isParsingPreprocessorDirective() const;
 
+  /// Returns true iff the TokenLexer is expanding a macro and not replaying a
+  /// stream of tokens.
+  bool isMacroExpansion() const { return Macro != nullptr; }
+
 private:
   void destroy();
 
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -33,6 +33,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
@@ -48,8 +49,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -124,6 +125,7 @@
   friend class VAOptDefinitionContext;
   friend class VariadicMacroScopeGuard;
 
+  llvm::unique_function OnToken;
   std::shared_ptr PPOpts;
   DiagnosticsEngine*Diags;
   LangOptions   &LangOpts;
@@ -997,6 +999,12 @@
   }
   /// \}
 
+  /// Register a function that would be called on each token in the final
+  /// expanded token stream.
+  void setTokenWatcher(llvm::unique_function F) {
+OnToken = std::move(F);
+  }
+
   bool isMacroDefined(StringRef Id) {
 return isMacroDefined(&Identifiers.get(Id));
   }
@@ -1341,6 +1349,12 @@
   /// Lex the next token for this preprocessor.
   void Lex(Token &Result);
 
+private:
+  /// Lex the next token and tell whether it should be reported to OnToken
+  /// callback.
+  void Lex(Token &Result, bool &Report);
+
+public:
   /// Lex a token, forming a header-name token if possible.
   bool LexHeaderName(Token &Result, bool AllowMacroExpansion = true);
 
@@ -2135,7 +2149,7 @@
 
   //======//
   // Caching stuff.
-  void CachingLex(Token &

[PATCH] D61130: [llvm-mc] Add reportWarning() to MCContext

2019-05-08 Thread Sid Manning via Phabricator via cfe-commits
sidneym accepted this revision.
sidneym added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61130



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


[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

I've managed to get what I needed by returning a flag from `Lex`.
@rsmith, could you take a look? Is there a better way to do the equivalent?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885



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


[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 198663.
ilya-biryukov added a comment.

- Get rid of an accidental change in how LexAfterModuleImport is handled


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/TokenLexer.h
  clang/lib/Lex/PPCaching.cpp
  clang/lib/Lex/Preprocessor.cpp

Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -636,7 +636,8 @@
   break;
 case CLK_CachingLexer:
   bool IsNewToken;
-  CachingLex(Tok, IsNewToken);
+  bool Report;
+  CachingLex(Tok, IsNewToken, Report);
   break;
 case CLK_LexAfterModuleImport:
   LexAfterModuleImport(Tok);
@@ -877,6 +878,11 @@
 }
 
 void Preprocessor::Lex(Token &Result) {
+  bool Report;
+  Lex(Result, Report);
+}
+
+void Preprocessor::Lex(Token &Result, bool &Report) {
   ++LexLevel;
 
   // We loop here until a lex function returns a token; this avoids recursion.
@@ -885,17 +891,20 @@
   do {
 switch (CurLexerKind) {
 case CLK_Lexer:
+  Report = true;
   ReturnedToken = CurLexer->Lex(Result);
   break;
 case CLK_TokenLexer:
+  Report = CurTokenLexer->isMacroExpansion();
   ReturnedToken = CurTokenLexer->Lex(Result);
   break;
 case CLK_CachingLexer:
-  CachingLex(Result, IsNewToken);
+  CachingLex(Result, IsNewToken, Report);
   ReturnedToken = true;
   break;
 case CLK_LexAfterModuleImport:
   ReturnedToken = LexAfterModuleImport(Result);
+  Report = true;
   break;
 }
   } while (!ReturnedToken);
@@ -952,6 +961,8 @@
 
   LastTokenWasAt = Result.is(tok::at);
   --LexLevel;
+  if (OnToken && LexLevel == 0 && Report)
+OnToken(Result);
 }
 
 /// Lex a header-name token (including one formed from header-name-tokens if
Index: clang/lib/Lex/PPCaching.cpp
===
--- clang/lib/Lex/PPCaching.cpp
+++ clang/lib/Lex/PPCaching.cpp
@@ -45,7 +45,7 @@
   recomputeCurLexerKind();
 }
 
-void Preprocessor::CachingLex(Token &Result, bool &IsNewToken) {
+void Preprocessor::CachingLex(Token &Result, bool &IsNewToken, bool &Report) {
   if (!InCachingLexMode())
 return;
 
@@ -56,11 +56,12 @@
   if (CachedLexPos < CachedTokens.size()) {
 Result = CachedTokens[CachedLexPos++];
 IsNewToken = false;
+Report = false;
 return;
   }
 
   ExitCachingLexMode();
-  Lex(Result);
+  Lex(Result, Report);
 
   if (isBacktrackEnabled()) {
 // Cache the lexed token.
Index: clang/include/clang/Lex/TokenLexer.h
===
--- clang/include/clang/Lex/TokenLexer.h
+++ clang/include/clang/Lex/TokenLexer.h
@@ -147,6 +147,10 @@
   /// preprocessor directive.
   bool isParsingPreprocessorDirective() const;
 
+  /// Returns true iff the TokenLexer is expanding a macro and not replaying a
+  /// stream of tokens.
+  bool isMacroExpansion() const { return Macro != nullptr; }
+
 private:
   void destroy();
 
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -33,6 +33,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
@@ -48,8 +49,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -124,6 +125,7 @@
   friend class VAOptDefinitionContext;
   friend class VariadicMacroScopeGuard;
 
+  llvm::unique_function OnToken;
   std::shared_ptr PPOpts;
   DiagnosticsEngine*Diags;
   LangOptions   &LangOpts;
@@ -997,6 +999,12 @@
   }
   /// \}
 
+  /// Register a function that would be called on each token in the final
+  /// expanded token stream.
+  void setTokenWatcher(llvm::unique_function F) {
+OnToken = std::move(F);
+  }
+
   bool isMacroDefined(StringRef Id) {
 return isMacroDefined(&Identifiers.get(Id));
   }
@@ -1341,6 +1349,12 @@
   /// Lex the next token for this preprocessor.
   void Lex(Token &Result);
 
+private:
+  /// Lex the next token and tell whether it should be reported to OnToken
+  /// callback.
+  void Lex(Token &Result, bool &Report);
+
+public:
   /// Lex a token, forming a header-name token if possible.
   bool LexHeaderName(Token &Result, bool AllowMacroExpansion = true);
 
@@ -2135,7 +2149,7 @@
 
   //======//
   // Caching stuff.
-  void CachingLex(Token &Result, bool &IsNewToken);
+  void CachingLex(Token &Result, bool &IsNewToken, bool &Report);
 
   bool InCachingLexMod

r360261 - [ASTImporter] Fix inequivalence of unresolved exception spec

2019-05-08 Thread Gabor Marton via cfe-commits
Author: martong
Date: Wed May  8 08:23:48 2019
New Revision: 360261

URL: http://llvm.org/viewvc/llvm-project?rev=360261&view=rev
Log:
[ASTImporter] Fix inequivalence of unresolved exception spec

Summary:
Structural equivalence of methods can falsely report false when the
exception specifier is unresolved (i.e unevaluated or not instantiated).

(This caused one assertion during bitcoin ctu-analysis.)

Reviewers: a_sidorin, shafik, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=360261&r1=360260&r2=360261&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed May  8 08:23:48 2019
@@ -3130,6 +3130,11 @@ ExpectedDecl ASTNodeImporter::VisitFunct
 auto *Recent = const_cast(
   FoundByLookup->getMostRecentDecl());
 ToFunction->setPreviousDecl(Recent);
+// FIXME Probably we should merge exception specifications.  E.g. In the
+// "To" context the existing function may have exception specification with
+// noexcept-unevaluated, while the newly imported function may have an
+// evaluated noexcept.  A call to adjustExceptionSpec() on the imported
+// decl and its redeclarations may be required.
   }
 
   // Import Ctor initializers.

Modified: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp?rev=360261&r1=360260&r2=360261&view=diff
==
--- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp (original)
+++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp Wed May  8 08:23:48 2019
@@ -322,6 +322,36 @@ static bool IsStructurallyEquivalent(Str
   return true;
 }
 
+/// Check the equivalence of exception specifications.
+static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,
+  const FunctionProtoType *Proto1,
+  const FunctionProtoType *Proto2) {
+
+  auto Spec1 = Proto1->getExceptionSpecType();
+  auto Spec2 = Proto2->getExceptionSpecType();
+
+  if (isUnresolvedExceptionSpec(Spec1) || isUnresolvedExceptionSpec(Spec2))
+return true;
+
+  if (Spec1 != Spec2)
+return false;
+  if (Spec1 == EST_Dynamic) {
+if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
+  return false;
+for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
+  if (!IsStructurallyEquivalent(Context, Proto1->getExceptionType(I),
+Proto2->getExceptionType(I)))
+return false;
+}
+  } else if (isComputedNoexcept(Spec1)) {
+if (!IsStructurallyEquivalent(Context, Proto1->getNoexceptExpr(),
+  Proto2->getNoexceptExpr()))
+  return false;
+  }
+
+  return true;
+}
+
 /// Determine structural equivalence of two types.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  QualType T1, QualType T2) {
@@ -536,24 +566,8 @@ static bool IsStructurallyEquivalent(Str
 cast(OrigT1.getDesugaredType(Context.FromCtx));
 const auto *OrigProto2 =
 cast(OrigT2.getDesugaredType(Context.ToCtx));
-auto Spec1 = OrigProto1->getExceptionSpecType();
-auto Spec2 = OrigProto2->getExceptionSpecType();
-
-if (Spec1 != Spec2)
+if (!IsEquivalentExceptionSpec(Context, OrigProto1, OrigProto2))
   return false;
-if (Spec1 == EST_Dynamic) {
-  if (OrigProto1->getNumExceptions() != OrigProto2->getNumExceptions())
-return false;
-  for (unsigned I = 0, N = OrigProto1->getNumExceptions(); I != N; ++I) {
-if (!IsStructurallyEquivalent(Context, OrigProto1->getExceptionType(I),
-  OrigProto2->getExceptionType(I)))
-  return false;
-  }
-} else if (isComputedNoexcept(Spec1)) {
-  if (!IsStructurallyEquivalent(Context, OrigProto1->getNoexceptExpr(),
-OrigProto2->getNoexceptExpr()))
-return false;
-}
 
 // Fall through to check the bits common with FunctionNoProtoType.
 LLVM_FALLTHROUGH;


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


[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-08 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 198664.
gtbercea added a comment.

- Eliminate declarations of functions not needed for math function resolution.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399

Files:
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/__clang_cuda_cmath.h
  lib/Headers/__clang_cuda_device_functions.h
  lib/Headers/__clang_cuda_libdevice_declares.h
  lib/Headers/__clang_cuda_math_forward_declares.h
  lib/Headers/openmp_wrappers/__clang_openmp_math.h
  lib/Headers/openmp_wrappers/cmath
  lib/Headers/openmp_wrappers/math.h
  test/Driver/openmp-offload-gpu.c
  test/Headers/Inputs/include/cmath
  test/Headers/Inputs/include/limits
  test/Headers/Inputs/include/math.h
  test/Headers/nvptx_device_cmath_functions.c
  test/Headers/nvptx_device_cmath_functions.cpp
  test/Headers/nvptx_device_math_functions.c
  test/Headers/nvptx_device_math_functions.cpp

Index: test/Headers/nvptx_device_math_functions.cpp
===
--- /dev/null
+++ test/Headers/nvptx_device_math_functions.cpp
@@ -0,0 +1,21 @@
+// Test calling of device math functions.
+///==///
+
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include math.h -x c++ -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include math.h -internal-isystem %S/Inputs/include -include stdlib.h -include limits -x c++ -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
+
+#include 
+
+void test_sqrt(double a1) {
+  #pragma omp target
+  {
+// CHECK-YES: call double @__nv_sqrt(double
+double l1 = sqrt(a1);
+// CHECK-YES: call double @__nv_pow(double
+double l2 = pow(a1, a1);
+// CHECK-YES: call double @__nv_modf(double
+double l3 = modf(a1 + 3.5, &a1);
+  }
+}
Index: test/Headers/nvptx_device_math_functions.c
===
--- /dev/null
+++ test/Headers/nvptx_device_math_functions.c
@@ -0,0 +1,21 @@
+// Test calling of device math functions.
+///==///
+
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include math.h -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include math.h -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
+
+#include 
+
+void test_sqrt(double a1) {
+  #pragma omp target
+  {
+// CHECK-YES: call double @__nv_sqrt(double
+double l1 = sqrt(a1);
+// CHECK-YES: call double @__nv_pow(double
+double l2 = pow(a1, a1);
+// CHECK-YES: call double @__nv_modf(double
+double l3 = modf(a1 + 3.5, &a1);
+  }
+}
Index: test/Headers/nvptx_device_cmath_functions.cpp
===
--- /dev/null
+++ test/Headers/nvptx_device_cmath_functions.cpp
@@ -0,0 +1,21 @@
+// Test calling of device math functions.
+///==///
+
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include cmath -x c++ -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include cmath -internal-isystem %S/Inputs/include -include stdlib.h -x c++ -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
+
+#include 
+
+void test_sqrt(double a1) {
+  #pragma omp target
+  {
+// CHECK-YES: call double @__nv_sqrt(double
+double l1 = sqrt(a1);
+// CHECK-YES: call double @__nv_pow(double
+double l2 = pow(a1, a1);
+// CHECK-YES: call double @__nv_modf(double
+double l3 = modf(a1 + 

[PATCH] D61424: [ASTImporter] Fix inequivalence of unresolved exception spec

2019-05-08 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360261: [ASTImporter] Fix inequivalence of unresolved 
exception spec (authored by martong, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61424?vs=198626&id=198665#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61424

Files:
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp


Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -3130,6 +3130,11 @@
 auto *Recent = const_cast(
   FoundByLookup->getMostRecentDecl());
 ToFunction->setPreviousDecl(Recent);
+// FIXME Probably we should merge exception specifications.  E.g. In the
+// "To" context the existing function may have exception specification with
+// noexcept-unevaluated, while the newly imported function may have an
+// evaluated noexcept.  A call to adjustExceptionSpec() on the imported
+// decl and its redeclarations may be required.
   }
 
   // Import Ctor initializers.
Index: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
===
--- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
+++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
@@ -322,6 +322,36 @@
   return true;
 }
 
+/// Check the equivalence of exception specifications.
+static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,
+  const FunctionProtoType *Proto1,
+  const FunctionProtoType *Proto2) {
+
+  auto Spec1 = Proto1->getExceptionSpecType();
+  auto Spec2 = Proto2->getExceptionSpecType();
+
+  if (isUnresolvedExceptionSpec(Spec1) || isUnresolvedExceptionSpec(Spec2))
+return true;
+
+  if (Spec1 != Spec2)
+return false;
+  if (Spec1 == EST_Dynamic) {
+if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
+  return false;
+for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
+  if (!IsStructurallyEquivalent(Context, Proto1->getExceptionType(I),
+Proto2->getExceptionType(I)))
+return false;
+}
+  } else if (isComputedNoexcept(Spec1)) {
+if (!IsStructurallyEquivalent(Context, Proto1->getNoexceptExpr(),
+  Proto2->getNoexceptExpr()))
+  return false;
+  }
+
+  return true;
+}
+
 /// Determine structural equivalence of two types.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  QualType T1, QualType T2) {
@@ -536,24 +566,8 @@
 cast(OrigT1.getDesugaredType(Context.FromCtx));
 const auto *OrigProto2 =
 cast(OrigT2.getDesugaredType(Context.ToCtx));
-auto Spec1 = OrigProto1->getExceptionSpecType();
-auto Spec2 = OrigProto2->getExceptionSpecType();
-
-if (Spec1 != Spec2)
+if (!IsEquivalentExceptionSpec(Context, OrigProto1, OrigProto2))
   return false;
-if (Spec1 == EST_Dynamic) {
-  if (OrigProto1->getNumExceptions() != OrigProto2->getNumExceptions())
-return false;
-  for (unsigned I = 0, N = OrigProto1->getNumExceptions(); I != N; ++I) {
-if (!IsStructurallyEquivalent(Context, OrigProto1->getExceptionType(I),
-  OrigProto2->getExceptionType(I)))
-  return false;
-  }
-} else if (isComputedNoexcept(Spec1)) {
-  if (!IsStructurallyEquivalent(Context, OrigProto1->getNoexceptExpr(),
-OrigProto2->getNoexceptExpr()))
-return false;
-}
 
 // Fall through to check the bits common with FunctionNoProtoType.
 LLVM_FALLTHROUGH;


Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -3130,6 +3130,11 @@
 auto *Recent = const_cast(
   FoundByLookup->getMostRecentDecl());
 ToFunction->setPreviousDecl(Recent);
+// FIXME Probably we should merge exception specifications.  E.g. In the
+// "To" context the existing function may have exception specification with
+// noexcept-unevaluated, while the newly imported function may have an
+// evaluated noexcept.  A call to adjustExceptionSpec() on the imported
+// decl and its redeclarations may be required.
   }
 
   // Import Ctor initializers.
Index: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
===
--- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
+++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
@@ -322,6 +322,36 @@
   return true;
 }
 
+/// Check th

[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-08 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Gentle ping...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61335



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


[PATCH] D61333: [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src

2019-05-08 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Ping @shafik @teemperor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61333



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


r360265 - [OpenMP][Clang] Support for target math functions

2019-05-08 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Wed May  8 08:52:33 2019
New Revision: 360265

URL: http://llvm.org/viewvc/llvm-project?rev=360265&view=rev
Log:
[OpenMP][Clang] Support for target math functions

Summary:
In this patch we propose a temporary solution to resolving math functions for 
the NVPTX toolchain, temporary until OpenMP variant is supported by Clang.

We intercept the inclusion of math.h and cmath headers and if we are in the 
OpenMP-NVPTX case, we re-use CUDA's math function resolution mechanism.

Authors:
@gtbercea
@jdoerfert

Reviewers: hfinkel, caomhin, ABataev, tra

Reviewed By: hfinkel, ABataev, tra

Subscribers: JDevlieghere, mgorny, guansong, cfe-commits, jdoerfert

Tags: #clang

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

Added:
cfe/trunk/lib/Headers/openmp_wrappers/
cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math.h
cfe/trunk/lib/Headers/openmp_wrappers/cmath
cfe/trunk/lib/Headers/openmp_wrappers/math.h
cfe/trunk/test/Headers/Inputs/include/cmath
cfe/trunk/test/Headers/Inputs/include/limits
cfe/trunk/test/Headers/nvptx_device_cmath_functions.c
cfe/trunk/test/Headers/nvptx_device_cmath_functions.cpp
cfe/trunk/test/Headers/nvptx_device_math_functions.c
cfe/trunk/test/Headers/nvptx_device_math_functions.cpp
Modified:
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Headers/CMakeLists.txt
cfe/trunk/lib/Headers/__clang_cuda_cmath.h
cfe/trunk/lib/Headers/__clang_cuda_device_functions.h
cfe/trunk/lib/Headers/__clang_cuda_libdevice_declares.h
cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
cfe/trunk/test/Driver/openmp-offload-gpu.c
cfe/trunk/test/Headers/Inputs/include/math.h

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=360265&r1=360264&r2=360265&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Wed May  8 08:52:33 2019
@@ -425,7 +425,7 @@ bool ToolChain::needsProfileRT(const Arg
   Args.hasArg(options::OPT_fprofile_instr_generate) ||
   Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
   Args.hasArg(options::OPT_fcreate_profile) ||
-  Args.hasArg(options::OPT_forder_file_instrumentation)) 
+  Args.hasArg(options::OPT_forder_file_instrumentation))
 return true;
 
   return false;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=360265&r1=360264&r2=360265&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed May  8 08:52:33 2019
@@ -1151,6 +1151,24 @@ void Clang::AddPreprocessingOptions(Comp
   if (JA.isOffloading(Action::OFK_Cuda))
 getToolChain().AddCudaIncludeArgs(Args, CmdArgs);
 
+  // If we are offloading to a target via OpenMP we need to include the
+  // openmp_wrappers folder which contains alternative system headers.
+  if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&
+  getToolChain().getTriple().isNVPTX()){
+if (!Args.hasArg(options::OPT_nobuiltininc)) {
+  // Add openmp_wrappers/* to our system include path.  This lets us wrap
+  // standard library headers.
+  SmallString<128> P(D.ResourceDir);
+  llvm::sys::path::append(P, "include");
+  llvm::sys::path::append(P, "openmp_wrappers");
+  CmdArgs.push_back("-internal-isystem");
+  CmdArgs.push_back(Args.MakeArgString(P));
+}
+
+CmdArgs.push_back("-include");
+CmdArgs.push_back("__clang_openmp_math.h");
+  }
+
   // Add -i* options, and automatically translate to
   // -include-pch/-include-pth for transparent PCH support. It's
   // wonky, but we include looking for .gch so we can support seamless

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=360265&r1=360264&r2=360265&view=diff
==
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Wed May  8 08:52:33 2019
@@ -128,6 +128,12 @@ set(ppc_wrapper_files
   ppc_wrappers/mmintrin.h
 )
 
+set(openmp_wrapper_files
+  openmp_wrappers/math.h
+  openmp_wrappers/cmath
+  openmp_wrappers/__clang_openmp_math.h
+)
+
 set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
 set(out_files)
 set(generated_files)
@@ -156,7 +162,7 @@ endfunction(clang_generate_header)
 
 
 # Copy header files from the source directory to the build directory
-foreach( f ${files} ${cuda_wrapper_files} ${ppc_wrapper_files} )
+foreach( f ${files} ${cuda_wrapper_files} ${ppc_wrapper_files} 
${openmp_wrapper_files})
   copy_header_to_output_dir(${CMAKE_CUR

[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC360265: [OpenMP][Clang] Support for target math functions 
(authored by gbercea, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61399?vs=198664&id=198677#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D61399

Files:
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/__clang_cuda_cmath.h
  lib/Headers/__clang_cuda_device_functions.h
  lib/Headers/__clang_cuda_libdevice_declares.h
  lib/Headers/__clang_cuda_math_forward_declares.h
  lib/Headers/openmp_wrappers/__clang_openmp_math.h
  lib/Headers/openmp_wrappers/cmath
  lib/Headers/openmp_wrappers/math.h
  test/Driver/openmp-offload-gpu.c
  test/Headers/Inputs/include/cmath
  test/Headers/Inputs/include/limits
  test/Headers/Inputs/include/math.h
  test/Headers/nvptx_device_cmath_functions.c
  test/Headers/nvptx_device_cmath_functions.cpp
  test/Headers/nvptx_device_math_functions.c
  test/Headers/nvptx_device_math_functions.cpp

Index: lib/Headers/__clang_cuda_libdevice_declares.h
===
--- lib/Headers/__clang_cuda_libdevice_declares.h
+++ lib/Headers/__clang_cuda_libdevice_declares.h
@@ -10,443 +10,453 @@
 #ifndef __CLANG_CUDA_LIBDEVICE_DECLARES_H__
 #define __CLANG_CUDA_LIBDEVICE_DECLARES_H__
 
+#if defined(__cplusplus)
 extern "C" {
+#endif
 
-__device__ int __nv_abs(int __a);
-__device__ double __nv_acos(double __a);
-__device__ float __nv_acosf(float __a);
-__device__ double __nv_acosh(double __a);
-__device__ float __nv_acoshf(float __a);
-__device__ double __nv_asin(double __a);
-__device__ float __nv_asinf(float __a);
-__device__ double __nv_asinh(double __a);
-__device__ float __nv_asinhf(float __a);
-__device__ double __nv_atan2(double __a, double __b);
-__device__ float __nv_atan2f(float __a, float __b);
-__device__ double __nv_atan(double __a);
-__device__ float __nv_atanf(float __a);
-__device__ double __nv_atanh(double __a);
-__device__ float __nv_atanhf(float __a);
-__device__ int __nv_brev(int __a);
-__device__ long long __nv_brevll(long long __a);
-__device__ int __nv_byte_perm(int __a, int __b, int __c);
-__device__ double __nv_cbrt(double __a);
-__device__ float __nv_cbrtf(float __a);
-__device__ double __nv_ceil(double __a);
-__device__ float __nv_ceilf(float __a);
-__device__ int __nv_clz(int __a);
-__device__ int __nv_clzll(long long __a);
-__device__ double __nv_copysign(double __a, double __b);
-__device__ float __nv_copysignf(float __a, float __b);
-__device__ double __nv_cos(double __a);
-__device__ float __nv_cosf(float __a);
-__device__ double __nv_cosh(double __a);
-__device__ float __nv_coshf(float __a);
-__device__ double __nv_cospi(double __a);
-__device__ float __nv_cospif(float __a);
-__device__ double __nv_cyl_bessel_i0(double __a);
-__device__ float __nv_cyl_bessel_i0f(float __a);
-__device__ double __nv_cyl_bessel_i1(double __a);
-__device__ float __nv_cyl_bessel_i1f(float __a);
-__device__ double __nv_dadd_rd(double __a, double __b);
-__device__ double __nv_dadd_rn(double __a, double __b);
-__device__ double __nv_dadd_ru(double __a, double __b);
-__device__ double __nv_dadd_rz(double __a, double __b);
-__device__ double __nv_ddiv_rd(double __a, double __b);
-__device__ double __nv_ddiv_rn(double __a, double __b);
-__device__ double __nv_ddiv_ru(double __a, double __b);
-__device__ double __nv_ddiv_rz(double __a, double __b);
-__device__ double __nv_dmul_rd(double __a, double __b);
-__device__ double __nv_dmul_rn(double __a, double __b);
-__device__ double __nv_dmul_ru(double __a, double __b);
-__device__ double __nv_dmul_rz(double __a, double __b);
-__device__ float __nv_double2float_rd(double __a);
-__device__ float __nv_double2float_rn(double __a);
-__device__ float __nv_double2float_ru(double __a);
-__device__ float __nv_double2float_rz(double __a);
-__device__ int __nv_double2hiint(double __a);
-__device__ int __nv_double2int_rd(double __a);
-__device__ int __nv_double2int_rn(double __a);
-__device__ int __nv_double2int_ru(double __a);
-__device__ int __nv_double2int_rz(double __a);
-__device__ long long __nv_double2ll_rd(double __a);
-__device__ long long __nv_double2ll_rn(double __a);
-__device__ long long __nv_double2ll_ru(double __a);
-__device__ long long __nv_double2ll_rz(double __a);
-__device__ int __nv_double2loint(double __a);
-__device__ unsigned int __nv_double2uint_rd(double __a);
-__device__ unsigned int __nv_double2uint_rn(double __a);
-__device__ unsigned int __nv_double2uint_ru(double __a);
-__device__ unsigned int __nv_double2uint_rz(double __a);
-__device__ unsigned long long __nv_double2ull_rd(double __a);
-__device__ unsigned long long __nv_double2ull_rn(double __a);
-__device__ unsigned long long __nv_double2ull_ru(double __a);
-__device__ unsigned long long __nv_double2ull_rz(double __a);
-__devi

[PATCH] D61488: [OpenCL] Make global ctor init function a kernel

2019-05-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 198678.
Anastasia added a comment.

- Improved comments
- Switched to SPIR kernel


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

https://reviews.llvm.org/D61488

Files:
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenOpenCLCXX/global_init.cl

Index: test/CodeGenOpenCLCXX/global_init.cl
===
--- /dev/null
+++ test/CodeGenOpenCLCXX/global_init.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
+
+struct S {
+  S() {}
+};
+
+S s;
+
+//CHECK: define internal spir_kernel void @_GLOBAL__sub_I_{{.*}}!kernel_arg_addr_space [[ARGMD:![0-9]+]] !kernel_arg_access_qual [[ARGMD]] !kernel_arg_type [[ARGMD]] !kernel_arg_base_type [[ARGMD]] !kernel_arg_type_qual [[ARGMD]]
+// Check that parameters are empty.
+//CHECK: [[ARGMD]] = !{}
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -1315,6 +1315,19 @@
   llvm::Value *
   createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF);
 
+  /// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
+  /// information in the program executable. The argument information stored
+  /// includes the argument name, its type, the address and access qualifiers
+  /// used. This helper can be used to generate metadata for source code kernel
+  /// function as well as generated implicitly kernels. If a kernel is generated
+  /// implicitly null value has to be passed to the last two parameters,
+  /// otherwise all parameters must have valid non-null values.
+  /// \param FN is a pointer to IR function being generated.
+  /// \param FD is a pointer to function declaration if any.
+  /// \param CGF is a pointer to CodeGenFunction that generates this function.
+  void GenOpenCLArgMetadata(llvm::Function *Fn, const FunctionDecl *FD=nullptr,  
+ CodeGenFunction *CGF=nullptr);
+
   /// Get target specific null pointer.
   /// \param T is the LLVM type of the null pointer.
   /// \param QT is the clang QualType of the null pointer.
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1187,6 +1187,212 @@
   F->setCallingConv(static_cast(CallingConv));
 }
 
+static void removeImageAccessQualifier(std::string& TyName) {
+  std::string ReadOnlyQual("__read_only");
+  std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual);
+  if (ReadOnlyPos != std::string::npos)
+// "+ 1" for the space after access qualifier.
+TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1);
+  else {
+std::string WriteOnlyQual("__write_only");
+std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual);
+if (WriteOnlyPos != std::string::npos)
+  TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1);
+else {
+  std::string ReadWriteQual("__read_write");
+  std::string::size_type ReadWritePos = TyName.find(ReadWriteQual);
+  if (ReadWritePos != std::string::npos)
+TyName.erase(ReadWritePos, ReadWriteQual.size() + 1);
+}
+  }
+}
+
+// Returns the address space id that should be produced to the
+// kernel_arg_addr_space metadata. This is always fixed to the ids
+// as specified in the SPIR 2.0 specification in order to differentiate
+// for example in clGetKernelArgInfo() implementation between the address
+// spaces with targets without unique mapping to the OpenCL address spaces
+// (basically all single AS CPUs).
+static unsigned ArgInfoAddressSpace(LangAS AS) {
+  switch (AS) {
+  case LangAS::opencl_global:   return 1;
+  case LangAS::opencl_constant: return 2;
+  case LangAS::opencl_local:return 3;
+  case LangAS::opencl_generic:  return 4; // Not in SPIR 2.0 specs.
+  default:
+return 0; // Assume private.
+  }
+}
+
+void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
+ const FunctionDecl *FD,
+ CodeGenFunction *CGF) {
+  assert(((FD && CGF) || (!FD && !CGF)) &&
+ "Incorrect use - FD and CGF should either be both null or not!");
+  // Create MDNodes that represent the kernel arg metadata.
+  // Each MDNode is a list in the form of "key", N number of values which is
+  // the same number of values as their are kernel arguments.
+
+  const PrintingPolicy &Policy = Context.getPrintingPolicy();
+
+  // MDNode for the kernel argument address space qualifiers.
+  SmallVector addressQuals;
+
+  // MDNode for the kernel argument access qualifiers (images only).
+  SmallVector accessQuals;
+
+  // MDNode for the kernel argument type names.
+  SmallVector argTypeNames;
+
+  // MDNode for the kernel argument base

[PATCH] D60605: [clangd] Revamp textDocument/onTypeFormatting.

2019-05-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov 
What do you think about D53072 ? It can be 
polished and combined with this change removing some code from here (which I 
assume is a good thing).
The idea there is that clang-format knows that it's not allowed to remove new 
lines and it always marks them with MustBreakBefore.
I'm not sure if anybody needs an executable but I think it's not a big deal to 
have an extra reformat() function.

It is also safe because it was the only way I found which does not break the 
code style like, for instance, adding comment block to the end of the previous 
line.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60605



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


[PATCH] D60629: [clang-tidy] Change the namespace for llvm checkers from 'llvm' to 'llvm_check'

2019-05-08 Thread Don Hinton via Phabricator via cfe-commits
hintonda added a comment.

In D60629#1494908 , @aaron.ballman 
wrote:

> This LGTM, but you may want to wait a day or so to see if @alexfh has any 
> remaining concerns.


Will do, thanks Aaron...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60629



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


[PATCH] D60605: [clangd] Revamp textDocument/onTypeFormatting.

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D60605#1495268 , @yvvan wrote:

> @ilya-biryukov 
>  What do you think about D53072 ? It can be 
> polished and combined with this change removing some code from here (which I 
> assume is a good thing).
>  The idea there is that clang-format knows that it's not allowed to remove 
> new lines and it always marks them with MustBreakBefore.
>  I'm not sure if anybody needs an executable but I think it's not a big deal 
> to have an extra reformat() function.
>
> It is also safe because it was the only way I found which does not break the 
> code style like, for instance, adding comment block to the end of the 
> previous line.


I also think (both Sam and you seem to agree with this) that we'll definitely 
need changes to `clang-format` to support this use-case.
Also sympathetic to the view that this change should probably live in 
`clang-format`, but having it in clangd first and moving to `clang-format` 
later also LG.
@sammccall, what's your plan there? Experimenting in `clangd` and moving to 
`clang-format` later? Any reason to not start in `clang-format` in the first 
place?

Will add a few comments regarding the need for a separate tool in D53072 
 directly.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60605



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


[PATCH] D61689: Change -gz and -Wa,--compress-debug-sections to use gABI compression (SHF_COMPRESSED)

2019-05-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: compnerd, rsmith, echristo.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since July 15, 2015 (binutils-gdb commit
19a7fe52ae3d0971e67a134bcb1648899e21ae1c, included in 2.26), gas
--compress-debug-sections=zlib (gcc -gz) means zlib-gabi:
SHF_COMPRESSED.  Before that it meant zlib-gnu (.zdebug).

clang's -gz was introduced in rC306115  (Jun 
2017) to indicate zlib-gnu. It
is 2019 now and it is not unreasonable to assume users of the new
feature to have new linkers (ld.bfd/gold >= 2.26, lld >= rLLD273661 
).

Change clang's default accordingly to improve standard conformance.
zlib-gnu becomes out of fashion and gets poorer toolchain support.
Its mangled names confuse tools and are more likely to cause problems,
e.g.

lld up to 8.0.0 (and probably some older ld.bfd/gold) don't handle -r
linking of .rela.zdebug_* correctly: .rela.zdebug_* output sections are
created without compression. Consumers which assume these sections are
zlib-gnu may have parsing errors.


Repository:
  rC Clang

https://reviews.llvm.org/D61689

Files:
  lib/Frontend/CompilerInvocation.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -221,8 +221,7 @@
   if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
  OPT_compress_debug_sections_EQ)) {
 if (A->getOption().getID() == OPT_compress_debug_sections) {
-  // TODO: be more clever about the compression type auto-detection
-  Opts.CompressDebugSections = llvm::DebugCompressionType::GNU;
+  Opts.CompressDebugSections = llvm::DebugCompressionType::Z;
 } else {
   Opts.CompressDebugSections =
   llvm::StringSwitch(A->getValue())
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1052,8 +1052,7 @@
   if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
  OPT_compress_debug_sections_EQ)) {
 if (A->getOption().getID() == OPT_compress_debug_sections) {
-  // TODO: be more clever about the compression type auto-detection
-  Opts.setCompressDebugSections(llvm::DebugCompressionType::GNU);
+  Opts.setCompressDebugSections(llvm::DebugCompressionType::Z);
 } else {
   auto DCT = llvm::StringSwitch(A->getValue())
  .Case("none", llvm::DebugCompressionType::None)


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -221,8 +221,7 @@
   if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
  OPT_compress_debug_sections_EQ)) {
 if (A->getOption().getID() == OPT_compress_debug_sections) {
-  // TODO: be more clever about the compression type auto-detection
-  Opts.CompressDebugSections = llvm::DebugCompressionType::GNU;
+  Opts.CompressDebugSections = llvm::DebugCompressionType::Z;
 } else {
   Opts.CompressDebugSections =
   llvm::StringSwitch(A->getValue())
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1052,8 +1052,7 @@
   if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
  OPT_compress_debug_sections_EQ)) {
 if (A->getOption().getID() == OPT_compress_debug_sections) {
-  // TODO: be more clever about the compression type auto-detection
-  Opts.setCompressDebugSections(llvm::DebugCompressionType::GNU);
+  Opts.setCompressDebugSections(llvm::DebugCompressionType::Z);
 } else {
   auto DCT = llvm::StringSwitch(A->getValue())
  .Case("none", llvm::DebugCompressionType::None)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D53072#1478575 , @yvvan wrote:

> @sammccall
>
> Having a separate tool is nice because it allows the client to make it 
> plugable. clang-format sometimes changes options quite significantly and it 
> can be nice if you have a choice which version to pick, otherwise it might be 
> unable to read the configuration you have.


I second Sam's concerns about introducing a new tool.
Could you list the use-cases that `clang-format-ide` would cover that 
`clang-format` doesn't?
How is introducing a new tool different from adding a new formatting option to 
`clang-format`?


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

https://reviews.llvm.org/D53072



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


[PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2019-05-08 Thread Nolan O'Brien via Phabricator via cfe-commits
NSProgrammer added a comment.

In D17741#1413864 , @kristina wrote:

> If the author is still missing at the end of next week, any objections to me 
> resubmitting a similar patch that just implements `__FILE_NAME__` or 
> `__BASE_NAME__` (Need a few more opinions here I guess, personally I think 
> `__FILE_NAME__` makes more sense)?
>
> I'll carve it out from my PP extension which simply looks for the last path 
> separator (depending on the OS) and only renders the filename after it (or 
> the whole path if there's no separator). No need for additional complications 
> like depths etc. Since this idea was shot down last time, is it possible to 
> get a few people to voice their opinion before I mark this as abandoned and 
> carve out and clean up this from my PP extension and add proper tests for it?
>
> Would be appreciated, as this sort of thing is very useful (IMO) so would 
> like to know if anyone is really against this proposal.


Kristina, it looks like there is no push back and even plenty of support.  How 
do you feel about going forward with submitting a patch that implements 
`__FILE_NAME__`?


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

https://reviews.llvm.org/D17741



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


[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Sorry for the delay.
I personally like the `RewriteRule::Action` best. Allows to use a rather common 
term, while still avoiding any possible confusion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61335



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


[PATCH] D61454: [CodeGen][ObjC] Remove the leading 'l_' from ObjC symbols and make private symbols in the __DATA segment internal.

2019-05-08 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Lgtm, thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D61454



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


[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-08 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:5039
+  if (!ToOrErr)
+// FIXME: return the error?
+consumeError(ToOrErr.takeError());

We don't typically commit FIXME's into LLVM code. Why not just deal with the 
error properly from the start?



Comment at: lldb/source/Symbol/ClangASTImporter.cpp:65
 
-  if (delegate_sp)
-return delegate_sp->Import(type);
+  if (delegate_sp) {
+if (llvm::Expected ret_or_error = delegate_sp->Import(type)) {

```
 if (!delegate_sp)
  return {};
```



Comment at: lldb/source/Symbol/ClangASTImporter.cpp:68
+  return *ret_or_error;
+} else {
+  Log *log =

The `else` is redundant.



Comment at: lldb/source/Symbol/ClangASTImporter.cpp:139
+
+  llvm::consumeError(result.takeError());
+

Can you convert this to an early return instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61438



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


[PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2019-05-08 Thread Kristina Brooks via Phabricator via cfe-commits
kristina commandeered this revision.
kristina added a reviewer: weimingz.
kristina added a comment.

Sorry, forgot about this, will make a new diff with just the macro for review 
later tonight.


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

https://reviews.llvm.org/D17741



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


r360271 - Include corecrt.h in stddef.h and vcruntime.h in stdarg.h to improve MS

2019-05-08 Thread Mike Rice via cfe-commits
Author: mikerice
Date: Wed May  8 10:15:21 2019
New Revision: 360271

URL: http://llvm.org/viewvc/llvm-project?rev=360271&view=rev
Log:
Include corecrt.h in stddef.h and vcruntime.h in stdarg.h to improve MS
compatibility.  This allows some applications developed with MSVC to
compile with clang without any extra changes.

Fixes: llvm.org/PR40789

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

Added:
cfe/trunk/test/Headers/Inputs/ms-crt/
cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h   (with props)
cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h   (with props)
cfe/trunk/test/Headers/ms-additional-includes.cpp   (with props)
Modified:
cfe/trunk/lib/Headers/stdarg.h
cfe/trunk/lib/Headers/stddef.h
cfe/trunk/test/Headers/c11.c
cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp

Modified: cfe/trunk/lib/Headers/stdarg.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stdarg.h?rev=360271&r1=360270&r2=360271&view=diff
==
--- cfe/trunk/lib/Headers/stdarg.h (original)
+++ cfe/trunk/lib/Headers/stdarg.h Wed May  8 10:15:21 2019
@@ -10,6 +10,11 @@
 #ifndef __STDARG_H
 #define __STDARG_H
 
+#if defined(_MSC_VER)
+/* Include otherwise unneeded header for MSVC compatibility. */
+#include 
+#endif
+
 #ifndef _VA_LIST
 typedef __builtin_va_list va_list;
 #define _VA_LIST

Modified: cfe/trunk/lib/Headers/stddef.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stddef.h?rev=360271&r1=360270&r2=360271&view=diff
==
--- cfe/trunk/lib/Headers/stddef.h (original)
+++ cfe/trunk/lib/Headers/stddef.h Wed May  8 10:15:21 2019
@@ -18,6 +18,12 @@
 #if !__has_feature(modules)
 #define __STDDEF_H
 #endif
+
+#if defined(_MSC_VER)
+/* Include otherwise unneeded header for MSVC compatibility. */
+#include 
+#endif
+
 #define __need_ptrdiff_t
 #define __need_size_t
 #define __need_wchar_t

Added: cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h?rev=360271&view=auto
==
--- cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h (added)
+++ cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h Wed May  8 10:15:21 2019
@@ -0,0 +1 @@
+#pragma once

Propchange: cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
--
svn:eol-style = native

Propchange: cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
--
svn:mime-type = text/plain

Added: cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h?rev=360271&view=auto
==
--- cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h (added)
+++ cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h Wed May  8 10:15:21 2019
@@ -0,0 +1 @@
+#pragma once

Propchange: cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
--
svn:eol-style = native

Propchange: cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
--
svn:mime-type = text/plain

Modified: cfe/trunk/test/Headers/c11.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/c11.c?rev=360271&r1=360270&r2=360271&view=diff
==
--- cfe/trunk/test/Headers/c11.c (original)
+++ cfe/trunk/test/Headers/c11.c Wed May  8 10:15:21 2019
@@ -2,7 +2,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -fmodules 
-fmodules-cache-path=%t %s -D__STDC_WANT_LIB_EXT1__=1
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -triple i686-pc-win32 
-fms-compatibility-version=17.00 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -triple i686-pc-win32 \
+// RUN:  -fms-compatibility-version=17.00 -isystem %S/Inputs/ms-crt %s
 
 noreturn int f(); // expected-error 1+{{}}
 

Added: cfe/trunk/test/Headers/ms-additional-includes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-additional-includes.cpp?rev=360271&view=auto

[PATCH] D61646: Include corecrt.h/vcruntime.h to improve MS compatibility

2019-05-08 Thread Mike Rice via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360271: Include corecrt.h in stddef.h and vcruntime.h in 
stdarg.h to improve MS (authored by mikerice, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61646?vs=198559&id=198694#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61646

Files:
  cfe/trunk/lib/Headers/stdarg.h
  cfe/trunk/lib/Headers/stddef.h
  cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
  cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
  cfe/trunk/test/Headers/c11.c
  cfe/trunk/test/Headers/ms-additional-includes.cpp
  cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp


Index: cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
===
--- cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
+++ cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -triple i686-pc-win32 -fms-compatibility 
-fms-compatibility-version=17.00 %s
+// RUN: %clang_cc1 -fsyntax-only -triple i686-pc-win32 -fms-compatibility \
+// RUN:  -isystem %S/Inputs/ms-crt -fms-compatibility-version=17.00 %s
 // RUN: %clang_cc1 -fsyntax-only -triple i386-mingw32 %s
 
 // Something in MSVC's headers (pulled in e.g. by ) defines __null
Index: cfe/trunk/test/Headers/c11.c
===
--- cfe/trunk/test/Headers/c11.c
+++ cfe/trunk/test/Headers/c11.c
@@ -2,7 +2,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -fmodules 
-fmodules-cache-path=%t %s -D__STDC_WANT_LIB_EXT1__=1
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -triple i686-pc-win32 
-fms-compatibility-version=17.00 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -triple i686-pc-win32 \
+// RUN:  -fms-compatibility-version=17.00 -isystem %S/Inputs/ms-crt %s
 
 noreturn int f(); // expected-error 1+{{}}
 
Index: cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
===
--- cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
+++ cfe/trunk/test/Headers/Inputs/ms-crt/corecrt.h
@@ -0,0 +1 @@
+#pragma once
Index: cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
===
--- cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
+++ cfe/trunk/test/Headers/Inputs/ms-crt/vcruntime.h
@@ -0,0 +1 @@
+#pragma once
Index: cfe/trunk/test/Headers/ms-additional-includes.cpp
===
--- cfe/trunk/test/Headers/ms-additional-includes.cpp
+++ cfe/trunk/test/Headers/ms-additional-includes.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only --show-includes -triple i686-pc-win32 \
+// RUN:  -isystem %S/Inputs/ms-crt -fms-compatibility-version=17.00 %s \
+// RUN:  | FileCheck %s
+
+#include 
+// CHECK: including file:{{.*}}stddef.h
+// CHECK: including file:{{.*}}corecrt.h
+#include 
+// CHECK: including file:{{.*}}stdarg.h
+// CHECK: including file:{{.*}}vcruntime.h
Index: cfe/trunk/lib/Headers/stdarg.h
===
--- cfe/trunk/lib/Headers/stdarg.h
+++ cfe/trunk/lib/Headers/stdarg.h
@@ -10,6 +10,11 @@
 #ifndef __STDARG_H
 #define __STDARG_H
 
+#if defined(_MSC_VER)
+/* Include otherwise unneeded header for MSVC compatibility. */
+#include 
+#endif
+
 #ifndef _VA_LIST
 typedef __builtin_va_list va_list;
 #define _VA_LIST
Index: cfe/trunk/lib/Headers/stddef.h
===
--- cfe/trunk/lib/Headers/stddef.h
+++ cfe/trunk/lib/Headers/stddef.h
@@ -18,6 +18,12 @@
 #if !__has_feature(modules)
 #define __STDDEF_H
 #endif
+
+#if defined(_MSC_VER)
+/* Include otherwise unneeded header for MSVC compatibility. */
+#include 
+#endif
+
 #define __need_ptrdiff_t
 #define __need_size_t
 #define __need_wchar_t


Index: cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
===
--- cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
+++ cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -triple i686-pc-win32 -fms-compatibility -fms-compatibility-version=17.00 %s
+// RUN: %clang_cc1 -fsyntax-only -triple i686-pc-win32 -fms-compatibility \
+// RUN:  -isystem %S/Inputs/ms-crt -fms-compatibility-version=17.00 %s
 // RUN: %clang_cc1 -fsyntax-only -triple i386-mingw32 %s
 
 // Something in MSVC's headers (pulled in e.g. by ) defines __null
Index: cfe/trunk/test/Headers/c11.c
===
--- cfe/trunk/test/Headers/c11.c
+++ cfe/trunk/test/Headers/c11.c
@@ -2,7

[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-08 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added inline comments.



Comment at: lldb/source/Symbol/ClangASTImporter.cpp:68
+  return *ret_or_error;
+} else {
+  Log *log =

aprantl wrote:
> The `else` is redundant.
Here it's necessary for the scope of `ret_or_error`. That's a bit unfortunate. 
Maybe invert the condition?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61438



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


[clang-tools-extra] r360277 - [clang-tidy] Update documentation on ReSharper integration.

2019-05-08 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed May  8 11:12:12 2019
New Revision: 360277

URL: http://llvm.org/viewvc/llvm-project?rev=360277&view=rev
Log:
[clang-tidy] Update documentation on ReSharper integration.

It's now possible to set custom clang-tidy binary.

Patch by Alexander Zaitsev!

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

Modified:
clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst?rev=360277&r1=360276&r2=360277&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst Wed May  8 
11:12:12 2019
@@ -34,7 +34,7 @@ well-known :program:`clang-tidy` integra
 
+--++-+--+-+--+
 |Qt Creator IDE| \+\|  
 \+\   |   \-\| \-\ 
|   \+\|
 
+--++-+--+-+--+
-|ReSharper C++ for Visual Studio   | \+\|  
 \+\   |   \-\| \+\ 
|   \-\|
+|ReSharper C++ for Visual Studio   | \+\|  
 \+\   |   \-\| \+\ 
|   \+\|
 
+--++-+--+-+--+
 |Syntastic for Vim | \+\|  
 \-\   |   \-\| \-\ 
|   \+\|
 
+--++-+--+-+--+


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


[PATCH] D61350: [clang-tidy] New check calling out uses of +new in Objective-C code

2019-05-08 Thread Michael Wyman via Phabricator via cfe-commits
mwyman added inline comments.



Comment at: clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp:112
+  Result.Nodes.getNodeAs("new_call")) {
+// Don't warn if the call expression originates from a macro expansion.
+if (isMessageExpressionInsideMacro(CallExpr))

stephanemoore wrote:
> If the message expression is within a macro expansion, maybe we should emit 
> the diagnostic without the fixit?
I'm leery of emitting a warning in a case where the code may not originate from 
the code in question. Maybe if the macro is defined in the same source file, 
but I think perhaps that could be a follow-up.


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

https://reviews.llvm.org/D61350



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


[PATCH] D61475: Update an information about ReSharper C++ and clang-tidy custom binary integration

2019-05-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360277: [clang-tidy] Update documentation on ReSharper 
integration. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61475?vs=197909&id=198700#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61475

Files:
  clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst


Index: clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
@@ -34,7 +34,7 @@
 
+--++-+--+-+--+
 |Qt Creator IDE| \+\|  
 \+\   |   \-\| \-\ 
|   \+\|
 
+--++-+--+-+--+
-|ReSharper C++ for Visual Studio   | \+\|  
 \+\   |   \-\| \+\ 
|   \-\|
+|ReSharper C++ for Visual Studio   | \+\|  
 \+\   |   \-\| \+\ 
|   \+\|
 
+--++-+--+-+--+
 |Syntastic for Vim | \+\|  
 \-\   |   \-\| \-\ 
|   \+\|
 
+--++-+--+-+--+


Index: clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
@@ -34,7 +34,7 @@
 +--++-+--+-+--+
 |Qt Creator IDE| \+\|   \+\   |   \-\| \-\ |   \+\|
 +--++-+--+-+--+
-|ReSharper C++ for Visual Studio   | \+\|   \+\   |   \-\| \+\ |   \-\|
+|ReSharper C++ for Visual Studio   | \+\|   \+\   |   \-\| \+\ |   \+\|
 +--++-+--+-+--+
 |Syntastic for Vim | \+\|   \-\   |   \-\| \-\ |   \+\|
 +--++-+--+-+--+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61350: [clang-tidy] New check calling out uses of +new in Objective-C code

2019-05-08 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 198702.
mwyman marked 2 inline comments as done.
mwyman added a comment.

Update for review comments.


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

https://reviews.llvm.org/D61350

Files:
  clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp
  clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.h
  clang-tools-extra/clang-tidy/google/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/google-objc-avoid-nsobject-new.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/google-objc-avoid-nsobject-new.m

Index: clang-tools-extra/test/clang-tidy/google-objc-avoid-nsobject-new.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/google-objc-avoid-nsobject-new.m
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s google-objc-avoid-nsobject-new %t
+
+@interface NSObject
++ (instancetype)new;
++ (instancetype)alloc;
+- (instancetype)init;
+@end
+
+@interface NSProxy  // Root class with no -init method.
+@end
+
+// NSDate provides a specific factory method.
+@interface NSDate : NSObject
++ (instancetype)date;
+@end
+
+// For testing behavior with Objective-C Generics.
+@interface NSMutableDictionary<__covariant KeyType, __covariant ObjectType> : NSObject
+@end
+
+@class NSString;
+
+#define ALLOCATE_OBJECT(_Type) [_Type new]
+
+void CheckSpecificInitRecommendations(void) {
+  NSObject *object = [NSObject new];
+  // CHECK-MESSAGES: [[@LINE-1]]:22: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
+  // CHECK-FIXES: [NSObject alloc] init];
+
+  NSDate *correctDate = [NSDate date];
+  NSDate *incorrectDate = [NSDate new];
+  // CHECK-MESSAGES: [[@LINE-1]]:27: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
+  // CHECK-FIXES: [NSDate date];
+
+  NSObject *macroCreated = ALLOCATE_OBJECT(NSObject);  // Shouldn't warn on macros.
+
+  NSMutableDictionary *dict = [NSMutableDictionary new];
+  // CHECK-MESSAGES: [[@LINE-1]]:31: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
+  // CHECK-FIXES: [NSMutableDictionary alloc] init];
+}
+
+@interface Foo : NSObject
++ (instancetype)new; // Declare again to suppress warning.
+- (instancetype)initWithInt:(int)anInt;
+- (instancetype)init __attribute__((unavailable));
+
+- (id)new;
+@end
+
+@interface Baz : Foo // Check unavailable -init through inheritance.
+@end
+
+@interface ProxyFoo : NSProxy
+@end
+
+void CallNewWhenInitUnavailable(void) {
+  Foo *foo = [Foo new];
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
+
+  Baz *baz = [Baz new];
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
+
+  // Instance method -new calls may be weird, but are not strictly forbidden.
+  Foo *bar = [[Foo alloc] initWithInt:4];
+  [bar new];
+
+  ProxyFoo *proxy = [ProxyFoo new];
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
+}
+
+@interface HasNewOverride : NSObject
+@end
+
+@implementation HasNewOverride
++ (instancetype)new {
+  return [[self alloc] init];
+}
+// CHECK-MESSAGES: [[@LINE-3]]:1: warning: classes should not override +new [google-objc-avoid-nsobject-new]
+@end
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -133,6 +133,7 @@
google-default-arguments
google-explicit-constructor
google-global-names-in-headers
+   google-objc-avoid-nsobject-new
google-objc-avoid-throwing-exception
google-objc-function-naming
google-objc-global-variable-declaration
Index: clang-tools-extra/docs/clang-tidy/checks/google-objc-avoid-nsobject-new.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/google-objc-avoid-nsobject-new.rst
@@ -0,0 +1,29 @@
+.. title:: clang-tidy - google-objc-avoid-nsobject-new
+
+google-objc-avoid-nsobject-new
+==
+
+Finds calls to ``+new`` or overrides of it, which are prohibited by the
+Google Objective-C style guide.
+
+The Google Objective-C style guide forbids calling ``+new`` or overriding it in
+class implementations, preferring ``+alloc`` and ``-init`` methods to
+instantiate objects.
+
+An example:
+
+.. code-block:: objc
+
+  NSDate *now = [NSDate new];
+  Foo *bar = [Foo new];
+
+Instead, code should use ``+alloc``/``-init`` or class factory methods.
+
+.. code-block:: objc
+
+  NSDate *now = [NSDate date];
+  Foo *bar = [[Foo alloc] init];
+
+This check corresponds to the Google Objective-C Style Guide rule
+`Do No

[PATCH] D61620: [NewPassManager] Add tuning option: LoopUnrolling [clang-change]

2019-05-08 Thread Alina Sbirlea via Phabricator via cfe-commits
asbirlea updated this revision to Diff 198704.
asbirlea added a comment.

Update test.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61620

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGen/loop-unroll.c


Index: test/CodeGen/loop-unroll.c
===
--- /dev/null
+++ test/CodeGen/loop-unroll.c
@@ -0,0 +1,55 @@
+// RUN: %clang -target x86_64 -S -c -O1 -funroll-loops -emit-llvm -o - %s | 
FileCheck %s -check-prefix=CHECK-ENABLE-UNROLL
+// RUN: %clang -target x86_64 -S -c -O1 -fno-unroll-loops -emit-llvm -o - %s | 
FileCheck %s -check-prefix=CHECK-DISABLE-UNROLL
+// RUN: %clang -target x86_64 -fexperimental-new-pass-manager -S -c -O1 
-funroll-loops -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK-ENABLE-UNROLL
+// RUN: %clang -target x86_64 -fexperimental-new-pass-manager -S -c -O1 
-fno-unroll-loops -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK-DISABLE-UNROLL
+
+// CHECK-ENABLE-UNROLL-LABEL: @for_test()
+// CHECK-ENABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]]
+// CHECK-ENABLE-UNROLL: [[FORBODY]]:
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label 
%[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
+// CHECK-ENABLE-UNROLL: [[FORBODY5]]:
+// CHECK-ENABLE-UNROLL: fmul
+// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: fmul
+// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: fmul
+// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: store
+
+// CHECK-DISABLE-UNROLL-LABEL: @for_test()
+// CHECK-DISABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]]
+// CHECK-DISABLE-UNROLL: [[FORBODY]]:
+// CHECK-DISABLE-UNROLL: store
+// CHECK-DISABLE-UNROLL-NOT: store
+// CHECK-DISABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label 
%[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
+// CHECK-DISABLE-UNROLL: [[FORBODY5]]:
+// CHECK-DISABLE-UNROLL: fmul
+// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: store
+// CHECK-DISABLE-UNROLL: fmul
+// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: store
+// CHECK-DISABLE-UNROLL-NOT: fmul
+// CHECK-DISABLE-UNROLL-NOT: fadd
+// CHECK-DISABLE-UNROLL-NOT: store
+
+#include 
+
+void for_test() {
+  double A[1000], B[1000];
+  int L = 500;
+  for (int i = 0; i < L; i++) {
+A[i] = i;
+  }
+  for (int i = 0; i < L; i++) {
+B[i] = A[i]*5;
+B[i]++;
+A[i] *= 7;
+A[i]++;
+  }
+  printf("%lf %lf\n", A[0], B[0]);
+}
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1026,6 +1026,7 @@
   }
 
   PipelineTuningOptions PTO;
+  PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
   // For historical reasons, loop interleaving is set to mirror setting for 
loop
   // unrolling.
   PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;


Index: test/CodeGen/loop-unroll.c
===
--- /dev/null
+++ test/CodeGen/loop-unroll.c
@@ -0,0 +1,55 @@
+// RUN: %clang -target x86_64 -S -c -O1 -funroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-UNROLL
+// RUN: %clang -target x86_64 -S -c -O1 -fno-unroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-UNROLL
+// RUN: %clang -target x86_64 -fexperimental-new-pass-manager -S -c -O1 -funroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-UNROLL
+// RUN: %clang -target x86_64 -fexperimental-new-pass-manager -S -c -O1 -fno-unroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-UNROLL
+
+// CHECK-ENABLE-UNROLL-LABEL: @for_test()
+// CHECK-ENABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]]
+// CHECK-ENABLE-UNROLL: [[FORBODY]]:
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label %[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
+// CHECK-ENABLE-UNROLL: [[FORBODY5]]:
+// CHECK-ENABLE-UNROLL: fmul
+// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: fmul
+// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: store
+// CHECK-ENABLE-UNROLL: fmul
+// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: store
+
+// CHECK-DISABLE-UNROLL-LABEL: @for_test()
+// CHECK-DISABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]]
+// CHECK-DISABLE-UNROLL: [[FORBODY]]:
+// CHECK-DISABLE-UNROLL: store
+// CHECK-DISABLE-UNROLL-NOT: store
+// CHECK-DISABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label %[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
+// CHECK-DISABLE-UNROLL: [[FORBODY5]]:
+// CHECK-DISABLE-UNROLL: fmul
+// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: store
+// CHECK-DISABLE-UNROLL: fmul
+// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: store
+// CHECK-DISABLE-UNROLL-NOT: fmul
+// CHECK-DISABLE-UNROLL-NOT: fadd
+// CH

[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2019-05-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I'm a little concerned about overloading the code model this way. Currently we 
have the levels tiny, small, medium, large. Default is the same as small in 
every way so far as I'm aware. On COFF, the code models are currently untested, 
so far as I know, and I've been assuming that any usage of the non-small code 
model more or less implies ELF, and that it would be reasonable to emit wrong 
code or a fatal error on such codepaths during LLVM codegen. Maybe we have some 
use cases for the other code models in MCJIT.

With this change, "default" is now a new level that implies not small, but not 
medium either. Basically, I'm concerned that if we add this feature under 
-mcode-model=small, users will play with -mcode-model=medium, and they'll run 
into LLVM backend fatal errors, crashes, or wrong code. So, before we do this, 
I'd like to do some testing of COFF with the other code models, and make sure 
that LLVM does something reasonable in the other models, before we encourage 
users to use this flag.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61670



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


[PATCH] D61646: Include corecrt.h/vcruntime.h to improve MS compatibility

2019-05-08 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Did I get the bug right that this adds almost 400kB to every file that includes 
stddef.h?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61646



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


[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-08 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Lex/Preprocessor.cpp:870-900
+  TokenSource Source;
   do {
+Source = TokenSource();
+
 switch (CurLexerKind) {
 case CLK_Lexer:
+  Source.InDirective = CurLexer->ParsingPreprocessorDirective;

ilya-biryukov wrote:
> rsmith wrote:
> > This is a lot of extra stuff to be doing in the main `Lex` loop. Adding one 
> > (perfectly-predicted) branch on `OnToken` seems like it should be fine, but 
> > this seems like a bit more added complexity than I'd prefer. I'd like some 
> > performance measurements of `-cc1 -Eonly` to see if this makes any real 
> > difference.
> Happy to do the measurements. Do you have a good collection of input files 
> for this in mind?
I think any large header should be fine for testing; I don't expect this to 
scale worse in the presence of lots of macro expansion or anything like that.



Comment at: clang/lib/Lex/Preprocessor.cpp:896
 case CLK_LexAfterModuleImport:
-  ReturnedToken = LexAfterModuleImport(Result);
+  Source.InDirective = true;
+

ilya-biryukov wrote:
> rsmith wrote:
> > This isn't a directive; these are normal tokens.
> Sorry if it's a silly question, just wanted to clarify I'm not missing 
> anything here.
> 
> These tokens are the name of the module,  "import-suffix" and the semicolon 
> that follows it?
> And they end up being used to build the AST for `ImportDecl`?
Right. LexAfterModuleImport is a pass-through lexing layer that takes special 
action on the ObjC `@import module.name;` and C++20 `import "header";` 
declarations, which are just normal phase 4 tokens.



Comment at: clang/lib/Lex/Preprocessor.cpp:956-957
   --LexLevel;
+  if (OnToken)
+OnToken(Result, Source);
 }

ilya-biryukov wrote:
> ilya-biryukov wrote:
> > ilya-biryukov wrote:
> > > rsmith wrote:
> > > > This seems like it's going to be extremely hard to use. If you just 
> > > > want the expanded token stream, then removing all the other calls to 
> > > > `OnToken` and only calling it here when `LexLevel == 0` will give you 
> > > > that.
> > > I've tried `LexLevel == 0 && IsNewToken` and it **almost** works.
> > > The only trouble left is dealing with the delayed parsing. E.g. I'm 
> > > getting the callbacks for the same tokens multiple times in cases like 
> > > parsing of method bodies.
> > > 
> > > Any ideas on how to best tackle this?
> > > 
> > > The example is:
> > > ```
> > > struct X {
> > >   int method() { return 10; }
> > >   int a = 10;
> > > };
> > > ```
> > > 
> > > Seeing multiple callbacks for `{ return 10; }` and `= 10;`, want to see 
> > > only the first one.
> > It almost works now, see the update revision.
> > Almost no tokens get reported by the callback twice now, except the 
> > following case.
> > Input:
> > ```
> > struct X {
> >   int method() { return method(); }
> > };
> > ```
> > After the body of the class, we get a an extra callback for `)` token from 
> > one of the functions under `ParsedLexedMethodDef`.
> > This seems to be happening only for parenthesis.
> More precisely, this happens from a following sequence of calls:
> 
> ```
> Lex() {LexLevel=0}
> CachingLex() {LexLevel=1} // which does not have a token in `CachedTokens`, 
> so it recurses into ...
> Lex() {LexLevel=1}// which results in a call to ...
> CurTokenLexer->Lex()
> ```
> 
> At this point `CurTokenLexer` returns a token of a pre-lexed method 
> definition, but the current implementation forgets that this was the case by 
> the time the token is processed at the the top of the callstack (`Lex() 
> {LexLevel=0}`).
> So the token ends up being reported by a callback.
Yeah, the parser messes with the token stream to support C++'s out-of-order 
parsing rule (among other things). Ignoring that here seems right. You might 
also want to make sure that calls to `EnterToken` are handled properly. The 
extra paren likely comes from such a call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885



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


[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2019-05-08 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Fair enough.

On GCC, where the mingw x86_64 default code model is medium, switching it to 
small gave a small but not insignificant save in code size (around 9KB on a 1,3 
MB DLL). On clang, where the default code model is small, getting rid of the 
extra refptrs didn't gain more than around 512 bytes on the same DLL. So I 
think it's fair to say this change isn't really important, especially not with 
the iffy handling of code model that it requires.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61670



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


[PATCH] D61646: Include corecrt.h/vcruntime.h to improve MS compatibility

2019-05-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D61646#1495517 , @thakis wrote:

> Did I get the bug right that this adds almost 400kB to every file that 
> includes stddef.h?


I didn't put much confidence in that number because it was with 
`-frewrite-includes` which adds line markers etc, but I did this and now I'm 
not sure I'm in favor anymore:

  $ du -h /c/Program\ Files\ \(x86\)/Microsoft\ Visual\ 
Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/include/sal.h
  212K/c/Program Files (x86)/Microsoft Visual 
Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/include/sal.h

I'm guessing that the main dependency that's leaking out of msvc's stddef.h is 
in fact sal.h, but I think we really *don't* want to include that if we can 
avoid it. I think we'd be doing users a favor by keeping those macros out of 
their compilation if they don't need them.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61646



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


[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2019-05-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Well, I'm curious what meaning GCC ascribes to a medium code model for COFF. Do 
they generate code to allow PE images larger than 2GB, or is it more like the 
ELF small code model, where they assume everything can be reached with RIP 
relative addressing?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61670



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


[PATCH] D18914: [clang-tidy] new readability-redundant-inline

2019-05-08 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

Thank you for the review input! After learning about `inlinehint`, I don't feel 
its worthwhile for me to continue this check.


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

https://reviews.llvm.org/D18914



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


[PATCH] D61667: Assume `__cxa_allocate_exception` returns an under-aligned memory on Darwin if the version of libc++abi isn't new enough to include the fix in r319123

2019-05-08 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Basic/AlignedExceptionObject.h:31
+  case llvm::Triple::MacOSX: // Earliest supporting version is 10.14.
+return llvm::VersionTuple(10U, 14U);
+  case llvm::Triple::IOS:

ldionne wrote:
> Would it make more sense to return the alignment directly here?
I agree: this should be a function returning the minimum expected exception 
alignment on the current target.  Also, why does this have its own header 
instead of being, say, a function on `TargetInfo`?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61667



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


[PATCH] D61667: Assume `__cxa_allocate_exception` returns an under-aligned memory on Darwin if the version of libc++abi isn't new enough to include the fix in r319123

2019-05-08 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Basic/AlignedExceptionObject.h:31
+  case llvm::Triple::MacOSX: // Earliest supporting version is 10.14.
+return llvm::VersionTuple(10U, 14U);
+  case llvm::Triple::IOS:

rjmccall wrote:
> ldionne wrote:
> > Would it make more sense to return the alignment directly here?
> I agree: this should be a function returning the minimum expected exception 
> alignment on the current target.  Also, why does this have its own header 
> instead of being, say, a function on `TargetInfo`?
Or `ASTContext` or something similar.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61667



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


[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2019-05-08 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D61670#1495535 , @rnk wrote:

> Well, I'm curious what meaning GCC ascribes to a medium code model for COFF. 
> Do they generate code to allow PE images larger than 2GB, or is it more like 
> the ELF small code model, where they assume everything can be reached with 
> RIP relative addressing?


Not entirely sure TBH (and browsing GCC code to find out isn't the easiest 
thing). The strange thing is that when outputting assembly with -S, gcc 
produces the exact same thing regardless of the -mcmodel parameter, even if the 
emitted object file is vastly different.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61670



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


[PATCH] D61646: Include corecrt.h/vcruntime.h to improve MS compatibility

2019-05-08 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I agree with that.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61646



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


[PATCH] D61646: Include corecrt.h/vcruntime.h to improve MS compatibility

2019-05-08 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

For the most part, these headers are going to be included in almost every 
compilation unit anyway since they will come in through other C/C++ library 
headers.  So this would presumably affect only a small numbers of compilation 
units that only include stddef.h and none of the others.

It’s been our experience that if a user has code that compiles fine with their 
current compiler, and it doesn’t compile with the new compiler, they just won’t 
use the new compiler.  Many don’t really care that it would work fine if they 
added #includes where needed.  So changes like this can really improve compiler 
uptake.  I guess it is a trade-off between helping users easily moving their 
code to clang or a possible small compile time improvement.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61646



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


[PATCH] D50993: [clangd] Increase stack size of the new threads on macOS

2019-05-08 Thread Brennan Vincent via Phabricator via cfe-commits
umanwizard added a comment.
Herald added a subscriber: dexonsmith.
Herald added a project: clang.

Is there any good reason not to land this? Clangd is crashing for me on macOS 
with stack overflow in the worker threads.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D50993



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


  1   2   >