[PATCH] D58397: [analyzer] MIGChecker: Pour more data into the checker.

2019-02-19 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Aah, MIG_NO_REPLY.

LGTM.




Comment at: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp:42
+  std::vector> Deallocators = {
+#define CALL(required_args, deallocated_arg, ...)  
\
+  {{{__VA_ARGS__}, required_args}, deallocated_arg}

Could you put a comment with an example indicating how CALL works for a 
particular example function? I think that will make is easier for folks to add 
support for new APIs in the future without getting it wrong.



Comment at: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp:125
 
+  // See if there's an annotated method in the superclass.
+  if (const auto *MD = dyn_cast(D))

Perhaps we could make it a Sema error if a method doesn't have a mig server 
routine annotation but it overrides a method that does. From a 
documentation/usability perspective it would be unfortunate if a human looking 
at a method to determine its convention would have to look at its super classes 
to see whether they have an annotation too.

Although, thinking about it more that might make it a source-breaking change if 
an API author were to add annotation on a super class. Then API clients would 
have to add the annotations to get their projects to build, which would not be 
great..



Comment at: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp:162
+// Returns true if V can potentially represent a "successful" kern_return_t.
+static bool isSuccess(SVal V, CheckerContext ) {
+  ProgramStateRef State = C.getState();

Could we rename this to "mayBeSuccess()" or something like that so that the 
name of function indicate the "potentially" part of the comment.


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

https://reviews.llvm.org/D58397



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


[PATCH] D58392: [analyzer] MIGChecker: Fix false negatives for releases in automatic destructors.

2019-02-19 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Oh, interesting. I'm glad you thought of this!


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

https://reviews.llvm.org/D58392



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


r354435 - Limit new PM tests to X86 registered targets.

2019-02-19 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Tue Feb 19 21:07:14 2019
New Revision: 354435

URL: http://llvm.org/viewvc/llvm-project?rev=354435=rev
Log:
Limit new PM tests to X86 registered targets.

Modified:
cfe/trunk/test/Driver/msan.c
cfe/trunk/test/Driver/tsan.c

Modified: cfe/trunk/test/Driver/msan.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msan.c?rev=354435=354434=354435=diff
==
--- cfe/trunk/test/Driver/msan.c (original)
+++ cfe/trunk/test/Driver/msan.c Tue Feb 19 21:07:14 2019
@@ -1,3 +1,5 @@
+// REQUIRES: x86-registered-target
+
 // RUN: %clang -target x86_64-unknown-linux -fsanitize=memory %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-MSAN
 // RUN: %clang -O1 -target x86_64-unknown-linux -fsanitize=memory %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-MSAN
 // RUN: %clang -O2 -target x86_64-unknown-linux -fsanitize=memory %s -S 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-MSAN
@@ -22,9 +24,6 @@
 // RUN: %clang -O2 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
 // RUN: %clang -O3 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
 
-// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
-// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
-
 int foo(int *a) { return *a; }
 // CHECK-MSAN: __msan_init
 // CHECK-KMSAN: __msan_get_context_state

Modified: cfe/trunk/test/Driver/tsan.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/tsan.c?rev=354435=354434=354435=diff
==
--- cfe/trunk/test/Driver/tsan.c (original)
+++ cfe/trunk/test/Driver/tsan.c Tue Feb 19 21:07:14 2019
@@ -1,3 +1,5 @@
+// REQUIRES: x86-registered-target
+
 // RUN: %clang -target x86_64-unknown-linux -fsanitize=thread %s -S 
-emit-llvm -o - | FileCheck %s
 // RUN: %clang -O1 -target x86_64-unknown-linux -fsanitize=thread %s -S 
-emit-llvm -o - | FileCheck %s
 // RUN: %clang -O2 -target x86_64-unknown-linux -fsanitize=thread %s -S 
-emit-llvm -o - | FileCheck %s


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


[PATCH] D58368: [analyzer] MIGChecker: Implement bug reporter visitors.

2019-02-19 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Looks good to me. I have some a minor diagnostic wording suggestion in line.




Comment at: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp:109
+llvm::raw_svector_ostream OS(Str);
+OS << "Deallocating object passed through parameter '" << PVD->getName()
+   << '\'';

Could we just have the note say "'name' is deallocated"?

Or "Value passed through parameter 'name' is deallocated"

The ".. is ... " construction matches our other checkers. (Like "Memory is 
released" from the Malloc Checker.)



Comment at: clang/test/Analysis/mig.mm:52
+kern_return_t release_twice(mach_port_name_t port, vm_address_t addr1, 
vm_address_t addr2, vm_size_t size) {
+  kern_return_t ret = KERN_ERROR; // expected-note{{'ret' initialized to 1}}
+  vm_deallocate(port, addr1, size); // expected-note{{Deallocating object 
passed through parameter 'addr1'}}

A nice QoI improvement here (for a later patch, perhaps) would be to have this 
note use the macro name: "'ret initialized to KERN_ERROR'".

Users probably won't know that KERN_ERROR is 1.


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

https://reviews.llvm.org/D58368



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


[PATCH] D58095: [clang-tidy] Make google-objc-function-naming ignore implicit functions 

2019-02-19 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore marked 4 inline comments as done.
stephanemoore added inline comments.



Comment at: clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h:1
+#ifndef _STDIO_H_
+#define _STDIO_H_

aaron.ballman wrote:
> aaron.ballman wrote:
> > stephanemoore wrote:
> > > stephanemoore wrote:
> > > > I noticed that some of the other example headers don't have `#ifdef` 
> > > > guards at all. I decided to still include them—perhaps mostly for my 
> > > > own sanity. I figured that it wasn't necessary to use the full 
> > > > `LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_INPUTS_HEADER_STDIO_H` for this 
> > > > header that is mimicking a system header so I went with the shorter 
> > > > `_STDIO_H_` which I think better represents what actual stdio.h headers 
> > > > would have. Let me know if you think something else makes more sense.
> > > Do I need the licensing preamble on this test input header?
> > Yes, please add it.
> I don't think it matters all that much for our tests; I'm fine with the way 
> you have it currently.
Added the licensing preamble. Let me know if anything looks amiss.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58095



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


[PATCH] D58366: [analyzer] MIGChecker: Make use of the server routine annotation.

2019-02-19 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/test/Analysis/mig.mm:2
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG\
+// RUN:-fblocks -verify %s
 

Ooh, I didn't know you could split RUN lines like this. That is awesome!


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

https://reviews.llvm.org/D58366



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


[PATCH] D58095: [clang-tidy] Make google-objc-function-naming ignore implicit functions 

2019-02-19 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore updated this revision to Diff 187512.
stephanemoore added a comment.

Added licensing preamble to stdio.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58095

Files:
  clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
  clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
  clang-tools-extra/test/clang-tidy/google-objc-function-naming.m


Index: clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
===
--- clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
+++ clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy %s google-objc-function-naming %t
+// RUN: %check_clang_tidy %s google-objc-function-naming %t -- -- -isystem 
%S/Inputs/Headers
+
+#include 
+
+static void TestImplicitFunctionDeclaration(int a) {
+  // Call a builtin function so that the compiler generates an implicit
+  // function declaration.
+  printf("%d", a);
+}
 
 typedef _Bool bool;
 
Index: clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
@@ -0,0 +1,18 @@
+//===--- stdio.h - Stub header for tests *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _STDIO_H_
+#define _STDIO_H_
+
+// A header intended to contain C standard input and output library
+// declarations.
+
+int printf(const char *, ...);
+
+#endif // _STDIO_H_
+
Index: clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
@@ -93,12 +93,16 @@
   if (!getLangOpts().ObjC)
 return;
 
-  // Match function declarations that are not in system headers and are not
-  // main.
+  // Enforce Objective-C function naming conventions on all functions except:
+  // • Functions defined in system headers.
+  // • C++ member functions.
+  // • Namespaced functions.
+  // • Implicitly defined functions.
+  // • The main function.
   Finder->addMatcher(
   functionDecl(
   unless(anyOf(isExpansionInSystemHeader(), cxxMethodDecl(),
-   hasAncestor(namespaceDecl()), isMain(),
+   hasAncestor(namespaceDecl()), isMain(), isImplicit(),
matchesName(validFunctionNameRegex(true)),
allOf(isStaticStorageClass(),
  matchesName(validFunctionNameRegex(false))


Index: clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
===
--- clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
+++ clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy %s google-objc-function-naming %t
+// RUN: %check_clang_tidy %s google-objc-function-naming %t -- -- -isystem %S/Inputs/Headers
+
+#include 
+
+static void TestImplicitFunctionDeclaration(int a) {
+  // Call a builtin function so that the compiler generates an implicit
+  // function declaration.
+  printf("%d", a);
+}
 
 typedef _Bool bool;
 
Index: clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
@@ -0,0 +1,18 @@
+//===--- stdio.h - Stub header for tests *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _STDIO_H_
+#define _STDIO_H_
+
+// A header intended to contain C standard input and output library
+// declarations.
+
+int printf(const char *, ...);
+
+#endif // _STDIO_H_
+
Index: clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
@@ -93,12 +93,16 @@
   if (!getLangOpts().ObjC)
 return;
 
-  // Match function declarations that are not in system headers and are not
-  // main.
+  // Enforce Objective-C function naming conventions on all functions except:
+  // • Functions 

r354432 - Remove test on incompatible mpis target.

2019-02-19 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Tue Feb 19 20:35:28 2019
New Revision: 354432

URL: http://llvm.org/viewvc/llvm-project?rev=354432=rev
Log:
Remove test on incompatible mpis target.

Modified:
cfe/trunk/test/Driver/msan.c

Modified: cfe/trunk/test/Driver/msan.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msan.c?rev=354432=354431=354432=diff
==
--- cfe/trunk/test/Driver/msan.c (original)
+++ cfe/trunk/test/Driver/msan.c Tue Feb 19 20:35:28 2019
@@ -22,8 +22,6 @@
 // RUN: %clang -O2 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
 // RUN: %clang -O3 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
 
-// RUN: %clang -fexperimental-new-pass-manager -target mips64-linux-gnu 
-fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-MSAN
-// RUN: %clang -fexperimental-new-pass-manager -target 
mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
 // RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
 // RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
 


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


[PATCH] D58365: [attributes] Add a MIG server routine attribute.

2019-02-19 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

This looks good to me as long as Aaron is happy with it.


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

https://reviews.llvm.org/D58365



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


[PATCH] D58424: [NewPM] Add other sanitizers at O0

2019-02-19 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL354431: [NewPM] Add other sanitizers at O0 (authored by 
leonardchan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58424?vs=187492=187506#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58424

Files:
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/test/Driver/msan.c
  cfe/trunk/test/Driver/tsan.c


Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -932,6 +932,14 @@
 /*CompileKernel=*/false, Recover, ModuleUseAfterScope,
 CodeGenOpts.SanitizeAddressUseOdrIndicator));
   }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass({})));
+  }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
+  }
 }
 
 /// A clean version of `EmitAssembly` that uses the new pass manager.
Index: cfe/trunk/test/Driver/tsan.c
===
--- cfe/trunk/test/Driver/tsan.c
+++ cfe/trunk/test/Driver/tsan.c
@@ -5,5 +5,13 @@
 // RUN: %clang -target x86_64-unknown-linux -fsanitize=thread  %s -S 
-emit-llvm -o - | FileCheck %s
 // Verify that -fsanitize=thread invokes tsan instrumentation.
 
+// Also check that this works with the new pass manager with and without
+// optimization
+// RUN: %clang -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O1 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+
 int foo(int *a) { return *a; }
 // CHECK: __tsan_init
Index: cfe/trunk/test/Driver/msan.c
===
--- cfe/trunk/test/Driver/msan.c
+++ cfe/trunk/test/Driver/msan.c
@@ -15,6 +15,18 @@
 
 // Verify that -fsanitize=memory and -fsanitize=kernel-memory invoke 
MSan/KMSAN instrumentation.
 
+// Also check that this works with the new pass manager with and without
+// optimization
+// RUN: %clang -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O1 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O2 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O3 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+
+// RUN: %clang -fexperimental-new-pass-manager -target mips64-linux-gnu 
-fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+
 int foo(int *a) { return *a; }
 // CHECK-MSAN: __msan_init
 // CHECK-KMSAN: __msan_get_context_state


Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -932,6 +932,14 @@
 /*CompileKernel=*/false, Recover, ModuleUseAfterScope,
 CodeGenOpts.SanitizeAddressUseOdrIndicator));
   }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass({})));
+  }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
+  }
 }
 
 /// A clean version of `EmitAssembly` that uses the new pass manager.
Index: cfe/trunk/test/Driver/tsan.c

r354431 - [NewPM] Add other sanitizers at O0

2019-02-19 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Tue Feb 19 19:50:11 2019
New Revision: 354431

URL: http://llvm.org/viewvc/llvm-project?rev=354431=rev
Log:
[NewPM] Add other sanitizers at O0

This allows for MSan and TSan to be used without optimizations required.

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/Driver/msan.c
cfe/trunk/test/Driver/tsan.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=354431=354430=354431=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Feb 19 19:50:11 2019
@@ -932,6 +932,14 @@ void addSanitizersAtO0(ModulePassManager
 /*CompileKernel=*/false, Recover, ModuleUseAfterScope,
 CodeGenOpts.SanitizeAddressUseOdrIndicator));
   }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass({})));
+  }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
+  }
 }
 
 /// A clean version of `EmitAssembly` that uses the new pass manager.

Modified: cfe/trunk/test/Driver/msan.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msan.c?rev=354431=354430=354431=diff
==
--- cfe/trunk/test/Driver/msan.c (original)
+++ cfe/trunk/test/Driver/msan.c Tue Feb 19 19:50:11 2019
@@ -15,6 +15,18 @@
 
 // Verify that -fsanitize=memory and -fsanitize=kernel-memory invoke 
MSan/KMSAN instrumentation.
 
+// Also check that this works with the new pass manager with and without
+// optimization
+// RUN: %clang -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O1 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O2 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O3 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+
+// RUN: %clang -fexperimental-new-pass-manager -target mips64-linux-gnu 
-fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+
 int foo(int *a) { return *a; }
 // CHECK-MSAN: __msan_init
 // CHECK-KMSAN: __msan_get_context_state

Modified: cfe/trunk/test/Driver/tsan.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/tsan.c?rev=354431=354430=354431=diff
==
--- cfe/trunk/test/Driver/tsan.c (original)
+++ cfe/trunk/test/Driver/tsan.c Tue Feb 19 19:50:11 2019
@@ -5,5 +5,13 @@
 // RUN: %clang -target x86_64-unknown-linux -fsanitize=thread  %s -S 
-emit-llvm -o - | FileCheck %s
 // Verify that -fsanitize=thread invokes tsan instrumentation.
 
+// Also check that this works with the new pass manager with and without
+// optimization
+// RUN: %clang -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O1 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+
 int foo(int *a) { return *a; }
 // CHECK: __tsan_init


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


[PATCH] D58397: [analyzer] MIGChecker: Pour more data into the checker.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 187505.
NoQ added a comment.

Rebase. Fix behavior when the return code is not constrained enough. Test the 
C++11 attribute syntax (just in case). Update comments.


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

https://reviews.llvm.org/D58397

Files:
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/test/Analysis/mig.mm

Index: clang/test/Analysis/mig.mm
===
--- clang/test/Analysis/mig.mm
+++ clang/test/Analysis/mig.mm
@@ -1,20 +1,55 @@
 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG\
 // RUN:   -analyzer-output=text -fblocks -verify %s
 
+typedef unsigned uint32_t;
+
 // XNU APIs.
 
 typedef int kern_return_t;
 #define KERN_SUCCESS 0
 #define KERN_ERROR 1
+#define MIG_NO_REPLY (-305)
 
 typedef unsigned mach_port_name_t;
 typedef unsigned vm_address_t;
 typedef unsigned vm_size_t;
+typedef void *ipc_space_t;
+typedef unsigned long io_user_reference_t;
 
 kern_return_t vm_deallocate(mach_port_name_t, vm_address_t, vm_size_t);
+kern_return_t mach_vm_deallocate(mach_port_name_t, vm_address_t, vm_size_t);
+void mig_deallocate(vm_address_t, vm_size_t);
+kern_return_t mach_port_deallocate(ipc_space_t, mach_port_name_t);
 
 #define MIG_SERVER_ROUTINE __attribute__((mig_server_routine))
 
+// IOKit wrappers.
+
+class OSObject;
+typedef kern_return_t IOReturn;
+#define kIOReturnError 1
+
+enum {
+  kOSAsyncRef64Count = 8,
+};
+
+typedef io_user_reference_t OSAsyncReference64[kOSAsyncRef64Count];
+
+struct IOExternalMethodArguments {
+  io_user_reference_t *asyncReference;
+};
+
+struct IOExternalMethodDispatch {};
+
+class IOUserClient {
+public:
+  static IOReturn releaseAsyncReference64(OSAsyncReference64);
+
+  MIG_SERVER_ROUTINE
+  virtual IOReturn externalMethod(uint32_t selector, IOExternalMethodArguments *arguments,
+  IOExternalMethodDispatch *dispatch = 0, OSObject *target = 0, void *reference = 0);
+};
+
 
 // Tests.
 
@@ -123,3 +158,52 @@
 return Empty{}; // no-crash
   };
 }
+
+// Test various APIs.
+MIG_SERVER_ROUTINE
+kern_return_t test_mach_vm_deallocate(mach_port_name_t port, vm_address_t address, vm_size_t size) {
+  mach_vm_deallocate(port, address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
+  return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value}}
+}
+
+MIG_SERVER_ROUTINE
+kern_return_t test_mach_port_deallocate(ipc_space_t space,
+mach_port_name_t port) {
+  mach_port_deallocate(space, port); // expected-note{{Deallocating object passed through parameter 'port'}}
+  return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value}}
+}
+
+MIG_SERVER_ROUTINE
+kern_return_t test_mig_deallocate(vm_address_t address, vm_size_t size) {
+  mig_deallocate(address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
+  return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value}}
+}
+
+// Let's try the C++11 attribute spelling syntax as well.
+[[clang::mig_server_routine]]
+IOReturn test_releaseAsyncReference64(IOExternalMethodArguments *arguments) {
+  IOUserClient::releaseAsyncReference64(arguments->asyncReference); // expected-note{{Deallocating object passed through parameter 'arguments'}}
+  return kIOReturnError;// expected-warning{{MIG callback fails with error after deallocating argument value}}
+// expected-note@-1{{MIG callback fails with error after deallocating argument value}}
+}
+
+MIG_SERVER_ROUTINE
+kern_return_t test_no_reply(ipc_space_t space, mach_port_name_t port) {
+  mach_port_deallocate(space, port);
+  return MIG_NO_REPLY; // no-warning
+}
+
+class MyClient: public IOUserClient {
+  // The MIG_SERVER_ROUTINE annotation is intentionally skipped.
+  // It should be picked up from the superclass.
+  IOReturn externalMethod(uint32_t selector, IOExternalMethodArguments *arguments,
+  IOExternalMethodDispatch *dispatch = 0, OSObject *target = 0, void *reference = 0) override {
+
+releaseAsyncReference64(arguments->asyncReference); // expected-note{{Deallocating object passed through parameter 'arguments'}}
+return kIOReturnError;  // expected-warning{{MIG 

[PATCH] D58392: [analyzer] MIGChecker: Fix false negatives for releases in automatic destructors.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 187503.
NoQ added a comment.

Rebase.


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

https://reviews.llvm.org/D58392

Files:
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/test/Analysis/mig.mm


Index: clang/test/Analysis/mig.mm
===
--- clang/test/Analysis/mig.mm
+++ clang/test/Analysis/mig.mm
@@ -56,6 +56,31 @@
  // expected-note@-1{{MIG callback fails with error after 
deallocating argument value. This is use-after-free vulnerability because 
caller will try to deallocate it again}}
 }
 
+// Make sure we find the bug when the object is destroyed within an
+// automatic destructor.
+MIG_SERVER_ROUTINE
+kern_return_t test_vm_deallocate_in_automatic_dtor(mach_port_name_t port, 
vm_address_t address, vm_size_t size) {
+  struct WillDeallocate {
+mach_port_name_t port;
+vm_address_t address;
+vm_size_t size;
+~WillDeallocate() {
+  vm_deallocate(port, address, size); // expected-note{{Deallocating 
object passed through parameter 'address'}}
+}
+  } will_deallocate{port, address, size};
+
+ if (size > 10) {
+// expected-note@-1{{Assuming 'size' is > 10}}
+// expected-note@-2{{Taking true branch}}
+return KERN_ERROR;
+// expected-note@-1{{Calling '~WillDeallocate'}}
+// expected-note@-2{{Returning from '~WillDeallocate'}}
+// expected-warning@-3{{MIG callback fails with error after deallocating 
argument value. This is use-after-free vulnerability because caller will try to 
deallocate it again}}
+// expected-note@-4   {{MIG callback fails with error after deallocating 
argument value. This is use-after-free vulnerability because caller will try to 
deallocate it again}}
+  }
+  return KERN_SUCCESS;
+}
+
 // Check that we work on Objective-C messages and blocks.
 @interface I
 - (kern_return_t)fooAtPort:(mach_port_name_t)port 
withAddress:(vm_address_t)address ofSize:(vm_size_t)size;
Index: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
@@ -32,15 +32,30 @@
 using namespace ento;
 
 namespace {
-class MIGChecker : public Checker> 
{
+class MIGChecker : public Checker,
+  check::EndFunction> {
   BugType BT{this, "Use-after-free (MIG calling convention violation)",
  categories::MemoryError};
 
   CallDescription vm_deallocate { "vm_deallocate", 3 };
 
+  void checkReturnAux(const ReturnStmt *RS, CheckerContext ) const;
+
 public:
   void checkPostCall(const CallEvent , CheckerContext ) const;
-  void checkPreStmt(const ReturnStmt *RS, CheckerContext ) const;
+
+  // HACK: We're making two attempts to find the bug: checkEndFunction
+  // should normally be enough but it fails when the return value is a literal
+  // that never gets put into the Environment and ends of function with 
multiple
+  // returns get agglutinated across returns, preventing us from obtaining
+  // the return value. The problem is similar to 
https://reviews.llvm.org/D25326
+  // but now we step into it in the top-level function.
+  void checkPreStmt(const ReturnStmt *RS, CheckerContext ) const {
+checkReturnAux(RS, C);
+  }
+  void checkEndFunction(const ReturnStmt *RS, CheckerContext ) const {
+checkReturnAux(RS, C);
+  }
 };
 } // end anonymous namespace
 
@@ -113,7 +128,7 @@
   C.addTransition(C.getState()->set(true), T);
 }
 
-void MIGChecker::checkPreStmt(const ReturnStmt *RS, CheckerContext ) const {
+void MIGChecker::checkReturnAux(const ReturnStmt *RS, CheckerContext ) const 
{
   // It is very unlikely that a MIG callback will be called from anywhere
   // within the project under analysis and the caller isn't itself a routine
   // that follows the MIG calling convention. Therefore we're safe to believe


Index: clang/test/Analysis/mig.mm
===
--- clang/test/Analysis/mig.mm
+++ clang/test/Analysis/mig.mm
@@ -56,6 +56,31 @@
  // expected-note@-1{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
 }
 
+// Make sure we find the bug when the object is destroyed within an
+// automatic destructor.
+MIG_SERVER_ROUTINE
+kern_return_t test_vm_deallocate_in_automatic_dtor(mach_port_name_t port, vm_address_t address, vm_size_t size) {
+  struct WillDeallocate {
+mach_port_name_t port;
+vm_address_t address;
+vm_size_t size;
+~WillDeallocate() {
+  vm_deallocate(port, address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
+}
+  } will_deallocate{port, address, size};
+
+ if (size > 10) {
+// expected-note@-1{{Assuming 'size' is > 10}}
+// expected-note@-2{{Taking true 

[PATCH] D58375: [Clang][NewPM] Disable tests that are broken under new PM

2019-02-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D58375#1403144 , @efriedma wrote:

> I can understand why tests that use -O1 or -O2 would produce different 
> results with the new pass manager, but it looks like not all the tests are 
> like that.  Do you know why those tests are failing?


I only looked at some of them and what I saw was just a different sequence of 
instructions, I can dig into it a bit more.

> For the tests that do use -O, instead of marking them unsupported, could you 
> use -fno-experimental-new-pass-manager or something like that?

Done


Repository:
  rC Clang

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

https://reviews.llvm.org/D58375



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


[PATCH] D58368: [analyzer] MIGChecker: Implement bug reporter visitors.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 187502.
NoQ added a comment.

Rebase.


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

https://reviews.llvm.org/D58368

Files:
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/test/Analysis/mig.mm

Index: clang/test/Analysis/mig.mm
===
--- clang/test/Analysis/mig.mm
+++ clang/test/Analysis/mig.mm
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG\
-// RUN:-fblocks -verify %s
+// RUN:   -analyzer-output=text -fblocks -verify %s
 
 // XNU APIs.
 
@@ -20,9 +20,11 @@
 
 MIG_SERVER_ROUTINE
 kern_return_t basic_test(mach_port_name_t port, vm_address_t address, vm_size_t size) {
-  vm_deallocate(port, address, size);
-  if (size > 10) {
+  vm_deallocate(port, address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
+  if (size > 10) { // expected-note{{Assuming 'size' is > 10}}
+   // expected-note@-1{{Taking true branch}}
 return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+			 // expected-note@-1{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
   }
   return KERN_SUCCESS;
 }
@@ -42,6 +44,18 @@
   vm_deallocate(port, address, size);
 }
 
+// When releasing two parameters, add a note for both of them.
+// Also when returning a variable, explain why do we think that it contains
+// a non-success code.
+MIG_SERVER_ROUTINE
+kern_return_t release_twice(mach_port_name_t port, vm_address_t addr1, vm_address_t addr2, vm_size_t size) {
+  kern_return_t ret = KERN_ERROR; // expected-note{{'ret' initialized to 1}}
+  vm_deallocate(port, addr1, size); // expected-note{{Deallocating object passed through parameter 'addr1'}}
+  vm_deallocate(port, addr2, size); // expected-note{{Deallocating object passed through parameter 'addr2'}}
+  return ret; // expected-warning{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+}
+
 // Check that we work on Objective-C messages and blocks.
 @interface I
 - (kern_return_t)fooAtPort:(mach_port_name_t)port withAddress:(vm_address_t)address ofSize:(vm_size_t)size;
@@ -51,8 +65,9 @@
 - (kern_return_t)fooAtPort:(mach_port_name_t)port
withAddress:(vm_address_t)address
 ofSize:(vm_size_t)size MIG_SERVER_ROUTINE {
-  vm_deallocate(port, address, size);
+  vm_deallocate(port, address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
   return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
 }
 @end
 
@@ -60,8 +75,9 @@
   kern_return_t (^block)(mach_port_name_t, vm_address_t, vm_size_t) =
   ^MIG_SERVER_ROUTINE (mach_port_name_t port,
vm_address_t address, vm_size_t size) {
-vm_deallocate(port, address, size);
+vm_deallocate(port, address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
     return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+   // expected-note@-1{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
   };
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
@@ -46,14 +46,17 @@
 
 REGISTER_TRAIT_WITH_PROGRAMSTATE(ReleasedParameter, bool);
 
-static bool isCurrentArgSVal(SVal V, CheckerContext ) {
+static const ParmVarDecl *getOriginParam(SVal V, CheckerContext ) {
   SymbolRef Sym = V.getAsSymbol();
   if (!Sym)
-return false;
+return nullptr;
 
   const auto *VR = dyn_cast_or_null(Sym->getOriginRegion());
-  return VR && VR->hasStackParametersStorage() &&
- VR->getStackFrame()->inTopFrame();
+  if (VR && VR->hasStackParametersStorage() &&
+ 

[PATCH] D58366: [analyzer] MIGChecker: Make use of the server routine annotation.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 187501.
NoQ added a comment.

Whoops - make sure that the Objective-C test does actually test something.


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

https://reviews.llvm.org/D58366

Files:
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/test/Analysis/mig.mm

Index: clang/test/Analysis/mig.mm
===
--- clang/test/Analysis/mig.mm
+++ clang/test/Analysis/mig.mm
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG -verify %s
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG\
+// RUN:-fblocks -verify %s
 
 // XNU APIs.
 
@@ -12,8 +13,12 @@
 
 kern_return_t vm_deallocate(mach_port_name_t, vm_address_t, vm_size_t);
 
+#define MIG_SERVER_ROUTINE __attribute__((mig_server_routine))
+
+
 // Tests.
 
+MIG_SERVER_ROUTINE
 kern_return_t basic_test(mach_port_name_t port, vm_address_t address, vm_size_t size) {
   vm_deallocate(port, address, size);
   if (size > 10) {
@@ -22,6 +27,7 @@
   return KERN_SUCCESS;
 }
 
+MIG_SERVER_ROUTINE
 kern_return_t test_unknown_return_value(mach_port_name_t port, vm_address_t address, vm_size_t size) {
   extern kern_return_t foo();
 
@@ -31,6 +37,48 @@
 }
 
 // Make sure we don't crash when they forgot to write the return statement.
+MIG_SERVER_ROUTINE
 kern_return_t no_crash(mach_port_name_t port, vm_address_t address, vm_size_t size) {
   vm_deallocate(port, address, size);
 }
+
+// Check that we work on Objective-C messages and blocks.
+@interface I
+- (kern_return_t)fooAtPort:(mach_port_name_t)port withAddress:(vm_address_t)address ofSize:(vm_size_t)size;
+@end
+
+@implementation I
+- (kern_return_t)fooAtPort:(mach_port_name_t)port
+   withAddress:(vm_address_t)address
+ofSize:(vm_size_t)size MIG_SERVER_ROUTINE {
+  vm_deallocate(port, address, size);
+  return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+}
+@end
+
+void test_block() {
+  kern_return_t (^block)(mach_port_name_t, vm_address_t, vm_size_t) =
+  ^MIG_SERVER_ROUTINE (mach_port_name_t port,
+   vm_address_t address, vm_size_t size) {
+vm_deallocate(port, address, size);
+    return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+  };
+}
+
+void test_block_with_weird_return_type() {
+  struct Empty {};
+
+  // The block is written within a function so that it was actually analyzed as
+  // a top-level function during analysis. If we were to write it as a global
+  // variable of block type instead, it would not have been analyzed, because
+  // ASTConsumer won't find the block's code body within the VarDecl.
+  // At the same time, we shouldn't call it from the function, because otherwise
+  // it will be analyzed as an inlined function rather than as a top-level
+  // function.
+  Empty (^block)(mach_port_name_t, vm_address_t, vm_size_t) =
+  ^MIG_SERVER_ROUTINE(mach_port_name_t port,
+  vm_address_t address, vm_size_t size) {
+vm_deallocate(port, address, size);
+return Empty{}; // no-crash
+  };
+}
Index: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
@@ -20,6 +20,7 @@
 //
 //===--===//
 
+#include "clang/Analysis/AnyCall.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -55,8 +56,8 @@
  VR->getStackFrame()->inTopFrame();
 }
 
-// This function will probably be replaced with looking up annotations.
-static bool isInMIGCall(const LocationContext *LC) {
+static bool isInMIGCall(CheckerContext ) {
+  const LocationContext *LC = C.getLocationContext();
   const StackFrameContext *SFC;
   // Find the top frame.
   while (LC) {
@@ -64,21 +65,27 @@
 LC = SFC->getParent();
   }
 
-  const auto *FD = dyn_cast(SFC->getDecl());
-  if (!FD)
-return false;
+  const Decl *D = SFC->getDecl();
+
+  if (Optional AC = AnyCall::forDecl(D)) {
+// Even though there's a Sema warning when the return type of an annotated
+// function is not a kern_return_t, this warning isn't an error, so we need
+// an extra sanity check here.
+// FIXME: AnyCall doesn't support blocks yet, so they remain unchecked
+// for now.
+if (!AC->getReturnType(C.getASTContext())
+ .getCanonicalType()->isSignedIntegerType())
+  return false;
+  }
+
+  

[PATCH] D58366: [analyzer] MIGChecker: Make use of the server routine annotation.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 187498.
NoQ added a comment.

Rebase due to an update in D58365  - namely, 
add support for Objective-C messages and blocks that are now allowed to wear 
the attribute.


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

https://reviews.llvm.org/D58366

Files:
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/test/Analysis/mig.mm

Index: clang/test/Analysis/mig.mm
===
--- clang/test/Analysis/mig.mm
+++ clang/test/Analysis/mig.mm
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG -verify %s
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG\
+// RUN:-fblocks -verify %s
 
 // XNU APIs.
 
@@ -12,8 +13,12 @@
 
 kern_return_t vm_deallocate(mach_port_name_t, vm_address_t, vm_size_t);
 
+#define MIG_SERVER_ROUTINE __attribute__((mig_server_routine))
+
+
 // Tests.
 
+MIG_SERVER_ROUTINE
 kern_return_t basic_test(mach_port_name_t port, vm_address_t address, vm_size_t size) {
   vm_deallocate(port, address, size);
   if (size > 10) {
@@ -22,6 +27,7 @@
   return KERN_SUCCESS;
 }
 
+MIG_SERVER_ROUTINE
 kern_return_t test_unknown_return_value(mach_port_name_t port, vm_address_t address, vm_size_t size) {
   extern kern_return_t foo();
 
@@ -31,6 +37,46 @@
 }
 
 // Make sure we don't crash when they forgot to write the return statement.
+MIG_SERVER_ROUTINE
 kern_return_t no_crash(mach_port_name_t port, vm_address_t address, vm_size_t size) {
   vm_deallocate(port, address, size);
 }
+
+// Check that we work on Objective-C messages and blocks.
+@interface I
+- (kern_return_t)fooAtPort:(mach_port_name_t)port withAddress:(vm_address_t)address ofSize:(vm_size_t)size;
+@end
+
+@implementation I
+- (kern_return_t)fooAtPort:(mach_port_name_t)port withAddress:(vm_address_t)address ofSize:(vm_size_t)size {
+  vm_deallocate(port, address, size);
+  return KERN_ERROR;
+}
+@end
+
+void test_block() {
+  kern_return_t (^block)(mach_port_name_t, vm_address_t, vm_size_t) =
+  ^MIG_SERVER_ROUTINE (mach_port_name_t port,
+   vm_address_t address, vm_size_t size) {
+vm_deallocate(port, address, size);
+    return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value. This is use-after-free vulnerability because caller will try to deallocate it again}}
+  };
+}
+
+void test_block_with_weird_return_type() {
+  struct Empty {};
+
+  // The block is written within a function so that it was actually analyzed as
+  // a top-level function during analysis. If we were to write it as a global
+  // variable of block type instead, it would not have been analyzed, because
+  // ASTConsumer won't find the block's code body within the VarDecl.
+  // At the same time, we shouldn't call it from the function, because otherwise
+  // it will be analyzed as an inlined function rather than as a top-level
+  // function.
+  Empty (^block)(mach_port_name_t, vm_address_t, vm_size_t) =
+  ^MIG_SERVER_ROUTINE(mach_port_name_t port,
+  vm_address_t address, vm_size_t size) {
+vm_deallocate(port, address, size);
+return Empty{}; // no-crash
+  };
+}
Index: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
@@ -20,6 +20,7 @@
 //
 //===--===//
 
+#include "clang/Analysis/AnyCall.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -55,8 +56,8 @@
  VR->getStackFrame()->inTopFrame();
 }
 
-// This function will probably be replaced with looking up annotations.
-static bool isInMIGCall(const LocationContext *LC) {
+static bool isInMIGCall(CheckerContext ) {
+  const LocationContext *LC = C.getLocationContext();
   const StackFrameContext *SFC;
   // Find the top frame.
   while (LC) {
@@ -64,21 +65,27 @@
 LC = SFC->getParent();
   }
 
-  const auto *FD = dyn_cast(SFC->getDecl());
-  if (!FD)
-return false;
+  const Decl *D = SFC->getDecl();
+
+  if (Optional AC = AnyCall::forDecl(D)) {
+// Even though there's a Sema warning when the return type of an annotated
+// function is not a kern_return_t, this warning isn't an error, so we need
+// an extra sanity check here.
+// FIXME: AnyCall doesn't support blocks yet, so they remain unchecked
+// for now.
+if (!AC->getReturnType(C.getASTContext())
+ .getCanonicalType()->isSignedIntegerType())
+  return false;
+  }
+
+  if (D->hasAttr())
+return true;
 
-  // FIXME: This is an unreliable (even if surprisingly reliable) heuristic.
-  // The real 

[PATCH] D58365: [attributes] Add a MIG server routine attribute.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1310
 
+def MIGServerRoutine : InheritableAttr {
+  let Spellings = [Clang<"mig_server_routine">];

aaron.ballman wrote:
> Should this be limited to specific targets, or is this a general concept that 
> applies to all targets?
I guess it shouldn't. There are [[ 
https://en.wikipedia.org/wiki/Mach_(kernel)#Software_based_on_Mach | a lot of 
]] Darwin-inspecific forks of Mach, and restricting to a specific hardware 
architecture also doesn't seem to make much sense.



Comment at: clang/include/clang/Basic/Attr.td:1312
+  let Spellings = [Clang<"mig_server_routine">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MIGCallingConventionDocs];

aaron.ballman wrote:
> Objective-C methods as well?
Mmm, i guess it's technically possible, even if a bit annoying to support. Let 
me try.



Comment at: clang/include/clang/Basic/Attr.td:1313
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MIGCallingConventionDocs];
+}

aaron.ballman wrote:
> This isn't really a calling convention though, is it? It doesn't change 
> codegen, impact function types, or anything like that.
That's right, but for whatever reason it's often referred to as "a" calling 
convention. It makes slight sense because callee/caller-deallocated OOL 
parameters are kinda similar to callee/caller-saved registers, something like 
that. I guess i'll call it just "convention".



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8702
+def warn_mig_server_routine_does_not_return_kern_return_t : Warning<
+  "'%0' attribute only applies to functions that return a kernel return code">,
+  InGroup;

aaron.ballman wrote:
> Will users understand "kernel return code"? Should this say `kern_return_t` 
> explicitly?
> 
> No need to use %0 here, just spell out the attribute name directly (unless 
> you expect this to be used by multiple attributes, in which case the name of 
> the diagnostic should be changed).
It should say either `kern_return_t` or `IOReturn` depending on the specific 
framework that's being used (the latter is a typedef for the former). I guess i 
could scan the AST to for a `typedef kern_return_t IOReturn` and display the 
appropriate message, but this sort of stuff always sounds like an overkill. For 
now i change the wording to an exact "a kern_return_t". I could also say "a 
kern_return_t or an IOReturn", do you have any preference here?



Comment at: clang/test/Sema/attr-mig.c:17
+}
+
+kern_return_t bar_forward() { // no-warning

aaron.ballman wrote:
> Here's an edge case to consider:
> ```
> __attribute__((mig_server_routine)) int foo(void);
> 
> typedef int kern_return_t;
> 
> kern_return_t foo(void) { ... }
> ```
> Do you have to care about situations like that?
> Do you have to care about situations like that?

I hope i not :) `kern_return_t` is available pretty much everywhere and most 
likely it's not a problem to update the first declaration of `foo()` with 
`kern_return_t`. Ok if i add a relaxing code later if it turns out that i have 
to?



Comment at: clang/test/Sema/attr-mig.cpp:10
+public:
+  virtual __attribute__((mig_server_routine)) IOReturn externalMethod();
+  virtual __attribute__((mig_server_routine)) void anotherMethod(); // 
expected-warning{{'mig_server_routine' attribute only applies to functions that 
return a kernel return code}}

aaron.ballman wrote:
> Can you use the C++ spelling for the attribute, so we have a bit of coverage 
> for that?
Is there a vision that i should also provide a namespaced C++ attribute, eg. 
`[[mig::server_routine]]`?


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

https://reviews.llvm.org/D58365



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


[PATCH] D58365: [attributes] Add a MIG server routine attribute.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 187497.
NoQ marked 13 inline comments as done.
NoQ added a comment.

Fxd, thx!


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

https://reviews.llvm.org/D58365

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-mig.c
  clang/test/Sema/attr-mig.cpp
  clang/test/Sema/attr-mig.m

Index: clang/test/Sema/attr-mig.m
===
--- /dev/null
+++ clang/test/Sema/attr-mig.m
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
+
+typedef int kern_return_t;
+#define KERN_SUCCESS 0
+
+@interface NSObject
+@end
+
+@interface I: NSObject
+- (kern_return_t)foo __attribute__((mig_server_routine)); // no-warning
+- (void) bar_void __attribute__((mig_server_routine)); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}}
+- (int) bar_int __attribute__((mig_server_routine)); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}}
+@end
+
+@implementation I
+- (kern_return_t)foo {
+  kern_return_t (^block)() = ^ __attribute__((mig_server_routine)) { // no-warning
+return KERN_SUCCESS;
+  };
+
+  // TODO: Warn that this block doesn't return a kern_return_t.
+  void (^invalid_block)() = ^ __attribute__((mig_server_routine)) {};
+
+  return block();
+}
+- (void)bar_void {
+}
+- (int)bar_int {
+  return 0;
+}
+@end
Index: clang/test/Sema/attr-mig.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-mig.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef int kern_return_t;
+typedef kern_return_t IOReturn;
+#define KERN_SUCCESS 0
+#define kIOReturnSuccess KERN_SUCCESS
+
+class MyServer {
+public:
+  virtual __attribute__((mig_server_routine)) IOReturn externalMethod();
+  virtual __attribute__((mig_server_routine)) void anotherMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}}
+  virtual __attribute__((mig_server_routine)) int yetAnotherMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}}
+  [[clang::mig_server_routine]] virtual IOReturn cppAnnotatedMethod();
+  [[clang::mig_server_routine("arg")]] virtual IOReturn cppAnnotatedMethodWithInvalidArgs(); // expected-error{{'mig_server_routine' attribute takes no arguments}}
+  [[clang::mig_server_routine]] virtual int cppInvalidAnnotatedMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}}
+};
+
+IOReturn MyServer::externalMethod() {
+  return kIOReturnSuccess;
+}
Index: clang/test/Sema/attr-mig.c
===
--- /dev/null
+++ clang/test/Sema/attr-mig.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef int kern_return_t;
+#define KERN_SUCCESS 0
+
+__attribute__((mig_server_routine)) kern_return_t var = KERN_SUCCESS; // expected-warning-re{{'mig_server_routine' attribute only applies to functions, Objective-C methods, and blocks{{$
+
+__attribute__((mig_server_routine)) void foo_void(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}}
+__attribute__((mig_server_routine)) int foo_int(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}}
+
+__attribute__((mig_server_routine)) kern_return_t bar_extern(); // no-warning
+__attribute__((mig_server_routine)) kern_return_t bar_forward(); // no-warning
+
+__attribute__((mig_server_routine)) kern_return_t bar_definition() { // no-warning
+  return KERN_SUCCESS;
+}
+
+kern_return_t bar_forward() { // no-warning
+  return KERN_SUCCESS;
+}
+
+__attribute__((mig_server_routine(123))) kern_return_t bar_with_argument(); // expected-error{{'mig_server_routine' attribute takes no arguments}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -60,6 +60,7 @@
 // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record)
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
+// CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: MinSize (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: 

[PATCH] D58375: [Clang][NewPM] Disable tests that are broken under new PM

2019-02-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 187493.
Herald added a subscriber: mstorsjo.

Repository:
  rC Clang

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

https://reviews.llvm.org/D58375

Files:
  clang/test/CMakeLists.txt
  clang/test/CodeGen/aarch64-neon-across.c
  clang/test/CodeGen/aarch64-neon-fcvt-intrinsics.c
  clang/test/CodeGen/aarch64-neon-fma.c
  clang/test/CodeGen/aarch64-neon-perm.c
  clang/test/CodeGen/aarch64-neon-tbl.c
  clang/test/CodeGen/aarch64-poly128.c
  clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics.c
  clang/test/CodeGen/aggregate-assign-call.c
  clang/test/CodeGen/arm-neon-fma.c
  clang/test/CodeGen/arm-neon-numeric-maxmin.c
  clang/test/CodeGen/arm-neon-vcvtX.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGen/available-externally-suppress.c
  clang/test/CodeGen/avx-builtins.c
  clang/test/CodeGen/avx512-reduceMinMaxIntrin.c
  clang/test/CodeGen/avx512f-builtins.c
  clang/test/CodeGen/avx512vl-builtins.c
  clang/test/CodeGen/avx512vlbw-builtins.c
  clang/test/CodeGen/builtin-movdir.c
  clang/test/CodeGen/builtins-ppc-p9vector.c
  clang/test/CodeGen/builtins-ppc-vsx.c
  clang/test/CodeGen/callback_annotated.c
  clang/test/CodeGen/cfi-icall-cross-dso.c
  clang/test/CodeGen/complex-math.c
  clang/test/CodeGen/dllimport.c
  clang/test/CodeGen/flatten.c
  clang/test/CodeGen/inline2.c
  clang/test/CodeGen/lifetime.c
  clang/test/CodeGen/pgo-instrumentation.c
  clang/test/CodeGen/pgo-sample.c
  clang/test/CodeGen/sanitize-address-field-padding.cpp
  clang/test/CodeGen/split-debug-single-file.c
  clang/test/CodeGen/sse-builtins.c
  clang/test/CodeGen/sse2-builtins.c
  clang/test/CodeGen/tbaa-for-vptr.cpp
  clang/test/CodeGen/x86_64-instrument-functions.c
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/cfi-speculative-vtable.cpp
  clang/test/CodeGenCXX/conditional-temporaries.cpp
  clang/test/CodeGenCXX/debug-info-class-optzns.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/dso-local-executable.cpp
  clang/test/CodeGenCXX/flatten.cpp
  clang/test/CodeGenCXX/init-invariant.cpp
  clang/test/CodeGenCXX/member-function-pointer-calls.cpp
  clang/test/CodeGenCXX/merge-functions.cpp
  clang/test/CodeGenCXX/nrvo.cpp
  clang/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
  clang/test/CodeGenCXX/visibility-hidden-extern-templates.cpp
  clang/test/CodeGenObjC/os_log.m
  clang/test/CodeGenObjCXX/nrvo.mm
  clang/test/CodeGenOpenCL/convergent.cl
  clang/test/CoverageMapping/unused_names.c
  clang/test/Driver/asan.c
  clang/test/Driver/esan.c
  clang/test/Driver/msan.c
  clang/test/Driver/tsan.c
  clang/test/Frontend/optimization-remark-line-directive.c
  clang/test/Frontend/optimization-remark-with-hotness.c
  clang/test/Frontend/optimization-remark.c
  clang/test/Misc/pr32207.c
  clang/test/OpenMP/for_codegen.cpp
  clang/test/Profile/c-captured.c
  clang/test/Profile/c-general.c
  clang/test/Profile/c-generate.c
  clang/test/Profile/c-indirect-call.c
  clang/test/Profile/c-linkage-available_externally.c
  clang/test/Profile/c-linkage.c
  clang/test/Profile/c-ternary.c
  clang/test/Profile/c-unreachable-after-switch.c
  clang/test/Profile/cxx-class.cpp
  clang/test/Profile/cxx-implicit.cpp
  clang/test/Profile/cxx-indirect-call.cpp
  clang/test/Profile/cxx-lambda.cpp
  clang/test/Profile/cxx-linkage.cpp
  clang/test/Profile/cxx-rangefor.cpp
  clang/test/Profile/cxx-stmt-initializers.cpp
  clang/test/Profile/cxx-structors.cpp
  clang/test/Profile/cxx-templates.cpp
  clang/test/Profile/cxx-throws.cpp
  clang/test/Profile/cxx-virtual-destructor-calls.cpp
  clang/test/Profile/def-assignop.cpp
  clang/test/Profile/def-ctors.cpp
  clang/test/Profile/def-dtors.cpp
  clang/test/Profile/gcc-flag-compatibility.c
  clang/test/Profile/objc-general.m
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in

Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -24,6 +24,7 @@
 config.clang_examples = @CLANG_BUILD_EXAMPLES@
 config.enable_shared = @ENABLE_SHARED@
 config.enable_backtrace = @ENABLE_BACKTRACES@
+config.enable_experimental_new_pass_manager = @ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -99,6 +99,9 @@
 if config.clang_staticanalyzer_z3 == '1':
 config.available_features.add('z3')
 
+if config.enable_experimental_new_pass_manager:
+config.available_features.add('experimental-new-pass-manager')
+
 # As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
 if platform.system() not in ['FreeBSD']:
 

[PATCH] D58424: [NewPM] Add other sanitizers at O0

2019-02-19 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc accepted this revision.
chandlerc added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58424



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


[PATCH] D53076: [analyzer] Enhance ConditionBRVisitor to write out more information

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I'll take a closer look in a few days, sorry for the delays! The progress 
you're making is fantastic and i really appreciate your work, but i have an 
urgent piece of work of my own to deal with this week.


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

https://reviews.llvm.org/D53076



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


[PATCH] D58424: [NewPM] Add other sanitizers at O0

2019-02-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, philip.pfaffe, fedor.sergeev.
leonardchan added a project: clang.

This allows for MSan and TSan to be used without optimizations required.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58424

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/Driver/msan.c
  clang/test/Driver/tsan.c


Index: clang/test/Driver/tsan.c
===
--- clang/test/Driver/tsan.c
+++ clang/test/Driver/tsan.c
@@ -5,5 +5,13 @@
 // RUN: %clang -target x86_64-unknown-linux -fsanitize=thread  %s -S 
-emit-llvm -o - | FileCheck %s
 // Verify that -fsanitize=thread invokes tsan instrumentation.
 
+// Also check that this works with the new pass manager with and without
+// optimization
+// RUN: %clang -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O1 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -fexperimental-new-pass-manager -target 
x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+
 int foo(int *a) { return *a; }
 // CHECK: __tsan_init
Index: clang/test/Driver/msan.c
===
--- clang/test/Driver/msan.c
+++ clang/test/Driver/msan.c
@@ -15,6 +15,18 @@
 
 // Verify that -fsanitize=memory and -fsanitize=kernel-memory invoke 
MSan/KMSAN instrumentation.
 
+// Also check that this works with the new pass manager with and without
+// optimization
+// RUN: %clang -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O1 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O2 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -O3 -target x86_64-unknown-linux 
-fexperimental-new-pass-manager -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+
+// RUN: %clang -fexperimental-new-pass-manager -target mips64-linux-gnu 
-fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck 
%s --check-prefix=CHECK-MSAN
+// RUN: %clang -fexperimental-new-pass-manager -target 
powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-MSAN
+
 int foo(int *a) { return *a; }
 // CHECK-MSAN: __msan_init
 // CHECK-KMSAN: __msan_get_context_state
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -932,6 +932,14 @@
 /*CompileKernel=*/false, Recover, ModuleUseAfterScope,
 CodeGenOpts.SanitizeAddressUseOdrIndicator));
   }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass({})));
+  }
+
+  if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
+  }
 }
 
 /// A clean version of `EmitAssembly` that uses the new pass manager.


Index: clang/test/Driver/tsan.c
===
--- clang/test/Driver/tsan.c
+++ clang/test/Driver/tsan.c
@@ -5,5 +5,13 @@
 // RUN: %clang -target x86_64-unknown-linux -fsanitize=thread  %s -S -emit-llvm -o - | FileCheck %s
 // Verify that -fsanitize=thread invokes tsan instrumentation.
 
+// Also check that this works with the new pass manager with and without
+// optimization
+// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O1 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S 

[PATCH] D57497: [RISCV] Passing small data limitation value to RISCV backend

2019-02-19 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 added a comment.

In D57497#1394137 , @efriedma wrote:

> > Did you mean declare as a target feature in RISCV.td or I misunderstanding 
> > something?
>
> That's sort of the right idea, but I don't think it works in this context 
> because we aren't trying to change the generated code for a function; we 
> actually need to stick the global into a specific section.  Maybe worth 
> sending an email to llvmdev to discuss the right way to represent this in IR?


Hi Eli,
I have sent the email to llvmdev 
http://lists.llvm.org/pipermail/llvm-dev/2019-February/130222.html. It seems 
that there're not much consensus on how to represent in IR. I incline to 
implement passing through `-plugin-opt=` as the first version. We could create 
an incremental patch when we have more consensus on IR approach. What do you 
think?


Repository:
  rC Clang

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

https://reviews.llvm.org/D57497



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


[PATCH] D58375: [Clang][NewPM] Disable tests that are broken under new PM

2019-02-19 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a comment.

In D58375#1403144 , @efriedma wrote:

> I can understand why tests that use -O1 or -O2 would produce different 
> results with the new pass manager, but it looks like not all the tests are 
> like that.  Do you know why those tests are failing?
>
> For the tests that do use -O, instead of marking them unsupported, could you 
> use -fno-experimental-new-pass-manager or something like that?


For at least some of them, maybe we should run it in both modes (using the 
explicit flag as suggested by Eli) and check both forms.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58375



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


[PATCH] D58375: [Clang][NewPM] Disable tests that are broken under new PM

2019-02-19 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc requested changes to this revision.
chandlerc added a comment.
This revision now requires changes to proceed.

Based on the -dev discussion, update once the target machine differences are 
addressed by mimicing the way the legacy PM works, which will hopefully 
restrict this similarly to what Eli is suggesting as well...


Repository:
  rC Clang

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

https://reviews.llvm.org/D58375



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


[PATCH] D58204: CMake: Fix stand-alone clang builds since r353268

2019-02-19 Thread Tom Stellard via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL354417: CMake: Fix stand-alone clang builds since r353268 
(authored by tstellar, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58204?vs=186769=187473#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58204

Files:
  cfe/trunk/CMakeLists.txt
  llvm/trunk/cmake/modules/AddLLVM.cmake


Index: llvm/trunk/cmake/modules/AddLLVM.cmake
===
--- llvm/trunk/cmake/modules/AddLLVM.cmake
+++ llvm/trunk/cmake/modules/AddLLVM.cmake
@@ -1718,6 +1718,9 @@
 endfunction()
 
 function(find_first_existing_vc_file path out_var)
+  if(NOT EXISTS "${path}")
+return()
+  endif()
   if(EXISTS "${path}/.svn")
 set(svn_files
   "${path}/.svn/wc.db"   # SVN 1.7
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -75,6 +75,11 @@
 set(LIBRARY_DIR ${LLVM_LIBRARY_DIR})
 set(INCLUDE_DIR ${LLVM_INCLUDE_DIR})
 set(LLVM_OBJ_DIR ${LLVM_BINARY_DIR})
+# The LLVM_CMAKE_PATH variable is set when doing non-standalone builds and
+# used in this project, so we need to make sure we set this value.
+# FIXME: LLVM_CMAKE_DIR comes from LLVMConfig.cmake.  We should rename
+# LLVM_CMAKE_PATH to LLVM_CMAKE_DIR throughout the project.
+set(LLVM_CMAKE_PATH ${LLVM_CMAKE_DIR})
   endif()
 
   set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")


Index: llvm/trunk/cmake/modules/AddLLVM.cmake
===
--- llvm/trunk/cmake/modules/AddLLVM.cmake
+++ llvm/trunk/cmake/modules/AddLLVM.cmake
@@ -1718,6 +1718,9 @@
 endfunction()
 
 function(find_first_existing_vc_file path out_var)
+  if(NOT EXISTS "${path}")
+return()
+  endif()
   if(EXISTS "${path}/.svn")
 set(svn_files
   "${path}/.svn/wc.db"   # SVN 1.7
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -75,6 +75,11 @@
 set(LIBRARY_DIR ${LLVM_LIBRARY_DIR})
 set(INCLUDE_DIR ${LLVM_INCLUDE_DIR})
 set(LLVM_OBJ_DIR ${LLVM_BINARY_DIR})
+# The LLVM_CMAKE_PATH variable is set when doing non-standalone builds and
+# used in this project, so we need to make sure we set this value.
+# FIXME: LLVM_CMAKE_DIR comes from LLVMConfig.cmake.  We should rename
+# LLVM_CMAKE_PATH to LLVM_CMAKE_DIR throughout the project.
+set(LLVM_CMAKE_PATH ${LLVM_CMAKE_DIR})
   endif()
 
   set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58418: [clang][DirectoryWatcher] Upstream DirectoryWatcher

2019-02-19 Thread Jan Korous via Phabricator via cfe-commits
jkorous created this revision.
jkorous added reviewers: arphaman, dexonsmith, akyrtzi, nathawes, yvvan.
Herald added subscribers: cfe-commits, jdoerfert, jfb, mgorny.
Herald added a project: clang.

This patch contains implementation of DirectoryWatcher from 
github.com/apple/swift-clang

We are starting new push to upstream the index-while-building feature in clang 
and this is one of the dependencies.

Original author is David Farler, other contributors are Argyrios Kyrtzidis, 
Thomas Roughton and Alex Lorenz.

Part of this implementation was included in the review below so I am adding 
@tschuett and @yvvan in case they are interested.
https://reviews.llvm.org/D41407


Repository:
  rC Clang

https://reviews.llvm.org/D58418

Files:
  clang/include/clang/DirectoryWatcher/DirectoryWatcher.h
  clang/lib/CMakeLists.txt
  clang/lib/DirectoryWatcher/CMakeLists.txt
  clang/lib/DirectoryWatcher/DirectoryWatcher-linux.inc.h
  clang/lib/DirectoryWatcher/DirectoryWatcher-mac.inc.h
  clang/lib/DirectoryWatcher/DirectoryWatcher.cpp
  clang/unittests/CMakeLists.txt
  clang/unittests/DirectoryWatcher/CMakeLists.txt
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- /dev/null
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -0,0 +1,333 @@
+//===- unittests/DirectoryWatcher/DirectoryWatcherTest.cpp ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/DirectoryWatcher/DirectoryWatcher.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace llvm::sys;
+using namespace llvm::sys::fs;
+using namespace clang;
+
+namespace {
+
+class EventCollection {
+  SmallVector Events;
+
+public:
+  EventCollection() = default;
+  explicit EventCollection(ArrayRef events) {
+append(events);
+  }
+
+  void append(ArrayRef events) {
+Events.append(events.begin(), events.end());
+  }
+
+  bool empty() const { return Events.empty(); }
+  size_t size() const { return Events.size(); }
+  void clear() { Events.clear(); }
+
+  bool hasEvents(ArrayRef filenames,
+ ArrayRef kinds,
+ ArrayRef stats) const {
+assert(filenames.size() == kinds.size());
+assert(filenames.size() == stats.size());
+SmallVector evts = Events;
+bool hadError = false;
+for (unsigned i = 0, e = filenames.size(); i < e; ++i) {
+  StringRef fname = filenames[i];
+  DirectoryWatcher::EventKind kind = kinds[i];
+  file_status stat = stats[i];
+  auto it = std::find_if(evts.begin(), evts.end(),
+ [&](const DirectoryWatcher::Event ) -> bool {
+   return path::filename(evt.Filename) == fname;
+ });
+  if (it == evts.end()) {
+hadError = err(Twine("expected filename '" + fname + "' not found"));
+continue;
+  }
+  if (it->Kind != kind) {
+hadError = err(Twine("filename '" + fname + "' has event kind " +
+ std::to_string((int)it->Kind) + ", expected ") +
+   std::to_string((int)kind));
+  }
+  if (it->Kind != DirectoryWatcher::EventKind::Removed &&
+  it->ModTime != stat.getLastModificationTime())
+hadError =
+err(Twine("filename '" + fname + "' has different mod time"));
+  evts.erase(it);
+}
+for (const auto  : evts) {
+  hadError = err(Twine("unexpected filename '" +
+   path::filename(evt.Filename) + "' found"));
+}
+return !hadError;
+  }
+
+  bool hasAdded(ArrayRef filenames,
+ArrayRef stats) const {
+std::vector kinds{
+filenames.size(), DirectoryWatcher::EventKind::Added};
+return hasEvents(filenames, kinds, stats);
+  }
+
+  bool hasRemoved(ArrayRef filenames) const {
+std::vector kinds{
+filenames.size(), DirectoryWatcher::EventKind::Removed};
+std::vector stats{filenames.size(), file_status{}};
+return hasEvents(filenames, kinds, stats);
+  }
+
+private:
+  bool err(Twine msg) const {
+SmallString<128> buf;
+llvm::errs() << msg.toStringRef(buf) << '\n';
+return true;
+  }
+};
+
+struct EventOccurrence {
+  std::vector Events;
+  bool IsInitial;
+};
+
+class DirectoryWatcherTest
+: public std::enable_shared_from_this {
+  std::string WatchedDir;
+  std::string TempDir;
+  std::unique_ptr DirWatcher;
+
+  std::condition_variable Condition;
+  std::mutex Mutex;
+  std::deque EvtOccurs;
+
+public:
+  void init() {
+SmallString<128> pathBuf;
+

r354417 - CMake: Fix stand-alone clang builds since r353268

2019-02-19 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Feb 19 17:11:05 2019
New Revision: 354417

URL: http://llvm.org/viewvc/llvm-project?rev=354417=rev
Log:
CMake: Fix stand-alone clang builds since r353268

Summary:
Handle the case where LLVM_MAIN_SRC_DIR is not set and also use
LLVM_CMAKE_DIR for locating installed cmake files rather than
LLVM_CMAKE_PATH.

Reviewers: phosek, andrewrk, smeenai

Reviewed By: phosek, andrewrk, smeenai

Subscribers: mgorny, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/CMakeLists.txt

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=354417=354416=354417=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Tue Feb 19 17:11:05 2019
@@ -75,6 +75,11 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
 set(LIBRARY_DIR ${LLVM_LIBRARY_DIR})
 set(INCLUDE_DIR ${LLVM_INCLUDE_DIR})
 set(LLVM_OBJ_DIR ${LLVM_BINARY_DIR})
+# The LLVM_CMAKE_PATH variable is set when doing non-standalone builds and
+# used in this project, so we need to make sure we set this value.
+# FIXME: LLVM_CMAKE_DIR comes from LLVMConfig.cmake.  We should rename
+# LLVM_CMAKE_PATH to LLVM_CMAKE_DIR throughout the project.
+set(LLVM_CMAKE_PATH ${LLVM_CMAKE_DIR})
   endif()
 
   set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")


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


[PATCH] D58320: [Darwin] Introduce a new flag, -flink-builtins-rt that forces linking of the builtins library.

2019-02-19 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.

In D58320#1402254 , @peter.smith wrote:

> The implementation changes in the Darwin toolchain look fine to me, although 
> with respect to the command line option I think Petr Hosek's message on 
> cfe-dev is interesting:
>
> > GCC implements -nolibc which could be used to achieve the same effect when 
> > combined with -nostartfiles (and -nostdlib++ when compiling C++). I'd 
> > prefer that approach not only because it improves compatibility with with 
> > GCC, but also because it matches existing flag scheme which is subtractive 
> > rather than additive (i.e. -nodefaultlibs, -nostdlib, -nostdlib++, 
> > -nostartfiles). Clang already defines this flag but the only toolchain that 
> > currently supports it is DragonFly.
>
> Looking at https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html (quoted here 
> for convenience)
>
> > -nostartfiles
> >  Do not use the standard system startup files when linking. The standard 
> > system libraries are used normally, unless -nostdlib, -nolibc, or 
> > -nodefaultlibs is used.
> > -nolibc
> >  Do not use the C library or system libraries tightly coupled with it when 
> > linking. Still link with the startup files, libgcc or toolchain provided 
> > language support libraries such as libgnat, libgfortran or libstdc++ unless 
> > options preventing their inclusion are used as well. This typically removes 
> > -lc from the link command line, as well as system libraries that normally 
> > go with it and become meaningless when absence of a C library is assumed, 
> > for example -lpthread or -lm in some configurations. This is intended for 
> > bare-board targets when there is indeed no C library available.
>
> It does seem like these options accomplish what -flink_builtins_rt do with 
> the added advantage of being more portable with gcc. If they don't work for 
> you it will be worth double checking with Petr.


Thanks for taking a look. I've replied on the thread for the problem that 
approach presents.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58320



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-02-19 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

> There is a revision to solve this problem here: D58065 
> . I guess your input, as someone who didn't 
> participate in the checker dependency related patch reviews would be 
> invaluable, in terms of whether my description is understandable enough.

Thanks. I took a look at the documentation and it looks fine to me (modulo the 
comments from other reviewers and a couple of minor typos). I feel the 
csa-testbench documentation (https://github.com/Xazax-hun/csa-testbench) is 
very minimal and does not document a lot of intricacies which I had to figure 
out by trial-and-error.


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

https://reviews.llvm.org/D50488



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-02-19 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

Also I don't see the helptext for PointerSorting when I run:

  clang -cc1 -analyzer-checker-help | grep Pointer
  
alpha.core.PointerArithmCheck for pointer arithmetic on locations 
other than array elements
alpha.core.PointerSub   Check for pointer subtractions on two 
pointers pointing to different memory chunks
alpha.nondeterminism.PointerSorting
cplusplus.InnerPointer  Check for inner pointers of C++ containers 
used after re/deallocation


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

https://reviews.llvm.org/D50488



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-02-19 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

> It's because it invokes CodeChecker, which by default enables 
> valist.Uninitialized, but not ValistBase. Do you have assert failures after 
> my hotfix?

@Szelethus Thanks. I run into this assert when run through CodeChecker:

  Assertion `CheckerTags.count(tag) != 0 && "Requested checker is not 
registered! Maybe you should add it as a " "dependency in Checkers.td?"'

Is there a workaround?


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

https://reviews.llvm.org/D50488



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-02-19 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 187466.

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

https://reviews.llvm.org/D50488

Files:
  docs/analyzer/checkers.rst
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
  test/Analysis/ptr-sort.cpp
  www/analyzer/alpha_checks.html

Index: www/analyzer/alpha_checks.html
===
--- www/analyzer/alpha_checks.html
+++ www/analyzer/alpha_checks.html
@@ -33,6 +33,7 @@
 OS X Alpha Checkers
 Security Alpha Checkers
 Unix Alpha Checkers
+Non-determinism Alpha Checkers
 
 
 
@@ -1174,6 +1175,28 @@
 
 
 
+
+Non-determinism Alpha Checkers
+
+
+Name, DescriptionExample
+
+
+
+alpha.nondeterminism.PointerSorting
+(C++)
+Check for non-determinism caused by sorting of pointers.
+
+
+// C++
+void test() {
+ int a = 1, b = 2;
+ std::vector V = {, };
+ std::sort(V.begin(), V.end()); // warn
+}
+
+
+
  
  
 
Index: test/Analysis/ptr-sort.cpp
===
--- /dev/null
+++ test/Analysis/ptr-sort.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.nondeterminism.PointerSorting %s -analyzer-output=text -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+namespace std {
+  template
+  bool is_sorted(ForwardIt first, ForwardIt last);
+
+  template 
+  void nth_element(RandomIt first, RandomIt nth, RandomIt last);
+
+  template
+  void partial_sort(RandomIt first, RandomIt middle, RandomIt last);
+
+  template
+  void sort (RandomIt first, RandomIt last);
+
+  template
+  void stable_sort(RandomIt first, RandomIt last);
+
+  template
+  BidirIt partition(BidirIt first, BidirIt last, UnaryPredicate p);
+
+  template
+  BidirIt stable_partition(BidirIt first, BidirIt last, UnaryPredicate p);
+}
+
+bool f (int x) { return true; }
+bool g (int *x) { return true; }
+
+void PointerSorting() {
+  int a = 1, b = 2, c = 3;
+  std::vector V1 = {a, b};
+  std::vector V2 = {, };
+
+  std::is_sorted(V1.begin(), V1.end());// no-warning
+  std::nth_element(V1.begin(), V1.begin() + 1, V1.end());  // no-warning
+  std::partial_sort(V1.begin(), V1.begin() + 1, V1.end()); // no-warning
+  std::sort(V1.begin(), V1.end()); // no-warning
+  std::stable_sort(V1.begin(), V1.end());  // no-warning
+  std::partition(V1.begin(), V1.end(), f); // no-warning
+  std::stable_partition(V1.begin(), V1.end(), g);  // no-warning
+
+  std::is_sorted(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::nth_element(V2.begin(), V2.begin() + 1, V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::partial_sort(V2.begin(), V2.begin() + 1, V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::stable_sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::partition(V2.begin(), V2.end(), f); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::stable_partition(V2.begin(), V2.end(), g); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+}
Index: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
===
--- /dev/null
+++ 

[PATCH] D58065: [analyzer] Document the frontend library

2019-02-19 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added inline comments.



Comment at: docs/analyzer/developer-docs/FrontendLibrary.rst:12
+This document will describe the frontend of the Static Analyzer, basically
+everything from compiling the analyzer from source, through it's invocation up
+to the beginning of the analysis. It will touch on topics such as

typo: it's --> its



Comment at: docs/analyzer/developer-docs/FrontendLibrary.rst:42
+
+The following section is sort of a summary, and severeral items will be later
+revisited in greater detail.

typo: severeral --> several


Repository:
  rC Clang

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

https://reviews.llvm.org/D58065



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


[PATCH] D58375: [Clang][NewPM] Disable tests that are broken under new PM

2019-02-19 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I can understand why tests that use -O1 or -O2 would produce different results 
with the new pass manager, but it looks like not all the tests are like that.  
Do you know why those tests are failing?

For the tests that do use -O, instead of marking them unsupported, could you 
use -fno-experimental-new-pass-manager or something like that?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58375



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


[PATCH] D42593: GCC compatibility: Ignore -fstack-clash-protection

2019-02-19 Thread Tom Stellard via Phabricator via cfe-commits
tstellar abandoned this revision.
tstellar added a comment.
Herald added a subscriber: jdoerfert.
Herald added a project: clang.

I agree with Joerg, I don't think we should be ignoring these kinds of security 
flags (even though we already ignore -fstack-check).


Repository:
  rC Clang

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

https://reviews.llvm.org/D42593



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


[PATCH] D54880: Ignore gcc's stack-clash-protection flag

2019-02-19 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.
Herald added a project: clang.

See D42593 , I don't think it's good to ignore 
security flags like this.


Repository:
  rC Clang

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

https://reviews.llvm.org/D54880



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


[PATCH] D58243: [OPENMP] Delay emission of the asm target-specific error messages.

2019-02-19 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 added a comment.

The change looks okay to me.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58243



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


[PATCH] D58404: [clang-format] Add basic support for formatting C# files

2019-02-19 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: djasper, klimek, krasimir, benhamilton, 
JonasToth.
MyDeveloperDay added a project: clang.
Herald added subscribers: jdoerfert, mgorny.

This revision adds basic support for formatting C# files with clang-format, I 
know the barrier to entry is high here  so I'm sending this revision in to test 
the water as to whether this might be something we'd consider landing.

Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which 
is clang-formatted.

I've struggled with Visual Studio reformatting to get a clean and consistent 
style, I want to format our C# code on saving like I do now for C++ and i want 
it to have the same style as defined in our .clang-format file, so it 
consistent as it can be with C++.  (Braces/Breaking/Spaces/Indent etc..)

Using clang format without this patch leaves the code in a bad state, sometimes 
when the BreakStringLiterals is set, it  fails to compile.

Mostly the C# is similar to Java, except instead of JavaAnnotations I try to 
reuse the TT_AttributeSquare.

Almost the most valuable portion is to have a new Language in order to 
partition the configuration for C# within a common .clang-format file, with the 
auto detection on the .cs extension. But there are other C# specific styles 
that could be added later if this is accepted. in particular how  `{ set;get }` 
is formatted.

I'm including an example of its usage Before/After to demonstrate it initial 
capability.

C# code, formatted with current clang-format

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Reflection;
  
  namespace ConsoleApp1 {
  class Program {
  
[MainAttribute] static void Main(string[] args) {}
  
  public
void foo() {
  float f = 1.0;
  int a = (int)f;
  string[] args = new string[1];
  
  args[a] = "Hello";
}
  
  public
string Foo {
  set;
  get;
}
  }
  
  [ClassAttribute] public class Bar {
  public
Bar(){}
  
[MethodAttribute] public bool foo() {
  return true;
}
  
[XmlElement(ElementName = "TaxRate")] public int taxRate;
  
[MethodAttribute] internal bool foo() {
  string longstring =
  "VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLongLongLong";
  return true;
}
  }
  
  internal class InternalBar {
  public
InternalBar() {}
  }
  
  [TestClass][DeploymentItem("testData")] public class Test {
  }
  }

Same C# code, formatted with current clang-format with this revision  (no 
.clang-format file, out-of-box formatting)

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Reflection;
  
  namespace ConsoleApp1 {
  class Program {
  
[MainAttribute]
static void
Main(string[] args) {}
  
public void foo() {
  float f = 1.0;
  int a = (int) f;
  string[] args = new string[1];
  
  args[a] = "Hello";
}
  
public string Foo {
  set;
  get;
}
  }
  
  [ClassAttribute]
  public class Bar {
public Bar(){}
  
[MethodAttribute]
public bool foo() {
  return true;
}
  
[XmlElement(ElementName = "TaxRate")]
public int taxRate;
  
[MethodAttribute]
internal bool
foo() {
  string longstring =
  "VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLongLongLong";
  return true;
}
  }
  
  internal class InternalBar {
public InternalBar() {}
  }
  
  [TestClass]
  [DeploymentItem("testData")]
  public class Test {}
  }




Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D58404

Files:
  docs/ClangFormat.rst
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineParser.cpp
  tools/clang-format/ClangFormat.cpp
  unittests/Format/CMakeLists.txt
  unittests/Format/FormatTestCSharp.cpp

Index: unittests/Format/FormatTestCSharp.cpp
===
--- /dev/null
+++ unittests/Format/FormatTestCSharp.cpp
@@ -0,0 +1,100 @@
+//===- unittest/Format/FormatTestCSharp.cpp - Formatting tests for CSharp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+
+class FormatTestCSharp : public ::testing::Test {
+protected:
+  static 

[PATCH] D58367: [analyzer] NFC: Improve upon the concept of BugReporterVisitor.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a reviewer: Charusso.
NoQ marked an inline comment as done.
NoQ added a subscriber: Charusso.
NoQ added a comment.

In D58367#1402796 , @Szelethus wrote:

> 2. I guess most of the visitors could be changed to this format, do you have 
> plans to convert them? I'll happily land a hand, because it sounds like a big 
> chore. I guess that would also test this implementation fairly well.


I don't have an immediate plan but i'll definitely convert visitors when i 
touch them and get annoyed. Also i believe that this new functionality is much 
more useful for //core// visitors than for checker visitors, simply because 
there's much more information to reverse-engineer in every visitor. Eg., 
`trackExpressionValue` would have been so much easier if it didn't have to 
figure out where did an assignment happen, but instead relied on `ExprEngine` 
to write down this sort of info as a tag in, say, `evalStore`. There are just 
too many ways to introduce a store/environment binding that represents moving a 
value from one place to another and it hurts me when i see all of them 
duplicated in the visitor as a military-grade portion of spaghetti. The same 
apples to the `ConditionBRVisitor` that might probably even benefit from having 
`ConstraintManager` explain the high-level assumption that's being made //as// 
it's being made; it might have also made @Charusso's work on supporting various 
sorts of assumptions much easier. At the same time, there aren't that many ways 
to close a file descriptor, so these are much easier to catch and explain in a 
visitor, so the main problem in checkers is the boilerplate. Checker APIs, 
however, are much more important to get polished because they're used much more 
often.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:222-236
+  /// Produce a program point tag that displays an additional path note
+  /// to the user. This is a lightweirght alternative to the
+  /// BugReporterVisitor mechanism: instead of visiting the bug report
+  /// node-by-node to restore the sequence of events that led to discovering
+  /// a bug, you can add notes as you add your transitions.
+  const NoteTag *getNoteTag(NoteTag::Callback &) {
+return Eng.getNoteTags().getNoteTag(std::move(Cb));

Note: you can't use this API in checker callbacks that don't provide a 
`CheckerContext`. Let's have a quick look at the list of such callbacks:
- `checkEndAnalysis()`. I'm not super worried about this one because it's a 
really weird place to put an //intermediate// note. If someone really really 
needs this, it should be possible to access `ExprEngine` directly from this 
callback.
- `evalAssume()`. This one's a bummer - it could really benefit from the new 
functionality, but we can't squeeze a checker context into it because it 
definitely doesn't make sense to add transitions in the middle of `assume()`. 
We should probably be able to allow returning a note tag from that callback 
somehow.
- `checkLiveSymbols()`. I'm not worried about this one because it doesn't 
correspond to any actual event in the program and there's no way to change the 
program state at this point. If we want to extract some information from it 
anyway, i guess we can add opaque checker-specific data into `SymbolReaper` and 
transfer it to `checkDeadSymbols()`.
- `checkPointerEscape()`, `checkRegionChanges()`. These are usually used for 
invalidation that normally doesn't deserve a note. But it can be argued that it 
may deserve a note sometimes (eg., "note: function call might have changed the 
value of a global variable"), so i guess i'm a tiny bit worried, but we can 
have a closer look at this when we find any actual examples.
- `checkEndOfTranslationUnit()`, `checkASTDecl()`,`checkASTCodeBody()`. These 
don't fire during path-sensitive analysis, so there's nothing to worry about.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58367



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


[PATCH] D58243: [OPENMP] Delay emission of the asm target-specific error messages.

2019-02-19 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/Sema/SemaStmtAsm.cpp:256-263
   // If we're compiling CUDA file and function attributes indicate that it's 
not
   // for this compilation side, skip all the checks.
   if (!DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl())) {
 GCCAsmStmt *NS = new (Context) GCCAsmStmt(
 Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names,
 Constraints, Exprs.data(), AsmString, NumClobbers, Clobbers, 
RParenLoc);
 return NS;

ABataev wrote:
> tra wrote:
> > Now that inline asm errors are delayed, do we still need this check?
> With this patch, it is going to be delayed only for OpenMP. After the commit, 
> we could extend it for CUDA and remove this code. But not at the moment.
SGTM. 


Repository:
  rC Clang

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

https://reviews.llvm.org/D58243



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


[PATCH] D58365: [attributes] Add a MIG server routine attribute.

2019-02-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> @aaron.ballman, are you actually interested in reviewing these attributes? 
> 'Cause George added you on his reviews but i totally understand that these 
> are fairly exotic.

Yeah, I'd like to review these attributes -- thanks for double-checking with me!




Comment at: clang/include/clang/Basic/Attr.td:1310
 
+def MIGServerRoutine : InheritableAttr {
+  let Spellings = [Clang<"mig_server_routine">];

Should this be limited to specific targets, or is this a general concept that 
applies to all targets?



Comment at: clang/include/clang/Basic/Attr.td:1312
+  let Spellings = [Clang<"mig_server_routine">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MIGCallingConventionDocs];

Objective-C methods as well?



Comment at: clang/include/clang/Basic/Attr.td:1313
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MIGCallingConventionDocs];
+}

This isn't really a calling convention though, is it? It doesn't change 
codegen, impact function types, or anything like that.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8702
+def warn_mig_server_routine_does_not_return_kern_return_t : Warning<
+  "'%0' attribute only applies to functions that return a kernel return code">,
+  InGroup;

Will users understand "kernel return code"? Should this say `kern_return_t` 
explicitly?

No need to use %0 here, just spell out the attribute name directly (unless you 
expect this to be used by multiple attributes, in which case the name of the 
diagnostic should be changed).



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7142
+
+  // Mach Interface Generator annotations.
+  case ParsedAttr::AT_MIGServerRoutine:

This comment doesn't add a ton of value, I'd probably remove it.



Comment at: clang/test/Sema/attr-mig.c:6
+
+__attribute__((mig_server_routine)) kern_return_t var = KERN_SUCCESS; // 
expected-warning-re{{'mig_server_routine' attribute only applies to 
functions{{$
+

Can you also add a test showing that the attribute doesn't accept arguments.



Comment at: clang/test/Sema/attr-mig.c:17
+}
+
+kern_return_t bar_forward() { // no-warning

Here's an edge case to consider:
```
__attribute__((mig_server_routine)) int foo(void);

typedef int kern_return_t;

kern_return_t foo(void) { ... }
```
Do you have to care about situations like that?



Comment at: clang/test/Sema/attr-mig.cpp:10
+public:
+  virtual __attribute__((mig_server_routine)) IOReturn externalMethod();
+  virtual __attribute__((mig_server_routine)) void anotherMethod(); // 
expected-warning{{'mig_server_routine' attribute only applies to functions that 
return a kernel return code}}

Can you use the C++ spelling for the attribute, so we have a bit of coverage 
for that?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58365



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-02-19 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D50488#1402699 , @mgrang wrote:

> In D50488#1400823 , @whisperity 
> wrote:
>
> > Yeah, it seems upstream has moved away due to @Szelethus' implementation of 
> > a much more manageable "checker dependency" system. You most likely will 
> > have to rebase your patch first, then check what you missed which got added 
> > to other merged, existing checkers.
>
>
> Moreover, as I said I hit this assert only when invoking the checker via 
> csa-testbench. Outside that it seems to work fine. For example, my unit test 
> Analysis/ptr-sort.cpp passes.


It's because it invokes CodeChecker, which by default enables 
`valist.Uninitialized`, but not `ValistBase`. Do you have assert failures after 
my hotfix?

> Yes, I see that D55429 , D54438 
>  added a new dependency field for checkers. 
> However, I see that not all checkers need/have that field. In this case, 
> shouldn't providing a ento::shouldRegisterPointerSortingChecker function 
> which returns true be enough to register the checker?

It is enough, and you're very right about this not being properly documented! 
There is a revision to solve this problem here: D58065 
. I guess your input, as someone who didn't 
participate in the checker dependency related patch reviews would be 
invaluable, in terms of whether my description is understandable enough.


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

https://reviews.llvm.org/D50488



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


[PATCH] D58243: [OPENMP] Delay emission of the asm target-specific error messages.

2019-02-19 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev marked an inline comment as done.
ABataev added inline comments.



Comment at: lib/Sema/SemaStmtAsm.cpp:256-263
   // If we're compiling CUDA file and function attributes indicate that it's 
not
   // for this compilation side, skip all the checks.
   if (!DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl())) {
 GCCAsmStmt *NS = new (Context) GCCAsmStmt(
 Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names,
 Constraints, Exprs.data(), AsmString, NumClobbers, Clobbers, 
RParenLoc);
 return NS;

tra wrote:
> Now that inline asm errors are delayed, do we still need this check?
With this patch, it is going to be delayed only for OpenMP. After the commit, 
we could extend it for CUDA and remove this code. But not at the moment.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58243



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


[PATCH] D58367: [analyzer] NFC: Improve upon the concept of BugReporterVisitor.

2019-02-19 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

I love the idea! It looks way cleaner, tbh how messy visitors are have kept me 
away from implementing one for my own checker. Couple thoughts:

1. It would be great to have unit tests for this. Side note, I have already 
managed to make CSA unit tests tun under check-clang-analysis, but it makes 
check-clang and check-all run them twice, either way, if you find it helpful, I 
have a branch for it here: * I need to get home where I can push it to github, 
imagine a nice link here *. That should make development a tad bit less painful 
:)
2. I guess most of the visitors could be changed to this format, do you have 
plans to convert them? I'll happily land a hand, because it sounds like a big 
chore. I guess that would also test this implementation fairly well.
3. Either in your workbook, or even better, in the new sphinx documentation, it 
would be great to see a how-to. Although I guess it's fine to leave some time 
for this to mature.

Go at it, this really is great! ^-^


Repository:
  rC Clang

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

https://reviews.llvm.org/D58367



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


[PATCH] D49754: Add -m(no-)spe, and e500 CPU definitions and support to clang

2019-02-19 Thread vit9696 via Phabricator via cfe-commits
vit9696 added a comment.

This is a series of patches, which I believe should merged altogether. 
Currently the following patches are relevant:

- https://reviews.llvm.org/D49754
- https://reviews.llvm.org/D54409
- https://reviews.llvm.org/D54583
- https://reviews.llvm.org/D56703

The patches are intended to add PowerPC SPE support, and they do not seem to 
break things outside. Initially I wanted them to get merged into 8.x, but 
extensive local testing unveiled a number of issues, so the time was missed. I 
believe all the 4 patches are pretty much ready for merging, aside the 
following:

- approval from @jhibbits and @kthomsen, who do some testing as well
- https://reviews.llvm.org/D49754#1401168 is fixed or declared a separate 
issue, handled outside of the patchset

Depending on the above the decision should be taken. Meanwhile, a test should 
be added for `__NO_FPRS__` near `PPC32-SPE:#define __SPE__ 1 ` now that we 
define it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D49754



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


[PATCH] D57914: [Driver] Allow enum SanitizerOrdinal to represent more than 64 different sanitizer checks, NFC.

2019-02-19 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno marked an inline comment as done.
riccibruno added a comment.

Looks mostly fine to me. I have added a few inline comments but they are all 
little nits.




Comment at: include/clang/Basic/Sanitizers.h:39
+struct SanitizerMask {
+private:
+  // Number of array elements.

`struct` -> `class` and get rid of the `private` ?



Comment at: include/clang/Basic/Sanitizers.h:46
+  static constexpr unsigned kNumBits = sizeof(maskLoToHigh) * 8;
+  // Number of bits in a mask element.
+  static constexpr unsigned kNumBitElem = sizeof(maskLoToHigh[0]) * 8;

/// instead to have doxygen handle these comments (here and elsewhere).



Comment at: include/clang/Basic/Sanitizers.h:51
+  // Mask is initialized to 0.
+  SanitizerMask() : maskLoToHigh{} {}
+

You don't have to explicitly write the default ctor; you can just instead write 
`uint64_t maskLoToHigh[kNumElem]{};` above to value-initialize each element in 
the array.



Comment at: include/clang/Basic/Sanitizers.h:54
+  static constexpr bool
+  checkBitPos(const SanitizerKind::SanitizerOrdinal ) {
+return Pos < kNumBits;

`SanitizerOrdinal` should probably be passed by value here and elsewhere.



Comment at: include/clang/Basic/Sanitizers.h:61
+  bitPosToMask(const SanitizerKind::SanitizerOrdinal ) {
+assert(Pos < kNumBits);
+SanitizerMask mask;

Could you please add a relevant message to the assertion (here and elsewhere) ?



Comment at: include/clang/Basic/Sanitizers.h:96
+return false;
+}
+return true;

Is that vectorized by gcc/clang, or is that a sequence of branches ?



Comment at: lib/Driver/SanitizerArgs.cpp:53
+SanitizerMask CompatibleWithMinimalRuntime =
+TrappingSupported | Scudo | ShadowCallStack;
 

Shouldn't all of these masks be const to be sure that they are not modified by 
mistake (unless I a missing something and they are modified somewhere else) ?


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

https://reviews.llvm.org/D57914



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


[PATCH] D57977: [HIP] compile option code-object-v3 propagate to llc

2019-02-19 Thread Aaron Enye Shi via Phabricator via cfe-commits
ashi1 added a comment.

This was submitted again with the fix. Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D57977



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


[PATCH] D57662: [clang-tidy] Parallelise clang-tidy-diff.py

2019-02-19 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 187421.
zinovy.nis added a comment.

- `-j` is `1` by default;
- fixed minor remarks;


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

https://reviews.llvm.org/D57662

Files:
  clang-tidy/tool/clang-tidy-diff.py

Index: clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tidy/tool/clang-tidy-diff.py
+++ clang-tidy/tool/clang-tidy-diff.py
@@ -25,9 +25,56 @@
 
 import argparse
 import json
+import multiprocessing
+import os
 import re
 import subprocess
 import sys
+import threading
+
+is_py2 = sys.version[0] == '2'
+
+if is_py2:
+import Queue as queue
+else:
+import queue as queue
+
+def run_tidy(task_queue, lock, timeout):
+  watchdog = None
+  while True:
+command = task_queue.get()
+try:
+  proc = subprocess.Popen(command,
+  stdout=subprocess.PIPE,
+  stderr=subprocess.PIPE)
+
+  if timeout is not None:
+watchdog = threading.Timer(timeout, proc.kill)
+watchdog.start()
+
+  stdout, stderr = proc.communicate()
+
+  with lock:
+sys.stdout.write((' '.join(command)).decode('utf-8') + '\n' + stdout.decode('utf-8') + '\n')
+if stderr:
+  sys.stderr.write(stderr.decode('utf-8') + '\n')
+except Exception as e:
+  with lock:
+sys.stderr.write('Failed: ' + str(e) + ' '.join(command) + '\n')
+finally:
+  with lock:
+if (not timeout is None) and (not watchdog is None):
+  if not watchdog.is_alive():
+  sys.stderr.write('Terminated by timeout: ' + ' '.join(command) + '\n')
+  watchdog.cancel()
+  task_queue.task_done()
+
+
+def run_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+  for _ in range(max_tasks):
+t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
+t.daemon = True
+t.start()
 
 
 def main():
@@ -48,6 +95,10 @@
   help='custom pattern selecting file paths to check '
   '(case insensitive, overridden by -regex)')
 
+  parser.add_argument('-j', type=int, default=1,
+  help='number of tidy instances to be run in parallel.')
+  parser.add_argument('-timeout', type=int, default=None,
+  help='timeout per each file in seconds.')
   parser.add_argument('-fix', action='store_true', default=False,
   help='apply suggested fixes')
   parser.add_argument('-checks',
@@ -77,6 +128,11 @@
 
   args = parser.parse_args(argv)
 
+  if args.j == 0 or args.j > 1:
+if args.export_fixes:
+  print("error: -export-fixes and -j are mutually exclusive.")
+  sys.exit(1)
+
   # Extract changed lines for each file.
   filename = None
   lines_by_file = {}
@@ -84,7 +140,7 @@
 match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.p, line)
 if match:
   filename = match.group(2)
-if filename == None:
+if filename is None:
   continue
 
 if args.regex is not None:
@@ -102,44 +158,64 @@
 line_count = int(match.group(3))
   if line_count == 0:
 continue
-  end_line = start_line + line_count - 1;
+  end_line = start_line + line_count - 1
   lines_by_file.setdefault(filename, []).append([start_line, end_line])
 
-  if len(lines_by_file) == 0:
+  if not any(lines_by_file):
 print("No relevant changes found.")
 sys.exit(0)
 
-  line_filter_json = json.dumps(
-[{"name" : name, "lines" : lines_by_file[name]} for name in lines_by_file],
-separators = (',', ':'))
+  max_task = args.j
+  if max_task == 0:
+  max_task = multiprocessing.cpu_count()
+  max_task = min(len(lines_by_file), max_task)
+
+  # Tasks for clang-tidy.
+  task_queue = queue.Queue(max_task)
+  # A lock for console output.
+  lock = threading.Lock()
 
-  quote = "";
-  if sys.platform == 'win32':
-line_filter_json=re.sub(r'"', r'"""', line_filter_json)
-  else:
-quote = "'";
+  # Run a pool of clang-tidy workers.
+  run_workers(max_task, run_tidy, task_queue, lock, args.timeout)
 
-  # Run clang-tidy on files containing changes.
-  command = [args.clang_tidy_binary]
-  command.append('-line-filter=' + quote + line_filter_json + quote)
+  quote = ""
+  if sys.platform != 'win32':
+quote = "'"
+
+  # Form the common args list.
+  common_clang_tidy_args = []
   if args.fix:
-command.append('-fix')
+common_clang_tidy_args.append('-fix')
   if args.export_fixes:
-command.append('-export-fixes=' + args.export_fixes)
+common_clang_tidy_args.append('-export-fixes=' + args.export_fixes)
   if args.checks != '':
-command.append('-checks=' + quote + args.checks + quote)
+common_clang_tidy_args.append('-checks=' + quote + args.checks + quote)
   if args.quiet:
-command.append('-quiet')
+common_clang_tidy_args.append('-quiet')
   if args.build_path is not None:
-command.append('-p=%s' % 

[PATCH] D58365: [attributes] Add a MIG server routine attribute.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked an inline comment as done.
NoQ added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:4047-4048
+that have their return value of type ``kern_return_t`` unconditionally returned
+from the routine. The attribute can be applied to C++ methods, and in this case
+it will be automatically applied to overrides if the method is virtual.
+}];

Is there a way to enforce this automagically via adding some feature to the 
attribute? Or should i enforce it manually by teaching Static Analyzer to scan 
the overridden methods when looking for the attribute, like i did in D58397?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58365



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-02-19 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

In D50488#1400823 , @whisperity wrote:

> Yeah, it seems upstream has moved away due to @Szelethus' implementation of a 
> much more manageable "checker dependency" system. You most likely will have 
> to rebase your patch first, then check what you missed which got added to 
> other merged, existing checkers.


Yes, I see that D55429 , D54438 
 added a new dependency field for checkers. 
However, I see that not all checkers need/have that field. In this case, 
shouldn't providing a ento::shouldRegisterPointerSortingChecker function which 
returns true be enough to register the checker?
Moreover, as I said I hit this assert only when invoking the checker via 
csa-testbench. Outside that it seems to work fine. For example, my unit test 
Analysis/ptr-sort.cpp passes.


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

https://reviews.llvm.org/D50488



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


[PATCH] D58397: [analyzer] MIGChecker: Pour more data into the checker.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added a reviewer: dcoughlin.
Herald added subscribers: cfe-commits, jdoerfert, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

Previous patches were about the infrastructure of the checker. Right now the 
infrastructure is pretty much complete, so let's make use. Namely:

- Add more release functions. For now only `vm_deallocate()` was supported. 
I'll also have a look at adding an attribute so that users could annotate their 
own releasing functions, but hardcoding a few popular APIs wouldn't hurt.
- Add a non-zero value that isn't an error; this value is -315 ("MIG_NO_REPLY") 
and it's fine to deallocate data when you are returning this error.
- Make sure that the `mig_server_routine` annotation is inherited. Mmm, not 
sure, i expected Sema to do this automatically. I'll ask in D58365 
.


Repository:
  rC Clang

https://reviews.llvm.org/D58397

Files:
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/test/Analysis/mig.cpp

Index: clang/test/Analysis/mig.cpp
===
--- clang/test/Analysis/mig.cpp
+++ clang/test/Analysis/mig.cpp
@@ -1,21 +1,60 @@
 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.osx.MIG\
 // RUN:   -analyzer-output=text -verify %s
 
+typedef unsigned uint32_t;
 
 // XNU APIs.
 
 typedef int kern_return_t;
 #define KERN_SUCCESS 0
 #define KERN_ERROR 1
+#define MIG_NO_REPLY (-305)
 
 typedef unsigned mach_port_name_t;
 typedef unsigned vm_address_t;
 typedef unsigned vm_size_t;
+typedef void *ipc_space_t;
+typedef unsigned long io_user_reference_t;
 
 kern_return_t vm_deallocate(mach_port_name_t, vm_address_t, vm_size_t);
 
 #define MIG_SERVER_ROUTINE __attribute__((mig_server_routine))
 
+ kern_return_t mach_vm_deallocate(mach_port_name_t, vm_address_t, vm_size_t);
+ void mig_deallocate(vm_address_t, vm_size_t);
+ kern_return_t mach_port_deallocate(ipc_space_t, mach_port_name_t);
+
+
+// IOKit wrappers.
+
+class OSObject;
+typedef kern_return_t IOReturn;
+#define kIOReturnError 1
+
+enum {
+  kOSAsyncRef64Count = 8,
+};
+
+typedef io_user_reference_t OSAsyncReference64[kOSAsyncRef64Count];
+
+struct IOExternalMethodArguments {
+  io_user_reference_t *asyncReference;
+};
+
+struct IOExternalMethodDispatch {};
+
+class IOUserClient {
+public:
+  static IOReturn releaseAsyncReference64(OSAsyncReference64);
+
+  MIG_SERVER_ROUTINE
+  virtual IOReturn externalMethod(uint32_t selector, IOExternalMethodArguments *arguments,
+  IOExternalMethodDispatch *dispatch = 0, OSObject *target = 0, void *reference = 0);
+};
+
+
+// Tests.
+
 MIG_SERVER_ROUTINE
 kern_return_t basic_test(mach_port_name_t port, vm_address_t address, vm_size_t size) {
   vm_deallocate(port, address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
@@ -69,3 +108,51 @@
   }
   return KERN_SUCCESS;
 }
+
+// Test various APIs.
+MIG_SERVER_ROUTINE
+kern_return_t test_mach_vm_deallocate(mach_port_name_t port, vm_address_t address, vm_size_t size) {
+  mach_vm_deallocate(port, address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
+  return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value}}
+}
+
+MIG_SERVER_ROUTINE
+kern_return_t test_mach_port_deallocate(ipc_space_t space,
+mach_port_name_t port) {
+  mach_port_deallocate(space, port); // expected-note{{Deallocating object passed through parameter 'port'}}
+  return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value}}
+}
+
+MIG_SERVER_ROUTINE
+kern_return_t test_mig_deallocate(vm_address_t address, vm_size_t size) {
+  mig_deallocate(address, size); // expected-note{{Deallocating object passed through parameter 'address'}}
+  return KERN_ERROR; // expected-warning{{MIG callback fails with error after deallocating argument value}}
+ // expected-note@-1{{MIG callback fails with error after deallocating argument value}}
+}
+
+MIG_SERVER_ROUTINE
+IOReturn test_releaseAsyncReference64(IOExternalMethodArguments *arguments) {
+  IOUserClient::releaseAsyncReference64(arguments->asyncReference); // expected-note{{Deallocating object passed through parameter 'arguments'}}
+  return kIOReturnError;// expected-warning{{MIG callback fails with error after deallocating argument value}}
+// 

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-02-19 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 187418.

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

https://reviews.llvm.org/D50488

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
  test/Analysis/ptr-sort.cpp

Index: test/Analysis/ptr-sort.cpp
===
--- /dev/null
+++ test/Analysis/ptr-sort.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.nondeterminism.PointerSorting %s -analyzer-output=text -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+namespace std {
+  template
+  bool is_sorted(ForwardIt first, ForwardIt last);
+
+  template 
+  void nth_element(RandomIt first, RandomIt nth, RandomIt last);
+
+  template
+  void partial_sort(RandomIt first, RandomIt middle, RandomIt last);
+
+  template
+  void sort (RandomIt first, RandomIt last);
+
+  template
+  void stable_sort(RandomIt first, RandomIt last);
+
+  template
+  BidirIt partition(BidirIt first, BidirIt last, UnaryPredicate p);
+
+  template
+  BidirIt stable_partition(BidirIt first, BidirIt last, UnaryPredicate p);
+}
+
+bool f (int x) { return true; }
+bool g (int *x) { return true; }
+
+void PointerSorting() {
+  int a = 1, b = 2, c = 3;
+  std::vector V1 = {a, b};
+  std::vector V2 = {, };
+
+  std::is_sorted(V1.begin(), V1.end());// no-warning
+  std::nth_element(V1.begin(), V1.begin() + 1, V1.end());  // no-warning
+  std::partial_sort(V1.begin(), V1.begin() + 1, V1.end()); // no-warning
+  std::sort(V1.begin(), V1.end()); // no-warning
+  std::stable_sort(V1.begin(), V1.end());  // no-warning
+  std::partition(V1.begin(), V1.end(), f); // no-warning
+  std::stable_partition(V1.begin(), V1.end(), g);  // no-warning
+
+  std::is_sorted(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::nth_element(V2.begin(), V2.begin() + 1, V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::partial_sort(V2.begin(), V2.begin() + 1, V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::stable_sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::partition(V2.begin(), V2.end(), f); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::stable_partition(V2.begin(), V2.end(), g); // expected-warning {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+}
Index: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
===
--- /dev/null
+++ lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
@@ -0,0 +1,117 @@
+//===-- PointerSortingChecker.cpp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file defines PointerSortingChecker which checks for non-determinism
+// caused due to sorting containers with pointer-like elements.
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 

[PATCH] D56411: [CUDA][HIP][Sema] Fix template kernel with function as template parameter

2019-02-19 Thread Artem Belevich via Phabricator via cfe-commits
tra added a subscriber: rsmith.
tra added a comment.

In D56411#1400300 , @rjmccall wrote:

> Okay, but it's not great design to have a kind of overloading that can't be 
> resolved to an exact intended declaration even by an explicit cast.  That's 
> why I think making *optional* host/device typing is a good idea.  And I 
> strongly want to caution you against doing language design by just 
> incrementally hacking at the compiler to progressively make more test-cases 
> work, which is what it feels like you're doing.


+1. IMO for templates to work sensibly in this situations `__host__` / 
`__device__` must be part of the type.

I.e. extending the example above,

  __host__ int f() { return 1;}
  __device__ int f() { return 2;}
  template __kernel__ void t() { F(); }
  __host__ void g() { t<<<1,1>>>(); }
  __global__ void g() { t<<<1,1>>>(); } // technically legal in CUDA, though 
clang does not support it yet.

IMO, t in `__host__` g() should be different from t in `__device__` g(). 
Which implies that 'device-ness' must be part of the F's type so we would have 
two different instantiations, which is what we want to see in the AST.
Calling context if somewhat irrelevant for template instantiations. E.g. one 
could've explicitly instantiated the template in the global scope.

@rsmith Any suggestions how we could deal with this situation in a principled 
way?


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

https://reviews.llvm.org/D56411



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


[PATCH] D58392: [analyzer] MIGChecker: Fix false negatives for releases in automatic destructors.

2019-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added a reviewer: dcoughlin.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

The problem that was fixed in D25326  for 
inlined functions keeps biting us for the top-level functions as well. Namely, 
i had to use `check::PreStmt` rather than `check::EndFunction` in 
D57558  because in the `basic_test` test the 
paths get merged before invoking the `check::EndFunction` callback. I don't 
have an immediate fix for the whole overall problem, so for now, as a hack, 
`check::PreStmt` keeps being used.

However, the problem with `check::PreStmt` is that automatic 
destructors for function-local variables are not yet evaluated when this 
callback is invoked. This causes false negatives in MIGChecker: if memory is 
released in an automatic destructor and then an error code is returned, the bug 
is not found because the Static Analyzer evalues the destructor *after* the 
pre-return. Arguably, this may also be treated as a bug, depending on what does 
the "Pre" in `PreStmt` stand for.

But regardless, for now it seems that we'd have to subscribe on both callbacks.


Repository:
  rC Clang

https://reviews.llvm.org/D58392

Files:
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/test/Analysis/mig.cpp


Index: clang/test/Analysis/mig.cpp
===
--- clang/test/Analysis/mig.cpp
+++ clang/test/Analysis/mig.cpp
@@ -44,3 +44,28 @@
   return ret; // expected-warning{{MIG callback fails with error after 
deallocating argument value. This is use-after-free vulnerability because 
caller will try to deallocate it again}}
  // expected-note@-1{{MIG callback fails with error after 
deallocating argument value. This is use-after-free vulnerability because 
caller will try to deallocate it again}}
 }
+
+// Make sure we find the bug when the object is destroyed within an
+// automatic destructor.
+MIG_SERVER_ROUTINE
+kern_return_t test_vm_deallocate_in_automatic_dtor(mach_port_name_t port, 
vm_address_t address, vm_size_t size) {
+  struct WillDeallocate {
+mach_port_name_t port;
+vm_address_t address;
+vm_size_t size;
+~WillDeallocate() {
+  vm_deallocate(port, address, size); // expected-note{{Deallocating 
object passed through parameter 'address'}}
+}
+  } will_deallocate{port, address, size};
+
+ if (size > 10) {
+// expected-note@-1{{Assuming 'size' is > 10}}
+// expected-note@-2{{Taking true branch}}
+return KERN_ERROR;
+// expected-note@-1{{Calling '~WillDeallocate'}}
+// expected-note@-2{{Returning from '~WillDeallocate'}}
+// expected-warning@-3{{MIG callback fails with error after deallocating 
argument value. This is use-after-free vulnerability because caller will try to 
deallocate it again}}
+// expected-note@-4   {{MIG callback fails with error after deallocating 
argument value. This is use-after-free vulnerability because caller will try to 
deallocate it again}}
+  }
+  return KERN_SUCCESS;
+}
Index: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
@@ -31,15 +31,30 @@
 using namespace ento;
 
 namespace {
-class MIGChecker : public Checker> 
{
+class MIGChecker : public Checker,
+  check::EndFunction> {
   BugType BT{this, "Use-after-free (MIG calling convention violation)",
  categories::MemoryError};
 
   CallDescription vm_deallocate { "vm_deallocate", 3 };
 
+  void checkReturnAux(const ReturnStmt *RS, CheckerContext ) const;
+
 public:
   void checkPostCall(const CallEvent , CheckerContext ) const;
-  void checkPreStmt(const ReturnStmt *RS, CheckerContext ) const;
+
+  // HACK: We're making two attempts to find the bug: checkEndFunction
+  // should normally be enough but it fails when the return value is a literal
+  // that never gets put into the Environment and ends of function with 
multiple
+  // returns get agglutinated across returns, preventing us from obtaining
+  // the return value. The problem is similar to 
https://reviews.llvm.org/D25326
+  // but now we step into it in the top-level function.
+  void checkPreStmt(const ReturnStmt *RS, CheckerContext ) const {
+checkReturnAux(RS, C);
+  }
+  void checkEndFunction(const ReturnStmt *RS, CheckerContext ) const {
+checkReturnAux(RS, C);
+  }
 };
 } // end anonymous namespace
 
@@ -103,7 +118,7 @@
   C.addTransition(C.getState()->set(true), T);
 }
 
-void MIGChecker::checkPreStmt(const ReturnStmt *RS, CheckerContext ) const {
+void MIGChecker::checkReturnAux(const ReturnStmt *RS, CheckerContext ) const 
{
   // It is very unlikely that a MIG callback will be called from 

[PATCH] D58243: [OPENMP] Delay emission of the asm target-specific error messages.

2019-02-19 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/Sema/SemaStmtAsm.cpp:256-263
   // If we're compiling CUDA file and function attributes indicate that it's 
not
   // for this compilation side, skip all the checks.
   if (!DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl())) {
 GCCAsmStmt *NS = new (Context) GCCAsmStmt(
 Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names,
 Constraints, Exprs.data(), AsmString, NumClobbers, Clobbers, 
RParenLoc);
 return NS;

Now that inline asm errors are delayed, do we still need this check?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58243



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


Re: r354075 - [clang][FileManager] fillRealPathName even if we aren't opening the file

2019-02-19 Thread Jan Korous via cfe-commits
I see. You're right the name sounds slow indeed. Thank you for the explanation!

> On Feb 19, 2019, at 6:43 AM, Nico Weber  wrote:
> 
> I didn't realize it just copied a string. I just saw a call to 
> "fillRealPathName" and the "RealPath" bit sounded slow. From clicking around 
> in http://llvm-cs.pcc.me.uk/tools/clang/lib/Basic/FileManager.cpp#361 
>  it looks 
> like it's not really computing a realpath (for symlinks). It still does quite 
> a bit of string processing if InterndFileName isn't absolute, but that's 
> probably fine. It's still the kind of thing I'd carefully measure since 
> getFile(openFile=false) was performance-sensitive in a certain case iirc (I 
> think when using pch files?)
> 
> On Mon, Feb 18, 2019 at 5:26 PM Jan Korous  > wrote:
> Hi Nico,
> 
> I didn't think it necessary as the change doesn't introduce any interaction 
> with filesystem - it's just copying a string.
> 
> Do you mean it causes a performance regression?
> 
> Thanks.
> 
> Jan
> 
>> On Feb 15, 2019, at 6:15 AM, Nico Weber > > wrote:
>> 
>> Did you do any performance testing to check if this slows down clang?
>> 
>> On Thu, Feb 14, 2019 at 6:02 PM Jan Korous via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: jkorous
>> Date: Thu Feb 14 15:02:35 2019
>> New Revision: 354075
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=354075=rev 
>> 
>> Log:
>> [clang][FileManager] fillRealPathName even if we aren't opening the file
>> 
>> The pathname wasn't previously filled when the getFile() method was called 
>> with openFile = false.
>> We are caching FileEntry-s in ParsedAST::Includes in clangd and this caused 
>> the problem.
>> 
>> This fixes an internal test failure in clangd - ClangdTests.GoToInclude.All
>> 
>> rdar://47536127 <>
>> 
>> Differential Revision: https://reviews.llvm.org/D58213 
>> 
>> 
>> Modified:
>> cfe/trunk/lib/Basic/FileManager.cpp
>> cfe/trunk/unittests/Basic/FileManagerTest.cpp
>> 
>> Modified: cfe/trunk/lib/Basic/FileManager.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=354075=354074=354075=diff
>>  
>> 
>> ==
>> --- cfe/trunk/lib/Basic/FileManager.cpp (original)
>> +++ cfe/trunk/lib/Basic/FileManager.cpp Thu Feb 14 15:02:35 2019
>> @@ -267,6 +267,9 @@ const FileEntry *FileManager::getFile(St
>>if (UFE.File) {
>>  if (auto PathName = UFE.File->getName())
>>fillRealPathName(, *PathName);
>> +  } else if (!openFile) {
>> +// We should still fill the path even if we aren't opening the file.
>> +fillRealPathName(, InterndFileName);
>>}
>>return 
>>  }
>> 
>> Modified: cfe/trunk/unittests/Basic/FileManagerTest.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=354075=354074=354075=diff
>>  
>> 
>> ==
>> --- cfe/trunk/unittests/Basic/FileManagerTest.cpp (original)
>> +++ cfe/trunk/unittests/Basic/FileManagerTest.cpp Thu Feb 14 15:02:35 2019
>> @@ -346,4 +346,18 @@ TEST_F(FileManagerTest, getVirtualFileFi
>>EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
>>  }
>> 
>> +TEST_F(FileManagerTest, getFileDontOpenRealPath) {
>> +  auto statCache = llvm::make_unique();
>> +  statCache->InjectDirectory("/tmp/abc", 42);
>> +  SmallString<64> Path("/tmp/abc/foo.cpp");
>> +  statCache->InjectFile(Path.str().str().c_str(), 43);
>> +  manager.setStatCache(std::move(statCache));
>> +
>> +  const FileEntry *file = manager.getFile(Path, /*openFile=*/false);
>> +
>> +  ASSERT_TRUE(file != nullptr);
>> +
>> +  ASSERT_EQ(file->tryGetRealPathName(), Path);
>> +}
>> +
>>  } // anonymous namespace
>> 
>> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org 
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
>> 
> 

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


[PATCH] D49754: Add -m(no-)spe, and e500 CPU definitions and support to clang

2019-02-19 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

There is a long series of comments in this patch and I am not clear at this 
point on whether this patch breaks anything or it is fine. Could you please 
`Request Changes` if this patch is broken or approve if it is fine?


Repository:
  rC Clang

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

https://reviews.llvm.org/D49754



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


[PATCH] D57450: [RISCV] Set MaxAtomicInlineWidth and MaxAtomicPromoteWidth for RV32/RV64 targets with atomics

2019-02-19 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: lib/Basic/Targets/RISCV.h:94
+if (HasA)
+  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
+  }

MaxAtomicPromoteWidth is an incompatible ABI-change kind of thing.

We should set that to the maximum atomic size this target ABI will _EVER_ 
support with any hardware, since it changes the data layout for atomic types.

MaxAtomicInlineWidth can change based on hardware, and be increased in the 
future if other hardware is introduced, but MaxAtomicPromoteWidth shouldn't.

I think it should be set it to 64 for most 32-bit platforms, and 128 for most 
64-bit platforms.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57450



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


[PATCH] D57914: [Driver] Allow enum SanitizerOrdinal to represent more than 64 different sanitizer checks, NFC.

2019-02-19 Thread pierre gousseau via Phabricator via cfe-commits
pgousseau updated this revision to Diff 187400.
pgousseau added a comment.

Updated to use an array as suggested.


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

https://reviews.llvm.org/D57914

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/Sanitizers.def
  include/clang/Basic/Sanitizers.h
  include/clang/Driver/ToolChain.h
  lib/Basic/SanitizerSpecialCaseList.cpp
  lib/Basic/Sanitizers.cpp
  lib/CodeGen/CGExpr.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp

Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6199,7 +6199,8 @@
 if (!S.checkStringLiteralArgumentAttr(AL, I, SanitizerName, ))
   return;
 
-if (parseSanitizerValue(SanitizerName, /*AllowGroups=*/true) == 0)
+if (parseSanitizerValue(SanitizerName, /*AllowGroups=*/true) ==
+SanitizerMask())
   S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
 else if (isGlobalVar(D) && SanitizerName != "address")
   S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -551,7 +551,7 @@
 DiagnosticsEngine , SanitizerSet ) {
   for (const auto  : Sanitizers) {
 SanitizerMask K = parseSanitizerValue(Sanitizer, /*AllowGroups=*/false);
-if (K == 0)
+if (K == SanitizerMask())
   Diags.Report(diag::err_drv_invalid_value) << FlagName << Sanitizer;
 else
   S.set(K, true);
Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -25,29 +25,32 @@
 using namespace clang::driver;
 using namespace llvm::opt;
 
-enum : SanitizerMask {
-  NeedsUbsanRt = Undefined | Integer | ImplicitConversion | Nullability | CFI,
-  NeedsUbsanCxxRt = Vptr | CFI,
-  NotAllowedWithTrap = Vptr,
-  NotAllowedWithMinimalRuntime = Vptr,
-  RequiresPIE = DataFlow | HWAddress | Scudo,
-  NeedsUnwindTables = Address | HWAddress | Thread | Memory | DataFlow,
-  SupportsCoverage = Address | HWAddress | KernelAddress | KernelHWAddress |
- Memory | KernelMemory | Leak | Undefined | Integer |
- ImplicitConversion | Nullability | DataFlow | Fuzzer |
- FuzzerNoLink,
-  RecoverableByDefault = Undefined | Integer | ImplicitConversion | Nullability,
-  Unrecoverable = Unreachable | Return,
-  AlwaysRecoverable = KernelAddress | KernelHWAddress,
-  LegacyFsanitizeRecoverMask = Undefined | Integer,
-  NeedsLTO = CFI,
-  TrappingSupported = (Undefined & ~Vptr) | UnsignedIntegerOverflow |
-  ImplicitConversion | Nullability | LocalBounds | CFI,
-  TrappingDefault = CFI,
-  CFIClasses =
-  CFIVCall | CFINVCall | CFIMFCall | CFIDerivedCast | CFIUnrelatedCast,
-  CompatibleWithMinimalRuntime = TrappingSupported | Scudo | ShadowCallStack,
-};
+SanitizerMask NeedsUbsanRt =
+Undefined | Integer | ImplicitConversion | Nullability | CFI;
+SanitizerMask NeedsUbsanCxxRt = Vptr | CFI;
+SanitizerMask NotAllowedWithTrap = Vptr;
+SanitizerMask NotAllowedWithMinimalRuntime = Vptr;
+SanitizerMask RequiresPIE = DataFlow | HWAddress | Scudo;
+SanitizerMask NeedsUnwindTables =
+Address | HWAddress | Thread | Memory | DataFlow;
+SanitizerMask SupportsCoverage =
+Address | HWAddress | KernelAddress | KernelHWAddress | Memory |
+KernelMemory | Leak | Undefined | Integer | ImplicitConversion |
+Nullability | DataFlow | Fuzzer | FuzzerNoLink;
+SanitizerMask RecoverableByDefault =
+Undefined | Integer | ImplicitConversion | Nullability;
+SanitizerMask Unrecoverable = Unreachable | Return;
+SanitizerMask AlwaysRecoverable = KernelAddress | KernelHWAddress;
+SanitizerMask LegacyFsanitizeRecoverMask = Undefined | Integer;
+SanitizerMask NeedsLTO = CFI;
+SanitizerMask TrappingSupported = (Undefined & ~Vptr) |
+  UnsignedIntegerOverflow | ImplicitConversion |
+  Nullability | LocalBounds | CFI;
+SanitizerMask TrappingDefault = CFI;
+SanitizerMask CFIClasses =
+CFIVCall | CFINVCall | CFIMFCall | CFIDerivedCast | CFIUnrelatedCast;
+SanitizerMask CompatibleWithMinimalRuntime =
+TrappingSupported | Scudo | ShadowCallStack;
 
 enum CoverageFeature {
   CoverageFunc = 1 << 0,
@@ -136,10 +139,10 @@
 
 static SanitizerMask parseSanitizeTrapArgs(const Driver ,
const llvm::opt::ArgList ) {
-  SanitizerMask TrapRemove = 0; // During the loop below, the accumulated set of
+  SanitizerMask TrapRemove; // During the loop below, the accumulated set of
 // sanitizers disabled by 

[PATCH] D58388: [OpenCL] Simplify LLVM IR generated for OpenCL blocks

2019-02-19 Thread Alexey Sotkin via Phabricator via cfe-commits
AlexeySotkin updated this revision to Diff 187399.
AlexeySotkin added a comment.

Fix ObjC lit tests failure


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

https://reviews.llvm.org/D58388

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  test/CodeGenOpenCL/blocks.cl
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -312,9 +312,7 @@
   };
 
   // Uses global block literal [[BLG8]] and invoke function [[INVG8]].
-  // COMMON: [[r1:%.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* getelementptr inbounds (%struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), i32 0, i32 2)
-  // COMMON: [[r2:%.*]] = addrspacecast i8 addrspace(4)* [[r1]] to void (i8 addrspace(4)*)*
-  // COMMON: call spir_func void [[r2]](i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
+  // COMMON: call spir_func void @__device_side_enqueue_block_invoke_11(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
   block_A();
 
   // Emits global block literal [[BLG8]] and block kernel [[INVGK8]]. [[INVGK8]] calls [[INVG8]].
@@ -333,9 +331,7 @@
   unsigned size = get_kernel_work_group_size(block_A);
 
   // Uses global block literal [[BLG8]] and invoke function [[INVG8]]. Make sure no redundant block literal and invoke functions are emitted.
-  // COMMON: [[r1:%.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* getelementptr inbounds (%struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), i32 0, i32 2)
-  // COMMON: [[r2:%.*]] = addrspacecast i8 addrspace(4)* [[r1]] to void (i8 addrspace(4)*)*
-  // COMMON: call spir_func void [[r2]](i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
+  // COMMON: call spir_func void @__device_side_enqueue_block_invoke_11(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
   block_A();
 
   void (^block_C)(void) = ^{
Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -39,11 +39,8 @@
   // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast %struct.__opencl_block_literal_generic* %[[blk_ptr]] to %struct.__opencl_block_literal_generic addrspace(4)*
   // SPIR: store %struct.__opencl_block_literal_generic addrspace(4)* %[[blk_gen_ptr]], %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B:.*]],
   // SPIR: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic addrspace(4)*, %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B]]
-  // SPIR: %[[invoke_addr:.*]] = getelementptr inbounds %struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]], i32 0, i32 2
   // SPIR: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]] to i8 addrspace(4)*
-  // SPIR: %[[invoke_func_ptr:.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* %[[invoke_addr]]
-  // SPIR: %[[invoke_func:.*]] = addrspacecast i8 addrspace(4)* %[[invoke_func_ptr]] to i32 (i8 addrspace(4)*)*
-  // SPIR: call {{.*}}i32 %[[invoke_func]](i8 addrspace(4)* %[[blk_gen_ptr]])
+  // SPIR: call {{.*}}i32 @__foo_block_invoke(i8 addrspace(4)* %[[blk_gen_ptr]])
   // AMDGCN: %[[block_invoke:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block:.*]], i32 0, i32 2
   // AMDGCN: store i8* bitcast (i32 (i8*)* @__foo_block_invoke to i8*), i8* addrspace(5)* %[[block_invoke]]
   // AMDGCN: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]], i32 0, i32 3
@@ -53,11 +50,8 @@
   // AMDGCN: %[[blk_gen_ptr:.*]] = addrspacecast %struct.__opencl_block_literal_generic addrspace(5)* %[[blk_ptr]] to 

[PATCH] D58292: Add support for importing ChooseExpr AST nodes.

2019-02-19 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 187393.
tmroeder marked 6 inline comments as done.
tmroeder added a comment.

Thanks for the review and the suggestions for improving the tests.

This update cleans up the tests as suggested.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58292

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTImporter.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  lib/ASTMatchers/Dynamic/Registry.cpp
  test/ASTMerge/choose-expr/Inputs/choose.c
  test/ASTMerge/choose-expr/test.c
  unittests/AST/ASTImporterTest.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -754,6 +754,11 @@
   EXPECT_TRUE(matches("int* i = nullptr;", cxxNullPtrLiteralExpr()));
 }
 
+TEST(Matcher, ChooseExpr) {
+  EXPECT_TRUE(matchesC("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+   chooseExpr()));
+}
+
 TEST(Matcher, GNUNullExpr) {
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -563,6 +563,15 @@
   stringLiteral(hasType(asString("const char [7]"));
 }
 
+TEST_P(ImportExpr, ImportChooseExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+"void declToImport() { __builtin_choose_expr(1, 2, 3); }",
+Lang_C, "", Lang_C, Verifier,
+functionDecl(hasDescendant(chooseExpr(;
+}
+
 TEST_P(ImportExpr, ImportGNUNullExpr) {
   MatchVerifier Verifier;
   testImport(
Index: test/ASTMerge/choose-expr/test.c
===
--- /dev/null
+++ test/ASTMerge/choose-expr/test.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -std=c11 -emit-pch -o %t.ast %S/Inputs/choose.c
+// RUN: %clang_cc1 -std=c11 -ast-merge %t.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
+
Index: test/ASTMerge/choose-expr/Inputs/choose.c
===
--- /dev/null
+++ test/ASTMerge/choose-expr/Inputs/choose.c
@@ -0,0 +1,2 @@
+_Static_assert(__builtin_choose_expr(1, 1, 0), "Incorrect semantics of __builtin_choose_expr");
+_Static_assert(__builtin_choose_expr(0, 0, 1), "Incorrect semantics of __builtin_choose_expr");
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -147,6 +147,7 @@
   REGISTER_MATCHER(caseStmt);
   REGISTER_MATCHER(castExpr);
   REGISTER_MATCHER(characterLiteral);
+  REGISTER_MATCHER(chooseExpr);
   REGISTER_MATCHER(classTemplateDecl);
   REGISTER_MATCHER(classTemplateSpecializationDecl);
   REGISTER_MATCHER(complexType);
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -727,6 +727,7 @@
 compoundLiteralExpr;
 const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
+const internal::VariadicDynCastAllOfMatcher chooseExpr;
 const internal::VariadicDynCastAllOfMatcher gnuNullExpr;
 const internal::VariadicDynCastAllOfMatcher atomicExpr;
 const internal::VariadicDynCastAllOfMatcher stmtExpr;
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -552,6 +552,7 @@
 // Importing expressions
 ExpectedStmt VisitExpr(Expr *E);
 ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
+ExpectedStmt VisitChooseExpr(ChooseExpr *E);
 ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
 ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
 ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
@@ -6135,6 +6136,35 @@
   E->isMicrosoftABI());
 }
 
+ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) {
+  auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(),
+   E->getBuiltinLoc(), E->getRParenLoc(), E->getType());
+  if (!Imp)
+return Imp.takeError();
+
+  Expr *ToCond;
+  Expr *ToLHS;
+  Expr *ToRHS;
+  SourceLocation ToBuiltinLoc, ToRParenLoc;
+  QualType ToType;
+  std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp;
+
+  ExprValueKind VK = E->getValueKind();
+  ExprObjectKind OK = E->getObjectKind();
+
+  bool TypeDependent = ToCond->isTypeDependent();
+  bool ValueDependent = ToCond->isValueDependent();
+
+  // The value of CondIsTrue only matters if the value is not
+  // condition-dependent.
+  bool CondIsTrue = false;
+  if (!E->isConditionDependent())
+CondIsTrue = 

[PATCH] D58292: Add support for importing ChooseExpr AST nodes.

2019-02-19 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added inline comments.



Comment at: test/ASTMerge/choose-expr/Inputs/choose1.c:1
+#define abs_int(x) __builtin_choose_expr( \
+__builtin_types_compatible_p(__typeof(x), unsigned int),  \

a_sidorin wrote:
> This test duplicates unit test. I think we can keep unit test only and remove 
> this one.
> The other option (I like it even more) is to turn this test into constexpr 
> check and verify that this code _behaves_ as expected, not only that its AST 
> structure is fine. You can find some examples in ASTMerge tests - for expr 
> import, for example.
I can't use constexpr (and static_assert, as in the expr tests) because those 
are C++ keywords, and __builtin_choose_expr is only in C.

Instead, I used _Static_assert (from C11) to get a similar effect. Please take 
a look.



Comment at: unittests/AST/ASTImporterTest.cpp:1101
+  Decl *FromTU = getTuDecl(
+  R"(
+  #define abs_int(x) __builtin_choose_expr(\

a_sidorin wrote:
> I don't think we really need such macros in unit test just to check that the 
> expr is imported correctly - a single valid __builtin_choose_expr is enough. 
> It can even be checked with a simple `testImport()` call.
OK, dropped the test, since I already have that in ImportExpr.ImportChooseExpr 
in this patch.



Comment at: unittests/ASTMatchers/ASTMatchersNodeTest.cpp:765
+  EXPECT_TRUE(matchesC(R"(
+  void f() {
+int x = -10;

a_sidorin wrote:
> Same here - I think the tests should be concise if it is possible.
OK, dropped this part of the test too, since the first part checks that a 
simple __builtin_choose_expr matches correctly.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58292



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


[PATCH] D58293: [clang][Index] Enable indexing of Template Type Parameters behind a flag

2019-02-19 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, but see the comment about avoiding code duplication




Comment at: lib/Index/IndexDecl.cpp:678
 IndexCtx.indexTypeSourceInfo(TTP->getDefaultArgumentInfo(), 
Parent);
+  if(IndexCtx.shouldIndexTemplateParameters())
+IndexCtx.handleDecl(TTP);

Maybe do it once on top of `TP` to avoid code duplication?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58293



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


[PATCH] D58343: Enablement for AMD znver2 architecture - skeleton patch

2019-02-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58343



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


[PATCH] D58343: Enablement for AMD znver2 architecture - skeleton patch

2019-02-19 Thread Ganesh Gopalasubramanian via Phabricator via cfe-commits
GGanesh updated this revision to Diff 187389.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58343

Files:
  include/llvm/Support/X86TargetParser.def
  lib/Support/Host.cpp
  lib/Target/X86/X86.td
  test/CodeGen/X86/cpus-amd.ll
  test/CodeGen/X86/lzcnt-zext-cmp.ll
  test/CodeGen/X86/slow-unaligned-mem.ll
  test/CodeGen/X86/x86-64-double-shifts-var.ll

Index: test/CodeGen/X86/x86-64-double-shifts-var.ll
===
--- test/CodeGen/X86/x86-64-double-shifts-var.ll
+++ test/CodeGen/X86/x86-64-double-shifts-var.ll
@@ -13,8 +13,9 @@
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=bdver3 | FileCheck %s
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=bdver4 | FileCheck %s
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver1 | FileCheck %s
+; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver2 | FileCheck %s
 
-; Verify that for the X86_64 processors that are known to have poor latency 
+; Verify that for the X86_64 processors that are known to have poor latency
 ; double precision shift instructions we do not generate 'shld' or 'shrd'
 ; instructions.
 
@@ -25,7 +26,7 @@
 
 define i64 @lshift(i64 %a, i64 %b, i32 %c) nounwind readnone {
 entry:
-; CHECK-NOT: shld 
+; CHECK-NOT: shld
   %sh_prom = zext i32 %c to i64
   %shl = shl i64 %a, %sh_prom
   %sub = sub nsw i32 64, %c
Index: test/CodeGen/X86/slow-unaligned-mem.ll
===
--- test/CodeGen/X86/slow-unaligned-mem.ll
+++ test/CodeGen/X86/slow-unaligned-mem.ll
@@ -47,6 +47,7 @@
 ; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=bdver32>&1 | FileCheck %s --check-prefix=FAST
 ; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=bdver42>&1 | FileCheck %s --check-prefix=FAST
 ; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=znver12>&1 | FileCheck %s --check-prefix=FAST
+; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=znver22>&1 | FileCheck %s --check-prefix=FAST
 
 ; Other chips with slow unaligned memory accesses
 
Index: test/CodeGen/X86/lzcnt-zext-cmp.ll
===
--- test/CodeGen/X86/lzcnt-zext-cmp.ll
+++ test/CodeGen/X86/lzcnt-zext-cmp.ll
@@ -5,6 +5,8 @@
 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=btver2 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s
 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver1 | FileCheck --check-prefix=ALL --check-prefix=FASTLZCNT %s
 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver1 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s
+; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver2 | FileCheck --check-prefix=ALL --check-prefix=FASTLZCNT %s
+; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver2 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s
 
 ; Test one 32-bit input, output is 32-bit, no transformations expected.
 define i32 @test_zext_cmp0(i32 %a) {
Index: test/CodeGen/X86/cpus-amd.ll
===
--- test/CodeGen/X86/cpus-amd.ll
+++ test/CodeGen/X86/cpus-amd.ll
@@ -26,6 +26,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=btver1 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=btver2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=znver1 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=znver2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: lib/Target/X86/X86.td
===
--- lib/Target/X86/X86.td
+++ lib/Target/X86/X86.td
@@ -1144,8 +1144,8 @@
   FeatureMacroFusion
 ]>;
 
-// Znver1
-def: ProcessorModel<"znver1", Znver1Model, [
+// AMD Zen Processors common ISAs
+def ZNFeatures : ProcessorFeatures<[], [
   FeatureADX,
   FeatureAES,
   FeatureAVX2,
@@ -1184,6 +1184,19 @@
   FeatureXSAVEOPT,
   FeatureXSAVES]>;
 
+class Znver1Proc : ProcModel;
+def : Znver1Proc<"znver1">;
+
+class Znver2Proc : ProcModel;
+def : Znver2Proc<"znver2">;
+
 def : Proc<"geode",   [FeatureX87, FeatureSlowUAMem16, Feature3DNowA]>;
 
 def : Proc<"winchip-c6",  [FeatureX87, FeatureSlowUAMem16, FeatureMMX]>;
Index: lib/Support/Host.cpp
===
--- lib/Support/Host.cpp
+++ lib/Support/Host.cpp
@@ -916,7 +916,14 @@
 break; // "btver2"
   case 23:
 *Type = X86::AMDFAM17H;
-*Subtype = X86::AMDFAM17H_ZNVER1;
+if (Model >= 0x30 && Model <= 0x3f) {
+  *Subtype = X86::AMDFAM17H_ZNVER2;
+  break; // "znver2"; 30h-3fh: Zen2
+}
+if (Model <= 0x0f) {
+  *Subtype = 

[PATCH] D58377: Remove extraneous space in MSVC-style diagnostic output

2019-02-19 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC354351: Remove extraneous space in MSVC-style diagnostic 
output (authored by hans, committed by ).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D58377?vs=187320=187388#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D58377

Files:
  lib/Frontend/TextDiagnostic.cpp
  test/Misc/diag-format.c


Index: test/Misc/diag-format.c
===
--- test/Misc/diag-format.c
+++ test/Misc/diag-format.c
@@ -1,30 +1,30 @@
-// RUN: %clang -fsyntax-only  %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
-// RUN: %clang -fsyntax-only -fdiagnostics-format=clang %s 2>&1 | FileCheck %s 
-check-prefix=DEFAULT
-// RUN: %clang -fsyntax-only -fdiagnostics-format=clang -target 
x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang -fsyntax-only  %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=DEFAULT
+// RUN: %clang -fsyntax-only -fdiagnostics-format=clang %s 2>&1 | FileCheck %s 
--strict-whitespace -check-prefix=DEFAULT
+// RUN: %clang -fsyntax-only -fdiagnostics-format=clang -target 
x86_64-pc-win32 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=DEFAULT
 //
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300  %s 
2>&1 | FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00  %s 2>&1 | FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1800 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2013
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 
%s 2>&1 | FileCheck %s -check-prefix=MSVC
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1900 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2015
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00 -target x86_64-pc-win32 -fshow-column %s 2>&1 
| FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1800 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2013
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 
-fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1900 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2015
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300  %s 
2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00  %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s 
--strict-whitespace -check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
--strict-whitespace -check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1800 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=MSVC2013
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 
%s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1900 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=MSVC2015
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00 -target x86_64-pc-win32 -fshow-column %s 2>&1 
| FileCheck %s --strict-whitespace -check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1800 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
--strict-whitespace -check-prefix=MSVC2013
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 
-fshow-column %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC
+// RUN: %clang -fsyntax-only 

[PATCH] D58343: Enablement for AMD znver2 architecture - skeleton patch

2019-02-19 Thread Ganesh Gopalasubramanian via Phabricator via cfe-commits
GGanesh updated this revision to Diff 187386.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58343

Files:
  include/llvm/Support/X86TargetParser.def
  lib/Support/Host.cpp
  lib/Target/X86/X86.td
  test/CodeGen/X86/cpus-amd.ll
  test/CodeGen/X86/lzcnt-zext-cmp.ll
  test/CodeGen/X86/slow-unaligned-mem.ll
  test/CodeGen/X86/x86-64-double-shifts-var.ll

Index: test/CodeGen/X86/x86-64-double-shifts-var.ll
===
--- test/CodeGen/X86/x86-64-double-shifts-var.ll
+++ test/CodeGen/X86/x86-64-double-shifts-var.ll
@@ -13,8 +13,9 @@
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=bdver3 | FileCheck %s
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=bdver4 | FileCheck %s
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver1 | FileCheck %s
+; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver2 | FileCheck %s
 
-; Verify that for the X86_64 processors that are known to have poor latency 
+; Verify that for the X86_64 processors that are known to have poor latency
 ; double precision shift instructions we do not generate 'shld' or 'shrd'
 ; instructions.
 
@@ -25,7 +26,7 @@
 
 define i64 @lshift(i64 %a, i64 %b, i32 %c) nounwind readnone {
 entry:
-; CHECK-NOT: shld 
+; CHECK-NOT: shld
   %sh_prom = zext i32 %c to i64
   %shl = shl i64 %a, %sh_prom
   %sub = sub nsw i32 64, %c
Index: test/CodeGen/X86/slow-unaligned-mem.ll
===
--- test/CodeGen/X86/slow-unaligned-mem.ll
+++ test/CodeGen/X86/slow-unaligned-mem.ll
@@ -47,6 +47,7 @@
 ; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=bdver32>&1 | FileCheck %s --check-prefix=FAST
 ; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=bdver42>&1 | FileCheck %s --check-prefix=FAST
 ; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=znver12>&1 | FileCheck %s --check-prefix=FAST
+; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=znver22>&1 | FileCheck %s --check-prefix=FAST
 
 ; Other chips with slow unaligned memory accesses
 
Index: test/CodeGen/X86/lzcnt-zext-cmp.ll
===
--- test/CodeGen/X86/lzcnt-zext-cmp.ll
+++ test/CodeGen/X86/lzcnt-zext-cmp.ll
@@ -5,6 +5,8 @@
 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=btver2 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s
 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver1 | FileCheck --check-prefix=ALL --check-prefix=FASTLZCNT %s
 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver1 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s
+; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver2 | FileCheck --check-prefix=ALL --check-prefix=FASTLZCNT %s
+; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver2 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s
 
 ; Test one 32-bit input, output is 32-bit, no transformations expected.
 define i32 @test_zext_cmp0(i32 %a) {
Index: test/CodeGen/X86/cpus-amd.ll
===
--- test/CodeGen/X86/cpus-amd.ll
+++ test/CodeGen/X86/cpus-amd.ll
@@ -26,6 +26,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=btver1 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=btver2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=znver1 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=znver2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: lib/Target/X86/X86.td
===
--- lib/Target/X86/X86.td
+++ lib/Target/X86/X86.td
@@ -1144,15 +1144,14 @@
   FeatureMacroFusion
 ]>;
 
-// Znver1
-def: ProcessorModel<"znver1", Znver1Model, [
+// AMD Zen Processors common ISAs
+def ZNFeatures : ProcessorFeatures<[], [
   FeatureADX,
   FeatureAES,
   FeatureAVX2,
   FeatureBMI,
   FeatureBMI2,
   FeatureCLFLUSHOPT,
-  FeatureCLZERO,
   FeatureCMOV,
   Feature64Bit,
   FeatureCMPXCHG16B,
@@ -1184,6 +1183,21 @@
   FeatureXSAVEOPT,
   FeatureXSAVES]>;
 
+class Znver1Proc : ProcModel;
+def : Znver1Proc<"znver1">;
+
+class Znver2Proc : ProcModel;
+def : Znver2Proc<"znver2">;
+
 def : Proc<"geode",   [FeatureX87, FeatureSlowUAMem16, Feature3DNowA]>;
 
 def : Proc<"winchip-c6",  [FeatureX87, FeatureSlowUAMem16, FeatureMMX]>;
Index: lib/Support/Host.cpp
===
--- lib/Support/Host.cpp
+++ lib/Support/Host.cpp
@@ -916,7 +916,14 @@
 break; // "btver2"
   case 23:
 *Type = X86::AMDFAM17H;
-*Subtype = X86::AMDFAM17H_ZNVER1;
+if (Model >= 0x30 && Model <= 0x3f) {
+  

[PATCH] D58344: Enablement for AMD znver2 architecture - skeleton

2019-02-19 Thread Ganesh Gopalasubramanian via Phabricator via cfe-commits
GGanesh updated this revision to Diff 187387.

Repository:
  rC Clang

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

https://reviews.llvm.org/D58344

Files:
  include/clang/Basic/X86Target.def
  lib/Basic/Targets/X86.cpp
  test/CodeGen/target-builtin-noerror.c
  test/Driver/x86-march.c
  test/Frontend/x86-target-cpu.c
  test/Misc/target-invalid-cpu-note.c
  test/Preprocessor/predefined-arch-macros.c

Index: test/Preprocessor/predefined-arch-macros.c
===
--- test/Preprocessor/predefined-arch-macros.c
+++ test/Preprocessor/predefined-arch-macros.c
@@ -2676,6 +2676,100 @@
 // CHECK_ZNVER1_M64: #define __znver1 1
 // CHECK_ZNVER1_M64: #define __znver1__ 1
 
+// RUN: %clang -march=znver2 -m32 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_ZNVER2_M32
+// CHECK_ZNVER2_M32-NOT: #define __3dNOW_A__ 1
+// CHECK_ZNVER2_M32-NOT: #define __3dNOW__ 1
+// CHECK_ZNVER2_M32: #define __ADX__ 1
+// CHECK_ZNVER2_M32: #define __AES__ 1
+// CHECK_ZNVER2_M32: #define __AVX2__ 1
+// CHECK_ZNVER2_M32: #define __AVX__ 1
+// CHECK_ZNVER2_M32: #define __BMI2__ 1
+// CHECK_ZNVER2_M32: #define __BMI__ 1
+// CHECK_ZNVER2_M32: #define __CLFLUSHOPT__ 1
+// CHECK_ZNVER2_M32: #define __CLWB__ 1
+// CHECK_ZNVER2_M32: #define __CLZERO__ 1
+// CHECK_ZNVER2_M32: #define __F16C__ 1
+// CHECK_ZNVER2_M32: #define __FMA__ 1
+// CHECK_ZNVER2_M32: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M32: #define __LZCNT__ 1
+// CHECK_ZNVER2_M32: #define __MMX__ 1
+// CHECK_ZNVER2_M32: #define __PCLMUL__ 1
+// CHECK_ZNVER2_M32: #define __POPCNT__ 1
+// CHECK_ZNVER2_M32: #define __PRFCHW__ 1
+// CHECK_ZNVER2_M32: #define __RDPID__ 1
+// CHECK_ZNVER2_M32: #define __RDRND__ 1
+// CHECK_ZNVER2_M32: #define __RDSEED__ 1
+// CHECK_ZNVER2_M32: #define __SHA__ 1
+// CHECK_ZNVER2_M32: #define __SSE2_MATH__ 1
+// CHECK_ZNVER2_M32: #define __SSE2__ 1
+// CHECK_ZNVER2_M32: #define __SSE3__ 1
+// CHECK_ZNVER2_M32: #define __SSE4A__ 1
+// CHECK_ZNVER2_M32: #define __SSE4_1__ 1
+// CHECK_ZNVER2_M32: #define __SSE4_2__ 1
+// CHECK_ZNVER2_M32: #define __SSE_MATH__ 1
+// CHECK_ZNVER2_M32: #define __SSE__ 1
+// CHECK_ZNVER2_M32: #define __SSSE3__ 1
+// CHECK_ZNVER2_M32: #define __WBNOINVD__ 1
+// CHECK_ZNVER2_M32: #define __XSAVEC__ 1
+// CHECK_ZNVER2_M32: #define __XSAVEOPT__ 1
+// CHECK_ZNVER2_M32: #define __XSAVES__ 1
+// CHECK_ZNVER2_M32: #define __XSAVE__ 1
+// CHECK_ZNVER2_M32: #define __i386 1
+// CHECK_ZNVER2_M32: #define __i386__ 1
+// CHECK_ZNVER2_M32: #define __tune_znver2__ 1
+// CHECK_ZNVER2_M32: #define __znver2 1
+// CHECK_ZNVER2_M32: #define __znver2__ 1
+
+// RUN: %clang -march=znver2 -m64 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_ZNVER2_M64
+// CHECK_ZNVER2_M64-NOT: #define __3dNOW_A__ 1
+// CHECK_ZNVER2_M64-NOT: #define __3dNOW__ 1
+// CHECK_ZNVER2_M64: #define __ADX__ 1
+// CHECK_ZNVER2_M64: #define __AES__ 1
+// CHECK_ZNVER2_M64: #define __AVX2__ 1
+// CHECK_ZNVER2_M64: #define __AVX__ 1
+// CHECK_ZNVER2_M64: #define __BMI2__ 1
+// CHECK_ZNVER2_M64: #define __BMI__ 1
+// CHECK_ZNVER2_M64: #define __CLFLUSHOPT__ 1
+// CHECK_ZNVER2_M64: #define __CLWB__ 1
+// CHECK_ZNVER2_M64: #define __CLZERO__ 1
+// CHECK_ZNVER2_M64: #define __F16C__ 1
+// CHECK_ZNVER2_M64: #define __FMA__ 1
+// CHECK_ZNVER2_M64: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M64: #define __LZCNT__ 1
+// CHECK_ZNVER2_M64: #define __MMX__ 1
+// CHECK_ZNVER2_M64: #define __PCLMUL__ 1
+// CHECK_ZNVER2_M64: #define __POPCNT__ 1
+// CHECK_ZNVER2_M64: #define __PRFCHW__ 1
+// CHECK_ZNVER2_M64: #define __RDPID__ 1
+// CHECK_ZNVER2_M64: #define __RDRND__ 1
+// CHECK_ZNVER2_M64: #define __RDSEED__ 1
+// CHECK_ZNVER2_M64: #define __SHA__ 1
+// CHECK_ZNVER2_M64: #define __SSE2_MATH__ 1
+// CHECK_ZNVER2_M64: #define __SSE2__ 1
+// CHECK_ZNVER2_M64: #define __SSE3__ 1
+// CHECK_ZNVER2_M64: #define __SSE4A__ 1
+// CHECK_ZNVER2_M64: #define __SSE4_1__ 1
+// CHECK_ZNVER2_M64: #define __SSE4_2__ 1
+// CHECK_ZNVER2_M64: #define __SSE_MATH__ 1
+// CHECK_ZNVER2_M64: #define __SSE__ 1
+// CHECK_ZNVER2_M64: #define __SSSE3__ 1
+// CHECK_ZNVER2_M64: #define __WBNOINVD__ 1
+// CHECK_ZNVER2_M64: #define __XSAVEC__ 1
+// CHECK_ZNVER2_M64: #define __XSAVEOPT__ 1
+// CHECK_ZNVER2_M64: #define __XSAVES__ 1
+// CHECK_ZNVER2_M64: #define __XSAVE__ 1
+// CHECK_ZNVER2_M64: #define __amd64 1
+// CHECK_ZNVER2_M64: #define __amd64__ 1
+// CHECK_ZNVER2_M64: #define __tune_znver2__ 1
+// CHECK_ZNVER2_M64: #define __x86_64 1
+// CHECK_ZNVER2_M64: #define __x86_64__ 1
+// CHECK_ZNVER2_M64: #define __znver2 1
+// CHECK_ZNVER2_M64: #define __znver2__ 1
+
 // End X86/GCC/Linux tests --
 
 // Begin PPC/GCC/Linux tests 
Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c

r354351 - Remove extraneous space in MSVC-style diagnostic output

2019-02-19 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Tue Feb 19 08:58:25 2019
New Revision: 354351

URL: http://llvm.org/viewvc/llvm-project?rev=354351=rev
Log:
Remove extraneous space in MSVC-style diagnostic output

There was an extra space between the file location and the diagnostic
message:

  /tmp/a.c(1,12):  warning: unused parameter 'unused'

the tests didn't catch this due to FileCheck not running in --strict-whitespace 
mode.

Reported by Marco: 
http://lists.llvm.org/pipermail/cfe-dev/2019-February/061326.html

Differential revision: https://reviews.llvm.org/D58377

Modified:
cfe/trunk/lib/Frontend/TextDiagnostic.cpp
cfe/trunk/test/Misc/diag-format.c

Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=354351=354350=354351=diff
==
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Tue Feb 19 08:58:25 2019
@@ -837,7 +837,7 @@ void TextDiagnostic::emitDiagnosticLoc(F
 if (LangOpts.MSCompatibilityVersion &&
 !LangOpts.isCompatibleWithMSVC(LangOptions::MSVC2015))
   OS << ' ';
-OS << ": ";
+OS << ':';
 break;
   }
 

Modified: cfe/trunk/test/Misc/diag-format.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-format.c?rev=354351=354350=354351=diff
==
--- cfe/trunk/test/Misc/diag-format.c (original)
+++ cfe/trunk/test/Misc/diag-format.c Tue Feb 19 08:58:25 2019
@@ -1,30 +1,30 @@
-// RUN: %clang -fsyntax-only  %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
-// RUN: %clang -fsyntax-only -fdiagnostics-format=clang %s 2>&1 | FileCheck %s 
-check-prefix=DEFAULT
-// RUN: %clang -fsyntax-only -fdiagnostics-format=clang -target 
x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang -fsyntax-only  %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=DEFAULT
+// RUN: %clang -fsyntax-only -fdiagnostics-format=clang %s 2>&1 | FileCheck %s 
--strict-whitespace -check-prefix=DEFAULT
+// RUN: %clang -fsyntax-only -fdiagnostics-format=clang -target 
x86_64-pc-win32 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=DEFAULT
 //
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300  %s 
2>&1 | FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00  %s 2>&1 | FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1800 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2013
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 
%s 2>&1 | FileCheck %s -check-prefix=MSVC
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1900 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2015
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00 -target x86_64-pc-win32 -fshow-column %s 2>&1 
| FileCheck %s -check-prefix=MSVC2010
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1800 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2013
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 
-fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC
-// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1900 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
-check-prefix=MSVC2015
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300  %s 
2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00  %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 %s 2>&1 | FileCheck %s --strict-whitespace 
-check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc 
-fms-compatibility-version=13.00 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s 
--strict-whitespace -check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1300 
-target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s 
--strict-whitespace -check-prefix=MSVC2010
+// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1800 
-target 

[PATCH] D58387: [clangd] Add an option in the code to not display number of fixes

2019-02-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL354349: [clangd] Add an option in the code to not display 
number of fixes (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58387?vs=187377=187383#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58387

Files:
  clang-tools-extra/trunk/clangd/Diagnostics.cpp
  clang-tools-extra/trunk/clangd/Diagnostics.h


Index: clang-tools-extra/trunk/clangd/Diagnostics.cpp
===
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp
@@ -161,11 +161,11 @@
 ///
 /// dir1/dir2/dir3/../../dir4/header.h:12:23
 /// note: candidate function not viable: requires 3 arguments
-std::string mainMessage(const Diag ) {
+std::string mainMessage(const Diag , bool DisplayFixesCount) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << D.Message;
-  if (!D.Fixes.empty())
+  if (DisplayFixesCount && !D.Fixes.empty())
 OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)";
   for (auto  : D.Notes) {
 OS << "\n\n";
@@ -252,7 +252,7 @@
 
   {
 clangd::Diagnostic Main = FillBasicFields(D);
-Main.message = mainMessage(D);
+Main.message = mainMessage(D, Opts.DisplayFixesCount);
 if (Opts.EmbedFixesInDiagnostics) {
   Main.codeActions.emplace();
   for (const auto  : D.Fixes)
Index: clang-tools-extra/trunk/clangd/Diagnostics.h
===
--- clang-tools-extra/trunk/clangd/Diagnostics.h
+++ clang-tools-extra/trunk/clangd/Diagnostics.h
@@ -32,6 +32,10 @@
   /// stage during which the issue was produced, e.g. "Semantic Issue" or 
"Parse
   /// Issue".
   bool SendDiagnosticCategory = false;
+
+  /// If true, Clangd will add a number of available fixes to the diagnostic's
+  /// message.
+  bool DisplayFixesCount = true;
 };
 
 /// Contains basic information about a diagnostic.


Index: clang-tools-extra/trunk/clangd/Diagnostics.cpp
===
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp
@@ -161,11 +161,11 @@
 ///
 /// dir1/dir2/dir3/../../dir4/header.h:12:23
 /// note: candidate function not viable: requires 3 arguments
-std::string mainMessage(const Diag ) {
+std::string mainMessage(const Diag , bool DisplayFixesCount) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << D.Message;
-  if (!D.Fixes.empty())
+  if (DisplayFixesCount && !D.Fixes.empty())
 OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)";
   for (auto  : D.Notes) {
 OS << "\n\n";
@@ -252,7 +252,7 @@
 
   {
 clangd::Diagnostic Main = FillBasicFields(D);
-Main.message = mainMessage(D);
+Main.message = mainMessage(D, Opts.DisplayFixesCount);
 if (Opts.EmbedFixesInDiagnostics) {
   Main.codeActions.emplace();
   for (const auto  : D.Fixes)
Index: clang-tools-extra/trunk/clangd/Diagnostics.h
===
--- clang-tools-extra/trunk/clangd/Diagnostics.h
+++ clang-tools-extra/trunk/clangd/Diagnostics.h
@@ -32,6 +32,10 @@
   /// stage during which the issue was produced, e.g. "Semantic Issue" or "Parse
   /// Issue".
   bool SendDiagnosticCategory = false;
+
+  /// If true, Clangd will add a number of available fixes to the diagnostic's
+  /// message.
+  bool DisplayFixesCount = true;
 };
 
 /// Contains basic information about a diagnostic.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r354349 - [clangd] Add an option in the code to not display number of fixes

2019-02-19 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Feb 19 08:50:37 2019
New Revision: 354349

URL: http://llvm.org/viewvc/llvm-project?rev=354349=rev
Log:
[clangd] Add an option in the code to not display number of fixes

Summary:
Only to the APIs, which are used by our embedders.
We do not plan to add a user-facing option for this.

Reviewers: sammccall, ioeric

Reviewed By: sammccall

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/clangd/Diagnostics.h

Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=354349=354348=354349=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Tue Feb 19 08:50:37 2019
@@ -161,11 +161,11 @@ std::string capitalize(std::string Messa
 ///
 /// dir1/dir2/dir3/../../dir4/header.h:12:23
 /// note: candidate function not viable: requires 3 arguments
-std::string mainMessage(const Diag ) {
+std::string mainMessage(const Diag , bool DisplayFixesCount) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << D.Message;
-  if (!D.Fixes.empty())
+  if (DisplayFixesCount && !D.Fixes.empty())
 OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)";
   for (auto  : D.Notes) {
 OS << "\n\n";
@@ -252,7 +252,7 @@ void toLSPDiags(
 
   {
 clangd::Diagnostic Main = FillBasicFields(D);
-Main.message = mainMessage(D);
+Main.message = mainMessage(D, Opts.DisplayFixesCount);
 if (Opts.EmbedFixesInDiagnostics) {
   Main.codeActions.emplace();
   for (const auto  : D.Fixes)

Modified: clang-tools-extra/trunk/clangd/Diagnostics.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.h?rev=354349=354348=354349=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.h (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.h Tue Feb 19 08:50:37 2019
@@ -32,6 +32,10 @@ struct ClangdDiagnosticOptions {
   /// stage during which the issue was produced, e.g. "Semantic Issue" or 
"Parse
   /// Issue".
   bool SendDiagnosticCategory = false;
+
+  /// If true, Clangd will add a number of available fixes to the diagnostic's
+  /// message.
+  bool DisplayFixesCount = true;
 };
 
 /// Contains basic information about a diagnostic.


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


[PATCH] D58343: Enablement for AMD znver2 architecture - skeleton patch

2019-02-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I think you uploaded the clang patch into the llvm review?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58343



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


[PATCH] D58388: [OpenCL] Simplify LLVM IR generated for OpenCL blocks

2019-02-19 Thread Alexey Sotkin via Phabricator via cfe-commits
AlexeySotkin created this revision.
AlexeySotkin added reviewers: Anastasia, yaxunl, svenvh.
AlexeySotkin added a project: clang.

Emit direct call of block invoke functions when possible, i.e. in case the
block is not passed as a function argument.
Also doing some refactoring of `CodeGenFunction::EmitBlockCallExpr()`


Repository:
  rC Clang

https://reviews.llvm.org/D58388

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  test/CodeGenOpenCL/blocks.cl
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -312,9 +312,7 @@
   };
 
   // Uses global block literal [[BLG8]] and invoke function [[INVG8]].
-  // COMMON: [[r1:%.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* getelementptr inbounds (%struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), i32 0, i32 2)
-  // COMMON: [[r2:%.*]] = addrspacecast i8 addrspace(4)* [[r1]] to void (i8 addrspace(4)*)*
-  // COMMON: call spir_func void [[r2]](i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
+  // COMMON: call spir_func void @__device_side_enqueue_block_invoke_11(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
   block_A();
 
   // Emits global block literal [[BLG8]] and block kernel [[INVGK8]]. [[INVGK8]] calls [[INVG8]].
@@ -333,9 +331,7 @@
   unsigned size = get_kernel_work_group_size(block_A);
 
   // Uses global block literal [[BLG8]] and invoke function [[INVG8]]. Make sure no redundant block literal and invoke functions are emitted.
-  // COMMON: [[r1:%.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* getelementptr inbounds (%struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), i32 0, i32 2)
-  // COMMON: [[r2:%.*]] = addrspacecast i8 addrspace(4)* [[r1]] to void (i8 addrspace(4)*)*
-  // COMMON: call spir_func void [[r2]](i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
+  // COMMON: call spir_func void @__device_side_enqueue_block_invoke_11(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
   block_A();
 
   void (^block_C)(void) = ^{
Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -39,11 +39,8 @@
   // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast %struct.__opencl_block_literal_generic* %[[blk_ptr]] to %struct.__opencl_block_literal_generic addrspace(4)*
   // SPIR: store %struct.__opencl_block_literal_generic addrspace(4)* %[[blk_gen_ptr]], %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B:.*]],
   // SPIR: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic addrspace(4)*, %struct.__opencl_block_literal_generic addrspace(4)** %[[block_B]]
-  // SPIR: %[[invoke_addr:.*]] = getelementptr inbounds %struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]], i32 0, i32 2
   // SPIR: %[[blk_gen_ptr:.*]] = bitcast %struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]] to i8 addrspace(4)*
-  // SPIR: %[[invoke_func_ptr:.*]] = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* %[[invoke_addr]]
-  // SPIR: %[[invoke_func:.*]] = addrspacecast i8 addrspace(4)* %[[invoke_func_ptr]] to i32 (i8 addrspace(4)*)*
-  // SPIR: call {{.*}}i32 %[[invoke_func]](i8 addrspace(4)* %[[blk_gen_ptr]])
+  // SPIR: call {{.*}}i32 @__foo_block_invoke(i8 addrspace(4)* %[[blk_gen_ptr]])
   // AMDGCN: %[[block_invoke:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block:.*]], i32 0, i32 2
   // AMDGCN: store i8* bitcast (i32 (i8*)* @__foo_block_invoke to i8*), i8* addrspace(5)* %[[block_invoke]]
   // AMDGCN: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8*, i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]], i32 0, i32 3

[PATCH] D57660: [Sema] SequenceChecker: Handle references and members

2019-02-19 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno planned changes to this revision.
riccibruno added a comment.

This needs more work.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57660



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


[PATCH] D58346: [Sema] Change addr space diagnostics in casts to follow C++ style

2019-02-19 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia marked an inline comment as done.
Anastasia added inline comments.



Comment at: lib/Sema/SemaCast.cpp:2309
+auto DestPointeeTypeWithoutAS = Self.Context.removeAddrSpaceQualType(
+DestPointeeType.getCanonicalType());
+return Self.Context.hasSameType(SrcPointeeTypeWithoutAS,

Anastasia wrote:
> ebevhan wrote:
> > Maybe I'm mistaken, but won't getting the canonical type here drop 
> > qualifiers (like cv) in nested pointers? If so, an addrspace_cast might 
> > strip qualifiers by mistake.
> Yes, indeed I will need to extend this to nested pointers when we are ready. 
> But for now I can try to change this bit... however I am not sure it will 
> work w/o canonical types when we have typedef. I will try to create an 
> example and see.
I checked the canonical type does preserve the qualifiers correctly.

Here is the AST dump of the following C type `mytype const __generic*` where  
`typedef  __generic int* mytype;`.


```
PointerType 0x204d3b0 'const __generic mytype *'
`-QualType 0x204d369 'const __generic mytype' const __generic
  `-TypedefType 0x204d320 'mytype' sugar
|-Typedef 0x204d1b0 'mytype'
`-PointerType 0x204d170 '__generic int *'
  `-QualType 0x204d158 '__generic int' __generic
`-BuiltinType 0x2009750 'int'
```

and it's canonical representation in AST is:

```
PointerType 0x204d380 '__generic int *const __generic *'
`-QualType 0x204d349 '__generic int *const __generic' const __generic
  `-PointerType 0x204d170 '__generic int *'
`-QualType 0x204d158 '__generic int' __generic
  `-BuiltinType 0x2009750 'int'
```

So using canonical type will just simply handling of nested pointer chain by 
avoiding special casing typedefs. We won't loose any qualifiers.


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

https://reviews.llvm.org/D58346



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


[PATCH] D58387: [clangd] Add an option in the code to not display number of fixes

2019-02-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: sammccall, ioeric.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Only to the APIs, which are used by our embedders.
We do not plan to add a user-facing option for this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58387

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h


Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -32,6 +32,10 @@
   /// stage during which the issue was produced, e.g. "Semantic Issue" or 
"Parse
   /// Issue".
   bool SendDiagnosticCategory = false;
+
+  /// If true, Clangd will add a number of available fixes to the diagnostic's
+  /// message.
+  bool DisplayFixesCount = true;
 };
 
 /// Contains basic information about a diagnostic.
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -161,11 +161,11 @@
 ///
 /// dir1/dir2/dir3/../../dir4/header.h:12:23
 /// note: candidate function not viable: requires 3 arguments
-std::string mainMessage(const Diag ) {
+std::string mainMessage(const Diag , bool DisplayFixesCount) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << D.Message;
-  if (!D.Fixes.empty())
+  if (DisplayFixesCount && !D.Fixes.empty())
 OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)";
   for (auto  : D.Notes) {
 OS << "\n\n";
@@ -252,7 +252,7 @@
 
   {
 clangd::Diagnostic Main = FillBasicFields(D);
-Main.message = mainMessage(D);
+Main.message = mainMessage(D, Opts.SendDiagnosticCategory);
 if (Opts.EmbedFixesInDiagnostics) {
   Main.codeActions.emplace();
   for (const auto  : D.Fixes)


Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -32,6 +32,10 @@
   /// stage during which the issue was produced, e.g. "Semantic Issue" or "Parse
   /// Issue".
   bool SendDiagnosticCategory = false;
+
+  /// If true, Clangd will add a number of available fixes to the diagnostic's
+  /// message.
+  bool DisplayFixesCount = true;
 };
 
 /// Contains basic information about a diagnostic.
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -161,11 +161,11 @@
 ///
 /// dir1/dir2/dir3/../../dir4/header.h:12:23
 /// note: candidate function not viable: requires 3 arguments
-std::string mainMessage(const Diag ) {
+std::string mainMessage(const Diag , bool DisplayFixesCount) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << D.Message;
-  if (!D.Fixes.empty())
+  if (DisplayFixesCount && !D.Fixes.empty())
 OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)";
   for (auto  : D.Notes) {
 OS << "\n\n";
@@ -252,7 +252,7 @@
 
   {
 clangd::Diagnostic Main = FillBasicFields(D);
-Main.message = mainMessage(D);
+Main.message = mainMessage(D, Opts.SendDiagnosticCategory);
 if (Opts.EmbedFixesInDiagnostics) {
   Main.codeActions.emplace();
   for (const auto  : D.Fixes)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58341: [clangd] Index UsingDecls

2019-02-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 187376.
kadircet marked an inline comment as done.
kadircet added a comment.

- Revert last change


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58341

Files:
  unittests/clangd/SymbolCollectorTests.cpp
  unittests/clangd/SymbolInfoTests.cpp


Index: unittests/clangd/SymbolInfoTests.cpp
===
--- unittests/clangd/SymbolInfoTests.cpp
+++ unittests/clangd/SymbolInfoTests.cpp
@@ -167,7 +167,8 @@
 )cpp",
   {CreateExpectedSymbolDetails("foo", "", "c:@F@foo#"),
CreateExpectedSymbolDetails("foo", "", "c:@F@foo#b#"),
-   CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#")}},
+   CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#"),
+   CreateExpectedSymbolDetails("foo", "bar::", 
"c:@N@bar@UD@foo")}},
   {
   R"cpp( // Multiple symbols returned - implicit conversion
   struct foo {};
Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -7,8 +7,12 @@
 
//===--===//
 
 #include "Annotations.h"
+#include "ClangdServer.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "index/Index.h"
+#include "index/MemIndex.h"
 #include "index/SymbolCollector.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
@@ -50,6 +54,7 @@
 MATCHER_P(Snippet, S, "") {
   return (arg.Name + arg.CompletionSnippetSuffix).str() == S;
 }
+MATCHER_P(CompletionQName, Name, "") { return (arg.Scope + arg.Name) == Name; }
 MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
 MATCHER_P(DeclURI, P, "") {
   return StringRef(arg.CanonicalDeclaration.FileURI) == P;
@@ -325,9 +330,6 @@
 // Namespace alias
 namespace baz = bar;
 
-// FIXME: using declaration is not supported as the IndexAction will ignore
-// implicit declarations (the implicit using shadow declaration) by 
default,
-// and there is no way to customize this behavior at the moment.
 using bar::v2;
 } // namespace foo
   )";
@@ -354,6 +356,7 @@
AllOf(QName("foo::int32_t"), ForCodeCompletion(true)),
AllOf(QName("foo::v1"), ForCodeCompletion(true)),
AllOf(QName("foo::bar::v2"), ForCodeCompletion(true)),
+   AllOf(QName("foo::v2"), ForCodeCompletion(true)),
AllOf(QName("foo::baz"), ForCodeCompletion(true))}));
 }
 
@@ -1118,6 +1121,16 @@
   AllOf(QName("Public"), Not(ImplementationDetail();
 }
 
+TEST_F(SymbolCollectorTest, UsingDecl) {
+  const char *Header = R"(
+  void foo();
+  namespace std {
+using ::foo;
+  })";
+  runSymbolCollector(Header, /**/ "");
+  EXPECT_THAT(Symbols, Contains(QName("std::foo")));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: unittests/clangd/SymbolInfoTests.cpp
===
--- unittests/clangd/SymbolInfoTests.cpp
+++ unittests/clangd/SymbolInfoTests.cpp
@@ -167,7 +167,8 @@
 )cpp",
   {CreateExpectedSymbolDetails("foo", "", "c:@F@foo#"),
CreateExpectedSymbolDetails("foo", "", "c:@F@foo#b#"),
-   CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#")}},
+   CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#"),
+   CreateExpectedSymbolDetails("foo", "bar::", "c:@N@bar@UD@foo")}},
   {
   R"cpp( // Multiple symbols returned - implicit conversion
   struct foo {};
Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -7,8 +7,12 @@
 //===--===//
 
 #include "Annotations.h"
+#include "ClangdServer.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "index/Index.h"
+#include "index/MemIndex.h"
 #include "index/SymbolCollector.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
@@ -50,6 +54,7 @@
 MATCHER_P(Snippet, S, "") {
   return (arg.Name + arg.CompletionSnippetSuffix).str() == S;
 }
+MATCHER_P(CompletionQName, Name, "") { return (arg.Scope + arg.Name) == Name; }
 MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
 MATCHER_P(DeclURI, P, "") {
   return StringRef(arg.CanonicalDeclaration.FileURI) == P;
@@ -325,9 +330,6 @@
 // Namespace alias
 namespace baz = bar;
 
-// FIXME: using declaration is not supported as the IndexAction will 

[PATCH] D58314: [Driver] Sync ARM behavior between clang-as and gas.

2019-02-19 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

My main concern is that this changes the default behaviour for 
arm-linux-gnueabi and arm-linux-gnueabihf targets. I've put some suggestions on 
what I think the behaviour should be.




Comment at: clang/lib/Driver/ToolChains/Arch/ARM.cpp:277
+  }
+  return "";
+}

I'm a bit worried that we've changed the default behaviour for gnueabi[hf] 
targets here. 
For example with:
```
.text
vmov.32 d13[1], r6 ; Needs VFPv2
vadd.i32 d0, d0, d0 ; Needs Neon
```
I get with --target=armv7a-linux (no environment, -mfloat-abi will disable 
floating point, and neon)
```
clang: warning: unknown platform, assuming -mfloat-abi=soft
neon.s:2:9: error: instruction requires: VFP2
vmov.32 d13[1],r6
^
neon.s:3:9: error: instruction requires: NEON
vadd.i32 d0, d0, d0
^
```
With the target=armv7a-linux-gnueabi armv7a-linux-gnueabihf or explicitly 
adding -mfloat-abi=softfp the integrated assembler will happily assemble it.
GNU needs -mfpu=neon to assemble the file:

```
arm-linux-gnueabihf-as -march=armv7-a neon.s 
neon.s: Assembler messages:
neon.s:2: Error: selected processor does not support ARM mode `vmov.32 
d13[1],r6'
neon.s:3: Error: selected processor does not support ARM mode `vadd.i32 
d0,d0,d0'
```
It is a similar story for armv8 and crypto.

I think we should have something like:
```
if (Triple.isLinux() && getARMSubArchVersionNumber(Triple) >= 8)
   return "crypto-neon-fp-armv8";
if (Triple.isAndroid() || Triple.isLinux() && 
getARMSubArchVersionNumber(Triple) >= 7)
return "neon";
return "";
```



Comment at: clang/lib/Driver/ToolChains/Arch/ARM.cpp:389
+std::string DefaultFPU = getDefaultFPUName(Triple);
+if (DefaultFPU != "") {
+  if (!llvm::ARM::getFPUFeatures(llvm::ARM::parseFPU(DefaultFPU), 
Features))

I'm wondering whether you need this bit of code anymore? In D53121 there needed 
to be a switch between vfpv3-d16 and neon based on Android version. With 
--target=armv7a-linux-android or --target=arm-linux-android -march=armv7a or 
any v7a -mcpu applicable to Android then you'll get feature Neon by default and 
won't need to do this? We could then move getDefaultFPUName out of ARM.cpp



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:692
+}
+if (!hasMOrWaMArg(Args, options::OPT_mfpu_EQ, "-mfpu=")) {
+std::string DefaultFPU = arm::getDefaultFPUName(Triple);

I think we'd not want to do this for -mfloat-abi=soft as this disables the FPU 
in the integrated assembler. It seems like -mfloat-abi has no effect at all on 
the gnu assembler, it will happily assemble neon instructions with 
-mfloat-abi=soft -mfpu=neon.
 



Comment at: clang/test/Driver/linux-as.c:3
 //
 // RUN: %clang -target arm-linux -### \
 // RUN:   -no-integrated-as -c %s 2>&1 \

the target arm-linux (effectively arm-linux-unknown) defaults to 
-mfloat-abi=soft which disables the FPU for the integrated assembler. While 
these test cases are not wrong, the number of v7a + linux targets without an 
FPU using entirely software floating point is likely to be very small. We 
should have some more that have arm-linux-gnueabi and arm-linux-gnueabihf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58314



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


[PATCH] D58293: [clang][Index] Enable indexing of Template Type Parameters behind a flag

2019-02-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: lib/Index/IndexingContext.cpp:51
+
 bool IndexingContext::handleDecl(const Decl *D,
  SymbolRoleSet Roles,

ilya-biryukov wrote:
> kadircet wrote:
> > ilya-biryukov wrote:
> > > Do we call `handleDecl` for template parameters now too?
> > No we don't. I believe having the decl itself is not that useful for a 
> > template parameter without a reference to it. We only call handlereference.
> I'm probably call both just for the sake of symmetry.
> How does `IndexParametersInDeclarations` behaves? When set to true will it 
> call both `handleDecl` and `handleReference`?
> I'd argue we should do the same for template parameters.
yes it calls both, OK than adding also the `handleDecl`


Repository:
  rC Clang

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

https://reviews.llvm.org/D58293



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


[PATCH] D58294: [clangd] Enable indexing of template type parameters

2019-02-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 187371.
kadircet marked an inline comment as done.
kadircet added a comment.

- Option's name has changed


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58294

Files:
  clangd/XRefs.cpp
  unittests/clangd/SymbolInfoTests.cpp
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -285,11 +285,15 @@
 }
   )cpp",
 
-  /* FIXME: clangIndex doesn't handle template type parameters
   R"cpp(// Template type parameter
-template <[[typename T]]>
+template 
 void foo() { ^T t; }
-  )cpp", */
+  )cpp",
+
+  R"cpp(// Template template type parameter
+template  class [[T]]>
+void foo() { ^T t; }
+  )cpp",
 
   R"cpp(// Namespace
 namespace $decl[[ns]] {
Index: unittests/clangd/SymbolInfoTests.cpp
===
--- unittests/clangd/SymbolInfoTests.cpp
+++ unittests/clangd/SymbolInfoTests.cpp
@@ -213,14 +213,14 @@
 T^T t;
   };
 )cpp",
-  {/* not implemented */}},
+  {CreateExpectedSymbolDetails("TT", "bar::", "c:TestTU.cpp@65")}},
   {
   R"cpp( // Template parameter reference - type param
   template struct bar {
 int a = N^N;
   };
 )cpp",
-  {/* not implemented */}},
+  {CreateExpectedSymbolDetails("NN", "bar::", "c:TestTU.cpp@65")}},
   {
   R"cpp( // Class member reference - objec
   struct foo {
Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -39,7 +39,8 @@
   if (const auto *FD = dyn_cast(D))
 return FD->getDefinition();
   // Only a single declaration is allowed.
-  if (isa(D)) // except cases above
+  if (isa(D) || isa(D) ||
+  isa(D)) // except cases above
 return D;
   // Multiple definitions are allowed.
   return nullptr; // except cases above
@@ -243,6 +244,7 @@
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
   IndexOpts.IndexParametersInDeclarations = true;
+  IndexOpts.IndexTemplateParameters = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
  AST.getLocalTopLevelDecls(), DeclMacrosFinder, IndexOpts);
 
@@ -441,6 +443,7 @@
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
   IndexOpts.IndexParametersInDeclarations = true;
+  IndexOpts.IndexTemplateParameters = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
  AST.getLocalTopLevelDecls(), RefFinder, IndexOpts);
   return std::move(RefFinder).take();


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -285,11 +285,15 @@
 }
   )cpp",
 
-  /* FIXME: clangIndex doesn't handle template type parameters
   R"cpp(// Template type parameter
-template <[[typename T]]>
+template 
 void foo() { ^T t; }
-  )cpp", */
+  )cpp",
+
+  R"cpp(// Template template type parameter
+template  class [[T]]>
+void foo() { ^T t; }
+  )cpp",
 
   R"cpp(// Namespace
 namespace $decl[[ns]] {
Index: unittests/clangd/SymbolInfoTests.cpp
===
--- unittests/clangd/SymbolInfoTests.cpp
+++ unittests/clangd/SymbolInfoTests.cpp
@@ -213,14 +213,14 @@
 T^T t;
   };
 )cpp",
-  {/* not implemented */}},
+  {CreateExpectedSymbolDetails("TT", "bar::", "c:TestTU.cpp@65")}},
   {
   R"cpp( // Template parameter reference - type param
   template struct bar {
 int a = N^N;
   };
 )cpp",
-  {/* not implemented */}},
+  {CreateExpectedSymbolDetails("NN", "bar::", "c:TestTU.cpp@65")}},
   {
   R"cpp( // Class member reference - objec
   struct foo {
Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -39,7 +39,8 @@
   if (const auto *FD = dyn_cast(D))
 return FD->getDefinition();
   // Only a single declaration is allowed.
-  if (isa(D)) // except cases above
+  if (isa(D) || isa(D) ||
+  isa(D)) // except cases above
 return D;
   // Multiple definitions are allowed.
   return nullptr; // except cases above
@@ -243,6 +244,7 @@
   index::IndexingOptions::SystemSymbolFilterKind::All;
   

[PATCH] D58293: [clang][Index] Enable indexing of Template Type Parameters behind a flag

2019-02-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 187370.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Change options name
- Also index decls


Repository:
  rC Clang

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

https://reviews.llvm.org/D58293

Files:
  include/clang/Index/IndexingAction.h
  lib/Index/IndexDecl.cpp
  lib/Index/IndexSymbol.cpp
  lib/Index/IndexTypeSourceInfo.cpp
  lib/Index/IndexingContext.cpp
  lib/Index/IndexingContext.h
  unittests/Index/IndexTests.cpp

Index: unittests/Index/IndexTests.cpp
===
--- unittests/Index/IndexTests.cpp
+++ unittests/Index/IndexTests.cpp
@@ -93,6 +93,7 @@
   IndexingOptions Opts;
 };
 
+using testing::AllOf;
 using testing::Contains;
 using testing::Not;
 using testing::UnorderedElementsAre;
@@ -134,6 +135,29 @@
   EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar";
 }
 
+TEST(IndexTest, IndexTypeParmDecls) {
+  std::string Code = R"cpp(
+template  class C, typename NoRef>
+struct Foo {
+  T t = I;
+  C x;
+};
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, AllOf(Not(Contains(QName("Foo::T"))),
+Not(Contains(QName("Foo::I"))),
+Not(Contains(QName("Foo::C");
+
+  Opts.IndexTemplateParameters = true;
+  Index->Symbols.clear();
+  tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  AllOf(Contains(QName("Foo::T")), Contains(QName("Foo::I")),
+Contains(QName("Foo::C")), Contains(QName("Foo::NoRef";
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: lib/Index/IndexingContext.h
===
--- lib/Index/IndexingContext.h
+++ lib/Index/IndexingContext.h
@@ -63,6 +63,8 @@
 
   bool shouldIndexParametersInDeclarations() const;
 
+  bool shouldIndexTemplateParameters() const;
+
   static bool isTemplateImplicitInstantiation(const Decl *D);
 
   bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
Index: lib/Index/IndexingContext.cpp
===
--- lib/Index/IndexingContext.cpp
+++ lib/Index/IndexingContext.cpp
@@ -44,6 +44,10 @@
   return IndexOpts.IndexParametersInDeclarations;
 }
 
+bool IndexingContext::shouldIndexTemplateParameters() const {
+  return IndexOpts.IndexTemplateParameters;
+}
+
 bool IndexingContext::handleDecl(const Decl *D,
  SymbolRoleSet Roles,
  ArrayRef Relations) {
@@ -76,8 +80,11 @@
   if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalSymbol(D))
 return true;
 
-  if (isa(D) || isa(D))
+  if (!shouldIndexTemplateParameters() &&
+  (isa(D) || isa(D) ||
+   isa(D))) {
 return true;
+  }
 
   return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations,
   RefE, RefD, DC);
Index: lib/Index/IndexTypeSourceInfo.cpp
===
--- lib/Index/IndexTypeSourceInfo.cpp
+++ lib/Index/IndexTypeSourceInfo.cpp
@@ -45,6 +45,13 @@
   return false;\
   } while (0)
 
+  bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TTPL) {
+SourceLocation Loc = TTPL.getNameLoc();
+TemplateTypeParmDecl *TTPD = TTPL.getDecl();
+return IndexCtx.handleReference(TTPD, Loc, Parent, ParentDC,
+SymbolRoleSet());
+  }
+
   bool VisitTypedefTypeLoc(TypedefTypeLoc TL) {
 SourceLocation Loc = TL.getNameLoc();
 TypedefNameDecl *ND = TL.getTypedefNameDecl();
Index: lib/Index/IndexSymbol.cpp
===
--- lib/Index/IndexSymbol.cpp
+++ lib/Index/IndexSymbol.cpp
@@ -55,9 +55,6 @@
   if (isa(D))
 return true;
 
-  if (isa(D))
-return true;
-
   if (isa(D))
 return true;
 
Index: lib/Index/IndexDecl.cpp
===
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -675,13 +675,19 @@
 if (const auto *TTP = dyn_cast(TP)) {
   if (TTP->hasDefaultArgument())
 IndexCtx.indexTypeSourceInfo(TTP->getDefaultArgumentInfo(), Parent);
+  if(IndexCtx.shouldIndexTemplateParameters())
+IndexCtx.handleDecl(TTP);
 } else if (const auto *NTTP = dyn_cast(TP)) {
   if (NTTP->hasDefaultArgument())
 IndexCtx.indexBody(NTTP->getDefaultArgument(), Parent);
+  if (IndexCtx.shouldIndexTemplateParameters())
+IndexCtx.handleDecl(NTTP);
 } else if (const auto *TTPD = dyn_cast(TP)) {
   if (TTPD->hasDefaultArgument())
 

[PATCH] D58341: [clangd] Index UsingDecls

2019-02-19 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 from my side, with a few NITs.
But let's wait for an LGTM from Haojian too, to make sure his concerns are 
addressed.




Comment at: unittests/clangd/SymbolCollectorTests.cpp:1126
+TEST_F(SymbolCollectorTest, UsingDecl) {
+  auto completions = [](const Annotations , SymbolSlab SS) {
+class IgnoreDiagnostics : public DiagnosticsConsumer {

That's definitely too much setup for such a simple test.
I thought it's possible to wire up a real index in the completion tests, but it 
seems that's not the case. So let's not bother to run an actual completion 
here, ignore my previous comment about adding a test.




Comment at: unittests/clangd/SymbolCollectorTests.cpp:1163
+  Contains(AllOf(
+  ReturnType(/*Currently using decls does not export target info*/ ""),
+  CompletionQName("std::foo";

a typo NIT: s/does not/do not
also, maybe use "type info" or "signature" instead of "target info"?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58341



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


[PATCH] D58341: [clangd] Index UsingDecls

2019-02-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 187367.
kadircet added a comment.

- Add tests for code completion


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58341

Files:
  unittests/clangd/SymbolCollectorTests.cpp
  unittests/clangd/SymbolInfoTests.cpp

Index: unittests/clangd/SymbolInfoTests.cpp
===
--- unittests/clangd/SymbolInfoTests.cpp
+++ unittests/clangd/SymbolInfoTests.cpp
@@ -167,7 +167,8 @@
 )cpp",
   {CreateExpectedSymbolDetails("foo", "", "c:@F@foo#"),
CreateExpectedSymbolDetails("foo", "", "c:@F@foo#b#"),
-   CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#")}},
+   CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#"),
+   CreateExpectedSymbolDetails("foo", "bar::", "c:@N@bar@UD@foo")}},
   {
   R"cpp( // Multiple symbols returned - implicit conversion
   struct foo {};
Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -7,8 +7,13 @@
 //===--===//
 
 #include "Annotations.h"
+#include "ClangdServer.h"
+#include "CodeComplete.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "index/Index.h"
+#include "index/MemIndex.h"
 #include "index/SymbolCollector.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
@@ -50,6 +55,7 @@
 MATCHER_P(Snippet, S, "") {
   return (arg.Name + arg.CompletionSnippetSuffix).str() == S;
 }
+MATCHER_P(CompletionQName, Name, "") { return (arg.Scope + arg.Name) == Name; }
 MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
 MATCHER_P(DeclURI, P, "") {
   return StringRef(arg.CanonicalDeclaration.FileURI) == P;
@@ -325,9 +331,6 @@
 // Namespace alias
 namespace baz = bar;
 
-// FIXME: using declaration is not supported as the IndexAction will ignore
-// implicit declarations (the implicit using shadow declaration) by default,
-// and there is no way to customize this behavior at the moment.
 using bar::v2;
 } // namespace foo
   )";
@@ -354,6 +357,7 @@
AllOf(QName("foo::int32_t"), ForCodeCompletion(true)),
AllOf(QName("foo::v1"), ForCodeCompletion(true)),
AllOf(QName("foo::bar::v2"), ForCodeCompletion(true)),
+   AllOf(QName("foo::v2"), ForCodeCompletion(true)),
AllOf(QName("foo::baz"), ForCodeCompletion(true))}));
 }
 
@@ -1118,6 +1122,48 @@
   AllOf(QName("Public"), Not(ImplementationDetail();
 }
 
+TEST_F(SymbolCollectorTest, UsingDecl) {
+  auto completions = [](const Annotations , SymbolSlab SS) {
+class IgnoreDiagnostics : public DiagnosticsConsumer {
+  void onDiagnosticsReady(PathRef File,
+  std::vector Diagnostics) override {}
+};
+
+MockFSProvider FS;
+MockCompilationDatabase CDB;
+IgnoreDiagnostics DiagConsumer;
+ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+std::unique_ptr OverrideIndex =
+MemIndex::build(std::move(SS), {});
+clangd::CodeCompleteOptions Opts;
+Opts.Index = OverrideIndex.get();
+
+auto File = testPath("foo.cpp");
+runAddDocument(Server, File, Test.code());
+auto CompletionList =
+llvm::cantFail(runCodeComplete(Server, File, Test.point(), Opts));
+return CompletionList;
+  };
+
+  const Annotations Header(R"(
+  void foo();
+  namespace std {
+using ::foo;
+  }
+  void bar() {
+(void)std::^foo;
+  })");
+  runSymbolCollector(Header.code(), /**/ "");
+  EXPECT_THAT(Symbols, Contains(QName("std::foo")));
+
+  const auto Results = completions(Header, std::move(Symbols));
+  EXPECT_THAT(
+  Results.Completions,
+  Contains(AllOf(
+  ReturnType(/*Currently using decls does not export target info*/ ""),
+  CompletionQName("std::foo";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58277: [OpenCL] Change type of block pointer for OpenCL

2019-02-19 Thread Alexey Bader via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL354337: [OpenCL] Change type of block pointer for OpenCL 
(authored by bader, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58277?vs=186988=187363#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58277

Files:
  cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
  cfe/trunk/test/CodeGenOpenCL/blocks.cl
  cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
@@ -635,7 +635,9 @@
 
   case Type::BlockPointer: {
 const QualType FTy = cast(Ty)->getPointeeType();
-llvm::Type *PointeeType = ConvertTypeForMem(FTy);
+llvm::Type *PointeeType = CGM.getLangOpts().OpenCL
+  ? CGM.getGenericBlockLiteralType()
+  : ConvertTypeForMem(FTy);
 unsigned AS = Context.getTargetAddressSpace(FTy);
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;
Index: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -11,7 +11,7 @@
 
 // For a block global variable, first emit the block literal as a global variable, then emit the block variable itself.
 // COMMON: [[BL_GLOBAL:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* [[INV_G:@[^ ]+]] to i8*) to i8 addrspace(4)*) }
-// COMMON: @block_G =  addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BL_GLOBAL]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
+// COMMON: @block_G = addrspace(1) constant %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BL_GLOBAL]] to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*)
 
 // For anonymous blocks without captures, emit block literals as global variable.
 // COMMON: [[BLG1:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
@@ -77,9 +77,9 @@
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // COMMON: store i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* [[INVL1:@__device_side_enqueue_block_invoke[^ ]*]] to i8*) to i8 addrspace(4)*), i8 addrspace(4)** %block.invoke
-  // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to void ()*
-  // B64: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32 addrspace(1)*, i32 }>* %block to void ()*
-  // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* [[BL]] to i8 addrspace(4)*
+  // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to %struct.__opencl_block_literal_generic*
+  // B64: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32 addrspace(1)*, i32 }>* %block to %struct.__opencl_block_literal_generic*
+  // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast %struct.__opencl_block_literal_generic* [[BL]] to i8 addrspace(4)*
   // COMMON-LABEL: call i32 @__enqueue_kernel_basic(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVLK1:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
@@ -95,8 +95,8 @@
   // COMMON: [[WAIT_EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %event_wait_list to %opencl.clk_event_t{{.*}}* addrspace(4)*
   // COMMON: [[EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %clk_event to %opencl.clk_event_t{{.*}}* addrspace(4)*
   // COMMON: store i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* [[INVL2:@__device_side_enqueue_block_invoke[^ ]*]] to i8*) to i8 addrspace(4)*), i8 addrspace(4)** %block.invoke
-  // COMMON: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, 

r354337 - [OpenCL] Change type of block pointer for OpenCL

2019-02-19 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Feb 19 07:19:06 2019
New Revision: 354337

URL: http://llvm.org/viewvc/llvm-project?rev=354337=rev
Log:
[OpenCL] Change type of block pointer for OpenCL

Summary:

For some reason OpenCL blocks in LLVM IR are represented as function pointers.
These pointers do not point to any real function and never get called. Actually
they point to some structure, which in turn contains pointer to the real block
invoke function.
This patch changes represntation of OpenCL blocks in LLVM IR from function
pointers to pointers to `%struct.__block_literal_generic`.
Such representation allows to avoid unnecessary bitcasts and simplifies
further processing (e.g. translation to SPIR-V ) of the module for targets
which do not support function pointers.

Patch by: Alexey Sotkin.

Reviewers: Anastasia, yaxunl, svenvh

Reviewed By: Anastasia

Subscribers: alexbatashev, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/test/CodeGenOpenCL/blocks.cl
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=354337=354336=354337=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Tue Feb 19 07:19:06 2019
@@ -635,7 +635,9 @@ llvm::Type *CodeGenTypes::ConvertType(Qu
 
   case Type::BlockPointer: {
 const QualType FTy = cast(Ty)->getPointeeType();
-llvm::Type *PointeeType = ConvertTypeForMem(FTy);
+llvm::Type *PointeeType = CGM.getLangOpts().OpenCL
+  ? CGM.getGenericBlockLiteralType()
+  : ConvertTypeForMem(FTy);
 unsigned AS = Context.getTargetAddressSpace(FTy);
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;

Modified: cfe/trunk/test/CodeGenOpenCL/blocks.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/blocks.cl?rev=354337=354336=354337=diff
==
--- cfe/trunk/test/CodeGenOpenCL/blocks.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/blocks.cl Tue Feb 19 07:19:06 2019
@@ -35,11 +35,10 @@ void foo(){
   // SPIR: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8 
addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block]], i32 
0, i32 3
   // SPIR: %[[i_value:.*]] = load i32, i32* %i
   // SPIR: store i32 %[[i_value]], i32* %[[block_captured]],
-  // SPIR: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 }>* 
%[[block]] to i32 ()*
-  // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast i32 ()* %[[blk_ptr]] to i32 () 
addrspace(4)*
-  // SPIR: store i32 () addrspace(4)* %[[blk_gen_ptr]], i32 () addrspace(4)** 
%[[block_B:.*]],
-  // SPIR: %[[blk_gen_ptr:.*]] = load i32 () addrspace(4)*, i32 () 
addrspace(4)** %[[block_B]]
-  // SPIR: %[[block_literal:.*]] = bitcast i32 () addrspace(4)* 
%[[blk_gen_ptr]] to %struct.__opencl_block_literal_generic addrspace(4)*
+  // SPIR: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 }>* 
%[[block]] to %struct.__opencl_block_literal_generic*
+  // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast 
%struct.__opencl_block_literal_generic* %[[blk_ptr]] to 
%struct.__opencl_block_literal_generic addrspace(4)*
+  // SPIR: store %struct.__opencl_block_literal_generic addrspace(4)* 
%[[blk_gen_ptr]], %struct.__opencl_block_literal_generic addrspace(4)** 
%[[block_B:.*]],
+  // SPIR: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic 
addrspace(4)*, %struct.__opencl_block_literal_generic addrspace(4)** 
%[[block_B]]
   // SPIR: %[[invoke_addr:.*]] = getelementptr inbounds 
%struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic 
addrspace(4)* %[[block_literal]], i32 0, i32 2
   // SPIR: %[[blk_gen_ptr:.*]] = bitcast 
%struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]] to i8 
addrspace(4)*
   // SPIR: %[[invoke_func_ptr:.*]] = load i8 addrspace(4)*, i8 addrspace(4)* 
addrspace(4)* %[[invoke_addr]]
@@ -50,11 +49,10 @@ void foo(){
   // AMDGCN: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8*, 
i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]], i32 0, i32 3
   // AMDGCN: %[[i_value:.*]] = load i32, i32 addrspace(5)* %i
   // AMDGCN: store i32 %[[i_value]], i32 addrspace(5)* %[[block_captured]],
-  // AMDGCN: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8*, i32 }> addrspace(5)* 
%[[block]] to i32 () addrspace(5)*
-  // AMDGCN: %[[blk_gen_ptr:.*]] = addrspacecast i32 () addrspace(5)* 
%[[blk_ptr]] to i32 ()*
-  // AMDGCN: store i32 ()* %[[blk_gen_ptr]], i32 ()* addrspace(5)* 
%[[block_B:.*]],
-  // AMDGCN: %[[blk_gen_ptr:.*]] = load i32 ()*, i32 ()* addrspace(5)* 
%[[block_B]]
-  // AMDGCN: %[[block_literal:.*]] = bitcast i32 

[PATCH] D57896: Variable names rule

2019-02-19 Thread Zachary Turner via Phabricator via cfe-commits
zturner requested changes to this revision.
zturner added a comment.
This revision now requires changes to proceed.

Since someone already accepted this, I suppose I should mark require changes to 
formalize my dissent


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57896



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


[PATCH] D57896: Variable names rule

2019-02-19 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

In D57896#1402194 , @lattner wrote:

> > Changed recommendation for acronyms from lower case to upper case, as 
> > suggested by several responses to the RFC.
>
> I haven't been following the discussion closely - why is this the preferred 
> direction?  I don't think that things like "Basicblock *bb" or "MachineInstr 
> *mi" will be confusing, and going towards a consistently leading lower case 
> letter seems simple and preferable.
>
> -Chris


I don’t think we should use this review as evidence of consensus.  For example, 
I’m going to be against any change that doesn’t bring us closer to LLDB’s style 
of `lower_case` simply on the grounds that a move which brings us farther away 
from global consistency is strictly worse than one which brings us closer, 
despite ones personal aesthetic preferences.

And so far, I don’t really see that addressed here (or in the thread)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57896



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


[PATCH] D58293: [clang][Index] Enable indexing of Template Type Parameters behind a flag

2019-02-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang/Index/IndexingAction.h:49
   bool IndexParametersInDeclarations = false;
+  bool IndexTemplateParmDecls = false;
 };

NIT: maybe rename to `IndexTemplateParameters`? The `ParmDecl` is a somewhat 
weird name that does not add much clarity.



Comment at: lib/Index/IndexingContext.cpp:51
+
 bool IndexingContext::handleDecl(const Decl *D,
  SymbolRoleSet Roles,

kadircet wrote:
> ilya-biryukov wrote:
> > Do we call `handleDecl` for template parameters now too?
> No we don't. I believe having the decl itself is not that useful for a 
> template parameter without a reference to it. We only call handlereference.
I'm probably call both just for the sake of symmetry.
How does `IndexParametersInDeclarations` behaves? When set to true will it call 
both `handleDecl` and `handleReference`?
I'd argue we should do the same for template parameters.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58293



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


[PATCH] D58377: Remove extraneous space in MSVC-style diagnostic output

2019-02-19 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

wht


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

https://reviews.llvm.org/D58377



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


Re: r354075 - [clang][FileManager] fillRealPathName even if we aren't opening the file

2019-02-19 Thread Nico Weber via cfe-commits
I didn't realize it just copied a string. I just saw a call to
"fillRealPathName" and the "RealPath" bit sounded slow. From clicking
around in http://llvm-cs.pcc.me.uk/tools/clang/lib/Basic/FileManager.cpp#361
it looks like it's not really computing a realpath (for symlinks). It still
does quite a bit of string processing if InterndFileName isn't absolute,
but that's probably fine. It's still the kind of thing I'd carefully
measure since getFile(openFile=false) was performance-sensitive in a
certain case iirc (I think when using pch files?)

On Mon, Feb 18, 2019 at 5:26 PM Jan Korous  wrote:

> Hi Nico,
>
> I didn't think it necessary as the change doesn't introduce any
> interaction with filesystem - it's just copying a string.
>
> Do you mean it causes a performance regression?
>
> Thanks.
>
> Jan
>
> On Feb 15, 2019, at 6:15 AM, Nico Weber  wrote:
>
> Did you do any performance testing to check if this slows down clang?
>
> On Thu, Feb 14, 2019 at 6:02 PM Jan Korous via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: jkorous
>> Date: Thu Feb 14 15:02:35 2019
>> New Revision: 354075
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=354075=rev
>> Log:
>> [clang][FileManager] fillRealPathName even if we aren't opening the file
>>
>> The pathname wasn't previously filled when the getFile() method was
>> called with openFile = false.
>> We are caching FileEntry-s in ParsedAST::Includes in clangd and this
>> caused the problem.
>>
>> This fixes an internal test failure in clangd -
>> ClangdTests.GoToInclude.All
>>
>> rdar://47536127
>>
>> Differential Revision: https://reviews.llvm.org/D58213
>>
>> Modified:
>> cfe/trunk/lib/Basic/FileManager.cpp
>> cfe/trunk/unittests/Basic/FileManagerTest.cpp
>>
>> Modified: cfe/trunk/lib/Basic/FileManager.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=354075=354074=354075=diff
>>
>> ==
>> --- cfe/trunk/lib/Basic/FileManager.cpp (original)
>> +++ cfe/trunk/lib/Basic/FileManager.cpp Thu Feb 14 15:02:35 2019
>> @@ -267,6 +267,9 @@ const FileEntry *FileManager::getFile(St
>>if (UFE.File) {
>>  if (auto PathName = UFE.File->getName())
>>fillRealPathName(, *PathName);
>> +  } else if (!openFile) {
>> +// We should still fill the path even if we aren't opening the file.
>> +fillRealPathName(, InterndFileName);
>>}
>>return 
>>  }
>>
>> Modified: cfe/trunk/unittests/Basic/FileManagerTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=354075=354074=354075=diff
>>
>> ==
>> --- cfe/trunk/unittests/Basic/FileManagerTest.cpp (original)
>> +++ cfe/trunk/unittests/Basic/FileManagerTest.cpp Thu Feb 14 15:02:35 2019
>> @@ -346,4 +346,18 @@ TEST_F(FileManagerTest, getVirtualFileFi
>>EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
>>  }
>>
>> +TEST_F(FileManagerTest, getFileDontOpenRealPath) {
>> +  auto statCache = llvm::make_unique();
>> +  statCache->InjectDirectory("/tmp/abc", 42);
>> +  SmallString<64> Path("/tmp/abc/foo.cpp");
>> +  statCache->InjectFile(Path.str().str().c_str(), 43);
>> +  manager.setStatCache(std::move(statCache));
>> +
>> +  const FileEntry *file = manager.getFile(Path, /*openFile=*/false);
>> +
>> +  ASSERT_TRUE(file != nullptr);
>> +
>> +  ASSERT_EQ(file->tryGetRealPathName(), Path);
>> +}
>> +
>>  } // anonymous namespace
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58320: [Darwin] Introduce a new flag, -flink-builtins-rt that forces linking of the builtins library.

2019-02-19 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

The implementation changes in the Darwin toolchain look fine to me, although 
with respect to the command line option I think Petr Hosek's message on cfe-dev 
is interesting:

> GCC implements -nolibc which could be used to achieve the same effect when 
> combined with -nostartfiles (and -nostdlib++ when compiling C++). I'd prefer 
> that approach not only because it improves compatibility with with GCC, but 
> also because it matches existing flag scheme which is subtractive rather than 
> additive (i.e. -nodefaultlibs, -nostdlib, -nostdlib++, -nostartfiles). Clang 
> already defines this flag but the only toolchain that currently supports it 
> is DragonFly.

Looking at https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html (quoted here 
for convenience)

> -nostartfiles
>  Do not use the standard system startup files when linking. The standard 
> system libraries are used normally, unless -nostdlib, -nolibc, or 
> -nodefaultlibs is used.
> -nolibc
>  Do not use the C library or system libraries tightly coupled with it when 
> linking. Still link with the startup files, libgcc or toolchain provided 
> language support libraries such as libgnat, libgfortran or libstdc++ unless 
> options preventing their inclusion are used as well. This typically removes 
> -lc from the link command line, as well as system libraries that normally go 
> with it and become meaningless when absence of a C library is assumed, for 
> example -lpthread or -lm in some configurations. This is intended for 
> bare-board targets when there is indeed no C library available.

It does seem like these options accomplish what -flink_builtins_rt do with the 
added advantage of being more portable with gcc. If they don't work for you it 
will be worth double checking with Petr.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58320



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


[PATCH] D58185: [clangd] Handle unresolved scope specifier when fixing includes.

2019-02-19 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL354330: [clangd] Handle unresolved scope specifier when 
fixing includes. (authored by ioeric, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58185

Files:
  clang-tools-extra/trunk/clangd/IncludeFixer.cpp
  clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp

Index: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/trunk/clangd/IncludeFixer.cpp
+++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp
@@ -19,6 +19,10 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Scope.h"
@@ -28,6 +32,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -172,6 +177,121 @@
   }
   return Fixes;
 }
+
+// Returns the identifiers qualified by an unresolved name. \p Loc is the
+// start location of the unresolved name. For the example below, this returns
+// "::X::Y" that is qualified by unresolved name "clangd":
+// clang::clangd::X::Y
+//~
+llvm::Optional qualifiedByUnresolved(const SourceManager ,
+  SourceLocation Loc,
+  const LangOptions ) {
+  std::string Result;
+
+  SourceLocation NextLoc = Loc;
+  while (auto CCTok = Lexer::findNextToken(NextLoc, SM, LangOpts)) {
+if (!CCTok->is(tok::coloncolon))
+  break;
+auto IDTok = Lexer::findNextToken(CCTok->getLocation(), SM, LangOpts);
+if (!IDTok || !IDTok->is(tok::raw_identifier))
+  break;
+Result.append(("::" + IDTok->getRawIdentifier()).str());
+NextLoc = IDTok->getLocation();
+  }
+  if (Result.empty())
+return llvm::None;
+  return Result;
+}
+
+// An unresolved name and its scope information that can be extracted cheaply.
+struct CheapUnresolvedName {
+  std::string Name;
+  // This is the part of what was typed that was resolved, and it's in its
+  // resolved form not its typed form (think `namespace clang { clangd::x }` -->
+  // `clang::clangd::`).
+  llvm::Optional ResolvedScope;
+
+  // Unresolved part of the scope. When the unresolved name is a specifier, we
+  // use the name that comes after it as the alternative name to resolve and use
+  // the specifier as the extra scope in the accessible scopes.
+  llvm::Optional UnresolvedScope;
+};
+
+// Extracts unresolved name and scope information around \p Unresolved.
+// FIXME: try to merge this with the scope-wrangling code in CodeComplete.
+llvm::Optional extractUnresolvedNameCheaply(
+const SourceManager , const DeclarationNameInfo ,
+CXXScopeSpec *SS, const LangOptions , bool UnresolvedIsSpecifier) {
+  bool Invalid = false;
+  llvm::StringRef Code = SM.getBufferData(
+  SM.getDecomposedLoc(Unresolved.getBeginLoc()).first, );
+  if (Invalid)
+return llvm::None;
+  CheapUnresolvedName Result;
+  Result.Name = Unresolved.getAsString();
+  if (SS && SS->isNotEmpty()) { // "::" or "ns::"
+if (auto *Nested = SS->getScopeRep()) {
+  if (Nested->getKind() == NestedNameSpecifier::Global)
+Result.ResolvedScope = "";
+  else if (const auto *NS = Nested->getAsNamespace()) {
+auto SpecifiedNS = printNamespaceScope(*NS);
+
+// Check the specifier spelled in the source.
+// If the resolved scope doesn't end with the spelled scope. The
+// resolved scope can come from a sema typo correction. For example,
+// sema assumes that "clangd::" is a typo of "clang::" and uses
+// "clang::" as the specified scope in:
+// namespace clang { clangd::X; }
+// In this case, we use the "typo" specifier as extra scope instead
+// of using the scope assumed by sema.
+auto B = SM.getFileOffset(SS->getBeginLoc());
+auto E = SM.getFileOffset(SS->getEndLoc());
+std::string Spelling = (Code.substr(B, E - B) + "::").str();
+if (llvm::StringRef(SpecifiedNS).endswith(Spelling))
+  Result.ResolvedScope = SpecifiedNS;
+else
+  Result.UnresolvedScope = Spelling;
+  } else if (const auto *ANS = Nested->getAsNamespaceAlias()) {
+Result.ResolvedScope = printNamespaceScope(*ANS->getNamespace());
+  } else {
+// We don't fix symbols in scopes that are not top-level e.g. class
+// members, as we 

[clang-tools-extra] r354330 - [clangd] Handle unresolved scope specifier when fixing includes.

2019-02-19 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Feb 19 06:32:22 2019
New Revision: 354330

URL: http://llvm.org/viewvc/llvm-project?rev=354330=rev
Log:
[clangd] Handle unresolved scope specifier when fixing includes.

Summary:
In the following examples, "clangd" is unresolved, and the fixer will try to fix
include for `clang::clangd`; however, clang::clangd::X is usually intended. So
when handling a qualifier that is unresolved, we change the unresolved name and
scopes so that the fixer will fix "clang::clangd::X" in the following example.
```
  namespace clang {
clangd::X
~~
  }
  // or
  clang::clangd::X
 ~~
```

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jdoerfert, 
cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/IncludeFixer.cpp
clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp

Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=354330=354329=354330=diff
==
--- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Tue Feb 19 06:32:22 2019
@@ -19,6 +19,10 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Scope.h"
@@ -28,6 +32,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -172,6 +177,121 @@ std::vector IncludeFixer::fixesForS
   }
   return Fixes;
 }
+
+// Returns the identifiers qualified by an unresolved name. \p Loc is the
+// start location of the unresolved name. For the example below, this returns
+// "::X::Y" that is qualified by unresolved name "clangd":
+// clang::clangd::X::Y
+//~
+llvm::Optional qualifiedByUnresolved(const SourceManager ,
+  SourceLocation Loc,
+  const LangOptions ) 
{
+  std::string Result;
+
+  SourceLocation NextLoc = Loc;
+  while (auto CCTok = Lexer::findNextToken(NextLoc, SM, LangOpts)) {
+if (!CCTok->is(tok::coloncolon))
+  break;
+auto IDTok = Lexer::findNextToken(CCTok->getLocation(), SM, LangOpts);
+if (!IDTok || !IDTok->is(tok::raw_identifier))
+  break;
+Result.append(("::" + IDTok->getRawIdentifier()).str());
+NextLoc = IDTok->getLocation();
+  }
+  if (Result.empty())
+return llvm::None;
+  return Result;
+}
+
+// An unresolved name and its scope information that can be extracted cheaply.
+struct CheapUnresolvedName {
+  std::string Name;
+  // This is the part of what was typed that was resolved, and it's in its
+  // resolved form not its typed form (think `namespace clang { clangd::x }` 
-->
+  // `clang::clangd::`).
+  llvm::Optional ResolvedScope;
+
+  // Unresolved part of the scope. When the unresolved name is a specifier, we
+  // use the name that comes after it as the alternative name to resolve and 
use
+  // the specifier as the extra scope in the accessible scopes.
+  llvm::Optional UnresolvedScope;
+};
+
+// Extracts unresolved name and scope information around \p Unresolved.
+// FIXME: try to merge this with the scope-wrangling code in CodeComplete.
+llvm::Optional extractUnresolvedNameCheaply(
+const SourceManager , const DeclarationNameInfo ,
+CXXScopeSpec *SS, const LangOptions , bool UnresolvedIsSpecifier) 
{
+  bool Invalid = false;
+  llvm::StringRef Code = SM.getBufferData(
+  SM.getDecomposedLoc(Unresolved.getBeginLoc()).first, );
+  if (Invalid)
+return llvm::None;
+  CheapUnresolvedName Result;
+  Result.Name = Unresolved.getAsString();
+  if (SS && SS->isNotEmpty()) { // "::" or "ns::"
+if (auto *Nested = SS->getScopeRep()) {
+  if (Nested->getKind() == NestedNameSpecifier::Global)
+Result.ResolvedScope = "";
+  else if (const auto *NS = Nested->getAsNamespace()) {
+auto SpecifiedNS = printNamespaceScope(*NS);
+
+// Check the specifier spelled in the source.
+// If the resolved scope doesn't end with the spelled scope. The
+// resolved scope can come from a sema typo correction. For example,
+// sema assumes that "clangd::" is a typo of "clang::" and uses
+// "clang::" as the specified scope in:
+// namespace clang { clangd::X; }
+// In this case, we use the "typo" specifier as extra scope instead
+ 

[PATCH] D58185: [clangd] Handle unresolved scope specifier when fixing includes.

2019-02-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 187359.
ioeric added a comment.

- minor cleanup


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58185

Files:
  clangd/IncludeFixer.cpp
  unittests/clangd/DiagnosticsTests.cpp

Index: unittests/clangd/DiagnosticsTests.cpp
===
--- unittests/clangd/DiagnosticsTests.cpp
+++ unittests/clangd/DiagnosticsTests.cpp
@@ -20,6 +20,7 @@
 namespace clangd {
 namespace {
 
+using testing::_;
 using testing::ElementsAre;
 using testing::Field;
 using testing::IsEmpty;
@@ -369,6 +370,8 @@
 $insert[[]]namespace ns {
 void foo() {
   $unqualified1[[X]] x;
+  // No fix if the unresolved type is used as specifier. (ns::)X::Nested will be
+  // considered the unresolved type.
   $unqualified2[[X]]::Nested n;
 }
 }
@@ -391,10 +394,7 @@
   AllOf(Diag(Test.range("unqualified1"), "unknown type name 'X'"),
 WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
 "Add include \"x.h\" for symbol ns::X"))),
-  AllOf(Diag(Test.range("unqualified2"),
- "use of undeclared identifier 'X'"),
-WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-"Add include \"x.h\" for symbol ns::X"))),
+  Diag(Test.range("unqualified2"), "use of undeclared identifier 'X'"),
   AllOf(Diag(Test.range("qualified1"),
  "no type named 'X' in namespace 'ns'"),
 WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
@@ -487,6 +487,88 @@
   }
 }
 
+TEST(IncludeFixerTest, UnresolvedNameAsSpecifier) {
+  Annotations Test(R"cpp(
+$insert[[]]namespace ns {
+}
+void g() {  ns::$[[scope]]::X_Y();  }
+  )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  auto Index = buildIndexWithSymbol(
+  SymbolWithHeader{"ns::scope::X_Y", "unittest:///x.h", "\"x.h\""});
+  TU.ExternalIndex = Index.get();
+
+  EXPECT_THAT(
+  TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Test.range(), "no member named 'scope' in namespace 'ns'"),
+  WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+  "Add include \"x.h\" for symbol ns::scope::X_Y");
+}
+
+TEST(IncludeFixerTest, UnresolvedSpecifierWithSemaCorrection) {
+  Annotations Test(R"cpp(
+$insert[[]]namespace clang {
+void f() {
+  // "clangd::" will be corrected to "clang::" by Sema.
+  $q1[[clangd]]::$x[[X]] x;
+  $q2[[clangd]]::$ns[[ns]]::Y y;
+}
+}
+  )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  auto Index = buildIndexWithSymbol(
+  {SymbolWithHeader{"clang::clangd::X", "unittest:///x.h", "\"x.h\""},
+   SymbolWithHeader{"clang::clangd::ns::Y", "unittest:///y.h", "\"y.h\""}});
+  TU.ExternalIndex = Index.get();
+
+  EXPECT_THAT(
+  TU.build().getDiagnostics(),
+  UnorderedElementsAre(
+  AllOf(
+  Diag(Test.range("q1"), "use of undeclared identifier 'clangd'; "
+ "did you mean 'clang'?"),
+  WithFix(_, // change clangd to clang
+  Fix(Test.range("insert"), "#include \"x.h\"\n",
+  "Add include \"x.h\" for symbol clang::clangd::X"))),
+  AllOf(
+  Diag(Test.range("x"), "no type named 'X' in namespace 'clang'"),
+  WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+  "Add include \"x.h\" for symbol clang::clangd::X"))),
+  AllOf(
+  Diag(Test.range("q2"), "use of undeclared identifier 'clangd'; "
+ "did you mean 'clang'?"),
+  WithFix(
+  _, // change clangd to clangd
+  Fix(Test.range("insert"), "#include \"y.h\"\n",
+  "Add include \"y.h\" for symbol clang::clangd::ns::Y"))),
+  AllOf(Diag(Test.range("ns"),
+ "no member named 'ns' in namespace 'clang'"),
+WithFix(Fix(
+Test.range("insert"), "#include \"y.h\"\n",
+"Add include \"y.h\" for symbol clang::clangd::ns::Y");
+}
+
+TEST(IncludeFixerTest, SpecifiedScopeIsNamespaceAlias) {
+  Annotations Test(R"cpp(
+$insert[[]]namespace a {}
+namespace b = a;
+namespace c {
+  b::$[[X]] x;
+}
+  )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  auto Index = buildIndexWithSymbol(
+  SymbolWithHeader{"a::X", "unittest:///x.h", "\"x.h\""});
+  TU.ExternalIndex = Index.get();
+
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Test.range(), "no type named 'X' in namespace 'a'"),
+  WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+  "Add include \"x.h\" for symbol a::X");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace 

[PATCH] D57896: Variable names rule

2019-02-19 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added a comment.

In D57896#1402194 , @lattner wrote:

> > Changed recommendation for acronyms from lower case to upper case, as 
> > suggested by several responses to the RFC.
>
> I haven't been following the discussion closely - why is this the preferred 
> direction?  I don't think that things like "Basicblock *bb" or "MachineInstr 
> *mi" will be confusing, and going towards a consistently leading lower case 
> letter seems simple and preferable.


Maybe I misunderstood you 
(http://lists.llvm.org/pipermail/llvm-dev/2019-February/130223.html):

>> Maybe there should be an exception that variable names that start with an 
>> acronym still should start with an upper case letter?
>  That would also be fine with me - it could push such a debate down the road, 
> and is definitely important for a transition period anyway.

Also Chandler 
(http://lists.llvm.org/pipermail/llvm-dev/2019-February/130313.html):

> FWIW, I suspect separating the transition of our acronyms from the transition 
> of identifiers with non-acronym words may be an effective way to chip away at 
> the transition cost... Definitely an area that people who really care about 
> this should look at carefully.

And Sanjoy (kind of) 
(http://lists.llvm.org/pipermail/llvm-dev/2019-February/130304.html):

> maybe a gradual transition plan could be to allow these upper case acronyms 
> for specific classes?

I agree that lower case acronyms would ultimately be more consistent, but given 
where we are it seems more achievable to only change the rule for non-acronyms.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57896



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


[PATCH] D58306: [AArch64] Change size suffix for FP16FML intrinsics.

2019-02-19 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.

LGTM

The ACLE has been updated and a new version with change included will be 
released soon.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58306



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


[PATCH] D57896: Variable names rule

2019-02-19 Thread Chris Lattner via Phabricator via cfe-commits
lattner added a comment.

> Changed recommendation for acronyms from lower case to upper case, as 
> suggested by several responses to the RFC.

I haven't been following the discussion closely - why is this the preferred 
direction?  I don't think that things like "Basicblock *bb" or "MachineInstr 
*mi" will be confusing, and going towards a consistently leading lower case 
letter seems simple and preferable.

-Chris


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57896



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


[PATCH] D55250: [clangd] Enhance macro hover to see full definition

2019-02-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:823
+  (*H)->contents.value =
+  llvm::formatv("```C++\n{0}\n```", (*H)->contents.value);
+}

The contents of the hover is not strictly C++ code, so we shouldn't put the 
whole block into the C++ code.
Could we return the plain text results for now? The hover implementation should 
probably create markdown (or some other form of formatted text) on its own, but 
that's out of scope of this patch.



Comment at: clangd/Protocol.h:378
+  /// textDocument.hover.contentFormat.
+  llvm::Optional HoverMarkupKinds;
 };

Could we replace this with a single boolean to simplify the code?
```
bool HoverSupportsMarkdown = false;
```

Would also allow to get remove `MarkupKindBitset`.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55250



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


  1   2   >