r334577 - [X86] Remove masking from avx512vbmi2 concat and shift by immediate builtins. Use select builtins instead.

2018-06-13 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Wed Jun 13 00:19:28 2018
New Revision: 334577

URL: http://llvm.org/viewvc/llvm-project?rev=334577&view=rev
Log:
[X86] Remove masking from avx512vbmi2 concat and shift by immediate builtins. 
Use select builtins instead.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512vbmi2intrin.h
cfe/trunk/lib/Headers/avx512vlvbmi2intrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/avx512vbmi2-builtins.c
cfe/trunk/test/CodeGen/avx512vlvbmi2-builtins.c
cfe/trunk/test/Sema/builtins-x86.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334577&r1=334576&r2=334577&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Jun 13 00:19:28 2018
@@ -1238,15 +1238,15 @@ TARGET_BUILTIN(__builtin_ia32_vpermi2var
 TARGET_BUILTIN(__builtin_ia32_vpermi2varhi256, "V16sV16sV16sV16s", "nc", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_vpermi2varhi512, "V32sV32sV32sV32s", "nc", 
"avx512bw")
 
-TARGET_BUILTIN(__builtin_ia32_vpshldd128_mask, "V4iV4iV4iIiV4iUc", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldd256_mask, "V8iV8iV8iIiV8iUc", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldd512_mask, "V16iV16iV16iIiV16iUs", "nc", 
"avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldq128_mask, "V2LLiV2LLiV2LLiIiV2LLiUc", 
"nc", "avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldq256_mask, "V4LLiV4LLiV4LLiIiV4LLiUc", 
"nc", "avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldq512_mask, "V8LLiV8LLiV8LLiIiV8LLiUc", 
"nc", "avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldw128_mask, "V8sV8sV8sIiV8sUc", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldw256_mask, "V16sV16sV16sIiV16sUs", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshldw512_mask, "V32sV32sV32sIiV32sUi", "nc", 
"avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldd128, "V4iV4iV4iIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldd256, "V8iV8iV8iIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldd512, "V16iV16iV16iIi", "nc", 
"avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldq128, "V2LLiV2LLiV2LLiIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldq256, "V4LLiV4LLiV4LLiIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldq512, "V8LLiV8LLiV8LLiIi", "nc", 
"avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldw128, "V8sV8sV8sIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldw256, "V16sV16sV16sIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshldw512, "V32sV32sV32sIi", "nc", 
"avx512vbmi2")
 
 TARGET_BUILTIN(__builtin_ia32_vpshldvd128_mask, "V4iV4iV4iV4iUc", "nc", 
"avx512vl,avx512vbmi2")
 TARGET_BUILTIN(__builtin_ia32_vpshldvd256_mask, "V8iV8iV8iV8iUc", "nc", 
"avx512vl,avx512vbmi2")
@@ -1286,15 +1286,15 @@ TARGET_BUILTIN(__builtin_ia32_vpshrdvw12
 TARGET_BUILTIN(__builtin_ia32_vpshrdvw256_maskz, "V16sV16sV16sV16sUs", "nc", 
"avx512vl,avx512vbmi2")
 TARGET_BUILTIN(__builtin_ia32_vpshrdvw512_maskz, "V32sV32sV32sV32sUi", "nc", 
"avx512vbmi2")
 
-TARGET_BUILTIN(__builtin_ia32_vpshrdd128_mask, "V4iV4iV4iIiV4iUc", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdd256_mask, "V8iV8iV8iIiV8iUc", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdd512_mask, "V16iV16iV16iIiV16iUs", "nc", 
"avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdq128_mask, "V2LLiV2LLiV2LLiIiV2LLiUc", 
"nc", "avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdq256_mask, "V4LLiV4LLiV4LLiIiV4LLiUc", 
"nc", "avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdq512_mask, "V8LLiV8LLiV8LLiIiV8LLiUc", 
"nc", "avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdw128_mask, "V8sV8sV8sIiV8sUc", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdw256_mask, "V16sV16sV16sIiV16sUs", "nc", 
"avx512vl,avx512vbmi2")
-TARGET_BUILTIN(__builtin_ia32_vpshrdw512_mask, "V32sV32sV32sIiV32sUi", "nc", 
"avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdd128, "V4iV4iV4iIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdd256, "V8iV8iV8iIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdd512, "V16iV16iV16iIi", "nc", 
"avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdq128, "V2LLiV2LLiV2LLiIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdq256, "V4LLiV4LLiV4LLiIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdq512, "V8LLiV8LLiV8LLiIi", "nc", 
"avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdw128, "V8sV8sV8sIi", "nc", 
"avx512vl,avx512vbmi2")
+TARGET_BUILTIN(__builtin_ia32_vpshrdw256, "V16sV16sV16sIi", "nc", 
"avx512vl,av

[PATCH] D48116: [libclang] Allow skipping warnings from all included files

2018-06-13 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik created this revision.
Herald added a subscriber: cfe-commits.

Depending on the included files and the used warning flags, e.g. -
Weverything, a huge number of warnings can be reported for included
files. As processing that many diagnostics comes with a performance
impact and not all clients are interested in those diagnostics, add a
flag to skip them.


Repository:
  rC Clang

https://reviews.llvm.org/D48116

Files:
  include/clang-c/Index.h
  include/clang/Basic/Diagnostic.h
  lib/Basic/DiagnosticIDs.cpp
  test/Index/ignore-warnings-from-headers.cpp
  test/Index/ignore-warnings-from-headers.h
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3397,6 +3397,9 @@
   if (options & CXTranslationUnit_KeepGoing)
 Diags->setSuppressAfterFatalError(false);
 
+  if (options & CXTranslationUnit_IgnoreWarningsFromIncludedFiles)
+  Diags->setSuppressWarningsFromIncludedFiles(true);
+
   // Recover resources if we crash before exiting this function.
   llvm::CrashRecoveryContextCleanupRegistrar >
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -84,6 +84,8 @@
 options |= CXTranslationUnit_KeepGoing;
   if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE"))
 options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
+  if (getenv("CINDEXTEST_IGNORE_WARNINGS_FROM_INCLUDED_FILES"))
+options |= CXTranslationUnit_IgnoreWarningsFromIncludedFiles;
 
   return options;
 }
Index: test/Index/ignore-warnings-from-headers.h
===
--- /dev/null
+++ test/Index/ignore-warnings-from-headers.h
@@ -0,0 +1 @@
+void f(int unusedInHeader) {}
Index: test/Index/ignore-warnings-from-headers.cpp
===
--- /dev/null
+++ test/Index/ignore-warnings-from-headers.cpp
@@ -0,0 +1,7 @@
+#include "ignore-warnings-from-headers.h"
+
+void g(int unusedInMainFile) {}
+
+// RUN: env CINDEXTEST_IGNORE_WARNINGS_FROM_INCLUDED_FILES=1 c-index-test -test-load-source function %s -Wunused-parameter 2>&1 | FileCheck %s
+// CHECK-NOT: warning: unused parameter 'unusedInHeader'
+// CHECK: warning: unused parameter 'unusedInMainFile'
Index: lib/Basic/DiagnosticIDs.cpp
===
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -477,6 +477,13 @@
   Result = diag::Severity::Fatal;
   }
 
+  // If requested, ignore warnings from all headers.
+  if (Diag.SuppressWarningsFromIncludedFiles && Result <= diag::Severity::Warning &&
+  Loc.isValid() &&
+  !Diag.getSourceManager().isInMainFile(
+  Diag.getSourceManager().getExpansionLoc(Loc)))
+return diag::Severity::Ignored;
+
   // Custom diagnostics always are emitted in system headers.
   bool ShowInSystemHeader =
   !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
Index: include/clang/Basic/Diagnostic.h
===
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -213,6 +213,9 @@
   // Suppress all diagnostics.
   bool SuppressAllDiagnostics = false;
 
+  // Suppress warnings from all included files.
+  bool SuppressWarningsFromIncludedFiles = false;
+
   // Elide common types of templates.
   bool ElideType = true;
 
@@ -634,6 +637,10 @@
   }
   bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; }
 
+  void setSuppressWarningsFromIncludedFiles(bool Val = true) {
+SuppressWarningsFromIncludedFiles = Val;
+  }
+
   /// Set type eliding, to skip outputting same types occurring in
   /// template types.
   void setElideType(bool Val = true) { ElideType = Val; }
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -1332,7 +1332,17 @@
*
* The function bodies of the main file are not skipped.
*/
-  CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800
+  CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800,
+
+  /**
+   * Used to indicate that warnings from included files should be ignored.
+   *
+   * If set, clang_getDiagnosticSetFromTU() will not report warnings from
+   * included files anymore. This speeds up clang_getDiagnosticSetFromTU() for
+   * the case where these warnings are not of interest, as for an IDE for
+   * example, which typically shows only the diagnostics in the main file.
+   */
+  CXTranslationUnit_IgnoreWarningsFromIncludedFiles = 0x1000
 };
 
 /**
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bi

Re: r334494 - Re-apply r334418 "Enable crash recovery tests on Windows, globs work in the lit internal shell now"

2018-06-13 Thread Hans Wennborg via cfe-commits
The bot turned green:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/10234

On Wed, Jun 13, 2018 at 8:54 AM, Hans Wennborg  wrote:
> As a near term fix, I've tried to shorten the path in r334574. Let's
> see if the bot likes it.
>
> On Wed, Jun 13, 2018 at 6:34 AM, Galina Kistanova via cfe-commits
>  wrote:
>> That could be the case. However, the bot shall not be left red.
>>
>> Hans, could you revert the patch for now, till the problem would be
>> addressed on all the Windows bots one way or another, please?
>> I can take a look at my bots later this week.
>>
>> Thanks
>>
>> Galina
>>
>> On Tue, Jun 12, 2018 at 1:52 PM, Reid Kleckner  wrote:
>>>
>>> The length of that path is about 257, or very near MAX_PATH, which
>>> suggests that the version of rm you are using does not tolerate deep paths.
>>> This has been a long standing problem, and our solution to it was to install
>>> a special version of rm.exe on all of our buildbots that reliably handles
>>> long paths and copes with virus scanners and things.
>>>
>>> We may try to fix this in lit by reimplementing 'rm' in python, but that
>>> is not a near term solution.
>>>
>>> On Tue, Jun 12, 2018 at 1:30 PM Galina Kistanova 
>>> wrote:

 Hello Hans,

 The test Driver/crash-report-modules.m still fails on one of windows
 builder:


 http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/10221

 . . .
 Failing Tests (1):
 Clang :: Driver/crash-report-modules.m

 Please have a look?

 Thanks

 Galina



 On Tue, Jun 12, 2018 at 4:51 AM, Hans Wennborg via cfe-commits
  wrote:
>
> Author: hans
> Date: Tue Jun 12 04:51:22 2018
> New Revision: 334494
>
> URL: http://llvm.org/viewvc/llvm-project?rev=334494&view=rev
> Log:
> Re-apply r334418 "Enable crash recovery tests on Windows, globs work in
> the lit internal shell now"
>
> Plus change run lines from
>
>   not env FOO=bar %clang
>
> to
>
>   env FOO=bar not %clang
>
> To not confuse the internal shell.
>
> Modified:
> cfe/trunk/test/Driver/crash-report-header.h
> cfe/trunk/test/Driver/crash-report-modules.m
> cfe/trunk/test/Driver/crash-report-spaces.c
> cfe/trunk/test/Driver/crash-report.c
>
> Modified: cfe/trunk/test/Driver/crash-report-header.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/crash-report-header.h?rev=334494&r1=334493&r2=334494&view=diff
>
> ==
> --- cfe/trunk/test/Driver/crash-report-header.h (original)
> +++ cfe/trunk/test/Driver/crash-report-header.h Tue Jun 12 04:51:22 2018
> @@ -1,13 +1,10 @@
>  // RUN: rm -rf %t
>  // RUN: mkdir %t
> -// RUN: not env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1
> %clang -fsyntax-only %s 2>&1 | FileCheck %s
> +// RUN: env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 not
> %clang -fsyntax-only %s 2>&1 | FileCheck %s
>  // RUN: cat %t/crash-report-header-*.h | FileCheck
> --check-prefix=CHECKSRC "%s"
>  // RUN: cat %t/crash-report-header-*.sh | FileCheck
> --check-prefix=CHECKSH "%s"
>  // REQUIRES: crash-recovery
>
> -// because of the glob (*.h, *.sh)
> -// REQUIRES: shell
> -
>  #pragma clang __debug parser_crash
>  // CHECK: Preprocessed source(s) and associated run script(s) are
> located at:
>  // CHECK-NEXT: note: diagnostic msg: {{.*}}.h
>
> Modified: cfe/trunk/test/Driver/crash-report-modules.m
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/crash-report-modules.m?rev=334494&r1=334493&r2=334494&view=diff
>
> ==
> --- cfe/trunk/test/Driver/crash-report-modules.m (original)
> +++ cfe/trunk/test/Driver/crash-report-modules.m Tue Jun 12 04:51:22
> 2018
> @@ -1,20 +1,14 @@
>  // RUN: rm -rf %t
>  // RUN: mkdir -p %t/i %t/m %t
>
> -// RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t
> \
> -// RUN: %clang -fsyntax-only %s -I %S/Inputs/module -isysroot %/t/i/
> \
> +// RUN: env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t
> \
> +// RUN: not %clang -fsyntax-only %s -I %S/Inputs/module -isysroot
> %/t/i/ \
>  // RUN: -fmodules -fmodules-cache-path=%t/m/ -DFOO=BAR 2>&1 | FileCheck
> %s
>
>  // RUN: FileCheck --check-prefix=CHECKSRC %s -input-file
> %t/crash-report-*.m
>  // RUN: FileCheck --check-prefix=CHECKSH %s -input-file
> %t/crash-report-*.sh
>  // REQUIRES: crash-recovery
>
> -// because of the glob (*.m, *.sh)
> -// REQUIRES: shell
> -
> -// FIXME: This XFAIL is cargo-culted from crash-report.c. Do we need
> it

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

2018-06-13 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: lib/Lex/LiteralSupport.cpp:1187
+
+  uint64_t Base = (radix == 16) ? 2 : 10;
+  if (BaseShift > 0) {

leonardchan wrote:
> ebevhan wrote:
> > I don't think loops are needed here. BaseShift is essentially Exponent so 
> > it should be possible to implement as a `pow(radix, abs(BaseShift))` and 
> > then either a mul or a div based on whether or not it was positive or 
> > negative.
> There's a chance though that the value represented by `pow(radix, 
> abs(BaseShift))` may be too large to fit into an integer which is why used 
> the loop.
True, but I suspect that can be solved by making BaseShift an APInt with the 
same bitwidth as Val.



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

leonardchan wrote:
> ebevhan wrote:
> > leonardchan wrote:
> > > ebevhan wrote:
> > > > I don't see how these semantics work properly. The specification 
> > > > requires that operations be done in the full precision of both types. 
> > > > You cannot convert the types before performing the operation like this, 
> > > > since the operation will not be done in full precision in that case.
> > > > 
> > > > The operator semantics of Embedded-C require the operand types of 
> > > > binary operators to be different. It's only when you've performed the 
> > > > operation that you are allowed to convert the result to the resulting 
> > > > type.
> > > Initially the idea was to convert both sides to fixed point types, then 
> > > perform standard binary operations between the fixed point types.
> > > 
> > > For the example, a `fract * int` would have the int converted to a fixed 
> > > point type by left shifting it by the scale of the fract, multiplying, 
> > > then right shifting by the scale again to get the resulting fract. The 
> > > only unhandled thing is overflow, but the precision of the fract remains 
> > > the same. The operands would also be casted up beforehand so there was 
> > > enough space to store the result, which was casted down back to the 
> > > original fract after performing the right shift by the scale.
> > > 
> > > Operations between fixed point types would follow a similar process of 
> > > casting both operands to the higher rank fixed point type, and depending 
> > > on the operation, more underlying shifting and casting would be done to 
> > > retain full precision of the higher ranked type.
> > > 
> > > Though I will admit that I did not realize until now that multiplying a 
> > > fixed point type by an integer does not require shifting the integer.
> > I see how you've reasoned; this is how C normally works. The `fract` is of 
> > higher rank than `int` and therefore is the 'common type' of the operation. 
> > However, even though it is higher rank there is no guarantee that you can 
> > perform the operation without overflowing. And overflow matters here; the 
> > spec says that it must be done in the full precision (integral + 
> > fractional) of both types.
> > 
> > > The only unhandled thing is overflow, but the precision of the fract 
> > > remains the same. The operands would also be casted up beforehand so 
> > > there was enough space to store the result, which was casted down back to 
> > > the original fract after performing the right shift by the scale.
> > 
> > The precision remains the same (and while it doesn't have to be the same to 
> > perform an operation, it makes the implementation more regular; things like 
> > addition and subtraction 'just work'), but you cannot perform a conversion 
> > to `fract` *before* the operation itself, since if you do, there's nothing 
> > to 'cast up'. Casting up is needed for things like `fract * fract` to 
> > prevent overflow, but for `fract * int` you need to cast to a type that can 
> > fit both all values of the int and all values of the fract, and *then* you 
> > can cast up before doing the multiplication.
> > 
> > > Operations between fixed point types would follow a similar process of 
> > > casting both operands to the higher rank fixed point type, and depending 
> > > on the operation, more underlying shifting and casting would be done to 
> > > retain full precision of the higher ranked type.
> > 
> > This might work, but I feel there could be edge cases. The E-C fixed-point 
> > ranks are very odd as they don't reflect reality; `short _Accum` cannot be 
> > considered strictly 'above' `long _Fract`, but the former has a higher rank 
> > than the latter. Depending on how the types are specified for a target, 
> > implicit casts between fixed-point types might inadvertantly discard bits, 
> > even though the spec says that operations must be done in full precision.
> I see, so just to confirm, something like a `fract * int` would not result in 
> any implicit casting between either operand, but any special arithmetic, like 
> intermediate storage types or satur

[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-13 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Ross, do you have commit access or do you need someone to commit this for you?


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


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

2018-06-13 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



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

leonardchan wrote:
> ebevhan wrote:
> > leonardchan wrote:
> > > ebevhan wrote:
> > > > I suspect it's still possible to calculate the ibits based on the 
> > > > fbits, even for _Accum.
> > > > 
> > > > Are the unsigned values needed? The fbits for unsigned _Fract are the 
> > > > same as for signed _Fract if SameFBits is set, and +1 otherwise. The 
> > > > same should go for unsigned _Accum, but I don't think it's entirely 
> > > > clear how this affects the integral part.
> > > Similar to the previous comment, if we choose to make SameFBits dependent 
> > > on/controlled by the target, then I think it would be better for the 
> > > target to explicitly specify the integral bits since there could be some 
> > > cases where there may be padding (such as for unsigned _Accum types if 
> > > this flag is set), and in this case, I think it should be explicit that 
> > > the `bit_width != IBits + FBits`.
> > > 
> > > We also can't fill in that padding for the unsigned _Accum types as an 
> > > extra integral bit since the standard says that `"each signed accum type 
> > > has at least as many integral bits as its corresponding unsigned accum 
> > > type".`
> > > 
> > > For the unsigned _Fract values, I think we can get rid of them if we 
> > > choose to keep the flag instead, but it would no longer apply to unsigned 
> > > _Accum types since it would allow for extra padding in these types and 
> > > would conflict with the logic of `bit_width == IBits + FBits`
> > > 
> > > For now, I actually think the simplest option is to keep these target 
> > > properties, but have the target override them individually, with checks 
> > > to make sure the values adhere to the standard.
> > Is it not the case that `bitwidth != IBits + FBits` for signed types only? 
> > Signed types require a sign bit (which is neither a fractional bit nor an 
> > integral bit, according to spec) but unsigned types do not, and if IBits 
> > and FBits for the signed and unsigned types are the same, the MSB is simply 
> > a padding bit, at least for _Accum (for _Fract everything above the fbits 
> > is padding). 
> > 
> > My reasoning for keeping the number of configurable values down was to 
> > limit the number of twiddly knobs to make the implementation simpler. 
> > Granting a lot of freedom is nice, but I suspect that it will be quite hard 
> > to get the implementation working properly for every valid configuration. I 
> > also don't really see much of a reason for `FBits != UFBits` in general. I 
> > know the spec gives a recommendation to implement it that way, but I think 
> > the benefit of normalizing the signed and unsigned representations 
> > outweighs the lost bit in the unsigned type.
> > 
> > It's hard to say what the differences are beyond that since I'm not sure 
> > how you plan on treating padding bits. In our implementation, padding bits 
> > (the MSB in all of the unsigned types for us) after any operation are 
> > zeroed.
> I see. The implementation would be much simpler this way. The initial idea 
> was to treat the padding bits as "don't care" bits where we would mask only 
> the data bits when doing operations like comparisons that look at the whole 
> integer.
That does work, but for binary operations it means you might need multiple 
maskings per operation. If you mask after every operation instead, you only 
need one. In our implementation, the only padding bit we have is the MSB in the 
unsigned types. We simply insert a 'bit clear' after every operation that 
produces an unsigned type (with some exceptions).

The E-C spec says that padding bits are 'unspecified', but implementation-wise, 
they have to be defined to something in order to operate on them. So long as 
you ensure that it is never possible to observe anything but zero in those bits 
from a program perspective, most operations just work. Naturally, there are 
ways to subvert this design. If you have a `signed _Fract *` and cast it to an 
`unsigned _Fract *` and the values happen to be negative, the padding bit will 
be set and you'll get exciting behavior.

Although... I just realized that the topmost half of the `_Fract`s in your 
configuration is all padding. That might make things a bit more complicated for 
things like signed types... Ideally the sign bit would be extended into the 
padding for those.


Repository:
  rC Clang

https://reviews.llvm.org/D46915



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


[PATCH] D47672: [Headers] Add _Interlocked*_HLEAcquire/_HLERelease

2018-06-13 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Nice! Looks good to me.


https://reviews.llvm.org/D47672



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


[PATCH] D47111: : Implement monotonic_buffer_resource.

2018-06-13 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 151112.
Quuxplusone added a comment.
Herald added a subscriber: christof.

- Shrink monotonic_buffer_resource, and make release() not "leak" allocation 
size.

  Repeatedly calling allocate() and release() in a loop should not blow up. I 
originally thought this was required by the Standard, and maybe it is, but that 
was before I discovered this terrible effect, and before Pablo Halpern told me 
that it was not his actual intent.

  Since the only purpose of storing `__next_buffer_size_` in the object was to 
implement the "looping blows up" misfeature, we can now get rid of that field, 
which shrinks `monotonic_buffer_resource` from 56 bytes down to 48 bytes, 
matching Boost.Container's implementation.

- Add `REQUIRES: c++experimental` to all tests (oops).


Repository:
  rCXX libc++

https://reviews.llvm.org/D47111

Files:
  include/experimental/memory_resource
  src/experimental/memory_resource.cpp
  
test/libcxx/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_in_geometric_progression.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/copy_move.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/with_default_resource.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/without_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_deallocate.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_exception_safety.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_initial_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_underaligned_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_zero_sized_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_in_geometric_progression.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_overaligned_request.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_with_initial_size.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/nothing_to_do.pass.cpp

Index: test/std/experimental/memory/memory.resource.monotonic.buffer/nothing_to_do.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.monotonic.buffer/nothing_to_do.pass.cpp
@@ -0,0 +1,13 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+int main()
+{
+}
Index: test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
@@ -0,0 +1,62 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// REQUIRES: c++experimental
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// class monotonic_buffer_resource
+
+#include 
+#include 
+#include 
+#include 
+
+struct assert_on_compare : public std::experimental::pmr::memory_resource
+{
+protected:
+virtual void * do_allocate(size_t, size_t)
+{ assert(false); }
+
+virtual void do_deallocate(void *, size_t, size_t)
+{ assert(false); }
+
+virtual bool do_is_equal(std::experimental::pmr::memory_resource const &) const noexcept
+{ assert(false); }
+};
+
+int main()
+{
+// Same object
+{
+std::experimental::pmr::monotonic_buffer_resource r1;
+std::experimental::pmr::monotonic_buffer_resource r2;
+assert(r1 == r1);
+assert(r1 != r2);
+
+std::experimental::pmr::memory_resource & p1 = r1;
+std::experimental::pmr::memory_resource & p2 = r2;
+assert(p1 == p1);
+assert(p1 != p2);
+assert(p1 == r1);
+assert(r1 == p1);
+assert(p1 != r2);
+assert(r2 != p1);
+ 

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

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

LGTM with a few nits. And comment requests for things that were unclear when 
reading the code.




Comment at: clangd/FuzzyMatch.cpp:269
+   : AwfulScore,
+   MissMatchScore = allowMatch(P, W, Miss)
+? PreMatch[Miss].Score + matchBonus(P, W, Miss)

NIT: maybe split into two declarations?
```
auto MatchMatchScore = ...;
auto MissMatchScore = ;
```



Comment at: clangd/FuzzyMatch.h:56
   //   - GCC 4.8 complains not all values fit if the type is unsigned
   using Action = bool;
   constexpr static Action Miss = false, Match = true;

Maybe add a small doc comment for `Action`? Found myself figuring out what it 
is while reading this patch.



Comment at: clangd/FuzzyMatch.h:79
   CharRole WordRole[MaxWord]; // Word segmentation info
   int WordTypeSet;// Bitmask of 1

[PATCH] D47111: : Implement monotonic_buffer_resource.

2018-06-13 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: include/experimental/memory_resource:489
+memory_resource* __res_;
+size_t __next_buffer_size_;
+};

Quuxplusone wrote:
> I've discovered that Boost.Container does not bother to preserve this state 
> across calls to `release()`. If that's legal, then we can save 8 bytes here. 
> I've asked for an LWG issue to be opened on the subject of "what the heck is 
> `release()` supposed to do anyway."
On discussion with Ion Gaztañaga, Pablo Halpern, and Casey Carter, I've come to 
the conclusion that we *must not* preserve this state across calls to 
`release`, no matter what the Standard currently says, because that leads to 
insanely high memory usage when calling `mr.release()` in a loop. (Casey 
implies that MSVC's implementation has this issue; Pablo confirms that he never 
intended it.)

Fixed my implementation and added a regression test in 
`test/libcxx/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_in_geometric_progression.pass.cpp`.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47111



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


[PATCH] D48083: [clangd] Boost keyword completions.

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

LGTM.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48083



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


[PATCH] D48116: [libclang] Allow skipping warnings from all included files

2018-06-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Cool! That's actually quite a small change with big outcome!




Comment at: include/clang/Basic/Diagnostic.h:216
 
+  // Suppress warnings from all included files.
+  bool SuppressWarningsFromIncludedFiles = false;

Probably mention that it also suppresses everything with lower priority? 



Comment at: lib/Basic/DiagnosticIDs.cpp:484
+  !Diag.getSourceManager().isInMainFile(
+  Diag.getSourceManager().getExpansionLoc(Loc)))
+return diag::Severity::Ignored;

{ } around return


Repository:
  rC Clang

https://reviews.llvm.org/D48116



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


[PATCH] D48071: [clangd] Add an option controlling caching of compile commands.

2018-06-13 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdLSPServer.h:38
   llvm::Optional CompileCommandsDir,
-  const ClangdServer::Options &Opts);
+  const ClangdServer::Options &Opts, bool 
CacheCompileCommands);
 

sammccall wrote:
> (the options split looks a little odd from the outside. One could make an 
> argument for inheriting ClangdLSPServer::Options from ClangdServer::Options 
> and adding the compile-commands/code completion options there. No need to 
> restructure anything in this patch though)
Options struct SG, even though is number of params is manageable, and we have 
just a single call of this ctor at the time.
I'm not a big fan of inheriting data structs, though, would rather use 
composition.



Comment at: clangd/ClangdLSPServer.h:105
+  // Can be null if no caching was requested.
+  std::unique_ptr CachedCDB;
 

sammccall wrote:
> nit: any reason for unique_ptr over optional?
> (With optional, I think it's clear enough to remove the comment)
CachingCompilationDb is non-movable (because of std::mutex field), so we can't 
properly initialize it in ctor-initializers.
And we need it to pass it into `ClangdServer` in ctor-initializers, so it's 
hard to put the init code into the ctor body.
That all looks brittle, but I wouldn't refactor this in this patch.



Comment at: clangd/tool/ClangdMain.cpp:141
+   "come from the compilation databases."),
+llvm::cl::init(false), llvm::cl::Hidden);
+

sammccall wrote:
> init(true) to avoid changing behavior?
This is intentional, it seems `false` is a better default, given that all 
implementation in LLVM cache it all themselves.
We should set to true for our CDB that actually needs it. WDYT?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48071



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


[PATCH] D48068: [clangd] Move caching of compile args out of ClangdServer.

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

- Address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48068

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CompileArgsCache.cpp
  clangd/CompileArgsCache.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h

Index: unittests/clangd/SyncAPI.h
===
--- unittests/clangd/SyncAPI.h
+++ unittests/clangd/SyncAPI.h
@@ -20,8 +20,7 @@
 
 // Calls addDocument and then blockUntilIdleForTest.
 void runAddDocument(ClangdServer &Server, PathRef File, StringRef Contents,
-WantDiagnostics WantDiags = WantDiagnostics::Auto,
-bool SkipCache = false);
+WantDiagnostics WantDiags = WantDiagnostics::Auto);
 
 llvm::Expected
 runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
Index: unittests/clangd/SyncAPI.cpp
===
--- unittests/clangd/SyncAPI.cpp
+++ unittests/clangd/SyncAPI.cpp
@@ -12,8 +12,8 @@
 namespace clangd {
 
 void runAddDocument(ClangdServer &Server, PathRef File, StringRef Contents,
-WantDiagnostics WantDiags, bool SkipCache) {
-  Server.addDocument(File, Contents, WantDiags, SkipCache);
+WantDiagnostics WantDiags) {
+  Server.addDocument(File, Contents, WantDiags);
   if (!Server.blockUntilIdleForTest())
 llvm_unreachable("not idle after addDocument");
 }
Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -390,16 +390,7 @@
 
   // Now switch to C++ mode.
   CDB.ExtraClangFlags = {"-xc++"};
-  // By default addDocument does not check if CompileCommand has changed, so we
-  // expect to see the errors.
-  runAddDocument(Server, FooCpp, SourceContents1);
-  EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
-  runAddDocument(Server, FooCpp, SourceContents2);
-  EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
-  // Passing SkipCache=true will force addDocument to reparse the file with
-  // proper flags.
-  runAddDocument(Server, FooCpp, SourceContents2, WantDiagnostics::Auto,
- /*SkipCache=*/true);
+  runAddDocument(Server, FooCpp, SourceContents2, WantDiagnostics::Auto);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
   // Subsequent addDocument calls should finish without errors too.
   runAddDocument(Server, FooCpp, SourceContents1);
@@ -431,14 +422,7 @@
 
   // Parse without the define, no errors should be produced.
   CDB.ExtraClangFlags = {};
-  // By default addDocument does not check if CompileCommand has changed, so we
-  // expect to see the errors.
-  runAddDocument(Server, FooCpp, SourceContents);
-  EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
-  // Passing SkipCache=true will force addDocument to reparse the file with
-  // proper flags.
-  runAddDocument(Server, FooCpp, SourceContents, WantDiagnostics::Auto,
- /*SkipCache=*/true);
+  runAddDocument(Server, FooCpp, SourceContents, WantDiagnostics::Auto);
   ASSERT_TRUE(Server.blockUntilIdleForTest());
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
   // Subsequent addDocument call should finish without errors too.
@@ -500,10 +484,8 @@
   CDB.ExtraClangFlags.clear();
   DiagConsumer.clear();
   Server.removeDocument(BazCpp);
-  Server.addDocument(FooCpp, FooSource.code(), WantDiagnostics::Auto,
- /*SkipCache=*/true);
-  Server.addDocument(BarCpp, BarSource.code(), WantDiagnostics::Auto,
- /*SkipCache=*/true);
+  Server.addDocument(FooCpp, FooSource.code(), WantDiagnostics::Auto);
+  Server.addDocument(BarCpp, BarSource.code(), WantDiagnostics::Auto);
   ASSERT_TRUE(Server.blockUntilIdleForTest());
 
   EXPECT_THAT(DiagConsumer.filesWithDiags(),
@@ -708,7 +690,7 @@
   Server.addDocument(FilePaths[FileIndex],
  ShouldHaveErrors ? SourceContentsWithErrors
   : SourceContentsWithoutErrors,
- WantDiagnostics::Auto, SkipCache);
+ WantDiagnostics::Auto);
   UpdateStatsOnAddDocument(FileIndex, ShouldHaveErrors);
 };
 
Index: clangd/GlobalCompilationDatabase.h
===
--- clangd/GlobalCompilationDatabase.h
+++ clangd/GlobalCompilationDatabase.h
@@ -85,6 +85,34 @@
   /// is located.
   llvm::Optional CompileCommandsDir;
 };
+
+/// A wrapper around GlobalCompilationDatabase that caches the compile commands.
+/// Note that only results of getCompil

[PATCH] D48068: [clangd] Move caching of compile args out of ClangdServer.

2018-06-13 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/GlobalCompilationDatabase.cpp:137
+  // 'It' may be invalid at this point, recompute it.
+  It = Cached.find(File);
+  if (It != Cached.end())

sammccall wrote:
> `return try_emplace(File, std::move(Command)).second`?
> 
> (This has different behavior if the cache was filled while you unlocked, but 
> it's arguably the right behavior and doesn't really matter).
Thanks, good catch! We'd rather return the cached value rather than the 
computed one.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48068



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


[PATCH] D48071: [clangd] Add an option controlling caching of compile commands.

2018-06-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:141
+   "come from the compilation databases."),
+llvm::cl::init(false), llvm::cl::Hidden);
+

ilya-biryukov wrote:
> sammccall wrote:
> > init(true) to avoid changing behavior?
> This is intentional, it seems `false` is a better default, given that all 
> implementation in LLVM cache it all themselves.
> We should set to true for our CDB that actually needs it. WDYT?
I agree the default should be false, at least eventually.

I'm not sure what you're suggesting though - we change the default value of the 
flag in our own copy when we link against our DB that doesn't cache?

That could work. I wonder if this will break others who might have similar DBs.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48071



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


[clang-tools-extra] r334585 - [clangd] Move caching of compile args out of ClangdServer.

2018-06-13 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Jun 13 02:20:41 2018
New Revision: 334585

URL: http://llvm.org/viewvc/llvm-project?rev=334585&view=rev
Log:
[clangd] Move caching of compile args out of ClangdServer.

Summary:
Caching is now handled by ClangdLSPServer and hidden behind the
GlobalCompilationDatabase interface. This simplifies ClangdServer.
This change also removes the SkipCache flag from addDocument,
which is now obsolete.

No behavioral changes are intended, the clangd binary still caches the
compile commands on the first read.

Reviewers: sammccall

Reviewed By: sammccall

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

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

Removed:
clang-tools-extra/trunk/clangd/CompileArgsCache.cpp
clang-tools-extra/trunk/clangd/CompileArgsCache.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=334585&r1=334584&r2=334585&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Wed Jun 13 02:20:41 2018
@@ -14,7 +14,6 @@ add_clang_library(clangDaemon
   ClangdUnit.cpp
   CodeComplete.cpp
   CodeCompletionStrings.cpp
-  CompileArgsCache.cpp
   Compiler.cpp
   Context.cpp
   Diagnostics.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=334585&r1=334584&r2=334585&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jun 13 02:20:41 2018
@@ -129,11 +129,13 @@ void ClangdLSPServer::onShutdown(Shutdow
 void ClangdLSPServer::onExit(ExitParams &Params) { IsDone = true; }
 
 void ClangdLSPServer::onDocumentDidOpen(DidOpenTextDocumentParams &Params) {
-  if (Params.metadata && !Params.metadata->extraFlags.empty())
-CDB.setExtraFlagsForFile(Params.textDocument.uri.file(),
- std::move(Params.metadata->extraFlags));
-
   PathRef File = Params.textDocument.uri.file();
+  if (Params.metadata && !Params.metadata->extraFlags.empty()) {
+NonCachedCDB.setExtraFlagsForFile(File,
+  std::move(Params.metadata->extraFlags));
+CDB.invalidate(File);
+  }
+
   std::string &Contents = Params.textDocument.text;
 
   DraftMgr.addDraft(File, Contents);
@@ -155,6 +157,7 @@ void ClangdLSPServer::onDocumentDidChang
 // fail rather than giving wrong results.
 DraftMgr.removeDraft(File);
 Server.removeDocument(File);
+CDB.invalidate(File);
 log(llvm::toString(Contents.takeError()));
 return;
   }
@@ -383,7 +386,10 @@ void ClangdLSPServer::onChangeConfigurat
 
   // Compilation database change.
   if (Settings.compilationDatabasePath.hasValue()) {
-CDB.setCompileCommandsDir(Settings.compilationDatabasePath.getValue());
+NonCachedCDB.setCompileCommandsDir(
+Settings.compilationDatabasePath.getValue());
+CDB.clear();
+
 reparseOpenedFiles();
   }
 }
@@ -392,8 +398,8 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
  const clangd::CodeCompleteOptions &CCOpts,
  llvm::Optional CompileCommandsDir,
  const ClangdServer::Options &Opts)
-: Out(Out), CDB(std::move(CompileCommandsDir)), CCOpts(CCOpts),
-  SupportedSymbolKinds(defaultSymbolKinds()),
+: Out(Out), NonCachedCDB(std::move(CompileCommandsDir)), CDB(NonCachedCDB),
+  CCOpts(CCOpts), SupportedSymbolKinds(defaultSymbolKinds()),
   Server(CDB, FSProvider, /*DiagConsumer=*/*this, Opts) {}
 
 bool ClangdLSPServer::run(std::FILE *In, JSONStreamStyle InputStyle) {
@@ -471,6 +477,5 @@ void ClangdLSPServer::onDiagnosticsReady
 void ClangdLSPServer::reparseOpenedFiles() {
   for (const Path &FilePath : DraftMgr.getActiveFiles())
 Server.addDocument(FilePath, *DraftMgr.getDraft(FilePath),
-   WantDiagnostics::Auto,
-   /*SkipCache=*/true);
+   WantDiagnostics::Auto);
 }

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/tru

[PATCH] D47672: [Headers] Add _Interlocked*_HLEAcquire/_HLERelease

2018-06-13 Thread Ethan via Phabricator via cfe-commits
ethanhs accepted this revision.
ethanhs added a comment.

Works great!


https://reviews.llvm.org/D47672



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


[PATCH] D48068: [clangd] Move caching of compile args out of ClangdServer.

2018-06-13 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE334585: [clangd] Move caching of compile args out of 
ClangdServer. (authored by ibiryukov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48068?vs=151113&id=151114#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48068

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CompileArgsCache.cpp
  clangd/CompileArgsCache.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h

Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -119,5 +119,38 @@
   return nullptr;
 }
 
+CachingCompilationDb::CachingCompilationDb(
+const GlobalCompilationDatabase &InnerCDB)
+: InnerCDB(InnerCDB) {}
+
+llvm::Optional
+CachingCompilationDb::getCompileCommand(PathRef File) const {
+  std::unique_lock Lock(Mut);
+  auto It = Cached.find(File);
+  if (It != Cached.end())
+return It->second;
+
+  Lock.unlock();
+  llvm::Optional Command =
+  InnerCDB.getCompileCommand(File);
+  Lock.lock();
+  return Cached.try_emplace(File, std::move(Command)).first->getValue();
+}
+
+tooling::CompileCommand
+CachingCompilationDb::getFallbackCommand(PathRef File) const {
+  return InnerCDB.getFallbackCommand(File);
+}
+
+void CachingCompilationDb::invalidate(PathRef File) {
+  std::unique_lock Lock(Mut);
+  Cached.erase(File);
+}
+
+void CachingCompilationDb::clear() {
+  std::unique_lock Lock(Mut);
+  Cached.clear();
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -12,7 +12,6 @@
 
 #include "ClangdUnit.h"
 #include "CodeComplete.h"
-#include "CompileArgsCache.h"
 #include "Function.h"
 #include "GlobalCompilationDatabase.h"
 #include "Protocol.h"
@@ -122,8 +121,7 @@
   /// When \p SkipCache is true, compile commands will always be requested from
   /// compilation database even if they were cached in previous invocations.
   void addDocument(PathRef File, StringRef Contents,
-   WantDiagnostics WD = WantDiagnostics::Auto,
-   bool SkipCache = false);
+   WantDiagnostics WD = WantDiagnostics::Auto);
 
   /// Remove \p File from list of tracked files, schedule a request to free
   /// resources associated with it.
@@ -216,13 +214,16 @@
   void consumeDiagnostics(PathRef File, DocVersion Version,
   std::vector Diags);
 
-  CompileArgsCache CompileArgs;
+  tooling::CompileCommand getCompileCommand(PathRef File);
+
+  GlobalCompilationDatabase &CDB;
   DiagnosticsConsumer &DiagConsumer;
   FileSystemProvider &FSProvider;
 
   /// Used to synchronize diagnostic responses for added and removed files.
   llvm::StringMap InternalVersion;
 
+  Path ResourceDir;
   // The index used to look up symbols. This could be:
   //   - null (all index functionality is optional)
   //   - the dynamic index owned by ClangdServer (FileIdx)
Index: clangd/ClangdLSPServer.h
===
--- clangd/ClangdLSPServer.h
+++ clangd/ClangdLSPServer.h
@@ -100,7 +100,9 @@
 
   // Various ClangdServer parameters go here. It's important they're created
   // before ClangdServer.
-  DirectoryBasedGlobalCompilationDatabase CDB;
+  DirectoryBasedGlobalCompilationDatabase NonCachedCDB;
+  CachingCompilationDb CDB;
+
   RealFileSystemProvider FSProvider;
   /// Options used for code completion
   clangd::CodeCompleteOptions CCOpts;
Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -14,7 +14,6 @@
   ClangdUnit.cpp
   CodeComplete.cpp
   CodeCompletionStrings.cpp
-  CompileArgsCache.cpp
   Compiler.cpp
   Context.cpp
   Diagnostics.cpp
Index: clangd/GlobalCompilationDatabase.h
===
--- clangd/GlobalCompilationDatabase.h
+++ clangd/GlobalCompilationDatabase.h
@@ -85,6 +85,34 @@
   /// is located.
   llvm::Optional CompileCommandsDir;
 };
+
+/// A wrapper around GlobalCompilationDatabase that caches the compile commands.
+/// Note that only results of getCompileCommand are cached.
+class CachingCompilationDb : public GlobalCompilationDatabase {
+public:
+  explicit CachingCompilationDb(const GlobalCompilationDatabase &InnerCDB);
+
+  /// Gets compile command for \p File from cache or CDB if it's not in the
+  /// cache.
+  llvm::Optional
+  getCompileCommand(PathRef File) const override;
+
+  /// Forwards to the inner CDB. Results of this function are no

[PATCH] D45679: [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

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

In https://reviews.llvm.org/D45679#1122826, @shuaiwang wrote:

> Thanks a lot for the review!
>
> Could you also help commit this diff as well? Thanks!


There are at least two previous accepted&committed differentials 
(https://reviews.llvm.org/D17586, https://reviews.llvm.org/D45702),
i think you can ask for commit bit now.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679



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


[PATCH] D48116: [libclang] Allow skipping warnings from all included files

2018-06-13 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik updated this revision to Diff 151116.
nik added a comment.

Addressed comments.


Repository:
  rC Clang

https://reviews.llvm.org/D48116

Files:
  include/clang-c/Index.h
  include/clang/Basic/Diagnostic.h
  lib/Basic/DiagnosticIDs.cpp
  test/Index/ignore-warnings-from-headers.cpp
  test/Index/ignore-warnings-from-headers.h
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3397,6 +3397,9 @@
   if (options & CXTranslationUnit_KeepGoing)
 Diags->setSuppressAfterFatalError(false);
 
+  if (options & CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles)
+  Diags->setSuppressNonErrorsFromIncludedFiles(true);
+
   // Recover resources if we crash before exiting this function.
   llvm::CrashRecoveryContextCleanupRegistrar >
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -84,6 +84,8 @@
 options |= CXTranslationUnit_KeepGoing;
   if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE"))
 options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
+  if (getenv("CINDEXTEST_IGNORE_NONERRORS_FROM_INCLUDED_FILES"))
+options |= CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles;
 
   return options;
 }
Index: test/Index/ignore-warnings-from-headers.h
===
--- /dev/null
+++ test/Index/ignore-warnings-from-headers.h
@@ -0,0 +1 @@
+void f(int unusedInHeader) {}
Index: test/Index/ignore-warnings-from-headers.cpp
===
--- /dev/null
+++ test/Index/ignore-warnings-from-headers.cpp
@@ -0,0 +1,7 @@
+#include "ignore-warnings-from-headers.h"
+
+void g(int unusedInMainFile) {}
+
+// RUN: env CINDEXTEST_IGNORE_NONERRORS_FROM_INCLUDED_FILES=1 c-index-test -test-load-source function %s -Wunused-parameter 2>&1 | FileCheck %s
+// CHECK-NOT: warning: unused parameter 'unusedInHeader'
+// CHECK: warning: unused parameter 'unusedInMainFile'
Index: lib/Basic/DiagnosticIDs.cpp
===
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -477,6 +477,14 @@
   Result = diag::Severity::Fatal;
   }
 
+  // If requested, ignore non-errors from all included files.
+  if (Diag.SuppressNonErrorsFromIncludedFiles &&
+  Result <= diag::Severity::Warning && Loc.isValid() &&
+  !Diag.getSourceManager().isInMainFile(
+  Diag.getSourceManager().getExpansionLoc(Loc))) {
+return diag::Severity::Ignored;
+  }
+
   // Custom diagnostics always are emitted in system headers.
   bool ShowInSystemHeader =
   !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
Index: include/clang/Basic/Diagnostic.h
===
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -213,6 +213,9 @@
   // Suppress all diagnostics.
   bool SuppressAllDiagnostics = false;
 
+  // Suppress non-errors from all included files.
+  bool SuppressNonErrorsFromIncludedFiles = false;
+
   // Elide common types of templates.
   bool ElideType = true;
 
@@ -634,6 +637,10 @@
   }
   bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; }
 
+  void setSuppressNonErrorsFromIncludedFiles(bool Val = true) {
+SuppressNonErrorsFromIncludedFiles = Val;
+  }
+
   /// Set type eliding, to skip outputting same types occurring in
   /// template types.
   void setElideType(bool Val = true) { ElideType = Val; }
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -1332,7 +1332,17 @@
*
* The function bodies of the main file are not skipped.
*/
-  CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800
+  CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800,
+
+  /**
+   * Used to indicate that non-errors from included files should be ignored.
+   *
+   * If set, clang_getDiagnosticSetFromTU() will not report e.g. warnings from
+   * included files anymore. This speeds up clang_getDiagnosticSetFromTU() for
+   * the case where these warnings are not of interest, as for an IDE for
+   * example, which typically shows only the diagnostics in the main file.
+   */
+  CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles = 0x1000
 };
 
 /**
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48071: [clangd] Add an option controlling caching of compile commands.

2018-06-13 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:141
+   "come from the compilation databases."),
+llvm::cl::init(false), llvm::cl::Hidden);
+

sammccall wrote:
> ilya-biryukov wrote:
> > sammccall wrote:
> > > init(true) to avoid changing behavior?
> > This is intentional, it seems `false` is a better default, given that all 
> > implementation in LLVM cache it all themselves.
> > We should set to true for our CDB that actually needs it. WDYT?
> I agree the default should be false, at least eventually.
> 
> I'm not sure what you're suggesting though - we change the default value of 
> the flag in our own copy when we link against our DB that doesn't cache?
> 
> That could work. I wonder if this will break others who might have similar 
> DBs.
I suggested telling our users to set this flag to true.
Otherwise I think we should just punt on this change and not introduce the 
flag. If we'll have dependency tracking, caching could probably be nicely 
incorporated into the build system integration and than we'll just remove the 
caching from ClangdLSPServer.
Happy to go this way, BTW, I don't think this cache creates any problems apart 
from some inefficiency.

The flag is of no use if we're the only ones who need to set it to 'true', but 
'true' is also the default.

> I wonder if this will break others who might have similar DBs.
Do we know of anyone else who builds clangd with custom DB implementations?
If there are any and this change breaks them, we can revert it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48071



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


[PATCH] D48098: clang-format-diff: Switch to python3 by default, support python 2.7

2018-06-13 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir requested changes to this revision.
krasimir added a comment.
This revision now requires changes to proceed.

Sorry, I'm not familiar with this tool. Could you elaborate:

- why is this switch necessary?
- what's expected to be supported with it?
- how do I test it?


https://reviews.llvm.org/D48098



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


[PATCH] D46862: [libclang] Optionally add code completion results for arrow instead of dot

2018-06-13 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added inline comments.



Comment at: include/clang-c/Index.h:5302
+CXCodeCompleteResults *results, unsigned completion_index,
+unsigned fixit_index, CXSourceRange *replacement_range);
+

Please document the parameters. It's more important here than for any other 
function that was introduced.



Comment at: include/clang-c/Index.h:5338
+  /**
+   * Whether to include completion items with small
+   * fix-its, e.g. change '.' to '->' on member access, etc.

s/completion items/completions/g


https://reviews.llvm.org/D46862



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


[PATCH] D46013: [ARM] Conform to AAPCS when passing overaligned composites as arguments

2018-06-13 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

Ping?


https://reviews.llvm.org/D46013



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


[PATCH] D47554: [analyzer] Check for dead/impossible status checks

2018-06-13 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/DeadStatusChecker.cpp:33
+
+const Expr *hasNullptr(const BinaryOperator *BO) const {
+  const Expr *ret = nullptr;

george.karpenkov wrote:
> Could this be rewritten as a matcher instead? Surely there must be one 
> comparing the literal to null?
For this particular part a matchers-based solution might be a bit wordy:

  binaryOperator(anyOf(
allOf(hasLHS(ignoringParenCasts(nullPointerConstant())), 
hasRHS(expr().bind("other"))),
allOf(hasRHS(ignoringParenCasts(nullPointerConstant())), 
hasLHS(expr().bind("other")

But maybe it's time to add a helper matcher similar to hasEitherOperand, for 
example:
  inline internal::Matcher hasOperands(
  const internal::Matcher &One, const internal::Matcher 
&Another) {
return anyOf(allOf(hasLHS(One), hasRHS(Another)), allOf(hasRHS(One), 
hasLHS(Another)));
  }

This can be done locally, but I wouldn't object adding it to ASTMatchers.h, 
since it could already be used a few times in the existing code (at least in 
clang-tidy/bugprone/IncorrectRoundingsCheck.cpp and 
clang-tidy/misc/RedundantExpressionCheck.cpp).


Repository:
  rC Clang

https://reviews.llvm.org/D47554



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


[PATCH] D48119: [AArch64] Added Clang Codegen+Test Support for FP16 VCVTA_U16 intrinsic

2018-06-13 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson created this revision.
LukeGeeson added a reviewer: SjoerdMeijer.
Herald added a reviewer: javed.absar.
Herald added a subscriber: kristof.beyls.

-Added support for existing IP for vcvta_u16_f16 instrinsic for Arm v8.2a 
-CGBuiltin simply adds cases for this intrinsic to gen the clang IR
-tests added for Aarch64 and Arm test suites
-tested and works using ninja check


Repository:
  rC Clang

https://reviews.llvm.org/D48119

Files:
  CodeGen/CGBuiltin.cpp
  CodeGen/aarch64-v8.2a-neon-intrinsics.c
  CodeGen/arm-v8.2a-neon-intrinsics.c


Index: CodeGen/arm-v8.2a-neon-intrinsics.c
===
--- CodeGen/arm-v8.2a-neon-intrinsics.c
+++ CodeGen/arm-v8.2a-neon-intrinsics.c
@@ -164,6 +164,13 @@
   return vcvta_s16_f16(a);
 }
 
+// CHECK-LABEL: test_vcvta_u16_f16
+// CHECK:  [[VCVT:%.*]] = call <4 x i16> @llvm.arm.neon.fcvtau.v4i16.v4f16(<4 
x half> %a)
+// CHECK:  ret <4 x i16> [[VCVT]]
+int16x4_t test_vcvta_u16_f16 (float16x4_t a) {
+   return vcvta_u16_f16(a);
+}
+
 // CHECK-LABEL: test_vcvtaq_s16_f16
 // CHECK:  [[VCVT:%.*]] = call <8 x i16> @llvm.arm.neon.vcvtas.v8i16.v8f16(<8 
x half> %a)
 // CHECK:  ret <8 x i16> [[VCVT]]
Index: CodeGen/aarch64-v8.2a-neon-intrinsics.c
===
--- CodeGen/aarch64-v8.2a-neon-intrinsics.c
+++ CodeGen/aarch64-v8.2a-neon-intrinsics.c
@@ -164,6 +164,13 @@
   return vcvta_s16_f16(a);
 }
 
+// CHECK-LABEL: test_vcvta_u16_f16
+// CHECK:  [[VCVT:%.*]] = call <4 x i16> 
@llvm.aarch64.neon.fcvtau.v4i16.v4f16(<4 x half> %a)
+// CHECK:  ret <4 x i16> [[VCVT]]
+int16x4_t test_vcvta_u16_f16 (float16x4_t a) {
+  return vcvta_u16_f16(a);
+}
+
 // CHECK-LABEL: test_vcvtaq_s16_f16
 // CHECK:  [[VCVT:%.*]] = call <8 x i16> 
@llvm.aarch64.neon.fcvtas.v8i16.v8f16(<8 x half> %a)
 // CHECK:  ret <8 x i16> [[VCVT]]
Index: CodeGen/CGBuiltin.cpp
===
--- CodeGen/CGBuiltin.cpp
+++ CodeGen/CGBuiltin.cpp
@@ -3998,6 +3998,7 @@
   NEONMAP0(vcvt_u32_v),
   NEONMAP0(vcvt_u64_v),
   NEONMAP1(vcvta_s16_v, arm_neon_vcvtas, 0),
+  NEONMAP1(vcvta_u16_v, arm_neon_vcvtau, 0),
   NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0),
   NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0),
   NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0),
@@ -4882,6 +4883,7 @@
 : Builder.CreateFPToSI(Ops[0], Ty, "vcvt");
   }
   case NEON::BI__builtin_neon_vcvta_s16_v:
+  case NEON::BI__builtin_neon_vcvta_u16_v:
   case NEON::BI__builtin_neon_vcvta_s32_v:
   case NEON::BI__builtin_neon_vcvta_s64_v:
   case NEON::BI__builtin_neon_vcvta_u32_v:
@@ -7618,6 +7620,7 @@
 return Builder.CreateFPToSI(Ops[0], Ty);
   }
   case NEON::BI__builtin_neon_vcvta_s16_v:
+  case NEON::BI__builtin_neon_vcvta_u16_v:
   case NEON::BI__builtin_neon_vcvta_s32_v:
   case NEON::BI__builtin_neon_vcvtaq_s16_v:
   case NEON::BI__builtin_neon_vcvtaq_s32_v:


Index: CodeGen/arm-v8.2a-neon-intrinsics.c
===
--- CodeGen/arm-v8.2a-neon-intrinsics.c
+++ CodeGen/arm-v8.2a-neon-intrinsics.c
@@ -164,6 +164,13 @@
   return vcvta_s16_f16(a);
 }
 
+// CHECK-LABEL: test_vcvta_u16_f16
+// CHECK:  [[VCVT:%.*]] = call <4 x i16> @llvm.arm.neon.fcvtau.v4i16.v4f16(<4 x half> %a)
+// CHECK:  ret <4 x i16> [[VCVT]]
+int16x4_t test_vcvta_u16_f16 (float16x4_t a) {
+   return vcvta_u16_f16(a);
+}
+
 // CHECK-LABEL: test_vcvtaq_s16_f16
 // CHECK:  [[VCVT:%.*]] = call <8 x i16> @llvm.arm.neon.vcvtas.v8i16.v8f16(<8 x half> %a)
 // CHECK:  ret <8 x i16> [[VCVT]]
Index: CodeGen/aarch64-v8.2a-neon-intrinsics.c
===
--- CodeGen/aarch64-v8.2a-neon-intrinsics.c
+++ CodeGen/aarch64-v8.2a-neon-intrinsics.c
@@ -164,6 +164,13 @@
   return vcvta_s16_f16(a);
 }
 
+// CHECK-LABEL: test_vcvta_u16_f16
+// CHECK:  [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtau.v4i16.v4f16(<4 x half> %a)
+// CHECK:  ret <4 x i16> [[VCVT]]
+int16x4_t test_vcvta_u16_f16 (float16x4_t a) {
+  return vcvta_u16_f16(a);
+}
+
 // CHECK-LABEL: test_vcvtaq_s16_f16
 // CHECK:  [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtas.v8i16.v8f16(<8 x half> %a)
 // CHECK:  ret <8 x i16> [[VCVT]]
Index: CodeGen/CGBuiltin.cpp
===
--- CodeGen/CGBuiltin.cpp
+++ CodeGen/CGBuiltin.cpp
@@ -3998,6 +3998,7 @@
   NEONMAP0(vcvt_u32_v),
   NEONMAP0(vcvt_u64_v),
   NEONMAP1(vcvta_s16_v, arm_neon_vcvtas, 0),
+  NEONMAP1(vcvta_u16_v, arm_neon_vcvtau, 0),
   NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0),
   NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0),
   NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0),
@@ -4882,6 +4883,7 @@
 : Builder.CreateFPToSI(Ops[0], Ty, "vcvt");
   }
   case NEON::BI__builtin_neon_vcvta_s16_v:
+  case NEON::BI__builtin_neon_vcvta_u16_v:
   case NEON::BI__builtin_neon_vcvta_s32_v:
   case NEON::BI__builtin_neon_vcvta_s64_v:
   case NEON::BI__builti

[PATCH] D48119: [AArch64] Added Clang Codegen+Test Support for FP16 VCVTA_U16 intrinsic

2018-06-13 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

Nits title:

- Think you can simplify the title to something along the lines of: "[AArch64] 
Support the FP16 VCVTA_U16 intrinsic". No need to mention tests are added in 
the subject (tests should always be added).

Nits summary:

- Arm v8.2a -> Armv8.2-A
- Aarch64 -> AArch64
- No need to mention "tested and works using ninja check"; this is obvious and 
should always be done.
- This is a bit vague: "Added support for existing IP". I think you can reduce 
the summary to just: "Added support for the vcvta_u16_f16 instrinsic for FP16 
Armv8.2-A"




Comment at: CodeGen/arm-v8.2a-neon-intrinsics.c:170
+// CHECK:  ret <4 x i16> [[VCVT]]
+int16x4_t test_vcvta_u16_f16 (float16x4_t a) {
+   return vcvta_u16_f16(a);

Is this exactly the same test also added in aarch64-v8.2a-neon-intrinsics.c?


Repository:
  rC Clang

https://reviews.llvm.org/D48119



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


[PATCH] D48119: [AArch64] Added support for the vcvta_u16_f16 instrinsic for FP16 Armv8.2-A

2018-06-13 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson marked an inline comment as done.
LukeGeeson added a comment.

address Nit's and code comments, please see above.




Comment at: CodeGen/arm-v8.2a-neon-intrinsics.c:170
+// CHECK:  ret <4 x i16> [[VCVT]]
+int16x4_t test_vcvta_u16_f16 (float16x4_t a) {
+   return vcvta_u16_f16(a);

SjoerdMeijer wrote:
> Is this exactly the same test also added in aarch64-v8.2a-neon-intrinsics.c?
Not that I'm aware. One is for AArch platforms and the other is Arm. see the 
second CHECK line of each


Repository:
  rC Clang

https://reviews.llvm.org/D48119



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


[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-13 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan accepted this revision.
ebevhan added a comment.
This revision is now accepted and ready to land.

LGTM, but I'm not a code owner so maybe someone else should chime in if they 
have any input.


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[clang-tools-extra] r334589 - Revert "[clangd] Log completion context type. NFC"

2018-06-13 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jun 13 04:31:20 2018
New Revision: 334589

URL: http://llvm.org/viewvc/llvm-project?rev=334589&view=rev
Log:
Revert "[clangd] Log completion context type. NFC"

This reverts commit r334572, which has a potential use-after-free.

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=334589&r1=334588&r2=334589&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Jun 13 04:31:20 2018
@@ -881,12 +881,10 @@ public:
 SPAN_ATTACH(Tracer, "merged_results", NBoth);
 SPAN_ATTACH(Tracer, "returned_results", Output.items.size());
 SPAN_ATTACH(Tracer, "incomplete", Output.isIncomplete);
-log(llvm::formatv(
-"Code complete ({0}): {1} results from Sema, {2} from Index, "
-"{3} matched, {4} returned{5}.",
-getCompletionKindString(Recorder->CCContext.getKind()), NSema, NIndex,
-NBoth, Output.items.size(),
-Output.isIncomplete ? " (incomplete)" : ""));
+log(llvm::formatv("Code complete: {0} results from Sema, {1} from Index, "
+  "{2} matched, {3} returned{4}.",
+  NSema, NIndex, NBoth, Output.items.size(),
+  Output.isIncomplete ? " (incomplete)" : ""));
 assert(!Opts.Limit || Output.items.size() <= Opts.Limit);
 // We don't assert that isIncomplete means we hit a limit.
 // Indexes may choose to impose their own limits even if we don't have one.


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


[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-13 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: test/Frontend/fixed_point_bit_widths.c:44
+
+// CHECK-NEXT: @size_SsF  = dso_local global i{{[0-9]+}} 2
+// CHECK-NEXT: @size_SF   = dso_local global i{{[0-9]+}} 4

Wait; should these dso_local be `{{.*}}`?


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[PATCH] D46862: [libclang] Optionally add code completion results for arrow instead of dot

2018-06-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 151123.
yvvan marked 2 inline comments as done.
yvvan added a comment.

Address comments about Index.h new functions parameters


https://reviews.llvm.org/D46862

Files:
  include/clang-c/Index.h
  include/clang/Sema/CodeCompleteConsumer.h
  test/Index/complete-arrow-dot.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp
  tools/libclang/CIndexCodeCompletion.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -171,6 +171,8 @@
 clang_getCompletionChunkCompletionString
 clang_getCompletionChunkKind
 clang_getCompletionChunkText
+clang_getCompletionNumFixIts
+clang_getCompletionFixIt
 clang_getCompletionNumAnnotations
 clang_getCompletionParent
 clang_getCompletionPriority
@@ -260,6 +262,7 @@
 clang_getSpellingLocation
 clang_getTUResourceUsageName
 clang_getTemplateCursorKind
+clang_getToken
 clang_getTokenExtent
 clang_getTokenKind
 clang_getTokenLocation
Index: tools/libclang/CIndexCodeCompletion.cpp
===
--- tools/libclang/CIndexCodeCompletion.cpp
+++ tools/libclang/CIndexCodeCompletion.cpp
@@ -16,6 +16,7 @@
 #include "CIndexDiagnostic.h"
 #include "CLog.h"
 #include "CXCursor.h"
+#include "CXSourceLocation.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
 #include "clang/AST/Decl.h"
@@ -302,10 +303,53 @@
   /// A string containing the Objective-C selector entered thus far for a
   /// message send.
   std::string Selector;
+
+  /// Vector of fix-its for each completion result that *must* be applied
+  /// before that result for the corresponding completion item.
+  std::vector> FixItsVector;
 };
 
 } // end anonymous namespace
 
+unsigned clang_getCompletionNumFixIts(CXCodeCompleteResults *results,
+  unsigned completion_index) {
+  AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+  if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index)
+return 0;
+
+  return static_cast(allocated_results->FixItsVector[completion_index].size());
+}
+
+CXString clang_getCompletionFixIt(CXCodeCompleteResults *results,
+  unsigned completion_index,
+  unsigned fixit_index,
+  CXSourceRange *replacement_range) {
+  AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+  if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  ArrayRef FixIts = allocated_results->FixItsVector[completion_index];
+  if (FixIts.size() <= fixit_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  const FixItHint &FixIt = FixIts[fixit_index];
+  if (replacement_range) {
+*replacement_range = cxloc::translateSourceRange(
+*allocated_results->SourceMgr, allocated_results->LangOpts,
+FixIt.RemoveRange);
+  }
+
+  return cxstring::createRef(FixIt.CodeToInsert.c_str());
+}
+
 /// Tracks the number of code-completion result objects that are 
 /// currently active.
 ///
@@ -531,18 +575,22 @@
 CodeCompletionResult *Results,
 unsigned NumResults) override {
   StoredResults.reserve(StoredResults.size() + NumResults);
+  if (includeFixIts())
+AllocatedResults.FixItsVector.reserve(NumResults);
   for (unsigned I = 0; I != NumResults; ++I) {
-CodeCompletionString *StoredCompletion
+CodeCompletionString *StoredCompletion
   = Results[I].CreateCodeCompletionString(S, Context, getAllocator(),
   getCodeCompletionTUInfo(),
   includeBriefComments());
 
 CXCompletionResult R;
 R.CursorKind = Results[I].CursorKind;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
+if (includeFixIts())
+  AllocatedResults.FixItsVector.emplace_back(std::move(Results[I].FixIts));
   }
-  
+
   enum CodeCompletionContext::Kind contextKind = Context.getKind();
   
   AllocatedResults.ContextKind = contextKind;
@@ -644,13 +692,13 @@
   unsigned options) {
   bool IncludeBriefComments = options & CXCodeComplete_IncludeBriefComments;
   bool SkipPreamble = options & CXCodeComplete_SkipPreamble;
+  bool IncludeFixIts = options & CXCodeComplete_IncludeCompletionsWithFixIts;
 
 #ifdef UDP_CODE_COMPLETION_LOGGER
 #ifdef UDP_CODE_COMPLETION_LOGGER_PORT
   const llvm::

[PATCH] D46862: [libclang] Optionally add code completion results for arrow instead of dot

2018-06-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 151124.
yvvan added a comment.

Diff with unix line endings


https://reviews.llvm.org/D46862

Files:
  include/clang-c/Index.h
  include/clang/Sema/CodeCompleteConsumer.h
  test/Index/complete-arrow-dot.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp
  tools/libclang/CIndexCodeCompletion.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -171,6 +171,8 @@
 clang_getCompletionChunkCompletionString
 clang_getCompletionChunkKind
 clang_getCompletionChunkText
+clang_getCompletionNumFixIts
+clang_getCompletionFixIt
 clang_getCompletionNumAnnotations
 clang_getCompletionParent
 clang_getCompletionPriority
@@ -260,6 +262,7 @@
 clang_getSpellingLocation
 clang_getTUResourceUsageName
 clang_getTemplateCursorKind
+clang_getToken
 clang_getTokenExtent
 clang_getTokenKind
 clang_getTokenLocation
Index: tools/libclang/CIndexCodeCompletion.cpp
===
--- tools/libclang/CIndexCodeCompletion.cpp
+++ tools/libclang/CIndexCodeCompletion.cpp
@@ -16,6 +16,7 @@
 #include "CIndexDiagnostic.h"
 #include "CLog.h"
 #include "CXCursor.h"
+#include "CXSourceLocation.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
 #include "clang/AST/Decl.h"
@@ -302,10 +303,53 @@
   /// A string containing the Objective-C selector entered thus far for a
   /// message send.
   std::string Selector;
+
+  /// Vector of fix-its for each completion result that *must* be applied
+  /// before that result for the corresponding completion item.
+  std::vector> FixItsVector;
 };
 
 } // end anonymous namespace
 
+unsigned clang_getCompletionNumFixIts(CXCodeCompleteResults *results,
+  unsigned completion_index) {
+  AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+  if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index)
+return 0;
+
+  return static_cast(allocated_results->FixItsVector[completion_index].size());
+}
+
+CXString clang_getCompletionFixIt(CXCodeCompleteResults *results,
+  unsigned completion_index,
+  unsigned fixit_index,
+  CXSourceRange *replacement_range) {
+  AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+  if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  ArrayRef FixIts = allocated_results->FixItsVector[completion_index];
+  if (FixIts.size() <= fixit_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  const FixItHint &FixIt = FixIts[fixit_index];
+  if (replacement_range) {
+*replacement_range = cxloc::translateSourceRange(
+*allocated_results->SourceMgr, allocated_results->LangOpts,
+FixIt.RemoveRange);
+  }
+
+  return cxstring::createRef(FixIt.CodeToInsert.c_str());
+}
+
 /// Tracks the number of code-completion result objects that are 
 /// currently active.
 ///
@@ -531,18 +575,22 @@
 CodeCompletionResult *Results,
 unsigned NumResults) override {
   StoredResults.reserve(StoredResults.size() + NumResults);
+  if (includeFixIts())
+AllocatedResults.FixItsVector.reserve(NumResults);
   for (unsigned I = 0; I != NumResults; ++I) {
-CodeCompletionString *StoredCompletion
+CodeCompletionString *StoredCompletion
   = Results[I].CreateCodeCompletionString(S, Context, getAllocator(),
   getCodeCompletionTUInfo(),
   includeBriefComments());
 
 CXCompletionResult R;
 R.CursorKind = Results[I].CursorKind;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
+if (includeFixIts())
+  AllocatedResults.FixItsVector.emplace_back(std::move(Results[I].FixIts));
   }
-  
+
   enum CodeCompletionContext::Kind contextKind = Context.getKind();
   
   AllocatedResults.ContextKind = contextKind;
@@ -644,13 +692,13 @@
   unsigned options) {
   bool IncludeBriefComments = options & CXCodeComplete_IncludeBriefComments;
   bool SkipPreamble = options & CXCodeComplete_SkipPreamble;
+  bool IncludeFixIts = options & CXCodeComplete_IncludeCompletionsWithFixIts;
 
 #ifdef UDP_CODE_COMPLETION_LOGGER
 #ifdef UDP_CODE_COMPLETION_LOGGER_PORT
   const llvm::TimeRecord &StartTime =  llvm::TimeRecord::getCurrentTime();
 #endif

r334593 - [libclang] Optionally add code completion results for arrow instead of dot

2018-06-13 Thread Ivan Donchevskii via cfe-commits
Author: yvvan
Date: Wed Jun 13 05:37:08 2018
New Revision: 334593

URL: http://llvm.org/viewvc/llvm-project?rev=334593&view=rev
Log:
[libclang] Optionally add code completion results for arrow instead of dot

Follow up for D41537 - libclang part.

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

Added:
cfe/trunk/test/Index/complete-arrow-dot.cpp
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=334593&r1=334592&r2=334593&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Jun 13 05:37:08 2018
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 48
+#define CINDEX_VERSION_MINOR 49
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -1327,7 +1327,7 @@ enum CXTranslationUnit_Flags {
   CXTranslationUnit_SingleFileParse = 0x400,
 
   /**
-   * \brief Used in combination with CXTranslationUnit_SkipFunctionBodies to
+   * Used in combination with CXTranslationUnit_SkipFunctionBodies to
* constrain the skipping of function bodies to the preamble.
*
* The function bodies of the main file are not skipped.
@@ -4749,6 +4749,20 @@ typedef struct {
 } CXToken;
 
 /**
+ * Get the raw lexical token starting with the given location.
+ *
+ * \param TU the translation unit whose text is being tokenized.
+ *
+ * \param Location the source location with which the token starts.
+ *
+ * \returns The token starting with the given location or NULL if no such token
+ * exist. The returned pointer must be freed with clang_disposeTokens before 
the
+ * translation unit is destroyed.
+ */
+CINDEX_LINKAGE CXToken *clang_getToken(CXTranslationUnit TU,
+   CXSourceLocation Location);
+
+/**
  * Determine the kind of the given token.
  */
 CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
@@ -5244,6 +5258,70 @@ typedef struct {
 } CXCodeCompleteResults;
 
 /**
+ * Retrieve the number of fix-its for the given completion index.
+ *
+ * Calling this makes sense only if CXCodeComplete_IncludeCompletionsWithFixIts
+ * option was set.
+ *
+ * \param results The structure keeping all completion results
+ *
+ * \param completion_index The index of the completion
+ *
+ * \return The number of fix-its which must be applied before the completion at
+ * completion_index can be applied
+ */
+CINDEX_LINKAGE unsigned
+clang_getCompletionNumFixIts(CXCodeCompleteResults *results,
+ unsigned completion_index);
+
+/**
+ * Fix-its that *must* be applied before inserting the text for the
+ * corresponding completion.
+ *
+ * By default, clang_codeCompleteAt() only returns completions with empty
+ * fix-its. Extra completions with non-empty fix-its should be explicitly
+ * requested by setting CXCodeComplete_IncludeCompletionsWithFixIts.
+ *
+ * For the clients to be able to compute position of the cursor after applying
+ * fix-its, the following conditions are guaranteed to hold for
+ * replacement_range of the stored fix-its:
+ *  - Ranges in the fix-its are guaranteed to never contain the completion
+ *  point (or identifier under completion point, if any) inside them, except
+ *  at the start or at the end of the range.
+ *  - If a fix-it range starts or ends with completion point (or starts or
+ *  ends after the identifier under completion point), it will contain at
+ *  least one character. It allows to unambiguously recompute completion
+ *  point after applying the fix-it.
+ *
+ * The intuition is that provided fix-its change code around the identifier we
+ * complete, but are not allowed to touch the identifier itself or the
+ * completion point. One example of completions with corrections are the ones
+ * replacing '.' with '->' and vice versa:
+ *
+ * std::unique_ptr> vec_ptr;
+ * In 'vec_ptr.^', one of the completions is 'push_back', it requires
+ * replacing '.' with '->'.
+ * In 'vec_ptr->^', one of the completions is 'release', it requires
+ * replacing '->' with '.'.
+ *
+ * \param results The structure keeping all completion results
+ *
+ * \param completion_index The index of the completion
+ *
+ * \param fixit_index The index of the fix-it for the completion at
+ * completion_index
+ *
+ * \param replacement_range The fix-it range that must be replaced before the
+ * completion at completion_index can be applied
+ *
+ * \returns The fix-it string that must replace the code at replacement_range
+ * before the co

[PATCH] D46862: [libclang] Optionally add code completion results for arrow instead of dot

2018-06-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334593: [libclang] Optionally add code completion results 
for arrow instead of dot (authored by yvvan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46862?vs=151124&id=151133#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46862

Files:
  include/clang-c/Index.h
  include/clang/Sema/CodeCompleteConsumer.h
  test/Index/complete-arrow-dot.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp
  tools/libclang/CIndexCodeCompletion.cpp
  tools/libclang/libclang.exports

Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 48
+#define CINDEX_VERSION_MINOR 49
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -1327,7 +1327,7 @@
   CXTranslationUnit_SingleFileParse = 0x400,
 
   /**
-   * \brief Used in combination with CXTranslationUnit_SkipFunctionBodies to
+   * Used in combination with CXTranslationUnit_SkipFunctionBodies to
* constrain the skipping of function bodies to the preamble.
*
* The function bodies of the main file are not skipped.
@@ -4749,6 +4749,20 @@
 } CXToken;
 
 /**
+ * Get the raw lexical token starting with the given location.
+ *
+ * \param TU the translation unit whose text is being tokenized.
+ *
+ * \param Location the source location with which the token starts.
+ *
+ * \returns The token starting with the given location or NULL if no such token
+ * exist. The returned pointer must be freed with clang_disposeTokens before the
+ * translation unit is destroyed.
+ */
+CINDEX_LINKAGE CXToken *clang_getToken(CXTranslationUnit TU,
+   CXSourceLocation Location);
+
+/**
  * Determine the kind of the given token.
  */
 CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
@@ -5244,6 +5258,70 @@
 } CXCodeCompleteResults;
 
 /**
+ * Retrieve the number of fix-its for the given completion index.
+ *
+ * Calling this makes sense only if CXCodeComplete_IncludeCompletionsWithFixIts
+ * option was set.
+ *
+ * \param results The structure keeping all completion results
+ *
+ * \param completion_index The index of the completion
+ *
+ * \return The number of fix-its which must be applied before the completion at
+ * completion_index can be applied
+ */
+CINDEX_LINKAGE unsigned
+clang_getCompletionNumFixIts(CXCodeCompleteResults *results,
+ unsigned completion_index);
+
+/**
+ * Fix-its that *must* be applied before inserting the text for the
+ * corresponding completion.
+ *
+ * By default, clang_codeCompleteAt() only returns completions with empty
+ * fix-its. Extra completions with non-empty fix-its should be explicitly
+ * requested by setting CXCodeComplete_IncludeCompletionsWithFixIts.
+ *
+ * For the clients to be able to compute position of the cursor after applying
+ * fix-its, the following conditions are guaranteed to hold for
+ * replacement_range of the stored fix-its:
+ *  - Ranges in the fix-its are guaranteed to never contain the completion
+ *  point (or identifier under completion point, if any) inside them, except
+ *  at the start or at the end of the range.
+ *  - If a fix-it range starts or ends with completion point (or starts or
+ *  ends after the identifier under completion point), it will contain at
+ *  least one character. It allows to unambiguously recompute completion
+ *  point after applying the fix-it.
+ *
+ * The intuition is that provided fix-its change code around the identifier we
+ * complete, but are not allowed to touch the identifier itself or the
+ * completion point. One example of completions with corrections are the ones
+ * replacing '.' with '->' and vice versa:
+ *
+ * std::unique_ptr> vec_ptr;
+ * In 'vec_ptr.^', one of the completions is 'push_back', it requires
+ * replacing '.' with '->'.
+ * In 'vec_ptr->^', one of the completions is 'release', it requires
+ * replacing '->' with '.'.
+ *
+ * \param results The structure keeping all completion results
+ *
+ * \param completion_index The index of the completion
+ *
+ * \param fixit_index The index of the fix-it for the completion at
+ * completion_index
+ *
+ * \param replacement_range The fix-it range that must be replaced before the
+ * completion at completion_index can be applied
+ *
+ * \returns The fix-it string that must replace the code at replacement_range
+ * before the completion at completion_index can be applied
+ */
+CINDEX_LINKAGE CXString clang_getCompletionFixIt(
+CXCodeCompleteResults *results, unsigned completion_index,
+unsigned fixit_index, CXSourceRange *replacement_range);
+
+/**
  * Flags that can be passed to \c clang_codeCompleteAt() to
  * modify i

[PATCH] D48119: [AArch64] Added support for the vcvta_u16_f16 instrinsic for FP16 Armv8.2-A

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

Thanks. Looks like a straightforward fix to me.




Comment at: CodeGen/arm-v8.2a-neon-intrinsics.c:170
+// CHECK:  ret <4 x i16> [[VCVT]]
+int16x4_t test_vcvta_u16_f16 (float16x4_t a) {
+   return vcvta_u16_f16(a);

LukeGeeson wrote:
> SjoerdMeijer wrote:
> > Is this exactly the same test also added in aarch64-v8.2a-neon-intrinsics.c?
> Not that I'm aware. One is for AArch platforms and the other is Arm. see the 
> second CHECK line of each
Ah, of course, my bad. Looked too quickly.


Repository:
  rC Clang

https://reviews.llvm.org/D48119



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


[PATCH] D47698: [ASTImporter] import macro source locations

2018-06-13 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl updated this revision to Diff 151138.
r.stahl added a comment.

remove stray include


Repository:
  rC Clang

https://reviews.llvm.org/D47698

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

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1518,6 +1518,50 @@
 ToTU, cxxRecordDecl(unless(isImplicit();
 }
 
+static void CompareSourceLocs(SourceLocation Loc1, SourceLocation Loc2,
+  SourceManager &SM1, SourceManager &SM2) {
+  EXPECT_EQ(SM1.getExpansionLineNumber(Loc1), SM2.getExpansionLineNumber(Loc2));
+  EXPECT_EQ(SM1.getExpansionColumnNumber(Loc1),
+SM2.getExpansionColumnNumber(Loc2));
+  EXPECT_EQ(SM1.getSpellingLineNumber(Loc1), SM2.getSpellingLineNumber(Loc2));
+  EXPECT_EQ(SM1.getSpellingColumnNumber(Loc1),
+SM2.getSpellingColumnNumber(Loc2));
+}
+static void CompareSourceRanges(SourceRange Range1, SourceRange Range2,
+SourceManager &SM1, SourceManager &SM2) {
+  CompareSourceLocs(Range1.getBegin(), Range2.getBegin(), SM1, SM2);
+  CompareSourceLocs(Range1.getEnd(), Range2.getEnd(), SM1, SM2);
+}
+TEST_P(ASTImporterTestBase, ImportSourceLocs) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  #define MFOO(arg) arg = arg + 1
+
+  void foo() {
+int a = 5;
+MFOO(a);
+  }
+  )",
+  Lang_CXX);
+  auto FromD = FirstDeclMatcher().match(FromTU, functionDecl());
+  auto ToD = Import(FromD, Lang_CXX);
+
+  auto ToLHS = LastDeclMatcher().match(ToD, declRefExpr());
+  auto FromLHS = LastDeclMatcher().match(FromTU, declRefExpr());
+  auto ToRHS = LastDeclMatcher().match(ToD, integerLiteral());
+  auto FromRHS =
+  LastDeclMatcher().match(FromTU, integerLiteral());
+
+  SourceManager &ToSM = ToAST->getASTContext().getSourceManager();
+  SourceManager &FromSM = FromD->getASTContext().getSourceManager();
+  CompareSourceRanges(ToD->getSourceRange(), FromD->getSourceRange(), ToSM,
+  FromSM);
+  CompareSourceRanges(ToLHS->getSourceRange(), FromLHS->getSourceRange(), ToSM,
+  FromSM);
+  CompareSourceRanges(ToRHS->getSourceRange(), FromRHS->getSourceRange(), ToSM,
+  FromSM);
+}
+
 TEST_P(
 ASTImporterTestBase,
 ImportDefinitionOfClassTemplateSpecIfThereIsAnExistingFwdDeclAndDefinition)
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -7029,61 +7029,70 @@
 return {};
 
   SourceManager &FromSM = FromContext.getSourceManager();
-  
-  // For now, map everything down to its file location, so that we
-  // don't have to import macro expansions.
-  // FIXME: Import macro expansions!
-  FromLoc = FromSM.getFileLoc(FromLoc);
+
   std::pair Decomposed = FromSM.getDecomposedLoc(FromLoc);
-  SourceManager &ToSM = ToContext.getSourceManager();
   FileID ToFileID = Import(Decomposed.first);
   if (ToFileID.isInvalid())
 return {};
-  SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID)
-   .getLocWithOffset(Decomposed.second);
-  return ret;
+  SourceManager &ToSM = ToContext.getSourceManager();
+  return ToSM.getComposedLoc(ToFileID, Decomposed.second);
 }
 
 SourceRange ASTImporter::Import(SourceRange FromRange) {
   return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
 }
 
 FileID ASTImporter::Import(FileID FromID) {
-  llvm::DenseMap::iterator Pos
-= ImportedFileIDs.find(FromID);
+  llvm::DenseMap::iterator Pos = ImportedFileIDs.find(FromID);
   if (Pos != ImportedFileIDs.end())
 return Pos->second;
-  
+
   SourceManager &FromSM = FromContext.getSourceManager();
   SourceManager &ToSM = ToContext.getSourceManager();
   const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
-  assert(FromSLoc.isFile() && "Cannot handle macro expansions yet");
-  
-  // Include location of this file.
-  SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
-  
+
   // Map the FileID for to the "to" source manager.
   FileID ToID;
-  const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
-  if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
-// FIXME: We probably want to use getVirtualFile(), so we don't hit the
-// disk again
-// FIXME: We definitely want to re-use the existing MemoryBuffer, rather
-// than mmap the files several times.
-const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName());
-if (!Entry)
-  return {};
-ToID = ToSM.createFileID(Entry, ToIncludeLoc, 
- FromSLoc.getFile().getFileCharacteristic());
+  if (FromSLoc.isExpansion()) {
+const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
+SourceLocation ToSpLoc = Import(FromEx.getSpelling

[PATCH] D48053: Correct behavior of __builtin_*_overflow and constexpr.

2018-06-13 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334597: Correct behavior of __builtin_*_overflow and 
constexpr. (authored by erichkeane, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D48053

Files:
  lib/Sema/SemaChecking.cpp
  test/SemaCXX/builtins-overflow.cpp


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -197,30 +197,42 @@
 
   // First two arguments should be integers.
   for (unsigned I = 0; I < 2; ++I) {
-Expr *Arg = TheCall->getArg(I);
-QualType Ty = Arg->getType();
+ExprResult Arg = TheCall->getArg(I);
+QualType Ty = Arg.get()->getType();
 if (!Ty->isIntegerType()) {
-  S.Diag(Arg->getLocStart(), diag::err_overflow_builtin_must_be_int)
-  << Ty << Arg->getSourceRange();
+  S.Diag(Arg.get()->getLocStart(), diag::err_overflow_builtin_must_be_int)
+  << Ty << Arg.get()->getSourceRange();
   return true;
 }
+InitializedEntity Entity = InitializedEntity::InitializeParameter(
+S.getASTContext(), Ty, /*consume*/ false);
+Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
+if (Arg.isInvalid())
+  return true;
+TheCall->setArg(I, Arg.get());
   }
 
   // Third argument should be a pointer to a non-const integer.
   // IRGen correctly handles volatile, restrict, and address spaces, and
   // the other qualifiers aren't possible.
   {
-Expr *Arg = TheCall->getArg(2);
-QualType Ty = Arg->getType();
+ExprResult Arg = TheCall->getArg(2);
+QualType Ty = Arg.get()->getType();
 const auto *PtrTy = Ty->getAs();
 if (!(PtrTy && PtrTy->getPointeeType()->isIntegerType() &&
   !PtrTy->getPointeeType().isConstQualified())) {
-  S.Diag(Arg->getLocStart(), diag::err_overflow_builtin_must_be_ptr_int)
-  << Ty << Arg->getSourceRange();
+  S.Diag(Arg.get()->getLocStart(),
+ diag::err_overflow_builtin_must_be_ptr_int)
+  << Ty << Arg.get()->getSourceRange();
   return true;
 }
+InitializedEntity Entity = InitializedEntity::InitializeParameter(
+S.getASTContext(), Ty, /*consume*/ false);
+Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
+if (Arg.isInvalid())
+  return true;
+TheCall->setArg(2, Arg.get());
   }
-
   return false;
 }
 
Index: test/SemaCXX/builtins-overflow.cpp
===
--- test/SemaCXX/builtins-overflow.cpp
+++ test/SemaCXX/builtins-overflow.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// expected-no-diagnostics
+
+int a() {
+  const int x = 3;
+  static int z;
+  constexpr int *y = &z;
+  return []() { return __builtin_sub_overflow((int)x, (int)x, (int *)y); }();
+}
+int a2() {
+  const int x = 3;
+  static int z;
+  constexpr int *y = &z;
+  return []() { return __builtin_sub_overflow(x, x, y); }();
+}


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -197,30 +197,42 @@
 
   // First two arguments should be integers.
   for (unsigned I = 0; I < 2; ++I) {
-Expr *Arg = TheCall->getArg(I);
-QualType Ty = Arg->getType();
+ExprResult Arg = TheCall->getArg(I);
+QualType Ty = Arg.get()->getType();
 if (!Ty->isIntegerType()) {
-  S.Diag(Arg->getLocStart(), diag::err_overflow_builtin_must_be_int)
-  << Ty << Arg->getSourceRange();
+  S.Diag(Arg.get()->getLocStart(), diag::err_overflow_builtin_must_be_int)
+  << Ty << Arg.get()->getSourceRange();
   return true;
 }
+InitializedEntity Entity = InitializedEntity::InitializeParameter(
+S.getASTContext(), Ty, /*consume*/ false);
+Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
+if (Arg.isInvalid())
+  return true;
+TheCall->setArg(I, Arg.get());
   }
 
   // Third argument should be a pointer to a non-const integer.
   // IRGen correctly handles volatile, restrict, and address spaces, and
   // the other qualifiers aren't possible.
   {
-Expr *Arg = TheCall->getArg(2);
-QualType Ty = Arg->getType();
+ExprResult Arg = TheCall->getArg(2);
+QualType Ty = Arg.get()->getType();
 const auto *PtrTy = Ty->getAs();
 if (!(PtrTy && PtrTy->getPointeeType()->isIntegerType() &&
   !PtrTy->getPointeeType().isConstQualified())) {
-  S.Diag(Arg->getLocStart(), diag::err_overflow_builtin_must_be_ptr_int)
-  << Ty << Arg->getSourceRange();
+  S.Diag(Arg.get()->getLocStart(),
+ diag::err_overflow_builtin_must_be_ptr_int)
+  << Ty << Arg.get()->getSourceRange();
   return true;
 }
+InitializedEntity Entity = InitializedEntity::InitializeParameter(
+S.getASTContext(), Ty, /*consume*/ false);
+Arg = S.PerformCop

r334597 - Correct behavior of __builtin_*_overflow and constexpr.

2018-06-13 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Wed Jun 13 06:25:11 2018
New Revision: 334597

URL: http://llvm.org/viewvc/llvm-project?rev=334597&view=rev
Log:
Correct behavior of __builtin_*_overflow and constexpr.

Enable these builtins to be called across a lambda
boundary with captureless const/constexpr, as brought up by 
Eli here: https://reviews.llvm.org/D48040

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

Added:
cfe/trunk/test/SemaCXX/builtins-overflow.cpp   (with props)
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=334597&r1=334596&r2=334597&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Jun 13 06:25:11 2018
@@ -197,30 +197,42 @@ static bool SemaBuiltinOverflow(Sema &S,
 
   // First two arguments should be integers.
   for (unsigned I = 0; I < 2; ++I) {
-Expr *Arg = TheCall->getArg(I);
-QualType Ty = Arg->getType();
+ExprResult Arg = TheCall->getArg(I);
+QualType Ty = Arg.get()->getType();
 if (!Ty->isIntegerType()) {
-  S.Diag(Arg->getLocStart(), diag::err_overflow_builtin_must_be_int)
-  << Ty << Arg->getSourceRange();
+  S.Diag(Arg.get()->getLocStart(), diag::err_overflow_builtin_must_be_int)
+  << Ty << Arg.get()->getSourceRange();
   return true;
 }
+InitializedEntity Entity = InitializedEntity::InitializeParameter(
+S.getASTContext(), Ty, /*consume*/ false);
+Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
+if (Arg.isInvalid())
+  return true;
+TheCall->setArg(I, Arg.get());
   }
 
   // Third argument should be a pointer to a non-const integer.
   // IRGen correctly handles volatile, restrict, and address spaces, and
   // the other qualifiers aren't possible.
   {
-Expr *Arg = TheCall->getArg(2);
-QualType Ty = Arg->getType();
+ExprResult Arg = TheCall->getArg(2);
+QualType Ty = Arg.get()->getType();
 const auto *PtrTy = Ty->getAs();
 if (!(PtrTy && PtrTy->getPointeeType()->isIntegerType() &&
   !PtrTy->getPointeeType().isConstQualified())) {
-  S.Diag(Arg->getLocStart(), diag::err_overflow_builtin_must_be_ptr_int)
-  << Ty << Arg->getSourceRange();
+  S.Diag(Arg.get()->getLocStart(),
+ diag::err_overflow_builtin_must_be_ptr_int)
+  << Ty << Arg.get()->getSourceRange();
   return true;
 }
+InitializedEntity Entity = InitializedEntity::InitializeParameter(
+S.getASTContext(), Ty, /*consume*/ false);
+Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
+if (Arg.isInvalid())
+  return true;
+TheCall->setArg(2, Arg.get());
   }
-
   return false;
 }
 

Added: cfe/trunk/test/SemaCXX/builtins-overflow.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtins-overflow.cpp?rev=334597&view=auto
==
--- cfe/trunk/test/SemaCXX/builtins-overflow.cpp (added)
+++ cfe/trunk/test/SemaCXX/builtins-overflow.cpp Wed Jun 13 06:25:11 2018
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// expected-no-diagnostics
+
+int a() {
+  const int x = 3;
+  static int z;
+  constexpr int *y = &z;
+  return []() { return __builtin_sub_overflow((int)x, (int)x, (int *)y); }();
+}
+int a2() {
+  const int x = 3;
+  static int z;
+  constexpr int *y = &z;
+  return []() { return __builtin_sub_overflow(x, x, y); }();
+}

Propchange: cfe/trunk/test/SemaCXX/builtins-overflow.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/SemaCXX/builtins-overflow.cpp
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/SemaCXX/builtins-overflow.cpp
--
svn:mime-type = text/plain


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


[PATCH] D47103: Implement strip.invariant.group

2018-06-13 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

Friendly ping @hfinkel @rsmith


Repository:
  rL LLVM

https://reviews.llvm.org/D47103



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


[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-13 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:10090-10100
+// _CMP_TRUE_UQ, _CMP_TRUE_US produce -1,-1... vector
+// on any input and _CMP_FALSE_OQ, _CMP_FALSE_OS produce 0, 0...
+if (CC == 0xf || CC == 0xb || CC == 0x1b || CC == 0x1f) {
+   llvm::Type *ResultType = ConvertType(E->getType());
+
+   Value *Constant = (CC == 0xf || CC == 0x1f) ?
+  llvm::Constant::getAllOnesValue(ResultType) :

  llvm::Type *ResultType = ConvertType(E->getType());
  if (CC == 0x0f || CC == 0x1f)
return llvm::Constant::getAllOnesValue(ResultType);
  if (CC == 0x0b || CC == 0x1b)
return llvm::Constant::getNullValue(ResultType);

?

Also, can we use the defined predicate names instead of hex values in this code?


https://reviews.llvm.org/D45616



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


[PATCH] D48040: Implement constexpr __builtin_*_overflow

2018-06-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 151151.
erichkeane added a comment.

Separated out the other patch as Eli suggested (which has now been committed), 
and rebased this patch on top of it.


https://reviews.llvm.org/D48040

Files:
  lib/AST/ExprConstant.cpp
  test/SemaCXX/builtins-overflow.cpp

Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -8155,6 +8155,124 @@
   case Builtin::BIomp_is_initial_device:
 // We can decide statically which value the runtime would return if called.
 return Success(Info.getLangOpts().OpenMPIsDevice ? 0 : 1, E);
+  case Builtin::BI__builtin_add_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_smulll_overflow: {
+LValue ResultLValue;
+APSInt LHS, RHS;
+
+QualType ResultType = E->getArg(2)->getType()->getPointeeType();
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info) ||
+!EvaluatePointer(E->getArg(2), ResultLValue, Info))
+  return false;
+
+APSInt Result;
+bool DidOverflow = false;
+
+// If the types don't have to match, enlarge all 3 to the largest of them.
+if (BuiltinOp == Builtin::BI__builtin_add_overflow ||
+BuiltinOp == Builtin::BI__builtin_sub_overflow ||
+BuiltinOp == Builtin::BI__builtin_mul_overflow) {
+  bool IsSigned = LHS.isSigned() || RHS.isSigned() ||
+  ResultType->isSignedIntegerOrEnumerationType();
+  bool AllSigned = LHS.isSigned() && RHS.isSigned() &&
+  ResultType->isSignedIntegerOrEnumerationType();
+  uint64_t LHSSize = LHS.getBitWidth();
+  uint64_t RHSSize = RHS.getBitWidth();
+  uint64_t ResultSize = Info.Ctx.getTypeSize(ResultType);
+  uint64_t MaxBits = std::max(std::max(LHSSize, RHSSize), ResultSize);
+
+  // Add an additional bit if the signedness isn't uniformly agreed to. We
+  // could do this ONLY if there is a signed and an unsigned that both have
+  // MaxBits, but the code to check that is pretty nasty.  The issue will be
+  // caught in the shrink-to-result later anyway.
+  if (IsSigned && !AllSigned)
+++MaxBits;
+
+  LHS = APSInt(IsSigned ? LHS.sextOrSelf(MaxBits) : LHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  RHS = APSInt(IsSigned ? RHS.sextOrSelf(MaxBits) : RHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  Result = APSInt(MaxBits, !IsSigned);
+}
+
+// Find largest int.
+switch (BuiltinOp) {
+default:
+  llvm_unreachable("Invalid value for BuiltinOp");
+case Builtin::BI__builtin_add_overflow:
+case Builtin::BI__builtin_sadd_overflow:
+case Builtin::BI__builtin_saddl_overflow:
+case Builtin::BI__builtin_saddll_overflow:
+case Builtin::BI__builtin_uadd_overflow:
+case Builtin::BI__builtin_uaddl_overflow:
+case Builtin::BI__builtin_uaddll_overflow:
+  Result = LHS.isSigned() ? LHS.sadd_ov(RHS, DidOverflow)
+  : LHS.uadd_ov(RHS, DidOverflow);
+  break;
+case Builtin::BI__builtin_sub_overflow:
+case Builtin::BI__builtin_ssub_overflow:
+case Builtin::BI__builtin_ssubl_overflow:
+case Builtin::BI__builtin_ssubll_overflow:
+case Builtin::BI__builtin_usub_overflow:
+case Builtin::BI__builtin_usubl_overflow:
+case Builtin::BI__builtin_usubll_overflow:
+  Result = LHS.isSigned() ? LHS.ssub_ov(RHS, DidOverflow)
+  : LHS.usub_ov(RHS, DidOverflow);
+  break;
+case Builtin::BI__builtin_mul_overflow:
+case Builtin::BI__builtin_smul_overflow:
+case Builtin::BI__builtin_smull_overflow:
+case Builtin::BI__builtin_smulll_overflow:
+case Builtin::BI__builtin_umul_overflow:
+case Builtin::BI__builtin_umull_overflow:
+case Builtin::BI__builtin_umulll_overflow:
+  Result = LHS.isSigned() ? LHS.smul_ov(RHS, DidOverflow)
+  : LHS.umul_ov(RHS, DidOverflow);
+  break;
+}
+
+// In the case where multiple sizes are allowed, truncate and see if
+// the values are th

r334600 - Add -fforce-emit-vtables

2018-06-13 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Jun 13 06:55:42 2018
New Revision: 334600

URL: http://llvm.org/viewvc/llvm-project?rev=334600&view=rev
Log:
Add -fforce-emit-vtables

Summary:
 In many cases we can't devirtualize
 because definition of vtable is not present. Most of the
 time it is caused by inline virtual function not beeing
 emitted. Forcing emitting of vtable adds a reference of these
 inline virtual functions.
 Note that GCC was always doing it.

Reviewers: rjmccall, rsmith, amharc, kuhar

Subscribers: llvm-commits, cfe-commits

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

Co-authored-by: Krzysztof Pszeniczny 

Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Wed Jun 13 06:55:42 2018
@@ -1934,6 +1934,12 @@ Set the default symbol visibility for al
 
 Enables whole-program vtable optimization. Requires -flto
 
+.. option:: -fforce-emit-vtables, -fno-force-emit-vtables
+
+In order to improve devirtualization, forces emitting of vtables even in
+modules where it isn't necessary. It causes more inline virtual functions
+to be emitted.
+
 .. option:: -fwrapv, -fno-wrapv
 
 Treat signed integer overflow as two's complement

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Jun 13 06:55:42 2018
@@ -112,6 +112,12 @@ New Compiler Flags
   'no-strict' option, Clang attempts to match the overflowing behavior of the
   target's native float-to-int conversion instructions.
 
+- :option: `-fforce-emit-vtables` and `-fno-force-emit-vtables`.
+
+   In order to improve devirtualization, forces emitting of vtables even in
+   modules where it isn't necessary. It causes more inline virtual functions
+   to be emitted.
+
 - ...
 
 Deprecated Compiler Flags

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Wed Jun 13 06:55:42 2018
@@ -1269,6 +1269,12 @@ are listed below.
devirtualization and virtual constant propagation, for classes with
:doc:`hidden LTO visibility `. Requires ``-flto``.
 
+.. option:: -fforce-emit-vtables
+
+   In order to improve devirtualization, forces emitting of vtables even in
+   modules where it isn't necessary. It causes more inline virtual functions
+   to be emitted.
+
 .. option:: -fno-assume-sane-operator-new
 
Don't assume that the C++'s new operator is sane.

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Wed Jun 13 06:55:42 2018
@@ -293,6 +293,8 @@ LANGOPT(XRayAlwaysEmitTypedEvents, 1, 0,
 "controls whether to always emit intrinsic calls to "
 "__xray_typedevent(...) builtin.")
 
+LANGOPT(ForceEmitVTables, 1, 0, "whether to emit all vtables")
+
 BENIGN_LANGOPT(AllowEditorPlaceholders, 1, 0,
"allow editor placeholders in source")
 

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jun 13 06:55:42 2018
@@ -1688,6 +1688,11 @@ def fwhole_program_vtables : Flag<["-"],
   HelpText<"Enables whole-program vtable optimization. Requires -flto">;
 def fno_whole_program_vtables : Flag<["-"], "fno-whole-program-vtables">, 
Group,
   Flags<[CoreOption]>;
+def fforce_emi

[PATCH] D47108: [CodeGenCXX] Add -fforce-emit-vtables

2018-06-13 Thread Piotr Padlewski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Prazek marked an inline comment as done.
Closed by commit rC334600: Add -fforce-emit-vtables (authored by Prazek, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47108?vs=150735&id=151154#toc

Repository:
  rC Clang

https://reviews.llvm.org/D47108

Files:
  docs/ClangCommandLineReference.rst
  docs/ReleaseNotes.rst
  docs/UsersManual.rst
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: docs/ClangCommandLineReference.rst
===
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -1934,6 +1934,12 @@
 
 Enables whole-program vtable optimization. Requires -flto
 
+.. option:: -fforce-emit-vtables, -fno-force-emit-vtables
+
+In order to improve devirtualization, forces emitting of vtables even in
+modules where it isn't necessary. It causes more inline virtual functions
+to be emitted.
+
 .. option:: -fwrapv, -fno-wrapv
 
 Treat signed integer overflow as two's complement
Index: docs/UsersManual.rst
===
--- docs/UsersManual.rst
+++ docs/UsersManual.rst
@@ -1269,6 +1269,12 @@
devirtualization and virtual constant propagation, for classes with
:doc:`hidden LTO visibility `. Requires ``-flto``.
 
+.. option:: -fforce-emit-vtables
+
+   In order to improve devirtualization, forces emitting of vtables even in
+   modules where it isn't necessary. It causes more inline virtual functions
+   to be emitted.
+
 .. option:: -fno-assume-sane-operator-new
 
Don't assume that the C++'s new operator is sane.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -112,6 +112,12 @@
   'no-strict' option, Clang attempts to match the overflowing behavior of the
   target's native float-to-int conversion instructions.
 
+- :option: `-fforce-emit-vtables` and `-fno-force-emit-vtables`.
+
+   In order to improve devirtualization, forces emitting of vtables even in
+   modules where it isn't necessary. It causes more inline virtual functions
+   to be emitted.
+
 - ...
 
 Deprecated Compiler Flags
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -293,6 +293,8 @@
 "controls whether to always emit intrinsic calls to "
 "__xray_typedevent(...) builtin.")
 
+LANGOPT(ForceEmitVTables, 1, 0, "whether to emit all vtables")
+
 BENIGN_LANGOPT(AllowEditorPlaceholders, 1, 0,
"allow editor placeholders in source")
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -332,6 +332,10 @@
 /// Whether to embed source in DWARF debug line section.
 CODEGENOPT(EmbedSource, 1, 0)
 
+/// Whether to emit all vtables
+CODEGENOPT(ForceEmitVTables, 1, 0)
+
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1688,6 +1688,11 @@
   HelpText<"Enables whole-program vtable optimization. Requires -flto">;
 def fno_whole_program_vtables : Flag<["-"], "fno-whole-program-vtables">, Group,
   Flags<[CoreOption]>;
+def fforce_emit_vtables : Flag<["-"], "fforce-emit-vtables">, Group,
+Flags<[CC1Option]>,
+HelpText<"Emits more virtual tables to improve devirtualization">;
+def fno_force_emit_vtables : Flag<["-"], "fno-force-emit-vtables">, Group,
+  Flags<[CoreOption]>;
 def fwrapv : Flag<["-"], "fwrapv">, Group, Flags<[CC1Option]>,
   HelpText<"Treat signed integer overflow as two's complement">;
 def fwritable_strings : Flag<["-"], "fwritable-strings">, Group, Flags<[CC1Option]>,
Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -std=c++98 -emit-llvm -o %t
 // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -std=c++98 -O2 -disable-llvm-passes -emit-llvm -o %t.opt
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -std=c++98 -O2 -disable-llvm-passes -emit-llvm -o %t.vtable -fforce-emit-vtables -fstrict-vtable-pointers -mconstructor-aliases
 // RUN: FileCheck --check-pref

[PATCH] D48071: [clangd] Add an option controlling caching of compile commands.

2018-06-13 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

Does this change affect the switching of compilation database, through 
workspace/didChangeConfiguration ?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48071



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


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

2018-06-13 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D47578#1127749, @takuto.ikuta wrote:

> Rui-san, can I ask you to merge this?


Committed here: 
http://llvm.org/viewvc/llvm-project?view=revision&revision=334602


https://reviews.llvm.org/D47578



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


[clang-tools-extra] r334604 - Add a new class to analyze whether an expression is mutated within a statement.

2018-06-13 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 13 07:41:42 2018
New Revision: 334604

URL: http://llvm.org/viewvc/llvm-project?rev=334604&view=rev
Log:
Add a new class to analyze whether an expression is mutated within a statement.

ExprMutationAnalyzer is a generally useful helper that can be used in different 
clang-tidy checks for checking whether a given expression is (potentially) 
mutated within a statement (typically the enclosing compound statement.) This 
is a more general and more powerful/accurate version of isOnlyUsedAsConst, 
which is used in ForRangeCopyCheck, UnnecessaryCopyInitialization.

Patch by Shuai Wang

Added:
clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp
clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.h
clang-tools-extra/trunk/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt
clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt?rev=334604&r1=334603&r2=334604&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt Wed Jun 13 07:41:42 
2018
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyUtils
   ASTUtils.cpp
   DeclRefExprUtils.cpp
+  ExprMutationAnalyzer.cpp
   ExprSequence.cpp
   FixItHintUtils.cpp
   HeaderFileExtensionsUtils.cpp

Added: clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp?rev=334604&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp Wed Jun 
13 07:41:42 2018
@@ -0,0 +1,261 @@
+//===-- ExprMutationAnalyzer.cpp - clang-tidy 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+#include "ExprMutationAnalyzer.h"
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/STLExtras.h"
+
+namespace clang {
+namespace tidy {
+namespace utils {
+using namespace ast_matchers;
+
+namespace {
+
+AST_MATCHER_P(LambdaExpr, hasCaptureInit, const Expr *, E) {
+  return llvm::is_contained(Node.capture_inits(), E);
+}
+
+AST_MATCHER_P(CXXForRangeStmt, hasRangeStmt,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  const DeclStmt *const Range = Node.getRangeStmt();
+  return InnerMatcher.matches(*Range, Finder, Builder);
+}
+
+const ast_matchers::internal::VariadicDynCastAllOfMatcher
+cxxTypeidExpr;
+
+AST_MATCHER(CXXTypeidExpr, isPotentiallyEvaluated) {
+  return Node.isPotentiallyEvaluated();
+}
+
+const ast_matchers::internal::VariadicDynCastAllOfMatcher
+cxxNoexceptExpr;
+
+const ast_matchers::internal::VariadicDynCastAllOfMatcher
+genericSelectionExpr;
+
+AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.getControllingExpr(), Finder, Builder);
+}
+
+const auto nonConstReferenceType = [] {
+  return referenceType(pointee(unless(isConstQualified(;
+};
+
+} // namespace
+
+const Stmt *ExprMutationAnalyzer::findMutation(const Expr *Exp) {
+  const auto Memoized = Results.find(Exp);
+  if (Memoized != Results.end())
+return Memoized->second;
+
+  if (isUnevaluated(Exp))
+return Results[Exp] = nullptr;
+
+  for (const auto &Finder : {&ExprMutationAnalyzer::findDirectMutation,
+ &ExprMutationAnalyzer::findMemberMutation,
+ &ExprMutationAnalyzer::findArrayElementMutation,
+ &ExprMutationAnalyzer::findCastMutation,
+ &ExprMutationAnalyzer::findRangeLoopMutation,
+ &ExprMutationAnalyzer::findReferenceMutation}) {
+if (const Stmt *S = (this->*Finder)(Exp))
+  return Results[Exp] = S;
+  }
+
+  return Results[Exp] = nullptr;
+}
+
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
+  return selectFirst(
+ "expr",
+ match(
+ findAll(
+ expr(equalsNode(Exp),
+  anyOf(
+  // `Exp` is part of the underlying expression of
+  // decltype/typeof if it has an ancestor of
+  // typeLoc.
+ 

[PATCH] D45679: [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

2018-06-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit in r334604 with one minor change -- I added an include for  
to the unit test so that `std::isspace()` would compile properly on all 
platforms.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679



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


[PATCH] D48027: [analyzer] Improve `CallDescription` to handle c++ method.

2018-06-13 Thread Henry Wong via Phabricator via cfe-commits
MTC updated this revision to Diff 151166.
MTC added a comment.

- Use `hasName` matcher to match the qualified name.
- Use the full name, like `std::basic_string::c_str` instead of `c_str` 
to match the `c_str` method in `DanglingInternalBufferChecker.cpp`.




Repository:
  rC Clang

https://reviews.llvm.org/D48027

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  lib/StaticAnalyzer/Checkers/DanglingInternalBufferChecker.cpp
  lib/StaticAnalyzer/Core/CallEvent.cpp

Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -28,6 +28,7 @@
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/ProgramPoint.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
@@ -65,6 +66,7 @@
 
 using namespace clang;
 using namespace ento;
+using namespace clang::ast_matchers;
 
 QualType CallEvent::getResultType() const {
   ASTContext &Ctx = getState()->getStateManager().getContext();
@@ -256,11 +258,24 @@
 return false;
   if (!CD.IsLookupDone) {
 CD.IsLookupDone = true;
-CD.II = &getState()->getStateManager().getContext().Idents.get(CD.FuncName);
+CD.II = &getState()->getStateManager().getContext().Idents.get(
+CD.getFunctionName());
   }
   const IdentifierInfo *II = getCalleeIdentifier();
   if (!II || II != CD.II)
 return false;
+
+  const NamedDecl *ND = dyn_cast_or_null(getDecl());
+  if (!ND)
+return false;
+
+  auto Matches =
+  match(namedDecl(hasName(CD.FuncName)).bind("match_qualified_name"), *ND,
+LCtx->getAnalysisDeclContext()->getASTContext());
+
+  if (Matches.empty())
+return false;
+
   return (CD.RequiredArgs == CallDescription::NoArgRequirement ||
   CD.RequiredArgs == getNumArgs());
 }
Index: lib/StaticAnalyzer/Checkers/DanglingInternalBufferChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/DanglingInternalBufferChecker.cpp
+++ lib/StaticAnalyzer/Checkers/DanglingInternalBufferChecker.cpp
@@ -13,26 +13,28 @@
 //
 //===--===//
 
+#include "AllocationState.h"
 #include "ClangSACheckers.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include "AllocationState.h"
+#include "llvm/ADT/SmallVector.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
 class DanglingInternalBufferChecker : public Checker {
-  CallDescription CStrFn;
+  const llvm::SmallVector CStrFnFamily = {
+{"std::basic_string::c_str"}, {"std::basic_string::c_str"},
+{"std::basic_string::c_str"},
+{"std::basic_string::c_str"}};
 
 public:
-  DanglingInternalBufferChecker() : CStrFn("c_str") {}
-
   /// Record the connection between the symbol returned by c_str() and the
   /// corresponding string object region in the ProgramState. Mark the symbol
   /// released if the string object is destroyed.
@@ -65,7 +67,15 @@
 
   ProgramStateRef State = C.getState();
 
-  if (Call.isCalled(CStrFn)) {
+  auto isCStrFnFamilyCall = [&](const CallEvent &Call) -> bool {
+for (auto CStrFn : CStrFnFamily) {
+  if (Call.isCalled(CStrFn))
+return true;
+}
+return false;
+  };
+
+  if (isCStrFnFamilyCall(Call)) {
 SVal RawPtr = Call.getReturnValue();
 if (!RawPtr.isUnknown()) {
   State = State->set(TypedR, RawPtr.getAsSymbol());
Index: include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -79,6 +79,7 @@
 
   mutable IdentifierInfo *II = nullptr;
   mutable bool IsLookupDone = false;
+  // Represent the function name or method name, like "X" or "a::b::X".
   StringRef FuncName;
   unsigned RequiredArgs;
 
@@ -96,7 +97,11 @@
   : FuncName(FuncName), RequiredArgs(RequiredArgs) {}
 
   /// Get the name of the function that this object matches.
-  StringRef getFunctionName() const { return FuncName; }
+  StringRef getFunctionName() const {
+auto QualifierNamePair = FuncName.rsplit("::");
+return QualifierNamePair.second.empty() ? QualifierNamePair.first
+: QualifierNamePair.second;
+  }
 };
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-06-13 Thread Takuto Ikuta via Phabricator via cfe-commits
takuto.ikuta added a comment.

Thank you!


https://reviews.llvm.org/D47578



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


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

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

- Introduced a one-per-query structure for relevance signals; use 
multiplication for proximity; simplify tests a bit; separate index and sema 
proximity scores.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935

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

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

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

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

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

> Sorry for the delay on this change. There's a bunch of complexity in this 
> problem that I haven't seen how to slice through:
>
> 1. the signals needed seem like a weird fit for the Symbol*Signals structs 
> for some reason (maybe my misdesign)


According to offline discussion, I added a structure  `SymbolRelevanceContext`  
that captures per-query signals like proximity paths. Not sure about the name 
though.

> 2. the inconsistency between how we do this for Sema and for Index results 
> has... only slightly good reasons

The proximity scores for index and sema are now explicitly separated to make it 
easier to understand and debug.

> 3. the URI vs filename thing is awkward
> 4. with all this, the actual scoring still seems ad-hoc and is missing 
> important parts (main header, transitive includes)
> 
>   Not all your fault that the code reflects this, the problem is tangly. But 
> it's hard for me to reason about APIs or performance or layering.
> 
>   Looking at the last point (scoring model) because it seems the most 
> tractable. I think this is basically an edit distance problem? (We can call 
> the result "proximity", start at one, and multiply by <1, or call it 
> "distance" and start at 0 and add penalties, but it's equivalent).
> 5. we're computing distances between files (glossing over URI-space vs 
> file-space)
> 6. the roots are the main file, and maybe the matching header
> 7. edits take us from a filepath to a related filepath:
>   - from a file to a header it `#include`s
>   - from a file to its parent directory
>   - from a parent directory to a child directory
>   - from a parent directory to a file in it
> 8. the distance is the smallest sum-of-penalties for any path leading from 
> the root to the symbol
> 
>   What do you think of this model?
> 
>   
> 
>   **If** the model seems reasonable, then it suggests an approach of building 
> a one-per-query data structure that computes the needed edit-distance 
> recursively, memoizing results. `SymbolRelevanceResults` could store the 
> symbol path and a pointer to the edit-distance machine, and for debugging the 
> machine would know how to describe its configuration. URI/path mapping 
> wouldn't be a performance concern (I think) if the memoization captured it.

I like how this model addresses the proximity for src/ and include/ setup. I 
think we could start with something simple and iterate, although I agree that 
we should strike for a design that would be easy to replace the proximity 
algorithm in the future.

> Let's chat offline?




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

sammccall wrote:
> ioeric wrote:
> > sammccall wrote:
> > > This doesn't look quite right to me.
> > > We can tune the details later, but in practice this seems like it's 
> > > *very* hard to get zero proximity, which is our neutral score - you need 
> > > to be 18 directories away?
> > > 
> > > FWIW, fozzie appears to give an additive boost proportional to 5-up, 
> > > where up is the number of directories from the context you have to 
> > > traverse up from the context to get to a parent of the symbol. (There's 
> > > no penalty for down-traversals probably for implementation reasons, this 
> > > should be smaller than the up-traversal penalty I think)
> > The numbers are guessed... definitely happy to tune.
> > > We can tune the details later, but in practice this seems like it's 
> > > *very* hard to get zero proximity, which is our neutral score - you need 
> > > to be 18 directories away?
> > It's 18 directories away if one file is in an ancestor directories of the 
> > other (i.e. only traverse up or down). If you need to traverse up and down, 
> > the penalty for each directory is 0.1, which takes 10 directories (up+down, 
> > so 
> > 5 up in average). I think it's useful to make this distinction because I 
> > think it's more likely for a file to use a header if it's in the file path. 
> >  
> > 
> > I'm not sure if we should use zero as the neutral score. For example, if a 
> > codebase has deep directory structure, most scores are probably going to be 
> > small; conversely, most scores would be relatively big. I think relative 
> > scores are more useful.
> > 
> > > (There's no penalty for down-traversals probably for implementation 
> > > reasons, this should be smaller than the up-traversal penalty I think)
> > Why do you think down-traversal should take less penalty?
> > 
> > If you need to traverse up and down, the penalty for each directory is 0.1, 
> > which takes 10 directories (up+down, so 5 up in average).
> I think you've halved twice there - it still seems to be 10, which is a lot.
> 
> > I'm not sure if we should use zero as the neutral score.
> Well, zero is currently the neu

[clang-tools-extra] r334606 - Reverting r334604 due to failing tests.

2018-06-13 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 13 08:02:34 2018
New Revision: 334606

URL: http://llvm.org/viewvc/llvm-project?rev=334606&view=rev
Log:
Reverting r334604 due to failing tests.

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/31500

Removed:
clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp
clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.h
clang-tools-extra/trunk/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt
clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt?rev=334606&r1=334605&r2=334606&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt Wed Jun 13 08:02:34 
2018
@@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyUtils
   ASTUtils.cpp
   DeclRefExprUtils.cpp
-  ExprMutationAnalyzer.cpp
   ExprSequence.cpp
   FixItHintUtils.cpp
   HeaderFileExtensionsUtils.cpp

Removed: clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp?rev=334605&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/ExprMutationAnalyzer.cpp (removed)
@@ -1,261 +0,0 @@
-//===-- ExprMutationAnalyzer.cpp - clang-tidy 
-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-#include "ExprMutationAnalyzer.h"
-
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "llvm/ADT/STLExtras.h"
-
-namespace clang {
-namespace tidy {
-namespace utils {
-using namespace ast_matchers;
-
-namespace {
-
-AST_MATCHER_P(LambdaExpr, hasCaptureInit, const Expr *, E) {
-  return llvm::is_contained(Node.capture_inits(), E);
-}
-
-AST_MATCHER_P(CXXForRangeStmt, hasRangeStmt,
-  ast_matchers::internal::Matcher, InnerMatcher) {
-  const DeclStmt *const Range = Node.getRangeStmt();
-  return InnerMatcher.matches(*Range, Finder, Builder);
-}
-
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-cxxTypeidExpr;
-
-AST_MATCHER(CXXTypeidExpr, isPotentiallyEvaluated) {
-  return Node.isPotentiallyEvaluated();
-}
-
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-cxxNoexceptExpr;
-
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-genericSelectionExpr;
-
-AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
-  ast_matchers::internal::Matcher, InnerMatcher) {
-  return InnerMatcher.matches(*Node.getControllingExpr(), Finder, Builder);
-}
-
-const auto nonConstReferenceType = [] {
-  return referenceType(pointee(unless(isConstQualified(;
-};
-
-} // namespace
-
-const Stmt *ExprMutationAnalyzer::findMutation(const Expr *Exp) {
-  const auto Memoized = Results.find(Exp);
-  if (Memoized != Results.end())
-return Memoized->second;
-
-  if (isUnevaluated(Exp))
-return Results[Exp] = nullptr;
-
-  for (const auto &Finder : {&ExprMutationAnalyzer::findDirectMutation,
- &ExprMutationAnalyzer::findMemberMutation,
- &ExprMutationAnalyzer::findArrayElementMutation,
- &ExprMutationAnalyzer::findCastMutation,
- &ExprMutationAnalyzer::findRangeLoopMutation,
- &ExprMutationAnalyzer::findReferenceMutation}) {
-if (const Stmt *S = (this->*Finder)(Exp))
-  return Results[Exp] = S;
-  }
-
-  return Results[Exp] = nullptr;
-}
-
-bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
-  return selectFirst(
- "expr",
- match(
- findAll(
- expr(equalsNode(Exp),
-  anyOf(
-  // `Exp` is part of the underlying expression of
-  // decltype/typeof if it has an ancestor of
-  // typeLoc.
-  hasAncestor(typeLoc(unless(
-  hasAncestor(unaryExprOrTypeTraitExpr(),
-  hasAncestor(expr(anyOf(
-  // `UnaryExprOrTypeTraitExpr` is unevaluated
-  // unless it's sizeof on VLA.
-  unaryExprOrT

[PATCH] D45679: [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

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

I had to revert due to failing tests. The revert was done in r334606 and this 
is an example of a failing bot: 
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/31500


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679



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


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

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

- Rebased.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47935

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

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

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

2018-06-13 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: lib/AST/ExprConstant.cpp:9437
+  }
+  return Success(-Value, E);
+}

This looks very suspect to me as well... This might not respect padding on 
types whose sign bit is not the MSB, such as _Fract. The same goes for the 
overflow check above.

I think it's quite important that we define the semantics of what padding bits 
should contain. Probably zeroes for unsigned types and a sexted sign bit for 
signed types.


Repository:
  rC Clang

https://reviews.llvm.org/D46915



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


r334612 - [libclang] Make c-index-test.c ISO C90 compliant.

2018-06-13 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Wed Jun 13 09:00:39 2018
New Revision: 334612

URL: http://llvm.org/viewvc/llvm-project?rev=334612&view=rev
Log:
[libclang] Make c-index-test.c ISO C90 compliant.

Fixes a build bot breakage caused by r334593.

Modified:
cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=334612&r1=334611&r2=334612&view=diff
==
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Jun 13 09:00:39 2018
@@ -2304,6 +2304,7 @@ static void print_completion_result(CXTr
   CXString BriefComment;
   CXString Annotation;
   const char *BriefCommentCString;
+  unsigned i;
   
   fprintf(file, "%s:", clang_getCString(ks));
   clang_disposeString(ks);
@@ -2365,7 +2366,6 @@ static void print_completion_result(CXTr
   }
   clang_disposeString(BriefComment);
 
-  unsigned i;
   for (i = 0; i < clang_getCompletionNumFixIts(completion_results, index);
++i) {
 CXSourceRange correction_range;


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


r334613 - [PowerPC] The __float128 type should only be available on Power9

2018-06-13 Thread Stefan Pintilie via cfe-commits
Author: stefanp
Date: Wed Jun 13 09:05:05 2018
New Revision: 334613

URL: http://llvm.org/viewvc/llvm-project?rev=334613&view=rev
Log:
[PowerPC] The __float128 type should only be available on Power9

Diasble the use of the type __float128 for PPC machines older
than Power9.

The use of -mfloat128 for PPC machine older than Power9 will result
in an error.

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

Added:
cfe/trunk/test/Driver/ppc-f128-support-check.c
Modified:
cfe/trunk/lib/Basic/Targets/PPC.cpp
cfe/trunk/lib/Basic/Targets/PPC.h
cfe/trunk/test/Preprocessor/init.c
cfe/trunk/test/Sema/float128-ld-incompatibility.cpp

Modified: cfe/trunk/lib/Basic/Targets/PPC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/PPC.cpp?rev=334613&r1=334612&r2=334613&view=diff
==
--- cfe/trunk/lib/Basic/Targets/PPC.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/PPC.cpp Wed Jun 13 09:05:05 2018
@@ -15,7 +15,6 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
-#include "llvm/ADT/StringSwitch.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -116,111 +115,37 @@ void PPCTargetInfo::getTargetDefines(con
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
 Builder.defineMacro("__STRUCT_PARM_ALIGN__", "16");
 
-  // CPU identification.
-  ArchDefineTypes defs =
-  (ArchDefineTypes)llvm::StringSwitch(CPU)
-  .Case("440", ArchDefineName)
-  .Case("450", ArchDefineName | ArchDefine440)
-  .Case("601", ArchDefineName)
-  .Case("602", ArchDefineName | ArchDefinePpcgr)
-  .Case("603", ArchDefineName | ArchDefinePpcgr)
-  .Case("603e", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
-  .Case("603ev", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
-  .Case("604", ArchDefineName | ArchDefinePpcgr)
-  .Case("604e", ArchDefineName | ArchDefine604 | ArchDefinePpcgr)
-  .Case("620", ArchDefineName | ArchDefinePpcgr)
-  .Case("630", ArchDefineName | ArchDefinePpcgr)
-  .Case("7400", ArchDefineName | ArchDefinePpcgr)
-  .Case("7450", ArchDefineName | ArchDefinePpcgr)
-  .Case("750", ArchDefineName | ArchDefinePpcgr)
-  .Case("970", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr |
-   ArchDefinePpcsq)
-  .Case("a2", ArchDefineA2)
-  .Case("a2q", ArchDefineName | ArchDefineA2 | ArchDefineA2q)
-  .Case("pwr3", ArchDefinePpcgr)
-  .Case("pwr4", ArchDefineName | ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("pwr5", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr |
-ArchDefinePpcsq)
-  .Case("pwr5x", ArchDefineName | ArchDefinePwr5 | ArchDefinePwr4 |
- ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("pwr6", ArchDefineName | ArchDefinePwr5x | ArchDefinePwr5 |
-ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("pwr6x", ArchDefineName | ArchDefinePwr6 | ArchDefinePwr5x |
- ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr 
|
- ArchDefinePpcsq)
-  .Case("pwr7", ArchDefineName | ArchDefinePwr6x | ArchDefinePwr6 |
-ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4 |
-ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("pwr8", ArchDefineName | ArchDefinePwr7 | ArchDefinePwr6x |
-ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5 |
-ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("pwr9", ArchDefineName | ArchDefinePwr8 | ArchDefinePwr7 |
-ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x 
|
-ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
-ArchDefinePpcsq)
-  .Case("power3", ArchDefinePpcgr)
-  .Case("power4", ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("power5", ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
-  ArchDefinePpcsq)
-  .Case("power5x", ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4 |
-   ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("power6", ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5 |
-  ArchDefinePwr4 | ArchDefinePpcgr |
-  ArchDefinePpcsq)
-  .Case("power6x", ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x |
-   ArchDefinePwr5 | ArchDefinePwr4 |
-   ArchDefinePpcgr | ArchDefinePpcsq)
-  .Case("power7", ArchDefinePwr7 | ArchDefinePwr6x | ArchDefinePwr6 |
-   

[PATCH] D48088: [PowerPC] The __float128 type should only be available on Power9

2018-06-13 Thread Stefan Pintilie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334613: [PowerPC] The __float128 type should only be 
available on Power9 (authored by stefanp, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D48088

Files:
  lib/Basic/Targets/PPC.cpp
  lib/Basic/Targets/PPC.h
  test/Driver/ppc-f128-support-check.c
  test/Preprocessor/init.c
  test/Sema/float128-ld-incompatibility.cpp

Index: test/Driver/ppc-f128-support-check.c
===
--- test/Driver/ppc-f128-support-check.c
+++ test/Driver/ppc-f128-support-check.c
@@ -0,0 +1,20 @@
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=pwr9 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=HASF128
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=power9 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=HASF128
+
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=pwr8 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=NOF128
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=pwr7 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=NOF128
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=NOF128
+
+#ifdef __FLOAT128__
+static_assert(false, "__float128 enabled");
+#endif
+
+// HASF128: __float128 enabled
+// HASF128-NOT: option '-mfloat128' cannot be specified with
+// NOF128: option '-mfloat128' cannot be specified with
+
Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -6370,7 +6370,7 @@
 // PPCPOWER9:#define _ARCH_PWR7 1
 // PPCPOWER9:#define _ARCH_PWR9 1
 //
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +float128 -target-cpu power8 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-FLOAT128 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +float128 -target-cpu power9 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-FLOAT128 %s
 // PPC-FLOAT128:#define __FLOAT128__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-LINUX %s
Index: test/Sema/float128-ld-incompatibility.cpp
===
--- test/Sema/float128-ld-incompatibility.cpp
+++ test/Sema/float128-ld-incompatibility.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 \
-// RUN: -triple powerpc64le-unknown-linux-gnu -target-cpu pwr8 \
+// RUN: -triple powerpc64le-unknown-linux-gnu -target-cpu pwr9 \
 // RUN: -target-feature +float128 %s
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -Wno-parentheses %s
 
Index: lib/Basic/Targets/PPC.h
===
--- lib/Basic/Targets/PPC.h
+++ lib/Basic/Targets/PPC.h
@@ -18,13 +18,38 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Compiler.h"
 
 namespace clang {
 namespace targets {
 
 // PPC abstract base class
 class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
+
+  /// Flags for architecture specific defines.
+  typedef enum {
+ArchDefineNone = 0,
+ArchDefineName = 1 << 0, //  is substituted for arch name.
+ArchDefinePpcgr = 1 << 1,
+ArchDefinePpcsq = 1 << 2,
+ArchDefine440 = 1 << 3,
+ArchDefine603 = 1 << 4,
+ArchDefine604 = 1 << 5,
+ArchDefinePwr4 = 1 << 6,
+ArchDefinePwr5 = 1 << 7,
+ArchDefinePwr5x = 1 << 8,
+ArchDefinePwr6 = 1 << 9,
+ArchDefinePwr6x = 1 << 10,
+ArchDefinePwr7 = 1 << 11,
+ArchDefinePwr8 = 1 << 12,
+ArchDefinePwr9 = 1 << 13,
+ArchDefineA2 = 1 << 14,
+ArchDefineA2q = 1 << 15
+  } ArchDefineTypes;
+
+
+  ArchDefineTypes ArchDefs;
   static const Builtin::Info BuiltinInfo[];
   static const char *const GCCRegNames[];
   static const TargetInfo::GCCRegAlias GCCRegAliases[];
@@ -50,34 +75,13 @@
   : TargetInfo(Triple), HasAltivec(false), HasVSX(false),
 HasP8Vector(false), HasP8Crypto(false), HasDirectMove(false),
 HasQPX(false), HasHTM(false), HasBPERMD(false), HasExtDiv(false),
-HasP9Vector(false) {
+HasP9Vector(false), ArchDefs(ArchDefineNone) {
 SuitableAlign = 128;
 SimdDefaultAlign = 128;
 LongDoubleWidth = LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble();
   }
 
-  /// Flags for architecture specific defines.
-  typedef enum {
-ArchDefineNone = 0,
-ArchDefineName = 1 << 0, //  is substitute

[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 151184.
leonardchan marked an inline comment as done.

Repository:
  rC Clang

https://reviews.llvm.org/D46911

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/BuiltinTypes.def
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/Analysis/PrintfFormatString.cpp
  lib/Basic/TargetInfo.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Index/USRGeneration.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/Frontend/fixed_point.c
  test/Frontend/fixed_point_bit_widths.c
  test/Frontend/fixed_point_errors.c
  test/Frontend/fixed_point_errors.cpp

Index: test/Frontend/fixed_point_errors.cpp
===
--- test/Frontend/fixed_point_errors.cpp
+++ test/Frontend/fixed_point_errors.cpp
@@ -1,5 +1,9 @@
+// RUN: %clang_cc1 -x c++ %s -verify
 // RUN: %clang_cc1 -x c++ -ffixed-point %s -verify
 
 // Name namgling is not provided for fixed point types in c++
 
 _Accum accum;   // expected-error{{unknown type name '_Accum'}}
+_Fract fract;   // expected-error{{unknown type name '_Fract'}}
+_Sat _Accum sat_accum;  // expected-error{{unknown type name '_Sat'}}
+// expected-error@-1{{expected ';' after top level declarator}}
Index: test/Frontend/fixed_point_errors.c
===
--- test/Frontend/fixed_point_errors.c
+++ test/Frontend/fixed_point_errors.c
@@ -5,6 +5,14 @@
 
 long long _Accum longlong_accum;  // expected-error{{'long long _Accum' is invalid}}
 unsigned long long _Accum u_longlong_accum;   // expected-error{{'long long _Accum' is invalid}}
+long long _Fract longlong_fract;  // expected-error{{'long long _Fract' is invalid}}
+unsigned long long _Fract u_longlong_fract;   // expected-error{{'long long _Fract' is invalid}}
+
+_Sat long long _Accum sat_longlong_accum; // expected-error{{'long long _Accum' is invalid}}
+_Sat unsigned long long _Accum sat_u_longlong_accum;  // expected-error{{'long long _Accum' is invalid}}
+_Sat long long _Fract sat_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
+_Sat unsigned long long _Fract sat_u_longlong_fract;  // expected-error{{'long long _Fract' is invalid}}
+
 
 /* Although _Complex types work with floating point numbers, the extension
  * provides no info for complex fixed point types. */
@@ -19,9 +27,67 @@
 _Complex _Accum cmplx_s_accum;  // expected-error{{'_Complex _Accum' is invalid}}
 _Complex long _Accum cmplx_s_long_accum;// expected-error{{'_Complex _Accum' is invalid}}
 
+_Complex signed short _Fract cmplx_s_short_fract;   // expected-error{{'_Complex _Fract' is invalid}}
+_Complex signed _Fract cmplx_s_fract;   // expected-error{{'_Complex _Fract' is invalid}}
+_Complex signed long _Fract cmplx_s_long_fract; // expected-error{{'_Complex _Fract' is invalid}}
+_Complex unsigned short _Fract cmplx_u_short_fract; // expected-error{{'_Complex _Fract' is invalid}}
+_Complex unsigned _Fract cmplx_u_fract; // expected-error{{'_Complex _Fract' is invalid}}
+_Complex unsigned long _Fract cmplx_u_long_fract;   // expected-error{{'_Complex _Fract' is invalid}}
+_Complex short _Fract cmplx_s_short_fract;  // expected-error{{'_Complex _Fract' is invalid}}
+_Complex _Fract cmplx_s_fract;  // expected-error{{'_Complex _Fract' is invalid}}
+_Complex long _Fract cmplx_s_long_fract;// expected-error{{'_Complex _Fract' is invalid}}
+
+_Complex _Sat signed short _Accum cmplx_sat_s_short_accum;   // expected-error{{'_Complex _Accum' is invalid}}
+_Complex _Sat signed _Accum cmplx_sat_s_accum;   // expected-error{{'_Complex _Accum' is invalid}}
+_Complex _Sat signed long _Accum cmplx_sat_s_long_accum; // expected-error{{'_Complex _Accum' is invalid}}
+_Complex _Sat unsigned short _Accum cmplx_sat_u_short_accum; // expected-error{{'_Complex _Accum' is invalid}}
+_Complex _Sat unsigned _Accum cmplx_sat_u_accum; // expected-error{{'_Complex _Accum' is invalid}}
+_Complex _Sat unsigned long _Accum cmplx_sat_u_long_accum;   // expected-error{{'_Complex _Accum' is invalid}}
+_Complex _Sat short _Accum cmplx_sat_s_short_accum;  // expected-error{{'_Complex _Accum' is i

[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

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



Comment at: test/Frontend/fixed_point_bit_widths.c:44
+
+// CHECK-NEXT: @size_SsF  = dso_local global i{{[0-9]+}} 2
+// CHECK-NEXT: @size_SF   = dso_local global i{{[0-9]+}} 4

ebevhan wrote:
> Wait; should these dso_local be `{{.*}}`?
They should, I forgot to get the latest diff which checks this since not all 
targets produce `dso_local`.


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[PATCH] D48027: [analyzer] Improve `CallDescription` to handle c++ method.

2018-06-13 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/DanglingInternalBufferChecker.cpp:32
  check::PostCall> {
-  CallDescription CStrFn;
+  const llvm::SmallVector CStrFnFamily = {
+{"std::basic_string::c_str"}, {"std::basic_string::c_str"},

I am not sure if this is the right solution in case of this check. We should 
track `c_str` calls regardless of what the template parameter is, so supporting 
any instantiation of `basic_string` is desired. This might not be the case, 
however, for other checks. 

If we think it is more likely we do not care about the template arguments, 
maybe a separate API could be used, where we pass the qualified name of the 
class separately without the template arguments.
Alternatively, we could use matches name so the users could use regexps.

At this point I also wonder what isCalled API gives us compared to matchers? 
Maybe it is more convenient to use than calling a `match`. Also, isCalled API 
has an IdentifierInfo cached which could be used for relatively efficient 
checks.

@NoQ what do you think?





Comment at: lib/StaticAnalyzer/Checkers/DanglingInternalBufferChecker.cpp:65
   auto *TypeDecl = TypedR->getValueType()->getAsCXXRecordDecl();
   if (TypeDecl->getName() != "basic_string")
 return;

If we check for fully qualified names, this check might be redundant.



Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:273
+  auto Matches =
+  match(namedDecl(hasName(CD.FuncName)).bind("match_qualified_name"), *ND,
+LCtx->getAnalysisDeclContext()->getASTContext());

Doesn't match also traverse the subtree of the AST? We only need to check if 
that particular node matches the qualified name. I wonder if we could, during 
the traversal, find another node that is a match unintentionally.


Repository:
  rC Clang

https://reviews.llvm.org/D48027



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


[PATCH] D48132: [COFF] Add ARM64 intrinsics: __yield, __wfe, __wfi, __sev, __sevl

2018-06-13 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang created this revision.
mgrang added reviewers: mstorsjo, compnerd.
Herald added a reviewer: javed.absar.
Herald added subscribers: chrib, kristof.beyls.

These intrinsics result in hint instructions. They are provided here for MSVC 
ARM64 compatibility.


Repository:
  rC Clang

https://reviews.llvm.org/D48132

Files:
  include/clang/Basic/BuiltinsAArch64.def
  lib/CodeGen/CGBuiltin.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
@@ -24,3 +24,38 @@
 
 // CHECK-MSVC: @llvm.aarch64.isb(i32 0)
 // CHECK-LINUX: error: implicit declaration of function '__isb'
+
+void check__yield(void) {
+  __yield();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 1)
+// CHECK-LINUX: error: implicit declaration of function '__yield'
+
+void check__wfe(void) {
+  __wfe();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 2)
+// CHECK-LINUX: error: implicit declaration of function '__wfe'
+
+void check__wfi(void) {
+  __wfi();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 3)
+// CHECK-LINUX: error: implicit declaration of function '__wfi'
+
+void check__sev(void) {
+  __sev();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 4)
+// CHECK-LINUX: error: implicit declaration of function '__sev'
+
+void check__sevl(void) {
+  __sevl();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 5)
+// CHECK-LINUX: error: implicit declaration of function '__sevl'
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -6362,18 +6362,23 @@
 HintID = 0;
 break;
   case AArch64::BI__builtin_arm_yield:
+  case AArch64::BI__yield:
 HintID = 1;
 break;
   case AArch64::BI__builtin_arm_wfe:
+  case AArch64::BI__wfe:
 HintID = 2;
 break;
   case AArch64::BI__builtin_arm_wfi:
+  case AArch64::BI__wfi:
 HintID = 3;
 break;
   case AArch64::BI__builtin_arm_sev:
+  case AArch64::BI__sev:
 HintID = 4;
 break;
   case AArch64::BI__builtin_arm_sevl:
+  case AArch64::BI__sevl:
 HintID = 5;
 break;
   }
Index: include/clang/Basic/BuiltinsAArch64.def
===
--- include/clang/Basic/BuiltinsAArch64.def
+++ include/clang/Basic/BuiltinsAArch64.def
@@ -65,9 +65,15 @@
 BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
+// MSVC
 LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES)
+LANGBUILTIN(__yield, "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfe,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfi,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sev,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sevl,  "v", "",   ALL_MS_LANGUAGES)
 
 // MSVC intrinsics for volatile but non-acquire/release loads and stores
 LANGBUILTIN(__iso_volatile_load8,   "ccCD*", "n", ALL_MS_LANGUAGES)


Index: test/CodeGen/arm64-microsoft-intrinsics.c
===
--- test/CodeGen/arm64-microsoft-intrinsics.c
+++ test/CodeGen/arm64-microsoft-intrinsics.c
@@ -24,3 +24,38 @@
 
 // CHECK-MSVC: @llvm.aarch64.isb(i32 0)
 // CHECK-LINUX: error: implicit declaration of function '__isb'
+
+void check__yield(void) {
+  __yield();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 1)
+// CHECK-LINUX: error: implicit declaration of function '__yield'
+
+void check__wfe(void) {
+  __wfe();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 2)
+// CHECK-LINUX: error: implicit declaration of function '__wfe'
+
+void check__wfi(void) {
+  __wfi();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 3)
+// CHECK-LINUX: error: implicit declaration of function '__wfi'
+
+void check__sev(void) {
+  __sev();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 4)
+// CHECK-LINUX: error: implicit declaration of function '__sev'
+
+void check__sevl(void) {
+  __sevl();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 5)
+// CHECK-LINUX: error: implicit declaration of function '__sevl'
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -6362,18 +6362,23 @@
 HintID = 0;
 break;
   case AArch64::BI__builtin_arm_yield:
+  case AArch64::BI__yield:
 HintID = 1;
 break;
   case AArch64::BI__builtin_arm_wfe:
+  case AArch64::BI__wfe:
 HintID = 2;
 break;
   case AArch64::BI__builtin_arm_wfi:
+  case AArch64::BI__wfi:
 HintID = 3;
 break;
   case AArch64::BI__builtin_arm_sev:
+  case AArch64::BI__sev:
 HintID = 4;
 break;
   case AArch64::BI__builtin_arm_sevl:
+  case AArch64::BI__sevl:
 HintID = 5;
 break;
   }
Index: include/clang/Basic/BuiltinsAArch64.def

[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-13 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

I'll need someone to commit. Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2018-06-13 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.
Herald added a subscriber: mikhail.ramalho.

Any idea how to proceed?


https://reviews.llvm.org/D35110



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


[PATCH] D48036: [CUDA] Make min/max shims host+device.

2018-06-13 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

> Last comment in the bug pointed out that those overloads should be constexpr 
> in c++14. Maybe in a separate patch, though.

Yeah, would prefer to do it in a separate patch.  It's possible that having 
constexpr min/max in C++14 mode *without a C++14 standard library* will cause 
problems.  (Don't mean to FUD it -- we should try.  I just would like to be 
able to roll them back separately.  :)


https://reviews.llvm.org/D48036



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


r334619 - [Basic] Fix -Wreorder warning

2018-06-13 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Jun 13 09:45:12 2018
New Revision: 334619

URL: http://llvm.org/viewvc/llvm-project?rev=334619&view=rev
Log:
[Basic] Fix -Wreorder warning

Just use field initializers that don't suffer from this problem

Modified:
cfe/trunk/lib/Basic/Targets/PPC.h

Modified: cfe/trunk/lib/Basic/Targets/PPC.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/PPC.h?rev=334619&r1=334618&r2=334619&view=diff
==
--- cfe/trunk/lib/Basic/Targets/PPC.h (original)
+++ cfe/trunk/lib/Basic/Targets/PPC.h Wed Jun 13 09:45:12 2018
@@ -49,33 +49,30 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetI
   } ArchDefineTypes;
 
 
-  ArchDefineTypes ArchDefs;
+  ArchDefineTypes ArchDefs = ArchDefineNone;
   static const Builtin::Info BuiltinInfo[];
   static const char *const GCCRegNames[];
   static const TargetInfo::GCCRegAlias GCCRegAliases[];
   std::string CPU;
 
   // Target cpu features.
-  bool HasAltivec;
-  bool HasVSX;
-  bool HasP8Vector;
-  bool HasP8Crypto;
-  bool HasDirectMove;
-  bool HasQPX;
-  bool HasHTM;
-  bool HasBPERMD;
-  bool HasExtDiv;
-  bool HasP9Vector;
+  bool HasAltivec = false;
+  bool HasVSX = false;
+  bool HasP8Vector = false;
+  bool HasP8Crypto = false;
+  bool HasDirectMove = false;
+  bool HasQPX = false;
+  bool HasHTM = false;
+  bool HasBPERMD = false;
+  bool HasExtDiv = false;
+  bool HasP9Vector = false;
 
 protected:
   std::string ABI;
 
 public:
   PPCTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
-  : TargetInfo(Triple), HasAltivec(false), HasVSX(false),
-HasP8Vector(false), HasP8Crypto(false), HasDirectMove(false),
-HasQPX(false), HasHTM(false), HasBPERMD(false), HasExtDiv(false),
-HasP9Vector(false), ArchDefs(ArchDefineNone) {
+  : TargetInfo(Triple) {
 SuitableAlign = 128;
 SimdDefaultAlign = 128;
 LongDoubleWidth = LongDoubleAlign = 128;


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


[PATCH] D48134: [CodeGen] make nan builtins pure rather than const (PR37778)

2018-06-13 Thread Sanjay Patel via Phabricator via cfe-commits
spatel created this revision.
spatel added reviewers: gfalcon, lebedev.ri.
Herald added a subscriber: mcrosier.

https://bugs.llvm.org/show_bug.cgi?id=37778
...shows a miscompile resulting from marking nan builtins as 'const'.

The nan libcalls/builtins take a pointer argument:
http://www.cplusplus.com/reference/cmath/nan-function/
...and the chars dereferenced by that arg are used to fill in the NaN constant 
payload bits.

"const" means that the pointer argument isn't dereferenced. That's translated 
to "readnone" in LLVM.
"pure" means that the pointer argument may be dereferenced. That's translated 
to "readonly" in LLVM.

This change prevents the IR optimizer from killing the lead-up to the nan call 
here:

  double a() {
char buf[4];
buf[0] = buf[1] = buf[2] = '9';
buf[3] = '\0';
return __builtin_nan(buf);
  }

...the optimizer isn't currently able to simplify this to a constant as we 
might hope, but this patch should solve the miscompile.


https://reviews.llvm.org/D48134

Files:
  include/clang/Basic/Builtins.def
  test/CodeGen/math-builtins.c


Index: test/CodeGen/math-builtins.c
===
--- test/CodeGen/math-builtins.c
+++ test/CodeGen/math-builtins.c
@@ -90,25 +90,25 @@
 
   __builtin_nan(c);__builtin_nanf(c);   __builtin_nanl(c); 
__builtin_nanf128(c);
 
-// NO__ERRNO: declare double @nan(i8*) [[READNONE]]
-// NO__ERRNO: declare float @nanf(i8*) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @nanl(i8*) [[READNONE]]
-// NO__ERRNO: declare fp128 @nanf128(i8*) [[READNONE]]
-// HAS_ERRNO: declare double @nan(i8*) [[READNONE:#[0-9]+]]
-// HAS_ERRNO: declare float @nanf(i8*) [[READNONE]]
-// HAS_ERRNO: declare x86_fp80 @nanl(i8*) [[READNONE]]
-// HAS_ERRNO: declare fp128 @nanf128(i8*) [[READNONE]]
+// NO__ERRNO: declare double @nan(i8*) [[PURE:#[0-9]+]]
+// NO__ERRNO: declare float @nanf(i8*) [[PURE]]
+// NO__ERRNO: declare x86_fp80 @nanl(i8*) [[PURE]]
+// NO__ERRNO: declare fp128 @nanf128(i8*) [[PURE]]
+// HAS_ERRNO: declare double @nan(i8*) [[PURE:#[0-9]+]]
+// HAS_ERRNO: declare float @nanf(i8*) [[PURE]]
+// HAS_ERRNO: declare x86_fp80 @nanl(i8*) [[PURE]]
+// HAS_ERRNO: declare fp128 @nanf128(i8*) [[PURE]]
 
   __builtin_nans(c);__builtin_nansf(c);   __builtin_nansl(c); 
__builtin_nansf128(c);
 
-// NO__ERRNO: declare double @nans(i8*) [[READNONE]]
-// NO__ERRNO: declare float @nansf(i8*) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @nansl(i8*) [[READNONE]]
-// NO__ERRNO: declare fp128 @nansf128(i8*) [[READNONE]]
-// HAS_ERRNO: declare double @nans(i8*) [[READNONE]]
-// HAS_ERRNO: declare float @nansf(i8*) [[READNONE]]
-// HAS_ERRNO: declare x86_fp80 @nansl(i8*) [[READNONE]]
-// HAS_ERRNO: declare fp128 @nansf128(i8*) [[READNONE]]
+// NO__ERRNO: declare double @nans(i8*) [[PURE]]
+// NO__ERRNO: declare float @nansf(i8*) [[PURE]]
+// NO__ERRNO: declare x86_fp80 @nansl(i8*) [[PURE]]
+// NO__ERRNO: declare fp128 @nansf128(i8*) [[PURE]]
+// HAS_ERRNO: declare double @nans(i8*) [[PURE]]
+// HAS_ERRNO: declare float @nansf(i8*) [[PURE]]
+// HAS_ERRNO: declare x86_fp80 @nansl(i8*) [[PURE]]
+// HAS_ERRNO: declare fp128 @nansf128(i8*) [[PURE]]
 
   __builtin_pow(f,f);__builtin_powf(f,f);   __builtin_powl(f,f);
 
@@ -188,7 +188,7 @@
 // NO__ERRNO: declare double @cbrt(double) [[READNONE]]
 // NO__ERRNO: declare float @cbrtf(float) [[READNONE]]
 // NO__ERRNO: declare x86_fp80 @cbrtl(x86_fp80) [[READNONE]]
-// HAS_ERRNO: declare double @cbrt(double) [[READNONE]]
+// HAS_ERRNO: declare double @cbrt(double) [[READNONE:#[0-9]+]]
 // HAS_ERRNO: declare float @cbrtf(float) [[READNONE]]
 // HAS_ERRNO: declare x86_fp80 @cbrtl(x86_fp80) [[READNONE]]
 
@@ -581,9 +581,11 @@
 // NO__ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 // NO__ERRNO: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
 // NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// NO__ERRNO: attributes [[PURE]] = { {{.*}}readonly{{.*}} }
 
 // HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
 // HAS_ERRNO: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
+// HAS_ERRNO: attributes [[PURE]] = { {{.*}}readonly{{.*}} }
 // HAS_ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 
 // HAS_ERRNO_GNU: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -137,14 +137,14 @@
 BUILTIN(__builtin_modf , "ddd*"  , "Fn")
 BUILTIN(__builtin_modff, "fff*"  , "Fn")
 BUILTIN(__builtin_modfl, "LdLdLd*", "Fn")
-BUILTIN(__builtin_nan,  "dcC*" , "ncF")
-BUILTIN(__builtin_nanf, "fcC*" , "ncF")
-BUILTIN(__builtin_nanl, "LdcC*", "ncF")
-BUILTIN(__builtin_nanf128, "LLdcC*", "ncF")
-BUILTIN(__builtin_nans,  "dcC*" , "ncF")
-BUILTIN(__builtin_nansf, "fcC*" , "ncF")
-BUILTIN(__builtin_nansl, "LdcC*", "

[PATCH] D48036: [CUDA] Make min/max shims host+device.

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

Ack.


https://reviews.llvm.org/D48036



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


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

2018-06-13 Thread Matthew Voss via Phabricator via cfe-commits
ormris closed this revision.
ormris added a comment.

This change has been committed, so I'm closing this review.

https://reviews.llvm.org/rC334554


Repository:
  rC Clang

https://reviews.llvm.org/D47044



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


[libcxx] r334621 - Merging r323390:

2018-06-13 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Wed Jun 13 09:57:18 2018
New Revision: 334621

URL: http://llvm.org/viewvc/llvm-project?rev=334621&view=rev
Log:
Merging r323390:


r323390 | ericwf | 2018-01-24 16:02:48 -0800 (Wed, 24 Jan 2018) | 9 lines

Fix PR35564 - std::list splice/erase incorrectly throw in debug mode.

There was a bug in the implementation of splice where the container
sizes were updated before decrementing one of the iterators. Afterwards,
the result of decrementing the iterator was flagged as UB by the debug
implementation because the container was reported to be empty.

This patch fixes that bug by delaying the updating of the container
sizes until after the iterators have been correctly constructed.


Modified:
libcxx/branches/release_60/include/list

libcxx/branches/release_60/test/libcxx/debug/containers/db_sequence_container_iterators.pass.cpp

Modified: libcxx/branches/release_60/include/list
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_60/include/list?rev=334621&r1=334620&r2=334621&view=diff
==
--- libcxx/branches/release_60/include/list (original)
+++ libcxx/branches/release_60/include/list Wed Jun 13 09:57:18 2018
@@ -2058,15 +2058,15 @@ list<_Tp, _Alloc>::splice(const_iterator
 #endif
 if (__f != __l)
 {
+__link_pointer __first = __f.__ptr_;
+--__l;
+__link_pointer __last = __l.__ptr_;
 if (this != &__c)
 {
-size_type __s = _VSTD::distance(__f, __l);
+size_type __s = _VSTD::distance(__f, __l) + 1;
 __c.__sz() -= __s;
 base::__sz() += __s;
 }
-__link_pointer __first = __f.__ptr_;
---__l;
-__link_pointer __last = __l.__ptr_;
 base::__unlink_nodes(__first, __last);
 __link_nodes(__p.__ptr_, __first, __last);
 #if _LIBCPP_DEBUG_LEVEL >= 2

Modified: 
libcxx/branches/release_60/test/libcxx/debug/containers/db_sequence_container_iterators.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_60/test/libcxx/debug/containers/db_sequence_container_iterators.pass.cpp?rev=334621&r1=334620&r2=334621&view=diff
==
--- 
libcxx/branches/release_60/test/libcxx/debug/containers/db_sequence_container_iterators.pass.cpp
 (original)
+++ 
libcxx/branches/release_60/test/libcxx/debug/containers/db_sequence_container_iterators.pass.cpp
 Wed Jun 13 09:57:18 2018
@@ -42,6 +42,7 @@ public:
 Base::run();
 try {
   FrontOnEmptyContainer();
+
   if constexpr (CT != CT_ForwardList) {
 AssignInvalidates();
 BackOnEmptyContainer();
@@ -50,6 +51,8 @@ public:
 InsertIterIterIter();
 EmplaceIterValue();
 EraseIterIter();
+  } else {
+SpliceFirstElemAfter();
   }
   if constexpr (CT == CT_Vector || CT == CT_Deque || CT == CT_List) {
 PopBack();
@@ -57,12 +60,66 @@ public:
   if constexpr (CT == CT_List || CT == CT_Deque) {
 PopFront(); // FIXME: Run with forward list as well
   }
+  if constexpr (CT == CT_List || CT == CT_ForwardList) {
+RemoveFirstElem();
+  }
+  if constexpr (CT == CT_List) {
+SpliceFirstElem();
+  }
 } catch (...) {
   assert(false && "uncaught debug exception");
 }
   }
 
 private:
+  static void RemoveFirstElem() {
+// See llvm.org/PR35564
+CHECKPOINT("remove()");
+{
+  Container C = makeContainer(1);
+  auto FirstVal = *(C.begin());
+  C.remove(FirstVal);
+  assert(C.empty());
+}
+{
+  Container C = {1, 1, 1, 1};
+  auto FirstVal = *(C.begin());
+  C.remove(FirstVal);
+  assert(C.empty());
+}
+  }
+
+  static void SpliceFirstElem() {
+// See llvm.org/PR35564
+CHECKPOINT("splice()");
+{
+  Container C = makeContainer(1);
+  Container C2;
+  C2.splice(C2.end(), C, C.begin(), ++C.begin());
+}
+{
+  Container C = makeContainer(1);
+  Container C2;
+  C2.splice(C2.end(), C, C.begin());
+}
+  }
+
+
+  static void SpliceFirstElemAfter() {
+// See llvm.org/PR35564
+CHECKPOINT("splice()");
+{
+  Container C = makeContainer(1);
+  Container C2;
+  C2.splice_after(C2.begin(), C, C.begin(), ++C.begin());
+}
+{
+  Container C = makeContainer(1);
+  Container C2;
+  C2.splice_after(C2.begin(), C, C.begin());
+}
+  }
+
   static void AssignInvalidates() {
 CHECKPOINT("assign(Size, Value)");
 Container C(allocator_type{});


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


[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-13 Thread Gabor Buella via Phabricator via cfe-commits
GBuella added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:10090-10100
+// _CMP_TRUE_UQ, _CMP_TRUE_US produce -1,-1... vector
+// on any input and _CMP_FALSE_OQ, _CMP_FALSE_OS produce 0, 0...
+if (CC == 0xf || CC == 0xb || CC == 0x1b || CC == 0x1f) {
+   llvm::Type *ResultType = ConvertType(E->getType());
+
+   Value *Constant = (CC == 0xf || CC == 0x1f) ?
+  llvm::Constant::getAllOnesValue(ResultType) :

spatel wrote:
>   llvm::Type *ResultType = ConvertType(E->getType());
>   if (CC == 0x0f || CC == 0x1f)
> return llvm::Constant::getAllOnesValue(ResultType);
>   if (CC == 0x0b || CC == 0x1b)
> return llvm::Constant::getNullValue(ResultType);
> 
> ?
> 
> Also, can we use the defined predicate names instead of hex values in this 
> code?
Well, I believe we would need to predefine them first.
I only found those in the client header `avxintrin.h`.


https://reviews.llvm.org/D45616



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


[PATCH] D48134: [CodeGen] make nan builtins pure rather than const (PR37778)

2018-06-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

Makes sense.


https://reviews.llvm.org/D48134



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


[PATCH] D47672: [Headers] Add _Interlocked*_HLEAcquire/_HLERelease

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

FWIW, I found a cfe-dev thread about adding HLE support 
http://lists.llvm.org/pipermail/cfe-dev/2013-February/028031.html And a bunch 
of dead patches in phabricator https://reviews.llvm.org/people/revisions/110/

I also spoke to Andi Kleen here at Intel to make sure I got these inline 
assembly versions correct. And he's not sure CPython should be using these the 
way it is. It looks like they try to use the HLE versions anytime the memory 
order is acquire/release. But HLE isn't suitable for every acquire/release.


https://reviews.llvm.org/D47672



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


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

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



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

ebevhan wrote:
> leonardchan wrote:
> > ebevhan wrote:
> > > leonardchan wrote:
> > > > ebevhan wrote:
> > > > > I suspect it's still possible to calculate the ibits based on the 
> > > > > fbits, even for _Accum.
> > > > > 
> > > > > Are the unsigned values needed? The fbits for unsigned _Fract are the 
> > > > > same as for signed _Fract if SameFBits is set, and +1 otherwise. The 
> > > > > same should go for unsigned _Accum, but I don't think it's entirely 
> > > > > clear how this affects the integral part.
> > > > Similar to the previous comment, if we choose to make SameFBits 
> > > > dependent on/controlled by the target, then I think it would be better 
> > > > for the target to explicitly specify the integral bits since there 
> > > > could be some cases where there may be padding (such as for unsigned 
> > > > _Accum types if this flag is set), and in this case, I think it should 
> > > > be explicit that the `bit_width != IBits + FBits`.
> > > > 
> > > > We also can't fill in that padding for the unsigned _Accum types as an 
> > > > extra integral bit since the standard says that `"each signed accum 
> > > > type has at least as many integral bits as its corresponding unsigned 
> > > > accum type".`
> > > > 
> > > > For the unsigned _Fract values, I think we can get rid of them if we 
> > > > choose to keep the flag instead, but it would no longer apply to 
> > > > unsigned _Accum types since it would allow for extra padding in these 
> > > > types and would conflict with the logic of `bit_width == IBits + FBits`
> > > > 
> > > > For now, I actually think the simplest option is to keep these target 
> > > > properties, but have the target override them individually, with checks 
> > > > to make sure the values adhere to the standard.
> > > Is it not the case that `bitwidth != IBits + FBits` for signed types 
> > > only? Signed types require a sign bit (which is neither a fractional bit 
> > > nor an integral bit, according to spec) but unsigned types do not, and if 
> > > IBits and FBits for the signed and unsigned types are the same, the MSB 
> > > is simply a padding bit, at least for _Accum (for _Fract everything above 
> > > the fbits is padding). 
> > > 
> > > My reasoning for keeping the number of configurable values down was to 
> > > limit the number of twiddly knobs to make the implementation simpler. 
> > > Granting a lot of freedom is nice, but I suspect that it will be quite 
> > > hard to get the implementation working properly for every valid 
> > > configuration. I also don't really see much of a reason for `FBits != 
> > > UFBits` in general. I know the spec gives a recommendation to implement 
> > > it that way, but I think the benefit of normalizing the signed and 
> > > unsigned representations outweighs the lost bit in the unsigned type.
> > > 
> > > It's hard to say what the differences are beyond that since I'm not sure 
> > > how you plan on treating padding bits. In our implementation, padding 
> > > bits (the MSB in all of the unsigned types for us) after any operation 
> > > are zeroed.
> > I see. The implementation would be much simpler this way. The initial idea 
> > was to treat the padding bits as "don't care" bits where we would mask only 
> > the data bits when doing operations like comparisons that look at the whole 
> > integer.
> That does work, but for binary operations it means you might need multiple 
> maskings per operation. If you mask after every operation instead, you only 
> need one. In our implementation, the only padding bit we have is the MSB in 
> the unsigned types. We simply insert a 'bit clear' after every operation that 
> produces an unsigned type (with some exceptions).
> 
> The E-C spec says that padding bits are 'unspecified', but 
> implementation-wise, they have to be defined to something in order to operate 
> on them. So long as you ensure that it is never possible to observe anything 
> but zero in those bits from a program perspective, most operations just work. 
> Naturally, there are ways to subvert this design. If you have a `signed 
> _Fract *` and cast it to an `unsigned _Fract *` and the values happen to be 
> negative, the padding bit will be set and you'll get exciting behavior.
> 
> Although... I just realized that the topmost half of the `_Fract`s in your 
> configuration is all padding. That might make things a bit more complicated 
> for things like signed types... Ideally the sign bit would be extended into 
> the padding for those.
Yeah, I initially had 2 general purpose ideas for handling the padding:

- Zero/sign extend them after all operations that modify the value (+, *, <<, 
casting to 
 another type, ...). This way we know the sign part of a fixed point type, 
regardl

r334628 - [CodeGen] make nan builtins pure rather than const (PR37778)

2018-06-13 Thread Sanjay Patel via cfe-commits
Author: spatel
Date: Wed Jun 13 10:54:52 2018
New Revision: 334628

URL: http://llvm.org/viewvc/llvm-project?rev=334628&view=rev
Log:
[CodeGen] make nan builtins pure rather than const (PR37778)

https://bugs.llvm.org/show_bug.cgi?id=37778
...shows a miscompile resulting from marking nan builtins as 'const'.

The nan libcalls/builtins take a pointer argument:
http://www.cplusplus.com/reference/cmath/nan-function/
...and the chars dereferenced by that arg are used to fill in the NaN constant 
payload bits.

"const" means that the pointer argument isn't dereferenced. That's translated 
to "readnone" in LLVM.
"pure" means that the pointer argument may be dereferenced. That's translated 
to "readonly" in LLVM.

This change prevents the IR optimizer from killing the lead-up to the nan call 
here:

double a() {
  char buf[4];
  buf[0] = buf[1] = buf[2] = '9';
  buf[3] = '\0';
  return __builtin_nan(buf);
}

...the optimizer isn't currently able to simplify this to a constant as we 
might hope, 
but this patch should solve the miscompile.

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

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/test/CodeGen/math-builtins.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=334628&r1=334627&r2=334628&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Wed Jun 13 10:54:52 2018
@@ -137,14 +137,14 @@ BUILTIN(__builtin_ldexpl, "LdLdi", "Fne"
 BUILTIN(__builtin_modf , "ddd*"  , "Fn")
 BUILTIN(__builtin_modff, "fff*"  , "Fn")
 BUILTIN(__builtin_modfl, "LdLdLd*", "Fn")
-BUILTIN(__builtin_nan,  "dcC*" , "ncF")
-BUILTIN(__builtin_nanf, "fcC*" , "ncF")
-BUILTIN(__builtin_nanl, "LdcC*", "ncF")
-BUILTIN(__builtin_nanf128, "LLdcC*", "ncF")
-BUILTIN(__builtin_nans,  "dcC*" , "ncF")
-BUILTIN(__builtin_nansf, "fcC*" , "ncF")
-BUILTIN(__builtin_nansl, "LdcC*", "ncF")
-BUILTIN(__builtin_nansf128, "LLdcC*", "ncF")
+BUILTIN(__builtin_nan,  "dcC*" , "FnU")
+BUILTIN(__builtin_nanf, "fcC*" , "FnU")
+BUILTIN(__builtin_nanl, "LdcC*", "FnU")
+BUILTIN(__builtin_nanf128, "LLdcC*", "FnU")
+BUILTIN(__builtin_nans,  "dcC*" , "FnU")
+BUILTIN(__builtin_nansf, "fcC*" , "FnU")
+BUILTIN(__builtin_nansl, "LdcC*", "FnU")
+BUILTIN(__builtin_nansf128, "LLdcC*", "FnU")
 BUILTIN(__builtin_powi , "ddi"  , "Fnc")
 BUILTIN(__builtin_powif, "ffi"  , "Fnc")
 BUILTIN(__builtin_powil, "LdLdi", "Fnc")

Modified: cfe/trunk/test/CodeGen/math-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/math-builtins.c?rev=334628&r1=334627&r2=334628&view=diff
==
--- cfe/trunk/test/CodeGen/math-builtins.c (original)
+++ cfe/trunk/test/CodeGen/math-builtins.c Wed Jun 13 10:54:52 2018
@@ -90,25 +90,25 @@ void foo(double *d, float f, float *fp,
 
   __builtin_nan(c);__builtin_nanf(c);   __builtin_nanl(c); 
__builtin_nanf128(c);
 
-// NO__ERRNO: declare double @nan(i8*) [[READNONE]]
-// NO__ERRNO: declare float @nanf(i8*) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @nanl(i8*) [[READNONE]]
-// NO__ERRNO: declare fp128 @nanf128(i8*) [[READNONE]]
-// HAS_ERRNO: declare double @nan(i8*) [[READNONE:#[0-9]+]]
-// HAS_ERRNO: declare float @nanf(i8*) [[READNONE]]
-// HAS_ERRNO: declare x86_fp80 @nanl(i8*) [[READNONE]]
-// HAS_ERRNO: declare fp128 @nanf128(i8*) [[READNONE]]
+// NO__ERRNO: declare double @nan(i8*) [[PURE:#[0-9]+]]
+// NO__ERRNO: declare float @nanf(i8*) [[PURE]]
+// NO__ERRNO: declare x86_fp80 @nanl(i8*) [[PURE]]
+// NO__ERRNO: declare fp128 @nanf128(i8*) [[PURE]]
+// HAS_ERRNO: declare double @nan(i8*) [[PURE:#[0-9]+]]
+// HAS_ERRNO: declare float @nanf(i8*) [[PURE]]
+// HAS_ERRNO: declare x86_fp80 @nanl(i8*) [[PURE]]
+// HAS_ERRNO: declare fp128 @nanf128(i8*) [[PURE]]
 
   __builtin_nans(c);__builtin_nansf(c);   __builtin_nansl(c); 
__builtin_nansf128(c);
 
-// NO__ERRNO: declare double @nans(i8*) [[READNONE]]
-// NO__ERRNO: declare float @nansf(i8*) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @nansl(i8*) [[READNONE]]
-// NO__ERRNO: declare fp128 @nansf128(i8*) [[READNONE]]
-// HAS_ERRNO: declare double @nans(i8*) [[READNONE]]
-// HAS_ERRNO: declare float @nansf(i8*) [[READNONE]]
-// HAS_ERRNO: declare x86_fp80 @nansl(i8*) [[READNONE]]
-// HAS_ERRNO: declare fp128 @nansf128(i8*) [[READNONE]]
+// NO__ERRNO: declare double @nans(i8*) [[PURE]]
+// NO__ERRNO: declare float @nansf(i8*) [[PURE]]
+// NO__ERRNO: declare x86_fp80 @nansl(i8*) [[PURE]]
+// NO__ERRNO: declare fp128 @nansf128(i8*) [[PURE]]
+// HAS_ERRNO: declare double @nans(i8*) [[PURE]]
+// HAS_ERRNO: declare float @nansf(i8*) [[PURE]]
+// HAS_ERRNO: declare x86_fp80 @nansl(i8*) [[PURE]]
+// HAS_ERRNO: declare fp128 @nansf128(i8*) [[PURE]]
 
   __builtin_pow(f,f);__builtin_powf(f,f);  

[PATCH] D48134: [CodeGen] make nan builtins pure rather than const (PR37778)

2018-06-13 Thread Sanjay Patel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334628: [CodeGen] make nan builtins pure rather than const 
(PR37778) (authored by spatel, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48134?vs=151187&id=151202#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48134

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/test/CodeGen/math-builtins.c


Index: cfe/trunk/include/clang/Basic/Builtins.def
===
--- cfe/trunk/include/clang/Basic/Builtins.def
+++ cfe/trunk/include/clang/Basic/Builtins.def
@@ -137,14 +137,14 @@
 BUILTIN(__builtin_modf , "ddd*"  , "Fn")
 BUILTIN(__builtin_modff, "fff*"  , "Fn")
 BUILTIN(__builtin_modfl, "LdLdLd*", "Fn")
-BUILTIN(__builtin_nan,  "dcC*" , "ncF")
-BUILTIN(__builtin_nanf, "fcC*" , "ncF")
-BUILTIN(__builtin_nanl, "LdcC*", "ncF")
-BUILTIN(__builtin_nanf128, "LLdcC*", "ncF")
-BUILTIN(__builtin_nans,  "dcC*" , "ncF")
-BUILTIN(__builtin_nansf, "fcC*" , "ncF")
-BUILTIN(__builtin_nansl, "LdcC*", "ncF")
-BUILTIN(__builtin_nansf128, "LLdcC*", "ncF")
+BUILTIN(__builtin_nan,  "dcC*" , "FnU")
+BUILTIN(__builtin_nanf, "fcC*" , "FnU")
+BUILTIN(__builtin_nanl, "LdcC*", "FnU")
+BUILTIN(__builtin_nanf128, "LLdcC*", "FnU")
+BUILTIN(__builtin_nans,  "dcC*" , "FnU")
+BUILTIN(__builtin_nansf, "fcC*" , "FnU")
+BUILTIN(__builtin_nansl, "LdcC*", "FnU")
+BUILTIN(__builtin_nansf128, "LLdcC*", "FnU")
 BUILTIN(__builtin_powi , "ddi"  , "Fnc")
 BUILTIN(__builtin_powif, "ffi"  , "Fnc")
 BUILTIN(__builtin_powil, "LdLdi", "Fnc")
Index: cfe/trunk/test/CodeGen/math-builtins.c
===
--- cfe/trunk/test/CodeGen/math-builtins.c
+++ cfe/trunk/test/CodeGen/math-builtins.c
@@ -90,25 +90,25 @@
 
   __builtin_nan(c);__builtin_nanf(c);   __builtin_nanl(c); 
__builtin_nanf128(c);
 
-// NO__ERRNO: declare double @nan(i8*) [[READNONE]]
-// NO__ERRNO: declare float @nanf(i8*) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @nanl(i8*) [[READNONE]]
-// NO__ERRNO: declare fp128 @nanf128(i8*) [[READNONE]]
-// HAS_ERRNO: declare double @nan(i8*) [[READNONE:#[0-9]+]]
-// HAS_ERRNO: declare float @nanf(i8*) [[READNONE]]
-// HAS_ERRNO: declare x86_fp80 @nanl(i8*) [[READNONE]]
-// HAS_ERRNO: declare fp128 @nanf128(i8*) [[READNONE]]
+// NO__ERRNO: declare double @nan(i8*) [[PURE:#[0-9]+]]
+// NO__ERRNO: declare float @nanf(i8*) [[PURE]]
+// NO__ERRNO: declare x86_fp80 @nanl(i8*) [[PURE]]
+// NO__ERRNO: declare fp128 @nanf128(i8*) [[PURE]]
+// HAS_ERRNO: declare double @nan(i8*) [[PURE:#[0-9]+]]
+// HAS_ERRNO: declare float @nanf(i8*) [[PURE]]
+// HAS_ERRNO: declare x86_fp80 @nanl(i8*) [[PURE]]
+// HAS_ERRNO: declare fp128 @nanf128(i8*) [[PURE]]
 
   __builtin_nans(c);__builtin_nansf(c);   __builtin_nansl(c); 
__builtin_nansf128(c);
 
-// NO__ERRNO: declare double @nans(i8*) [[READNONE]]
-// NO__ERRNO: declare float @nansf(i8*) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @nansl(i8*) [[READNONE]]
-// NO__ERRNO: declare fp128 @nansf128(i8*) [[READNONE]]
-// HAS_ERRNO: declare double @nans(i8*) [[READNONE]]
-// HAS_ERRNO: declare float @nansf(i8*) [[READNONE]]
-// HAS_ERRNO: declare x86_fp80 @nansl(i8*) [[READNONE]]
-// HAS_ERRNO: declare fp128 @nansf128(i8*) [[READNONE]]
+// NO__ERRNO: declare double @nans(i8*) [[PURE]]
+// NO__ERRNO: declare float @nansf(i8*) [[PURE]]
+// NO__ERRNO: declare x86_fp80 @nansl(i8*) [[PURE]]
+// NO__ERRNO: declare fp128 @nansf128(i8*) [[PURE]]
+// HAS_ERRNO: declare double @nans(i8*) [[PURE]]
+// HAS_ERRNO: declare float @nansf(i8*) [[PURE]]
+// HAS_ERRNO: declare x86_fp80 @nansl(i8*) [[PURE]]
+// HAS_ERRNO: declare fp128 @nansf128(i8*) [[PURE]]
 
   __builtin_pow(f,f);__builtin_powf(f,f);   __builtin_powl(f,f);
 
@@ -188,7 +188,7 @@
 // NO__ERRNO: declare double @cbrt(double) [[READNONE]]
 // NO__ERRNO: declare float @cbrtf(float) [[READNONE]]
 // NO__ERRNO: declare x86_fp80 @cbrtl(x86_fp80) [[READNONE]]
-// HAS_ERRNO: declare double @cbrt(double) [[READNONE]]
+// HAS_ERRNO: declare double @cbrt(double) [[READNONE:#[0-9]+]]
 // HAS_ERRNO: declare float @cbrtf(float) [[READNONE]]
 // HAS_ERRNO: declare x86_fp80 @cbrtl(x86_fp80) [[READNONE]]
 
@@ -581,9 +581,11 @@
 // NO__ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 // NO__ERRNO: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
 // NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// NO__ERRNO: attributes [[PURE]] = { {{.*}}readonly{{.*}} }
 
 // HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
 // HAS_ERRNO: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
+// HAS_ERRNO: attributes [[PURE]] = { {{.*}}readonly{{.*}} }
 // HAS_ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 
 // HAS_ERRNO_GNU: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }


Index: cfe/trunk/include/clan

[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-13 Thread Gabor Buella via Phabricator via cfe-commits
GBuella updated this revision to Diff 151203.
GBuella edited the summary of this revision.
GBuella added a comment.

Ignoring signaling behviour - and rounding mode with it.
Also lowering `__builtin_ia32_cmpsd` and `__builtin_ia32_cmpss`.


https://reviews.llvm.org/D45616

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/avx-builtins.c
  test/CodeGen/avx-cmp-builtins.c
  test/CodeGen/avx2-builtins.c
  test/CodeGen/avx512f-builtins.c
  test/CodeGen/avx512vl-builtins.c

Index: test/CodeGen/avx512vl-builtins.c
===
--- test/CodeGen/avx512vl-builtins.c
+++ test/CodeGen/avx512vl-builtins.c
@@ -1073,53 +1073,168 @@
 
 __mmask8 test_mm256_cmp_ps_mask(__m256 __A, __m256 __B) {
   // CHECK-LABEL: @test_mm256_cmp_ps_mask
-  // CHECK: call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256
+  // CHECK: fcmp oeq <8 x float> %{{.*}}, %{{.*}}
   return (__mmask8)_mm256_cmp_ps_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm256_cmp_ps_mask_true_uq(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_true_us(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_false_oq(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_false_os(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_FALSE_OS);
+}
+
 __mmask8 test_mm256_mask_cmp_ps_mask(__mmask8 m, __m256 __A, __m256 __B) {
   // CHECK-LABEL: @test_mm256_mask_cmp_ps_mask
-  // CHECK: [[CMP:%.*]] = call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256
-  // CHECK: and <8 x i1> [[CMP]], {{.*}}
+  // CHECK: fcmp oeq <8 x float> %{{.*}}, %{{.*}}
+  // CHECK: and <8 x i1> %{{.*}}, %{{.*}}
   return _mm256_mask_cmp_ps_mask(m, __A, __B, 0);
 }
 
 __mmask8 test_mm_cmp_ps_mask(__m128 __A, __m128 __B) {
   // CHECK-LABEL: @test_mm_cmp_ps_mask
-  // CHECK: call <4 x i1> @llvm.x86.avx512.mask.cmp.ps.128
+  // CHECK: fcmp oeq <4 x float> %{{.*}}, %{{.*}}
   return (__mmask8)_mm_cmp_ps_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm_cmp_ps_mask_true_uq(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm_cmp_ps_mask_true_us(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm_cmp_ps_mask_false_oq(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm_cmp_ps_mask_false_os(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_FALSE_OS);
+}
+
 __mmask8 test_mm_mask_cmp_ps_mask(__mmask8 m, __m128 __A, __m128 __B) {
   // CHECK-LABEL: @test_mm_mask_cmp_ps_mask
-  // CHECK: [[CMP:%.*]] = call <4 x i1> @llvm.x86.avx512.mask.cmp.ps.128
-  // CHECK: and <4 x i1> [[CMP]], {{.*}}
+  // CHECK: fcmp oeq <4 x float> %{{.*}}, %{{.*}}
+  // CHECK: shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <4 x i32> 
+  // CHECK: and <4 x i1> %{{.*}}, %{{.*}}
   return _mm_mask_cmp_ps_mask(m, __A, __B, 0);
 }
 
 __mmask8 test_mm256_cmp_pd_mask(__m256d __A, __m256d __B) {
   // CHECK-LABEL: @test_mm256_cmp_pd_mask
-  // CHECK: call <4 x i1> @llvm.x86.avx512.mask.cmp.pd.256
+  // CHECK: fcmp oeq <4 x double> %{{.*}}, %{{.*}}
   return (__mmask8)_mm256_cmp_pd_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm256_cmp_pd_mask_true_uq(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_true_us(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_false_oq(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_false_os(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_false_os
+  // CHEC

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

2018-06-13 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

> This change has been committed, so I'm closing this review.

@ormris The process which should be followed here is to add a line (exactly) 
"Differential Revision: https://reviews.llvm.org/D47044"; to the bottom of your 
commit message, so that the phabricator can cross-reference the review and the 
commit.
Alternatively, you could use the "arc" tool which would do that for you.


Repository:
  rC Clang

https://reviews.llvm.org/D47044



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


[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-13 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:10107-10112
+case 0x0b: // FALSE_OQ
+case 0x1b: // FALSE_OS
+  return llvm::Constant::getNullValue(ConvertType(E->getType()));
+case 0x0f: // TRUE_UQ
+case 0x1f: // TRUE_US
+  return llvm::Constant::getAllOnesValue(ConvertType(E->getType()));

On 2nd thought, why are we optimizing when we have matching IR predicates for 
these?
Just translate to FCMP_TRUE / FCMP_FALSE instead of special-casing these values.
InstSimplify can handle the constant folding if optimization is on.


https://reviews.llvm.org/D45616



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


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

2018-06-13 Thread Matthew Voss via Phabricator via cfe-commits
ormris added a comment.

Thanks @george.karpenkov . I was wondering why it didn't close automatically.


Repository:
  rC Clang

https://reviews.llvm.org/D47044



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


[PATCH] D48100: Append new attributes to the end of an AttributeList.

2018-06-13 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 151209.
Meinersbur added a comment.

- Remove obsolete comment
- Refactor getOrderedEnableIfAttrs


Repository:
  rC Clang

https://reviews.llvm.org/D48100

Files:
  include/clang/Sema/AttributeList.h
  lib/AST/ItaniumMangle.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaOverload.cpp
  test/Index/annotate-comments-availability-attrs.cpp
  test/Index/complete-with-annotations.cpp
  test/Misc/ast-print-pragmas.cpp
  test/PCH/pragma-loop.cpp
  test/Parser/pragma-loop-safety.cpp
  test/Parser/pragma-loop.cpp
  test/Parser/pragma-unroll.cpp
  test/Sema/attr-availability-tvos.c
  test/Sema/attr-availability.c
  test/Sema/attr-coldhot.c
  test/Sema/attr-disable-tail-calls.c
  test/Sema/attr-long-call.c
  test/Sema/attr-micromips.c
  test/Sema/attr-notail.c
  test/Sema/attr-ownership.c
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.c
  test/Sema/attr-swiftcall.c
  test/Sema/attr-target-mv.c
  test/Sema/attr-visibility.c
  test/Sema/internal_linkage.c
  test/Sema/mips-interrupt-attr.c
  test/Sema/ms_abi-sysv_abi.c
  test/Sema/nullability.c
  test/Sema/stdcall-fastcall.c
  test/SemaCXX/attr-print.cpp
  test/SemaCXX/attr-swiftcall.cpp
  test/SemaCXX/decl-microsoft-call-conv.cpp
  test/SemaCXX/ms-uuid.cpp
  test/SemaOpenCL/address-spaces.cl
  test/SemaTemplate/attributes.cpp

Index: test/SemaTemplate/attributes.cpp
===
--- test/SemaTemplate/attributes.cpp
+++ test/SemaTemplate/attributes.cpp
@@ -55,11 +55,11 @@
 }
 
 // CHECK: FunctionTemplateDecl {{.*}} HasAnnotations
-// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_BAR"
 // CHECK:   AnnotateAttr {{.*}} "ANNOTATE_FOO"
+// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_BAR"
 // CHECK: FunctionDecl {{.*}} HasAnnotations
 // CHECK:   TemplateArgument type 'int'
-// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_BAR"
 // CHECK:   AnnotateAttr {{.*}} "ANNOTATE_FOO"
+// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_BAR"
 template [[clang::annotate("ANNOTATE_FOO"), clang::annotate("ANNOTATE_BAR")]] void HasAnnotations();
 void UseAnnotations() { HasAnnotations(); }
Index: test/SemaOpenCL/address-spaces.cl
===
--- test/SemaOpenCL/address-spaces.cl
+++ test/SemaOpenCL/address-spaces.cl
@@ -58,8 +58,8 @@
 
 void func_multiple_addr(void) {
   typedef __private int private_int_t;
-  __local __private int var1;   // expected-error {{multiple address spaces specified for type}}
-  __local __private int *var2;  // expected-error {{multiple address spaces specified for type}}
+  __private __local int var1;   // expected-error {{multiple address spaces specified for type}}
+  __private __local int *var2;  // expected-error {{multiple address spaces specified for type}}
   __local private_int_t var3;   // expected-error {{multiple address spaces specified for type}}
   __local private_int_t *var4;  // expected-error {{multiple address spaces specified for type}}
 }
Index: test/SemaCXX/ms-uuid.cpp
===
--- test/SemaCXX/ms-uuid.cpp
+++ test/SemaCXX/ms-uuid.cpp
@@ -62,14 +62,14 @@
 [uuid("22A0---C000-0049")] class C4 {};
 
 // Both cl and clang-cl error out on this:
-// expected-note@+1 {{previous uuid specified here}}
-class __declspec(uuid("00A0---C000-0049"))
 // expected-error@+1 {{uuid does not match previous declaration}}
+class __declspec(uuid("00A0---C000-0049"))
+// expected-note@+1 {{previous uuid specified here}}
   __declspec(uuid("11A0---C000-0049")) C5;
 
-// expected-note@+1 {{previous uuid specified here}}
-[uuid("00A0---C000-0049"),
 // expected-error@+1 {{uuid does not match previous declaration}}
+[uuid("00A0---C000-0049"),
+// expected-note@+1 {{previous uuid specified here}}
  uuid("11A0---C000-0049")] class C6;
 
 // cl doesn't diagnose having one uuid each as []-style attributes and as
Index: test/SemaCXX/decl-microsoft-call-conv.cpp
===
--- test/SemaCXX/decl-microsoft-call-conv.cpp
+++ test/SemaCXX/decl-microsoft-call-conv.cpp
@@ -161,7 +161,7 @@
 // expected-error@+3 {{vectorcall and cdecl attributes are not compatible}}
 // expected-error@+2 {{stdcall and cdecl attributes are not compatible}}
 // expected-error@+1 {{fastcall and cdecl attributes are not compatible}}
-void __cdecl __cdecl __stdcall __cdecl __fastcall __vectorcall multi_cc(int x);
+void __vectorcall __fastcall __cdecl __stdcall __cdecl __cdecl multi_cc(int x);
 
 template  void __stdcall StdcallTemplate(T) {}
 template <> void StdcallTemplate(int) {}
Index: test/SemaCXX/attr-swiftcall.cpp
===
--- test/SemaCXX/attr-swiftcall.cpp
+++ test/SemaCXX/attr-swiftcall.cpp
@@ -7,7 +7,7 @@
 
 int notAFunction SWIFTCALL; // expected-warni

r334636 - [analyzer] Fix offset overflow check in MemRegion

2018-06-13 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Jun 13 11:32:19 2018
New Revision: 334636

URL: http://llvm.org/viewvc/llvm-project?rev=334636&view=rev
Log:
[analyzer] Fix offset overflow check in MemRegion

rdar://39593879
https://bugs.llvm.org/show_bug.cgi?id=37142

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/trunk/test/Analysis/region_store_overflow.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=334636&r1=334635&r2=334636&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Wed Jun 13 11:32:19 2018
@@ -41,6 +41,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CheckedArithmetic.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -1181,38 +1182,8 @@ const SymbolicRegion *MemRegion::getSymb
   return nullptr;
 }
 
-/// Perform a given operation on two integers, return whether it overflows.
-/// Optionally write the resulting output into \p Res.
-static bool checkedOp(
-int64_t LHS,
-int64_t RHS,
-std::function Op,
-int64_t *Res = nullptr) {
-  llvm::APInt ALHS(/*BitSize=*/64, LHS, /*Signed=*/true);
-  llvm::APInt ARHS(/*BitSize=*/64, RHS, /*Signed=*/true);
-  bool Overflow;
-  llvm::APInt Out = Op(&ALHS, ARHS, Overflow);
-  if (!Overflow && Res)
-*Res = Out.getSExtValue();
-  return Overflow;
-}
-
-static bool checkedAdd(
-int64_t LHS,
-int64_t RHS,
-int64_t *Res=nullptr) {
-  return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov, Res);
-}
-
-static bool checkedMul(
-int64_t LHS,
-int64_t RHS,
-int64_t *Res=nullptr) {
-  return checkedOp(LHS, RHS, &llvm::APInt::smul_ov, Res);
-}
-
 RegionRawOffset ElementRegion::getAsArrayOffset() const {
-  CharUnits offset = CharUnits::Zero();
+  int64_t offset = 0;
   const ElementRegion *ER = this;
   const MemRegion *superR = nullptr;
   ASTContext &C = getContext();
@@ -1224,7 +1195,7 @@ RegionRawOffset ElementRegion::getAsArra
 
 // FIXME: generalize to symbolic offsets.
 SVal index = ER->getIndex();
-if (Optional CI = index.getAs()) 
{
+if (auto CI = index.getAs()) {
   // Update the offset.
   int64_t i = CI->getValue().getSExtValue();
 
@@ -1237,20 +1208,15 @@ RegionRawOffset ElementRegion::getAsArra
   break;
 }
 
-CharUnits size = C.getTypeSizeInChars(elemType);
-
-int64_t Mult;
-bool Overflow = checkedAdd(i, size.getQuantity(), &Mult);
-if (!Overflow)
-  Overflow = checkedMul(Mult, offset.getQuantity());
-if (Overflow) {
+int64_t size = C.getTypeSizeInChars(elemType).getQuantity();
+if (auto NewOffset = llvm::checkedMulAdd(i, size, offset)) {
+  offset = *NewOffset;
+} else {
   LLVM_DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
   << "offset overflowing, returning 
unknown\n");
 
   return nullptr;
 }
-
-offset += (i * size);
   }
 
   // Go to the next ElementRegion (if any).
@@ -1262,7 +1228,7 @@ RegionRawOffset ElementRegion::getAsArra
   }
 
   assert(superR && "super region cannot be NULL");
-  return RegionRawOffset(superR, offset);
+  return RegionRawOffset(superR, CharUnits::fromQuantity(offset));
 }
 
 /// Returns true if \p Base is an immediate base class of \p Child

Modified: cfe/trunk/test/Analysis/region_store_overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region_store_overflow.c?rev=334636&r1=334635&r2=334636&view=diff
==
--- cfe/trunk/test/Analysis/region_store_overflow.c (original)
+++ cfe/trunk/test/Analysis/region_store_overflow.c Wed Jun 13 11:32:19 2018
@@ -1,6 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -verify %s
 
-// expected-no-diagnostics
 int **h;
 int overflow_in_memregion(long j) {
   for (int l = 0;; ++l) {
@@ -9,3 +8,9 @@ int overflow_in_memregion(long j) {
   }
   return 0;
 }
+
+void rdar39593879(long long *d) {
+  long e, f;
+  e = f = d[1]; // no-crash
+  for (; d[e];) f-- > 0; // expected-warning{{relational comparison result 
unused}}; 
+}


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


[PATCH] D48040: Implement constexpr __builtin_*_overflow

2018-06-13 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.

I'd like to see a couple of testcases ensuring the return value is correct on 
overflow (we had a problem with that for __builtin_mul_overflow in the past).

Otherwise LGTM.


https://reviews.llvm.org/D48040



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


[PATCH] D48040: Implement constexpr __builtin_*_overflow

2018-06-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I believe my tests DO validate the return value correctly, don't they?  It uses 
a sentinel, but the ternary should check that return value, right?

Or is there an obvious thing I'm missing?


https://reviews.llvm.org/D48040



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


[PATCH] D48132: [COFF] Add ARM64 intrinsics: __yield, __wfe, __wfi, __sev, __sevl

2018-06-13 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D48132



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


r334639 - [COFF] Add ARM64 intrinsics: __yield, __wfe, __wfi, __sev, __sevl

2018-06-13 Thread Mandeep Singh Grang via cfe-commits
Author: mgrang
Date: Wed Jun 13 11:49:35 2018
New Revision: 334639

URL: http://llvm.org/viewvc/llvm-project?rev=334639&view=rev
Log:
[COFF] Add ARM64 intrinsics: __yield, __wfe, __wfi, __sev, __sevl

Summary: These intrinsics result in hint instructions. They are provided here 
for MSVC ARM64 compatibility.

Reviewers: mstorsjo, compnerd, javed.absar

Reviewed By: mstorsjo

Subscribers: kristof.beyls, chrib, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
cfe/trunk/lib/CodeGen/CGBuiltin.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=334639&r1=334638&r2=334639&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def Wed Jun 13 11:49:35 2018
@@ -65,9 +65,15 @@ BUILTIN(__builtin_arm_wsr, "vcC*Ui", "nc
 BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
+// MSVC
 LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES)
+LANGBUILTIN(__yield, "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfe,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfi,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sev,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sevl,  "v", "",   ALL_MS_LANGUAGES)
 
 // MSVC intrinsics for volatile but non-acquire/release loads and stores
 LANGBUILTIN(__iso_volatile_load8,   "ccCD*", "n", ALL_MS_LANGUAGES)

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334639&r1=334638&r2=334639&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Jun 13 11:49:35 2018
@@ -6362,18 +6362,23 @@ Value *CodeGenFunction::EmitAArch64Built
 HintID = 0;
 break;
   case AArch64::BI__builtin_arm_yield:
+  case AArch64::BI__yield:
 HintID = 1;
 break;
   case AArch64::BI__builtin_arm_wfe:
+  case AArch64::BI__wfe:
 HintID = 2;
 break;
   case AArch64::BI__builtin_arm_wfi:
+  case AArch64::BI__wfi:
 HintID = 3;
 break;
   case AArch64::BI__builtin_arm_sev:
+  case AArch64::BI__sev:
 HintID = 4;
 break;
   case AArch64::BI__builtin_arm_sevl:
+  case AArch64::BI__sevl:
 HintID = 5;
 break;
   }

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=334639&r1=334638&r2=334639&view=diff
==
--- cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c (original)
+++ cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c Wed Jun 13 11:49:35 2018
@@ -24,3 +24,38 @@ void check__isb(void) {
 
 // CHECK-MSVC: @llvm.aarch64.isb(i32 0)
 // CHECK-LINUX: error: implicit declaration of function '__isb'
+
+void check__yield(void) {
+  __yield();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 1)
+// CHECK-LINUX: error: implicit declaration of function '__yield'
+
+void check__wfe(void) {
+  __wfe();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 2)
+// CHECK-LINUX: error: implicit declaration of function '__wfe'
+
+void check__wfi(void) {
+  __wfi();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 3)
+// CHECK-LINUX: error: implicit declaration of function '__wfi'
+
+void check__sev(void) {
+  __sev();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 4)
+// CHECK-LINUX: error: implicit declaration of function '__sev'
+
+void check__sevl(void) {
+  __sevl();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 5)
+// CHECK-LINUX: error: implicit declaration of function '__sevl'


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


[PATCH] D48132: [COFF] Add ARM64 intrinsics: __yield, __wfe, __wfi, __sev, __sevl

2018-06-13 Thread Mandeep Singh Grang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334639: [COFF] Add ARM64 intrinsics: __yield, __wfe, __wfi, 
__sev, __sevl (authored by mgrang, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48132?vs=151186&id=151218#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48132

Files:
  cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c


Index: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
+++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
@@ -65,9 +65,15 @@
 BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
+// MSVC
 LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES)
+LANGBUILTIN(__yield, "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfe,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfi,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sev,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sevl,  "v", "",   ALL_MS_LANGUAGES)
 
 // MSVC intrinsics for volatile but non-acquire/release loads and stores
 LANGBUILTIN(__iso_volatile_load8,   "ccCD*", "n", ALL_MS_LANGUAGES)
Index: cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
===
--- cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
+++ cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -24,3 +24,38 @@
 
 // CHECK-MSVC: @llvm.aarch64.isb(i32 0)
 // CHECK-LINUX: error: implicit declaration of function '__isb'
+
+void check__yield(void) {
+  __yield();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 1)
+// CHECK-LINUX: error: implicit declaration of function '__yield'
+
+void check__wfe(void) {
+  __wfe();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 2)
+// CHECK-LINUX: error: implicit declaration of function '__wfe'
+
+void check__wfi(void) {
+  __wfi();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 3)
+// CHECK-LINUX: error: implicit declaration of function '__wfi'
+
+void check__sev(void) {
+  __sev();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 4)
+// CHECK-LINUX: error: implicit declaration of function '__sev'
+
+void check__sevl(void) {
+  __sevl();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 5)
+// CHECK-LINUX: error: implicit declaration of function '__sevl'
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -6362,18 +6362,23 @@
 HintID = 0;
 break;
   case AArch64::BI__builtin_arm_yield:
+  case AArch64::BI__yield:
 HintID = 1;
 break;
   case AArch64::BI__builtin_arm_wfe:
+  case AArch64::BI__wfe:
 HintID = 2;
 break;
   case AArch64::BI__builtin_arm_wfi:
+  case AArch64::BI__wfi:
 HintID = 3;
 break;
   case AArch64::BI__builtin_arm_sev:
+  case AArch64::BI__sev:
 HintID = 4;
 break;
   case AArch64::BI__builtin_arm_sevl:
+  case AArch64::BI__sevl:
 HintID = 5;
 break;
   }


Index: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
+++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
@@ -65,9 +65,15 @@
 BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
+// MSVC
 LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES)
+LANGBUILTIN(__yield, "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfe,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfi,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sev,   "v", "",   ALL_MS_LANGUAGES)
+LANGBUILTIN(__sevl,  "v", "",   ALL_MS_LANGUAGES)
 
 // MSVC intrinsics for volatile but non-acquire/release loads and stores
 LANGBUILTIN(__iso_volatile_load8,   "ccCD*", "n", ALL_MS_LANGUAGES)
Index: cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
===
--- cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
+++ cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -24,3 +24,38 @@
 
 // CHECK-MSVC: @llvm.aarch64.isb(i32 0)
 // CHECK-LINUX: error: implicit declaration of function '__isb'
+
+void check__yield(void) {
+  __yield();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 1)
+// CHECK-LINUX: error: implicit declaration of function '__yield'
+
+void check__wfe(void) {
+  __wfe();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 2)
+// CHECK-LINUX: error: implicit declaration of function '__wfe'
+
+void check__wfi(void) {
+  __wfi();
+}
+
+// CHECK-MSVC: @llvm.aarch64.hint(i32 3)
+// CHECK-LINUX: erro

[PATCH] D48040: Implement constexpr __builtin_*_overflow

2018-06-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Oh, sorry, I mixed up the two values.  I meant that you should add a couple 
testcases to ensure the stored value is correct on overflow.


https://reviews.llvm.org/D48040



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


[PATCH] D48106: implemented proto to llvm

2018-06-13 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 151239.
emmettneyman added a comment.

- refactored loop_proto_to_llvm.cpp


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,179 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::pair  BinopToString(const BinaryOp &x);
+std::pair  StateSeqToString(const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+int ctr = 0;
+std::string get_var() {
+  ctr++;
+  return "%var" + std::to_string(ctr);
+}
+
+// Proto to LLVM.
+
+std::pair  ConstToString(const Const &x) {
+  std::string alloca_var = get_var();
+  std::string load_var = get_var();
+  std::string val = std::to_string(x.val());
+  std::string insns = alloca_var + " = alloca i32\n"
+   + "store i32 " + val + ", i32* " + alloca_var + "\n"
+   + load_var + " = load i32, i32* " + alloca_var + "\n";
+  return std::make_pair(insns, load_var);
+}
+std::pair  VarRefToString(const VarRef &x) {
+  std::string arr;
+  switch(x.arr()) {
+  case VarRef::ARR_A:
+arr = "%a";
+break;
+  case VarRef::ARR_B:

[PATCH] D48106: implemented proto to llvm

2018-06-13 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added a comment.

In https://reviews.llvm.org/D48106#1130581, @morehouse wrote:

> Where is the fuzz target?


I wanted to implement the proto_to_llvm converter before the fuzz target.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D48134: [CodeGen] make nan builtins pure rather than const (PR37778)

2018-06-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Can we mark these as `argmemonly`?


Repository:
  rL LLVM

https://reviews.llvm.org/D48134



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


[PATCH] D48106: implemented proto to llvm

2018-06-13 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 151240.
emmettneyman added a comment.

- removed typo in emitted llvm insn


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,179 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::pair  BinopToString(const BinaryOp &x);
+std::pair  StateSeqToString(const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+int ctr = 0;
+std::string get_var() {
+  ctr++;
+  return "%var" + std::to_string(ctr);
+}
+
+// Proto to LLVM.
+
+std::pair  ConstToString(const Const &x) {
+  std::string alloca_var = get_var();
+  std::string load_var = get_var();
+  std::string val = std::to_string(x.val());
+  std::string insns = alloca_var + " = alloca i32\n"
+   + "store i32 " + val + ", i32* " + alloca_var + "\n"
+   + load_var + " = load i32, i32* " + alloca_var + "\n";
+  return std::make_pair(insns, load_var);
+}
+std::pair  VarRefToString(const VarRef &x) {
+  std::string arr;
+  switch(x.arr()) {
+  case VarRef::ARR_A:
+arr = "%a";
+break;
+  case VarRef::ARR_B:

r334650 - Implement constexpr __builtin_*_overflow

2018-06-13 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Wed Jun 13 13:43:27 2018
New Revision: 334650

URL: http://llvm.org/viewvc/llvm-project?rev=334650&view=rev
Log:
Implement constexpr __builtin_*_overflow

As requested here:https://bugs.llvm.org/show_bug.cgi?id=37633
permit the __builtin_*_overflow builtins in constexpr functions.

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

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/builtins-overflow.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=334650&r1=334649&r2=334650&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Jun 13 13:43:27 2018
@@ -8155,6 +8155,124 @@ bool IntExprEvaluator::VisitBuiltinCallE
   case Builtin::BIomp_is_initial_device:
 // We can decide statically which value the runtime would return if called.
 return Success(Info.getLangOpts().OpenMPIsDevice ? 0 : 1, E);
+  case Builtin::BI__builtin_add_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_smulll_overflow: {
+LValue ResultLValue;
+APSInt LHS, RHS;
+
+QualType ResultType = E->getArg(2)->getType()->getPointeeType();
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info) ||
+!EvaluatePointer(E->getArg(2), ResultLValue, Info))
+  return false;
+
+APSInt Result;
+bool DidOverflow = false;
+
+// If the types don't have to match, enlarge all 3 to the largest of them.
+if (BuiltinOp == Builtin::BI__builtin_add_overflow ||
+BuiltinOp == Builtin::BI__builtin_sub_overflow ||
+BuiltinOp == Builtin::BI__builtin_mul_overflow) {
+  bool IsSigned = LHS.isSigned() || RHS.isSigned() ||
+  ResultType->isSignedIntegerOrEnumerationType();
+  bool AllSigned = LHS.isSigned() && RHS.isSigned() &&
+  ResultType->isSignedIntegerOrEnumerationType();
+  uint64_t LHSSize = LHS.getBitWidth();
+  uint64_t RHSSize = RHS.getBitWidth();
+  uint64_t ResultSize = Info.Ctx.getTypeSize(ResultType);
+  uint64_t MaxBits = std::max(std::max(LHSSize, RHSSize), ResultSize);
+
+  // Add an additional bit if the signedness isn't uniformly agreed to. We
+  // could do this ONLY if there is a signed and an unsigned that both have
+  // MaxBits, but the code to check that is pretty nasty.  The issue will 
be
+  // caught in the shrink-to-result later anyway.
+  if (IsSigned && !AllSigned)
+++MaxBits;
+
+  LHS = APSInt(IsSigned ? LHS.sextOrSelf(MaxBits) : 
LHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  RHS = APSInt(IsSigned ? RHS.sextOrSelf(MaxBits) : 
RHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  Result = APSInt(MaxBits, !IsSigned);
+}
+
+// Find largest int.
+switch (BuiltinOp) {
+default:
+  llvm_unreachable("Invalid value for BuiltinOp");
+case Builtin::BI__builtin_add_overflow:
+case Builtin::BI__builtin_sadd_overflow:
+case Builtin::BI__builtin_saddl_overflow:
+case Builtin::BI__builtin_saddll_overflow:
+case Builtin::BI__builtin_uadd_overflow:
+case Builtin::BI__builtin_uaddl_overflow:
+case Builtin::BI__builtin_uaddll_overflow:
+  Result = LHS.isSigned() ? LHS.sadd_ov(RHS, DidOverflow)
+  : LHS.uadd_ov(RHS, DidOverflow);
+  break;
+case Builtin::BI__builtin_sub_overflow:
+case Builtin::BI__builtin_ssub_overflow:
+case Builtin::BI__builtin_ssubl_overflow:
+case Builtin::BI__builtin_ssubll_overflow:
+case Builtin::BI__builtin_usub_overflow:
+case Builtin::BI__builtin_usubl_overflow:
+case Builtin::BI__builtin_usubll_overflow:
+  Result = LHS.isSigned() ? LHS.ssub_ov(RHS, DidOverflow)
+  : LHS.usub_ov(RHS, DidOverflow);
+  break;
+case Builtin::BI__builtin_mul_overflow:
+case Builtin::BI__builtin_smul_overflow:
+case Builtin::BI__builtin_smull_overflow:
+case Builtin::BI__builtin_smul

[PATCH] D48040: Implement constexpr __builtin_*_overflow

2018-06-13 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334650: Implement constexpr __builtin_*_overflow (authored 
by erichkeane, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48040?vs=151151&id=151241#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48040

Files:
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/test/SemaCXX/builtins-overflow.cpp

Index: cfe/trunk/lib/AST/ExprConstant.cpp
===
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -8155,6 +8155,124 @@
   case Builtin::BIomp_is_initial_device:
 // We can decide statically which value the runtime would return if called.
 return Success(Info.getLangOpts().OpenMPIsDevice ? 0 : 1, E);
+  case Builtin::BI__builtin_add_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_smulll_overflow: {
+LValue ResultLValue;
+APSInt LHS, RHS;
+
+QualType ResultType = E->getArg(2)->getType()->getPointeeType();
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info) ||
+!EvaluatePointer(E->getArg(2), ResultLValue, Info))
+  return false;
+
+APSInt Result;
+bool DidOverflow = false;
+
+// If the types don't have to match, enlarge all 3 to the largest of them.
+if (BuiltinOp == Builtin::BI__builtin_add_overflow ||
+BuiltinOp == Builtin::BI__builtin_sub_overflow ||
+BuiltinOp == Builtin::BI__builtin_mul_overflow) {
+  bool IsSigned = LHS.isSigned() || RHS.isSigned() ||
+  ResultType->isSignedIntegerOrEnumerationType();
+  bool AllSigned = LHS.isSigned() && RHS.isSigned() &&
+  ResultType->isSignedIntegerOrEnumerationType();
+  uint64_t LHSSize = LHS.getBitWidth();
+  uint64_t RHSSize = RHS.getBitWidth();
+  uint64_t ResultSize = Info.Ctx.getTypeSize(ResultType);
+  uint64_t MaxBits = std::max(std::max(LHSSize, RHSSize), ResultSize);
+
+  // Add an additional bit if the signedness isn't uniformly agreed to. We
+  // could do this ONLY if there is a signed and an unsigned that both have
+  // MaxBits, but the code to check that is pretty nasty.  The issue will be
+  // caught in the shrink-to-result later anyway.
+  if (IsSigned && !AllSigned)
+++MaxBits;
+
+  LHS = APSInt(IsSigned ? LHS.sextOrSelf(MaxBits) : LHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  RHS = APSInt(IsSigned ? RHS.sextOrSelf(MaxBits) : RHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  Result = APSInt(MaxBits, !IsSigned);
+}
+
+// Find largest int.
+switch (BuiltinOp) {
+default:
+  llvm_unreachable("Invalid value for BuiltinOp");
+case Builtin::BI__builtin_add_overflow:
+case Builtin::BI__builtin_sadd_overflow:
+case Builtin::BI__builtin_saddl_overflow:
+case Builtin::BI__builtin_saddll_overflow:
+case Builtin::BI__builtin_uadd_overflow:
+case Builtin::BI__builtin_uaddl_overflow:
+case Builtin::BI__builtin_uaddll_overflow:
+  Result = LHS.isSigned() ? LHS.sadd_ov(RHS, DidOverflow)
+  : LHS.uadd_ov(RHS, DidOverflow);
+  break;
+case Builtin::BI__builtin_sub_overflow:
+case Builtin::BI__builtin_ssub_overflow:
+case Builtin::BI__builtin_ssubl_overflow:
+case Builtin::BI__builtin_ssubll_overflow:
+case Builtin::BI__builtin_usub_overflow:
+case Builtin::BI__builtin_usubl_overflow:
+case Builtin::BI__builtin_usubll_overflow:
+  Result = LHS.isSigned() ? LHS.ssub_ov(RHS, DidOverflow)
+  : LHS.usub_ov(RHS, DidOverflow);
+  break;
+case Builtin::BI__builtin_mul_overflow:
+case Builtin::BI__builtin_smul_overflow:
+case Builtin::BI__builtin_smull_overflow:
+case Builtin::BI__builtin_smulll_overflow:
+case Builtin::BI__builtin_umul_overflow:
+case Builtin::BI__builtin_umull_overflow:
+case Builtin::BI__builtin_umulll_overflow:
+  Result = LHS.isSigned() ? LHS.smul_ov(RHS, DidOverflow)

r334652 - Simplify test from r334650

2018-06-13 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Wed Jun 13 13:47:12 2018
New Revision: 334652

URL: http://llvm.org/viewvc/llvm-project?rev=334652&view=rev
Log:
Simplify test from r334650

No reason to have the 'bool' as an intermediary value,
simply use the fact that curley braces enforce eval order.

Modified:
cfe/trunk/test/SemaCXX/builtins-overflow.cpp

Modified: cfe/trunk/test/SemaCXX/builtins-overflow.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtins-overflow.cpp?rev=334652&r1=334651&r2=334652&view=diff
==
--- cfe/trunk/test/SemaCXX/builtins-overflow.cpp (original)
+++ cfe/trunk/test/SemaCXX/builtins-overflow.cpp Wed Jun 13 13:47:12 2018
@@ -29,8 +29,7 @@ struct Result {
 template 
 constexpr Result add(LHS &&lhs, RHS &&rhs) {
   RET sum{};
-  bool b = __builtin_add_overflow(lhs, rhs, &sum);
-  return {b, sum};
+  return {__builtin_add_overflow(lhs, rhs, &sum), sum};
 }
 
 static_assert(add(static_cast(120), static_cast(10)) == 
Result{false, 130});
@@ -45,8 +44,7 @@ static_assert(add(INT_MIN + 22, -23
 template 
 constexpr Result sub(LHS &&lhs, RHS &&rhs) {
   RET sum{};
-  bool b = __builtin_sub_overflow(lhs, rhs, &sum);
-  return {b, sum};
+  return {__builtin_sub_overflow(lhs, rhs, &sum), sum};
 }
 
 static_assert(sub(static_cast(0),static_cast(1)) == 
Result{true, UCHAR_MAX});
@@ -60,8 +58,7 @@ static_assert(sub(INT_MIN + 22, 23)
 template 
 constexpr Result mul(LHS &&lhs, RHS &&rhs) {
   RET sum{};
-  bool b  = __builtin_mul_overflow(lhs, rhs, &sum);
-  return {b, sum};
+  return {__builtin_mul_overflow(lhs, rhs, &sum), sum};
 }
 
 static_assert(mul(17,22) == Result{false, 374});
@@ -70,8 +67,7 @@ static_assert(mul(INT_MIN / 22, -23
 
 constexpr Result sadd(int lhs, int rhs) {
   int sum{};
-  bool b = __builtin_sadd_overflow(lhs, rhs, &sum);
-  return {b, sum};
+  return {__builtin_sadd_overflow(lhs, rhs, &sum), sum};
 }
 
 static_assert(sadd(17,22) == Result{false, 39});
@@ -80,8 +76,7 @@ static_assert(sadd(INT_MIN + 22, -23) ==
 
 constexpr Result ssub(int lhs, int rhs) {
   int sum{};
-  bool b = __builtin_ssub_overflow(lhs, rhs, &sum);
-  return {b, sum};
+  return {__builtin_ssub_overflow(lhs, rhs, &sum), sum};
 }
 
 static_assert(ssub(17,22) == Result{false, -5});
@@ -90,8 +85,7 @@ static_assert(ssub(INT_MIN + 22, 23) ==
 
 constexpr Result smul(int lhs, int rhs) {
   int sum{};
-  bool b = __builtin_smul_overflow(lhs, rhs, &sum);
-  return {b, sum};
+  return {__builtin_smul_overflow(lhs, rhs, &sum), sum};
 }
 
 static_assert(smul(17,22) == Result{false, 374});


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


[PATCH] D45679: [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

2018-06-13 Thread Shuai Wang via Phabricator via cfe-commits
shuaiwang updated this revision to Diff 151244.
shuaiwang added a comment.

Don't include  in unit tests, should fix the test failures.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679

Files:
  clang-tidy/utils/CMakeLists.txt
  clang-tidy/utils/ExprMutationAnalyzer.cpp
  clang-tidy/utils/ExprMutationAnalyzer.h
  unittests/clang-tidy/CMakeLists.txt
  unittests/clang-tidy/ExprMutationAnalyzerTest.cpp

Index: unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
===
--- /dev/null
+++ unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
@@ -0,0 +1,608 @@
+//===-- ExprMutationAnalyzerTest.cpp - clang-tidy -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../clang-tidy/utils/ExprMutationAnalyzer.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+using namespace clang::ast_matchers;
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+using ::testing::ResultOf;
+using ::testing::StartsWith;
+using ::testing::Values;
+
+namespace {
+
+using ExprMatcher = internal::Matcher;
+using StmtMatcher = internal::Matcher;
+
+ExprMatcher declRefTo(StringRef Name) {
+  return declRefExpr(to(namedDecl(hasName(Name;
+}
+
+StmtMatcher withEnclosingCompound(ExprMatcher Matcher) {
+  return expr(Matcher, hasAncestor(compoundStmt().bind("stmt"))).bind("expr");
+}
+
+bool isMutated(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  const auto *const E = selectFirst("expr", Results);
+  return utils::ExprMutationAnalyzer(S, &AST->getASTContext()).isMutated(E);
+}
+
+SmallVector
+mutatedBy(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  SmallVector Chain;
+  utils::ExprMutationAnalyzer Analyzer(S, &AST->getASTContext());
+  for (const auto *E = selectFirst("expr", Results); E != nullptr;) {
+const Stmt *By = Analyzer.findMutation(E);
+std::string buffer;
+llvm::raw_string_ostream stream(buffer);
+By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
+Chain.push_back(StringRef(stream.str()).trim().str());
+E = dyn_cast(By);
+  }
+  return Chain;
+}
+
+std::string removeSpace(std::string s) {
+  s.erase(std::remove_if(s.begin(), s.end(),
+ [](char c) { return std::isspace(c); }),
+  s.end());
+  return s;
+}
+
+} // namespace
+
+TEST(ExprMutationAnalyzerTest, Trivial) {
+  const auto AST = tooling::buildASTFromCode("void f() { int x; x; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+}
+
+class AssignmentTest : public ::testing::TestWithParam {};
+
+TEST_P(AssignmentTest, AssignmentModifies) {
+  const std::string ModExpr = "x " + GetParam() + " 10";
+  const auto AST =
+  tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr));
+}
+
+INSTANTIATE_TEST_CASE_P(AllAssignmentOperators, AssignmentTest,
+Values("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=",
+   "^=", "<<=", ">>="), );
+
+class IncDecTest : public ::testing::TestWithParam {};
+
+TEST_P(IncDecTest, IncDecModifies) {
+  const std::string ModExpr = GetParam();
+  const auto AST =
+  tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr));
+}
+
+INSTANTIATE_TEST_CASE_P(AllIncDecOperators, IncDecTest,
+Values("++x", "--x", "x++", "x--"), );
+
+TEST(ExprMutationAnalyzerTest, NonConstMemberFunc) {
+  const auto AST = tooling::buildASTFromCode(
+  "void f() { struct Foo { void mf(); }; Foo x; x.mf(); }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()"));
+}
+
+TEST(ExprMutationAnalyzerTest, ConstMemberFunc) {
+  const auto AST = tooling::buildASTFromCode(
+  "void f() { struct Foo { void mf() const; }; Foo x; x.mf(); }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+}
+
+TEST(ExprMutationAnalyzerTest, Non

[PATCH] D48134: [CodeGen] make nan builtins pure rather than const (PR37778)

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

In https://reviews.llvm.org/D48134#1131626, @rsmith wrote:

> Can we mark these as `argmemonly`?


Header comment in `include/clang/Basic/Builtins.def` does not list that as a 
possibility.


Repository:
  rL LLVM

https://reviews.llvm.org/D48134



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


[PATCH] D45679: [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

2018-06-13 Thread Shuai Wang via Phabricator via cfe-commits
shuaiwang updated this revision to Diff 151245.
shuaiwang added a comment.

Add include  for std::isspace() (thanks aaron.ballman!)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679

Files:
  clang-tidy/utils/CMakeLists.txt
  clang-tidy/utils/ExprMutationAnalyzer.cpp
  clang-tidy/utils/ExprMutationAnalyzer.h
  unittests/clang-tidy/CMakeLists.txt
  unittests/clang-tidy/ExprMutationAnalyzerTest.cpp

Index: unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
===
--- /dev/null
+++ unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
@@ -0,0 +1,609 @@
+//===-- ExprMutationAnalyzerTest.cpp - clang-tidy -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../clang-tidy/utils/ExprMutationAnalyzer.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+using namespace clang::ast_matchers;
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+using ::testing::ResultOf;
+using ::testing::StartsWith;
+using ::testing::Values;
+
+namespace {
+
+using ExprMatcher = internal::Matcher;
+using StmtMatcher = internal::Matcher;
+
+ExprMatcher declRefTo(StringRef Name) {
+  return declRefExpr(to(namedDecl(hasName(Name;
+}
+
+StmtMatcher withEnclosingCompound(ExprMatcher Matcher) {
+  return expr(Matcher, hasAncestor(compoundStmt().bind("stmt"))).bind("expr");
+}
+
+bool isMutated(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  const auto *const E = selectFirst("expr", Results);
+  return utils::ExprMutationAnalyzer(S, &AST->getASTContext()).isMutated(E);
+}
+
+SmallVector
+mutatedBy(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  SmallVector Chain;
+  utils::ExprMutationAnalyzer Analyzer(S, &AST->getASTContext());
+  for (const auto *E = selectFirst("expr", Results); E != nullptr;) {
+const Stmt *By = Analyzer.findMutation(E);
+std::string buffer;
+llvm::raw_string_ostream stream(buffer);
+By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
+Chain.push_back(StringRef(stream.str()).trim().str());
+E = dyn_cast(By);
+  }
+  return Chain;
+}
+
+std::string removeSpace(std::string s) {
+  s.erase(std::remove_if(s.begin(), s.end(),
+ [](char c) { return std::isspace(c); }),
+  s.end());
+  return s;
+}
+
+} // namespace
+
+TEST(ExprMutationAnalyzerTest, Trivial) {
+  const auto AST = tooling::buildASTFromCode("void f() { int x; x; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+}
+
+class AssignmentTest : public ::testing::TestWithParam {};
+
+TEST_P(AssignmentTest, AssignmentModifies) {
+  const std::string ModExpr = "x " + GetParam() + " 10";
+  const auto AST =
+  tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr));
+}
+
+INSTANTIATE_TEST_CASE_P(AllAssignmentOperators, AssignmentTest,
+Values("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=",
+   "^=", "<<=", ">>="), );
+
+class IncDecTest : public ::testing::TestWithParam {};
+
+TEST_P(IncDecTest, IncDecModifies) {
+  const std::string ModExpr = GetParam();
+  const auto AST =
+  tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr));
+}
+
+INSTANTIATE_TEST_CASE_P(AllIncDecOperators, IncDecTest,
+Values("++x", "--x", "x++", "x--"), );
+
+TEST(ExprMutationAnalyzerTest, NonConstMemberFunc) {
+  const auto AST = tooling::buildASTFromCode(
+  "void f() { struct Foo { void mf(); }; Foo x; x.mf(); }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()"));
+}
+
+TEST(ExprMutationAnalyzerTest, ConstMemberFunc) {
+  const auto AST = tooling::buildASTFromCode(
+  "void f() { struct Foo { void mf() const; }; Foo x; x.mf(); }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+}
+
+TEST(ExprMutationAnalyzerTe

  1   2   >