[PATCH] D40259: [libcxx] LWG2993: reference_wrapper

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/__functional_base:396
+!is_same<__uncvref_t<_Up>, reference_wrapper>::value
+>::type, bool _IsNothrow = noexcept(__bind(_VSTD::declval<_Up>()))>
+_LIBCPP_INLINE_VISIBILITY reference_wrapper(_Up&& __u) 
_NOEXCEPT_(_IsNothrow)

tcanens wrote:
> Is it safe to do this when we are using `_NOEXCEPT_` in the next line?
It should be. The noexcept condition should only be evaluated *as needed* for 
functions selected by overload resolution. i.e. The noexcept condition is only 
considered on well-formed functions. And this function is only well-formed if 
`_IsNothrow` is well formed.

If `IsNothrow` is ill-formed, it will prevent the functions noexcept specifier 
from ever being evaluated.


https://reviews.llvm.org/D40259



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


r318736 - [MS] add an init test for thumbv7-windows-msvc

2017-11-21 Thread Martell Malone via cfe-commits
Author: martell
Date: Tue Nov 21 00:09:59 2017
New Revision: 318736

URL: http://llvm.org/viewvc/llvm-project?rev=318736&view=rev
Log:
[MS] add an init test for thumbv7-windows-msvc

Modified:
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=318736&r1=318735&r2=318736&view=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Tue Nov 21 00:09:59 2017
@@ -1438,6 +1438,11 @@
 // AARCH64-DARWIN: #define __WINT_WIDTH__ 32
 // AARCH64-DARWIN: #define __aarch64__ 1
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=thumbv7-windows-msvc < 
/dev/null | FileCheck -match-full-lines -check-prefix ARM-MSVC %s
+//
+// ARM-MSVC: #define _M_ARM_NT 1
+// ARM-MSVC: #define _WIN32 1
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < 
/dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 //
 // AARCH64-MSVC: #define _INTEGRAL_MAX_BITS 64


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


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell created this revision.
Herald added subscribers: kristof.beyls, javed.absar, rengolin, aemerson.

_WIN32 is already defined in lib/Basic/Targets/OSTargets.h
WIN32 and WIN64 are not real definitions they are typically
defined by the system headers,  _WIN32 and _WIN64 are the
compiler definitions.


Repository:
  rL LLVM

https://reviews.llvm.org/D40285

Files:
  lib/Basic/Targets/AArch64.cpp
  test/Preprocessor/predefined-macros.c


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -204,8 +204,6 @@
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
 
 // CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
-// CHECK-ARM64-MINGW: #define WIN32 1
-// CHECK-ARM64-MINGW: #define WIN64 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -474,7 +474,6 @@
 void MicrosoftARM64TargetInfo::getVisualStudioDefines(
 const LangOptions &Opts, MacroBuilder &Builder) const {
   WindowsTargetInfo::getVisualStudioDefines(Opts, 
Builder);
-  Builder.defineMacro("_WIN32", "1");
   Builder.defineMacro("_WIN64", "1");
   Builder.defineMacro("_M_ARM64", "1");
 }
@@ -494,10 +493,7 @@
 void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
   Builder.defineMacro("_WIN64", "1");
-  Builder.defineMacro("WIN32", "1");
-  Builder.defineMacro("WIN64", "1");
   addMinGWDefines(Opts, Builder);
 }
 


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -204,8 +204,6 @@
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
 
 // CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
-// CHECK-ARM64-MINGW: #define WIN32 1
-// CHECK-ARM64-MINGW: #define WIN64 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -474,7 +474,6 @@
 void MicrosoftARM64TargetInfo::getVisualStudioDefines(
 const LangOptions &Opts, MacroBuilder &Builder) const {
   WindowsTargetInfo::getVisualStudioDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
   Builder.defineMacro("_WIN64", "1");
   Builder.defineMacro("_M_ARM64", "1");
 }
@@ -494,10 +493,7 @@
 void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
   Builder.defineMacro("_WIN64", "1");
-  Builder.defineMacro("WIN32", "1");
-  Builder.defineMacro("WIN64", "1");
   addMinGWDefines(Opts, Builder);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

> WIN32 and WIN64 are not real definitions they are typically defined by the 
> system headers, _WIN32 and _WIN64 are the compiler definitions.

Almost.

In MSVC, WIN32 and WIN64 are never defined by the compiler, neither by system 
headers. Project files created by the IDE often contains them set manually 
though.

GCC on the other hand predefines both `_WIN32` and `WIN32` (and similarly for 
-64), but only when using the GNU standards additions (which are enabled by 
default) `x86_64-w64-mingw32-gcc -E -dM - < /dev/null | grep WIN32` does 
include both, while the unprefixed one vanishes if you add e.g. `-std=c99` (but 
are still included if you set `-std=gnu99`).

clang on the other hand doesn't check the standards version, but provides both 
`WIN32` and `_WIN32`. And for the really inconsistent case, with `clang -target 
x86_64-w64-mingw32 -E -dM - < /dev/null`, you will have `WIN64`, `_WIN64` and 
`_WIN32`, but no unprefixed `WIN32`.


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

... so in general I wouldn't mind doing a change like this, but I'd like to 
make it consistent on ARM, i386 and x86_64 at the same time in that case, 
instead of just changing aarch64.


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell updated this revision to Diff 123728.

Repository:
  rL LLVM

https://reviews.llvm.org/D40285

Files:
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/X86.h
  test/Preprocessor/predefined-macros.c


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -200,12 +200,20 @@
 // CHECK-ARM64-WIN: #define _WIN32 1
 // CHECK-ARM64-WIN: #define _WIN64 1
 
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW
+
+// CHECK-AMD64-MINGW: #define WIN32 1
+// CHECK-AMD64-MINGW: #define WINNT 1
+// CHECK-AMD64-MINGW: #define _WIN32 1
+// CHECK-AMD64-MINGW: #define _WIN64 1
+
 // RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
 
 // CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
 // CHECK-ARM64-MINGW: #define WIN32 1
-// CHECK-ARM64-MINGW: #define WIN64 1
+// CHECK-ARM64-MINGW: #define WINNT 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: lib/Basic/Targets/X86.h
===
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -726,7 +726,6 @@
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
-DefineStd(Builder, "WIN64", Opts);
 Builder.defineMacro("__MINGW64__");
 addMinGWDefines(Opts, Builder);
 
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -474,7 +474,6 @@
 void MicrosoftARM64TargetInfo::getVisualStudioDefines(
 const LangOptions &Opts, MacroBuilder &Builder) const {
   WindowsTargetInfo::getVisualStudioDefines(Opts, 
Builder);
-  Builder.defineMacro("_WIN32", "1");
   Builder.defineMacro("_WIN64", "1");
   Builder.defineMacro("_M_ARM64", "1");
 }
@@ -494,10 +493,9 @@
 void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
+  DefineStd(Builder, "WIN32", Opts);
+  DefineStd(Builder, "WINNT", Opts);
   Builder.defineMacro("_WIN64", "1");
-  Builder.defineMacro("WIN32", "1");
-  Builder.defineMacro("WIN64", "1");
   addMinGWDefines(Opts, Builder);
 }
 


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -200,12 +200,20 @@
 // CHECK-ARM64-WIN: #define _WIN32 1
 // CHECK-ARM64-WIN: #define _WIN64 1
 
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW
+
+// CHECK-AMD64-MINGW: #define WIN32 1
+// CHECK-AMD64-MINGW: #define WINNT 1
+// CHECK-AMD64-MINGW: #define _WIN32 1
+// CHECK-AMD64-MINGW: #define _WIN64 1
+
 // RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
 
 // CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
 // CHECK-ARM64-MINGW: #define WIN32 1
-// CHECK-ARM64-MINGW: #define WIN64 1
+// CHECK-ARM64-MINGW: #define WINNT 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: lib/Basic/Targets/X86.h
===
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -726,7 +726,6 @@
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
-DefineStd(Builder, "WIN64", Opts);
 Builder.defineMacro("__MINGW64__");
 addMinGWDefines(Opts, Builder);
 
Index: lib/Basic/Targets/AArch64.cpp
===
--- lib/Basic/Targets/AArch64.cpp
+++ lib/Basic/Targets/AArch64.cpp
@@ -474,7 +474,6 @@
 void MicrosoftARM64TargetInfo::getVisualStudioDefines(
 const LangOptions &Opts, MacroBuilder &Builder) const {
   WindowsTargetInfo::getVisualStudioDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
   Builder.defineMacro("_WIN64", "1");
   Builder.defineMacro("_M_ARM64", "1");
 }
@@ -494,10 +493,9 @@
 void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
+  DefineStd(Builder, "WIN32", Opts);

[PATCH] D40259: [libcxx] LWG2993: reference_wrapper

2017-11-21 Thread Tim Song via Phabricator via cfe-commits
tcanens added inline comments.



Comment at: include/__functional_base:396
+!is_same<__uncvref_t<_Up>, reference_wrapper>::value
+>::type, bool _IsNothrow = noexcept(__bind(_VSTD::declval<_Up>()))>
+_LIBCPP_INLINE_VISIBILITY reference_wrapper(_Up&& __u) 
_NOEXCEPT_(_IsNothrow)

EricWF wrote:
> tcanens wrote:
> > Is it safe to do this when we are using `_NOEXCEPT_` in the next line?
> It should be. The noexcept condition should only be evaluated *as needed* for 
> functions selected by overload resolution. i.e. The noexcept condition is 
> only considered on well-formed functions. And this function is only 
> well-formed if `_IsNothrow` is well formed.
> 
> If `IsNothrow` is ill-formed, it will prevent the functions noexcept 
> specifier from ever being evaluated.
My point is that the use of macro-ized `_NOEXCEPT_` suggests that we are 
supporting compilers that doesn't have noexcept-specifications. Given that, can 
we then use the `noexcept` operator here?


https://reviews.llvm.org/D40259



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


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.

In https://reviews.llvm.org/D40285#931241, @mstorsjo wrote:

> ... so in general I wouldn't mind doing a change like this, but I'd like to 
> make it consistent on ARM, i386 and x86_64 at the same time in that case, 
> instead of just changing aarch64.


Thanks for the quick feedback :)
The easy one is to get rid of WIN64 because gcc doesn't even do that for mingw.
What are your thoughts here on WIN32, I would prefer to move it.
I remember a long time ago a lot of projects moved to _WIN32 when they 
discovered that it was not supposed to be defined.
I updated the diff to reflect removing WIN64


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.

... also WINNT was defined for X86 so I just added that to note it.
what do you suggest we do with that one.


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


r318739 - [x86][inline-asm] allow recognition of MPX regs inside ms inline-asm blob

2017-11-21 Thread Coby Tayree via cfe-commits
Author: coby
Date: Tue Nov 21 00:50:10 2017
New Revision: 318739

URL: http://llvm.org/viewvc/llvm-project?rev=318739&view=rev
Log:
[x86][inline-asm] allow recognition of MPX regs inside ms inline-asm blob
Differential Revision: https://reviews.llvm.org/D38445

Modified:
cfe/trunk/lib/Basic/Targets/X86.cpp
cfe/trunk/test/CodeGen/ms-inline-asm.c

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=318739&r1=318738&r2=318739&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Tue Nov 21 00:50:10 2017
@@ -60,6 +60,7 @@ static const char *const GCCRegNames[] =
 "k2","k3","k4","k5","k6",  "k7",
 "cr0",   "cr2",   "cr3",   "cr4",   "cr8",
 "dr0",   "dr1",   "dr2",   "dr3",   "dr6", "dr7",
+"bnd0",  "bnd1",  "bnd2",  "bnd3",
 };
 
 const TargetInfo::AddlRegName AddlRegNames[] = {

Modified: cfe/trunk/test/CodeGen/ms-inline-asm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm.c?rev=318739&r1=318738&r2=318739&view=diff
==
--- cfe/trunk/test/CodeGen/ms-inline-asm.c (original)
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c Tue Nov 21 00:50:10 2017
@@ -661,6 +661,17 @@ void t46() {
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", 
"~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t47() {
+  // CHECK-LABEL: define void @t47
+  __asm {
+bndmk bnd0, dword ptr [eax]
+bndmk bnd1, dword ptr [ebx]
+bndmk bnd2, dword ptr [ecx]
+bndmk bnd3, dword ptr [edx]
+  }
+  // CHECK: call void asm sideeffect inteldialect "bndmk bnd0, dword ptr 
[eax]\0A\09bndmk bnd1, dword ptr [ebx]\0A\09bndmk bnd2, dword ptr 
[ecx]\0A\09bndmk bnd3, dword ptr [edx]", 
"~{bnd0},~{bnd1},~{bnd2},~{bnd3},~{dirflag},~{fpsr},~{flags}"()
+}
+
 void dot_operator(){
   // CHECK-LABEL: define void @dot_operator
__asm { mov eax, 3[ebx]A.b}


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


[PATCH] D38445: [x86][inline-asm] allow recognition of MPX regs inside ms inline-asm blob

2017-11-21 Thread coby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318739: [x86][inline-asm] allow recognition of MPX regs 
inside ms inline-asm blob (authored by coby).

Changed prior to commit:
  https://reviews.llvm.org/D38445?vs=117278&id=123730#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38445

Files:
  cfe/trunk/lib/Basic/Targets/X86.cpp
  cfe/trunk/test/CodeGen/ms-inline-asm.c


Index: cfe/trunk/lib/Basic/Targets/X86.cpp
===
--- cfe/trunk/lib/Basic/Targets/X86.cpp
+++ cfe/trunk/lib/Basic/Targets/X86.cpp
@@ -60,6 +60,7 @@
 "k2","k3","k4","k5","k6",  "k7",
 "cr0",   "cr2",   "cr3",   "cr4",   "cr8",
 "dr0",   "dr1",   "dr2",   "dr3",   "dr6", "dr7",
+"bnd0",  "bnd1",  "bnd2",  "bnd3",
 };
 
 const TargetInfo::AddlRegName AddlRegNames[] = {
Index: cfe/trunk/test/CodeGen/ms-inline-asm.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c
@@ -661,6 +661,17 @@
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", 
"~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t47() {
+  // CHECK-LABEL: define void @t47
+  __asm {
+bndmk bnd0, dword ptr [eax]
+bndmk bnd1, dword ptr [ebx]
+bndmk bnd2, dword ptr [ecx]
+bndmk bnd3, dword ptr [edx]
+  }
+  // CHECK: call void asm sideeffect inteldialect "bndmk bnd0, dword ptr 
[eax]\0A\09bndmk bnd1, dword ptr [ebx]\0A\09bndmk bnd2, dword ptr 
[ecx]\0A\09bndmk bnd3, dword ptr [edx]", 
"~{bnd0},~{bnd1},~{bnd2},~{bnd3},~{dirflag},~{fpsr},~{flags}"()
+}
+
 void dot_operator(){
   // CHECK-LABEL: define void @dot_operator
__asm { mov eax, 3[ebx]A.b}


Index: cfe/trunk/lib/Basic/Targets/X86.cpp
===
--- cfe/trunk/lib/Basic/Targets/X86.cpp
+++ cfe/trunk/lib/Basic/Targets/X86.cpp
@@ -60,6 +60,7 @@
 "k2","k3","k4","k5","k6",  "k7",
 "cr0",   "cr2",   "cr3",   "cr4",   "cr8",
 "dr0",   "dr1",   "dr2",   "dr3",   "dr6", "dr7",
+"bnd0",  "bnd1",  "bnd2",  "bnd3",
 };
 
 const TargetInfo::AddlRegName AddlRegNames[] = {
Index: cfe/trunk/test/CodeGen/ms-inline-asm.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c
@@ -661,6 +661,17 @@
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", "~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t47() {
+  // CHECK-LABEL: define void @t47
+  __asm {
+bndmk bnd0, dword ptr [eax]
+bndmk bnd1, dword ptr [ebx]
+bndmk bnd2, dword ptr [ecx]
+bndmk bnd3, dword ptr [edx]
+  }
+  // CHECK: call void asm sideeffect inteldialect "bndmk bnd0, dword ptr [eax]\0A\09bndmk bnd1, dword ptr [ebx]\0A\09bndmk bnd2, dword ptr [ecx]\0A\09bndmk bnd3, dword ptr [edx]", "~{bnd0},~{bnd1},~{bnd2},~{bnd3},~{dirflag},~{fpsr},~{flags}"()
+}
+
 void dot_operator(){
   // CHECK-LABEL: define void @dot_operator
 	__asm { mov eax, 3[ebx]A.b}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D40285#931242, @martell wrote:

> The easy one is to get rid of WIN64 because gcc doesn't even do that for 
> mingw.


Yes it does, it behaves just the same as WIN32:

  $ x86_64-w64-mingw32-gcc -E -dM - < /dev/null | grep WIN64
  #define _WIN64 1
  #define __WIN64 1
  #define WIN64 1
  #define __WIN64__ 1



> What are your thoughts here on WIN32, I would prefer to move it.

I'm a little divided - either we remove both WIN32 and WIN64 from all mingw 
configurations, or we add the missing WIN32 for x86_64 mingw. Removing would be 
the strictly correct thing to do, but I'm sure it will break code that used to 
work before (even though it's wrong to rely on the unprefixed one).

> I remember a long time ago a lot of projects moved to _WIN32 when they 
> discovered that it was not supposed to be defined.

Yes, generally projects shouldn't check for the unprefixed defines, but 
unfortunately some do. I just recently ran into such an issue when building 
with the x86_64 configuration, where GCC would have had WIN32 defined but clang 
didn't.


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-21 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin requested changes to this revision.
a.sidorin added a comment.
This revision now requires changes to proceed.

Hello Takafumi,

Could you investigate the patch https://reviews.llvm.org/D30876? It should fix 
same issue. However, it also handles conflict resolution. I accidentally forgot 
about this patch.


https://reviews.llvm.org/D39886



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


[PATCH] D40285: [MS] AARCH64 cleanup default WIN macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.

In https://reviews.llvm.org/D40285#931248, @mstorsjo wrote:

> I'm a little divided - either we remove both WIN32 and WIN64 from all mingw 
> configurations, or we add the missing WIN32 for x86_64 mingw. Removing would 
> be the strictly correct thing to do, but I'm sure it will break code that 
> used to work before (even though it's wrong to rely on the unprefixed one).


looking at different `windef.h` I see - specifically ReactOS

  #ifndef WIN32
  #define WIN32
  #endif

I don't have MSVC off hand to check if it is there but I do remember MSVC 
projects used to pass `/D "WIN32"` so having them might make sense also.
I'm going to try include them and fold all the code for the different arch's 
for mingw in a moment


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


[PATCH] D36390: Fix overloaded static functions in SemaCodeComplete

2017-11-21 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaOverload.cpp:6365
cast(FD)->getParent(), ObjectType,
-   ObjectClassification, Args.slice(1), CandidateSet,
+   ObjectClassification, FunctionArgs, CandidateSet,
SuppressUserConversions, PartialOverloading);

cameron314 wrote:
> This breaks normal (non-static) method overload resolution, since the `this` 
> argument is now passed to `AddMethodCandidate` which is not expecting it. It 
> always thinks too many arguments are passed to methods with no parameters; 
> most other calls to `AddMethodCandidate` in SemaOverload.cpp don't pass the 
> implicit `this`.
This code is correct. It is sliced at line 6361 - only in the case when the 
args size is greater than 0.



Comment at: cfe/trunk/lib/Sema/SemaOverload.cpp:6396
   } else {
 AddTemplateOverloadCandidate(FunTmpl, F.getPair(),
  ExplicitTemplateArgs, Args,

cameron314 wrote:
> The same slice that was added above needs to be done here for templated 
> static methods that are accessed via a non-static object.
It might be the case. You can add that :)
I did not check template cases in details.


Repository:
  rL LLVM

https://reviews.llvm.org/D36390



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


[PATCH] D40259: [libcxx] LWG2993: reference_wrapper

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/__functional_base:396
+!is_same<__uncvref_t<_Up>, reference_wrapper>::value
+>::type, bool _IsNothrow = noexcept(__bind(_VSTD::declval<_Up>()))>
+_LIBCPP_INLINE_VISIBILITY reference_wrapper(_Up&& __u) 
_NOEXCEPT_(_IsNothrow)

tcanens wrote:
> EricWF wrote:
> > tcanens wrote:
> > > Is it safe to do this when we are using `_NOEXCEPT_` in the next line?
> > It should be. The noexcept condition should only be evaluated *as needed* 
> > for functions selected by overload resolution. i.e. The noexcept condition 
> > is only considered on well-formed functions. And this function is only 
> > well-formed if `_IsNothrow` is well formed.
> > 
> > If `IsNothrow` is ill-formed, it will prevent the functions noexcept 
> > specifier from ever being evaluated.
> My point is that the use of macro-ized `_NOEXCEPT_` suggests that we are 
> supporting compilers that doesn't have noexcept-specifications. Given that, 
> can we then use the `noexcept` operator here?
Ah, I see!

The `_NOEXCEPT_` macro is a holdover from the C++03/C++11 era. This code 
expects a C++11 conformant compiler, and hence expects `noexcept` to work as a 
non-buggy feature-complete C++11 construct.

Much in the same way the current (and previous) code expects C++11 template 
aliases, default function template arguments, `decltype`, ect. to work.


https://reviews.llvm.org/D40259



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


[PATCH] D29930: Add `__reference_binds_to_temporary` trait for checking safe reference initialization.

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked an inline comment as done.
EricWF added inline comments.



Comment at: test/SemaCXX/type-traits.cpp:2102-2116
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = ConvertsToRef;
+  { int arr[T((__is_constructible(int&, LRef)))]; }
+  { int arr[F((__reference_binds_to_temporary(int&, LRef)))]; }
+

rsmith wrote:
> Please also check things like:
> 
>   `__reference_binds_to_temporary(const int&, ConvertsToRef)`
> 
> (That is, a user-defined conversion to a reference type followed by 
> converting and materializing a temporary.)
Isn't that exactly what the test on the specified line does? `LongRef` is  
`ConvertsToRef`


https://reviews.llvm.org/D29930



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


[PATCH] D40288: [clang-format] Add option to group multiple #include blocks when sorting includes

2017-11-21 Thread Krzysztof Kapusta via Phabricator via cfe-commits
KrzysztofKapusta created this revision.
KrzysztofKapusta added a project: clang-tools-extra.
Herald added a subscriber: klimek.

This patch allows grouping multiple #include blocks together and sort all 
includes as one big block.
Additionally, sorted includes can be regrouped after sorting based on 
configured categories.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40288

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -77,6 +77,28 @@
   EXPECT_TRUE(sortIncludes(Style, Code, GetCodeRange(Code), "a.cc").empty());
 }
 
+TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) {
+  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"b.h\"\n"
+"#include \"c.h\"\n",
+sort("#include \"a.h\"\n"
+ "#include \"c.h\"\n"
+ "\n"
+ "\n"
+ "#include \"b.h\"\n"));
+
+  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"b.h\"\n"
+"#include \"c.h\"\n",
+sort("#include \"a.h\"\n"
+ "#include \"c.h\"\n"
+ "\n"
+ "\n"
+ "#include \"b.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, SupportClangFormatOff) {
   EXPECT_EQ("#include \n"
 "#include \n"
@@ -159,6 +181,48 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SortsAllBlocksWhenMerging) {
+  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"b.h\"\n"
+"#include \"c.h\"\n",
+sort("#include \"a.h\"\n"
+ "#include \"c.h\"\n"
+ "\n"
+ "#include \"b.h\"\n"));
+}
+
+TEST_F(SortIncludesTest, CommentsAlwaysSeparateGroups) {
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"c.h\"\n"
+"// comment\n"
+"#include \"b.h\"\n",
+sort("#include \"c.h\"\n"
+ "#include \"a.h\"\n"
+ "// comment\n"
+ "#include \"b.h\"\n"));
+
+  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"c.h\"\n"
+"// comment\n"
+"#include \"b.h\"\n",
+sort("#include \"c.h\"\n"
+ "#include \"a.h\"\n"
+ "// comment\n"
+ "#include \"b.h\"\n"));
+
+  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"c.h\"\n"
+"// comment\n"
+"#include \"b.h\"\n",
+sort("#include \"c.h\"\n"
+ "#include \"a.h\"\n"
+ "// comment\n"
+ "#include \"b.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) {
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"c.h\"\n"
@@ -180,6 +244,19 @@
  "#include \"a.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, RegroupsAngledIncludesInSeparateBlocks) {
+  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"c.h\"\n"
+"\n"
+"#include \n"
+"#include \n",
+sort("#include \n"
+ "#include \n"
+ "#include \"c.h\"\n"
+ "#include \"a.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, HandlesMultilineIncludes) {
   EXPECT_EQ("#include \"a.h\"\n"
 "#include \"b.h\"\n"
@@ -266,6 +343,35 @@
  "a.cc"));
 }
 
+TEST_F(SortIncludesTest, RecognizeMainHeaderInAllGroups) {
+  Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
+  Style.IncludeBlocks = FormatStyle::IBS_Merge;
+
+  EXPECT_EQ("#include \"a.h\"\n"
+"#include \"b.h\"\n"
+"#include \"c.h\"\n",
+sort("#include \"b.h\"\n"
+ "\n"
+ "#include \"a.h\"\n"
+ "#include \"c.h\"\n",
+ "a.cc"));
+}
+
+TEST_F(SortIncludesTest, MainHeaderIsSeparatedWhenRegroupping) {
+  Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
+  Style.IncludeBlocks = FormatStyle::IBS_Regroup;
+
+  EXPECT_EQ("#include \"a.h\"\n"
+"\n"
+"#include \"b.h\"\n"
+"#include \"c.h\"\n",
+sort("#include \"b.h\"\n"
+ "\n"
+ "#include \"a.h\"\n"
+ "#include \"c.h\"\n",
+ "a.cc"));
+}
+
 TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) {
   // Setup an regex for main includes so we can cover those as well.
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
@@ -309,6

[PATCH] D40270: [Modules TS] Added re-export support

2017-11-21 Thread Hamza Sood via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318744: [Modules TS] Added module re-export support. 
(authored by hamzasood).

Changed prior to commit:
  https://reviews.llvm.org/D40270?vs=123666&id=123736#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40270

Files:
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/lib/Parse/ParseObjc.cpp
  cfe/trunk/lib/Parse/Parser.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp
  cfe/trunk/test/SemaCXX/modules-ts.cppm

Index: cfe/trunk/test/SemaCXX/modules-ts.cppm
===
--- cfe/trunk/test/SemaCXX/modules-ts.cppm
+++ cfe/trunk/test/SemaCXX/modules-ts.cppm
@@ -52,10 +52,6 @@
 export { ; }
 export { static_assert(true); }
 
-// FIXME: These diagnostics are not very good.
-export import foo; // expected-error {{expected unqualified-id}}
-export { import foo; } // expected-error {{expected unqualified-id}}
-
 int use_b = b;
 int use_n = n; // FIXME: this should not be visible, because it is not exported
 
Index: cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp
===
--- cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp
+++ cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp
@@ -0,0 +1,40 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+//
+// RUN: echo 'export module a; export class A{};' | %clang_cc1 -x c++ -fmodules-ts -emit-module-interface - -o %t/a.pcm
+// RUN: echo 'export module b; export class B{};' | %clang_cc1 -x c++ -fmodules-ts -emit-module-interface - -o %t/b.pcm
+// RUN: echo 'export module c; export class C{};' | %clang_cc1 -x c++ -fmodules-ts -emit-module-interface - -o %t/c.pcm
+//
+// RUN: %clang_cc1 -fmodules-ts -fprebuilt-module-path=%t -emit-module-interface %s -o %t/aggregate.internal.pcm -DAGGREGATE_INTERNAL
+// RUN: %clang_cc1 -fmodules-ts -fprebuilt-module-path=%t -emit-module-interface %s -o %t/aggregate.pcm -DAGGREGATE
+//
+// RUN: %clang_cc1 -fmodules-ts -fprebuilt-module-path=%t %s -verify -DTEST
+// expected-no-diagnostics
+
+
+#ifdef AGGREGATE_INTERNAL
+export module aggregate.internal;
+export import a;
+export {
+  import b;
+  import c;
+}
+#endif
+
+
+// Export the above aggregate module.
+// This is done to ensure that re-exports are transitive.
+#ifdef AGGREGATE
+export module aggregate;
+export import aggregate.internal;
+#endif
+
+
+// For the actual test, just try using the classes from the exported modules
+// and hope that they're accessible.
+#ifdef TEST
+import aggregate;
+A a;
+B b;
+C c;
+#endif
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -16171,7 +16171,7 @@
 DC = LSD->getParent();
   }
 
-  while (isa(DC))
+  while (isa(DC) || isa(DC))
 DC = DC->getParent();
 
   if (!isa(DC)) {
@@ -16349,12 +16349,17 @@
 IdentifierLocs.push_back(Path[I].second);
   }
 
-  TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
-  ImportDecl *Import = ImportDecl::Create(Context, TU, StartLoc,
+  ImportDecl *Import = ImportDecl::Create(Context, CurContext, StartLoc,
   Mod, IdentifierLocs);
   if (!ModuleScopes.empty())
 Context.addModuleInitializer(ModuleScopes.back().Module, Import);
-  TU->addDecl(Import);
+  CurContext->addDecl(Import);
+
+  // Re-export the module if needed.
+  if (Import->isExported() &&
+  !ModuleScopes.empty() && ModuleScopes.back().ModuleInterface)
+getCurrentModule()->Exports.emplace_back(Mod, false);
+
   return Import;
 }
 
Index: cfe/trunk/lib/Parse/ParseObjc.cpp
===
--- cfe/trunk/lib/Parse/ParseObjc.cpp
+++ cfe/trunk/lib/Parse/ParseObjc.cpp
@@ -81,8 +81,10 @@
 SingleDecl = ParseObjCPropertyDynamic(AtLoc);
 break;
   case tok::objc_import:
-if (getLangOpts().Modules || getLangOpts().DebuggerSupport)
-  return ParseModuleImport(AtLoc);
+if (getLangOpts().Modules || getLangOpts().DebuggerSupport) {
+  SingleDecl = ParseModuleImport(AtLoc);
+  break;
+}
 Diag(AtLoc, diag::err_atimport);
 SkipUntil(tok::semi);
 return Actions.ConvertDeclToDeclGroup(nullptr);
Index: cfe/trunk/lib/Parse/Parser.cpp
===
--- cfe/trunk/lib/Parse/Parser.cpp
+++ cfe/trunk/lib/Parse/Parser.cpp
@@ -556,10 +556,6 @@
 HandlePragmaUnused();
 return false;
 
-  case tok::kw_import:
-Result = ParseModuleImport(SourceLocation());
-return false;
-
   case tok::kw_export:
 if (NextToken().isNot(tok::kw_module))
   break;
@@ -637,6 +633,9 @@
 ///   ';'
 ///
 /// [C++0x/GNU] 'extern' 'template' declaration
+///
+/// [Modules-TS] module-impo

r318744 - [Modules TS] Added module re-export support.

2017-11-21 Thread Hamza Sood via cfe-commits
Author: hamzasood
Date: Tue Nov 21 01:42:42 2017
New Revision: 318744

URL: http://llvm.org/viewvc/llvm-project?rev=318744&view=rev
Log:
[Modules TS] Added module re-export support.

This implements [dcl.modules.export] from the C++ Modules TS, which lets a 
module re-export another module with the "export import" syntax.
Differential Revision: https://reviews.llvm.org/D40270

Added:
cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/modules-ts.cppm

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=318744&r1=318743&r2=318744&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Nov 21 01:42:42 2017
@@ -2788,7 +2788,7 @@ private:
   
//======//
   // Modules
   DeclGroupPtrTy ParseModuleDecl();
-  DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc);
+  Decl *ParseModuleImport(SourceLocation AtLoc);
   bool parseMisplacedModuleImport();
   bool tryParseMisplacedModuleImport() {
 tok::TokenKind Kind = Tok.getKind();

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=318744&r1=318743&r2=318744&view=diff
==
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Nov 21 01:42:42 2017
@@ -81,8 +81,10 @@ Parser::DeclGroupPtrTy Parser::ParseObjC
 SingleDecl = ParseObjCPropertyDynamic(AtLoc);
 break;
   case tok::objc_import:
-if (getLangOpts().Modules || getLangOpts().DebuggerSupport)
-  return ParseModuleImport(AtLoc);
+if (getLangOpts().Modules || getLangOpts().DebuggerSupport) {
+  SingleDecl = ParseModuleImport(AtLoc);
+  break;
+}
 Diag(AtLoc, diag::err_atimport);
 SkipUntil(tok::semi);
 return Actions.ConvertDeclToDeclGroup(nullptr);

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=318744&r1=318743&r2=318744&view=diff
==
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Tue Nov 21 01:42:42 2017
@@ -556,10 +556,6 @@ bool Parser::ParseTopLevelDecl(DeclGroup
 HandlePragmaUnused();
 return false;
 
-  case tok::kw_import:
-Result = ParseModuleImport(SourceLocation());
-return false;
-
   case tok::kw_export:
 if (NextToken().isNot(tok::kw_module))
   break;
@@ -637,6 +633,9 @@ bool Parser::ParseTopLevelDecl(DeclGroup
 ///   ';'
 ///
 /// [C++0x/GNU] 'extern' 'template' declaration
+///
+/// [Modules-TS] module-import-declaration
+///
 Parser::DeclGroupPtrTy
 Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
  ParsingDeclSpec *DS) {
@@ -764,6 +763,9 @@ Parser::ParseExternalDeclaration(ParsedA
 CurParsedObjCImpl ? Sema::PCC_ObjCImplementation : 
Sema::PCC_Namespace);
 cutOffParsing();
 return nullptr;
+  case tok::kw_import:
+SingleDecl = ParseModuleImport(SourceLocation());
+break;
   case tok::kw_export:
 if (getLangOpts().ModulesTS) {
   SingleDecl = ParseExportDeclaration();
@@ -2092,7 +2094,7 @@ Parser::DeclGroupPtrTy Parser::ParseModu
 ///   '@' 'import' module-name ';'
 /// [ModTS] module-import-declaration:
 ///   'import' module-name attribute-specifier-seq[opt] ';'
-Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) {
+Decl *Parser::ParseModuleImport(SourceLocation AtLoc) {
   assert((AtLoc.isInvalid() ? Tok.is(tok::kw_import)
 : Tok.isObjCAtKeyword(tok::objc_import)) &&
  "Improper start to module import");
@@ -2119,7 +2121,7 @@ Parser::DeclGroupPtrTy Parser::ParseModu
   if (Import.isInvalid())
 return nullptr;
 
-  return Actions.ConvertDeclToDeclGroup(Import.get());
+  return Import.get();
 }
 
 /// Parse a C++ Modules TS / Objective-C module name (both forms use the same

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=318744&r1=318743&r2=318744&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 21 01:42:42 2017
@@ -16171,7 +16171,7 @@ static void checkModuleImportContext(Sem
 DC = LSD->getParent();
   }
 
-  while (isa(DC))
+  while (isa(DC) || isa(DC))
 DC = DC->getParent();
 
   if (!isa(DC)) {
@@ -16349,12

[PATCH] D35894: [clangd] Code hover for Clangd

2017-11-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added a comment.
This revision now requires changes to proceed.

I haven't looked into the `getHover` method's body yet, but here are some 
comments about other parts.
Good work, BTW, this looks close to being ready.




Comment at: clangd/ClangdServer.cpp:511
+Tagged ClangdServer::findHover(PathRef File, Position Pos) {
+
+  //Default Hover values

NIT: could you remove the empty newlines at the start of the methods?



Comment at: clangd/ClangdServer.cpp:514
+  std::vector EmptyVector;
+  Position BeginPosition = {0,0};
+  Position EndPosition = {0,0};

Let's follow error-reporting pattern used in other `ClangdServer` features.
We should return `llvm::Expected` and do `Ctx.replyError` on error return 
values.



Comment at: clangd/ClangdUnit.cpp:959
+std::sort(DeclarationDecls.begin(), DeclarationDecls.end());
+auto last = std::unique(DeclarationDecls.begin(), DeclarationDecls.end());
+DeclarationDecls.erase(last, DeclarationDecls.end());

NIT: local vars are `UpperCamelCase`. (Not introduced by this commit, but 
probably a good place to fix the naming anyway).



Comment at: clangd/ClangdUnit.cpp:967
+// This can happen when nodes in the AST are visited twice.
+std::sort(DeclarationMacroInfs.begin(), DeclarationMacroInfs.end());
 auto last =

NIT: local vars are `UpperCamelCase`. (Not introduced by this commit, but 
probably a good place to fix the naming anyway).



Comment at: clangd/ClangdUnit.cpp:1100
+
+  const SourceManager &SM = AST.getASTContext().getSourceManager();
+  const LangOptions &LangOpts = AST.getASTContext().getLangOpts();

I think this functionality is already implemented in clang. Could you use 
`ASTContext::getRawCommentForAnyRedecl`?



Comment at: clangd/ClangdUnit.cpp:1199
+  } else if (dyn_cast(LocationDecl)) {
+// TODO: find a way to get the hover for the type that is being aliased
+SR = LocationDecl->getSourceRange();

NIT: we use `FIXME`



Comment at: clangd/ClangdUnit.h:323
+
+Location getDeclarationLocation(ParsedAST &AST, const SourceRange 
&ValSourceRange);
+

Could we put `getDeclarationLocation` and `getFunctionComments` in the cpp file 
instead? They're just implementation detail of `findDefinitions`/`getHover`, 
right?



Comment at: clangd/MyClass.cpp:1
+#include "MyClass.h"
+

Remove it.



Comment at: clangd/Protocol.h:26
 #include "llvm/ADT/Optional.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/Optional.h"

We don't need `SourceLocation`  here



Comment at: clangd/Protocol.h:27
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/YAMLParser.h"

This include is redundant


https://reviews.llvm.org/D35894



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


[PATCH] D40279: [libcxxabi][demangler] Add demangling for __attribute__((abi_tag))

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: src/cxa_demangle.cpp:10
 
+// FIXME: (possibly) incomplete list of features that clang mangles that this
+// file does not yet support:

Awesome comment!

If your awesomeness knows no bound, I would love to add currently-failing tests 
that demonstrate the FIXME.
Obviously that has no bearing on how this patch proceeds. 



Comment at: src/cxa_demangle.cpp:16
+
 #define _LIBCPP_NO_EXCEPTIONS
 

Urg...

Entirely unrelated to this patch, but manually defining `_LIBCPP_NO_EXCEPTIONS` 
here smells awful.



Comment at: src/cxa_demangle.cpp:1848
+//  ::= B  
+
+const char*

I realize the unneeded blank line is part of the existing style... But I 
fudging hate it.

If you're not opposed I would love to start removing the unneeded line wherever 
it's
part of this changeset.



Comment at: src/cxa_demangle.cpp:4353
 //  ::= C3# complete object allocating constructor
 //   extension  ::= C5# ?
 //  ::= D0# deleting destructor

Does this comment need updating now that `` now parses with an 
optional ABI tag at the end?



Comment at: src/cxa_demangle.cpp:4408
 //  ::= Ut [  ] _
 // ::= 
 // 

Does this comment need to be updated to reflect that `` now 
parses with an optional ABI tag after the `_` character?



Comment at: test/test_demangle.pass.cpp:29608
 {"_Z4algoIJiiiEEvZ1gEUlT_E_", "void algo(g::'lambda'(int, 
int, int))"},
+
+{"_Z1fB3foov", "f[abi:foo]()"},

Perhaps it would be better to replace this blank line with a comment stating 
the tests below are for the ABI tag extension?


https://reviews.llvm.org/D40279



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


[PATCH] D29930: Add `__reference_binds_to_temporary` trait for checking safe reference initialization.

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 123741.
EricWF added a comment.

- Address spelling errors pointed out during review.


https://reviews.llvm.org/D29930

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/TokenKinds.def
  include/clang/Basic/TypeTraits.h
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/type-traits.cpp

Index: test/SemaCXX/type-traits.cpp
===
--- test/SemaCXX/type-traits.cpp
+++ test/SemaCXX/type-traits.cpp
@@ -2225,6 +2225,7 @@
 
   // PR25513
   { int arr[F(__is_constructible(int(int)))]; }
+  { int arr[T(__is_constructible(int const &, long))]; }
 
   { int arr[T(__is_constructible(ACompleteType))]; }
   { int arr[T(__is_nothrow_constructible(ACompleteType))]; }
@@ -2275,6 +2276,47 @@
   { int arr[F(__is_trivially_constructible(const volatile void))]; }
 }
 
+template 
+struct ConvertsToRef {
+  operator RefType() const { return static_cast(obj); }
+  mutable T obj = 42;
+};
+
+void reference_binds_to_temporary_checks() {
+  { int arr[F((__reference_binds_to_temporary(int &, int &)))]; }
+  { int arr[F((__reference_binds_to_temporary(int &, int &&)))]; }
+
+  { int arr[F((__reference_binds_to_temporary(int const &, int &)))]; }
+  { int arr[F((__reference_binds_to_temporary(int const &, int const &)))]; }
+  { int arr[F((__reference_binds_to_temporary(int const &, int &&)))]; }
+
+  { int arr[F((__reference_binds_to_temporary(int &, long &)))]; } // doesn't construct
+  { int arr[T((__reference_binds_to_temporary(int const &, long &)))]; }
+  { int arr[T((__reference_binds_to_temporary(int const &, long &&)))]; }
+  { int arr[T((__reference_binds_to_temporary(int &&, long &)))]; }
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = ConvertsToRef;
+  { int arr[T((__is_constructible(int &, LRef)))]; }
+  { int arr[F((__reference_binds_to_temporary(int &, LRef)))]; }
+
+  { int arr[T((__is_constructible(int &&, RRef)))]; }
+  { int arr[F((__reference_binds_to_temporary(int &&, RRef)))]; }
+
+  { int arr[T((__is_constructible(int const &, CLRef)))]; }
+  { int arr[F((__reference_binds_to_temporary(int &&, CLRef)))]; }
+
+  { int arr[T((__is_constructible(int const &, LongRef)))]; }
+  { int arr[T((__reference_binds_to_temporary(int const &, LongRef)))]; }
+
+  // Test that it doesn't accept non-reference types as input.
+  { int arr[F((__reference_binds_to_temporary(int, long)))]; }
+
+  { int arr[T((__reference_binds_to_temporary(const int &, long)))]; }
+}
+
 void array_rank() {
   int t01[T(__array_rank(IntAr) == 1)];
   int t02[T(__array_rank(ConstIntArAr) == 2)];
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4629,11 +4629,14 @@
   if (Kind <= UTT_Last)
 return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
 
-  if (Kind <= BTT_Last)
+  // Evaluate BTT_ReferenceBindsToTemporary alongside the IsConstructible
+  // traits to avoid duplication.
+  if (Kind <= BTT_Last && Kind != BTT_ReferenceBindsToTemporary)
 return EvaluateBinaryTypeTrait(S, Kind, Args[0]->getType(),
Args[1]->getType(), RParenLoc);
 
   switch (Kind) {
+  case clang::BTT_ReferenceBindsToTemporary:
   case clang::TT_IsConstructible:
   case clang::TT_IsNothrowConstructible:
   case clang::TT_IsTriviallyConstructible: {
@@ -4710,6 +4713,13 @@
 if (Kind == clang::TT_IsConstructible)
   return true;
 
+if (Kind == clang::BTT_ReferenceBindsToTemporary) {
+  if (!T->isReferenceType())
+return false;
+
+  return !Init.isDirectReferenceBinding();
+}
+
 if (Kind == clang::TT_IsNothrowConstructible)
   return S.canThrow(Result.get()) == CT_Cannot;
 
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -900,6 +900,7 @@
   REVERTIBLE_TYPE_TRAIT(__is_unsigned);
   REVERTIBLE_TYPE_TRAIT(__is_void);
   REVERTIBLE_TYPE_TRAIT(__is_volatile);
+  REVERTIBLE_TYPE_TRAIT(__reference_binds_to_temporary);
 #undef REVERTIBLE_TYPE_TRAIT
 #undef RTT_JOIN
 }
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -1404,61 +1404,32 @@
   // C++11 attributes
   SourceLocation AttrFixitLoc = Tok.getLocation();
 
-  if (TagType == DeclSpec::TST_struct &&
-  Tok.isNot(tok::identifier) &&
-  !Tok.isAnnotation() &&
-  Tok.getIdentifierInfo() &&
-  Tok.isOneOf(tok::kw___is_abstract,
-  tok::kw___is_aggregate,
-  tok::kw___is_arithmetic,
-  tok::kw___is_array,
-  tok::kw___is_assignable,
-  tok::kw___is_base_of,
-   

[PATCH] D35755: [Solaris] gcc toolchain handling revamp

2017-11-21 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In https://reviews.llvm.org/D35755#931120, @krytarowski wrote:

> Do we still target Oracle Solaris or SmartOS? Just wondering and noted the 
> domain change in e-mail.


Both, I'd say ;-)  They still have much common heritage and the vast majority 
of linker/toolchain work on Illumos derivatives is done by
a single guy, so the various distributions will be the same in this area.  This 
is very much like asking wether to target OS X 10.11 or 10.13.

There will of course be some divergence, but that can be handled when the need 
arrises.


https://reviews.llvm.org/D35755



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


[PATCH] D40285: [MINGW] normalize WIN32 macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell updated this revision to Diff 123747.
martell edited the summary of this revision.
martell added a comment.

[MINGW] normalize WIN32 macros


Repository:
  rL LLVM

https://reviews.llvm.org/D40285

Files:
  lib/Basic/Targets.cpp
  lib/Basic/Targets.h
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/AArch64.h
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/OSTargets.h
  lib/Basic/Targets/X86.h
  test/Preprocessor/predefined-macros.c

Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -193,19 +193,79 @@
 // MSCOPE:#define __OPENCL_MEMORY_SCOPE_WORK_GROUP 1
 // MSCOPE:#define __OPENCL_MEMORY_SCOPE_WORK_ITEM 0
 
+// RUN: %clang_cc1 -triple i386-windows %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-WIN
+
+// CHECK-X86-WIN: #define _WIN32 1
+// CHECK-X86-WIN-NOT: #define _WIN64 1
+// CHECK-X86-WIN-NOT: #define WINNT 1
+// CHECK-X86-WIN-NOT: #define WIN32 1
+// CHECK-X86-WIN-NOT: #define WIN64 1
+
+
+// RUN: %clang_cc1 -triple thumbv7-windows %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-WIN
+
+// CHECK-ARM-WIN: #define _WIN32 1
+// CHECK-ARM-WIN-NOT: #define _WIN64 1
+// CHECK-ARM-WIN-NOT: #define WINNT 1
+// CHECK-ARM-WIN-NOT: #define WIN32 1
+// CHECK-ARM-WIN-NOT: #define WIN64 1
+
+
+// RUN: %clang_cc1 -triple x86_64-windows %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-WIN
+
+// CHECK-AMD64-WIN: #define _WIN32 1
+// CHECK-AMD64-WIN: #define _WIN64 1
+// CHECK-AMD64-WIN-NOT: #define WINNT 1
+// CHECK-AMD64-WIN-NOT: #define WIN32 1
+// CHECK-AMD64-WIN-NOT: #define WIN64 1
+
 // RUN: %clang_cc1 -triple aarch64-windows %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-WIN
 
 // CHECK-ARM64-WIN: #define _M_ARM64 1
 // CHECK-ARM64-WIN: #define _WIN32 1
 // CHECK-ARM64-WIN: #define _WIN64 1
+// CHECK-ARM64-WIN-NOT: #define WINNT 1
+// CHECK-ARM64-WIN-NOT: #define WIN32 1
+// CHECK-ARM64-WIN-NOT: #define WIN64 1
+
+// RUN: %clang_cc1 -triple i686-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-MINGW
+
+// CHECK-X86-MINGW: #define WIN32 1
+// CHECK-X86-MINGW: #define WINNT 1
+// CHECK-X86-MINGW: #define _WIN32 1
+// CHECK-X86-MINGW-NOT: #define WIN64 1
+// CHECK-X86-MINGW-NOT: #define _WIN64 1
+
+// RUN: %clang_cc1 -triple thumbv7-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-MINGW
+
+// CHECK-ARM-MINGW: #define WIN32 1
+// CHECK-ARM-MINGW: #define WINNT 1
+// CHECK-ARM-MINGW: #define _WIN32 1
+// CHECK-ARM-MINGW-NOT: #define WIN64 1
+// CHECK-ARM-MINGW-NOT: #define _WIN64 1
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW
+
+// CHECK-AMD64-MINGW: #define WIN32 1
+// CHECK-AMD64-MINGW: #define WIN64 1
+// CHECK-AMD64-MINGW: #define WINNT 1
+// CHECK-AMD64-MINGW: #define _WIN32 1
+// CHECK-AMD64-MINGW: #define _WIN64 1
 
 // RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
 
 // CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
 // CHECK-ARM64-MINGW: #define WIN32 1
 // CHECK-ARM64-MINGW: #define WIN64 1
+// CHECK-ARM64-MINGW: #define WINNT 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: lib/Basic/Targets/X86.h
===
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -410,11 +410,6 @@
 ? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
 : "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
   }
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  }
 };
 
 // x86-32 Windows Visual Studio target
@@ -451,10 +446,7 @@
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
-DefineStd(Builder, "WIN32", Opts);
-DefineStd(Builder, "WINNT", Opts);
 Builder.defineMacro("_X86_");
-addMinGWDefines(Opts, Builder);
   }
 };
 
@@ -658,12 +650,6 @@
 IntPtrType = SignedLongLong;
   }
 
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-WindowsTargetInfo::getTargetDefines(Opts, Builder);
-Builder.defineMacro("_WIN64");
-  }
-
   BuiltinVaListKind getBuiltinVaListKind() const override {
 return TargetInfo::CharPtrBuiltinVaList;
   }
@@ -726,9 +712,6 @@
   void getTargetDefines(const LangOptions &Opts,
   

[PATCH] D40285: [MINGW] normalize WIN32 macros

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

LGTM




Comment at: test/Preprocessor/predefined-macros.c:200
+// CHECK-X86-WIN: #define _WIN32 1
+// CHECK-X86-WIN-NOT: #define _WIN64 1
+// CHECK-X86-WIN-NOT: #define WINNT 1

In general, these kinds of `-NOT` tests don't work quite as one would want here 
- if the non-wanted `#define _WIN64` would appear before the expected `#define 
_WIN32`, it would actually pass this test. Usually the `-DAG` kinds of checks 
can be used to avoid that issue. Not sure how well it mixes with `-DAG` and 
`-DAG-NOT` though.

Can we assume that these defines appear in alphabetical order? In that case, we 
can be pretty sure to catch the issue if they're reordered slightly. This at 
least clearly documents what is the intended behaviour in any case.


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


r318750 - [Analyzer] Non-determinism: stable iteration on indirect goto LabelDecl's

2017-11-21 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Tue Nov 21 03:05:28 2017
New Revision: 318750

URL: http://llvm.org/viewvc/llvm-project?rev=318750&view=rev
Log:
[Analyzer] Non-determinism: stable iteration on indirect goto LabelDecl's

CFG wass built in non-deterministic order due to the fact that indirect
goto labels' declarations (LabelDecl's) are stored in the llvm::SmallSet
container. LabelDecl's are pointers, whose order is not deterministic,
and llvm::SmallSet sorts them by their non-deterministic addresses after
"small" container is exceeded. This leads to non-deterministic processing
of the elements of the container.

The fix is to use llvm::SmallSetVector that was designed to have 
deterministic iteration order.

Patch by Ilya Palachev!

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



Added:
cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=318750&r1=318749&r2=318750&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 21 03:05:28 2017
@@ -58,7 +58,7 @@ namespace clang {
 QualType VisitExtVectorType(const ExtVectorType *T);
 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
 QualType VisitFunctionProtoType(const FunctionProtoType *T);
-// FIXME: UnresolvedUsingType
+QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T);
 QualType VisitParenType(const ParenType *T);
 QualType VisitTypedefType(const TypedefType *T);
 QualType VisitTypeOfExprType(const TypeOfExprType *T);
@@ -129,8 +129,8 @@ namespace clang {
 TemplateParameterList *ImportTemplateParameterList(
  TemplateParameterList 
*Params);
 TemplateArgument ImportTemplateArgument(const TemplateArgument &From);
-TemplateArgumentLoc ImportTemplateArgumentLoc(
-const TemplateArgumentLoc &TALoc, bool &Error);
+Optional ImportTemplateArgumentLoc(
+const TemplateArgumentLoc &TALoc);
 bool ImportTemplateArguments(const TemplateArgument *FromArgs,
  unsigned NumFromArgs,
SmallVectorImpl &ToArgs);
@@ -143,10 +143,12 @@ namespace clang {
 bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
 bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
 Decl *VisitDecl(Decl *D);
+Decl *VisitEmptyDecl(EmptyDecl *D);
 Decl *VisitAccessSpecDecl(AccessSpecDecl *D);
 Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
 Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D);
 Decl *VisitNamespaceDecl(NamespaceDecl *D);
+Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
 Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
 Decl *VisitTypedefDecl(TypedefDecl *D);
 Decl *VisitTypeAliasDecl(TypeAliasDecl *D);
@@ -172,6 +174,12 @@ namespace clang {
 Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D);
 Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
 Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D);
+Decl *VisitUsingDecl(UsingDecl *D);
+Decl *VisitUsingShadowDecl(UsingShadowDecl *D);
+Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
+Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
+Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
+
 
 ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list);
 Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
@@ -569,6 +577,22 @@ QualType ASTNodeImporter::VisitFunctionP
   return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, 
ToEPI);
 }
 
+QualType ASTNodeImporter::VisitUnresolvedUsingType(
+const UnresolvedUsingType *T) {
+  UnresolvedUsingTypenameDecl *ToD = cast_or_null(
+Importer.Import(T->getDecl()));
+  if (!ToD)
+return QualType();
+
+  UnresolvedUsingTypenameDecl *ToPrevD =
+  cast_or_null(
+Importer.Import(T->getDecl()->getPreviousDecl()));
+  if (!ToPrevD && T->getDecl()->getPreviousDecl())
+return QualType();
+
+  return Importer.getToContext().getTypeDeclType(ToD, ToPrevD);
+}
+
 QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
   QualType ToInnerType = Importer.Import(T->getInnerType());
   if (ToInnerType.isNull())
@@ -1183,9 +1207,8 @@ ASTNodeImporter::ImportTemplateArgument(
   llvm_unreachable("Invalid template argument kind");
 }
 
-TemplateArgumentLoc ASTNodeImporter::ImportTemplateArgumentLoc(
-const TemplateArgumentLoc &TALoc, bool &Error) {
-  Error = false;
+Optional
+ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) {
   TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument());
   TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo

[PATCH] D40073: [Analyzer] Non-determinism: don't sort indirect goto LabelDecl's by addresses

2017-11-21 Thread Aleksei Sidorin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318750: [Analyzer] Non-determinism: stable iteration on 
indirect goto LabelDecl's (authored by a.sidorin).

Changed prior to commit:
  https://reviews.llvm.org/D40073?vs=123558&id=123750#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40073

Files:
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp

Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -58,7 +58,7 @@
 QualType VisitExtVectorType(const ExtVectorType *T);
 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
 QualType VisitFunctionProtoType(const FunctionProtoType *T);
-// FIXME: UnresolvedUsingType
+QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T);
 QualType VisitParenType(const ParenType *T);
 QualType VisitTypedefType(const TypedefType *T);
 QualType VisitTypeOfExprType(const TypeOfExprType *T);
@@ -129,8 +129,8 @@
 TemplateParameterList *ImportTemplateParameterList(
  TemplateParameterList *Params);
 TemplateArgument ImportTemplateArgument(const TemplateArgument &From);
-TemplateArgumentLoc ImportTemplateArgumentLoc(
-const TemplateArgumentLoc &TALoc, bool &Error);
+Optional ImportTemplateArgumentLoc(
+const TemplateArgumentLoc &TALoc);
 bool ImportTemplateArguments(const TemplateArgument *FromArgs,
  unsigned NumFromArgs,
SmallVectorImpl &ToArgs);
@@ -143,10 +143,12 @@
 bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
 bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
 Decl *VisitDecl(Decl *D);
+Decl *VisitEmptyDecl(EmptyDecl *D);
 Decl *VisitAccessSpecDecl(AccessSpecDecl *D);
 Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
 Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D);
 Decl *VisitNamespaceDecl(NamespaceDecl *D);
+Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
 Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
 Decl *VisitTypedefDecl(TypedefDecl *D);
 Decl *VisitTypeAliasDecl(TypeAliasDecl *D);
@@ -172,6 +174,12 @@
 Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D);
 Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
 Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D);
+Decl *VisitUsingDecl(UsingDecl *D);
+Decl *VisitUsingShadowDecl(UsingShadowDecl *D);
+Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
+Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
+Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
+
 
 ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list);
 Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
@@ -569,6 +577,22 @@
   return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI);
 }
 
+QualType ASTNodeImporter::VisitUnresolvedUsingType(
+const UnresolvedUsingType *T) {
+  UnresolvedUsingTypenameDecl *ToD = cast_or_null(
+Importer.Import(T->getDecl()));
+  if (!ToD)
+return QualType();
+
+  UnresolvedUsingTypenameDecl *ToPrevD =
+  cast_or_null(
+Importer.Import(T->getDecl()->getPreviousDecl()));
+  if (!ToPrevD && T->getDecl()->getPreviousDecl())
+return QualType();
+
+  return Importer.getToContext().getTypeDeclType(ToD, ToPrevD);
+}
+
 QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
   QualType ToInnerType = Importer.Import(T->getInnerType());
   if (ToInnerType.isNull())
@@ -1183,22 +1207,21 @@
   llvm_unreachable("Invalid template argument kind");
 }
 
-TemplateArgumentLoc ASTNodeImporter::ImportTemplateArgumentLoc(
-const TemplateArgumentLoc &TALoc, bool &Error) {
-  Error = false;
+Optional
+ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) {
   TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument());
   TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
   TemplateArgumentLocInfo ToInfo;
   if (Arg.getKind() == TemplateArgument::Expression) {
 Expr *E = Importer.Import(FromInfo.getAsExpr());
 ToInfo = TemplateArgumentLocInfo(E);
 if (!E)
-  Error = true;
+  return None;
   } else if (Arg.getKind() == TemplateArgument::Type) {
 if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo()))
   ToInfo = TemplateArgumentLocInfo(TSI);
 else
-  Error = true;
+  return None;
   } else {
 ToInfo = TemplateArgumentLocInfo(
   Importer.Import(FromInfo.getTemplateQualifierLoc()),
@@ -1288,6 +1311,28 @@
   return nullptr;
 }
 
+Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) {
+  // Import the context of this declaration.
+  DeclContext *DC = Importer.ImportContex

[PATCH] D40285: [MINGW] normalize WIN32 macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell updated this revision to Diff 123751.
martell added a comment.

reorder test checks


Repository:
  rL LLVM

https://reviews.llvm.org/D40285

Files:
  lib/Basic/Targets.cpp
  lib/Basic/Targets.h
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/AArch64.h
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/OSTargets.h
  lib/Basic/Targets/X86.h
  test/Preprocessor/predefined-macros.c

Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -193,19 +193,77 @@
 // MSCOPE:#define __OPENCL_MEMORY_SCOPE_WORK_GROUP 1
 // MSCOPE:#define __OPENCL_MEMORY_SCOPE_WORK_ITEM 0
 
+// RUN: %clang_cc1 -triple i386-windows %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-WIN
+
+// CHECK-X86-WIN-NOT: #define WIN32 1
+// CHECK-X86-WIN-NOT: #define WIN64 1
+// CHECK-X86-WIN-NOT: #define WINNT 1
+// CHECK-X86-WIN: #define _WIN32 1
+// CHECK-X86-WIN-NOT: #define _WIN64 1
+
+// RUN: %clang_cc1 -triple thumbv7-windows %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-WIN
+
+// CHECK-ARM-WIN-NOT: #define WIN32 1
+// CHECK-ARM-WIN-NOT: #define WIN64 1
+// CHECK-ARM-WIN-NOT: #define WINNT 1
+// CHECK-ARM-WIN: #define _WIN32 1
+// CHECK-ARM-WIN-NOT: #define _WIN64 1
+
+// RUN: %clang_cc1 -triple x86_64-windows %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-WIN
+
+// CHECK-AMD64-WIN-NOT: #define WIN32 1
+// CHECK-AMD64-WIN-NOT: #define WIN64 1
+// CHECK-AMD64-WIN-NOT: #define WINNT 1
+// CHECK-AMD64-WIN: #define _WIN32 1
+// CHECK-AMD64-WIN: #define _WIN64 1
+
 // RUN: %clang_cc1 -triple aarch64-windows %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-WIN
 
+// CHECK-ARM64-WIN-NOT: #define WIN32 1
+// CHECK-ARM64-WIN-NOT: #define WIN64 1
+// CHECK-ARM64-WIN-NOT: #define WINNT 1
 // CHECK-ARM64-WIN: #define _M_ARM64 1
 // CHECK-ARM64-WIN: #define _WIN32 1
 // CHECK-ARM64-WIN: #define _WIN64 1
 
+// RUN: %clang_cc1 -triple i686-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-MINGW
+
+// CHECK-X86-MINGW: #define WIN32 1
+// CHECK-X86-MINGW-NOT: #define WIN64 1
+// CHECK-X86-MINGW: #define WINNT 1
+// CHECK-X86-MINGW: #define _WIN32 1
+// CHECK-X86-MINGW-NOT: #define _WIN64 1
+
+// RUN: %clang_cc1 -triple thumbv7-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-MINGW
+
+// CHECK-ARM-MINGW: #define WIN32 1
+// CHECK-ARM-MINGW-NOT: #define WIN64 1
+// CHECK-ARM-MINGW: #define WINNT 1
+// CHECK-ARM-MINGW: #define _WIN32 1
+// CHECK-ARM-MINGW-NOT: #define _WIN64 1
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW
+
+// CHECK-AMD64-MINGW: #define WIN32 1
+// CHECK-AMD64-MINGW: #define WIN64 1
+// CHECK-AMD64-MINGW: #define WINNT 1
+// CHECK-AMD64-MINGW: #define _WIN32 1
+// CHECK-AMD64-MINGW: #define _WIN64 1
+
 // RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
 
 // CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
 // CHECK-ARM64-MINGW: #define WIN32 1
 // CHECK-ARM64-MINGW: #define WIN64 1
+// CHECK-ARM64-MINGW: #define WINNT 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: lib/Basic/Targets/X86.h
===
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -410,11 +410,6 @@
 ? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
 : "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
   }
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  }
 };
 
 // x86-32 Windows Visual Studio target
@@ -451,10 +446,7 @@
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
-DefineStd(Builder, "WIN32", Opts);
-DefineStd(Builder, "WINNT", Opts);
 Builder.defineMacro("_X86_");
-addMinGWDefines(Opts, Builder);
   }
 };
 
@@ -658,12 +650,6 @@
 IntPtrType = SignedLongLong;
   }
 
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-WindowsTargetInfo::getTargetDefines(Opts, Builder);
-Builder.defineMacro("_WIN64");
-  }
-
   BuiltinVaListKind getBuiltinVaListKind() const override {
 return TargetInfo::CharPtrBuiltinVaList;
   }
@@ -726,9 +712,6 @@
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 W

[PATCH] D40285: [MINGW] normalize WIN32 macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.

@mstorsjo can you confirm this new order looks good to you?


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


r318752 - [CodeGen] Generate TBAA type descriptors in a more reliable manner

2017-11-21 Thread Ivan A. Kosarev via cfe-commits
Author: kosarev
Date: Tue Nov 21 03:18:06 2017
New Revision: 318752

URL: http://llvm.org/viewvc/llvm-project?rev=318752&view=rev
Log:
[CodeGen] Generate TBAA type descriptors in a more reliable manner

This patch introduces a couple of helper functions that make it
possible to handle the caching logic in a single place.

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
cfe/trunk/lib/CodeGen/CodeGenTBAA.h

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=318752&r1=318751&r2=318752&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Tue Nov 21 03:18:06 2017
@@ -107,29 +107,7 @@ static bool isValidBaseType(QualType QTy
   return false;
 }
 
-llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
-  // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
-  if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
-return nullptr;
-
-  // If the type has the may_alias attribute (even on a typedef), it is
-  // effectively in the general char alias class.
-  if (TypeHasMayAlias(QTy))
-return getChar();
-
-  // We need this function to not fall back to returning the "omnipotent char"
-  // type node for aggregate and union types. Otherwise, any dereference of an
-  // aggregate will result into the may-alias access descriptor, meaning all
-  // subsequent accesses to direct and indirect members of that aggregate will
-  // be considered may-alias too.
-  // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
-  if (isValidBaseType(QTy))
-return getBaseTypeInfo(QTy);
-
-  const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-  if (llvm::MDNode *N = MetadataCache[Ty])
-return N;
-
+llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
   // Handle builtin types.
   if (const BuiltinType *BTy = dyn_cast(Ty)) {
 switch (BTy->getKind()) {
@@ -160,8 +138,7 @@ llvm::MDNode *CodeGenTBAA::getTypeInfo(Q
 // treating wchar_t, char16_t, and char32_t as distinct from their
 // "underlying types".
 default:
-  return MetadataCache[Ty] =
-createTBAAScalarType(BTy->getName(Features), getChar());
+  return createTBAAScalarType(BTy->getName(Features), getChar());
 }
   }
 
@@ -169,14 +146,13 @@ llvm::MDNode *CodeGenTBAA::getTypeInfo(Q
   // an object through a glvalue of other than one of the following types the
   // behavior is undefined: [...] a char, unsigned char, or std::byte type."
   if (Ty->isStdByteType())
-return MetadataCache[Ty] = getChar();
+return getChar();
 
   // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
   if (Ty->isPointerType() || Ty->isReferenceType())
-return MetadataCache[Ty] = createTBAAScalarType("any pointer",
-getChar());
+return createTBAAScalarType("any pointer", getChar());
 
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
@@ -186,16 +162,46 @@ llvm::MDNode *CodeGenTBAA::getTypeInfo(Q
 // TODO: Is there a way to get a program-wide unique name for a
 // decl with local linkage or no linkage?
 if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
-  return MetadataCache[Ty] = getChar();
+  return getChar();
 
 SmallString<256> OutName;
 llvm::raw_svector_ostream Out(OutName);
 MContext.mangleTypeName(QualType(ETy, 0), Out);
-return MetadataCache[Ty] = createTBAAScalarType(OutName, getChar());
+return createTBAAScalarType(OutName, getChar());
   }
 
   // For now, handle any other kind of type conservatively.
-  return MetadataCache[Ty] = getChar();
+  return getChar();
+}
+
+llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
+  // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
+  if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
+return nullptr;
+
+  // If the type has the may_alias attribute (even on a typedef), it is
+  // effectively in the general char alias class.
+  if (TypeHasMayAlias(QTy))
+return getChar();
+
+  // We need this function to not fall back to returning the "omnipotent char"
+  // type node for aggregate and union types. Otherwise, any dereference of an
+  // aggregate will result into the may-alias access descriptor, meaning all
+  // subsequent accesses to direct and indirect members of that aggregate will
+  // be considered may-alias too.
+  // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
+  if (isValidBaseType(QTy))
+return getBaseTypeInfo(QTy);
+
+  const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
+  if (llvm::MDNo

[PATCH] D40285: [MINGW] normalize WIN32 macros

2017-11-21 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.

LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D40285



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


[PATCH] D39953: [CodeGen] Generate TBAA type descriptors in a more reliable manner

2017-11-21 Thread Ivan Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318752: [CodeGen] Generate TBAA type descriptors in a more 
reliable manner (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D39953?vs=123563&id=123754#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39953

Files:
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/lib/CodeGen/CodeGenTBAA.h

Index: cfe/trunk/lib/CodeGen/CodeGenTBAA.h
===
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.h
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.h
@@ -143,6 +143,14 @@
   /// pointer to another node in the type DAG.
   llvm::MDNode *createTBAAScalarType(StringRef Name, llvm::MDNode *Parent);
 
+  /// getTypeInfoHelper - An internal helper function to generate metadata used
+  /// to describe accesses to objects of the given type.
+  llvm::MDNode *getTypeInfoHelper(const Type *Ty);
+
+  /// getBaseTypeInfoHelper - An internal helper function to generate metadata
+  /// used to describe accesses to objects of the given base type.
+  llvm::MDNode *getBaseTypeInfoHelper(const Type *Ty);
+
 public:
   CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext,
   const CodeGenOptions &CGO,
Index: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
@@ -107,29 +107,7 @@
   return false;
 }
 
-llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
-  // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
-  if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
-return nullptr;
-
-  // If the type has the may_alias attribute (even on a typedef), it is
-  // effectively in the general char alias class.
-  if (TypeHasMayAlias(QTy))
-return getChar();
-
-  // We need this function to not fall back to returning the "omnipotent char"
-  // type node for aggregate and union types. Otherwise, any dereference of an
-  // aggregate will result into the may-alias access descriptor, meaning all
-  // subsequent accesses to direct and indirect members of that aggregate will
-  // be considered may-alias too.
-  // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
-  if (isValidBaseType(QTy))
-return getBaseTypeInfo(QTy);
-
-  const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-  if (llvm::MDNode *N = MetadataCache[Ty])
-return N;
-
+llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
   // Handle builtin types.
   if (const BuiltinType *BTy = dyn_cast(Ty)) {
 switch (BTy->getKind()) {
@@ -160,23 +138,21 @@
 // treating wchar_t, char16_t, and char32_t as distinct from their
 // "underlying types".
 default:
-  return MetadataCache[Ty] =
-createTBAAScalarType(BTy->getName(Features), getChar());
+  return createTBAAScalarType(BTy->getName(Features), getChar());
 }
   }
 
   // C++1z [basic.lval]p10: "If a program attempts to access the stored value of
   // an object through a glvalue of other than one of the following types the
   // behavior is undefined: [...] a char, unsigned char, or std::byte type."
   if (Ty->isStdByteType())
-return MetadataCache[Ty] = getChar();
+return getChar();
 
   // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
   if (Ty->isPointerType() || Ty->isReferenceType())
-return MetadataCache[Ty] = createTBAAScalarType("any pointer",
-getChar());
+return createTBAAScalarType("any pointer", getChar());
 
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
@@ -186,16 +162,46 @@
 // TODO: Is there a way to get a program-wide unique name for a
 // decl with local linkage or no linkage?
 if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
-  return MetadataCache[Ty] = getChar();
+  return getChar();
 
 SmallString<256> OutName;
 llvm::raw_svector_ostream Out(OutName);
 MContext.mangleTypeName(QualType(ETy, 0), Out);
-return MetadataCache[Ty] = createTBAAScalarType(OutName, getChar());
+return createTBAAScalarType(OutName, getChar());
   }
 
   // For now, handle any other kind of type conservatively.
-  return MetadataCache[Ty] = getChar();
+  return getChar();
+}
+
+llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
+  // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
+  if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
+return nullptr;
+
+  // If the type has the may_alias attribute (even on a typedef), it is
+  // effectively in the general char alias class.
+  if (TypeHasMayAlias(QTy))
+return getChar();
+
+  // We need this function to not fall back to returni

r318753 - [Analyzer] Revert r318750 because incorrect files were added for commit.

2017-11-21 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Tue Nov 21 03:20:07 2017
New Revision: 318753

URL: http://llvm.org/viewvc/llvm-project?rev=318753&view=rev
Log:
[Analyzer] Revert r318750 because incorrect files were added for commit.

Sorry for the noise.


Removed:
cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=318753&r1=318752&r2=318753&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 21 03:20:07 2017
@@ -58,7 +58,7 @@ namespace clang {
 QualType VisitExtVectorType(const ExtVectorType *T);
 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
 QualType VisitFunctionProtoType(const FunctionProtoType *T);
-QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T);
+// FIXME: UnresolvedUsingType
 QualType VisitParenType(const ParenType *T);
 QualType VisitTypedefType(const TypedefType *T);
 QualType VisitTypeOfExprType(const TypeOfExprType *T);
@@ -129,8 +129,8 @@ namespace clang {
 TemplateParameterList *ImportTemplateParameterList(
  TemplateParameterList 
*Params);
 TemplateArgument ImportTemplateArgument(const TemplateArgument &From);
-Optional ImportTemplateArgumentLoc(
-const TemplateArgumentLoc &TALoc);
+TemplateArgumentLoc ImportTemplateArgumentLoc(
+const TemplateArgumentLoc &TALoc, bool &Error);
 bool ImportTemplateArguments(const TemplateArgument *FromArgs,
  unsigned NumFromArgs,
SmallVectorImpl &ToArgs);
@@ -143,12 +143,10 @@ namespace clang {
 bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
 bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
 Decl *VisitDecl(Decl *D);
-Decl *VisitEmptyDecl(EmptyDecl *D);
 Decl *VisitAccessSpecDecl(AccessSpecDecl *D);
 Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
 Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D);
 Decl *VisitNamespaceDecl(NamespaceDecl *D);
-Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
 Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
 Decl *VisitTypedefDecl(TypedefDecl *D);
 Decl *VisitTypeAliasDecl(TypeAliasDecl *D);
@@ -174,12 +172,6 @@ namespace clang {
 Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D);
 Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
 Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D);
-Decl *VisitUsingDecl(UsingDecl *D);
-Decl *VisitUsingShadowDecl(UsingShadowDecl *D);
-Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
-Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
-Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
-
 
 ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list);
 Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
@@ -577,22 +569,6 @@ QualType ASTNodeImporter::VisitFunctionP
   return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, 
ToEPI);
 }
 
-QualType ASTNodeImporter::VisitUnresolvedUsingType(
-const UnresolvedUsingType *T) {
-  UnresolvedUsingTypenameDecl *ToD = cast_or_null(
-Importer.Import(T->getDecl()));
-  if (!ToD)
-return QualType();
-
-  UnresolvedUsingTypenameDecl *ToPrevD =
-  cast_or_null(
-Importer.Import(T->getDecl()->getPreviousDecl()));
-  if (!ToPrevD && T->getDecl()->getPreviousDecl())
-return QualType();
-
-  return Importer.getToContext().getTypeDeclType(ToD, ToPrevD);
-}
-
 QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
   QualType ToInnerType = Importer.Import(T->getInnerType());
   if (ToInnerType.isNull())
@@ -1207,8 +1183,9 @@ ASTNodeImporter::ImportTemplateArgument(
   llvm_unreachable("Invalid template argument kind");
 }
 
-Optional
-ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) {
+TemplateArgumentLoc ASTNodeImporter::ImportTemplateArgumentLoc(
+const TemplateArgumentLoc &TALoc, bool &Error) {
+  Error = false;
   TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument());
   TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
   TemplateArgumentLocInfo ToInfo;
@@ -1216,12 +1193,12 @@ ASTNodeImporter::ImportTemplateArgumentL
 Expr *E = Importer.Import(FromInfo.getAsExpr());
 ToInfo = TemplateArgumentLocInfo(E);
 if (!E)
-  return None;
+  Error = true;
   } else if (Arg.getKind() == TemplateArgument::Type) {
 if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo()))
   ToInfo = TemplateArgumentLocInfo(TSI);
 else
-  return None;
+  Error = true;
   } else {
 ToInfo = TemplateArgumentLocInfo(
   Impor

[PATCH] D40073: [Analyzer] Non-determinism: don't sort indirect goto LabelDecl's by addresses

2017-11-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Thank you for the patch!~

In https://reviews.llvm.org/D40073#930470, @a.sidorin wrote:

> By the way, is there a common way to write tests for non-determinism for LLVM 
> test suite?


I guess the most recent update on this subject is in this thread: 
https://lists.llvm.org/pipermail/llvm-dev/2017-July/115025.html


Repository:
  rL LLVM

https://reviews.llvm.org/D40073



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


[PATCH] D40256: [ARM] disable FPU features when using soft floating point.

2017-11-21 Thread Keith Walker via Phabricator via cfe-commits
keith.walker.arm added inline comments.



Comment at: lib/Driver/ToolChains/Arch/ARM.cpp:406
+const bool HasVFPv4  = (std::find(ItBegin, ItEnd, "+vfpv4") != ItEnd);
+const bool HasFParmv8  = (std::find(ItBegin, ItEnd, "+fp-armv8") != ItEnd);
+const bool HasFullFP16  = (std::find(ItBegin, ItEnd, "+fullfp16") != 
ItEnd);

efriedma wrote:
> I don't like explicitly enumerating the features like this; it'll mess up if 
> there's ever a new feature which isn't explicitly enumerated here.  Can we 
> just do `Features.push_back("-vfpv2")` and depend on that to implicitly 
> disable all the other vfp features?
I'll check on whether disabling a feature on which other features depend 
automatically disables the other features is something that can be relied upon 
(It would seem sensible that one could  but need to check).

That would certainly mean the code could be simplified, although I would also 
need to check the impact on the what is checked in the testing (only test for 
the base feature being disabled because the dependent features are 
automatically disabled).



Comment at: lib/Driver/ToolChains/Arch/ARM.cpp:419
+Features.push_back("-fullfp16");
+
+const bool HasNeon  = (std::find(ItBegin, ItEnd, "+neon") != ItEnd);

compnerd wrote:
> It would be nice to not have these explicitly listed.  But at the very least, 
> I think that having a list and looping through it would be better:
> 
> for (const auto Feature : {"vfpv2", "vfpv3", "vfpv4", "fp-armv8", 
> "fullfp16"})
>   if (std::find(std::begin(Features), std::end(Features), "+" + Feature) 
> == std::end(Features))
> continue;
>   else
> Features.push_back("-" + Feature);
This certainly looks a better way to do it if we do need to provide a list of 
features rather than relying on disabling a base feature on which the other 
features depend. 


https://reviews.llvm.org/D40256



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


r318754 - [Analyzer] Stable iteration on indirect goto LabelDecl's to avoid non-determinism (attempt 2)

2017-11-21 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Tue Nov 21 03:27:47 2017
New Revision: 318754

URL: http://llvm.org/viewvc/llvm-project?rev=318754&view=rev
Log:
[Analyzer] Stable iteration on indirect goto LabelDecl's to avoid 
non-determinism (attempt 2)

CFG wass built in non-deterministic order due to the fact that indirect
goto labels' declarations (LabelDecl's) are stored in the llvm::SmallSet
container. LabelDecl's are pointers, whose order is not deterministic,
and llvm::SmallSet sorts them by their non-deterministic addresses after
"small" container is exceeded. This leads to non-deterministic processing
of the elements of the container.

The fix is to use llvm::SmallSetVector that was designed to have
deterministic iteration order.

Patch by Ilya Palachev!

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


Added:
cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp
Modified:
cfe/trunk/lib/Analysis/CFG.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=318754&r1=318753&r2=318754&view=diff
==
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Nov 21 03:27:47 2017
@@ -420,7 +420,7 @@ class CFGBuilder {
   BackpatchBlocksTy BackpatchBlocks;
 
   // A list of labels whose address has been taken (for indirect gotos).
-  typedef llvm::SmallPtrSet LabelSetTy;
+  typedef llvm::SmallSetVector LabelSetTy;
   LabelSetTy AddressTakenLabels;
 
   bool badCFG;

Added: cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp?rev=318754&view=auto
==
--- cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp (added)
+++ cfe/trunk/test/Analysis/cfg-indirect-goto-determinism.cpp Tue Nov 21 
03:27:47 2017
@@ -0,0 +1,96 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG %s 2>&1 | FileCheck 
%s
+
+void *target;
+int indirectBlockSuccessorDeterminism() {
+(void)&&L1;
+(void)&&L2;
+(void)&&L3;
+(void)&&L4;
+(void)&&L5;
+(void)&&L6;
+(void)&&L7;
+(void)&&L8;
+(void)&&L9;
+(void)&&L10;
+(void)&&L11;
+(void)&&L12;
+(void)&&L13;
+(void)&&L14;
+(void)&&L15;
+(void)&&L16;
+(void)&&L17;
+(void)&&L18;
+(void)&&L19;
+(void)&&L20;
+(void)&&L21;
+(void)&&L22;
+(void)&&L23;
+(void)&&L24;
+(void)&&L25;
+(void)&&L26;
+(void)&&L27;
+(void)&&L28;
+(void)&&L29;
+(void)&&L30;
+(void)&&L31;
+(void)&&L32;
+(void)&&L33;
+(void)&&L34;
+(void)&&L35;
+(void)&&L36;
+(void)&&L37;
+(void)&&L38;
+(void)&&L39;
+(void)&&L40;
+
+goto *target;
+  L1:
+  L2:
+  L3:
+  L4:
+  L5:
+  L6:
+  L7:
+  L8:
+  L9:
+  L10:
+  L11:
+  L12:
+  L13:
+  L14:
+  L15:
+  L16:
+  L17:
+  L18:
+  L19:
+  L20:
+  L21:
+  L22:
+  L23:
+  L24:
+  L25:
+  L26:
+  L27:
+  L28:
+  L29:
+  L30:
+  L31:
+  L32:
+  L33:
+  L34:
+  L35:
+  L36:
+  L37:
+  L38:
+  L39:
+  L40:
+return 0;
+}
+
+// CHECK-LABEL:  [B41 (INDIRECT GOTO DISPATCH)]
+// CHECK-NEXT:   Preds (1): B42
+// CHECK-NEXT:  Succs (40): B1 B2 B3 B4 B5 B6 B7 B8
+// CHECK-NEXT:   B9 B10 B11 B12 B13 B14 B15 B16 B17 B18
+// CHECK-NEXT:   B19 B20 B21 B22 B23 B24 B25 B26 B27 B28
+// CHECK-NEXT:   B29 B30 B31 B32 B33 B34 B35 B36 B37 B38
+// CHECK-NEXT:   B39 B40


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


r318755 - [MINGW] normalize WIN32 macros

2017-11-21 Thread Martell Malone via cfe-commits
Author: martell
Date: Tue Nov 21 03:28:29 2017
New Revision: 318755

URL: http://llvm.org/viewvc/llvm-project?rev=318755&view=rev
Log:
[MINGW] normalize WIN32 macros

move _WIN64 and _WIN32 defines to lib/Basic/Targets/OSTargets.h
move WIN32, WIN64 and __MINGW64__ to addMinGWDefines

fixes __MINGW64__ not being defined for aarch64
adds WIN32 definition for x64

Reviewers: mstorsjo

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Basic/Targets.h
cfe/trunk/lib/Basic/Targets/AArch64.cpp
cfe/trunk/lib/Basic/Targets/AArch64.h
cfe/trunk/lib/Basic/Targets/ARM.cpp
cfe/trunk/lib/Basic/Targets/OSTargets.h
cfe/trunk/lib/Basic/Targets/X86.h
cfe/trunk/test/Preprocessor/predefined-macros.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=318755&r1=318754&r2=318755&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Nov 21 03:28:29 2017
@@ -97,7 +97,14 @@ void addCygMingDefines(const LangOptions
   }
 }
 
-void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder) {
+void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts,
+ MacroBuilder &Builder) {
+  DefineStd(Builder, "WIN32", Opts);
+  DefineStd(Builder, "WINNT", Opts);
+  if (Triple.isArch64Bit()) {
+DefineStd(Builder, "WIN64", Opts);
+Builder.defineMacro("__MINGW64__");
+  }
   Builder.defineMacro("__MSVCRT__");
   Builder.defineMacro("__MINGW32__");
   addCygMingDefines(Opts, Builder);

Modified: cfe/trunk/lib/Basic/Targets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.h?rev=318755&r1=318754&r2=318755&view=diff
==
--- cfe/trunk/lib/Basic/Targets.h (original)
+++ cfe/trunk/lib/Basic/Targets.h Tue Nov 21 03:28:29 2017
@@ -40,7 +40,7 @@ void defineCPUMacros(clang::MacroBuilder
  bool Tuning = true);
 
 LLVM_LIBRARY_VISIBILITY
-void addMinGWDefines(const clang::LangOptions &Opts,
+void addMinGWDefines(const llvm::Triple &Triple, const clang::LangOptions 
&Opts,
  clang::MacroBuilder &Builder);
 
 LLVM_LIBRARY_VISIBILITY

Modified: cfe/trunk/lib/Basic/Targets/AArch64.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.cpp?rev=318755&r1=318754&r2=318755&view=diff
==
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp Tue Nov 21 03:28:29 2017
@@ -474,8 +474,6 @@ MicrosoftARM64TargetInfo::MicrosoftARM64
 void MicrosoftARM64TargetInfo::getVisualStudioDefines(
 const LangOptions &Opts, MacroBuilder &Builder) const {
   WindowsTargetInfo::getVisualStudioDefines(Opts, 
Builder);
-  Builder.defineMacro("_WIN32", "1");
-  Builder.defineMacro("_WIN64", "1");
   Builder.defineMacro("_M_ARM64", "1");
 }
 
@@ -491,17 +489,6 @@ MinGWARM64TargetInfo::MinGWARM64TargetIn
   TheCXXABI.set(TargetCXXABI::GenericAArch64);
 }
 
-void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const {
-  WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
-  Builder.defineMacro("_WIN64", "1");
-  Builder.defineMacro("WIN32", "1");
-  Builder.defineMacro("WIN64", "1");
-  addMinGWDefines(Opts, Builder);
-}
-
-
 DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : DarwinTargetInfo(Triple, Opts) {

Modified: cfe/trunk/lib/Basic/Targets/AArch64.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.h?rev=318755&r1=318754&r2=318755&view=diff
==
--- cfe/trunk/lib/Basic/Targets/AArch64.h (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.h Tue Nov 21 03:28:29 2017
@@ -122,9 +122,6 @@ class LLVM_LIBRARY_VISIBILITY MinGWARM64
 : public WindowsARM64TargetInfo {
 public:
   MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {

Modified: cfe/trunk/lib/Basic/Targets/ARM.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/ARM.cpp?rev=318755&r1=318754&r2=318755&view=diff
==
--- cfe/trunk/lib/Basic/Targets/ARM.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/ARM.cpp Tue Nov 21 03:28:29 2017
@@ -999,11 +999,8 @@ MinGWARMTargetInfo::MinGWARMT

[PATCH] D40285: [MINGW] normalize WIN32 macros

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318755: [MINGW] normalize WIN32 macros (authored by martell).

Changed prior to commit:
  https://reviews.llvm.org/D40285?vs=123751&id=123755#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40285

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/Basic/Targets.h
  cfe/trunk/lib/Basic/Targets/AArch64.cpp
  cfe/trunk/lib/Basic/Targets/AArch64.h
  cfe/trunk/lib/Basic/Targets/ARM.cpp
  cfe/trunk/lib/Basic/Targets/OSTargets.h
  cfe/trunk/lib/Basic/Targets/X86.h
  cfe/trunk/test/Preprocessor/predefined-macros.c

Index: cfe/trunk/lib/Basic/Targets.h
===
--- cfe/trunk/lib/Basic/Targets.h
+++ cfe/trunk/lib/Basic/Targets.h
@@ -40,7 +40,7 @@
  bool Tuning = true);
 
 LLVM_LIBRARY_VISIBILITY
-void addMinGWDefines(const clang::LangOptions &Opts,
+void addMinGWDefines(const llvm::Triple &Triple, const clang::LangOptions &Opts,
  clang::MacroBuilder &Builder);
 
 LLVM_LIBRARY_VISIBILITY
Index: cfe/trunk/lib/Basic/Targets/AArch64.cpp
===
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp
@@ -474,8 +474,6 @@
 void MicrosoftARM64TargetInfo::getVisualStudioDefines(
 const LangOptions &Opts, MacroBuilder &Builder) const {
   WindowsTargetInfo::getVisualStudioDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
-  Builder.defineMacro("_WIN64", "1");
   Builder.defineMacro("_M_ARM64", "1");
 }
 
@@ -491,17 +489,6 @@
   TheCXXABI.set(TargetCXXABI::GenericAArch64);
 }
 
-void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const {
-  WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
-  Builder.defineMacro("_WIN64", "1");
-  Builder.defineMacro("WIN32", "1");
-  Builder.defineMacro("WIN64", "1");
-  addMinGWDefines(Opts, Builder);
-}
-
-
 DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : DarwinTargetInfo(Triple, Opts) {
Index: cfe/trunk/lib/Basic/Targets/ARM.cpp
===
--- cfe/trunk/lib/Basic/Targets/ARM.cpp
+++ cfe/trunk/lib/Basic/Targets/ARM.cpp
@@ -999,11 +999,8 @@
 void MinGWARMTargetInfo::getTargetDefines(const LangOptions &Opts,
   MacroBuilder &Builder) const {
   WindowsARMTargetInfo::getTargetDefines(Opts, Builder);
-  DefineStd(Builder, "WIN32", Opts);
-  DefineStd(Builder, "WINNT", Opts);
   Builder.defineMacro("_ARM_");
   Builder.defineMacro("__ARM_DWARF_EH__");
-  addMinGWDefines(Opts, Builder);
 }
 
 CygwinARMTargetInfo::CygwinARMTargetInfo(const llvm::Triple &Triple,
Index: cfe/trunk/lib/Basic/Targets/AArch64.h
===
--- cfe/trunk/lib/Basic/Targets/AArch64.h
+++ cfe/trunk/lib/Basic/Targets/AArch64.h
@@ -122,9 +122,6 @@
 : public WindowsARM64TargetInfo {
 public:
   MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
Index: cfe/trunk/lib/Basic/Targets/OSTargets.h
===
--- cfe/trunk/lib/Basic/Targets/OSTargets.h
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h
@@ -572,6 +572,11 @@
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
 MacroBuilder &Builder) const override {
 Builder.defineMacro("_WIN32");
+if (Triple.isArch64Bit())
+  Builder.defineMacro("_WIN64");
+if (Triple.isWindowsGNUEnvironment())
+  addMinGWDefines(Triple, Opts, Builder);
+
   }
   void getVisualStudioDefines(const LangOptions &Opts,
   MacroBuilder &Builder) const {
Index: cfe/trunk/lib/Basic/Targets/X86.h
===
--- cfe/trunk/lib/Basic/Targets/X86.h
+++ cfe/trunk/lib/Basic/Targets/X86.h
@@ -410,11 +410,6 @@
 ? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
 : "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
   }
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  }
 };
 
 // x86-32 Windows Visual Studio target
@@ -451,10 +446,7 @@
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
-DefineStd(Builde

[PATCH] D39673: Toolchain: Normalize dwarf, sjlj and seh eh

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell updated this revision to Diff 123758.
martell added a comment.

updated to HEAD.
added a NOT msvc test


Repository:
  rL LLVM

https://reviews.llvm.org/D39673

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Driver/ToolChain.h
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/OSTargets.h
  lib/Basic/Targets/X86.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGException.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/MinGW.cpp
  lib/Driver/ToolChains/MinGW.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/CodeGenCXX/mingw-w64-exceptions.c
  test/CodeGenCXX/mingw-w64-seh-exceptions.cpp
  test/Preprocessor/arm-target-features.c
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -1442,6 +1442,7 @@
 //
 // ARM-MSVC: #define _M_ARM_NT 1
 // ARM-MSVC: #define _WIN32 1
+// ARM-MSVC-NOT:#define __ARM_DWARF_EH__ 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 //
Index: test/Preprocessor/arm-target-features.c
===
--- test/Preprocessor/arm-target-features.c
+++ test/Preprocessor/arm-target-features.c
@@ -214,6 +214,7 @@
 // A5:#define __ARM_ARCH_7A__ 1
 // A5-NOT:#define __ARM_ARCH_EXT_IDIV__
 // A5:#define __ARM_ARCH_PROFILE 'A'
+// A5-NOT:#define __ARM_DWARF_EH__ 1
 // A5-NOT: #define __ARM_FEATURE_DIRECTED_ROUNDING
 // A5:#define __ARM_FEATURE_DSP 1
 // A5-NOT: #define __ARM_FEATURE_NUMERIC_MAXMIN
@@ -225,6 +226,7 @@
 // A7:#define __ARM_ARCH 7
 // A7:#define __ARM_ARCH_EXT_IDIV__ 1
 // A7:#define __ARM_ARCH_PROFILE 'A'
+// A7-NOT:#define __ARM_DWARF_EH__ 1
 // A7:#define __ARM_FEATURE_DSP 1
 // A7:#define __ARM_FP 0xE
 
Index: test/CodeGenCXX/mingw-w64-seh-exceptions.cpp
===
--- test/CodeGenCXX/mingw-w64-seh-exceptions.cpp
+++ test/CodeGenCXX/mingw-w64-seh-exceptions.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -fexceptions -emit-llvm -triple x86_64-w64-windows-gnu -o - | FileCheck %s --check-prefix=X64
+// RUN: %clang_cc1 %s -fexceptions -fseh-exceptions -emit-llvm -triple x86_64-w64-windows-gnu -o - | FileCheck %s --check-prefix=X64
+// RUN: %clang_cc1 %s -fexceptions -fdwarf-exceptions -emit-llvm -triple i686-w64-windows-gnu -o - | FileCheck %s --check-prefix=X86
 // RUN: %clang_cc1 %s -fexceptions -emit-llvm -triple i686-w64-windows-gnu -o - | FileCheck %s --check-prefix=X86
 
 extern "C" void foo();
Index: test/CodeGenCXX/mingw-w64-exceptions.c
===
--- /dev/null
+++ test/CodeGenCXX/mingw-w64-exceptions.c
@@ -0,0 +1,22 @@
+// RUN: %clang -target x86_64-windows-gnu -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SEH
+// RUN: %clang -target i686-windows-gnu -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DWARF
+
+// RUN: %clang -target x86_64-windows-gnu -fsjlj-exceptions -c %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-SJLJ
+
+// RUN: %clang -target x86_64-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-DWARF
+
+// RUN: %clang -target x86_64-windows-gnu -fsjlj-exceptions -fseh-exceptions -c %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-SEH
+
+// RUN: %clang -target x86_64-windows-gnu -fseh-exceptions -fsjlj-exceptions -c %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-SJLJ
+
+// RUN: %clang -target x86_64-windows-gnu -fseh-exceptions -fdwarf-exceptions -c %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-DWARF
+
+// CHECK-SEH: "-fseh-exceptions"
+// CHECK-SJLJ: "-fsjlj-exceptions"
+// CHECK-DWARF-NOT: "-fsjlj-exceptions"
+// CHECK-DWARF-NOT: "-fseh-exceptions"
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -677,8 +677,14 @@
 Builder.defineMacro("__EXCEPTIONS");
   if (!LangOpts.MSVCCompat && LangOpts.RTTI)
 Builder.defineMacro("__GXX_RTTI");
+
   if (LangOpts.SjLjExceptions)
 Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
+  else if (LangOpts.SEHExceptions)
+Builder.defineMacro("__SEH__");
+  else if ((TI.getTriple().isThumb() || TI.getTriple().isARM()) &&
+  (TI.getTriple().isOSNetBSD() || TI.getTriple().isOSWindows()))
+Builder.defineMacro("__ARM_DWARF_EH__");
 
   if (LangOpts.Deprecated)
 Builder.defineMacro("__DEPRECATED");
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2139,7 +2139,18 @@
   Opts.Exceptions = Args.hasArg(OPT_fexcept

[PATCH] D39673: Toolchain: Normalize dwarf, sjlj and seh eh

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.

In https://reviews.llvm.org/D39673#929986, @mstorsjo wrote:

> I'm not sure if this is the right thing to do. Since the exception handling 
> model more or less also defines what ABI the code conforms to, I can see it 
> being useful to know what exception handling mode is intended to be used, 
> even if compiling plain C code without exceptions enabled. E.g. when building 
> libunwind, some of the C sources there have ifdefs that check for 
> `__USING_SJLJ_EXCEPTIONS__` and/or `__ARM_DWARF_EH__`. With this change, one 
> has to manually start specifying it when building libunwind, to match 
> whatever the default and/or manually chosen exception handling model is.


It seems reasonable to me that one would specify `-fexceptions` when building  
c sources to get the macro for the exceptions, libunwind included, but yes 
right now there are c sources in `libunwind` that this would break and probably 
other libraries that have c sources that check unconditionally. This is not an 
issue for c++ as `-fexceptions` is enabled by default.

This is a little beyond the scope of what I am trying to achieve in this patch 
though and should be in a different differential after libunwind adds 
-fexceptions when building it's c sources, if we go that route.
For now I have update this patch to HEAD and reverted back to using the model 
macros defines independent of `-fexceptions` as you suggested.


Repository:
  rL LLVM

https://reviews.llvm.org/D39673



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


[PATCH] D39049: [analyzer] Fix wrong calculation of offset in ArrayBoundsV2

2017-11-21 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun requested changes to this revision.
xazax.hun added a comment.
This revision now requires changes to proceed.

In https://reviews.llvm.org/D39049#928620, @danielmarjamaki wrote:

>   > So what are the arguments that are passed to getSimplifiedOffset() in 
> that case? 0? That does not seem to be correct.
>   
>
> yes.


Maybe I am missing something but this does not seem to be correct for me. We 
should either have the correct symbolic expression or UnknownVal if the 
analyzer cannot reason about something (or UndefVal if the result is 
undefined). But never the wrong value. 
If you are sure that this happens, this needs to be investigated.

> so the conclusion is:
> 
> - this code does not work
> - this code is untested
> - this code is not even used in the use cases it was intended for because of 
> bugs elsewhere
> 
>   therefore it should be removed.

I am ok with removing that code AND altering the comment to reflect the 
changes. Please update this patch accordingly. 
Also, I think maybe an easier test case could be added to show what is wrong 
with the current approach.


Repository:
  rL LLVM

https://reviews.llvm.org/D39049



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


[PATCH] D39673: Toolchain: Normalize dwarf, sjlj and seh eh

2017-11-21 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.

Just as a note there is still a lot to be desired here. I do not particularly 
like the `UseSEHExceptions` function default and the actual macro definition 
guards should be based on the current `ExceptionModel` because we set that in 
`lib/CodeGen/BackendUtil.cpp`. This way we do not need to have some silly 
default of x64 && windows for UseSEHExceptions and can rely on the llvm backend 
defaults but override within the driver we want like the apple targets do for 
sjlj. This does for now keep the current functionality which giving us a flag 
to override which is the goal of this patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D39673



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


[PATCH] D40295: -fsanitize=vptr warnings on bad static types in dynamic_cast and typeid

2017-11-21 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg created this revision.
Herald added a subscriber: kubamracek.

...when such an operation is done on an object during con-/destruction.

This adds a test case to compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp 
that, unlike the existing test cases there, wants to detect multiple UBSan 
warnings in one go.  Therefore, that file had to be changed from globally using 
-fno-sanitize-recover to individually using halt_on_error only where 
appropriate.


https://reviews.llvm.org/D40295

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  compiler-rt/lib/ubsan/ubsan_handlers.cc
  compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp

Index: compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
===
--- compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
@@ -1,41 +1,53 @@
-// RUN: %clangxx -frtti -fsanitize=null,vptr -fno-sanitize-recover=null,vptr -g %s -O3 -o %t -mllvm -enable-tail-merge=false
-// RUN: %run %t rT && %run %t mT && %run %t fT && %run %t cT
-// RUN: %run %t rU && %run %t mU && %run %t fU && %run %t cU
-// RUN: %run %t rS && %run %t rV && %run %t oV
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t mS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t fS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t cS 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t mV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t fV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t cV 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t oU 2>&1 | FileCheck %s --check-prefix=CHECK-OFFSET --check-prefix=CHECK-%os-OFFSET --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-MEMBER --check-prefix=CHECK-%os-NULL-MEMBER --strict-whitespace
-// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-MEMBER --check-prefix=CHECK-%os-NULL-MEMBER --strict-whitespace
-// RUN: not %run %t nN 2>&1 | FileCheck %s --check-prefix=CHECK-NULL-MEMFUN --strict-whitespace
+// RUN: %clangxx -frtti -fsanitize=null,vptr -g %s -O3 -o %t -mllvm -enable-tail-merge=false
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t rT
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t mT
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t fT
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t cT
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t rU
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t mU
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t fU
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t cU
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t rS
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t rV
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t oV
+// RUN: %env_ubsan_opts=halt_on_error=1 %run %t zN
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t mS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t fS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t cS 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t mV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t fV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t cV 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t oU 2>&1 | FileCheck %s --check-prefix=CHECK-OFFSET --check-prefix=CHECK-%os-OFFSET --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-MEMBER --check-prefix=CHECK-%os-NULL-MEMBER --strict-whitespace
+// RUN: %env_ubsan_opts=halt_on_error=1:print_stacktrace=1 not %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-MEMBER --check-prefix=CHECK-%os-NULL-MEMBER -

[PATCH] D40276: Add -finstrument-function-entry-bare flag

2017-11-21 Thread Egor Pasko via Phabricator via cfe-commits
pasko accepted this revision.
pasko added a comment.
This revision is now accepted and ready to land.

Instrumenting the function entry post-inlining, without function exit, and with 
no parameters is exactly what we need. The `__cyg_profile_func_enter_bare` 
sounds good to me as a name. Thank you!

Unnecessary thoughts just to get a feeling we are on the same page: this could 
theoretically be made more orthogonal where 
`-finstrument-functions-after-inlining` could regulate whether the call is pre- 
or post-inlining, but I don't see how pre-inlining without parameters would be 
usable without too much DWARF digging, which is not too practical.


https://reviews.llvm.org/D40276



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


[PATCH] D40295: -fsanitize=vptr warnings on bad static types in dynamic_cast and typeid

2017-11-21 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

Some items I'm unclear about:

- Should those additional calls to EmitTypeCheck be restricted via those 
SkippedChecks or not?

- Maybe there's a better way to add tests for this than to try shoehorn it into 
the existing vptr.cpp?


https://reviews.llvm.org/D40295



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


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-21 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 added a comment.

Oh, yes.

https://reviews.llvm.org/D30876 is motivated by the same problem.

The notable difference between this patch and https://reviews.llvm.org/D30876 
is that ASTImporter should check the conflict resolution for the unnamed 
structs/unions in a record context or not.
Then, I think https://reviews.llvm.org/D30876's solution is more conservative.
In fact,  simply omitting the conflict check for all unnamed structures works 
well in my experience.
I have not hit the case where two unnamed structs have the same `Index`.
However, according to two past patches (1cef459 

 and 11ce5fe 

 ), he clearly added the anonymous structs/unions to the checking path.
So, I guess there is an example where ASTImporter has to handle them rather 
than simply skips them.
https://reviews.llvm.org/D30876 more reflects the policy of these patches.

Furthermore, I also agree with the fix of findUntaggedStructOrUnionIndex(), 
although findUntaggedStructOrUnionIndex() is not in ASTImporter.cpp anymore.
The function exists in ASTStructuralEquivalence.cpp insead.

Sorry for this redundant patch.


https://reviews.llvm.org/D39886



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


[PATCH] D40013: [DeclPrinter] Allow printing fully qualified name of function declaration

2017-11-21 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.
This revision is now accepted and ready to land.

LGTM.

Thanks!


https://reviews.llvm.org/D40013



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


[PATCH] D40299: [Complex] Don't use __div?c3 when building with fast-math.

2017-11-21 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm created this revision.

Plant an inline version of "((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))" instead.


https://reviews.llvm.org/D40299

Files:
  lib/CodeGen/CGExprComplex.cpp
  test/CodeGen/complex-math.c

Index: test/CodeGen/complex-math.c
===
--- test/CodeGen/complex-math.c
+++ test/CodeGen/complex-math.c
@@ -5,6 +5,7 @@
 // RUN %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s --check-prefix=ARM7K
+// RUN %clang_cc1 %s -O1 -ffast-math -emit-llvm -triple x86_64-unknown-unknown | FileCheck %s --check-prefix=FASTMATH
 
 float _Complex add_float_rr(float a, float b) {
   // X86-LABEL: @add_float_rr(
@@ -128,13 +129,25 @@
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divsc3(
   // X86: ret
+  // FASTMATH-LABEL: @div_float_rc(
+  // FASTMATH-NOT: @__divsc3
+  // FASTMATH: fdiv
+  // FASTMATH: fdiv
+  // FASTMATH-NOT: fdiv
+  // FASTMATH: ret
   return a / b;
 }
 float _Complex div_float_cc(float _Complex a, float _Complex b) {
   // X86-LABEL: @div_float_cc(
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divsc3(
   // X86: ret
+  // FASTMATH-LABEL: @div_float_cc(
+  // FASTMATH-NOT: @__divsc3
+  // FASTMATH: fdiv
+  // FASTMATH: fdiv
+  // FASTMATH-NOT: fdiv
+  // FASTMATH: ret
   return a / b;
 }
 
@@ -260,13 +273,25 @@
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divdc3(
   // X86: ret
+  // FASTMATH-LABEL: @div_double_rc(
+  // FASTMATH-NOT: @__divdc3
+  // FASTMATH: fdiv
+  // FASTMATH: fdiv
+  // FASTMATH-NOT: fdiv
+  // FASTMATH: ret
   return a / b;
 }
 double _Complex div_double_cc(double _Complex a, double _Complex b) {
   // X86-LABEL: @div_double_cc(
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divdc3(
   // X86: ret
+  // FASTMATH-LABEL: @div_double_cc(
+  // FASTMATH-NOT: @__divdc3
+  // FASTMATH: fdiv
+  // FASTMATH: fdiv
+  // FASTMATH-NOT: fdiv
+  // FASTMATH: ret
   return a / b;
 }
 
@@ -410,6 +435,12 @@
   // PPC-NOT: fdiv
   // PPC: call {{.*}} @__divtc3(
   // PPC: ret
+  // FASTMATH-LABEL: @div_long_double_rc(
+  // FASTMATH-NOT: @__divxc3
+  // FASTMATH: fdiv
+  // FASTMATH: fdiv
+  // FASTMATH-NOT: fdiv
+  // FASTMATH: ret
   return a / b;
 }
 long double _Complex div_long_double_cc(long double _Complex a, long double _Complex b) {
@@ -421,6 +452,12 @@
   // PPC-NOT: fdiv
   // PPC: call {{.*}} @__divtc3(
   // PPC: ret
+  // FASTMATH-LABEL: @div_double_cc(
+  // FASTMATH-NOT: @__divxc3
+  // FASTMATH: fdiv
+  // FASTMATH: fdiv
+  // FASTMATH-NOT: fdiv
+  // FASTMATH: ret
   return a / b;
 }
 
Index: lib/CodeGen/CGExprComplex.cpp
===
--- lib/CodeGen/CGExprComplex.cpp
+++ lib/CodeGen/CGExprComplex.cpp
@@ -761,15 +761,16 @@
   llvm::Value *LHSr = Op.LHS.first, *LHSi = Op.LHS.second;
   llvm::Value *RHSr = Op.RHS.first, *RHSi = Op.RHS.second;
 
-
   llvm::Value *DSTr, *DSTi;
   if (LHSr->getType()->isFloatingPointTy()) {
+llvm::FastMathFlags FMF = Builder.getFastMathFlags();
+
 // If we have a complex operand on the RHS, we delegate to a libcall to
 // handle all of the complexities and minimize underflow/overflow cases.
 //
 // FIXME: We would be able to avoid the libcall in many places if we
 // supported imaginary types in addition to complex types.
-if (RHSi) {
+if (RHSi && !FMF.isFast()) {
   BinOpInfo LibCallOp = Op;
   // If LHS was a real, supply a null imaginary part.
   if (!LHSi)
@@ -791,11 +792,31 @@
   case llvm::Type::FP128TyID:
 return EmitComplexBinOpLibCall("__divtc3", LibCallOp);
   }
-}
-assert(LHSi && "Can have at most one non-complex operand!");
+} else if (RHSi) {
+  if (!LHSi)
+LHSi = llvm::Constant::getNullValue(RHSi->getType());
+
+  // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))
+  llvm::Value *AC = Builder.CreateFMul(LHSr, RHSr); // a*c
+  llvm::Value *BD = Builder.CreateFMul(LHSi, RHSi); // b*d
+  llvm::Value *ACpBD = Builder.CreateFAdd(AC, BD); // ac+bd
 
-DSTr = Builder.CreateFDiv(LHSr, RHSr);
-DSTi = Builder.CreateFDiv(LHSi, RHSr);
+  llvm::Value *CC = Builder.CreateFMul(RHSr, RHSr); // c*c
+  llvm::Value *DD = Builder.CreateFMul(RHSi, RHSi); // d*d
+  llvm::Value *CCpDD = Builder.CreateFAdd(CC, DD); // cc+dd
+
+  llvm::Value *BC = Builder.CreateFMul(LHSi, RHSr); // b*c
+  llvm::Value *AD = Builder.CreateFMul(LHSr, RHSi); // a*d
+  llvm::Value *BCmAD = Builder.CreateFSub(BC, AD); // bc-ad
+
+  DSTr = Builder.CreateFDiv(ACpBD, CCpDD);
+  DSTi = Builder.CreateFDiv(BCmAD, CCpDD);
+} else {
+  assert(LHSi && "Can have at most one non-complex operand!");
+
+  DSTr = Builder.CreateFDiv(LHS

[PATCH] D34848: Driver: Don't mix system tools with devtoolset tools on RHEL

2017-11-21 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

Ping.


https://reviews.llvm.org/D34848



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


[PATCH] D40281: [Clang][OpenMP] New clang/libomptarget map interface: new function signatures, clang-side

2017-11-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rL LLVM

https://reviews.llvm.org/D40281



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


[PATCH] D40301: [clangd] Ensure preamble outlives the AST

2017-11-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

In-memory preambles will not be copied anymore, so we need to make
sure they outlive the AST.


https://reviews.llvm.org/D40301

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h

Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -48,15 +48,16 @@
   llvm::SmallVector FixIts;
 };
 
+struct PreambleData;
+
 /// Stores and provides access to parsed AST.
 class ParsedAST {
 public:
   /// Attempts to run Clang and store parsed AST. If \p Preamble is non-null
   /// it is reused during parsing.
   static llvm::Optional
   Build(std::unique_ptr CI,
-const PrecompiledPreamble *Preamble,
-ArrayRef PreambleDeclIDs,
+std::shared_ptr Preamble,
 std::unique_ptr Buffer,
 std::shared_ptr PCHs,
 IntrusiveRefCntPtr VFS, clangd::Logger &Logger);
@@ -80,15 +81,18 @@
   const std::vector &getDiagnostics() const;
 
 private:
-  ParsedAST(std::unique_ptr Clang,
+  ParsedAST(std::shared_ptr Preamble,
+std::unique_ptr Clang,
 std::unique_ptr Action,
 std::vector TopLevelDecls,
-std::vector PendingTopLevelDecls,
 std::vector Diags);
 
 private:
   void ensurePreambleDeclsDeserialized();
 
+  // In-memory preambles must outlive the AST, it is important that this member
+  // goes before Clang and Action.
+  std::shared_ptr Preamble;
   // We store an "incomplete" FrontendAction (i.e. no EndSourceFile was called
   // on it) and CompilerInstance used to run it. That way we don't have to do
   // complex memory management of all Clang structures on our own. (They are
@@ -100,7 +104,7 @@
   // Data, stored after parsing.
   std::vector Diags;
   std::vector TopLevelDecls;
-  std::vector PendingTopLevelDecls;
+  bool PreambleDeclsDeserialized;
 };
 
 // Provides thread-safe access to ParsedAST.
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -878,18 +878,19 @@
 
 llvm::Optional
 ParsedAST::Build(std::unique_ptr CI,
- const PrecompiledPreamble *Preamble,
- ArrayRef PreambleDeclIDs,
+ std::shared_ptr Preamble,
  std::unique_ptr Buffer,
  std::shared_ptr PCHs,
  IntrusiveRefCntPtr VFS,
  clangd::Logger &Logger) {
 
   std::vector ASTDiags;
   StoreDiagsConsumer UnitDiagsConsumer(/*ref*/ ASTDiags);
 
+  const PrecompiledPreamble *PreamblePCH =
+  Preamble ? &Preamble->Preamble : nullptr;
   auto Clang = prepareCompilerInstance(
-  std::move(CI), Preamble, std::move(Buffer), std::move(PCHs),
+  std::move(CI), PreamblePCH, std::move(Buffer), std::move(PCHs),
   std::move(VFS), /*ref*/ UnitDiagsConsumer);
 
   // Recover resources if we crash before exiting this method.
@@ -911,15 +912,8 @@
   Clang->getDiagnostics().setClient(new EmptyDiagsConsumer);
 
   std::vector ParsedDecls = Action->takeTopLevelDecls();
-  std::vector PendingDecls;
-  if (Preamble) {
-PendingDecls.reserve(PreambleDeclIDs.size());
-PendingDecls.insert(PendingDecls.begin(), PreambleDeclIDs.begin(),
-PreambleDeclIDs.end());
-  }
-
-  return ParsedAST(std::move(Clang), std::move(Action), std::move(ParsedDecls),
-   std::move(PendingDecls), std::move(ASTDiags));
+  return ParsedAST(std::move(Preamble), std::move(Clang), std::move(Action),
+   std::move(ParsedDecls), std::move(ASTDiags));
 }
 
 namespace {
@@ -1060,24 +1054,25 @@
 }
 
 void ParsedAST::ensurePreambleDeclsDeserialized() {
-  if (PendingTopLevelDecls.empty())
+  if (PreambleDeclsDeserialized || !Preamble)
 return;
 
   std::vector Resolved;
-  Resolved.reserve(PendingTopLevelDecls.size());
+  Resolved.reserve(Preamble->TopLevelDeclIDs.size());
 
   ExternalASTSource &Source = *getASTContext().getExternalSource();
-  for (serialization::DeclID TopLevelDecl : PendingTopLevelDecls) {
+  for (serialization::DeclID TopLevelDecl : Preamble->TopLevelDeclIDs) {
 // Resolve the declaration ID to an actual declaration, possibly
 // deserializing the declaration in the process.
 if (Decl *D = Source.GetExternalDecl(TopLevelDecl))
   Resolved.push_back(D);
   }
 
-  TopLevelDecls.reserve(TopLevelDecls.size() + PendingTopLevelDecls.size());
+  TopLevelDecls.reserve(TopLevelDecls.size() +
+Preamble->TopLevelDeclIDs.size());
   TopLevelDecls.insert(TopLevelDecls.begin(), Resolved.begin(), Resolved.end());
 
-  PendingTopLevelDecls.clear();
+  PreambleDeclsDeserialized = true;
 }
 
 ParsedAST::ParsedAST(ParsedAST &&Other) = default;
@@ -,14 +1106,15 @@
   return Diags;
 }
 
-ParsedAST::ParsedAST(std::unique_ptr Clang,
+ParsedAST::ParsedAST(std::shared_ptr Preamble,
+ std::unique_ptr Clang,
  std::unique_ptr A

[PATCH] D40302: Avoid copying the data of in-memory preambles

2017-11-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

Preambles are large and we should prefer not to copy it.


https://reviews.llvm.org/D40302

Files:
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/PrecompiledPreamble.cpp


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -699,9 +699,7 @@
 StringRef PCHPath = getInMemoryPreamblePath();
 PreprocessorOpts.ImplicitPCHInclude = PCHPath;
 
-// FIMXE(ibiryukov): Preambles can be large. We should allow shared access
-// to the preamble data instead of copying it here.
-auto Buf = llvm::MemoryBuffer::getMemBufferCopy(Storage.asMemory().Data);
+auto Buf = llvm::MemoryBuffer::getMemBuffer(Storage.asMemory().Data);
 VFS = createVFSOverlayForPreamblePCH(PCHPath, std::move(Buf), VFS);
   }
 }
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -98,6 +98,10 @@
   /// Changes options inside \p CI to use PCH from this preamble. Also remaps
   /// main file to \p MainFileBuffer and updates \p VFS to ensure the preamble
   /// is accessible.
+  /// For in-memory preambles, PrecompiledPreamble instance continues to owns
+  /// the MemoryBuffer with the Preamble after this method returns. The caller
+  /// is reponsible for making sure the PrecompiledPreamble instance outlives
+  /// the compiler run and the AST that will be using the PCH.
   void AddImplicitPreamble(CompilerInvocation &CI,
IntrusiveRefCntPtr &VFS,
llvm::MemoryBuffer *MainFileBuffer) const;


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -699,9 +699,7 @@
 StringRef PCHPath = getInMemoryPreamblePath();
 PreprocessorOpts.ImplicitPCHInclude = PCHPath;
 
-// FIMXE(ibiryukov): Preambles can be large. We should allow shared access
-// to the preamble data instead of copying it here.
-auto Buf = llvm::MemoryBuffer::getMemBufferCopy(Storage.asMemory().Data);
+auto Buf = llvm::MemoryBuffer::getMemBuffer(Storage.asMemory().Data);
 VFS = createVFSOverlayForPreamblePCH(PCHPath, std::move(Buf), VFS);
   }
 }
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -98,6 +98,10 @@
   /// Changes options inside \p CI to use PCH from this preamble. Also remaps
   /// main file to \p MainFileBuffer and updates \p VFS to ensure the preamble
   /// is accessible.
+  /// For in-memory preambles, PrecompiledPreamble instance continues to owns
+  /// the MemoryBuffer with the Preamble after this method returns. The caller
+  /// is reponsible for making sure the PrecompiledPreamble instance outlives
+  /// the compiler run and the AST that will be using the PCH.
   void AddImplicitPreamble(CompilerInvocation &CI,
IntrusiveRefCntPtr &VFS,
llvm::MemoryBuffer *MainFileBuffer) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-21 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

No need to apologize. Thank you for your work anyway. Even if the bug-fixing 
part of this patch will be omitted, I'd still like to add your tests into the 
test suite.


https://reviews.llvm.org/D39886



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-21 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hello Aaron,

This patch is OK for me but could you please take a look at ASTMatchers changes?


https://reviews.llvm.org/D39722



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-21 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun requested changes to this revision.
xazax.hun added a comment.
This revision now requires changes to proceed.

The checker documentation should be updated as well.




Comment at: include/clang/ASTMatchers/ASTMatchers.h:2251
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+

Note that the matchers are no longer defined in the header. They are just 
declared and the definition is moved to a cpp file. 


https://reviews.llvm.org/D39722



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


r318763 - [OpenMP] Consistently use cubin extension for nvlink

2017-11-21 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Tue Nov 21 06:44:45 2017
New Revision: 318763

URL: http://llvm.org/viewvc/llvm-project?rev=318763&view=rev
Log:
[OpenMP] Consistently use cubin extension for nvlink

This was previously done in some places, but for example not for
bundling so that single object compilation with -c failed. In
addition cubin was used for all file types during unbundling which
is incorrect for assembly files that are passed to ptxas.
Tighten up the tests so that we can't regress in that area.

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

Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.h
cfe/trunk/test/Driver/openmp-offload-gpu.c

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=318763&r1=318762&r2=318763&view=diff
==
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Tue Nov 21 06:44:45 2017
@@ -40,6 +40,7 @@ namespace driver {
   class Compilation;
   class CudaInstallationDetector;
   class Driver;
+  class InputInfo;
   class JobAction;
   class RegisterEffectiveTriple;
   class SanitizerArgs;
@@ -172,6 +173,11 @@ public:
   /// while the aux triple is the host (CPU) toolchain, e.g. x86-linux-gnu.
   virtual const llvm::Triple *getAuxTriple() const { return nullptr; }
 
+  /// Some toolchains need to modify the file name, for example to replace the
+  /// extension for object files with .cubin for OpenMP offloading to Nvidia
+  /// GPUs.
+  virtual std::string getInputFilename(const InputInfo &Input) const;
+
   llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
   StringRef getArchName() const { return Triple.getArchName(); }
   StringRef getPlatform() const { return Triple.getVendorName(); }

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=318763&r1=318762&r2=318763&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Tue Nov 21 06:44:45 2017
@@ -215,6 +215,10 @@ StringRef ToolChain::getDefaultUniversal
   }
 }
 
+std::string ToolChain::getInputFilename(const InputInfo &Input) const {
+  return Input.getFilename();
+}
+
 bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const {
   return false;
 }

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=318763&r1=318762&r2=318763&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Nov 21 06:44:45 2017
@@ -5310,12 +5310,15 @@ void OffloadBundler::ConstructJob(Compil
 if (I)
   Triples += ',';
 
+// Find ToolChain for this input.
 Action::OffloadKind CurKind = Action::OFK_Host;
 const ToolChain *CurTC = &getToolChain();
 const Action *CurDep = JA.getInputs()[I];
 
 if (const auto *OA = dyn_cast(CurDep)) {
+  CurTC = nullptr;
   OA->doOnEachDependence([&](Action *A, const ToolChain *TC, const char *) 
{
+assert(CurTC == nullptr && "Expected one dependence!");
 CurKind = A->getOffloadingDeviceKind();
 CurTC = TC;
   });
@@ -5336,7 +5339,17 @@ void OffloadBundler::ConstructJob(Compil
   for (unsigned I = 0; I < Inputs.size(); ++I) {
 if (I)
   UB += ',';
-UB += Inputs[I].getFilename();
+
+// Find ToolChain for this input.
+const ToolChain *CurTC = &getToolChain();
+if (const auto *OA = dyn_cast(JA.getInputs()[I])) {
+  CurTC = nullptr;
+  OA->doOnEachDependence([&](Action *, const ToolChain *TC, const char *) {
+assert(CurTC == nullptr && "Expected one dependence!");
+CurTC = TC;
+  });
+}
+UB += CurTC->getInputFilename(Inputs[I]);
   }
   CmdArgs.push_back(TCArgs.MakeArgString(UB));
 
@@ -5396,13 +5409,7 @@ void OffloadBundler::ConstructJobMultipl
   for (unsigned I = 0; I < Outputs.size(); ++I) {
 if (I)
   UB += ',';
-SmallString<256> OutputFileName(Outputs[I].getFilename());
-// Change extension of target files for OpenMP offloading
-// to NVIDIA GPUs.
-if (DepInfo[I].DependentToolChain->getTriple().isNVPTX() &&
-JA.isOffloading(Action::OFK_OpenMP))
-  llvm::sys::path::replace_extension(OutputFileName, "cubin");
-UB += OutputFileName;
+UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
   }
   CmdArgs.push_back(TCArgs.MakeArgString(UB));
   CmdArgs.push_back("-unbundle");

Modified: cfe/trunk/lib/Driver/ToolCh

[PATCH] D40250: [OpenMP] Consistently use cubin extension for nvlink

2017-11-21 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Hahnfeld marked an inline comment as done.
Closed by commit rL318763: [OpenMP] Consistently use cubin extension for nvlink 
(authored by Hahnfeld).

Changed prior to commit:
  https://reviews.llvm.org/D40250?vs=123649&id=123780#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40250

Files:
  cfe/trunk/include/clang/Driver/ToolChain.h
  cfe/trunk/lib/Driver/ToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
  cfe/trunk/lib/Driver/ToolChains/Cuda.h
  cfe/trunk/test/Driver/openmp-offload-gpu.c

Index: cfe/trunk/lib/Driver/ToolChains/Cuda.h
===
--- cfe/trunk/lib/Driver/ToolChains/Cuda.h
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.h
@@ -137,10 +137,12 @@
 const ToolChain &HostTC, const llvm::opt::ArgList &Args,
 const Action::OffloadKind OK);
 
-  virtual const llvm::Triple *getAuxTriple() const override {
+  const llvm::Triple *getAuxTriple() const override {
 return &HostTC.getTriple();
   }
 
+  std::string getInputFilename(const InputInfo &Input) const override;
+
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
 Action::OffloadKind DeviceOffloadKind) const override;
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -5310,12 +5310,15 @@
 if (I)
   Triples += ',';
 
+// Find ToolChain for this input.
 Action::OffloadKind CurKind = Action::OFK_Host;
 const ToolChain *CurTC = &getToolChain();
 const Action *CurDep = JA.getInputs()[I];
 
 if (const auto *OA = dyn_cast(CurDep)) {
+  CurTC = nullptr;
   OA->doOnEachDependence([&](Action *A, const ToolChain *TC, const char *) {
+assert(CurTC == nullptr && "Expected one dependence!");
 CurKind = A->getOffloadingDeviceKind();
 CurTC = TC;
   });
@@ -5336,7 +5339,17 @@
   for (unsigned I = 0; I < Inputs.size(); ++I) {
 if (I)
   UB += ',';
-UB += Inputs[I].getFilename();
+
+// Find ToolChain for this input.
+const ToolChain *CurTC = &getToolChain();
+if (const auto *OA = dyn_cast(JA.getInputs()[I])) {
+  CurTC = nullptr;
+  OA->doOnEachDependence([&](Action *, const ToolChain *TC, const char *) {
+assert(CurTC == nullptr && "Expected one dependence!");
+CurTC = TC;
+  });
+}
+UB += CurTC->getInputFilename(Inputs[I]);
   }
   CmdArgs.push_back(TCArgs.MakeArgString(UB));
 
@@ -5396,13 +5409,7 @@
   for (unsigned I = 0; I < Outputs.size(); ++I) {
 if (I)
   UB += ',';
-SmallString<256> OutputFileName(Outputs[I].getFilename());
-// Change extension of target files for OpenMP offloading
-// to NVIDIA GPUs.
-if (DepInfo[I].DependentToolChain->getTriple().isNVPTX() &&
-JA.isOffloading(Action::OFK_OpenMP))
-  llvm::sys::path::replace_extension(OutputFileName, "cubin");
-UB += OutputFileName;
+UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
   }
   CmdArgs.push_back(TCArgs.MakeArgString(UB));
   CmdArgs.push_back("-unbundle");
Index: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
@@ -301,10 +301,7 @@
   CmdArgs.push_back("--gpu-name");
   CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
   CmdArgs.push_back("--output-file");
-  SmallString<256> OutputFileName(Output.getFilename());
-  if (JA.isOffloading(Action::OFK_OpenMP))
-llvm::sys::path::replace_extension(OutputFileName, "cubin");
-  CmdArgs.push_back(Args.MakeArgString(OutputFileName));
+  CmdArgs.push_back(Args.MakeArgString(TC.getInputFilename(Output)));
   for (const auto& II : Inputs)
 CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
 
@@ -431,11 +428,8 @@
 if (!II.isFilename())
   continue;
 
-SmallString<256> Name(II.getFilename());
-llvm::sys::path::replace_extension(Name, "cubin");
-
-const char *CubinF =
-C.addTempFile(C.getArgs().MakeArgString(Name));
+const char *CubinF = C.addTempFile(
+C.getArgs().MakeArgString(getToolChain().getInputFilename(II)));
 
 CmdArgs.push_back(CubinF);
   }
@@ -463,6 +457,20 @@
   getProgramPaths().push_back(getDriver().Dir);
 }
 
+std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
+  // Only object files are changed, for example assembly files keep their .s
+  // extensions. CUDA also continues to use .o as they don't use nvlink but
+  // fatbinary.
+  if (!(OK == Action::OFK_OpenMP && Input.getType() == types::TY_Object))
+return ToolChain::getInputFilename(Input);
+
+  // Replace extens

[libcxxabi] r318765 - [demangler] Document some features that the demangler doesn't yet support, NFC

2017-11-21 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Tue Nov 21 07:04:08 2017
New Revision: 318765

URL: http://llvm.org/viewvc/llvm-project?rev=318765&view=rev
Log:
[demangler] Document some features that the demangler doesn't yet support, NFC

Modified:
libcxxabi/trunk/src/cxa_demangle.cpp
libcxxabi/trunk/test/test_demangle.pass.cpp

Modified: libcxxabi/trunk/src/cxa_demangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=318765&r1=318764&r2=318765&view=diff
==
--- libcxxabi/trunk/src/cxa_demangle.cpp (original)
+++ libcxxabi/trunk/src/cxa_demangle.cpp Tue Nov 21 07:04:08 2017
@@ -7,6 +7,12 @@
 //
 
//===--===//
 
+// FIXME: (possibly) incomplete list of features that clang mangles that this
+// file does not yet support:
+//   - enable_if attribute
+//   - decomposition declarations
+//   - C++ modules TS
+
 #define _LIBCPP_NO_EXCEPTIONS
 
 #include "__cxxabi_config.h"

Modified: libcxxabi/trunk/test/test_demangle.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_demangle.pass.cpp?rev=318765&r1=318764&r2=318765&view=diff
==
--- libcxxabi/trunk/test/test_demangle.pass.cpp (original)
+++ libcxxabi/trunk/test/test_demangle.pass.cpp Tue Nov 21 07:04:08 2017
@@ -29712,7 +29712,7 @@ void test()
 free(buf);
 }
 
-void test2()
+void test_invalid_cases()
 {
 std::size_t len = 0;
 char* buf = nullptr;
@@ -29733,6 +29733,36 @@ void test2()
 free(buf);
 }
 
+const char *xfail_cases[] = {
+"_Z1fUa9enable_ifIXLi1EEEv", // enable_if attribute
+"_ZDC2a12a2E", // decomposition decl
+"_ZW6FooBarE2f3v", // C++ modules TS
+};
+
+const size_t num_xfails = sizeof(xfail_cases) / sizeof(xfail_cases[0]);
+
+void test_xfail_cases()
+{
+std::size_t len = 0;
+char* buf = nullptr;
+for (std::size_t i = 0; i < num_xfails; ++i)
+{
+int status;
+char* demang = __cxxabiv1::__cxa_demangle(xfail_cases[i], buf, &len, 
&status);
+if (status != -2)
+{
+std::cout << xfail_cases[i] << " was documented as xfail but 
passed\n"
+  << "got status = " << status << '\n';
+assert(status == -2);
+}
+else
+{
+buf = demang;
+}
+}
+free(buf);
+}
+
 void testFPLiterals()
 {
 std::size_t len = 0;
@@ -29769,7 +29799,8 @@ int main()
 {
 timer t;
 test();
-test2();
+test_invalid_cases();
+test_xfail_cases();
 testFPLiterals();
 }
 #if 0


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


r318767 - Add target triples to openmp-offload-gpu.c

2017-11-21 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Tue Nov 21 07:06:28 2017
New Revision: 318767

URL: http://llvm.org/viewvc/llvm-project?rev=318767&view=rev
Log:
Add target triples to openmp-offload-gpu.c

This might fix the failure on Green Dragon.

Modified:
cfe/trunk/test/Driver/openmp-offload-gpu.c

Modified: cfe/trunk/test/Driver/openmp-offload-gpu.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openmp-offload-gpu.c?rev=318767&r1=318766&r2=318767&view=diff
==
--- cfe/trunk/test/Driver/openmp-offload-gpu.c (original)
+++ cfe/trunk/test/Driver/openmp-offload-gpu.c Tue Nov 21 07:06:28 2017
@@ -47,7 +47,8 @@
 
 /// Check unbundlink of assembly file, cubin file generation and usage by 
nvlink
 // RUN:   touch %t.s
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -save-temps %t.s 2>&1 \
+// RUN:   %clang -### -target powerpc64le-unknown-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:  -no-canonical-prefixes -save-temps %t.s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-UNBUNDLING-PTXAS-CUBIN-NVLINK %s
 
 /// Use DAG to ensure that assembly file has been unbundled.
@@ -59,7 +60,8 @@
 /// ###
 
 /// Check cubin file generation and bundling
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -save-temps %s -c 2>&1 \
+// RUN:   %clang -### -target powerpc64le-unknown-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:  -no-canonical-prefixes -save-temps %s -c 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-PTXAS-CUBIN-BUNDLING %s
 
 // CHK-PTXAS-CUBIN-BUNDLING: clang{{.*}}" "-o" "[[PTX:.*\.s]]"
@@ -70,7 +72,8 @@
 
 /// Check cubin file unbundling and usage by nvlink
 // RUN:   touch %t.o
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -save-temps %t.o 2>&1 \
+// RUN:   %clang -### -target powerpc64le-unknown-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:  -no-canonical-prefixes -save-temps %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-CUBIN-UNBUNDLING-NVLINK %s
 
 /// Use DAG to ensure that cubin file has been unbundled.


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


[PATCH] D37187: [Analyzer] Fix Bug 25609 - Assertion UNREACHABLE: 'Unexpected ProgramPoint' with widen-loops=true

2017-11-21 Thread Henry Wong via Phabricator via cfe-commits
MTC updated this revision to Diff 123783.
MTC added a comment.
Herald added subscribers: a.sidorin, rnkovacs.

Update diff, use the SourceLocation of the first element of the entered block 
as the argument of `PathDiagnosticLocation`.


https://reviews.llvm.org/D37187

Files:
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/loop-widening-notes.cpp


Index: test/Analysis/loop-widening-notes.cpp
===
--- /dev/null
+++ test/Analysis/loop-widening-notes.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha -analyzer-max-loop 2 
-analyzer-config widen-loops=true -analyzer-output=text -verify %s
+
+int *p_a;
+int bar();
+int flag_a;
+int test_for_bug_25609() {
+  if (p_a == 0) // expected-note {{Assuming 'p_a' is equal to null}} 
+// expected-note@-1 {{Taking true branch}}
+bar();
+  for (int i = 0;  // expected-note {{Loop condition is true.  Entering loop 
body}}
+   // expected-note@-1 {{Loop condition is false. Execution 
continues on line 16}}
+   ++i,// expected-note {{Value assigned to 'p_a'}} 
+   i < flag_a;
+   ++i) {}
+  
+  *p_a = 25609; // no-crash expected-warning {{Dereference of null pointer 
(loaded from variable 'p_a')}}
+// expected-note@-1 {{Dereference of null pointer (loaded from 
variable 'p_a')}}
+  return *p_a;
+}
+
+int flag_b;
+int while_analyzer_output() {
+  flag_b = 100;
+  int num = 10;
+  while (flag_b-- > 0) { // expected-note {{Loop condition is true.  Entering 
loop body}} 
+ // expected-note@-1 {{Value assigned to 'num'}} 
+ // expected-note@-2 {{Loop condition is false. 
Execution continues on line 30}}
+num = flag_b;
+  }
+  if (num < 0) // expected-note {{Assuming 'num' is >= 0}} 
+   // expected-note@-1 {{Taking false branch}}
+flag_b = 0;
+  else if (num >= 1) // expected-note {{Assuming 'num' is < 1}} 
+ // expected-note@-1 {{Taking false branch}}
+flag_b = 50;
+  else
+flag_b = 100;
+  return flag_b / num; // no-crash expected-warning {{Division by zero}} 
+   // expected-note@-1 {{Division by zero}}
+}
+
+int flag_c;
+int do_while_analyzer_output() {
+  int num = 10;
+  do {   // expected-note {{Loop condition is true. Execution continues on 
line 47}} 
+ // expected-note@-1 {{Loop condition is false.  Exiting loop}}
+num--;
+  } while (flag_c-- > 0); //expected-note {{Value assigned to 'num'}}
+  int local = 0;
+  if (num == 0)   // expected-note {{Assuming 'num' is equal to 0}} 
+  // expected-note@-1 {{Taking true branch}}
+local = 10 / num; // no-crash expected-warning {{Division by zero}}
+  // expected-note@-1 {{Division by zero}}
+  return local;
+}
+
+int flag_d;
+int test_for_loop() {
+  int num = 10;
+  for (int i = 0;// expected-note {{Loop condition is true.  Entering loop 
body}} 
+ // expected-note@-1 {{Loop condition is false. Execution 
continues on line 67}}
+   new int(10),  // expected-note {{Value assigned to 'num'}}
+   i < flag_d;
+   ++i) {
+++num;
+  }
+  if (num == 0) // expected-note {{Assuming 'num' is equal to 0}} 
+// expected-note@-1 {{Taking true branch}}
+flag_d += 10;
+  return flag_d / num; // no-crash expected-warning {{Division by zero}} 
+   // expected-note@-1 {{Division by zero}}
+}
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -690,6 +690,17 @@
 return getLocationForCaller(CEE->getCalleeContext(),
 CEE->getLocationContext(),
 SMng);
+  } else if (Optional BE = P.getAs()) {
+CFGElement BlockFront = BE->getBlock()->front();
+if (BlockFront.getKind() == CFGElement::Kind::Statement) {
+  return PathDiagnosticLocation(
+  BlockFront.getAs()->getStmt()->getLocStart(), SMng);
+} else if (BlockFront.getKind() == CFGElement::Kind::NewAllocator) {
+  return PathDiagnosticLocation(BlockFront.getAs()
+->getAllocatorExpr()
+->getLocStart(),
+SMng);
+}
   } else {
 llvm_unreachable("Unexpected ProgramPoint");
   }


Index: test/Analysis/loop-widening-notes.cpp
===
--- /dev/null
+++ test/Analysis/loop-widening-notes.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha -analyzer-max-loop 2 -analyzer-config widen-loops=true -analyzer-output=text -verify %s
+
+int *p_a;
+int bar();
+int flag_a;
+int test_

[PATCH] D40279: [libcxxabi][demangler] Add demangling for __attribute__((abi_tag))

2017-11-21 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 123787.
erik.pilkington added a comment.

In this new patch:

- Update the comment BNF to show the new attribute, fix comment formatting
- Move call to parse_abi_tag_seq() from parse_unqualified_name() to 
parse_operator_name() to more closely model BNF

Thanks!


https://reviews.llvm.org/D40279

Files:
  src/cxa_demangle.cpp
  test/test_demangle.pass.cpp

Index: test/test_demangle.pass.cpp
===
--- test/test_demangle.pass.cpp
+++ test/test_demangle.pass.cpp
@@ -29605,6 +29605,12 @@
 {"_ZTW1x", "thread-local wrapper routine for x"},
 {"_ZTHN3fooE", "thread-local initialization routine for foo"},
 {"_Z4algoIJiiiEEvZ1gEUlT_E_", "void algo(g::'lambda'(int, int, int))"},
+// attribute abi_tag
+{"_Z1fB3foov", "f[abi:foo]()"},
+{"_Z1fB3fooB3barv", "f[abi:foo][abi:bar]()"},
+{"_ZN1SB5outer1fB5innerEv", "S[abi:outer]::f[abi:inner]()"},
+{"_ZN1SC2B8ctor_tagEv", "S::S[abi:ctor_tag]()"},
+{"_ZplB4MERP1SS_", "operator+[abi:MERP](S, S)"},
 };
 
 const unsigned N = sizeof(cases) / sizeof(cases[0]);
Index: src/cxa_demangle.cpp
===
--- src/cxa_demangle.cpp
+++ src/cxa_demangle.cpp
@@ -184,6 +184,7 @@
 KConversionOperatorType,
 KPostfixQualifiedType,
 KNameType,
+KAbiTagAttr,
 KObjCProtoName,
 KPointerType,
 KLValueReferenceType,
@@ -390,6 +391,21 @@
   void printLeft(OutputStream &s) const override { s += Name; }
 };
 
+class AbiTagAttr final : public Node {
+  const Node* Base;
+  StringView Tag;
+public:
+  AbiTagAttr(const Node* Base_, StringView Tag_)
+  : Node(KAbiTagAttr), Base(Base_), Tag(Tag_) {}
+
+  void printLeft(OutputStream &S) const override {
+Base->printLeft(S);
+S += "[abi:";
+S += Tag;
+S += "]";
+  }
+};
+
 class ObjCProtoName : public Node {
   Node *Ty;
   Node *Protocol;
@@ -1801,10 +1817,9 @@
 return first;
 }
 
-//  ::=  
-
+//  ::= [0-9]*
 const char*
-parse_source_name(const char* first, const char* last, Db& db)
+parse_positive_integer(const char* first, const char* last, size_t* out)
 {
 if (first != last)
 {
@@ -1819,15 +1834,53 @@
 if (++t == last)
 return first;
 }
-if (static_cast(last - t) >= n)
-{
-StringView r(t, t + n);
-if (r.substr(0, 10) == "_GLOBAL__N")
-db.Names.push_back(db.make("(anonymous namespace)"));
-else
-db.Names.push_back(db.make(r));
-first = t + n;
-}
+*out = n;
+first = t;
+}
+}
+return first;
+}
+
+// extension
+//  ::= *
+//  ::= B  
+const char*
+parse_abi_tag_seq(const char* first, const char* last, Db& db)
+{
+while (first != last && *first == 'B' && first+1 != last)
+{
+size_t length;
+const char* t = parse_positive_integer(first+1, last, &length);
+if (t == first+1)
+return first;
+if (static_cast(last - t) < length || db.Names.empty())
+return first;
+db.Names.back() = db.make(
+db.Names.back(), StringView(t, t + length));
+first = t + length;
+}
+return first;
+}
+
+//  ::=   []
+const char*
+parse_source_name(const char* first, const char* last, Db& db)
+{
+if (first != last)
+{
+size_t length;
+const char* t = parse_positive_integer(first, last, &length);
+if (t == first)
+return first;
+if (static_cast(last - t) >= length)
+{
+StringView r(t, t + length);
+if (r.substr(0, 10) == "_GLOBAL__N")
+db.Names.push_back(db.make("(anonymous namespace)"));
+else
+db.Names.push_back(db.make(r));
+first = t + length;
+first = parse_abi_tag_seq(first, last, db);
 }
 }
 return first;
@@ -3763,10 +3816,11 @@
 //   ::= rs# >>
 //   ::= rS# >>=   
 //   ::= v  # vendor extended operator
-
+//   extension   ::=  
 const char*
 parse_operator_name(const char* first, const char* last, Db& db)
 {
+const char* original_first = first;
 if (last - first >= 2)
 {
 switch (first[0])
@@ -4063,6 +4117,10 @@
 break;
 }
 }
+
+if (original_first != first)
+first = parse_abi_tag_seq(first, last, db);
+
 return first;
 }
 
@@ -4299,7 +4357,7 @@
 //  ::= D1# complete object destructor
 //  ::= D2# base object destructor
 //   extension  ::= D5# ?
-
+//   extension  ::=  
 const char*
 parse_ctor_dtor_name(const char* first, const char* last, Db& db)
 {
@@ -4321,6 +4379,7 @@
 db.Names.push_back(
 db.make(d

[PATCH] D40279: [libcxxabi][demangler] Add demangling for __attribute__((abi_tag))

2017-11-21 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington marked 5 inline comments as done.
erik.pilkington added inline comments.



Comment at: src/cxa_demangle.cpp:10
 
+// FIXME: (possibly) incomplete list of features that clang mangles that this
+// file does not yet support:

EricWF wrote:
> Awesome comment!
> 
> If your awesomeness knows no bound, I would love to add currently-failing 
> tests that demonstrate the FIXME.
> Obviously that has no bearing on how this patch proceeds. 
Sure, r318765



Comment at: src/cxa_demangle.cpp:1848
+//  ::= B  
+
+const char*

EricWF wrote:
> I realize the unneeded blank line is part of the existing style... But I 
> fudging hate it.
> 
> If you're not opposed I would love to start removing the unneeded line 
> wherever it's
> part of this changeset.
I'm not opposed! The new patch removes it in the functions I touched


https://reviews.llvm.org/D40279



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


[PATCH] D37187: [Analyzer] Fix Bug 25609 - Assertion UNREACHABLE: 'Unexpected ProgramPoint' with widen-loops=true

2017-11-21 Thread Henry Wong via Phabricator via cfe-commits
MTC marked an inline comment as done.
MTC added inline comments.



Comment at: lib/StaticAnalyzer/Core/PathDiagnostic.cpp:694
+  } else if (Optional BE = P.getAs()) {
+CFGElement BlockFront = BE->getBlock()->front();
+if (BlockFront.getKind() == CFGElement::Statement) {

dcoughlin wrote:
> MTC wrote:
> > szepet wrote:
> > > I think it would be more correct to use the location what is used in case 
> > > of the BlockEdge. (So on the entranced block terminator condition.) The 
> > > reason is because the BlockEntrance display message will be displayed 
> > > before the message of the BlockEdge (since it is an "earlier" node in the 
> > > ExplodedGraph). So it would result that if check these notes in a viewer 
> > > then the earlier note would belong to the later location which could be 
> > > confusing.
> > Yes, it would be better to use the location of the TerminatorCondition :D.
> Thanks for looking into fixing this.
> 
> I don't think using the terminator condition of the entered block is the 
> right thing to do. The terminator is at the *end* of a basic block and this 
> program point represents the entrance to the block. I think it is better to 
> use the location corresponding to the first element in in the entered block.
Thank you, dcoughlin!

I have updated the diff.  The first element  kind I can think of is only `Stmt` 
and `NewAllocator`. I don't know if it's enough? 



https://reviews.llvm.org/D37187



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-21 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 123792.
tk1012 added a comment.

Hello Gábor,

Thank you for responding.

I move the definition of the mather `typeTraitExpr` into 
unittests/AST/ASTImporterTest.cpp.
I also slightly modify the test code.


https://reviews.llvm.org/D39722

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,27 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,28 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for (auto FromArg : E->getArgs()) {
+TypeSourceInfo *ToTI = Importer.Import(FromArg);
+if (!ToTI)
+  return nullptr;
+ToArgVec.push_back(ToTI);
+  }
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = (!E->isValueDependent()) ? E->getValue() : false;
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgVec, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,27 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,28 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for (auto FromArg : E->getArgs()) {
+TypeSourceInfo *ToTI = Importer.Import(FromArg);
+if (!ToTI)
+  return nullptr;
+ToArgVec.push_back(ToTI);
+  }
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = (!E->isV

[PATCH] D40068: Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-21 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

Generally, this indeed improves the situation (though I cannot say much about 
the code itself, it is still too subtle for my shallow knowledge of 
clang-format).

But it seems to give some strange looking result with long comments: it seems 
like the decision is made at each line (e.g. is it better to wrap this line or 
overflow a bit), so we can get a comment where each line overflows by a few 
characters, even if the total is worse... For exemple, say we have a 100 lines 
of comment, with 9 characters overflow on each line, and an excess character 
penalty of 30 : with this patch nothing will be re-wrapped (9*30 = 270 is less 
the the 300 penalty for wrapping); but the total penatly would be 900

(btw, it seems this got merged, but the ticket does not reflect it)




Comment at: lib/Format/BreakableToken.cpp:293
   Split ReflowSplit =
-  FullWidth <= ColumnLimit
-  ? Split(TrimmedText.size(), Text.size() - TrimmedText.size())
-  : getCommentSplit(Text, ReflowStartColumn, ColumnLimit,
-Style.TabWidth, Encoding);
-
+//  FullWidth <= ColumnLimit
+  //? 

commented-out code to be removed?



Comment at: lib/Format/BreakableToken.cpp:300
+
+  return ReflowSplit;
   // We need to be extra careful here, because while it's OK to keep a long 
line

unconditional return --> remove the end of the function



Comment at: lib/Format/BreakableToken.cpp:572
+  return Split(0, 0);
+  /*
   StringRef TrimmedContent = Content[LineIndex].ltrim(Blanks);

remove commented-out code



Comment at: lib/Format/BreakableToken.cpp:603
+  // FIXME: pull together with getLineLegnthAfterSplit (same as for
+  // BreakableLineCommentSeciotn.
+  unsigned ContentStartColumn = 0;

BreakableLineCommentSection


https://reviews.llvm.org/D40068



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


[PATCH] D40182: [clangd] Add parsing and value inspection to JSONExpr.

2017-11-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/JSONExpr.h:62
+// Array and Object also have typed indexing accessors for easy traversal:
+//   if (json::obj* Opts = O.array("options"))
+// if (Optional Font = Opts->string("font"))

ioeric wrote:
> It's not obvious what `O.array("options")` does. Does it convert 
> `O.at("options")` to an array?
Yes. Added a bit more context here.



Comment at: clangd/JSONExpr.h:78
 public:
-  class Object;
+  enum Kind {
+Null,

ioeric wrote:
> I wonder if we could merge `Kind` and `ExprType`.
As discussed offline, the conceptual difference is public API vs internal 
implementation. If there was no difference in practice, YAGNI, but we have 
String->{T_String, T_StringRef}.

So either we need two enums or some hidden internal state which helps us 
distinguish. The latter seems more error prone to me (e.g. no help from 
-Wswitch).

So I prefer the current way overall, though it's not a really big deal.


https://reviews.llvm.org/D40182



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


[PATCH] D40182: [clangd] Add parsing and value inspection to JSONExpr.

2017-11-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 123794.
sammccall added a comment.

Address comment.


https://reviews.llvm.org/D40182

Files:
  clangd/JSONExpr.cpp
  clangd/JSONExpr.h
  unittests/clangd/JSONExprTests.cpp

Index: unittests/clangd/JSONExprTests.cpp
===
--- unittests/clangd/JSONExprTests.cpp
+++ unittests/clangd/JSONExprTests.cpp
@@ -15,6 +15,9 @@
 namespace clang {
 namespace clangd {
 namespace json {
+void PrintTo(const Expr &E, std::ostream *OS) {
+  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
+}
 namespace {
 
 std::string s(const Expr &E) { return llvm::formatv("{0}", E).str(); }
@@ -108,6 +111,77 @@
  }));
 }
 
+TEST(JSONTest, Parse) {
+  auto Compare = [](llvm::StringRef S, Expr Expected) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  EXPECT_EQ(*E, Expected);
+  EXPECT_EQ(sp(*E), sp(Expected));
+} else {
+  handleAllErrors(E.takeError(), [S](const llvm::ErrorInfoBase &E) {
+FAIL() << "Failed to parse JSON >>> " << S << " <<<: " << E.message();
+  });
+}
+  };
+
+  Compare(R"(true)", true);
+  Compare(R"(false)", false);
+  Compare(R"(null)", nullptr);
+
+  Compare(R"(42)", 42);
+  Compare(R"(2.5)", 2.5);
+  Compare(R"(2e50)", 2e50);
+  Compare(R"(1.2e3456789)", 1.0 / 0.0);
+
+  Compare(R"("foo")", "foo");
+  Compare(R"("\"\\\b\f\n\r\t")", "\"\\\b\f\n\r\t");
+  Compare(R"("\u")", llvm::StringRef("\0", 1));
+  Compare("\"\x7f\"", "\x7f");
+  Compare(R"("\ud801\udc37")", "\U00010437"); // UTF16 surrogate pair escape.
+  Compare("\"\xE2\x82\xAC\xF0\x9D\x84\x9E\"", "\u20ac\U0001d11e"); // UTF8
+  Compare(R"("\ud801")", "\ufffd"); // Invalid codepoint.
+
+  Compare(R"({"":0,"":0})", obj{{"", 0}});
+  Compare(R"({"obj":{},"arr":[]})", obj{{"obj", obj{}}, {"arr", {}}});
+  Compare(R"({"\n":{"\u":}})",
+  obj{{"\n", obj{
+ {llvm::StringRef("\0", 1), },
+ }}});
+  Compare("\r[\n\t] ", {});
+}
+
+TEST(JSONTest, ParseErrors) {
+  auto ExpectErr = [](llvm::StringRef Msg, llvm::StringRef S) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  FAIL() << "Parsed JSON >>> " << S << " <<< but wanted error: " << Msg;
+} else {
+  handleAllErrors(E.takeError(), [S, Msg](const llvm::ErrorInfoBase &E) {
+EXPECT_THAT(E.message(), testing::HasSubstr(Msg)) << S;
+  });
+}
+  };
+  ExpectErr("Unexpected EOF", "");
+  ExpectErr("Unexpected EOF", "[");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Invalid bareword", "fuzzy");
+  ExpectErr("Expected , or ]", "[2?]");
+  ExpectErr("Expected object key", "{a:2}");
+  ExpectErr("Expected : after object key", R"({"a",2})");
+  ExpectErr("Expected , or } after object property", R"({"a":2 "b":3})");
+  ExpectErr("Expected JSON value", R"([&%!])");
+  ExpectErr("Invalid number", "1e1.0");
+  ExpectErr("Unterminated string", R"("abc\"def)");
+  ExpectErr("Control character in string", "\"abc\ndef\"");
+  ExpectErr("Invalid escape sequence", R"("\030")");
+  ExpectErr("Invalid \\u escape sequence", R"("\usuck")");
+  ExpectErr("[3:3, byte=19]", R"({
+  "valid": 1,
+  invalid: 2
+})");
+}
+
 } // namespace
 } // namespace json
 } // namespace clangd
Index: clangd/JSONExpr.h
===
--- clangd/JSONExpr.h
+++ clangd/JSONExpr.h
@@ -1,30 +1,35 @@
-//===--- JSONExpr.h - composable JSON expressions ---*- C++ -*-===//
+//===--- JSONExpr.h - JSON expressions, parsing and serialization - C++ -*-===//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===-===//
 
+// FIXME: rename to JSON.h now that the scope is wider?
+
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_JSON_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_JSON_H
 
 #include 
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace json {
 
-// An Expr is an opaque temporary JSON structure used to compose documents.
+// An Expr is an JSON value of unknown type.
 // They can be copied, but should generally be moved.
 //
-// You can implicitly construct literals from:
+// === Composing expressions ===
+//
+// You can implicitly construct Exprs from:
 //   - strings: std::string, SmallString, formatv, StringRef, char*
 //  (char*, and StringRef are references, not copies!)
 //   - numbers
@@ -39,25 +44,62 @@
 // These can be list-initialized, or used to build up col

[PATCH] D40276: Add -finstrument-function-entry-bare flag

2017-11-21 Thread Matthew Cary via Phabricator via cfe-commits
mattcary added a comment.

It looks like there also has to be a change to 
llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp?

Index: lib/Transforms/Utils/EntryExitInstrumenter.cpp
=

- lib/Transforms/Utils/EntryExitInstrumenter.cpp(revision 318760)

+++ lib/Transforms/Utils/EntryExitInstrumenter.cpp  (working copy)
@@ -51,6 +51,10 @@

  CallInst::Create(Fn, ArrayRef(Args), "", InsertionPt);
  return;

+  } else if (Func == "__cyg_profile_func_enter_bare") {
+Constant *Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C));
+CallInst::Create(Fn, "", InsertionPt);
+return;

  }
   
  // We only know how to call a fixed set of instrumentation functions, because


https://reviews.llvm.org/D40276



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


[PATCH] D40182: [clangd] Add parsing and value inspection to JSONExpr.

2017-11-21 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D40182



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-21 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

In https://reviews.llvm.org/D33589#924716, @klimek wrote:

> One interesting trade-off I'm running into:
>  My gut feeling is that we really want to make local decisions about whether 
> we want to break/reflow - this makes the code significantly simpler (IMO), 
> and handles all tests in this patch correctly, but is fundamentally limiting 
> the global optimizations we can do. Specifically, we would not correctly 
> reflow this:
>
>   //   |< limit
>   // foo bar
>   // baz
>   // x
>
> to
>
>   // foo
>   // bar
>   // baz x
>
> when the excess character limit is low.


As I can see with your patch, local decision does not account for accumulated 
penalty on multi-line comment, and will thus give unexpected (e.g. no change) 
result when each line overlaps by a few characters, but not enough to trigger a 
break at this line.

> That would be a point for global optimization, but I find it really hard to 
> understand exactly why it's ok to do it. Won't we get things like this wrong:
> 
>   Limit: 13
>   // foo  bar baz
>   // bab  bob
> 
> as we'll not compress whitespace?

Indeed, this patch would not trigger whitespace compression when not reflowing; 
it would compare "not doing anything" (no reflow, no whitespace compression) 
with the complete reflowing (including whitespace compression). I don't think 
that would break anything, but indeed we could possibly get even better result 
by trying to apply whitespace compression in the no-reflow case [which should 
be simple, just a bit more code at line 1376 in the version of the patch].


https://reviews.llvm.org/D33589



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


[PATCH] D40044: [CodeGen] convert math libcalls/builtins to equivalent LLVM intrinsics

2017-11-21 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

Ping.


https://reviews.llvm.org/D40044



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-21 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

In https://reviews.llvm.org/D33589#925903, @klimek wrote:

> I think this patch doesn't handle a couple of cases that I'd like to see 
> handled. A counter-proposal with different trade-offs is in 
> https://reviews.llvm.org/D40068.


It may be simpler (though not to my eyes, I am not knowledgeable enough to 
really understand how you go this fixed...), and works fine for "almost 
correct" comments: e.g. when there are indeed just a few extra characters 
overall. But it still procudes strange result when each line of the (long) 
comment is too long, but not enough to trigger a line-wrap by itself.

Since that version has landed already, not sure how to improve on this. I could 
probably rewrite my patch on master, but it seems a bit redundant. As a simpler 
fix, I could imagine adding a "total" overflow counter, to allow detecting the 
situation; but when this is detected (e.g. on subsequent lines) we would need 
to "backtrack" and revisit the initial decision...


https://reviews.llvm.org/D33589



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


[PATCH] D40279: [libcxxabi][demangler] Add demangling for __attribute__((abi_tag))

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


https://reviews.llvm.org/D40279



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


[clang-tools-extra] r318774 - [clangd] Add parsing and value inspection to JSONExpr.

2017-11-21 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Nov 21 08:00:53 2017
New Revision: 318774

URL: http://llvm.org/viewvc/llvm-project?rev=318774&view=rev
Log:
[clangd] Add parsing and value inspection to JSONExpr.

Summary:
This will replace the places where we're using YAMLParser to parse JSON now:
  - the new marshalling code (T::parse()) should handle fewer cases and require
fewer explicit casts
  - we'll early-reject invalid JSON that YAMLParser accepts
  - we'll be able to fix protocol-parsing bugs caused by the fact that YAML can
only parse forward

I plan to do the conversion as soon as this lands, but I don't want it in one
patch as the protocol.cpp changes are conflict-prone.

Reviewers: ioeric

Subscribers: ilya-biryukov, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/JSONExpr.cpp
clang-tools-extra/trunk/clangd/JSONExpr.h
clang-tools-extra/trunk/unittests/clangd/JSONExprTests.cpp

Modified: clang-tools-extra/trunk/clangd/JSONExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONExpr.cpp?rev=318774&r1=318773&r2=318774&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONExpr.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONExpr.cpp Tue Nov 21 08:00:53 2017
@@ -22,10 +22,10 @@ void Expr::copyFrom(const Expr &M) {
 create(M.as());
 break;
   case T_Object:
-create(M.as());
+create(M.as());
 break;
   case T_Array:
-create(M.as());
+create(M.as());
 break;
   }
 }
@@ -46,11 +46,11 @@ void Expr::moveFrom(const Expr &&M) {
 M.Type = T_Null;
 break;
   case T_Object:
-create(std::move(M.as()));
+create(std::move(M.as()));
 M.Type = T_Null;
 break;
   case T_Array:
-create(std::move(M.as()));
+create(std::move(M.as()));
 M.Type = T_Null;
 break;
   }
@@ -69,14 +69,318 @@ void Expr::destroy() {
 as().~basic_string();
 break;
   case T_Object:
-as().~Object();
+as().~ObjectExpr();
 break;
   case T_Array:
-as().~Array();
+as().~ArrayExpr();
 break;
   }
 }
 
+namespace {
+// Simple recursive-descent JSON parser.
+class Parser {
+public:
+  Parser(StringRef JSON)
+  : Start(JSON.begin()), P(JSON.begin()), End(JSON.end()) {}
+
+  bool parseExpr(Expr &Out);
+
+  bool assertEnd() {
+eatWhitespace();
+if (P == End)
+  return true;
+return parseError("Text after end of document");
+  }
+
+  Error takeError() {
+assert(Error);
+return std::move(*Error);
+  }
+
+private:
+  void eatWhitespace() {
+while (P != End && (*P == ' ' || *P == '\r' || *P == '\n' || *P == '\t'))
+  ++P;
+  }
+
+  // On invalid syntax, parseX() functions return false and and set Error.
+  bool parseNumber(char First, double &Out);
+  bool parseString(std::string &Out);
+  bool parseUnicode(std::string &Out);
+  bool parseError(const char *Msg); // always returns false
+
+  char next() { return P == End ? 0 : *P++; }
+  char peek() { return P == End ? 0 : *P; }
+  static bool isNumber(char C) {
+return C == '0' || C == '1' || C == '2' || C == '3' || C == '4' ||
+   C == '5' || C == '6' || C == '7' || C == '8' || C == '9' ||
+   C == 'e' || C == 'E' || C == '+' || C == '-' || C == '.';
+  }
+  static void encodeUtf8(uint32_t Rune, std::string &Out);
+
+  Optional Error;
+  const char *Start, *P, *End;
+};
+
+bool Parser::parseExpr(Expr &Out) {
+  eatWhitespace();
+  if (P == End)
+return parseError("Unexpected EOF");
+  switch (char C = next()) {
+  // Bare null/true/false are easy - first char identifies them.
+  case 'n':
+Out = nullptr;
+return (next() == 'u' && next() == 'l' && next() == 'l') ||
+   parseError("Invalid bareword");
+  case 't':
+Out = true;
+return (next() == 'r' && next() == 'u' && next() == 'e') ||
+   parseError("Invalid bareword");
+  case 'f':
+Out = false;
+return (next() == 'a' && next() == 'l' && next() == 's' && next() == 'e') 
||
+   parseError("Invalid bareword");
+  case '"': {
+std::string S;
+if (parseString(S)) {
+  Out = std::move(S);
+  return true;
+}
+return false;
+  }
+  case '[': {
+Out = json::ary{};
+json::ary &A = *Out.array();
+eatWhitespace();
+if (peek() == ']') {
+  ++P;
+  return true;
+}
+for (;;) {
+  A.emplace_back(nullptr);
+  if (!parseExpr(A.back()))
+return false;
+  eatWhitespace();
+  switch (next()) {
+  case ',':
+eatWhitespace();
+continue;
+  case ']':
+return true;
+  default:
+return parseError("Expected , or ] after array element");
+  }
+}
+  }
+  case '{': {
+Out = json::obj{};
+json::obj &O = *Out.object();
+eatWhitespace();
+if (peek() == '}') {
+  ++P;
+  return true;
+}
+for (;;) {
+  if (next() != '"')
+return parseError

[PATCH] D40182: [clangd] Add parsing and value inspection to JSONExpr.

2017-11-21 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318774: [clangd] Add parsing and value inspection to 
JSONExpr. (authored by sammccall).

Repository:
  rL LLVM

https://reviews.llvm.org/D40182

Files:
  clang-tools-extra/trunk/clangd/JSONExpr.cpp
  clang-tools-extra/trunk/clangd/JSONExpr.h
  clang-tools-extra/trunk/unittests/clangd/JSONExprTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/JSONExprTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/JSONExprTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/JSONExprTests.cpp
@@ -15,6 +15,9 @@
 namespace clang {
 namespace clangd {
 namespace json {
+void PrintTo(const Expr &E, std::ostream *OS) {
+  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
+}
 namespace {
 
 std::string s(const Expr &E) { return llvm::formatv("{0}", E).str(); }
@@ -108,6 +111,77 @@
  }));
 }
 
+TEST(JSONTest, Parse) {
+  auto Compare = [](llvm::StringRef S, Expr Expected) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  EXPECT_EQ(*E, Expected);
+  EXPECT_EQ(sp(*E), sp(Expected));
+} else {
+  handleAllErrors(E.takeError(), [S](const llvm::ErrorInfoBase &E) {
+FAIL() << "Failed to parse JSON >>> " << S << " <<<: " << E.message();
+  });
+}
+  };
+
+  Compare(R"(true)", true);
+  Compare(R"(false)", false);
+  Compare(R"(null)", nullptr);
+
+  Compare(R"(42)", 42);
+  Compare(R"(2.5)", 2.5);
+  Compare(R"(2e50)", 2e50);
+  Compare(R"(1.2e3456789)", 1.0 / 0.0);
+
+  Compare(R"("foo")", "foo");
+  Compare(R"("\"\\\b\f\n\r\t")", "\"\\\b\f\n\r\t");
+  Compare(R"("\u")", llvm::StringRef("\0", 1));
+  Compare("\"\x7f\"", "\x7f");
+  Compare(R"("\ud801\udc37")", "\U00010437"); // UTF16 surrogate pair escape.
+  Compare("\"\xE2\x82\xAC\xF0\x9D\x84\x9E\"", "\u20ac\U0001d11e"); // UTF8
+  Compare(R"("\ud801")", "\ufffd"); // Invalid codepoint.
+
+  Compare(R"({"":0,"":0})", obj{{"", 0}});
+  Compare(R"({"obj":{},"arr":[]})", obj{{"obj", obj{}}, {"arr", {}}});
+  Compare(R"({"\n":{"\u":}})",
+  obj{{"\n", obj{
+ {llvm::StringRef("\0", 1), },
+ }}});
+  Compare("\r[\n\t] ", {});
+}
+
+TEST(JSONTest, ParseErrors) {
+  auto ExpectErr = [](llvm::StringRef Msg, llvm::StringRef S) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  FAIL() << "Parsed JSON >>> " << S << " <<< but wanted error: " << Msg;
+} else {
+  handleAllErrors(E.takeError(), [S, Msg](const llvm::ErrorInfoBase &E) {
+EXPECT_THAT(E.message(), testing::HasSubstr(Msg)) << S;
+  });
+}
+  };
+  ExpectErr("Unexpected EOF", "");
+  ExpectErr("Unexpected EOF", "[");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Invalid bareword", "fuzzy");
+  ExpectErr("Expected , or ]", "[2?]");
+  ExpectErr("Expected object key", "{a:2}");
+  ExpectErr("Expected : after object key", R"({"a",2})");
+  ExpectErr("Expected , or } after object property", R"({"a":2 "b":3})");
+  ExpectErr("Expected JSON value", R"([&%!])");
+  ExpectErr("Invalid number", "1e1.0");
+  ExpectErr("Unterminated string", R"("abc\"def)");
+  ExpectErr("Control character in string", "\"abc\ndef\"");
+  ExpectErr("Invalid escape sequence", R"("\030")");
+  ExpectErr("Invalid \\u escape sequence", R"("\usuck")");
+  ExpectErr("[3:3, byte=19]", R"({
+  "valid": 1,
+  invalid: 2
+})");
+}
+
 } // namespace
 } // namespace json
 } // namespace clangd
Index: clang-tools-extra/trunk/clangd/JSONExpr.h
===
--- clang-tools-extra/trunk/clangd/JSONExpr.h
+++ clang-tools-extra/trunk/clangd/JSONExpr.h
@@ -1,30 +1,35 @@
-//===--- JSONExpr.h - composable JSON expressions ---*- C++ -*-===//
+//===--- JSONExpr.h - JSON expressions, parsing and serialization - C++ -*-===//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===-===//
 
+// FIXME: rename to JSON.h now that the scope is wider?
+
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_JSON_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_JSON_H
 
 #include 
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace json {
 
-// An Expr is an opaque temporary JSON structure used to compose documents.
+// An Expr is an JSON value of unknown type.
 // They can be copied, but should generally be moved.
 //
-// You can implicitly construct li

[PATCH] D40310: Restructure how we break tokens.

2017-11-21 Thread Manuel Klimek via Phabricator via cfe-commits
klimek created this revision.

This fixes some bugs in the reflowing logic and splits out the concerns
of reflowing from BreakableToken.

Things to do after this patch:

- Refactor the breakProtrudingToken function possibly into a class, so we can 
split it up into methods that operate on the common state.
- Optimize whitespace compression when reflowing by using the next possible 
split point instead of the latest possible split point.


https://reviews.llvm.org/D40310

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -1096,11 +1096,12 @@
 }
 
 TEST_F(FormatTestComments, SplitsLongLinesInComments) {
+  // FIXME: Do we need to fix up the "  */" at the end?
+  // It doesn't look like any of our current logic triggers this.
   EXPECT_EQ("/* This is a long\n"
 " * comment that\n"
-" * doesn't\n"
-" * fit on one line.\n"
-" */",
+" * doesn't fit on\n"
+" * one line.  */",
 format("/* "
"This is a long "
"comment that "
@@ -2102,6 +2103,66 @@
   EXPECT_EQ("///", format(" ///  ", getLLVMStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestComments, ReflowsCommentsPrecise) {
+  // FIXME: This assumes we do not continue compressing whitespace once we are
+  // in reflow mode. Consider compressing whitespace.
+
+  // Test that we stop reflowing precisely at the column limit.
+  // After reflowing, "// reflows into   foo" does not fit the column limit,
+  // so we compress the whitespace.
+  EXPECT_EQ("// some text that\n"
+"// reflows into foo\n",
+format("// some text that reflows\n"
+   "// into   foo\n",
+   getLLVMStyleWithColumns(20)));
+  // Given one more column, "// reflows into   foo" does fit the limit, so we
+  // do not compress the whitespace.
+  EXPECT_EQ("// some text that\n"
+"// reflows into   foo\n",
+format("// some text that reflows\n"
+   "// into   foo\n",
+   getLLVMStyleWithColumns(21)));
+}
+
+TEST_F(FormatTestComments, ReflowsCommentsWithExtraWhitespace) {
+  // Baseline.
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// re flows\n",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// reflows\n",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("/* some text\n"
+" * that re flows\n"
+" */\n",
+format("/* some text that\n"
+   "*  re   flows\n"
+   "*/\n",
+   getLLVMStyleWithColumns(16)));
+  // FIXME: We do not reflow if the indent of two subsequent lines differs;
+  // given that this is different behavior from block comments, do we want
+  // to keep this?
+  EXPECT_EQ("// some text\n"
+"// that\n"
+"// re flows\n",
+format("// some text that\n"
+   "// re   flows\n",
+   getLLVMStyleWithColumns(16)));
+  // Space within parts of a line that fit.
+  // FIXME: Use the earliest possible split while reflowing to compress the
+  // whitespace within the line.
+  EXPECT_EQ("// some text that\n"
+"// does re   flow\n"
+"// more  here\n",
+format("// some text that does\n"
+   "// re   flow  more  here\n",
+   getLLVMStyleWithColumns(21)));
+}
+
 TEST_F(FormatTestComments, IgnoresIf0Contents) {
   EXPECT_EQ("#if 0\n"
 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
@@ -2484,6 +2545,7 @@
   " long */\n"
   "  b);",
   format("a = f(a, /* long long */ b);", getLLVMStyleWithColumns(16)));
+
   EXPECT_EQ(
   "a = f(\n"
   "a,\n"
@@ -2888,16 +2950,15 @@
getLLVMStyleWithColumns(20)));
 }
 
-TEST_F(FormatTestComments, NoCrush_Bug34236) {
+TEST_F(FormatTestComments, NoCrash_Bug34236) {
   // This is a test case from a crasher reported in:
   // https://bugs.llvm.org/show_bug.cgi?id=34236
   // Temporarily disable formatting for readability.
   // clang-format off
   EXPECT_EQ(
 "/**/ /*\n"
 "  *   a\n"
-"  * b c\n"
-"

[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-11-21 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

Btw, another issue I am having is that reflowing does not respect the 
alignment. For exemple:

  enum {
 Foo,///< This is a very long comment
 Bar,///< This is shorter  
 BarBar, ///< This is shorter
  } Stuff;

will be reflown to :

  enum {
 Foo, ///< This is a very long
  ///< comment
 Bar, ///< This is shorter  
 BarBar, ///< This is shorter
  } Stuff;

when I would expect:

  enum {
 Foo,///< This is a very
 ///< long comment
 Bar,///< This is shorter  
 BarBar, ///< This is shorter
  } Stuff;

I see there is no penalty for breaking alignment, which may be accounted for 
when compressing the whitespace 'before' the comment... Or maybe simply the 
breaking should be smarter, to try to keep the alignment; but I am not sure it 
can be done without another kind of 'global' optimization of the comment 
reflow... Any idea/hint?


https://reviews.llvm.org/D33589



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


r318776 - [ASTImporter] Support new AST nodes:

2017-11-21 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Tue Nov 21 08:08:41 2017
New Revision: 318776

URL: http://llvm.org/viewvc/llvm-project?rev=318776&view=rev
Log:
[ASTImporter] Support new AST nodes:

 * UnresolvedUsingType
 * EmptyDecl
 * NamespaceAliasDecl
 * UsingDecl
 * UsingShadowDecl
 * UsingDirectiveDecl
 * UnresolvedUsingValueDecl
 * UnresolvedUsingTypenameDecl

Refactor error handling in ImportTemplateArgumentLoc() method.
Add a test for inline namespaces.


Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/test/ASTMerge/namespace/Inputs/namespace1.cpp
cfe/trunk/test/ASTMerge/namespace/Inputs/namespace2.cpp
cfe/trunk/test/ASTMerge/namespace/test.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=318776&r1=318775&r2=318776&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 21 08:08:41 2017
@@ -58,7 +58,7 @@ namespace clang {
 QualType VisitExtVectorType(const ExtVectorType *T);
 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
 QualType VisitFunctionProtoType(const FunctionProtoType *T);
-// FIXME: UnresolvedUsingType
+QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T);
 QualType VisitParenType(const ParenType *T);
 QualType VisitTypedefType(const TypedefType *T);
 QualType VisitTypeOfExprType(const TypeOfExprType *T);
@@ -129,8 +129,8 @@ namespace clang {
 TemplateParameterList *ImportTemplateParameterList(
  TemplateParameterList 
*Params);
 TemplateArgument ImportTemplateArgument(const TemplateArgument &From);
-TemplateArgumentLoc ImportTemplateArgumentLoc(
-const TemplateArgumentLoc &TALoc, bool &Error);
+Optional ImportTemplateArgumentLoc(
+const TemplateArgumentLoc &TALoc);
 bool ImportTemplateArguments(const TemplateArgument *FromArgs,
  unsigned NumFromArgs,
SmallVectorImpl &ToArgs);
@@ -143,10 +143,12 @@ namespace clang {
 bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
 bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
 Decl *VisitDecl(Decl *D);
+Decl *VisitEmptyDecl(EmptyDecl *D);
 Decl *VisitAccessSpecDecl(AccessSpecDecl *D);
 Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
 Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D);
 Decl *VisitNamespaceDecl(NamespaceDecl *D);
+Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
 Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
 Decl *VisitTypedefDecl(TypedefDecl *D);
 Decl *VisitTypeAliasDecl(TypeAliasDecl *D);
@@ -172,6 +174,12 @@ namespace clang {
 Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D);
 Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
 Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D);
+Decl *VisitUsingDecl(UsingDecl *D);
+Decl *VisitUsingShadowDecl(UsingShadowDecl *D);
+Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
+Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
+Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
+
 
 ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list);
 Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
@@ -569,6 +577,22 @@ QualType ASTNodeImporter::VisitFunctionP
   return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, 
ToEPI);
 }
 
+QualType ASTNodeImporter::VisitUnresolvedUsingType(
+const UnresolvedUsingType *T) {
+  UnresolvedUsingTypenameDecl *ToD = cast_or_null(
+Importer.Import(T->getDecl()));
+  if (!ToD)
+return QualType();
+
+  UnresolvedUsingTypenameDecl *ToPrevD =
+  cast_or_null(
+Importer.Import(T->getDecl()->getPreviousDecl()));
+  if (!ToPrevD && T->getDecl()->getPreviousDecl())
+return QualType();
+
+  return Importer.getToContext().getTypeDeclType(ToD, ToPrevD);
+}
+
 QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
   QualType ToInnerType = Importer.Import(T->getInnerType());
   if (ToInnerType.isNull())
@@ -1183,9 +1207,8 @@ ASTNodeImporter::ImportTemplateArgument(
   llvm_unreachable("Invalid template argument kind");
 }
 
-TemplateArgumentLoc ASTNodeImporter::ImportTemplateArgumentLoc(
-const TemplateArgumentLoc &TALoc, bool &Error) {
-  Error = false;
+Optional
+ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) {
   TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument());
   TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
   TemplateArgumentLocInfo ToInfo;
@@ -1193,12 +1216,12 @@ TemplateArgumentLoc ASTNodeImporter::Imp
 Expr *E = Importer.Import(FromInfo.getAsExpr());
 ToInfo = TemplateArgumentLocInfo(E);
 if (!E)
-  Error = true;
+  return

[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)

2017-11-21 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin closed this revision.
a.sidorin added a comment.

Closed with https://reviews.llvm.org/rL318776 (forgot Differential Revision, 
sorry).


https://reviews.llvm.org/D32751



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


[PATCH] D40065: [libcxx] [test] Change (void)s to TEST_IGNORE_NODISCARD as requested by Eric.

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D40065



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


[clang-tools-extra] r318778 - [clangd] Fix dumb && || bug from r318774

2017-11-21 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Nov 21 08:44:16 2017
New Revision: 318778

URL: http://llvm.org/viewvc/llvm-project?rev=318778&view=rev
Log:
[clangd] Fix dumb && || bug from r318774

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

Modified: clang-tools-extra/trunk/clangd/JSONExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONExpr.cpp?rev=318778&r1=318777&r2=318778&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONExpr.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONExpr.cpp Tue Nov 21 08:44:16 2017
@@ -344,7 +344,7 @@ bool Parser::parseUnicode(std::string &O
 uint16_t Second;
 if (!Parse4Hex(Second))
   return false;
-if (Second < 0xDC00 && Second >= 0xE000) {
+if (Second < 0xDC00 || Second >= 0xE000) {
   Invalid();  // Leading surrogate not followed by trailing.
   First = Second; // Second escape still needs to be processed.
   continue;


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


r318779 - Fix test/OpenMP/nvptx_data_sharing.cpp

2017-11-21 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Tue Nov 21 08:49:11 2017
New Revision: 318779

URL: http://llvm.org/viewvc/llvm-project?rev=318779&view=rev
Log:
Fix test/OpenMP/nvptx_data_sharing.cpp

This was an oversight that stayed in the test from development.

Modified:
cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp

Modified: cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp?rev=318779&r1=318778&r2=318779&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp Tue Nov 21 08:49:11 2017
@@ -26,7 +26,7 @@ void test_ds(){
 // CK1: [[SHAREDARGS:%.+]] = alloca i8**
 // CK1: call i1 @__kmpc_kernel_parallel(i8** %work_fn, i8*** [[SHAREDARGS]])
 // CK1: [[SHARGSTMP:%.+]] = load i8**, i8*** [[SHAREDARGS]]
-// CK1: call void @__omp_outlined___wrapper{{.*}}({{.*}}, i8** %5)
+// CK1: call void @__omp_outlined___wrapper{{.*}}({{.*}}, i8** [[SHARGSTMP]])
 
 /// = In the kernel function = ///
 
@@ -49,4 +49,4 @@ void test_ds(){
 // CK1: [[SHARGSTMP6:%.+]] = load i32*, i32** [[SHARGSTMP5]]
 // CK1: call void @__omp_outlined__({{.*}}, i32* [[SHARGSTMP6]])
 
-#endif
\ No newline at end of file
+#endif


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


[PATCH] D40276: Add -finstrument-function-entry-bare flag

2017-11-21 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Reid, are you happy with this too?

In https://reviews.llvm.org/D40276#931502, @pasko wrote:

> Instrumenting the function entry post-inlining, without function exit, and 
> with no parameters is exactly what we need. The 
> `__cyg_profile_func_enter_bare` sounds good to me as a name. Thank you!


Great!

> Unnecessary thoughts just to get a feeling we are on the same page: this 
> could theoretically be made more orthogonal where 
> `-finstrument-functions-after-inlining` could regulate whether the call is 
> pre- or post-inlining, but I don't see how pre-inlining without parameters 
> would be usable without too much DWARF digging, which is not too practical.

The way I think about them, these flags all enable separate instrumentations 
(though you can only enable one at a time), they don't modify eachother as I 
think that might end up messier for the user.

In https://reviews.llvm.org/D40276#931706, @mattcary wrote:

> It looks like there also has to be a change to 
> llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp?


Yes, I'll land that in llvm once we're happy with this. I just wanted to make 
sure we get the flag and function names right, then the rest is trivial.


https://reviews.llvm.org/D40276



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


[PATCH] D40276: Add -finstrument-function-entry-bare flag

2017-11-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

Yep, looks good. :)


https://reviews.llvm.org/D40276



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


[PATCH] D40259: [libcxx] LWG2993: reference_wrapper

2017-11-21 Thread Agustín Bergé via Phabricator via cfe-commits
K-ballo updated this revision to Diff 123813.
K-ballo added a comment.

Full context diff.


https://reviews.llvm.org/D40259

Files:
  include/__functional_base
  include/functional
  
test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp
  
test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp
  
test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp
  test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp

Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp
===
--- test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp
+++ test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 
 class functor1
 {
@@ -41,4 +42,19 @@
 test(i);
 const int j = 0;
 test(j);
+
+{
+using Ref = std::reference_wrapper;
+static_assert((std::is_constructible::value), "");
+static_assert((!std::is_constructible::value), "");
+static_assert((!std::is_constructible::value), "");
+}
+
+#if TEST_STD_VER >= 11
+{
+using Ref = std::reference_wrapper;
+static_assert((std::is_nothrow_constructible::value), "");
+static_assert((!std::is_nothrow_constructible::value), "");
+}
+#endif
 }
Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp
===
--- /dev/null
+++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp
@@ -0,0 +1,82 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// reference_wrapper
+
+// template 
+//   reference_wrapper(U&&) noexcept(see below);
+
+// XFAIL: c++98, c++03
+
+#include 
+#include 
+
+struct convertible_to_int_ref {
+int val = 0;
+operator int&() { return val; }
+operator int const&() const { return val; }
+};
+
+template 
+struct nothrow_convertible {
+int val = 0;
+operator int&() noexcept(IsNothrow) { return val; }
+};
+
+struct convertible_from_int {
+convertible_from_int(int) {}
+};
+
+void meow(std::reference_wrapper) {}
+void meow(convertible_from_int) {}
+
+int gi;
+std::reference_wrapper purr() { return gi; };
+
+template 
+void
+test(T& t)
+{
+std::reference_wrapper r(t);
+assert(&r.get() == &t);
+}
+
+void f() {}
+
+int main()
+{
+convertible_to_int_ref convi;
+test(convi);
+convertible_to_int_ref const convic;
+test(convic);
+
+{
+using Ref = std::reference_wrapper;
+static_assert((std::is_nothrow_constructible>::value), "");
+static_assert((!std::is_nothrow_constructible>::value), "");
+}
+
+{
+meow(0);
+(true) ? purr() : 0;
+}
+
+#ifdef __cpp_deduction_guides
+{
+int i = 0;
+std::reference_wrapper ri(i);
+static_assert((std::is_same>::value), "" );
+const int j = 0;
+std::reference_wrapper rj(j);
+static_assert((std::is_same>::value), "" );
+}
+#endif
+}
Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp
===
--- /dev/null
+++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp
@@ -0,0 +1,31 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// reference_wrapper
+
+// template 
+//   reference_wrapper(U&&) noexcept(see below);
+
+// XFAIL: c++98, c++03
+
+#include 
+#include 
+
+struct convertible_to_float_ref {
+float val = 0;
+operator float const&() const { return val; }
+};
+
+int main()
+{
+convertible_to_float_ref convf;
+std::reference_wrapper r(convf);
+}
Index: test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp
===
--- test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp
+++ test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp
@@ -15,11 +15,18 @@
 
 #include 
 #include 
+#include 
 
 class functor1
 {
 };
 
+struct convertible_to_int_ref {
+int val = 0;
+operator int&() { return val; }
+operator int const&() const { return val; }
+};
+
 template 
 void
 test(T& t)
@

[clang-tools-extra] r318780 - [clangd] Satisfy GCC: 'changes meaning of Error'

2017-11-21 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Nov 21 09:02:24 2017
New Revision: 318780

URL: http://llvm.org/viewvc/llvm-project?rev=318780&view=rev
Log:
[clangd] Satisfy GCC: 'changes meaning of Error'

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

Modified: clang-tools-extra/trunk/clangd/JSONExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONExpr.cpp?rev=318780&r1=318779&r2=318780&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONExpr.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONExpr.cpp Tue Nov 21 09:02:24 2017
@@ -94,8 +94,8 @@ public:
   }
 
   Error takeError() {
-assert(Error);
-return std::move(*Error);
+assert(Err);
+return std::move(*Err);
   }
 
 private:
@@ -104,7 +104,7 @@ private:
   ++P;
   }
 
-  // On invalid syntax, parseX() functions return false and and set Error.
+  // On invalid syntax, parseX() functions return false and and set Err.
   bool parseNumber(char First, double &Out);
   bool parseString(std::string &Out);
   bool parseUnicode(std::string &Out);
@@ -119,7 +119,7 @@ private:
   }
   static void encodeUtf8(uint32_t Rune, std::string &Out);
 
-  Optional Error;
+  Optional Err;
   const char *Start, *P, *End;
 };
 
@@ -365,7 +365,7 @@ bool Parser::parseError(const char *Msg)
   StartOfLine = X + 1;
 }
   }
-  Error.emplace(
+  Err.emplace(
   llvm::make_unique(Msg, Line, P - StartOfLine, P - Start));
   return false;
 }


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


r318781 - [OPENMP] Initial support for asynchronous data update, NFC.

2017-11-21 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Nov 21 09:08:48 2017
New Revision: 318781

URL: http://llvm.org/viewvc/llvm-project?rev=318781&view=rev
Log:
[OPENMP] Initial support for asynchronous data update, NFC.

OpenMP 5.0 introduces asynchronous data update/dependecies clauses on
target data directives. Patch adds initial support for outer task
regions to use task-based codegen for future async target data
directives.

Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/StmtOpenMP.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=318781&r1=318780&r2=318781&view=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Tue Nov 21 09:08:48 2017
@@ -2348,7 +2348,7 @@ class OMPTargetEnterDataDirective : publ
   unsigned NumClauses)
   : OMPExecutableDirective(this, OMPTargetEnterDataDirectiveClass,
OMPD_target_enter_data, StartLoc, EndLoc,
-   NumClauses, /*NumChildren=*/0) {}
+   NumClauses, /*NumChildren=*/1) {}
 
   /// \brief Build an empty directive.
   ///
@@ -2358,7 +2358,7 @@ class OMPTargetEnterDataDirective : publ
   : OMPExecutableDirective(this, OMPTargetEnterDataDirectiveClass,
OMPD_target_enter_data, SourceLocation(),
SourceLocation(), NumClauses,
-   /*NumChildren=*/0) {}
+   /*NumChildren=*/1) {}
 
 public:
   /// \brief Creates directive with a list of \a Clauses.
@@ -2367,11 +2367,11 @@ public:
   /// \param StartLoc Starting location of the directive kind.
   /// \param EndLoc Ending Location of the directive.
   /// \param Clauses List of clauses.
+  /// \param AssociatedStmt Statement, associated with the directive.
   ///
-  static OMPTargetEnterDataDirective *Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation EndLoc,
- ArrayRef Clauses);
+  static OMPTargetEnterDataDirective *
+  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+ ArrayRef Clauses, Stmt *AssociatedStmt);
 
   /// \brief Creates an empty directive with the place for \a N clauses.
   ///
@@ -2407,7 +2407,7 @@ class OMPTargetExitDataDirective : publi
  unsigned NumClauses)
   : OMPExecutableDirective(this, OMPTargetExitDataDirectiveClass,
OMPD_target_exit_data, StartLoc, EndLoc,
-   NumClauses, /*NumChildren=*/0) {}
+   NumClauses, /*NumChildren=*/1) {}
 
   /// \brief Build an empty directive.
   ///
@@ -2417,7 +2417,7 @@ class OMPTargetExitDataDirective : publi
   : OMPExecutableDirective(this, OMPTargetExitDataDirectiveClass,
OMPD_target_exit_data, SourceLocation(),
SourceLocation(), NumClauses,
-   /*NumChildren=*/0) {}
+   /*NumChildren=*/1) {}
 
 public:
   /// \brief Creates directive with a list of \a Clauses.
@@ -2426,11 +2426,11 @@ public:
   /// \param StartLoc Starting location of the directive kind.
   /// \param EndLoc Ending Location of the directive.
   /// \param Clauses List of clauses.
+  /// \param AssociatedStmt Statement, associated with the directive.
   ///
-  static OMPTargetExitDataDirective *Create(const ASTContext &C,
-SourceLocation StartLoc,
-SourceLocation EndLoc,
-ArrayRef Clauses);
+  static OMPTargetExitDataDirective *
+  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+ ArrayRef Clauses, Stmt *AssociatedStmt);
 
   /// \brief Creates an empty directive with the place for \a N clauses.
   ///
@@ -2984,7 +2984,7 @@ class OMPTargetUpdateDirective : public
unsigned NumClauses)
   : OMPExecutableDirective(this, OMPTargetUpdateDirectiveClass,
OMPD_target_update, StartLoc, EndLoc, 
NumClauses,
-   0) {}
+   1) {}
 
   /// \brief Build an empty directive.
   ///
@@ -2993,7 +2993,7 @@ class OMPTargetUpdateDirective : public
   explicit OMPTargetUpdateDirective(unsigned NumClauses)
   : OMPE

[PATCH] D39836: [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 123817.
sammccall added a comment.
This revision is now accepted and ready to land.

Add an option to allow impossible completions.
While here, remove 'helpful' constructors that take some subset of the params.


https://reviews.llvm.org/D39836

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/JSONExpr.cpp
  clangd/JSONExpr.h
  clangd/tool/ClangdMain.cpp
  test/clangd/completion-priorities.test
  test/clangd/completion-qualifiers.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/JSONExprTests.cpp

Index: unittests/clangd/JSONExprTests.cpp
===
--- unittests/clangd/JSONExprTests.cpp
+++ unittests/clangd/JSONExprTests.cpp
@@ -15,6 +15,9 @@
 namespace clang {
 namespace clangd {
 namespace json {
+void PrintTo(const Expr &E, std::ostream *OS) {
+  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
+}
 namespace {
 
 std::string s(const Expr &E) { return llvm::formatv("{0}", E).str(); }
@@ -108,6 +111,77 @@
  }));
 }
 
+TEST(JSONTest, Parse) {
+  auto Compare = [](llvm::StringRef S, Expr Expected) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  EXPECT_EQ(*E, Expected);
+  EXPECT_EQ(sp(*E), sp(Expected));
+} else {
+  handleAllErrors(E.takeError(), [S](const llvm::ErrorInfoBase &E) {
+FAIL() << "Failed to parse JSON >>> " << S << " <<<: " << E.message();
+  });
+}
+  };
+
+  Compare(R"(true)", true);
+  Compare(R"(false)", false);
+  Compare(R"(null)", nullptr);
+
+  Compare(R"(42)", 42);
+  Compare(R"(2.5)", 2.5);
+  Compare(R"(2e50)", 2e50);
+  Compare(R"(1.2e3456789)", 1.0 / 0.0);
+
+  Compare(R"("foo")", "foo");
+  Compare(R"("\"\\\b\f\n\r\t")", "\"\\\b\f\n\r\t");
+  Compare(R"("\u")", llvm::StringRef("\0", 1));
+  Compare("\"\x7f\"", "\x7f");
+  Compare(R"("\ud801\udc37")", "\U00010437"); // UTF16 surrogate pair escape.
+  Compare("\"\xE2\x82\xAC\xF0\x9D\x84\x9E\"", "\u20ac\U0001d11e"); // UTF8
+  Compare(R"("\ud801")", "\ufffd"); // Invalid codepoint.
+
+  Compare(R"({"":0,"":0})", obj{{"", 0}});
+  Compare(R"({"obj":{},"arr":[]})", obj{{"obj", obj{}}, {"arr", {}}});
+  Compare(R"({"\n":{"\u":}})",
+  obj{{"\n", obj{
+ {llvm::StringRef("\0", 1), },
+ }}});
+  Compare("\r[\n\t] ", {});
+}
+
+TEST(JSONTest, ParseErrors) {
+  auto ExpectErr = [](llvm::StringRef Msg, llvm::StringRef S) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  FAIL() << "Parsed JSON >>> " << S << " <<< but wanted error: " << Msg;
+} else {
+  handleAllErrors(E.takeError(), [S, Msg](const llvm::ErrorInfoBase &E) {
+EXPECT_THAT(E.message(), testing::HasSubstr(Msg)) << S;
+  });
+}
+  };
+  ExpectErr("Unexpected EOF", "");
+  ExpectErr("Unexpected EOF", "[");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Invalid bareword", "fuzzy");
+  ExpectErr("Expected , or ]", "[2?]");
+  ExpectErr("Expected object key", "{a:2}");
+  ExpectErr("Expected : after object key", R"({"a",2})");
+  ExpectErr("Expected , or } after object property", R"({"a":2 "b":3})");
+  ExpectErr("Expected JSON value", R"([&%!])");
+  ExpectErr("Invalid number", "1e1.0");
+  ExpectErr("Unterminated string", R"("abc\"def)");
+  ExpectErr("Control character in string", "\"abc\ndef\"");
+  ExpectErr("Invalid escape sequence", R"("\030")");
+  ExpectErr("Invalid \\u escape sequence", R"("\usuck")");
+  ExpectErr("[3:3, byte=19]", R"({
+  "valid": 1,
+  invalid: 2
+})");
+}
+
 } // namespace
 } // namespace json
 } // namespace clangd
Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -788,6 +788,8 @@
   int method();
 
   int field;
+private:
+  int private_field;
 };
 
 int test() {
@@ -828,7 +830,10 @@
   // Class members. The only items that must be present in after-dor
   // completion.
   EXPECT_TRUE(ContainsItem(Results, MethodItemText));
+  EXPECT_TRUE(ContainsItem(Results, MethodItemText));
   EXPECT_TRUE(ContainsItem(Results, "field"));
+  EXPECT_EQ(Opts.IncludeIneligibleResults,
+ContainsItem(Results, "private_field"));
   // Global items.
   EXPECT_FALSE(ContainsItem(Results, "global_var"));
   EXPECT_FALSE(ContainsItem(Results, GlobalFuncItemText));
@@ -889,18 +894,26 @@
 }
   };
 
-  for (bool IncludeMacros : {true, false})
-for (bool IncludeGlobals : {true, false})
-  for (bool IncludeBriefComments : {true, false})
-for (bool EnableSnippets : {true, false})
+  clangd::CodeCompleteO

[PATCH] D39673: Toolchain: Normalize dwarf, sjlj and seh eh

2017-11-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D39673#931487, @martell wrote:

> Just as a note there is still a lot to be desired here. I do not particularly 
> like the `UseSEHExceptions` function default and the actual macro definition 
> guards should be based on the current `ExceptionModel` because we set that in 
> `lib/CodeGen/BackendUtil.cpp`. This way we do not need to have some silly 
> default of x64 && windows for UseSEHExceptions and can rely on the llvm 
> backend defaults but override within the driver we want like the apple 
> targets do for sjlj. This does for now keep the current functionality while 
> giving us a flag to override which is the goal of this patch.


We have to know the EH model before pre-processing, and that shouldn't rely on 
LLVM TargetOptions. We can probably reuse the `llvm::ExceptionHandling` enum 
instead of these various overlapping booleans, if that's the direction you want 
to go. However, I don't see how we can get away from the clang toolchain 
knowing the default EH model for each target.


Repository:
  rL LLVM

https://reviews.llvm.org/D39673



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


[clang-tools-extra] r318782 - [clangd] Include the right header for std::isxdigit

2017-11-21 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Nov 21 09:18:30 2017
New Revision: 318782

URL: http://llvm.org/viewvc/llvm-project?rev=318782&view=rev
Log:
[clangd] Include the right header for std::isxdigit

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

Modified: clang-tools-extra/trunk/clangd/JSONExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONExpr.cpp?rev=318782&r1=318781&r2=318782&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONExpr.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONExpr.cpp Tue Nov 21 09:18:30 2017
@@ -1,6 +1,16 @@
+//=== JSONExpr.cpp - JSON expressions, parsing and serialization - C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-===//
+
 #include "JSONExpr.h"
 
 #include "llvm/Support/Format.h"
+#include 
 
 using namespace llvm;
 namespace clang {


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


[PATCH] D39836: [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 123819.
sammccall added a comment.

(trying to resync the diff to head)


https://reviews.llvm.org/D39836

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/tool/ClangdMain.cpp
  test/clangd/completion-priorities.test
  test/clangd/completion-qualifiers.test
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -788,6 +788,8 @@
   int method();
 
   int field;
+private:
+  int private_field;
 };
 
 int test() {
@@ -828,7 +830,10 @@
   // Class members. The only items that must be present in after-dor
   // completion.
   EXPECT_TRUE(ContainsItem(Results, MethodItemText));
+  EXPECT_TRUE(ContainsItem(Results, MethodItemText));
   EXPECT_TRUE(ContainsItem(Results, "field"));
+  EXPECT_EQ(Opts.IncludeIneligibleResults,
+ContainsItem(Results, "private_field"));
   // Global items.
   EXPECT_FALSE(ContainsItem(Results, "global_var"));
   EXPECT_FALSE(ContainsItem(Results, GlobalFuncItemText));
@@ -889,18 +894,26 @@
 }
   };
 
-  for (bool IncludeMacros : {true, false})
-for (bool IncludeGlobals : {true, false})
-  for (bool IncludeBriefComments : {true, false})
-for (bool EnableSnippets : {true, false})
+  clangd::CodeCompleteOptions CCOpts;
+  for (bool IncludeMacros : {true, false}){
+CCOpts.IncludeMacros = IncludeMacros;
+for (bool IncludeGlobals : {true, false}){
+  CCOpts.IncludeGlobals = IncludeGlobals;
+  for (bool IncludeBriefComments : {true, false}){
+CCOpts.IncludeBriefComments = IncludeBriefComments;
+for (bool EnableSnippets : {true, false}){
+  CCOpts.EnableSnippets = EnableSnippets;
   for (bool IncludeCodePatterns : {true, false}) {
-TestWithOpts(clangd::CodeCompleteOptions(
-/*EnableSnippets=*/EnableSnippets,
-/*IncludeCodePatterns=*/IncludeCodePatterns,
-/*IncludeMacros=*/IncludeMacros,
-/*IncludeGlobals=*/IncludeGlobals,
-/*IncludeBriefComments=*/IncludeBriefComments));
+CCOpts.IncludeCodePatterns = IncludeCodePatterns;
+for (bool IncludeIneligibleResults : {true, false}) {
+  CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
+  TestWithOpts(CCOpts);
+}
   }
+}
+  }
+}
+  }
 }
 
 class ClangdThreadingTest : public ClangdVFSTest {};
Index: test/clangd/completion-qualifiers.test
===
--- test/clangd/completion-qualifiers.test
+++ test/clangd/completion-qualifiers.test
@@ -13,7 +13,7 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-# Eligible const functions are at the top of the list.
+# Eligible functions are at the top of the list.
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "int",
 # CHECK-NEXT:"filterText": "bar",
@@ -32,18 +32,9 @@
 # CHECK-NEXT:"label": "Foo::foo() const",
 # CHECK-NEXT:"sortText": "37foo"
 # CHECK-NEXT:  },
-# Ineligible non-const function is at the bottom of the list.
-# CHECK-NEXT:  {
-#  CHECK:"detail": "int",
-#  CHECK:"filterText": "foo",
-# CHECK-NEXT:"insertText": "foo",
-# CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 2,
-# CHECK-NEXT:"label": "foo() const",
-# CHECK-NEXT:"sortText": "200035foo"
-# CHECK-NEXT:  }
-# CHECK-NEXT:]
-# CHECK-NEXT:  }
+# Ineligible private functions are not present.
+#  CHECK-NOT:"label": "foo() const",
+#  CHECK:]
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: test/clangd/completion-priorities.test
===
--- test/clangd/completion-priorities.test
+++ test/clangd/completion-priorities.test
@@ -61,28 +61,10 @@
 # CHECK-NEXT:"kind": 2,
 # CHECK-NEXT:"label": "pub()",
 # CHECK-NEXT:"sortText": "34pub"
-# CHECK-NEXT:  },
-# priv() and prot() are at the end of the list
-# CHECK-NEXT:  {
-#  CHECK:"detail": "void",
-#  CHECK:"filterText": "priv",
-# CHECK-NEXT:"insertText": "priv",
-# CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 2,
-# CHECK-NEXT:"label": "priv()",
-# CHECK-NEXT:"sortText": "200034priv"
-# CHECK-NEXT:  },
-# CHECK-NEXT:  {
-# CHECK-NEXT:"detail": "void",
-# CHECK-NEXT:"filterText": "prot",
-# CHECK-NEXT:"insertText": "prot",
-# CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 2,
-# CHECK-NEXT:   

[PATCH] D39836: [clangd] Drop impossible completions (unavailable or inaccessible)

2017-11-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall requested review of this revision.
sammccall added a comment.

PTAL - this is now optional. The results will be hidden by default, but can be 
turned on with a flag.


https://reviews.llvm.org/D39836



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


r318785 - Add -finstrument-function-entry-bare flag

2017-11-21 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Tue Nov 21 09:30:34 2017
New Revision: 318785

URL: http://llvm.org/viewvc/llvm-project?rev=318785&view=rev
Log:
Add -finstrument-function-entry-bare flag

This is an instrumentation flag that's similar to
-finstrument-functions, but it only inserts calls on function entry, the
calls are inserted post-inlining, and they don't take any arugments.

This is intended for users who want to instrument function entry with
minimal overhead.

(-pg would be another alternative, but forces frame pointer emission and
affects link flags, so is probably best left alone to be used for
generating gcov data.)

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/instrument-functions.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=318785&r1=318784&r2=318785&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Nov 21 09:30:34 2017
@@ -1030,6 +1030,8 @@ def finstrument_functions : Flag<["-"],
   HelpText<"Generate calls to instrument function entry and exit">;
 def finstrument_functions_after_inlining : Flag<["-"], 
"finstrument-functions-after-inlining">, Group, Flags<[CC1Option]>,
   HelpText<"Like -finstrument-functions, but insert the calls after inlining">;
+def finstrument_function_entry_bare : Flag<["-"], 
"finstrument-function-entry-bare">, Group, Flags<[CC1Option]>,
+  HelpText<"Instrument function entry only, after inlining, without arguments 
to the instrumentation call">;
 
 def fxray_instrument : Flag<["-"], "fxray-instrument">, Group,
   Flags<[CC1Option]>,

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=318785&r1=318784&r2=318785&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Nov 21 09:30:34 2017
@@ -78,6 +78,8 @@ CODEGENOPT(InstrumentFunctions , 1, 0) /
///< enabled.
 CODEGENOPT(InstrumentFunctionsAfterInlining , 1, 0) ///< Set when
   ///< -finstrument-functions-after-inlining is 
enabled.
+CODEGENOPT(InstrumentFunctionEntryBare , 1, 0) ///< Set when
+   ///< -finstrument-function-entry-bare is 
enabled.
 
 CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
///< enabled.

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=318785&r1=318784&r2=318785&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Nov 21 09:30:34 2017
@@ -355,10 +355,11 @@ void CodeGenFunction::FinishFunction(Sou
   llvm::DebugLoc Loc = EmitReturnBlock();
 
   if (ShouldInstrumentFunction()) {
-CurFn->addFnAttr(!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining
- ? "instrument-function-exit"
- : "instrument-function-exit-inlined",
- "__cyg_profile_func_exit");
+if (CGM.getCodeGenOpts().InstrumentFunctions)
+  CurFn->addFnAttr("instrument-function-exit", "__cyg_profile_func_exit");
+if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
+  CurFn->addFnAttr("instrument-function-exit-inlined",
+   "__cyg_profile_func_exit");
   }
 
   // Emit debug descriptor for function end.
@@ -443,7 +444,8 @@ void CodeGenFunction::FinishFunction(Sou
 /// instrumented with __cyg_profile_func_* calls
 bool CodeGenFunction::ShouldInstrumentFunction() {
   if (!CGM.getCodeGenOpts().InstrumentFunctions &&
-  !CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
+  !CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining &&
+  !CGM.getCodeGenOpts().InstrumentFunctionEntryBare)
 return false;
   if (!CurFuncDecl || CurFuncDecl->hasAttr())
 return false;
@@ -982,10 +984,14 @@ void CodeGenFunction::StartFunction(Glob
   }
 
   if (ShouldInstrumentFunction()) {
-Fn->addFnAttr(!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining
-  ? "instrument-function-entry"
-  : "instrument-function-entry-inlined",
-  "__cyg_profile_func_enter");
+if (CGM.getCodeGenOpts().InstrumentFunc

[PATCH] D40276: Add -finstrument-function-entry-bare flag

2017-11-21 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318785: Add -finstrument-function-entry-bare flag (authored 
by hans).

Changed prior to commit:
  https://reviews.llvm.org/D40276?vs=123691&id=123821#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40276

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/instrument-functions.c

Index: cfe/trunk/test/CodeGen/instrument-functions.c
===
--- cfe/trunk/test/CodeGen/instrument-functions.c
+++ cfe/trunk/test/CodeGen/instrument-functions.c
@@ -1,21 +1,34 @@
 // RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-function-entry-bare -disable-llvm-passes | FileCheck -check-prefix=BARE %s
 
 int test1(int x) {
 // CHECK: @test1(i32 {{.*}}%x) #[[ATTR1:[0-9]+]]
 // CHECK: ret
+
+// BARE: @test1(i32 {{.*}}%x) #[[ATTR1:[0-9]+]]
+// BARE: ret
   return x;
 }
 
 int test2(int) __attribute__((no_instrument_function));
 int test2(int x) {
 // CHECK: @test2(i32 {{.*}}%x) #[[ATTR2:[0-9]+]]
 // CHECK: ret
+
+// BARE: @test2(i32 {{.*}}%x) #[[ATTR2:[0-9]+]]
+// BARE: ret
   return x;
 }
 
 // CHECK: attributes #[[ATTR1]] =
 // CHECK-SAME: "instrument-function-entry"="__cyg_profile_func_enter"
 // CHECK-SAME: "instrument-function-exit"="__cyg_profile_func_exit"
 
+// BARE: attributes #[[ATTR1]] =
+// BARE-SAME: "instrument-function-entry-inlined"="__cyg_profile_func_enter_bare"
+
 // CHECK: attributes #[[ATTR2]] =
 // CHECK-NOT: "instrument-function-entry"
+
+// BARE: attributes #[[ATTR2]] =
+// BARE-NOT: "instrument-function-entry"
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -782,6 +782,8 @@
   Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
   Opts.InstrumentFunctionsAfterInlining =
   Args.hasArg(OPT_finstrument_functions_after_inlining);
+  Opts.InstrumentFunctionEntryBare =
+  Args.hasArg(OPT_finstrument_function_entry_bare);
   Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
@@ -355,10 +355,11 @@
   llvm::DebugLoc Loc = EmitReturnBlock();
 
   if (ShouldInstrumentFunction()) {
-CurFn->addFnAttr(!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining
- ? "instrument-function-exit"
- : "instrument-function-exit-inlined",
- "__cyg_profile_func_exit");
+if (CGM.getCodeGenOpts().InstrumentFunctions)
+  CurFn->addFnAttr("instrument-function-exit", "__cyg_profile_func_exit");
+if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
+  CurFn->addFnAttr("instrument-function-exit-inlined",
+   "__cyg_profile_func_exit");
   }
 
   // Emit debug descriptor for function end.
@@ -443,7 +444,8 @@
 /// instrumented with __cyg_profile_func_* calls
 bool CodeGenFunction::ShouldInstrumentFunction() {
   if (!CGM.getCodeGenOpts().InstrumentFunctions &&
-  !CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
+  !CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining &&
+  !CGM.getCodeGenOpts().InstrumentFunctionEntryBare)
 return false;
   if (!CurFuncDecl || CurFuncDecl->hasAttr())
 return false;
@@ -982,10 +984,14 @@
   }
 
   if (ShouldInstrumentFunction()) {
-Fn->addFnAttr(!CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining
-  ? "instrument-function-entry"
-  : "instrument-function-entry-inlined",
-  "__cyg_profile_func_enter");
+if (CGM.getCodeGenOpts().InstrumentFunctions)
+  CurFn->addFnAttr("instrument-function-entry", "__cyg_profile_func_enter");
+if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
+  CurFn->addFnAttr("instrument-function-entry-inlined",
+   "__cyg_profile_func_enter");
+if (CGM.getCodeGenOpts().InstrumentFunctionEntryBare)
+  CurFn->addFnAttr("instrument-function-entry-inlined",
+   "__cyg_profile_func_enter_bare");
   }
 
   // Since emitting the mcount call here impacts optimizations such as function
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
==

[PATCH] D40275: [CUDA] Report "unsupported VLA" errors only on device side.

2017-11-21 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:2188
+   !Context.getTargetInfo().isVLASupported() &&
+   shouldDiagnoseTargetSupportFromOpenMP()) {
+  // Some targets don't support VLAs.

rjmccall wrote:
> Please write this check so that it trips in an "ordinary" build on a target 
> that just happens to not support VLAs, something like:
> 
>   else if (!Context.getTargetInfo().isVLASupported() && 
> shouldDiagnoseTargetSupportFromOpenMP())
> 
> If you want to include the explicit OpenMP check there, it would need to be:
> 
>   else if (!Context.getTargetInfo().isVLASupported() && 
> (!getLangOpts().OpenMP || shouldDiagnoseTargetSupportFromOpenMP()))
> 
> but I think the first looks better.
> 
> The CUDA and OpenMP paths here seem to be trying to achieve analogous things; 
> it's unfortunate that we can't find a way to unify their approaches, even if 
> we'd eventually want to use different diagnostic text.  I imagine that the 
> target-environment language restrictions are basically the same, since they 
> arise for the same fundamental reasons, so all the places using 
> CUDADiagIfDeviceCode are likely to have a check for 
> shouldDiagnoseTargetSupportFromOpenMP() and vice-versa.
The problem is that in CUDA we can't just do 
```
if (!Context.getTargetInfo().isVLASupported() && 
shouldDiagnoseTargetSupportFromOpenMP())
   Diag(Loc, diag::err_vla_unsupported);
```

In some situations diag messages will only be emitted if we attempt to generate 
unsupported code on device side.
Consider 
```
__host__ __device__ void foo(int n) {
  int vla[n];
}
```

When Sema sees this code during compilation, it can not tell whether there is 
an error. Calling foo from the host code is perfectly valid. Calling it from 
device code is not. `CUDADiagIfDeviceCode` creates 'postponed' diagnostics 
which only gets emitted if we ever need to generate code for the function on 
device.

So, while CUDA and OpenMP do similar things, they are not quite the same.  If 
your goal to generalize CUDA and OpenMP handling, then it would have to be 
folded into diagnostic-emitting itself and we'll need an analog of 
CUDADiagIfDeviceCode which can handle both OpenMP and CUDA. 
E.g. something like this:
```
??? DiagIfDeviceCode(???) {
   if (OpenCL || (OpenMP && shouldDiagnoseTargetSupportFromOpenMP()))
   Diag(...);
   else if (CUDA)
   CUDADiagIfDeviceCode()
} 

...

if (!Context.getTargetInfo().isVLASupported()) 
   DiagIfDeviceCode();

```

Would that work for you?


https://reviews.llvm.org/D40275



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


[PATCH] D40275: [CUDA] Report "unsupported VLA" errors only on device side.

2017-11-21 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

> When Sema sees this code during compilation, it can not tell whether there is 
> an error. Calling foo from the host code is perfectly valid. Calling it from 
> device code is not. CUDADiagIfDeviceCode creates 'postponed' diagnostics 
> which only gets emitted if we ever need to generate code for the function on 
> device.

Interesting. I suspect that we'll end up dealing with this problem for OpenMP 
as well (in the future - for OpenMP v5). In this next version (for which the 
draft is available here: 
http://www.openmp.org/wp-content/uploads/openmp-TR6.pdf), we'll have "implicit 
declare target" functions (whereby we generate target code based on the 
locally-defined subset of the transitive closure of the call graph starting 
from target regions).


https://reviews.llvm.org/D40275



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


[PATCH] D40275: [CUDA] Report "unsupported VLA" errors only on device side.

2017-11-21 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 123823.
tra added a comment.

Updated to partially address rjmccall@ comments.


https://reviews.llvm.org/D40275

Files:
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCUDA/vla.cu


Index: clang/test/SemaCUDA/vla.cu
===
--- clang/test/SemaCUDA/vla.cu
+++ clang/test/SemaCUDA/vla.cu
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -DHOST %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -verify -DHOST %s
 
 #include "Inputs/cuda.h"
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2175,19 +2175,16 @@
 T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
   }
 
-  // OpenCL v1.2 s6.9.d: variable length arrays are not supported.
-  if (getLangOpts().OpenCL && T->isVariableArrayType()) {
-Diag(Loc, diag::err_opencl_vla);
-return QualType();
-  }
-  // CUDA device code doesn't support VLAs.
-  if (getLangOpts().CUDA && T->isVariableArrayType())
-CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget();
-  // Some targets don't support VLAs.
-  if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported() &&
-  shouldDiagnoseTargetSupportFromOpenMP()) {
-Diag(Loc, diag::err_vla_unsupported);
-return QualType();
+  if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported()) {
+if (getLangOpts().CUDA) {
+  // CUDA device code doesn't support VLAs.
+  CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget();
+} else if (!getLangOpts().OpenMP ||
+   shouldDiagnoseTargetSupportFromOpenMP()) {
+  // Some targets don't support VLAs.
+  Diag(Loc, diag::err_vla_unsupported);
+  return QualType();
+}
   }
 
   // If this is not C99, extwarn about VLA's and C99 array size modifiers.


Index: clang/test/SemaCUDA/vla.cu
===
--- clang/test/SemaCUDA/vla.cu
+++ clang/test/SemaCUDA/vla.cu
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -DHOST %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -verify -DHOST %s
 
 #include "Inputs/cuda.h"
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2175,19 +2175,16 @@
 T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
   }
 
-  // OpenCL v1.2 s6.9.d: variable length arrays are not supported.
-  if (getLangOpts().OpenCL && T->isVariableArrayType()) {
-Diag(Loc, diag::err_opencl_vla);
-return QualType();
-  }
-  // CUDA device code doesn't support VLAs.
-  if (getLangOpts().CUDA && T->isVariableArrayType())
-CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget();
-  // Some targets don't support VLAs.
-  if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported() &&
-  shouldDiagnoseTargetSupportFromOpenMP()) {
-Diag(Loc, diag::err_vla_unsupported);
-return QualType();
+  if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported()) {
+if (getLangOpts().CUDA) {
+  // CUDA device code doesn't support VLAs.
+  CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget();
+} else if (!getLangOpts().OpenMP ||
+   shouldDiagnoseTargetSupportFromOpenMP()) {
+  // Some targets don't support VLAs.
+  Diag(Loc, diag::err_vla_unsupported);
+  return QualType();
+}
   }
 
   // If this is not C99, extwarn about VLA's and C99 array size modifiers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40275: [CUDA] Report "unsupported VLA" errors only on device side.

2017-11-21 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:2188
+   !Context.getTargetInfo().isVLASupported() &&
+   shouldDiagnoseTargetSupportFromOpenMP()) {
+  // Some targets don't support VLAs.

tra wrote:
> rjmccall wrote:
> > Please write this check so that it trips in an "ordinary" build on a target 
> > that just happens to not support VLAs, something like:
> > 
> >   else if (!Context.getTargetInfo().isVLASupported() && 
> > shouldDiagnoseTargetSupportFromOpenMP())
> > 
> > If you want to include the explicit OpenMP check there, it would need to be:
> > 
> >   else if (!Context.getTargetInfo().isVLASupported() && 
> > (!getLangOpts().OpenMP || shouldDiagnoseTargetSupportFromOpenMP()))
> > 
> > but I think the first looks better.
> > 
> > The CUDA and OpenMP paths here seem to be trying to achieve analogous 
> > things; it's unfortunate that we can't find a way to unify their 
> > approaches, even if we'd eventually want to use different diagnostic text.  
> > I imagine that the target-environment language restrictions are basically 
> > the same, since they arise for the same fundamental reasons, so all the 
> > places using CUDADiagIfDeviceCode are likely to have a check for 
> > shouldDiagnoseTargetSupportFromOpenMP() and vice-versa.
> The problem is that in CUDA we can't just do 
> ```
> if (!Context.getTargetInfo().isVLASupported() && 
> shouldDiagnoseTargetSupportFromOpenMP())
>Diag(Loc, diag::err_vla_unsupported);
> ```
> 
> In some situations diag messages will only be emitted if we attempt to 
> generate unsupported code on device side.
> Consider 
> ```
> __host__ __device__ void foo(int n) {
>   int vla[n];
> }
> ```
> 
> When Sema sees this code during compilation, it can not tell whether there is 
> an error. Calling foo from the host code is perfectly valid. Calling it from 
> device code is not. `CUDADiagIfDeviceCode` creates 'postponed' diagnostics 
> which only gets emitted if we ever need to generate code for the function on 
> device.
> 
> So, while CUDA and OpenMP do similar things, they are not quite the same.  If 
> your goal to generalize CUDA and OpenMP handling, then it would have to be 
> folded into diagnostic-emitting itself and we'll need an analog of 
> CUDADiagIfDeviceCode which can handle both OpenMP and CUDA. 
> E.g. something like this:
> ```
> ??? DiagIfDeviceCode(???) {
>if (OpenCL || (OpenMP && shouldDiagnoseTargetSupportFromOpenMP()))
>Diag(...);
>else if (CUDA)
>CUDADiagIfDeviceCode()
> } 
> 
> ...
> 
> if (!Context.getTargetInfo().isVLASupported()) 
>DiagIfDeviceCode();
> 
> ```
> 
> Would that work for you?
There's another issue with this approach -- diagnostics itself. Each dialect 
has its own. Specifically CUDA diags have details that are relevant only to 
CUDA. I suspect OpenMP has something specific as well. If we insist emitting 
only one kind of error for particular case across all dialects, we'll have to 
stick to bare bones "feature X is not supported" which will not have sufficient 
details to explain why the error was triggered in CUDA.

IMO dialect-specific handling of cuda errors in this case is the lesser evil. 

I'll update the patch to handle non-cuda cases the way  you suggested.


https://reviews.llvm.org/D40275



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


[PATCH] D40275: [CUDA] Report "unsupported VLA" errors only on device side.

2017-11-21 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D40275#931947, @hfinkel wrote:

> > When Sema sees this code during compilation, it can not tell whether there 
> > is an error. Calling foo from the host code is perfectly valid. Calling it 
> > from device code is not. CUDADiagIfDeviceCode creates 'postponed' 
> > diagnostics which only gets emitted if we ever need to generate code for 
> > the function on device.
>
> Interesting. I suspect that we'll end up dealing with this problem for OpenMP 
> as well (in the future - for OpenMP v5). In this next version (for which the 
> draft is available here: 
> http://www.openmp.org/wp-content/uploads/openmp-TR6.pdf), we'll have 
> "implicit declare target" functions (whereby we generate target code based on 
> the locally-defined subset of the transitive closure of the call graph 
> starting from target regions).


We've been contemplating treating all functions as `__host__ __device__` by 
default. After all, most of the source code is target-agnostic. Currently a lot 
of templated code must be `__host__ __device__` in order to be usable and it's 
a major obstacle to making standard library and other template libraries 
(somewhat) usable on device. Alas, making `__host__ __device__` the default 
would be a major departure from CUDA semantics.


https://reviews.llvm.org/D40275



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


  1   2   >