[PATCH] D52926: Rename EM_ConstantExpressionUnevaluated to EM_ConstantFoldUnevaluated, which is actually what the code is currently doing.

2018-10-04 Thread James Y Knight via Phabricator via cfe-commits
jyknight created this revision.
jyknight added a reviewer: rsmith.

And, configure it to explicitly request equivalent behavior to
ConstantFold, instead of getting that behavior accidentally.

While it seems that diagnose_if and enable_if were intended to require
a constexpr argument, the code was actually only checking whether it
could be constant-folded, due to the confusing way the constant
evaluator code currently works.

It _probably_ should be fixed to actually check for
constexpr-ness. However, r290584 now depends on it NOT doing so -- and
it's possible that some users are, too.

I'd like to land this, to unblock the follow-on cleanup -- without
changing the semantics first -- and maybe loop back to convert it to
require a constexpr later, if it looks like users aren't depending on
the semantics it has now.

This change is a prerequisite for fixing the confusion in the
ExprConstant code which led to this situation.


https://reviews.llvm.org/D52926

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/enable_if.c

Index: clang/test/Sema/enable_if.c
===
--- clang/test/Sema/enable_if.c
+++ clang/test/Sema/enable_if.c
@@ -170,4 +170,24 @@
   variadic_enable_if(0, m); // expected-error{{no matching}}
   variadic_enable_if(0, m, 3); // expected-error{{no matching}}
 }
+
+// Test of the current weird semantics of enable_if (and diagnose_if).
+//
+// There's two kinds of checking of the expression going on:
+//  1. Whether it could potentially be a constexpr -- without access to the
+// parameters.
+//  2. Checking if the condition evaluates to true with concrete
+// arguments. While #1 requires that it could potentially be a constexpr,
+// this step does not require that it actually _IS_ a constexpr, only that
+// it's evaluable! (Note: this looseness might be unintended)
+
+void non_constexpr() __attribute__((enable_if((int*)(char*)0 == 0, ""))); // expected-error{{'enable_if' attribute expression never produces a constant expression}} expected-note{{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
+void non_constexpr_call() {
+non_constexpr();
+}
+
+void non_constexpr_conditional(long x) __attribute__((enable_if(x?1: (int*)(char*)0 == 0, "")));
+void non_constexpr_conditional_call() {
+non_constexpr_conditional(0);
+}
 #endif
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -744,12 +744,11 @@
   /// can't be modeled.
   EM_IgnoreSideEffects,
 
-  /// Evaluate as a constant expression. Stop if we find that the expression
-  /// is not a constant expression. Some expressions can be retried in the
+  /// Evaluate as a constant fold. Some expressions can be retried in the
   /// optimizer if we don't constant fold them here, but in an unevaluated
-  /// context we try to fold them immediately since the optimizer never
-  /// gets a chance to look at it.
-  EM_ConstantExpressionUnevaluated,
+  /// context we try to fold them immediately since the optimizer never gets
+  /// a chance to look at it.
+  EM_ConstantFoldUnevaluated,
 
   /// Evaluate as a potential constant expression. Keep going if we hit a
   /// construct that we can't evaluate yet (because we don't yet know the
@@ -854,13 +853,13 @@
   case EM_ConstantFold:
   case EM_IgnoreSideEffects:
   case EM_EvaluateForOverflow:
+  case EM_ConstantFoldUnevaluated:
 if (!HasFoldFailureDiagnostic)
   break;
 // We've already failed to fold something. Keep that diagnostic.
 LLVM_FALLTHROUGH;
   case EM_ConstantExpression:
   case EM_PotentialConstantExpression:
-  case EM_ConstantExpressionUnevaluated:
   case EM_PotentialConstantExpressionUnevaluated:
 HasActiveDiagnostic = false;
 return OptionalDiagnostic();
@@ -951,7 +950,7 @@
 return true;
 
   case EM_ConstantExpression:
-  case EM_ConstantExpressionUnevaluated:
+  case EM_ConstantFoldUnevaluated:
   case EM_ConstantFold:
 return false;
   }
@@ -971,12 +970,12 @@
   case EM_EvaluateForOverflow:
   case EM_IgnoreSideEffects:
   case EM_ConstantFold:
+  case EM_ConstantFoldUnevaluated:
 return true;
 
   case EM_PotentialConstantExpression:
   case EM_PotentialConstantExpressionUnevaluated:
   case EM_ConstantExpression:
-  case EM_ConstantExpressionUnevaluated:
 return false;
   }
   llvm_unreachable("Missed EvalMode case");
@@ -1003,7 +1002,7 @@
 return true;
 
   case EM_ConstantExpression:
-  case EM_ConstantExpressionUnevaluated:
+  case EM_ConstantFoldUnevaluated:
   case EM_ConstantFold:
   case EM_IgnoreSideEffects:

[PATCH] D52924: Make __builtin_object_size use the EM_IgnoreSideEffects evaluation mode.

2018-10-04 Thread James Y Knight via Phabricator via cfe-commits
jyknight created this revision.
jyknight added a reviewer: rsmith.

And, since EM_OffsetFold is now unused, remove it.

While builtin_object_size intends to ignore the presence of
side-effects in its argument, the EM_OffsetFold mode was NOT
configured to ignore side-effects. Rather it was effectively identical
to EM_ConstantFold -- its explanatory comment
notwithstanding.

However, currently, keepEvaluatingAfterSideEffect() is not always
honored -- sometimes evaluation continues despite it returning
false. Therefore, since the b_o_s code was only checking the return
value from evaluation, and not additionally checking the
HasSideEffects flag, side-effects _were_ in many cases actually being
ignored.

This change is a prerequisite cleanup towards fixing that issue.


https://reviews.llvm.org/D52924

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -759,18 +759,6 @@
   /// context we try to fold them immediately since the optimizer never
   /// gets a chance to look at it.
   EM_PotentialConstantExpressionUnevaluated,
-
-  /// Evaluate as a constant expression. In certain scenarios, if:
-  /// - we find a MemberExpr with a base that can't be evaluated, or
-  /// - we find a variable initialized with a call to a function that has
-  ///   the alloc_size attribute on it
-  /// then we may consider evaluation to have succeeded.
-  ///
-  /// In either case, the LValue returned shall have an invalid base; in 
the
-  /// former, the base will be the invalid MemberExpr, in the latter, the
-  /// base will be either the alloc_size CallExpr or a CastExpr wrapping
-  /// said CallExpr.
-  EM_OffsetFold,
 } EvalMode;
 
 /// Are we checking whether the expression is a potential constant
@@ -874,7 +862,6 @@
   case EM_PotentialConstantExpression:
   case EM_ConstantExpressionUnevaluated:
   case EM_PotentialConstantExpressionUnevaluated:
-  case EM_OffsetFold:
 HasActiveDiagnostic = false;
 return OptionalDiagnostic();
   }
@@ -966,7 +953,6 @@
   case EM_ConstantExpression:
   case EM_ConstantExpressionUnevaluated:
   case EM_ConstantFold:
-  case EM_OffsetFold:
 return false;
   }
   llvm_unreachable("Missed EvalMode case");
@@ -985,7 +971,6 @@
   case EM_EvaluateForOverflow:
   case EM_IgnoreSideEffects:
   case EM_ConstantFold:
-  case EM_OffsetFold:
 return true;
 
   case EM_PotentialConstantExpression:
@@ -1021,7 +1006,6 @@
   case EM_ConstantExpressionUnevaluated:
   case EM_ConstantFold:
   case EM_IgnoreSideEffects:
-  case EM_OffsetFold:
 return false;
   }
   llvm_unreachable("Missed EvalMode case");
@@ -1093,18 +1077,18 @@
 }
   };
 
-  /// RAII object used to treat the current evaluation as the correct pointer
-  /// offset fold for the current EvalMode
-  struct FoldOffsetRAII {
+  /// RAII object used to set the current evaluation mode to ignore
+  /// side-effects.
+  struct IgnoreSideEffectsRAII {
 EvalInfo &Info;
 EvalInfo::EvaluationMode OldMode;
-explicit FoldOffsetRAII(EvalInfo &Info)
+explicit IgnoreSideEffectsRAII(EvalInfo &Info)
 : Info(Info), OldMode(Info.EvalMode) {
   if (!Info.checkingPotentialConstantExpression())
-Info.EvalMode = EvalInfo::EM_OffsetFold;
+Info.EvalMode = EvalInfo::EM_IgnoreSideEffects;
 }
 
-~FoldOffsetRAII() { Info.EvalMode = OldMode; }
+~IgnoreSideEffectsRAII() { Info.EvalMode = OldMode; }
   };
 
   /// RAII object used to optionally suppress diagnostics and side-effects from
@@ -8049,7 +8033,7 @@
 // If there are any, but we can determine the pointed-to object anyway, 
then
 // ignore the side-effects.
 SpeculativeEvaluationRAII SpeculativeEval(Info);
-FoldOffsetRAII Fold(Info);
+IgnoreSideEffectsRAII Fold(Info);
 
 if (E->isGLValue()) {
   // It's possible for us to be given GLValues if we're called via
@@ -8117,7 +8101,6 @@
 case EvalInfo::EM_ConstantFold:
 case EvalInfo::EM_EvaluateForOverflow:
 case EvalInfo::EM_IgnoreSideEffects:
-case EvalInfo::EM_OffsetFold:
   // Leave it to IR generation.
   return Error(E);
 case EvalInfo::EM_ConstantExpressionUnevaluated:


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -759,18 +759,6 @@
   /// context we try to fold them immediately since the optimizer never
   /// gets a chance to look at it.
   EM_PotentialConstantExpressionUnevaluated,
-
-  /// Evaluate as a constant expression. In certain scenarios, if:
-  /// - we find a MemberExpr with a base that can't be evaluated, or
-

Re: r343790 - [clang] Add the exclude_from_explicit_instantiation attribute

2018-10-04 Thread Galina Kistanova via cfe-commits
Hello Louis,

This commit broke build step on one of our builders:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/13042

. . .
FAILED: tools/clang/lib/Sema/CMakeFiles/clangSema.dir/SemaExprCXX.cpp.obj
C:\PROGRA~2\MICROS~1.0\VC\bin\amd64\cl.exe  /nologo /TP -DEXPENSIVE_CHECKS
-DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE
-D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_DEBUG -D_GNU_SOURCE
-D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS
-D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS -Itools\clang\lib\Sema
-IC:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\lib\Sema
-IC:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\include
-Itools\clang\include -Iinclude
-IC:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\include
/DWIN32 /D_WINDOWS   /Zc:inline /Zc:strictStrings /Oi /Zc:rvalueCast /W4
-wd4141 -wd4146 -wd4180 -wd4244 -wd4258 -wd4267 -wd4291 -wd4345 -wd4351
-wd4355 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4800
-wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706
-wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091
-wd4592 -wd4319 -wd4324 -w14062 -we4238 /MDd /Zi /Ob0 /Od /RTC1/EHs-c-
/GR- /showIncludes
/Fotools\clang\lib\Sema\CMakeFiles\clangSema.dir\SemaExprCXX.cpp.obj
/Fdtools\clang\lib\Sema\CMakeFiles\clangSema.dir\clangSema.pdb /FS -c
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\lib\Sema\SemaExprCXX.cpp
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\lib\Sema\SemaExprCXX.cpp
: fatal error C1128: number of sections exceeded object file format limit:
compile with /bigobj


Please have a look?
The builder was already red and did not send notifications on this.

Thanks

Galina

On Thu, Oct 4, 2018 at 8:51 AM Louis Dionne via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ldionne
> Date: Thu Oct  4 08:49:42 2018
> New Revision: 343790
>
> URL: http://llvm.org/viewvc/llvm-project?rev=343790&view=rev
> Log:
> [clang] Add the exclude_from_explicit_instantiation attribute
>
> Summary:
> This attribute allows excluding a member of a class template from being
> part
> of an explicit template instantiation of that class template. This also
> makes
> sure that code using such a member will not take for granted that an
> external
> instantiation exists in another translation unit. The attribute was
> discussed
> on cfe-dev at [1] and is primarily motivated by the removal of
> always_inline
> in libc++ to control what's part of the ABI (see links in [1]).
>
> [1]: http://lists.llvm.org/pipermail/cfe-dev/2018-August/059024.html
>
> rdar://problem/43428125
>
> Reviewers: rsmith
>
> Subscribers: dexonsmith, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D51789
>
> Added:
>
> cfe/trunk/test/CodeGenCXX/attr-exclude_from_explicit_instantiation.dont_assume_extern_instantiation.cpp
>
> cfe/trunk/test/SemaCXX/attr-exclude_from_explicit_instantiation.diagnose_on_undefined_entity.cpp
>
> cfe/trunk/test/SemaCXX/attr-exclude_from_explicit_instantiation.explicit_instantiation.cpp
>
> cfe/trunk/test/SemaCXX/attr-exclude_from_explicit_instantiation.extern_declaration.cpp
>
> cfe/trunk/test/SemaCXX/attr-exclude_from_explicit_instantiation.merge_redeclarations.cpp
> Modified:
> cfe/trunk/include/clang/Basic/Attr.td
> cfe/trunk/include/clang/Basic/AttrDocs.td
> cfe/trunk/lib/Sema/Sema.cpp
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
> cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=343790&r1=343789&r2=343790&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Thu Oct  4 08:49:42 2018
> @@ -3042,6 +3042,13 @@ def InternalLinkage : InheritableAttr {
>let Documentation = [InternalLinkageDocs];
>  }
>
> +def ExcludeFromExplicitInstantiation : InheritableAttr {
> +  let Spellings = [Clang<"exclude_from_explicit_instantiation">];
> +  let Subjects = SubjectList<[Var, Function, CXXRecord]>;
> +  let Documentation = [ExcludeFromExplicitInstantiationDocs];
> +  let MeaningfulToClassTemplateDefinition = 1;
> +}
> +
>  def Reinitializes : InheritableAttr {
>let Spellings = [Clang<"reinitializes", 0>];
>let Subjects = SubjectList<[NonStaticNonConstCXXMethod], ErrorDiag>;
>
> Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=343790&r1=343789&r2=343790&view=diff
>
> ==

[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions

2018-10-04 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Tests should also include some global variables


https://reviews.llvm.org/D52891



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


[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions

2018-10-04 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I think the name needs work, but I'm not sure what it should be. I think it 
should avoid using "non" and "amdgpu"


https://reviews.llvm.org/D52891



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


[PATCH] D52064: [Sema] Add a note pointing to the first use of an implicit capture

2018-10-04 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

@rsmith, friendly ping. I'm not in a rush on this one, but I know you wanted to 
see an improvement in lambda capture diagnostics.


https://reviews.llvm.org/D52064



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


[PATCH] D52418: [driver][mips] Enable integrated assembler for MIPS64 except N32 ABI selected

2018-10-04 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

Simon, and what about lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp?


Repository:
  rC Clang

https://reviews.llvm.org/D52418



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


[PATCH] D52920: Introduce code_model macros

2018-10-04 Thread Ali Tamur via Phabricator via cfe-commits
tamur created this revision.
tamur added reviewers: compnerd, MaskRay.
tamur added a project: clang.
Herald added a subscriber: cfe-commits.

gcc defines macros such as __code_model_small_ based on the user passed command 
line flag -mcmodel. clang accepts a flag with the same name and similar 
effects, but does not generate any macro that the user can use. This cl narrows 
the gap between gcc and clang behaviour.

However, achieving full compatibility with gcc is not trivial: The set of valid 
values for mcmodel in gcc and clang are not equal. Also, gcc defines different 
macros for different architectures. In this cl, we only tackle an easy part of 
the problem and define the macro only for x64 architecture. When the user does 
not specify a mcmodel, the macro for small code model is produced, as is the 
case with gcc.


Repository:
  rC Clang

https://reviews.llvm.org/D52920

Files:
  include/clang/Basic/TargetOptions.h
  lib/Basic/Targets/X86.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -47,21 +47,21 @@
 // CXX11:#define __cplusplus 201103L
 // CXX11:#define __private_extern__ extern
 //
-// 
+//
 // RUN: %clang_cc1 -x c++ -std=c++98 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX98 %s
-// 
+//
 // CXX98:#define __GNUG__ {{.*}}
 // CXX98:#define __GXX_RTTI 1
 // CXX98:#define __GXX_WEAK__ 1
 // CXX98:#define __cplusplus 199711L
 // CXX98:#define __private_extern__ extern
 //
-// 
+//
 // RUN: %clang_cc1 -fdeprecated-macro -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix DEPRECATED %s
 //
 // DEPRECATED:#define __DEPRECATED 1
 //
-// 
+//
 // RUN: %clang_cc1 -std=c99 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix C99 %s
 //
 // C99:#define __STDC_VERSION__ 199901L
@@ -71,7 +71,7 @@
 // C99-NOT: __GXX_WEAK__
 // C99-NOT: __cplusplus
 //
-// 
+//
 // RUN: %clang_cc1 -std=c11 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix C11 %s
 // RUN: %clang_cc1 -std=c1x -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix C11 %s
 // RUN: %clang_cc1 -std=iso9899:2011 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix C11 %s
@@ -86,7 +86,7 @@
 // C11-NOT: __GXX_WEAK__
 // C11-NOT: __cplusplus
 //
-// 
+//
 // RUN: %clang_cc1 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix COMMON %s
 //
 // COMMON:#define __CONSTANT_CFSTRINGS__ 1
@@ -113,7 +113,7 @@
 // RUN: %clang_cc1 -E -dM -triple=x86_64-pc-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix C-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -triple=x86_64-apple-darwin < /dev/null | FileCheck -match-full-lines -check-prefix C-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -triple=armv7a-apple-darwin < /dev/null | FileCheck -match-full-lines -check-prefix C-DEFAULT %s
-// 
+//
 // C-DEFAULT:#define __STDC_VERSION__ 201112L
 //
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
@@ -158,12 +158,12 @@
 // GXX98:#define __cplusplus 199711L
 // GXX98:#define __private_extern__ extern
 //
-// 
+//
 // RUN: %clang_cc1 -std=iso9899:199409 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix C94 %s
 //
 // C94:#define __STDC_VERSION__ 199409L
 //
-// 
+//
 // RUN: %clang_cc1 -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix MSEXT %s
 //
 // MSEXT-NOT:#define __STDC__
@@ -185,7 +185,7 @@
 // MSEXT-CXX-NOWCHAR-NOT:#define _WCHAR_T_DEFINED 1
 // MSEXT-CXX-NOWCHAR:#define __BOOL_DEFINED 1
 //
-// 
+//
 // RUN: %clang_cc1 -x objective-c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix OBJC %s
 //
 // OBJC:#define OBJC_NEW_PROPERTIES 1
@@ -197,7 +197,7 @@
 //
 // OBJCGC:#define __OBJC_GC__ 1
 //
-// 
+//
 // RUN: %clang_cc1 -x objective-c -fobjc-exceptions -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix NONFRAGILE %s
 //
 // NONFRAGILE:#define OBJC_ZEROCOST_EXCEPTIONS 1
@@ -246,9 +246,9 @@
 //
 // PASCAL:#define __PASCAL_STRINGS__ 1
 //
-// 
+//
 // RUN: %clang_cc1 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix SCHAR %s
-// 
+//
 // SCHAR:#define __STDC__ 1
 // SCHAR-NOT:#define __UNSIGNED_CHAR__
 // SCHAR:#define __clang__ 1
@@ -7978,6 +7978,7 @@
 // X86_64:#define __WINT_WIDTH__ 32
 // X86_64:#define __amd64 1
 // X86_64:#define __amd64__ 1
+// X86_64:#define __code_model_small_ 1
 // X86_64:#define __x86_64 1
 // X86_64:#define __x86_64__ 1
 //
@@ -7987,7 +7988,10 @@
 // X86_64H:#define __x86_64__ 1
 // X86_64H:#define __x86_64h 1
 // X86_64H:#define __x86_64h__ 1
-
+//
+// RUN: %clang -xc - -E -dD -mcmodel=medium --target=i386-unknown-linux < /dev/null | FileCheck -match-full-lines -check-prefix X86_MEDIUM %s
+// X86_MEDIUM:#define __code_model_medium_ 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-none-none-gnux32 < /dev/

[PATCH] D52842: clang-format: Don't insert spaces in front of :: for Java 8 Method References.

2018-10-04 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

krasimir, do you do clang-format reviews these days? If not, do you know who 
does?


https://reviews.llvm.org/D52842



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


r343837 - [WebAssembly] any_true and all_true builtins

2018-10-04 Thread Thomas Lively via cfe-commits
Author: tlively
Date: Thu Oct  4 17:59:37 2018
New Revision: 343837

URL: http://llvm.org/viewvc/llvm-project?rev=343837&view=rev
Log:
[WebAssembly] any_true and all_true builtins

Summary: Depends on D52858.

Reviewers: aheejin, dschuff, craig.topper

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-wasm.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=343837&r1=343836&r2=343837&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Oct  4 17:59:37 
2018
@@ -66,4 +66,13 @@ BUILTIN(__builtin_wasm_sub_saturate_u_i8
 BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
 BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
 
+BUILTIN(__builtin_wasm_any_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_any_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_any_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_any_true_i64x2, "iV2LLi", "nc")
+BUILTIN(__builtin_wasm_all_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
+
 #undef BUILTIN

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343837&r1=343836&r2=343837&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 17:59:37 2018
@@ -12536,6 +12536,35 @@ Value *CodeGenFunction::EmitWebAssemblyB
 Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  IntNo = Intrinsic::wasm_anytrue;
+  break;
+case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+case WebAssembly::BI__builtin_wasm_all_true_i64x2:
+  IntNo = Intrinsic::wasm_alltrue;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=343837&r1=343836&r2=343837&view=diff
==
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Thu Oct  4 17:59:37 2018
@@ -228,3 +228,51 @@ i16x8 f32(i16x8 x, i16x8 y) {
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
+
+int f33(i8x16 x) {
+  return __builtin_wasm_any_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f34(i16x8 x) {
+  return __builtin_wasm_any_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f35(i32x4 x) {
+  return __builtin_wasm_any_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f36(i64x2 x) {
+  return __builtin_wasm_any_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f37(i8x16 x) {
+  return __builtin_wasm_all_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f38(i16x8 x) {
+  return __builtin_wasm_all_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f39(i32x4 x) {
+  return __builtin_wasm_all_true_i32x4(x

r343835 - [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via cfe-commits
Author: tlively
Date: Thu Oct  4 17:58:07 2018
New Revision: 343835

URL: http://llvm.org/viewvc/llvm-project?rev=343835&view=rev
Log:
[WebAssembly] __builtin_wasm_replace_lane_* builtins

Summary: Depends on D52852.

Reviewers: aheejin, dschuff

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-wasm.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=343835&r1=343834&r2=343835&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Oct  4 17:58:07 
2018
@@ -49,4 +49,11 @@ BUILTIN(__builtin_wasm_extract_lane_i64x
 BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
 BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
 
+BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2LLiV2LLiIiLLi", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
+
 #undef BUILTIN

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343835&r1=343834&r2=343835&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 17:58:07 2018
@@ -12474,6 +12474,34 @@ Value *CodeGenFunction::EmitWebAssemblyB
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i16x8:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_replace_lane_f64x2: {
+llvm::APSInt LaneConst;
+if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
+  llvm_unreachable("Constant arg isn't actually constant?");
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
+Value *Val = EmitScalarExpr(E->getArg(2));
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+case WebAssembly::BI__builtin_wasm_replace_lane_i16x8: {
+  llvm::Type *ElemType = ConvertType(E->getType())->getVectorElementType();
+  Value *Trunc = Builder.CreateTrunc(Val, ElemType);
+  return Builder.CreateInsertElement(Vec, Trunc, Lane);
+}
+case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+case WebAssembly::BI__builtin_wasm_replace_lane_f64x2:
+  return Builder.CreateInsertElement(Vec, Val, Lane);
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+  }
 
   default:
 return nullptr;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=343835&r1=343834&r2=343835&view=diff
==
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Thu Oct  4 17:58:07 2018
@@ -134,3 +134,41 @@ double f18(f64x2 v) {
   // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f19(i8x16 v, int x) {
+  return __builtin_wasm_replace_lane_i8x16(v, 13, x);
+  // WEBASSEMBLY: trunc i32 %x to i8
+  // WEBASSEMBLY-NEXT: insertelement <16 x i8> %v, i8 %{{.*}}, i32 13
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f20(i16x8 v, int x) {
+  return __builtin_wasm_replace_lane_i16x8(v, 7, x);
+  // WEBASSEMBLY: trunc i32 %x to i16
+  // WEBASSEMBLY-NEXT: insertelement <8 x i16> %v, i16 %{{.*}}, i32 7
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i32x4 f21(i32x4 v, int x) {
+  return __builtin_wasm_replace_lane_i32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x i32> %v, i32 %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 f22(i64x2 v, long long x) {
+  return __builtin_wasm_replace_lane_i64x2(v, 1, x);
+  // WEBASSEMBLY: insertelement <2 x i64> %v, i64 %x, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f32x4 f23(f32x4 v, float x) {
+  return __builtin_wasm_replace_lane_f32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x float> %v, float %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f64x2 f24(f64

r343836 - [WebAssembly] saturating arithmetic builtins

2018-10-04 Thread Thomas Lively via cfe-commits
Author: tlively
Date: Thu Oct  4 17:58:56 2018
New Revision: 343836

URL: http://llvm.org/viewvc/llvm-project?rev=343836&view=rev
Log:
[WebAssembly] saturating arithmetic builtins

Summary: Depends on D52856.

Reviewers: aheejin, dschuff

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-wasm.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=343836&r1=343835&r2=343836&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Oct  4 17:58:56 
2018
@@ -56,4 +56,14 @@ BUILTIN(__builtin_wasm_replace_lane_i64x
 BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
 BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8s", "nc")
+
+BUILTIN(__builtin_wasm_sub_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
+
 #undef BUILTIN

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343836&r1=343835&r2=343836&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 17:58:56 2018
@@ -12502,6 +12502,40 @@ Value *CodeGenFunction::EmitWebAssemblyB
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_unsigned;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
+return Builder.CreateCall(Callee, {LHS, RHS});
+  }
 
   default:
 return nullptr;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=343836&r1=343835&r2=343836&view=diff
==
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Thu Oct  4 17:58:56 2018
@@ -172,3 +172,59 @@ f64x2 f24(f64x2 v, double x) {
   // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f25(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f26(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f27(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x 

r343834 - [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-04 Thread Thomas Lively via cfe-commits
Author: tlively
Date: Thu Oct  4 17:54:44 2018
New Revision: 343834

URL: http://llvm.org/viewvc/llvm-project?rev=343834&view=rev
Log:
[WebAssembly] __builtin_wasm_extract_lane_* builtins

Reviewers: aheejin, dschuff

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-wasm.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=343834&r1=343833&r2=343834&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Oct  4 17:54:44 
2018
@@ -39,4 +39,14 @@ BUILTIN(__builtin_wasm_atomic_wait_i32,
 BUILTIN(__builtin_wasm_atomic_wait_i64, "iLLi*LLiLLi", "n")
 BUILTIN(__builtin_wasm_atomic_notify, "Uii*i", "n")
 
+// SIMD builtins
+BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i32x4, "iV4iIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
+
 #undef BUILTIN

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343834&r1=343833&r2=343834&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 17:54:44 2018
@@ -12444,6 +12444,36 @@ Value *CodeGenFunction::EmitWebAssemblyB
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f64x2: {
+llvm::APSInt LaneConst;
+if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
+  llvm_unreachable("Constant arg isn't actually constant?");
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
+Value *Extract = Builder.CreateExtractElement(Vec, Lane);
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  return Builder.CreateSExt(Extract, ConvertType(E->getType()));
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  return Builder.CreateZExt(Extract, ConvertType(E->getType()));
+case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+case WebAssembly::BI__builtin_wasm_extract_lane_f64x2:
+  return Extract;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+  }
 
   default:
 return nullptr;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=343834&r1=343833&r2=343834&view=diff
==
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Thu Oct  4 17:54:44 2018
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_si

[PATCH] D52386: [Lexer] Add udefined_behavior_sanitizer feature

2018-10-04 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

> This sounds like something that would be better handled in the build system 
> rather than in source code. In particular, I think you don't actually want to 
> detect "is this translation unit being compiled with ubsan enabled?", you 
> instead want to detect "is the rest of musl libc being compiled with ubsan 
> enabled?" -- you should not compile the stubs themselves with ubsan enabled, 
> because ubsan might insert calls to its runtime at arbitrary places within 
> that translation unit, which means you'll get infinite recursion when one of 
> the ubsan callbacks ends up calling itself.

UBSan doesn't actually instrument these stubs though. We have them initially 
defined to be weakly linked and just call __builtin_trap(), which is be 
replaced when the UBSan runtime eventually gets linked when compiling something 
that uses this libc.

I also imagine it would be convenient for there to be some `__has_feature` to 
detect if any of the UBSan checks are being used.


Repository:
  rL LLVM

https://reviews.llvm.org/D52386



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


[PATCH] D52913: [WebAssembly] abs and sqrt builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343838: [WebAssembly] abs and sqrt builtins (authored by 
tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52913?vs=168402&id=168424#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52913

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-wasm.c


Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -75,4 +75,10 @@
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
+
+BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+
 #undef BUILTIN
Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -276,3 +276,27 @@
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12565,6 +12565,18 @@
 Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
 return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;


Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -75,4 +75,10 @@
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
+
+BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+
 #undef BUILTIN
Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -276,3 +276,27 @@
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12565,6 +12565,18 @@
 Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
 return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+Value *Vec = Emit

r343838 - [WebAssembly] abs and sqrt builtins

2018-10-04 Thread Thomas Lively via cfe-commits
Author: tlively
Date: Thu Oct  4 18:02:54 2018
New Revision: 343838

URL: http://llvm.org/viewvc/llvm-project?rev=343838&view=rev
Log:
[WebAssembly] abs and sqrt builtins

Summary: Depends on D52910.

Reviewers: aheejin, dschuff, craig.topper

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-wasm.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=343838&r1=343837&r2=343838&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Oct  4 18:02:54 
2018
@@ -75,4 +75,10 @@ BUILTIN(__builtin_wasm_all_true_i16x8, "
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
+
+BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+
 #undef BUILTIN

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343838&r1=343837&r2=343838&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 18:02:54 2018
@@ -12565,6 +12565,18 @@ Value *CodeGenFunction::EmitWebAssemblyB
 Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
 return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=343838&r1=343837&r2=343838&view=diff
==
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Thu Oct  4 18:02:54 2018
@@ -276,3 +276,27 @@ int f40(i64x2 x) {
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}


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


[PATCH] D52913: [WebAssembly] abs and sqrt builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343838: [WebAssembly] abs and sqrt builtins (authored by 
tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52913

Files:
  cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-wasm.c


Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -276,3 +276,27 @@
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12565,6 +12565,18 @@
 Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
 return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;
Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -75,4 +75,10 @@
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
+
+BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+
 #undef BUILTIN


Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -276,3 +276,27 @@
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12565,6 +12565,18 @@
 Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
 return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;
Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -75

[PATCH] D52910: [WebAssembly] any_true and all_true builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343837: [WebAssembly] any_true and all_true builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52910

Files:
  cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-wasm.c

Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12536,6 +12536,35 @@
 Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  IntNo = Intrinsic::wasm_anytrue;
+  break;
+case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+case WebAssembly::BI__builtin_wasm_all_true_i64x2:
+  IntNo = Intrinsic::wasm_alltrue;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;
Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -66,4 +66,13 @@
 BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
 BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
 
+BUILTIN(__builtin_wasm_any_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_any_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_any_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_any_true_i64x2, "iV2LLi", "nc")
+BUILTIN(__builtin_wasm_all_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
+
 #undef BUILTIN
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -228,3 +228,51 @@
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
+
+int f33(i8x16 x) {
+  return __builtin_wasm_any_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f34(i16x8 x) {
+  return __builtin_wasm_any_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f35(i32x4 x) {
+  return __builtin_wasm_any_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f36(i64x2 x) {
+  return __builtin_wasm_any_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f37(i8x16 x) {
+  return __builtin_wasm_all_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f38(i16x8 x) {
+  return __builtin_wasm_all_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f39(i32x4 x) {
+  return __builtin_wasm_all_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f40(i64x2 x) {
+  return __builtin_wasm_all_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343836: [WebAssembly] saturating arithmetic builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52858

Files:
  cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-wasm.c

Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -56,4 +56,14 @@
 BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
 BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8s", "nc")
+
+BUILTIN(__builtin_wasm_sub_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
+
 #undef BUILTIN
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -172,3 +172,59 @@
   // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f25(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f26(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f27(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f28(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f29(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f30(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f31(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f32(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12502,6 +12502,40 @@
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_signed;
+  br

[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343835: [WebAssembly] __builtin_wasm_replace_lane_* builtins 
(authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52856?vs=168387&id=168421#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52856

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-wasm.c

Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12474,6 +12474,34 @@
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i16x8:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_replace_lane_f64x2: {
+llvm::APSInt LaneConst;
+if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
+  llvm_unreachable("Constant arg isn't actually constant?");
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
+Value *Val = EmitScalarExpr(E->getArg(2));
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+case WebAssembly::BI__builtin_wasm_replace_lane_i16x8: {
+  llvm::Type *ElemType = ConvertType(E->getType())->getVectorElementType();
+  Value *Trunc = Builder.CreateTrunc(Val, ElemType);
+  return Builder.CreateInsertElement(Vec, Trunc, Lane);
+}
+case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+case WebAssembly::BI__builtin_wasm_replace_lane_f64x2:
+  return Builder.CreateInsertElement(Vec, Val, Lane);
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -49,4 +49,11 @@
 BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
 BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
 
+BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2LLiV2LLiIiLLi", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
+
 #undef BUILTIN
Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -134,3 +134,41 @@
   // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f19(i8x16 v, int x) {
+  return __builtin_wasm_replace_lane_i8x16(v, 13, x);
+  // WEBASSEMBLY: trunc i32 %x to i8
+  // WEBASSEMBLY-NEXT: insertelement <16 x i8> %v, i8 %{{.*}}, i32 13
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f20(i16x8 v, int x) {
+  return __builtin_wasm_replace_lane_i16x8(v, 7, x);
+  // WEBASSEMBLY: trunc i32 %x to i16
+  // WEBASSEMBLY-NEXT: insertelement <8 x i16> %v, i16 %{{.*}}, i32 7
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i32x4 f21(i32x4 v, int x) {
+  return __builtin_wasm_replace_lane_i32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x i32> %v, i32 %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 f22(i64x2 v, long long x) {
+  return __builtin_wasm_replace_lane_i64x2(v, 1, x);
+  // WEBASSEMBLY: insertelement <2 x i64> %v, i64 %x, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f32x4 f23(f32x4 v, float x) {
+  return __builtin_wasm_replace_lane_f32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x float> %v, float %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f64x2 f24(f64x2 v, double x) {
+  return __builtin_wasm_replace_lane_f64x2(v, 1, x);
+  // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52852: [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343834: [WebAssembly] __builtin_wasm_extract_lane_* builtins 
(authored by tlively, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52852

Files:
  cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-wasm.c

Index: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
@@ -39,4 +39,14 @@
 BUILTIN(__builtin_wasm_atomic_wait_i64, "iLLi*LLiLLi", "n")
 BUILTIN(__builtin_wasm_atomic_notify, "Uii*i", "n")
 
+// SIMD builtins
+BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_u_i16x8, "iV8sIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i32x4, "iV4iIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
+BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
+
 #undef BUILTIN
Index: cfe/trunk/test/CodeGen/builtins-wasm.c
===
--- cfe/trunk/test/CodeGen/builtins-wasm.c
+++ cfe/trunk/test/CodeGen/builtins-wasm.c
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_size(16)));
+typedef long long i64x2 __attribute((vector_size(16)));
+typedef unsigned char u8x16 __attribute((vector_size(16)));
+typedef unsigned short u16x8 __attribute((vector_size(16)));
+typedef unsigned int u32x4 __attribute((vector_size(16)));
+typedef unsigned long long u64x2 __attribute((vector_size(16)));
+typedef float f32x4 __attribute((vector_size(16)));
+typedef double f64x2 __attribute((vector_size(16)));
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
@@ -68,3 +82,55 @@
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
+
+int f11(i8x16 v) {
+  return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f12(i8x16 v) {
+  return __builtin_wasm_extract_lane_u_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f13(i16x8 v) {
+  return __builtin_wasm_extract_lane_s_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f14(i16x8 v) {
+  return __builtin_wasm_extract_lane_u_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f15(i32x4 v) {
+  return __builtin_wasm_extract_lane_i32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long f16(i64x2 v) {
+  return __builtin_wasm_extract_lane_i64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float f17(f32x4 v) {
+  return __builtin_wasm_extract_lane_f32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x float> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double f18(f64x2 v) {
+  return __builtin_wasm_extract_lane_f64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -12444,6 +12444,36 @@
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  case WebAssembly::

Re: [libcxx] r342073 - Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955

2018-10-04 Thread Eric Fiselier via cfe-commits
On Thu, Oct 4, 2018 at 11:42 AM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Perhaps libc++ could provide a __version file that contains the headers,
> and use #include <__version> internally? We'd still need a  header
> that just includes <__version> for conformance, but that should be after
> user headers on the include path so shouldn't break things.
>

+1

I was going to suggest this exact fix. (But only in the case of 
and not as a general rule going forward.)




>
> On Thu, 4 Oct 2018, 07:10 Marshall Clow via cfe-commits, <
> cfe-commits@lists.llvm.org> wrote:
>
>> On Wed, Oct 3, 2018 at 3:38 AM Christof Douma 
>> wrote:
>>
>>> Hi.
>>>
>>>
>>>
>>> Yes, including  would try to include the “version” file inside
>>> the users project. The problem is not the existence of the header file, but
>>> the #include directive that is not guarded. To give examples on when this
>>> goes wrong:
>>>
>>>
>>>
>>> A project uses VERSION in their source directory to hold some version
>>> string used in the build system. On platforms like Windows and OS X this
>>> file is indistinguishable from the system include file that many headers
>>> include.
>>>
>>>
>>>
>>> I don’t think this is a strange setup, and while I expect that for C++20
>>> code bases, people need to pick a different name, I think that existing
>>> projects should not be bothered by this. It would be nice if everybody was
>>> using -iquote, or better in my opinion, that -I was behaving like -iquote.
>>> But a fix that we can apply now is to use:
>>>
>>>
>>>
>>>   #if _LIBCPP_STD_VER > 17
>>>
>>> #include 
>>>
>>>   #endif
>>>
>>>
>>>
>>> Would that be acceptable?
>>>
>>
>> Christof -
>>
>> There are people in the community who really want these feature macros.
>> In particular, they *really* want them for C++14 and C++17 (not just
>> c++20)
>>
>> In general, I am against back-porting new features to old language
>> versions (string_view being the one large exception), but this seems like a
>> low-risk thing to do.
>>
>> However, it would make your suggestion unfeasible.
>>
>> -- Marshall
>>
>>
>>
>>
>>>
>>>
>>> Thanks,
>>>
>>> Christof
>>>
>>>
>>>
>>> *From: *Eric Fiselier 
>>> *Date: *Tuesday, 2 October 2018 at 19:52
>>> *To: *Christof Douma 
>>> *Cc: *Marshall Clow , cfe-commits <
>>> cfe-commits@lists.llvm.org>, nd 
>>> *Subject: *Re: [libcxx] r342073 - Implement the infrastructure for
>>> feature-test macros. Very few actual feature test macros, though. Reviewed
>>> as: https://reviews.llvm.org/D51955
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Oct 2, 2018 at 1:33 PM Christof Douma via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>> Hi Marshall.
>>>
>>> I think that this patch breaks backwards compatibility.  Assumes that
>>> the header file "version" is used by C++ projects that use a C++ standard
>>> that did not specify a 'version' header. Many toolchains will put search
>>> paths specified with -I in front of the system search path. The result is
>>> that the application header file is included whenever a standard header
>>> file is included. That is unexpected and can break builds.
>>>
>>> Do you agree this is an issue or do you consider this an issue with the
>>> way toolchains handle include search paths?
>>>
>>>
>>>
>>> If I understand correctly, you have user code which provides a header
>>> called "version", and now when files like  include  they
>>> pick up the user header instead of the STL one?
>>>
>>> Are you specifying custom libc++ include paths when this occurs? Or just
>>> passing "-stdlib=libc++" and letting the compiler do the rest?
>>>
>>>
>>>
>>> In general, I don't consider this a bug. There is no way for libc++ to
>>> make the  file disappear in older dialects, and libc++ headers are
>>> free to include w/e additional headers
>>>
>>> they need.
>>>
>>>
>>> ___
>> 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
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52919: Emit diagnostic note when calling an invalid function declaration.

2018-10-04 Thread James Y Knight via Phabricator via cfe-commits
jyknight created this revision.
jyknight added a reviewer: rsmith.

The comment said it was intentionally not emitting any diagnostic
because the declaration itself was already diagnosed. However,
everywhere else that wants to not emit a diagnostic without an extra
note emits note_invalid_subexpr_in_const_expr instead, which gets
suppressed later.

This was the only place which did not emit a diagnostic note.


https://reviews.llvm.org/D52919

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/enable_if.cpp


Index: clang/test/SemaCXX/enable_if.cpp
===
--- clang/test/SemaCXX/enable_if.cpp
+++ clang/test/SemaCXX/enable_if.cpp
@@ -414,7 +414,8 @@
 
 template  constexpr int callTemplated() { return templated(); }
 
-constexpr int B = callTemplated<0>(); // expected-error{{initialized by a 
constant expression}} expected-error@-2{{no matching function for call to 
'templated'}} expected-note{{in instantiation of function template}} 
expected-note@-9{{candidate disabled}}
+constexpr int B = 10 + // the carat for the error should be pointing to the 
problematic call (on the next line), not here.
+callTemplated<0>(); // expected-error{{initialized by a constant 
expression}} expected-error@-3{{no matching function for call to 'templated'}} 
expected-note{{in instantiation of function template}} 
expected-note@-10{{candidate disabled}}
 static_assert(callTemplated<1>() == 1, "");
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4330,10 +4330,13 @@
   Declaration->isConstexpr())
 return false;
 
-  // Bail out with no diagnostic if the function declaration itself is invalid.
-  // We will have produced a relevant diagnostic while parsing it.
-  if (Declaration->isInvalidDecl())
+  // Bail out if the function declaration itself is invalid.  We will
+  // have produced a relevant diagnostic while parsing it, so just
+  // note the problematic sub-expression.
+  if (Declaration->isInvalidDecl()) {
+Info.FFDiag(CallLoc, diag::note_invalid_subexpr_in_const_expr);
 return false;
+  }
 
   // Can we evaluate this function call?
   if (Definition && Definition->isConstexpr() &&


Index: clang/test/SemaCXX/enable_if.cpp
===
--- clang/test/SemaCXX/enable_if.cpp
+++ clang/test/SemaCXX/enable_if.cpp
@@ -414,7 +414,8 @@
 
 template  constexpr int callTemplated() { return templated(); }
 
-constexpr int B = callTemplated<0>(); // expected-error{{initialized by a constant expression}} expected-error@-2{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-9{{candidate disabled}}
+constexpr int B = 10 + // the carat for the error should be pointing to the problematic call (on the next line), not here.
+callTemplated<0>(); // expected-error{{initialized by a constant expression}} expected-error@-3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-10{{candidate disabled}}
 static_assert(callTemplated<1>() == 1, "");
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4330,10 +4330,13 @@
   Declaration->isConstexpr())
 return false;
 
-  // Bail out with no diagnostic if the function declaration itself is invalid.
-  // We will have produced a relevant diagnostic while parsing it.
-  if (Declaration->isInvalidDecl())
+  // Bail out if the function declaration itself is invalid.  We will
+  // have produced a relevant diagnostic while parsing it, so just
+  // note the problematic sub-expression.
+  if (Declaration->isInvalidDecl()) {
+Info.FFDiag(CallLoc, diag::note_invalid_subexpr_in_const_expr);
 return false;
+  }
 
   // Can we evaluate this function call?
   if (Definition && Definition->isConstexpr() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52918: Emit CK_NoOp casts in C mode, not just C++.

2018-10-04 Thread James Y Knight via Phabricator via cfe-commits
jyknight created this revision.
jyknight added a reviewer: rsmith.

Previously, it had been using CK_BitCast even for casts that only
change const/restrict/volatile. Now it will use CK_Noop where
appropriate.

This is an alternate solution to r336746.


https://reviews.llvm.org/D52918

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5846,7 +5846,9 @@
   // pointers.  Everything else should be possible.
 
   QualType SrcTy = Src.get()->getType();
-  if (Context.hasSameUnqualifiedType(SrcTy, DestTy))
+  // We can use a no-op cast if the types are the same, or only adding/removing
+  // const, volatile, or restricted qualifiers.
+  if (Context.hasCvrSimilarType(SrcTy, DestTy))
 return CK_NoOp;
 
   switch (Type::ScalarTypeKind SrcKind = SrcTy->getScalarTypeKind()) {
@@ -7762,7 +7764,12 @@
 if (isa(RHSType)) {
   LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
   LangAS AddrSpaceR = RHSType->getPointeeType().getAddressSpace();
-  Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
+  if (AddrSpaceL != AddrSpaceR)
+Kind = CK_AddressSpaceConversion;
+  else if (Context.hasCvrSimilarType(RHSType, LHSType))
+Kind = CK_NoOp;
+  else
+Kind = CK_BitCast;
   return checkPointerTypesForAssignment(*this, LHSType, RHSType);
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5861,11 +5861,7 @@
 // permitted in constant expressions in C++11. Bitcasts from cv void* are
 // also static_casts, but we disallow them as a resolution to DR1312.
 if (!E->getType()->isVoidPointerType()) {
-  // If we changed anything other than cvr-qualifiers, we can't use this
-  // value for constant folding. FIXME: Qualification conversions should
-  // always be CK_NoOp, but we get this wrong in C.
-  if (!Info.Ctx.hasCvrSimilarType(E->getType(), 
E->getSubExpr()->getType()))
-Result.Designator.setInvalid();
+  Result.Designator.setInvalid();
   if (SubExpr->getType()->isVoidPointerType())
 CCEDiag(E, diag::note_constexpr_invalid_cast)
   << 3 << SubExpr->getType();


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5846,7 +5846,9 @@
   // pointers.  Everything else should be possible.
 
   QualType SrcTy = Src.get()->getType();
-  if (Context.hasSameUnqualifiedType(SrcTy, DestTy))
+  // We can use a no-op cast if the types are the same, or only adding/removing
+  // const, volatile, or restricted qualifiers.
+  if (Context.hasCvrSimilarType(SrcTy, DestTy))
 return CK_NoOp;
 
   switch (Type::ScalarTypeKind SrcKind = SrcTy->getScalarTypeKind()) {
@@ -7762,7 +7764,12 @@
 if (isa(RHSType)) {
   LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
   LangAS AddrSpaceR = RHSType->getPointeeType().getAddressSpace();
-  Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
+  if (AddrSpaceL != AddrSpaceR)
+Kind = CK_AddressSpaceConversion;
+  else if (Context.hasCvrSimilarType(RHSType, LHSType))
+Kind = CK_NoOp;
+  else
+Kind = CK_BitCast;
   return checkPointerTypesForAssignment(*this, LHSType, RHSType);
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5861,11 +5861,7 @@
 // permitted in constant expressions in C++11. Bitcasts from cv void* are
 // also static_casts, but we disallow them as a resolution to DR1312.
 if (!E->getType()->isVoidPointerType()) {
-  // If we changed anything other than cvr-qualifiers, we can't use this
-  // value for constant folding. FIXME: Qualification conversions should
-  // always be CK_NoOp, but we get this wrong in C.
-  if (!Info.Ctx.hasCvrSimilarType(E->getType(), E->getSubExpr()->getType()))
-Result.Designator.setInvalid();
+  Result.Designator.setInvalid();
   if (SubExpr->getType()->isVoidPointerType())
 CCEDiag(E, diag::note_constexpr_invalid_cast)
   << 3 << SubExpr->getType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52443: Thread safety analysis: Examine constructor arguments

2018-10-04 Thread Aaron Puchert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343831: Thread safety analysis: Examine constructor 
arguments (authored by aaronpuchert, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52443?vs=167856&id=168414#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52443

Files:
  lib/Analysis/ThreadSafety.cpp
  test/SemaCXX/warn-thread-safety-analysis.cpp

Index: lib/Analysis/ThreadSafety.cpp
===
--- lib/Analysis/ThreadSafety.cpp
+++ lib/Analysis/ThreadSafety.cpp
@@ -1538,6 +1538,10 @@
  ProtectedOperationKind POK = POK_VarAccess);
 
   void handleCall(const Expr *Exp, const NamedDecl *D, VarDecl *VD = nullptr);
+  void examineArguments(const FunctionDecl *FD,
+CallExpr::const_arg_iterator ArgBegin,
+CallExpr::const_arg_iterator ArgEnd,
+bool SkipFirstParam = false);
 
 public:
   BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info)
@@ -1938,10 +1942,37 @@
   checkAccess(CE->getSubExpr(), AK_Read);
 }
 
-void BuildLockset::VisitCallExpr(const CallExpr *Exp) {
-  bool ExamineArgs = true;
-  bool OperatorFun = false;
+void BuildLockset::examineArguments(const FunctionDecl *FD,
+CallExpr::const_arg_iterator ArgBegin,
+CallExpr::const_arg_iterator ArgEnd,
+bool SkipFirstParam) {
+  // Currently we can't do anything if we don't know the function declaration.
+  if (!FD)
+return;
+
+  // NO_THREAD_SAFETY_ANALYSIS does double duty here.  Normally it
+  // only turns off checking within the body of a function, but we also
+  // use it to turn off checking in arguments to the function.  This
+  // could result in some false negatives, but the alternative is to
+  // create yet another attribute.
+  if (FD->hasAttr())
+return;
+
+  const ArrayRef Params = FD->parameters();
+  auto Param = Params.begin();
+  if (SkipFirstParam)
+++Param;
+
+  // There can be default arguments, so we stop when one iterator is at end().
+  for (auto Arg = ArgBegin; Param != Params.end() && Arg != ArgEnd;
+   ++Param, ++Arg) {
+QualType Qt = (*Param)->getType();
+if (Qt->isReferenceType())
+  checkAccess(*Arg, AK_Read, POK_PassByRef);
+  }
+}
 
+void BuildLockset::VisitCallExpr(const CallExpr *Exp) {
   if (const auto *CE = dyn_cast(Exp)) {
 const auto *ME = dyn_cast(CE->getCallee());
 // ME can be null when calling a method pointer
@@ -1960,75 +1991,41 @@
   checkAccess(CE->getImplicitObjectArgument(), AK_Read);
   }
 }
-  } else if (const auto *OE = dyn_cast(Exp)) {
-OperatorFun = true;
 
+examineArguments(CE->getDirectCallee(), CE->arg_begin(), CE->arg_end());
+  } else if (const auto *OE = dyn_cast(Exp)) {
 auto OEop = OE->getOperator();
 switch (OEop) {
   case OO_Equal: {
-ExamineArgs = false;
 const Expr *Target = OE->getArg(0);
 const Expr *Source = OE->getArg(1);
 checkAccess(Target, AK_Written);
 checkAccess(Source, AK_Read);
 break;
   }
   case OO_Star:
   case OO_Arrow:
-  case OO_Subscript: {
-const Expr *Obj = OE->getArg(0);
-checkAccess(Obj, AK_Read);
+  case OO_Subscript:
 if (!(OEop == OO_Star && OE->getNumArgs() > 1)) {
   // Grrr.  operator* can be multiplication...
-  checkPtAccess(Obj, AK_Read);
+  checkPtAccess(OE->getArg(0), AK_Read);
 }
-break;
-  }
+LLVM_FALLTHROUGH;
   default: {
 // TODO: get rid of this, and rely on pass-by-ref instead.
 const Expr *Obj = OE->getArg(0);
 checkAccess(Obj, AK_Read);
+// Check the remaining arguments. For method operators, the first
+// argument is the implicit self argument, and doesn't appear in the
+// FunctionDecl, but for non-methods it does.
+const FunctionDecl *FD = OE->getDirectCallee();
+examineArguments(FD, std::next(OE->arg_begin()), OE->arg_end(),
+ /*SkipFirstParam*/ !isa(FD));
 break;
   }
 }
-  }
-
-  if (ExamineArgs) {
-if (const FunctionDecl *FD = Exp->getDirectCallee()) {
-  // NO_THREAD_SAFETY_ANALYSIS does double duty here.  Normally it
-  // only turns off checking within the body of a function, but we also
-  // use it to turn off checking in arguments to the function.  This
-  // could result in some false negatives, but the alternative is to
-  // create yet another attribute.
-  if (!FD->hasAttr()) {
-unsigned Fn = FD->getNumParams();
-unsigned Cn = Exp->getNumArgs();
-unsigned Skip = 0;
-
-unsigned i = 0;
-if (OperatorFun) {
-  if (isa(FD)) {
-// First arg in operator call is implicit self argument,
-

r343831 - Thread safety analysis: Examine constructor arguments

2018-10-04 Thread Aaron Puchert via cfe-commits
Author: aaronpuchert
Date: Thu Oct  4 16:51:14 2018
New Revision: 343831

URL: http://llvm.org/viewvc/llvm-project?rev=343831&view=rev
Log:
Thread safety analysis: Examine constructor arguments

Summary:
Instead of only examining call arguments, we also examine constructor
arguments applying the same rules.

That was an opportunity for refactoring the examination procedure to
work with iterators instead of integer indices. For the case of
CallExprs no functional change is intended.

Reviewers: aaron.ballman, delesley

Reviewed By: delesley

Subscribers: JonasToth, cfe-commits

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

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=343831&r1=343830&r2=343831&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Thu Oct  4 16:51:14 2018
@@ -1538,6 +1538,10 @@ class BuildLockset : public ConstStmtVis
  ProtectedOperationKind POK = POK_VarAccess);
 
   void handleCall(const Expr *Exp, const NamedDecl *D, VarDecl *VD = nullptr);
+  void examineArguments(const FunctionDecl *FD,
+CallExpr::const_arg_iterator ArgBegin,
+CallExpr::const_arg_iterator ArgEnd,
+bool SkipFirstParam = false);
 
 public:
   BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info)
@@ -1938,10 +1942,37 @@ void BuildLockset::VisitCastExpr(const C
   checkAccess(CE->getSubExpr(), AK_Read);
 }
 
-void BuildLockset::VisitCallExpr(const CallExpr *Exp) {
-  bool ExamineArgs = true;
-  bool OperatorFun = false;
+void BuildLockset::examineArguments(const FunctionDecl *FD,
+CallExpr::const_arg_iterator ArgBegin,
+CallExpr::const_arg_iterator ArgEnd,
+bool SkipFirstParam) {
+  // Currently we can't do anything if we don't know the function declaration.
+  if (!FD)
+return;
+
+  // NO_THREAD_SAFETY_ANALYSIS does double duty here.  Normally it
+  // only turns off checking within the body of a function, but we also
+  // use it to turn off checking in arguments to the function.  This
+  // could result in some false negatives, but the alternative is to
+  // create yet another attribute.
+  if (FD->hasAttr())
+return;
+
+  const ArrayRef Params = FD->parameters();
+  auto Param = Params.begin();
+  if (SkipFirstParam)
+++Param;
+
+  // There can be default arguments, so we stop when one iterator is at end().
+  for (auto Arg = ArgBegin; Param != Params.end() && Arg != ArgEnd;
+   ++Param, ++Arg) {
+QualType Qt = (*Param)->getType();
+if (Qt->isReferenceType())
+  checkAccess(*Arg, AK_Read, POK_PassByRef);
+  }
+}
 
+void BuildLockset::VisitCallExpr(const CallExpr *Exp) {
   if (const auto *CE = dyn_cast(Exp)) {
 const auto *ME = dyn_cast(CE->getCallee());
 // ME can be null when calling a method pointer
@@ -1960,13 +1991,12 @@ void BuildLockset::VisitCallExpr(const C
   checkAccess(CE->getImplicitObjectArgument(), AK_Read);
   }
 }
-  } else if (const auto *OE = dyn_cast(Exp)) {
-OperatorFun = true;
 
+examineArguments(CE->getDirectCallee(), CE->arg_begin(), CE->arg_end());
+  } else if (const auto *OE = dyn_cast(Exp)) {
 auto OEop = OE->getOperator();
 switch (OEop) {
   case OO_Equal: {
-ExamineArgs = false;
 const Expr *Target = OE->getArg(0);
 const Expr *Source = OE->getArg(1);
 checkAccess(Target, AK_Written);
@@ -1975,60 +2005,27 @@ void BuildLockset::VisitCallExpr(const C
   }
   case OO_Star:
   case OO_Arrow:
-  case OO_Subscript: {
-const Expr *Obj = OE->getArg(0);
-checkAccess(Obj, AK_Read);
+  case OO_Subscript:
 if (!(OEop == OO_Star && OE->getNumArgs() > 1)) {
   // Grrr.  operator* can be multiplication...
-  checkPtAccess(Obj, AK_Read);
+  checkPtAccess(OE->getArg(0), AK_Read);
 }
-break;
-  }
+LLVM_FALLTHROUGH;
   default: {
 // TODO: get rid of this, and rely on pass-by-ref instead.
 const Expr *Obj = OE->getArg(0);
 checkAccess(Obj, AK_Read);
+// Check the remaining arguments. For method operators, the first
+// argument is the implicit self argument, and doesn't appear in the
+// FunctionDecl, but for non-methods it does.
+const FunctionDecl *FD = OE->getDirectCallee();
+examineArguments(FD, std::next(OE->arg_begin()), OE->arg_end(),
+ /*SkipFirstParam*/ !isa(FD));
 break;
   }
 }
-  }
-
-  if (ExamineArgs) {
-if (const FunctionDecl *FD = Exp->ge

[PATCH] D52807: [COFF, ARM64] Add _InterlockedCompareExchangePointer_nf intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 168403.

https://reviews.llvm.org/D52807

Files:
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/ms-intrinsics.c


Index: test/CodeGen/ms-intrinsics.c
===
--- test/CodeGen/ms-intrinsics.c
+++ test/CodeGen/ms-intrinsics.c
@@ -235,6 +235,21 @@
 // CHECK:   ret i8* %[[RESULT:[0-9]+]]
 // CHECK: }
 
+void *test_InterlockedCompareExchangePointer_nf(void * volatile *Destination,
+ void *Exchange, void *Comparand) {
+  return _InterlockedCompareExchangePointer_nf(Destination, Exchange, 
Comparand);
+}
+
+// CHECK: define{{.*}}i8* @test_InterlockedCompareExchangePointer_nf(i8** 
{{[a-z_ ]*}}%Destination, i8* {{[a-z_ ]*}}%Exchange, i8* {{[a-z_ 
]*}}%Comparand){{.*}}{
+// CHECK:   %[[DEST:[0-9]+]] = bitcast i8** %Destination to [[iPTR]]*
+// CHECK:   %[[EXCHANGE:[0-9]+]] = ptrtoint i8* %Exchange to [[iPTR]]
+// CHECK:   %[[COMPARAND:[0-9]+]] = ptrtoint i8* %Comparand to [[iPTR]]
+// CHECK:   %[[XCHG:[0-9]+]] = cmpxchg volatile [[iPTR]]* %[[DEST:[0-9]+]], 
[[iPTR]] %[[COMPARAND:[0-9]+]], [[iPTR]] %[[EXCHANGE:[0-9]+]] monotonic 
monotonic
+// CHECK:   %[[EXTRACT:[0-9]+]] = extractvalue { [[iPTR]], i1 } %[[XCHG]], 0
+// CHECK:   %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXTRACT]] to i8*
+// CHECK:   ret i8* %[[RESULT:[0-9]+]]
+// CHECK: }
+
 char test_InterlockedExchange8(char volatile *value, char mask) {
   return _InterlockedExchange8(value, mask);
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -2999,7 +2999,8 @@
   case Builtin::BI_InterlockedExchangePointer:
 return RValue::get(
 EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchange, E));
-  case Builtin::BI_InterlockedCompareExchangePointer: {
+  case Builtin::BI_InterlockedCompareExchangePointer:
+  case Builtin::BI_InterlockedCompareExchangePointer_nf: {
 llvm::Type *RTy;
 llvm::IntegerType *IntType =
   IntegerType::get(getLLVMContext(),
@@ -3016,10 +3017,12 @@
 llvm::Value *Comparand =
   Builder.CreatePtrToInt(EmitScalarExpr(E->getArg(2)), IntType);
 
-auto Result =
-Builder.CreateAtomicCmpXchg(Destination, Comparand, Exchange,
-AtomicOrdering::SequentiallyConsistent,
-AtomicOrdering::SequentiallyConsistent);
+auto Ordering =
+  BuiltinID == Builtin::BI_InterlockedCompareExchangePointer_nf ?
+  AtomicOrdering::Monotonic : AtomicOrdering::SequentiallyConsistent;
+
+auto Result = Builder.CreateAtomicCmpXchg(Destination, Comparand, Exchange,
+  Ordering, Ordering);
 Result->setVolatile(true);
 
 return 
RValue::get(Builder.CreateIntToPtr(Builder.CreateExtractValue(Result,
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -786,6 +786,7 @@
 LANGBUILTIN(_InterlockedCompareExchange,"NiNiD*NiNi", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchange64,  "LLiLLiD*LLiLLi", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchangePointer, "v*v*D*v*v*", "n", 
ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedCompareExchangePointer_nf, "v*v*D*v*v*", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedDecrement16,"ssD*", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedDecrement,  "NiNiD*",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchange,   "NiNiD*Ni", "n", 
ALL_MS_LANGUAGES)


Index: test/CodeGen/ms-intrinsics.c
===
--- test/CodeGen/ms-intrinsics.c
+++ test/CodeGen/ms-intrinsics.c
@@ -235,6 +235,21 @@
 // CHECK:   ret i8* %[[RESULT:[0-9]+]]
 // CHECK: }
 
+void *test_InterlockedCompareExchangePointer_nf(void * volatile *Destination,
+ void *Exchange, void *Comparand) {
+  return _InterlockedCompareExchangePointer_nf(Destination, Exchange, Comparand);
+}
+
+// CHECK: define{{.*}}i8* @test_InterlockedCompareExchangePointer_nf(i8** {{[a-z_ ]*}}%Destination, i8* {{[a-z_ ]*}}%Exchange, i8* {{[a-z_ ]*}}%Comparand){{.*}}{
+// CHECK:   %[[DEST:[0-9]+]] = bitcast i8** %Destination to [[iPTR]]*
+// CHECK:   %[[EXCHANGE:[0-9]+]] = ptrtoint i8* %Exchange to [[iPTR]]
+// CHECK:   %[[COMPARAND:[0-9]+]] = ptrtoint i8* %Comparand to [[iPTR]]
+// CHECK:   %[[XCHG:[0-9]+]] = cmpxchg volatile [[iPTR]]* %[[DEST:[0-9]+]], [[iPTR]] %[[COMPARAND:[0-9]+]], [[iPTR]] %[[EXCHANGE:[0-9]+]] monotonic monotonic
+// CHECK:   %[[EXTRACT:[0-9]+]] = extractvalue { [[iPTR]], i1 } %[[XCHG]], 0
+// CHECK:   %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXTRACT]] to i8*
+// CHECK:   ret i8* %[[RESULT:[0-9]+]]
+// CHECK: }
+
 char test_InterlockedEx

[PATCH] D52807: [COFF, ARM64] Add _InterlockedCompareExchangePointer_nf intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

In https://reviews.llvm.org/D52807#1255835, @efriedma wrote:

> How are you testing?
>
> You might see different behavior at -O0.


Yes, I was testing at -O0. At -O2 I can see monotonic ordering affect the 
choice of LD/ST insts used.


https://reviews.llvm.org/D52807



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


[PATCH] D52578: Thread safety analysis: Allow scoped releasing of capabilities

2018-10-04 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: lib/Analysis/ThreadSafety.cpp:893
 private:
-  SmallVector UnderlyingMutexes;
+  enum UnderlyingCapabilityKind {
+UCK_Acquired,  ///< Any kind of acquired capability.

delesley wrote:
> aaronpuchert wrote:
> > delesley wrote:
> > > IMHO, it would make more sense to break this into two properties (or 
> > > bits): acquired/released and shared/exclusive. 
> > We don't use the information (shared/exclusive) for acquired locks, but we 
> > need two bits anyway, so why not.
> The normal unlock doesn't distinguish between shared/exclusive, but there is 
> a release_shared_capability which does...
Right, but see [bug 33504](https://bugs.llvm.org/show_bug.cgi?id=33504): 
currently `release_shared_capability` does not work with scoped capabilities. 
If we allow it, we would have to discuss when it is allowed. A scoped 
capability can lock multiple locks, some of them shared, some of them exclusive.

My assumption, as I wrote in the bug: scoped capabilities are always exclusive, 
hence can only be unlocked exclusively, but automatically release underlying 
mutexes in the right mode.



Comment at: lib/Analysis/ThreadSafety.cpp:951
+}
   } else {
+// We're removing the underlying mutex. Warn on double unlocking.

delesley wrote:
> aaronpuchert wrote:
> > delesley wrote:
> > > I find this very confusing.  A lock here unlocks the underlying mutex, 
> > > and vice versa.  At the very least, some methods need to be renamed, or 
> > > maybe we can have separate classes for ScopedLockable and 
> > > ScopedUnlockable. 
> > I agree that it's confusing, but it follows what I think was the idea 
> > behind scoped capabilities: that they are also capabilities that can be 
> > acquired/released. Now since the scoped capability releases a mutex on 
> > construction (i.e. when it is acquired), it has to acquire the mutex when 
> > released. So the way it handles the released mutexes mirrors what happens 
> > on the scoped capability itself.
> > 
> > It's definitely not very intuitive, but I feel it's the most consistent 
> > variant with what we have already.
> > 
> > The nice thing about this is that it works pretty well with the existing 
> > semantics and allows constructs such as `MutexLockUnlock` (see the tests) 
> > that unlocks one mutex and locks another. Not sure if anyone needs this, 
> > but why not?
> A scoped_lockable object is not a capability, it is an object that manages 
> capabilities.  IMHO, conflating those two concepts is a bad idea, and recipe 
> for confusion.  You would not, for example, use a scoped_lockable object in a 
> guarded_by attribute.  
> 
> Unfortunately, the existing code tends to conflate "capabilities" and 
> "facts", which is my fault.  A scoped_lockable object is a valid fact -- the 
> fact records whether the object is in scope -- it's just not a valid 
> capability. 
> 
> Simply renaming the methods from handleLock/Unlock to  addFact/removeFact 
> would be a nice first step in making the code clearer, and would distinguish 
> between facts that refer to capabilities, and facts that refer to scoped 
> objects.  
> 
> 
> 
> 
Makes sense to me. I'll see if I can refactor some of the code to clarify this.

I think that we should also separate between unlocking the underlying mutexes 
and destructing the scoped_lockable, which is currently handled via the extra 
parameter `FullyRemove` of `handleUnlock`.



Comment at: lib/Analysis/ThreadSafety.cpp:992
+FSet.removeLock(FactMan, UnderCp);
+FSet.addLock(FactMan, std::move(UnderEntry));
+  }

delesley wrote:
> aaronpuchert wrote:
> > delesley wrote:
> > > Shouldn't this be outside of the else?
> > If we don't find `UnderCp` anymore, the negation should be there already. 
> > But I can also keep it outside if you like.
> That's not necessarily true.  Not knowing whether a mutex is locked is 
> different from knowing that it is unlocked. 
> 
> You're probably right in this case, because capabilities that are managed by 
> scoped objects obey a more restricted set of rules.  But then, you're also 
> extending the ways in which scoped objects can be used.  :-)
> 
Emphasis is on "anymore". We know we held `UnderCp` once (on construction) and 
it has been released since then. Since we have to add the negative capability 
whenever a lock is removed, it must already be there.

If we introduce support for deferred locking (like `std::defer_lock_t`) we 
would have to make sure we add the negative capability right at the beginning.


Repository:
  rC Clang

https://reviews.llvm.org/D52578



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


[PATCH] D52913: [WebAssembly] abs and sqrt builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff, craig.topper.
Herald added subscribers: cfe-commits, kristina, sunfish, jgravelle-google, 
sbc100.

Depends on https://reviews.llvm.org/D52910.


Repository:
  rC Clang

https://reviews.llvm.org/D52913

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-wasm.c


Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -276,3 +276,27 @@
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12548,6 +12548,18 @@
 Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
 return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -75,4 +75,10 @@
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
+
+BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+
 #undef BUILTIN


Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -276,3 +276,27 @@
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12548,6 +12548,18 @@
 Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
 return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -75,4 +75,10 @@
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64

[PATCH] D52443: Thread safety analysis: Examine constructor arguments

2018-10-04 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley accepted this revision.
delesley added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Analysis/ThreadSafety.cpp:2046
   const CXXConstructorDecl *D = Exp->getConstructor();
   if (D && D->isCopyConstructor()) {
 const Expr* Source = Exp->getArg(0);

aaronpuchert wrote:
> delesley wrote:
> > As a side note, we should probably special-case the move constructor too, 
> > with AK_Written.  That should be in a separate patch, though, and needs to 
> > be sequestered under -Wthread-safety-beta, which is complicated.   
> I think your arguments from D52395 apply here as well: the move constructor 
> does not necessarily write. Many simple types are trivially move 
> constructible, and then the move constructor is effectively the same as the 
> copy constructor.
Good point.


Repository:
  rC Clang

https://reviews.llvm.org/D52443



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 168395.
void marked an inline comment as done.

Repository:
  rC Clang

https://reviews.llvm.org/D52854

Files:
  include/clang/AST/Expr.h
  include/clang/Sema/Sema.h
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  test/Analysis/builtin-functions.cpp
  test/Sema/builtins.c

Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -122,6 +122,14 @@
  __builtin_constant_p(1, 2); // expected-error {{too many arguments}}
 }
 
+// __builtin_constant_p cannot resolve non-constants such as a file scoped array.
+int expr;
+char y[__builtin_constant_p(expr) ? -1 : 1]; // no warning, the builtin is false.
+
+// no warning, the builtin is false.
+struct foo { int a; };
+struct foo x = (struct foo) { __builtin_constant_p(42) ? 37 : 927 };
+
 const int test17_n = 0;
 const char test17_c[] = {1, 2, 3, 0};
 const char test17_d[] = {1, 2, 3, 4};
@@ -168,14 +176,17 @@
   // a builtin.
   ASSERT(OPT("abc"));
   ASSERT(!OPT("abcd"));
+
   // In these cases, the strlen is non-constant, but the __builtin_constant_p
-  // is 0: the array size is not an ICE but is foldable.
-  ASSERT(!OPT(test17_c));// expected-warning {{folded}}
+  // is 0: the array size is not an ICE.
+  ASSERT(!OPT(test17_c));// no warning expected
+  ASSERT(!OPT((char*)test17_c)); // no warning expected
+  ASSERT(!OPT(test17_d));// no warning expected
+  ASSERT(!OPT((char*)test17_d)); // no warning expected
+
+  // These are foldable.
   ASSERT(!OPT(&test17_c[0]));// expected-warning {{folded}}
-  ASSERT(!OPT((char*)test17_c)); // expected-warning {{folded}}
-  ASSERT(!OPT(test17_d));// expected-warning {{folded}}
   ASSERT(!OPT(&test17_d[0]));// expected-warning {{folded}}
-  ASSERT(!OPT((char*)test17_d)); // expected-warning {{folded}}
 
 #undef OPT
 #undef T
@@ -287,3 +298,18 @@
   memcpy(buf, src, 11); // expected-warning{{'memcpy' will always overflow; destination buffer has size 10, but size argument is 11}}
   my_memcpy(buf, src, 11); // expected-warning{{'__builtin___memcpy_chk' will always overflow; destination buffer has size 10, but size argument is 11}}
 }
+
+size_t test24(int a) {
+  char x[__builtin_constant_p(a) ? -1 : 1]; // no warning expected
+  return strlen(x);
+}
+
+__attribute__((always_inline))
+size_t test25(int a) {
+  char x[__builtin_constant_p(a) ? 1 : -1]; // no warning expected
+  return strlen(x);
+}
+
+size_t test26() {
+  return test25(2);
+}
Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -70,14 +70,14 @@
   const int j = 2;
   constexpr int k = 3;
   clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning {{FALSE}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning {{TRUE}}
 }
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4435,6 +4435,11 @@
 checkNullabilityConsistency(S, SimplePointerKind::Array, DeclType.Loc);
   }
 
+  if (ArraySize && !D.isExpressionContext())
+// Mark all __builtin_constant_p() calls in an array size expression as
+// needing to be evaluated early.
+S.MaybeMarkBuiltinConstantPCannotDelayEvaluation(ArraySize);
+
   T = S.BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals,
SourceRange(DeclType.Loc, DeclType.EndLoc), Name);
   break;
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -5767,9 +5767,10 @@
   ? VK_RValue
   : VK_LValue;
 
-  return MaybeBindToTemporary(
-  new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literal

r343824 - [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Mandeep Singh Grang via cfe-commits
Author: mgrang
Date: Thu Oct  4 15:32:42 2018
New Revision: 343824

URL: http://llvm.org/viewvc/llvm-project?rev=343824&view=rev
Log:
[COFF, ARM64] Add __getReg intrinsic

Reviewers: rnk, mstorsjo, compnerd, TomTan, haripul, javed.absar, efriedma

Reviewed By: efriedma

Subscribers: peter.smith, efriedma, kristof.beyls, chrib, cfe-commits

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

Added:
cfe/trunk/test/Sema/builtins-microsoft-arm64.c
Modified:
cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAArch64.def?rev=343824&r1=343823&r2=343824&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def Thu Oct  4 15:32:42 2018
@@ -104,6 +104,7 @@ TARGET_HEADER_BUILTIN(_InterlockedOr64,
 TARGET_HEADER_BUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "nh", 
"intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__getReg, "ULLii", "nh", "intrin.h", ALL_MS_LANGUAGES, 
"")
 
 #undef BUILTIN
 #undef LANGBUILTIN

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343824&r1=343823&r2=343824&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct  4 15:32:42 2018
@@ -6576,6 +6576,23 @@ Value *CodeGenFunction::EmitAArch64Built
 return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr");
   }
 
+  if (BuiltinID == AArch64::BI__getReg) {
+APSInt Value;
+if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
+  llvm_unreachable("Sema will ensure that the parameter is constant");
+
+LLVMContext &Context = CGM.getLLVMContext();
+std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
+
+llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
+llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+
+llvm::Value *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+return Builder.CreateCall(F, Metadata);
+  }
+
   if (BuiltinID == AArch64::BI__builtin_arm_clrex) {
 Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex);
 return Builder.CreateCall(F);

Modified: cfe/trunk/lib/Headers/intrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/intrin.h?rev=343824&r1=343823&r2=343824&view=diff
==
--- cfe/trunk/lib/Headers/intrin.h (original)
+++ cfe/trunk/lib/Headers/intrin.h Thu Oct  4 15:32:42 2018
@@ -865,6 +865,13 @@ __nop(void) {
 #endif
 
 
/**\
+|* MS AArch64 specific
+\**/
+#if defined(__aarch64__)
+unsigned __int64 __getReg(int);
+#endif
+
+/**\
 |* Privileged intrinsics
 
\**/
 #if defined(__i386__) || defined(__x86_64__)

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=343824&r1=343823&r2=343824&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Oct  4 15:32:42 2018
@@ -1749,6 +1749,9 @@ bool Sema::CheckAArch64BuiltinFunctionCa
   BuiltinID == AArch64::BI__builtin_arm_wsrp)
 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
 
+  if (BuiltinID == AArch64::BI__getReg)
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
+
   if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
 return true;
 

Modified: cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c?rev=343824&r1=343823&r2=343824&view=diff
==
--- cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c (original)
+++ cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c Thu Oct  4 15:32:42 2018
@@ -66,3 +66,15 @@ void check_ReadWriteBarrier() {
 
 // CHECK-MSVC: fence syncscope("singlethread")
 // CHECK-LINUX: error: implicit declaration of functio

[PATCH] D52838: [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343824: [COFF, ARM64] Add __getReg intrinsic (authored by 
mgrang, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D52838

Files:
  include/clang/Basic/BuiltinsAArch64.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/intrin.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/arm64-microsoft-intrinsics.c
  test/Sema/builtins-microsoft-arm64.c

Index: include/clang/Basic/BuiltinsAArch64.def
===
--- include/clang/Basic/BuiltinsAArch64.def
+++ include/clang/Basic/BuiltinsAArch64.def
@@ -104,6 +104,7 @@
 TARGET_HEADER_BUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__getReg, "ULLii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 #undef BUILTIN
 #undef LANGBUILTIN
Index: test/CodeGen/arm64-microsoft-intrinsics.c
===
--- test/CodeGen/arm64-microsoft-intrinsics.c
+++ test/CodeGen/arm64-microsoft-intrinsics.c
@@ -66,3 +66,15 @@
 
 // CHECK-MSVC: fence syncscope("singlethread")
 // CHECK-LINUX: error: implicit declaration of function '_ReadWriteBarrier'
+
+unsigned __int64 check__getReg() {
+  unsigned volatile __int64 reg;
+  reg = __getReg(18);
+  reg = __getReg(31);
+  return reg;
+}
+
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !2)
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !3)
+// CHECK-MSVC: !2 = !{!"x18"}
+// CHECK-MSVC: !3 = !{!"sp"}
Index: test/Sema/builtins-microsoft-arm64.c
===
--- test/Sema/builtins-microsoft-arm64.c
+++ test/Sema/builtins-microsoft-arm64.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple arm64-windows -fsyntax-only -verify \
+// RUN: -fms-compatibility -ffreestanding -fms-compatibility-version=17.00 %s
+
+#include 
+
+void check__getReg() {
+  __getReg(-1); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+  __getReg(32); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1749,6 +1749,9 @@
   BuiltinID == AArch64::BI__builtin_arm_wsrp)
 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
 
+  if (BuiltinID == AArch64::BI__getReg)
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
+
   if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
 return true;
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -865,6 +865,13 @@
 #endif
 
 /**\
+|* MS AArch64 specific
+\**/
+#if defined(__aarch64__)
+unsigned __int64 __getReg(int);
+#endif
+
+/**\
 |* Privileged intrinsics
 \**/
 #if defined(__i386__) || defined(__x86_64__)
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -6576,6 +6576,23 @@
 return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr");
   }
 
+  if (BuiltinID == AArch64::BI__getReg) {
+APSInt Value;
+if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
+  llvm_unreachable("Sema will ensure that the parameter is constant");
+
+LLVMContext &Context = CGM.getLLVMContext();
+std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
+
+llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
+llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+
+llvm::Value *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+return Builder.CreateCall(F, Metadata);
+  }
+
   if (BuiltinID == AArch64::BI__builtin_arm_clrex) {
 Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex);
 return Builder.CreateCall(F);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void marked 9 inline comments as done.
void added a comment.

In https://reviews.llvm.org/D52854#1255755, @rsmith wrote:

> Essentially, you would add a `ConstExpr` node (or similar), teach 
> `IgnoreImplicit` and friends to step over it


I've been trying to do this to no avail. Here's the code I was working with:

  
//===--===//
  // Wrapper Expressions.
  
//===--===//
  
  // ConstExpr is a wrapper class indicating that the expression must be 
constant.
  // This is useful for something like __builtin_constant_p(), which in some
  // contexts is required to be constant before generating LLVM IR.
  template 
  class ConstExpr : public Expr {
T *E;
  
   public:
ConstExpr(Expr *E) : E(E) {}
  
T *getSubExpr() { return E; }
const T *getSubExpr() const { return E; }
  
static bool classof(const Stmt *T) {
  return T->getStmtClass() == ConstExprClass;
}
  };

I did it this way because otherwise I would have to forward all calls to 
individual expression, which is ugly and made me want to cry. The issue is 
getting the `ConstExprClass` variable. Those variables are automatically 
generated via macro magick, but those macros aren't set up to handle templates.

Do I need to mangle the macros to support templates, or is there another way to 
achieve this?




Comment at: lib/AST/ExprConstant.cpp:8162
+  return Success(true, E);
+if (isa(Arg->IgnoreParenCasts()) &&
+E->getCanDelayEvaluation())

rsmith wrote:
> rsmith wrote:
> > Your `canDelayEvaluation` check does not appear to cover several of the 
> > cases we'd need to check for here. Eg:
> > 
> > ```
> > void f(int n) {
> >   enum E { a = __builtin_constant_p(n) }; // ok, a == 0, not an error 
> > because a's value is non-constant
> > ```
> > 
> > 
> Hmm, OK. Per https://bugs.llvm.org/show_bug.cgi?id=4898#c38, the correct 
> check would be whether the reason we found the expression to be non-constant 
> was that it tried to read the value of a local variable or function 
> parameter. Eg, for:
> 
> ```
> void f(int x, int y) {
>   bool k = __builtin_constant_p(3 + x < 5 * y);
> ```
> 
> ... we should defer the `__builtin_constant_p` until after optimization. (And 
> we should never do this if the expression has side-effects.) But given that 
> your goal is merely to improve the status quo, not to exactly match GCC, this 
> may be sufficient.
> 
> You should at least check that the variable is non-volatile, though. (More 
> generally, check that `Arg` doesn't have side-effects.)
I had the side effect check in there before. I removed it for some reason. I'll 
re-add it.



Comment at: lib/Sema/SemaExpr.cpp:5694
 
+  MarkBuiltinConstantPCannotDelayEvaluation(InitExpr);
   return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, InitExpr);

rsmith wrote:
> Why are you marking this? This isn't (necessarily) a context where a constant 
> expression is required. (In C, the overall initializer for a global would be, 
> but a local-scope compound literal would not.)
> 
> Also, this should be in the `Build` function, not in the `ActOn` function.
The name may be misleading. It's looking to see if it should mark whether it 
can delay evaluation or not. I'll change its name to be clearer.



Comment at: lib/Sema/SemaExpr.cpp:5799
   E->setType(Context.VoidTy); // FIXME: just a place holder for now.
+  MarkBuiltinConstantPCannotDelayEvaluation(E);
   return E;

rsmith wrote:
> Likewise here, I don't see the justification for this.
I can't find an equivalent "Build..." for `InitList` expressions. Could you 
point me to it?


https://reviews.llvm.org/D52854



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


[PATCH] D52910: [WebAssembly] any_true and all_true builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff, craig.topper.
Herald added subscribers: cfe-commits, kristina, sunfish, jgravelle-google, 
sbc100.

Depends on https://reviews.llvm.org/D52858.


Repository:
  rC Clang

https://reviews.llvm.org/D52910

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -228,3 +228,51 @@
   // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
   // WEBASSEMBLY-NEXT: ret
 }
+
+int f33(i8x16 x) {
+  return __builtin_wasm_any_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f34(i16x8 x) {
+  return __builtin_wasm_any_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f35(i32x4 x) {
+  return __builtin_wasm_any_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f36(i64x2 x) {
+  return __builtin_wasm_any_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f37(i8x16 x) {
+  return __builtin_wasm_all_true_i8x16(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v16i8(<16 x i8> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f38(i16x8 x) {
+  return __builtin_wasm_all_true_i16x8(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v8i16(<8 x i16> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f39(i32x4 x) {
+  return __builtin_wasm_all_true_i32x4(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v4i32(<4 x i32> %x)
+  // WEBASSEMBLY: ret
+}
+
+int f40(i64x2 x) {
+  return __builtin_wasm_all_true_i64x2(x);
+  // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
+  // WEBASSEMBLY: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12519,6 +12519,35 @@
 Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+  case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+  case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+  case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_any_true_i8x16:
+case WebAssembly::BI__builtin_wasm_any_true_i16x8:
+case WebAssembly::BI__builtin_wasm_any_true_i32x4:
+case WebAssembly::BI__builtin_wasm_any_true_i64x2:
+  IntNo = Intrinsic::wasm_anytrue;
+  break;
+case WebAssembly::BI__builtin_wasm_all_true_i8x16:
+case WebAssembly::BI__builtin_wasm_all_true_i16x8:
+case WebAssembly::BI__builtin_wasm_all_true_i32x4:
+case WebAssembly::BI__builtin_wasm_all_true_i64x2:
+  IntNo = Intrinsic::wasm_alltrue;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
+return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -66,4 +66,13 @@
 BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
 BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
 
+BUILTIN(__builtin_wasm_any_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_any_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_any_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_any_true_i64x2, "iV2LLi", "nc")
+BUILTIN(__builtin_wasm_all_true_i8x16, "iV16c", "nc")
+BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc")
+BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
+BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
+
 #undef BUILTIN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52807: [COFF, ARM64] Add _InterlockedCompareExchangePointer_nf intrinsic

2018-10-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:3003
+  case Builtin::BI_InterlockedCompareExchangePointer:
+  case Builtin::BI_InterlockedCompareExchangePointer_nf: {
 llvm::Type *RTy;

efriedma wrote:
> rnk wrote:
> > mgrang wrote:
> > > rnk wrote:
> > > > Is the no fence version really equivalent to this seq_cst version here?
> > > I don't see InterlockedCompareExchangePointer creating a fence but it 
> > > should. (since it is the fence version). So maybe that needs to be fixed 
> > > (and possibly other fence functions).
> > > 
> > > InterlockedCompareExchangePointer_nf should not create a fence so the 
> > > current implementation seems correct.
> > Hm, if we're supposed to have fences, we're probably missing them 
> > everywhere. I thought the atomicrmw orderings were enough, but that shows 
> > what I know about the C++ memory model. =p
> > 
> > We don't generate a fence for this intrinsic when MSVC does:
> > ```
> > unsigned char test_arm(long *base, long idx) {
> >   return _interlockedbittestandreset_acq(base, idx);
> > }
> > ```
> > 
> > @efriedma, is MSVC over-emitting extra fences, or are we under-emitting? If 
> > this is their "bug", should we be bug-for-bug compatible with it so we get 
> > the same observable memory states?
> "create a fence" is a little confusing because the AArch64 ldaxr/stlxr have 
> builtin fences... but presumably the "nf" version should use ldxr/stxr 
> instead.  At the IR level, that corresponds to "monotonic".
In terms of emitting fences, maybe we are actually missing a fence.

An ldaxr+stlxr pair isn't a complete fence, at least in theory; it stops loads 
from being hosted past it, and stores from being sunk past it, but stores can 
be hoisted and loads can be sunk.  That said, a stronger fence isn't necessary 
to model C++11 atomics; C++11 only requires sequential consistency with other 
sequentially consistent operations, plus an acquire/release barrier.  And a 
program that isn't using C++11 relaxed atomics can't depend on a stronger 
barrier without triggering a data race.

A program written before C++11 atomics were generally available could 
theoretically depend on the barrier through a series of operations that cause a 
data race under the C++11 rules.  Since there were no clear rules before C++11, 
programs did things like emulate relaxed atomics on top of volatile pointers; 
using such a construct, a program could depend on the implied barrier.  For 
this reason, gcc emits a fence on AArch64 after `__sync_*` (but not 
`__atomic_*`).  And I guess MSVC does something similar for `_Interlocked*`.

That said, LLVM has never emitted a dmb for `__sync_*` operations on AArch64, 
and it hasn't led to any practical problems as far as I know.


Repository:
  rC Clang

https://reviews.llvm.org/D52807



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


[PATCH] D52578: Thread safety analysis: Allow scoped releasing of capabilities

2018-10-04 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley added inline comments.



Comment at: lib/Analysis/ThreadSafety.cpp:893
 private:
-  SmallVector UnderlyingMutexes;
+  enum UnderlyingCapabilityKind {
+UCK_Acquired,  ///< Any kind of acquired capability.

aaronpuchert wrote:
> delesley wrote:
> > IMHO, it would make more sense to break this into two properties (or bits): 
> > acquired/released and shared/exclusive. 
> We don't use the information (shared/exclusive) for acquired locks, but we 
> need two bits anyway, so why not.
The normal unlock doesn't distinguish between shared/exclusive, but there is a 
release_shared_capability which does...


Repository:
  rC Clang

https://reviews.llvm.org/D52578



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


[PATCH] D52578: Thread safety analysis: Allow scoped releasing of capabilities

2018-10-04 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley added inline comments.



Comment at: lib/Analysis/ThreadSafety.cpp:951
+}
   } else {
+// We're removing the underlying mutex. Warn on double unlocking.

aaronpuchert wrote:
> delesley wrote:
> > I find this very confusing.  A lock here unlocks the underlying mutex, and 
> > vice versa.  At the very least, some methods need to be renamed, or maybe 
> > we can have separate classes for ScopedLockable and ScopedUnlockable. 
> I agree that it's confusing, but it follows what I think was the idea behind 
> scoped capabilities: that they are also capabilities that can be 
> acquired/released. Now since the scoped capability releases a mutex on 
> construction (i.e. when it is acquired), it has to acquire the mutex when 
> released. So the way it handles the released mutexes mirrors what happens on 
> the scoped capability itself.
> 
> It's definitely not very intuitive, but I feel it's the most consistent 
> variant with what we have already.
> 
> The nice thing about this is that it works pretty well with the existing 
> semantics and allows constructs such as `MutexLockUnlock` (see the tests) 
> that unlocks one mutex and locks another. Not sure if anyone needs this, but 
> why not?
A scoped_lockable object is not a capability, it is an object that manages 
capabilities.  IMHO, conflating those two concepts is a bad idea, and recipe 
for confusion.  You would not, for example, use a scoped_lockable object in a 
guarded_by attribute.  

Unfortunately, the existing code tends to conflate "capabilities" and "facts", 
which is my fault.  A scoped_lockable object is a valid fact -- the fact 
records whether the object is in scope -- it's just not a valid capability. 

Simply renaming the methods from handleLock/Unlock to  addFact/removeFact would 
be a nice first step in making the code clearer, and would distinguish between 
facts that refer to capabilities, and facts that refer to scoped objects.  







Comment at: lib/Analysis/ThreadSafety.cpp:992
+FSet.removeLock(FactMan, UnderCp);
+FSet.addLock(FactMan, std::move(UnderEntry));
+  }

aaronpuchert wrote:
> delesley wrote:
> > Shouldn't this be outside of the else?
> If we don't find `UnderCp` anymore, the negation should be there already. But 
> I can also keep it outside if you like.
That's not necessarily true.  Not knowing whether a mutex is locked is 
different from knowing that it is unlocked. 

You're probably right in this case, because capabilities that are managed by 
scoped objects obey a more restricted set of rules.  But then, you're also 
extending the ways in which scoped objects can be used.  :-)



Repository:
  rC Clang

https://reviews.llvm.org/D52578



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


[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

In https://reviews.llvm.org/D52856#1255905, @dschuff wrote:

> W is int64_t (which is long long for wasm32 and would probably be long for 
> wasm64 since that would probably LP64 (like Linux) rather than LLP64 (Like 
> Win64). So if we want it to be the same for both wasm32 and wasm64, I guess 
> we want LL.


Ideally I would be able to exactly specify int8_t, int32_t, etc, but c/s/i/LLi 
works too.


Repository:
  rC Clang

https://reviews.llvm.org/D52856



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


[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

W is int64_t (which is long long for wasm32 and would probably be long for 
wasm64 since that would probably LP64 (like Linux) rather than LLP64 (Like 
Win64). So if we want it to be the same for both wasm32 and wasm64, I guess we 
want LL.


Repository:
  rC Clang

https://reviews.llvm.org/D52856



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


[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168388.
tlively added a comment.

- Remove V:128: attributes


Repository:
  rC Clang

https://reviews.llvm.org/D52858

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -172,3 +172,59 @@
   // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f25(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f26(i8x16 x, i8x16 y) {
+  return __builtin_wasm_add_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.add.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f27(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f28(i16x8 x, i16x8 y) {
+  return __builtin_wasm_add_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.add.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f29(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_s_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.signed.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i8x16 f30(i8x16 x, i8x16 y) {
+  return __builtin_wasm_sub_saturate_u_i8x16(x, y);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.saturate.unsigned.v16i8(
+  // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f31(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_s_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.signed.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f32(i16x8 x, i16x8 y) {
+  return __builtin_wasm_sub_saturate_u_i16x8(x, y);
+  // WEBASSEMBLY: call <8 x i16> @llvm.wasm.sub.saturate.unsigned.v8i16(
+  // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12485,6 +12485,40 @@
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8: {
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_add_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_add_saturate_unsigned;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_s_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_signed;
+  break;
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i8x16:
+case WebAssembly::BI__builtin_wasm_sub_saturate_u_i16x8:
+  IntNo = Intrinsic::wasm_sub_saturate_unsigned;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+Value *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));
+return Builder.CreateCall(Callee, {LHS, RHS});
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -56,4 +56,14 @@
 BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
 BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "nc")
+BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "nc")
+BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8s", "nc")
+

[PATCH] D52674: [AST] Add Obj-C discriminator to MS ABI RTTI

2018-10-04 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In https://reviews.llvm.org/D52674#1253408, @rjmccall wrote:

> In https://reviews.llvm.org/D52674#1253401, @smeenai wrote:
>
> > Actually, I take that back ... I just misread the stack trace.
> >
> > There are a bunch of hops between the `mangleCXXRTTI` call and the ultimate 
> > mangling function:
> >
> >   MicrosoftMangleContextImpl::mangleCXXRTTI(QualType, raw_ostream &)
> >   MicrosoftCXXNameMangler::mangleType(QualType, SourceRange, 
> > QualifierMangleMode)
> >   MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *, 
> > Qualifiers, SourceRange)
> >   MicrosoftCXXNameMangler::mangleType(QualType, SourceRange, 
> > QualifierMangleMode)
> >   MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *, Qualifiers, 
> > SourceRange)
> >
> >
> > (the last one will be `ObjCInterfaceType` instead of `ObjCObjectType` if 
> > catching anything other than `id`)
> >
> > Threading a `ForRTTI` flag or similar all the way to the final call seems 
> > pretty tricky. I can add an optional paramater to `mangleType(QualType, 
> > SourceRange, QualifierMangleMode)`, but that function uses a generated 
> > switch case 
> > 
> >  to call the specific `mangleType` functions, and I don't know how to 
> > special-case certain types in that switch case (to pass the extra parameter 
> > along) without doing something super ugly. Adding the extra parameter to 
> > every single `mangleType` overload seems highly non-ideal, which is why I 
> > was thinking of maintaining some internal state instead.
>
>
> Well, that's why I was talking about how the pointee type of an 
> `ObjCObjectPointerType` is always an `ObjCObjectType` (of which 
> `ObjCInterfaceType` is a subclass) — the implication being that you don't 
> actually have to do the `switch` to dispatch to one of those two cases.


The intermediate `mangleType(QualType, SourceRange, QualifierMangleMode)` calls 
have a bunch of logic 

 in them; it's not just a direct dispatch to the actual mangling function, so I 
don't think we can skip over it. I think it's hard to discuss this in the 
abstract though (and it's also entirely possible I'm missing your point 
completely), so I'll just actually try out the parameter approach and put up 
the resulting patch and we can see how it turns out.


Repository:
  rC Clang

https://reviews.llvm.org/D52674



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


[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168387.
tlively added a comment.

- Replace Wi with LLi and remove V:128:


Repository:
  rC Clang

https://reviews.llvm.org/D52856

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -134,3 +134,41 @@
   // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
   // WEBASSEMBLY-NEXT: ret
 }
+
+i8x16 f19(i8x16 v, int x) {
+  return __builtin_wasm_replace_lane_i8x16(v, 13, x);
+  // WEBASSEMBLY: trunc i32 %x to i8
+  // WEBASSEMBLY-NEXT: insertelement <16 x i8> %v, i8 %{{.*}}, i32 13
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i16x8 f20(i16x8 v, int x) {
+  return __builtin_wasm_replace_lane_i16x8(v, 7, x);
+  // WEBASSEMBLY: trunc i32 %x to i16
+  // WEBASSEMBLY-NEXT: insertelement <8 x i16> %v, i16 %{{.*}}, i32 7
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i32x4 f21(i32x4 v, int x) {
+  return __builtin_wasm_replace_lane_i32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x i32> %v, i32 %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 f22(i64x2 v, long long x) {
+  return __builtin_wasm_replace_lane_i64x2(v, 1, x);
+  // WEBASSEMBLY: insertelement <2 x i64> %v, i64 %x, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f32x4 f23(f32x4 v, float x) {
+  return __builtin_wasm_replace_lane_f32x4(v, 3, x);
+  // WEBASSEMBLY: insertelement <4 x float> %v, float %x, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+f64x2 f24(f64x2 v, double x) {
+  return __builtin_wasm_replace_lane_f64x2(v, 1, x);
+  // WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12457,6 +12457,34 @@
   llvm_unreachable("unexpected builtin ID");
 }
   }
+  case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i16x8:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_replace_lane_f64x2: {
+llvm::APSInt LaneConst;
+if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
+  llvm_unreachable("Constant arg isn't actually constant?");
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
+Value *Val = EmitScalarExpr(E->getArg(2));
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
+case WebAssembly::BI__builtin_wasm_replace_lane_i16x8: {
+  llvm::Type *ElemType = ConvertType(E->getType())->getVectorElementType();
+  Value *Trunc = Builder.CreateTrunc(Val, ElemType);
+  return Builder.CreateInsertElement(Vec, Trunc, Lane);
+}
+case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
+case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
+case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
+case WebAssembly::BI__builtin_wasm_replace_lane_f64x2:
+  return Builder.CreateInsertElement(Vec, Val, Lane);
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+  }
 
   default:
 return nullptr;
Index: include/clang/Basic/BuiltinsWebAssembly.def
===
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -49,4 +49,11 @@
 BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
 BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
 
+BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "nc")
+BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2LLiV2LLiIiLLi", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
+BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
+
 #undef BUILTIN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52852: [WebAssembly] __builtin_wasm_extract_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 168385.
tlively added a comment.

- Replace Wi with LLi in signature string
- Remove unnecessary V:128: attribute


Repository:
  rC Clang

https://reviews.llvm.org/D52852

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-wasm.c

Index: test/CodeGen/builtins-wasm.c
===
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -1,7 +1,21 @@
-// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
-// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s \
-// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fno-lax-vector-conversions \
+// RUN:   -O3 -emit-llvm -o - %s \
+// RUN:   | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+
+// SIMD convenience types
+typedef char i8x16 __attribute((vector_size(16)));
+typedef short i16x8 __attribute((vector_size(16)));
+typedef int i32x4 __attribute((vector_size(16)));
+typedef long long i64x2 __attribute((vector_size(16)));
+typedef unsigned char u8x16 __attribute((vector_size(16)));
+typedef unsigned short u16x8 __attribute((vector_size(16)));
+typedef unsigned int u32x4 __attribute((vector_size(16)));
+typedef unsigned long long u64x2 __attribute((vector_size(16)));
+typedef float f32x4 __attribute((vector_size(16)));
+typedef double f64x2 __attribute((vector_size(16)));
 
 __SIZE_TYPE__ f0(void) {
   return __builtin_wasm_memory_size(0);
@@ -68,3 +82,55 @@
   // WEBASSEMBLY32: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
   // WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
 }
+
+int f11(i8x16 v) {
+  return __builtin_wasm_extract_lane_s_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f12(i8x16 v) {
+  return __builtin_wasm_extract_lane_u_i8x16(v, 13);
+  // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f13(i16x8 v) {
+  return __builtin_wasm_extract_lane_s_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: sext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f14(i16x8 v) {
+  return __builtin_wasm_extract_lane_u_i16x8(v, 7);
+  // WEBASSEMBLY: extractelement <8 x i16> %v, i32 7
+  // WEBASSEMBLY-NEXT: zext
+  // WEBASSEMBLY-NEXT: ret
+}
+
+int f15(i32x4 v) {
+  return __builtin_wasm_extract_lane_i32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x i32> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+long long f16(i64x2 v) {
+  return __builtin_wasm_extract_lane_i64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x i64> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
+
+float f17(f32x4 v) {
+  return __builtin_wasm_extract_lane_f32x4(v, 3);
+  // WEBASSEMBLY: extractelement <4 x float> %v, i32 3
+  // WEBASSEMBLY-NEXT: ret
+}
+
+double f18(f64x2 v) {
+  return __builtin_wasm_extract_lane_f64x2(v, 1);
+  // WEBASSEMBLY: extractelement <2 x double> %v, i32 1
+  // WEBASSEMBLY-NEXT: ret
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -12427,6 +12427,36 @@
 Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
 return Builder.CreateCall(Callee, {Addr, Count});
   }
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+  case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
+  case WebAssembly::BI__builtin_wasm_extract_lane_f64x2: {
+llvm::APSInt LaneConst;
+if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
+  llvm_unreachable("Constant arg isn't actually constant?");
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
+Value *Extract = Builder.CreateExtractElement(Vec, Lane);
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
+  return Builder.CreateSExt(Extract, ConvertType(E->getType()));
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
+case WebAssembly::BI__builtin_wasm_extract_lane_u_i16x8:
+  return Builder.CreateZExt(Extract, ConvertType(E->getType()));
+case WebAssembly::BI__builtin_wasm_ext

[PATCH] D52673: [HIP] Remove disabled irif library

2018-10-04 Thread Aaron Enye Shi via Phabricator via cfe-commits
ashi1 added a comment.

I've added a hip.amdgcn.bc library for the fence functions that were originally 
in irif library.


https://reviews.llvm.org/D52673



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


[PATCH] D52673: [HIP] Remove disabled irif library

2018-10-04 Thread Aaron Enye Shi via Phabricator via cfe-commits
ashi1 updated this revision to Diff 168384.
ashi1 edited the summary of this revision.
Herald added a subscriber: jfb.

https://reviews.llvm.org/D52673

Files:
  lib/Driver/ToolChains/HIP.cpp
  test/Driver/hip-device-libs.hip


Index: test/Driver/hip-device-libs.hip
===
--- test/Driver/hip-device-libs.hip
+++ test/Driver/hip-device-libs.hip
@@ -21,8 +21,8 @@


 // COM: [[LLVM_LINK:"*.llvm-link"]]
-// COM-SAME: {{.*}} "{{.*}}ocml.amdgcn.bc" "{{.*}}ockl.amdgcn.bc" 
"{{.*}}irif.amdgcn.bc"
+// COM-SAME: {{.*}} "{{.*}}ocml.amdgcn.bc" "{{.*}}ockl.amdgcn.bc" 
"{{.*}}hip.amdgcn.bc"
 // FLUSHD-SAME: {{.*}} "{{.*}}oclc_daz_opt_on.amdgcn.bc"
 // NOFLUSHD-SAME: {{.*}} "{{.*}}oclc_daz_opt_off.amdgcn.bc"
 // COM-SAME: {{.*}} "-o" "{{.*}}-gfx900-linked-{{.*bc}}"

Index: lib/Driver/ToolChains/HIP.cpp
===
--- lib/Driver/ToolChains/HIP.cpp
+++ lib/Driver/ToolChains/HIP.cpp
@@ -82,15 +82,15 @@
   FlushDenormalControlBC = "oclc_daz_opt_off.amdgcn.bc";

 BCLibs.append({"opencl.amdgcn.bc",
-   "ocml.amdgcn.bc", "ockl.amdgcn.bc", "irif.amdgcn.bc",
+   "ocml.amdgcn.bc", "ockl.amdgcn.bc", "hip.amdgcn.bc",
"oclc_finite_only_off.amdgcn.bc",
FlushDenormalControlBC,
"oclc_correctly_rounded_sqrt_on.amdgcn.bc",
"oclc_unsafe_math_off.amdgcn.bc", ISAVerBC});
   }
   for (auto Lib : BCLibs)
 addBCLib(C, Args, CmdArgs, LibraryPaths, Lib);

   // Add an intermediate output file.
   CmdArgs.push_back("-o");
   std::string TmpName =


Index: test/Driver/hip-device-libs.hip
===
--- test/Driver/hip-device-libs.hip
+++ test/Driver/hip-device-libs.hip
@@ -21,8 +21,8 @@


 // COM: [[LLVM_LINK:"*.llvm-link"]]
-// COM-SAME: {{.*}} "{{.*}}ocml.amdgcn.bc" "{{.*}}ockl.amdgcn.bc" "{{.*}}irif.amdgcn.bc"
+// COM-SAME: {{.*}} "{{.*}}ocml.amdgcn.bc" "{{.*}}ockl.amdgcn.bc" "{{.*}}hip.amdgcn.bc"
 // FLUSHD-SAME: {{.*}} "{{.*}}oclc_daz_opt_on.amdgcn.bc"
 // NOFLUSHD-SAME: {{.*}} "{{.*}}oclc_daz_opt_off.amdgcn.bc"
 // COM-SAME: {{.*}} "-o" "{{.*}}-gfx900-linked-{{.*bc}}"

Index: lib/Driver/ToolChains/HIP.cpp
===
--- lib/Driver/ToolChains/HIP.cpp
+++ lib/Driver/ToolChains/HIP.cpp
@@ -82,15 +82,15 @@
   FlushDenormalControlBC = "oclc_daz_opt_off.amdgcn.bc";

 BCLibs.append({"opencl.amdgcn.bc",
-   "ocml.amdgcn.bc", "ockl.amdgcn.bc", "irif.amdgcn.bc",
+   "ocml.amdgcn.bc", "ockl.amdgcn.bc", "hip.amdgcn.bc",
"oclc_finite_only_off.amdgcn.bc",
FlushDenormalControlBC,
"oclc_correctly_rounded_sqrt_on.amdgcn.bc",
"oclc_unsafe_math_off.amdgcn.bc", ISAVerBC});
   }
   for (auto Lib : BCLibs)
 addBCLib(C, Args, CmdArgs, LibraryPaths, Lib);

   // Add an intermediate output file.
   CmdArgs.push_back("-o");
   std::string TmpName =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52311: [clangd] Add support for hierarchical documentSymbol

2018-10-04 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

I just tried this, this looks very promising!  It should help build our outline 
view in a much more robust way than we do currently.

A nit for the final patch, I would suggest omitting the fields that are 
optional, like `children` (when the list is empty) and `deprecated`.

In vscode, is there a way to get a tree representation of this data?  When I 
look at "Go to symbol in File..." (ctrl-shift-o) or the outline view at the 
bottom of the file explorer, they are both a flat list.  What difference does 
this patch make in how vscode shows the data?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52311



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


[PATCH] D52754: [clang-doc] Clean up Markdown output

2018-10-04 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343818: [clang-doc] Clean up Markdown output (authored by 
juliehockett, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D52754?vs=167851&id=168381#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52754

Files:
  clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
  clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
  clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp
  clang-tools-extra/trunk/test/clang-doc/md-module.cpp
  clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
  clang-tools-extra/trunk/test/clang-doc/md-record.cpp

Index: clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
@@ -74,18 +74,18 @@
   return Stream.str();
 }
 
-void writeLine(const Twine &Text, raw_ostream &OS) { OS << Text << "\n"; }
+void writeLine(const Twine &Text, raw_ostream &OS) { OS << Text << "\n\n"; }
 
-void writeNewLine(raw_ostream &OS) { OS << "\n"; }
+void writeNewLine(raw_ostream &OS) { OS << "\n\n"; }
 
 void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS) {
-  OS << std::string(Num, '#') + " " + Text << "\n";
+  OS << std::string(Num, '#') + " " + Text << "\n\n";
 }
 
 void writeFileDefinition(const Location &L, raw_ostream &OS) {
   OS << genItalic("Defined at line " + std::to_string(L.LineNumber) + " of " +
   L.Filename)
- << "\n";
+ << "\n\n";
 }
 
 void writeDescription(const CommentInfo &I, raw_ostream &OS) {
@@ -104,10 +104,10 @@
 OS << genEmphasis(I.Name) << " " << I.Text;
   } else if (I.Kind == "ParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "TParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "VerbatimBlockComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
@@ -132,7 +132,7 @@
   } else if (I.Kind == "TextComment") {
 OS << I.Text;
   } else {
-OS << "Unknown comment kind: " << I.Kind << ".\n";
+OS << "Unknown comment kind: " << I.Kind << ".\n\n";
   }
 }
 
@@ -166,11 +166,16 @@
 Stream << N.Type.Name + " " + N.Name;
 First = false;
   }
+  writeHeader(I.Name, 3, OS);
   std::string Access = getAccess(I.Access);
   if (Access != "")
-writeHeader(genItalic(Access) + " " + I.ReturnType.Type.Name + " " + I.Name + "(" + Stream.str() + ")", 3, OS);
-  else 
-writeHeader(I.ReturnType.Type.Name + " " + I.Name + "(" + Stream.str() + ")", 3, OS);
+writeLine(genItalic(Access + " " + I.ReturnType.Type.Name + " " + I.Name +
+"(" + Stream.str() + ")"),
+  OS);
+  else
+writeLine(genItalic(I.ReturnType.Type.Name + " " + I.Name + "(" +
+Stream.str() + ")"),
+  OS);
   if (I.DefLoc)
 writeFileDefinition(I.DefLoc.getValue(), OS);
 
Index: clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
===
--- clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
+++ clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
@@ -33,7 +33,8 @@
 // RUN: cat %t/docs/./GlobalNamespace.md | FileCheck %s --check-prefix CHECK-0
 // CHECK-0: # Global Namespace
 // CHECK-0: ## Functions
-// CHECK-0: ### void F(int I, int J)
+// CHECK-0: ### F
+// CHECK-0: *void F(int I, int J)*
 // CHECK-0: *Defined at line 28 of test*
 // CHECK-0: **brief** Brief description.
 // CHECK-0:  Extended description that continues onto the next line.
Index: clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
===
--- clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
+++ clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
@@ -31,13 +31,15 @@
 // RUN: cat %t/docs/./A.md | FileCheck %s --check-prefix CHECK-0
 // CHECK-0: # namespace A
 // CHECK-0: ## Functions
-// CHECK-0: ### void f()
+// CHECK-0: ### f
+// CHECK-0: *void f()*
 // CHECK-0: *Defined at line 17 of test*
 
 // RUN: cat %t/docs/A/B.md | FileCheck %s --check-prefix CHECK-1
 // CHECK-1: # namespace B
 // CHECK-1: ## Functions
-// CHECK-1: ### enum A::B::E func(int i)
+// CHECK-1: ### func
+// CHECK-1: *enum A::B::E func(int i)*
 // CHECK-1: *Defined at line 23 of test*
 // CHECK-1: ## Enums
 // CHECK-1: | enum E |
Index: clang-tools-extra/trunk/test/clang-doc/md-module.cpp
==

[clang-tools-extra] r343818 - [clang-doc] Clean up Markdown output

2018-10-04 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Thu Oct  4 14:34:13 2018
New Revision: 343818

URL: http://llvm.org/viewvc/llvm-project?rev=343818&view=rev
Log:
[clang-doc] Clean up Markdown output

Make the output for the MDGenerator cleaner and more readable.

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

Modified:
clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp
clang-tools-extra/trunk/test/clang-doc/md-module.cpp
clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/md-record.cpp

Modified: clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/MDGenerator.cpp?rev=343818&r1=343817&r2=343818&view=diff
==
--- clang-tools-extra/trunk/clang-doc/MDGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/MDGenerator.cpp Thu Oct  4 14:34:13 2018
@@ -74,18 +74,18 @@ std::string genReferenceList(const llvm:
   return Stream.str();
 }
 
-void writeLine(const Twine &Text, raw_ostream &OS) { OS << Text << "\n"; }
+void writeLine(const Twine &Text, raw_ostream &OS) { OS << Text << "\n\n"; }
 
-void writeNewLine(raw_ostream &OS) { OS << "\n"; }
+void writeNewLine(raw_ostream &OS) { OS << "\n\n"; }
 
 void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS) {
-  OS << std::string(Num, '#') + " " + Text << "\n";
+  OS << std::string(Num, '#') + " " + Text << "\n\n";
 }
 
 void writeFileDefinition(const Location &L, raw_ostream &OS) {
   OS << genItalic("Defined at line " + std::to_string(L.LineNumber) + " of " +
   L.Filename)
- << "\n";
+ << "\n\n";
 }
 
 void writeDescription(const CommentInfo &I, raw_ostream &OS) {
@@ -104,10 +104,10 @@ void writeDescription(const CommentInfo
 OS << genEmphasis(I.Name) << " " << I.Text;
   } else if (I.Kind == "ParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "TParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "VerbatimBlockComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
@@ -132,7 +132,7 @@ void writeDescription(const CommentInfo
   } else if (I.Kind == "TextComment") {
 OS << I.Text;
   } else {
-OS << "Unknown comment kind: " << I.Kind << ".\n";
+OS << "Unknown comment kind: " << I.Kind << ".\n\n";
   }
 }
 
@@ -166,11 +166,16 @@ void genMarkdown(const FunctionInfo &I,
 Stream << N.Type.Name + " " + N.Name;
 First = false;
   }
+  writeHeader(I.Name, 3, OS);
   std::string Access = getAccess(I.Access);
   if (Access != "")
-writeHeader(genItalic(Access) + " " + I.ReturnType.Type.Name + " " + 
I.Name + "(" + Stream.str() + ")", 3, OS);
-  else 
-writeHeader(I.ReturnType.Type.Name + " " + I.Name + "(" + Stream.str() + 
")", 3, OS);
+writeLine(genItalic(Access + " " + I.ReturnType.Type.Name + " " + I.Name +
+"(" + Stream.str() + ")"),
+  OS);
+  else
+writeLine(genItalic(I.ReturnType.Type.Name + " " + I.Name + "(" +
+Stream.str() + ")"),
+  OS);
   if (I.DefLoc)
 writeFileDefinition(I.DefLoc.getValue(), OS);
 

Modified: clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-doc/md-comment.cpp?rev=343818&r1=343817&r2=343818&view=diff
==
--- clang-tools-extra/trunk/test/clang-doc/md-comment.cpp (original)
+++ clang-tools-extra/trunk/test/clang-doc/md-comment.cpp Thu Oct  4 14:34:13 
2018
@@ -33,7 +33,8 @@ void F(int I, int J) {}
 // RUN: cat %t/docs/./GlobalNamespace.md | FileCheck %s --check-prefix CHECK-0
 // CHECK-0: # Global Namespace
 // CHECK-0: ## Functions
-// CHECK-0: ### void F(int I, int J)
+// CHECK-0: ### F
+// CHECK-0: *void F(int I, int J)*
 // CHECK-0: *Defined at line 28 of test*
 // CHECK-0: **brief** Brief description.
 // CHECK-0:  Extended description that continues onto the next line.

Modified: clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp?rev=343818&r1=343817&r2=343818&view=diff
==
--- clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp (original)
+++ clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp Thu Oct  4 1

[PATCH] D52856: [WebAssembly] __builtin_wasm_replace_lane_* builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: include/clang/Basic/BuiltinsWebAssembly.def:55
+BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "ncV:128:")
+BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2WiV2WiIiWi", "ncV:128:")
+BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "ncV:128:")

craig.topper wrote:
> aheejin wrote:
> > craig.topper wrote:
> > > I think maybe you want LL instead of W, but I'm not sure.
> > Not sure what the differences are either. I've used LL for other builtins 
> > in this file though.
> W changes based on what's returned from getInt64Type() for the target. I 
> think it will be either L or LL. It looks to be almost exclusively used by 
> MSVC compatibility intrinsics except for two builtins in NVPTX.
Ok, I'll switch to using LL.


Repository:
  rC Clang

https://reviews.llvm.org/D52856



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


[PATCH] D52858: [WebAssembly] saturating arithmetic builtins

2018-10-04 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: include/clang/Basic/BuiltinsWebAssembly.def:59
 
+BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "ncV:128:")
+BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "ncV:128:")

craig.topper wrote:
> Don't copy the "V:128:" part from X86. You just need the "nc".  The V:128: is 
> a special thing I'm working on for our AVX512 frequency issues.
ok, sounds good


Repository:
  rC Clang

https://reviews.llvm.org/D52858



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


[PATCH] D52888: Thread safety analysis: Handle conditional expression in getTrylockCallExpr

2018-10-04 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Additional branches (with non-tail recursion unfortunately) would allow the 
following to work:

  void foo16() {
if (cond ? mu.TryLock() : false)
  mu.Unlock();
  }
  
  void foo17() {
if (cond ? true : !mu.TryLock())
  return;
mu.Unlock();
  }

Worth the effort, or is that too exotic?


Repository:
  rC Clang

https://reviews.llvm.org/D52888



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


[PATCH] D51741: [coro]Pass rvalue reference for named local variable to return_value

2018-10-04 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 added a comment.

@modocache I do need someone to land this for me! Take it away!


Repository:
  rC Clang

https://reviews.llvm.org/D51741



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


[PATCH] D51741: [coro]Pass rvalue reference for named local variable to return_value

2018-10-04 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 updated this revision to Diff 168380.
tks2103 added a comment.

comply with clang-format


Repository:
  rC Clang

https://reviews.llvm.org/D51741

Files:
  lib/Sema/SemaCoroutine.cpp
  test/SemaCXX/coroutine-rvo.cpp


Index: test/SemaCXX/coroutine-rvo.cpp
===
--- /dev/null
+++ test/SemaCXX/coroutine-rvo.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z 
-fcoroutines-ts -fsyntax-only
+
+namespace std::experimental {
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+}
+
+struct suspend_never {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct MoveOnly {
+  MoveOnly() {};
+  MoveOnly(const MoveOnly&) = delete;
+  MoveOnly(MoveOnly&&) noexcept {};
+  ~MoveOnly() {};
+};
+
+template 
+struct task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() { return suspend_never{}; }
+auto get_return_object() { return task{}; }
+static void unhandled_exception() {}
+void return_value(T&& value) {}
+  };
+};
+
+task f() {
+  MoveOnly value;
+  co_return value;
+}
+
+int main() {
+  f();
+  return 0;
+}
+
+// expected-no-diagnostics
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -841,6 +841,19 @@
 E = R.get();
   }
 
+  // Move the return value if we can
+  if (E) {
+auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, 
CES_AsIfByStdMove);
+if (NRVOCandidate) {
+  InitializedEntity Entity =
+  InitializedEntity::InitializeResult(Loc, E->getType(), 
NRVOCandidate);
+  ExprResult MoveResult = this->PerformMoveOrCopyInitialization(
+  Entity, NRVOCandidate, E->getType(), E);
+  if (MoveResult.get())
+E = MoveResult.get();
+}
+  }
+
   // FIXME: If the operand is a reference to a variable that's about to go out
   // of scope, we should treat the operand as an xvalue for this overload
   // resolution.


Index: test/SemaCXX/coroutine-rvo.cpp
===
--- /dev/null
+++ test/SemaCXX/coroutine-rvo.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only
+
+namespace std::experimental {
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+}
+
+struct suspend_never {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct MoveOnly {
+  MoveOnly() {};
+  MoveOnly(const MoveOnly&) = delete;
+  MoveOnly(MoveOnly&&) noexcept {};
+  ~MoveOnly() {};
+};
+
+template 
+struct task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() { return suspend_never{}; }
+auto get_return_object() { return task{}; }
+static void unhandled_exception() {}
+void return_value(T&& value) {}
+  };
+};
+
+task f() {
+  MoveOnly value;
+  co_return value;
+}
+
+int main() {
+  f();
+  return 0;
+}
+
+// expected-no-diagnostics
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -841,6 +841,19 @@
 E = R.get();
   }
 
+  // Move the return value if we can
+  if (E) {
+auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, CES_AsIfByStdMove);
+if (NRVOCandidate) {
+  InitializedEntity Entity =
+  InitializedEntity::InitializeResult(Loc, E->getType(), NRVOCandidate);
+ 

[PATCH] D52610: [Esan] Port cache frag to FreeBSD

2018-10-04 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

ping compiler-rt component committed :-)


Repository:
  rC Clang

https://reviews.llvm.org/D52610



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


[PATCH] D52807: [COFF, ARM64] Add _InterlockedCompareExchangePointer_nf intrinsic

2018-10-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

How are you testing?

You might see different behavior at -O0.


Repository:
  rC Clang

https://reviews.llvm.org/D52807



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


[PATCH] D52838: [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D52838



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


[PATCH] D52807: [COFF, ARM64] Add _InterlockedCompareExchangePointer_nf intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

AArch64 Psuedo Expansion does not seem to honor AtomicOrdering types 
(SequentiallyConsistent/Monotonic). It seems to always generate LDAXRX/STLXRX 
for 64-bit Cmp_Xchg.


Repository:
  rC Clang

https://reviews.llvm.org/D52807



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


[PATCH] D52807: [COFF, ARM64] Add _InterlockedCompareExchangePointer_nf intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

MSVC seems to generate ldaxr/stlxr (as well as dmb) for 
InterlockedCompareExchangePointer and ldxr/stxr for 
InterlockedCompareExchangePointer_nf.

  void *test_InterlockedCompareExchangePointer(void * volatile *Destination,
   void *Exchange, void *Comparand) 
{
return _InterlockedCompareExchangePointer(Destination, Exchange, Comparand);
  }
  
  test_InterlockedCompareExchangePointer:
58:   ff 83 00 d1 sub sp, sp, #32
5c:   e0 0b 00 f9 str x0, [sp, #16]
60:   e1 07 00 f9 str x1, [sp, #8]
64:   e2 03 00 f9 str x2, [sp]
68:   ec 03 40 f9 ldr x12, [sp]
6c:   ec 03 0c aa mov x12, x12
70:   eb 07 40 f9 ldr x11, [sp, #8]
74:   eb 03 0b aa mov x11, x11
78:   ea 0b 40 f9 ldr x10, [sp, #16]
7c:   ea 03 0a aa mov x10, x10
  
  $LN3:
80:   49 fd 5f c8 ldaxr   x9, [x10]
84:   e9 03 09 aa mov x9, x9
88:   3f 01 0c eb cmp x9, x12
8c:   81 00 00 54 b.ne#16 <$LN4>
90:   4b fd 08 c8 stlxr   w8, x11, [x10]
94:   1f 01 00 71 cmp w8, #0
98:   41 ff ff 54 b.ne#-24 <$LN3>
  
  $LN4:
9c:   bf 3b 03 d5 dmb ish
a0:   e9 0f 00 f9 str x9, [sp, #24]
a4:   e0 0f 40 f9 ldr x0, [sp, #24]
a8:   ff 83 00 91 add sp, sp, #32
ac:   c0 03 5f d6 ret



  void *test_InterlockedCompareExchangePointer_nf(void * volatile *Destination,
   void *Exchange, void *Comparand) 
{
return _InterlockedCompareExchangePointer_nf(Destination, Exchange, 
Comparand);
  }
  
  test_InterlockedCompareExchangePointer_nf:
 0:   ff 83 00 d1 sub sp, sp, #32
 4:   e0 0b 00 f9 str x0, [sp, #16]
 8:   e1 07 00 f9 str x1, [sp, #8]
 c:   e2 03 00 f9 str x2, [sp]
10:   ec 03 40 f9 ldr x12, [sp]
14:   ec 03 0c aa mov x12, x12
18:   eb 07 40 f9 ldr x11, [sp, #8]
1c:   eb 03 0b aa mov x11, x11
20:   ea 0b 40 f9 ldr x10, [sp, #16]
24:   ea 03 0a aa mov x10, x10
  
  $LN3:
28:   49 7d 5f c8 ldxrx9, [x10]
2c:   e9 03 09 aa mov x9, x9
30:   3f 01 0c eb cmp x9, x12
34:   81 00 00 54 b.ne#16 <$LN4>
38:   4b 7d 08 c8 stxrw8, x11, [x10]
3c:   1f 01 00 71 cmp w8, #0
40:   41 ff ff 54 b.ne#-24 <$LN3>
  
  $LN4:
44:   e9 0f 00 f9 str x9, [sp, #24]
48:   e0 0f 40 f9 ldr x0, [sp, #24]
4c:   ff 83 00 91 add sp, sp, #32
50:   c0 03 5f d6 ret
54:   00 00 00 00  


Repository:
  rC Clang

https://reviews.llvm.org/D52807



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


[PATCH] D52838: [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 168371.

https://reviews.llvm.org/D52838

Files:
  include/clang/Basic/BuiltinsAArch64.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/intrin.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/arm64-microsoft-intrinsics.c
  test/Sema/builtins-microsoft-arm64.c

Index: test/Sema/builtins-microsoft-arm64.c
===
--- /dev/null
+++ test/Sema/builtins-microsoft-arm64.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple arm64-windows -fsyntax-only -verify \
+// RUN: -fms-compatibility -ffreestanding -fms-compatibility-version=17.00 %s
+
+#include 
+
+void check__getReg() {
+  __getReg(-1); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+  __getReg(32); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+}
Index: test/CodeGen/arm64-microsoft-intrinsics.c
===
--- test/CodeGen/arm64-microsoft-intrinsics.c
+++ test/CodeGen/arm64-microsoft-intrinsics.c
@@ -66,3 +66,15 @@
 
 // CHECK-MSVC: fence syncscope("singlethread")
 // CHECK-LINUX: error: implicit declaration of function '_ReadWriteBarrier'
+
+unsigned __int64 check__getReg() {
+  unsigned volatile __int64 reg;
+  reg = __getReg(18);
+  reg = __getReg(31);
+  return reg;
+}
+
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !2)
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !3)
+// CHECK-MSVC: !2 = !{!"x18"}
+// CHECK-MSVC: !3 = !{!"sp"}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1749,6 +1749,9 @@
   BuiltinID == AArch64::BI__builtin_arm_wsrp)
 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
 
+  if (BuiltinID == AArch64::BI__getReg)
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
+
   if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
 return true;
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -865,6 +865,13 @@
 #endif
 
 /**\
+|* MS AArch64 specific
+\**/
+#if defined(__aarch64__)
+unsigned __int64 __getReg(int);
+#endif
+
+/**\
 |* Privileged intrinsics
 \**/
 #if defined(__i386__) || defined(__x86_64__)
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -6576,6 +6576,23 @@
 return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr");
   }
 
+  if (BuiltinID == AArch64::BI__getReg) {
+APSInt Value;
+if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
+  llvm_unreachable("Sema will ensure that the parameter is constant");
+
+LLVMContext &Context = CGM.getLLVMContext();
+std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
+
+llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
+llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+
+llvm::Value *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+return Builder.CreateCall(F, Metadata);
+  }
+
   if (BuiltinID == AArch64::BI__builtin_arm_clrex) {
 Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex);
 return Builder.CreateCall(F);
Index: include/clang/Basic/BuiltinsAArch64.def
===
--- include/clang/Basic/BuiltinsAArch64.def
+++ include/clang/Basic/BuiltinsAArch64.def
@@ -104,6 +104,7 @@
 TARGET_HEADER_BUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__getReg, "ULLii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 #undef BUILTIN
 #undef LANGBUILTIN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52838: [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 168368.

https://reviews.llvm.org/D52838

Files:
  include/clang/Basic/BuiltinsAArch64.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/intrin.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/arm64-microsoft-intrinsics.c
  test/Sema/builtins-microsoft-arm64.c

Index: test/Sema/builtins-microsoft-arm64.c
===
--- /dev/null
+++ test/Sema/builtins-microsoft-arm64.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple arm64-windows -fsyntax-only -verify \
+// RUN: -fms-compatibility -ffreestanding -fms-compatibility-version=17.00 %s
+
+#include 
+
+void check__getReg() {
+  __getReg(-1); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+  __getReg(32); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+}
Index: test/CodeGen/arm64-microsoft-intrinsics.c
===
--- test/CodeGen/arm64-microsoft-intrinsics.c
+++ test/CodeGen/arm64-microsoft-intrinsics.c
@@ -66,3 +66,15 @@
 
 // CHECK-MSVC: fence syncscope("singlethread")
 // CHECK-LINUX: error: implicit declaration of function '_ReadWriteBarrier'
+
+unsigned __int64 check_getReg() {
+  unsigned volatile __int64 reg;
+  reg = __getReg(18);
+  reg = __getReg(31);
+  return reg;
+}
+
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !2)
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !3)
+// CHECK-MSVC: !2 = !{!"x18"}
+// CHECK-MSVC: !3 = !{!"sp"}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1749,6 +1749,9 @@
   BuiltinID == AArch64::BI__builtin_arm_wsrp)
 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
 
+  if (BuiltinID == AArch64::BI__getReg)
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
+
   if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
 return true;
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -865,6 +865,13 @@
 #endif
 
 /**\
+|* MS AArch64 specific
+\**/
+#if defined(__aarch64__)
+unsigned __int64 __getReg(int);
+#endif
+
+/**\
 |* Privileged intrinsics
 \**/
 #if defined(__i386__) || defined(__x86_64__)
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -6576,6 +6576,23 @@
 return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr");
   }
 
+  if (BuiltinID == AArch64::BI__getReg) {
+APSInt Value;
+if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
+  llvm_unreachable("Sema will ensure that the parameter is constant");
+
+LLVMContext &Context = CGM.getLLVMContext();
+std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
+
+llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
+llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+
+llvm::Value *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+return Builder.CreateCall(F, Metadata);
+  }
+
   if (BuiltinID == AArch64::BI__builtin_arm_clrex) {
 Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex);
 return Builder.CreateCall(F);
Index: include/clang/Basic/BuiltinsAArch64.def
===
--- include/clang/Basic/BuiltinsAArch64.def
+++ include/clang/Basic/BuiltinsAArch64.def
@@ -104,6 +104,7 @@
 TARGET_HEADER_BUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__getReg, "ULLii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 #undef BUILTIN
 #undef LANGBUILTIN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52906: CSA: allow plugins built as shared libraries to receive events

2018-10-04 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech created this revision.
Herald added a subscriber: cfe-commits.

Event types are uniqued by using the addresses of a local static defined in a 
header files, but it isn't the same across shared library boundaries and 
plugins can't currently handle ImplicitNullDerefEvents.


Repository:
  rC Clang

https://reviews.llvm.org/D52906

Files:
  include/clang/StaticAnalyzer/Core/Checker.h
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  lib/StaticAnalyzer/Core/Checker.cpp


Index: lib/StaticAnalyzer/Core/Checker.cpp
===
--- lib/StaticAnalyzer/Core/Checker.cpp
+++ lib/StaticAnalyzer/Core/Checker.cpp
@@ -17,6 +17,8 @@
 using namespace clang;
 using namespace ento;
 
+int ImplicitNullDerefEvent::Tag;
+
 StringRef CheckerBase::getTagDescription() const {
   return getCheckName().getName();
 }
Index: include/clang/StaticAnalyzer/Core/CheckerManager.h
===
--- include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -532,19 +532,19 @@
 
   template 
   void _registerListenerForEvent(CheckEventFunc checkfn) {
-EventInfo &info = Events[getTag()];
+EventInfo &info = Events[&EVENT::Tag];
 info.Checkers.push_back(checkfn);
   }
 
   template 
   void _registerDispatcherForEvent() {
-EventInfo &info = Events[getTag()];
+EventInfo &info = Events[&EVENT::Tag];
 info.HasDispatcher = true;
   }
 
   template 
   void _dispatchEvent(const EVENT &event) const {
-EventsTy::const_iterator I = Events.find(getTag());
+EventsTy::const_iterator I = Events.find(&EVENT::Tag);
 if (I == Events.end())
   return;
 const EventInfo &info = I->second;
Index: include/clang/StaticAnalyzer/Core/Checker.h
===
--- include/clang/StaticAnalyzer/Core/Checker.h
+++ include/clang/StaticAnalyzer/Core/Checker.h
@@ -558,6 +558,8 @@
   // dereference might happen later (for example pointer passed to a parameter
   // that is marked with nonnull attribute.)
   bool IsDirectDereference;
+
+  static int Tag;
 };
 
 /// A helper class which wraps a boolean value set to false by default.


Index: lib/StaticAnalyzer/Core/Checker.cpp
===
--- lib/StaticAnalyzer/Core/Checker.cpp
+++ lib/StaticAnalyzer/Core/Checker.cpp
@@ -17,6 +17,8 @@
 using namespace clang;
 using namespace ento;
 
+int ImplicitNullDerefEvent::Tag;
+
 StringRef CheckerBase::getTagDescription() const {
   return getCheckName().getName();
 }
Index: include/clang/StaticAnalyzer/Core/CheckerManager.h
===
--- include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -532,19 +532,19 @@
 
   template 
   void _registerListenerForEvent(CheckEventFunc checkfn) {
-EventInfo &info = Events[getTag()];
+EventInfo &info = Events[&EVENT::Tag];
 info.Checkers.push_back(checkfn);
   }
 
   template 
   void _registerDispatcherForEvent() {
-EventInfo &info = Events[getTag()];
+EventInfo &info = Events[&EVENT::Tag];
 info.HasDispatcher = true;
   }
 
   template 
   void _dispatchEvent(const EVENT &event) const {
-EventsTy::const_iterator I = Events.find(getTag());
+EventsTy::const_iterator I = Events.find(&EVENT::Tag);
 if (I == Events.end())
   return;
 const EventInfo &info = I->second;
Index: include/clang/StaticAnalyzer/Core/Checker.h
===
--- include/clang/StaticAnalyzer/Core/Checker.h
+++ include/clang/StaticAnalyzer/Core/Checker.h
@@ -558,6 +558,8 @@
   // dereference might happen later (for example pointer passed to a parameter
   // that is marked with nonnull attribute.)
   bool IsDirectDereference;
+
+  static int Tag;
 };
 
 /// A helper class which wraps a boolean value set to false by default.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52905: CSA: fix accessing GDM data from shared libraries

2018-10-04 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech created this revision.
Herald added subscribers: cfe-commits, mgorny.

The `GDMIndex` functions return a pointer that's used as a key for looking up 
data, but addresses of local statics defined in header files aren't the same 
across shared library boundaries and the result is that analyzer plugins can't 
access this data.


Repository:
  rC Clang

https://reviews.llvm.org/D52905

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h
  lib/StaticAnalyzer/Core/CMakeLists.txt
  lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  lib/StaticAnalyzer/Core/TaintManager.cpp

Index: lib/StaticAnalyzer/Core/TaintManager.cpp
===
--- lib/StaticAnalyzer/Core/TaintManager.cpp
+++ lib/StaticAnalyzer/Core/TaintManager.cpp
@@ -0,0 +1,23 @@
+//== TaintManager.cpp -- -*- C++ -*--=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h"
+
+using namespace clang;
+using namespace ento;
+
+void *ProgramStateTrait::GDMIndex() {
+  static int index = 0;
+  return &index;
+}
+
+void *ProgramStateTrait::GDMIndex() {
+  static int index;
+  return &index;
+}
Index: lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -200,6 +200,11 @@
   }
 }
 
+void *ProgramStateTrait::GDMIndex() {
+  static int Index;
+  return &Index;
+}
+
 } // end of namespace ento
 
 } // end of namespace clang
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3106,3 +3106,8 @@
   llvm::errs() << "Warning: dumping graph requires assertions" << "\n";
   return "";
 }
+
+void *ProgramStateTrait::GDMIndex() {
+  static int index = 0;
+  return &index;
+}
Index: lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
===
--- lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
+++ lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
@@ -77,5 +77,10 @@
   }
 }
 
+void *ProgramStateTrait::GDMIndex() {
+  static int index = 0;
+  return &index;
+}
+
 } // namespace ento
 } // namespace clang
Index: lib/StaticAnalyzer/Core/CMakeLists.txt
===
--- lib/StaticAnalyzer/Core/CMakeLists.txt
+++ lib/StaticAnalyzer/Core/CMakeLists.txt
@@ -52,6 +52,7 @@
   Store.cpp
   SubEngine.cpp
   SymbolManager.cpp
+  TaintManager.cpp
   WorkList.cpp
   Z3ConstraintManager.cpp
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h
@@ -34,10 +34,7 @@
 
 template<> struct ProgramStateTrait
 :  public ProgramStatePartialTrait {
-  static void *GDMIndex() {
-static int index = 0;
-return &index;
-  }
+  static void *GDMIndex();
 };
 
 /// The GDM component mapping derived symbols' parent symbols to their
@@ -49,10 +46,7 @@
 
 template<> struct ProgramStateTrait
 :  public ProgramStatePartialTrait {
-  static void *GDMIndex() {
-static int index;
-return &index;
-  }
+  static void *GDMIndex();
 };
 
 class TaintManager {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
@@ -131,7 +131,7 @@
 template <>
 struct ProgramStateTrait
   : public ProgramStatePartialTrait {
-  static void *GDMIndex() { static int Index; return &Index; }
+  static void *GDMIndex();
 };
 
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -832,7 +832,7 @@
 template <>
 struct ProgramStateTrait :
   public ProgramStatePartialTrait {
-  static void *GDMIndex() { static int index = 0; retur

[PATCH] D52807: [COFF, ARM64] Add _InterlockedCompareExchangePointer_nf intrinsic

2018-10-04 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:3003
+  case Builtin::BI_InterlockedCompareExchangePointer:
+  case Builtin::BI_InterlockedCompareExchangePointer_nf: {
 llvm::Type *RTy;

mgrang wrote:
> rnk wrote:
> > Is the no fence version really equivalent to this seq_cst version here?
> I don't see InterlockedCompareExchangePointer creating a fence but it should. 
> (since it is the fence version). So maybe that needs to be fixed (and 
> possibly other fence functions).
> 
> InterlockedCompareExchangePointer_nf should not create a fence so the current 
> implementation seems correct.
Hm, if we're supposed to have fences, we're probably missing them everywhere. I 
thought the atomicrmw orderings were enough, but that shows what I know about 
the C++ memory model. =p

We don't generate a fence for this intrinsic when MSVC does:
```
unsigned char test_arm(long *base, long idx) {
  return _interlockedbittestandreset_acq(base, idx);
}
```

@efriedma, is MSVC over-emitting extra fences, or are we under-emitting? If 
this is their "bug", should we be bug-for-bug compatible with it so we get the 
same observable memory states?


Repository:
  rC Clang

https://reviews.llvm.org/D52807



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: test/Sema/builtins.c:125
 
+// __builtin_constant_p cannot resolve non-constants as a file scoped array.
+int expr;

such as

Otherwise it's possible to read this as the non-constants being resolved to a 
file scoped array.


https://reviews.llvm.org/D52854



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:15621-15623
+for (InitListExpr::iterator II = E->begin(), IE = E->end();
+ II != IE; ++II)
+  Visit(*II);

nickdesaulniers wrote:
> void wrote:
> > nickdesaulniers wrote:
> > > nickdesaulniers wrote:
> > > > `std::for_each`?
> > > Sorry, posted that comment as you uploaded the next version.  This should 
> > > be highlighting L15618 to L15620.
> > That's no used anywhere else in the source code. Maybe there's another 
> > mechanism that they use?
> Oh, looks like it was only added to C++17; I think Clang+LLVM use a lower 
> language version.  Did C++ stl really not have a way to apply the same 
> function over an iterator until C++17?
At least a range for would make this more concise:

```
for (auto& II : *E)
  Visit(II);
```


https://reviews.llvm.org/D52854



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Rather than adding a `CanDelayEvaluation` flag to call expressions, I think it 
would be substantially better to introduce a new `Expr` wrapper node for 
expressions that are required to be constant expressions. (That'd eventually 
also give us a place to cache the evaluated value of such an expression, where 
today we recompute it each time it's needed.) Essentially, you would add a 
`ConstExpr` node (or similar), teach `IgnoreImplicit` and friends to step over 
it, and add it in the places where we semantically require an expression to be 
a constant expression. This has various benefits: there are other upcoming 
language features (in C++20) that require this knowledge and don't necessarily 
have a `CallExpr` to tie it to, and it gives us a place to stash an evaluated 
value, and it gives IR generation a simple way to detect expressions that it 
can constant-evaluate rather than emitting.

When the evaluator steps into such an expression, it can track that it's done 
so, and ensure that it always produces a constant value for any 
`__builtin_constant_p` calls in that scope.




Comment at: include/clang/AST/Expr.h:2290
   SourceLocation RParenLoc;
+  bool CanDelayEvaluation;
 

It's not reasonable to make all `CallExpr`s `sizeof(void*)` bytes larger for 
this. If we really need this, you can track it it in the `CallExprBits` on the 
base class. (But you'll also need to extend at least the Serialization and 
ASTImporter code to handle it, and probably TreeTransform too.)

But I don't think you need this.



Comment at: lib/AST/ExprConstant.cpp:8162
+  return Success(true, E);
+if (isa(Arg->IgnoreParenCasts()) &&
+E->getCanDelayEvaluation())

rsmith wrote:
> Your `canDelayEvaluation` check does not appear to cover several of the cases 
> we'd need to check for here. Eg:
> 
> ```
> void f(int n) {
>   enum E { a = __builtin_constant_p(n) }; // ok, a == 0, not an error because 
> a's value is non-constant
> ```
> 
> 
Hmm, OK. Per https://bugs.llvm.org/show_bug.cgi?id=4898#c38, the correct check 
would be whether the reason we found the expression to be non-constant was that 
it tried to read the value of a local variable or function parameter. Eg, for:

```
void f(int x, int y) {
  bool k = __builtin_constant_p(3 + x < 5 * y);
```

... we should defer the `__builtin_constant_p` until after optimization. (And 
we should never do this if the expression has side-effects.) But given that 
your goal is merely to improve the status quo, not to exactly match GCC, this 
may be sufficient.

You should at least check that the variable is non-volatile, though. (More 
generally, check that `Arg` doesn't have side-effects.)



Comment at: lib/AST/ExprConstant.cpp:8162-8164
+if (isa(Arg->IgnoreParenCasts()) &&
+E->getCanDelayEvaluation())
+  return false;

Your `canDelayEvaluation` check does not appear to cover several of the cases 
we'd need to check for here. Eg:

```
void f(int n) {
  enum E { a = __builtin_constant_p(n) }; // ok, a == 0, not an error because 
a's value is non-constant
```





Comment at: lib/AST/ExprConstant.cpp:8164
+E->getCanDelayEvaluation())
+  return false;
+return Success(false, E);

It's not correct to return `false` here without producing a diagnostic 
explaining why the evaluation is non-constant. You can use `Info.FFDiag()` to 
produce a default "invalid subexpression" diagnostic, which is probably 
sufficient given that we won't actually show the diagnostic to the user in most 
cases.



Comment at: lib/Sema/SemaExpr.cpp:5694
 
+  MarkBuiltinConstantPCannotDelayEvaluation(InitExpr);
   return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, InitExpr);

Why are you marking this? This isn't (necessarily) a context where a constant 
expression is required. (In C, the overall initializer for a global would be, 
but a local-scope compound literal would not.)

Also, this should be in the `Build` function, not in the `ActOn` function.



Comment at: lib/Sema/SemaExpr.cpp:5799
   E->setType(Context.VoidTy); // FIXME: just a place holder for now.
+  MarkBuiltinConstantPCannotDelayEvaluation(E);
   return E;

Likewise here, I don't see the justification for this.


https://reviews.llvm.org/D52854



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


[PATCH] D52843: Update Clang Windows getting started docs

2018-10-04 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343809: Update Clang Windows getting started docs (authored 
by rnk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52843?vs=168205&id=168363#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52843

Files:
  www/get_started.html

Index: www/get_started.html
===
--- www/get_started.html
+++ www/get_started.html
@@ -127,23 +127,21 @@
   
 
 
-If you encounter problems while building Clang, make sure that your LLVM
-checkout is at the same revision as your Clang checkout. LLVM's interfaces
-change over time, and mismatched revisions are not expected to work
-together.
-
 Simultaneously Building Clang and LLVM:
 
 Once you have checked out Clang into the llvm source tree it will build along
 with the rest of llvm. To build all of LLVM and Clang together all at
 once simply run make from the root LLVM directory.
 
-Note: Observe that Clang is technically part of a separate
-Subversion repository. As mentioned above, the latest Clang sources are tied to
-the latest sources in the LLVM tree. You can update your toplevel LLVM project
-and all (possibly unrelated) projects inside it with make
-update. This will run svn update on all subdirectories related
-to subversion. 
+If you encounter problems while building Clang, make sure that your LLVM
+checkout is at the same revision as your Clang checkout. LLVM's interfaces
+change over time, and mismatched revisions are not expected to work
+together. We recommend writing a script to automatically run svn up in
+each repository to keep them synchronized. Alternatively, you may consider using
+the unofficial
+https://llvm.org/docs/GettingStarted.html#for-developers-to-work-with-a-git-monorepo";>git monorepo
+which automatically keeps everything in sync at the same revision and lets you
+commit changes atomically across multiple LLVM subprojects.
 
 Using Visual Studio
 
@@ -154,37 +152,37 @@
   Get the required tools:
   
 Subversion.  Source code control program.  Get it from:
-http://subversion.apache.org/packages.html";>
-http://subversion.apache.org/packages.html
+https://subversion.apache.org/packages.html";>
+https://subversion.apache.org/packages.html
 CMake.  This is used for generating Visual Studio solution and
 project files.  Get it from:
-http://www.cmake.org/cmake/resources/software.html";>
-http://www.cmake.org/cmake/resources/software.html
-Visual Studio 2013 or later
-Python.  This is needed only if you will be running the tests
-(which is essential, if you will be developing for clang).
-Get it from:
-http://www.python.org/download/";>
-http://www.python.org/download/
+https://cmake.org/download/";>
+https://cmake.org/download/
+Visual Studio 2015 or later
+Python.  It is used to run the clang test suite. Get it from:
+https://www.python.org/download/";>
+https://www.python.org/download/
 GnuWin32 tools
-These are also necessary for running the tests.
-(Note that the grep from MSYS or Cygwin doesn't work with the tests
-because of embedded double-quotes in the search strings.  The GNU
-grep does work in this case.)
-Get them from http://getgnuwin32.sourceforge.net/";>
+The Clang and LLVM test suite use various GNU core utilities, such as
+grep, sed, and find. The gnuwin32 packages
+are the oldest and most well-tested way to get these tools. However, the
+MSys utilities provided by git for Windows have been known to work.
+Cygwin has worked in the past, but is not well tested.
+If you don't already have the core utilies from some other source, get
+gnuwin32 from http://getgnuwin32.sourceforge.net/";>
 http://getgnuwin32.sourceforge.net/.
   
   
 
   Check out LLVM:
   
-svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
+svn co https://llvm.org/svn/llvm-project/llvm/trunk llvm
   
   
   Check out Clang:
   
  cd llvm\tools
- svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
+ svn co https://llvm.org/svn/llvm-project/cfe/trunk clang
   
   Note:  Some Clang tests are sensitive to the line endings.  Ensure
  that checking out the files does not convert LF line endings to CR+LF.
@@ -195,11 +193,12 @@
 cd ..\..  (back to where you started)
 mkdir build (for building without polluting the source dir)
 cd build
-If you are using Visual Studio 2013:  cmake -G "Visual Studio 12" ..\llvm
-By default, the Visual Studio project files generated by CMake use the
- 32-bit toolset. If you are developing on a 64-bit version of Windows and
- want to use the 64-bit toolset, pass the ``-Thost=x64``

[PATCH] D52843: Update Clang Windows getting started docs

2018-10-04 Thread Reid Kleckner via Phabricator via cfe-commits
rnk marked an inline comment as done.
rnk added a comment.

I'm going to go ahead and commit this. Hopefully it's more accurate and useful 
than what we have, and we can fix any issues in post.


https://reviews.llvm.org/D52843



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


r343809 - Update Clang Windows getting started docs

2018-10-04 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Oct  4 13:34:52 2018
New Revision: 343809

URL: http://llvm.org/viewvc/llvm-project?rev=343809&view=rev
Log:
Update Clang Windows getting started docs

Summary:
- Update the example VS project generation to use VS2017.
- Add docs for generating ninja build files, since they are popular.
- Remove reference to "make update" which no longer exists. Mention the
  monorepo instead.
- Try to explain gnuwin32/coreutils requirements better.
- Use https:// links where possible

Reviewers: zturner, STL_MSFT

Subscribers: jfb, cfe-commits

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

Modified:
cfe/trunk/www/get_started.html

Modified: cfe/trunk/www/get_started.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/get_started.html?rev=343809&r1=343808&r2=343809&view=diff
==
--- cfe/trunk/www/get_started.html (original)
+++ cfe/trunk/www/get_started.html Thu Oct  4 13:34:52 2018
@@ -127,23 +127,21 @@ follows:
   
 
 
-If you encounter problems while building Clang, make sure that your LLVM
-checkout is at the same revision as your Clang checkout. LLVM's interfaces
-change over time, and mismatched revisions are not expected to work
-together.
-
 Simultaneously Building Clang and LLVM:
 
 Once you have checked out Clang into the llvm source tree it will build 
along
 with the rest of llvm. To build all of LLVM and Clang together all at
 once simply run make from the root LLVM directory.
 
-Note: Observe that Clang is technically part of a separate
-Subversion repository. As mentioned above, the latest Clang sources are tied to
-the latest sources in the LLVM tree. You can update your toplevel LLVM project
-and all (possibly unrelated) projects inside it with make
-update. This will run svn update on all subdirectories 
related
-to subversion. 
+If you encounter problems while building Clang, make sure that your LLVM
+checkout is at the same revision as your Clang checkout. LLVM's interfaces
+change over time, and mismatched revisions are not expected to work
+together. We recommend writing a script to automatically run svn up in
+each repository to keep them synchronized. Alternatively, you may consider 
using
+the unofficial
+https://llvm.org/docs/GettingStarted.html#for-developers-to-work-with-a-git-monorepo";>git
 monorepo
+which automatically keeps everything in sync at the same revision and lets you
+commit changes atomically across multiple LLVM subprojects.
 
 Using Visual Studio
 
@@ -154,37 +152,37 @@ Visual Studio:
   Get the required tools:
   
 Subversion.  Source code control program.  Get it from:
-http://subversion.apache.org/packages.html";>
-http://subversion.apache.org/packages.html
+https://subversion.apache.org/packages.html";>
+https://subversion.apache.org/packages.html
 CMake.  This is used for generating Visual Studio solution and
 project files.  Get it from:
-http://www.cmake.org/cmake/resources/software.html";>
-http://www.cmake.org/cmake/resources/software.html
-Visual Studio 2013 or later
-Python.  This is needed only if you will be running the tests
-(which is essential, if you will be developing for clang).
-Get it from:
-http://www.python.org/download/";>
-http://www.python.org/download/
+https://cmake.org/download/";>
+https://cmake.org/download/
+Visual Studio 2015 or later
+Python.  It is used to run the clang test suite. Get it from:
+https://www.python.org/download/";>
+https://www.python.org/download/
 GnuWin32 tools
-These are also necessary for running the tests.
-(Note that the grep from MSYS or Cygwin doesn't work with the tests
-because of embedded double-quotes in the search strings.  The GNU
-grep does work in this case.)
-Get them from http://getgnuwin32.sourceforge.net/";>
+The Clang and LLVM test suite use various GNU core utilities, such as
+grep, sed, and find. The gnuwin32 packages
+are the oldest and most well-tested way to get these tools. However, 
the
+MSys utilities provided by git for Windows have been known to work.
+Cygwin has worked in the past, but is not well tested.
+If you don't already have the core utilies from some other source, get
+gnuwin32 from http://getgnuwin32.sourceforge.net/";>
 http://getgnuwin32.sourceforge.net/.
   
   
 
   Check out LLVM:
   
-svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
+svn co https://llvm.org/svn/llvm-project/llvm/trunk llvm
   
   
   Check out Clang:
   
  cd llvm\tools
- svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
+ svn co https://llvm.org/svn/llvm-project/cfe/trunk clang
   
   Note:  Some Clang tests are sensitive to the line endings.  
Ensure
  that checking out the files does not convert LF line endings 

[PATCH] D52888: Thread safety analysis: Handle conditional expression in getTrylockCallExpr

2018-10-04 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: test/SemaCXX/warn-thread-safety-analysis.cpp:1879-1880
+  void foo13() {
+if (mu.TryLock() ? 1 : 0)
+  mu.Unlock();
+  }

aaron.ballman wrote:
> aaronpuchert wrote:
> > aaron.ballman wrote:
> > > Can you add a test that shows we get it right even if the user does 
> > > something less than practical, like:
> > > ```
> > > if (mu.TryLock() ? mu.TryLock() : false); // Warn about double lock
> > > if (mu.TryLock() ? mu.Unlock(), 1 : 0)
> > >   mu.Unlock(); // Warn about unlocking unheld lock
> > > if (mu.TryLock() ? 1 : mu.Unlock(), 0)
> > >   mu.Unlock(); // Warn about unlocking an unheld lock
> > > if (mu.TryLock() ? (true ? mu.TryLock() : false) : false); // Warn about 
> > > double lock
> > > ```
> > I'm afraid these don't work as expected if we don't branch on `?:` as 
> > before. Basically we treat this as if both conditions where evaluated 
> > unconditionally.
> > 
> > On calling a try-lock function, no lock is immediately acquired. Only when 
> > we branch on the result of that try-lock call is the mutex added to the 
> > capability set on the appropriate branch. Now if we branch on `?:` (the 
> > situation before this change), we are going to complain about conditionally 
> > held locks on the join point in @hokein's use case, and if we don't branch 
> > (the behavior after this change), we are not treating your examples 
> > correctly. I'm not sure we can treat both as intended.
> > 
> > I'm slightly leaning towards not branching: the C++ standard says that only 
> > the [used expression is actually 
> > evaluated](https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator),
> >  but I think it's not considered good practice to have side effects in a 
> > ternary operator. (I can't actually find it anywhere besides a discussion 
> > on [Hacker News](https://news.ycombinator.com/item?id=14810994). Personally 
> > I would prefer to use an if-statement if one of the expressions has 
> > side-effects.)
> > 
> > Tell me what you think.
> I agree that we don't want to encourage complex code in ternary operators, 
> but that complexity does come up often as a result of macro expansion. It 
> feels like there isn't a good answer here because either approach will have 
> unexpected results.
> 
> I'll let @delesley be the tie-breaker on whether we follow ternary branches 
> or not, but if we decide to accept this patch and not follow branches, I 
> think we should capture those test cases as expected false negatives with a 
> comment about why they happen and why it's expected behavior.
> 
> Related, does this patch then impact the behavior of code like:
> ```
> void f(Mutex &M) {
>   M.Lock();
> }
> 
> void g() {
>   Mutex mu;
>   (void)(true ? f(mu) : (void)0);
>   mu.Unlock(); // Ok
> }
> ```
> 
No, this is not affected. There will be a warning independently of this patch. 
We notice that the lock is held on only one branch after joining them.

I think my wording was a bit unfortunate: we still follow the ordinary CFG. On 
try-lock the lock is not acquired immediately, only when we branch on the 
return value. So we weaken the usual requirement of "no conditional locks" for 
the period between the try-lock call and the branch. That was the situation 
before this patch already.

With this patch `?:` branches on the return value of a try-lock are no longer 
considered as possible acquisition points. We postpone the acquisition even 
further to another (more obvious) branch like an `if` statement that uses the 
try-lock return result. To that end we inspect possible `ConditionalExpr`s so 
that we can derive which branch holds the lock even when these are used.


Repository:
  rC Clang

https://reviews.llvm.org/D52888



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:15621-15623
+for (InitListExpr::iterator II = E->begin(), IE = E->end();
+ II != IE; ++II)
+  Visit(*II);

void wrote:
> nickdesaulniers wrote:
> > nickdesaulniers wrote:
> > > `std::for_each`?
> > Sorry, posted that comment as you uploaded the next version.  This should 
> > be highlighting L15618 to L15620.
> That's no used anywhere else in the source code. Maybe there's another 
> mechanism that they use?
Oh, looks like it was only added to C++17; I think Clang+LLVM use a lower 
language version.  Did C++ stl really not have a way to apply the same function 
over an iterator until C++17?


https://reviews.llvm.org/D52854



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:15621-15623
+for (InitListExpr::iterator II = E->begin(), IE = E->end();
+ II != IE; ++II)
+  Visit(*II);

nickdesaulniers wrote:
> nickdesaulniers wrote:
> > `std::for_each`?
> Sorry, posted that comment as you uploaded the next version.  This should be 
> highlighting L15618 to L15620.
That's no used anywhere else in the source code. Maybe there's another 
mechanism that they use?


https://reviews.llvm.org/D52854



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:15621-15623
+for (InitListExpr::iterator II = E->begin(), IE = E->end();
+ II != IE; ++II)
+  Visit(*II);

nickdesaulniers wrote:
> `std::for_each`?
Sorry, posted that comment as you uploaded the next version.  This should be 
highlighting L15618 to L15620.


https://reviews.llvm.org/D52854



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:15621-15623
+for (InitListExpr::iterator II = E->begin(), IE = E->end();
+ II != IE; ++II)
+  Visit(*II);

`std::for_each`?


https://reviews.llvm.org/D52854



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 168356.
void added a comment.

Removed unused field.


https://reviews.llvm.org/D52854

Files:
  include/clang/AST/Expr.h
  include/clang/Sema/Sema.h
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  test/Analysis/builtin-functions.cpp
  test/Sema/builtins.c

Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -122,6 +122,14 @@
  __builtin_constant_p(1, 2); // expected-error {{too many arguments}}
 }
 
+// __builtin_constant_p cannot resolve non-constants as a file scoped array.
+int expr;
+char y[__builtin_constant_p(expr) ? -1 : 1]; // no warning, the builtin is false.
+
+// no warning, the builtin is false.
+struct foo { int a; };
+struct foo x = (struct foo) { __builtin_constant_p(42) ? 37 : 927 };
+
 const int test17_n = 0;
 const char test17_c[] = {1, 2, 3, 0};
 const char test17_d[] = {1, 2, 3, 4};
@@ -168,14 +176,17 @@
   // a builtin.
   ASSERT(OPT("abc"));
   ASSERT(!OPT("abcd"));
+
   // In these cases, the strlen is non-constant, but the __builtin_constant_p
-  // is 0: the array size is not an ICE but is foldable.
-  ASSERT(!OPT(test17_c));// expected-warning {{folded}}
+  // is 0: the array size is not an ICE.
+  ASSERT(!OPT(test17_c));// no warning expected
+  ASSERT(!OPT((char*)test17_c)); // no warning expected
+  ASSERT(!OPT(test17_d));// no warning expected
+  ASSERT(!OPT((char*)test17_d)); // no warning expected
+
+  // These are foldable.
   ASSERT(!OPT(&test17_c[0]));// expected-warning {{folded}}
-  ASSERT(!OPT((char*)test17_c)); // expected-warning {{folded}}
-  ASSERT(!OPT(test17_d));// expected-warning {{folded}}
   ASSERT(!OPT(&test17_d[0]));// expected-warning {{folded}}
-  ASSERT(!OPT((char*)test17_d)); // expected-warning {{folded}}
 
 #undef OPT
 #undef T
@@ -287,3 +298,18 @@
   memcpy(buf, src, 11); // expected-warning{{'memcpy' will always overflow; destination buffer has size 10, but size argument is 11}}
   my_memcpy(buf, src, 11); // expected-warning{{'__builtin___memcpy_chk' will always overflow; destination buffer has size 10, but size argument is 11}}
 }
+
+size_t test24(int a) {
+  char x[__builtin_constant_p(a) ? -1 : 1]; // no warning expected
+  return strlen(x);
+}
+
+__attribute__((always_inline))
+size_t test25(int a) {
+  char x[__builtin_constant_p(a) ? 1 : -1]; // no warning expected
+  return strlen(x);
+}
+
+size_t test26() {
+  return test25(2);
+}
Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -70,14 +70,14 @@
   const int j = 2;
   constexpr int k = 3;
   clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning {{FALSE}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning {{TRUE}}
 }
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4435,6 +4435,11 @@
 checkNullabilityConsistency(S, SimplePointerKind::Array, DeclType.Loc);
   }
 
+  if (ArraySize && !D.isExpressionContext())
+// Mark all __builtin_constant_p() calls in an array size expression as
+// needing to be evaluated early.
+S.MarkBuiltinConstantPCannotDelayEvaluation(ArraySize);
+
   T = S.BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals,
SourceRange(DeclType.Loc, DeclType.EndLoc), Name);
   break;
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -5691,6 +5691,7 @@
   if (!TInfo)
 TInfo = Context.getTrivialTypeSourceInfo(literalType);
 
+  MarkBuiltinConstantPCannotDelayEvaluation(InitExpr);
   return BuildCompoundLiteralExpr(LParenL

[PATCH] D52418: [driver][mips] Enable integrated assembler for MIPS64 except N32 ABI selected

2018-10-04 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm, sorry it got lost.


Repository:
  rC Clang

https://reviews.llvm.org/D52418



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


[PATCH] D52892: [Clang-tidy] readability check to convert numerical constants to std::numeric_limits

2018-10-04 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/readability/NumericalCostantsToMaxIntCheck.cpp:44
+SrcMgr::CharacteristicKind FileType) {
+
+  if (FileName == "limits") {

Unnecessary empty line.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52892



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


[PATCH] D52838: [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Needs a testcase for the error message like we have for other intrinsics in 
test/Sema/builtins-arm64.c .  Otherwise LGTM.


https://reviews.llvm.org/D52838



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


[PATCH] D52395: Thread safety analysis: Require exclusive lock for passing by non-const reference

2018-10-04 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley added a comment.

For future patches, please add Richard Trieu (rtr...@google.com) as a 
subscriber.  I will continue to try and do code reviews, but Richard is on the 
team that actually rolls out new compiler changes.  Thanks!

BTW, the issue is not just that changes may introduce false positives.  Even if 
it's a true positive, you risk breaking the build.


Repository:
  rC Clang

https://reviews.llvm.org/D52395



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


[PATCH] D52581: [AST] Revert mangling changes from r339428

2018-10-04 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343808: [AST] Revert mangling changes from r339428 (authored 
by smeenai, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52581?vs=167219&id=168354#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52581

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenObjCXX/arc-marker-funclet.mm
  test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
  test/CodeGenObjCXX/msabi-objc-extensions.mm
  test/CodeGenObjCXX/msabi-objc-types.mm

Index: test/CodeGenObjCXX/msabi-objc-extensions.mm
===
--- test/CodeGenObjCXX/msabi-objc-extensions.mm
+++ test/CodeGenObjCXX/msabi-objc-extensions.mm
@@ -7,92 +7,91 @@
 @class J;
 
 void f(id, id, id, id) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjCPAU.objc_object@@01@Z"
+// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjCPAUobjc_object@@01@Z"
 
 void f(id, id, id, id) {}
-// CHECK-LABEL: "?f@@YAXPAU.objc_object@@PAU?$.objc_object@U?$Protocol@UP@@@__ObjC10@Z"
+// CHECK-LABEL: "?f@@YAXPAUobjc_object@@PAU?$objc_object@U?$Protocol@UP@@@__ObjC10@Z"
 
 void f(id, id) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC0@Z"
+// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjC0@Z"
 
 void f(id) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjC@Z"
 
 void f(id) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2Z"
+// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2Z"
 
 void f(Class) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_class@U?$Protocol@UP@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXPAU?$objc_class@U?$Protocol@UP@@@__ObjC@Z"
 
 void f(Class) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_class@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2Z"
+// CHECK-LABEL: "?f@@YAXPAU?$objc_class@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2Z"
 
 void f(I *) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXPAU?$I@U?$Protocol@UP@@@__ObjC@Z"
 
 void f(I *) {}
-// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2Z"
+// CHECK-LABEL: "?f@@YAXPAU?$I@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2Z"
 
 template 
 struct S {};
 
 void f(S<__unsafe_unretained id>) {}
-// CHECK-LABEL: "?f@@YAXU?$S@PAU.objc_object@Z"
+// CHECK-LABEL: "?f@@YAXU?$S@PAUobjc_object@Z"
 
 void f(S<__autoreleasing id>) {}
-// CHECK-LABEL: "?f@@YAXU?$S@U?$Autoreleasing@PAU.objc_object@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXU?$S@U?$Autoreleasing@PAUobjc_object@@@__ObjC@Z"
 
 void f(S<__strong id>) {}
-// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU.objc_object@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAUobjc_object@@@__ObjC@Z"
 
 void f(S<__weak id>) {}
-// CHECK-LABEL: "?f@@YAXU?$S@U?$Weak@PAU.objc_object@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXU?$S@U?$Weak@PAUobjc_object@@@__ObjC@Z"
 
 void w(__weak id) {}
-// CHECK-LABEL: "?w@@YAXPAU.objc_object@@@Z"
+// CHECK-LABEL: "?w@@YAXPAUobjc_object@@@Z"
 
 void s(__strong id) {}
-// CHECK-LABEL: "?s@@YAXPAU.objc_object@@@Z"
+// CHECK-LABEL: "?s@@YAXPAUobjc_object@@@Z"
 
 void a(__autoreleasing id) {}
-// CHECK-LABEL: "?a@@YAXPAU.objc_object@@@Z"
+// CHECK-LABEL: "?a@@YAXPAUobjc_object@@@Z"
 
 void u(__unsafe_unretained id) {}
-// CHECK-LABEL: "?u@@YAXPAU.objc_object@@@Z"
+// CHECK-LABEL: "?u@@YAXPAUobjc_object@@@Z"
 
 S<__autoreleasing id> g() { return S<__autoreleasing id>(); }
-// CHECK-LABEL: "?g@@YA?AU?$S@U?$Autoreleasing@PAU.objc_object@@@__ObjCXZ"
+// CHECK-LABEL: "?g@@YA?AU?$S@U?$Autoreleasing@PAUobjc_object@@@__ObjCXZ"
 
 __autoreleasing id h() { return nullptr; }
-// CHECK-LABEL: "?h@@YAPAU.objc_object@@XZ"
+// CHECK-LABEL: "?h@@YAPAUobjc_object@@XZ"
 
 void f(I *) {}
-// CHECK-LABEL: "?f@@YAXPAU.objc_cls_I@@@Z"
+// CHECK-LABEL: "?f@@YAXPAUI@@@Z"
 
 void f(__kindof I *) {}
-// CHECK-LABEL: "?f@@YAXPAU?$KindOf@U.objc_cls_I@@@__ObjC@@@Z"
+// CHECK-LABEL: "?f@@YAXPAU?$KindOf@UI@@@__ObjC@@@Z"
 
 void f(__kindof I *) {}
-// CHECK-LABEL: "?f@@YAXPAU?$KindOf@U?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@__ObjC@@@Z"
+// CHECK-LABEL: "?f@@YAXPAU?$KindOf@U?$I@U?$Protocol@UP@@@__ObjC@__ObjC@@@Z"
 
 void f(S) {}
-// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU.objc_cls_I@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAUI@@@__ObjC@Z"
 
 void f(S<__kindof I *>) {}
-// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU?$KindOf@U.objc_cls_I@@@__ObjC@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU?$KindOf@UI@@@__ObjC@@@__ObjC@Z"
 
 void f(S<__kindof I *>) {}
-// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU?$KindOf@U?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@__ObjC@@@__ObjC@Z"
+// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU?$K

r343808 - [AST] Revert mangling changes from r339428

2018-10-04 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Thu Oct  4 12:50:14 2018
New Revision: 343808

URL: http://llvm.org/viewvc/llvm-project?rev=343808&view=rev
Log:
[AST] Revert mangling changes from r339428

As discussed in https://reviews.llvm.org/D50144, we want Obj-C classes
to have the same mangling as C++ structs, to support headers like the
following:

```
@class I;
struct I;

void f(I *);
```

since the header can be used from both C++ and Obj-C++ TUs, and we want
a consistent mangling across the two to prevent link errors. Itanium
mangles both the same way, and so should the MS ABI.

The main concern with having the same mangling for C++ structs and Obj-C
classes was that we want to treat them differently for the purposes of
exception handling, e.g. we don't want a C++ catch statement for a
struct to be able to catch an Obj-C class with the same name as the
struct. We can accomplish this by mangling Obj-C class names differently
in their RTTI, which I'll do in a follow-up patch.

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

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm
cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm
cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=343808&r1=343807&r2=343808&view=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Oct  4 12:50:14 2018
@@ -482,7 +482,7 @@ void MicrosoftCXXNameMangler::mangle(con
 mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD));
   else if (const VarDecl *VD = dyn_cast(D))
 mangleVariableEncoding(VD);
-  else if (!isa(D))
+  else
 llvm_unreachable("Tried to mangle unexpected NamedDecl!");
 }
 
@@ -1951,13 +1951,13 @@ void MicrosoftCXXNameMangler::mangleType
 llvm_unreachable("placeholder types shouldn't get to name mangling");
 
   case BuiltinType::ObjCId:
-mangleArtificalTagType(TTK_Struct, ".objc_object");
+mangleArtificalTagType(TTK_Struct, "objc_object");
 break;
   case BuiltinType::ObjCClass:
-mangleArtificalTagType(TTK_Struct, ".objc_class");
+mangleArtificalTagType(TTK_Struct, "objc_class");
 break;
   case BuiltinType::ObjCSel:
-mangleArtificalTagType(TTK_Struct, ".objc_selector");
+mangleArtificalTagType(TTK_Struct, "objc_selector");
 break;
 
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
@@ -2637,10 +2637,9 @@ void MicrosoftCXXNameMangler::mangleType
 
 void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, 
Qualifiers,
  SourceRange) {
-  // ObjC interfaces are mangled as if they were structs with a name that is
-  // not a valid C/C++ identifier
+  // ObjC interfaces have structs underlying them.
   mangleTagTypeKind(TTK_Struct);
-  mangle(T->getDecl(), ".objc_cls_");
+  mangleName(T->getDecl());
 }
 
 void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T,
@@ -2661,11 +2660,11 @@ void MicrosoftCXXNameMangler::mangleType
 
   Out << "?$";
   if (T->isObjCId())
-mangleSourceName(".objc_object");
+mangleSourceName("objc_object");
   else if (T->isObjCClass())
-mangleSourceName(".objc_class");
+mangleSourceName("objc_class");
   else
-mangleSourceName((".objc_cls_" + T->getInterface()->getName()).str());
+mangleSourceName(T->getInterface()->getName());
 
   for (const auto &Q : T->quals())
 mangleObjCProtocol(Q);

Modified: cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm?rev=343808&r1=343807&r2=343808&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm Thu Oct  4 12:50:14 2018
@@ -10,7 +10,7 @@ void g() {
   }
 }
 
-// CHECK: call i8* @"?f@@YAPAU.objc_object@@XZ"() [ "funclet"(token %1) ]
+// CHECK: call i8* @"?f@@YAPAUobjc_object@@XZ"() [ "funclet"(token %1) ]
 // CHECK-NEXT: call void asm sideeffect "movl{{.*}}%ebp, %ebp{{.*}}", ""() [ 
"funclet"(token %1) ]
 
 // The corresponding f() call was invoked from the entry basic block.

Modified: cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm?rev=343808&r1=343807&r2=343808&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm Thu Oct  4 
12:50:14 2018
@@ -9,7 +9,7 @@ struct A {
 
 // Verify that we dest

[PATCH] D52521: [Sema] DR727: Ensure we pick up enclosing template instantiation arguments for a class-scope explicit specialization.

2018-10-04 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/include/clang/AST/DeclTemplate.h:1771-1779
+  void setIsSpecializedMember(bool V = true) { IsSpecializedMember = V; }
+
+  /// If this class template specialization was declared at class scope 
(DR727).
+  /// For example, the specialization G below:
+  ///   struct S {
+  /// template  struct G {};
+  /// template <> struct G {};

rsmith wrote:
> I think this name is confusing, given that we also have 
> `isMemberSpecialization`, which is an entirely different thing.
> 
> Maybe `isInstantiatedSpecialization` would capture the essence here? (That 
> is, this is a partial or explicit specialization that we instantiated from 
> its enclosing template context rather than one that was declared in a 
> non-template context.)
> 
> That also makes me wonder if we need to store additional state for this at 
> all, or if we can determine this by checking whether the (first) declaration 
> `isOutOfLine()`.
> Maybe isInstantiatedSpecialization would capture the essence here? (That is, 
> this is a partial or explicit specialization that we instantiated from its 
> enclosing template context rather than one that was declared in a 
> non-template context.)

But we should still probably return true for a specialization in a non-template 
class even though it wasn't instantiated (it doesn't really matter here, but 
for consistency). The new patch calls this `isClassScopeSpecialization`, what 
do you think of that name?

> That also makes me wonder if we need to store additional state for this at 
> all, or if we can determine this by checking whether the (first) declaration 
> isOutOfLine().

Oh, good point! I think that would work too.


Repository:
  rC Clang

https://reviews.llvm.org/D52521



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


[PATCH] D52521: [Sema] DR727: Ensure we pick up enclosing template instantiation arguments for a class-scope explicit specialization.

2018-10-04 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 168352.
erik.pilkington added a comment.

Address @rsmith's review comments.


https://reviews.llvm.org/D52521

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/member-spec-dr727.cpp

Index: clang/test/SemaCXX/member-spec-dr727.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/member-spec-dr727.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s -emit-llvm -o -
+
+// expected-no-diagnostics
+
+namespace PR39031 {
+template 
+struct S {
+  template 
+  struct Wrapper;
+
+  template <>
+  struct Wrapper {
+template 
+void f(T) {
+  T x;
+}
+  };
+};
+
+void Run() {
+  S::Wrapper().f(1);
+}
+} // namespace PR39031
+
+template  struct is_same { static constexpr bool value = false; };
+template  struct is_same { static constexpr bool value = true; };
+
+namespace t1 {
+template  struct A {
+  template  struct B;
+
+  template <> struct B {
+template  struct C {
+  static_assert(is_same::value);
+  static_assert(is_same::value);
+};
+  };
+};
+
+A::B::C x;
+}
+
+namespace t2 {
+template 
+struct A {
+  template  static constexpr int p = 0;
+  template <> static constexpr int p = 1;
+};
+
+// FIXME: why aren't we selecting the specialization here?
+static_assert(A::p == 0);
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -71,7 +71,8 @@
 dyn_cast(D)) {
   // We're done when we hit an explicit specialization.
   if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
-  !isa(Spec))
+  !isa(Spec) &&
+  !Spec->isClassScopeSpecialization())
 return Result;
 
   Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs());
@@ -113,10 +114,19 @@
 // Add template arguments from a class template instantiation.
 if (ClassTemplateSpecializationDecl *Spec
   = dyn_cast(Ctx)) {
-  // We're done when we hit an explicit specialization.
+  // We're done when we hit an explicit specialization ...
   if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
-  !isa(Spec))
+  !isa(Spec)) {
+// ... unless this explicit specialization is a member of a template
+// (DR727), in which case we need to skip past it to gather the
+// enclosing template argument lists.
+if (Spec->isClassScopeSpecialization()) {
+  Ctx = Spec->getDeclContext();
+  RelativeToPrimary = false;
+  continue;
+}
 break;
+  }
 
   Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs());
 
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -1765,6 +1765,19 @@
 PointOfInstantiation = Loc;
   }
 
+  /// If this class template specialization was declared at class scope, as
+  /// opposed to out-of-line (DR727). For example, G below:
+  ///
+  /// \code
+  /// template  struct S {
+  ///   template  struct G {};
+  ///   template <> struct G {};
+  /// };
+  /// \endcode
+  bool isClassScopeSpecialization() const {
+return !getFirstDecl()->isOutOfLine();
+  }
+
   /// If this class template specialization is an instantiation of
   /// a template (rather than an explicit specialization), return the
   /// class template or class template partial specialization from which it
@@ -2704,6 +2717,19 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
+  /// If this variable template specialization was declared at class scope, as
+  /// opposed to out-of-line (DR727). For example, v below:
+  ///
+  /// \code
+  /// template  struct S {
+  ///   template  static int v;
+  ///   template <> static int v;
+  /// };
+  /// \endcode
+  bool isClassScopeSpecialization() const {
+return !getFirstDecl()->isOutOfLine();
+  }
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52838: [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 168353.

https://reviews.llvm.org/D52838

Files:
  include/clang/Basic/BuiltinsAArch64.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/intrin.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/arm64-microsoft-intrinsics.c


Index: test/CodeGen/arm64-microsoft-intrinsics.c
===
--- test/CodeGen/arm64-microsoft-intrinsics.c
+++ test/CodeGen/arm64-microsoft-intrinsics.c
@@ -66,3 +66,15 @@
 
 // CHECK-MSVC: fence syncscope("singlethread")
 // CHECK-LINUX: error: implicit declaration of function '_ReadWriteBarrier'
+
+unsigned __int64 check_getReg() {
+  unsigned volatile __int64 reg;
+  reg = __getReg(18);
+  reg = __getReg(31);
+  return reg;
+}
+
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !2)
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !3)
+// CHECK-MSVC: !2 = !{!"x18"}
+// CHECK-MSVC: !3 = !{!"sp"}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1749,6 +1749,9 @@
   BuiltinID == AArch64::BI__builtin_arm_wsrp)
 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
 
+  if (BuiltinID == AArch64::BI__getReg)
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
+
   if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
 return true;
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -865,6 +865,13 @@
 #endif
 
 
/**\
+|* MS AArch64 specific
+\**/
+#if defined(__aarch64__)
+unsigned __int64 __getReg(int);
+#endif
+
+/**\
 |* Privileged intrinsics
 
\**/
 #if defined(__i386__) || defined(__x86_64__)
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -6576,6 +6576,23 @@
 return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr");
   }
 
+  if (BuiltinID == AArch64::BI__getReg) {
+APSInt Value;
+if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
+  llvm_unreachable("Sema will ensure that the parameter is constant");
+
+LLVMContext &Context = CGM.getLLVMContext();
+std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
+
+llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
+llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+
+llvm::Value *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+return Builder.CreateCall(F, Metadata);
+  }
+
   if (BuiltinID == AArch64::BI__builtin_arm_clrex) {
 Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex);
 return Builder.CreateCall(F);
Index: include/clang/Basic/BuiltinsAArch64.def
===
--- include/clang/Basic/BuiltinsAArch64.def
+++ include/clang/Basic/BuiltinsAArch64.def
@@ -104,6 +104,7 @@
 TARGET_HEADER_BUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "nh", 
"intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__getReg, "ULLii", "nh", "intrin.h", ALL_MS_LANGUAGES, 
"")
 
 #undef BUILTIN
 #undef LANGBUILTIN


Index: test/CodeGen/arm64-microsoft-intrinsics.c
===
--- test/CodeGen/arm64-microsoft-intrinsics.c
+++ test/CodeGen/arm64-microsoft-intrinsics.c
@@ -66,3 +66,15 @@
 
 // CHECK-MSVC: fence syncscope("singlethread")
 // CHECK-LINUX: error: implicit declaration of function '_ReadWriteBarrier'
+
+unsigned __int64 check_getReg() {
+  unsigned volatile __int64 reg;
+  reg = __getReg(18);
+  reg = __getReg(31);
+  return reg;
+}
+
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !2)
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !3)
+// CHECK-MSVC: !2 = !{!"x18"}
+// CHECK-MSVC: !3 = !{!"sp"}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1749,6 +1749,9 @@
   BuiltinID == AArch64::BI__builtin_arm_wsrp)
 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
 
+  if (BuiltinID == AArch64::BI__getReg)
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
+
   if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
 return true;
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+

[PATCH] D51725: Allow un-setting the compilation database path

2018-10-04 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

So I revisited this today.  In the end, restarting clangd in our IDE works 
well.  It should be merged anytime soon:

https://github.com/theia-ide/theia/pull/3017

But I am wondering what to do with the feature that allows clangd to change 
compilation database path using the `didChangeConfiguration` notification.  In 
my opinion, it's a bug that it's not possible to switch back to use no explicit 
compilation database path, so I'd still like to get this patch merged.  Or, if 
we decide this is really not useful, then it should be removed.  I don't think 
we should keep the feature in the current state, either we fix it or remove it.

Even if right now it's not very expensive to restart clangd, do you foresee a 
situation in the future where it could become more expensive?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51725



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


[PATCH] D52838: [COFF, ARM64] Add __getReg intrinsic

2018-10-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:6589
+std::string Reg = StrVal == "31" ? "sp" :
+  "x" + std::string(StrVal.c_str());
+

Could you just write this as `std::string Reg = Value == 31 ? "sp" : "x" + 
Value.toString(10);`, and get rid of StrVal?


https://reviews.llvm.org/D52838



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


[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p

2018-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:15604
+public EvaluatedExprVisitor {
+  Sema &S;
+

../tools/clang/lib/Sema/SemaExpr.cpp:15619:13: warning: private field 'S' is 
not used [-Wunused-private-field]
  Sema &S;
^



Repository:
  rC Clang

https://reviews.llvm.org/D52854



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


[PATCH] D52814: [PassManager/Sanitizer] Enable usage of ported AddressSanitizer passes with -fsanitize=address

2018-10-04 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 168348.
leonardchan marked an inline comment as done.

Repository:
  rC Clang

https://reviews.llvm.org/D52814

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGen/asan-new-pm.ll


Index: test/CodeGen/asan-new-pm.ll
===
--- /dev/null
+++ test/CodeGen/asan-new-pm.ll
@@ -0,0 +1,31 @@
+; RUN: %clang_cc1 -S -emit-llvm -o - -fexperimental-new-pass-manager 
-fsanitize=address %s | FileCheck %s
+
+; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
+
+define i32 @test_load(i32* %a) sanitize_address {
+entry:
+; CHECK:  %0 = ptrtoint i32* %a to i64
+; CHECK:  %1 = lshr i64 %0, 3
+; CHECK:  %2 = add i64 %1, 2147450880
+; CHECK:  %3 = inttoptr i64 %2 to i8*
+; CHECK:  %4 = load i8, i8* %3
+; CHECK:  %5 = icmp ne i8 %4, 0
+; CHECK:  br i1 %5, label %6, label %12, !prof !0
+
+; CHECK:; :6:  ; preds = %entry
+; CHECK:  %7 = and i64 %0, 7
+; CHECK:  %8 = add i64 %7, 3
+; CHECK:  %9 = trunc i64 %8 to i8
+; CHECK:  %10 = icmp sge i8 %9, %4
+; CHECK:  br i1 %10, label %11, label %12
+
+; CHECK:; :11: ; preds = %6
+; CHECK:  call void @__asan_report_load4(i64 %0)
+; CHECK:  call void asm sideeffect "", ""()
+; CHECK:  unreachable
+
+; CHECK:; :12: ; preds = %6, %entry
+
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -27,6 +27,7 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/SchedulerRegistry.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/AddressSanitizerPass.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LegacyPassManager.h"
@@ -1019,6 +1020,11 @@
CodeGenOpts.DebugPassManager);
   }
 }
+
+if (LangOpts.Sanitize.has(SanitizerKind::Address)) {
+  MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass()));
+  MPM.addPass(AddressSanitizerModulePass());
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We


Index: test/CodeGen/asan-new-pm.ll
===
--- /dev/null
+++ test/CodeGen/asan-new-pm.ll
@@ -0,0 +1,31 @@
+; RUN: %clang_cc1 -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address %s | FileCheck %s
+
+; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
+
+define i32 @test_load(i32* %a) sanitize_address {
+entry:
+; CHECK:  %0 = ptrtoint i32* %a to i64
+; CHECK:  %1 = lshr i64 %0, 3
+; CHECK:  %2 = add i64 %1, 2147450880
+; CHECK:  %3 = inttoptr i64 %2 to i8*
+; CHECK:  %4 = load i8, i8* %3
+; CHECK:  %5 = icmp ne i8 %4, 0
+; CHECK:  br i1 %5, label %6, label %12, !prof !0
+
+; CHECK:; :6:  ; preds = %entry
+; CHECK:  %7 = and i64 %0, 7
+; CHECK:  %8 = add i64 %7, 3
+; CHECK:  %9 = trunc i64 %8 to i8
+; CHECK:  %10 = icmp sge i8 %9, %4
+; CHECK:  br i1 %10, label %11, label %12
+
+; CHECK:; :11: ; preds = %6
+; CHECK:  call void @__asan_report_load4(i64 %0)
+; CHECK:  call void asm sideeffect "", ""()
+; CHECK:  unreachable
+
+; CHECK:; :12: ; preds = %6, %entry
+
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -27,6 +27,7 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/SchedulerRegistry.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/AddressSanitizerPass.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LegacyPassManager.h"
@@ -1019,6 +1020,11 @@
CodeGenOpts.DebugPassManager);
   }
 }
+
+if (LangOpts.Sanitize.has(SanitizerKind::Address)) {
+  MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass()));
+  MPM.addPass(AddressSanitizerModulePass());
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52870: [NestedNameSpecifier] Add missing stream-specific dump methods

2018-10-04 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343807: [NestedNameSpecifier] Add missing stream-specific 
dump methods (authored by steveire, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52870

Files:
  cfe/trunk/include/clang/AST/NestedNameSpecifier.h
  cfe/trunk/lib/AST/NestedNameSpecifier.cpp


Index: cfe/trunk/include/clang/AST/NestedNameSpecifier.h
===
--- cfe/trunk/include/clang/AST/NestedNameSpecifier.h
+++ cfe/trunk/include/clang/AST/NestedNameSpecifier.h
@@ -225,6 +225,8 @@
   /// in debugging.
   void dump(const LangOptions &LO) const;
   void dump() const;
+  void dump(llvm::raw_ostream &OS) const;
+  void dump(llvm::raw_ostream &OS, const LangOptions &LO) const;
 };
 
 /// A C++ nested-name-specifier augmented with source location
Index: cfe/trunk/lib/AST/NestedNameSpecifier.cpp
===
--- cfe/trunk/lib/AST/NestedNameSpecifier.cpp
+++ cfe/trunk/lib/AST/NestedNameSpecifier.cpp
@@ -339,13 +339,20 @@
   OS << "::";
 }
 
-void NestedNameSpecifier::dump(const LangOptions &LO) const {
-  print(llvm::errs(), PrintingPolicy(LO));
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {
+  dump(llvm::errs(), LO);
 }
 
-LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const {
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS) const {
   LangOptions LO;
-  print(llvm::errs(), PrintingPolicy(LO));
+  dump(OS, LO);
+}
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS,
+const LangOptions &LO) const {
+  print(OS, PrintingPolicy(LO));
 }
 
 unsigned


Index: cfe/trunk/include/clang/AST/NestedNameSpecifier.h
===
--- cfe/trunk/include/clang/AST/NestedNameSpecifier.h
+++ cfe/trunk/include/clang/AST/NestedNameSpecifier.h
@@ -225,6 +225,8 @@
   /// in debugging.
   void dump(const LangOptions &LO) const;
   void dump() const;
+  void dump(llvm::raw_ostream &OS) const;
+  void dump(llvm::raw_ostream &OS, const LangOptions &LO) const;
 };
 
 /// A C++ nested-name-specifier augmented with source location
Index: cfe/trunk/lib/AST/NestedNameSpecifier.cpp
===
--- cfe/trunk/lib/AST/NestedNameSpecifier.cpp
+++ cfe/trunk/lib/AST/NestedNameSpecifier.cpp
@@ -339,13 +339,20 @@
   OS << "::";
 }
 
-void NestedNameSpecifier::dump(const LangOptions &LO) const {
-  print(llvm::errs(), PrintingPolicy(LO));
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {
+  dump(llvm::errs(), LO);
 }
 
-LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const {
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS) const {
   LangOptions LO;
-  print(llvm::errs(), PrintingPolicy(LO));
+  dump(OS, LO);
+}
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS,
+const LangOptions &LO) const {
+  print(OS, PrintingPolicy(LO));
 }
 
 unsigned
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52814: [PassManager/Sanitizer] Enable usage of ported AddressSanitizer passes with -fsanitize=address

2018-10-04 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In https://reviews.llvm.org/D52814#1254901, @philip.pfaffe wrote:

> Is this the right place in the pipeline to put the passes? The legacy PM 
> inserts the asan passes at EP_OptimizerLast, why not do the same thing?


I noticed this also and thought adding this using 
`registerScalarOptimizerLateEPCallback` was the initial correct way to add this 
function pass, but it seems that the vector of callbacks this gets added to 
(`ScalarOptimizerLateEPCallbacks` in `buildFunctionSimplificationPipeline`) 
doesn't get called unless some sort of optimization is requested (that is I run 
with `-fexperimental-new-pass-manager -fsanitize=address -O1`) when the 
sanitizer should still be applied even without optimization.

We could force this pipeline to be run if we run 
`PB.buildPerModuleDefaultPipeline()`regardless of the optimization level, but I 
don't know why it's only called if optimization is zero.




Comment at: lib/CodeGen/BackendUtil.cpp:1031-1038
+  MPM.addPass(AddressSanitizerModulePass());
+
+  // Add Function Pass
+  CGSCCPassManager MainCGPipeline(CodeGenOpts.DebugPassManager);
+  MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
+  buildAddressSanitizerPipeline(CodeGenOpts.DebugPassManager)));
+  MPM.addPass(

fedor.sergeev wrote:
> I dont believe CGSCC is appropriate here.
> 
> I would expect to see a simple ModuleToFunction adapter, something like this:
> 
> MPM.addPass(AddressSanitizerModulePass());
> MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerFunctionPass())
> 
> Also, it seems that legacy runs Function sanitizer first and then Module 
> sanitizer after it.
> This sequence does it backwards. Is it intentional?
My bad. I didn't see there was a `createModuleToFunctionPassAdaptor` earlier 
and used CGSCC since that seemed to be how other function passes were added to 
the module.

I also wasn't sure if the order mattered since it seems both passes can be run 
independently of each other and provide different instrumentation. I think 
@vitalybuka might be able to answer that better, Regardless, I switched them 
still so Module runs after Function.


Repository:
  rC Clang

https://reviews.llvm.org/D52814



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


r343807 - [NestedNameSpecifier] Add missing stream-specific dump methods

2018-10-04 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Thu Oct  4 12:22:00 2018
New Revision: 343807

URL: http://llvm.org/viewvc/llvm-project?rev=343807&view=rev
Log:
[NestedNameSpecifier] Add missing stream-specific dump methods

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/NestedNameSpecifier.h
cfe/trunk/lib/AST/NestedNameSpecifier.cpp

Modified: cfe/trunk/include/clang/AST/NestedNameSpecifier.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/NestedNameSpecifier.h?rev=343807&r1=343806&r2=343807&view=diff
==
--- cfe/trunk/include/clang/AST/NestedNameSpecifier.h (original)
+++ cfe/trunk/include/clang/AST/NestedNameSpecifier.h Thu Oct  4 12:22:00 2018
@@ -225,6 +225,8 @@ public:
   /// in debugging.
   void dump(const LangOptions &LO) const;
   void dump() const;
+  void dump(llvm::raw_ostream &OS) const;
+  void dump(llvm::raw_ostream &OS, const LangOptions &LO) const;
 };
 
 /// A C++ nested-name-specifier augmented with source location

Modified: cfe/trunk/lib/AST/NestedNameSpecifier.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NestedNameSpecifier.cpp?rev=343807&r1=343806&r2=343807&view=diff
==
--- cfe/trunk/lib/AST/NestedNameSpecifier.cpp (original)
+++ cfe/trunk/lib/AST/NestedNameSpecifier.cpp Thu Oct  4 12:22:00 2018
@@ -339,13 +339,20 @@ NestedNameSpecifier::print(raw_ostream &
   OS << "::";
 }
 
-void NestedNameSpecifier::dump(const LangOptions &LO) const {
-  print(llvm::errs(), PrintingPolicy(LO));
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {
+  dump(llvm::errs(), LO);
 }
 
-LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const {
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS) const {
   LangOptions LO;
-  print(llvm::errs(), PrintingPolicy(LO));
+  dump(OS, LO);
+}
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS,
+const LangOptions &LO) const {
+  print(OS, PrintingPolicy(LO));
 }
 
 unsigned


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


[PATCH] D52870: [NestedNameSpecifier] Add missing stream-specific dump methods

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

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D52870



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


[PATCH] D52888: Thread safety analysis: Handle conditional expression in getTrylockCallExpr

2018-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Analysis/ThreadSafety.cpp:1445
+  if (!TCond && FCond) {
+Negate = !Negate;
+return getTrylockCallExpr(COP->getCond(), C, Negate);

aaronpuchert wrote:
> aaron.ballman wrote:
> > Rather than do an assignment here, why not just pass `!Negate` directly 
> > below, since you're returning?
> The third parameter of `getTrylockCallExpr` is a (non-const) reference, so I 
> can only pass an lvalue. It's basically a 
> [call-by-reference](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference)
>  pattern.
Ah, I missed that when looking at the code in Phab, thanks for the explanation!



Comment at: test/SemaCXX/warn-thread-safety-analysis.cpp:1879-1880
+  void foo13() {
+if (mu.TryLock() ? 1 : 0)
+  mu.Unlock();
+  }

aaronpuchert wrote:
> aaron.ballman wrote:
> > Can you add a test that shows we get it right even if the user does 
> > something less than practical, like:
> > ```
> > if (mu.TryLock() ? mu.TryLock() : false); // Warn about double lock
> > if (mu.TryLock() ? mu.Unlock(), 1 : 0)
> >   mu.Unlock(); // Warn about unlocking unheld lock
> > if (mu.TryLock() ? 1 : mu.Unlock(), 0)
> >   mu.Unlock(); // Warn about unlocking an unheld lock
> > if (mu.TryLock() ? (true ? mu.TryLock() : false) : false); // Warn about 
> > double lock
> > ```
> I'm afraid these don't work as expected if we don't branch on `?:` as before. 
> Basically we treat this as if both conditions where evaluated unconditionally.
> 
> On calling a try-lock function, no lock is immediately acquired. Only when we 
> branch on the result of that try-lock call is the mutex added to the 
> capability set on the appropriate branch. Now if we branch on `?:` (the 
> situation before this change), we are going to complain about conditionally 
> held locks on the join point in @hokein's use case, and if we don't branch 
> (the behavior after this change), we are not treating your examples 
> correctly. I'm not sure we can treat both as intended.
> 
> I'm slightly leaning towards not branching: the C++ standard says that only 
> the [used expression is actually 
> evaluated](https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator),
>  but I think it's not considered good practice to have side effects in a 
> ternary operator. (I can't actually find it anywhere besides a discussion on 
> [Hacker News](https://news.ycombinator.com/item?id=14810994). Personally I 
> would prefer to use an if-statement if one of the expressions has 
> side-effects.)
> 
> Tell me what you think.
I agree that we don't want to encourage complex code in ternary operators, but 
that complexity does come up often as a result of macro expansion. It feels 
like there isn't a good answer here because either approach will have 
unexpected results.

I'll let @delesley be the tie-breaker on whether we follow ternary branches or 
not, but if we decide to accept this patch and not follow branches, I think we 
should capture those test cases as expected false negatives with a comment 
about why they happen and why it's expected behavior.

Related, does this patch then impact the behavior of code like:
```
void f(Mutex &M) {
  M.Lock();
}

void g() {
  Mutex mu;
  (void)(true ? f(mu) : (void)0);
  mu.Unlock(); // Ok
}
```



Repository:
  rC Clang

https://reviews.llvm.org/D52888



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


[PATCH] D52888: Thread safety analysis: Handle conditional expression in getTrylockCallExpr

2018-10-04 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: lib/Analysis/ThreadSafety.cpp:1445
+  if (!TCond && FCond) {
+Negate = !Negate;
+return getTrylockCallExpr(COP->getCond(), C, Negate);

aaron.ballman wrote:
> Rather than do an assignment here, why not just pass `!Negate` directly 
> below, since you're returning?
The third parameter of `getTrylockCallExpr` is a (non-const) reference, so I 
can only pass an lvalue. It's basically a 
[call-by-reference](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference)
 pattern.



Comment at: test/SemaCXX/warn-thread-safety-analysis.cpp:1879-1880
+  void foo13() {
+if (mu.TryLock() ? 1 : 0)
+  mu.Unlock();
+  }

aaron.ballman wrote:
> Can you add a test that shows we get it right even if the user does something 
> less than practical, like:
> ```
> if (mu.TryLock() ? mu.TryLock() : false); // Warn about double lock
> if (mu.TryLock() ? mu.Unlock(), 1 : 0)
>   mu.Unlock(); // Warn about unlocking unheld lock
> if (mu.TryLock() ? 1 : mu.Unlock(), 0)
>   mu.Unlock(); // Warn about unlocking an unheld lock
> if (mu.TryLock() ? (true ? mu.TryLock() : false) : false); // Warn about 
> double lock
> ```
I'm afraid these don't work as expected if we don't branch on `?:` as before. 
Basically we treat this as if both conditions where evaluated unconditionally.

On calling a try-lock function, no lock is immediately acquired. Only when we 
branch on the result of that try-lock call is the mutex added to the capability 
set on the appropriate branch. Now if we branch on `?:` (the situation before 
this change), we are going to complain about conditionally held locks on the 
join point in @hokein's use case, and if we don't branch (the behavior after 
this change), we are not treating your examples correctly. I'm not sure we can 
treat both as intended.

I'm slightly leaning towards not branching: the C++ standard says that only the 
[used expression is actually 
evaluated](https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator),
 but I think it's not considered good practice to have side effects in a 
ternary operator. (I can't actually find it anywhere besides a discussion on 
[Hacker News](https://news.ycombinator.com/item?id=14810994). Personally I 
would prefer to use an if-statement if one of the expressions has side-effects.)

Tell me what you think.


Repository:
  rC Clang

https://reviews.llvm.org/D52888



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


[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)

2018-10-04 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

It doesn't address the version skew issue, but my blanket argument against any 
new environment variable is the existance of things like `_CL_` and 
`CCC_OVERRIDE_OPTIONS`. You can set any compiler flag you want from the 
environment, so we should standardize on one way of setting options: flags.


https://reviews.llvm.org/D52773



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


[PATCH] D52870: [NestedNameSpecifier] Add missing stream-specific dump methods

2018-10-04 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 168338.
steveire added a comment.

Format


Repository:
  rC Clang

https://reviews.llvm.org/D52870

Files:
  include/clang/AST/NestedNameSpecifier.h
  lib/AST/NestedNameSpecifier.cpp


Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -339,13 +339,20 @@
   OS << "::";
 }
 
-void NestedNameSpecifier::dump(const LangOptions &LO) const {
-  print(llvm::errs(), PrintingPolicy(LO));
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {
+  dump(llvm::errs(), LO);
 }
 
-LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const {
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS) const {
   LangOptions LO;
-  print(llvm::errs(), PrintingPolicy(LO));
+  dump(OS, LO);
+}
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS,
+const LangOptions &LO) const {
+  print(OS, PrintingPolicy(LO));
 }
 
 unsigned
Index: include/clang/AST/NestedNameSpecifier.h
===
--- include/clang/AST/NestedNameSpecifier.h
+++ include/clang/AST/NestedNameSpecifier.h
@@ -225,6 +225,8 @@
   /// in debugging.
   void dump(const LangOptions &LO) const;
   void dump() const;
+  void dump(llvm::raw_ostream &OS) const;
+  void dump(llvm::raw_ostream &OS, const LangOptions &LO) const;
 };
 
 /// A C++ nested-name-specifier augmented with source location


Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -339,13 +339,20 @@
   OS << "::";
 }
 
-void NestedNameSpecifier::dump(const LangOptions &LO) const {
-  print(llvm::errs(), PrintingPolicy(LO));
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {
+  dump(llvm::errs(), LO);
 }
 
-LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const {
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS) const {
   LangOptions LO;
-  print(llvm::errs(), PrintingPolicy(LO));
+  dump(OS, LO);
+}
+
+LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS,
+const LangOptions &LO) const {
+  print(OS, PrintingPolicy(LO));
 }
 
 unsigned
Index: include/clang/AST/NestedNameSpecifier.h
===
--- include/clang/AST/NestedNameSpecifier.h
+++ include/clang/AST/NestedNameSpecifier.h
@@ -225,6 +225,8 @@
   /// in debugging.
   void dump(const LangOptions &LO) const;
   void dump() const;
+  void dump(llvm::raw_ostream &OS) const;
+  void dump(llvm::raw_ostream &OS, const LangOptions &LO) const;
 };
 
 /// A C++ nested-name-specifier augmented with source location
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)

2018-10-04 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

In https://reviews.llvm.org/D52773#1255491, @thakis wrote:

> In https://reviews.llvm.org/D52773#1255093, @zturner wrote:
>
> > I agree magic environment variables are bad, but without it we don’t
> >  address the only current actual use we have for this, which is making the
> >  vs integration print filenames. Detecting compiler version from inside the
> >  integration is hard
>
>
> We need some solution to this anyhow; e.g. say "this now requires clang 8.0", 
> or have a clang version dropdown in the UI (which defaults to the latest 
> release), or something. We can't add an env var for every future flag that 
> the vs integration might want to use.


But it is **very hard** to automatically detect the version from the 
integration.  I tried this and gave up because it was flaky.  So sure, we can 
present a drop-down in the UI, but it could be mismatched, and that would end 
up creating more problems than it solves.

Right now we have exactly 1 use case for showing filenames from clang-cl, and 
there's no good way to satisfy that use case with a command line option.

I agree that we can't add an environment variable for every future flag that 
the VS integration might want to use, but until that happens, YAGNI.  And if 
and when we do need it, if we manage to come up with a solution to the problem, 
we can delete support for the environment variable and make it use the new 
method.


https://reviews.llvm.org/D52773



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


[PATCH] D52794: [analyzer][PlistMacroExpansion] Part 2.: Retrieving the macro name and primitive expansion

2018-10-04 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 168334.

https://reviews.llvm.org/D52794

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -27,8 +27,8 @@
   *ptr = 5; // expected-warning{{Dereference of null pointer}}
 }
 
-// CHECK: name
-// CHECK: expansion
+// CHECK: nameSET_PTR_VAR_TO_NULL
+// CHECK: expansionptr = 0 
 
 #define NULL 0
 #define SET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO \
@@ -40,5 +40,51 @@
   *ptr = 5; // expected-warning{{Dereference of null pointer}}
 }
 
-// CHECK: name
-// CHECK: expansion
+// CHECK: nameSET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO
+// CHECK: expansionptr = 0 
+
+//===--===//
+// Tests for function-like macro expansions.
+//===--===//
+
+void setToNull(int **vptr) {
+  *vptr = nullptr;
+}
+
+#define TO_NULL(x) \
+  setToNull(x)
+
+void functionLikeMacroTest() {
+  int *ptr;
+  TO_NULL(&ptr);
+  *ptr = 5; // expected-warning{{Dereference of null pointer}}
+}
+
+// TODO: Expand argumnts.
+// CHECK: nameTO_NULL
+// CHECK: expansionsetToNull ( x ) 
+
+#define DOES_NOTHING(x) \
+  { \
+int b;  \
+b = 5;  \
+  } \
+  print(x)
+
+#define DEREF(x)   \
+  DOES_NOTHING(x); \
+  *x
+
+void functionLikeNestedMacroTest() {
+  int *a;
+  TO_NULL(&a);
+  DEREF(a) = 5; // expected-warning{{Dereference of null pointer}}
+}
+
+// TODO: Expand argumnts.
+// CHECK: nameTO_NULL
+// CHECK: expansionsetToNull ( x ) 
+
+// TODO: Expand argumnts.
+// CHECK: nameDEREF
+// CHECK: expansion{ int b ; b = 5 ; } print ( x ) ; * x 
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -3,7 +3,7 @@
 
 
  clang_version
-clang version 8.0.0 (http://mainstream.inf.elte.hu/Szelethus/clang 80e1678b9f598ca78bb3b71cf546a63414a37b11) (https://github.com/llvm-mirror/llvm 1ffbf26a1a0a190d69327af875a3337b74a2ce82)
+clang version 8.0.0 (http://mainstream.inf.elte.hu/Szelethus/clang 54f58baf2c799080816023e7f78b92e4f9460078) (https://github.com/llvm-mirror/llvm 1ffbf26a1a0a190d69327af875a3337b74a2ce82)
  diagnostics
  
   
@@ -51,8 +51,8 @@
   col3
   file0
  
- name
- expansion
+ nameSET_PTR_VAR_TO_NULL
+ expansionptr = 0 
 
 
  kindevent
@@ -218,8 +218,8 @@
   col3
   file0
  
- name
- expansion
+ nameSET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO
+ expansionptr = 0 
 
 
  kindevent
@@ -340,10 +340,537 @@

   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line58
+   col3
+   file0
+  
+  
+   line58
+   col5
+   file0
+  
+ 
+end
+ 
+  
+   line59
+   col3
+   file0
+  
+  
+   line59
+   col9
+   file0
+  
+ 
+   
+  
+
+
+ kindmacro_expansion
+ location
+ 
+  line59
+  col3
+  file0
+ 
+ nameTO_NULL
+ expansionsetToNull ( x ) 
+
+
+ kindevent
+ location
+ 
+  line59
+  col3
+  file0
+ 
+ ranges
+ 
+   
+
+ line59
+ col3
+ file0
+
+
+ line59
+ col15
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling 'setToNull'
+ message
+ Calling 'setToNull'
+
+
+ kindevent
+ location
+ 
+  line50
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from 'functionLikeMacroTest'
+ message
+ Entered call from 'functionLikeMacroTest'
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line50
+   col1
+   file0
+  
+  
+   line50
+   col4
+   file0
+  
+ 
+end
+ 
+  
+   line51
+   col3
+   file0
+  
+  
+   line51
+   col3
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line51
+  col3
+  file0
+ 
+ ranges
+ 
+   
+
+ line51
+ 

  1   2   3   >