[PATCH] D50144: Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-08 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1276
+InitVar->setSection(".CRT$XCLa");
+CGM.addUsedGlobal(InitVar);
+  }

DHowett-MSFT wrote:
> rjmccall wrote:
> > Is the priority system not good enough?
> My reading of the LLVM language reference leads me to believe it’s only 
> ordered per-module. If that’s the case, the benefit of emitting into `XC*` is 
> that it provides guaranteed order over all linker input.
> 
> `llvm.global_ctors` excerpt:
> 
> > The functions referenced by this array will be called in ascending order of 
> > priority (i.e. lowest first) when the module is loaded.
> 
> Now if the priority system _is_ guaranteed over all linker input, will that 
> guarantee hold for mixed Clang and CL objects?
Init priorities on ELF are preserved in the section name like 
`.init_array.200`, and the sections get sorted by that in the image — it's 
really a very similar trick to how it works with `.CRT$XC`.  Of the major 
formats, I think it's just Mach-O that doesn't have any built-in prioritization 
mechanism across object files.  But I don't know if LLVM actually tries to 
translate init priorities over into `.CRT$XC` suffices when targeting PE/COFF, 
and arguably that's good: init priorities as presented in LLVM right now are 
pretty specific to the ELF mechanism.  Long-term, maybe `llvm.global_ctors` 
should be generalized so that on ELF targets it takes an integer priority, on 
PE/COFF targets it takes a string, and on Mach-O it doesn't take anything at 
all; but I won't hold up this patch for that.

On the other hand, I tend to agree that maybe the best solution is for the 
backend to just take care of this and automatically create a global initializer 
to install non-function (or maybe non-function & `unnamed_addr`) `dllimport`ed 
symbols in global data.


Repository:
  rC Clang

https://reviews.llvm.org/D50144



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


[PATCH] D50144: Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-08 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1276
+InitVar->setSection(".CRT$XCLa");
+CGM.addUsedGlobal(InitVar);
+  }

rjmccall wrote:
> DHowett-MSFT wrote:
> > rjmccall wrote:
> > > Is the priority system not good enough?
> > My reading of the LLVM language reference leads me to believe it’s only 
> > ordered per-module. If that’s the case, the benefit of emitting into `XC*` 
> > is that it provides guaranteed order over all linker input.
> > 
> > `llvm.global_ctors` excerpt:
> > 
> > > The functions referenced by this array will be called in ascending order 
> > > of priority (i.e. lowest first) when the module is loaded.
> > 
> > Now if the priority system _is_ guaranteed over all linker input, will that 
> > guarantee hold for mixed Clang and CL objects?
> Init priorities on ELF are preserved in the section name like 
> `.init_array.200`, and the sections get sorted by that in the image — it's 
> really a very similar trick to how it works with `.CRT$XC`.  Of the major 
> formats, I think it's just Mach-O that doesn't have any built-in 
> prioritization mechanism across object files.  But I don't know if LLVM 
> actually tries to translate init priorities over into `.CRT$XC` suffices when 
> targeting PE/COFF, and arguably that's good: init priorities as presented in 
> LLVM right now are pretty specific to the ELF mechanism.  Long-term, maybe 
> `llvm.global_ctors` should be generalized so that on ELF targets it takes an 
> integer priority, on PE/COFF targets it takes a string, and on Mach-O it 
> doesn't take anything at all; but I won't hold up this patch for that.
> 
> On the other hand, I tend to agree that maybe the best solution is for the 
> backend to just take care of this and automatically create a global 
> initializer to install non-function (or maybe non-function & `unnamed_addr`) 
> `dllimport`ed symbols in global data.
> But I don't know if LLVM actually tries to translate init priorities over 
> into .CRT$XC suffices when targeting PE/COFF, and arguably that's good: init 
> priorities as presented in LLVM right now are pretty specific to the ELF 
> mechanism. Long-term, maybe llvm.global_ctors should be generalized so that 
> on ELF targets it takes an integer priority, on PE/COFF targets it takes a 
> string, and on Mach-O it doesn't take anything at all; but I won't hold up 
> this patch for that.

FWIW, for the MinGW targets, the same ELF-like priority system is used (or I 
think it's actually an older mechanism previously used on ELF); constructors 
are emitted in `.ctors`, and those with a priority go into sections named 
`.ctors.01234` where the number is 65535 minus the init priority specified. By 
making these zero padded, they get ordered right by the normal alphabetical 
sorting. MinGW CRT startup routines then have extra code to run constructors in 
the right order from the `.ctors` section, in addition to the normal `.CRT$XC` 
ones.


Repository:
  rC Clang

https://reviews.llvm.org/D50144



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


[libunwind] r339222 - Merging r339217:

2018-08-08 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Aug  8 00:50:31 2018
New Revision: 339222

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

r339217 | cdavis | 2018-08-08 06:21:24 +0200 (Wed, 08 Aug 2018) | 11 lines

[libunwind] Fix pointer-to-integer cast warnings on LLP64.

Summary:
`long` is too short on LLP64. We have to use `intptr_t` to
avoid truncating pointers.

Reviewers: mstorsjo, rnk, compnerd, smeenai

Subscribers: christof, cfe-commits, llvm-commits

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


Modified:
libunwind/branches/release_70/   (props changed)
libunwind/branches/release_70/src/UnwindLevel1-gcc-ext.c
libunwind/branches/release_70/src/UnwindLevel1.c

Propchange: libunwind/branches/release_70/
--
svn:mergeinfo = /libunwind/trunk:339217

Modified: libunwind/branches/release_70/src/UnwindLevel1-gcc-ext.c
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_70/src/UnwindLevel1-gcc-ext.c?rev=339222&r1=339221&r2=339222&view=diff
==
--- libunwind/branches/release_70/src/UnwindLevel1-gcc-ext.c (original)
+++ libunwind/branches/release_70/src/UnwindLevel1-gcc-ext.c Wed Aug  8 
00:50:31 2018
@@ -33,9 +33,9 @@ _Unwind_Resume_or_Rethrow(_Unwind_Except
(void *)exception_object,
(long)exception_object->unwinder_cache.reserved1);
 #else
-  _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld",
+  _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" 
PRIdPTR,
(void *)exception_object,
-   (long)exception_object->private_1);
+   (intptr_t)exception_object->private_1);
 #endif
 
 #if defined(_LIBUNWIND_ARM_EHABI)
@@ -92,9 +92,9 @@ _LIBUNWIND_EXPORT void *_Unwind_FindEncl
   unw_proc_info_t info;
   unw_getcontext(&uc);
   unw_init_local(&cursor, &uc);
-  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
+  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc);
   if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS)
-return (void *)(long) info.start_ip;
+return (void *)(intptr_t) info.start_ip;
   else
 return NULL;
 }
@@ -190,14 +190,14 @@ _LIBUNWIND_EXPORT const void *_Unwind_Fi
   unw_proc_info_t info;
   unw_getcontext(&uc);
   unw_init_local(&cursor, &uc);
-  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
+  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc);
   unw_get_proc_info(&cursor, &info);
   bases->tbase = (uintptr_t)info.extra;
   bases->dbase = 0; // dbase not used on Mac OS X
   bases->func = (uintptr_t)info.start_ip;
   _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc,
-  (void *)(long) info.unwind_info);
-  return (void *)(long) info.unwind_info;
+  (void *)(intptr_t) info.unwind_info);
+  return (void *)(intptr_t) info.unwind_info;
 }
 
 /// Returns the CFA (call frame area, or stack pointer at start of function)

Modified: libunwind/branches/release_70/src/UnwindLevel1.c
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_70/src/UnwindLevel1.c?rev=339222&r1=339221&r2=339222&view=diff
==
--- libunwind/branches/release_70/src/UnwindLevel1.c (original)
+++ libunwind/branches/release_70/src/UnwindLevel1.c Wed Aug  8 00:50:31 2018
@@ -287,7 +287,7 @@ unwind_phase2_forced(unw_context_t *uc,
 // If there is a personality routine, tell it we are unwinding.
 if (frameInfo.handler != 0) {
   __personality_routine p =
-  (__personality_routine)(long)(frameInfo.handler);
+  (__personality_routine)(intptr_t)(frameInfo.handler);
   _LIBUNWIND_TRACE_UNWINDING(
   "unwind_phase2_forced(ex_ojb=%p): calling personality function %p",
   (void *)exception_object, (void *)(uintptr_t)p);


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


[PATCH] D50412: [libunwind] Fix pointer-to-integer cast warnings on LLP64.

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

In https://reviews.llvm.org/D50412#1191843, @mstorsjo wrote:

> @hans This looks 7.0-worthy to me.


Okay, r339222.


Repository:
  rL LLVM

https://reviews.llvm.org/D50412



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


Re: [libunwind] r339217 - [libunwind] Fix pointer-to-integer cast warnings on LLP64.

2018-08-08 Thread Hans Wennborg via cfe-commits
Merged to 7.0 in r339222.

On Wed, Aug 8, 2018 at 6:21 AM, Charles Davis via cfe-commits
 wrote:
> Author: cdavis
> Date: Tue Aug  7 21:21:24 2018
> New Revision: 339217
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339217&view=rev
> Log:
> [libunwind] Fix pointer-to-integer cast warnings on LLP64.
>
> Summary:
> `long` is too short on LLP64. We have to use `intptr_t` to
> avoid truncating pointers.
>
> Reviewers: mstorsjo, rnk, compnerd, smeenai
>
> Subscribers: christof, cfe-commits, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D50412
>
> Modified:
> libunwind/trunk/src/UnwindLevel1-gcc-ext.c
> libunwind/trunk/src/UnwindLevel1.c
>
> Modified: libunwind/trunk/src/UnwindLevel1-gcc-ext.c
> URL: 
> http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindLevel1-gcc-ext.c?rev=339217&r1=339216&r2=339217&view=diff
> ==
> --- libunwind/trunk/src/UnwindLevel1-gcc-ext.c (original)
> +++ libunwind/trunk/src/UnwindLevel1-gcc-ext.c Tue Aug  7 21:21:24 2018
> @@ -33,9 +33,9 @@ _Unwind_Resume_or_Rethrow(_Unwind_Except
> (void *)exception_object,
> (long)exception_object->unwinder_cache.reserved1);
>  #else
> -  _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld",
> +  _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" 
> PRIdPTR,
> (void *)exception_object,
> -   (long)exception_object->private_1);
> +   (intptr_t)exception_object->private_1);
>  #endif
>
>  #if defined(_LIBUNWIND_ARM_EHABI)
> @@ -92,9 +92,9 @@ _LIBUNWIND_EXPORT void *_Unwind_FindEncl
>unw_proc_info_t info;
>unw_getcontext(&uc);
>unw_init_local(&cursor, &uc);
> -  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
> +  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc);
>if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS)
> -return (void *)(long) info.start_ip;
> +return (void *)(intptr_t) info.start_ip;
>else
>  return NULL;
>  }
> @@ -190,14 +190,14 @@ _LIBUNWIND_EXPORT const void *_Unwind_Fi
>unw_proc_info_t info;
>unw_getcontext(&uc);
>unw_init_local(&cursor, &uc);
> -  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
> +  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc);
>unw_get_proc_info(&cursor, &info);
>bases->tbase = (uintptr_t)info.extra;
>bases->dbase = 0; // dbase not used on Mac OS X
>bases->func = (uintptr_t)info.start_ip;
>_LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc,
> -  (void *)(long) info.unwind_info);
> -  return (void *)(long) info.unwind_info;
> +  (void *)(intptr_t) info.unwind_info);
> +  return (void *)(intptr_t) info.unwind_info;
>  }
>
>  /// Returns the CFA (call frame area, or stack pointer at start of function)
>
> Modified: libunwind/trunk/src/UnwindLevel1.c
> URL: 
> http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindLevel1.c?rev=339217&r1=339216&r2=339217&view=diff
> ==
> --- libunwind/trunk/src/UnwindLevel1.c (original)
> +++ libunwind/trunk/src/UnwindLevel1.c Tue Aug  7 21:21:24 2018
> @@ -287,7 +287,7 @@ unwind_phase2_forced(unw_context_t *uc,
>  // If there is a personality routine, tell it we are unwinding.
>  if (frameInfo.handler != 0) {
>__personality_routine p =
> -  (__personality_routine)(long)(frameInfo.handler);
> +  (__personality_routine)(intptr_t)(frameInfo.handler);
>_LIBUNWIND_TRACE_UNWINDING(
>"unwind_phase2_forced(ex_ojb=%p): calling personality function %p",
>(void *)exception_object, (void *)(uintptr_t)p);
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50193: Added functionality to suggest FixIts for conversion of '->' to '.' and vice versa.

2018-08-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 159648.
kadircet marked 3 inline comments as done.
kadircet added a comment.

- Resolve some more discussions.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50193

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Diagnostics.cpp
  clangd/Protocol.h
  clangd/Quality.cpp
  clangd/Quality.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/QualityTests.cpp

Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -346,6 +346,28 @@
   EXPECT_EQ(Q.Category, SymbolQualitySignals::Constructor);
 }
 
+TEST(QualityTests, ItemWithFixItsRankedDown) {
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+
+  auto Header = TestTU::withHeaderCode(R"cpp(
+int x;
+  )cpp");
+  auto AST = Header.build();
+
+  SymbolRelevanceSignals RelevanceWithFixIt;
+  RelevanceWithFixIt.merge(CodeCompletionResult(&findDecl(AST, "x"), 0, nullptr,
+false, true, {FixItHint{}}));
+  EXPECT_TRUE(RelevanceWithFixIt.NeedsFixIts);
+
+  SymbolRelevanceSignals RelevanceWithoutFixIt;
+  RelevanceWithoutFixIt.merge(
+  CodeCompletionResult(&findDecl(AST, "x"), 0, nullptr, false, true, {}));
+  EXPECT_FALSE(RelevanceWithoutFixIt.NeedsFixIts);
+
+  EXPECT_LT(RelevanceWithFixIt.evaluate(), RelevanceWithoutFixIt.evaluate());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -79,6 +79,23 @@
   return MemIndex::build(std::move(Slab).build());
 }
 
+CodeCompleteResult completions(ClangdServer &Server, StringRef TestCode,
+   Position point,
+   std::vector IndexSymbols = {},
+   clangd::CodeCompleteOptions Opts = {}) {
+  std::unique_ptr OverrideIndex;
+  if (!IndexSymbols.empty()) {
+assert(!Opts.Index && "both Index and IndexSymbols given!");
+OverrideIndex = memIndex(std::move(IndexSymbols));
+Opts.Index = OverrideIndex.get();
+  }
+
+  auto File = testPath("foo.cpp");
+  runAddDocument(Server, File, TestCode);
+  auto CompletionList = cantFail(runCodeComplete(Server, File, point, Opts));
+  return CompletionList;
+}
+
 CodeCompleteResult completions(ClangdServer &Server, StringRef Text,
std::vector IndexSymbols = {},
clangd::CodeCompleteOptions Opts = {}) {
@@ -1338,6 +1355,85 @@
   EXPECT_THAT(Results.Context, CodeCompletionContext::CCC_DotMemberAccess);
 }
 
+TEST(CompletionTest, FixItForArrowToDot) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+  Annotations TestCode(
+  R"cpp(
+class Auxilary {
+ public:
+  void AuxFunction();
+};
+class ClassWithPtr {
+ public:
+  void MemberFunction();
+  Auxilary* operator->() const;
+  Auxilary* Aux;
+};
+void f() {
+  ClassWithPtr x;
+  x[[->]]^;
+}
+  )cpp");
+  auto Results =
+  completions(Server, TestCode.code(), TestCode.point(), {}, Opts);
+  EXPECT_EQ(Results.Completions.size(), 3u);
+
+  TextEdit ReplacementEdit;
+  ReplacementEdit.range = TestCode.range();
+  ReplacementEdit.newText = ".";
+  for (const auto &C : Results.Completions) {
+EXPECT_TRUE(C.FixIts.size() == 1u || C.Name == "AuxFunction");
+if (!C.FixIts.empty())
+  EXPECT_THAT(C.FixIts, ElementsAre(ReplacementEdit));
+  }
+}
+
+TEST(CompletionTest, FixItForDotToArrow) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+  Annotations TestCode(
+  R"cpp(
+class Auxilary {
+ public:
+  void AuxFunction();
+};
+class ClassWithPtr {
+ public:
+  void MemberFunction();
+  Auxilary* operator->() const;
+  Auxilary* Aux;
+};
+void f() {
+  ClassWithPtr x;
+  x[[.]]^;
+}
+  )cpp");
+  auto Results =
+  completions(Server, TestCode.code(), TestCode.point(), {}, Opts);
+  EXPECT_EQ(Results.Completions.size(), 3u);
+
+  TextEdit ReplacementEdit;
+  ReplacementEdit.range = TestCode.range();
+  ReplacementEdit.newText = "->";
+  for (const auto &C : Results.Completions) {
+EXPECT_TRUE(C.FixIts.empty() || C.Name == "AuxFunction");
+if (!C.Fix

[PATCH] D45444: [clang-tidy] implement new check for const-correctness

2018-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

> Could you give a concrete example of this?

vi llvm/lib/Demangle/ItaniumDemangle.cpp +1762

/home/jonas/opt/llvm/lib/Demangle/ItaniumDemangle.cpp:1762:7: warning:
variable 'num' of type 'char [FloatData::max_demangled_size]' can
be declared 'const' [cppcoreguidelines-const-correctness]
  char num[FloatData::max_demangled_size] = {0};
 ^
/home/jonas/opt/llvm/lib/Demangle/ItaniumDemangle.cpp:1763:7: warning:
variable 'n' of type 'int' can be declared 'const'
[cppcoreguidelines-const-correctness]
      int n = snprintf(num, sizeof(num), FloatData::spec, value);
 ^


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444



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


[PATCH] D50144: Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-08 Thread David Chisnall via Phabricator via cfe-commits
theraven updated this revision to Diff 159651.
theraven marked 2 inline comments as done.
theraven added a comment.
Herald added a subscriber: mgrang.

- Address Dustin's review comments.
- Fix an issue in protocol generation.
- Fix failing test.
- [gnu-objc] Make selector order deterministic.
- Address rjmcall's review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D50144

Files:
  include/clang/Driver/Options.td
  lib/AST/MicrosoftMangle.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/CGObjCRuntime.cpp
  lib/CodeGen/CGObjCRuntime.h
  lib/CodeGen/CodeGenFunction.h
  lib/Driver/ToolChains/Clang.cpp
  test/CodeGenObjC/gnu-init.m
  test/CodeGenObjC/gnustep2-proto.m
  test/CodeGenObjCXX/arc-marker-funclet.mm
  test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
  test/CodeGenObjCXX/msabi-objc-extensions.mm
  test/CodeGenObjCXX/msabi-objc-types.mm

Index: test/CodeGenObjCXX/msabi-objc-types.mm
===
--- test/CodeGenObjCXX/msabi-objc-types.mm
+++ test/CodeGenObjCXX/msabi-objc-types.mm
@@ -3,166 +3,166 @@
 @class I;
 
 id kid;
-// CHECK: @"?kid@@3PAUobjc_object@@A" =  dso_local global
+// CHECK: @"?kid@@3PAU.objc_object@@A" =  dso_local global
 
 Class klass;
-// CHECK: @"?klass@@3PAUobjc_class@@A" = dso_local global
+// CHECK: @"?klass@@3PAU.objc_class@@A" = dso_local global
 
 I *kI;
-// CHECK: @"?kI@@3PAUI@@A" = dso_local global
+// CHECK: @"?kI@@3PAU.objc_cls_I@@A" = dso_local global
 
 void f(I *) {}
-// CHECK-LABEL: "?f@@YAXPAUI@@@Z"
+// CHECK-LABEL: "?f@@YAXPAU.objc_cls_I@@@Z"
 
 void f(const I *) {}
-// CHECK-LABEL: "?f@@YAXPBUI@@@Z"
+// CHECK-LABEL: "?f@@YAXPBU.objc_cls_I@@@Z"
 
 void f(I &) {}
-// CHECK-LABEL: "?f@@YAXAAUI@@@Z"
+// CHECK-LABEL: "?f@@YAXAAU.objc_cls_I@@@Z"
 
 void f(const I &) {}
-// CHECK-LABEL: "?f@@YAXABUI@@@Z"
+// CHECK-LABEL: "?f@@YAXABU.objc_cls_I@@@Z"
 
 void f(const I &&) {}
-// CHECK-LABEL: "?f@@YAX$$QBUI@@@Z"
+// CHECK-LABEL: "?f@@YAX$$QBU.objc_cls_I@@@Z"
 
 void g(id) {}
-// CHECK-LABEL: "?g@@YAXPAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAXPAU.objc_object@@@Z"
 
 void g(id &) {}
-// CHECK-LABEL: "?g@@YAXAAPAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAXAAPAU.objc_object@@@Z"
 
 void g(const id &) {}
-// CHECK-LABEL: "?g@@YAXABQAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAXABQAU.objc_object@@@Z"
 
 void g(id &&) {}
-// CHECK-LABEL: "?g@@YAX$$QAPAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAX$$QAPAU.objc_object@@@Z"
 
 void h(Class) {}
-// CHECK-LABEL: "?h@@YAXPAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAXPAU.objc_class@@@Z"
 
 void h(Class &) {}
-// CHECK-LABEL: "?h@@YAXAAPAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAXAAPAU.objc_class@@@Z"
 
 void h(const Class &) {}
-// CHECK-LABEL: "?h@@YAXABQAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAXABQAU.objc_class@@@Z"
 
 void h(Class &&) {}
-// CHECK-LABEL: "?h@@YAX$$QAPAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAX$$QAPAU.objc_class@@@Z"
 
 I *i() { return nullptr; }
-// CHECK-LABEL: "?i@@YAPAUI@@XZ"
+// CHECK-LABEL: "?i@@YAPAU.objc_cls_I@@XZ"
 
 const I *j() { return nullptr; }
-// CHECK-LABEL: "?j@@YAPBUI@@XZ"
+// CHECK-LABEL: "?j@@YAPBU.objc_cls_I@@XZ"
 
 I &k() { return *kI; }
-// CHECK-LABEL: "?k@@YAAAUI@@XZ"
+// CHECK-LABEL: "?k@@YAAAU.objc_cls_I@@XZ"
 
 const I &l() { return *kI; }
-// CHECK-LABEL: "?l@@YAABUI@@XZ"
+// CHECK-LABEL: "?l@@YAABU.objc_cls_I@@XZ"
 
 void m(const id) {}
-// CHECK-LABEL: "?m@@YAXQAUobjc_object@@@Z"
+// CHECK-LABEL: "?m@@YAXQAU.objc_object@@@Z"
 
 void m(const I *) {}
-// CHECK-LABEL: "?m@@YAXPBUI@@@Z"
+// CHECK-LABEL: "?m@@YAXPBU.objc_cls_I@@@Z"
 
 void n(SEL) {}
-// CHECK-LABEL: "?n@@YAXPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXPAU.objc_selector@@@Z"
 
 void n(SEL *) {}
-// CHECK-LABEL: "?n@@YAXPAPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXPAPAU.objc_selector@@@Z"
 
 void n(const SEL *) {}
-// CHECK-LABEL: "?n@@YAXPBQAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXPBQAU.objc_selector@@@Z"
 
 void n(SEL &) {}
-// CHECK-LABEL: "?n@@YAXAAPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXAAPAU.objc_selector@@@Z"
 
 void n(const SEL &) {}
-// CHECK-LABEL: "?n@@YAXABQAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXABQAU.objc_selector@@@Z"
 
 void n(SEL &&) {}
-// CHECK-LABEL: "?n@@YAX$$QAPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAX$$QAPAU.objc_selector@@@Z"
 
 struct __declspec(dllexport) s {
   struct s &operator=(const struct s &) = delete;
 
   void m(I *) {}
-  // CHECK-LABEL: "?m@s@@QAAXPAUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXPAU.objc_cls_I@@@Z"
 
   void m(const I *) {}
-  // CHECK-LABEL: "?m@s@@QAAXPBUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXPBU.objc_cls_I@@@Z"
 
   void m(I &) {}
-  // CHECK-LABEL: "?m@s@@QAAXAAUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXAAU.objc_cls_I@@@Z"
 
   void m(const I &) {}
-  // CHECK-LABEL: "?m@s@@QAAXABUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXABU.objc_cls_I@@@Z"
 
   void m(I &&) {}
-  // CHECK-LABEL: "?m@s@@QAAX$$QAUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAX$$QAU.objc_cl

[PATCH] D50144: Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-08 Thread David Chisnall via Phabricator via cfe-commits
theraven updated this revision to Diff 159653.
theraven added a comment.

- Revert blocks part of the patch to put in a separate review.


Repository:
  rC Clang

https://reviews.llvm.org/D50144

Files:
  include/clang/Driver/Options.td
  lib/AST/MicrosoftMangle.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/CGObjCRuntime.cpp
  lib/CodeGen/CGObjCRuntime.h
  lib/CodeGen/CodeGenFunction.h
  lib/Driver/ToolChains/Clang.cpp
  test/CodeGenObjC/gnu-init.m
  test/CodeGenObjC/gnustep2-proto.m
  test/CodeGenObjCXX/arc-marker-funclet.mm
  test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
  test/CodeGenObjCXX/msabi-objc-extensions.mm
  test/CodeGenObjCXX/msabi-objc-types.mm

Index: test/CodeGenObjCXX/msabi-objc-types.mm
===
--- test/CodeGenObjCXX/msabi-objc-types.mm
+++ test/CodeGenObjCXX/msabi-objc-types.mm
@@ -3,166 +3,166 @@
 @class I;
 
 id kid;
-// CHECK: @"?kid@@3PAUobjc_object@@A" =  dso_local global
+// CHECK: @"?kid@@3PAU.objc_object@@A" =  dso_local global
 
 Class klass;
-// CHECK: @"?klass@@3PAUobjc_class@@A" = dso_local global
+// CHECK: @"?klass@@3PAU.objc_class@@A" = dso_local global
 
 I *kI;
-// CHECK: @"?kI@@3PAUI@@A" = dso_local global
+// CHECK: @"?kI@@3PAU.objc_cls_I@@A" = dso_local global
 
 void f(I *) {}
-// CHECK-LABEL: "?f@@YAXPAUI@@@Z"
+// CHECK-LABEL: "?f@@YAXPAU.objc_cls_I@@@Z"
 
 void f(const I *) {}
-// CHECK-LABEL: "?f@@YAXPBUI@@@Z"
+// CHECK-LABEL: "?f@@YAXPBU.objc_cls_I@@@Z"
 
 void f(I &) {}
-// CHECK-LABEL: "?f@@YAXAAUI@@@Z"
+// CHECK-LABEL: "?f@@YAXAAU.objc_cls_I@@@Z"
 
 void f(const I &) {}
-// CHECK-LABEL: "?f@@YAXABUI@@@Z"
+// CHECK-LABEL: "?f@@YAXABU.objc_cls_I@@@Z"
 
 void f(const I &&) {}
-// CHECK-LABEL: "?f@@YAX$$QBUI@@@Z"
+// CHECK-LABEL: "?f@@YAX$$QBU.objc_cls_I@@@Z"
 
 void g(id) {}
-// CHECK-LABEL: "?g@@YAXPAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAXPAU.objc_object@@@Z"
 
 void g(id &) {}
-// CHECK-LABEL: "?g@@YAXAAPAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAXAAPAU.objc_object@@@Z"
 
 void g(const id &) {}
-// CHECK-LABEL: "?g@@YAXABQAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAXABQAU.objc_object@@@Z"
 
 void g(id &&) {}
-// CHECK-LABEL: "?g@@YAX$$QAPAUobjc_object@@@Z"
+// CHECK-LABEL: "?g@@YAX$$QAPAU.objc_object@@@Z"
 
 void h(Class) {}
-// CHECK-LABEL: "?h@@YAXPAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAXPAU.objc_class@@@Z"
 
 void h(Class &) {}
-// CHECK-LABEL: "?h@@YAXAAPAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAXAAPAU.objc_class@@@Z"
 
 void h(const Class &) {}
-// CHECK-LABEL: "?h@@YAXABQAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAXABQAU.objc_class@@@Z"
 
 void h(Class &&) {}
-// CHECK-LABEL: "?h@@YAX$$QAPAUobjc_class@@@Z"
+// CHECK-LABEL: "?h@@YAX$$QAPAU.objc_class@@@Z"
 
 I *i() { return nullptr; }
-// CHECK-LABEL: "?i@@YAPAUI@@XZ"
+// CHECK-LABEL: "?i@@YAPAU.objc_cls_I@@XZ"
 
 const I *j() { return nullptr; }
-// CHECK-LABEL: "?j@@YAPBUI@@XZ"
+// CHECK-LABEL: "?j@@YAPBU.objc_cls_I@@XZ"
 
 I &k() { return *kI; }
-// CHECK-LABEL: "?k@@YAAAUI@@XZ"
+// CHECK-LABEL: "?k@@YAAAU.objc_cls_I@@XZ"
 
 const I &l() { return *kI; }
-// CHECK-LABEL: "?l@@YAABUI@@XZ"
+// CHECK-LABEL: "?l@@YAABU.objc_cls_I@@XZ"
 
 void m(const id) {}
-// CHECK-LABEL: "?m@@YAXQAUobjc_object@@@Z"
+// CHECK-LABEL: "?m@@YAXQAU.objc_object@@@Z"
 
 void m(const I *) {}
-// CHECK-LABEL: "?m@@YAXPBUI@@@Z"
+// CHECK-LABEL: "?m@@YAXPBU.objc_cls_I@@@Z"
 
 void n(SEL) {}
-// CHECK-LABEL: "?n@@YAXPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXPAU.objc_selector@@@Z"
 
 void n(SEL *) {}
-// CHECK-LABEL: "?n@@YAXPAPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXPAPAU.objc_selector@@@Z"
 
 void n(const SEL *) {}
-// CHECK-LABEL: "?n@@YAXPBQAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXPBQAU.objc_selector@@@Z"
 
 void n(SEL &) {}
-// CHECK-LABEL: "?n@@YAXAAPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXAAPAU.objc_selector@@@Z"
 
 void n(const SEL &) {}
-// CHECK-LABEL: "?n@@YAXABQAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAXABQAU.objc_selector@@@Z"
 
 void n(SEL &&) {}
-// CHECK-LABEL: "?n@@YAX$$QAPAUobjc_selector@@@Z"
+// CHECK-LABEL: "?n@@YAX$$QAPAU.objc_selector@@@Z"
 
 struct __declspec(dllexport) s {
   struct s &operator=(const struct s &) = delete;
 
   void m(I *) {}
-  // CHECK-LABEL: "?m@s@@QAAXPAUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXPAU.objc_cls_I@@@Z"
 
   void m(const I *) {}
-  // CHECK-LABEL: "?m@s@@QAAXPBUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXPBU.objc_cls_I@@@Z"
 
   void m(I &) {}
-  // CHECK-LABEL: "?m@s@@QAAXAAUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXAAU.objc_cls_I@@@Z"
 
   void m(const I &) {}
-  // CHECK-LABEL: "?m@s@@QAAXABUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAXABU.objc_cls_I@@@Z"
 
   void m(I &&) {}
-  // CHECK-LABEL: "?m@s@@QAAX$$QAUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAX$$QAU.objc_cls_I@@@Z"
 
   void m(const I &&) {}
-  // CHECK-LABEL: "?m@s@@QAAX$$QBUI@@@Z"
+  // CHECK-LABEL: "?m@s@@QAAX$$QBU.objc_cls_I@@@Z"
 
   void m(id) {}
-  // CHECK-LABEL: "?m@s@@QAAXPAUobjc_object@@@Z"
+  // CHECK-LABEL: "?m@

[PATCH] D50193: Added functionality to suggest FixIts for conversion of '->' to '.' and vice versa.

2018-08-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE339224: Added functionality to suggest FixIts for 
conversion of '->' to '.' and vice… (authored by 
kadircet, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50193?vs=159648&id=159655#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50193

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Diagnostics.cpp
  clangd/Protocol.h
  clangd/Quality.cpp
  clangd/Quality.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/QualityTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -79,6 +79,23 @@
   return MemIndex::build(std::move(Slab).build());
 }
 
+CodeCompleteResult completions(ClangdServer &Server, StringRef TestCode,
+   Position point,
+   std::vector IndexSymbols = {},
+   clangd::CodeCompleteOptions Opts = {}) {
+  std::unique_ptr OverrideIndex;
+  if (!IndexSymbols.empty()) {
+assert(!Opts.Index && "both Index and IndexSymbols given!");
+OverrideIndex = memIndex(std::move(IndexSymbols));
+Opts.Index = OverrideIndex.get();
+  }
+
+  auto File = testPath("foo.cpp");
+  runAddDocument(Server, File, TestCode);
+  auto CompletionList = cantFail(runCodeComplete(Server, File, point, Opts));
+  return CompletionList;
+}
+
 CodeCompleteResult completions(ClangdServer &Server, StringRef Text,
std::vector IndexSymbols = {},
clangd::CodeCompleteOptions Opts = {}) {
@@ -1342,6 +1359,85 @@
   EXPECT_THAT(Results.Context, CodeCompletionContext::CCC_DotMemberAccess);
 }
 
+TEST(CompletionTest, FixItForArrowToDot) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+  Annotations TestCode(
+  R"cpp(
+class Auxilary {
+ public:
+  void AuxFunction();
+};
+class ClassWithPtr {
+ public:
+  void MemberFunction();
+  Auxilary* operator->() const;
+  Auxilary* Aux;
+};
+void f() {
+  ClassWithPtr x;
+  x[[->]]^;
+}
+  )cpp");
+  auto Results =
+  completions(Server, TestCode.code(), TestCode.point(), {}, Opts);
+  EXPECT_EQ(Results.Completions.size(), 3u);
+
+  TextEdit ReplacementEdit;
+  ReplacementEdit.range = TestCode.range();
+  ReplacementEdit.newText = ".";
+  for (const auto &C : Results.Completions) {
+EXPECT_TRUE(C.FixIts.size() == 1u || C.Name == "AuxFunction");
+if (!C.FixIts.empty())
+  EXPECT_THAT(C.FixIts, ElementsAre(ReplacementEdit));
+  }
+}
+
+TEST(CompletionTest, FixItForDotToArrow) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+  Annotations TestCode(
+  R"cpp(
+class Auxilary {
+ public:
+  void AuxFunction();
+};
+class ClassWithPtr {
+ public:
+  void MemberFunction();
+  Auxilary* operator->() const;
+  Auxilary* Aux;
+};
+void f() {
+  ClassWithPtr x;
+  x[[.]]^;
+}
+  )cpp");
+  auto Results =
+  completions(Server, TestCode.code(), TestCode.point(), {}, Opts);
+  EXPECT_EQ(Results.Completions.size(), 3u);
+
+  TextEdit ReplacementEdit;
+  ReplacementEdit.range = TestCode.range();
+  ReplacementEdit.newText = "->";
+  for (const auto &C : Results.Completions) {
+EXPECT_TRUE(C.FixIts.empty() || C.Name == "AuxFunction");
+if (!C.FixIts.empty()) {
+  EXPECT_THAT(C.FixIts, ElementsAre(ReplacementEdit));
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -346,6 +346,28 @@
   EXPECT_EQ(Q.Category, SymbolQualitySignals::Constructor);
 }
 
+TEST(QualityTests, ItemWithFixItsRankedDown) {
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+
+  auto Header = TestTU::withHeaderCode(R"cpp(
+int x;
+  )cpp");
+  auto AST = Header.build();
+
+  SymbolRelevanceSignals RelevanceWithFixIt;
+  RelevanceWithFixIt.merge(CodeCompletionResult(&findDecl(AST, "x"), 0, nullptr,
+false, true, {FixItHint{}}));
+  EXPECT_TRUE(RelevanceWithFixIt.NeedsFixIts);
+
+  SymbolRelevanceSignals RelevanceWithoutFixIt;
+  

[PATCH] D50385: [clangd] Collect symbol occurrences from AST.

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

2 high-level questions:

1. What's the reason for having a separate `SymbolOccurrenceSlab`? Could store 
occurrences as extra payload of `Symbol`?

2. Could we merge `SymbolOccurrenceCollector` into the existing 
`SymbolCollector`? They look a lot alike. Having another index data consumer 
seems like more overhead on the user side.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50385



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


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

2018-08-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D47849#1190997, @gtbercea wrote:

> Don't we want to use device specific math functions?
>  It's not just about avoiding some the host specific assembly, it's also 
> about getting an implementation tailored to the device.


Ok, so you are already talking about performance. I think we should fix 
correctness first, in particular the compiler shouldn't complain whenever 
`` is included.

I experimented with adding only a minimum of target defines (`__amd64__` and 
`__x86_64__`): While I think this is a step into the right direction it still 
fails when including ``.

Btw the GCC folks don't have a complete solution either: If you compile with 
`-O2` you get the same complaints once the code starts calling `signbit`. Maybe 
Clang should also implement lazy Sema checking for device side compilation?


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D50428: Add support for importing imaginary literals

2018-08-08 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a_sidorin, r.stahl, xazax.hun.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

Repository:
  rC Clang

https://reviews.llvm.org/D50428

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTImporter.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -553,6 +553,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport(
+  "void declToImport() { (void)1.0i; }",
+  Lang_CXX14, "", Lang_CXX14, Verifier,
+  functionDecl(hasDescendant(imaginaryLiteral(;
+}
+
 TEST_P(ImportExpr, ImportCompoundLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -710,6 +710,7 @@
 const internal::VariadicDynCastAllOfMatcher
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher 
floatLiteral;
+const internal::VariadicDynCastAllOfMatcher 
imaginaryLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -412,6 +412,7 @@
 Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
 Expr *VisitIntegerLiteral(IntegerLiteral *E);
 Expr *VisitFloatingLiteral(FloatingLiteral *E);
+Expr *VisitImaginaryLiteral(ImaginaryLiteral *E);
 Expr *VisitCharacterLiteral(CharacterLiteral *E);
 Expr *VisitStringLiteral(StringLiteral *E);
 Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -5594,6 +5595,7 @@
 Importer.Import(E->getLocation()));
 }
 
+
 Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) {
   QualType T = Importer.Import(E->getType());
   if (T.isNull())
@@ -5604,6 +5606,19 @@
 Importer.Import(E->getLocation()));
 }
 
+Expr *ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+  QualType T = Importer.Import(E->getType());
+  if (T.isNull())
+return nullptr;
+
+  Expr *SubE = Importer.Import(E->getSubExpr());
+  if (!SubE)
+return nullptr;
+
+  return new (Importer.getToContext())
+  ImaginaryLiteral(SubE, T);
+}
+
 Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
   QualType T = Importer.Import(E->getType());
   if (T.isNull())
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -1975,6 +1975,11 @@
 extern const internal::VariadicDynCastAllOfMatcher
 floatLiteral;
 
+/// Matches imaginary literals, which are based on integer and floating
+/// point literals e.g.: 1i, 1.0i
+extern const internal::VariadicDynCastAllOfMatcher
+imaginaryLiteral;
+
 /// Matches user defined literal operator call.
 ///
 /// Example match: "foo"_suffix


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -553,6 +553,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport(
+  "void declToImport() { (void)1.0i; }",
+  Lang_CXX14, "", Lang_CXX14, Verifier,
+  functionDecl(hasDescendant(imaginaryLiteral(;
+}
+
 TEST_P(ImportExpr, ImportCompoundLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -710,6 +710,7 @@
 const internal::VariadicDynCastAllOfMatcher
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher floatLiteral;
+const internal::VariadicDynCastAllOfMatcher imaginaryLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -412,6 +412,7 @@
 Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
 Expr *VisitIntegerLiteral(IntegerLiteral *E);
 Expr *VisitFloatingLiteral(FloatingLiteral *E);
+Expr *VisitImaginaryLiteral(ImaginaryLiteral *E);
 Expr *VisitCharacter

[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 159658.
kbobyrev added a comment.

Minor code cleanup. This is now a fully functional symbol index.

I have reflected my concerns and uncertainties in `FIXME`s, please indicate if 
you think there's something to improve in this patch. In general, I believe it 
is ready for a review.


https://reviews.llvm.org/D50337

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h
  clang-tools-extra/clangd/index/dex/Token.cpp
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp
  clang-tools-extra/unittests/clangd/IndexTests.cpp
  clang-tools-extra/unittests/clangd/TestIndexOperations.cpp
  clang-tools-extra/unittests/clangd/TestIndexOperations.h

Index: clang-tools-extra/unittests/clangd/TestIndexOperations.h
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndexOperations.h
@@ -0,0 +1,57 @@
+//===-- IndexHelpers.h --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+
+#include "index/Index.h"
+#include "index/Merge.h"
+#include "index/dex/DexIndex.h"
+#include "index/dex/Iterator.h"
+#include "index/dex/Token.h"
+#include "index/dex/Trigram.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName);
+
+struct SlabAndPointers {
+  SymbolSlab Slab;
+  std::vector Pointers;
+};
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr);
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr);
+
+std::string getQualifiedName(const Symbol &Sym);
+
+std::vector match(const SymbolIndex &I,
+   const FuzzyFindRequest &Req,
+   bool *Incomplete = nullptr);
+
+// Returns qualified names of symbols with any of IDs in the index.
+std::vector lookup(const SymbolIndex &I,
+llvm::ArrayRef IDs);
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/unittests/clangd/TestIndexOperations.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndexOperations.cpp
@@ -0,0 +1,89 @@
+//===-- IndexHelpers.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "IndexHelpers.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName) {
+  Symbol Sym;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos + 2);
+  }
+  return Sym;
+}
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols) {
+  SymbolSlab::Builder Slab;
+  for (llvm::StringRef QName : QualifiedNames)
+Slab.insert(symbol(QName));
+
+  auto Storage = std::make_shared();
+  Storage->Slab = std::move(Slab).build();
+  for (const auto &Sym : Storage->Slab)
+Storage->Pointers.push_back(&Sym);
+  if (WeakSymbols)
+*WeakSymbols = Storage;
+  auto *Pointers = &Storage->Pointers;
+  return {std::move(Storage), Pointers};
+}
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   

[PATCH] D49796: [ASTImporter] Load external Decls when getting field index.

2018-08-08 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 159659.
balazske added a comment.

- Added common getFieldIndex.
- Corrected test ImportUnnamedFieldsInCorrectOrder.


Repository:
  rC Clang

https://reviews.llvm.org/D49796

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp
  test/ASTMerge/unnamed_fields/Inputs/il.cpp
  test/ASTMerge/unnamed_fields/test.cpp
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2641,6 +2641,40 @@
   R1, recordDecl(has(fieldDecl(hasName("next"));
 }
 
+TEST_P(ASTImporterTestBase, ImportUnnamedFieldsInCorrectOrder) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  void f(int X, int Y, bool Z) {
+(void)[X, Y, Z] { (void)Z; };
+  }
+  )",
+  Lang_CXX11, "input0.cc");
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  auto *ToF = cast_or_null(Import(FromF, Lang_CXX11));
+  EXPECT_TRUE(ToF);
+
+  CXXRecordDecl *FromLambda =
+  cast(cast(cast(
+  FromF->getBody())->body_front())->getSubExpr())->getLambdaClass();
+
+  auto *ToLambda = cast_or_null(Import(FromLambda, Lang_CXX11));
+  EXPECT_TRUE(ToLambda);
+
+  // Check if the fields of the lambda class are imported in correct order.
+  unsigned FromIndex = 0u;
+  for (auto *FromField : FromLambda->fields()) {
+ASSERT_FALSE(FromField->getDeclName());
+auto *ToField = cast_or_null(Import(FromField, Lang_CXX11));
+EXPECT_TRUE(ToField);
+unsigned ToIndex = ASTImporter::getFieldIndex(ToField);
+EXPECT_EQ(ToIndex, FromIndex + 1);
+++FromIndex;
+  }
+
+  EXPECT_EQ(FromIndex, 3u);
+}
+
 struct DeclContextTest : ASTImporterTestBase {};
 
 TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) {
Index: test/ASTMerge/unnamed_fields/test.cpp
===
--- /dev/null
+++ test/ASTMerge/unnamed_fields/test.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/il.cpp
+// RUN: %clang_cc1 -ast-merge %t.1.ast -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
+// CHECK-NOT: warning: field '' declared with incompatible types in different translation units ('bool' vs. 'int')
Index: test/ASTMerge/unnamed_fields/Inputs/il.cpp
===
--- /dev/null
+++ test/ASTMerge/unnamed_fields/Inputs/il.cpp
@@ -0,0 +1,3 @@
+void f(int X, int Y, bool Z) {
+  auto x = [X, Y, Z] { (void)Z; };
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -71,6 +71,28 @@
 
 namespace clang {
 
+  unsigned ASTImporter::getFieldIndex(Decl *F) {
+assert(F && (isa(*F) || isa(*F)) &&
+"Try to get field index for non-field.");
+
+auto *Owner = dyn_cast(F->getDeclContext());
+if (!Owner)
+  return 0;
+
+unsigned Index = 1;
+for (const auto *D : Owner->decls()) {
+  if (D == F)
+return Index;
+
+  if (isa(*D) || isa(*D))
+++Index;
+}
+
+llvm_unreachable("Field was not found in its parent context.");
+
+return 0;
+  }
+
   template 
   SmallVector
   getCanonicalForwardRedeclChain(Redeclarable* D) {
@@ -2829,23 +2851,6 @@
   return VisitCXXMethodDecl(D);
 }
 
-static unsigned getFieldIndex(Decl *F) {
-  auto *Owner = dyn_cast(F->getDeclContext());
-  if (!Owner)
-return 0;
-
-  unsigned Index = 1;
-  for (const auto *D : Owner->noload_decls()) {
-if (D == F)
-  return Index;
-
-if (isa(*D) || isa(*D))
-  ++Index;
-  }
-
-  return Index;
-}
-
 Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
   // Import the major distinguishing characteristics of a variable.
   DeclContext *DC, *LexicalDC;
@@ -2863,7 +2868,9 @@
   for (auto *FoundDecl : FoundDecls) {
 if (auto *FoundField = dyn_cast(FoundDecl)) {
   // For anonymous fields, match up by index.
-  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
+  if (!Name &&
+  ASTImporter::getFieldIndex(D) !=
+  ASTImporter::getFieldIndex(FoundField))
 continue;
 
   if (Importer.IsStructurallyEquivalent(D->getType(),
@@ -2928,7 +2935,9 @@
   for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
 if (auto *FoundField = dyn_cast(FoundDecls[I])) {
   // For anonymous indirect fields, match up by index.
-  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
+  if (!Name &&
+  ASTImporter::getFieldIndex(D) !=
+  ASTImporter::getFieldIndex(FoundField))
 continue;
 
   if (Importer.IsStructurallyEquivalent(D->getType(),
Index: include/clang/AST/ASTImporter.h
===
--- include/clang/AST/ASTImporter.h
+++ include/clang/AST/ASTImporter.h
@@ -333,6 +333,13 @@
 /// equivalent.

[PATCH] D50428: Add support for importing imaginary literals

2018-08-08 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 159662.
martong added a comment.

Remove superflous newline


Repository:
  rC Clang

https://reviews.llvm.org/D50428

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTImporter.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -553,6 +553,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport(
+  "void declToImport() { (void)1.0i; }",
+  Lang_CXX14, "", Lang_CXX14, Verifier,
+  functionDecl(hasDescendant(imaginaryLiteral(;
+}
+
 TEST_P(ImportExpr, ImportCompoundLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -710,6 +710,7 @@
 const internal::VariadicDynCastAllOfMatcher
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher 
floatLiteral;
+const internal::VariadicDynCastAllOfMatcher 
imaginaryLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -412,6 +412,7 @@
 Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
 Expr *VisitIntegerLiteral(IntegerLiteral *E);
 Expr *VisitFloatingLiteral(FloatingLiteral *E);
+Expr *VisitImaginaryLiteral(ImaginaryLiteral *E);
 Expr *VisitCharacterLiteral(CharacterLiteral *E);
 Expr *VisitStringLiteral(StringLiteral *E);
 Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -5604,6 +5605,19 @@
 Importer.Import(E->getLocation()));
 }
 
+Expr *ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+  QualType T = Importer.Import(E->getType());
+  if (T.isNull())
+return nullptr;
+
+  Expr *SubE = Importer.Import(E->getSubExpr());
+  if (!SubE)
+return nullptr;
+
+  return new (Importer.getToContext())
+  ImaginaryLiteral(SubE, T);
+}
+
 Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
   QualType T = Importer.Import(E->getType());
   if (T.isNull())
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -1975,6 +1975,11 @@
 extern const internal::VariadicDynCastAllOfMatcher
 floatLiteral;
 
+/// Matches imaginary literals, which are based on integer and floating
+/// point literals e.g.: 1i, 1.0i
+extern const internal::VariadicDynCastAllOfMatcher
+imaginaryLiteral;
+
 /// Matches user defined literal operator call.
 ///
 /// Example match: "foo"_suffix


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -553,6 +553,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport(
+  "void declToImport() { (void)1.0i; }",
+  Lang_CXX14, "", Lang_CXX14, Verifier,
+  functionDecl(hasDescendant(imaginaryLiteral(;
+}
+
 TEST_P(ImportExpr, ImportCompoundLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -710,6 +710,7 @@
 const internal::VariadicDynCastAllOfMatcher
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher floatLiteral;
+const internal::VariadicDynCastAllOfMatcher imaginaryLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -412,6 +412,7 @@
 Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
 Expr *VisitIntegerLiteral(IntegerLiteral *E);
 Expr *VisitFloatingLiteral(FloatingLiteral *E);
+Expr *VisitImaginaryLiteral(ImaginaryLiteral *E);
 Expr *VisitCharacterLiteral(CharacterLiteral *E);
 Expr *VisitStringLiteral(StringLiteral *E);
 Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -5604,6 +5605,19 @@
 Importer.Import(E->getLocation()));
 }
 
+Expr *ASTNodeImporter::VisitImaginaryL

r339226 - [ASTImporter] Load external Decls when getting field index.

2018-08-08 Thread Balazs Keri via cfe-commits
Author: balazske
Date: Wed Aug  8 02:40:57 2018
New Revision: 339226

URL: http://llvm.org/viewvc/llvm-project?rev=339226&view=rev
Log:
[ASTImporter] Load external Decls when getting field index.

Summary:
At equality check of fields without name the index of fields is compared.
At determining the index of a field all fields of the parent context
should be loaded from external source to find the field at all.

Reviewers: a.sidorin, a_sidorin, r.stahl

Reviewed By: a.sidorin

Subscribers: martong, cfe-commits

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

Added:
cfe/trunk/test/ASTMerge/unnamed_fields/
cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/
cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp
cfe/trunk/test/ASTMerge/unnamed_fields/test.cpp
Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=339226&r1=339225&r2=339226&view=diff
==
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Wed Aug  8 02:40:57 2018
@@ -333,6 +333,13 @@ class Attr;
 /// equivalent.
 bool IsStructurallyEquivalent(QualType From, QualType To,
   bool Complain = true);
+
+/// Determine the index of a field in its parent record.
+/// F should be a field (or indirect field) declaration.
+/// \returns The index of the field in its parent context, starting from 1.
+/// 0 is returned on error (parent context is non-record).
+static unsigned getFieldIndex(Decl *F);
+
   };
 
 } // namespace clang

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=339226&r1=339225&r2=339226&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Aug  8 02:40:57 2018
@@ -71,6 +71,28 @@
 
 namespace clang {
 
+  unsigned ASTImporter::getFieldIndex(Decl *F) {
+assert(F && (isa(*F) || isa(*F)) &&
+"Try to get field index for non-field.");
+
+auto *Owner = dyn_cast(F->getDeclContext());
+if (!Owner)
+  return 0;
+
+unsigned Index = 1;
+for (const auto *D : Owner->decls()) {
+  if (D == F)
+return Index;
+
+  if (isa(*D) || isa(*D))
+++Index;
+}
+
+llvm_unreachable("Field was not found in its parent context.");
+
+return 0;
+  }
+
   template 
   SmallVector
   getCanonicalForwardRedeclChain(Redeclarable* D) {
@@ -2829,23 +2851,6 @@ Decl *ASTNodeImporter::VisitCXXConversio
   return VisitCXXMethodDecl(D);
 }
 
-static unsigned getFieldIndex(Decl *F) {
-  auto *Owner = dyn_cast(F->getDeclContext());
-  if (!Owner)
-return 0;
-
-  unsigned Index = 1;
-  for (const auto *D : Owner->noload_decls()) {
-if (D == F)
-  return Index;
-
-if (isa(*D) || isa(*D))
-  ++Index;
-  }
-
-  return Index;
-}
-
 Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
   // Import the major distinguishing characteristics of a variable.
   DeclContext *DC, *LexicalDC;
@@ -2863,7 +2868,9 @@ Decl *ASTNodeImporter::VisitFieldDecl(Fi
   for (auto *FoundDecl : FoundDecls) {
 if (auto *FoundField = dyn_cast(FoundDecl)) {
   // For anonymous fields, match up by index.
-  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
+  if (!Name &&
+  ASTImporter::getFieldIndex(D) !=
+  ASTImporter::getFieldIndex(FoundField))
 continue;
 
   if (Importer.IsStructurallyEquivalent(D->getType(),
@@ -2928,7 +2935,9 @@ Decl *ASTNodeImporter::VisitIndirectFiel
   for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
 if (auto *FoundField = dyn_cast(FoundDecls[I])) {
   // For anonymous indirect fields, match up by index.
-  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
+  if (!Name &&
+  ASTImporter::getFieldIndex(D) !=
+  ASTImporter::getFieldIndex(FoundField))
 continue;
 
   if (Importer.IsStructurallyEquivalent(D->getType(),

Added: cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp?rev=339226&view=auto
==
--- cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp (added)
+++ cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp Wed Aug  8 02:40:57 
2018
@@ -0,0 +1,3 @@
+void f(int X, int Y, bool Z) {
+  auto x = [X, Y, Z] { (void)Z; };
+}

Added: cfe/trunk/test/ASTMerge/unnamed_fields/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/unnamed_fields/test.cpp?rev=339226&view=auto

[PATCH] D49796: [ASTImporter] Load external Decls when getting field index.

2018-08-08 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339226: [ASTImporter] Load external Decls when getting field 
index. (authored by balazske, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D49796

Files:
  cfe/trunk/include/clang/AST/ASTImporter.h
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp
  cfe/trunk/test/ASTMerge/unnamed_fields/test.cpp
  cfe/trunk/unittests/AST/ASTImporterTest.cpp

Index: cfe/trunk/include/clang/AST/ASTImporter.h
===
--- cfe/trunk/include/clang/AST/ASTImporter.h
+++ cfe/trunk/include/clang/AST/ASTImporter.h
@@ -333,6 +333,13 @@
 /// equivalent.
 bool IsStructurallyEquivalent(QualType From, QualType To,
   bool Complain = true);
+
+/// Determine the index of a field in its parent record.
+/// F should be a field (or indirect field) declaration.
+/// \returns The index of the field in its parent context, starting from 1.
+/// 0 is returned on error (parent context is non-record).
+static unsigned getFieldIndex(Decl *F);
+
   };
 
 } // namespace clang
Index: cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp
===
--- cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp
+++ cfe/trunk/test/ASTMerge/unnamed_fields/Inputs/il.cpp
@@ -0,0 +1,3 @@
+void f(int X, int Y, bool Z) {
+  auto x = [X, Y, Z] { (void)Z; };
+}
Index: cfe/trunk/test/ASTMerge/unnamed_fields/test.cpp
===
--- cfe/trunk/test/ASTMerge/unnamed_fields/test.cpp
+++ cfe/trunk/test/ASTMerge/unnamed_fields/test.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/il.cpp
+// RUN: %clang_cc1 -ast-merge %t.1.ast -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
+// CHECK-NOT: warning: field '' declared with incompatible types in different translation units ('bool' vs. 'int')
Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -71,6 +71,28 @@
 
 namespace clang {
 
+  unsigned ASTImporter::getFieldIndex(Decl *F) {
+assert(F && (isa(*F) || isa(*F)) &&
+"Try to get field index for non-field.");
+
+auto *Owner = dyn_cast(F->getDeclContext());
+if (!Owner)
+  return 0;
+
+unsigned Index = 1;
+for (const auto *D : Owner->decls()) {
+  if (D == F)
+return Index;
+
+  if (isa(*D) || isa(*D))
+++Index;
+}
+
+llvm_unreachable("Field was not found in its parent context.");
+
+return 0;
+  }
+
   template 
   SmallVector
   getCanonicalForwardRedeclChain(Redeclarable* D) {
@@ -2829,23 +2851,6 @@
   return VisitCXXMethodDecl(D);
 }
 
-static unsigned getFieldIndex(Decl *F) {
-  auto *Owner = dyn_cast(F->getDeclContext());
-  if (!Owner)
-return 0;
-
-  unsigned Index = 1;
-  for (const auto *D : Owner->noload_decls()) {
-if (D == F)
-  return Index;
-
-if (isa(*D) || isa(*D))
-  ++Index;
-  }
-
-  return Index;
-}
-
 Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
   // Import the major distinguishing characteristics of a variable.
   DeclContext *DC, *LexicalDC;
@@ -2863,7 +2868,9 @@
   for (auto *FoundDecl : FoundDecls) {
 if (auto *FoundField = dyn_cast(FoundDecl)) {
   // For anonymous fields, match up by index.
-  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
+  if (!Name &&
+  ASTImporter::getFieldIndex(D) !=
+  ASTImporter::getFieldIndex(FoundField))
 continue;
 
   if (Importer.IsStructurallyEquivalent(D->getType(),
@@ -2928,7 +2935,9 @@
   for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
 if (auto *FoundField = dyn_cast(FoundDecls[I])) {
   // For anonymous indirect fields, match up by index.
-  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
+  if (!Name &&
+  ASTImporter::getFieldIndex(D) !=
+  ASTImporter::getFieldIndex(FoundField))
 continue;
 
   if (Importer.IsStructurallyEquivalent(D->getType(),
Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp
@@ -2641,6 +2641,40 @@
   R1, recordDecl(has(fieldDecl(hasName("next"));
 }
 
+TEST_P(ASTImporterTestBase, ImportUnnamedFieldsInCorrectOrder) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  void f(int X, int Y, bool Z) {
+(void)[X, Y, Z] { (void)Z; };
+  }
+  )",
+  Lang_CXX11, "input0.cc");
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  auto *ToF = cast_or_null(Import(FromF, Lang_CXX11));
+  EXPECT

[PATCH] D50436: Correctly initialise global blocks on Windows.

2018-08-08 Thread David Chisnall via Phabricator via cfe-commits
theraven created this revision.
theraven added a reviewer: rjmccall.
Herald added a subscriber: cfe-commits.

Windows does not allow globals to be initialised to point to globals in
another DLL.  Exported globals may be referenced only from code.  Work
around this by creating an initialiser that runs in early library
initialisation and sets the isa pointer.


Repository:
  rC Clang

https://reviews.llvm.org/D50436

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGen/global-blocks-win32.c


Index: test/CodeGen/global-blocks-win32.c
===
--- /dev/null
+++ test/CodeGen/global-blocks-win32.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fblocks -triple i386-pc-windows-msvc %s -emit-llvm -o - 
-fblocks | FileCheck %s
+
+
+int (^x)(void) = ^() { return 21; };
+
+
+// Check that the block literal is emitted with a null isa pointer
+// CHECK: @__block_literal_global = internal global { i8**, i32, i32, i8*, 
%struct.__block_descriptor* } { i8** null, 
+
+// Check that _NSConcreteGlobalBlock has the correct dllimport specifier.
+// CHECK: @_NSConcreteGlobalBlock = external dllimport global i8*
+// Check that we create an initialiser pointer in the correct section (early 
library initialisation).
+// CHECK: @.block_isa_init_ptr = internal constant void ()* @.block_isa_init, 
section ".CRT$XCLa"
+
+// Check that we emit an initialiser for it.
+// CHECK: define internal void @.block_isa_init() {
+// CHECK: store i8** @_NSConcreteGlobalBlock, i8*** getelementptr inbounds ({ 
i8**, i32, i32, i8*, %struct.__block_descriptor* }, { i8**, i32, i32, i8*, 
%struct.__block_descriptor* }* @__block_literal_global, i32 0, i32 0), align 4
+
Index: lib/CodeGen/CGBlocks.cpp
===
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -1213,9 +1213,13 @@
   auto fields = builder.beginStruct();
 
   bool IsOpenCL = CGM.getLangOpts().OpenCL;
+  bool IsWindows = CGM.getTarget().getTriple().isOSWindows();
   if (!IsOpenCL) {
 // isa
-fields.add(CGM.getNSConcreteGlobalBlock());
+if (IsWindows)
+  fields.addNullPointer(CGM.Int8PtrPtrTy);
+else
+  fields.add(CGM.getNSConcreteGlobalBlock());
 
 // __flags
 BlockFlags flags = BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE;
@@ -1250,7 +1254,27 @@
 
   llvm::Constant *literal = fields.finishAndCreateGlobal(
   "__block_literal_global", blockInfo.BlockAlign,
-  /*constant*/ true, llvm::GlobalVariable::InternalLinkage, AddrSpace);
+  /*constant*/ !IsWindows, llvm::GlobalVariable::InternalLinkage, 
AddrSpace);
+
+  // Windows does not allow globals to be initialised to point to globals in
+  // different DLLs.  Any such variables must run code to initialise them.
+  if (IsWindows) {
+auto *Init = llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy,
+  {}), llvm::GlobalValue::InternalLinkage, ".block_isa_init",
+&CGM.getModule());
+llvm::IRBuilder<> b(llvm::BasicBlock::Create(CGM.getLLVMContext(), "entry",
+  Init));
+b.CreateAlignedStore(CGM.getNSConcreteGlobalBlock(),
+b.CreateStructGEP(literal, 0), CGM.getPointerAlign().getQuantity());
+b.CreateRetVoid();
+// We can't use the normal LLVM global initialisation array, because we
+// need to specify that this runs early in library initialisation.
+auto *InitVar = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
+/*isConstant*/true, llvm::GlobalValue::InternalLinkage,
+Init, ".block_isa_init_ptr");
+InitVar->setSection(".CRT$XCLa");
+CGM.addUsedGlobal(InitVar);
+  }
 
   // Return a constant of the appropriately-casted type.
   llvm::Type *RequiredType =


Index: test/CodeGen/global-blocks-win32.c
===
--- /dev/null
+++ test/CodeGen/global-blocks-win32.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fblocks -triple i386-pc-windows-msvc %s -emit-llvm -o - -fblocks | FileCheck %s
+
+
+int (^x)(void) = ^() { return 21; };
+
+
+// Check that the block literal is emitted with a null isa pointer
+// CHECK: @__block_literal_global = internal global { i8**, i32, i32, i8*, %struct.__block_descriptor* } { i8** null, 
+
+// Check that _NSConcreteGlobalBlock has the correct dllimport specifier.
+// CHECK: @_NSConcreteGlobalBlock = external dllimport global i8*
+// Check that we create an initialiser pointer in the correct section (early library initialisation).
+// CHECK: @.block_isa_init_ptr = internal constant void ()* @.block_isa_init, section ".CRT$XCLa"
+
+// Check that we emit an initialiser for it.
+// CHECK: define internal void @.block_isa_init() {
+// CHECK: store i8** @_NSConcreteGlobalBlock, i8*** getelementptr inbounds ({ i8**, i32, i32, i8*, %struct.__block_descriptor* }, { i8**, i32, i32, i8*, %struct.__block_descriptor* }* @__block_literal_global, i32 0, i32 0), align 4
+
Index: lib/CodeGen/CGBlocks.cpp
===

[PATCH] D50144: Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-08 Thread David Chisnall via Phabricator via cfe-commits
theraven added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1262
+  if (IsWindows) {
+auto *Init = llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy,
+  {}), llvm::GlobalValue::InternalLinkage, ".block_isa_init",

rjmccall wrote:
> theraven wrote:
> > DHowett-MSFT wrote:
> > > Is there value in emitting a list of blocks that need to be initialized, 
> > > then initializing them in one go in a COMDAT-foldable function?
> > I think that the best solution is to move this into the back end, so that 
> > this code goes away in the front end, but anything that's referring to a 
> > dllimport global in a global initialiser is transformed in the back end to 
> > a list of initialisations and a comdat function that walks the list and 
> > sets them up.  That said, this seems sufficiently generally useful that it 
> > would be nice for the function to be in the CRT bits.  
> > 
> > 
> > I should be in Redmond some time in October, so maybe we can discuss it 
> > with some of the VS team then?
> Can the blocks part of this patch be split out?  It's basically a totally 
> different bugfix.
Split into D50436.



Comment at: lib/CodeGen/CGObjCGNU.cpp:915
+return name;
+  }
   /// The GCC ABI superclass message lookup function.  Takes a pointer to a

rjmccall wrote:
> Can this section-names cleanup also just be in a separate patch?
This is difficult to extract, because it's mostly needed for the COFF part 
where we need to modify the section names.  For ELF, it was fine to keep them 
as separate `const char*`s



Comment at: lib/CodeGen/CGObjCGNU.cpp:2262
 llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
+  if (CGM.getContext().getTargetInfo().getTriple().isWindowsMSVCEnvironment())
+return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);

rjmccall wrote:
> I think this is the third different way that you test for Windows in this 
> patch. :) Is there a reason why this is just testing for MSVC and the others 
> are testing for PE/COFF or for Windows generally?
For the EH logic, we are using DWARF exceptions if we are targeting a Windows 
environment that uses DWARF EH and SEH-based exceptions if we are targeting a 
Windows environment that uses MSVC-compatible SEH.

The section code is specific to PE/COFF, where we don't get to use some of the 
ELF tricks.

The blocks code is specific to Windows, because it relates to Windows run-time 
linking.  Hypothetically, a PE/COFF platform could provide dynamic relocations 
that would eliminate the need for that check.

It's possible that some of the PE/COFF vs Windows distinctions are wrong.  For 
example, UEFI images are PE/COFF binaries and if anyone wanted to use blocks in 
a UEFI firmware image then they may find that they need the Windows code path 
(but I do not have a good way of testing this, so restricted it to Windows 
initially).  Similarly, some of the section initialisation code in CGObjCGNU 
may actually be Windows-only, but it's probably a good starting point for 
anyone who actually wants to use Objective-C in UEFI firmware (though the final 
destination for such people is likely to involve padded cells). 



Comment at: lib/CodeGen/CGObjCGNU.cpp:3817
+  if (isRethrow && CGF.CGM.getTarget().getTriple().isWindowsMSVCEnvironment()) 
{
+CGF.EmitRuntimeCallOrInvoke(ExceptionReThrowFn).setDoesNotReturn();
+  }

rjmccall wrote:
> You're sure here that the static information aligns with the dynamic?
I'm not sure I understand this question.



Comment at: lib/CodeGen/CGObjCRuntime.cpp:125
 llvm::Constant *TypeInfo;
+unsigned Flags;
   };

rjmccall wrote:
> Please add some sort of comment about the meaning and source of these flags.
These are not well documented anywhere, including in the Clang Microsoft C++ 
ABI code that I read to see why exceptions weren't working, but I've added a 
small comment that explains why they exist.  I have no idea where the values 
come from though.


Repository:
  rC Clang

https://reviews.llvm.org/D50144



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


Re: r339128 - [objc-gnustep] Don't emit .guess ivar offset vars.

2018-08-08 Thread Hans Wennborg via cfe-commits
Merged to 7.0 in r339233.

On Tue, Aug 7, 2018 at 2:02 PM, David Chisnall via cfe-commits
 wrote:
> Author: theraven
> Date: Tue Aug  7 05:02:46 2018
> New Revision: 339128
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339128&view=rev
> Log:
> [objc-gnustep] Don't emit .guess ivar offset vars.
>
> These were intended to allow non-fragile and fragile ABI code to be
> mixed, as long as the fragile classes were higher up the hierarchy than
> the non-fragile ones.  Unfortunately:
>
>  - No one actually wants to do this.
>  - Recent versions of Linux's run-time linker break it.
>
> Modified:
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=339128&r1=339127&r2=339128&view=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue Aug  7 05:02:46 2018
> @@ -3812,40 +3812,10 @@ llvm::GlobalVariable *CGObjCGNU::ObjCIva
>// is.  This allows code compiled with non-fragile ivars to work correctly
>// when linked against code which isn't (most of the time).
>llvm::GlobalVariable *IvarOffsetPointer = TheModule.getNamedGlobal(Name);
> -  if (!IvarOffsetPointer) {
> -// This will cause a run-time crash if we accidentally use it.  A value 
> of
> -// 0 would seem more sensible, but will silently overwrite the isa 
> pointer
> -// causing a great deal of confusion.
> -uint64_t Offset = -1;
> -// We can't call ComputeIvarBaseOffset() here if we have the
> -// implementation, because it will create an invalid ASTRecordLayout 
> object
> -// that we are then stuck with forever, so we only initialize the ivar
> -// offset variable with a guess if we only have the interface.  The
> -// initializer will be reset later anyway, when we are generating the 
> class
> -// description.
> -if (!CGM.getContext().getObjCImplementation(
> -  const_cast(ID)))
> -  Offset = ComputeIvarBaseOffset(CGM, ID, Ivar);
> -
> -llvm::ConstantInt *OffsetGuess = llvm::ConstantInt::get(Int32Ty, Offset,
> - /*isSigned*/true);
> -// Don't emit the guess in non-PIC code because the linker will not be 
> able
> -// to replace it with the real version for a library.  In non-PIC code 
> you
> -// must compile with the fragile ABI if you want to use ivars from a
> -// GCC-compiled class.
> -if (CGM.getLangOpts().PICLevel) {
> -  llvm::GlobalVariable *IvarOffsetGV = new 
> llvm::GlobalVariable(TheModule,
> -Int32Ty, false,
> -llvm::GlobalValue::PrivateLinkage, OffsetGuess, Name+".guess");
> -  IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
> -IvarOffsetGV->getType(), false, 
> llvm::GlobalValue::LinkOnceAnyLinkage,
> -IvarOffsetGV, Name);
> -} else {
> -  IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
> -  llvm::Type::getInt32PtrTy(VMContext), false,
> -  llvm::GlobalValue::ExternalLinkage, nullptr, Name);
> -}
> -  }
> +  if (!IvarOffsetPointer)
> +IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
> +llvm::Type::getInt32PtrTy(VMContext), false,
> +llvm::GlobalValue::ExternalLinkage, nullptr, Name);
>return IvarOffsetPointer;
>  }
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50415: [clangd] extend the publishDiagnostics response to send back fixits to the client directly as well (if requested)

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

+1 Sam's suggestion of configuring this during initial LSP handshake, rather 
than as a command-line flag.
We could put it into `ClientCapabilities` or into `initializationOptions`. The 
latter has type 'any' in LSP, so it seems to be most in-line with the protocol 
to put clangd-specific config options there, but not opposed to having this in 
other structs as an extension either.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50415



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


[PATCH] D50438: [clangd] Sort GoToDefinition results.

2018-08-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: arphaman, mgrang, jkorous, MaskRay, ioeric.

GoToDefinition returns all declaration results (implicit/explicit) that are
in the same location, and the results are returned in arbitrary order.

Some LSP clients defaultly take the first result as the final result, which
might present a bad result (implicit decl) to users.

this patch ranks the result based on whether the declarations are
referenced explicitly/implicitly. We put explicit declarations first.

This also improve the "hover" (which just take the first result) feature
in some cases.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50438

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

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -311,6 +311,50 @@
   }
 }
 
+TEST(GoToDefinition, Rank) {
+  auto T = Annotations(R"cpp(
+struct $foo1[[Foo]] {
+  $foo2[[Foo]]();
+  $foo3[[Foo]](Foo&&);
+  $foo4[[Foo]](const char*);
+};
+
+Foo $f[[f]]();
+
+void $g[[g]](Foo foo);
+
+void call() {
+  const char* $str[[str]] = "123";
+  Foo a = $1^str;
+  Foo b = Foo($2^str);
+  Foo c = $3^f();
+  $4^g($5^f());
+  g($6^str);
+}
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  EXPECT_THAT(findDefinitions(AST, T.point("1")),
+  ElementsAre(RangeIs(T.range("str")), RangeIs(T.range("foo4";
+  EXPECT_THAT(findDefinitions(AST, T.point("2")),
+  ElementsAre(RangeIs(T.range("str";
+  EXPECT_THAT(findDefinitions(AST, T.point("3")),
+  ElementsAre(RangeIs(T.range("f")), RangeIs(T.range("foo3";
+  EXPECT_THAT(findDefinitions(AST, T.point("4")),
+  ElementsAre(RangeIs(T.range("g";
+  EXPECT_THAT(findDefinitions(AST, T.point("5")),
+  ElementsAre(RangeIs(T.range("f")),
+  RangeIs(T.range("foo3";
+
+  auto DefinitionAtPoint6 = findDefinitions(AST, T.point("6"));
+  EXPECT_EQ(3ul, DefinitionAtPoint6.size());
+  EXPECT_THAT(
+  DefinitionAtPoint6,
+  HasSubsequence(RangeIs(T.range("str")), RangeIs(T.range("foo4";
+  EXPECT_THAT(
+  DefinitionAtPoint6,
+  HasSubsequence(RangeIs(T.range("str")), RangeIs(T.range("foo3";
+}
+
 TEST(GoToDefinition, RelPathsInCompileCommand) {
   Annotations SourceAnnotations(R"cpp(
 int [[foo]];
Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -68,10 +68,24 @@
   const MacroInfo *Info;
 };
 
+struct DeclInfo {
+  const Decl *D;
+  // Indicates the declaration is referenced by an explicit AST node.
+  bool IsReferencedExplicitly;
+  bool operator==(const DeclInfo &L) {
+return std::tie(D, IsReferencedExplicitly) ==
+   std::tie(L.D, L.IsReferencedExplicitly);
+  }
+};
+
 /// Finds declarations locations that a given source location refers to.
 class DeclarationAndMacrosFinder : public index::IndexDataConsumer {
-  std::vector Decls;
   std::vector MacroInfos;
+  // The value of the map indicates whether the declaration has been referenced
+  // explicitly in the code.
+  // True means the declaration is explicitly referenced at least once; false
+  // otherwise
+  llvm::DenseMap Decls;
   const SourceLocation &SearchedLocation;
   const ASTContext &AST;
   Preprocessor &PP;
@@ -82,13 +96,17 @@
  ASTContext &AST, Preprocessor &PP)
   : SearchedLocation(SearchedLocation), AST(AST), PP(PP) {}
 
-  std::vector takeDecls() {
-// Don't keep the same declaration multiple times.
-// This can happen when nodes in the AST are visited twice.
-std::sort(Decls.begin(), Decls.end());
-auto Last = std::unique(Decls.begin(), Decls.end());
-Decls.erase(Last, Decls.end());
-return std::move(Decls);
+  std::vector getDecls() const {
+std::vector Result;
+for (auto It : Decls)
+  Result.push_back({It.first, It.second});
+
+// Sort results. Declarations being referenced explicitly come first.
+std::sort(Result.begin(), Result.end(),
+  [](const DeclInfo &L, const DeclInfo &R) {
+return L.IsReferencedExplicitly > R.IsReferencedExplicitly;
+  });
+return Result;
   }
 
   std::vector takeMacroInfos() {
@@ -106,21 +124,45 @@
 return std::move(MacroInfos);
   }
 
+  void insertDecl(const Decl *D, bool IsExplicitReferenced) {
+auto It = Decls.find(D);
+if (It != Decls.end())
+  It->getSecond() |= IsExplicitReferenced;
+else
+  Decls.insert({D, IsExplicitReferenced});
+  }
+
   bool
   handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
   ArrayRef Relations,
   SourceLocation Loc,
   index::IndexDataConsumer::ASTNodeInf

[PATCH] D50154: [clangd] capitalize diagnostic messages

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

In https://reviews.llvm.org/D50154#1191002, @dblaikie wrote:

> What's the motivation for clangd to differ from clang here?


The presentation of diagnostics to the users is different between clang and 
clangd:

- clang diagnostics are always prefixed with the file, location and severity of 
the diagnostic, e.g. `main.cpp:1:2: error: expected '}'`
- In LSP clients (VSCode in particular), the diagnostic message is the first 
thing the user sees and it looks a little nicer (subjectively) if the first 
letter is capitalized.

See the screenshots from VSCode on how diagnostics are presented:
F6901986: image.png  F6901990: image.png 



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50154



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


[PATCH] D48436: [analyzer][UninitializedObjectChecker] Fixed a false negative by no longer filtering out certain constructor calls

2018-08-08 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

In https://reviews.llvm.org/D48436#1191458, @NoQ wrote:

> Ok, let's commit this and see how to fix it later.


Thanks! ^-^

> I still think it's more important to come up with clear rules of who is 
> responsible for initializing fields than making sure our warnings are 
> properly grouped together.

I'll admit that the main reason why I only added a TODO about this issue and 
delayed it for later is that I'm a little unsure about some details myself. I 
spent serious effort on some ideas, which I later realized didn't work out too 
well, so I'm looking for a solid solution on some issues (like base class 
handling) that is both efficient to a degree and makes sense from a user 
standpoint before writing a doc file of some sort.

Currently, I'm working on refactoring the checker (which is why I didn't update 
some of my patches, as those changes would become obsolete), which will greatly 
increase readability and reliability (let's face it, the code about pointer 
chasing is a spaghetti).

>> [...]ideally we wouldn't like to have a warning for an object (`t`) and a 
>> separate warning for it's field (`t.bptr.x`)[...]
> 
> I don't quite understand this. How would the first warning look like? What 
> would it warn about?

I'm afraid I explained my thoughts very poorly. I have a much better grasp on 
this issue now, and I have a very good solution in testing. I'll upload a new 
diff during the week that will clarify this.
Here's what I meant with the correct code:

  struct DynTBase {
// This is the line I meant but forgot to add.
int x; // expected-note{{uninitialized field 'this->bptr->x'}}
  };
  struct DynTDerived : DynTBase {
// TODO: we'd expect the note: {{uninitialized field 'this->bptr->y'}}
int y; // no-note
  };
  
  struct DynamicTypeTest {
DynTBase *bptr;

int i = 0;
  
DynamicTypeTest(DynTBase *bptr) : bptr(bptr) {} // expected-warning{{1 
uninitialized field}}
  };
  
  void f() {
DynTDerived d;
DynamicTypeTest t(&d);
  };

In this one, note that the constructed object `t` has two uninitialized fields, 
`t.bptr->x` and `t.bptr->y`. Currently, my checker misses the second one. The 
first one gets picked up rather easily, but then the problem arises about how 
do we deal with `t.bptr->y`. I proposed two ideas:

1. In `isNonUnionUninit`, obtain the dynamic type of the object we're 
analyzing. This is the easier solution, as the current implementation 
explicitly checks each base. This would result in one warning with a note for 
each field.
2. Change `willObjectBeAnalyzedLater` so that bases are analyzed on their own, 
and eliminate checking bases explicitly 
(https://reviews.llvm.org/D45532#inline-415396). The checker won't run when `d` 
is constructed, because it has a default ctor, but will run after `t`. How do 
we catch `t.bptr->y?` If we don't analyze bases explicitly, we can't just 
obtain the dynamic type in `isNonUnionUninit`, because then we'd miss 
`t.bptr->x`. If we decide that for fields we will explicitly check bases, that 
would be inconsistent, because in `t`s case we would analyze base classes on 
their own (if it had any), but we wouldn't for its fields. As you said,

> With that i guess you'll still have to deep-scan fields and bases, which 
> prevents us from simplifying our code.

I really just wanted to emphasize the point that I need more time to figure 
this out.




Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:669-671
+  Optional CurrentObject = getObjectVal(Ctor, 
Context);
+  if (!CurrentObject)
+return false;

NoQ wrote:
> All uses of `getObjectVal` so far are followed by retrieving the parent 
> region from the `LazyCompoundVal`. Why do you need to obtain the 
> `LazyCompoundVal` in the first place, i.e. do the second `getSVal` "for 
> '*this'" in `getObjectVal`? Why not just operate over the this-region on the 
> current Store? I think there isn't even a guarantee that these two regions 
> are the same. Like, in this case they probably will be the same, but we 
> shouldn't rely on that.
Fair point, that part was written when I knew very little about how these 
things worked. I'll add a TODO to get that fixed before commiting.


https://reviews.llvm.org/D48436



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


Re: r339210 - PR38286: Don't crash when attempting to define a constructor for an

2018-08-08 Thread Hans Wennborg via cfe-commits
Merged in r339236. Thanks!

On Wed, Aug 8, 2018 at 2:46 AM, Richard Smith  wrote:
> Would be good to get this into the Clang 7 release.
>
> On Tue, 7 Aug 2018 at 17:43, Richard Smith via cfe-commits
>  wrote:
>>
>> Author: rsmith
>> Date: Tue Aug  7 17:42:42 2018
>> New Revision: 339210
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=339210&view=rev
>> Log:
>> PR38286: Don't crash when attempting to define a constructor for an
>> incomplete class template.
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> cfe/trunk/test/SemaCXX/constructor.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=339210&r1=339209&r2=339210&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Aug  7 17:42:42 2018
>> @@ -113,9 +113,15 @@ ParsedType Sema::getConstructorName(Iden
>>break;
>>  }
>>}
>> -  if (!InjectedClassName && CurClass->isInvalidDecl())
>> +  if (!InjectedClassName) {
>> +if (!CurClass->isInvalidDecl()) {
>> +  // FIXME: RequireCompleteDeclContext doesn't check dependent
>> contexts
>> +  // properly. Work around it here for now.
>> +  Diag(SS.getLastQualifierNameLoc(),
>> +   diag::err_incomplete_nested_name_spec) << CurClass <<
>> SS.getRange();
>> +}
>>  return ParsedType();
>> -  assert(InjectedClassName && "couldn't find injected class name");
>> +  }
>>
>>QualType T = Context.getTypeDeclType(InjectedClassName);
>>DiagnoseUseOfDecl(InjectedClassName, NameLoc);
>>
>> Modified: cfe/trunk/test/SemaCXX/constructor.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor.cpp?rev=339210&r1=339209&r2=339210&view=diff
>>
>> ==
>> --- cfe/trunk/test/SemaCXX/constructor.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/constructor.cpp Tue Aug  7 17:42:42 2018
>> @@ -86,3 +86,14 @@ A::S::operator int() { return 1; }
>>
>>  A::S::~S() {}
>>
>> +namespace PR38286 {
>> +  // FIXME: It'd be nice to give more consistent diagnostics for these
>> cases
>> +  // (but they're all failing for somewhat different reasons...).
>> +  template struct A;
>> +  template A::A() {} // expected-error {{incomplete type
>> 'A' named in nested name specifier}}
>> +  /*FIXME: needed to recover properly from previous error*/;
>> +  template struct B;
>> +  template void B::f() {} // expected-error {{out-of-line
>> definition of 'f' from class 'B'}}
>> +  template struct C;
>> +  template C::~C() {} // expected-error {{no type named
>> 'C' in 'C'}}
>> +}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48436: [analyzer][UninitializedObjectChecker] Fixed a false negative by no longer filtering out certain constructor calls

2018-08-08 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 159687.
Szelethus added a comment.

Added a TODO.


https://reviews.llvm.org/D48436

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -1040,13 +1040,12 @@
 // While a singleton would make more sense as a static variable, that would zero
 // initialize all of its fields, hence the not too practical implementation.
 struct Singleton {
-  // TODO: we'd expect the note: {{uninitialized field 'this->i'}}
-  int i; // no-note
+  int i; // expected-note{{uninitialized field 'this->i'}}
+  int dontGetFilteredByNonPedanticMode = 0;
 
   Singleton() {
 assert(!isInstantiated);
-// TODO: we'd expect the warning: {{1 uninitialized field}}
-isInstantiated = true; // no-warning
+isInstantiated = true; // expected-warning{{1 uninitialized field}}
   }
 
   ~Singleton() {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -225,12 +225,16 @@
 
 /// Returns the object that was constructed by CtorDecl, or None if that isn't
 /// possible.
+// TODO: Refactor this function so that it returns the constructed object's
+// region.
 static Optional
 getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context);
 
-/// Checks whether the constructor under checking is called by another
-/// constructor.
-static bool isCalledByConstructor(const CheckerContext &Context);
+/// Checks whether the object constructed by \p Ctor will be analyzed later
+/// (e.g. if the object is a field of another object, in which case we'd check
+/// it multiple times).
+static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
+   CheckerContext &Context);
 
 /// Returns whether FD can be (transitively) dereferenced to a void pointer type
 /// (void*, void**, ...). The type of the region behind a void pointer isn't
@@ -273,7 +277,7 @@
 return;
 
   // This avoids essentially the same error being reported multiple times.
-  if (isCalledByConstructor(Context))
+  if (willObjectBeAnalyzedLater(CtorDecl, Context))
 return;
 
   Optional Object = getObjectVal(CtorDecl, Context);
@@ -433,8 +437,8 @@
   }
 
   // Checking bases.
-  // FIXME: As of now, because of `isCalledByConstructor`, objects whose type
-  // is a descendant of another type will emit warnings for uninitalized
+  // FIXME: As of now, because of `willObjectBeAnalyzedLater`, objects whose
+  // type is a descendant of another type will emit warnings for uninitalized
   // inherited members.
   // This is not the only way to analyze bases of an object -- if we didn't
   // filter them out, and didn't analyze the bases, this checker would run for
@@ -661,18 +665,32 @@
   return Object.getAs();
 }
 
-// TODO: We should also check that if the constructor was called by another
-// constructor, whether those two are in any relation to one another. In it's
-// current state, this introduces some false negatives.
-static bool isCalledByConstructor(const CheckerContext &Context) {
-  const LocationContext *LC = Context.getLocationContext()->getParent();
+static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
+   CheckerContext &Context) {
 
-  while (LC) {
-if (isa(LC->getDecl()))
-  return true;
+  Optional CurrentObject = getObjectVal(Ctor, Context);
+  if (!CurrentObject)
+return false;
+
+  const LocationContext *LC = Context.getLocationContext();
+  while ((LC = LC->getParent())) {
+
+// If \p Ctor was called by another constructor.
+const auto *OtherCtor = dyn_cast(LC->getDecl());
+if (!OtherCtor)
+  continue;
 
-LC = LC->getParent();
+Optional OtherObject =
+getObjectVal(OtherCtor, Context);
+if (!OtherObject)
+  continue;
+
+// If the CurrentObject is a subregion of OtherObject, it will be analyzed
+// during the analysis of OtherObject.
+if (CurrentObject->getRegion()->isSubRegionOf(OtherObject->getRegion()))
+  return true;
   }
+
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339237 - [analyzer][UninitializedObjectChecker] Fixed a false negative by no longer filtering out certain constructor calls

2018-08-08 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug  8 05:23:02 2018
New Revision: 339237

URL: http://llvm.org/viewvc/llvm-project?rev=339237&view=rev
Log:
[analyzer][UninitializedObjectChecker] Fixed a false negative by no longer 
filtering out certain constructor calls

As of now, all constructor calls are ignored that are being called
by a constructor. The point of this was not to analyze the fields
of an object, so an uninitialized field wouldn't be reported
multiple times.

This however introduced false negatives when the two constructors
were in no relation to one another -- see the test file for a neat
example for this with singletons. This patch aims so fix this issue.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp?rev=339237&r1=339236&r2=339237&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp Wed 
Aug  8 05:23:02 2018
@@ -225,12 +225,16 @@ static llvm::ImmutableListFactory
 getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context);
 
-/// Checks whether the constructor under checking is called by another
-/// constructor.
-static bool isCalledByConstructor(const CheckerContext &Context);
+/// Checks whether the object constructed by \p Ctor will be analyzed later
+/// (e.g. if the object is a field of another object, in which case we'd check
+/// it multiple times).
+static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
+   CheckerContext &Context);
 
 /// Returns whether FD can be (transitively) dereferenced to a void pointer 
type
 /// (void*, void**, ...). The type of the region behind a void pointer isn't
@@ -273,7 +277,7 @@ void UninitializedObjectChecker::checkEn
 return;
 
   // This avoids essentially the same error being reported multiple times.
-  if (isCalledByConstructor(Context))
+  if (willObjectBeAnalyzedLater(CtorDecl, Context))
 return;
 
   Optional Object = getObjectVal(CtorDecl, Context);
@@ -433,8 +437,8 @@ bool FindUninitializedFields::isNonUnion
   }
 
   // Checking bases.
-  // FIXME: As of now, because of `isCalledByConstructor`, objects whose type
-  // is a descendant of another type will emit warnings for uninitalized
+  // FIXME: As of now, because of `willObjectBeAnalyzedLater`, objects whose
+  // type is a descendant of another type will emit warnings for uninitalized
   // inherited members.
   // This is not the only way to analyze bases of an object -- if we didn't
   // filter them out, and didn't analyze the bases, this checker would run for
@@ -661,18 +665,32 @@ getObjectVal(const CXXConstructorDecl *C
   return Object.getAs();
 }
 
-// TODO: We should also check that if the constructor was called by another
-// constructor, whether those two are in any relation to one another. In it's
-// current state, this introduces some false negatives.
-static bool isCalledByConstructor(const CheckerContext &Context) {
-  const LocationContext *LC = Context.getLocationContext()->getParent();
+static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
+   CheckerContext &Context) {
 
-  while (LC) {
-if (isa(LC->getDecl()))
-  return true;
+  Optional CurrentObject = getObjectVal(Ctor, 
Context);
+  if (!CurrentObject)
+return false;
+
+  const LocationContext *LC = Context.getLocationContext();
+  while ((LC = LC->getParent())) {
+
+// If \p Ctor was called by another constructor.
+const auto *OtherCtor = dyn_cast(LC->getDecl());
+if (!OtherCtor)
+  continue;
 
-LC = LC->getParent();
+Optional OtherObject =
+getObjectVal(OtherCtor, Context);
+if (!OtherObject)
+  continue;
+
+// If the CurrentObject is a subregion of OtherObject, it will be analyzed
+// during the analysis of OtherObject.
+if (CurrentObject->getRegion()->isSubRegionOf(OtherObject->getRegion()))
+  return true;
   }
+
   return false;
 }
 

Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp?rev=339237&r1=339236&r2=339237&view=diff
==
--- cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp (original)
+++ cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp Wed Aug  8 05:23:02 
2018
@@ -1040,13 +1040,12 @@ void assert(int b) {
 // While a singleton would make more sense as a static variable, that would 
zero
 // initialize all of its fields, he

[PATCH] D48436: [analyzer][UninitializedObjectChecker] Fixed a false negative by no longer filtering out certain constructor calls

2018-08-08 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339237: [analyzer][UninitializedObjectChecker] Fixed a false 
negative by no longer… (authored by Szelethus, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D48436

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -225,12 +225,16 @@
 
 /// Returns the object that was constructed by CtorDecl, or None if that isn't
 /// possible.
+// TODO: Refactor this function so that it returns the constructed object's
+// region.
 static Optional
 getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context);
 
-/// Checks whether the constructor under checking is called by another
-/// constructor.
-static bool isCalledByConstructor(const CheckerContext &Context);
+/// Checks whether the object constructed by \p Ctor will be analyzed later
+/// (e.g. if the object is a field of another object, in which case we'd check
+/// it multiple times).
+static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
+   CheckerContext &Context);
 
 /// Returns whether FD can be (transitively) dereferenced to a void pointer type
 /// (void*, void**, ...). The type of the region behind a void pointer isn't
@@ -273,7 +277,7 @@
 return;
 
   // This avoids essentially the same error being reported multiple times.
-  if (isCalledByConstructor(Context))
+  if (willObjectBeAnalyzedLater(CtorDecl, Context))
 return;
 
   Optional Object = getObjectVal(CtorDecl, Context);
@@ -433,8 +437,8 @@
   }
 
   // Checking bases.
-  // FIXME: As of now, because of `isCalledByConstructor`, objects whose type
-  // is a descendant of another type will emit warnings for uninitalized
+  // FIXME: As of now, because of `willObjectBeAnalyzedLater`, objects whose
+  // type is a descendant of another type will emit warnings for uninitalized
   // inherited members.
   // This is not the only way to analyze bases of an object -- if we didn't
   // filter them out, and didn't analyze the bases, this checker would run for
@@ -661,18 +665,32 @@
   return Object.getAs();
 }
 
-// TODO: We should also check that if the constructor was called by another
-// constructor, whether those two are in any relation to one another. In it's
-// current state, this introduces some false negatives.
-static bool isCalledByConstructor(const CheckerContext &Context) {
-  const LocationContext *LC = Context.getLocationContext()->getParent();
+static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
+   CheckerContext &Context) {
 
-  while (LC) {
-if (isa(LC->getDecl()))
-  return true;
+  Optional CurrentObject = getObjectVal(Ctor, Context);
+  if (!CurrentObject)
+return false;
+
+  const LocationContext *LC = Context.getLocationContext();
+  while ((LC = LC->getParent())) {
+
+// If \p Ctor was called by another constructor.
+const auto *OtherCtor = dyn_cast(LC->getDecl());
+if (!OtherCtor)
+  continue;
 
-LC = LC->getParent();
+Optional OtherObject =
+getObjectVal(OtherCtor, Context);
+if (!OtherObject)
+  continue;
+
+// If the CurrentObject is a subregion of OtherObject, it will be analyzed
+// during the analysis of OtherObject.
+if (CurrentObject->getRegion()->isSubRegionOf(OtherObject->getRegion()))
+  return true;
   }
+
   return false;
 }
 
Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -1040,13 +1040,12 @@
 // While a singleton would make more sense as a static variable, that would zero
 // initialize all of its fields, hence the not too practical implementation.
 struct Singleton {
-  // TODO: we'd expect the note: {{uninitialized field 'this->i'}}
-  int i; // no-note
+  int i; // expected-note{{uninitialized field 'this->i'}}
+  int dontGetFilteredByNonPedanticMode = 0;
 
   Singleton() {
 assert(!isInstantiated);
-// TODO: we'd expect the warning: {{1 uninitialized field}}
-isInstantiated = true; // no-warning
+isInstantiated = true; // expected-warning{{1 uninitialized field}}
   }
 
   ~Singleton() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49199: [analyzer][UninitializedObjectChecker] Pointer/reference objects are dereferenced according to dynamic type

2018-08-08 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

Thanks! I plan on revisiting how heap allocated regions are handled in the 
future.


https://reviews.llvm.org/D49199



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


[PATCH] D50439: [Tooling] Switch JSONCompilationDatabase to use JSON parser.

2018-08-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: ioeric, klimek.
Herald added a subscriber: cfe-commits.

Rather than hold all the JSON source in memory, as well as the YAML structures
needed to index into it, we parse eagerly into CompileCommand structures, which
simplifies the implementation a lot.

Possibly at the cost of performance/memory usage, need to measure that.
(I'd expect that eager parsing with string deduplication would be fine at least)


Repository:
  rC Clang

https://reviews.llvm.org/D50439

Files:
  include/clang/Tooling/JSONCompilationDatabase.h
  lib/Tooling/JSONCompilationDatabase.cpp
  test/Index/skip-parsed-bodies/compile_commands.json
  test/Index/skip-parsed-bodies/compile_commands.test
  test/Index/skip-parsed-bodies/lit.local.cfg

Index: test/Index/skip-parsed-bodies/lit.local.cfg
===
--- test/Index/skip-parsed-bodies/lit.local.cfg
+++ test/Index/skip-parsed-bodies/lit.local.cfg
@@ -1 +1 @@
-config.suffixes = ['.json']
+config.suffixes = ['.test']
Index: test/Index/skip-parsed-bodies/compile_commands.test
===
--- test/Index/skip-parsed-bodies/compile_commands.test
+++ test/Index/skip-parsed-bodies/compile_commands.test
@@ -1,22 +1,4 @@
-[
-{
-  "directory": ".",
-  "command": "/usr/bin/clang++ -fsyntax-only -fno-ms-compatibility -fno-delayed-template-parsing t1.cpp",
-  "file": "t1.cpp"
-},
-{
-  "directory": ".",
-  "command": "/usr/bin/clang++ -fsyntax-only -fno-ms-compatibility -fno-delayed-template-parsing t2.cpp -DBLAH",
-  "file": "t2.cpp"
-},
-{
-  "directory": ".",
-  "command": "/usr/bin/clang++ -fsyntax-only -fno-ms-compatibility -fno-delayed-template-parsing t3.cpp -DBLAH",
-  "file": "t2.cpp"
-}
-]
-
-// RUN: c-index-test -index-compile-db %s | FileCheck %s
+// RUN: c-index-test -index-compile-db %S/compile_commands.json | FileCheck %s
 
 // CHECK:  [startedTranslationUnit]
 // CHECK-NEXT: [enteredMainFile]: t1.cpp
@@ -71,3 +53,4 @@
 // CHECK:  [indexDeclaration]: kind: function | name: imp_foo | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
 // CHECK-NOT:  [indexEntityReference]: kind: variable | name: some_val |
 // CHECK-NOT:  [diagnostic]: {{.*}} undeclared identifier
+
Index: test/Index/skip-parsed-bodies/compile_commands.json
===
--- test/Index/skip-parsed-bodies/compile_commands.json
+++ test/Index/skip-parsed-bodies/compile_commands.json
@@ -15,59 +15,3 @@
   "file": "t2.cpp"
 }
 ]
-
-// RUN: c-index-test -index-compile-db %s | FileCheck %s
-
-// CHECK:  [startedTranslationUnit]
-// CHECK-NEXT: [enteredMainFile]: t1.cpp
-// CHECK:  [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:9:27
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 1 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS |
-// CHECK-NEXT: [indexEntityReference]: kind: c++-class | name: C |
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:15:5
-// CHECK-NEXT: [indexDeclaration]: kind: function | name: foo1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:19:5
-// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val1'
-// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val2'
-// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val3'
-
-// CHECK-NEXT: [startedTranslationUnit]
-// CHECK-NEXT: [enteredMainFile]: t2.cpp
-// CHECK:  [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isContainer: skipped
-// CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS |
-// CHECK-NEXT: [indexEntityReference]: kind: c++-class | name: C |
-// CHECK-NEXT: [indexDeclaration]: kind: function | name: foo1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
-// CHECK-NEXT: [ppIncludedFile]: ./pragma_once.h
-// CHECK-NEXT: [indexDeclaration]: kind: function | n

[PATCH] D50439: [Tooling] Switch JSONCompilationDatabase to use JSON parser.

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

(just updating description)


Repository:
  rC Clang

https://reviews.llvm.org/D50439

Files:
  include/clang/Tooling/JSONCompilationDatabase.h
  lib/Tooling/JSONCompilationDatabase.cpp
  test/Index/skip-parsed-bodies/compile_commands.json
  test/Index/skip-parsed-bodies/compile_commands.test
  test/Index/skip-parsed-bodies/lit.local.cfg

Index: test/Index/skip-parsed-bodies/lit.local.cfg
===
--- test/Index/skip-parsed-bodies/lit.local.cfg
+++ test/Index/skip-parsed-bodies/lit.local.cfg
@@ -1 +1 @@
-config.suffixes = ['.json']
+config.suffixes = ['.test']
Index: test/Index/skip-parsed-bodies/compile_commands.test
===
--- test/Index/skip-parsed-bodies/compile_commands.test
+++ test/Index/skip-parsed-bodies/compile_commands.test
@@ -1,22 +1,4 @@
-[
-{
-  "directory": ".",
-  "command": "/usr/bin/clang++ -fsyntax-only -fno-ms-compatibility -fno-delayed-template-parsing t1.cpp",
-  "file": "t1.cpp"
-},
-{
-  "directory": ".",
-  "command": "/usr/bin/clang++ -fsyntax-only -fno-ms-compatibility -fno-delayed-template-parsing t2.cpp -DBLAH",
-  "file": "t2.cpp"
-},
-{
-  "directory": ".",
-  "command": "/usr/bin/clang++ -fsyntax-only -fno-ms-compatibility -fno-delayed-template-parsing t3.cpp -DBLAH",
-  "file": "t2.cpp"
-}
-]
-
-// RUN: c-index-test -index-compile-db %s | FileCheck %s
+// RUN: c-index-test -index-compile-db %S/compile_commands.json | FileCheck %s
 
 // CHECK:  [startedTranslationUnit]
 // CHECK-NEXT: [enteredMainFile]: t1.cpp
@@ -71,3 +53,4 @@
 // CHECK:  [indexDeclaration]: kind: function | name: imp_foo | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
 // CHECK-NOT:  [indexEntityReference]: kind: variable | name: some_val |
 // CHECK-NOT:  [diagnostic]: {{.*}} undeclared identifier
+
Index: test/Index/skip-parsed-bodies/compile_commands.json
===
--- test/Index/skip-parsed-bodies/compile_commands.json
+++ test/Index/skip-parsed-bodies/compile_commands.json
@@ -15,59 +15,3 @@
   "file": "t2.cpp"
 }
 ]
-
-// RUN: c-index-test -index-compile-db %s | FileCheck %s
-
-// CHECK:  [startedTranslationUnit]
-// CHECK-NEXT: [enteredMainFile]: t1.cpp
-// CHECK:  [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:9:27
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 1 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS |
-// CHECK-NEXT: [indexEntityReference]: kind: c++-class | name: C |
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:15:5
-// CHECK-NEXT: [indexDeclaration]: kind: function | name: foo1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:19:5
-// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val1'
-// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val2'
-// CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val3'
-
-// CHECK-NEXT: [startedTranslationUnit]
-// CHECK-NEXT: [enteredMainFile]: t2.cpp
-// CHECK:  [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
-// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isContainer: skipped
-// CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS |
-// CHECK-NEXT: [indexEntityReference]: kind: c++-class | name: C |
-// CHECK-NEXT: [indexDeclaration]: kind: function | name: foo1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
-// CHECK-NEXT: [ppIncludedFile]: ./pragma_once.h
-// CHECK-NEXT: [indexDeclaration]: kind: function | name: foo2 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:25:5
-// CHECK:  [indexDeclaration]: kind: c++-instance-method | name: tsmeth | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {

[PATCH] D50389: [clang-tidy] new check for Abseil

2018-08-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for contributing to clang-tidy!




Comment at: docs/clang-tidy/checks/abseil-duration-division.rst:3
+  
+abseil-duration-division
+

This is a nice document. Does abseil have similar thing in its official 
guideline/practice? If yes, we can add the link in the document as well.



Comment at: test/clang-tidy/abseil-duration-division.cpp:21
+#define CHECK(x) (x)
+
+void Positives() {

JonasToth wrote:
> What happens on this snippet:
> 
> ```
> const auto SomeVal = 1.0 + d / d; // auto deduces to a double?! so it should 
> be considered as relevant
> const auto AnotherVal = 1 + d / d; // Here everything will be an integer, so 
> interesting as well
> ```
> 
+1, we need to add more test cases.


https://reviews.llvm.org/D50389



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


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

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



> Ok, so you are already talking about performance. I think we should fix 
> correctness first, in particular the compiler shouldn't complain whenever 
> `` is included.

This patch is concerned with calling device functions when you're on the 
device. The correctness issues you mention are orthogonal to this and should be 
handled by another patch. I don't think this patch should be held up any longer.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D50439: [Tooling] Switch JSONCompilationDatabase to use JSON parser.

2018-08-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall planned changes to this revision.
sammccall added a comment.

Nevermind, this is like 5x slower to load the chromium CDB. probably because of 
all the little non-arena allocations.
I'll profile and fix it when I get bored again.


Repository:
  rC Clang

https://reviews.llvm.org/D50439



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


[PATCH] D50376: AMDGPU: Fix enabling denormals by default on pre-VI targets

2018-08-08 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl accepted this revision.
kzhuravl added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D50376



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


[PATCH] D50443: [clang] Store code completion token range in preprocessor.This change is to support a new fature in clangd, tests will be send toclang-tools-extra with that change.

2018-08-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric.

Repository:
  rC Clang

https://reviews.llvm.org/D50443

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/Preprocessor.cpp


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -868,6 +868,7 @@
   if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) {
 // Remember the identifier before code completion token.
 setCodeCompletionIdentifierInfo(Result.getIdentifierInfo());
+setCodeCompletionTokenRange(Result.getLocation(), Result.getEndLoc());
 // Set IdenfitierInfo to null to avoid confusing code that handles both
 // identifiers and completion tokens.
 Result.setIdentifierInfo(nullptr);
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -310,6 +310,9 @@
   /// on the stem that is to be code completed.
   IdentifierInfo *CodeCompletionII = nullptr;
 
+  /// Range for the code completion taken.
+  SourceRange CodeCompletionTokenRange;
+
   /// The directory that the main file should be considered to occupy,
   /// if it does not correspond to a real file (as happens when building a
   /// module).
@@ -1131,6 +1134,16 @@
 CodeCompletionII = Filter;
   }
 
+  /// Set the code completion token range for detecting replacement range later
+  /// on.
+  void setCodeCompletionTokenRange(const SourceLocation start,
+   const SourceLocation end) {
+CodeCompletionTokenRange = {start, end};
+  }
+  SourceRange getCodeCompletionTokenRange() const {
+return CodeCompletionTokenRange;
+  }
+
   /// Get the code completion token for filtering purposes.
   StringRef getCodeCompletionFilter() {
 if (CodeCompletionII)


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -868,6 +868,7 @@
   if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) {
 // Remember the identifier before code completion token.
 setCodeCompletionIdentifierInfo(Result.getIdentifierInfo());
+setCodeCompletionTokenRange(Result.getLocation(), Result.getEndLoc());
 // Set IdenfitierInfo to null to avoid confusing code that handles both
 // identifiers and completion tokens.
 Result.setIdentifierInfo(nullptr);
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -310,6 +310,9 @@
   /// on the stem that is to be code completed.
   IdentifierInfo *CodeCompletionII = nullptr;
 
+  /// Range for the code completion taken.
+  SourceRange CodeCompletionTokenRange;
+
   /// The directory that the main file should be considered to occupy,
   /// if it does not correspond to a real file (as happens when building a
   /// module).
@@ -1131,6 +1134,16 @@
 CodeCompletionII = Filter;
   }
 
+  /// Set the code completion token range for detecting replacement range later
+  /// on.
+  void setCodeCompletionTokenRange(const SourceLocation start,
+   const SourceLocation end) {
+CodeCompletionTokenRange = {start, end};
+  }
+  SourceRange getCodeCompletionTokenRange() const {
+return CodeCompletionTokenRange;
+  }
+
   /// Get the code completion token for filtering purposes.
   StringRef getCodeCompletionFilter() {
 if (CodeCompletionII)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50444: Fix structural inequivalency of forward EnumDecl

2018-08-08 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a_sidorin, r.stahl, xazax.hun.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

Currently we consider one forward declared RecordDecl and another with a
definition equal. We have to do the same in case of enums.


Repository:
  rC Clang

https://reviews.llvm.org/D50444

Files:
  lib/AST/ASTStructuralEquivalence.cpp
  unittests/AST/StructuralEquivalenceTest.cpp


Index: unittests/AST/StructuralEquivalenceTest.cpp
===
--- unittests/AST/StructuralEquivalenceTest.cpp
+++ unittests/AST/StructuralEquivalenceTest.cpp
@@ -618,6 +618,31 @@
   EXPECT_FALSE(testStructuralMatch(R0, R1));
 }
 
+TEST_F(StructuralEquivalenceRecordTest,
+FwdDeclRecordShouldBeEqualWithFwdDeclRecord) {
+  auto t = makeNamedDecls("class foo;", "class foo;", Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceRecordTest,
+   FwdDeclRecordShouldBeEqualWithRecordWhichHasDefinition) {
+  auto t =
+  makeNamedDecls("class foo;", "class foo { int A; };", Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceRecordTest,
+   RecordShouldBeEqualWithRecordWhichHasDefinition) {
+  auto t = makeNamedDecls("class foo { int A; };", "class foo { int A; };",
+  Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceRecordTest, RecordsWithDifferentBody) {
+  auto t = makeNamedDecls("class foo { int B; };", "class foo { int A; };",
+  Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
 
 TEST_F(StructuralEquivalenceTest, CompareSameDeclWithMultiple) {
   auto t = makeNamedDecls(
@@ -627,5 +652,33 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+struct StructuralEquivalenceEnumTest : StructuralEquivalenceTest {};
+
+TEST_F(StructuralEquivalenceEnumTest, FwdDeclEnumShouldBeEqualWithFwdDeclEnum) 
{
+  auto t = makeNamedDecls("enum class foo;", "enum class foo;", Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumTest,
+   FwdDeclEnumShouldBeEqualWithEnumWhichHasDefinition) {
+  auto t =
+  makeNamedDecls("enum class foo;", "enum class foo { A };", Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumTest,
+   EnumShouldBeEqualWithEnumWhichHasDefinition) {
+  auto t = makeNamedDecls("enum class foo { A };", "enum class foo { A };",
+  Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumTest, EnumsWithDifferentBody) {
+  auto t = makeNamedDecls("enum class foo { B };", "enum class foo { A };",
+  Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTStructuralEquivalence.cpp
===
--- lib/AST/ASTStructuralEquivalence.cpp
+++ lib/AST/ASTStructuralEquivalence.cpp
@@ -1178,6 +1178,14 @@
 /// Determine structural equivalence of two enums.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  EnumDecl *D1, EnumDecl *D2) {
+
+  // Compare the definitions of these two eunums. If either or both are
+  // incomplete (i.e. forward declared), we assume that they are equivalent.
+  D1 = D1->getDefinition();
+  D2 = D2->getDefinition();
+  if (!D1 || !D2)
+return true;
+
   EnumDecl::enumerator_iterator EC2 = D2->enumerator_begin(),
 EC2End = D2->enumerator_end();
   for (EnumDecl::enumerator_iterator EC1 = D1->enumerator_begin(),


Index: unittests/AST/StructuralEquivalenceTest.cpp
===
--- unittests/AST/StructuralEquivalenceTest.cpp
+++ unittests/AST/StructuralEquivalenceTest.cpp
@@ -618,6 +618,31 @@
   EXPECT_FALSE(testStructuralMatch(R0, R1));
 }
 
+TEST_F(StructuralEquivalenceRecordTest,
+FwdDeclRecordShouldBeEqualWithFwdDeclRecord) {
+  auto t = makeNamedDecls("class foo;", "class foo;", Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceRecordTest,
+   FwdDeclRecordShouldBeEqualWithRecordWhichHasDefinition) {
+  auto t =
+  makeNamedDecls("class foo;", "class foo { int A; };", Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceRecordTest,
+   RecordShouldBeEqualWithRecordWhichHasDefinition) {
+  auto t = makeNamedDecls("class foo { int A; };", "class foo { int A; };",
+  Lang_CXX11);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceRecordTest, RecordsWithDifferentBody) {
+  auto t = makeNamedDecls("class foo { int B; };", "class foo { int A; };",
+  Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
 
 TEST_F(StructuralEquivalenceTest, Co

[PATCH] D49199: [analyzer][UninitializedObjectChecker] Pointer/reference objects are dereferenced according to dynamic type

2018-08-08 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 159699.
Szelethus added a comment.

Rebased to latest trunk.


https://reviews.llvm.org/D49199

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object-inheritance.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp

Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -196,7 +196,7 @@
 
 struct CyclicPointerTest {
   int *ptr;
-  CyclicPointerTest() : ptr(reinterpret_cast(&ptr)) {}
+  CyclicPointerTest() : ptr(reinterpret_cast(&ptr)) {}
 };
 
 void fCyclicPointerTest() {
@@ -285,13 +285,62 @@
   void *vptr; // no-crash
 
   CyclicVoidPointerTest() : vptr(&vptr) {}
-
 };
 
 void fCyclicVoidPointerTest() {
   CyclicVoidPointerTest();
 }
 
+struct IntDynTypedVoidPointerTest1 {
+  void *vptr; // expected-note{{uninitialized pointee 'this->vptr'}}
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  IntDynTypedVoidPointerTest1(void *vptr) : vptr(vptr) {} // expected-warning{{1 uninitialized field}}
+};
+
+void fIntDynTypedVoidPointerTest1() {
+  int a;
+  IntDynTypedVoidPointerTest1 tmp(&a);
+}
+
+struct RecordDynTypedVoidPointerTest {
+  struct RecordType {
+int x; // expected-note{{uninitialized field 'this->vptr->x'}}
+int y; // expected-note{{uninitialized field 'this->vptr->y'}}
+  };
+
+  void *vptr;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  RecordDynTypedVoidPointerTest(void *vptr) : vptr(vptr) {} // expected-warning{{2 uninitialized fields}}
+};
+
+void fRecordDynTypedVoidPointerTest() {
+  RecordDynTypedVoidPointerTest::RecordType a;
+  RecordDynTypedVoidPointerTest tmp(&a);
+}
+
+struct NestedNonVoidDynTypedVoidPointerTest {
+  struct RecordType {
+int x;  // expected-note{{uninitialized field 'this->vptr->x'}}
+int y;  // expected-note{{uninitialized field 'this->vptr->y'}}
+void *vptr; // expected-note{{uninitialized pointee 'this->vptr->vptr'}}
+  };
+
+  void *vptr;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  NestedNonVoidDynTypedVoidPointerTest(void *vptr, void *c) : vptr(vptr) {
+static_cast(vptr)->vptr = c; // expected-warning{{3 uninitialized fields}}
+  }
+};
+
+void fNestedNonVoidDynTypedVoidPointerTest() {
+  NestedNonVoidDynTypedVoidPointerTest::RecordType a;
+  char c;
+  NestedNonVoidDynTypedVoidPointerTest tmp(&a, &c);
+}
+
 //===--===//
 // Multipointer tests.
 //===--===//
Index: test/Analysis/cxx-uninitialized-object-inheritance.cpp
===
--- test/Analysis/cxx-uninitialized-object-inheritance.cpp
+++ test/Analysis/cxx-uninitialized-object-inheritance.cpp
@@ -776,3 +776,26 @@
 void fVirtualDiamondInheritanceTest3() {
   VirtualDiamondInheritanceTest3();
 }
+
+//===--===//
+// Dynamic type test.
+//===--===//
+
+struct DynTBase {};
+struct DynTDerived : DynTBase {
+  // TODO: we'd expect the note: {{uninitialized field 'this->x'}}
+  int x; // no-note
+};
+
+struct DynamicTypeTest {
+  DynTBase *bptr;
+  int i = 0;
+
+  // TODO: we'd expect the warning: {{1 uninitialized field}}
+  DynamicTypeTest(DynTBase *bptr) : bptr(bptr) {} // no-warning
+};
+
+void f() {
+  DynTDerived d;
+  DynamicTypeTest t(&d);
+};
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -44,7 +44,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include 
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
 
 using namespace clang;
 using namespace clang::ento;
@@ -236,10 +236,10 @@
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
CheckerContext &Context);
 
-/// Returns whether FD can be (transitively) dereferenced to a void pointer type
+/// Returns whether T can be (transitively) dereferenced to a void pointer type
 /// (void*, void**, ...). The type of the region behind a void pointer isn't
 /// known, and thus FD can not be analyzed.
-static bool isVoidPointer(const FieldDecl *FD);
+static bool isVoidPointer(QualType T);
 
 /// Returns true if T is a primitive type. We defined this type so that for
 /// objects that we'd only like analyze as much as checking whether their
@@ -483,7 +483,7 @@
 
   SVal V = State->getSVal(FR);
 
-  if (V.isUnknown() || V.

[PATCH] D50443: [clang] Store code completion token range in preprocessor.This change is to support a new fature in clangd, tests will be send toclang-tools-extra with that change.

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

Maybe split the commit message into multiple lines?

I suggest we wait for clangd changes to be reviewed and land them together, so 
that we have the tests and usages of this code.
Other than that LG




Comment at: include/clang/Lex/Preprocessor.h:1139
+  /// on.
+  void setCodeCompletionTokenRange(const SourceLocation start,
+   const SourceLocation end) {

NIT: parameters are are `UpperCamelCase` in LLVM naming conventions


Repository:
  rC Clang

https://reviews.llvm.org/D50443



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


[PATCH] D50446: [clangd] Record the currently active file in context for codeCompletion and findDefinitions.

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

This allows implementations like different symbol indexes to know what
the current active file is. For example, some customized index implementation
might decide to only return results for some files.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50446

Files:
  clangd/ClangdServer.cpp
  clangd/Context.cpp
  clangd/Context.h


Index: clangd/Context.h
===
--- clangd/Context.h
+++ clangd/Context.h
@@ -217,6 +217,11 @@
   WithContext Restore;
 };
 
+// The active file in a clangd request (e.g. file in which code completion or
+// go-to-definition is triggered). This is not always set and has to be set in
+// individual requests.
+extern const clang::clangd::Key kActiveFile;
+
 } // namespace clangd
 } // namespace clang
 
Index: clangd/Context.cpp
===
--- clangd/Context.cpp
+++ clangd/Context.cpp
@@ -32,5 +32,7 @@
   return Replacement;
 }
 
+const clang::clangd::Key kActiveFile;
+
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -159,6 +159,7 @@
 
 auto PreambleData = IP->Preamble;
 
+WithContextValue WithFileName(kActiveFile, File);
 // FIXME(ibiryukov): even if Preamble is non-null, we may want to check
 // both the old and the new version in case only one of them matches.
 CodeCompleteResult Result = clangd::codeComplete(
@@ -297,10 +298,13 @@
 
 void ClangdServer::findDefinitions(PathRef File, Position Pos,
Callback> CB) {
-  auto Action = [Pos, this](Callback> CB,
-llvm::Expected InpAST) {
+  std::string ActiveFile = File;
+  auto Action = [Pos, ActiveFile, this](Callback> CB,
+llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
+
+WithContextValue WithFileName(kActiveFile, ActiveFile);
 CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 


Index: clangd/Context.h
===
--- clangd/Context.h
+++ clangd/Context.h
@@ -217,6 +217,11 @@
   WithContext Restore;
 };
 
+// The active file in a clangd request (e.g. file in which code completion or
+// go-to-definition is triggered). This is not always set and has to be set in
+// individual requests.
+extern const clang::clangd::Key kActiveFile;
+
 } // namespace clangd
 } // namespace clang
 
Index: clangd/Context.cpp
===
--- clangd/Context.cpp
+++ clangd/Context.cpp
@@ -32,5 +32,7 @@
   return Replacement;
 }
 
+const clang::clangd::Key kActiveFile;
+
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -159,6 +159,7 @@
 
 auto PreambleData = IP->Preamble;
 
+WithContextValue WithFileName(kActiveFile, File);
 // FIXME(ibiryukov): even if Preamble is non-null, we may want to check
 // both the old and the new version in case only one of them matches.
 CodeCompleteResult Result = clangd::codeComplete(
@@ -297,10 +298,13 @@
 
 void ClangdServer::findDefinitions(PathRef File, Position Pos,
Callback> CB) {
-  auto Action = [Pos, this](Callback> CB,
-llvm::Expected InpAST) {
+  std::string ActiveFile = File;
+  auto Action = [Pos, ActiveFile, this](Callback> CB,
+llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
+
+WithContextValue WithFileName(kActiveFile, ActiveFile);
 CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339240 - [analyzer][UninitializedObjectChecker] Pointer/reference objects are dereferenced according to dynamic type

2018-08-08 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug  8 06:18:53 2018
New Revision: 339240

URL: http://llvm.org/viewvc/llvm-project?rev=339240&view=rev
Log:
[analyzer][UninitializedObjectChecker] Pointer/reference objects are 
dereferenced according to dynamic type

This patch fixed an issue where the dynamic type of pointer/reference
object was known by the analyzer, but wasn't obtained in the checker,
which resulted in false negatives. This should also increase reliability
of the checker, as derefencing is always done now according to the
dynamic type (even if that happens to be the same as the static type).

Special thanks to Artem Degrachev for setting me on the right track.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp?rev=339240&r1=339239&r2=339240&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp Wed 
Aug  8 06:18:53 2018
@@ -44,7 +44,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include 
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
 
 using namespace clang;
 using namespace clang::ento;
@@ -236,10 +236,10 @@ getObjectVal(const CXXConstructorDecl *C
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
CheckerContext &Context);
 
-/// Returns whether FD can be (transitively) dereferenced to a void pointer 
type
+/// Returns whether T can be (transitively) dereferenced to a void pointer type
 /// (void*, void**, ...). The type of the region behind a void pointer isn't
 /// known, and thus FD can not be analyzed.
-static bool isVoidPointer(const FieldDecl *FD);
+static bool isVoidPointer(QualType T);
 
 /// Returns true if T is a primitive type. We defined this type so that for
 /// objects that we'd only like analyze as much as checking whether their
@@ -483,7 +483,7 @@ bool FindUninitializedFields::isPointerO
 
   SVal V = State->getSVal(FR);
 
-  if (V.isUnknown() || V.isZeroConstant()) {
+  if (V.isUnknown() || V.getAs()) {
 IsAnyFieldInitialized = true;
 return false;
   }
@@ -497,48 +497,70 @@ bool FindUninitializedFields::isPointerO
 return false;
   }
 
-  const FieldDecl *FD = FR->getDecl();
+  assert(V.getAs() &&
+ "At this point V must be loc::MemRegionVal!");
+  auto L = V.castAs();
+
+  // We can't reason about symbolic regions, assume its initialized.
+  // Note that this also avoids a potential infinite recursion, because
+  // constructors for list-like classes are checked without being called, and
+  // the Static Analyzer will construct a symbolic region for Node *next; or
+  // similar code snippets.
+  if (L.getRegion()->getSymbolicBase()) {
+IsAnyFieldInitialized = true;
+return false;
+  }
 
-  // TODO: The dynamic type of a void pointer may be retrieved with
-  // `getDynamicTypeInfo`.
-  if (isVoidPointer(FD)) {
+  DynamicTypeInfo DynTInfo = getDynamicTypeInfo(State, L.getRegion());
+  if (!DynTInfo.isValid()) {
 IsAnyFieldInitialized = true;
 return false;
   }
 
-  assert(V.getAs() && "V should be Loc at this point!");
+  QualType DynT = DynTInfo.getType();
+
+  if (isVoidPointer(DynT)) {
+IsAnyFieldInitialized = true;
+return false;
+  }
 
   // At this point the pointer itself is initialized and points to a valid
   // location, we'll now check the pointee.
-  SVal DerefdV = State->getSVal(V.castAs());
-
-  // TODO: Dereferencing should be done according to the dynamic type.
-  while (Optional L = DerefdV.getAs()) {
-DerefdV = State->getSVal(*L);
-  }
+  SVal DerefdV = State->getSVal(V.castAs(), DynT);
 
-  // If V is a pointer pointing to a record type.
-  if (Optional RecordV =
-  DerefdV.getAs()) {
+  // If DerefdV is still a pointer value, we'll dereference it again (e.g.:
+  // int** -> int*).
+  while (auto Tmp = DerefdV.getAs()) {
+if (Tmp->getRegion()->getSymbolicBase()) {
+  IsAnyFieldInitialized = true;
+  return false;
+}
 
-const TypedValueRegion *R = RecordV->getRegion();
+DynTInfo = getDynamicTypeInfo(State, Tmp->getRegion());
+if (!DynTInfo.isValid()) {
+  IsAnyFieldInitialized = true;
+  return false;
+}
 
-// We can't reason about symbolic regions, assume its initialized.
-// Note that this also avoids a potential infinite recursion, because
-// constructors f

[PATCH] D49199: [analyzer][UninitializedObjectChecker] Pointer/reference objects are dereferenced according to dynamic type

2018-08-08 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339240: [analyzer][UninitializedObjectChecker] 
Pointer/reference objects are… (authored by Szelethus, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D49199

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object-inheritance.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp

Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -44,7 +44,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include 
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
 
 using namespace clang;
 using namespace clang::ento;
@@ -236,10 +236,10 @@
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
CheckerContext &Context);
 
-/// Returns whether FD can be (transitively) dereferenced to a void pointer type
+/// Returns whether T can be (transitively) dereferenced to a void pointer type
 /// (void*, void**, ...). The type of the region behind a void pointer isn't
 /// known, and thus FD can not be analyzed.
-static bool isVoidPointer(const FieldDecl *FD);
+static bool isVoidPointer(QualType T);
 
 /// Returns true if T is a primitive type. We defined this type so that for
 /// objects that we'd only like analyze as much as checking whether their
@@ -483,7 +483,7 @@
 
   SVal V = State->getSVal(FR);
 
-  if (V.isUnknown() || V.isZeroConstant()) {
+  if (V.isUnknown() || V.getAs()) {
 IsAnyFieldInitialized = true;
 return false;
   }
@@ -497,66 +497,90 @@
 return false;
   }
 
-  const FieldDecl *FD = FR->getDecl();
+  assert(V.getAs() &&
+ "At this point V must be loc::MemRegionVal!");
+  auto L = V.castAs();
+
+  // We can't reason about symbolic regions, assume its initialized.
+  // Note that this also avoids a potential infinite recursion, because
+  // constructors for list-like classes are checked without being called, and
+  // the Static Analyzer will construct a symbolic region for Node *next; or
+  // similar code snippets.
+  if (L.getRegion()->getSymbolicBase()) {
+IsAnyFieldInitialized = true;
+return false;
+  }
 
-  // TODO: The dynamic type of a void pointer may be retrieved with
-  // `getDynamicTypeInfo`.
-  if (isVoidPointer(FD)) {
+  DynamicTypeInfo DynTInfo = getDynamicTypeInfo(State, L.getRegion());
+  if (!DynTInfo.isValid()) {
 IsAnyFieldInitialized = true;
 return false;
   }
 
-  assert(V.getAs() && "V should be Loc at this point!");
+  QualType DynT = DynTInfo.getType();
+
+  if (isVoidPointer(DynT)) {
+IsAnyFieldInitialized = true;
+return false;
+  }
 
   // At this point the pointer itself is initialized and points to a valid
   // location, we'll now check the pointee.
-  SVal DerefdV = State->getSVal(V.castAs());
-
-  // TODO: Dereferencing should be done according to the dynamic type.
-  while (Optional L = DerefdV.getAs()) {
-DerefdV = State->getSVal(*L);
-  }
+  SVal DerefdV = State->getSVal(V.castAs(), DynT);
 
-  // If V is a pointer pointing to a record type.
-  if (Optional RecordV =
-  DerefdV.getAs()) {
+  // If DerefdV is still a pointer value, we'll dereference it again (e.g.:
+  // int** -> int*).
+  while (auto Tmp = DerefdV.getAs()) {
+if (Tmp->getRegion()->getSymbolicBase()) {
+  IsAnyFieldInitialized = true;
+  return false;
+}
 
-const TypedValueRegion *R = RecordV->getRegion();
+DynTInfo = getDynamicTypeInfo(State, Tmp->getRegion());
+if (!DynTInfo.isValid()) {
+  IsAnyFieldInitialized = true;
+  return false;
+}
 
-// We can't reason about symbolic regions, assume its initialized.
-// Note that this also avoids a potential infinite recursion, because
-// constructors for list-like classes are checked without being called, and
-// the Static Analyzer will construct a symbolic region for Node *next; or
-// similar code snippets.
-if (R->getSymbolicBase()) {
+DynT = DynTInfo.getType();
+if (isVoidPointer(DynT)) {
   IsAnyFieldInitialized = true;
   return false;
 }
 
-const QualType T = R->getValueType();
+DerefdV = State->getSVal(*Tmp, DynT);
+  }
+
+  // If FR is a pointer pointing to a non-primitive type.
+  if (Optional RecordV =
+  DerefdV.getAs()) {
+
+const TypedValueRegion *R = RecordV->getRegion();
 
-if (T->isStructureOrClassType())
+if (DynT->getPointeeType()->isStructureOrClassType())
   return isNonUnionUninit(R, {LocalChain, FR});
 
-if (T->isUnionType()) {
+if (DynT->getPointeeType()->isUnionType()) {
   if (isUnionUn

[PATCH] D50443: [clang] Store code completion token range in preprocessor.

2018-08-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 159703.
kadircet marked an inline comment as done.
kadircet added a comment.

- Resolve discussions.


Repository:
  rC Clang

https://reviews.llvm.org/D50443

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/Preprocessor.cpp


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -868,6 +868,7 @@
   if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) {
 // Remember the identifier before code completion token.
 setCodeCompletionIdentifierInfo(Result.getIdentifierInfo());
+setCodeCompletionTokenRange(Result.getLocation(), Result.getEndLoc());
 // Set IdenfitierInfo to null to avoid confusing code that handles both
 // identifiers and completion tokens.
 Result.setIdentifierInfo(nullptr);
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -310,6 +310,9 @@
   /// on the stem that is to be code completed.
   IdentifierInfo *CodeCompletionII = nullptr;
 
+  /// Range for the code completion taken.
+  SourceRange CodeCompletionTokenRange;
+
   /// The directory that the main file should be considered to occupy,
   /// if it does not correspond to a real file (as happens when building a
   /// module).
@@ -1131,6 +1134,16 @@
 CodeCompletionII = Filter;
   }
 
+  /// Set the code completion token range for detecting replacement range later
+  /// on.
+  void setCodeCompletionTokenRange(const SourceLocation Start,
+   const SourceLocation End) {
+CodeCompletionTokenRange = {Start, End};
+  }
+  SourceRange getCodeCompletionTokenRange() const {
+return CodeCompletionTokenRange;
+  }
+
   /// Get the code completion token for filtering purposes.
   StringRef getCodeCompletionFilter() {
 if (CodeCompletionII)


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -868,6 +868,7 @@
   if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) {
 // Remember the identifier before code completion token.
 setCodeCompletionIdentifierInfo(Result.getIdentifierInfo());
+setCodeCompletionTokenRange(Result.getLocation(), Result.getEndLoc());
 // Set IdenfitierInfo to null to avoid confusing code that handles both
 // identifiers and completion tokens.
 Result.setIdentifierInfo(nullptr);
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -310,6 +310,9 @@
   /// on the stem that is to be code completed.
   IdentifierInfo *CodeCompletionII = nullptr;
 
+  /// Range for the code completion taken.
+  SourceRange CodeCompletionTokenRange;
+
   /// The directory that the main file should be considered to occupy,
   /// if it does not correspond to a real file (as happens when building a
   /// module).
@@ -1131,6 +1134,16 @@
 CodeCompletionII = Filter;
   }
 
+  /// Set the code completion token range for detecting replacement range later
+  /// on.
+  void setCodeCompletionTokenRange(const SourceLocation Start,
+   const SourceLocation End) {
+CodeCompletionTokenRange = {Start, End};
+  }
+  SourceRange getCodeCompletionTokenRange() const {
+return CodeCompletionTokenRange;
+  }
+
   /// Get the code completion token for filtering purposes.
   StringRef getCodeCompletionFilter() {
 if (CodeCompletionII)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50168: [Builtins] Implement __builtin_clrsb to be compatible with gcc

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

About the bit hacking: I don't think clang should be in the optimization 
business. We should be able to take the most obvious/simple representation for 
this builtin and reduce it as needed (either in instcombine or the backend). So 
it would be better to use the version with the subtract rather than shift/or. 
That version corresponds more directly to the code in APInt::getMinSignedBits()?




Comment at: include/clang/Basic/Builtins.def:416
 BUILTIN(__builtin_popcountll, "iULLi", "nc")
+BUILTIN(__builtin_clrsb  , "ii"  , "nc")
+BUILTIN(__builtin_clrsbl , "iLi" , "nc")

Is is intentional that clang doesn't document the behavior of the builtins that 
it copies from gcc? I'd think logic descriptions for all of these would be 
handy, but especially for less common ones like 'clrsb'.


https://reviews.llvm.org/D50168



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


r339244 - [analyzer] Fix a typo in `RegionStore.txt`.

2018-08-08 Thread Henry Wong via cfe-commits
Author: henrywong
Date: Wed Aug  8 06:37:28 2018
New Revision: 339244

URL: http://llvm.org/viewvc/llvm-project?rev=339244&view=rev
Log:
[analyzer] Fix a typo in `RegionStore.txt`.

Summary: The typo of the description for default bindings can be confusing.

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ, george.karpenkov

Subscribers: xazax.hun, szepet, a.sidorin, mikhail.ramalho, cfe-commits, MTC

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

Modified:
cfe/trunk/docs/analyzer/RegionStore.txt

Modified: cfe/trunk/docs/analyzer/RegionStore.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/analyzer/RegionStore.txt?rev=339244&r1=339243&r2=339244&view=diff
==
--- cfe/trunk/docs/analyzer/RegionStore.txt (original)
+++ cfe/trunk/docs/analyzer/RegionStore.txt Wed Aug  8 06:37:28 2018
@@ -118,7 +118,7 @@ sometimes zero, for static data, or "uni
   int manyInts[10];
   manyInts[1] = 42;   // Creates a Direct binding for manyInts[1].
   print(manyInts[1]); // Retrieves the Direct binding for manyInts[1];
-  print(manyInts[0]); // There is no Direct binding for manyInts[1].
+  print(manyInts[0]); // There is no Direct binding for manyInts[0].
   // Is there a Default binding for the entire array?
   // There is not, but it is a stack variable, so we use
   // "uninitialized" as the default value (and emit a
@@ -166,6 +166,6 @@ Here's a concrete example:
 return p2.x;// The binding for FieldRegion 'p2.x' is requested.
 // There is no Direct binding, so we look for a Default
 // binding to 'p2' and find the LCV.
-// Because it's an LCV, we look at our requested region
+// Because it's a LCV, we look at our requested region
 // and see that it's the '.x' field. We ask for the value
 // of 'p.x' within the snapshot, and get back 42.


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


[PATCH] D50382: [analyzer] Fix a typo in `RegionStore.txt`.

2018-08-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339244: [analyzer] Fix a typo in `RegionStore.txt`. 
(authored by henrywong, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D50382

Files:
  cfe/trunk/docs/analyzer/RegionStore.txt


Index: cfe/trunk/docs/analyzer/RegionStore.txt
===
--- cfe/trunk/docs/analyzer/RegionStore.txt
+++ cfe/trunk/docs/analyzer/RegionStore.txt
@@ -118,7 +118,7 @@
   int manyInts[10];
   manyInts[1] = 42;   // Creates a Direct binding for manyInts[1].
   print(manyInts[1]); // Retrieves the Direct binding for manyInts[1];
-  print(manyInts[0]); // There is no Direct binding for manyInts[1].
+  print(manyInts[0]); // There is no Direct binding for manyInts[0].
   // Is there a Default binding for the entire array?
   // There is not, but it is a stack variable, so we use
   // "uninitialized" as the default value (and emit a
@@ -166,6 +166,6 @@
 return p2.x;// The binding for FieldRegion 'p2.x' is requested.
 // There is no Direct binding, so we look for a Default
 // binding to 'p2' and find the LCV.
-// Because it's an LCV, we look at our requested region
+// Because it's a LCV, we look at our requested region
 // and see that it's the '.x' field. We ask for the value
 // of 'p.x' within the snapshot, and get back 42.


Index: cfe/trunk/docs/analyzer/RegionStore.txt
===
--- cfe/trunk/docs/analyzer/RegionStore.txt
+++ cfe/trunk/docs/analyzer/RegionStore.txt
@@ -118,7 +118,7 @@
   int manyInts[10];
   manyInts[1] = 42;   // Creates a Direct binding for manyInts[1].
   print(manyInts[1]); // Retrieves the Direct binding for manyInts[1];
-  print(manyInts[0]); // There is no Direct binding for manyInts[1].
+  print(manyInts[0]); // There is no Direct binding for manyInts[0].
   // Is there a Default binding for the entire array?
   // There is not, but it is a stack variable, so we use
   // "uninitialized" as the default value (and emit a
@@ -166,6 +166,6 @@
 return p2.x;// The binding for FieldRegion 'p2.x' is requested.
 // There is no Direct binding, so we look for a Default
 // binding to 'p2' and find the LCV.
-// Because it's an LCV, we look at our requested region
+// Because it's a LCV, we look at our requested region
 // and see that it's the '.x' field. We ask for the value
 // of 'p.x' within the snapshot, and get back 42.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-08-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D47849#1192134, @gtbercea wrote:

> This patch is concerned with calling device functions when you're on the 
> device. The correctness issues you mention are orthogonal to this and should 
> be handled by another patch. I don't think this patch should be held up any 
> longer.


I'm confused by now, could you please highlight the point that I'm missing?

IIRC you started to work on this to fix the problem with inline assembly (see 
https://reviews.llvm.org/D47849#1125019). AFAICS this patch fixes declarations 
of math functions but you still cannot include `math.h` which most "correct" 
codes do.

In https://reviews.llvm.org/D47849#1170670, @tra wrote:

> The rumors of "high performance" functions in the libdevice are somewhat 
> exaggerated , IMO. If you take a look at the IR in the libdevice of recent 
> CUDA version, you will see that a lot of the functions just call their llvm 
> counterpart. If it turns out that in some case llvm generates slower code 
> than what nvidia provides, I'm sure it will be possible to implement a 
> reasonably fast replacement.


So regarding performance it's not yet clear to me which cases actually benefit: 
Is there a particular function that is slow if LLVM's backend resolves the call 
vs. the wrapper script directly calls libdevice?
If I understand @tra's comment correctly, I think we should have clear evidence 
(ie a small "benchmark") that this patch actually improves performance.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: ilya-biryukov, alexfh.
Herald added a subscriber: xazax.hun.

The upstream change r336737 causes a regression issue in our internal
base codebase.

Adding an option to the check allowing us whitelist these classes.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447

Files:
  clang-tidy/performance/ForRangeCopyCheck.cpp
  clang-tidy/performance/ForRangeCopyCheck.h
  docs/clang-tidy/checks/performance-for-range-copy.rst
  test/clang-tidy/performance-for-range-copy.cpp


Index: test/clang-tidy/performance-for-range-copy.cpp
===
--- test/clang-tidy/performance-for-range-copy.cpp
+++ test/clang-tidy/performance-for-range-copy.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-for-range-copy %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s performance-for-range-copy %t 
-config="{CheckOptions: [{key: "performance-for-range-copy.WhitelistClasses", 
value: "WhitelistFoo"}]}" -- -std=c++11 -fno-delayed-template-parsing
 
 namespace std {
 
@@ -260,3 +260,11 @@
 bool result = ConstOperatorInvokee != Mutable();
   }
 }
+
+struct WhitelistFoo {
+  ~WhitelistFoo();
+};
+void IgnoreBlacklistedType() {
+  for (auto _ : View>()) {
+  }
+}
Index: docs/clang-tidy/checks/performance-for-range-copy.rst
===
--- docs/clang-tidy/checks/performance-for-range-copy.rst
+++ docs/clang-tidy/checks/performance-for-range-copy.rst
@@ -25,3 +25,8 @@
 
When non-zero, warns on any use of `auto` as the type of the range-based for
loop variable. Default is `0`.
+
+.. option:: WhitelistClasses
+
+   A semicolon-separated list of names of whitelist classes, which will be
+   ignored by the check. Default is empty.
Index: clang-tidy/performance/ForRangeCopyCheck.h
===
--- clang-tidy/performance/ForRangeCopyCheck.h
+++ clang-tidy/performance/ForRangeCopyCheck.h
@@ -40,6 +40,7 @@
ASTContext &Context);
 
   const bool WarnOnAllAutoCopies;
+  std::vector WhitelistClasses;
 };
 
 } // namespace performance
Index: clang-tidy/performance/ForRangeCopyCheck.cpp
===
--- clang-tidy/performance/ForRangeCopyCheck.cpp
+++ clang-tidy/performance/ForRangeCopyCheck.cpp
@@ -11,6 +11,7 @@
 #include "../utils/ExprMutationAnalyzer.h"
 #include "../utils/FixItHintUtils.h"
 #include "../utils/TypeTraits.h"
+#include "../utils/OptionsUtils.h"
 
 using namespace clang::ast_matchers;
 
@@ -20,18 +21,28 @@
 
 ForRangeCopyCheck::ForRangeCopyCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  WarnOnAllAutoCopies(Options.get("WarnOnAllAutoCopies", 0)) {}
+  WarnOnAllAutoCopies(Options.get("WarnOnAllAutoCopies", 0)),
+  WhitelistClasses(utils::options::parseStringList(
+  Options.get("WhitelistClasses", ""))) {}
 
 void ForRangeCopyCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnAllAutoCopies", WarnOnAllAutoCopies);
+  Options.store(Opts, "WhitelistClasses",
+utils::options::serializeStringList(WhitelistClasses));
 }
 
 void ForRangeCopyCheck::registerMatchers(MatchFinder *Finder) {
   // Match loop variables that are not references or pointers or are already
   // initialized through MaterializeTemporaryExpr which indicates a type
   // conversion.
+  auto WhitelistClassMatcher =
+  cxxRecordDecl(hasAnyName(SmallVector(
+  WhitelistClasses.begin(), WhitelistClasses.end(;
+  auto WhitelistType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(WhitelistClassMatcher)));
   auto LoopVar = varDecl(
-  hasType(hasCanonicalType(unless(anyOf(referenceType(), pointerType(),
+  hasType(hasCanonicalType(
+  unless(anyOf(referenceType(), pointerType(), WhitelistType,
   unless(hasInitializer(expr(hasDescendant(materializeTemporaryExpr());
   Finder->addMatcher(cxxForRangeStmt(hasLoopVariable(LoopVar.bind("loopVar")))
  .bind("forRange"),


Index: test/clang-tidy/performance-for-range-copy.cpp
===
--- test/clang-tidy/performance-for-range-copy.cpp
+++ test/clang-tidy/performance-for-range-copy.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-for-range-copy %t -- -- -std=c++11 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s performance-for-range-copy %t -config="{CheckOptions: [{key: "performance-for-range-copy.WhitelistClasses", value: "WhitelistFoo"}]}" -- -std=c++11 -fno-delayed-template-parsing
 
 namespace std {
 
@@ -260,3 +260,11 @@
 bool result = ConstOperatorInvokee != Mutable();
   }
 }
+
+struct WhitelistFoo {
+  ~WhitelistFoo();
+};
+void IgnoreBlacklistedType() {
+  for 

[PATCH] D50175: [AArch64][NFC] better matching of AArch64 target in aarch64-cpus.c tests

2018-08-08 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 added inline comments.



Comment at: test/Driver/aarch64-cpus.c:10
+// GENERIC: "-cc1"{{.*}} "-triple" "aarch64"{{.*}} "-target-cpu" "generic"
+// GENERIC-LE: "-cc1"{{.*}} "-triple" "aarch64--"{{.*}} "-target-cpu" "generic"
 

Why do these need new check prefixes? All of the RUN lines above are selecting 
little-endian, so I'd expect GENERIC and GENERIC-LE to be the same.


https://reviews.llvm.org/D50175



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


[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added subscribers: shuaiwang, JonasToth, lebedev.ri.
lebedev.ri added a comment.

Regression is very broad term. Is it a false-positive?
Perhaps it is better to address the issue in the ExprMutationAnalyzer itself?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D50414: [libunwind][include] Add SEH declarations to .

2018-08-08 Thread Charles Davis via Phabricator via cfe-commits
cdavis5x added a comment.

In https://reviews.llvm.org/D50414#1191834, @mstorsjo wrote:

> Should we maybe add the same declaration of `_GCC_specific_handler` to 
> clang's unwind.h? That would allow removing the forward declaration in 
> libcxxabi from https://reviews.llvm.org/D49638.


Probably. I believe it's present in GCC's ``, too.

> Do you plan on implementing these SEH specific bits in libunwind,

Already have. Patch forthcoming.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50414



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


[PATCH] D50448: [CGObjCGNU] Rename GetSelector helper method to fix -Woverloaded-virtual warning (PR38210)

2018-08-08 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added a reviewer: theraven.

As suggested by @theraven on PR38210, this patch fixes the gcc 
-Woverloaded-virtual warnings by renaming the extra CGObjCGNU::GetSelector 
method to CGObjCGNU::GetTypedSelector


Repository:
  rC Clang

https://reviews.llvm.org/D50448

Files:
  lib/CodeGen/CGObjCGNU.cpp


Index: lib/CodeGen/CGObjCGNU.cpp
===
--- lib/CodeGen/CGObjCGNU.cpp
+++ lib/CodeGen/CGObjCGNU.cpp
@@ -510,8 +510,8 @@
 
   /// Returns a selector with the specified type encoding.  An empty string is
   /// used to return an untyped selector (with the types field set to NULL).
-  virtual llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-   const std::string &TypeEncoding);
+  virtual llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding);
 
   /// Returns the name of ivar offset variables.  In the GNUstep v1 ABI, this
   /// contains the class and ivar names, in the v2 ABI this contains the type
@@ -1342,8 +1342,8 @@
   return Val;
 return llvm::ConstantExpr::getBitCast(Val, Ty);
   }
-  llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) override {
+  llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding) override {
 return GetConstantSelector(Sel, TypeEncoding);
   }
   llvm::Constant  *GetTypeString(llvm::StringRef TypeEncoding) {
@@ -2121,8 +2121,8 @@
   return Value;
 }
 
-llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) {
+llvm::Value *CGObjCGNU::GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+ const std::string &TypeEncoding) {
   SmallVectorImpl &Types = SelectorTable[Sel];
   llvm::GlobalAlias *SelValue = nullptr;
 
@@ -2155,13 +2155,13 @@
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel) {
-  return GetSelector(CGF, Sel, std::string());
+  return GetTypedSelector(CGF, Sel, std::string());
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF,
 const ObjCMethodDecl *Method) {
   std::string SelTypes = CGM.getContext().getObjCEncodingForMethodDecl(Method);
-  return GetSelector(CGF, Method->getSelector(), SelTypes);
+  return GetTypedSelector(CGF, Method->getSelector(), SelTypes);
 }
 
 llvm::Constant *CGObjCGNU::GetEHType(QualType T) {


Index: lib/CodeGen/CGObjCGNU.cpp
===
--- lib/CodeGen/CGObjCGNU.cpp
+++ lib/CodeGen/CGObjCGNU.cpp
@@ -510,8 +510,8 @@
 
   /// Returns a selector with the specified type encoding.  An empty string is
   /// used to return an untyped selector (with the types field set to NULL).
-  virtual llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-   const std::string &TypeEncoding);
+  virtual llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding);
 
   /// Returns the name of ivar offset variables.  In the GNUstep v1 ABI, this
   /// contains the class and ivar names, in the v2 ABI this contains the type
@@ -1342,8 +1342,8 @@
   return Val;
 return llvm::ConstantExpr::getBitCast(Val, Ty);
   }
-  llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) override {
+  llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding) override {
 return GetConstantSelector(Sel, TypeEncoding);
   }
   llvm::Constant  *GetTypeString(llvm::StringRef TypeEncoding) {
@@ -2121,8 +2121,8 @@
   return Value;
 }
 
-llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) {
+llvm::Value *CGObjCGNU::GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+ const std::string &TypeEncoding) {
   SmallVectorImpl &Types = SelectorTable[Sel];
   llvm::GlobalAlias *SelValue = nullptr;
 
@@ -2155,13 +2155,13 @@
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel) {
-  return GetSelector(CGF, Sel, std::string());
+  return GetTypedSelector(CGF, Sel, std::string());
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF,
 const ObjCMethodDecl *Method) {
   std::string SelTypes = CGM.getContext().getObjCEncodingForMethodDecl(Method);
-  return GetSelector(CGF, Method->getSelector(), SelTypes);
+  return GetTypedSelector(CGF, Method->getSelector(), SelTypes);
 }
 
 llvm::Constant *CGObjCGNU::GetEHType(QualType T) {
_

[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

If whitelisting works, thats fine. But I agree with @lebedev.ri that a 
contribution/improvement to the ExprMutAnalyzer is the better option. This is 
especially the case, because multiple checks (and maybe even some other parts 
then clang-tidy) will utilize this analysis.




Comment at: clang-tidy/performance/ForRangeCopyCheck.cpp:39
+  auto WhitelistClassMatcher =
+  cxxRecordDecl(hasAnyName(SmallVector(
+  WhitelistClasses.begin(), WhitelistClasses.end(;

I have seens this pattern now multiple times in various checks, we should have 
some utility wrapping the `hasAnyName(MyList)`. (Just in general, does not need 
to happen with this check)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D50446: [clangd] Record the currently active file in context for codeCompletion and findDefinitions.

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

Short summary of the offline discussion: I suggest adding this parameter into 
the corresponding requests of the index (FuzzyFindRequest, 
FindDefinitionsRequest) instead of stashing it in the context. Context has all 
the same problems as the global variables, so we should try to avoid using it 
where possible.
On the other hand, where this key is stored might not be terribly important if 
we don't have too many usages and remove it when we can workaround the 
limitations that we're currently facing.

In any case, we should add a comment that the active file should be avoided and 
will be removed.




Comment at: clangd/ClangdServer.cpp:162
 
+WithContextValue WithFileName(kActiveFile, File);
 // FIXME(ibiryukov): even if Preamble is non-null, we may want to check

If we want to set this value more consistently, maybe do it in 
TUScheduler::runWithPreamble/runWithAST? 
All interesting operations that work on files go through those, so it's easier 
to certify that the file is set correctly.



Comment at: clangd/Context.cpp:35
 
+const clang::clangd::Key kActiveFile;
+

Maybe move it somewhere else? E.g. to `Index.h`, since that's where it's 
supposed to be used to workaround current limitations?
`Context.h/cpp` is a general-purpose support library for the contexts, 
application-specific keys do not fit in well there.



Comment at: clangd/Context.cpp:35
 
+const clang::clangd::Key kActiveFile;
+

ilya-biryukov wrote:
> Maybe move it somewhere else? E.g. to `Index.h`, since that's where it's 
> supposed to be used to workaround current limitations?
> `Context.h/cpp` is a general-purpose support library for the contexts, 
> application-specific keys do not fit in well there.
Maybe use `std::string`? Contexts can easily be cloned/migrated between 
threads, so it's very easy to end up with pointers to dead strings here.



Comment at: clangd/Context.h:223
+// individual requests.
+extern const clang::clangd::Key kActiveFile;
+

Maybe choose a scarier name and add a comment that we're not gonna use it in 
the long-term?
Maybe also add a comment that this is only used in our index implementation to 
workaround the limitations of the current design? 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50446



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


[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/performance-for-range-copy.cpp:1
-// RUN: %check_clang_tidy %s performance-for-range-copy %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s performance-for-range-copy %t 
-config="{CheckOptions: [{key: "performance-for-range-copy.WhitelistClasses", 
value: "WhitelistFoo"}]}" -- -std=c++11 -fno-delayed-template-parsing
 

I would prefer a single file, that has the configuration and leave the standard 
test like it is.

with this, you can always track what is actually done by default and what is 
done with different conigurations + potential inconsistencies that might occur 
by bugs in the configured code.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D50448: [CGObjCGNU] Rename GetSelector helper method to fix -Woverloaded-virtual warning (PR38210)

2018-08-08 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Thanks, this warning is really annoying.


Repository:
  rC Clang

https://reviews.llvm.org/D50448



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


[PATCH] D50449: [clangd] Support textEdit in addition to insertText.

2018-08-08 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric.

Completion replies contains textEdits as well. Note that this change
relies on https://reviews.llvm.org/D50443.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50449

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/SourceCodeTests.cpp

Index: unittests/clangd/SourceCodeTests.cpp
===
--- unittests/clangd/SourceCodeTests.cpp
+++ unittests/clangd/SourceCodeTests.cpp
@@ -37,6 +37,14 @@
   return Pos;
 }
 
+Range range(const std::pair p1,
+const std::pair p2) {
+  Range range;
+  range.start = position(p1.first, p1.second);
+  range.end = position(p2.first, p2.second);
+  return range;
+}
+
 TEST(SourceCodeTests, PositionToOffset) {
   // line out of bounds
   EXPECT_THAT_EXPECTED(positionToOffset(File, position(-1, 2)), Failed());
@@ -119,6 +127,14 @@
   EXPECT_THAT(offsetToPosition(File, 30), Pos(2, 9)) << "out of bounds";
 }
 
+TEST(SourceCodeTests, IsRangeConsecutive) {
+  EXPECT_TRUE(IsRangeConsecutive(range({2, 2}, {2, 3}), range({2, 3}, {2, 4})));
+  EXPECT_FALSE(
+  IsRangeConsecutive(range({0, 2}, {0, 3}), range({2, 3}, {2, 4})));
+  EXPECT_FALSE(
+  IsRangeConsecutive(range({2, 2}, {2, 3}), range({2, 4}, {2, 5})));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -1438,6 +1438,82 @@
   }
 }
 
+TEST(CompletionTest, RenderWithFixItMerged) {
+  TextEdit FixIt;
+  FixIt.range.end.character = 5;
+  FixIt.newText = "->";
+
+  CodeCompletion C;
+  C.Name = "x";
+  C.RequiredQualifier = "Foo::";
+  C.FixIts = {FixIt};
+  C.textEdit.range.start.character = 5;
+
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+
+  auto R = C.render(Opts);
+  EXPECT_TRUE(R.textEdit);
+  EXPECT_EQ(R.textEdit->newText, "->Foo::x");
+  EXPECT_TRUE(R.additionalTextEdits.empty());
+}
+
+TEST(CompletionTest, RenderWithFixItNonMerged) {
+  TextEdit FixIt;
+  FixIt.range.end.character = 4;
+  FixIt.newText = "->";
+
+  CodeCompletion C;
+  C.Name = "x";
+  C.RequiredQualifier = "Foo::";
+  C.FixIts = {FixIt};
+  C.textEdit.range.start.character = 5;
+
+  CodeCompleteOptions Opts;
+  Opts.IncludeFixIts = true;
+
+  auto R = C.render(Opts);
+  EXPECT_TRUE(R.textEdit);
+  EXPECT_EQ(R.textEdit->newText, "Foo::x");
+  EXPECT_THAT(R.additionalTextEdits, UnorderedElementsAre(FixIt));
+}
+
+TEST(CompletionTest, CompletionTokenRange) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  constexpr const char *TestCodes[] = {
+  R"cpp(
+class Auxilary {
+ public:
+  void AuxFunction();
+};
+void f() {
+  Auxilary x;
+  x.[[Aux]]^;
+}
+  )cpp",
+  R"cpp(
+class Auxilary {
+ public:
+  void AuxFunction();
+};
+void f() {
+  Auxilary x;
+  x.[[]]^;
+}
+  )cpp"};
+  for (const auto &Text : TestCodes) {
+Annotations TestCode(Text);
+auto Results = completions(Server, TestCode.code(), TestCode.point());
+
+EXPECT_EQ(Results.Completions.size(), 1u);
+EXPECT_THAT(Results.Completions.front().textEdit.range, TestCode.range());
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/SourceCode.h
===
--- clangd/SourceCode.h
+++ clangd/SourceCode.h
@@ -69,6 +69,7 @@
 TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M,
 const LangOptions &L);
 
+bool IsRangeConsecutive(const Range &Left, const Range &Right);
 } // namespace clangd
 } // namespace clang
 #endif
Index: clangd/SourceCode.cpp
===
--- clangd/SourceCode.cpp
+++ clangd/SourceCode.cpp
@@ -208,5 +208,10 @@
   return Result;
 }
 
+bool IsRangeConsecutive(const Range &Left, const Range &Right) {
+  return Left.end.line == Right.start.line &&
+ Left.end.character == Right.start.character;
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/CodeComplete.h
===
--- clangd/CodeComplete.h
+++ clangd/CodeComplete.h
@@ -123,6 +123,8 @@
   /// converting '->' to '.' on member access.
   std::vector FixIts;
 
+  TextEdit textEdit;
+
   // Scores are used to rank completion items.
   struct Scores {
 // The score that items are ranked by.
Index: clangd/CodeComplete.cpp

[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang-tools-extra/clangd/index/MemIndex.h:45
   // Index is a set of symbols that are deduplicated by symbol IDs.
-  // FIXME: build smarter index structure.
   llvm::DenseMap Index;

I think this FIXME still applies here. This can probably go away when we 
completely get rid of MemIndex.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:31
+
+// Symbols are sorted by symbol qualities so that items in the posting 
lists
+// are stored in the descending order of symbol quality.

Couldn we build the inverted index also outside of the critical section? As 
this blocks ongoing index requests, we should do as little work as possible in 
the CS.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:40
+for (DocID SymbolRank = 0; SymbolRank < Symbols->size(); ++SymbolRank) {
+  const auto Sym = (*Symbols)[SymbolRank];
+  for (const auto &Token : generateSearchTokens(*Sym)) {

nit: `const auto * Sym`



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:57
+  FuzzyMatcher Filter(Req.Query);
+  bool More;
+  {

nit: Initialize to false



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:67
+// also implemented in that approach.
+// FIXME(kbobyrev): Code sharing is not very pleasant here, is it better to
+// dispatch long and short queries to internal helper functions?

I'm not quite sure what this FIXME means. What code do you want to share 
between them? 

But we do want to refactor the code a bit to make it easier to follow.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:92
+  // otherwise the iterator won't have any children and will be invalid.
+  if (ScopeIterators.size())
+TopLevelChildren.push_back(createOr(move(ScopeIterators)));

Can we avoid creating scope iterators in the first place if they are not going 
to be used?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:98
+  // Req.MaxCandidateCount. That would require implementing Limit iterator.
+  SymbolDocIDs = consume(*QueryIterator);
+  More = SymbolDocIDs.size() > Req.MaxCandidateCount;

It seems that the lack of limiting iterators can make the query very 
inefficient. Maybe we should implement the limiting iterators before getting 
the index in, in case people start using it before it's ready?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:102
+  // FIXME(kbobyrev): Don't score items twice.
+  for (const auto &Pair : Index) {
+const auto Sym = Pair.second;

Could you document what the approach you are taking to handle short queries? It 
seems that this can be very expensive, for example, if all matching symbols are 
at the end of the DenseMap. Short queries happen very often, so we need to make 
sure index handles them efficiently.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:102
+  // FIXME(kbobyrev): Don't score items twice.
+  for (const auto &Pair : Index) {
+const auto Sym = Pair.second;

ioeric wrote:
> Could you document what the approach you are taking to handle short queries? 
> It seems that this can be very expensive, for example, if all matching 
> symbols are at the end of the DenseMap. Short queries happen very often, so 
> we need to make sure index handles them efficiently.
Did you mean to iterate on `Symbols` which is sorted by quality?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:8
+//
+//===--===//
+

I think this file could use some high-level documentation.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:27
+public:
+  void build(std::shared_ptr> Symbols);
+

There is some assumption about `Symbols` (like`MemIndex::build`). Please add 
documentation.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:31
+  // out to Index.h?
+  static std::unique_ptr build(SymbolSlab Slab);
+

Do we need this for this patch? If not, I'd suggest leaving it out and revisit 
when we actually need it (e.g. when replacing MemIndex); otherwise, I think 
what we want is basically a function that takes a `SymbolSlab` and returns 
`std::shared_ptr>`. This can probably live in 
Index.h as you suggested.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:47
+  std::shared_ptr> Symbols;
+  llvm::DenseMap Index;
+  mutable std::mutex Mutex;

Unlike `MemIndex` where this is used as an actual index, here it's simply a 
lookup table, IIUC? Maybe just `SymbolsByID` or `lookupTable`?



[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D50447#1192280, @JonasToth wrote:

> If whitelisting works, thats fine. But I agree with @lebedev.ri that a 
> contribution/improvement to the ExprMutAnalyzer is the better option. This is 
> especially the case, because multiple checks (and maybe even some other parts 
> then clang-tidy) will utilize this analysis.


I'm sorry for not explaining it with more details. Might be "regression" is a 
confusing world :(. It is not false positive. The change using ExprMutAnalyzer 
is reasonable, IMO. It makes this check smarter to catch cases which will not 
be caught before. For example,

  for (auto widget : container) {
widget.call_const_method(); // const usage recongized by ExprMutAnalyzer, 
so it is fine to change widget to `const auto&`
  } 

But in our codebase, we have code intended to use like below, and it is in base 
library, and is used widely. I think it makes sense to whitelist this class in 
our internal configuration.

  for (auto _ : state) {
 ... // no `_` being referenced in the for-loop body
  }


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

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

In https://reviews.llvm.org/D50447#1192316, @hokein wrote:

> In https://reviews.llvm.org/D50447#1192280, @JonasToth wrote:
>
> > If whitelisting works, thats fine. But I agree with @lebedev.ri that a 
> > contribution/improvement to the ExprMutAnalyzer is the better option. This 
> > is especially the case, because multiple checks (and maybe even some other 
> > parts then clang-tidy) will utilize this analysis.
>
>
> I'm sorry for not explaining it with more details. Might be "regression" is a 
> confusing world :(. It is not false positive. The change using 
> ExprMutAnalyzer is reasonable, IMO. It makes this check smarter to catch 
> cases which will not be caught before. For example,
>
>   for (auto widget : container) {
> widget.call_const_method(); // const usage recongized by ExprMutAnalyzer, 
> so it is fine to change widget to `const auto&`
>   } 
>
>
> But in our codebase, we have code intended to use like below, and it is in 
> base library, and is used widely. I think it makes sense to whitelist this 
> class in our internal configuration.
>
>   for (auto _ : state) {
>  ... // no `_` being referenced in the for-loop body
>   }
>


That looks remarkably like google benchmark main loop. (i don't know at hand if 
making this const will break it, but probably not?)
I wonder if instead there should be an option to not complain about the 
variables that aren't actually used?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D50175: [AArch64][NFC] better matching of AArch64 target in aarch64-cpus.c tests

2018-08-08 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: test/Driver/aarch64-cpus.c:10
+// GENERIC: "-cc1"{{.*}} "-triple" "aarch64"{{.*}} "-target-cpu" "generic"
+// GENERIC-LE: "-cc1"{{.*}} "-triple" "aarch64--"{{.*}} "-target-cpu" "generic"
 

olista01 wrote:
> Why do these need new check prefixes? All of the RUN lines above are 
> selecting little-endian, so I'd expect GENERIC and GENERIC-LE to be the same.
Ok, good point. The output is slightly different. For the little-endian runs 
above the output is:

  "-triple" "aarch64"

and with "-target aarch64_be -mlittle-endian" the output is:

  "-triple" "aarch64--"

As we don't want to be too generic and match "aarch64{{.*}}", I will therefore 
change the GENERIC checks to match "aarch64{{[--]*}}", and indeed remove 
GENERIC-LE.


https://reviews.llvm.org/D50175



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


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

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

In https://reviews.llvm.org/D47849#1192245, @Hahnfeld wrote:

> In https://reviews.llvm.org/D47849#1192134, @gtbercea wrote:
>
> > This patch is concerned with calling device functions when you're on the 
> > device. The correctness issues you mention are orthogonal to this and 
> > should be handled by another patch. I don't think this patch should be held 
> > up any longer.
>
>
> I'm confused by now, could you please highlight the point that I'm missing?


You're bringing up the correctness of the header files which is a detail that 
is orthogonal to this patch. Even if the header files worked correctly I would 
still want to use the libdevice functions. Fixing the header files themselves 
should be therefore done in a separate patch.
Using the libdevice functions guarantees correctness (no weird assembly 
instructions that the device doesn't recognize etc.) and may improve 
performance (if for example the libdevice contained device specific assembly).

The purpose of this patch is to call NVIDIA's libdevice math functions which 
should in principle be more efficient in terms of runtime and register usage. 
Not all of them may be more effecient today (like @tra suggested) but some of 
them will be. Maybe others will be improved in the future, maybe not, again 
that's an orthogonal point. The benefit of using libdevice functions is that 
any improvements NVIDIA makes we will be there to use them in the OpenMP NVPTX 
toolchain. The premise of the OpenMP NVPTX toolchain is that it will leverage 
as much of the CUDA toolchain as possible.

Another point is that users specifically ask for NVIDIA math functions to be 
called on the device when using OpenMP NVPTX device offloading. The libdevice 
library offers __nv_fast_* variants of some math functions. Users want to have 
access to those functions and other functions that the libdevice library 
contains.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


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

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



> IIRC you started to work on this to fix the problem with inline assembly (see 
> https://reviews.llvm.org/D47849#1125019). AFAICS this patch fixes 
> declarations of math functions but you still cannot include `math.h` which 
> most "correct" codes do.

I'm not sure what you mean by this. This patch enables me to include math.h.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Is the type important, or specifics about the variable (e.g. the name?)
The `_` variable names are sometimes used for RAII variables/lambdas
that shall just do some cleanup, e.g. gsl::finally().

It might make sense to give `ExprMutAnalyzer` an ignore-mechanism.

I wonder if instead there should be an option to not complain about the 
variables that aren't actually used?

Checking for variable usage would be simple. The `ExprMutAnalyzer`
always analyses the scope, e.g. a function. You can match this scope for
a `DeclRefExpr` of the variable, empty result means no usage.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D49851: [clang-tidy] run-clang-tidy add synchronisation to the output

2018-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

@alexfh or @aaron.ballman could you take a final look on this one?


https://reviews.llvm.org/D49851



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


[PATCH] D50175: [AArch64][NFC] better matching of AArch64 target in aarch64-cpus.c tests

2018-08-08 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 159715.
SjoerdMeijer added a comment.

Addressed comments.


https://reviews.llvm.org/D50175

Files:
  test/Driver/aarch64-cpus.c

Index: test/Driver/aarch64-cpus.c
===
--- test/Driver/aarch64-cpus.c
+++ test/Driver/aarch64-cpus.c
@@ -6,7 +6,7 @@
 // RUN: %clang -target aarch64 -mlittle-endian -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=GENERIC %s
 // RUN: %clang -target aarch64_be -mlittle-endian -### -c %s 2>&1 | FileCheck -check-prefix=GENERIC %s
 // RUN: %clang -target aarch64_be -mlittle-endian -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=GENERIC %s
-// GENERIC: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"
+// GENERIC: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "generic"
 
 // RUN: %clang -target arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-GENERIC %s
 // RUN: %clang -target arm64 -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-GENERIC %s
@@ -29,8 +29,8 @@
 // RUN: %clang -target aarch64 -mtune=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35-TUNE %s
 // RUN: %clang -target aarch64 -mlittle-endian -mtune=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35-TUNE %s
 // RUN: %clang -target aarch64_be -mlittle-endian -mtune=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35-TUNE %s
-// CA35: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a35"
-// CA35-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"
+// CA35: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "cortex-a35"
+// CA35-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "generic"
 
 // RUN: %clang -target arm64 -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA35 %s
 // RUN: %clang -target arm64 -mlittle-endian -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA35 %s
@@ -44,8 +44,8 @@
 // RUN: %clang -target aarch64_be -mlittle-endian -mcpu=cortex-a53 -### -c %s 2>&1 | FileCheck -check-prefix=CA53 %s
 // RUN: %clang -target aarch64 -mtune=cortex-a53 -### -c %s 2>&1 | FileCheck -check-prefix=CA53-TUNE %s
 // RUN: %clang -target aarch64_be -mlittle-endian -mtune=cortex-a53 -### -c %s 2>&1 | FileCheck -check-prefix=CA53-TUNE %s
-// CA53: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a53"
-// CA53-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"
+// CA53: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "cortex-a53"
+// CA53-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "generic"
 
 // RUN: %clang -target arm64 -mcpu=cortex-a53 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA53 %s
 // RUN: %clang -target arm64 -mlittle-endian -mcpu=cortex-a53 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA53 %s
@@ -59,8 +59,8 @@
 // RUN: %clang -target aarch64_be -mlittle-endian -mcpu=cortex-a55 -### -c %s 2>&1 | FileCheck -check-prefix=CA55 %s
 // RUN: %clang -target aarch64 -mtune=cortex-a55 -### -c %s 2>&1 | FileCheck -check-prefix=CA55-TUNE %s
 // RUN: %clang -target aarch64_be -mlittle-endian -mtune=cortex-a55 -### -c %s 2>&1 | FileCheck -check-prefix=CA55-TUNE %s
-// CA55: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a55"
-// CA55-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"
+// CA55: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "cortex-a55"
+// CA55-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "generic"
 
 // RUN: %clang -target arm64 -mcpu=cortex-a55 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA55 %s
 // RUN: %clang -target arm64 -mlittle-endian -mcpu=cortex-a55 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA55 %s
@@ -75,8 +75,8 @@
 // RUN: %clang -target aarch64 -mtune=cortex-a57 -### -c %s 2>&1 | FileCheck -check-prefix=CA57-TUNE %s
 // RUN: %clang -target aarch64 -mlittle-endian -mtune=cortex-a57 -### -c %s 2>&1 | FileCheck -check-prefix=CA57-TUNE %s
 // RUN: %clang -target aarch64_be -mlittle-endian -mtune=cortex-a57 -### -c %s 2>&1 | FileCheck -check-prefix=CA57-TUNE %s
-// CA57: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a57"
-// CA57-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"
+// CA57: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "cortex-a57"
+// CA57-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{[--]*}}"{{.*}} "-target-cpu" "generic"
 
 // RUN: %clang -target arm64 -mcpu=cortex-a57 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA57 %s
 // RUN: %clang -target arm64 -mlittle-endian -mcpu=cortex-a57 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-CA57 %s
@@ -91,8 +91,8 @@
 // RUN: %clang -target aarch64 -mtune=cortex-a72 -### -c %s 2>&1 | FileCheck -check-prefix=CA72-TUNE %s
 // RUN: %clang -target aarch64 -mlittle-endian -mtune=cortex-a72 -### -c %s 2>&1 | FileCheck -check-prefix=CA72-TUNE %s
 // RUN: %clang -target aarch64_be -mlittle

[PATCH] D50446: [clangd] Record the currently active file in context for codeCompletion and findDefinitions.

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

In https://reviews.llvm.org/D50446#1192282, @ilya-biryukov wrote:

> Short summary of the offline discussion: I suggest adding this parameter into 
> the corresponding requests of the index (FuzzyFindRequest, 
> FindDefinitionsRequest) instead of stashing it in the context. Context has 
> all the same problems as the global variables, so we should try to avoid 
> using it where possible.


Thanks for the summary! Just for the record, my concerns were:

1. The concept of active files are not really index-specific.
2. We need to do this for all 3 different requests (need "scary" comments 3 
places?).
3. The context value seems to be trivial enough and hard to be misused.

> On the other hand, where this key is stored might not be terribly important 
> if we don't have too many usages and remove it when we can workaround the 
> limitations that we're currently facing.




Comment at: clangd/ClangdServer.cpp:162
 
+WithContextValue WithFileName(kActiveFile, File);
 // FIXME(ibiryukov): even if Preamble is non-null, we may want to check

ilya-biryukov wrote:
> If we want to set this value more consistently, maybe do it in 
> TUScheduler::runWithPreamble/runWithAST? 
> All interesting operations that work on files go through those, so it's 
> easier to certify that the file is set correctly.
I have two concerns about doing this:
1. Setting it in the TUScheduler seems to bury this deeper e.g. into scheduling 
logic. Limiting this in specific callbacks right before it's needed seems to 
make it less accessible.

2. There are operations like `workspaceSymbols` (although not handled in this 
patch)  that do not go through TUScheduler.



Comment at: clangd/Context.cpp:35
 
+const clang::clangd::Key kActiveFile;
+

ilya-biryukov wrote:
> ilya-biryukov wrote:
> > Maybe move it somewhere else? E.g. to `Index.h`, since that's where it's 
> > supposed to be used to workaround current limitations?
> > `Context.h/cpp` is a general-purpose support library for the contexts, 
> > application-specific keys do not fit in well there.
> Maybe use `std::string`? Contexts can easily be cloned/migrated between 
> threads, so it's very easy to end up with pointers to dead strings here.
I intentionally used `StringRef` here to make it harder to use and hoped that 
users would be more careful when using this. For the current simple use cases, 
`StringRef` should be sufficient IMO.



Comment at: clangd/Context.cpp:35
 
+const clang::clangd::Key kActiveFile;
+

ioeric wrote:
> ilya-biryukov wrote:
> > ilya-biryukov wrote:
> > > Maybe move it somewhere else? E.g. to `Index.h`, since that's where it's 
> > > supposed to be used to workaround current limitations?
> > > `Context.h/cpp` is a general-purpose support library for the contexts, 
> > > application-specific keys do not fit in well there.
> > Maybe use `std::string`? Contexts can easily be cloned/migrated between 
> > threads, so it's very easy to end up with pointers to dead strings here.
> I intentionally used `StringRef` here to make it harder to use and hoped that 
> users would be more careful when using this. For the current simple use 
> cases, `StringRef` should be sufficient IMO.
We should probably look for some other place to put this, but I don't think 
`Index.h` is the right place. Although context might not be the best place to 
host the active file, the active file seems to be a well-defined concept in 
clangd in general and not index-specific.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50446



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


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

2018-08-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D47849#1192321, @gtbercea wrote:

> > IIRC you started to work on this to fix the problem with inline assembly 
> > (see https://reviews.llvm.org/D47849#1125019). AFAICS this patch fixes 
> > declarations of math functions but you still cannot include `math.h` which 
> > most "correct" codes do.
>
> I'm not sure what you mean by this. This patch enables me to include math.h.


`math.c`:

  #include 

executed commands:

   $ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -c math.c -O2
  In file included from math.c:1:
  In file included from /usr/include/math.h:413:
  /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' in 
asm
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
^
  /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' in 
asm
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
^
  2 errors generated.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


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

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

In https://reviews.llvm.org/D47849#1192368, @Hahnfeld wrote:

> In https://reviews.llvm.org/D47849#1192321, @gtbercea wrote:
>
> > > IIRC you started to work on this to fix the problem with inline assembly 
> > > (see https://reviews.llvm.org/D47849#1125019). AFAICS this patch fixes 
> > > declarations of math functions but you still cannot include `math.h` 
> > > which most "correct" codes do.
> >
> > I'm not sure what you mean by this. This patch enables me to include math.h.
>
>
> `math.c`:
>
>   #include 
>
>
> executed commands:
>
>$ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -c math.c -O2
>   In file included from math.c:1:
>   In file included from /usr/include/math.h:413:
>   /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' 
> in asm
> __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
> ^
>   /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' 
> in asm
> __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
> ^
>   2 errors generated.
>


I do not get that error.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D50414: [libunwind][include] Add SEH declarations to .

2018-08-08 Thread Charles Davis via Phabricator via cfe-commits
cdavis5x updated this revision to Diff 159722.
cdavis5x added a comment.

- Remove unneeded preprocessor condition.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50414

Files:
  include/unwind.h


Index: include/unwind.h
===
--- include/unwind.h
+++ include/unwind.h
@@ -19,6 +19,10 @@
 #include 
 #include 
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#include 
+#endif
+
 #if defined(__APPLE__)
 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
 #else
@@ -120,13 +124,17 @@
   uint64_t exception_class;
   void (*exception_cleanup)(_Unwind_Reason_Code reason,
 _Unwind_Exception *exc);
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+  uintptr_t private_[6];
+#else
   uintptr_t private_1; // non-zero means forced unwind
   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
+#endif
 #if __SIZEOF_POINTER__ == 4
   // The implementation of _Unwind_Exception uses an attribute mode on the
   // above fields which has the side effect of causing this whole struct to
-  // round up to 32 bytes in size. To be more explicit, we add pad fields
-  // added for binary compatibility.
+  // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
+  // pad fields added for binary compatibility.
   uint32_t reserved[3];
 #endif
   // The Itanium ABI requires that _Unwind_Exception objects are "double-word
@@ -369,6 +377,15 @@
 extern void *__deregister_frame_info_bases(const void *fde)
 LIBUNWIND_UNAVAIL;
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+// This is the common wrapper for GCC-style personality functions with SEH.
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PDISPATCHER_CONTEXT disp,
+   _Unwind_Personality_Fn 
pers);
+#endif
+
 #ifdef __cplusplus
 }
 #endif


Index: include/unwind.h
===
--- include/unwind.h
+++ include/unwind.h
@@ -19,6 +19,10 @@
 #include 
 #include 
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#include 
+#endif
+
 #if defined(__APPLE__)
 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
 #else
@@ -120,13 +124,17 @@
   uint64_t exception_class;
   void (*exception_cleanup)(_Unwind_Reason_Code reason,
 _Unwind_Exception *exc);
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+  uintptr_t private_[6];
+#else
   uintptr_t private_1; // non-zero means forced unwind
   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
+#endif
 #if __SIZEOF_POINTER__ == 4
   // The implementation of _Unwind_Exception uses an attribute mode on the
   // above fields which has the side effect of causing this whole struct to
-  // round up to 32 bytes in size. To be more explicit, we add pad fields
-  // added for binary compatibility.
+  // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
+  // pad fields added for binary compatibility.
   uint32_t reserved[3];
 #endif
   // The Itanium ABI requires that _Unwind_Exception objects are "double-word
@@ -369,6 +377,15 @@
 extern void *__deregister_frame_info_bases(const void *fde)
 LIBUNWIND_UNAVAIL;
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+// This is the common wrapper for GCC-style personality functions with SEH.
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PDISPATCHER_CONTEXT disp,
+   _Unwind_Personality_Fn pers);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-08-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D47849#1192375, @gtbercea wrote:

> I do not get that error.


In the beginning you said that you were facing the same error. Did that go away 
in the meantime?
Are you testing on x86 or Power? With optimizations enabled?


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D50451: Fix import of class templates partial specialization

2018-08-08 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a_sidorin, xazax.hun, r.stahl.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

Currently there are several issues with the import of class template
specializations.  (1) Different TUs may have class template specializations
with the same template arguments, but with different set of instantiated
MethodDecls and FieldDecls.  In this patch we provide a fix to merge these
methods and fields.  (2) Currently, we search the partial template
specializations in the set of simple specializations and we add partial
specializations as simple specializations. This is bad, this patch fixes it.


Repository:
  rC Clang

https://reviews.llvm.org/D50451

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTImporter.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2641,6 +2641,216 @@
   R1, recordDecl(has(fieldDecl(hasName("next"));
 }
 
+TEST_P(ASTImporterTestBase, MergeFieldDeclsOfClassTemplateSpecialization) {
+  std::string ClassTemplate =
+  R"(
+  template 
+  struct X {
+  int a{0}; // FieldDecl with InitListExpr
+  X(char) : a(3) {} // (1)
+  X(int) {} // (2)
+  };
+  )";
+  Decl *ToTU = getToTuDecl(ClassTemplate +
+  R"(
+  void foo() {
+  // ClassTemplateSpec with ctor (1): FieldDecl without InitlistExpr
+  X xc('c');
+  }
+  )", Lang_CXX11);
+  auto *ToSpec = FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl(hasName("X")));
+  // FieldDecl without InitlistExpr:
+  auto *ToField = *ToSpec->field_begin();
+  ASSERT_TRUE(ToField);
+  ASSERT_FALSE(ToField->getInClassInitializer());
+  Decl *FromTU = getTuDecl(ClassTemplate +
+  R"(
+  void bar() {
+  // ClassTemplateSpec with ctor (2): FieldDecl WITH InitlistExpr
+  X xc(1);
+  }
+  )", Lang_CXX11);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("X")));
+  // FieldDecl with InitlistExpr:
+  auto *FromField = *FromSpec->field_begin();
+  ASSERT_TRUE(FromField);
+  ASSERT_TRUE(FromField->getInClassInitializer());
+
+  auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  ASSERT_TRUE(ImportedSpec);
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  // After the import, the FieldDecl has to be merged, thus it should have the
+  // InitListExpr.
+  EXPECT_TRUE(ToField->getInClassInitializer());
+}
+
+TEST_P(ASTImporterTestBase, MergeFunctionOfClassTemplateSpecialization) {
+  std::string ClassTemplate =
+  R"(
+  template 
+  struct X {
+void f() {}
+void g() {}
+  };
+  )";
+  Decl *ToTU = getToTuDecl(ClassTemplate +
+  R"(
+  void foo() {
+  X x;
+  x.f();
+  }
+  )", Lang_CXX11);
+  Decl *FromTU = getTuDecl(ClassTemplate +
+  R"(
+  void bar() {
+  X x;
+  x.g();
+  }
+  )", Lang_CXX11);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("X")));
+  auto FunPattern = functionDecl(hasName("g"),
+ hasParent(classTemplateSpecializationDecl()));
+  auto *FromFun =
+  FirstDeclMatcher().match(FromTU, FunPattern);
+  auto *ToFun =
+  FirstDeclMatcher().match(ToTU, FunPattern);
+  ASSERT_TRUE(FromFun->hasBody());
+  ASSERT_FALSE(ToFun->hasBody());
+   auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+   ASSERT_TRUE(ImportedSpec);
+  auto *ToSpec = FirstDeclMatcher().match(
+  ToTU, classTemplateSpecializationDecl(hasName("X")));
+  EXPECT_EQ(ImportedSpec, ToSpec);
+  EXPECT_TRUE(ToFun->hasBody());
+}
+
+TEST_P(ASTImporterTestBase, MergeCtorOfClassTemplateSpecialization) {
+  std::string ClassTemplate =
+  R"(
+  template 
+  struct X {
+  X(char) {}
+  X(int) {}
+  };
+  )";
+  Decl *ToTU = getToTuDecl(ClassTemplate +
+  R"(
+  void foo() {
+  X x('c');
+  }
+  )", Lang_CXX11);
+  Decl *FromTU = getTuDecl(ClassTemplate +
+  R"(
+  void bar() {
+  X x(1);
+  }
+  )", Lang_CXX11);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("X")));
+  // Match the void(int) ctor.
+  auto CtorPattern =
+  cxxConstructorDecl(hasParameter(0, varDecl(hasType(asString("int",
+ hasParent(classTemplateSpecializationDecl()));
+  auto *FromCtor =
+  FirstDeclMatcher().match(FromTU, CtorPattern);
+  auto *ToCtor =
+  FirstDeclMatcher().match(ToTU, CtorPattern);
+  ASSERT_TRUE(FromCtor->hasBody());
+  ASSERT_FALSE(ToCtor->hasBody());
+   auto *ImportedSpec = Import(FromSpec, Lang_CXX11);
+  ASSERT_TRUE(ImportedSpec);
+  auto *ToSpec = FirstDeclMatcher().match(

[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

> That looks remarkably like google benchmark main loop. (i don't know at hand 
> if making this const will break it, but probably not?)
>  I wonder if instead there should be an option to not complain about the 
> variables that aren't actually used?

Yeah, it is google benchmark library.

The new fix `for (const auto& _ : state)` will trigger -Wunused warning. 
`__attribute__((unused))` doesn't help to suppress the warning :(

  $ cat /tmp/main4.cc 
  #include 
  
  struct __attribute__((unused)) Foo {
  };
  
  void f() {
std::vector foos;
for (const Foo& _ : foos) {
}
  }
  $ g++ /tmp/main4.cc -Wunused  

   
  /tmp/main4.cc: In function ‘void f()’:
  /tmp/main4.cc:8:19: warning: unused variable ‘_’ [-Wunused-variable]
 for (const Foo& _ : foos) {
 ^



> Is the type important, or specifics about the variable (e.g. the name?)
>  The _ variable names are sometimes used for RAII variables/lambdas
>  that shall just do some cleanup, e.g. gsl::finally().
> 
> It might make sense to give ExprMutAnalyzer an ignore-mechanism.
> 
> I wonder if instead there should be an option to not complain about the 
> variables that aren't actually used?
> 
> Checking for variable usage would be simple. The ExprMutAnalyzer
>  always analyses the scope, e.g. a function. You can match this scope for
>  a DeclRefExpr of the variable, empty result means no usage.

Both type and variable name "_" can fix the issue here, but the variable name 
seems a fragile way (if the name is changed, things will be broken again).

Yeah, adding an ignore mechanism to ExprMutAnalyzer is another option.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Given it is about the performance in loops and the optimizer?! can
better work with the copy-and-don't-use it might make sense to just
check if the variable is dereferenced in the scope of the loop (any
declRefExpr exists).

That is more userfriendly, too.

Am 08.08.2018 um 17:02 schrieb Haojian Wu via Phabricator:

> hokein added a comment.
> 
>> That looks remarkably like google benchmark main loop. (i don't know at hand 
>> if making this const will break it, but probably not?)
>> 
>>   I wonder if instead there should be an option to not complain about the 
>> variables that aren't actually used?
> 
> Yeah, it is google benchmark library.
> 
> The new fix `for (const auto& _ : state)` will trigger -Wunused warning. 
> `__attribute__((unused))` doesn't help to suppress the warning :(
> 
>   $ cat /tmp/main4.cc 
>   #include 
>   
>   struct __attribute__((unused)) Foo {
>   };
>   
>   void f() {
> std::vector foos;
> for (const Foo& _ : foos) {
> }
>   }
>   $ g++ /tmp/main4.cc -Wunused
>   
>
>   /tmp/main4.cc: In function ‘void f()’:
>   /tmp/main4.cc:8:19: warning: unused variable ‘_’ [-Wunused-variable]
>  for (const Foo& _ : foos) {
>  ^
> 
>> Is the type important, or specifics about the variable (e.g. the name?)
>> 
>>   The _ variable names are sometimes used for RAII variables/lambdas
>>   that shall just do some cleanup, e.g. gsl::finally().
>> 
>> It might make sense to give ExprMutAnalyzer an ignore-mechanism.
>> 
>> I wonder if instead there should be an option to not complain about the 
>> variables that aren't actually used?
>> 
>> Checking for variable usage would be simple. The ExprMutAnalyzer
>> 
>>   always analyses the scope, e.g. a function. You can match this scope for
>>   a DeclRefExpr of the variable, empty result means no usage.
> 
> Both type and variable name "_" can fix the issue here, but the variable name 
> seems a fragile way (if the name is changed, things will be broken again).
> 
> Yeah, adding an ignore mechanism to ExprMutAnalyzer is another option.
> 
> Repository:
> 
>   rCTE Clang Tools Extra
> 
> https://reviews.llvm.org/D50447


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D49223: [AST] Check described template at structural equivalence check.

2018-08-08 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339256: [AST] Check described template at structural 
equivalence check. (authored by balazske, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49223?vs=159458&id=159725#toc

Repository:
  rC Clang

https://reviews.llvm.org/D49223

Files:
  include/clang/AST/ASTStructuralEquivalence.h
  lib/AST/ASTStructuralEquivalence.cpp
  unittests/AST/StructuralEquivalenceTest.cpp

Index: include/clang/AST/ASTStructuralEquivalence.h
===
--- include/clang/AST/ASTStructuralEquivalence.h
+++ include/clang/AST/ASTStructuralEquivalence.h
@@ -114,8 +114,19 @@
 private:
   /// Finish checking all of the structural equivalences.
   ///
-  /// \returns true if an error occurred, false otherwise.
+  /// \returns true if the equivalence check failed (non-equivalence detected),
+  /// false if equivalence was detected.
   bool Finish();
+
+  /// Check for common properties at Finish.
+  /// \returns true if D1 and D2 may be equivalent,
+  /// false if they are for sure not.
+  bool CheckCommonEquivalence(Decl *D1, Decl *D2);
+
+  /// Check for class dependent properties at Finish.
+  /// \returns true if D1 and D2 may be equivalent,
+  /// false if they are for sure not.
+  bool CheckKindSpecificEquivalence(Decl *D1, Decl *D2);
 };
 
 } // namespace clang
Index: lib/AST/ASTStructuralEquivalence.cpp
===
--- lib/AST/ASTStructuralEquivalence.cpp
+++ lib/AST/ASTStructuralEquivalence.cpp
@@ -1023,7 +1023,7 @@
 return true;
 
   // If any of the records has external storage and we do a minimal check (or
-  // AST import) we assmue they are equivalent. (If we didn't have this
+  // AST import) we assume they are equivalent. (If we didn't have this
   // assumption then `RecordDecl::LoadFieldsFromExternalStorage` could trigger
   // another AST import which in turn would call the structural equivalency
   // check again and finally we'd have an improper result.)
@@ -1497,6 +1497,141 @@
   return !Finish();
 }
 
+bool StructuralEquivalenceContext::CheckCommonEquivalence(Decl *D1, Decl *D2) {
+  // Check for equivalent described template.
+  TemplateDecl *Template1 = D1->getDescribedTemplate();
+  TemplateDecl *Template2 = D2->getDescribedTemplate();
+  if ((Template1 != nullptr) != (Template2 != nullptr))
+return false;
+  if (Template1 && !IsStructurallyEquivalent(*this, Template1, Template2))
+return false;
+
+  // FIXME: Move check for identifier names into this function.
+
+  return true;
+}
+
+bool StructuralEquivalenceContext::CheckKindSpecificEquivalence(
+Decl *D1, Decl *D2) {
+  // FIXME: Switch on all declaration kinds. For now, we're just going to
+  // check the obvious ones.
+  if (auto *Record1 = dyn_cast(D1)) {
+if (auto *Record2 = dyn_cast(D2)) {
+  // Check for equivalent structure names.
+  IdentifierInfo *Name1 = Record1->getIdentifier();
+  if (!Name1 && Record1->getTypedefNameForAnonDecl())
+Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier();
+  IdentifierInfo *Name2 = Record2->getIdentifier();
+  if (!Name2 && Record2->getTypedefNameForAnonDecl())
+Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier();
+  if (!::IsStructurallyEquivalent(Name1, Name2) ||
+  !::IsStructurallyEquivalent(*this, Record1, Record2))
+return false;
+} else {
+  // Record/non-record mismatch.
+  return false;
+}
+  } else if (auto *Enum1 = dyn_cast(D1)) {
+if (auto *Enum2 = dyn_cast(D2)) {
+  // Check for equivalent enum names.
+  IdentifierInfo *Name1 = Enum1->getIdentifier();
+  if (!Name1 && Enum1->getTypedefNameForAnonDecl())
+Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier();
+  IdentifierInfo *Name2 = Enum2->getIdentifier();
+  if (!Name2 && Enum2->getTypedefNameForAnonDecl())
+Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier();
+  if (!::IsStructurallyEquivalent(Name1, Name2) ||
+  !::IsStructurallyEquivalent(*this, Enum1, Enum2))
+return false;
+} else {
+  // Enum/non-enum mismatch
+  return false;
+}
+  } else if (const auto *Typedef1 = dyn_cast(D1)) {
+if (const auto *Typedef2 = dyn_cast(D2)) {
+  if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(),
+  Typedef2->getIdentifier()) ||
+  !::IsStructurallyEquivalent(*this, Typedef1->getUnderlyingType(),
+  Typedef2->getUnderlyingType()))
+return false;
+} else {
+  // Typedef/non-typedef mismatch.
+  return false;
+}
+  } else if (auto *ClassTemplate1 = dyn_cast(D1)) {
+if (auto *ClassTemplate2 = dyn_cast(D2)) {
+  if (!::IsStructurallyEquivalent(*this, ClassTemplate1,
+  ClassTemplate2)

r339256 - [AST] Check described template at structural equivalence check.

2018-08-08 Thread Balazs Keri via cfe-commits
Author: balazske
Date: Wed Aug  8 08:04:27 2018
New Revision: 339256

URL: http://llvm.org/viewvc/llvm-project?rev=339256&view=rev
Log:
[AST] Check described template at structural equivalence check.

Summary:
When checking a class or function the described class or function template
is checked too.
Split StructuralEquivalenceContext::Finish into multiple functions.
Improved test with symmetric check, added new tests.

Reviewers: martong, a.sidorin, a_sidorin, bruno

Reviewed By: martong, a.sidorin

Subscribers: rnkovacs, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/ASTStructuralEquivalence.h
cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
cfe/trunk/unittests/AST/StructuralEquivalenceTest.cpp

Modified: cfe/trunk/include/clang/AST/ASTStructuralEquivalence.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTStructuralEquivalence.h?rev=339256&r1=339255&r2=339256&view=diff
==
--- cfe/trunk/include/clang/AST/ASTStructuralEquivalence.h (original)
+++ cfe/trunk/include/clang/AST/ASTStructuralEquivalence.h Wed Aug  8 08:04:27 
2018
@@ -114,8 +114,19 @@ struct StructuralEquivalenceContext {
 private:
   /// Finish checking all of the structural equivalences.
   ///
-  /// \returns true if an error occurred, false otherwise.
+  /// \returns true if the equivalence check failed (non-equivalence detected),
+  /// false if equivalence was detected.
   bool Finish();
+
+  /// Check for common properties at Finish.
+  /// \returns true if D1 and D2 may be equivalent,
+  /// false if they are for sure not.
+  bool CheckCommonEquivalence(Decl *D1, Decl *D2);
+
+  /// Check for class dependent properties at Finish.
+  /// \returns true if D1 and D2 may be equivalent,
+  /// false if they are for sure not.
+  bool CheckKindSpecificEquivalence(Decl *D1, Decl *D2);
 };
 
 } // namespace clang

Modified: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp?rev=339256&r1=339255&r2=339256&view=diff
==
--- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp (original)
+++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp Wed Aug  8 08:04:27 2018
@@ -1023,7 +1023,7 @@ static bool IsStructurallyEquivalent(Str
 return true;
 
   // If any of the records has external storage and we do a minimal check (or
-  // AST import) we assmue they are equivalent. (If we didn't have this
+  // AST import) we assume they are equivalent. (If we didn't have this
   // assumption then `RecordDecl::LoadFieldsFromExternalStorage` could trigger
   // another AST import which in turn would call the structural equivalency
   // check again and finally we'd have an improper result.)
@@ -1497,6 +1497,141 @@ bool StructuralEquivalenceContext::IsEqu
   return !Finish();
 }
 
+bool StructuralEquivalenceContext::CheckCommonEquivalence(Decl *D1, Decl *D2) {
+  // Check for equivalent described template.
+  TemplateDecl *Template1 = D1->getDescribedTemplate();
+  TemplateDecl *Template2 = D2->getDescribedTemplate();
+  if ((Template1 != nullptr) != (Template2 != nullptr))
+return false;
+  if (Template1 && !IsStructurallyEquivalent(*this, Template1, Template2))
+return false;
+
+  // FIXME: Move check for identifier names into this function.
+
+  return true;
+}
+
+bool StructuralEquivalenceContext::CheckKindSpecificEquivalence(
+Decl *D1, Decl *D2) {
+  // FIXME: Switch on all declaration kinds. For now, we're just going to
+  // check the obvious ones.
+  if (auto *Record1 = dyn_cast(D1)) {
+if (auto *Record2 = dyn_cast(D2)) {
+  // Check for equivalent structure names.
+  IdentifierInfo *Name1 = Record1->getIdentifier();
+  if (!Name1 && Record1->getTypedefNameForAnonDecl())
+Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier();
+  IdentifierInfo *Name2 = Record2->getIdentifier();
+  if (!Name2 && Record2->getTypedefNameForAnonDecl())
+Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier();
+  if (!::IsStructurallyEquivalent(Name1, Name2) ||
+  !::IsStructurallyEquivalent(*this, Record1, Record2))
+return false;
+} else {
+  // Record/non-record mismatch.
+  return false;
+}
+  } else if (auto *Enum1 = dyn_cast(D1)) {
+if (auto *Enum2 = dyn_cast(D2)) {
+  // Check for equivalent enum names.
+  IdentifierInfo *Name1 = Enum1->getIdentifier();
+  if (!Name1 && Enum1->getTypedefNameForAnonDecl())
+Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier();
+  IdentifierInfo *Name2 = Enum2->getIdentifier();
+  if (!Name2 && Enum2->getTypedefNameForAnonDecl())
+Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier();
+  if (!::IsStructurallyEquivalent(Name1, Name2) ||
+  !

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

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

In https://reviews.llvm.org/D47849#1192368, @Hahnfeld wrote:

> In https://reviews.llvm.org/D47849#1192321, @gtbercea wrote:
>
> > > IIRC you started to work on this to fix the problem with inline assembly 
> > > (see https://reviews.llvm.org/D47849#1125019). AFAICS this patch fixes 
> > > declarations of math functions but you still cannot include `math.h` 
> > > which most "correct" codes do.
> >
> > I'm not sure what you mean by this. This patch enables me to include math.h.
>
>
> `math.c`:
>
>   #include 
>
>
> executed commands:
>
>$ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -c math.c -O2
>   In file included from math.c:1:
>   In file included from /usr/include/math.h:413:
>   /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' 
> in asm
> __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
> ^
>   /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' 
> in asm
> __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
> ^
>   2 errors generated.
>


We are probably linking against different math.h files. I don't seem to have a 
mathinline.h with those instructions. Perhaps this is an x86 specific error.

I think I know what's happening. I think the host math.h is still included but 
not necessarily used. Math functions resolve to math functions in the CUDA 
header first (that's what this patch does). This patch doesn't prevent math.h 
from being included.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D50447: [clang-tidy] Add a whitelistClasses option in performance-for-range-copy check.

2018-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

> But in our codebase, we have code intended to use like below, and it is in 
> base library, and is used widely. I think it makes sense to whitelist this 
> class in our internal configuration.
> 
>   for (auto _ : state) {
>  ... // no `_` being referenced in the for-loop body
>   }

I see.




Comment at: clang-tidy/performance/ForRangeCopyCheck.cpp:93
 return false;
   if (utils::ExprMutationAnalyzer(ForRange.getBody(), &Context)
   .isMutated(&LoopVar))

Adding a `..IsMutated(&LoopVar) && IsReferenced(ForScope, LoopVar))` here 
should fix the warning as well.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50447



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


[PATCH] D50414: [libunwind][include] Add SEH declarations to .

2018-08-08 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.

In https://reviews.llvm.org/D50414#1192267, @cdavis5x wrote:

> In https://reviews.llvm.org/D50414#1191834, @mstorsjo wrote:
>
> > Do you plan on implementing these SEH specific bits in libunwind,
>
>
> Already have. Patch forthcoming.


Oh, excellent - looking forward to it.

This version LGTM.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50414



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


[libunwind] r339258 - [libunwind][include] Add SEH declarations to .

2018-08-08 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Wed Aug  8 08:18:20 2018
New Revision: 339258

URL: http://llvm.org/viewvc/llvm-project?rev=339258&view=rev
Log:
[libunwind][include] Add SEH declarations to .

Summary:
Make the `_Unwind_Exception` struct correct under SEH. Add a
declaration of `_GCC_specific_handler()`, which is used by SEH versions
of Itanium personality handlers to do common setup. Roughly corresponds
to Clang's D50380.

Reviewers: mstorsjo, rnk, compnerd, smeenai

Subscribers: christof, chrib, cfe-commits, llvm-commits

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

Modified:
libunwind/trunk/include/unwind.h

Modified: libunwind/trunk/include/unwind.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/unwind.h?rev=339258&r1=339257&r2=339258&view=diff
==
--- libunwind/trunk/include/unwind.h (original)
+++ libunwind/trunk/include/unwind.h Wed Aug  8 08:18:20 2018
@@ -19,6 +19,10 @@
 #include 
 #include 
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#include 
+#endif
+
 #if defined(__APPLE__)
 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
 #else
@@ -120,13 +124,17 @@ struct _Unwind_Exception {
   uint64_t exception_class;
   void (*exception_cleanup)(_Unwind_Reason_Code reason,
 _Unwind_Exception *exc);
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+  uintptr_t private_[6];
+#else
   uintptr_t private_1; // non-zero means forced unwind
   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
+#endif
 #if __SIZEOF_POINTER__ == 4
   // The implementation of _Unwind_Exception uses an attribute mode on the
   // above fields which has the side effect of causing this whole struct to
-  // round up to 32 bytes in size. To be more explicit, we add pad fields
-  // added for binary compatibility.
+  // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
+  // pad fields added for binary compatibility.
   uint32_t reserved[3];
 #endif
   // The Itanium ABI requires that _Unwind_Exception objects are "double-word
@@ -369,6 +377,24 @@ extern void *__deregister_frame_info(con
 extern void *__deregister_frame_info_bases(const void *fde)
 LIBUNWIND_UNAVAIL;
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+// This is the common wrapper for GCC-style personality functions with SEH.
+#ifdef __x86_64__
+// The DISPATCHER_CONTEXT struct is only defined on x64.
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PDISPATCHER_CONTEXT disp,
+   _Unwind_Personality_Fn 
pers);
+#else
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PVOID disp,
+   _Unwind_Personality_Fn 
pers);
+#endif
+#endif
+
 #ifdef __cplusplus
 }
 #endif


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


[PATCH] D50414: [libunwind][include] Add SEH declarations to .

2018-08-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339258: [libunwind][include] Add SEH declarations to 
. (authored by cdavis, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50414?vs=159722&id=159728#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50414

Files:
  libunwind/trunk/include/unwind.h


Index: libunwind/trunk/include/unwind.h
===
--- libunwind/trunk/include/unwind.h
+++ libunwind/trunk/include/unwind.h
@@ -19,6 +19,10 @@
 #include 
 #include 
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#include 
+#endif
+
 #if defined(__APPLE__)
 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
 #else
@@ -120,13 +124,17 @@
   uint64_t exception_class;
   void (*exception_cleanup)(_Unwind_Reason_Code reason,
 _Unwind_Exception *exc);
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+  uintptr_t private_[6];
+#else
   uintptr_t private_1; // non-zero means forced unwind
   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
+#endif
 #if __SIZEOF_POINTER__ == 4
   // The implementation of _Unwind_Exception uses an attribute mode on the
   // above fields which has the side effect of causing this whole struct to
-  // round up to 32 bytes in size. To be more explicit, we add pad fields
-  // added for binary compatibility.
+  // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
+  // pad fields added for binary compatibility.
   uint32_t reserved[3];
 #endif
   // The Itanium ABI requires that _Unwind_Exception objects are "double-word
@@ -369,6 +377,24 @@
 extern void *__deregister_frame_info_bases(const void *fde)
 LIBUNWIND_UNAVAIL;
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+// This is the common wrapper for GCC-style personality functions with SEH.
+#ifdef __x86_64__
+// The DISPATCHER_CONTEXT struct is only defined on x64.
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PDISPATCHER_CONTEXT disp,
+   _Unwind_Personality_Fn 
pers);
+#else
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PVOID disp,
+   _Unwind_Personality_Fn 
pers);
+#endif
+#endif
+
 #ifdef __cplusplus
 }
 #endif


Index: libunwind/trunk/include/unwind.h
===
--- libunwind/trunk/include/unwind.h
+++ libunwind/trunk/include/unwind.h
@@ -19,6 +19,10 @@
 #include 
 #include 
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#include 
+#endif
+
 #if defined(__APPLE__)
 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
 #else
@@ -120,13 +124,17 @@
   uint64_t exception_class;
   void (*exception_cleanup)(_Unwind_Reason_Code reason,
 _Unwind_Exception *exc);
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+  uintptr_t private_[6];
+#else
   uintptr_t private_1; // non-zero means forced unwind
   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
+#endif
 #if __SIZEOF_POINTER__ == 4
   // The implementation of _Unwind_Exception uses an attribute mode on the
   // above fields which has the side effect of causing this whole struct to
-  // round up to 32 bytes in size. To be more explicit, we add pad fields
-  // added for binary compatibility.
+  // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
+  // pad fields added for binary compatibility.
   uint32_t reserved[3];
 #endif
   // The Itanium ABI requires that _Unwind_Exception objects are "double-word
@@ -369,6 +377,24 @@
 extern void *__deregister_frame_info_bases(const void *fde)
 LIBUNWIND_UNAVAIL;
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+// This is the common wrapper for GCC-style personality functions with SEH.
+#ifdef __x86_64__
+// The DISPATCHER_CONTEXT struct is only defined on x64.
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PDISPATCHER_CONTEXT disp,
+   _Unwind_Personality_Fn pers);
+#else
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+  

[libunwind] r339259 - Remove unneeded preprocessor condition.

2018-08-08 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Wed Aug  8 08:18:22 2018
New Revision: 339259

URL: http://llvm.org/viewvc/llvm-project?rev=339259&view=rev
Log:
Remove unneeded preprocessor condition.

Modified:
libunwind/trunk/include/unwind.h

Modified: libunwind/trunk/include/unwind.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/unwind.h?rev=339259&r1=339258&r2=339259&view=diff
==
--- libunwind/trunk/include/unwind.h (original)
+++ libunwind/trunk/include/unwind.h Wed Aug  8 08:18:22 2018
@@ -379,20 +379,11 @@ extern void *__deregister_frame_info_bas
 
 #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
 // This is the common wrapper for GCC-style personality functions with SEH.
-#ifdef __x86_64__
-// The DISPATCHER_CONTEXT struct is only defined on x64.
 extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
PVOID frame,
PCONTEXT ctx,
PDISPATCHER_CONTEXT disp,
_Unwind_Personality_Fn 
pers);
-#else
-extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
-   PVOID frame,
-   PCONTEXT ctx,
-   PVOID disp,
-   _Unwind_Personality_Fn 
pers);
-#endif
 #endif
 
 #ifdef __cplusplus


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


[PATCH] D50452: [WIP] clangd XPC adapter

2018-08-08 Thread Jan Korous via Phabricator via cfe-commits
jkorous created this revision.
jkorous added reviewers: arphaman, sammccall, ilya-biryukov, simark.
Herald added subscribers: cfe-commits, dexonsmith, MaskRay, ioeric, mgorny.

Based on our internal discussions we decided to change our direction with XPC 
support for clangd. We did some extra measurements and found out that JSON 
serialized over XPC is good enough for our use-case. We also took into 
consideration that we'd have to deal with support for multiple workspaces in 
near future.

Probably the simplest solution is to keep XPC completely out of clangd binary 
and use one clangd instance per workspace. This design means it's the least 
intrusive change, it's rather simple (compared to adding support for multiple 
workspaces to clangd itself) and robust (compared to threads-based 
implementation). Long-term it's hopefully also going to be less 
maintenance-demanding since it's dependent only on LSP and not it's 
implementation.

The patch is nearly finished - I just wanted to get some feedback on the design 
early on (before finishing doxygen annotations, documentation, etc.).

Our approach to testing for the future is to reuse existing clangd lit tests 
and just send messages through our XPC code. For the time being there's just a 
single minimal testcase.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50452

Files:
  CMakeLists.txt
  Features.inc.in
  clangd/CMakeLists.txt
  clangd/xpc/initialize.test
  lit.cfg
  lit.site.cfg.in
  xpc/CMakeLists.txt
  xpc/README.txt
  xpc/cmake/Info.plist.in
  xpc/cmake/XPCServiceInfo.plist.in
  xpc/cmake/modules/CreateClangdXPCFramework.cmake
  xpc/framework/CMakeLists.txt
  xpc/framework/ClangdXPC.cpp
  xpc/test-client/CMakeLists.txt
  xpc/test-client/ClangdXPCTestClient.cpp
  xpc/tool/CMakeLists.txt
  xpc/tool/ClangdSubprocess.cpp
  xpc/tool/ClangdSubprocess.h
  xpc/tool/ClangdWorkspaceInstances.cpp
  xpc/tool/ClangdWorkspaceInstances.h
  xpc/tool/ClangdXpcAdapter.cpp
  xpc/tool/log.h

Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -51,4 +51,4 @@
   clangToolingInclusions
   LLVMSupport
   LLVMTestingSupport
-  )
+  )
\ No newline at end of file
Index: lit.site.cfg.in
===
--- lit.site.cfg.in
+++ lit.site.cfg.in
@@ -11,6 +11,7 @@
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
+config.clangd_xpc_support = @CLANGD_BUILD_XPC@
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
Index: lit.cfg
===
--- lit.cfg
+++ lit.cfg
@@ -117,6 +117,10 @@
 if platform.system() not in ['Windows']:
 config.available_features.add('ansi-escape-sequences')
 
+# XPC support for Clangd.
+if config.clangd_xpc_support:
+config.available_features.add('clangd-xpc-support')
+
 if config.clang_staticanalyzer:
 config.available_features.add('static-analyzer')
 check_clang_tidy = os.path.join(
Index: clangd/xpc/initialize.test
===
--- /dev/null
+++ clangd/xpc/initialize.test
@@ -0,0 +1,10 @@
+# RUN: clangd-xpc-test-client < %s | FileCheck %s
+# REQUIRES: clangd-xpc-support
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootUri":"test:///workspace","capabilities":{},"trace":"off"}}
+# CHECK-DAG: {"id":0,"jsonrpc":"2.0","result":{"capabilities":{"codeActionProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",">",":"]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix"]},"hoverProvider":true,"renameProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":2,"workspaceSymbolProvider":true}}}
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK-DAG: {"id":3,"jsonrpc":"2.0","result":null}
+
+{"jsonrpc":"2.0","method":"exit"}
Index: xpc/tool/log.h
===
--- /dev/null
+++ xpc/tool/log.h
@@ -0,0 +1,49 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_XPC_LOG_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_XPC_LOG_H
+
+#include 
+#include 
+
+#include 
+
+class Logger {
+private:
+  enum class log_type { log, info, debug };
+  log_type type;
+  std::string buffer_data;
+  std::stringstream buffer;
+  Logger(log_type type) : type(type), buffer_data(), buffer(buffer_data) {}
+
+public:
+  template  Logger &operator<<(const T &in) {
+buffer << in;
+return *this;
+  }
+  friend 

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

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

In https://reviews.llvm.org/D47849#1192383, @Hahnfeld wrote:

> In https://reviews.llvm.org/D47849#1192375, @gtbercea wrote:
>
> > I do not get that error.
>
>
> In the beginning you said that you were facing the same error. Did that go 
> away in the meantime?
>  Are you testing on x86 or Power? With optimizations enabled?


Since I'm running on Power I was facing a similar problem related to host 
assembly instructions on device but not exactly the same error.

The error you are seeing is that the NVPTX target doesn't regard "x" as a valid 
input constraint. x is an x86 specific constraint which I don't have on the 
Power side.

The problems I was having were related to the math functions on the device 
resolving to host math functions which contained host assembly instructions 
which were not recognized by NVPTX. This patch fixes that issue.

Perhaps the inclusion of the host math.h should just be prevented for device 
code?


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D49548: [clangd] XPC WIP

2018-08-08 Thread Jan Korous via Phabricator via cfe-commits
jkorous abandoned this revision.
jkorous added a comment.

We decided to abandon this direction in favor of simpler solution.
https://reviews.llvm.org/D50452

One of the reasons is that there's a design fault - handling of 
server-originated messages (notifications) in this patch.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49548



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


[PATCH] D48559: [clangd] refactoring for XPC transport layer [NFCI]

2018-08-08 Thread Jan Korous via Phabricator via cfe-commits
jkorous added a comment.

Hi, we decided to go with a different solution:
https://reviews.llvm.org/D50452


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48559



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


[PATCH] D48562: [clangd] XPC transport layer

2018-08-08 Thread Jan Korous via Phabricator via cfe-commits
jkorous abandoned this revision.
jkorous added a comment.

We decided to go with a different solution:
https://reviews.llvm.org/D50452


https://reviews.llvm.org/D48562



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


[PATCH] D50446: [clangd] Record the currently active file in context for codeCompletion and findDefinitions.

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



Comment at: clangd/ClangdServer.cpp:162
 
+WithContextValue WithFileName(kActiveFile, File);
 // FIXME(ibiryukov): even if Preamble is non-null, we may want to check

ioeric wrote:
> ilya-biryukov wrote:
> > If we want to set this value more consistently, maybe do it in 
> > TUScheduler::runWithPreamble/runWithAST? 
> > All interesting operations that work on files go through those, so it's 
> > easier to certify that the file is set correctly.
> I have two concerns about doing this:
> 1. Setting it in the TUScheduler seems to bury this deeper e.g. into 
> scheduling logic. Limiting this in specific callbacks right before it's 
> needed seems to make it less accessible.
> 
> 2. There are operations like `workspaceSymbols` (although not handled in this 
> patch)  that do not go through TUScheduler.
> 1. Setting it in the TUScheduler seems to bury this deeper e.g. into 
> scheduling logic. Limiting this in specific callbacks right before it's 
> needed seems to make it less accessible.

If we want to make the data-flow explicit, let's add this to the index request 
parameters.
Otherwise, I suggest we do something consistent across all requests, rather 
than special-casing the index-calling ones. E.g. if someone adds an index call 
in `onHover`, they'll need to remember to also update the ClangdServer call to 
set this value and they really shouldn't care about this hack of ours. The less 
intrusive this thing is, the better.

> 2. There are operations like workspaceSymbols (although not handled in this 
> patch) that do not go through TUScheduler.
And we don't set the file path for them anyway, because there's not active file 
in that case. How is that different in either of the approaches?



Comment at: clangd/Context.cpp:35
 
+const clang::clangd::Key kActiveFile;
+

ioeric wrote:
> ioeric wrote:
> > ilya-biryukov wrote:
> > > ilya-biryukov wrote:
> > > > Maybe move it somewhere else? E.g. to `Index.h`, since that's where 
> > > > it's supposed to be used to workaround current limitations?
> > > > `Context.h/cpp` is a general-purpose support library for the contexts, 
> > > > application-specific keys do not fit in well there.
> > > Maybe use `std::string`? Contexts can easily be cloned/migrated between 
> > > threads, so it's very easy to end up with pointers to dead strings here.
> > I intentionally used `StringRef` here to make it harder to use and hoped 
> > that users would be more careful when using this. For the current simple 
> > use cases, `StringRef` should be sufficient IMO.
> We should probably look for some other place to put this, but I don't think 
> `Index.h` is the right place. Although context might not be the best place to 
> host the active file, the active file seems to be a well-defined concept in 
> clangd in general and not index-specific.
Maybe move it `ClangdServer.h` or `TUScheduler,h` then? (depending on where we 
set it).

I still don't think `Context.h` is the right place for it,  it should not 
contain any application-specific keys.



Comment at: clangd/Context.cpp:35
 
+const clang::clangd::Key kActiveFile;
+

ilya-biryukov wrote:
> ioeric wrote:
> > ioeric wrote:
> > > ilya-biryukov wrote:
> > > > ilya-biryukov wrote:
> > > > > Maybe move it somewhere else? E.g. to `Index.h`, since that's where 
> > > > > it's supposed to be used to workaround current limitations?
> > > > > `Context.h/cpp` is a general-purpose support library for the 
> > > > > contexts, application-specific keys do not fit in well there.
> > > > Maybe use `std::string`? Contexts can easily be cloned/migrated between 
> > > > threads, so it's very easy to end up with pointers to dead strings here.
> > > I intentionally used `StringRef` here to make it harder to use and hoped 
> > > that users would be more careful when using this. For the current simple 
> > > use cases, `StringRef` should be sufficient IMO.
> > We should probably look for some other place to put this, but I don't think 
> > `Index.h` is the right place. Although context might not be the best place 
> > to host the active file, the active file seems to be a well-defined concept 
> > in clangd in general and not index-specific.
> Maybe move it `ClangdServer.h` or `TUScheduler,h` then? (depending on where 
> we set it).
> 
> I still don't think `Context.h` is the right place for it,  it should not 
> contain any application-specific keys.
We're relying too much on the data flow of contexts, which is implicit and we 
completely don't control. Even if we don't access dead StringRefs now, it's 
very easy to accidentally introduce this behavior later.

We should use `string` here, there's just too high risk of hitting a bug 
otherwise. What are the disadvantages of using `string` here?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50446



___

r339261 - Fix -Wdocumentation warnings. NFCI.

2018-08-08 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Aug  8 08:34:00 2018
New Revision: 339261

URL: http://llvm.org/viewvc/llvm-project?rev=339261&view=rev
Log:
Fix -Wdocumentation warnings. NFCI.

Modified:
cfe/trunk/include/clang/Basic/IdentifierTable.h

Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=339261&r1=339260&r2=339261&view=diff
==
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Wed Aug  8 08:34:00 2018
@@ -50,60 +50,60 @@ using IdentifierLocPair = std::pair *Entry = nullptr;


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


[PATCH] D50413: [libunwind][include] Add some missing definitions to .

2018-08-08 Thread Charles Davis via Phabricator via cfe-commits
cdavis5x added inline comments.



Comment at: include/unwind.h:46
+typedef uintptr_t _Unwind_Ptr;
+#endif
+

mstorsjo wrote:
> What other reference is this list of typedefs for `_Unwind_Ptr` based on? I 
> don't see any of these cases in clang's unwind.h at least.
Where //did// I get those from...? These seem to be for ARM EHABI, but I can't 
find them anymore in the GCC source. They aren't in Clang's header, either. I 
wrote this a while ago... did something change in the meantime?

I could probably get away with removing those special cases if we don't really 
need them.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50413



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


[PATCH] D50448: [CGObjCGNU] Rename GetSelector helper method to fix -Woverloaded-virtual warning (PR38210)

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

Looks good to me.  This method should probably take a StringRef rather than a 
`const std::string&`, but I can make that change separately.


Repository:
  rC Clang

https://reviews.llvm.org/D50448



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


[PATCH] D50413: [libunwind][include] Add some missing definitions to .

2018-08-08 Thread Charles Davis via Phabricator via cfe-commits
cdavis5x marked an inline comment as done.
cdavis5x added a comment.

In https://reviews.llvm.org/D50413#1191726, @krytarowski wrote:

> NetBSD uses `typedef void *_Unwind_Ptr;` unconditionally in its 
> ``... if that has to be matched.


Done.

> Additionally: `typedef long _Unwind_Word;`.

Done.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50413



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


[PATCH] D50413: [libunwind][include] Add some missing definitions to .

2018-08-08 Thread Charles Davis via Phabricator via cfe-commits
cdavis5x updated this revision to Diff 159731.
cdavis5x added a comment.

- Add NetBSD-specific definitions.
- Pull out common declaration of `__personality_routine`.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50413

Files:
  include/unwind.h


Index: include/unwind.h
===
--- include/unwind.h
+++ include/unwind.h
@@ -29,6 +29,32 @@
 #define LIBUNWIND_UNAVAIL
 #endif
 
+#if defined(__NetBSD__)
+typedef long _Unwind_Word;
+#else
+typedef uintptr_t _Unwind_Word;
+#endif
+typedef intptr_t _Unwind_Sword;
+typedef uintptr_t _Unwind_Internal_Ptr;
+typedef uint64_t _Unwind_Exception_Class;
+
+typedef intptr_t _sleb128_t;
+typedef uintptr_t _uleb128_t;
+
+#if _LIBUNWIND_ARM_EHABI
+#if defined(__FreeBSD__)
+typedef void *_Unwind_Ptr;
+#elif defined(__linux__)
+typedef unsigned long *_Unwind_Ptr;
+#else
+typedef uintptr_t _Unwind_Ptr;
+#endif
+#elif defined(__NetBSD__)
+typedef void *_Unwind_Ptr;
+#else
+typedef uintptr_t _Unwind_Ptr;
+#endif
+
 typedef enum {
   _URC_NO_REASON = 0,
   _URC_OK = 0,
@@ -111,7 +137,7 @@
_Unwind_Exception* exceptionObject,
struct _Unwind_Context* context);
 
-typedef _Unwind_Reason_Code (*__personality_routine)
+typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
   (_Unwind_State state,
_Unwind_Exception* exceptionObject,
struct _Unwind_Context* context);
@@ -150,13 +176,14 @@
  struct _Unwind_Context* context,
  void* stop_parameter );
 
-typedef _Unwind_Reason_Code (*__personality_routine)
+typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
   (int version,
_Unwind_Action actions,
uint64_t exceptionClass,
_Unwind_Exception* exceptionObject,
struct _Unwind_Context* context);
 #endif
+typedef _Unwind_Personality_Fn __personality_routine;
 
 #ifdef __cplusplus
 extern "C" {


Index: include/unwind.h
===
--- include/unwind.h
+++ include/unwind.h
@@ -29,6 +29,32 @@
 #define LIBUNWIND_UNAVAIL
 #endif
 
+#if defined(__NetBSD__)
+typedef long _Unwind_Word;
+#else
+typedef uintptr_t _Unwind_Word;
+#endif
+typedef intptr_t _Unwind_Sword;
+typedef uintptr_t _Unwind_Internal_Ptr;
+typedef uint64_t _Unwind_Exception_Class;
+
+typedef intptr_t _sleb128_t;
+typedef uintptr_t _uleb128_t;
+
+#if _LIBUNWIND_ARM_EHABI
+#if defined(__FreeBSD__)
+typedef void *_Unwind_Ptr;
+#elif defined(__linux__)
+typedef unsigned long *_Unwind_Ptr;
+#else
+typedef uintptr_t _Unwind_Ptr;
+#endif
+#elif defined(__NetBSD__)
+typedef void *_Unwind_Ptr;
+#else
+typedef uintptr_t _Unwind_Ptr;
+#endif
+
 typedef enum {
   _URC_NO_REASON = 0,
   _URC_OK = 0,
@@ -111,7 +137,7 @@
_Unwind_Exception* exceptionObject,
struct _Unwind_Context* context);
 
-typedef _Unwind_Reason_Code (*__personality_routine)
+typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
   (_Unwind_State state,
_Unwind_Exception* exceptionObject,
struct _Unwind_Context* context);
@@ -150,13 +176,14 @@
  struct _Unwind_Context* context,
  void* stop_parameter );
 
-typedef _Unwind_Reason_Code (*__personality_routine)
+typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
   (int version,
_Unwind_Action actions,
uint64_t exceptionClass,
_Unwind_Exception* exceptionObject,
struct _Unwind_Context* context);
 #endif
+typedef _Unwind_Personality_Fn __personality_routine;
 
 #ifdef __cplusplus
 extern "C" {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50448: [CGObjCGNU] Rename GetSelector helper method to fix -Woverloaded-virtual warning (PR38210)

2018-08-08 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339264: [CGObjCGNU] Rename GetSelector helper method to fix 
-Woverloaded-virtual… (authored by RKSimon, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50448?vs=159709&id=159732#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50448

Files:
  cfe/trunk/lib/CodeGen/CGObjCGNU.cpp


Index: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
@@ -510,8 +510,8 @@
 
   /// Returns a selector with the specified type encoding.  An empty string is
   /// used to return an untyped selector (with the types field set to NULL).
-  virtual llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-   const std::string &TypeEncoding);
+  virtual llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding);
 
   /// Returns the name of ivar offset variables.  In the GNUstep v1 ABI, this
   /// contains the class and ivar names, in the v2 ABI this contains the type
@@ -1342,8 +1342,8 @@
   return Val;
 return llvm::ConstantExpr::getBitCast(Val, Ty);
   }
-  llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) override {
+  llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding) override {
 return GetConstantSelector(Sel, TypeEncoding);
   }
   llvm::Constant  *GetTypeString(llvm::StringRef TypeEncoding) {
@@ -2121,8 +2121,8 @@
   return Value;
 }
 
-llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) {
+llvm::Value *CGObjCGNU::GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+ const std::string &TypeEncoding) {
   SmallVectorImpl &Types = SelectorTable[Sel];
   llvm::GlobalAlias *SelValue = nullptr;
 
@@ -2155,13 +2155,13 @@
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel) {
-  return GetSelector(CGF, Sel, std::string());
+  return GetTypedSelector(CGF, Sel, std::string());
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF,
 const ObjCMethodDecl *Method) {
   std::string SelTypes = CGM.getContext().getObjCEncodingForMethodDecl(Method);
-  return GetSelector(CGF, Method->getSelector(), SelTypes);
+  return GetTypedSelector(CGF, Method->getSelector(), SelTypes);
 }
 
 llvm::Constant *CGObjCGNU::GetEHType(QualType T) {


Index: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
@@ -510,8 +510,8 @@
 
   /// Returns a selector with the specified type encoding.  An empty string is
   /// used to return an untyped selector (with the types field set to NULL).
-  virtual llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-   const std::string &TypeEncoding);
+  virtual llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding);
 
   /// Returns the name of ivar offset variables.  In the GNUstep v1 ABI, this
   /// contains the class and ivar names, in the v2 ABI this contains the type
@@ -1342,8 +1342,8 @@
   return Val;
 return llvm::ConstantExpr::getBitCast(Val, Ty);
   }
-  llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) override {
+  llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding) override {
 return GetConstantSelector(Sel, TypeEncoding);
   }
   llvm::Constant  *GetTypeString(llvm::StringRef TypeEncoding) {
@@ -2121,8 +2121,8 @@
   return Value;
 }
 
-llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) {
+llvm::Value *CGObjCGNU::GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+ const std::string &TypeEncoding) {
   SmallVectorImpl &Types = SelectorTable[Sel];
   llvm::GlobalAlias *SelValue = nullptr;
 
@@ -2155,13 +2155,13 @@
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel) {
-  return GetSelector(CGF, Sel, std::string());
+  return GetTypedSelector(CGF, Sel, std::string());
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF,
 const ObjCMethodDecl *Method) {
   std::string SelTypes = CGM.getContext().getObjCEncodingForMethodDecl(Method);
-  return GetSelector(CGF, Method->getSelector(), SelTypes);
+  

r339264 - [CGObjCGNU] Rename GetSelector helper method to fix -Woverloaded-virtual warning (PR38210)

2018-08-08 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Aug  8 08:53:14 2018
New Revision: 339264

URL: http://llvm.org/viewvc/llvm-project?rev=339264&view=rev
Log:
[CGObjCGNU] Rename GetSelector helper method to fix -Woverloaded-virtual 
warning (PR38210)

As suggested by @theraven on PR38210, this patch fixes the gcc 
-Woverloaded-virtual warnings by renaming the extra CGObjCGNU::GetSelector 
method to CGObjCGNU::GetTypedSelector

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

Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=339264&r1=339263&r2=339264&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Aug  8 08:53:14 2018
@@ -510,8 +510,8 @@ protected:
 
   /// Returns a selector with the specified type encoding.  An empty string is
   /// used to return an untyped selector (with the types field set to NULL).
-  virtual llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-   const std::string &TypeEncoding);
+  virtual llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding);
 
   /// Returns the name of ivar offset variables.  In the GNUstep v1 ABI, this
   /// contains the class and ivar names, in the v2 ABI this contains the type
@@ -1342,8 +1342,8 @@ class CGObjCGNUstep2 : public CGObjCGNUs
   return Val;
 return llvm::ConstantExpr::getBitCast(Val, Ty);
   }
-  llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) override {
+  llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+const std::string &TypeEncoding) override {
 return GetConstantSelector(Sel, TypeEncoding);
   }
   llvm::Constant  *GetTypeString(llvm::StringRef TypeEncoding) {
@@ -2121,8 +2121,8 @@ llvm::Value *CGObjCGNU::EmitNSAutoreleas
   return Value;
 }
 
-llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel,
-const std::string &TypeEncoding) {
+llvm::Value *CGObjCGNU::GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
+ const std::string &TypeEncoding) {
   SmallVectorImpl &Types = SelectorTable[Sel];
   llvm::GlobalAlias *SelValue = nullptr;
 
@@ -2155,13 +2155,13 @@ Address CGObjCGNU::GetAddrOfSelector(Cod
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF, Selector Sel) {
-  return GetSelector(CGF, Sel, std::string());
+  return GetTypedSelector(CGF, Sel, std::string());
 }
 
 llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF,
 const ObjCMethodDecl *Method) {
   std::string SelTypes = CGM.getContext().getObjCEncodingForMethodDecl(Method);
-  return GetSelector(CGF, Method->getSelector(), SelTypes);
+  return GetTypedSelector(CGF, Method->getSelector(), SelTypes);
 }
 
 llvm::Constant *CGObjCGNU::GetEHType(QualType T) {


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


Re: [PATCH] D50154: [clangd] capitalize diagnostic messages

2018-08-08 Thread David Blaikie via cfe-commits
On Wed, Aug 8, 2018 at 5:00 AM Ilya Biryukov via Phabricator <
revi...@reviews.llvm.org> wrote:

> ilya-biryukov added a comment.
>
> In https://reviews.llvm.org/D50154#1191002, @dblaikie wrote:
>
> > What's the motivation for clangd to differ from clang here?
>
>
> The presentation of diagnostics to the users is different between clang
> and clangd:
>
> - clang diagnostics are always prefixed with the file, location and
> severity of the diagnostic, e.g. `main.cpp:1:2: error: expected '}'`
>

*nod* That's a fairly natural one - and I assume the information is
provided semantically - source, line, column, and text. A client can stitch
them together as clang does or it can render the information some other way
(by placing the text as a mouseover/popup at the source location). I don't
see that as a divergence - but providing the full fidelity of the
information (rather than prematurely stringifying it all together) &
leaving it up to the client to decide how to render it to the user.


> - In LSP clients (VSCode in particular), the diagnostic message is the
> first thing the user sees and it looks a little nicer (subjectively) if the
> first letter is capitalized.
>

It looks nicer in VSCode because that's the UI convention for mouseover
text (in Windows, at least) - first letter capitalized. But it seems hard
to me to generalize from there to all or most LSP clients. (& I also worry
that such a mechanical transformation might be erroneous in some messages)

(well, there's at least one case where reversing this would fail - there's
a diagnostic in Clang that starts with "ISO" - so uppercasing does nothing,
but lowercasing it to try to get back to the original would result in "iSO"
- several others like "Objective-C", "Neon", "GCC", etc)

(also, there's one that this will mangle: "ms_struct may not produce
Microsoft-compatible layouts" - I assume capitalizing "ms_struct" would be
incorrect (though arguably/mostly identifiers like that are quoted in error
messages - and that may be reasonable/correct/better to do that here).
Similar use of 'sizeof' at the start of a diagnostic, 'os_log()', -
those'll be an issue no matter where the implementation is (in clangd or
its client(s)) though - short of having a more customized thing in the
diagnostics table itself to record which things can be capitalized/how they
should be capitalized - but, yeah, arguably quoting might be the right
thing in many, maybe all, of those cases)




>
> See the screenshots from VSCode on how diagnostics are presented:
> F6901986: image.png  F6901990:
> image.png 
>
>
> Repository:
>   rCTE Clang Tools Extra
>
> https://reviews.llvm.org/D50154
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-08 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339265: [DebugInfo][OpenCL] Address post-commit review for 
r338299 (authored by scott.linder, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50099?vs=159512&id=159734#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50099

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/test/CodeGenOpenCL/blocks.cl

Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h
@@ -311,6 +311,22 @@
   void AppendAddressSpaceXDeref(unsigned AddressSpace,
 SmallVectorImpl &Expr) const;
 
+  /// A helper function to collect debug info for the default elements of a
+  /// block.
+  ///
+  /// \returns The next available field offset after the default elements.
+  uint64_t collectDefaultElementTypesForBlockPointer(
+  const BlockPointerType *Ty, llvm::DIFile *Unit,
+  llvm::DIDerivedType *DescTy, unsigned LineNo,
+  SmallVectorImpl &EltTys);
+
+  /// A helper function to collect debug info for the default fields of a
+  /// block.
+  void collectDefaultFieldsForBlockLiteralDeclare(
+  const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
+  const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
+  SmallVectorImpl &Fields);
+
 public:
   CGDebugInfo(CodeGenModule &CGM);
   ~CGDebugInfo();
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -942,12 +942,47 @@
   return Cache;
 }
 
+uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
+const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
+unsigned LineNo, SmallVectorImpl &EltTys) {
+  QualType FType;
+
+  // Advanced by calls to CreateMemberType in increments of FType, then
+  // returned as the overall size of the default elements.
+  uint64_t FieldOffset = 0;
+
+  // Blocks in OpenCL have unique constraints which make the standard fields
+  // redundant while requiring size and align fields for enqueue_kernel. See
+  // initializeForBlockHeader in CGBlocks.cpp
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
+uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
+EltTys.push_back(DBuilder.createMemberType(
+Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign,
+FieldOffset, llvm::DINode::FlagZero, DescTy));
+FieldOffset += FieldSize;
+  }
+
+  return FieldOffset;
+}
+
 llvm::DIType *CGDebugInfo::CreateType(const BlockPointerType *Ty,
   llvm::DIFile *Unit) {
   SmallVector EltTys;
   QualType FType;
-  uint64_t FieldSize, FieldOffset;
-  uint32_t FieldAlign;
+  uint64_t FieldOffset;
   llvm::DINodeArray Elements;
 
   FieldOffset = 0;
@@ -959,46 +994,26 @@
   EltTys.clear();
 
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
-  unsigned LineNo = 0;
 
   auto *EltTy =
-  DBuilder.createStructType(Unit, "__block_descriptor", nullptr, LineNo,
+  DBuilder.createStructType(Unit, "__block_descriptor", nullptr, 0,
 FieldOffset, 0, Flags, nullptr, Elements);
 
   // Bit size, align and offset of the type.
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
 
   auto *DescTy = DBuilder.createPointerType(EltTy, Size);
 
-  FieldOffset = 0;
-  if (CGM.getLangOpts().OpenCL) {
-FType = CGM.getContext().IntTy;
-EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
-EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
-  } else {
-FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
-FType = CGM.getContext().IntTy;
-EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
-EltTys.push_back(Cre

r339265 - [DebugInfo][OpenCL] Address post-commit review for r338299

2018-08-08 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Wed Aug  8 08:56:12 2018
New Revision: 339265

URL: http://llvm.org/viewvc/llvm-project?rev=339265&view=rev
Log:
[DebugInfo][OpenCL] Address post-commit review for r338299

NFC refactor of code to generate debug info for OpenCL 2.X blocks.

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

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/test/CodeGenOpenCL/blocks.cl

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=339265&r1=339264&r2=339265&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Aug  8 08:56:12 2018
@@ -942,12 +942,47 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
   return Cache;
 }
 
+uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
+const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType 
*DescTy,
+unsigned LineNo, SmallVectorImpl &EltTys) {
+  QualType FType;
+
+  // Advanced by calls to CreateMemberType in increments of FType, then
+  // returned as the overall size of the default elements.
+  uint64_t FieldOffset = 0;
+
+  // Blocks in OpenCL have unique constraints which make the standard fields
+  // redundant while requiring size and align fields for enqueue_kernel. See
+  // initializeForBlockHeader in CGBlocks.cpp
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", 
&FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
+uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
+EltTys.push_back(DBuilder.createMemberType(
+Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign,
+FieldOffset, llvm::DINode::FlagZero, DescTy));
+FieldOffset += FieldSize;
+  }
+
+  return FieldOffset;
+}
+
 llvm::DIType *CGDebugInfo::CreateType(const BlockPointerType *Ty,
   llvm::DIFile *Unit) {
   SmallVector EltTys;
   QualType FType;
-  uint64_t FieldSize, FieldOffset;
-  uint32_t FieldAlign;
+  uint64_t FieldOffset;
   llvm::DINodeArray Elements;
 
   FieldOffset = 0;
@@ -959,10 +994,9 @@ llvm::DIType *CGDebugInfo::CreateType(co
   EltTys.clear();
 
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
-  unsigned LineNo = 0;
 
   auto *EltTy =
-  DBuilder.createStructType(Unit, "__block_descriptor", nullptr, LineNo,
+  DBuilder.createStructType(Unit, "__block_descriptor", nullptr, 0,
 FieldOffset, 0, Flags, nullptr, Elements);
 
   // Bit size, align and offset of the type.
@@ -970,27 +1004,8 @@ llvm::DIType *CGDebugInfo::CreateType(co
 
   auto *DescTy = DBuilder.createPointerType(EltTy, Size);
 
-  FieldOffset = 0;
-  if (CGM.getLangOpts().OpenCL) {
-FType = CGM.getContext().IntTy;
-EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
-EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
-  } else {
-FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
-FType = CGM.getContext().IntTy;
-EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
-EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", 
&FieldOffset));
-FType = CGM.getContext().getPointerType(Ty->getPointeeType());
-EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
-FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-FieldSize = CGM.getContext().getTypeSize(Ty);
-FieldAlign = CGM.getContext().getTypeAlign(Ty);
-EltTys.push_back(DBuilder.createMemberType(
-Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign, 
FieldOffset,
-llvm::DINode::FlagZero, DescTy));
-FieldOffset += FieldSize;
-  }
+  FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
+  0, EltTys);
 
   Elements = DBuilder.getOrCreateArray(EltTys);
 
@@ -998,7 +1013,7 @@ llvm::DIType *CGDebugInfo::CreateType(co
   // DW_AT_APPLE_BLOC

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

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

@Hahnfeld do you get the same error if you compile with clang++ instead of 
clang?


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


  1   2   >