Re: r359067 - [Builtins] Implement __builtin_is_constant_evaluated for use in C++2a

2019-05-08 Thread Eric Fiselier via cfe-commits
Sorry, I should have been on top of this.

/Eric

On Wed., May 8, 2019, 11:47 p.m. Richard Smith, 
wrote:

> I went ahead and did this in r360310.
>
> On Thu, 25 Apr 2019 at 14:31, Richard Smith  wrote:
> >
> > On Wed, 24 Apr 2019 at 19:28, Eric Fiselier via cfe-commits
> >  wrote:
> > > Do I just edit the HTML file directly?
> > > Or is it generated by something?
> >
> > Just edit the HTML file directly.
> >
> > > On Wed, Apr 24, 2019 at 3:35 PM Richard Smith 
> wrote:
> > >>
> > >> Thanks! Can you update cxx_status.html to mark P0595R2 as done?
> > >>
> > >> On Tue, 23 Apr 2019 at 19:21, Eric Fiselier via cfe-commits
> > >>  wrote:
> > >> >
> > >> > Author: ericwf
> > >> > Date: Tue Apr 23 19:23:30 2019
> > >> > New Revision: 359067
> > >> >
> > >> > URL: http://llvm.org/viewvc/llvm-project?rev=359067=rev
> > >> > Log:
> > >> > [Builtins] Implement __builtin_is_constant_evaluated for use in
> C++2a
> > >> >
> > >> > Summary:
> > >> > This patch implements `__builtin_is_constant_evaluated` as
> specifier by [P0595R2](https://wg21.link/p0595r2). It is built on the
> back of Bill Wendling's work for `__builtin_constant_p()`.
> > >> >
> > >> > More tests to come, but early feedback is appreciated.
> > >> >
> > >> > I plan to implement warnings for common mis-usages like those
> belowe in a following patch:
> > >> > ```
> > >> > void foo(int x) {
> > >> >   if constexpr (std::is_constant_evaluated())) { // condition is
> always `true`. Should use plain `if` instead.
> > >> >foo_constexpr(x);
> > >> >   } else {
> > >> > foo_runtime(x);
> > >> >   }
> > >> > }
> > >> > ```
> > >> >
> > >> >
> > >> >
> > >> > Reviewers: rsmith, MaskRay, bruno, void
> > >> >
> > >> > Reviewed By: rsmith
> > >> >
> > >> > Subscribers: dexonsmith, zoecarver, fdeazeve, kristina, cfe-commits
> > >> >
> > >> > Differential Revision: https://reviews.llvm.org/D55500
> > >> >
> > >> > Added:
> > >> > cfe/trunk/test/CodeGenCXX/builtin-is-constant-evaluated.cpp
> > >> > cfe/trunk/test/SemaCXX/builtin-is-constant-evaluated.cpp
> > >> > Modified:
> > >> > cfe/trunk/include/clang/Basic/Builtins.def
> > >> > cfe/trunk/lib/AST/ExprConstant.cpp
> > >> > cfe/trunk/lib/Basic/Builtins.cpp
> > >> > cfe/trunk/lib/CodeGen/CGDecl.cpp
> > >> > cfe/trunk/test/Sema/builtins.c
> > >> >
> > >> > Modified: cfe/trunk/include/clang/Basic/Builtins.def
> > >> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=359067=359066=359067=diff
> > >> >
> ==
> > >> > --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> > >> > +++ cfe/trunk/include/clang/Basic/Builtins.def Tue Apr 23 19:23:30
> 2019
> > >> > @@ -500,6 +500,7 @@ BUILTIN(__builtin_vsprintf, "ic*cC*a", "
> > >> >  BUILTIN(__builtin_vsnprintf, "ic*zcC*a", "nFP:2:")
> > >> >  BUILTIN(__builtin_thread_pointer, "v*", "nc")
> > >> >  BUILTIN(__builtin_launder, "v*v*", "nt")
> > >> > +LANGBUILTIN(__builtin_is_constant_evaluated, "b", "n", CXX_LANG)
> > >> >
> > >> >  // GCC exception builtins
> > >> >  BUILTIN(__builtin_eh_return, "vzv*", "r") // FIXME: Takes
> intptr_t, not size_t!
> > >> >
> > >> > Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> > >> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=359067=359066=359067=diff
> > >> >
> ==
> > >> > --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> > >> > +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Apr 23 19:23:30 2019
> > >> > @@ -8279,6 +8279,9 @@ bool IntExprEvaluator::VisitBuiltinCallE
> > >> >  return Success(false, E);
> > >> >}
> > >> >
> > >> > +  case Builtin::BI__builtin_is_constant_evaluated:
> > >> > +return Success(Info.InConstantContext, E);
> > >> > +
> > >> >case Builtin::BI__builtin_ctz:
> > >> >case Builtin::BI__builtin_ctzl:
> > >> >case Builtin::BI__builtin_ctzll:
> > >> > @@ -11139,6 +11142,7 @@ bool Expr::EvaluateAsConstantExpr(EvalRe
> > >> >EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;
> > >> >EvalInfo Info(Ctx, Result, EM);
> > >> >Info.InConstantContext = true;
> > >> > +
> > >> >if (!::Evaluate(Result.Val, Info, this))
> > >> >  return false;
> > >> >
> > >> >
> > >> > Modified: cfe/trunk/lib/Basic/Builtins.cpp
> > >> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=359067=359066=359067=diff
> > >> >
> ==
> > >> > --- cfe/trunk/lib/Basic/Builtins.cpp (original)
> > >> > +++ cfe/trunk/lib/Basic/Builtins.cpp Tue Apr 23 19:23:30 2019
> > >> > @@ -75,9 +75,12 @@ bool Builtin::Context::builtinIsSupporte
> > >> >bool OclCUnsupported = !LangOpts.OpenCL &&
> > >> >   (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
> > >> >bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs
> 

[PATCH] D41911: [clangd] Include scanner that finds compile commands for headers.

2019-05-08 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: clangd/IncludeScanner.cpp:75
+  bool WasEmpty = Queue.empty();
+  for (const auto  : Cmds) {
+QueueEntry E(Cmd, VFS);

Usually I'd try to not lock a loop, as a large number of compile commands now 
blocks other threads for a bit. Fairness might not matter here, though.



Comment at: clangd/IncludeScanner.cpp:97
+auto  = Queue.front();
+Lock.unlock();
+process(std::move(Entry));

I'd find it a bit more idiomatic to have two unique_locked blocks instead 
(easier to pull out a function when things grow etc), but I see it's annoying 
to have to default-construct an entry in that case :(
Given that I'd probably pull that into a function, but then we need to 
communicate Done. Sigh.



Comment at: clangd/IncludeScanner.cpp:100
+Lock.lock();
+Queue.pop_front();
+if (Queue.empty()) {

I'd try to write the code so multiple consumer threads would work - given that 
process() can't fail, why not pop in the locked session above?



Comment at: clangd/IncludeScanner.cpp:131
+  IgnoringDiagConsumer IgnoreDiags;
+  // XXX the VFS working directory is global state, this is unsafe.
+  Cmd.VFS->setCurrentWorkingDirectory(Cmd.Directory);

I assume that's a note to you that you want to change this?



Comment at: clangd/IncludeScanner.cpp:159
+  // When reusing flags, we add an explicit `-x cpp` to override the extension.
+  // TODO: copying CompilerInvocation would avoid this, and is more robust.
+  if (std::find(Cmd.CommandLine.begin(), Cmd.CommandLine.end(), "-x") ==

Wondering why we can't use one of the tooling abstractions here...


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D41911



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


[PATCH] D61716: Expose AtomicType

2019-05-08 Thread Henry Jen via Phabricator via cfe-commits
slowhog created this revision.
slowhog added reviewers: yvvan, jbcoe.
Herald added subscribers: cfe-commits, jfb, arphaman.
Herald added a project: clang.

Expose atomic type through the C API.


Repository:
  rC Clang

https://reviews.llvm.org/D61716

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

Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -108,6 +108,7 @@
 clang_Type_getObjCTypeArg
 clang_Type_getModifiedType
 clang_Type_getNullability
+clang_Type_getValueType
 clang_VerbatimBlockLineComment_getText
 clang_VerbatimLineComment_getText
 clang_HTMLTagComment_getAsString
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -115,6 +115,7 @@
 TKCASE(Elaborated);
 TKCASE(Pipe);
 TKCASE(Attributed);
+TKCASE(Atomic);
 default:
   return CXType_Unexposed;
   }
@@ -616,6 +617,7 @@
 TKIND(OCLEvent);
 TKIND(OCLQueue);
 TKIND(OCLReserveID);
+TKIND(Atomic);
   }
 #undef TKIND
   return cxstring::createRef(s);
@@ -1308,3 +1310,13 @@
   }
   return CXTypeNullability_Invalid;
 }
+
+CXType clang_Type_getValueType(CXType CT) {
+  QualType T = GetQualType(CT);
+  const Type *TP = T.getTypePtrOrNull();
+
+  if (TP && TP->getTypeClass() == Type::Atomic)
+return MakeCXType(cast(TP)->getValueType(), GetTU(CT));
+
+  return MakeCXType(QualType(), GetTU(CT));
+}
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -1573,6 +1573,13 @@
 PrintTypeTemplateArgs(CT, " [canonicaltemplateargs/%d=");
   }
 }
+/* Print the value type if it exists. */
+{
+  CXType VT = clang_Type_getValueType(T);
+  if (VT.kind != CXType_Invalid) {
+PrintTypeAndTypeKind(VT, " [valuetype=%s] [valuetypekind=%s]");
+  }
+}
 /* Print the modified type if it exists. */
 {
   CXType MT = clang_Type_getModifiedType(T);
Index: clang/test/Index/print-type.c
===
--- clang/test/Index/print-type.c
+++ clang/test/Index/print-type.c
@@ -22,13 +22,15 @@
 
 struct {
   struct {
-int x;
+_Atomic int x;
 int y;
   };
 } bar;
 
 void fun(struct { int x; int y; } *param);
 
+_Atomic(unsigned long) aul;
+
 // RUN: c-index-test -test-print-type %s | FileCheck %s
 // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0]
 // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1] [pointeetype=int] [pointeekind=Int]
@@ -70,4 +72,7 @@
 // CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
 // CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] [isAnonRecDecl=0]
 // CHECK: StructDecl=:24:3 (Definition) [type=struct (anonymous at {{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1]
+// CHECK: FieldDecl=x:25:17 (Definition) [type=_Atomic(int)] [typekind=Atomic] [valuetype=int] [valuetypekind=Int] [isPOD=0] [isAnonRecDecl=0]
+// CHECK: FieldDecl=y:26:9 (Definition) [type=int] [typekind=Int] [isPOD=1] [isAnonRecDecl=0]
 // CHECK: StructDecl=:30:10 (Definition) [type=struct (anonymous at {{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
+// CHECK: VarDecl=aul:32:24 [type=_Atomic(unsigned long)] [typekind=Atomic] [valuetype=unsigned long] [valuetypekind=ULong] [isPOD=0] [isAnonRecDecl=0]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 56
+#define CINDEX_VERSION_MINOR 57
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -3317,7 +3317,8 @@
 
   CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175,
 
-  CXType_ExtVector = 176
+  CXType_ExtVector = 176,
+  CXType_Atomic = 177
 };
 
 

Re: r359067 - [Builtins] Implement __builtin_is_constant_evaluated for use in C++2a

2019-05-08 Thread Richard Smith via cfe-commits
I went ahead and did this in r360310.

On Thu, 25 Apr 2019 at 14:31, Richard Smith  wrote:
>
> On Wed, 24 Apr 2019 at 19:28, Eric Fiselier via cfe-commits
>  wrote:
> > Do I just edit the HTML file directly?
> > Or is it generated by something?
>
> Just edit the HTML file directly.
>
> > On Wed, Apr 24, 2019 at 3:35 PM Richard Smith  wrote:
> >>
> >> Thanks! Can you update cxx_status.html to mark P0595R2 as done?
> >>
> >> On Tue, 23 Apr 2019 at 19:21, Eric Fiselier via cfe-commits
> >>  wrote:
> >> >
> >> > Author: ericwf
> >> > Date: Tue Apr 23 19:23:30 2019
> >> > New Revision: 359067
> >> >
> >> > URL: http://llvm.org/viewvc/llvm-project?rev=359067=rev
> >> > Log:
> >> > [Builtins] Implement __builtin_is_constant_evaluated for use in C++2a
> >> >
> >> > Summary:
> >> > This patch implements `__builtin_is_constant_evaluated` as specifier by 
> >> > [P0595R2](https://wg21.link/p0595r2). It is built on the back of Bill 
> >> > Wendling's work for `__builtin_constant_p()`.
> >> >
> >> > More tests to come, but early feedback is appreciated.
> >> >
> >> > I plan to implement warnings for common mis-usages like those belowe in 
> >> > a following patch:
> >> > ```
> >> > void foo(int x) {
> >> >   if constexpr (std::is_constant_evaluated())) { // condition is always 
> >> > `true`. Should use plain `if` instead.
> >> >foo_constexpr(x);
> >> >   } else {
> >> > foo_runtime(x);
> >> >   }
> >> > }
> >> > ```
> >> >
> >> >
> >> >
> >> > Reviewers: rsmith, MaskRay, bruno, void
> >> >
> >> > Reviewed By: rsmith
> >> >
> >> > Subscribers: dexonsmith, zoecarver, fdeazeve, kristina, cfe-commits
> >> >
> >> > Differential Revision: https://reviews.llvm.org/D55500
> >> >
> >> > Added:
> >> > cfe/trunk/test/CodeGenCXX/builtin-is-constant-evaluated.cpp
> >> > cfe/trunk/test/SemaCXX/builtin-is-constant-evaluated.cpp
> >> > Modified:
> >> > cfe/trunk/include/clang/Basic/Builtins.def
> >> > cfe/trunk/lib/AST/ExprConstant.cpp
> >> > cfe/trunk/lib/Basic/Builtins.cpp
> >> > cfe/trunk/lib/CodeGen/CGDecl.cpp
> >> > cfe/trunk/test/Sema/builtins.c
> >> >
> >> > Modified: cfe/trunk/include/clang/Basic/Builtins.def
> >> > URL: 
> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=359067=359066=359067=diff
> >> > ==
> >> > --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> >> > +++ cfe/trunk/include/clang/Basic/Builtins.def Tue Apr 23 19:23:30 2019
> >> > @@ -500,6 +500,7 @@ BUILTIN(__builtin_vsprintf, "ic*cC*a", "
> >> >  BUILTIN(__builtin_vsnprintf, "ic*zcC*a", "nFP:2:")
> >> >  BUILTIN(__builtin_thread_pointer, "v*", "nc")
> >> >  BUILTIN(__builtin_launder, "v*v*", "nt")
> >> > +LANGBUILTIN(__builtin_is_constant_evaluated, "b", "n", CXX_LANG)
> >> >
> >> >  // GCC exception builtins
> >> >  BUILTIN(__builtin_eh_return, "vzv*", "r") // FIXME: Takes intptr_t, not 
> >> > size_t!
> >> >
> >> > Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> >> > URL: 
> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=359067=359066=359067=diff
> >> > ==
> >> > --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> >> > +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Apr 23 19:23:30 2019
> >> > @@ -8279,6 +8279,9 @@ bool IntExprEvaluator::VisitBuiltinCallE
> >> >  return Success(false, E);
> >> >}
> >> >
> >> > +  case Builtin::BI__builtin_is_constant_evaluated:
> >> > +return Success(Info.InConstantContext, E);
> >> > +
> >> >case Builtin::BI__builtin_ctz:
> >> >case Builtin::BI__builtin_ctzl:
> >> >case Builtin::BI__builtin_ctzll:
> >> > @@ -11139,6 +11142,7 @@ bool Expr::EvaluateAsConstantExpr(EvalRe
> >> >EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;
> >> >EvalInfo Info(Ctx, Result, EM);
> >> >Info.InConstantContext = true;
> >> > +
> >> >if (!::Evaluate(Result.Val, Info, this))
> >> >  return false;
> >> >
> >> >
> >> > Modified: cfe/trunk/lib/Basic/Builtins.cpp
> >> > URL: 
> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=359067=359066=359067=diff
> >> > ==
> >> > --- cfe/trunk/lib/Basic/Builtins.cpp (original)
> >> > +++ cfe/trunk/lib/Basic/Builtins.cpp Tue Apr 23 19:23:30 2019
> >> > @@ -75,9 +75,12 @@ bool Builtin::Context::builtinIsSupporte
> >> >bool OclCUnsupported = !LangOpts.OpenCL &&
> >> >   (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
> >> >bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == 
> >> > OMP_LANG;
> >> > +  bool CPlusPlusUnsupported =
> >> > +  !LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG;
> >> >return !BuiltinsUnsupported && !MathBuiltinsUnsupported && 
> >> > !OclCUnsupported &&
> >> >   !OclC1Unsupported && !OclC2Unsupported && 

r360310 - [cxx_status] Mark support for std::is_constant_evaluated as done.

2019-05-08 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed May  8 20:49:47 2019
New Revision: 360310

URL: http://llvm.org/viewvc/llvm-project?rev=360310=rev
Log:
[cxx_status] Mark support for std::is_constant_evaluated as done.

Eric implemented this in r359067.

Modified:
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/www/cxx_status.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=360310=360309=360310=diff
==
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Wed May  8 20:49:47 2019
@@ -1023,7 +1023,7 @@ as the draft C++2a standard evolves.
 
   std::is_constant_evaluated
   http://wg21.link/p0595r2;>P0595R2
-  No
+  SVN
 
 
   Nested inline namespaces


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


[PATCH] D41911: [clangd] Include scanner that finds compile commands for headers.

2019-05-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.
Herald added subscribers: jfb, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Are there are plans to move forward with this sort of an include scanning 
approach?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D41911



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


r360302 - When typo-correcting a function name, consider correcting to a type name

2019-05-08 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed May  8 17:57:24 2019
New Revision: 360302

URL: http://llvm.org/viewvc/llvm-project?rev=360302=rev
Log:
When typo-correcting a function name, consider correcting to a type name
for a function-style cast.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/CXX/class/class.mem/p1.cpp
cfe/trunk/test/FixIt/fixit-unrecoverable.cpp
cfe/trunk/test/SemaCXX/typo-correction.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=360302=360301=360302=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed May  8 17:57:24 2019
@@ -2068,8 +2068,8 @@ bool Sema::DiagnoseEmptyLookup(Scope *S,
   AcceptableWithoutRecovery =
   isa(UnderlyingND) || isa(UnderlyingND);
 } else {
-  // FIXME: We found a keyword. Suggest it, but don't provide a fix-it
-  // because we aren't able to recover.
+  // FIXME: We found a keyword or a type. Suggest it, but don't provide a
+  // fix-it because we aren't able to recover.
   AcceptableWithoutRecovery = true;
 }
 

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=360302=360301=360302=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed May  8 17:57:24 2019
@@ -4996,7 +4996,9 @@ FunctionCallFilterCCC::FunctionCallFilte
 : NumArgs(NumArgs), HasExplicitTemplateArgs(HasExplicitTemplateArgs),
   CurContext(SemaRef.CurContext), MemberFn(ME) {
   WantTypeSpecifiers = false;
-  WantFunctionLikeCasts = SemaRef.getLangOpts().CPlusPlus && NumArgs == 1;
+  WantFunctionLikeCasts = SemaRef.getLangOpts().CPlusPlus &&
+  !HasExplicitTemplateArgs && NumArgs == 1;
+  WantCXXNamedCasts = HasExplicitTemplateArgs && NumArgs == 1;
   WantRemainingKeywords = false;
 }
 
@@ -5025,6 +5027,13 @@ bool FunctionCallFilterCCC::ValidateCand
   }
 }
 
+// A typo for a function-style cast can look like a function call in C++.
+if ((HasExplicitTemplateArgs ? getAsTypeTemplateDecl(ND) != nullptr
+ : isa(ND)) &&
+CurContext->getParentASTContext().getLangOpts().CPlusPlus)
+  // Only a class or class template can take two or more arguments.
+  return NumArgs <= 1 || HasExplicitTemplateArgs || isa(ND);
+
 // Skip the current candidate if it is not a FunctionDecl or does not 
accept
 // the current number of arguments.
 if (!FD || !(FD->getNumParams() >= NumArgs &&

Modified: cfe/trunk/test/CXX/class/class.mem/p1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.mem/p1.cpp?rev=360302=360301=360302=diff
==
--- cfe/trunk/test/CXX/class/class.mem/p1.cpp (original)
+++ cfe/trunk/test/CXX/class/class.mem/p1.cpp Wed May  8 17:57:24 2019
@@ -9,14 +9,14 @@ struct S
   static int v; //expected-error{{redefinition of 'v' as different kind of 
symbol}}
   int v; //expected-error{{duplicate member 'v'}}
   static int v; //expected-error{{redefinition of 'v' as different kind of 
symbol}}
-  enum EnumT { E = 10 };
+  enum EnumT { E = 10 }; // expected-note {{declared here}}
   friend struct M;
   struct X;  //expected-note{{forward declaration of 'S::X'}}
   friend struct X;
 };
 
 S::EnumT Evar = S::E; // ok
-S::EnumT Evar2 = EnumT(); //expected-error{{use of undeclared identifier 
'EnumT'}}
+S::EnumT Evar2 = EnumT(); //expected-error{{use of undeclared identifier 
'EnumT'; did you mean 'S::EnumT'?}}
 S::M m; //expected-error{{no type named 'M' in 'S'}}
 S::X x; //expected-error{{variable has incomplete type 'S::X'}}
 

Modified: cfe/trunk/test/FixIt/fixit-unrecoverable.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-unrecoverable.cpp?rev=360302=360301=360302=diff
==
--- cfe/trunk/test/FixIt/fixit-unrecoverable.cpp (original)
+++ cfe/trunk/test/FixIt/fixit-unrecoverable.cpp Wed May  8 17:57:24 2019
@@ -8,3 +8,10 @@
 float f(int y) {
   return static_cst(y); // expected-error{{use of undeclared identifier 
'static_cst'; did you mean 'static_cast'?}}
 }
+
+struct Foobar {}; // expected-note {{here}}
+template struct Goobar {}; // expected-note {{here}}
+void use_foobar() {
+  auto x = zoobar(); // expected-error {{did you mean 'Foobar'}}
+  auto y = zoobar(); // expected-error {{did you mean 'Goobar'}}
+}

Modified: cfe/trunk/test/SemaCXX/typo-correction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=360302=360301=360302=diff

[PATCH] D61709: [NewPM] Port HWASan

2019-05-08 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: philip.pfaffe, fedor.sergeev, chandlerc, phosek.
leonardchan added projects: LLVM, clang.
Herald added subscribers: hiraditya, srhines.

Port hardware assisted address sanitizer to new PM following the same 
guidelines as msan and tsan.

Changes:

- Separate `HWAddressSanitizer` into a pass class and a sanitizer class.
- Create new PM wrapper pass for the sanitizer class.
- Use the `getOrINsert` pattern for some module level initialization 
declarations.
- Update llvm tests and add clang test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61709

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/hwasan-new-pm.c
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
  llvm/test/Instrumentation/HWAddressSanitizer/basic.ll

Index: llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
===
--- llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
+++ llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
@@ -5,6 +5,12 @@
 ; RUN: opt < %s -hwasan -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-ZERO-BASED-SHADOW
 ; RUN: opt < %s -hwasan -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
 
+; Ensure than hwasan runs with the new PM pass
+; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=0 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-DYNAMIC-SHADOW
+; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=1 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-DYNAMIC-SHADOW
+; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-ZERO-BASED-SHADOW
+; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
+
 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @hwasan.module_ctor, i8* bitcast (void ()* @hwasan.module_ctor to i8*) }]
 ; CHECK: @__hwasan = private constant [0 x i8] zeroinitializer, section "__hwasan_frames", comdat($hwasan.module_ctor)
 
Index: llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
@@ -114,7 +114,7 @@
   initializeInstrOrderFileLegacyPassPass(Registry);
   initializeInstrProfilingLegacyPassPass(Registry);
   initializeMemorySanitizerLegacyPassPass(Registry);
-  initializeHWAddressSanitizerPass(Registry);
+  initializeHWAddressSanitizerLegacyPassPass(Registry);
   initializeThreadSanitizerLegacyPassPass(Registry);
   initializeSanitizerCoverageModulePass(Registry);
   initializeDataFlowSanitizerPass(Registry);
Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -11,6 +11,7 @@
 /// based on tagged addressing.
 //===--===//
 
+#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -164,22 +165,19 @@
 
 /// An instrumentation pass implementing detection of addressability bugs
 /// using tagged pointers.
-class HWAddressSanitizer : public FunctionPass {
+class HWAddressSanitizer {
 public:
-  // Pass identification, replacement for typeid.
-  static char ID;
-
-  explicit HWAddressSanitizer(bool CompileKernel = false, bool Recover = false)
-  : FunctionPass(ID) {
+  explicit HWAddressSanitizer(Module , bool CompileKernel = false,
+  bool Recover = false) {
 this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
 this->CompileKernel = ClEnableKhwasan.getNumOccurrences() > 0 ?
 ClEnableKhwasan : CompileKernel;
-  }
 
-  StringRef getPassName() const override { return "HWAddressSanitizer"; }
+initializeWithModule(M);
+  }
 
-  bool runOnFunction(Function ) override;
-  bool doInitialization(Module ) override;
+  bool instrumentFunction(Function );
+  void initializeWithModule(Module );
 
   void initializeCallbacks(Module );
 
@@ -279,29 +277,61 @@

[PATCH] D61707: [Preprocessor] Fix crash emitting note with framework location for "file not found" error.

2019-05-08 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: arphaman, erik.pilkington, jkorous.
Herald added a subscriber: dexonsmith.

A filename can be remapped with a header map to point to a framework
header and we can find the corresponding framework without the header.
But if the original filename doesn't have a remapped framework name,
we'll fail to find its location and will dereference a null pointer
during diagnostics emission.

Fix by tracking remappings better and emit the note only if a framework
is found before any of the remappings.

rdar://problem/48883447


https://reviews.llvm.org/D61707

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  
clang/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
  clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c

Index: clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
===
--- /dev/null
+++ clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
@@ -0,0 +1,20 @@
+// RUN: rm -f %t.hmap
+// RUN: %hmaptool write %S/Inputs/include-header-missing-in-framework/TestFramework.hmap.json %t.hmap
+// RUN: %clang_cc1 -fsyntax-only -F %S/Inputs -I %t.hmap -verify %s -DLATE_REMAPPING
+// RUN: %clang_cc1 -fsyntax-only -I %t.hmap -F %S/Inputs -verify %s
+
+// The test is similar to 'include-header-missing-in-framework.c' but covers
+// the case when a header is remapped to a framework-like path with a .hmap
+// file. And we can find the framework but not the header.
+
+#ifdef LATE_REMAPPING
+// Framework is found before remapping.
+#include 
+// expected-error@-1 {{'TestFramework/BeforeRemapping.h' file not found}}
+// expected-note@-2 {{did not find header 'BeforeRemapping.h' in framework 'TestFramework' (loaded from}}
+
+#else
+// Framework is found after remapping.
+#include "RemappedHeader.h"
+// expected-error@-1 {{'RemappedHeader.h' file not found}}
+#endif // LATE_REMAPPING
Index: clang/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
@@ -0,0 +1,7 @@
+{
+  "mappings" :
+{
+ "RemappedHeader.h" : "TestFramework/RemappedHeader.h",
+ "TestFramework/BeforeRemapping.h" : "TestFramework/AfterRemapping.h"
+}
+}
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -818,6 +818,7 @@
   }
 
   CurDir = nullptr;
+  bool HasBeenMapped = false;
 
   // If this is a system #include, ignore the user #include locs.
   unsigned i = isAngled ? AngledDirIdx : 0;
@@ -841,6 +842,7 @@
 i = CacheLookup.HitIdx;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
+  HasBeenMapped = true;
   if (IsMapped)
 *IsMapped = true;
 }
@@ -856,20 +858,24 @@
   // Check each directory in sequence to see if it contains this file.
   for (; i != SearchDirs.size(); ++i) {
 bool InUserSpecifiedSystemFramework = false;
-bool HasBeenMapped = false;
+bool HasBeenMappedInDir = false;
 bool IsFrameworkFoundInDir = false;
 const FileEntry *FE = SearchDirs[i].LookupFile(
 Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule,
 SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
-HasBeenMapped, MappedName);
-if (HasBeenMapped) {
+HasBeenMappedInDir, MappedName);
+if (HasBeenMappedInDir) {
   CacheLookup.MappedName =
   copyString(Filename, LookupFileCache.getAllocator());
+  HasBeenMapped = true;
   if (IsMapped)
 *IsMapped = true;
 }
 if (IsFrameworkFound)
-  *IsFrameworkFound |= IsFrameworkFoundInDir;
+  // Because we keep a filename remapped for subsequent search directory
+  // lookups, ignore IsFrameworkFoundInDir after the first remapping and not
+  // just for remapping in a current search directory.
+  *IsFrameworkFound |= (IsFrameworkFoundInDir && !HasBeenMapped);
 if (!FE) continue;
 
 CurDir = [i];
@@ -911,11 +917,10 @@
   return MSFE;
 }
 
-bool FoundByHeaderMap = !IsMapped ? false : *IsMapped;
 if (!Includers.empty())
   diagnoseFrameworkInclude(Diags, IncludeLoc,
Includers.front().second->getName(), Filename,
-   FE, isAngled, FoundByHeaderMap);
+   FE, isAngled, HasBeenMapped);
 
 // Remember this location for the next lookup we do.
 CacheLookup.HitIdx = i;
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ 

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

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



Comment at: clang/lib/Sema/SemaOverload.cpp:6369
 // very difficult. Ideally, we should handle them more gracefully.
-if (!EIA->getCond()->EvaluateWithSubstitution(
+if (EIA->getCond()->isValueDependent() ||
+!EIA->getCond()->EvaluateWithSubstitution(

This is treating value-dependent `enable_if` conditions as having failed. Is 
that really appropriate? (When do we call this with value-depnedent `enable_if` 
attributes? I'd expect it to only be called after substitution)


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] D56160: [clang-tidy] modernize-use-trailing-return-type check

2019-05-08 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber added a comment.

@aaron.ballman and @JonasToth: Thank you for the patience and all the feedback! 
It means a great deal to me to have a patch accepted here!




Comment at: clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:95-98
+if (!S->getQualifierLoc() && Name.isIdentifier() &&
+VisitUnqualName(Name.getAsIdentifierInfo()->getName()))
+  return false;
+return true;

aaron.ballman wrote:
> This can also be simplified into a single return statement rather than an 
> `if`, but it's less clear to me whether that's an improvement. WDYT?
Let's simplify it.



Comment at: clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:203
+  if (ContainsQualifiers + ContainsSpecifiers + ContainsSomethingElse > 1)
+return {};
+

aaron.ballman wrote:
> This should return `llvm::None`
I always wondered what the point of `llvm::None`, `std::nullopt` or 
`boost::none` is. When I write `return {};` it looks like i return an empty 
shell, exactly how I picture an empty optional in my head. That is why I prefer 
it this way. I will change it of course for this patch, but would you mind 
giving me a short reason, why `llvm::None` is preferable here?


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] 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.

By the way, index/Background.{cpp,h} also need to be changed to use the new 
API. I made that change locally and clangd with full project indexing is now 
working for me on macOS.


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


r360297 - Try to restore some clang test headers lost in r360291

2019-05-08 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Wed May  8 15:30:46 2019
New Revision: 360297

URL: http://llvm.org/viewvc/llvm-project?rev=360297=rev
Log:
Try to restore some clang test headers lost in r360291

I'm not sure why 'git llvm revert' removed them.

Added:
cfe/trunk/test/Headers/Inputs/
cfe/trunk/test/Headers/Inputs/include/
cfe/trunk/test/Headers/Inputs/include/cmath
cfe/trunk/test/Headers/Inputs/include/complex.h
cfe/trunk/test/Headers/Inputs/include/limits
cfe/trunk/test/Headers/Inputs/include/math.h
cfe/trunk/test/Headers/Inputs/include/setjmp.h
cfe/trunk/test/Headers/Inputs/include/stdint.h
cfe/trunk/test/Headers/Inputs/include/stdlib.h
cfe/trunk/test/Headers/Inputs/usr/
cfe/trunk/test/Headers/Inputs/usr/include/
cfe/trunk/test/Headers/Inputs/usr/include/float.h
cfe/trunk/test/Headers/Inputs/usr/include/math.h
cfe/trunk/test/Headers/Inputs/usr/include/tgmath.h

Added: cfe/trunk/test/Headers/Inputs/include/cmath
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/cmath?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/include/cmath (added)
+++ cfe/trunk/test/Headers/Inputs/include/cmath Wed May  8 15:30:46 2019
@@ -0,0 +1,5 @@
+#pragma once
+
+double sqrt(double);
+double pow(double, double);
+double modf(double, double*);

Added: cfe/trunk/test/Headers/Inputs/include/complex.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/complex.h?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/include/complex.h (added)
+++ cfe/trunk/test/Headers/Inputs/include/complex.h Wed May  8 15:30:46 2019
@@ -0,0 +1,3 @@
+#pragma once
+
+#define complex _Complex

Added: cfe/trunk/test/Headers/Inputs/include/limits
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/limits?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/include/limits (added)
+++ cfe/trunk/test/Headers/Inputs/include/limits Wed May  8 15:30:46 2019
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace std
+{
+struct __numeric_limits_base
+  {};
+template
+  struct numeric_limits : public __numeric_limits_base
+{};
+}

Added: cfe/trunk/test/Headers/Inputs/include/math.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/math.h?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/include/math.h (added)
+++ cfe/trunk/test/Headers/Inputs/include/math.h Wed May  8 15:30:46 2019
@@ -0,0 +1,5 @@
+#pragma once
+
+double sqrt(double);
+double pow(double, double);
+double modf(double, double*);

Added: cfe/trunk/test/Headers/Inputs/include/setjmp.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/setjmp.h?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/include/setjmp.h (added)
+++ cfe/trunk/test/Headers/Inputs/include/setjmp.h Wed May  8 15:30:46 2019
@@ -0,0 +1,8 @@
+#ifndef SETJMP_H
+#define SETJMP_H
+
+typedef struct {
+  int x[42];
+} jmp_buf;
+
+#endif

Added: cfe/trunk/test/Headers/Inputs/include/stdint.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/stdint.h?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/include/stdint.h (added)
+++ cfe/trunk/test/Headers/Inputs/include/stdint.h Wed May  8 15:30:46 2019
@@ -0,0 +1,19 @@
+#ifndef STDINT_H
+#define STDINT_H
+
+#ifdef __INT32_TYPE__
+typedef unsigned __INT32_TYPE__ uint32_t;
+#endif
+
+#ifdef __INT64_TYPE__
+typedef unsigned __INT64_TYPE__ uint64_t;
+#endif
+
+#ifdef __INTPTR_TYPE__
+typedef __INTPTR_TYPE__ intptr_t;
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+#else
+#error Every target should have __INTPTR_TYPE__
+#endif
+
+#endif /* STDINT_H */

Added: cfe/trunk/test/Headers/Inputs/include/stdlib.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/stdlib.h?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/include/stdlib.h (added)
+++ cfe/trunk/test/Headers/Inputs/include/stdlib.h Wed May  8 15:30:46 2019
@@ -0,0 +1,2 @@
+#pragma once
+typedef __SIZE_TYPE__ size_t;

Added: cfe/trunk/test/Headers/Inputs/usr/include/float.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/usr/include/float.h?rev=360297=auto
==
--- cfe/trunk/test/Headers/Inputs/usr/include/float.h (added)
+++ cfe/trunk/test/Headers/Inputs/usr/include/float.h Wed May  8 15:30:46 2019
@@ -0,0 +1,6 @@
+#ifndef SYSFLOAT_H
+#define SYSFLOAT_H
+
+#define 

[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#1495778 , @phosek wrote:

> This change broke our build which is using Clang and the 
> `x86_64-windows-msvc` target to cross-compile our EFI bootloader. Now the 
> compilation fails 
> 
>  because it cannot find Windows headers (as expected).  We're probably going 
> to work around the issue by setting `-U_MSC_VER`, but I'm going to start a 
> discussion whether we should maybe define a new target for EFI.


We could fix forward by conditionalizing this under __has_include or something 
like that, but I think there's enough reasons to say that perhaps we don't want 
to do this after all. I'll go ahead and revert this and we can discuss it more.

In D61646#1495597 , @mikerice wrote:

> 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.


This is true, and it's part of why I figured we should approve this. However, 
the fact that users actually encounter these issues suggests that there are 
actually files in the wild that only use stddef.h, so avoiding including sal.h 
for them might be worthwhile.

> 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.

That's certainly the case, but even considering clang's approach to GCC 
compatibility, we've always drawn the line somewhere around "system headers". 
We're willing to make changes to clang to accommodate code that the user cannot 
change: code from OS SDKs, glibc, Windows SDK, STL, etc, but we usually assume 
that the user is willing to put in some effort to make their code 
clang-compatible.


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


r360291 - Revert Include corecrt.h in stddef.h and vcruntime.h in stdarg.h to improve MS compatibility.

2019-05-08 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Wed May  8 15:01:20 2019
New Revision: 360291

URL: http://llvm.org/viewvc/llvm-project?rev=360291=rev
Log:
Revert Include corecrt.h in stddef.h and vcruntime.h in stdarg.h to improve MS 
compatibility.

This reverts r360271 (git commit a0933bd8ec1515167ea653f7ee788b8bbde27d51)

There are concerns on the review that this breaks EFI builds and that
the transitive includes (sal.h) are actually heavy enough that we might
care.

Removed:
cfe/trunk/test/Headers/Inputs/
cfe/trunk/test/Headers/ms-additional-includes.cpp
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=360291=360290=360291=diff
==
--- cfe/trunk/lib/Headers/stdarg.h (original)
+++ cfe/trunk/lib/Headers/stdarg.h Wed May  8 15:01:20 2019
@@ -10,11 +10,6 @@
 #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=360291=360290=360291=diff
==
--- cfe/trunk/lib/Headers/stddef.h (original)
+++ cfe/trunk/lib/Headers/stddef.h Wed May  8 15:01:20 2019
@@ -18,12 +18,6 @@
 #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

Modified: cfe/trunk/test/Headers/c11.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/c11.c?rev=360291=360290=360291=diff
==
--- cfe/trunk/test/Headers/c11.c (original)
+++ cfe/trunk/test/Headers/c11.c Wed May  8 15:01:20 2019
@@ -2,8 +2,7 @@
 // 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 \
-// RUN:  -fms-compatibility-version=17.00 -isystem %S/Inputs/ms-crt %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -triple i686-pc-win32 
-fms-compatibility-version=17.00 %s
 
 noreturn int f(); // expected-error 1+{{}}
 

Removed: cfe/trunk/test/Headers/ms-additional-includes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-additional-includes.cpp?rev=360290=auto
==
--- cfe/trunk/test/Headers/ms-additional-includes.cpp (original)
+++ cfe/trunk/test/Headers/ms-additional-includes.cpp (removed)
@@ -1,10 +0,0 @@
-// 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

Modified: cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp?rev=360291=360290=360291=diff
==
--- cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp (original)
+++ cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp Wed May  8 15:01:20 
2019
@@ -1,5 +1,4 @@
-// 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 i686-pc-win32 -fms-compatibility 
-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


___
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 Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

This change broke our build which is using Clang and the `x86_64-windows-msvc` 
target to cross-compile our EFI bootloader. Now the compilation fails 

 because it cannot find Windows headers (as expected).  We're probably going to 
work around the issue by setting `-U_MSC_VER`, but I'm going to start a 
discussion whether we should maybe define a new target for EFI.


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] 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/DiagnosticGroups.td:411
 def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
+def UnderalignedExcpObj : DiagGroup<"underaligned-exception-object">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;

Why is this name so clipped?



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6572
+  "The alignment of %0 (%1-bytes) is larger than the guaranteed alignment of "
+  "the memory Itanium C++ runtime returns (%2-bytes)">;
 def err_return_in_constructor_handler : Error<

Hyphens seem wrong here, and you're missing some words, and it shouldn't be 
capitalized.  How about:

"required alignment of type %0 (%1 bytes) is larger than the supported 
alignment of C++ exception objects on this target (%2 bytes)"



Comment at: include/clang/Basic/TargetInfo.h:643
+  /// runtime, such as those using the Itanium C++ ABI.
+  virtual unsigned getExnObjectAlignment() const {
+// Itanium says that an _Unwind_Exception has to be "double-word"

CharUnits?



Comment at: lib/Sema/SemaExprCXX.cpp:946
+  // is larger than the minimum alignment the libc++abi runtime guarantees.
+  if (Context.getTargetInfo().getTriple().isOSDarwin()) {
+CharUnits TypeAlign = Context.getTypeAlignInChars(Ty);

Why is this a Darwin-specific check?  Seems like it ought to be an 
Itanium-specific check, but it's equally applicable on Linux to highly-aligned 
types.


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] D61700: [clang-tidy] readability-redundant-declaration: fix false positive with C "extern inline"

2019-05-08 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre created this revision.
mgehre added reviewers: alexfh, danielmarjamaki.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

readability-redundant-declaration was diagnosing a redundant declaration
on "extern inline void f();", which is needed in C code to force an external 
definition
of the inline function f. (This is different to how inline behaves in C++).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61700

Files:
  clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
  clang-tools-extra/test/clang-tidy/readability-redundant-declaration.c
  clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp


Index: clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp
===
--- clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp
+++ clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp
@@ -68,3 +68,13 @@
 // CHECK-FIXES: {{^}}DEFINE(test);{{$}}
 
 } // namespace macros
+
+inline void g() {}
+
+inline void g(); // g
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration
+// CHECK-FIXES: {{^}}// g{{$}}
+
+extern inline void g(); // extern g
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant 'g' declaration
+// CHECK-FIXES: {{^}}// extern g{{$}}
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/readability-redundant-declaration.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-redundant-declaration.c
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s readability-redundant-declaration %t
+
+extern int Xyz;
+extern int Xyz; // Xyz
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Xyz' declaration 
[readability-redundant-declaration]
+// CHECK-FIXES: {{^}}// Xyz{{$}}
+int Xyz = 123;
+
+extern int A;
+extern int A, B;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'A' declaration
+// CHECK-FIXES: {{^}}extern int A, B;{{$}}
+
+extern int Buf[10];
+extern int Buf[10]; // Buf[10]
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Buf' declaration
+// CHECK-FIXES: {{^}}// Buf[10]{{$}}
+
+static int f();
+static int f(); // f
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration
+// CHECK-FIXES: {{^}}// f{{$}}
+static int f() {}
+
+inline void g() {}
+
+inline void g();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration
+
+// OK: Needed to emit an external definition.
+extern inline void g();
\ No newline at end of file
Index: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
@@ -18,6 +18,10 @@
 namespace tidy {
 namespace readability {
 
+AST_MATCHER(FunctionDecl, doesDeclarationForceExternallyVisibleDefinition) {
+  return Node.doesDeclarationForceExternallyVisibleDefinition();
+}
+
 RedundantDeclarationCheck::RedundantDeclarationCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -26,8 +30,10 @@
 void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   namedDecl(anyOf(varDecl(unless(isDefinition())),
-  functionDecl(unless(anyOf(isDefinition(), isDefaulted(),
-hasParent(friendDecl()))
+  functionDecl(unless(anyOf(
+  isDefinition(), isDefaulted(),
+  doesDeclarationForceExternallyVisibleDefinition(),
+  hasParent(friendDecl()))
   .bind("Decl"),
   this);
 }


Index: clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp
===
--- clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp
+++ clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp
@@ -68,3 +68,13 @@
 // CHECK-FIXES: {{^}}DEFINE(test);{{$}}
 
 } // namespace macros
+
+inline void g() {}
+
+inline void g(); // g
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration
+// CHECK-FIXES: {{^}}// g{{$}}
+
+extern inline void g(); // extern g
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant 'g' declaration
+// CHECK-FIXES: {{^}}// extern g{{$}}
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/readability-redundant-declaration.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-redundant-declaration.c
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s readability-redundant-declaration %t
+
+extern int Xyz;
+extern int 

[PATCH] D61697: [lit] Disable test on darwin when building shared libs.

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

@zturner, I only disabled this on Darwin because that's all I can test on right 
now.  Please let me know if there's a better way to do this or if it should 
fire on different platforms.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61697



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


[PATCH] D61697: [lit] Disable test on darwin when building shared libs.

2019-05-08 Thread Don Hinton via Phabricator via cfe-commits
hintonda created this revision.
hintonda added a reviewer: zturner.
Herald added subscribers: llvm-commits, delcypher.
Herald added projects: clang, LLVM.

This test fails to link shared libraries because tries to run
a copied version of clang-check to see if the mock version of libcxx
in the same directory can be loaded dynamically.  Since the test is
specifically designed not to look in the default just-built lib
directory, it must be disabled when building with
BUILD_SHARED_LIBS=ON.

Currently only disabling it on Darwin and basing it on the
enable_shared flag.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61697

Files:
  clang/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
  llvm/utils/lit/lit/llvm/config.py


Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -52,6 +52,8 @@
 # We should standardize on the former.
 features.add('system-linker-mach-o')
 features.add('system-darwin')
+if config.enable_shared:
+features.add("enable_shared")
 elif platform.system() == 'Windows':
 # For tests that require Windows to run.
 features.add('system-windows')
Index: clang/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
===
--- clang/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
+++ clang/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
@@ -16,5 +16,7 @@
 //
 // ^ -ccc-install-dir passed to unbreak tests on *BSD where
 //   getMainExecutable() relies on real argv[0] being passed
+//
+// UNSUPPORTED: enable_shared
 #include 
 vector v;


Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -52,6 +52,8 @@
 # We should standardize on the former.
 features.add('system-linker-mach-o')
 features.add('system-darwin')
+if config.enable_shared:
+features.add("enable_shared")
 elif platform.system() == 'Windows':
 # For tests that require Windows to run.
 features.add('system-windows')
Index: clang/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
===
--- clang/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
+++ clang/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
@@ -16,5 +16,7 @@
 //
 // ^ -ccc-install-dir passed to unbreak tests on *BSD where
 //   getMainExecutable() relies on real argv[0] being passed
+//
+// UNSUPPORTED: enable_shared
 #include 
 vector v;
___
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 Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

If you're happy with these two conditions, then I have no concerns with this 
moving forward:

- There is no implied stability for the content or format of the dump between 
major releases, other than that it be valid JSON; this should be stated 
explicitly in the documentation. (Compatibility between patch releases seems 
like something we can work out with the release manager, but I'm inclined to 
say we should make a best-effort attempt to preserve it.) If people want to 
build tools on this rather than on one of our stable APIs, they should expect 
to be broken in some way on every major release.
- There is no requirement for people maintaining the AST (changing or adding 
AST nodes) to update the dump output for modified AST nodes to show any new 
information -- unlike the existing -ast-dump, this is not just for debugging, 
but we should be able to treat it as if it were. Perhaps a better way to put 
it: there is no requirement that the information in this dump is complete, but 
the information that is dumped should be correct.

If you want stronger guarantees than that, then we should have a broader 
discussion to establish some community buy-in.


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] 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 updated this revision to Diff 198716.
ahatanak marked 3 inline comments as done.
ahatanak edited the summary of this revision.
ahatanak added a comment.

Move the code that was in `AlignedExceptionObject.h` to `getExnObjectAlignment` 
and remove the header.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61667

Files:
  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"*
   // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"* [[T1]] to i8*
-  // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 16 [[T2]], i8 0, i64 16, i1 false)
+  // UNALIGNED-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 [[T2]], i8 0, i64 16, i1 false)
+  // ALIGNED-NEXT: call void @llvm.memset.p0i8.i64(i8* align 16 [[T2]], i8 0, i64 16, i1 false)
 }
 }
 
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -941,6 +941,20 @@
 }
   }
 
+  // Issue a warning if the type of the thrown object requires an alignment that
+  

[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 marked an inline comment as done.
ahatanak 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:
> 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.
I moved the code in `alignedExceptionObjectMinVersion` to 
`getExnObjectAlignment` and deleted the header.


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] D24892: [clang-tidy] Add option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init

2019-05-08 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre updated this revision to Diff 198714.
mgehre added a comment.
Herald added a project: clang.

Implement review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D24892

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
  
clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp

Index: clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: [{key: "cppcoreguidelines-pro-type-member-init.UseAssignment", value: 1}]}" -- -std=c++11
+
+struct T {
+  int i;
+};
+
+struct S {
+  bool b;
+  // CHECK-FIXES: bool b = false;
+  char c;
+  // CHECK-FIXES: char c = 0;
+  signed char sc;
+  // CHECK-FIXES: signed char sc = 0;
+  unsigned char uc;
+  // CHECK-FIXES: unsigned char uc = 0U;
+  int i;
+  // CHECK-FIXES: int i = 0;
+  unsigned u;
+  // CHECK-FIXES: unsigned u = 0U;
+  long l;
+  // CHECK-FIXES: long l = 0L;
+  unsigned long ul;
+  // CHECK-FIXES: unsigned long ul = 0UL;
+  long long ll;
+  // CHECK-FIXES: long long ll = 0LL;
+  unsigned long long ull;
+  // CHECK-FIXES: unsigned long long ull = 0ULL;
+  float f;
+  // CHECK-FIXES: float f = 0.0F;
+  double d;
+  // CHECK-FIXES: double d = 0.0;
+  long double ld;
+  // CHECK-FIXES: double ld = 0.0L;
+  int *ptr;
+  // CHECK-FIXES: int *ptr = nullptr;
+  T t;
+  // CHECK-FIXES: T t{};
+  S() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields:
+};
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
@@ -33,6 +33,10 @@
zero-initialized during construction. For performance critical code, it may
be important to not initialize fixed-size array members. Default is `0`.
 
+.. option:: UseAssignment
+   If set to non-zero, the check will provide fix-its with literal initializers
+   (``int i = 0;``) instead of curly braces (``int i{};``).
+
 This rule is part of the "Type safety" profile of the C++ Core
 Guidelines, corresponding to rule Type.6. See
 https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-memberinit.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -63,6 +63,11 @@
 
 
 The improvements are...
+- Added `UseAssignment` option to `cppcoreguidelines-pro-type-member-init`
+
+  If set to true, the check will provide fix-its with literal initializers
+  (``int i = 0;``) instead of curly braces (``int i{};``).
+
 
 Improvements to clang-tidy
 --
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -65,6 +65,11 @@
 
   // Whether arrays need to be initialized or not. Default is false.
   bool IgnoreArrays;
+
+  // Whether fix-its for initialization of fundamental type use assignment
+  // instead of brace initalization. Only effective in C++11 mode. Default is
+  // false.
+  bool UseAssignment;
 };
 
 } // namespace cppcoreguidelines
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -251,7 +251,8 @@
 ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  IgnoreArrays(Options.get("IgnoreArrays", false)) {}
+  IgnoreArrays(Options.get("IgnoreArrays", false)),
+  UseAssignment(Options.getLocalOrGlobal("UseAssignment", false)) {}
 
 void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus)
@@ -315,6 +316,7 @@
 
 void 

[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


[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] 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] 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] 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] 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] 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] 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] 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] 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 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] 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] 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
+// 

[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 

[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=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 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


[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=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=360276=360277=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] 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


[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=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 

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=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=360270=360271=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=360270=360271=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=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=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=360270=360271=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=auto
==
--- 

[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


[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] 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] 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] 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] 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] 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] 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] 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 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] 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 );
 
+  /// 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  = 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 type 

[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=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);

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=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=360264=360265=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=360264=360265=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=360264=360265=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_CURRENT_SOURCE_DIR} ${f})
 endforeach( f 

[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


[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] 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=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 ,
+  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 ,
  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 the equivalence of 

[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, );
+  }
+}
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, );
+  }
+}
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 + 3.5, 

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=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=360260=360261=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=360260=360261=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 ,
+  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 ,
  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] 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 ) {
+  bool Report;
+  Lex(Result, Report);
+}
+
+void Preprocessor::Lex(Token , bool ) {
   ++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 , bool ) {
+void Preprocessor::CachingLex(Token , bool , bool ) {
   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   
@@ -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((Id));
   }
@@ -1341,6 +1349,12 @@
   /// Lex the next token for this preprocessor.
   void Lex(Token );
 
+private:
+  /// Lex the next token and tell whether it should be reported to OnToken
+  /// callback.
+  void Lex(Token , bool );
+
+public:
   /// Lex a token, forming a header-name token if possible.
   bool LexHeaderName(Token , bool AllowMacroExpansion = true);
 
@@ -2135,7 +2149,7 @@
 
   //======//
   // Caching stuff.
-  void CachingLex(Token , bool );
+  void CachingLex(Token , bool , bool );
 
   bool InCachingLexMode() const {
 // If the Lexer pointers are 0 and IncludeMacroStack is empty, it means
___
cfe-commits mailing 

[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] 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 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 ) {
+  bool Report;
+  Lex(Result, Report);
+}
+
+void Preprocessor::Lex(Token , bool ) {
   ++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 , bool ) {
+void Preprocessor::CachingLex(Token , bool , bool ) {
   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   
@@ -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((Id));
   }
@@ -1341,6 +1349,12 @@
   /// Lex the next token for this preprocessor.
   void Lex(Token );
 
+private:
+  /// Lex the next token and tell whether it should be reported to OnToken
+  /// callback.
+  void Lex(Token , bool );
+
+public:
   /// Lex a token, forming a header-name token if possible.
   bool LexHeaderName(Token , bool AllowMacroExpansion = true);
 
@@ -2135,7 +2149,7 @@
 
   //======//
   // Caching stuff.
-  void CachingLex(Token , bool );
+  void CachingLex(Token , bool , bool );
 
   bool InCachingLexMode() const {
 // If the Lexer pointers 

[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  : 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] 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] 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] 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] 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 ) 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 ,
+   const syntax::Token ,
+   const syntax::Token ) {
+  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 ) const {
   bool Invalid = false;
   const char *Start = SM.getCharacterData(location(), );
@@ -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  = 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 ) {
+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 ,
 const LangOptions ) {
   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 ) const;
+};
+inline bool operator==(const FileRange , const FileRange ) {
+  return std::tie(L.File, L.Begin, L.End) == std::tie(R.File, R.Begin, R.End);
+}
+inline bool operator!=(const FileRange , const FileRange ) {
+  return !(L == R);
+}
+/// For debugging purposes.
+llvm::raw_ostream <<(llvm::raw_ostream , const FileRange );
+
 /// 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 ) 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
+  /// are from different files or \p Last is located before \p First.
+  

[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=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 

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=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=360257=360258=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=360257=360258=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=360257=360258=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 local -> generic is permitted.
   if 

[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 , const std::string ) {
 ::time_t now;
 ::time();
@@ -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  : 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  : 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 (OverridenFileBuffer->second != 

[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] 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=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


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=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=360256=360257=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
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


[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 

[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] 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] 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=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


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=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=360255=360256=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] 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


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=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=360253=360254=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 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


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=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=360249=360250=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=360249=360250=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


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=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=360248=360249=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


[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 ,
  StringRef File) override {
-// Insert the current diagnostics engine.
-Context->setDiagnosticsEngine(());
+// Create and set diagnostics engine
+

[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  : 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] 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] 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] 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 ,
+   ASTContext ) {

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 <<(llvm::raw_ostream , const HoverInfo ) {
+  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] 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 ,
   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;
+  /// Set 

[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 <<(llvm::raw_ostream ,
+  const std::vector ) {

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] 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] 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] 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=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


  1   2   >