[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-08 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: include/clang/AST/Type.h:6552
+// as a scaled integer.
+std::string FixedPointValueToString(unsigned Radix, unsigned Scale,
+uint64_t Val);

ebevhan wrote:
> This should probably take an APInt or APSInt.
> 
> Also, is there a reason to only have it produce unsigned numbers?
Done. It initially took only unsigned numbers since the literals could only be 
unsigned, but it makes sense to take signed also.



Comment at: include/clang/Basic/LangOptions.def:306
 LANGOPT(FixedPoint, 1, 0, "fixed point types")
+LANGOPT(SameFBits, 1, 0,
+"unsigned and signed fixed point type having the same number of 
fractional bits")

ebevhan wrote:
> Is it safe to have this as a flag? What about making it a target property?
Can do, but if the point of this option is just to set the Unsigned FBits to 
their corresponding Signed FBits, then would it be better instead to just 
ignore this flag altogether and have the target explicitly override the default 
Unsigned values with the corresponding Signed vals?



Comment at: include/clang/Basic/TargetInfo.h:89
+  // corresponding unsaturated types.
+  unsigned char ShortAccumFBits, ShortAccumIBits;
+  unsigned char AccumFBits, AccumIBits;

ebevhan wrote:
> I suspect it's still possible to calculate the ibits based on the fbits, even 
> for _Accum.
> 
> Are the unsigned values needed? The fbits for unsigned _Fract are the same as 
> for signed _Fract if SameFBits is set, and +1 otherwise. The same should go 
> for unsigned _Accum, but I don't think it's entirely clear how this affects 
> the integral part.
Similar to the previous comment, if we choose to make SameFBits dependent 
on/controlled by the target, then I think it would be better for the target to 
explicitly specify the integral bits since there could be some cases where 
there may be padding (such as for unsigned _Accum types if this flag is set), 
and in this case, I think it should be explicit that the `bit_width != IBits + 
FBits`.

We also can't fill in that padding for the unsigned _Accum types as an extra 
integral bit since the standard says that `"each signed accum type has at least 
as many integral bits as its corresponding unsigned accum type".`

For the unsigned _Fract values, I think we can get rid of them if we choose to 
keep the flag instead, but it would no longer apply to unsigned _Accum types 
since it would allow for extra padding in these types and would conflict with 
the logic of `bit_width == IBits + FBits`

For now, I actually think the simplest option is to keep these target 
properties, but have the target override them individually, with checks to make 
sure the values adhere to the standard.



Comment at: lib/AST/ExprConstant.cpp:9427
+  const APSInt  = Result.getInt();
+  if (Value.isSigned() && Value.isMinSignedValue() && E->canOverflow()) {
+std::string Val =

ebevhan wrote:
> This doesn't saturate properly. Is that coming in a later patch?
Handling of saturated types will come in a later patch. For now this is focused 
on literals for which we cannot specify saturation.



Comment at: lib/Lex/LiteralSupport.cpp:1045
 
+bool NumericLiteralParser::GetFixedPointValue(uint64_t , unsigned Scale) {
+  assert(radix == 16 || radix == 10);

ebevhan wrote:
> This should take an APInt (and use APInts for processing) to store the result 
> in.
> 
> It should be possible to calculate exactly how many bits are needed to fit 
> the literal before you start reading the digits. Overflow should not be a 
> problem, but you might get precision loss in the fractional part. The 
> calculation in our version is `ceil(log2(10^(noof-digits))) + Scale` but ours 
> only handles normal decimal notation (123.456) so it might need to be 
> extended to handle exponents and hex.
I see. For the decimal exponent, the number of extra bits needed I think is 
`ceil(Exponent * log2(10))` which requires parsing the exponent before parsing 
the integral or fractional part, assuming the exponent is positive.

For hex, the number of digits needed just for the integral and fractional part 
is just 4x the number of digits given in the hex literal + the exponent if it 
is positive.

With a bit more math we could also trim down the number of digits needed, but I 
think it's safe just to use the max number of digits needed.



Comment at: lib/Sema/SemaExpr.cpp:1248
+  bool RHSFixed = RHSType->isFixedPointType();
+
+  if (LHSFixed && RHSFixed) {

ebevhan wrote:
> I don't see how these semantics work properly. The specification requires 
> that operations be done in the full precision of both types. You cannot 
> convert the types before performing the operation like this, since the 
> operation will not be done in full precision in that 

[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-08 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 150602.
leonardchan marked 14 inline comments as done.

Repository:
  rC Clang

https://reviews.llvm.org/D46915

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Expr.h
  include/clang/AST/OperationKinds.def
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TargetInfo.h
  include/clang/Driver/Options.td
  include/clang/Lex/LiteralSupport.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/AST/Type.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Edit/RewriteObjCFoundationAPI.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Index/USRGeneration.cpp
  lib/Lex/LiteralSupport.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Frontend/fixed_point.c
  test/Frontend/fixed_point_declarations.c
  test/Frontend/fixed_point_errors.c
  test/Frontend/fixed_point_same_fbits.c
  test/Frontend/fixed_point_validation.c
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -305,6 +305,10 @@
 K = CXCursor_IntegerLiteral;
 break;
 
+  case Stmt::FixedPointLiteralClass:
+llvm_unreachable("No cursor for FixedPointLiteralClass");
+break;
+
   case Stmt::FloatingLiteralClass:
 K = CXCursor_FloatingLiteral;
 break;
Index: test/Frontend/fixed_point_validation.c
===
--- /dev/null
+++ test/Frontend/fixed_point_validation.c
@@ -0,0 +1,19 @@
+// RUN: %clang -ffixed-point -S -emit-llvm -o - %s | lli -force-interpreter=true
+
+// Run simple validation tests
+
+#define assert(b) if (!(b)) { return 1; }
+
+int main(){
+  short _Accum s_accum = 0.0hk;
+  short _Accum s_accum2 = 2.0hk;
+  short _Fract s_fract = 0.999hr;
+  short _Fract s_fract2 = -0.999hr;
+
+  assert(s_accum == 0);
+
+  s_accum = s_accum2;
+
+  assert(s_accum == s_accum2);
+  assert(s_accum == 2);
+}
Index: test/Frontend/fixed_point_same_fbits.c
===
--- /dev/null
+++ test/Frontend/fixed_point_same_fbits.c
@@ -0,0 +1,28 @@
+// RUN: %clang -ffixed-point -S -emit-llvm -o - %s | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang -ffixed-point -fsame-fbits -S -emit-llvm -o - %s | FileCheck %s -check-prefix=SAME
+
+/* The scale for unsigned fixed point types should be the same as that of signed
+ * fixed point types when -fsame-fbits is enabled. */
+
+void func() {
+  unsigned short _Accum u_short_accum = 0.5uhk;
+  unsigned _Accum u_accum = 0.5uk;
+  unsigned long _Accum u_long_accum = 0.5ulk;
+  unsigned short _Fract u_short_fract = 0.5uhr;
+  unsigned _Fract u_fract = 0.5ur;
+  unsigned long _Fract u_long_fract = 0.5ulr;
+
+// DEFAULT: store i16 128, i16* %u_short_accum, align 2
+// DEFAULT: store i32 32768, i32* %u_accum, align 4
+// DEFAULT: store i64 2147483648, i64* %u_long_accum, align 8
+// DEFAULT: store i16 128, i16* %u_short_fract, align 2
+// DEFAULT: store i32 32768, i32* %u_fract, align 4
+// DEFAULT: store i64 2147483648, i64* %u_long_fract, align 8
+
+// SAME: store i16 64, i16* %u_short_accum, align 2
+// SAME: store i32 16384, i32* %u_accum, align 4
+// SAME: store i64 1073741824, i64* %u_long_accum, align 8
+// SAME: store i16 64, i16* %u_short_fract, align 2
+// SAME: store i32 16384, i32* %u_fract, align 4
+// SAME: store i64 1073741824, i64* %u_long_fract, align 8
+}
Index: test/Frontend/fixed_point_errors.c
===
--- test/Frontend/fixed_point_errors.c
+++ test/Frontend/fixed_point_errors.c
@@ -13,7 +13,6 @@
 _Sat long long _Fract sat_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
 _Sat unsigned long long _Fract sat_u_longlong_fract;  // expected-error{{'long long _Fract' is invalid}}
 
-
 /* Although _Complex types work with floating point numbers, the extension
  * provides no info for complex fixed point types. */
 
@@ -78,6 +77,50 @@
 _Sat int i;   // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'int'}}
 _Sat _Sat _Fract fract;   // expected-warning{{duplicate '_Sat' declaration specifier}}
 
+
+/* Literals that cannot fit into types */
+signed 

[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing marked 3 inline comments as done.
Higuoxing added a comment.

In https://reviews.llvm.org/D47687#1126607, @dexonsmith wrote:

> In https://reviews.llvm.org/D47687#1126074, @lebedev.ri wrote:
>
> > In https://reviews.llvm.org/D47687#1126032, @Higuoxing wrote:
> >
> > > In https://reviews.llvm.org/D47687#1125926, @rnk wrote:
> > >
> > > > @dexonsmith is there someone from Apple who can comment on 
> > > > rdar://8678458 and the merits of disabling this warning in macros? I 
> > > > strongly suspect the original report was dealing with code like 
> > > > `assert(x || y && "str");`, if so we can go forward with this.
> > > >
> > > > @chandlerc I know you've hit this behavior difference vs. GCC before. 
> > > > Any thoughts on the proposed change?
> > >
> > >
> > >
> > >
> > > In https://reviews.llvm.org/D47687#1125964, @dexonsmith wrote:
> > >
> > > > In https://reviews.llvm.org/D47687#1125926, @rnk wrote:
> > > >
> > > > > @dexonsmith is there someone from Apple who can comment on 
> > > > > rdar://8678458 and the merits of disabling this warning in macros? I 
> > > > > strongly suspect the original report was dealing with code like 
> > > > > `assert(x || y && "str");`, if so we can go forward with this.
> > > >
> > > >
> > > > There were two commits with this radar: r119537 and r119540.  The main 
> > > > motivation was a deeply nested macro that when "inlined" included the 
> > > > moral equivalent of `#define DOUBLE_OP(OP1, OP2, X, Y, Z) (X OP1 Y OP2 
> > > > Z)`.  There was terrible note spew when the warning fired in this case, 
> > > > and the use case for the macro made the warning un-actionable.  We 
> > > > decided to suppress the warning entirely:
> > > >
> > > > > As a general comment, the warning seems to be useless for macros; 
> > > > > I'll follow the example of warn_logical_instead_of_bitwise which 
> > > > > doesn't trigger for macros and I'll make the warning not warn for 
> > > > > macros.
> > >
> > >
> > > Hi, Thank you,
> > >
> > > I noticed that `warn_logical_instead_of_bitwise ` will also skip 
> > > parentheses checking in macros... well, this patch seems not so 
> > > necessary... both ok for me ... depends on all of you :-)
> >
> >
> > At worst, we can issue this warning in a new `-Wparentheses-in-macros` 
> > subgroup, which, if apple so insists, could be off-by-default.
> >  That would less worse than just completely silencing it for the entire 
> > world.
>
>
> I’d be fine with strengthening the existing warning as long as there is an 
> actionable fix-it.  I suspect if you suppress it when the relevant expression 
> is constructed from multiple macro arguments that will be good enough.


Thanks, currently, `[-Wparentheses | -Wlogical-op-parentheses]` will not emit 
warning for parentheses in macros. only if you add 
`[-Wlogical-op-parentheses-in-macros]` it will emit something like `'&&' within 
'||'` warning...

However, `'&' within '|'` checking was disabled in macros as well... I don't 
know if this patch meet the needs... if this patch was ok, then, just as 
@lebedev.ri said, Maybe we could add a `[-Wparentheses-in-macros]` subgroup and 
add these warning into this new group, in the future... depends on users :-) 
any suggestion?

Thanks


https://reviews.llvm.org/D47687



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


[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-08 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu accepted this revision.
ruiu added a comment.
This revision is now accepted and ready to land.

Well, I don't think that pointing out that we shouldn't convert strings between 
UTF8 and UTF16 back and forth is nitpicking, but yeah, this has already been 
addressed, so feel free to submit. LGTM.


https://reviews.llvm.org/D47578



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


r334339 - Use SmallPtrSet instead of SmallSet in places where we iterate over the set.

2018-06-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jun  8 17:30:45 2018
New Revision: 334339

URL: http://llvm.org/viewvc/llvm-project?rev=334339=rev
Log:
Use SmallPtrSet instead of SmallSet in places where we iterate over the set.

SmallSet forwards to SmallPtrSet for pointer types. SmallPtrSet supports 
iteration, but a normal SmallSet doesn't. So if it wasn't for the forwarding, 
this wouldn't work.

These places were found by hiding the begin/end methods in the SmallSet 
forwarding.

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=334339=334338=334339=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Jun  8 17:30:45 2018
@@ -1293,7 +1293,7 @@ void clang::EmbedBitcode(llvm::Module *M
 
   // Save llvm.compiler.used and remote it.
   SmallVector UsedArray;
-  SmallSet UsedGlobals;
+  SmallPtrSet UsedGlobals;
   Type *UsedElementType = Type::getInt8Ty(M->getContext())->getPointerTo(0);
   GlobalVariable *Used = collectUsedGlobalVariables(*M, UsedGlobals, true);
   for (auto *GV : UsedGlobals) {

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=334339=334338=334339=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jun  8 17:30:45 2018
@@ -15054,9 +15054,9 @@ void Sema::SetIvarInitializers(ObjCImple
 
 static
 void DelegatingCycleHelper(CXXConstructorDecl* Ctor,
-   llvm::SmallSet ,
-   llvm::SmallSet ,
-   llvm::SmallSet ,
+   llvm::SmallPtrSet ,
+   llvm::SmallPtrSet ,
+   llvm::SmallPtrSet ,
Sema ) {
   if (Ctor->isInvalidDecl())
 return;
@@ -15118,7 +15118,7 @@ void DelegatingCycleHelper(CXXConstructo
 
 
 void Sema::CheckDelegatingCtorCycles() {
-  llvm::SmallSet Valid, Invalid, Current;
+  llvm::SmallPtrSet Valid, Invalid, Current;
 
   for (DelegatingCtorDeclsType::iterator
  I = DelegatingCtorDecls.begin(ExternalSource),
@@ -15126,9 +15126,7 @@ void Sema::CheckDelegatingCtorCycles() {
I != E; ++I)
 DelegatingCycleHelper(*I, Valid, Invalid, Current, *this);
 
-  for (llvm::SmallSet::iterator CI = Invalid.begin(),
- CE = Invalid.end();
-   CI != CE; ++CI)
+  for (auto CI = Invalid.begin(), CE = Invalid.end(); CI != CE; ++CI)
 (*CI)->setInvalidDecl();
 }
 


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


[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-08 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

ruiu: This review has now gone on for a week, with one cycle per day due to 
timezones. Since the comments are fairly minor nits, do you think you could 
address them yourself while landing this, in the interest of not spending 
another week on this?


https://reviews.llvm.org/D47578



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


[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-06-08 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In https://reviews.llvm.org/D45015#1121762, @EricWF wrote:

> In https://reviews.llvm.org/D45015#1121581, @ahatanak wrote:
>
> > Could you elaborate on what kind of changes you are planning to make in 
> > libc++ after committing this patch?
>
>
> Libc++ shouldn't actually need any changes if this current patch lands. 
> Currently libc++ is in a "incorrect" state where
>  it generates calls to `__builtin_operator_new(size_t, align_val_t)` when 
> `__cpp_aligned_new` is defined but when aligned new/delete
>  are actually unavailable.
>
> If we change `__cpp_aligned_new` to no longer be defined when aligned new is 
> unavailable, then libc++ will start doing the right thing.
>  See r328180 
> 
>  for the relevent commits which made these libc++ changes.


Looks like in libc++ we need to remove `_LIBCPP_STD_VER` check for aligned 
allocations, something like

   #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \
  -(!(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER > 14 || \
  +(!(defined(_LIBCPP_BUILDING_NEW) || \
   (defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606)))
   # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
   #endif

Is that correct? I didn't check the rest of the code, probably 
TEST_HAS_NO_ALIGNED_ALLOCATION needs some clean up too.


https://reviews.llvm.org/D45015



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


[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-06-08 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Sorry for the churn but can you please take out `-nostdinc++` part out of this 
change? After more thinking and discussion we think there is a chance 
developers can use `-nostdinc++` not only for building the standard library. 
`-nostdinc++` is a signal of building the standard library but it's not strong 
enough. Most likely developers will be unaware how `-nostdinc++` affects 
aligned allocations and that can lead to linker failures at runtime. So if you 
deploy on older macOS versions it is safer to assume aligned allocation isn't 
available. But if you provide your own libc++ with aligned allocations, you can 
still use `-faligned-allocation` to make that work. For now we prefer to use 
that approach and if it proves to be too onerous for developers, we can 
reintroduce `-nostdinc++` logic.

For building libc++ we rely on `_LIBCPP_BUILDING_NEW` to have support for 
aligned allocations even though the build host doesn't support them. So we 
don't need to change libc++ build.


https://reviews.llvm.org/D45015



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


[PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-08 Thread David Majnemer via Phabricator via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D47875



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


[PATCH] D47964: Modified protobuf and converter to add new signature, remove conditionals.

2018-06-08 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman created this revision.
emmettneyman added reviewers: kcc, morehouse, vitalybuka.
Herald added a subscriber: cfe-commits.

Cahnged the function signature and removed conditionals from loop body.


Repository:
  rC Clang

https://reviews.llvm.org/D47964

Files:
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp

Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -36,11 +36,23 @@
 std::ostream <<(std::ostream , const Const ) {
   return os << "(" << x.val() << ")";
 }
+std::ostream <<(std::ostream , const VarRef ) {
+  switch (x.arr()) {
+case VarRef::ARR_A:
+  return os << "a[i]";
+case VarRef::ARR_B:
+  return os << "b[i]";
+case VarRef::ARR_C:
+  return os << "c[i]";
+  }
+}
 std::ostream <<(std::ostream , const Rvalue ) {
   if (x.has_cons())
 return os << x.cons();
   if (x.has_binop())
 return os << x.binop();
+  if (x.has_varref())
+return os << x.varref();
   return os << "1";
 }
 std::ostream <<(std::ostream , const BinaryOp ) {
@@ -92,27 +104,24 @@
   return os << x.right() << ")";
 }
 std::ostream <<(std::ostream , const AssignmentStatement ) {
-  return os << "a[i]=" << x.rvalue();
+  return os << x.varref() << "=" << x.rvalue() << ";\n";
 }
 std::ostream <<(std::ostream , const IfElse ) {
   return os << "if (" << x.cond() << "){\n"
 << x.if_body() << "} else { \n"
 << x.else_body() << "}\n";
 }
 std::ostream <<(std::ostream , const Statement ) {
-  if (x.has_assignment())
-return os << x.assignment() << ";\n";
-  if (x.has_ifelse())
-return os << x.ifelse();
-  return os << "(void)0;\n";
+  return os << x.assignment();
 }
 std::ostream <<(std::ostream , const StatementSeq ) {
   for (auto  : x.statements())
 os << st;
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "void foo(int *a, size_t s) {\n"
+  return os << "#include \"foo.h\"\n" // This line is just for testing
+<< "void foo(int *a, int *b, int *__restrict__ c, size_t s) {\n"
 << "for (int i=0; i___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47301: Warning for framework include violation from Headers to PrivateHeaders

2018-06-08 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: lib/Lex/HeaderSearch.cpp:683
+  // from Foo.framework/PrivateHeaders, since this violates public/private
+  // api boundaries and can cause modular dependency cycles.
+  if (!IsIncluderPrivateHeader && IsIncludeeInFramework &&

Please capitalize "api". The rest looks good.


https://reviews.llvm.org/D47301



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


r334334 - [X86] Add avx512 feature flags to __builtin_ia32_select*.

2018-06-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jun  8 15:19:42 2018
New Revision: 334334

URL: http://llvm.org/viewvc/llvm-project?rev=334334=rev
Log:
[X86] Add avx512 feature flags to __builtin_ia32_select*.

There are many masked intrinsics that just wrap a select around a legacy 
intrinsic from a pre-avx512 instruciton set. If that intrinsic is implemented 
as a macro, nothing prevents it from being used when only the older feature was 
enabled. This likely generates very poor code since we don't have a good way to 
convert from the scalar masked type used by the intrinsic into a vector control 
for a legacy blend instruction. If we even have a blend instruction to use.

By adding a feature to the select builtins we can prevent and diagnose misuse 
of these intrinsics.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334334=334333=334334=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Jun  8 15:19:42 2018
@@ -1793,24 +1793,24 @@ TARGET_BUILTIN(__builtin_ia32_vpmultishi
 TARGET_BUILTIN(__builtin_ia32_vpmultishiftqb256_mask, "V32cV32cV32cV32cUi", 
"nc", "avx512vbmi,avx512vl")
 
 // generic select intrinsics
-TARGET_BUILTIN(__builtin_ia32_selectb_128, "V16cUsV16cV16c", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectb_256, "V32cUiV32cV32c", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectb_512, "V64cULLiV64cV64c", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectw_128, "V8sUcV8sV8s", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectw_256, "V16sUsV16sV16s", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectw_512, "V32sUiV32sV32s", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectd_128, "V4iUcV4iV4i", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectd_256, "V8iUcV8iV8i", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectd_512, "V16iUsV16iV16i", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectq_128, "V2LLiUcV2LLiV2LLi", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectq_256, "V4LLiUcV4LLiV4LLi", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectq_512, "V8LLiUcV8LLiV8LLi", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectps_128, "V4fUcV4fV4f", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectps_256, "V8fUcV8fV8f", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectps_512, "V16fUsV16fV16f", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectpd_128, "V2dUcV2dV2d", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectpd_256, "V4dUcV4dV4d", "nc", "")
-TARGET_BUILTIN(__builtin_ia32_selectpd_512, "V8dUcV8dV8d", "nc", "")
+TARGET_BUILTIN(__builtin_ia32_selectb_128, "V16cUsV16cV16c", "nc", 
"avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectb_256, "V32cUiV32cV32c", "nc", 
"avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectb_512, "V64cULLiV64cV64c", "nc", 
"avx512bw")
+TARGET_BUILTIN(__builtin_ia32_selectw_128, "V8sUcV8sV8s", "nc", 
"avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectw_256, "V16sUsV16sV16s", "nc", 
"avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectw_512, "V32sUiV32sV32s", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_selectd_128, "V4iUcV4iV4i", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectd_256, "V8iUcV8iV8i", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectd_512, "V16iUsV16iV16i", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_selectq_128, "V2LLiUcV2LLiV2LLi", "nc", 
"avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectq_256, "V4LLiUcV4LLiV4LLi", "nc", 
"avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectq_512, "V8LLiUcV8LLiV8LLi", "nc", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_selectps_128, "V4fUcV4fV4f", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectps_256, "V8fUcV8fV8f", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectps_512, "V16fUsV16fV16f", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_selectpd_128, "V2dUcV2dV2d", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectpd_256, "V4dUcV4dV4d", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_selectpd_512, "V8dUcV8dV8d", "nc", "avx512f")
 
 // MONITORX/MWAITX
 TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "n", "mwaitx")


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


r334331 - [X86] Add back some masked vector truncate builtins. Custom IRgen a a few others.

2018-06-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jun  8 14:50:08 2018
New Revision: 334331

URL: http://llvm.org/viewvc/llvm-project?rev=334331=rev
Log:
[X86] Add back some masked vector truncate builtins. Custom IRgen a a few 
others.

I'd like to make the select builtins require an avx512f, avx512bw, or avx512vl 
fature to match what is normally required to get masking. Truncate is special 
in that there are instructions with a 128/256-bit masked result even without 
avx512vl.

By using special buitlins we can emit a select without using the 128/256-bit 
select builtins.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512fintrin.h

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334331=334330=334331=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Jun  8 14:50:08 2018
@@ -1298,6 +1298,7 @@ TARGET_BUILTIN(__builtin_ia32_vpshrdw512
 
 TARGET_BUILTIN(__builtin_ia32_pmovswb512_mask, "V32cV32sV32cUi", "nc", 
"avx512bw")
 TARGET_BUILTIN(__builtin_ia32_pmovuswb512_mask, "V32cV32sV32cUi", "nc", 
"avx512bw")
+TARGET_BUILTIN(__builtin_ia32_pmovwb512_mask, "V32cV32sV32cUi", "nc", 
"avx512bw")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq128_mask, "V2LLiV2dV2LLiUc", "nc", 
"avx512vl,avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2qq256_mask, "V4LLiV4dV4LLiUc", "nc", 
"avx512vl,avx512dq")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2uqq128_mask, "V2LLiV2dV2LLiUc", "nc", 
"avx512vl,avx512dq")
@@ -1648,6 +1649,7 @@ TARGET_BUILTIN(__builtin_ia32_pmovdw512_
 TARGET_BUILTIN(__builtin_ia32_pmovdw512mem_mask, "vV16s*V16iUs", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512_mask, "V16cV8LLiV16cUc", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqb512mem_mask, "vV16c*V8LLiUc", "n", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmovqd512_mask, "V8iV8LLiV8iUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqd512mem_mask, "vV8i*V8LLiUc", "n", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqw512_mask, "V8sV8LLiV8sUc", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pmovqw512mem_mask, "vV8s*V8LLiUc", "n", 
"avx512f")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334331=334330=334331=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Jun  8 14:50:08 2018
@@ -9309,6 +9309,35 @@ Value *CodeGenFunction::EmitX86BuiltinEx
makeArrayRef(Indices, DstNumElts),
"insert");
   }
+  case X86::BI__builtin_ia32_pmovqd512_mask:
+  case X86::BI__builtin_ia32_pmovwb512_mask: {
+Value *Res = Builder.CreateTrunc(Ops[0], Ops[1]->getType());
+return EmitX86Select(*this, Ops[2], Res, Ops[1]);
+  }
+  case X86::BI__builtin_ia32_pmovdb512_mask:
+  case X86::BI__builtin_ia32_pmovdw512_mask:
+  case X86::BI__builtin_ia32_pmovqw512_mask: {
+if (const auto *C = dyn_cast(Ops[2]))
+  if (C->isAllOnesValue())
+return Builder.CreateTrunc(Ops[0], Ops[1]->getType());
+
+Intrinsic::ID IID;
+switch (BuiltinID) {
+default: llvm_unreachable("Unsupported intrinsic!");
+case X86::BI__builtin_ia32_pmovdb512_mask:
+  IID = Intrinsic::x86_avx512_mask_pmov_db_512;
+  break;
+case X86::BI__builtin_ia32_pmovdw512_mask:
+  IID = Intrinsic::x86_avx512_mask_pmov_dw_512;
+  break;
+case X86::BI__builtin_ia32_pmovqw512_mask:
+  IID = Intrinsic::x86_avx512_mask_pmov_qw_512;
+  break;
+}
+
+Function *Intr = CGM.getIntrinsic(IID);
+return Builder.CreateCall(Intr, Ops);
+  }
   case X86::BI__builtin_ia32_pblendw128:
   case X86::BI__builtin_ia32_blendpd:
   case X86::BI__builtin_ia32_blendps:

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=334331=334330=334331=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512bwintrin.h Fri Jun  8 14:50:08 2018
@@ -1080,21 +1080,23 @@ _mm512_maskz_cvtusepi16_epi8 (__mmask32
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS
 _mm512_cvtepi16_epi8 (__m512i __A) {
-  return (__m256i)__builtin_convertvector((__v32hi)__A, __v32qi);
+  return (__m256i) __builtin_ia32_pmovwb512_mask ((__v32hi) __A,
+  (__v32qi) _mm256_undefined_si256(),
+  (__mmask32) -1);
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS
 _mm512_mask_cvtepi16_epi8 (__m256i __O, __mmask32 __M, __m512i __A) {
-  return 

r334330 - [X86] Fold masking into subvector extract builtins.

2018-06-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jun  8 14:50:07 2018
New Revision: 334330

URL: http://llvm.org/viewvc/llvm-project?rev=334330=rev
Log:
[X86] Fold masking into subvector extract builtins.

I'm looking into making the select builtins require avx512f, avx512bw, or 
avx512vl since masking operations generally require those features.

The extract builtins are funny because the 512-bit versions return a 128 or 256 
bit vector with masking even when avx512vl is not supported.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx512dqintrin.h
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vldqintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334330=334329=334330=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Jun  8 14:50:07 2018
@@ -947,8 +947,8 @@ TARGET_BUILTIN(__builtin_ia32_alignd128,
 TARGET_BUILTIN(__builtin_ia32_alignd256, "V8iV8iV8iIi", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_alignq128, "V2LLiV2LLiV2LLiIi", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_alignq256, "V4LLiV4LLiV4LLiIi", "nc", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_extractf64x4, "V4dV8dIi", "nc", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_extractf32x4, "V4fV16fIi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_extractf64x4_mask, "V4dV8dIiV4dUc", "nc", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_extractf32x4_mask, "V4fV16fIiV4fUc", "nc", 
"avx512f")
 
 TARGET_BUILTIN(__builtin_ia32_vpdpbusd128, "V4iV4iV4iV4i", "nc", 
"avx512vl,avx512vnni")
 TARGET_BUILTIN(__builtin_ia32_vpdpbusd256, "V8iV8iV8iV8i", "nc", 
"avx512vl,avx512vnni")
@@ -1672,16 +1672,16 @@ TARGET_BUILTIN(__builtin_ia32_pmovqw128_
 TARGET_BUILTIN(__builtin_ia32_pmovqw128mem_mask, "vV8s*V2LLiUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqw256_mask, "V8sV4LLiV8sUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovqw256mem_mask, "vV8s*V4LLiUc", "n", 
"avx512vl")
-TARGET_BUILTIN(__builtin_ia32_extractf32x8, "V8fV16fIi", "nc", "avx512dq")
-TARGET_BUILTIN(__builtin_ia32_extractf64x2_512, "V2dV8dIi", "nc", "avx512dq")
-TARGET_BUILTIN(__builtin_ia32_extracti32x8, "V8iV16iIi", "nc", "avx512dq")
-TARGET_BUILTIN(__builtin_ia32_extracti64x2_512, "V2LLiV8LLiIi", "nc", 
"avx512dq")
-TARGET_BUILTIN(__builtin_ia32_extracti32x4, "V4iV16iIi", "nc", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_extracti64x4, "V4LLiV8LLiIi", "nc", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_extractf64x2_256, "V2dV4dIi", "nc", 
"avx512dq,avx512vl")
-TARGET_BUILTIN(__builtin_ia32_extracti64x2_256, "V2LLiV4LLiIi", "nc", 
"avx512dq,avx512vl")
-TARGET_BUILTIN(__builtin_ia32_extractf32x4_256, "V4fV8fIi", "nc", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_extracti32x4_256, "V4iV8iIi", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_extractf32x8_mask, "V8fV16fIiV8fUc", "nc", 
"avx512dq")
+TARGET_BUILTIN(__builtin_ia32_extractf64x2_512_mask, "V2dV8dIiV2dUc", "nc", 
"avx512dq")
+TARGET_BUILTIN(__builtin_ia32_extracti32x8_mask, "V8iV16iIiV8iUc", "nc", 
"avx512dq")
+TARGET_BUILTIN(__builtin_ia32_extracti64x2_512_mask, "V2LLiV8LLiIiV2LLiUc", 
"nc", "avx512dq")
+TARGET_BUILTIN(__builtin_ia32_extracti32x4_mask, "V4iV16iIiV4iUc", "nc", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_extracti64x4_mask, "V4LLiV8LLiIiV4LLiUc", "nc", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_extractf64x2_256_mask, "V2dV4dIiV2dUc", "nc", 
"avx512dq,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_extracti64x2_256_mask, "V2LLiV4LLiIiV2LLiUc", 
"nc", "avx512dq,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_extractf32x4_256_mask, "V4fV8fIiV4fUc", "nc", 
"avx512vl")
+TARGET_BUILTIN(__builtin_ia32_extracti32x4_256_mask, "V4iV8iIiV4iUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_insertf32x8, "V16fV16fV8fIi", "nc", "avx512dq")
 TARGET_BUILTIN(__builtin_ia32_insertf64x2_512, "V8dV8dV2dIi", "nc", "avx512dq")
 TARGET_BUILTIN(__builtin_ia32_inserti32x8, "V16iV16iV8iIi", "nc", "avx512dq")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334330=334329=334330=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Jun  8 14:50:07 2018
@@ -9239,18 +9239,18 @@ Value *CodeGenFunction::EmitX86BuiltinEx
   case X86::BI__builtin_ia32_vextractf128_ps256:
   case X86::BI__builtin_ia32_vextractf128_si256:
   case X86::BI__builtin_ia32_extract128i256:
-  case X86::BI__builtin_ia32_extractf64x4:
-  case X86::BI__builtin_ia32_extractf32x4:
-  case X86::BI__builtin_ia32_extracti64x4:
-  case X86::BI__builtin_ia32_extracti32x4:
-  

[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

2018-06-08 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

I just stumbled upon a very interesting situation.

I noticed that, for OpenMP, the use of device math functions happens as I 
expected for -O0. For -O1 or higher math functions such as "sqrt" resolve to 
llvm builtins/intrinsics:

  call double @llvm.sqrt.f64(double %1)

instead of the nvvm variant.

The surprising part (at least to me) is that the same llvm intrinsic is used 
when I use Clang to compile CUDA kernel code calling the "sqrt" function. I 
would have expected that the NVVM variant would be called for CUDA code.

Interestingly, for the "pow" function the expected device version of the 
function i.e.:

  @__internal_accurate_pow(double %14, double %4)

is used for both CUDA and OpenMP NVPTX targets (with this patch applied of 
course).

Is it ok for CUDA kernels to call llvm intrinsics instead of the device 
specific math library functions?
If it's ok for CUDA can this be ok for OpenMP NVPTX too?
If not we probably need to fix it for both toolchains.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D47945: Add support for arrays in performance-implicit-conversion-in-loop

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

LG


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47945



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


[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-08 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: llvm/lib/Support/Windows/Process.inc:216
+  wchar_t ModuleName[MAX_PATH];
+  int Length = ::GetModuleFileNameW(NULL, ModuleName, MAX_PATH);
+  if (Length == 0 || Length == MAX_PATH) {

Can't this be size_t?


https://reviews.llvm.org/D47578



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


[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-08 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: llvm/lib/Support/Windows/Process.inc:227
 return mapWindowsError(GetLastError());
-  if (Length > LongPath.capacity()) {
+  if (static_cast(Length) > MAX_PATH) {
 // We're not going to try to deal with paths longer than MAX_PATH, so we'll

and eliminate this static_cast.



Comment at: llvm/lib/Support/Windows/Process.inc:234
+
+  std::error_code ec = windows::UTF16ToUTF8(ModuleName, Length, Filename);
+  if (ec)

ec -> EC



Comment at: llvm/lib/Support/Windows/Process.inc:252
 
-  Args.reserve(ArgCount);
   std::error_code ec;
 

EC



Comment at: llvm/lib/Support/Windows/Process.inc:256
 
-  for (int i = 1; i < ArgCount && !ec; ++i) {
+  for (int i = 0; i < ArgCount; ++i) {
 ec = WildcardExpand(UnicodeCommandLine[i], Args, Alloc);

I


https://reviews.llvm.org/D47578



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


[clang-tools-extra] r334323 - [clangd] Deduplicate CompletionItemKind conversion.

2018-06-08 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Jun  8 14:17:19 2018
New Revision: 334323

URL: http://llvm.org/viewvc/llvm-project?rev=334323=rev
Log:
[clangd] Deduplicate CompletionItemKind conversion.

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=334323=334322=334323=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Jun  8 14:17:19 2018
@@ -44,69 +44,6 @@ namespace clang {
 namespace clangd {
 namespace {
 
-CompletionItemKind toCompletionItemKind(CXCursorKind CursorKind) {
-  switch (CursorKind) {
-  case CXCursor_MacroInstantiation:
-  case CXCursor_MacroDefinition:
-return CompletionItemKind::Text;
-  case CXCursor_CXXMethod:
-  case CXCursor_Destructor:
-return CompletionItemKind::Method;
-  case CXCursor_FunctionDecl:
-  case CXCursor_FunctionTemplate:
-return CompletionItemKind::Function;
-  case CXCursor_Constructor:
-return CompletionItemKind::Constructor;
-  case CXCursor_FieldDecl:
-return CompletionItemKind::Field;
-  case CXCursor_VarDecl:
-  case CXCursor_ParmDecl:
-return CompletionItemKind::Variable;
-  // FIXME(ioeric): use LSP struct instead of class when it is suppoted in the
-  // protocol.
-  case CXCursor_StructDecl:
-  case CXCursor_ClassDecl:
-  case CXCursor_UnionDecl:
-  case CXCursor_ClassTemplate:
-  case CXCursor_ClassTemplatePartialSpecialization:
-return CompletionItemKind::Class;
-  case CXCursor_Namespace:
-  case CXCursor_NamespaceAlias:
-  case CXCursor_NamespaceRef:
-return CompletionItemKind::Module;
-  case CXCursor_EnumConstantDecl:
-return CompletionItemKind::Value;
-  case CXCursor_EnumDecl:
-return CompletionItemKind::Enum;
-  // FIXME(ioeric): figure out whether reference is the right type for aliases.
-  case CXCursor_TypeAliasDecl:
-  case CXCursor_TypeAliasTemplateDecl:
-  case CXCursor_TypedefDecl:
-  case CXCursor_MemberRef:
-  case CXCursor_TypeRef:
-return CompletionItemKind::Reference;
-  default:
-return CompletionItemKind::Missing;
-  }
-}
-
-CompletionItemKind
-toCompletionItemKind(CodeCompletionResult::ResultKind ResKind,
- CXCursorKind CursorKind) {
-  switch (ResKind) {
-  case CodeCompletionResult::RK_Declaration:
-return toCompletionItemKind(CursorKind);
-  case CodeCompletionResult::RK_Keyword:
-return CompletionItemKind::Keyword;
-  case CodeCompletionResult::RK_Macro:
-return CompletionItemKind::Text; // unfortunately, there's no 'Macro'
- // completion items in LSP.
-  case CodeCompletionResult::RK_Pattern:
-return CompletionItemKind::Snippet;
-  }
-  llvm_unreachable("Unhandled CodeCompletionResult::ResultKind.");
-}
-
 CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
   using SK = index::SymbolKind;
   switch (Kind) {
@@ -160,6 +97,25 @@ CompletionItemKind toCompletionItemKind(
   llvm_unreachable("Unhandled clang::index::SymbolKind.");
 }
 
+CompletionItemKind
+toCompletionItemKind(CodeCompletionResult::ResultKind ResKind,
+ const NamedDecl *Decl) {
+  if (Decl)
+return toCompletionItemKind(index::getSymbolInfo(Decl).Kind);
+  switch (ResKind) {
+  case CodeCompletionResult::RK_Declaration:
+llvm_unreachable("RK_Declaration without Decl");
+  case CodeCompletionResult::RK_Keyword:
+return CompletionItemKind::Keyword;
+  case CodeCompletionResult::RK_Macro:
+return CompletionItemKind::Text; // unfortunately, there's no 'Macro'
+ // completion items in LSP.
+  case CodeCompletionResult::RK_Pattern:
+return CompletionItemKind::Snippet;
+  }
+  llvm_unreachable("Unhandled CodeCompletionResult::ResultKind.");
+}
+
 /// Get the optional chunk as a string. This function is possibly recursive.
 ///
 /// The parameter info for each parameter is appended to the Parameters.
@@ -238,7 +194,7 @@ struct CompletionCandidate {
 CompletionItem I;
 bool ShouldInsertInclude = true;
 if (SemaResult) {
-  I.kind = toCompletionItemKind(SemaResult->Kind, SemaResult->CursorKind);
+  I.kind = toCompletionItemKind(SemaResult->Kind, SemaResult->Declaration);
   getLabelAndInsertText(*SemaCCS, , ,
 Opts.EnableSnippets);
   I.filterText = getFilterText(*SemaCCS);


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


[PATCH] D47958: [CUDA][HIP] Allow CUDA `__global__` functions to have amdgpu kernel attributes

2018-06-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added a comment.

In https://reviews.llvm.org/D47958#1126875, @tra wrote:

> Drive-by review:
>
> The patch could use a better description.
>  Something that describes *what* the patch does (E.g. enforce that attributes 
> X/Y/Z are only applied to __global__ functions.)
>  *why* the change is needed is relevant, too, but it's not very useful 
> without the *what* part.


Thanks for your suggestion. Modified the description.




Comment at: test/SemaCUDA/amdgpu-attrs.cu:66-69
+// expected-error@+2{{attribute 'reqd_work_group_size' can only be applied to 
a kernel function}}
+__attribute__((reqd_work_group_size(32, 64, 64)))
+__global__ void reqd_work_group_size_32_64_64() {}
+

tra wrote:
> This is confusing. Isn't `kernel` == `__global__` function?
> 
> Considering that the error message is `diag::err_opencl_kernel_attr`, I think 
> the diagnostics should say `applied to a OpenCL kernel function`
Thanks for the suggestion. Will do.


https://reviews.llvm.org/D47958



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


[PATCH] D47044: [analyzer] Ensure that we only visit a destructor for a reference if type information is available.

2018-06-08 Thread Matthew Voss via Phabricator via cfe-commits
ormris marked 3 inline comments as done.
ormris added a comment.

Thanks for the comments so far.




Comment at: test/Analysis/loop-widening-invalid-type.cpp:1
+// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-max-loop 4 
-analyzer-config widen-loops=true -verify %s
+

MTC wrote:
> I think it's better to add more expressive tests. Like:
> 
> ```
> struct A {
>   int x;
>   A(int x) : x(x) {}
> };
> 
> void invalid_type_region_access() {
>   const A  = A(10);
>   for(int i = 0; i < 10; ++i) {}
>   clang_analyzer_eval(a.x ==10); // expected-warning{{TRUE}}
> }
> ```
> 
> I think should use more related names instead of 
> `loop-widening-invalid-type.cpp`, like `loop-widening-reference-type`.
Agreed. Fixed.



Comment at: test/Analysis/loop-widening-invalid-type.cpp:8
+
+void invalid_type_region_access() { // expected-no-diagnostics
+  const A  = B();

MTC wrote:
> I don't know what the purpose of the test is, is the comment `no-crash` 
> better?
I've changed the test to (hopefully) look for a valid address for "x".


Repository:
  rC Clang

https://reviews.llvm.org/D47044



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


[PATCH] D47044: [analyzer] Ensure that we only visit a destructor for a reference if type information is available.

2018-06-08 Thread Matthew Voss via Phabricator via cfe-commits
ormris updated this revision to Diff 150567.
ormris added a comment.
Herald added a subscriber: mikhail.ramalho.

- Reformat with clang-format-diff.py
- Rename test
- Modify test to use clang_analyzer_eval


Repository:
  rC Clang

https://reviews.llvm.org/D47044

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/LoopWidening.cpp
  test/Analysis/loop-widening-preserve-reference-type.cpp

Index: test/Analysis/loop-widening-preserve-reference-type.cpp
===
--- /dev/null
+++ test/Analysis/loop-widening-preserve-reference-type.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-max-loop 4 -analyzer-config widen-loops=true -verify %s
+
+void clang_analyzer_eval(int);
+
+struct A {
+  ~A() {}
+};
+struct B : public A {};
+
+void invalid_type_region_access() {
+  const A  = B();
+  for (int i = 0; i < 10; ++i) { }
+  clang_analyzer_eval( == ); // expected-warning{{TRUE}}
+}
Index: lib/StaticAnalyzer/Core/LoopWidening.cpp
===
--- lib/StaticAnalyzer/Core/LoopWidening.cpp
+++ lib/StaticAnalyzer/Core/LoopWidening.cpp
@@ -15,9 +15,15 @@
 //===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h"
+#include "clang/AST/AST.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
+#include "llvm/ADT/SmallSet.h"
 
 using namespace clang;
 using namespace ento;
+using namespace clang::ast_matchers;
 
 /// Return the loops condition Stmt or NULL if LoopStmt is not a loop
 static const Expr *getLoopCondition(const Stmt *LoopStmt) {
@@ -33,10 +39,26 @@
   }
 }
 
+struct Callback : public MatchFinder::MatchCallback {
+  const LocationContext *LCtx;
+  MemRegionManager 
+  RegionAndSymbolInvalidationTraits 
+  explicit Callback(const LocationContext *LCtx_, MemRegionManager _,
+RegionAndSymbolInvalidationTraits _)
+  : LCtx(LCtx_), MRMgr(MRMgr_), ITraits(ITraits_) {}
+  virtual void run(const MatchFinder::MatchResult ) override {
+const VarDecl *VD = Result.Nodes.getNodeAs("match");
+const VarRegion *VarMem = MRMgr.getVarRegion(VD, LCtx);
+ITraits.setTrait(VarMem,
+ RegionAndSymbolInvalidationTraits::TK_PreserveContents);
+  }
+};
+
 namespace clang {
 namespace ento {
 
 ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
+ASTContext ,
 const LocationContext *LCtx,
 unsigned BlockCount, const Stmt *LoopStmt) {
 
@@ -60,6 +82,12 @@
  RegionAndSymbolInvalidationTraits::TK_EntireMemSpace);
   }
 
+  // References should not be invalidated.
+  MatchFinder Finder;
+  Finder.addMatcher(varDecl(hasType(referenceType())).bind("match"),
+new Callback(LCtx, MRMgr, ITraits));
+  Finder.matchAST(ASTCtx);
+
   // 'this' pointer is not an lvalue, we should not invalidate it. If the loop
   // is located in a method, constructor or destructor, the value of 'this'
   // pointer shoule remain unchanged.
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1854,8 +1854,8 @@
   return;
 // Widen.
 const LocationContext *LCtx = Pred->getLocationContext();
-ProgramStateRef WidenedState =
-getWidenedLoopState(Pred->getState(), LCtx, BlockCount, Term);
+ProgramStateRef WidenedState = getWidenedLoopState(
+Pred->getState(), AMgr.getASTContext(), LCtx, BlockCount, Term);
 nodeBuilder.generateNode(WidenedState, Pred);
 return;
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
@@ -27,6 +27,7 @@
 /// Widen the loop by invalidating anything that might be modified
 /// by the loop body in any iteration.
 ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
+ASTContext ,
 const LocationContext *LCtx,
 unsigned BlockCount, const Stmt *LoopStmt);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47958: [CUDA][HIP] Allow CUDA kernel to have amdgpu kernel attributes

2018-06-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Drive-by review:

The patch could use a better description.
Something that describes *what* the patch does (E.g. enforce that attributes 
X/Y/Z are only applied to __global__ functions.)
*why* the change is needed is relevant, too, but it's not very useful without 
the *what* part.




Comment at: test/SemaCUDA/amdgpu-attrs.cu:66-69
+// expected-error@+2{{attribute 'reqd_work_group_size' can only be applied to 
a kernel function}}
+__attribute__((reqd_work_group_size(32, 64, 64)))
+__global__ void reqd_work_group_size_32_64_64() {}
+

This is confusing. Isn't `kernel` == `__global__` function?

Considering that the error message is `diag::err_opencl_kernel_attr`, I think 
the diagnostics should say `applied to a OpenCL kernel function`


https://reviews.llvm.org/D47958



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


Re: [clang-tools-extra] r333993 - [clangd] Rewrite JSON dispatcher loop using C IO (FILE*) instead of std::istream.

2018-06-08 Thread Kostya Serebryany via cfe-commits
thanks!

On Fri, Jun 8, 2018 at 1:31 PM Sam McCall  wrote:

> Oops, thank you!
> r334315 should fix this.
>
>
>
> On Fri, Jun 8, 2018 at 9:45 PM Kostya Serebryany  wrote:
>
>> Looks like this broke the clang-fuzzer:
>> https://oss-fuzz-build-logs.storage.googleapis.com/index.html
>>
>> Step #4: 
>> /src/llvm/tools/clang/tools/extra/clangd/fuzzer/ClangdFuzzer.cpp:31:17: 
>> error: no viable conversion from 'std::istringstream' (aka 
>> 'basic_istringstream') to 'std::FILE *' (aka '_IO_FILE *')
>> Step #4:   LSPServer.run(In);
>> Step #4: ^~
>> Step #4: 
>> /src/llvm/tools/clang/tools/extra/clangd/fuzzer/../ClangdLSPServer.h:46:23: 
>> note: passing argument to parameter 'In' here
>> Step #4:   bool run(std::FILE *In,
>> Step #4:   ^
>> Step #4: 1 error generated.
>> Step #4: ninja: build stopped: subcommand failed.
>>
>>
>>
>> On Tue, Jun 5, 2018 at 2:38 AM Sam McCall via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: sammccall
>>> Date: Tue Jun  5 02:34:46 2018
>>> New Revision: 333993
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=333993=rev
>>> Log:
>>> [clangd] Rewrite JSON dispatcher loop using C IO (FILE*) instead of
>>> std::istream.
>>>
>>> Summary:
>>> The EINTR loop around getline was added to fix an issue with mac gdb,
>>> but seems
>>> to loop infinitely in rare cases on linux where the parent editor exits
>>> (most
>>> reports with VSCode).
>>> I can't work out how to fix this in a portable way with std::istream,
>>> but the
>>> C APIs have clearer contracts and LLVM has a RetryAfterSignal function
>>> for use
>>> with them which seems battle-tested.
>>>
>>> While here, clean up some inconsistency around \n in log messages (now
>>> add it only after JSON payloads), and reduce the scope of the
>>> long-message handling which was only really added to fight fuzzers.
>>>
>>> Reviewers: malaperle, ilya-biryukov
>>>
>>> Subscribers: klimek, ioeric, jkorous, cfe-commits
>>>
>>> Differential Revision: https://reviews.llvm.org/D47643
>>>
>>> Modified:
>>> clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
>>> clang-tools-extra/trunk/clangd/ClangdLSPServer.h
>>> clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
>>> clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
>>> clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>>> clang-tools-extra/trunk/test/clangd/too_large.test
>>>
>>> Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=333993=333992=333993=diff
>>>
>>> ==
>>> --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
>>> +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Jun  5
>>> 02:34:46 2018
>>> @@ -396,7 +396,7 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
>>>SupportedSymbolKinds(defaultSymbolKinds()),
>>>Server(CDB, FSProvider, /*DiagConsumer=*/*this, Opts) {}
>>>
>>> -bool ClangdLSPServer::run(std::istream , JSONStreamStyle InputStyle)
>>> {
>>> +bool ClangdLSPServer::run(std::FILE *In, JSONStreamStyle InputStyle) {
>>>assert(!IsDone && "Run was called before");
>>>
>>>// Set up JSONRPCDispatcher.
>>>
>>> Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=333993=333992=333993=diff
>>>
>>> ==
>>> --- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
>>> +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Jun  5 02:34:46
>>> 2018
>>> @@ -42,8 +42,8 @@ public:
>>>/// class constructor. This method must not be executed more than
>>> once for
>>>/// each instance of ClangdLSPServer.
>>>///
>>> -  /// \return Wether we received a 'shutdown' request before an 'exit'
>>> request
>>> -  bool run(std::istream ,
>>> +  /// \return Whether we received a 'shutdown' request before an 'exit'
>>> request.
>>> +  bool run(std::FILE *In,
>>> JSONStreamStyle InputStyle = JSONStreamStyle::Standard);
>>>
>>>  private:
>>>
>>> Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=333993=333992=333993=diff
>>>
>>> ==
>>> --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
>>> +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Jun  5
>>> 02:34:46 2018
>>> @@ -14,6 +14,7 @@
>>>  #include "llvm/ADT/SmallString.h"
>>>  #include "llvm/ADT/StringExtras.h"
>>>  #include "llvm/Support/Chrono.h"
>>> +#include "llvm/Support/Errno.h"
>>>  #include "llvm/Support/SourceMgr.h"
>>>  #include 
>>>
>>> @@ -66,7 +67,7 @@ void JSONOutput::writeMessage(const json
>>>  Outs << 

Re: [clang-tools-extra] r333993 - [clangd] Rewrite JSON dispatcher loop using C IO (FILE*) instead of std::istream.

2018-06-08 Thread Sam McCall via cfe-commits
Oops, thank you!
r334315 should fix this.



On Fri, Jun 8, 2018 at 9:45 PM Kostya Serebryany  wrote:

> Looks like this broke the clang-fuzzer:
> https://oss-fuzz-build-logs.storage.googleapis.com/index.html
>
> Step #4: 
> /src/llvm/tools/clang/tools/extra/clangd/fuzzer/ClangdFuzzer.cpp:31:17: 
> error: no viable conversion from 'std::istringstream' (aka 
> 'basic_istringstream') to 'std::FILE *' (aka '_IO_FILE *')
> Step #4:   LSPServer.run(In);
> Step #4: ^~
> Step #4: 
> /src/llvm/tools/clang/tools/extra/clangd/fuzzer/../ClangdLSPServer.h:46:23: 
> note: passing argument to parameter 'In' here
> Step #4:   bool run(std::FILE *In,
> Step #4:   ^
> Step #4: 1 error generated.
> Step #4: ninja: build stopped: subcommand failed.
>
>
>
> On Tue, Jun 5, 2018 at 2:38 AM Sam McCall via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: sammccall
>> Date: Tue Jun  5 02:34:46 2018
>> New Revision: 333993
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=333993=rev
>> Log:
>> [clangd] Rewrite JSON dispatcher loop using C IO (FILE*) instead of
>> std::istream.
>>
>> Summary:
>> The EINTR loop around getline was added to fix an issue with mac gdb, but
>> seems
>> to loop infinitely in rare cases on linux where the parent editor exits
>> (most
>> reports with VSCode).
>> I can't work out how to fix this in a portable way with std::istream, but
>> the
>> C APIs have clearer contracts and LLVM has a RetryAfterSignal function
>> for use
>> with them which seems battle-tested.
>>
>> While here, clean up some inconsistency around \n in log messages (now
>> add it only after JSON payloads), and reduce the scope of the
>> long-message handling which was only really added to fight fuzzers.
>>
>> Reviewers: malaperle, ilya-biryukov
>>
>> Subscribers: klimek, ioeric, jkorous, cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D47643
>>
>> Modified:
>> clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
>> clang-tools-extra/trunk/clangd/ClangdLSPServer.h
>> clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
>> clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
>> clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>> clang-tools-extra/trunk/test/clangd/too_large.test
>>
>> Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=333993=333992=333993=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Jun  5
>> 02:34:46 2018
>> @@ -396,7 +396,7 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
>>SupportedSymbolKinds(defaultSymbolKinds()),
>>Server(CDB, FSProvider, /*DiagConsumer=*/*this, Opts) {}
>>
>> -bool ClangdLSPServer::run(std::istream , JSONStreamStyle InputStyle) {
>> +bool ClangdLSPServer::run(std::FILE *In, JSONStreamStyle InputStyle) {
>>assert(!IsDone && "Run was called before");
>>
>>// Set up JSONRPCDispatcher.
>>
>> Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=333993=333992=333993=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
>> +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Jun  5 02:34:46
>> 2018
>> @@ -42,8 +42,8 @@ public:
>>/// class constructor. This method must not be executed more than once
>> for
>>/// each instance of ClangdLSPServer.
>>///
>> -  /// \return Wether we received a 'shutdown' request before an 'exit'
>> request
>> -  bool run(std::istream ,
>> +  /// \return Whether we received a 'shutdown' request before an 'exit'
>> request.
>> +  bool run(std::FILE *In,
>> JSONStreamStyle InputStyle = JSONStreamStyle::Standard);
>>
>>  private:
>>
>> Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=333993=333992=333993=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Jun  5
>> 02:34:46 2018
>> @@ -14,6 +14,7 @@
>>  #include "llvm/ADT/SmallString.h"
>>  #include "llvm/ADT/StringExtras.h"
>>  #include "llvm/Support/Chrono.h"
>> +#include "llvm/Support/Errno.h"
>>  #include "llvm/Support/SourceMgr.h"
>>  #include 
>>
>> @@ -66,7 +67,7 @@ void JSONOutput::writeMessage(const json
>>  Outs << "Content-Length: " << S.size() << "\r\n\r\n" << S;
>>  Outs.flush();
>>}
>> -  log(llvm::Twine("--> ") + S);
>> +  log(llvm::Twine("--> ") + S + "\n");
>>  }
>>
>>  void 

[clang-tools-extra] r334315 - [clangd] Fix fuzzer after r333993

2018-06-08 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Jun  8 13:25:05 2018
New Revision: 334315

URL: http://llvm.org/viewvc/llvm-project?rev=334315=rev
Log:
[clangd] Fix fuzzer after r333993

Modified:
clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp

Modified: clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp?rev=334315=334314=334315=diff
==
--- clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp (original)
+++ clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp Fri Jun  8 13:25:05 
2018
@@ -17,6 +17,7 @@
 #include "ClangdServer.h"
 #include "CodeComplete.h"
 #include 
+#include 
 
 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
   clang::clangd::JSONOutput Out(llvm::nulls(), llvm::nulls(), nullptr);
@@ -26,8 +27,7 @@ extern "C" int LLVMFuzzerTestOneInput(ui
 
   // Initialize and run ClangdLSPServer.
   clang::clangd::ClangdLSPServer LSPServer(Out, CCOpts, llvm::None, Opts);
-
-  std::istringstream In(std::string(reinterpret_cast(data), size));
-  LSPServer.run(In);
+  // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
+  LSPServer.run(fmemopen(data, size, "r"));
   return 0;
 }


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


[PATCH] D47733: [CUDA][HIP] Set kernel calling convention before arrange function

2018-06-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 150559.
yaxunl marked an inline comment as done.
yaxunl added a comment.

Wrap long RUN lines in test.


https://reviews.llvm.org/D47733

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenCUDA/kernel-args.cu

Index: test/CodeGenCUDA/kernel-args.cu
===
--- /dev/null
+++ test/CodeGenCUDA/kernel-args.cu
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device \
+// RUN: -emit-llvm %s -o - | FileCheck -check-prefix=AMDGCN %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda- -fcuda-is-device \
+// RUN: -emit-llvm %s -o - | FileCheck -check-prefix=NVPTX %s
+#include "Inputs/cuda.h"
+
+struct A {
+  int a[32];
+};
+
+// AMDGCN: define amdgpu_kernel void @_Z6kernel1A(%struct.A %x.coerce)
+// NVPTX: define void @_Z6kernel1A(%struct.A* byval align 4 %x)
+__global__ void kernel(A x) {
+}
+
+class Kernel {
+public:
+  // AMDGCN: define amdgpu_kernel void @_ZN6Kernel12memberKernelE1A(%struct.A %x.coerce)
+  // NVPTX: define void @_ZN6Kernel12memberKernelE1A(%struct.A* byval align 4 %x)
+  static __global__ void memberKernel(A x){}
+  template static __global__ void templateMemberKernel(T x) {}
+};
+
+
+template 
+__global__ void templateKernel(T x) {}
+
+void launch(void*);
+
+void test() {
+  Kernel K;
+  // AMDGCN: define amdgpu_kernel void @_Z14templateKernelI1AEvT_(%struct.A %x.coerce)
+  // NVPTX: define void @_Z14templateKernelI1AEvT_(%struct.A* byval align 4 %x)
+  launch((void*)templateKernel);
+
+  // AMDGCN: define amdgpu_kernel void @_ZN6Kernel20templateMemberKernelI1AEEvT_(%struct.A %x.coerce)
+  // NVPTX: define void @_ZN6Kernel20templateMemberKernelI1AEEvT_(%struct.A* byval align 4 %x)
+  launch((void*)Kernel::templateMemberKernel);
+}
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -302,7 +302,7 @@
   /// as 'used', and having internal linkage.
   virtual bool shouldEmitStaticExternCAliases() const { return true; }
 
-  virtual void setCUDAKernelCallingConvention(llvm::Function *F) const {}
+  virtual void setCUDAKernelCallingConvention(const FunctionType *) const {}
 };
 
 } // namespace CodeGen
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7646,7 +7646,7 @@
 llvm::Function *BlockInvokeFunc,
 llvm::Value *BlockLiteral) const override;
   bool shouldEmitStaticExternCAliases() const override;
-  void setCUDAKernelCallingConvention(llvm::Function *F) const override;
+  void setCUDAKernelCallingConvention(const FunctionType *) const override;
 };
 }
 
@@ -7783,8 +7783,9 @@
 }
 
 void AMDGPUTargetCodeGenInfo::setCUDAKernelCallingConvention(
-llvm::Function *F) const {
-  F->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
+const FunctionType *) const {
+  FT = getABIInfo().getContext().adjustFunctionType(
+  FT, FT->getExtInfo().withCallingConv(CC_OpenCLKernel));
 }
 
 //===--===//
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -3671,8 +3671,6 @@
 
   MaybeHandleStaticInExternC(D, Fn);
 
-  if (D->hasAttr())
-getTargetCodeGenInfo().setCUDAKernelCallingConvention(Fn);
 
   maybeSetTrivialComdat(*D, *Fn);
 
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -255,6 +255,16 @@
   FTP->getCanonicalTypeUnqualified().getAs(), MD);
 }
 
+/// Set calling convention for CUDA/HIP kernel.
+static void setCUDAKernelCallingConvention(CanQualType , CodeGenModule ,
+   const FunctionDecl *FD) {
+  if (FD->hasAttr()) {
+const FunctionType *FT = FTy->getAs();
+CGM.getTargetCodeGenInfo().setCUDAKernelCallingConvention(FT);
+FTy = FT->getCanonicalTypeUnqualified();
+  }
+}
+
 /// Arrange the argument and result information for a declaration or
 /// definition of the given C++ non-static member function.  The
 /// member function must be an ordinary function, i.e. not a
@@ -264,7 +274,9 @@
   assert(!isa(MD) && "wrong method for constructors!");
   assert(!isa(MD) && "wrong method for destructors!");
 
-  CanQual prototype = GetFormalType(MD);
+  CanQualType FT = GetFormalType(MD).getAs();
+  setCUDAKernelCallingConvention(FT, CGM, MD);
+  auto prototype = FT.getAs();
 
   if (MD->isInstance()) {
 // The abstract case is perfectly fine.
@@ -424,6 +436,7 @@
   CanQualType FTy = FD->getType()->getCanonicalTypeUnqualified();
 
   assert(isa(FTy));
+  

[PATCH] D46993: [CUDA] Make std::min/max work when compiling in C++14 mode with a C++11 stdlib.

2018-06-08 Thread Jakub Klinkovský via Phabricator via cfe-commits
lahwaacz added a comment.

This revision does not do the right thing because it makes it impossible to use 
the std::min and std::max functions in __host__ __device__ functions under 
C++14: https://bugs.llvm.org/show_bug.cgi?id=37753


Repository:
  rC Clang

https://reviews.llvm.org/D46993



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


[PATCH] D47958: [CUDA][HIP] Allow CUDA kernel to have amdgpu kernel attributes

2018-06-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: kzhuravl.
Herald added subscribers: t-tye, tpr, dstuttard, nhaehnle, wdng.

There are HIP applications e.g. Tensorflow 1.3 using amdgpu kernel attributes.


https://reviews.llvm.org/D47958

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCUDA/amdgpu-kernel-attrs.cu
  test/SemaCUDA/amdgpu-attrs.cu

Index: test/SemaCUDA/amdgpu-attrs.cu
===
--- test/SemaCUDA/amdgpu-attrs.cu
+++ test/SemaCUDA/amdgpu-attrs.cu
@@ -1,110 +1,80 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-
 #include "Inputs/cuda.h"
 
 
-// expected-error@+2 {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
 __attribute__((amdgpu_flat_work_group_size(32, 64)))
 __global__ void flat_work_group_size_32_64() {}
 
-// expected-error@+2 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
 __attribute__((amdgpu_waves_per_eu(2)))
 __global__ void waves_per_eu_2() {}
 
-// expected-error@+2 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
 __attribute__((amdgpu_waves_per_eu(2, 4)))
 __global__ void waves_per_eu_2_4() {}
 
-// expected-error@+2 {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_num_sgpr(32)))
 __global__ void num_sgpr_32() {}
 
-// expected-error@+2 {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_num_vgpr(64)))
 __global__ void num_vgpr_64() {}
 
 
-// expected-error@+3 {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
 __attribute__((amdgpu_flat_work_group_size(32, 64), amdgpu_waves_per_eu(2)))
 __global__ void flat_work_group_size_32_64_waves_per_eu_2() {}
 
-// expected-error@+3 {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
 __attribute__((amdgpu_flat_work_group_size(32, 64), amdgpu_waves_per_eu(2, 4)))
 __global__ void flat_work_group_size_32_64_waves_per_eu_2_4() {}
 
-// expected-error@+3 {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_flat_work_group_size(32, 64), amdgpu_num_sgpr(32)))
 __global__ void flat_work_group_size_32_64_num_sgpr_32() {}
 
-// expected-error@+3 {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_flat_work_group_size(32, 64), amdgpu_num_vgpr(64)))
 __global__ void flat_work_group_size_32_64_num_vgpr_64() {}
 
-// expected-error@+3 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_waves_per_eu(2), amdgpu_num_sgpr(32)))
 __global__ void waves_per_eu_2_num_sgpr_32() {}
 
-// expected-error@+3 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_waves_per_eu(2), amdgpu_num_vgpr(64)))
 __global__ void waves_per_eu_2_num_vgpr_64() {}
 
-// expected-error@+3 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_waves_per_eu(2, 4), amdgpu_num_sgpr(32)))
 __global__ void waves_per_eu_2_4_num_sgpr_32() {}
 
-// expected-error@+3 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_waves_per_eu(2, 4), amdgpu_num_vgpr(64)))
 __global__ void waves_per_eu_2_4_num_vgpr_64() {}
 
-// expected-error@+3 {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_num_sgpr(32), amdgpu_num_vgpr(64)))
 __global__ void num_sgpr_32_num_vgpr_64() {}
 
-
-// expected-error@+4 {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
-// fixme-expected-error@+3 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
-// fixme-expected-error@+2 {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
 __attribute__((amdgpu_flat_work_group_size(32, 64), amdgpu_waves_per_eu(2), amdgpu_num_sgpr(32)))
 __global__ void flat_work_group_size_32_64_waves_per_eu_2_num_sgpr_32() {}
 
-// expected-error@+4 {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
-// fixme-expected-error@+3 {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
-// 

Re: [clang-tools-extra] r333993 - [clangd] Rewrite JSON dispatcher loop using C IO (FILE*) instead of std::istream.

2018-06-08 Thread Kostya Serebryany via cfe-commits
Looks like this broke the clang-fuzzer:
https://oss-fuzz-build-logs.storage.googleapis.com/index.html

Step #4: /src/llvm/tools/clang/tools/extra/clangd/fuzzer/ClangdFuzzer.cpp:31:17:
error: no viable conversion from 'std::istringstream' (aka
'basic_istringstream') to 'std::FILE *' (aka '_IO_FILE *')
Step #4:   LSPServer.run(In);
Step #4: ^~
Step #4: 
/src/llvm/tools/clang/tools/extra/clangd/fuzzer/../ClangdLSPServer.h:46:23:
note: passing argument to parameter 'In' here
Step #4:   bool run(std::FILE *In,
Step #4:   ^
Step #4: 1 error generated.
Step #4: ninja: build stopped: subcommand failed.



On Tue, Jun 5, 2018 at 2:38 AM Sam McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: sammccall
> Date: Tue Jun  5 02:34:46 2018
> New Revision: 333993
>
> URL: http://llvm.org/viewvc/llvm-project?rev=333993=rev
> Log:
> [clangd] Rewrite JSON dispatcher loop using C IO (FILE*) instead of
> std::istream.
>
> Summary:
> The EINTR loop around getline was added to fix an issue with mac gdb, but
> seems
> to loop infinitely in rare cases on linux where the parent editor exits
> (most
> reports with VSCode).
> I can't work out how to fix this in a portable way with std::istream, but
> the
> C APIs have clearer contracts and LLVM has a RetryAfterSignal function for
> use
> with them which seems battle-tested.
>
> While here, clean up some inconsistency around \n in log messages (now
> add it only after JSON payloads), and reduce the scope of the
> long-message handling which was only really added to fight fuzzers.
>
> Reviewers: malaperle, ilya-biryukov
>
> Subscribers: klimek, ioeric, jkorous, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D47643
>
> Modified:
> clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
> clang-tools-extra/trunk/clangd/ClangdLSPServer.h
> clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
> clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
> clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
> clang-tools-extra/trunk/test/clangd/too_large.test
>
> Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=333993=333992=333993=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
> +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Jun  5 02:34:46
> 2018
> @@ -396,7 +396,7 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
>SupportedSymbolKinds(defaultSymbolKinds()),
>Server(CDB, FSProvider, /*DiagConsumer=*/*this, Opts) {}
>
> -bool ClangdLSPServer::run(std::istream , JSONStreamStyle InputStyle) {
> +bool ClangdLSPServer::run(std::FILE *In, JSONStreamStyle InputStyle) {
>assert(!IsDone && "Run was called before");
>
>// Set up JSONRPCDispatcher.
>
> Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=333993=333992=333993=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
> +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Jun  5 02:34:46
> 2018
> @@ -42,8 +42,8 @@ public:
>/// class constructor. This method must not be executed more than once
> for
>/// each instance of ClangdLSPServer.
>///
> -  /// \return Wether we received a 'shutdown' request before an 'exit'
> request
> -  bool run(std::istream ,
> +  /// \return Whether we received a 'shutdown' request before an 'exit'
> request.
> +  bool run(std::FILE *In,
> JSONStreamStyle InputStyle = JSONStreamStyle::Standard);
>
>  private:
>
> Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=333993=333992=333993=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
> +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Jun  5
> 02:34:46 2018
> @@ -14,6 +14,7 @@
>  #include "llvm/ADT/SmallString.h"
>  #include "llvm/ADT/StringExtras.h"
>  #include "llvm/Support/Chrono.h"
> +#include "llvm/Support/Errno.h"
>  #include "llvm/Support/SourceMgr.h"
>  #include 
>
> @@ -66,7 +67,7 @@ void JSONOutput::writeMessage(const json
>  Outs << "Content-Length: " << S.size() << "\r\n\r\n" << S;
>  Outs.flush();
>}
> -  log(llvm::Twine("--> ") + S);
> +  log(llvm::Twine("--> ") + S + "\n");
>  }
>
>  void JSONOutput::log(const Twine ) {
> @@ -180,27 +181,43 @@ bool JSONRPCDispatcher::call(const json:
>return true;
>  }
>
> -static llvm::Optional readStandardMessage(std::istream ,
> +// Tries to read a line up to and including \n.
> +// If failing, feof() or ferror() 

[PATCH] D47957: [clangd] Prototype of overload folding

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ioeric, ilya-biryukov.

This folds together overloads items into a single CompletionItem.
It's full of hacks and breaks all the tests.

We may want to experiment with unfolding them sometimes, but this doesn't do 
that yet.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47957

Files:
  clangd/CodeComplete.cpp

Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -220,20 +220,56 @@
   return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
 }
 
+size_t overloadToken(const CodeCompletionResult ) {
+  if (!R.Declaration || !R.Declaration->isFunctionOrFunctionTemplate())
+return 0;
+  // XXX avoid string copies.
+  if (R.Declaration->isCXXClassMember())
+return hash_combine('M',
+StringRef(R.Declaration->getDeclName().getAsString()));
+  return hash_combine('F',
+  StringRef(R.Declaration->getQualifiedNameAsString()));
+}
+
+size_t overloadToken(const Symbol ) {
+  switch (S.SymInfo.Kind) {
+case index::SymbolKind::ClassMethod:
+case index::SymbolKind::InstanceMethod:
+case index::SymbolKind::StaticMethod:
+  return hash_combine('M', S.Name);
+case index::SymbolKind::Function:
+  return hash_combine('F', StringRef((S.Scope + S.Name).str()));
+default:
+  return 0;
+  }
+}
+
 /// A code completion result, in clang-native form.
 /// It may be promoted to a CompletionItem if it's among the top-ranked results.
 struct CompletionCandidate {
   llvm::StringRef Name; // Used for filtering and sorting.
   // We may have a result from Sema, from the index, or both.
   const CodeCompletionResult *SemaResult = nullptr;
   const Symbol *IndexResult = nullptr;
 
+  // Returns a token identifying the overload set this is part of.
+  // 0 indicates it's not part of any overload set.
+  size_t overload() const {
+if (SemaResult && IndexResult)
+  assert(overloadToken(*SemaResult) == overloadToken(*IndexResult));
+if (IndexResult)
+  return overloadToken(*IndexResult);
+if (SemaResult)
+  return overloadToken(*SemaResult);
+return 0;
+  }
+
   // Builds an LSP completion item.
   CompletionItem build(StringRef FileName, const CompletionItemScores ,
const CodeCompleteOptions ,
CodeCompletionString *SemaCCS,
const IncludeInserter *Includes,
-   llvm::StringRef SemaDocComment) const {
+   llvm::StringRef SemaDocComment, unsigned Bundle) const {
 assert(bool(SemaResult) == bool(SemaCCS));
 CompletionItem I;
 bool ShouldInsertInclude = true;
@@ -309,10 +345,27 @@
 I.sortText = sortText(Scores.finalScore, Name);
 I.insertTextFormat = Opts.EnableSnippets ? InsertTextFormat::Snippet
  : InsertTextFormat::PlainText;
+if (Bundle) {
+  I.detail = "[overloaded]";
+  I.insertText = Opts.EnableSnippets ? (Name + "(${0})").str() : Name.str();
+  I.label = (Name + "(...)").str();
+}
 return I;
   }
 };
-using ScoredCandidate = std::pair;
+struct CandidateBundle {
+  SmallVector Candidates;
+  // Builds an LSP completion item.
+  CompletionItem build(StringRef FileName, const CompletionItemScores ,
+   const CodeCompleteOptions ,
+   CodeCompletionString *SemaCCS,
+   const IncludeInserter *Includes,
+   llvm::StringRef SemaDocComment) const {
+return Candidates.front().build(FileName, Scores, Opts, SemaCCS, Includes,
+SemaDocComment, Candidates.size() > 1);
+  }
+};
+using ScoredBundle = std::pair;
 
 // Determine the symbol ID for a Sema code completion result, if possible.
 llvm::Optional getSymbolID(const CodeCompletionResult ) {
@@ -589,10 +642,10 @@
 };
 
 struct ScoredCandidateGreater {
-  bool operator()(const ScoredCandidate , const ScoredCandidate ) {
+  bool operator()(const ScoredBundle , const ScoredBundle ) {
 if (L.second.finalScore != R.second.finalScore)
   return L.second.finalScore > R.second.finalScore;
-return L.first.Name < R.first.Name; // Earlier name is better.
+return L.first.Candidates.front().Name < R.first.Candidates.front().Name; // Earlier name is better.
   }
 };
 
@@ -984,13 +1037,30 @@
 
   // Merges the Sema and Index results where possible, scores them, and
   // returns the top results from best to worst.
-  std::vector>
+  std::vector>
   mergeResults(const std::vector ,
const SymbolSlab ) {
 trace::Span Tracer("Merge and score results");
-// We only keep the best N results at any time, in "native" format.
-TopN Top(
-Opts.Limit == 0 ? std::numeric_limits::max() : Opts.Limit);
+// Candidates are grouped into 

[PATCH] D47956: [MS] Consder constexpr globals to be inline, as in C++17

2018-06-08 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:6597
+  (getLangOpts().CPlusPlus17 ||
+   Context.getTargetInfo().getCXXABI().isMicrosoft()))
 NewVD->setImplicitlyInline();

Is this related to /Zc:externConstexpr / PR36413? If so, maybe we should do the 
standards-conforming thing by default and ask people to pass 
/Zc:externConstexpr- if they need ABI compat?

Want to add a FIXME about doing this in the AST in the source too?


https://reviews.llvm.org/D47956



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


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-08 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In https://reviews.llvm.org/D47894#1125961, @srhines wrote:

> In https://reviews.llvm.org/D47894#1125728, @jyknight wrote:
>
> > In https://reviews.llvm.org/D47894#1125653, @efriedma wrote:
> >
> > > The problem would come from propagating nonnull-ness from something which 
> > > isn't inherently nonnull.  For example, strlen has a nonnull argument, so 
> > > `strlen(NULL)` is UB, therefore given `int z = strlen(x); if (x) {...}`, 
> > > we can remove the null check.  (Not sure we actually do this transform at 
> > > the moment, but it's something we could do in the future.)
> >
> >
> > I think the question there is actually whether we need to, in addition to 
> > supporting null pointer dereference, also cause all 
> > `__attribute__((nonnull))` annotations at the C/C++ level to be ignored.
> >
> > And, yes, I believe we should.
>
>
> Is that what the kernel community actually wants though? There are certainly 
> others who want a way to strip `__attribute__((nonnull))` completely, which 
> seems a bit orthogonal to the removal of null checks in general. I think it 
> would be good to support such a flag, but the presence of `nonnull` inside 
> kernel sources leads me to believe they want those cases to be treated 
> specially.


In GCC, the nonnull attribute still has an effect on warnings but not on 
codegen if you enable -fno-delete-null-pointer-checks: 
https://godbolt.org/g/7SSi2V

That seems a pretty sensible behavior, IMO.


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


[PATCH] D45202: [X86] Replacing X86-specific floor and ceil vector intrinsics with generic LLVM intrinsics

2018-06-08 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

In https://reviews.llvm.org/D45202#1126616, @craig.topper wrote:

> I'm not sure whether we should be doing this here or in InstCombine. @spatel, 
> what do you think?


It's been a while since I looked at these. Last memory I have is for the 
conversion from x86 masked ops to the generic LLVM intrinsics, and we did that 
in InstCombineCalls. I don't know if there was any sound reasoning for that 
though. If it makes no functional difference, I'd continue with that structure 
just so we don't become scattered in the transform.


https://reviews.llvm.org/D45202



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


[PATCH] D47956: [MS] Consder constexpr globals to be inline, as in C++17

2018-06-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.
rnk added a reviewer: thakis.

Microsoft seems to do this regardless of the language mode, so we must
also do it in order to be ABI compatible.

Fixes PR36125


https://reviews.llvm.org/D47956

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
  clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32   -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DMS %s
 // RUN: %clang_cc1 -triple i686-mingw32   -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
+// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -582,7 +583,10 @@
   __declspec(dllimport) static  const  int  StaticConstFieldEqualInit = 1;
   __declspec(dllimport) static  const  int  StaticConstFieldBraceInit{1};
   __declspec(dllimport) constexpr static int ConstexprField = 1;
-  __declspec(dllimport) constexpr static int ConstexprFieldDef = 1; // expected-note{{attribute is here}}
+#if __cplusplus < 201703L && !defined(MS)
+  // expected-note@+2{{attribute is here}}
+#endif
+  __declspec(dllimport) constexpr static int ConstexprFieldDef = 1;
 };
 
 #ifdef MS
@@ -627,7 +631,10 @@
 
int  ImportMembers::StaticFieldDef; // expected-error{{definition of dllimport static field not allowed}}
 const  int  ImportMembers::StaticConstFieldDef = 1; // expected-error{{definition of dllimport static field not allowed}}
-constexpr int ImportMembers::ConstexprFieldDef; // expected-error{{definition of dllimport static field not allowed}}
+#if __cplusplus < 201703L && !defined(MS)
+// expected-error@+2{{definition of dllimport static field not allowed}}
+#endif
+constexpr int ImportMembers::ConstexprFieldDef;
 
 
 // Import on member definitions.
@@ -663,7 +670,11 @@
 
 __declspec(dllimport)int  ImportMemberDefs::StaticField; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}}
 __declspec(dllimport) const  int  ImportMemberDefs::StaticConstField = 1; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}}
-__declspec(dllimport) constexpr int ImportMemberDefs::ConstexprField; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}}
+#if __cplusplus < 201703L && !defined(MS)
+// expected-error@+3{{definition of dllimport static field not allowed}}
+// expected-note@+2{{attribute is here}}
+#endif
+__declspec(dllimport) constexpr int ImportMemberDefs::ConstexprField;
 
 
 // Import special member functions.
@@ -796,7 +807,7 @@
 
   static int  StaticField; // expected-note{{previous declaration is here}}
   static  const  int  StaticConstField;// expected-note{{previous declaration is here}}
-  constexpr static int ConstexprField = 1; // expected-note{{previous declaration is here}}
+  constexpr static int ConstexprField = 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
 };
 
 __declspec(dllimport)void MemberRedecl::normalDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalDef' cannot add 'dllimport' attribute}}
@@ -827,9 +838,15 @@
 __declspec(dllimport) const  int  MemberRedecl::StaticConstField = 1;  // expected-error{{redeclaration of 'MemberRedecl::StaticConstField' cannot add 'dllimport' attribute}}
// expected-error@-1{{definition of dllimport static field not allowed}}
// expected-note@-2{{attribute is here}}
-__declspec(dllimport) constexpr int MemberRedecl::ConstexprField;  // expected-error{{redeclaration of 'MemberRedecl::ConstexprField' cannot add 'dllimport' attribute}}
-   // expected-error@-1{{definition of dllimport static field not allowed}}
-   // expected-note@-2{{attribute is here}}
+
+#if __cplusplus < 201703L && !defined(MS)
+// expected-error@+6{{redeclaration of 'MemberRedecl::ConstexprField' cannot add 'dllimport' attribute}}
+// expected-error@+5{{definition of dllimport static field not allowed}}
+// expected-note@+4{{attribute is here}}
+#else
+// 

r334310 - [X86] Change immediate type for some builtins from char to int.

2018-06-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jun  8 11:00:22 2018
New Revision: 334310

URL: http://llvm.org/viewvc/llvm-project?rev=334310=rev
Log:
[X86] Change immediate type for some builtins from char to int.

These builtins are all handled by CGBuiltin.cpp so it doesn't much matter what 
the immediate type is, but int matches the intrinsic spec.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx2intrin.h
cfe/trunk/lib/Headers/avxintrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334310=334309=334310=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Jun  8 11:00:22 2018
@@ -498,24 +498,24 @@ TARGET_BUILTIN(__builtin_ia32_cmpps, "V4
 TARGET_BUILTIN(__builtin_ia32_cmpps256, "V8fV8fV8fIc", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cmpsd, "V2dV2dV2dIc", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cmpss, "V4fV4fV4fIc", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vextractf128_pd256, "V2dV4dIc", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vextractf128_ps256, "V4fV8fIc", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vextractf128_si256, "V4iV8iIc", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vextractf128_pd256, "V2dV4dIi", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vextractf128_ps256, "V4fV8fIi", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vextractf128_si256, "V4iV8iIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2ps256, "V4fV4d", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cvtps2dq256, "V8iV8f", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cvttpd2dq256, "V4iV4d", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2dq256, "V4iV4d", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cvttps2dq256, "V8iV8f", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vperm2f128_pd256, "V4dV4dV4dIc", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vperm2f128_ps256, "V8fV8fV8fIc", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vperm2f128_si256, "V8iV8iV8iIc", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vperm2f128_pd256, "V4dV4dV4dIi", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vperm2f128_ps256, "V8fV8fV8fIi", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vperm2f128_si256, "V8iV8iV8iIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_vpermilpd, "V2dV2dIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_vpermilps, "V4fV4fIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_vpermilpd256, "V4dV4dIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_vpermilps256, "V8fV8fIi", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vinsertf128_pd256, "V4dV4dV2dIc", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vinsertf128_ps256, "V8fV8fV4fIc", "nc", "avx")
-TARGET_BUILTIN(__builtin_ia32_vinsertf128_si256, "V8iV8iV4iIc", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vinsertf128_pd256, "V4dV4dV2dIi", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vinsertf128_ps256, "V8fV8fV4fIi", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_vinsertf128_si256, "V8iV8iV4iIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_sqrtpd256, "V4dV4d", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_sqrtps256, "V8fV8f", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_rsqrtps256, "V8fV8f", "nc", "avx")
@@ -633,9 +633,9 @@ TARGET_BUILTIN(__builtin_ia32_pblendd128
 TARGET_BUILTIN(__builtin_ia32_pblendd256, "V8iV8iV8iIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsi256, "V8iV8iV8i", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsf256, "V8fV8fV8i", "nc", "avx2")
-TARGET_BUILTIN(__builtin_ia32_permti256, "V4LLiV4LLiV4LLiIc", "nc", "avx2")
-TARGET_BUILTIN(__builtin_ia32_extract128i256, "V2LLiV4LLiIc", "nc", "avx2")
-TARGET_BUILTIN(__builtin_ia32_insert128i256, "V4LLiV4LLiV2LLiIc", "nc", "avx2")
+TARGET_BUILTIN(__builtin_ia32_permti256, "V4LLiV4LLiV4LLiIi", "nc", "avx2")
+TARGET_BUILTIN(__builtin_ia32_extract128i256, "V2LLiV4LLiIi", "nc", "avx2")
+TARGET_BUILTIN(__builtin_ia32_insert128i256, "V4LLiV4LLiV2LLiIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_maskloadd256, "V8iV8iC*V8i", "n", "avx2")
 TARGET_BUILTIN(__builtin_ia32_maskloadq256, "V4LLiV4LLiC*V4LLi", "n", "avx2")
 TARGET_BUILTIN(__builtin_ia32_maskloadd, "V4iV4iC*V4i", "n", "avx2")

Modified: cfe/trunk/lib/Headers/avx2intrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx2intrin.h?rev=334310=334309=334310=diff
==
--- cfe/trunk/lib/Headers/avx2intrin.h (original)
+++ cfe/trunk/lib/Headers/avx2intrin.h Fri Jun  8 11:00:22 2018
@@ -847,7 +847,7 @@ _mm256_permutevar8x32_ps(__m256 __a, __m
((M) >> 6) & 0x3)
 
 #define _mm256_permute2x128_si256(V1, V2, M) \
-  (__m256i)__builtin_ia32_permti256((__m256i)(V1), (__m256i)(V2), (M))
+  (__m256i)__builtin_ia32_permti256((__m256i)(V1), (__m256i)(V2), (int)(M))
 
 #define 

r334311 - [X86] Add builtins for vpermq/vpermpd instructions to enable target feature checking.

2018-06-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jun  8 11:00:25 2018
New Revision: 334311

URL: http://llvm.org/viewvc/llvm-project?rev=334311=rev
Log:
[X86] Add builtins for vpermq/vpermpd instructions to enable target feature 
checking.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx2intrin.h
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/avx2-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334311=334310=334311=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Jun  8 11:00:25 2018
@@ -632,8 +632,10 @@ TARGET_BUILTIN(__builtin_ia32_psrlq256,
 TARGET_BUILTIN(__builtin_ia32_pblendd128, "V4iV4iV4iIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_pblendd256, "V8iV8iV8iIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsi256, "V8iV8iV8i", "nc", "avx2")
+TARGET_BUILTIN(__builtin_ia32_permdf256, "V4dV4dIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permvarsf256, "V8fV8fV8i", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_permti256, "V4LLiV4LLiV4LLiIi", "nc", "avx2")
+TARGET_BUILTIN(__builtin_ia32_permdi256, "V4LLiV4LLiIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_extract128i256, "V2LLiV4LLiIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_insert128i256, "V4LLiV4LLiV2LLiIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_maskloadd256, "V8iV8iC*V8i", "n", "avx2")
@@ -1710,6 +1712,8 @@ TARGET_BUILTIN(__builtin_ia32_vfmsubsd3_
 TARGET_BUILTIN(__builtin_ia32_vfmsubss3_mask3, "V4fV4fV4fV4fUcIi", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_vfnmsubsd3_mask3, "V2dV2dV2dV2dUcIi", "nc", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_vfnmsubss3_mask3, "V4fV4fV4fV4fUcIi", "nc", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_permdf512, "V8dV8dIi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_permdi512, "V8LLiV8LLiIi", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_permvarhi512, "V32sV32sV32s", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_permvardf512, "V8dV8dV8LLi", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_permvardi512, "V8LLiV8LLiV8LLi", "nc", "avx512f")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334311=334310=334311=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Jun  8 11:00:25 2018
@@ -9433,6 +9433,24 @@ Value *CodeGenFunction::EmitX86BuiltinEx
makeArrayRef(Indices, NumElts),
"shufp");
   }
+  case X86::BI__builtin_ia32_permdi256:
+  case X86::BI__builtin_ia32_permdf256:
+  case X86::BI__builtin_ia32_permdi512:
+  case X86::BI__builtin_ia32_permdf512: {
+unsigned Imm = cast(Ops[1])->getZExtValue();
+llvm::Type *Ty = Ops[0]->getType();
+unsigned NumElts = Ty->getVectorNumElements();
+
+// These intrinsics operate on 256-bit lanes of four 64-bit elements.
+uint32_t Indices[8];
+for (unsigned l = 0; l != NumElts; l += 4)
+  for (unsigned i = 0; i != 4; ++i)
+Indices[l + i] = l + ((Imm >> (2 * i)) & 0x3);
+
+return Builder.CreateShuffleVector(Ops[0], UndefValue::get(Ty),
+   makeArrayRef(Indices, NumElts),
+   "perm");
+  }
   case X86::BI__builtin_ia32_palignr128:
   case X86::BI__builtin_ia32_palignr256:
   case X86::BI__builtin_ia32_palignr512: {

Modified: cfe/trunk/lib/Headers/avx2intrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx2intrin.h?rev=334311=334310=334311=diff
==
--- cfe/trunk/lib/Headers/avx2intrin.h (original)
+++ cfe/trunk/lib/Headers/avx2intrin.h Fri Jun  8 11:00:25 2018
@@ -825,12 +825,7 @@ _mm256_permutevar8x32_epi32(__m256i __a,
 }
 
 #define _mm256_permute4x64_pd(V, M) \
-  (__m256d)__builtin_shufflevector((__v4df)(__m256d)(V), \
-   (__v4df)_mm256_undefined_pd(), \
-   ((M) >> 0) & 0x3, \
-   ((M) >> 2) & 0x3, \
-   ((M) >> 4) & 0x3, \
-   ((M) >> 6) & 0x3)
+  (__m256d)__builtin_ia32_permdf256((__v4df)(__m256d)(V), (int)(M))
 
 static __inline__ __m256 __DEFAULT_FN_ATTRS
 _mm256_permutevar8x32_ps(__m256 __a, __m256i __b)
@@ -839,12 +834,7 @@ _mm256_permutevar8x32_ps(__m256 __a, __m
 }
 
 #define 

[PATCH] D47953: [builtin] Add bitfield support for __builtin_dump_struct

2018-06-08 Thread Paul Semel via Phabricator via cfe-commits
paulsemel added a comment.

This version is working for non packed structures. For packed structures, it 
might sometimes work, sometimes not.
The resulting assembly code seems to be the right one.
If someone went through bitfields manipulation, please do not hesitate to 
comment !
Requesting for help :)


Repository:
  rC Clang

https://reviews.llvm.org/D47953



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


[PATCH] D47953: [builtin] Add bitfield support for __builtin_dump_struct

2018-06-08 Thread Paul Semel via Phabricator via cfe-commits
paulsemel created this revision.
paulsemel added a reviewer: aaron.ballman.

This is an attempt for adding bitfield support to __builtin_dump_struct.


Repository:
  rC Clang

https://reviews.llvm.org/D47953

Files:
  lib/CodeGen/CGBuiltin.cpp


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1170,6 +1170,7 @@
   RecordDecl *RD = RT->getDecl()->getDefinition();
   ASTContext  = RD->getASTContext();
   const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
+  const CGRecordLayout  = CGF.getTypes().getCGRecordLayout(RD);
   std::string Pad = std::string(Lvl * 4, ' ');
 
   Value *GString =
@@ -1208,7 +1209,7 @@
   FieldPtr, CGF.ConvertType(Context.getPointerType(FD->getType(;
 else
   FieldPtr = CGF.Builder.CreateStructGEP(CGF.ConvertType(RType), FieldPtr,
- FD->getFieldIndex());
+ CGRL.getLLVMFieldNo(FD));
 
 GString = CGF.Builder.CreateGlobalStringPtr(
 llvm::Twine(Pad)
@@ -1236,10 +1237,37 @@
  ? Types[Context.VoidPtrTy]
  : Types[CanonicalType];
 
+if (FD->isBitField())
+  FieldPtr = CGF.Builder.CreatePointerCast(
+  FieldPtr, CGF.ConvertType(Context.getPointerType(CanonicalType)));
+
 Address FieldAddress = Address(FieldPtr, Align);
 FieldPtr = CGF.Builder.CreateLoad(FieldAddress);
 
-// FIXME Need to handle bitfield here
+if (FD->isBitField()) {
+  const CGBitFieldInfo  = CGRL.getBitFieldInfo(FD);
+  if (Info.IsSigned) {
+unsigned HighBits = Info.StorageSize - Info.Offset - Info.Size;
+if (HighBits)
+  FieldPtr = CGF.Builder.CreateShl(FieldPtr, HighBits);
+if (Info.Offset + HighBits)
+  FieldPtr = CGF.Builder.CreateAShr(FieldPtr, Info.Offset + HighBits);
+  } else {
+if (Info.Offset)
+  FieldPtr = CGF.Builder.CreateLShr(FieldPtr, Info.Offset);
+if (static_cast(Info.Offset) + Info.Size < Info.StorageSize)
+  FieldPtr = CGF.Builder.CreateAnd(
+  FieldPtr,
+  ConstantInt::get(
+  CGF.ConvertType(CanonicalType),
+  llvm::APInt::getLowBitsSet(
+  CGF.CGM.getDataLayout().getTypeSizeInBits(CanonicalType),
+  Info.Size)));
+  }
+  FieldPtr = CGF.Builder.CreateIntCast(
+  FieldPtr, CGF.ConvertType(CanonicalType), Info.IsSigned);
+}
+
 GString = CGF.Builder.CreateGlobalStringPtr(
 Format.concat(llvm::Twine('\n')).str());
 TmpRes = CGF.Builder.CreateCall(Func, {GString, FieldPtr});


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1170,6 +1170,7 @@
   RecordDecl *RD = RT->getDecl()->getDefinition();
   ASTContext  = RD->getASTContext();
   const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
+  const CGRecordLayout  = CGF.getTypes().getCGRecordLayout(RD);
   std::string Pad = std::string(Lvl * 4, ' ');
 
   Value *GString =
@@ -1208,7 +1209,7 @@
   FieldPtr, CGF.ConvertType(Context.getPointerType(FD->getType(;
 else
   FieldPtr = CGF.Builder.CreateStructGEP(CGF.ConvertType(RType), FieldPtr,
- FD->getFieldIndex());
+ CGRL.getLLVMFieldNo(FD));
 
 GString = CGF.Builder.CreateGlobalStringPtr(
 llvm::Twine(Pad)
@@ -1236,10 +1237,37 @@
  ? Types[Context.VoidPtrTy]
  : Types[CanonicalType];
 
+if (FD->isBitField())
+  FieldPtr = CGF.Builder.CreatePointerCast(
+  FieldPtr, CGF.ConvertType(Context.getPointerType(CanonicalType)));
+
 Address FieldAddress = Address(FieldPtr, Align);
 FieldPtr = CGF.Builder.CreateLoad(FieldAddress);
 
-// FIXME Need to handle bitfield here
+if (FD->isBitField()) {
+  const CGBitFieldInfo  = CGRL.getBitFieldInfo(FD);
+  if (Info.IsSigned) {
+unsigned HighBits = Info.StorageSize - Info.Offset - Info.Size;
+if (HighBits)
+  FieldPtr = CGF.Builder.CreateShl(FieldPtr, HighBits);
+if (Info.Offset + HighBits)
+  FieldPtr = CGF.Builder.CreateAShr(FieldPtr, Info.Offset + HighBits);
+  } else {
+if (Info.Offset)
+  FieldPtr = CGF.Builder.CreateLShr(FieldPtr, Info.Offset);
+if (static_cast(Info.Offset) + Info.Size < Info.StorageSize)
+  FieldPtr = CGF.Builder.CreateAnd(
+  FieldPtr,
+  ConstantInt::get(
+  CGF.ConvertType(CanonicalType),
+  llvm::APInt::getLowBitsSet(
+  CGF.CGM.getDataLayout().getTypeSizeInBits(CanonicalType),
+  Info.Size)));
+  }
+  FieldPtr = 

[PATCH] D46651: [OpenCL] Support new/delete in Sema

2018-06-08 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 150535.
svenvh retitled this revision from "[OpenCL] Support placement new/delete in 
Sema" to "[OpenCL] Support new/delete in Sema".
svenvh edited the summary of this revision.
svenvh added a comment.

Relaxed the new/delete restrictions following the Khronos advice.


https://reviews.llvm.org/D46651

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCLCXX/newdelete.cl

Index: test/SemaOpenCLCXX/newdelete.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/newdelete.cl
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+class A {
+  public:
+  A() : x(21) {}
+  int x;
+};
+
+typedef __SIZE_TYPE__ size_t;
+
+class B {
+  public:
+  B() : bx(42) {}
+  void *operator new(size_t);
+  void operator delete(void *ptr);
+  int bx;
+};
+
+// There are no global user-defined new operators at this point. Test that clang
+// rejects these gracefully.
+void test_default_new_delete(void *buffer, A **pa) {
+  A *a = new A; // expected-error {{'default new' is not supported in OpenCL C++}}
+  delete a; // expected-error {{'default delete' is not supported in OpenCL C++}}
+  *pa = new (buffer) A; // expected-error {{'default new' is not supported in OpenCL C++}}
+}
+
+// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+void *operator new(size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+void *operator new[](size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+void test_new_delete(void *buffer, A **a, B **b) {
+  *a = new A; // expected-error {{no matching function for call to 'operator new'}}
+  delete a;   // expected-error {{'default delete' is not supported in OpenCL C++}}
+
+  *a = new A[20]; // expected-error {{no matching function for call to 'operator new[]'}}
+  delete[] *a;// expected-error {{'default delete' is not supported in OpenCL C++}}
+
+  // User-defined placement new is supported.
+  *a = new (buffer) A;
+
+  // User-defined placement new[] is supported.
+  *a = new (buffer) A[30];
+
+  // User-defined new is supported.
+  *b = new B;
+
+  // User-defined delete is supported.
+  delete *b;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7137,8 +7137,9 @@
   // The default address space name for arguments to a function in a
   // program, or local variables of a function is __private. All function
   // arguments shall be in the __private address space.
-  if (State.getSema().getLangOpts().OpenCLVersion <= 120) {
-  ImpAddr = LangAS::opencl_private;
+  if (State.getSema().getLangOpts().OpenCLVersion <= 120 &&
+  !State.getSema().getLangOpts().OpenCLCPlusPlus) {
+ImpAddr = LangAS::opencl_private;
   } else {
 // If address space is not set, OpenCL 2.0 defines non private default
 // address spaces for some cases:
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2146,7 +2146,8 @@
   else if (AllocType->isVariablyModifiedType())
 return Diag(Loc, diag::err_variably_modified_new_type)
  << AllocType;
-  else if (AllocType.getAddressSpace() != LangAS::Default)
+  else if (AllocType.getAddressSpace() != LangAS::Default &&
+  !getLangOpts().OpenCLCPlusPlus)
 return Diag(Loc, diag::err_address_space_qualified_new)
   << AllocType.getUnqualifiedType()
   << AllocType.getQualifiers().getAddressSpaceAttributePrintValue();
@@ -2362,6 +2363,11 @@
   LookupQualifiedName(R, Context.getTranslationUnitDecl());
 }
 
+if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
+  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  return true;
+}
+
 assert(!R.empty() && "implicitly declared allocation functions not found");
 assert(!R.isAmbiguous() && "global allocation functions are ambiguous");
 
@@ -2597,6 +2603,11 @@
   if (GlobalNewDeleteDeclared)
 return;
 
+  // OpenCL C++ 1.0 s2.9: the implicitly declared new and delete operators
+  // are not supported.
+  if (getLangOpts().OpenCLCPlusPlus)
+return;
+
   // C++ [basic.std.dynamic]p2:
   //   [...] The following allocation and deallocation functions (18.4) are
   //   implicitly declared in global scope in each translation unit of a
@@ -3230,7 +3241,8 @@
 QualType Pointee = Type->getAs()->getPointeeType();
 QualType PointeeElem = Context.getBaseElementType(Pointee);
 
-if (Pointee.getAddressSpace() != LangAS::Default)
+if (Pointee.getAddressSpace() != LangAS::Default &&
+!getLangOpts().OpenCLCPlusPlus)
   return Diag(Ex.get()->getLocStart(),
   

[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-06-08 Thread Yunlian Jiang via Phabricator via cfe-commits
yunlian added a comment.

ping?


https://reviews.llvm.org/D44788



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


[PATCH] D47950: [clangd] FuzzyMatch: forbid tail-tail matches after a miss: [pat] !~ "panther"

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 150531.
sammccall added a comment.

Simplify logic/make more consistent. Couple of extra test cases.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47950

Files:
  clangd/FuzzyMatch.cpp
  clangd/FuzzyMatch.h
  unittests/clangd/FuzzyMatchTests.cpp

Index: unittests/clangd/FuzzyMatchTests.cpp
===
--- unittests/clangd/FuzzyMatchTests.cpp
+++ unittests/clangd/FuzzyMatchTests.cpp
@@ -79,7 +79,7 @@
   EXPECT_THAT("", matches("unique_ptr"));
   EXPECT_THAT("u_p", matches("[u]nique[_p]tr"));
   EXPECT_THAT("up", matches("[u]nique_[p]tr"));
-  EXPECT_THAT("uq", matches("[u]ni[q]ue_ptr"));
+  EXPECT_THAT("uq", Not(matches("unique_ptr")));
   EXPECT_THAT("qp", Not(matches("unique_ptr")));
   EXPECT_THAT("log", Not(matches("SVGFEMorphologyElement")));
 
@@ -99,7 +99,7 @@
   EXPECT_THAT("moza", matches("-[moz]-[a]nimation"));
 
   EXPECT_THAT("ab", matches("[ab]A"));
-  EXPECT_THAT("ccm", matches("[c]a[cm]elCase"));
+  EXPECT_THAT("ccm", Not(matches("cacmelCase")));
   EXPECT_THAT("bti", Not(matches("the_black_knight")));
   EXPECT_THAT("ccm", Not(matches("camelCase")));
   EXPECT_THAT("cmcm", Not(matches("camelCase")));
@@ -110,17 +110,17 @@
   EXPECT_THAT("", Not(matches("SVisualLoggerLogsList")));
   EXPECT_THAT("TEdit", matches("[T]ext[Edit]"));
   EXPECT_THAT("TEdit", matches("[T]ext[Edit]or"));
-  EXPECT_THAT("TEdit", matches("[Te]xte[dit]"));
+  EXPECT_THAT("TEdit", Not(matches("[T]ext[edit]")));
   EXPECT_THAT("TEdit", matches("[t]ext_[edit]"));
-  EXPECT_THAT("TEditDit", matches("[T]ext[Edit]or[D]ecorat[i]on[T]ype"));
+  EXPECT_THAT("TEditDt", matches("[T]ext[Edit]or[D]ecoration[T]ype"));
   EXPECT_THAT("TEdit", matches("[T]ext[Edit]orDecorationType"));
   EXPECT_THAT("Tedit", matches("[T]ext[Edit]"));
   EXPECT_THAT("ba", Not(matches("?AB?")));
   EXPECT_THAT("bkn", matches("the_[b]lack_[kn]ight"));
-  EXPECT_THAT("bt", matches("the_[b]lack_knigh[t]"));
-  EXPECT_THAT("ccm", matches("[c]amelCase[cm]"));
-  EXPECT_THAT("fdm", matches("[f]in[dM]odel"));
-  EXPECT_THAT("fob", matches("[fo]o[b]ar"));
+  EXPECT_THAT("bt", Not(matches("the_[b]lack_knigh[t]")));
+  EXPECT_THAT("ccm", Not(matches("[c]amelCase[cm]")));
+  EXPECT_THAT("fdm", Not(matches("[f]in[dM]odel")));
+  EXPECT_THAT("fob", Not(matches("[fo]o[b]ar")));
   EXPECT_THAT("fobz", Not(matches("foobar")));
   EXPECT_THAT("foobar", matches("[foobar]"));
   EXPECT_THAT("form", matches("editor.[form]atOnSave"));
@@ -132,14 +132,14 @@
   EXPECT_THAT("gp", matches("[G]it_Git_[P]ull"));
   EXPECT_THAT("is", matches("[I]mport[S]tatement"));
   EXPECT_THAT("is", matches("[is]Valid"));
-  EXPECT_THAT("lowrd", matches("[low]Wo[rd]"));
-  EXPECT_THAT("myvable", matches("[myva]ria[ble]"));
+  EXPECT_THAT("lowrd", Not(matches("[low]Wo[rd]")));
+  EXPECT_THAT("myvable", Not(matches("[myva]ria[ble]")));
   EXPECT_THAT("no", Not(matches("")));
   EXPECT_THAT("no", Not(matches("match")));
   EXPECT_THAT("ob", Not(matches("foobar")));
   EXPECT_THAT("sl", matches("[S]Visual[L]oggerLogsList"));
-  EXPECT_THAT("s", matches("[S]Visua[lL]ogger[L]ogs[L]ist"));
-  EXPECT_THAT("Three", matches("H[T]ML[HRE]l[e]ment"));
+  EXPECT_THAT("s", matches("[S]Visua[L]ogger[Ll]ama[L]ist"));
+  EXPECT_THAT("THRE", matches("H[T]ML[HRE]lement"));
   EXPECT_THAT("b", Not(matches("NDEBUG")));
   EXPECT_THAT("Three", matches("[Three]"));
   EXPECT_THAT("fo", Not(matches("barfoo")));
@@ -173,6 +173,9 @@
   // These would ideally match, but would need special segmentation rules.
   EXPECT_THAT("printf", Not(matches("s[printf]")));
   EXPECT_THAT("str", Not(matches("o[str]eam")));
+  EXPECT_THAT("strcpy", Not(matches("strncpy")));
+  EXPECT_THAT("std", Not(matches("PTHREAD_MUTEX_STALLED")));
+  EXPECT_THAT("std", Not(matches("pthread_condattr_setpshared")));
 }
 
 struct RankMatcher : public testing::MatcherInterface {
@@ -236,12 +239,11 @@
 }
 
 TEST(FuzzyMatch, Ranking) {
-  EXPECT_THAT("eb", ranks("[e]mplace_[b]ack", "[e]m[b]ed"));
   EXPECT_THAT("cons",
   ranks("[cons]ole", "[Cons]ole", "ArrayBuffer[Cons]tructor"));
   EXPECT_THAT("foo", ranks("[foo]", "[Foo]"));
-  EXPECT_THAT("onMess",
-  ranks("[onMess]age", "[onmess]age", "[on]This[M]ega[Es]cape[s]"));
+  EXPECT_THAT("onMes",
+  ranks("[onMes]sage", "[onmes]sage", "[on]This[M]ega[Es]capes"));
   EXPECT_THAT("CC", ranks("[C]amel[C]ase", "[c]amel[C]ase"));
   EXPECT_THAT("cC", ranks("[c]amel[C]ase", "[C]amel[C]ase"));
   EXPECT_THAT("p", ranks("[p]", "[p]arse", "[p]osix", "[p]afdsa", "[p]ath"));
@@ -259,18 +261,13 @@
   ranks("[convertModelPosition]ToViewPosition",
 "[convert]ViewTo[ModelPosition]"));
   EXPECT_THAT("is", ranks("[is]ValidViewletId", "[i]mport [s]tatement"));
-  EXPECT_THAT("title", ranks("window.[title]",
- "files.[t]r[i]m[T]rai[l]ingWhit[e]space"));
-  EXPECT_THAT("strcpy", ranks("[strcpy]", 

[PATCH] D45202: [X86] Replacing X86-specific floor and ceil vector intrinsics with generic LLVM intrinsics

2018-06-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I'm not sure whether we should be doing this here or in InstCombine. @spatel, 
what do you think?


https://reviews.llvm.org/D45202



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


[PATCH] D47950: [clangd] FuzzyMatch: forbid tail-tail matches after a miss: [pat] !~ "panther"

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ioeric.

This is a small code change but vastly reduces noise in code completion results.
The intent of allowing this was to let [sc] ~ "strncpy" and [strcpy] ~ "strncpy"
however the benefits for unsegmented names aren't IMO worth the costs.

Test cases should be representative of the changes here.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47950

Files:
  clangd/FuzzyMatch.cpp
  clangd/FuzzyMatch.h
  unittests/clangd/FuzzyMatchTests.cpp

Index: unittests/clangd/FuzzyMatchTests.cpp
===
--- unittests/clangd/FuzzyMatchTests.cpp
+++ unittests/clangd/FuzzyMatchTests.cpp
@@ -79,7 +79,7 @@
   EXPECT_THAT("", matches("unique_ptr"));
   EXPECT_THAT("u_p", matches("[u]nique[_p]tr"));
   EXPECT_THAT("up", matches("[u]nique_[p]tr"));
-  EXPECT_THAT("uq", matches("[u]ni[q]ue_ptr"));
+  EXPECT_THAT("uq", Not(matches("unique_ptr")));
   EXPECT_THAT("qp", Not(matches("unique_ptr")));
   EXPECT_THAT("log", Not(matches("SVGFEMorphologyElement")));
 
@@ -99,7 +99,7 @@
   EXPECT_THAT("moza", matches("-[moz]-[a]nimation"));
 
   EXPECT_THAT("ab", matches("[ab]A"));
-  EXPECT_THAT("ccm", matches("[c]a[cm]elCase"));
+  EXPECT_THAT("ccm", Not(matches("cacmelCase")));
   EXPECT_THAT("bti", Not(matches("the_black_knight")));
   EXPECT_THAT("ccm", Not(matches("camelCase")));
   EXPECT_THAT("cmcm", Not(matches("camelCase")));
@@ -110,17 +110,17 @@
   EXPECT_THAT("", Not(matches("SVisualLoggerLogsList")));
   EXPECT_THAT("TEdit", matches("[T]ext[Edit]"));
   EXPECT_THAT("TEdit", matches("[T]ext[Edit]or"));
-  EXPECT_THAT("TEdit", matches("[Te]xte[dit]"));
+  EXPECT_THAT("TEdit", matches("[T]ext[edit]"));
   EXPECT_THAT("TEdit", matches("[t]ext_[edit]"));
-  EXPECT_THAT("TEditDit", matches("[T]ext[Edit]or[D]ecorat[i]on[T]ype"));
+  EXPECT_THAT("TEditDt", matches("[T]ext[Edit]or[D]ecoration[T]ype"));
   EXPECT_THAT("TEdit", matches("[T]ext[Edit]orDecorationType"));
   EXPECT_THAT("Tedit", matches("[T]ext[Edit]"));
   EXPECT_THAT("ba", Not(matches("?AB?")));
   EXPECT_THAT("bkn", matches("the_[b]lack_[kn]ight"));
-  EXPECT_THAT("bt", matches("the_[b]lack_knigh[t]"));
-  EXPECT_THAT("ccm", matches("[c]amelCase[cm]"));
-  EXPECT_THAT("fdm", matches("[f]in[dM]odel"));
-  EXPECT_THAT("fob", matches("[fo]o[b]ar"));
+  EXPECT_THAT("bt", Not(matches("the_[b]lack_knigh[t]")));
+  EXPECT_THAT("ccm", Not(matches("[c]amelCase[cm]")));
+  EXPECT_THAT("fdm", Not(matches("[f]in[dM]odel")));
+  EXPECT_THAT("fob", Not(matches("[fo]o[b]ar")));
   EXPECT_THAT("fobz", Not(matches("foobar")));
   EXPECT_THAT("foobar", matches("[foobar]"));
   EXPECT_THAT("form", matches("editor.[form]atOnSave"));
@@ -132,14 +132,14 @@
   EXPECT_THAT("gp", matches("[G]it_Git_[P]ull"));
   EXPECT_THAT("is", matches("[I]mport[S]tatement"));
   EXPECT_THAT("is", matches("[is]Valid"));
-  EXPECT_THAT("lowrd", matches("[low]Wo[rd]"));
-  EXPECT_THAT("myvable", matches("[myva]ria[ble]"));
+  EXPECT_THAT("lowrd", Not(matches("[low]Wo[rd]")));
+  EXPECT_THAT("myvable", Not(matches("[myva]ria[ble]")));
   EXPECT_THAT("no", Not(matches("")));
   EXPECT_THAT("no", Not(matches("match")));
   EXPECT_THAT("ob", Not(matches("foobar")));
   EXPECT_THAT("sl", matches("[S]Visual[L]oggerLogsList"));
-  EXPECT_THAT("s", matches("[S]Visua[lL]ogger[L]ogs[L]ist"));
-  EXPECT_THAT("Three", matches("H[T]ML[HRE]l[e]ment"));
+  EXPECT_THAT("s", matches("[S]Visua[L]ogger[Ll]ama[L]ist"));
+  EXPECT_THAT("Thre", matches("H[T]ML[HRE]lement"));
   EXPECT_THAT("b", Not(matches("NDEBUG")));
   EXPECT_THAT("Three", matches("[Three]"));
   EXPECT_THAT("fo", Not(matches("barfoo")));
@@ -173,6 +173,7 @@
   // These would ideally match, but would need special segmentation rules.
   EXPECT_THAT("printf", Not(matches("s[printf]")));
   EXPECT_THAT("str", Not(matches("o[str]eam")));
+  EXPECT_THAT("strcpy", Not(matches("strncpy")));
 }
 
 struct RankMatcher : public testing::MatcherInterface {
@@ -236,12 +237,11 @@
 }
 
 TEST(FuzzyMatch, Ranking) {
-  EXPECT_THAT("eb", ranks("[e]mplace_[b]ack", "[e]m[b]ed"));
   EXPECT_THAT("cons",
   ranks("[cons]ole", "[Cons]ole", "ArrayBuffer[Cons]tructor"));
   EXPECT_THAT("foo", ranks("[foo]", "[Foo]"));
-  EXPECT_THAT("onMess",
-  ranks("[onMess]age", "[onmess]age", "[on]This[M]ega[Es]cape[s]"));
+  EXPECT_THAT("onMes",
+  ranks("[onMes]sage", "[onmes]sage", "[on]This[M]ega[Es]capes"));
   EXPECT_THAT("CC", ranks("[C]amel[C]ase", "[c]amel[C]ase"));
   EXPECT_THAT("cC", ranks("[c]amel[C]ase", "[C]amel[C]ase"));
   EXPECT_THAT("p", ranks("[p]", "[p]arse", "[p]osix", "[p]afdsa", "[p]ath"));
@@ -259,18 +259,13 @@
   ranks("[convertModelPosition]ToViewPosition",
 "[convert]ViewTo[ModelPosition]"));
   EXPECT_THAT("is", ranks("[is]ValidViewletId", "[i]mport [s]tatement"));
-  

[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In https://reviews.llvm.org/D47687#1126074, @lebedev.ri wrote:

> In https://reviews.llvm.org/D47687#1126032, @Higuoxing wrote:
>
> > In https://reviews.llvm.org/D47687#1125926, @rnk wrote:
> >
> > > @dexonsmith is there someone from Apple who can comment on rdar://8678458 
> > > and the merits of disabling this warning in macros? I strongly suspect 
> > > the original report was dealing with code like `assert(x || y && 
> > > "str");`, if so we can go forward with this.
> > >
> > > @chandlerc I know you've hit this behavior difference vs. GCC before. Any 
> > > thoughts on the proposed change?
> >
> >
> >
> >
> > In https://reviews.llvm.org/D47687#1125964, @dexonsmith wrote:
> >
> > > In https://reviews.llvm.org/D47687#1125926, @rnk wrote:
> > >
> > > > @dexonsmith is there someone from Apple who can comment on 
> > > > rdar://8678458 and the merits of disabling this warning in macros? I 
> > > > strongly suspect the original report was dealing with code like 
> > > > `assert(x || y && "str");`, if so we can go forward with this.
> > >
> > >
> > > There were two commits with this radar: r119537 and r119540.  The main 
> > > motivation was a deeply nested macro that when "inlined" included the 
> > > moral equivalent of `#define DOUBLE_OP(OP1, OP2, X, Y, Z) (X OP1 Y OP2 
> > > Z)`.  There was terrible note spew when the warning fired in this case, 
> > > and the use case for the macro made the warning un-actionable.  We 
> > > decided to suppress the warning entirely:
> > >
> > > > As a general comment, the warning seems to be useless for macros; I'll 
> > > > follow the example of warn_logical_instead_of_bitwise which doesn't 
> > > > trigger for macros and I'll make the warning not warn for macros.
> >
> >
> > Hi, Thank you,
> >
> > I noticed that `warn_logical_instead_of_bitwise ` will also skip 
> > parentheses checking in macros... well, this patch seems not so 
> > necessary... both ok for me ... depends on all of you :-)
>
>
> At worst, we can issue this warning in a new `-Wparentheses-in-macros` 
> subgroup, which, if apple so insists, could be off-by-default.
>  That would less worse than just completely silencing it for the entire world.


I’d be fine with strengthening the existing warning as long as there is an 
actionable fix-it.  I suspect if you suppress it when the relevant expression 
is constructed from multiple macro arguments that will be good enough.


https://reviews.llvm.org/D47687



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


Re: r334208 - [X86] Add back builtins for _mm_slli_si128/_mm_srli_si128 and similar intrinsics.

2018-06-08 Thread Craig Topper via cfe-commits
Maybe we're checking the range too early. Maybe we need to do it during IR
emission instead of during semantic analysis.

~Craig


On Fri, Jun 8, 2018 at 12:59 AM Martin Storsjö via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Thu, 7 Jun 2018, Craig Topper via cfe-commits wrote:
>
> > Author: ctopper
> > Date: Thu Jun  7 10:28:03 2018
> > New Revision: 334208
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=334208=rev
> > Log:
> > [X86] Add back builtins for  _mm_slli_si128/_mm_srli_si128 and similar
> intrinsics.
> >
> > We still lower them to native shuffle IR, but we do it in CGBuiltin.cpp
> now. This allows us to check the target feature and ensure the immediate
> fits in 8 bits.
>
> FWIW, this change broke building libaom:
> https://bugs.chromium.org/p/aomedia/issues/detail?id=1945
>
> In libaom, there's a macro construct like this:
>
>   #define v256_shr_n_byte(a, n)
>  \
> ((n) < 16
>  \
>  ? _mm256_alignr_epi8(
>   \
>_mm256_permute2x128_si256(a, a, _MM_SHUFFLE(2, 0, 0, 1)),
> a, n)  \
>  : ((n) > 16
>   \
> ? _mm256_srli_si256(
>   \
>   _mm256_permute2x128_si256(a, a, _MM_SHUFFLE(2, 0, 0,
> 1)), \
>   (n)-16)
>  \
> : _mm256_permute2x128_si256(a, a, _MM_SHUFFLE(2, 0, 0,
> 1
>
> Since this commit, the compilation errors out due to the _mm256_srli_si256
> with invalid range, even though the toplevel ternary operator won't
> actually pick them to be used. Not sure if there's anything to do from the
> clang point of view here, I guess it's a tradeoff between having stricter
> parameter checks for the intrinsics, vs the convenience of piling them up
> in a macro like this in libaom.
>
> // Martin
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47946: [ASTmporter] Fix infinite recursion on function import with struct definition in parameters

2018-06-08 Thread Zoltán Gera via Phabricator via cfe-commits
gerazo created this revision.
gerazo added reviewers: a.sidorin, r.stahl.
Herald added a subscriber: cfe-commits.

Importing a function having a struct definition in the parameter list causes a 
crash in the importer via infinite recursion. This patch avoids the crash and 
reports such functions as not supported. Unit tests make sure that normal 
struct definitions inside function bodies work normally on the other hand and 
LLDB-like type imports also do.


Repository:
  rC Clang

https://reviews.llvm.org/D47946

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -168,11 +168,52 @@
 std::string FileName;
 std::unique_ptr Unit;
 TranslationUnitDecl *TUDecl = nullptr;
+std::unique_ptr Importer;
+
 TU(StringRef Code, StringRef FileName, ArgVector Args)
 : Code(Code), FileName(FileName),
   Unit(tooling::buildASTFromCodeWithArgs(this->Code, Args,
  this->FileName)),
-  TUDecl(Unit->getASTContext().getTranslationUnitDecl()) {}
+  TUDecl(Unit->getASTContext().getTranslationUnitDecl()) {
+  BeginSourceFile(&*Unit);
+}
+
+~TU() { EndSourceFile(&*Unit); }
+
+static void BeginSourceFile(ASTUnit *diagASTUnit) {
+  assert(diagASTUnit->getDiagnostics().getClient() &&
+ diagASTUnit->getPreprocessorPtr() &&
+ "Bad context for source file");
+  diagASTUnit->getDiagnostics().getClient()->BeginSourceFile(
+  diagASTUnit->getASTContext().getLangOpts(),
+  >getPreprocessor());
+}
+
+static void EndSourceFile(ASTUnit *diagASTUnit) {
+  if (diagASTUnit->isMainFileAST() &&
+  diagASTUnit->getDiagnostics().getClient()) {
+diagASTUnit->getDiagnostics().getClient()->EndSourceFile();
+  }
+}
+
+void lazyInitImporter(ASTUnit *ToAST) {
+  assert(ToAST);
+  if (!Importer) {
+Importer.reset(new ASTImporter(
+ToAST->getASTContext(), ToAST->getFileManager(),
+Unit->getASTContext(), Unit->getFileManager(), false));
+  }
+}
+
+Decl *import(ASTUnit *ToAST, Decl *FromDecl) {
+  lazyInitImporter(ToAST);
+  return Importer->Import(FromDecl);
+ }
+
+QualType import(ASTUnit *ToAST, QualType FromType) {
+  lazyInitImporter(ToAST);
+  return Importer->Import(FromType);
+}
   };
 
   // We may have several From contexts and related translation units. In each
@@ -184,6 +225,28 @@
   // vector is expanding, with the list we won't have these issues.
   std::list FromTUs;
 
+  void lazyInitToAST(Language ToLang) {
+if (ToAST)
+  return;
+ArgVector ToArgs = getArgVectorForLanguage(ToLang);
+// Build the AST from an empty file.
+ToAST = tooling::buildASTFromCodeWithArgs(/*Code=*/"", ToArgs, "empty.cc");
+TU::BeginSourceFile(&*ToAST);
+  }
+
+  TU *findFromTU(Decl *From) {
+// Create a virtual file in the To Ctx which corresponds to the file from
+// which we want to import the `From` Decl. Without this source locations
+// will be invalid in the ToCtx.
+auto It = std::find_if(FromTUs.begin(), FromTUs.end(), [From](const TU ) {
+  return E.TUDecl == From->getTranslationUnitDecl();
+});
+assert(It != FromTUs.end());
+assert(ToAST);
+createVirtualFileIfNeeded(ToAST.get(), It->FileName, It->Code);
+return &*It;
+  }
+
 public:
   // We may have several From context but only one To context.
   std::unique_ptr ToAST;
@@ -214,15 +277,12 @@
 ToCode = ToSrcCode;
 assert(!ToAST);
 ToAST = tooling::buildASTFromCodeWithArgs(ToCode, ToArgs, OutputFileName);
+TU::BeginSourceFile(&*ToAST);
 
-ASTContext  = FromTU.Unit->getASTContext(),
-= ToAST->getASTContext();
+ASTContext  = FromTU.Unit->getASTContext();
 
 createVirtualFileIfNeeded(ToAST.get(), InputFileName, FromTU.Code);
 
-ASTImporter Importer(ToCtx, ToAST->getFileManager(), FromCtx,
- FromTU.Unit->getFileManager(), false);
-
 IdentifierInfo *ImportedII = (Identifier);
 assert(ImportedII && "Declaration with the given identifier "
  "should be specified in test!");
@@ -233,7 +293,7 @@
 
 assert(FoundDecls.size() == 1);
 
-Decl *Imported = Importer.Import(FoundDecls.front());
+Decl *Imported = FromTU.import(ToAST.get(), FoundDecls.front());
 assert(Imported);
 return std::make_tuple(*FoundDecls.begin(), Imported);
   }
@@ -269,29 +329,17 @@
   // May be called several times in a given test.
   // The different instances of the param From may have different ASTContext.
   Decl *Import(Decl *From, Language ToLang) {
-if (!ToAST) {
-  ArgVector ToArgs = getArgVectorForLanguage(ToLang);
-  // Build the AST from an empty file.
-  ToAST =

[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing added a comment.

This diff version pass the both `parentheses.c` and `logical-op-parentheses.c`


https://reviews.llvm.org/D47687



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing updated this revision to Diff 150517.

https://reviews.llvm.org/D47687

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/logical-op-parentheses-in-macros.c

Index: test/Sema/logical-op-parentheses-in-macros.c
===
--- test/Sema/logical-op-parentheses-in-macros.c
+++ test/Sema/logical-op-parentheses-in-macros.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=silence %s
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify=silence %s
+// RUN: %clang_cc1 -Wlogical-op-parentheses-in-macros -fsyntax-only \
+// RUN:-verify=logical-op-parentheses %s
+// RUN: %clang_cc1 -Wlogical-op-parentheses -fsyntax-only \
+// RUN:-verify=silence %s
+
+#define macro_op_parentheses_check(x) ( \
+  ( (void)(x) ) \
+)
+
+// silence-no-diagnostics
+void logical_op_in_macros_test(unsigned i) {
+  macro_op_parentheses_check(i || i && i); // logical-op-parentheses-warning {{'&&' within '||'}} \
+   // logical-op-parentheses-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i || i && "I love LLVM"); // no warning.
+  macro_op_parentheses_check("I love LLVM" && i || i); // no warning.
+
+  macro_op_parentheses_check(i || i && "I love LLVM" || i); // logical-op-parentheses-warning {{'&&' within '||'}} \
+// logical-op-parentheses-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i || "I love LLVM" && i || i); // logical-op-parentheses-warning {{'&&' within '||'}} \
+// logical-op-parentheses-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i && i || 0); // no warning.
+  macro_op_parentheses_check(0 || i && i); // no warning.
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12172,8 +12172,16 @@
 EmitDiagnosticForLogicalAndInLogicalOr(Sema , SourceLocation OpLoc,
BinaryOperator *Bop) {
   assert(Bop->getOpcode() == BO_LAnd);
-  Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or)
-  << Bop->getSourceRange() << OpLoc;
+  Self.Diag(Bop->getOperatorLoc(), !OpLoc.isMacroID() ?
+// if this warning is in a normal context
+diag::warn_logical_and_in_logical_or :
+// else this warning is in a macro context
+// currently, this will not warn in macros by default.
+// add [-Wlogical-op-parentheses-in-macros]
+// to enable this warning.
+diag::warn_logical_and_in_logical_or_in_macros
+  ) << Bop->getSourceRange() << OpLoc;
+  
   SuggestParentheses(Self, Bop->getOperatorLoc(),
 Self.PDiag(diag::note_precedence_silence)
   << Bop->getOpcodeStr(),
@@ -12205,6 +12213,7 @@
   if (EvaluatesAsFalse(S, RHSExpr))
 return;
   // If it's "1 && a || b" don't warn since the precedence doesn't matter.
+  // And 'assert("some message" && a || b)' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getLHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 } else if (Bop->getOpcode() == BO_LOr) {
@@ -12227,6 +12236,7 @@
   if (EvaluatesAsFalse(S, LHSExpr))
 return;
   // If it's "a || b && 1" don't warn since the precedence doesn't matter.
+  // And 'assert(a || b && "some message")' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getRHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 }
@@ -12309,8 +12319,11 @@
   }
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
-  // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  // Here we will not skip 'logical and in logical or' checking
+  // in macros, since 'assert(a || b && "some message")' is equal
+  // to '(a || b && 1)' and 'assert("some message" && a || b)' is
+  // equal to '(1 && a || b)'.
+  if (Opc == BO_LOr) {
 DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
 DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5483,6 +5483,10 @@
 def warn_logical_and_in_logical_or : Warning<
   "'&&' within '||'">, InGroup;
 
+def warn_logical_and_in_logical_or_in_macros: 
+  Warning, 
+  InGroup, DefaultIgnore;
+
 def warn_overloaded_shift_in_comparison :Warning<
   "overloaded operator %select{>>|<<}0 has higher precedence than "
   

[PATCH] D12921: clang-format: Support 'template<>' (no space).

2018-06-08 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

This was merged here: https://reviews.llvm.org/D23317
we can close this review


https://reviews.llvm.org/D12921



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


[PATCH] D47935: [clangd] Boost completion score according to file proximity.

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

Here are some numbers by completing "clang::^" 40 times (with result limit 1000 
instead of 100).

Timing in `CodeCompleteFlow::measureResults`

  Before: Avg: 1811 us Med: 1792 us 
  After: Avg: 2714 us Med: 2689 us

As a reference, a full CodeCompleteFlow (with 1000 candidates) takes ~70 ms 
(using LLVM's yaml index).

So, with the current limit of 100 results, the increase for measureResults 
should be roughly 0.18ms -> 0.27ms, which I think is reasonable.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935



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


[PATCH] D46651: [OpenCL] Support placement new/delete in Sema

2018-06-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia requested changes to this revision.
Anastasia added inline comments.
This revision now requires changes to proceed.



Comment at: lib/Sema/SemaExprCXX.cpp:2030
+  }
+}
 

svenvh wrote:
> rjmccall wrote:
> > I think a better interpretation of this rule would be to just error on 
> > attempts to use the standard non-placement operator new/delete instead of 
> > trying to outlaw the operator declarations.  For example, I don't know why 
> > a user-defined non-global operator new would be problematic.
> Good point, I have raised this with Khronos, so I will hold this off until we 
> have clarification.
The decision by Khronos is to allow all user defined new/delete operators (even 
global). I have submitted the change to the spec. The next publishing date is 
however in July.


Repository:
  rC Clang

https://reviews.llvm.org/D46651



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


[PATCH] D47044: [analyzer] Ensure that we only visit a destructor for a reference if type information is available.

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

I didn't test the code, but the code seems correct. Thanks!




Comment at: lib/StaticAnalyzer/Core/LoopWidening.cpp:88
+  MatchFinder Finder;
+  Finder.addMatcher(varDecl(hasType(referenceType())).bind("match"), new 
Callback(LCtx, MRMgr, ITraits));
+  Finder.matchAST(ASTCtx);

The code should fit within 80 columns of text.



Comment at: test/Analysis/loop-widening-invalid-type.cpp:1
+// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-max-loop 4 
-analyzer-config widen-loops=true -verify %s
+

I think it's better to add more expressive tests. Like:

```
struct A {
  int x;
  A(int x) : x(x) {}
};

void invalid_type_region_access() {
  const A  = A(10);
  for(int i = 0; i < 10; ++i) {}
  clang_analyzer_eval(a.x ==10); // expected-warning{{TRUE}}
}
```

I think should use more related names instead of 
`loop-widening-invalid-type.cpp`, like `loop-widening-reference-type`.



Comment at: test/Analysis/loop-widening-invalid-type.cpp:8
+
+void invalid_type_region_access() { // expected-no-diagnostics
+  const A  = B();

I don't know what the purpose of the test is, is the comment `no-crash` better?


Repository:
  rC Clang

https://reviews.llvm.org/D47044



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


[PATCH] D47945: Add support for arrays in performance-implicit-conversion-in-loop

2018-06-08 Thread Alex Pilkiewicz via Phabricator via cfe-commits
pilki created this revision.
pilki added a reviewer: alexfh.
Herald added a subscriber: cfe-commits.

Add support for arrays (and structure that use naked pointers for their 
iterator, like std::array) in performance-implicit-conversion-in-loop


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47945

Files:
  clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
  clang-tidy/performance/ImplicitConversionInLoopCheck.h
  test/clang-tidy/performance-implicit-conversion-in-loop.cpp

Index: test/clang-tidy/performance-implicit-conversion-in-loop.cpp
===
--- test/clang-tidy/performance-implicit-conversion-in-loop.cpp
+++ test/clang-tidy/performance-implicit-conversion-in-loop.cpp
@@ -40,7 +40,7 @@
 template 
 class OperatorWrapper {
  public:
-  explicit OperatorWrapper(const T& t);
+  OperatorWrapper() = delete;
 };
 
 struct SimpleClass {
@@ -101,61 +101,97 @@
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit conversion; you can either change the type to the matching one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value [performance-implicit-conversion-in-loop]
   // for (ImplicitWrapper& foo : SimpleView()) {}
   for (const ImplicitWrapper foo : SimpleView()) {}
-  for (ImplicitWrapperfoo : SimpleView()) {}
+  for (ImplicitWrapper foo : SimpleView()) {}
 }
 
 void ImplicitSimpleClassRefIterator() {
   for (const ImplicitWrapper& foo : SimpleRefView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
   // for (ImplicitWrapper& foo : SimpleRefView()) {}
   for (const ImplicitWrapper foo : SimpleRefView()) {}
-  for (ImplicitWrapperfoo : SimpleRefView()) {}
+  for (ImplicitWrapper foo : SimpleRefView()) {}
+}
+
+void ImplicitSimpleClassArray() {
+  SimpleClass array[5];
+  for (const ImplicitWrapper& foo : array) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+  // for (ImplicitWrapper& foo : array) {}
+  for (const ImplicitWrapper foo : array) {}
+  for (ImplicitWrapper foo : array) {}
 }
 
 void ImplicitComplexClassIterator() {
   for (const ImplicitWrapper& foo : ComplexView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
   // for (ImplicitWrapper& foo : ComplexView()) {}
   for (const ImplicitWrapper foo : ComplexView()) {}
-  for (ImplicitWrapperfoo : ComplexView()) {}
+  for (ImplicitWrapper foo : ComplexView()) {}
 }
 
 void ImplicitComplexClassRefIterator() {
+  ComplexClass array[5];
+  for (const ImplicitWrapper& foo : array) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+  // for (ImplicitWrapper& foo : array) {}
+  for (const ImplicitWrapper foo : array) {}
+  for (ImplicitWrapper foo : array) {}
+}
+
+void ImplicitComplexClassArray() {
   for (const ImplicitWrapper& foo : ComplexRefView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
   // for (ImplicitWrapper& foo : ComplexRefView()) {}
   for (const ImplicitWrapper foo : ComplexRefView()) {}
-  for (ImplicitWrapperfoo : ComplexRefView()) {}
+  for (ImplicitWrapper foo : ComplexRefView()) {}
 }
 
 void OperatorSimpleClassIterator() {
   for (const OperatorWrapper& foo : SimpleView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
   // for (OperatorWrapper& foo : SimpleView()) {}
   for (const OperatorWrapper foo : SimpleView()) {}
-  for (OperatorWrapperfoo : SimpleView()) {}
+  for (OperatorWrapper foo : SimpleView()) {}
 }
 
 void OperatorSimpleClassRefIterator() {
   for (const OperatorWrapper& foo : SimpleRefView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
   // for (OperatorWrapper& foo : SimpleRefView()) {}
   for (const OperatorWrapper foo : SimpleRefView()) {}
-  for (OperatorWrapperfoo : SimpleRefView()) {}
+  for (OperatorWrapper foo : SimpleRefView()) {}
+}
+
+void OperatorSimpleClassArray() {
+  SimpleClass array[5];
+  for (const OperatorWrapper& foo : array) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+  // for (OperatorWrapper& foo : array) {}
+  for (const OperatorWrapper foo : array) {}
+  for (OperatorWrapper foo : array) {}
 }
 
 void OperatorComplexClassIterator() {
   for (const OperatorWrapper& foo : ComplexView()) {}
   // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
   // for (OperatorWrapper& foo : ComplexView()) {}
   for (const OperatorWrapper foo : ComplexView()) {}
-  for (OperatorWrapperfoo : ComplexView()) {}
+  for 

[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-08 Thread Takuto Ikuta via Phabricator via cfe-commits
takuto.ikuta marked 2 inline comments as done.
takuto.ikuta added a comment.

Can the patch be merged this time?


https://reviews.llvm.org/D47578



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


[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-08 Thread Takuto Ikuta via Phabricator via cfe-commits
takuto.ikuta updated this revision to Diff 150515.

https://reviews.llvm.org/D47578

Files:
  llvm/lib/Support/Windows/Process.inc
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/StringSaver.h"
@@ -821,4 +822,22 @@
   EXPECT_TRUE(Errs.empty());
 }
 
+#ifdef _WIN32
+TEST(CommandLineTest, GetCommandLineArguments) {
+  int argc = __argc;
+  char **argv = __argv;
+
+  // GetCommandLineArguments is called in InitLLVM.
+  llvm::InitLLVM X(argc, argv);
+
+  EXPECT_EQ(llvm::sys::path::is_absolute(argv[0]),
+llvm::sys::path::is_absolute(__argv[0]));
+
+  EXPECT_TRUE(llvm::sys::path::filename(argv[0])
+  .equals_lower("supporttests.exe"))
+  << "Filename of test executable is "
+  << llvm::sys::path::filename(argv[0]);
+}
+#endif
+
 }  // anonymous namespace
Index: llvm/lib/Support/Windows/Process.inc
===
--- llvm/lib/Support/Windows/Process.inc
+++ llvm/lib/Support/Windows/Process.inc
@@ -209,55 +209,65 @@
   return ec;
 }
 
-static std::error_code ExpandShortFileName(const wchar_t *Arg,
-   SmallVectorImpl ,
-   BumpPtrAllocator ) {
-  SmallVector LongPath;
-  DWORD Length = GetLongPathNameW(Arg, LongPath.data(), LongPath.capacity());
+static std::error_code GetExecutableName(SmallVectorImpl ) {
+  // The first argument may contain just the name of the executable (e.g.,
+  // "clang") rather than the full path, so swap it with the full path.
+  wchar_t ModuleName[MAX_PATH];
+  int Length = ::GetModuleFileNameW(NULL, ModuleName, MAX_PATH);
+  if (Length == 0 || Length == MAX_PATH) {
+return mapWindowsError(GetLastError());
+  }
+
+  // If the first argument is a shortened (8.3) name (which is possible even
+  // if we got the module name), the driver will have trouble distinguishing it
+  // (e.g., clang.exe v. clang++.exe), so expand it now.
+  Length = GetLongPathNameW(ModuleName, ModuleName, MAX_PATH);
   if (Length == 0)
 return mapWindowsError(GetLastError());
-  if (Length > LongPath.capacity()) {
+  if (static_cast(Length) > MAX_PATH) {
 // We're not going to try to deal with paths longer than MAX_PATH, so we'll
 // treat this as an error.  GetLastError() returns ERROR_SUCCESS, which
 // isn't useful, so we'll hardcode an appropriate error value.
 return mapWindowsError(ERROR_INSUFFICIENT_BUFFER);
   }
-  LongPath.set_size(Length);
-  return ConvertAndPushArg(LongPath.data(), Args, Alloc);
+
+  std::error_code ec = windows::UTF16ToUTF8(ModuleName, Length, Filename);
+  if (ec)
+return ec;
+
+  StringRef Base = sys::path::filename(Filename.data());
+  Filename.assign(Base.begin(), Base.end());
+  return std::error_code();
 }
 
 std::error_code
 windows::GetCommandLineArguments(SmallVectorImpl ,
  BumpPtrAllocator ) {
   int ArgCount;
-  wchar_t **UnicodeCommandLine =
-  CommandLineToArgvW(GetCommandLineW(), );
+  std::unique_ptr UnicodeCommandLine{
+CommandLineToArgvW(GetCommandLineW(), ), };
   if (!UnicodeCommandLine)
 return mapWindowsError(::GetLastError());
 
-  Args.reserve(ArgCount);
   std::error_code ec;
 
-  // The first argument may contain just the name of the executable (e.g.,
-  // "clang") rather than the full path, so swap it with the full path.
-  wchar_t ModuleName[MAX_PATH];
-  int Length = ::GetModuleFileNameW(NULL, ModuleName, MAX_PATH);
-  if (0 < Length && Length < MAX_PATH)
-UnicodeCommandLine[0] = ModuleName;
-
-  // If the first argument is a shortened (8.3) name (which is possible even
-  // if we got the module name), the driver will have trouble distinguishing it
-  // (e.g., clang.exe v. clang++.exe), so expand it now.
-  ec = ExpandShortFileName(UnicodeCommandLine[0], Args, Alloc);
+  Args.reserve(ArgCount);
 
-  for (int i = 1; i < ArgCount && !ec; ++i) {
+  for (int i = 0; i < ArgCount; ++i) {
 ec = WildcardExpand(UnicodeCommandLine[i], Args, Alloc);
 if (ec)
-  break;
+  return ec;
   }
 
-  LocalFree(UnicodeCommandLine);
-  return ec;
+  SmallVector Arg0(Args[0], Args[0] + strlen(Args[0]));
+  SmallVector Filename;
+  sys::path::remove_filename(Arg0);
+  ec = GetExecutableName(Filename);
+  if (ec)
+return ec;
+  sys::path::append(Arg0, Filename);
+  Args[0] = AllocateString(Arg0, Alloc);
+  return std::error_code();
 }
 
 std::error_code Process::FixupStandardFileDescriptors() {
___
cfe-commits mailing list

[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-06-08 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

Would it be acceptable to introduce an option to allow enabling this behavior?
I mean would it have a chance of being integrated, or must I keep maintaining a 
fork of clang-format...


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[PATCH] D47944: Add support for arrays (and structure that use naked pointers for their iterator, like std::array) in performance-implicit-conversion-in-loop

2018-06-08 Thread Alex Pilkiewicz via Phabricator via cfe-commits
pilki created this revision.
pilki added a reviewer: alexfh.
Herald added subscribers: cfe-commits, jkorous.

Add support for arrays (and structure that use naked pointers for their 
iterator, like std::array) in performance-implicit-conversion-in-loop.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47944

Files:
  clangd/CodeComplete.cpp
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1015,6 +1015,15 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate ) {
+// Macros can be very spammy, so we only support prefix completion.
+// We won't end up with underfull index results, as macros are sema-only.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN ,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1015,6 +1015,15 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate ) {
+// Macros can be very spammy, so we only support prefix completion.
+// We won't end up with underfull index results, as macros are sema-only.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN ,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37813: clang-format: better handle namespace macros

2018-06-08 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


Repository:
  rC Clang

https://reviews.llvm.org/D37813



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


[PATCH] D47290: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin

2018-06-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D47290#1125028, @aaron.ballman wrote:

> Okay, that's fair, but the vendor-specific type for my Windows example is 
> spelled `DWORD`. I'm really worried that this special case will become a 
> precedent and we'll wind up with -Wformat being relaxed for everything based 
> on the same rationale. If that's how the community wants -Wformat to work, 
> cool, but I'd like to know if we're intending to change (what I see as) the 
> design of this warning.


I spoke with @jfb offline and am less concerned about this patch now. He's 
welcome to correct me if I misrepresent anything, but the precedent this sets 
is that a platform "owner" (someone with authority, not Joe Q Random-User) can 
relax -Wformat as in this patch, but this is not a precedent for a blanket 
change to -Wformat just because the UB happens to work and we "know" it.


Repository:
  rC Clang

https://reviews.llvm.org/D47290



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


[PATCH] D43015: clang-format: Introduce BreakInheritanceList option

2018-06-08 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


Repository:
  rC Clang

https://reviews.llvm.org/D43015



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


[PATCH] D47936: [clangd] Require case-insensitive prefix match for macro completions.

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334287: [clangd] Require case-insensitive prefix match for 
macro completions. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D47936?vs=150476=150510#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47936

Files:
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp


Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -1015,6 +1015,15 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate ) {
+// Macros can be very spammy, so we only support prefix completion.
+// We won't end up with underfull index results, as macros are sema-only.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN ,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";


Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -1015,6 +1015,15 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate ) {
+// Macros can be very spammy, so we only support prefix completion.
+// We won't end up with underfull index results, as macros are sema-only.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN ,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r334287 - [clangd] Require case-insensitive prefix match for macro completions.

2018-06-08 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Jun  8 06:32:25 2018
New Revision: 334287

URL: http://llvm.org/viewvc/llvm-project?rev=334287=rev
Log:
[clangd] Require case-insensitive prefix match for macro completions.

Summary: Macros are terribly spammy at the moment and this offers some relief.

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=334287=334286=334287=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Jun  8 06:32:25 2018
@@ -1015,6 +1015,15 @@ private:
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate ) {
+// Macros can be very spammy, so we only support prefix completion.
+// We won't end up with underfull index results, as macros are sema-only.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN ,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1036,7 @@ private:
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=334287=334286=334287=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Jun  8 
06:32:25 2018
@@ -193,6 +193,7 @@ int main() { ClassWithMembers().^ }
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@ TEST(CompletionTest, Filter) {
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";


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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing marked 2 inline comments as done.
Higuoxing added a comment.

Sorry, I will check it and update the test case

Besides, shall I add the macro-parentheses checking test cases to the original 
'parentheses.c'?


https://reviews.llvm.org/D47687



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/Sema/logical-op-parentheses-in-macros.c:3-4
+// RUN:-verify=logical-op-parentheses %s
+// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only  %s
+

The comment got lost, but these two are incorrect, they don't actually do 
anything, the `-verify=` is missing.


https://reviews.llvm.org/D47687



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: include/clang/Basic/DiagnosticGroups.td:264-265
 def LogicalOpParentheses: DiagGroup<"logical-op-parentheses">;
+def LogicalOpParenthesesInMacros: 
DiagGroup<"logical-op-parentheses-in-macros">;
 def LogicalNotParentheses: DiagGroup<"logical-not-parentheses">;
 def ShiftOpParentheses: DiagGroup<"shift-op-parentheses">;

lebedev.ri wrote:
> lebedev.ri wrote:
> > `LogicalOpParenthesesInMacros` should be in `LogicalNotParentheses` group.
> That should have of course been: `LogicalOpParenthesesInMacros` should be in 
> `LogicalOpParentheses` group.
Are you sure you are uploading the correct diff?
Neither of these two notes is done.


https://reviews.llvm.org/D47687



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing updated this revision to Diff 150507.
Higuoxing marked 4 inline comments as done.
Higuoxing added a comment.

Hope this not disturb you too much : ) thanks


https://reviews.llvm.org/D47687

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/logical-op-parentheses-in-macros.c

Index: test/Sema/logical-op-parentheses-in-macros.c
===
--- test/Sema/logical-op-parentheses-in-macros.c
+++ test/Sema/logical-op-parentheses-in-macros.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -Wlogical-op-parentheses-in-macros -fsyntax-only \
+// RUN:-verify=logical-op-parentheses %s
+// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only  %s
+
+#define macro_op_parentheses_check(x) ( \
+  ( (void)(x) ) \
+)
+
+void logical_op_in_macros_test(unsigned i) {
+  
+  macro_op_parentheses_check(i || i && i); // logical-op-parentheses-warning {{'&&' within '||'}} \
+   // logical-op-parentheses-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i || i && "I love LLVM"); // no warning.
+  macro_op_parentheses_check("I love LLVM" && i || i); // no warning.
+
+  macro_op_parentheses_check(i || i && "I love LLVM" || i); // logical-op-parentheses-warning {{'&&' within '||'}} \
+// logical-op-parentheses-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i || "I love LLVM" && i || i); // logical-op-parentheses-warning {{'&&' within '||'}} \
+// logical-op-parentheses-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i && i || 0); // no warning.
+  macro_op_parentheses_check(0 || i && i); // no warning.
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12172,8 +12172,16 @@
 EmitDiagnosticForLogicalAndInLogicalOr(Sema , SourceLocation OpLoc,
BinaryOperator *Bop) {
   assert(Bop->getOpcode() == BO_LAnd);
-  Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or)
-  << Bop->getSourceRange() << OpLoc;
+  Self.Diag(Bop->getOperatorLoc(), !OpLoc.isMacroID() ?
+// if this warning is in a normal context
+diag::warn_logical_and_in_logical_or :
+// else this warning is in a macro context
+// currently, this will not warn in macros by default.
+// add [-Wlogical-op-parentheses-in-macros]
+// to enable this warning.
+diag::warn_logical_and_in_logical_or_in_macros
+  ) << Bop->getSourceRange() << OpLoc;
+  
   SuggestParentheses(Self, Bop->getOperatorLoc(),
 Self.PDiag(diag::note_precedence_silence)
   << Bop->getOpcodeStr(),
@@ -12205,6 +12213,7 @@
   if (EvaluatesAsFalse(S, RHSExpr))
 return;
   // If it's "1 && a || b" don't warn since the precedence doesn't matter.
+  // And 'assert("some message" && a || b)' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getLHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 } else if (Bop->getOpcode() == BO_LOr) {
@@ -12227,6 +12236,7 @@
   if (EvaluatesAsFalse(S, LHSExpr))
 return;
   // If it's "a || b && 1" don't warn since the precedence doesn't matter.
+  // And 'assert(a || b && "some message")' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getRHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 }
@@ -12309,8 +12319,11 @@
   }
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
-  // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  // Here we will not skip 'logical and in logical or' checking
+  // in macros, since 'assert(a || b && "some message")' is equal
+  // to '(a || b && 1)' and 'assert("some message" && a || b)' is
+  // equal to '(1 && a || b)'.
+  if (Opc == BO_LOr) {
 DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
 DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5483,6 +5483,10 @@
 def warn_logical_and_in_logical_or : Warning<
   "'&&' within '||'">, InGroup;
 
+def warn_logical_and_in_logical_or_in_macros: 
+  Warning, 
+  InGroup, DefaultIgnore;
+
 def warn_overloaded_shift_in_comparison :Warning<
   "overloaded operator %select{>>|<<}0 has higher precedence than "
   "comparison operator">,
Index: 

[PATCH] D47886: Move VersionTuple from clang/Basic to llvm/Support, clang part

2018-06-08 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

LGTM. Looks like LLDB has some uses of VersionTuple, you should fix those to 
#include the LLVM version before removing the header here. (Or, better yet, do 
it all atomically with the monorepo as @zturner suggested)


Repository:
  rC Clang

https://reviews.llvm.org/D47886



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


[PATCH] D47887: Move VersionTuple from clang/Basic to llvm/Support, llvm part

2018-06-08 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for adding the test!


Repository:
  rL LLVM

https://reviews.llvm.org/D47887



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: include/clang/Basic/DiagnosticGroups.td:264-265
 def LogicalOpParentheses: DiagGroup<"logical-op-parentheses">;
+def LogicalOpParenthesesInMacros: 
DiagGroup<"logical-op-parentheses-in-macros">;
 def LogicalNotParentheses: DiagGroup<"logical-not-parentheses">;
 def ShiftOpParentheses: DiagGroup<"shift-op-parentheses">;

lebedev.ri wrote:
> `LogicalOpParenthesesInMacros` should be in `LogicalNotParentheses` group.
That should have of course been: `LogicalOpParenthesesInMacros` should be in 
`LogicalOpParentheses` group.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:5487
+def warn_logical_and_in_logical_or_in_macros: Warning<
+  warn_logical_and_in_logical_or.Text>, InGroup, 
DefaultIgnore;
+

More than 80 chars per line.
```
def warn_logical_and_in_logical_or_in_macros: Warning<
  warn_logical_and_in_logical_or.Text>, InGroup,
  DefaultIgnore;
```




Comment at: test/Sema/logical-op-parentheses-in-macros.c:1
+// RUN: %clang_cc1 -Wlogical-op-parentheses-in-macros -fsyntax-only -verify %s
+

You need to also test that it is not enabled by default,
and is enabled by `-Wlogical-op-parentheses`.
It can sill be in one file, see e.g. 
`clang/test/Sema/tautological-unsigned-enum-zero-compare.c` for examples.


https://reviews.llvm.org/D47687



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing updated this revision to Diff 150495.
Higuoxing added a comment.

Update without conflict with test case `parentheses.c`... I add a separate 
option [-Wlogical-op-parentheses-in-macros] and will be silence by default

thanks


https://reviews.llvm.org/D47687

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/logical-op-parentheses-in-macros.c

Index: test/Sema/logical-op-parentheses-in-macros.c
===
--- test/Sema/logical-op-parentheses-in-macros.c
+++ test/Sema/logical-op-parentheses-in-macros.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -Wlogical-op-parentheses-in-macros -fsyntax-only -verify %s
+
+#define macro_op_parentheses_check(x) ( \
+  ( (void)(x) ) \
+)
+
+void logical_op_in_macros_test(unsigned i) {
+  
+  macro_op_parentheses_check(i || i && i); // expected-warning {{'&&' within '||'}} \
+// expected-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i || i && "I love LLVM"); // no warning.
+  macro_op_parentheses_check("I love LLVM" && i || i); // no warning.
+
+  macro_op_parentheses_check(i || i && "I love LLVM" || i); // expected-warning {{'&&' within '||'}} \
+  // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i || "I love LLVM" && i || i); // expected-warning {{'&&' within '||'}} \
+  // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  macro_op_parentheses_check(i && i || 0); // no warning.
+  macro_op_parentheses_check(0 || i && i); // no warning.
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12172,8 +12172,16 @@
 EmitDiagnosticForLogicalAndInLogicalOr(Sema , SourceLocation OpLoc,
BinaryOperator *Bop) {
   assert(Bop->getOpcode() == BO_LAnd);
-  Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or)
-  << Bop->getSourceRange() << OpLoc;
+  Self.Diag(Bop->getOperatorLoc(), !OpLoc.isMacroID() ?
+// if this warning is in a normal context
+diag::warn_logical_and_in_logical_or :
+// else this warning is in a macro context
+// currently, this will not warn in macros by default.
+// add [-Wlogical-op-parentheses-in-macros]
+// to enable this warning.
+diag::warn_logical_and_in_logical_or_in_macros
+  ) << Bop->getSourceRange() << OpLoc;
+  
   SuggestParentheses(Self, Bop->getOperatorLoc(),
 Self.PDiag(diag::note_precedence_silence)
   << Bop->getOpcodeStr(),
@@ -12205,6 +12213,7 @@
   if (EvaluatesAsFalse(S, RHSExpr))
 return;
   // If it's "1 && a || b" don't warn since the precedence doesn't matter.
+  // And 'assert("some message" && a || b)' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getLHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 } else if (Bop->getOpcode() == BO_LOr) {
@@ -12227,6 +12236,7 @@
   if (EvaluatesAsFalse(S, LHSExpr))
 return;
   // If it's "a || b && 1" don't warn since the precedence doesn't matter.
+  // And 'assert(a || b && "some message")' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getRHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 }
@@ -12309,8 +12319,11 @@
   }
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
-  // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  // Here we will not skip 'logical and in logical or' checking
+  // in macros, since 'assert(a || b && "some message")' is equal
+  // to '(a || b && 1)' and 'assert("some message" && a || b)' is
+  // equal to '(1 && a || b)'.
+  if (Opc == BO_LOr) {
 DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
 DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5483,6 +5483,9 @@
 def warn_logical_and_in_logical_or : Warning<
   "'&&' within '||'">, InGroup;
 
+def warn_logical_and_in_logical_or_in_macros: Warning<
+  warn_logical_and_in_logical_or.Text>, InGroup, DefaultIgnore;
+
 def warn_overloaded_shift_in_comparison :Warning<
   "overloaded operator %select{>>|<<}0 has higher precedence than "
   "comparison operator">,
Index: include/clang/Basic/DiagnosticGroups.td
===
--- 

[PATCH] D47935: [clangd] Boost completion score according to file proximity.

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

In https://reviews.llvm.org/D47935#1126283, @sammccall wrote:

> Can you benchmark this? I'm nervous about the URI stuff in the hot path.
>  Timing CodeCompleteFlow::measureResults before/after with index enabled 
> seems like a reasonable test.
>  (But you might want to make this apply to sema first too for realistic 
> numbers?)


Sure! I had some numbers but they are on some paper that I don't access to 
right now... will collect some new figures (with URI manipulations in sema).




Comment at: clangd/Quality.cpp:171
+/// "uri:///a/b/c" will be treated as /a/b/c
+static float uriProximity(StringRef UX, StringRef UY) {
+  auto SchemeSplitX = UX.split(':');

sammccall wrote:
> This doesn't look quite right to me.
> We can tune the details later, but in practice this seems like it's *very* 
> hard to get zero proximity, which is our neutral score - you need to be 18 
> directories away?
> 
> FWIW, fozzie appears to give an additive boost proportional to 5-up, where up 
> is the number of directories from the context you have to traverse up from 
> the context to get to a parent of the symbol. (There's no penalty for 
> down-traversals probably for implementation reasons, this should be smaller 
> than the up-traversal penalty I think)
The numbers are guessed... definitely happy to tune.
> We can tune the details later, but in practice this seems like it's *very* 
> hard to get zero proximity, which is our neutral score - you need to be 18 
> directories away?
It's 18 directories away if one file is in an ancestor directories of the other 
(i.e. only traverse up or down). If you need to traverse up and down, the 
penalty for each directory is 0.1, which takes 10 directories (up+down, so 
5 up in average). I think it's useful to make this distinction because I think 
it's more likely for a file to use a header if it's in the file path.  

I'm not sure if we should use zero as the neutral score. For example, if a 
codebase has deep directory structure, most scores are probably going to be 
small; conversely, most scores would be relatively big. I think relative scores 
are more useful.

> (There's no penalty for down-traversals probably for implementation reasons, 
> this should be smaller than the up-traversal penalty I think)
Why do you think down-traversal should take less penalty?




Comment at: clangd/Quality.cpp:208
+if (auto U = URI::create(ProximityPath, SymURI.split(':').first)) {
+  ProximityScore += uriProximity(SymURI, U->toString());
+} else {

sammccall wrote:
> Why U->toString() rather than ->body()?
Because both URIs need to be parsed in order to use `body()`. Here we don't 
parse `SymURI`.



Comment at: clangd/Quality.cpp:215
 
 void SymbolRelevanceSignals::merge(const CodeCompletionResult ) {
   if (SemaCCResult.Availability == CXAvailability_NotAvailable ||

sammccall wrote:
> proximity path needs to be set here too
Alternatively, I wonder if we could give sema result a fixed proximity score as 
they are symbols that are already included? 



Comment at: clangd/Quality.h:74
+  // If set, this is used to compute proximity from symbol's declaring file.
+  llvm::StringRef ProximityPath;
   /// Proximity between best declaration and the query. [0-1], 1 is closest.

sammccall wrote:
> sammccall wrote:
> > It seems OK to have ProximityPath or ProximityScore, but we shouldn't have 
> > both: drop proximityscore and calculate it during evaluate()?
> what's the plan for associated-header? should this be a smallvector<2>?
Just want to make sure I understand. We would copy the symbol URI to use in 
`merge` right?



Comment at: clangd/Quality.h:74
+  // If set, this is used to compute proximity from symbol's declaring file.
+  llvm::StringRef ProximityPath;
   /// Proximity between best declaration and the query. [0-1], 1 is closest.

ioeric wrote:
> sammccall wrote:
> > sammccall wrote:
> > > It seems OK to have ProximityPath or ProximityScore, but we shouldn't 
> > > have both: drop proximityscore and calculate it during evaluate()?
> > what's the plan for associated-header? should this be a smallvector<2>?
> Just want to make sure I understand. We would copy the symbol URI to use in 
> `merge` right?
I think it should be easy to change this to vector when it's actually needed?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935



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


[PATCH] D47896: [CodeComplete] suppress define X X macros

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Going to put this on hold until someone actually reports the bug.


Repository:
  rC Clang

https://reviews.llvm.org/D47896



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


[PATCH] D47446: [NEON] Support VST1xN intrinsics in AArch32 mode (Clang part)

2018-06-08 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer accepted this revision.
SjoerdMeijer added a comment.
This revision is now accepted and ready to land.

Agreed: supported architectures are v7/A32/A64.


https://reviews.llvm.org/D47446



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


[PATCH] D44539: [Sema][Objective-C] Add check to warn when property of objc type has assign attribute

2018-06-08 Thread Alfred Zien via Phabricator via cfe-commits
QF5690 updated this revision to Diff 150487.
QF5690 added a comment.

Remove warning for `Class` type, change warning message.


Repository:
  rC Clang

https://reviews.llvm.org/D44539

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaObjCProperty.cpp
  test/SemaObjC/property-assign-on-object-type.m
  test/SemaObjC/property-in-class-extension-1.m


Index: test/SemaObjC/property-in-class-extension-1.m
===
--- test/SemaObjC/property-in-class-extension-1.m
+++ test/SemaObjC/property-in-class-extension-1.m
@@ -15,12 +15,12 @@
 @property (readonly) NSString* none;
 @property (readonly) NSString* none1;
 
-@property (assign, readonly) NSString* changeMemoryModel; // expected-note 
{{property declared here}}
+@property (unsafe_unretained, readonly) NSString* changeMemoryModel; // 
expected-note {{property declared here}}
 
 @property (readonly) __weak id weak_prop;
 @property (readonly) __weak id weak_prop1;
 
-@property (assign, readonly) NSString* assignProperty;
+@property (unsafe_unretained, readonly) NSString* unsafeUnretainedProperty;
 
 @property (readonly) NSString* readonlyProp;
 
@@ -43,8 +43,8 @@
 @property () __weak id weak_prop;
 @property (readwrite) __weak id weak_prop1;
 
-@property (assign, readwrite) NSString* assignProperty;
-@property (assign) NSString* readonlyProp;
+@property (unsafe_unretained, readwrite) NSString* unsafeUnretainedProperty;
+@property (unsafe_unretained) NSString* readonlyProp;
 @end
 
 // rdar://12214070
Index: test/SemaObjC/property-assign-on-object-type.m
===
--- /dev/null
+++ test/SemaObjC/property-assign-on-object-type.m
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wobjc-property-assign-on-object-type 
%s
+
+@interface Foo @end
+
+@interface Bar
+@property(assign, readonly) Foo* o1; // expected-warning {{'assign' property 
of object type may become a dangling reference; consider using 
'unsafe_unretained'}}
+@property(unsafe_unretained, readonly) Foo* o2;
+
+@property(assign) Class classProperty;
+@property(assign) int s1;
+@property(assign) int* s2;
+@end
+
+@interface Bar ()
+@property(readwrite) Foo* o1;
+@property(readwrite) Foo* o2;
+@end
Index: lib/Sema/SemaObjCProperty.cpp
===
--- lib/Sema/SemaObjCProperty.cpp
+++ lib/Sema/SemaObjCProperty.cpp
@@ -2547,6 +2547,14 @@
 PropertyDecl->setInvalidDecl();
   }
 
+  // Check for assign on object types.
+  if ((Attributes & ObjCDeclSpec::DQ_PR_assign) &&
+  !(Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained) &&
+  PropertyTy->isObjCRetainableType() &&
+  !PropertyTy->isObjCClassType()) {
+Diag(Loc, diag::warn_objc_property_assign_on_object);
+  }
+
   // Check for more than one of { assign, copy, retain }.
   if (Attributes & ObjCDeclSpec::DQ_PR_assign) {
 if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1014,6 +1014,9 @@
   "property attributes '%0' and '%1' are mutually exclusive">;
 def err_objc_property_requires_object : Error<
   "property with '%0' attribute must be of object type">;
+def warn_objc_property_assign_on_object : Warning<
+  "'assign' property of object type may become a dangling reference; consider 
using 'unsafe_unretained'">,
+  InGroup, DefaultIgnore;
 def warn_objc_property_no_assignment_attribute : Warning<
   "no 'assign', 'retain', or 'copy' attribute is specified - "
   "'assign' is assumed">,
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -367,6 +367,7 @@
 def BadFunctionCast : DiagGroup<"bad-function-cast">;
 def ObjCPropertyImpl : DiagGroup<"objc-property-implementation">;
 def ObjCPropertyNoAttribute : DiagGroup<"objc-property-no-attribute">;
+def ObjCPropertyAssignOnObjectType : 
DiagGroup<"objc-property-assign-on-object-type">;
 def ObjCProtocolQualifiers : DiagGroup<"objc-protocol-qualifiers">;
 def ObjCMissingSuperCalls : DiagGroup<"objc-missing-super-calls">;
 def ObjCDesignatedInit : DiagGroup<"objc-designated-initializers">;


Index: test/SemaObjC/property-in-class-extension-1.m
===
--- test/SemaObjC/property-in-class-extension-1.m
+++ test/SemaObjC/property-in-class-extension-1.m
@@ -15,12 +15,12 @@
 @property (readonly) NSString* none;
 @property (readonly) NSString* none1;
 
-@property (assign, readonly) NSString* changeMemoryModel; // expected-note {{property declared here}}
+@property (unsafe_unretained, readonly) NSString* changeMemoryModel; // expected-note 

[PATCH] D47935: [clangd] Boost completion score according to file proximity.

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Oops, couple more comments.
But the big things I think are:

- what's the performance impact of doing all this work (including the URI 
stuff) inside the scoring loop?
- what's the most useful formula for the proximity score




Comment at: clangd/Quality.cpp:171
+/// "uri:///a/b/c" will be treated as /a/b/c
+static float uriProximity(StringRef UX, StringRef UY) {
+  auto SchemeSplitX = UX.split(':');

This doesn't look quite right to me.
We can tune the details later, but in practice this seems like it's *very* hard 
to get zero proximity, which is our neutral score - you need to be 18 
directories away?

FWIW, fozzie appears to give an additive boost proportional to 5-up, where up 
is the number of directories from the context you have to traverse up from the 
context to get to a parent of the symbol. (There's no penalty for 
down-traversals probably for implementation reasons, this should be smaller 
than the up-traversal penalty I think)



Comment at: clangd/Quality.h:74
+  // If set, this is used to compute proximity from symbol's declaring file.
+  llvm::StringRef ProximityPath;
   /// Proximity between best declaration and the query. [0-1], 1 is closest.

sammccall wrote:
> It seems OK to have ProximityPath or ProximityScore, but we shouldn't have 
> both: drop proximityscore and calculate it during evaluate()?
what's the plan for associated-header? should this be a smallvector<2>?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935



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


[PATCH] D47935: [clangd] Boost completion score according to file proximity.

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Can you benchmark this? I'm nervous about the URI stuff in the hot path.
Timing CodeCompleteFlow::measureResults before/after with index enabled seems 
like a reasonable test.
(But you might want to make this apply to sema first too for realistic numbers?)




Comment at: clangd/Quality.cpp:203
+  StringRef SymURI = IndexResult.CanonicalDeclaration.FileURI;
+  if (!ProximityPath.empty() && !SymURI.empty()) {
+// Only calculate proximity score for two URIs with the same scheme so that

how do we know proximitypath is set at this point?
Better to copy the symbol URL path I think :-(



Comment at: clangd/Quality.cpp:208
+if (auto U = URI::create(ProximityPath, SymURI.split(':').first)) {
+  ProximityScore += uriProximity(SymURI, U->toString());
+} else {

Why U->toString() rather than ->body()?



Comment at: clangd/Quality.cpp:215
 
 void SymbolRelevanceSignals::merge(const CodeCompletionResult ) {
   if (SemaCCResult.Availability == CXAvailability_NotAvailable ||

proximity path needs to be set here too



Comment at: clangd/Quality.h:74
+  // If set, this is used to compute proximity from symbol's declaring file.
+  llvm::StringRef ProximityPath;
   /// Proximity between best declaration and the query. [0-1], 1 is closest.

It seems OK to have ProximityPath or ProximityScore, but we shouldn't have 
both: drop proximityscore and calculate it during evaluate()?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935



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


[PATCH] D47446: [NEON] Support VST1xN intrinsics in AArch32 mode (Clang part)

2018-06-08 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Ping.


https://reviews.llvm.org/D47446



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


[PATCH] D47902: [CUDA] Fix emission of constant strings in sections

2018-06-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334281: [CUDA] Fix emission of constant strings in sections 
(authored by Hahnfeld, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D47902?vs=150387=150484#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47902

Files:
  cfe/trunk/lib/CodeGen/CGCUDANV.cpp
  cfe/trunk/test/CodeGenCUDA/device-stub.cu


Index: cfe/trunk/test/CodeGenCUDA/device-stub.cu
===
--- cfe/trunk/test/CodeGenCUDA/device-stub.cu
+++ cfe/trunk/test/CodeGenCUDA/device-stub.cu
@@ -65,7 +65,7 @@
 // ALL: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
 // * constant unnamed string with GPU binary
 // HIP: @[[FATBIN:__hip_fatbin]] = external constant i8, section ".hip_fatbin"
-// CUDA: @[[FATBIN:.*]] = private unnamed_addr constant{{.*GPU binary would be 
here.*}}\00",
+// CUDA: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
 // CUDANORDC-SAME: section ".nv_fatbin", align 8
 // CUDARDC-SAME: section "__nv_relfatbin", align 8
 // * constant struct that wraps GPU binary
@@ -81,7 +81,7 @@
 // * variable to save GPU binary handle after initialization
 // NORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
 // * constant unnamed string with NVModuleID
-// RDC: [[MODULE_ID_GLOBAL:@.*]] = private unnamed_addr constant
+// RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
 // HIPRDC-SAME: c"[[MODULE_ID:.+]]\00", section "__hip_module_id", align 32
 // * Make sure our constructor was added to global ctor list.
@@ -141,7 +141,7 @@
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
-// CUDANOGLOBALS: @{{.*}} = private unnamed_addr constant{{.*}}
+// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
 // HIPNOGLOBALS: @{{.*}} = external constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
 // NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
Index: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
===
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp
@@ -75,8 +75,12 @@
 auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
 llvm::GlobalVariable *GV =
 cast(ConstStr.getPointer());
-if (!SectionName.empty())
+if (!SectionName.empty()) {
   GV->setSection(SectionName);
+  // Mark the address as used which make sure that this section isn't
+  // merged and we will really have it in the object file.
+  GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+}
 if (Alignment)
   GV->setAlignment(Alignment);
 


Index: cfe/trunk/test/CodeGenCUDA/device-stub.cu
===
--- cfe/trunk/test/CodeGenCUDA/device-stub.cu
+++ cfe/trunk/test/CodeGenCUDA/device-stub.cu
@@ -65,7 +65,7 @@
 // ALL: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
 // * constant unnamed string with GPU binary
 // HIP: @[[FATBIN:__hip_fatbin]] = external constant i8, section ".hip_fatbin"
-// CUDA: @[[FATBIN:.*]] = private unnamed_addr constant{{.*GPU binary would be here.*}}\00",
+// CUDA: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
 // CUDANORDC-SAME: section ".nv_fatbin", align 8
 // CUDARDC-SAME: section "__nv_relfatbin", align 8
 // * constant struct that wraps GPU binary
@@ -81,7 +81,7 @@
 // * variable to save GPU binary handle after initialization
 // NORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
 // * constant unnamed string with NVModuleID
-// RDC: [[MODULE_ID_GLOBAL:@.*]] = private unnamed_addr constant
+// RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
 // HIPRDC-SAME: c"[[MODULE_ID:.+]]\00", section "__hip_module_id", align 32
 // * Make sure our constructor was added to global ctor list.
@@ -141,7 +141,7 @@
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
-// CUDANOGLOBALS: @{{.*}} = private unnamed_addr constant{{.*}}
+// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
 // HIPNOGLOBALS: @{{.*}} = external constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
 // NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
Index: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
===
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp
@@ -75,8 +75,12 @@
 auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
 

r334281 - [CUDA] Fix emission of constant strings in sections

2018-06-08 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Fri Jun  8 04:17:08 2018
New Revision: 334281

URL: http://llvm.org/viewvc/llvm-project?rev=334281=rev
Log:
[CUDA] Fix emission of constant strings in sections

CGM.GetAddrOfConstantCString() sets the adress of the created GlobalValue
to unnamed. When emitting the object file LLVM will mark the surrounding
section as SHF_MERGE iff the string is nul-terminated and contains no
other nuls (see IsNullTerminatedString). This results in problems when
saving temporaries because LLVM doesn't set an EntrySize, so reading in
the serialized assembly file fails.
This never happened for the GPU binaries because they usually contain
a nul-character somewhere. Instead this only affected the module ID
when compiling relocatable device code.

However, this points to a potentially larger problem: If we put a
constant string into a named section, we really want the data to end
up in that section in the object file. To avoid LLVM merging sections
this patch unmarks the GlobalVariable's address as unnamed which also
fixes the problem of invalid serialized assembly files when saving
temporaries.

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

Modified:
cfe/trunk/lib/CodeGen/CGCUDANV.cpp
cfe/trunk/test/CodeGenCUDA/device-stub.cu

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=334281=334280=334281=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Fri Jun  8 04:17:08 2018
@@ -75,8 +75,12 @@ private:
 auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
 llvm::GlobalVariable *GV =
 cast(ConstStr.getPointer());
-if (!SectionName.empty())
+if (!SectionName.empty()) {
   GV->setSection(SectionName);
+  // Mark the address as used which make sure that this section isn't
+  // merged and we will really have it in the object file.
+  GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+}
 if (Alignment)
   GV->setAlignment(Alignment);
 

Modified: cfe/trunk/test/CodeGenCUDA/device-stub.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/device-stub.cu?rev=334281=334280=334281=diff
==
--- cfe/trunk/test/CodeGenCUDA/device-stub.cu (original)
+++ cfe/trunk/test/CodeGenCUDA/device-stub.cu Fri Jun  8 04:17:08 2018
@@ -65,7 +65,7 @@ void use_pointers() {
 // ALL: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
 // * constant unnamed string with GPU binary
 // HIP: @[[FATBIN:__hip_fatbin]] = external constant i8, section ".hip_fatbin"
-// CUDA: @[[FATBIN:.*]] = private unnamed_addr constant{{.*GPU binary would be 
here.*}}\00",
+// CUDA: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
 // CUDANORDC-SAME: section ".nv_fatbin", align 8
 // CUDARDC-SAME: section "__nv_relfatbin", align 8
 // * constant struct that wraps GPU binary
@@ -81,7 +81,7 @@ void use_pointers() {
 // * variable to save GPU binary handle after initialization
 // NORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
 // * constant unnamed string with NVModuleID
-// RDC: [[MODULE_ID_GLOBAL:@.*]] = private unnamed_addr constant
+// RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
 // HIPRDC-SAME: c"[[MODULE_ID:.+]]\00", section "__hip_module_id", align 32
 // * Make sure our constructor was added to global ctor list.
@@ -141,7 +141,7 @@ void hostfunc(void) { kernelfunc<<<1, 1>
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
-// CUDANOGLOBALS: @{{.*}} = private unnamed_addr constant{{.*}}
+// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
 // HIPNOGLOBALS: @{{.*}} = external constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
 // NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor


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


[PATCH] D47937: [clangd] Support proximity paths in index fuzzy find.

2018-06-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47937

Files:
  clangd/CodeComplete.cpp
  clangd/index/Index.h


Index: clangd/index/Index.h
===
--- clangd/index/Index.h
+++ clangd/index/Index.h
@@ -271,6 +271,9 @@
   size_t MaxCandidateCount = UINT_MAX;
   /// If set to true, only symbols for completion support will be considered.
   bool RestrictForCodeCompletion = false;
+  /// Contextually relevant files (e.g. the file we're code-completing in).
+  /// Paths should be absolute.
+  std::vector ProximityPaths;
 };
 
 struct LookupRequest {
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -972,6 +972,7 @@
 Req.RestrictForCodeCompletion = true;
 Req.Scopes = getQueryScopes(Recorder->CCContext,
 Recorder->CCSema->getSourceManager());
+Req.ProximityPaths.push_back(FileName);
 log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])",
   Req.Query,
   llvm::join(Req.Scopes.begin(), Req.Scopes.end(), ",")));


Index: clangd/index/Index.h
===
--- clangd/index/Index.h
+++ clangd/index/Index.h
@@ -271,6 +271,9 @@
   size_t MaxCandidateCount = UINT_MAX;
   /// If set to true, only symbols for completion support will be considered.
   bool RestrictForCodeCompletion = false;
+  /// Contextually relevant files (e.g. the file we're code-completing in).
+  /// Paths should be absolute.
+  std::vector ProximityPaths;
 };
 
 struct LookupRequest {
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -972,6 +972,7 @@
 Req.RestrictForCodeCompletion = true;
 Req.Scopes = getQueryScopes(Recorder->CCContext,
 Recorder->CCSema->getSourceManager());
+Req.ProximityPaths.push_back(FileName);
 log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])",
   Req.Query,
   llvm::join(Req.Scopes.begin(), Req.Scopes.end(), ",")));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47936: [clangd] Require case-insensitive prefix match for macro completions.

2018-06-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

I like this.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47936



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


[PATCH] D47935: [clangd] Boost completion score according to file proximity.

2018-06-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 150477.
ioeric added a comment.

- Rebase again...


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935

Files:
  clangd/CodeComplete.cpp
  clangd/Quality.cpp
  clangd/Quality.h
  unittests/clangd/QualityTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/URITests.cpp

Index: unittests/clangd/URITests.cpp
===
--- unittests/clangd/URITests.cpp
+++ unittests/clangd/URITests.cpp
@@ -14,46 +14,20 @@
 
 namespace clang {
 namespace clangd {
+
+// Force the unittest URI scheme to be linked,
+extern volatile int UnittestSchemeAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest =
+UnittestSchemeAnchorSource;
+
 namespace {
 
 using ::testing::AllOf;
 
 MATCHER_P(Scheme, S, "") { return arg.scheme() == S; }
 MATCHER_P(Authority, A, "") { return arg.authority() == A; }
 MATCHER_P(Body, B, "") { return arg.body() == B; }
 
-// Assume all files in the schema have a "test-root/" root directory, and the
-// schema path is the relative path to the root directory.
-// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z".
-class TestScheme : public URIScheme {
-public:
-  static const char *Scheme;
-
-  static const char *TestRoot;
-
-  llvm::Expected
-  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
-  llvm::StringRef HintPath) const override {
-auto Pos = HintPath.find(TestRoot);
-assert(Pos != llvm::StringRef::npos);
-return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body)
-.str();
-  }
-
-  llvm::Expected
-  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
-auto Pos = AbsolutePath.find(TestRoot);
-assert(Pos != llvm::StringRef::npos);
-return URI(Scheme, /*Authority=*/"",
-   AbsolutePath.substr(Pos + llvm::StringRef(TestRoot).size()));
-  }
-};
-
-const char *TestScheme::Scheme = "unittest";
-const char *TestScheme::TestRoot = "/test-root/";
-
-static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema");
-
 std::string createOrDie(llvm::StringRef AbsolutePath,
 llvm::StringRef Scheme = "file") {
   auto Uri = URI::create(AbsolutePath, Scheme);
Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 #include "TestFS.h"
+#include "URI.h"
 #include "llvm/Support/Errc.h"
 #include "gtest/gtest.h"
 
@@ -62,5 +63,50 @@
   return Path.str();
 }
 
+// Assume all files in the schema have a "test-root/" root directory, and the
+// schema path is the relative path to the root directory.
+// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z".
+class TestScheme : public URIScheme {
+public:
+  static const char *Scheme;
+
+  static const char *TestRoot;
+
+  llvm::Expected
+  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
+  llvm::StringRef HintPath) const override {
+auto Pos = HintPath.find(TestRoot);
+assert(Pos != llvm::StringRef::npos);
+return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body)
+.str();
+  }
+
+  llvm::Expected
+  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
+auto Pos = AbsolutePath.find(TestRoot);
+if (Pos == llvm::StringRef::npos)
+  return llvm::make_error(
+  llvm::Twine("Directory ") + TestRoot + " not found in path " +
+  AbsolutePath,
+  llvm::inconvertibleErrorCode());
+
+return URI(Scheme, /*Authority=*/"",
+   AbsolutePath.substr(Pos + llvm::StringRef(TestRoot).size()));
+  }
+};
+
+const char *TestScheme::Scheme = "unittest";
+#ifdef _WIN32
+const char *TestScheme::TestRoot = "\\test-root\\";
+#else
+const char *TestScheme::TestRoot = "/test-root/";
+#endif
+
+static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema");
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the plugin.
+volatile int UnittestSchemeAnchorSource = 0;
+
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -18,12 +18,19 @@
 //===--===//
 
 #include "Quality.h"
+#include "TestFS.h"
 #include "TestTU.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
+
+// Force the unittest URI scheme to be linked,
+extern volatile int UnittestSchemeAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest =
+UnittestSchemeAnchorSource;
+
 namespace {
 
 TEST(QualityTests, 

[PATCH] D47936: [clangd] Require case-insensitive prefix match for macro completions.

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov.

Macros are terribly spammy at the moment and this offers some relief.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47936

Files:
  clangd/CodeComplete.cpp
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1015,6 +1015,14 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate ) {
+// Macros can be very spammy, so we only support prefix completion.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN ,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1035,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -193,6 +193,7 @@
 
 TEST(CompletionTest, Filter) {
   std::string Body = R"cpp(
+#define FooBarMacro
 int Abracadabra;
 int Alakazam;
 struct S {
@@ -202,7 +203,8 @@
 };
   )cpp";
   EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").items,
-  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux";
+  AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("FooBarMacro")),
+Not(Has("Qux";
 
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1015,6 +1015,14 @@
 return std::move(Top).items();
   }
 
+  Optional fuzzyScore(const CompletionCandidate ) {
+// Macros can be very spammy, so we only support prefix completion.
+if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
+!C.Name.startswith_lower(Filter->pattern()))
+  return None;
+return Filter->match(C.Name);
+  }
+
   // Scores a candidate and adds it to the TopN structure.
   void addCandidate(TopN ,
 const CodeCompletionResult *SemaResult,
@@ -1027,7 +1035,7 @@
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-if (auto FuzzyScore = Filter->match(C.Name))
+if (auto FuzzyScore = fuzzyScore(C))
   Relevance.NameMatch = *FuzzyScore;
 else
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47935: [clangd] Boost completion score according to file proximity.

2018-06-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 150475.
ioeric added a comment.

Rebase on https://reviews.llvm.org/D47931


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CodeComplete.cpp
  clangd/Quality.cpp
  clangd/Quality.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/QualityTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/URITests.cpp

Index: unittests/clangd/URITests.cpp
===
--- unittests/clangd/URITests.cpp
+++ unittests/clangd/URITests.cpp
@@ -14,46 +14,20 @@
 
 namespace clang {
 namespace clangd {
+
+// Force the unittest URI scheme to be linked,
+extern volatile int UnittestSchemeAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest =
+UnittestSchemeAnchorSource;
+
 namespace {
 
 using ::testing::AllOf;
 
 MATCHER_P(Scheme, S, "") { return arg.scheme() == S; }
 MATCHER_P(Authority, A, "") { return arg.authority() == A; }
 MATCHER_P(Body, B, "") { return arg.body() == B; }
 
-// Assume all files in the schema have a "test-root/" root directory, and the
-// schema path is the relative path to the root directory.
-// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z".
-class TestScheme : public URIScheme {
-public:
-  static const char *Scheme;
-
-  static const char *TestRoot;
-
-  llvm::Expected
-  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
-  llvm::StringRef HintPath) const override {
-auto Pos = HintPath.find(TestRoot);
-assert(Pos != llvm::StringRef::npos);
-return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body)
-.str();
-  }
-
-  llvm::Expected
-  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
-auto Pos = AbsolutePath.find(TestRoot);
-assert(Pos != llvm::StringRef::npos);
-return URI(Scheme, /*Authority=*/"",
-   AbsolutePath.substr(Pos + llvm::StringRef(TestRoot).size()));
-  }
-};
-
-const char *TestScheme::Scheme = "unittest";
-const char *TestScheme::TestRoot = "/test-root/";
-
-static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema");
-
 std::string createOrDie(llvm::StringRef AbsolutePath,
 llvm::StringRef Scheme = "file") {
   auto Uri = URI::create(AbsolutePath, Scheme);
Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 #include "TestFS.h"
+#include "URI.h"
 #include "llvm/Support/Errc.h"
 #include "gtest/gtest.h"
 
@@ -62,5 +63,50 @@
   return Path.str();
 }
 
+// Assume all files in the schema have a "test-root/" root directory, and the
+// schema path is the relative path to the root directory.
+// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z".
+class TestScheme : public URIScheme {
+public:
+  static const char *Scheme;
+
+  static const char *TestRoot;
+
+  llvm::Expected
+  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
+  llvm::StringRef HintPath) const override {
+auto Pos = HintPath.find(TestRoot);
+assert(Pos != llvm::StringRef::npos);
+return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body)
+.str();
+  }
+
+  llvm::Expected
+  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
+auto Pos = AbsolutePath.find(TestRoot);
+if (Pos == llvm::StringRef::npos)
+  return llvm::make_error(
+  llvm::Twine("Directory ") + TestRoot + " not found in path " +
+  AbsolutePath,
+  llvm::inconvertibleErrorCode());
+
+return URI(Scheme, /*Authority=*/"",
+   AbsolutePath.substr(Pos + llvm::StringRef(TestRoot).size()));
+  }
+};
+
+const char *TestScheme::Scheme = "unittest";
+#ifdef _WIN32
+const char *TestScheme::TestRoot = "\\test-root\\";
+#else
+const char *TestScheme::TestRoot = "/test-root/";
+#endif
+
+static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema");
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the plugin.
+volatile int UnittestSchemeAnchorSource = 0;
+
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -18,12 +18,19 @@
 //===--===//
 
 #include "Quality.h"
+#include "TestFS.h"
 #include "TestTU.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
+
+// Force the unittest URI scheme to be linked,

[PATCH] D47935: [clangd] Boost completion score according to file proximity.

2018-06-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov.

Also move unittest: URI scheme to TestFS so that it can be shared by
different tests.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CodeComplete.cpp
  clangd/Quality.cpp
  clangd/Quality.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/QualityTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/URITests.cpp

Index: unittests/clangd/URITests.cpp
===
--- unittests/clangd/URITests.cpp
+++ unittests/clangd/URITests.cpp
@@ -14,46 +14,20 @@
 
 namespace clang {
 namespace clangd {
+
+// Force the unittest URI scheme to be linked,
+extern volatile int UnittestSchemeAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest =
+UnittestSchemeAnchorSource;
+
 namespace {
 
 using ::testing::AllOf;
 
 MATCHER_P(Scheme, S, "") { return arg.scheme() == S; }
 MATCHER_P(Authority, A, "") { return arg.authority() == A; }
 MATCHER_P(Body, B, "") { return arg.body() == B; }
 
-// Assume all files in the schema have a "test-root/" root directory, and the
-// schema path is the relative path to the root directory.
-// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z".
-class TestScheme : public URIScheme {
-public:
-  static const char *Scheme;
-
-  static const char *TestRoot;
-
-  llvm::Expected
-  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
-  llvm::StringRef HintPath) const override {
-auto Pos = HintPath.find(TestRoot);
-assert(Pos != llvm::StringRef::npos);
-return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body)
-.str();
-  }
-
-  llvm::Expected
-  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
-auto Pos = AbsolutePath.find(TestRoot);
-assert(Pos != llvm::StringRef::npos);
-return URI(Scheme, /*Authority=*/"",
-   AbsolutePath.substr(Pos + llvm::StringRef(TestRoot).size()));
-  }
-};
-
-const char *TestScheme::Scheme = "unittest";
-const char *TestScheme::TestRoot = "/test-root/";
-
-static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema");
-
 std::string createOrDie(llvm::StringRef AbsolutePath,
 llvm::StringRef Scheme = "file") {
   auto Uri = URI::create(AbsolutePath, Scheme);
Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 #include "TestFS.h"
+#include "URI.h"
 #include "llvm/Support/Errc.h"
 #include "gtest/gtest.h"
 
@@ -62,5 +63,50 @@
   return Path.str();
 }
 
+// Assume all files in the schema have a "test-root/" root directory, and the
+// schema path is the relative path to the root directory.
+// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z".
+class TestScheme : public URIScheme {
+public:
+  static const char *Scheme;
+
+  static const char *TestRoot;
+
+  llvm::Expected
+  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
+  llvm::StringRef HintPath) const override {
+auto Pos = HintPath.find(TestRoot);
+assert(Pos != llvm::StringRef::npos);
+return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body)
+.str();
+  }
+
+  llvm::Expected
+  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
+auto Pos = AbsolutePath.find(TestRoot);
+if (Pos == llvm::StringRef::npos)
+  return llvm::make_error(
+  llvm::Twine("Directory ") + TestRoot + " not found in path " +
+  AbsolutePath,
+  llvm::inconvertibleErrorCode());
+
+return URI(Scheme, /*Authority=*/"",
+   AbsolutePath.substr(Pos + llvm::StringRef(TestRoot).size()));
+  }
+};
+
+const char *TestScheme::Scheme = "unittest";
+#ifdef _WIN32
+const char *TestScheme::TestRoot = "\\test-root\\";
+#else
+const char *TestScheme::TestRoot = "/test-root/";
+#endif
+
+static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema");
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the plugin.
+volatile int UnittestSchemeAnchorSource = 0;
+
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -18,12 +18,19 @@
 //===--===//
 
 #include "Quality.h"
+#include "TestFS.h"
 #include "TestTU.h"
 #include "gmock/gmock.h"
 #include 

[PATCH] D47707: [clangd] Downrank symbols with reserved names (score *= 0.1)

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE334274: [clangd] Downrank symbols with reserved names 
(score *= 0.1) (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47707?vs=150115=150469#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47707

Files:
  clangd/Quality.cpp
  clangd/Quality.h
  unittests/clangd/QualityTests.cpp

Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -28,31 +28,34 @@
 
 TEST(QualityTests, SymbolQualitySignalExtraction) {
   auto Header = TestTU::withHeaderCode(R"cpp(
-int x;
+int _X;
 
 [[deprecated]]
-int f() { return x; }
+int _f() { return _X; }
   )cpp");
   auto Symbols = Header.headerSymbols();
   auto AST = Header.build();
 
   SymbolQualitySignals Quality;
-  Quality.merge(findSymbol(Symbols, "x"));
+  Quality.merge(findSymbol(Symbols, "_X"));
   EXPECT_FALSE(Quality.Deprecated);
+  EXPECT_TRUE(Quality.ReservedName);
   EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Variable);
 
-  Symbol F = findSymbol(Symbols, "f");
+  Symbol F = findSymbol(Symbols, "_f");
   F.References = 24; // TestTU doesn't count references, so fake it.
   Quality = {};
   Quality.merge(F);
   EXPECT_FALSE(Quality.Deprecated); // FIXME: Include deprecated bit in index.
+  EXPECT_FALSE(Quality.ReservedName);
   EXPECT_EQ(Quality.References, 24u);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
 
   Quality = {};
-  Quality.merge(CodeCompletionResult((AST, "f"), /*Priority=*/42));
+  Quality.merge(CodeCompletionResult((AST, "_f"), /*Priority=*/42));
   EXPECT_TRUE(Quality.Deprecated);
+  EXPECT_FALSE(Quality.ReservedName);
   EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
 }
@@ -112,6 +115,10 @@
   Deprecated.Deprecated = true;
   EXPECT_LT(Deprecated.evaluate(), Default.evaluate());
 
+  SymbolQualitySignals ReservedName;
+  ReservedName.ReservedName = true;
+  EXPECT_LT(ReservedName.evaluate(), Default.evaluate());
+
   SymbolQualitySignals WithReferences, ManyReferences;
   WithReferences.References = 10;
   ManyReferences.References = 1000;
Index: clangd/Quality.h
===
--- clangd/Quality.h
+++ clangd/Quality.h
@@ -45,6 +45,8 @@
 /// Attributes of a symbol that affect how much we like it.
 struct SymbolQualitySignals {
   bool Deprecated = false;
+  bool ReservedName = false; // __foo, _Foo are usually implementation details.
+ // FIXME: make these findable once user types _.
   unsigned References = 0;
 
   enum SymbolCategory {
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -9,6 +9,7 @@
 #include "Quality.h"
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/CharInfo.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -19,6 +20,11 @@
 namespace clang {
 namespace clangd {
 using namespace llvm;
+static bool IsReserved(StringRef Name) {
+  // FIXME: Should we exclude _Bool and others recognized by the standard?
+  return Name.size() >= 2 && Name[0] == '_' &&
+ (isUppercase(Name[1]) || Name[1] == '_');
+}
 
 static bool hasDeclInMainFile(const Decl ) {
   auto  = D.getASTContext().getSourceManager();
@@ -101,11 +107,18 @@
 Category = categorize(*SemaCCResult.Declaration);
   else if (SemaCCResult.Kind == CodeCompletionResult::RK_Macro)
 Category = Macro;
+
+  if (SemaCCResult.Declaration) {
+if (auto *ID = SemaCCResult.Declaration->getIdentifier())
+  ReservedName = ReservedName || IsReserved(ID->getName());
+  } else if (SemaCCResult.Kind == CodeCompletionResult::RK_Macro)
+ReservedName = ReservedName || IsReserved(SemaCCResult.Macro->getName());
 }
 
 void SymbolQualitySignals::merge(const Symbol ) {
   References = std::max(IndexResult.References, References);
   Category = categorize(IndexResult.SymInfo);
+  ReservedName = ReservedName || IsReserved(IndexResult.Name);
 }
 
 float SymbolQualitySignals::evaluate() const {
@@ -118,6 +131,8 @@
 
   if (Deprecated)
 Score *= 0.1f;
+  if (ReservedName)
+Score *= 0.1f;
 
   switch (Category) {
 case Type:
@@ -142,6 +157,7 @@
   OS << formatv("=== Symbol quality: {0}\n", S.evaluate());
   OS << formatv("\tReferences: {0}\n", S.References);
   OS << formatv("\tDeprecated: {0}\n", S.Deprecated);
+  OS << formatv("\tReserved name: {0}\n", S.ReservedName);
   OS << formatv("\tCategory: {0}\n", static_cast(S.Category));
   return OS;
 }
___

[clang-tools-extra] r334274 - [clangd] Downrank symbols with reserved names (score *= 0.1)

2018-06-08 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Jun  8 02:36:34 2018
New Revision: 334274

URL: http://llvm.org/viewvc/llvm-project?rev=334274=rev
Log:
[clangd] Downrank symbols with reserved names (score *= 0.1)

Reviewers: ilya-biryukov

Subscribers: klimek, ioeric, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/Quality.h
clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=334274=334273=334274=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Fri Jun  8 02:36:34 2018
@@ -9,6 +9,7 @@
 #include "Quality.h"
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/CharInfo.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -19,6 +20,11 @@
 namespace clang {
 namespace clangd {
 using namespace llvm;
+static bool IsReserved(StringRef Name) {
+  // FIXME: Should we exclude _Bool and others recognized by the standard?
+  return Name.size() >= 2 && Name[0] == '_' &&
+ (isUppercase(Name[1]) || Name[1] == '_');
+}
 
 static bool hasDeclInMainFile(const Decl ) {
   auto  = D.getASTContext().getSourceManager();
@@ -101,11 +107,18 @@ void SymbolQualitySignals::merge(const C
 Category = categorize(*SemaCCResult.Declaration);
   else if (SemaCCResult.Kind == CodeCompletionResult::RK_Macro)
 Category = Macro;
+
+  if (SemaCCResult.Declaration) {
+if (auto *ID = SemaCCResult.Declaration->getIdentifier())
+  ReservedName = ReservedName || IsReserved(ID->getName());
+  } else if (SemaCCResult.Kind == CodeCompletionResult::RK_Macro)
+ReservedName = ReservedName || IsReserved(SemaCCResult.Macro->getName());
 }
 
 void SymbolQualitySignals::merge(const Symbol ) {
   References = std::max(IndexResult.References, References);
   Category = categorize(IndexResult.SymInfo);
+  ReservedName = ReservedName || IsReserved(IndexResult.Name);
 }
 
 float SymbolQualitySignals::evaluate() const {
@@ -118,6 +131,8 @@ float SymbolQualitySignals::evaluate() c
 
   if (Deprecated)
 Score *= 0.1f;
+  if (ReservedName)
+Score *= 0.1f;
 
   switch (Category) {
 case Type:
@@ -142,6 +157,7 @@ raw_ostream <<(raw_ostream ,
   OS << formatv("=== Symbol quality: {0}\n", S.evaluate());
   OS << formatv("\tReferences: {0}\n", S.References);
   OS << formatv("\tDeprecated: {0}\n", S.Deprecated);
+  OS << formatv("\tReserved name: {0}\n", S.ReservedName);
   OS << formatv("\tCategory: {0}\n", static_cast(S.Category));
   return OS;
 }

Modified: clang-tools-extra/trunk/clangd/Quality.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.h?rev=334274=334273=334274=diff
==
--- clang-tools-extra/trunk/clangd/Quality.h (original)
+++ clang-tools-extra/trunk/clangd/Quality.h Fri Jun  8 02:36:34 2018
@@ -45,6 +45,8 @@ struct Symbol;
 /// Attributes of a symbol that affect how much we like it.
 struct SymbolQualitySignals {
   bool Deprecated = false;
+  bool ReservedName = false; // __foo, _Foo are usually implementation details.
+ // FIXME: make these findable once user types _.
   unsigned References = 0;
 
   enum SymbolCategory {

Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=334274=334273=334274=diff
==
--- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Fri Jun  8 
02:36:34 2018
@@ -28,31 +28,34 @@ namespace {
 
 TEST(QualityTests, SymbolQualitySignalExtraction) {
   auto Header = TestTU::withHeaderCode(R"cpp(
-int x;
+int _X;
 
 [[deprecated]]
-int f() { return x; }
+int _f() { return _X; }
   )cpp");
   auto Symbols = Header.headerSymbols();
   auto AST = Header.build();
 
   SymbolQualitySignals Quality;
-  Quality.merge(findSymbol(Symbols, "x"));
+  Quality.merge(findSymbol(Symbols, "_X"));
   EXPECT_FALSE(Quality.Deprecated);
+  EXPECT_TRUE(Quality.ReservedName);
   EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Variable);
 
-  Symbol F = findSymbol(Symbols, "f");
+  Symbol F = findSymbol(Symbols, "_f");
   F.References = 24; // TestTU doesn't count references, so fake it.
   Quality = {};
   Quality.merge(F);
   EXPECT_FALSE(Quality.Deprecated); // FIXME: Include deprecated bit in index.
+  

[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing added a comment.

Thanks, let me have a try


https://reviews.llvm.org/D47687



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

+ there will need to be a new standalone test for 
`-Wlogical-op-parentheses-in-macros`,
what it does, how it relates to `-Wlogical-op-parentheses`,`-Wparentheses`, etc.




Comment at: include/clang/Basic/DiagnosticGroups.td:264-265
 def LogicalOpParentheses: DiagGroup<"logical-op-parentheses">;
+def LogicalOpParenthesesInMacros: 
DiagGroup<"logical-op-parentheses-in-macros">;
 def LogicalNotParentheses: DiagGroup<"logical-not-parentheses">;
 def ShiftOpParentheses: DiagGroup<"shift-op-parentheses">;

`LogicalOpParenthesesInMacros` should be in `LogicalNotParentheses` group.



Comment at: include/clang/Basic/DiagnosticGroups.td:672
 [LogicalOpParentheses,
+ LogicalOpParenthesesInMacros,
  LogicalNotParentheses,

No need



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:5486-5488
+def warn_logical_and_in_logical_or_in_macros: Warning<
+  "'&&' within '||'">, InGroup;
+

This should be
```
def warn_logical_and_in_logical_or_in_macros :
  Warning,
  InGroup, DefaultIgnore;
```
`DefaultIgnore` is my guess.



Comment at: lib/Sema/SemaExpr.cpp:12175-12183
+  if (!OpLoc.isMacroID()) {
+// if this warning is in a normal context
+Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or)
   << Bop->getSourceRange() << OpLoc;
+  } else {
+// else this warning is in a macro context
+Self.Diag(Bop->getOperatorLoc(), 
diag::warn_logical_and_in_logical_or_in_macros)

Might be simpler to do
```
Self.Diag(Bop->getOperatorLoc(), OpLoc.isMacroID() ? 
diag::warn_logical_and_in_logical_or_in_macros :
 
diag::warn_logical_and_in_logical_or)
  << Bop->getSourceRange() << OpLoc;
```


https://reviews.llvm.org/D47687



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


[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning

2018-06-08 Thread Xing via Phabricator via cfe-commits
Higuoxing updated this revision to Diff 150465.
Higuoxing added a comment.

I step out a little further... I made an attempt to add a new warning 
`[-Wlogical-op-parentheses-in-macros]`. Comparing to the previous one, which do 
you prefer? I am new to llvm community, and as you see, this is my first patch 
... so, forgive me if I made something wrong : ) suggestions are welcoming!

PS. I see something like `(x | y & z)` checking disabled in macros as well, how 
to deal with this?

thanks


https://reviews.llvm.org/D47687

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/parentheses.c

Index: test/Sema/parentheses.c
===
--- test/Sema/parentheses.c
+++ test/Sema/parentheses.c
@@ -14,6 +14,11 @@
   if ((i = 4)) {}
 }
 
+#define macro_parentheses_check(x) \
+  ( \
+( (void)(x) ) \
+  )
+
 void bitwise_rel(unsigned i) {
   (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \
 // expected-note{{place parentheses around the '==' expression to silence this warning}} \
@@ -96,6 +101,21 @@
 
   (void)(i && i || 0); // no warning.
   (void)(0 || i && i); // no warning.
+
+  macro_parentheses_check(i || i && i); // expected-warning {{'&&' within '||'}} \
+// expected-note {{place parentheses around the '&&' expression to silence this warning}}
+  
+  macro_parentheses_check(i || i && "I love LLVM"); // no warning.
+  macro_parentheses_check("I love LLVM" && i || i); // no warning.
+
+  macro_parentheses_check(i || i && "I love LLVM" || i); // expected-warning {{'&&' within '||'}} \
+ // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+  
+  macro_parentheses_check(i || "I love LLVM" && i || i); // expected-warning {{'&&' within '||'}} \
+ // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+  
+  macro_parentheses_check(i && i || 0); // no warning.
+  macro_parentheses_check(0 || i && i); // no warning.
 }
 
 _Bool someConditionFunc();
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12172,8 +12172,16 @@
 EmitDiagnosticForLogicalAndInLogicalOr(Sema , SourceLocation OpLoc,
BinaryOperator *Bop) {
   assert(Bop->getOpcode() == BO_LAnd);
-  Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or)
+  if (!OpLoc.isMacroID()) {
+// if this warning is in a normal context
+Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or)
   << Bop->getSourceRange() << OpLoc;
+  } else {
+// else this warning is in a macro context
+Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or_in_macros)
+  << Bop->getSourceRange() << OpLoc;
+  }
+  
   SuggestParentheses(Self, Bop->getOperatorLoc(),
 Self.PDiag(diag::note_precedence_silence)
   << Bop->getOpcodeStr(),
@@ -12205,6 +12213,7 @@
   if (EvaluatesAsFalse(S, RHSExpr))
 return;
   // If it's "1 && a || b" don't warn since the precedence doesn't matter.
+  // And 'assert("some message" && a || b)' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getLHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 } else if (Bop->getOpcode() == BO_LOr) {
@@ -12227,6 +12236,7 @@
   if (EvaluatesAsFalse(S, LHSExpr))
 return;
   // If it's "a || b && 1" don't warn since the precedence doesn't matter.
+  // And 'assert(a || b && "some message")' don't warn as well.
   if (!EvaluatesAsTrue(S, Bop->getRHS()))
 return EmitDiagnosticForLogicalAndInLogicalOr(S, OpLoc, Bop);
 }
@@ -12309,8 +12319,11 @@
   }
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
-  // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  // Here we will not skip 'logical and in logical or' checking
+  // in macros, since 'assert(a || b && "some message")' is equal
+  // to '(a || b && 1)' and 'assert("some message" && a || b)' is
+  // equal to '(1 && a || b)'.
+  if (Opc == BO_LOr) {
 DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
 DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5483,6 +5483,9 @@
 def warn_logical_and_in_logical_or : Warning<
   "'&&' within '||'">, InGroup;
 
+def warn_logical_and_in_logical_or_in_macros: Warning<
+  "'&&' within 

[PATCH] D47577: [clang-format] Separate block comments with CRLF correctly

2018-06-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir requested changes to this revision.
krasimir added inline comments.
This revision now requires changes to proceed.



Comment at: lib/Format/BreakableToken.cpp:327
+  TokenText.substr(2, TokenText.size() - 4)
+  .split(Lines, TokenText.count('\r') > 0 ? "\r\n" : "\n");
 

alexfh wrote:
> FYI, there's a global UseCRLF flag in WhitespaceManager. It may make sense to 
> use it everywhere instead of deciding for each comment. But I'll let actual 
> clang-format maintainers decide on pros and cons of this.
In case the text contains both `\r\n`-s and `\n` not preceded by `\r`, this 
would not break on the `\n`; neither will a version using 
`WhitespaceManager::UsesCRLF`. That is computed by:
```
bool inputUsesCRLF(StringRef Text) {
  return Text.count('\r') * 2 > Text.count('\n');
}```
which implies that we at least tentatively support such mixed cases.

I'd try keeping the split here just by `"\n"` and stripping a trailing 
`"\r"`from each line as a second step.


Repository:
  rC Clang

https://reviews.llvm.org/D47577



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


[PATCH] D47707: [clangd] Downrank symbols with reserved names (score *= 0.1)

2018-06-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM, sorry for the delay


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47707



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


[PATCH] D47896: [CodeComplete] suppress define X X macros

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

In https://reviews.llvm.org/D47896#1126171, @sammccall wrote:

> Hmm, musl does `#define stderr (stderr)` :-( And they discussed #define 
> stderr (stderr+0).
>  (To enforce it's not assigned to etc)
>  https://github.com/cloudius-systems/musl/blob/master/include/stdio.h#L61
>
> Ilya also pointed out offline the windows API convention: CreateFile is a 
> macro for CreateFileW or CreateFileA. In these cases merely suppressing the 
> macro isn't enough, we'd want to replace its info with the underlying decl.
>
> Not sure how/whether to generalize this hack...


Yeah, I'm not sure. Maybe we should just special-case the known cases...


Repository:
  rC Clang

https://reviews.llvm.org/D47896



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


[PATCH] D47896: [CodeComplete] suppress define X X macros

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Hmm, musl does `#define stderr (stderr)` :-( And they discussed #define stderr 
(stderr+0).
(To enforce it's not assigned to etc)
https://github.com/cloudius-systems/musl/blob/master/include/stdio.h#L61

Ilya also pointed out offline the windows API convention: CreateFile is a macro 
for CreateFileW or CreateFileA. In these cases merely suppressing the macro 
isn't enough, we'd want to replace its info with the underlying decl.

Not sure how/whether to generalize this hack...


Repository:
  rC Clang

https://reviews.llvm.org/D47896



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


[PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-08 Thread Hans Wennborg via Phabricator via cfe-commits
hans updated this revision to Diff 150462.
hans added a comment.

Falling back to the "Otherwise, number using $S" code for non-empty enums.


https://reviews.llvm.org/D47875

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/mangle-ms-cxx11.cpp


Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - 
-triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck %s 
--check-prefix=CHECK --check-prefix=MSVC2015
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - 
-triple=i386-pc-win32 -fms-compatibility-version=18.00 | FileCheck %s 
--check-prefix=CHECK --check-prefix=MSVC2013
+// RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - 
-triple=i386-pc-win32 -gcodeview -debug-info-kind=limited | FileCheck %s 
--check-prefix=DBG
 
 namespace FTypeWithQuals {
 template 
@@ -350,3 +351,10 @@
 void f(decltype(enumerator)) {}
 // CHECK-DAG: define internal void @"?f@@YAXW4@@@Z"(
 void use_f() { f(enumerator); }
+
+namespace pr37723 {
+struct s { enum {}; enum {}; };
+// DBG-DAG: DW_TAG_enumeration_type{{.*}}identifier: 
".?AW4@s@pr37723@@"
+// DBG-DAG: DW_TAG_enumeration_type{{.*}}identifier: 
".?AW4@s@pr37723@@"
+s x;
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -884,11 +884,13 @@
 // associate typedef mangled in if they have one.
 Name += "getName();
-  } else if (auto *ED = dyn_cast(TD)) {
-auto EnumeratorI = ED->enumerator_begin();
-assert(EnumeratorI != ED->enumerator_end());
+  } else if (isa(TD) &&
+ cast(TD)->enumerator_begin() !=
+ cast(TD)->enumerator_end()) {
+// Anonymous non-empty enums mangle in the first enumerator.
+auto *ED = cast(TD);
 Name += "getName();
+Name += ED->enumerator_begin()->getName();
   } else {
 // Otherwise, number the types using a $S prefix.
 Name += "Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck %s --check-prefix=CHECK --check-prefix=MSVC2015
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=18.00 | FileCheck %s --check-prefix=CHECK --check-prefix=MSVC2013
+// RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -gcodeview -debug-info-kind=limited | FileCheck %s --check-prefix=DBG
 
 namespace FTypeWithQuals {
 template 
@@ -350,3 +351,10 @@
 void f(decltype(enumerator)) {}
 // CHECK-DAG: define internal void @"?f@@YAXW4@@@Z"(
 void use_f() { f(enumerator); }
+
+namespace pr37723 {
+struct s { enum {}; enum {}; };
+// DBG-DAG: DW_TAG_enumeration_type{{.*}}identifier: ".?AW4@s@pr37723@@"
+// DBG-DAG: DW_TAG_enumeration_type{{.*}}identifier: ".?AW4@s@pr37723@@"
+s x;
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -884,11 +884,13 @@
 // associate typedef mangled in if they have one.
 Name += "getName();
-  } else if (auto *ED = dyn_cast(TD)) {
-auto EnumeratorI = ED->enumerator_begin();
-assert(EnumeratorI != ED->enumerator_end());
+  } else if (isa(TD) &&
+ cast(TD)->enumerator_begin() !=
+ cast(TD)->enumerator_end()) {
+// Anonymous non-empty enums mangle in the first enumerator.
+auto *ED = cast(TD);
 Name += "getName();
+Name += ED->enumerator_begin()->getName();
   } else {
 // Otherwise, number the types using a $S prefix.
 Name += "___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r334270 - [clang-tidy] Improve string type matcher for abseil-string-find-starts-with check.

2018-06-08 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jun  8 01:19:22 2018
New Revision: 334270

URL: http://llvm.org/viewvc/llvm-project?rev=334270=rev
Log:
[clang-tidy] Improve string type matcher for abseil-string-find-starts-with 
check.

Summary:
This patch improves the check to match the desugared "string" type (so that it
can handle custom-implemented string classes), see the newly-added test.

Reviewers: alexfh

Subscribers: klimek, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp?rev=334270=334269=334270=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp Fri 
Jun  8 01:19:22 2018
@@ -36,10 +36,13 @@ void StringFindStartswithCheck::register
   auto ZeroLiteral = integerLiteral(equals(0));
   auto StringClassMatcher = cxxRecordDecl(hasAnyName(SmallVector(
   StringLikeClasses.begin(), StringLikeClasses.end(;
+  auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
 
   auto StringFind = cxxMemberCallExpr(
   // .find()-call on a string...
-  callee(cxxMethodDecl(hasName("find"), ofClass(StringClassMatcher))),
+  callee(cxxMethodDecl(hasName("find"))),
+  on(hasType(StringType)),
   // ... with some search expression ...
   hasArgument(0, expr().bind("needle")),
   // ... and either "0" as second argument or the default argument (also 
0).

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp?rev=334270=334269=334270=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp 
Fri Jun  8 01:19:22 2018
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-string-find-startswith %t
+// RUN: %check_clang_tidy %s abseil-string-find-startswith %t -- \
+// RUN:   -config="{CheckOptions: [{key: 
'abseil-string-find-startswith.StringLikeClasses', value: 
'::std::basic_string;::basic_string'}]}" \
+// RUN:   -- -std=c++11
 
 namespace std {
 template  class allocator {};
@@ -15,14 +17,23 @@ struct basic_string {
 };
 typedef basic_string string;
 typedef basic_string wstring;
+
+struct cxx_string {
+  int find(const char *s, int pos = 0);
+};
 } // namespace std
 
+struct basic_string : public std::cxx_string {
+  basic_string();
+};
+typedef basic_string global_string;
+
 std::string foo(std::string);
 std::string bar();
 
 #define A_MACRO(x, y) ((x) == (y))
 
-void tests(std::string s) {
+void tests(std::string s, global_string s2) {
   s.find("a") == 0;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith instead of 
find() == 0 [abseil-string-find-startswith]
   // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, "a");{{$}}
@@ -47,6 +58,10 @@ void tests(std::string s) {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
   // CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "a");{{$}}
 
+  s2.find("a") == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s2, "a");{{$}}
+
   // expressions that don't trigger the check are here.
   A_MACRO(s.find("a"), 0);
   s.find("a", 1) == 0;


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


Re: r334208 - [X86] Add back builtins for _mm_slli_si128/_mm_srli_si128 and similar intrinsics.

2018-06-08 Thread Martin Storsjö via cfe-commits

On Thu, 7 Jun 2018, Craig Topper via cfe-commits wrote:


Author: ctopper
Date: Thu Jun  7 10:28:03 2018
New Revision: 334208

URL: http://llvm.org/viewvc/llvm-project?rev=334208=rev
Log:
[X86] Add back builtins for  _mm_slli_si128/_mm_srli_si128 and similar 
intrinsics.

We still lower them to native shuffle IR, but we do it in CGBuiltin.cpp now. 
This allows us to check the target feature and ensure the immediate fits in 8 
bits.


FWIW, this change broke building libaom: 
https://bugs.chromium.org/p/aomedia/issues/detail?id=1945


In libaom, there's a macro construct like this:

 #define v256_shr_n_byte(a, n) \
   ((n) < 16   \
? _mm256_alignr_epi8(  \
  _mm256_permute2x128_si256(a, a, _MM_SHUFFLE(2, 0, 0, 1)), a, n)  \
: ((n) > 16\
   ? _mm256_srli_si256(\
 _mm256_permute2x128_si256(a, a, _MM_SHUFFLE(2, 0, 0, 1)), \
 (n)-16)   \
   : _mm256_permute2x128_si256(a, a, _MM_SHUFFLE(2, 0, 0, 1

Since this commit, the compilation errors out due to the _mm256_srli_si256 
with invalid range, even though the toplevel ternary operator won't 
actually pick them to be used. Not sure if there's anything to do from the 
clang point of view here, I guess it's a tradeoff between having stricter 
parameter checks for the intrinsics, vs the convenience of piling them up 
in a macro like this in libaom.


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


[PATCH] D47931: [clangd] Customizable URI schemes for dynamic index.

2018-06-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov.

This allows dynamic index to have consistent URI schemes with the
static index which can have customized URI schemes, which would make file
proximity scoring based on URIs easier.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47931

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/FileIndexTests.cpp

Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -96,6 +96,42 @@
   M.update(File.Filename, (), AST.getPreprocessorPtr());
 }
 
+class TestURIScheme : public URIScheme {
+public:
+  llvm::Expected
+  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
+  llvm::StringRef /*HintPath*/) const override {
+llvm_unreachable("ClangdTests never makes absolute path.");
+  }
+
+  llvm::Expected
+  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
+return URI::parse(HardcodedURI);
+  }
+  static const char HardcodedURI[];
+  static const char Scheme[];
+};
+
+const char TestURIScheme::HardcodedURI[] = "ClangdTests:///test";
+const char TestURIScheme::Scheme[] = "ClangdTest";
+
+static URISchemeRegistry::Add X(TestURIScheme::Scheme,
+   "Test scheme for ClangdTests.");
+
+TEST(FileIndexTest, CustomizedURIScheme) {
+  FileIndex M({TestURIScheme::Scheme});
+  update(M, "f", "class string {};");
+
+  FuzzyFindRequest Req;
+  Req.Query = "";
+  bool SeenSymbol = false;
+  M.fuzzyFind(Req, [&](const Symbol ) {
+EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, TestURIScheme::HardcodedURI);
+SeenSymbol = true;
+  });
+  EXPECT_TRUE(SeenSymbol);
+}
+
 TEST(FileIndexTest, IndexAST) {
   FileIndex M;
   update(M, "f1", "namespace ns { void f() {} class X {}; }");
Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -152,28 +152,6 @@
   }
 };
 
-constexpr const char* ClangdTestScheme = "ClangdTests";
-class TestURIScheme : public URIScheme {
-public:
-  llvm::Expected
-  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
-  llvm::StringRef /*HintPath*/) const override {
-llvm_unreachable("ClangdTests never makes absolute path.");
-  }
-
-  llvm::Expected
-  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
-llvm_unreachable("ClangdTest never creates a test URI.");
-  }
-
-  llvm::Expected getIncludeSpelling(const URI ) const override {
-return ("\"" + U.body().trim("/") + "\"").str();
-  }
-};
-
-static URISchemeRegistry::Add
-X(ClangdTestScheme, "Test scheme for ClangdTests.");
-
 TEST_F(ClangdVFSTest, Parse) {
   // FIXME: figure out a stable format for AST dumps, so that we can check the
   // output of the dump itself is equal to the expected one, not just that it's
Index: clangd/index/FileIndex.h
===
--- clangd/index/FileIndex.h
+++ clangd/index/FileIndex.h
@@ -56,6 +56,10 @@
 /// \brief This manages symbls from files and an in-memory index on all symbols.
 class FileIndex : public SymbolIndex {
 public:
+  /// If URISchemes is empty, the default schemes in SymbolCollector will be
+  /// used.
+  FileIndex(std::vector URISchemes = {});
+
   /// \brief Update symbols in \p Path with symbols in \p AST. If \p AST is
   /// nullptr, this removes all symbols in the file.
   /// If \p AST is not null, \p PP cannot be null and it should be the
@@ -72,11 +76,14 @@
 private:
   FileSymbols FSymbols;
   MemIndex Index;
+  std::vector URISchemes;
 };
 
 /// Retrieves namespace and class level symbols in \p AST.
 /// Exposed to assist in unit tests.
-SymbolSlab indexAST(ASTContext , std::shared_ptr PP);
+/// If URISchemes is empty, the default schemes in SymbolCollector will be used.
+SymbolSlab indexAST(ASTContext , std::shared_ptr PP,
+llvm::ArrayRef URISchemes = {});
 
 } // namespace clangd
 } // namespace clang
Index: clangd/index/FileIndex.cpp
===
--- clangd/index/FileIndex.cpp
+++ clangd/index/FileIndex.cpp
@@ -15,15 +15,18 @@
 namespace clang {
 namespace clangd {
 
-SymbolSlab indexAST(ASTContext , std::shared_ptr PP) {
+SymbolSlab indexAST(ASTContext , std::shared_ptr PP,
+llvm::ArrayRef URISchemes) {
   SymbolCollector::Options CollectorOpts;
   // FIXME(ioeric): we might also want to collect include headers. We would need
   // to make sure all includes are canonicalized (with CanonicalIncludes), which
   // is not trivial given the current way of 

r334266 - [X86] Add builtins for shufps and shufpd to enable target feature and immediate range checking.

2018-06-08 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri Jun  8 00:18:33 2018
New Revision: 334266

URL: http://llvm.org/viewvc/llvm-project?rev=334266=rev
Log:
[X86] Add builtins for shufps and shufpd to enable target feature and immediate 
range checking.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avxintrin.h
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/lib/Headers/xmmintrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334266=334265=334266=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Jun  8 00:18:33 2018
@@ -316,6 +316,7 @@ TARGET_BUILTIN(__builtin_ia32_rsqrtps, "
 TARGET_BUILTIN(__builtin_ia32_rsqrtss, "V4fV4f", "nc", "sse")
 TARGET_BUILTIN(__builtin_ia32_sqrtps, "V4fV4f", "nc", "sse")
 TARGET_BUILTIN(__builtin_ia32_sqrtss, "V4fV4f", "nc", "sse")
+TARGET_BUILTIN(__builtin_ia32_shufps, "V4fV4fV4fIi", "nc", "sse")
 
 TARGET_BUILTIN(__builtin_ia32_maskmovdqu, "vV16cV16cc*", "n", "sse2")
 TARGET_BUILTIN(__builtin_ia32_movmskpd, "iV2d", "nc", "sse2")
@@ -327,6 +328,7 @@ TARGET_BUILTIN(__builtin_ia32_pshufhw, "
 TARGET_BUILTIN(__builtin_ia32_psadbw128, "V2LLiV16cV16c", "nc", "sse2")
 TARGET_BUILTIN(__builtin_ia32_sqrtpd, "V2dV2d", "nc", "sse2")
 TARGET_BUILTIN(__builtin_ia32_sqrtsd, "V2dV2d", "nc", "sse2")
+TARGET_BUILTIN(__builtin_ia32_shufpd, "V2dV2dV2di", "nc", "sse2")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2dq, "V2LLiV2d", "nc", "sse2")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2ps, "V4fV2d", "nc", "sse2")
 TARGET_BUILTIN(__builtin_ia32_cvttpd2dq, "V4iV2d", "nc", "sse2")
@@ -487,6 +489,8 @@ TARGET_BUILTIN(__builtin_ia32_blendpd256
 TARGET_BUILTIN(__builtin_ia32_blendps256, "V8fV8fV8fIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_blendvpd256, "V4dV4dV4dV4d", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_blendvps256, "V8fV8fV8fV8f", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_shufpd256, "V4dV4dV4dIi", "nc", "avx")
+TARGET_BUILTIN(__builtin_ia32_shufps256, "V8fV8fV8fIi", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_dpps256, "V8fV8fV8fIc", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cmppd, "V2dV2dV2dIc", "nc", "avx")
 TARGET_BUILTIN(__builtin_ia32_cmppd256, "V4dV4dV4dIc", "nc", "avx")
@@ -1536,6 +1540,8 @@ TARGET_BUILTIN(__builtin_ia32_shuf_f32x4
 TARGET_BUILTIN(__builtin_ia32_shuf_f64x2, "V8dV8dV8dIi", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_shuf_i32x4, "V16iV16iV16iIi", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_shuf_i64x2, "V8LLiV8LLiV8LLiIi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_shufpd512, "V8dV8dV8dIi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_shufps512, "V16fV16fV16fIi", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_shuf_f32x4_256, "V8fV8fV8fIi", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_shuf_f64x2_256, "V4dV4dV4dIi", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_shuf_i32x4_256, "V8iV8iV8iIi", "nc", "avx512vl")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334266=334265=334266=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Jun  8 00:18:33 2018
@@ -9403,6 +9403,36 @@ Value *CodeGenFunction::EmitX86BuiltinEx
makeArrayRef(Indices, NumElts),
"permil");
   }
+  case X86::BI__builtin_ia32_shufpd:
+  case X86::BI__builtin_ia32_shufpd256:
+  case X86::BI__builtin_ia32_shufpd512:
+  case X86::BI__builtin_ia32_shufps:
+  case X86::BI__builtin_ia32_shufps256:
+  case X86::BI__builtin_ia32_shufps512: {
+uint32_t Imm = cast(Ops[2])->getZExtValue();
+llvm::Type *Ty = Ops[0]->getType();
+unsigned NumElts = Ty->getVectorNumElements();
+unsigned NumLanes = Ty->getPrimitiveSizeInBits() / 128;
+unsigned NumLaneElts = NumElts / NumLanes;
+
+// Splat the 8-bits of immediate 4 times to help the loop wrap around.
+Imm = (Imm & 0xff) * 0x01010101;
+
+uint32_t Indices[16];
+for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
+  for (unsigned i = 0; i != NumLaneElts; ++i) {
+unsigned Index = Imm % NumLaneElts;
+Imm /= NumLaneElts;
+if (i >= (NumLaneElts / 2))
+  Index += NumElts;
+Indices[l + i] = l + Index;
+  }
+}
+
+return Builder.CreateShuffleVector(Ops[0], Ops[1],
+   makeArrayRef(Indices, NumElts),
+   "shufp");
+  }
   case X86::BI__builtin_ia32_palignr128:
   case X86::BI__builtin_ia32_palignr256:
   case X86::BI__builtin_ia32_palignr512: {

Modified: 

  1   2   >