r339164 - [VFS] Emit an error when entry at root level uses a relative path.

2018-08-07 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Aug  7 12:05:41 2018
New Revision: 339164

URL: http://llvm.org/viewvc/llvm-project?rev=339164&view=rev
Log:
[VFS] Emit an error when entry at root level uses a relative path.

Entries with only a filename prevent us from building a file system tree and
cause the assertion

> Assertion failed: (NewParentE && "Parent entry must exist"), function 
> uniqueOverlayTree, file clang/lib/Basic/VirtualFileSystem.cpp, line 1303.

Entries with a relative path are simply not discoverable during header search.

rdar://problem/28990865

Reviewers: bruno, benlangmuir

Reviewed By: bruno

Subscribers: dexonsmith, cfe-commits

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


Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=339164&r1=339163&r2=339164&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Aug  7 12:05:41 2018
@@ -1281,7 +1281,8 @@ class RedirectingFileSystemParser {
 }
   }
 
-  std::unique_ptr parseEntry(yaml::Node *N, RedirectingFileSystem *FS) {
+  std::unique_ptr parseEntry(yaml::Node *N, RedirectingFileSystem *FS,
+bool IsRootEntry) {
 auto *M = dyn_cast(N);
 if (!M) {
   error(N, "expected mapping node for file or directory entry");
@@ -1302,6 +1303,7 @@ class RedirectingFileSystemParser {
 std::vector> EntryArrayContents;
 std::string ExternalContentsPath;
 std::string Name;
+yaml::Node *NameValueNode;
 auto UseExternalName = RedirectingFileEntry::NK_NotSet;
 EntryKind Kind;
 
@@ -1321,6 +1323,7 @@ class RedirectingFileSystemParser {
 if (!parseScalarString(I.getValue(), Value, Buffer))
   return nullptr;
 
+NameValueNode = I.getValue();
 if (FS->UseCanonicalizedPaths) {
   SmallString<256> Path(Value);
   // Guarantee that old YAML files containing paths with ".." and "."
@@ -1357,7 +1360,8 @@ class RedirectingFileSystemParser {
 }
 
 for (auto &I : *Contents) {
-  if (std::unique_ptr E = parseEntry(&I, FS))
+  if (std::unique_ptr E =
+  parseEntry(&I, FS, /*IsRootEntry*/ false))
 EntryArrayContents.push_back(std::move(E));
   else
 return nullptr;
@@ -1418,6 +1422,13 @@ class RedirectingFileSystemParser {
   return nullptr;
 }
 
+if (IsRootEntry && !sys::path::is_absolute(Name)) {
+  assert(NameValueNode && "Name presence should be checked earlier");
+  error(NameValueNode,
+"entry with relative path at the root level is not discoverable");
+  return nullptr;
+}
+
 // Remove trailing slash(es), being careful not to remove the root path
 StringRef Trimmed(Name);
 size_t RootPathLen = sys::path::root_path(Trimmed).size();
@@ -1500,7 +1511,8 @@ public:
 }
 
 for (auto &I : *Roots) {
-  if (std::unique_ptr E = parseEntry(&I, FS))
+  if (std::unique_ptr E =
+  parseEntry(&I, FS, /*IsRootEntry*/ true))
 RootEntries.push_back(std::move(E));
   else
 return false;

Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=339164&r1=339163&r2=339164&view=diff
==
--- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original)
+++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Tue Aug  7 12:05:41 2018
@@ -1468,3 +1468,35 @@ TEST_F(VFSFromYAMLTest, RecursiveDirecto
   }
   EXPECT_EQ(I, E);
 }
+
+TEST_F(VFSFromYAMLTest, RelativePaths) {
+  IntrusiveRefCntPtr Lower(new DummyFileSystem());
+  // Filename at root level without a parent directory.
+  IntrusiveRefCntPtr FS = getFromYAMLString(
+  "{ 'roots': [\n"
+  "  { 'type': 'file', 'name': 'file-not-in-directory.h',\n"
+  "'external-contents': '//root/external/file'\n"
+  "  }\n"
+  "] }", Lower);
+  EXPECT_EQ(nullptr, FS.get());
+
+  // Relative file path.
+  FS = getFromYAMLString(
+  "{ 'roots': [\n"
+  "  { 'type': 'file', 'name': 'relative/file/path.h',\n"
+  "'external-contents': '//root/external/file'\n"
+  "  }\n"
+  "] }", Lower);
+  EXPECT_EQ(nullptr, FS.get());
+
+  // Relative directory path.
+  FS = getFromYAMLString(
+   "{ 'roots': [\n"
+   "  { 'type': 'directory', 'name': 'relative/directory/path.h',\n"
+   "'contents': []\n"
+   "  }\n"
+   "] }", Lower);
+  EXPECT_EQ(nullptr, FS.get());
+
+  EXPECT_EQ(3, NumDiagnostics);
+}


___
cfe-commits mai

r339199 - [VFS] Unify iteration code for VFSFromYamlDirIterImpl, NFC intended.

2018-08-07 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Aug  7 16:00:40 2018
New Revision: 339199

URL: http://llvm.org/viewvc/llvm-project?rev=339199&view=rev
Log:
[VFS] Unify iteration code for VFSFromYamlDirIterImpl, NFC intended.

First and subsequent iteration steps are similar, capture this similarity.

Reviewers: bruno, benlangmuir

Reviewed By: bruno

Subscribers: dexonsmith, cfe-commits

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


Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=339199&r1=339198&r2=339199&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Aug  7 16:00:40 2018
@@ -933,6 +933,8 @@ class VFSFromYamlDirIterImpl : public cl
   RedirectingFileSystem &FS;
   RedirectingDirectoryEntry::iterator Current, End;
 
+  std::error_code incrementImpl();
+
 public:
   VFSFromYamlDirIterImpl(const Twine &Path, RedirectingFileSystem &FS,
  RedirectingDirectoryEntry::iterator Begin,
@@ -1997,29 +1999,17 @@ VFSFromYamlDirIterImpl::VFSFromYamlDirIt
 RedirectingDirectoryEntry::iterator Begin,
 RedirectingDirectoryEntry::iterator End, std::error_code &EC)
 : Dir(_Path.str()), FS(FS), Current(Begin), End(End) {
-  while (Current != End) {
-SmallString<128> PathStr(Dir);
-llvm::sys::path::append(PathStr, (*Current)->getName());
-llvm::ErrorOr S = FS.status(PathStr);
-if (S) {
-  CurrentEntry = *S;
-  return;
-}
-// Skip entries which do not map to a reliable external content.
-if (FS.ignoreNonExistentContents() &&
-S.getError() == llvm::errc::no_such_file_or_directory) {
-  ++Current;
-  continue;
-} else {
-  EC = S.getError();
-  break;
-}
-  }
+  EC = incrementImpl();
 }
 
 std::error_code VFSFromYamlDirIterImpl::increment() {
   assert(Current != End && "cannot iterate past end");
-  while (++Current != End) {
+  ++Current;
+  return incrementImpl();
+}
+
+std::error_code VFSFromYamlDirIterImpl::incrementImpl() {
+  while (Current != End) {
 SmallString<128> PathStr(Dir);
 llvm::sys::path::append(PathStr, (*Current)->getName());
 llvm::ErrorOr S = FS.status(PathStr);
@@ -2027,6 +2017,7 @@ std::error_code VFSFromYamlDirIterImpl::
   // Skip entries which do not map to a reliable external content.
   if (FS.ignoreNonExistentContents() &&
   S.getError() == llvm::errc::no_such_file_or_directory) {
+++Current;
 continue;
   } else {
 return S.getError();


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


r339215 - [NFC][VFS] Fix typos in comments.

2018-08-07 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Aug  7 18:28:37 2018
New Revision: 339215

URL: http://llvm.org/viewvc/llvm-project?rev=339215&view=rev
Log:
[NFC][VFS] Fix typos in comments.

Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=339215&r1=339214&r2=339215&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Aug  7 18:28:37 2018
@@ -990,7 +990,7 @@ public:
 ///   'type': 'file',
 ///   'name': ,
 ///   'use-external-name':  # Optional
-///   'external-contents': )
+///   'external-contents': 
 /// }
 /// \endverbatim
 ///
@@ -1021,7 +1021,7 @@ class RedirectingFileSystem : public vfs
   /// Currently, case-insensitive matching only works correctly with ASCII.
   bool CaseSensitive = true;
 
-  /// IsRelativeOverlay marks whether a IsExternalContentsPrefixDir path must
+  /// IsRelativeOverlay marks whether a ExternalContentsPrefixDir path must
   /// be prefixed in every 'external-contents' when reading from YAML files.
   bool IsRelativeOverlay = false;
 


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


[libcxx] r339451 - [libcxx] Mark charconv tests as failing for previous libcxx versions.

2018-08-10 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Aug 10 10:03:47 2018
New Revision: 339451

URL: http://llvm.org/viewvc/llvm-project?rev=339451&view=rev
Log:
[libcxx] Mark charconv tests as failing for previous libcxx versions.

 was added in r338479. Previous libcxx versions don't have
this functionality and corresponding tests should be failing.

Reviewers: mclow.lists, ldionne, EricWF

Reviewed By: ldionne

Subscribers: christof, dexonsmith, lichray, EricWF, cfe-commits

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

Modified:

libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp?rev=339451&r1=339450&r2=339451&view=diff
==
--- 
libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp 
Fri Aug 10 10:03:47 2018
@@ -8,6 +8,15 @@
 
//===--===//
 
 // UNSUPPORTED: c++98, c++03, c++11
+
+// XFAIL: with_system_cxx_lib=macosx10.13
+// XFAIL: with_system_cxx_lib=macosx10.12
+// XFAIL: with_system_cxx_lib=macosx10.11
+// XFAIL: with_system_cxx_lib=macosx10.10
+// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: with_system_cxx_lib=macosx10.8
+// XFAIL: with_system_cxx_lib=macosx10.7
+
 // 
 
 // from_chars_result from_chars(const char* first, const char* last,

Modified: 
libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp?rev=339451&r1=339450&r2=339451&view=diff
==
--- 
libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp 
Fri Aug 10 10:03:47 2018
@@ -8,6 +8,15 @@
 
//===--===//
 
 // UNSUPPORTED: c++98, c++03, c++11
+
+// XFAIL: with_system_cxx_lib=macosx10.13
+// XFAIL: with_system_cxx_lib=macosx10.12
+// XFAIL: with_system_cxx_lib=macosx10.11
+// XFAIL: with_system_cxx_lib=macosx10.10
+// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: with_system_cxx_lib=macosx10.8
+// XFAIL: with_system_cxx_lib=macosx10.7
+
 // 
 
 // to_chars_result to_chars(char* first, char* last, Integral value,


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


[libcxx] r331818 - Revert "Emit an error when mixing and "

2018-05-08 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue May  8 15:50:35 2018
New Revision: 331818

URL: http://llvm.org/viewvc/llvm-project?rev=331818&view=rev
Log:
Revert "Emit an error when mixing  and "

It reverts commit r331379 because turned out `__ALLOW_STDC_ATOMICS_IN_CXX__`
doesn't work well in practice.

Removed:
libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp
Modified:
libcxx/trunk/include/atomic

Modified: libcxx/trunk/include/atomic
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=331818&r1=331817&r2=331818&view=diff
==
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Tue May  8 15:50:35 2018
@@ -555,9 +555,6 @@ void atomic_signal_fence(memory_order m)
 #if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
 #error  is not implemented
 #endif
-#ifdef __ALLOW_STDC_ATOMICS_IN_CXX__
-#error  is incompatible with the C++ standard library
-#endif
 
 #if _LIBCPP_STD_VER > 14
 # define __cpp_lib_atomic_is_always_lock_free 201603L

Removed: libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp?rev=331817&view=auto
==
--- libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp (original)
+++ libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp (removed)
@@ -1,28 +0,0 @@
-//===--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-//
-// UNSUPPORTED: libcpp-has-no-threads
-//
-// 
-
-// Test that including  fails to compile when we want to use C atomics
-// in C++ and have corresponding macro defined.
-
-// MODULES_DEFINES: __ALLOW_STDC_ATOMICS_IN_CXX__
-#ifndef __ALLOW_STDC_ATOMICS_IN_CXX__
-#define __ALLOW_STDC_ATOMICS_IN_CXX__
-#endif
-
-#include 
-// expected-error@atomic:* {{ is incompatible with the C++ 
standard library}}
-
-int main()
-{
-}
-


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


[libcxx] r332282 - Update XFAIL so apple-clang-9.0 is the last version not implementing Core 2094.

2018-05-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon May 14 12:45:24 2018
New Revision: 332282

URL: http://llvm.org/viewvc/llvm-project?rev=332282&view=rev
Log:
Update XFAIL so apple-clang-9.0 is the last version not implementing Core 2094.

The test is passing with apple-clang-9.1. rdar://problem/40222003

Modified:

libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp?rev=332282&r1=332281&r2=332282&view=diff
==
--- 
libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp
 Mon May 14 12:45:24 2018
@@ -13,7 +13,7 @@
 
 // These compilers have not implemented Core 2094 which makes volatile
 // qualified types trivially copyable.
-// XFAIL: clang-3, clang-4, apple-clang, gcc
+// XFAIL: clang-3, clang-4, apple-clang-6, apple-clang-7, apple-clang-8, 
apple-clang-9.0, gcc
 
 #include 
 #include 


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


r332307 - [c++17] Fix assertion on synthesizing deduction guides after a fatal error.

2018-05-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon May 14 15:49:44 2018
New Revision: 332307

URL: http://llvm.org/viewvc/llvm-project?rev=332307&view=rev
Log:
[c++17] Fix assertion on synthesizing deduction guides after a fatal error.

After a fatal error Sema::InstantiatingTemplate doesn't allow further
instantiation and doesn't push a CodeSynthesisContext. When we tried to
synthesize implicit deduction guides from constructors we hit the
assertion

> Assertion failed: (!CodeSynthesisContexts.empty() && "Cannot perform an 
> instantiation without some context on the " "instantiation stack"), function 
> SubstType, file clang/lib/Sema/SemaTemplateInstantiate.cpp, line 1580.

Fix by avoiding deduction guide synthesis if InstantiatingTemplate is invalid.

rdar://problem/39051732

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=332307&r1=332306&r2=332307&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon May 14 15:49:44 2018
@@ -1976,6 +1976,8 @@ void Sema::DeclareImplicitDeductionGuide
   // FIXME: Add a kind for this to give more meaningful diagnostics. But can
   // this substitution process actually fail?
   InstantiatingTemplate BuildingDeductionGuides(*this, Loc, Template);
+  if (BuildingDeductionGuides.isInvalid())
+return;
 
   // Convert declared constructors into deduction guide templates.
   // FIXME: Skip constructors for which deduction must necessarily fail (those

Added: cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp?rev=332307&view=auto
==
--- cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-after-fatal-cxx17.cpp Mon May 14 
15:49:44 2018
@@ -0,0 +1,16 @@
+// RUN: not %clang_cc1 -std=c++17 -fsyntax-only -ferror-limit 1 %s 2>&1 | 
FileCheck %s
+
+#error Error 1
+#error Error 2
+// CHECK: fatal error: too many errors emitted, stopping now
+
+namespace rdar39051732 {
+
+  template struct A {
+template  A(T&, ...);
+  };
+  // Deduction guide triggers constructor instantiation.
+  template A(const T&, const T&) -> A;
+
+}
+


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


[libcxx] r332413 - Emit an error when include after

2018-05-15 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue May 15 15:38:31 2018
New Revision: 332413

URL: http://llvm.org/viewvc/llvm-project?rev=332413&view=rev
Log:
Emit an error when include  after 

C11 defines `kill_dependency` as a macro in . When you
include  after , the macro clashes with
`std::kill_dependency` and causes multiple errors. Explicit error should
help in diagnosing those errors.

No change for working code that includes  before .

rdar://problem/27435938

Reviewers: rsmith, EricWF, mclow.lists, jfb

Reviewed By: jfb

Subscribers: jfb, jkorous-apple, christof, bumblebritches57, JonChesterfield, 
smeenai, cfe-commits

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


Modified:
libcxx/trunk/include/atomic

Modified: libcxx/trunk/include/atomic
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=332413&r1=332412&r2=332413&view=diff
==
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Tue May 15 15:38:31 2018
@@ -555,6 +555,9 @@ void atomic_signal_fence(memory_order m)
 #if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
 #error  is not implemented
 #endif
+#ifdef kill_dependency
+#error C++ standard library is incompatible with 
+#endif
 
 #if _LIBCPP_STD_VER > 14
 # define __cpp_lib_atomic_is_always_lock_free 201603L


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


r332509 - [Sema] Fix assertion when constructor is disabled with partially specialized template.

2018-05-16 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed May 16 11:28:58 2018
New Revision: 332509

URL: http://llvm.org/viewvc/llvm-project?rev=332509&view=rev
Log:
[Sema] Fix assertion when constructor is disabled with partially specialized 
template.

The added test case was triggering assertion

> Assertion failed: 
> (!SpecializedTemplate.is() && "Already set 
> to a class template partial specialization!"), function setInstantiationOf, 
> file clang/include/clang/AST/DeclTemplate.h, line 1825.

It was happening with ClassTemplateSpecializationDecl
`enable_if_not_same`. Because this template is specialized for
equal types not to have a definition, it wasn't instantiated and its
specialization kind remained TSK_Undeclared. And because it was implicit
instantiation, we didn't mark the decl as invalid. So when we try to
find the best matching partial specialization the second time, we hit
the assertion as partial specialization is already set.

Fix by reusing stored partial specialization when available, instead of
looking for the best match every time.

rdar://problem/39524996

Reviewers: rsmith, arphaman

Reviewed By: rsmith

Subscribers: cfe-commits

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


Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaTemplate/partial-spec-instantiate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=332509&r1=332508&r2=332509&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed May 16 11:28:58 2018
@@ -2398,127 +2398,137 @@ getPatternForClassTemplateSpecialization
   if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
 return nullptr;
 
-  ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
-  CXXRecordDecl *Pattern = nullptr;
-
-  // C++ [temp.class.spec.match]p1:
-  //   When a class template is used in a context that requires an
-  //   instantiation of the class, it is necessary to determine
-  //   whether the instantiation is to be generated using the primary
-  //   template or one of the partial specializations. This is done by
-  //   matching the template arguments of the class template
-  //   specialization with the template argument lists of the partial
-  //   specializations.
-  typedef PartialSpecMatchResult MatchResult;
-  SmallVector Matched;
-  SmallVector PartialSpecs;
-  Template->getPartialSpecializations(PartialSpecs);
-  TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation);
-  for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
-ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I];
-TemplateDeductionInfo Info(FailedCandidates.getLocation());
-if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments(
-Partial, ClassTemplateSpec->getTemplateArgs(), Info)) {
-  // Store the failed-deduction information for use in diagnostics, later.
-  // TODO: Actually use the failed-deduction info?
-  FailedCandidates.addCandidate().set(
-  DeclAccessPair::make(Template, AS_public), Partial,
-  MakeDeductionFailureInfo(S.Context, Result, Info));
-  (void)Result;
-} else {
-  Matched.push_back(PartialSpecMatchResult());
-  Matched.back().Partial = Partial;
-  Matched.back().Args = Info.take();
+  llvm::PointerUnion
+  Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
+  if (!Specialized.is()) {
+// Find best matching specialization.
+ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
+
+// C++ [temp.class.spec.match]p1:
+//   When a class template is used in a context that requires an
+//   instantiation of the class, it is necessary to determine
+//   whether the instantiation is to be generated using the primary
+//   template or one of the partial specializations. This is done by
+//   matching the template arguments of the class template
+//   specialization with the template argument lists of the partial
+//   specializations.
+typedef PartialSpecMatchResult MatchResult;
+SmallVector Matched;
+SmallVector PartialSpecs;
+Template->getPartialSpecializations(PartialSpecs);
+TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation);
+for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
+  ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I];
+  TemplateDeductionInfo Info(FailedCandidates.getLocation());
+  if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments(
+  Partial, ClassTemplateSpec->getTemplateArgs(), Info)) {
+// Store the failed-deduction information for use in diagnostics, 
later.
+// TODO: Actually use the failed-deduction info?
+FailedCandidates.ad

[libcxx] r333011 - [libcxx] [test] Mark the test as unsupported by apple-clang-8.1.

2018-05-22 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue May 22 11:46:16 2018
New Revision: 333011

URL: http://llvm.org/viewvc/llvm-project?rev=333011&view=rev
Log:
[libcxx] [test] Mark the test as unsupported by apple-clang-8.1.

Modified:

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp?rev=333011&r1=333010&r2=333011&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 Tue May 22 11:46:16 2018
@@ -10,7 +10,7 @@
 // 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang-4.0
-// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0, apple-clang-9
+// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9
 
 // template::value_type>>


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


r314473 - [Sema] Put nullability fix-it after the end of the pointer.

2017-09-28 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Sep 28 16:18:49 2017
New Revision: 314473

URL: http://llvm.org/viewvc/llvm-project?rev=314473&view=rev
Log:
[Sema] Put nullability fix-it after the end of the pointer.

Fixes nullability fix-it for `id`. With this change
nullability specifier is inserted after ">" instead of between
"id" and "<".

rdar://problem/34260995

Reviewers: jordan_rose, doug.gregor, ahatanak, arphaman

Reviewed By: jordan_rose

Subscribers: cfe-commits

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


Added:
cfe/trunk/test/FixIt/Inputs/nullability-objc.h
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/FixIt/nullability.mm
cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-2.h

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=314473&r1=314472&r2=314473&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Sep 28 16:18:49 2017
@@ -229,6 +229,10 @@ struct FileNullability {
   /// not have a corresponding nullability annotation.
   SourceLocation PointerLoc;
 
+  /// The end location for the first pointer declarator in the file. Used for
+  /// placing fix-its.
+  SourceLocation PointerEndLoc;
+
   /// Which kind of pointer declarator we saw.
   uint8_t PointerKind;
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=314473&r1=314472&r2=314473&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Sep 28 16:18:49 2017
@@ -3500,7 +3500,8 @@ static void fixItNullability(Sema &S, Di
 
 static void emitNullabilityConsistencyWarning(Sema &S,
   SimplePointerKind PointerKind,
-  SourceLocation PointerLoc) {
+  SourceLocation PointerLoc,
+  SourceLocation PointerEndLoc) {
   assert(PointerLoc.isValid());
 
   if (PointerKind == SimplePointerKind::Array) {
@@ -3510,14 +3511,15 @@ static void emitNullabilityConsistencyWa
   << static_cast(PointerKind);
   }
 
-  if (PointerLoc.isMacroID())
+  auto FixItLoc = PointerEndLoc.isValid() ? PointerEndLoc : PointerLoc;
+  if (FixItLoc.isMacroID())
 return;
 
   auto addFixIt = [&](NullabilityKind Nullability) {
-auto Diag = S.Diag(PointerLoc, diag::note_nullability_fix_it);
+auto Diag = S.Diag(FixItLoc, diag::note_nullability_fix_it);
 Diag << static_cast(Nullability);
 Diag << static_cast(PointerKind);
-fixItNullability(S, Diag, PointerLoc, Nullability);
+fixItNullability(S, Diag, FixItLoc, Nullability);
   };
   addFixIt(NullabilityKind::Nullable);
   addFixIt(NullabilityKind::NonNull);
@@ -3529,9 +3531,10 @@ static void emitNullabilityConsistencyWa
 ///
 /// If the file has \e not seen other uses of nullability, this particular
 /// pointer is saved for possible later diagnosis. See recordNullabilitySeen().
-static void checkNullabilityConsistency(Sema &S,
-SimplePointerKind pointerKind,
-SourceLocation pointerLoc) {
+static void
+checkNullabilityConsistency(Sema &S, SimplePointerKind pointerKind,
+SourceLocation pointerLoc,
+SourceLocation pointerEndLoc = SourceLocation()) {
   // Determine which file we're performing consistency checking for.
   FileID file = getNullabilityCompletenessCheckFileID(S, pointerLoc);
   if (file.isInvalid())
@@ -3552,6 +3555,7 @@ static void checkNullabilityConsistency(
 if (fileNullability.PointerLoc.isInvalid() &&
 !S.Context.getDiagnostics().isIgnored(diagKind, pointerLoc)) {
   fileNullability.PointerLoc = pointerLoc;
+  fileNullability.PointerEndLoc = pointerEndLoc;
   fileNullability.PointerKind = static_cast(pointerKind);
 }
 
@@ -3559,7 +3563,7 @@ static void checkNullabilityConsistency(
   }
 
   // Complain about missing nullability.
-  emitNullabilityConsistencyWarning(S, pointerKind, pointerLoc);
+  emitNullabilityConsistencyWarning(S, pointerKind, pointerLoc, pointerEndLoc);
 }
 
 /// Marks that a nullability feature has been used in the file containing
@@ -3585,7 +3589,8 @@ static void recordNullabilitySeen(Sema &
 return;
 
   auto kind = static_cast(fileNullability.PointerKind);
-  emitNullabilityConsistencyWarning(S, kind, fileNullability.PointerLoc);
+  emitNullabilityConsistencyWarning(S, kind, fileNullability.PointerLoc,
+fileNullability.PointerEndLoc);
 }
 
 /// Returns true if any of the declarator chunks before \p endIndex include a
@@ -3895,6 

Re: r313386 - [Sema] Error out early for tags defined inside an enumeration.

2017-10-17 Thread Volodymyr Sapsai via cfe-commits


> On Oct 11, 2017, at 16:02, Richard Smith  wrote:
> 
> On 22 September 2017 at 18:00, Volodymyr Sapsai via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> 
> 
>> On Sep 21, 2017, at 15:17, Richard Smith > <mailto:rich...@metafoo.co.uk>> wrote:
>> 
>> On 15 September 2017 at 12:51, Volodymyr Sapsai via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: vsapsai
>> Date: Fri Sep 15 12:51:42 2017
>> New Revision: 313386
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=313386&view=rev 
>> <http://llvm.org/viewvc/llvm-project?rev=313386&view=rev>
>> Log:
>> [Sema] Error out early for tags defined inside an enumeration.
>> 
>> This fixes PR28903 by avoiding access check for inner enum constant. We
>> are performing access check because one enum constant references another
>> and because enum is defined in CXXRecordDecl. But access check doesn't
>> work because FindDeclaringClass doesn't expect more than one EnumDecl
>> and because inner enum has access AS_none due to not being an immediate
>> child of a record.
>> 
>> The change detects an enum is defined in wrong place and allows to skip
>> parsing its body. Access check is skipped together with body parsing.
>> There was no crash in C, added test case to cover the new error.
>> 
>> rdar://problem/28530809 <>
>> 
>> Reviewers: rnk, doug.gregor, rsmith
>> 
>> Reviewed By: doug.gregor
>> 
>> Subscribers: cfe-commits
>> 
>> Differential Revision: https://reviews.llvm.org/D37089 
>> <https://reviews.llvm.org/D37089>
>> 
>> 
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/test/Sema/enum.c
>> cfe/trunk/test/SemaCXX/enum.cpp
>> 
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313386&r1=313385&r2=313386&view=diff
>>  
>> <http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313386&r1=313385&r2=313386&view=diff>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 15 12:51:42 
>> 2017
>> @@ -1335,6 +1335,8 @@ def err_type_defined_in_alias_template :
>>"%0 cannot be defined in a type alias template">;
>>  def err_type_defined_in_condition : Error<
>>"%0 cannot be defined in a condition">;
>> +def err_type_defined_in_enum : Error<
>> +  "%0 cannot be defined in an enumeration">;
>> 
>>  def note_pure_virtual_function : Note<
>>"unimplemented pure virtual method %0 in %1">;
>> 
>> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313386&r1=313385&r2=313386&view=diff
>>  
>> <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313386&r1=313385&r2=313386&view=diff>
>> ==
>> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 15 12:51:42 2017
>> @@ -13928,6 +13928,12 @@ CreateNewDecl:
>>  Invalid = true;
>>}
>> 
>> +  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) 
>> {
>> +Diag(New->getLocation(), diag::err_type_defined_in_enum)
>> +  << Context.getTagDeclType(New);
>> +Invalid = true;
>> +  }
>> 
>> This looks like the wrong fix. As noted elsewhere, this is wrong in C. And 
>> in C++, the relevant context is a type-specifier, which should be rejected 
>> due to the check 7 lines above.
>> 
>> It looks like the actual bug is that we don't consider the type within a C99 
>> compound literal to be a type-specifier. The fact that the context is an 
>> enumeration is irrelevant.
> 
> At which point can we detect IsTypeSpecifier should be true? Which in turn 
> boils down to DeclSpecContext should be DSC_type_specifier. Currently we have 
> DeclSpecContext DSC_normal because it is a default argument in 
> Parser::ParseSpecifierQualifierList. Which is called from
> 
> #4clang::Parser::ParseParenExpres

r316381 - [Sema] Add support for flexible array members in Obj-C.

2017-10-23 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon Oct 23 15:01:41 2017
New Revision: 316381

URL: http://llvm.org/viewvc/llvm-project?rev=316381&view=rev
Log:
[Sema] Add support for flexible array members in Obj-C.

Allow Obj-C ivars with incomplete array type but only as the last ivar.
Also add a requirement for ivars that contain a flexible array member to
be at the end of class too. It is possible to add in a subclass another
ivar at the end but we'll emit a warning in this case. Also we'll emit a
warning if a variable sized ivar is declared in class extension or in
implementation because subclasses won't know they should avoid adding
new ivars.

In ARC incomplete array objects are treated as __unsafe_unretained so
require them to be marked as such.

Prohibit synthesizing ivars with flexible array members because order of
synthesized ivars is not obvious and tricky to control. Spelling out
ivar explicitly gives control to developers and helps to avoid surprises
with unexpected ivar ordering.

For C and C++ changed diagnostic to tell explicitly a field is not the
last one and point to the next field. It is not as useful as in Obj-C
but it is an improvement and it is consistent with Obj-C. For C for
unions emit more specific err_flexible_array_union instead of generic
err_field_incomplete.

rdar://problem/21054495

Reviewers: rjmccall, theraven

Reviewed By: rjmccall

Subscribers: cfe-commits

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


Added:
cfe/trunk/test/SemaObjC/flexible-array-arc.m
cfe/trunk/test/SemaObjC/flexible-array.m
cfe/trunk/test/SemaObjCXX/flexible-array.mm
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/Sema/transparent-union.c
cfe/trunk/test/SemaCXX/flexible-array-test.cpp
cfe/trunk/test/SemaObjC/ivar-sem-check-1.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=316381&r1=316380&r2=316381&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Oct 23 15:01:41 2017
@@ -374,6 +374,7 @@ def ObjCRootClass : DiagGroup<"objc-root
 def ObjCPointerIntrospectPerformSelector : 
DiagGroup<"deprecated-objc-pointer-introspection-performSelector">;
 def ObjCPointerIntrospect : DiagGroup<"deprecated-objc-pointer-introspection", 
[ObjCPointerIntrospectPerformSelector]>;
 def ObjCMultipleMethodNames : DiagGroup<"objc-multiple-method-names">;
+def ObjCFlexibleArray : DiagGroup<"objc-flexible-array">;
 def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
@@ -750,6 +751,7 @@ def Most : DiagGroup<"most", [
 VolatileRegisterVar,
 ObjCMissingSuperCalls,
 ObjCDesignatedInit,
+ObjCFlexibleArray,
 OverloadedVirtual,
 PrivateExtern,
 SelTypeCast,

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=316381&r1=316380&r2=316381&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 23 15:01:41 
2017
@@ -5222,6 +5222,28 @@ def ext_flexible_array_empty_aggregate_g
 def ext_flexible_array_union_gnu : Extension<
   "flexible array member %0 in a union is a GNU extension">, 
InGroup;
 
+def err_flexible_array_not_at_end : Error<
+  "flexible array member %0 with type %1 is not at the end of"
+  " %select{struct|interface|union|class|enum}2">;
+def err_objc_variable_sized_type_not_at_end : Error<
+  "field %0 with variable sized type %1 is not at the end of class">;
+def note_next_field_declaration : Note<
+  "next field declaration is here">;
+def note_next_ivar_declaration : Note<
+  "next %select{instance variable declaration|synthesized instance variable}0"
+  " is here">;
+def err_synthesize_variable_sized_ivar : Error<
+  "synthesized property with variable size type %0"
+  " requires an existing instance variable">;
+def err_flexible_array_arc_retainable : Error<
+  "ARC forbids flexible array members with retainable object type">;
+def warn_variable_sized_ivar_visibility : Warning<
+  "field %0 with variable sized type %1 is not visible to subclasses and"
+  " can conflict with their instance variables">, InGroup;
+def warn_superclass_variable_sized_type_not_at_end : Warning<
+  "field %0 can overwrite instance variable %1 with variable sized type %2"
+  " in superclass %3">, InGroup;
+
 let C

r337953 - [Preprocessor] Stop entering included files after hitting a fatal error.

2018-07-25 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Jul 25 12:16:26 2018
New Revision: 337953

URL: http://llvm.org/viewvc/llvm-project?rev=337953&view=rev
Log:
[Preprocessor] Stop entering included files after hitting a fatal error.

Fixes a problem when we have multiple inclusion cycles and try to
enumerate all possible ways to reach the max inclusion depth.

rdar://problem/38871876

Reviewers: bruno, rsmith, jkorous, aaron.ballman

Reviewed By: bruno, jkorous, aaron.ballman

Subscribers: dexonsmith, cfe-commits

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


Added:
cfe/trunk/test/Preprocessor/Inputs/cycle/
cfe/trunk/test/Preprocessor/Inputs/cycle/a.h
cfe/trunk/test/Preprocessor/Inputs/cycle/b.h
cfe/trunk/test/Preprocessor/Inputs/cycle/c.h
cfe/trunk/test/Preprocessor/include-cycle.c
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=337953&r1=337952&r2=337953&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Jul 25 12:16:26 2018
@@ -1896,6 +1896,12 @@ void Preprocessor::HandleIncludeDirectiv
   if (PPOpts->SingleFileParseMode)
 ShouldEnter = false;
 
+  // Any diagnostics after the fatal error will not be visible. As the
+  // compilation failed already and errors in subsequently included files won't
+  // be visible, avoid preprocessing those files.
+  if (ShouldEnter && Diags->hasFatalErrorOccurred())
+ShouldEnter = false;
+
   // Determine whether we should try to import the module for this #include, if
   // there is one. Don't do so if precompiled module support is disabled or we
   // are processing this module textually (because we're building the module).

Added: cfe/trunk/test/Preprocessor/Inputs/cycle/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/cycle/a.h?rev=337953&view=auto
==
--- cfe/trunk/test/Preprocessor/Inputs/cycle/a.h (added)
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/a.h Wed Jul 25 12:16:26 2018
@@ -0,0 +1,8 @@
+// Presence of 2 inclusion cycles
+//b.h -> a.h -> b.h -> ...
+//c.h -> a.h -> c.h -> ...
+// makes it unfeasible to reach max inclusion depth in all possible ways. Need
+// to stop earlier.
+
+#include "b.h"
+#include "c.h"

Added: cfe/trunk/test/Preprocessor/Inputs/cycle/b.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/cycle/b.h?rev=337953&view=auto
==
--- cfe/trunk/test/Preprocessor/Inputs/cycle/b.h (added)
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/b.h Wed Jul 25 12:16:26 2018
@@ -0,0 +1 @@
+#include "a.h"

Added: cfe/trunk/test/Preprocessor/Inputs/cycle/c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/cycle/c.h?rev=337953&view=auto
==
--- cfe/trunk/test/Preprocessor/Inputs/cycle/c.h (added)
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/c.h Wed Jul 25 12:16:26 2018
@@ -0,0 +1 @@
+#include "a.h"

Added: cfe/trunk/test/Preprocessor/include-cycle.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-cycle.c?rev=337953&view=auto
==
--- cfe/trunk/test/Preprocessor/include-cycle.c (added)
+++ cfe/trunk/test/Preprocessor/include-cycle.c Wed Jul 25 12:16:26 2018
@@ -0,0 +1,5 @@
+// RUN: not %clang_cc1 -E -I%S/Inputs -ferror-limit 20 %s
+
+// Test that preprocessing terminates even if we have inclusion cycles.
+
+#include "cycle/a.h"


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


r338741 - [c-index-test] Use correct executable path to discover resource directory.

2018-08-02 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Aug  2 10:29:53 2018
New Revision: 338741

URL: http://llvm.org/viewvc/llvm-project?rev=338741&view=rev
Log:
[c-index-test] Use correct executable path to discover resource directory.

Driver builds resource directory path based on provided executable path.
Instead of string "clang" use actual executable path.

rdar://problem/42699514

Reviewers: nathawes, akyrtzi, bob.wilson

Reviewed By: akyrtzi

Subscribers: dexonsmith, cfe-commits

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


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

Modified: cfe/trunk/tools/c-index-test/core_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/core_main.cpp?rev=338741&r1=338740&r2=338741&view=diff
==
--- cfe/trunk/tools/c-index-test/core_main.cpp (original)
+++ cfe/trunk/tools/c-index-test/core_main.cpp Thu Aug  2 10:29:53 2018
@@ -20,6 +20,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/PrettyStackTrace.h"
@@ -202,11 +203,11 @@ static void dumpModuleFileInputs(seriali
   });
 }
 
-static bool printSourceSymbols(ArrayRef Args,
-   bool dumpModuleImports,
-   bool indexLocals) {
+static bool printSourceSymbols(const char *Executable,
+   ArrayRef Args,
+   bool dumpModuleImports, bool indexLocals) {
   SmallVector ArgsWithProgName;
-  ArgsWithProgName.push_back("clang");
+  ArgsWithProgName.push_back(Executable);
   ArgsWithProgName.append(Args.begin(), Args.end());
   IntrusiveRefCntPtr
 Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
@@ -314,6 +315,8 @@ static void printSymbolNameAndUSR(const
 int indextest_core_main(int argc, const char **argv) {
   sys::PrintStackTraceOnErrorSignal(argv[0]);
   PrettyStackTraceProgram X(argc, argv);
+  void *MainAddr = (void*) (intptr_t) indextest_core_main;
+  std::string Executable = llvm::sys::fs::getMainExecutable(argv[0], MainAddr);
 
   assert(argv[1] == StringRef("core"));
   ++argv;
@@ -343,7 +346,9 @@ int indextest_core_main(int argc, const
   errs() << "error: missing compiler args; pass '-- '\n";
   return 1;
 }
-return printSourceSymbols(CompArgs, options::DumpModuleImports, 
options::IncludeLocals);
+return printSourceSymbols(Executable.c_str(), CompArgs,
+  options::DumpModuleImports,
+  options::IncludeLocals);
   }
 
   return 0;


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


r338934 - [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-08-03 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Aug  3 16:12:37 2018
New Revision: 338934

URL: http://llvm.org/viewvc/llvm-project?rev=338934&view=rev
Log:
[Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

Libc++ needs to know when aligned allocation is supported by clang, but is
otherwise unavailable at link time. Otherwise, libc++ will incorrectly end up
generating calls to `__builtin_operator_new`/`__builtin_operator_delete` with
alignment arguments.

This patch implements the following changes:

* The `__cpp_aligned_new` feature test macro to no longer be defined when
  aligned allocation is otherwise enabled but unavailable.

* The Darwin driver no longer passes `-faligned-alloc-unavailable` when the
  user manually specifies `-faligned-allocation` or `-fno-aligned-allocation`.

* Instead of a warning Clang now generates a hard error when an aligned
  allocation or deallocation function is referenced but unavailable.

Patch by Eric Fiselier.

Reviewers: rsmith, vsapsai, erik.pilkington, ahatanak, dexonsmith

Reviewed By: rsmith

Subscribers: Quuxplusone, cfe-commits

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


Added:
cfe/trunk/test/Lexer/aligned-allocation.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=338934&r1=338933&r2=338934&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Aug  3 16:12:37 2018
@@ -364,7 +364,6 @@ def NonVirtualDtor : DiagGroup<"non-virt
 def NullPointerArithmetic : DiagGroup<"null-pointer-arithmetic">;
 def : DiagGroup<"effc++", [NonVirtualDtor]>;
 def OveralignedType : DiagGroup<"over-aligned">;
-def AlignedAllocationUnavailable : DiagGroup<"aligned-allocation-unavailable">;
 def OldStyleCast : DiagGroup<"old-style-cast">;
 def : DiagGroup<"old-style-definition">;
 def OutOfLineDeclaration : DiagGroup<"out-of-line-declaration">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=338934&r1=338933&r2=338934&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug  3 16:12:37 
2018
@@ -6465,12 +6465,12 @@ def warn_overaligned_type : Warning<
   "type %0 requires %1 bytes of alignment and the default allocator only "
   "guarantees %2 bytes">,
   InGroup, DefaultIgnore;
-def warn_aligned_allocation_unavailable :Warning<
+def err_aligned_allocation_unavailable : Error<
   "aligned %select{allocation|deallocation}0 function of type '%1' is only "
-  "available on %2 %3 or newer">, InGroup, 
DefaultError;
+  "available on %2 %3 or newer">;
 def note_silence_unligned_allocation_unavailable : Note<
   "if you supply your own aligned allocation functions, use "
-  "-Wno-aligned-allocation-unavailable to silence this diagnostic">;
+  "-faligned-allocation to silence this diagnostic">;
 
 def err_conditional_void_nonvoid : Error<
   "%select{left|right}1 operand to ? is void, but %select{right|left}1 operand 
"

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=338934&r1=338933&r2=338934&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Fri Aug  3 16:12:37 2018
@@ -2035,7 +2035,11 @@ bool Darwin::isAlignedAllocationUnavaila
 void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Action::OffloadKind DeviceOffloadKind) 
const {
-  if (isAlignedAllocationUnavailable())
+  // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
+  // enabled or disabled aligned allocations.
+  if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
+options::OPT_fno_aligned_allocation) &&
+  isAlignedAllocationUnavailable())
 CC1Args.push_back("-faligned-alloc-unavailable");
 }
 

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=338934&r1=338933&r2=338934&view=diff
===

r324419 - [Lex] Fix handling numerical literals ending with ' and signed exponent.

2018-02-06 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Feb  6 14:39:25 2018
New Revision: 324419

URL: http://llvm.org/viewvc/llvm-project?rev=324419&view=rev
Log:
[Lex] Fix handling numerical literals ending with ' and signed exponent.

For input `0'e+1` lexer tokenized as numeric constant only `0'e`. Later
NumericLiteralParser skipped 0 and ' as digits and parsed `e+1` as valid
exponent going past the end of the token. Because it didn't mark numeric
literal as having an error, it continued parsing and tried to expandUCNs
with StringRef of length -2.

The fix is not to parse exponent when we reached the end of token.

Discovered by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4588

rdar://problem/36076719

Reviewers: rsmith, t.p.northover

Reviewed By: rsmith

Subscribers: cfe-commits, jkorous-apple

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

Modified:
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=324419&r1=324418&r2=324419&view=diff
==
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Tue Feb  6 14:39:25 2018
@@ -738,15 +738,17 @@ void NumericLiteralParser::ParseDecimalO
 s++;
 radix = 10;
 saw_exponent = true;
-if (*s == '+' || *s == '-')  s++; // sign
+if (s != ThisTokEnd && (*s == '+' || *s == '-'))  s++; // sign
 const char *first_non_digit = SkipDigits(s);
 if (containsDigits(s, first_non_digit)) {
   checkSeparator(TokLoc, s, CSK_BeforeDigits);
   s = first_non_digit;
 } else {
-  PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
-  diag::err_exponent_has_no_digits);
-  hadError = true;
+  if (!hadError) {
+PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
+diag::err_exponent_has_no_digits);
+hadError = true;
+  }
   return;
 }
   }
@@ -787,10 +789,12 @@ void NumericLiteralParser::checkSeparato
   } else if (Pos == ThisTokEnd)
 return;
 
-  if (isDigitSeparator(*Pos))
+  if (isDigitSeparator(*Pos)) {
 PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Pos - ThisTokBegin),
 diag::err_digit_separator_not_between_digits)
   << IsAfterDigits;
+hadError = true;
+  }
 }
 
 /// ParseNumberStartingWithZero - This method is called when the first 
character
@@ -840,12 +844,14 @@ void NumericLiteralParser::ParseNumberSt
   const char *Exponent = s;
   s++;
   saw_exponent = true;
-  if (*s == '+' || *s == '-')  s++; // sign
+  if (s != ThisTokEnd && (*s == '+' || *s == '-'))  s++; // sign
   const char *first_non_digit = SkipDigits(s);
   if (!containsDigits(s, first_non_digit)) {
-PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
-diag::err_exponent_has_no_digits);
-hadError = true;
+if (!hadError) {
+  PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
+  diag::err_exponent_has_no_digits);
+  hadError = true;
+}
 return;
   }
   checkSeparator(TokLoc, s, CSK_BeforeDigits);

Modified: cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp?rev=324419&r1=324418&r2=324419&view=diff
==
--- cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp (original)
+++ cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp Tue Feb  6 14:39:25 2018
@@ -51,6 +51,8 @@ namespace floating {
   float u = 0x.'p1f; // expected-error {{hexadecimal floating literal requires 
a significand}}
   float v = 0e'f; // expected-error {{exponent has no digits}}
   float w = 0x0p'f; // expected-error {{exponent has no digits}}
+  float x = 0'e+1; // expected-error {{digit separator cannot appear at end of 
digit sequence}}
+  float y = 0x0'p+1; // expected-error {{digit separator cannot appear at end 
of digit sequence}}
 }
 
 #line 123'456


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


r325997 - [ExprConstant] Fix crash when initialize an indirect field with another field.

2018-02-23 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Feb 23 15:59:20 2018
New Revision: 325997

URL: http://llvm.org/viewvc/llvm-project?rev=325997&view=rev
Log:
[ExprConstant] Fix crash when initialize an indirect field with another field.

When indirect field is initialized with another field, you have
MemberExpr with CXXThisExpr that corresponds to the field's immediate
anonymous parent. But 'this' was referring to the non-anonymous parent.
So when we were building LValue Designator, it was incorrect as it had
wrong starting point. Usage of such designator would cause unexpected
APValue changes and crashes.

The fix is in adjusting 'this' for indirect fields from non-anonymous
parent to the field's immediate parent.

Discovered by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4985

rdar://problem/36359187

Reviewers: rsmith, efriedma

Reviewed By: rsmith

Subscribers: cfe-commits, jkorous-apple

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


Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=325997&r1=325996&r2=325997&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Feb 23 15:59:20 2018
@@ -4383,6 +4383,7 @@ static bool HandleConstructorCall(const
 #endif
   for (const auto *I : Definition->inits()) {
 LValue Subobject = This;
+LValue SubobjectParent = This;
 APValue *Value = &Result;
 
 // Determine the subobject to initialize.
@@ -4413,7 +4414,8 @@ static bool HandleConstructorCall(const
 } else if (IndirectFieldDecl *IFD = I->getIndirectMember()) {
   // Walk the indirect field decl's chain to find the object to initialize,
   // and make sure we've initialized every step along it.
-  for (auto *C : IFD->chain()) {
+  auto IndirectFieldChain = IFD->chain();
+  for (auto *C : IndirectFieldChain) {
 FD = cast(C);
 CXXRecordDecl *CD = cast(FD->getParent());
 // Switch the union field if it differs. This happens if we had
@@ -4429,6 +4431,10 @@ static bool HandleConstructorCall(const
 *Value = APValue(APValue::UninitStruct(), CD->getNumBases(),
  std::distance(CD->field_begin(), 
CD->field_end()));
 }
+// Store Subobject as its parent before updating it for the last 
element
+// in the chain.
+if (C == IndirectFieldChain.back())
+  SubobjectParent = Subobject;
 if (!HandleLValueMember(Info, I->getInit(), Subobject, FD))
   return false;
 if (CD->isUnion())
@@ -4440,10 +4446,16 @@ static bool HandleConstructorCall(const
   llvm_unreachable("unknown base initializer kind");
 }
 
+// Need to override This for implicit field initializers as in this case
+// This refers to innermost anonymous struct/union containing initializer,
+// not to currently constructed class.
+const Expr *Init = I->getInit();
+ThisOverrideRAII ThisOverride(*Info.CurrentCall, &SubobjectParent,
+  isa(Init));
 FullExpressionRAII InitScope(Info);
-if (!EvaluateInPlace(*Value, Info, Subobject, I->getInit()) ||
-(FD && FD->isBitField() && !truncateBitfieldValue(Info, I->getInit(),
-  *Value, FD))) {
+if (!EvaluateInPlace(*Value, Info, Subobject, Init) ||
+(FD && FD->isBitField() &&
+ !truncateBitfieldValue(Info, Init, *Value, FD))) {
   // If we're checking for a potential constant expression, evaluate all
   // initializers even if some of them fail.
   if (!Info.noteFailure())

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=325997&r1=325996&r2=325997&view=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Fri Feb 23 15:59:20 
2018
@@ -1045,3 +1045,57 @@ namespace Mutable {
   constexpr B b;
   constexpr int p = b.n; // expected-error {{constant expression}} 
expected-note {{mutable}}
 }
+
+namespace IndirectFields {
+
+// Reference indirect field.
+struct A {
+  struct {
+union {
+  int x = x = 3; // expected-note {{outside its lifetime}}
+};
+  };
+  constexpr A() {}
+};
+static_assert(A().x == 3, ""); // expected-error{{not an integral constant 
expression}} expected-note{{in call to 'A()'}}
+
+// Reference another indirect field, with different 'this'.
+struct B {
+  struct {
+union {
+  int x = 3;
+};
+int y = x;
+  };
+  constexpr B() {}
+};
+static_assert(B().y == 3, "");
+
+// Nested evaluation of i

r326145 - Fix which Darwin versions have ObjC runtime with full subscripting support.

2018-02-26 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon Feb 26 15:10:23 2018
New Revision: 326145

URL: http://llvm.org/viewvc/llvm-project?rev=326145&view=rev
Log:
Fix which Darwin versions have ObjC runtime with full subscripting support.

Update min deployment target in some tests so that they don't try
to link against libarclite and don't fail when it's not available.

rdar://problem/29253617

Reviewers: vsk, kubamracek

Reviewed By: vsk

Subscribers: jkorous-apple, cfe-commits

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


Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/test/Driver/arclite-link.c

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=326145&r1=326144&r2=326145&view=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Mon Feb 26 15:10:23 2018
@@ -207,8 +207,8 @@ public:
   bool hasSubscripting() const {
 switch (getKind()) {
 case FragileMacOSX: return false;
-case MacOSX: return getVersion() >= VersionTuple(10, 8);
-case iOS: return getVersion() >= VersionTuple(6);
+case MacOSX: return getVersion() >= VersionTuple(10, 11);
+case iOS: return getVersion() >= VersionTuple(9);
 case WatchOS: return true;
 
 // This is really a lie, because some implementations and versions

Modified: cfe/trunk/test/Driver/arclite-link.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/arclite-link.c?rev=326145&r1=326144&r2=326145&view=diff
==
--- cfe/trunk/test/Driver/arclite-link.c (original)
+++ cfe/trunk/test/Driver/arclite-link.c Mon Feb 26 15:10:23 2018
@@ -1,6 +1,6 @@
 // RUN: touch %t.o
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-ARCLITE-OSX 
%s
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.8 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.10 %t.o 2>&1 | FileCheck 
-check-prefix=CHECK-ARCLITE-OSX %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.11 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE 
%s
 // RUN: %clang -### -target i386-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-nostdlib %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOSTDLIB %s
 
@@ -12,6 +12,6 @@
 // CHECK-NOARCLITE-NOT: libarclite
 // CHECK-NOSTDLIB-NOT: -lobjc
 
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-fobjc-arc -mmacosx-version-min=10.7 %s 2>&1 | FileCheck 
-check-prefix=CHECK-UNUSED %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-fobjc-arc -mmacosx-version-min=10.10 %s 2>&1 | FileCheck 
-check-prefix=CHECK-UNUSED %s
 
 // CHECK-UNUSED-NOT: warning: argument unused during compilation: 
'-fobjc-link-runtime'


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


r321296 - [CodeGen] Fix crash when a function taking transparent union is redeclared.

2017-12-21 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Dec 21 11:42:37 2017
New Revision: 321296

URL: http://llvm.org/viewvc/llvm-project?rev=321296&view=rev
Log:
[CodeGen] Fix crash when a function taking transparent union is redeclared.

When a function taking transparent union is declared as taking one of
union members earlier in the translation unit, clang would hit an
"Invalid cast" assertion during EmitFunctionProlog. This case
corresponds to function f1 in test/CodeGen/transparent-union-redecl.c.
We decided to cast i32 to union because after merging function
declarations function parameter type becomes int,
CGFunctionInfo::ArgInfo type matches with ABIArgInfo type, so we decide
it is a trivial case. But these types should also be castable to
parameter declaration type which is not the case here.

The fix is in checking for the trivial case if ABIArgInfo type matches with
parameter declaration type. It exposed inconsistency that we check
hasScalarEvaluationKind for different types in EmitParmDecl and
EmitFunctionProlog, and comment says they should match.

Additional tests in Sema/transparent-union.c capture current behavior and make
sure there are no regressions.

rdar://problem/34949329

Reviewers: rjmccall, rafael

Reviewed By: rjmccall

Subscribers: aemerson, cfe-commits, kristof.beyls

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

Added:
cfe/trunk/test/CodeGen/transparent-union-redecl.c
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/test/CodeGen/kr-func-promote.c
cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance-vtordisps.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
cfe/trunk/test/Sema/transparent-union.c

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=321296&r1=321295&r2=321296&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Dec 21 11:42:37 2017
@@ -2317,7 +2317,7 @@ void CodeGenFunction::EmitFunctionProlog
 
   // If we have the trivial case, handle it with no muss and fuss.
   if (!isa(ArgI.getCoerceToType()) &&
-  ArgI.getCoerceToType() == ConvertType(Ty) &&
+  ArgI.getCoerceToType() == ConvertType(Arg->getType()) &&
   ArgI.getDirectOffset() == 0) {
 assert(NumIRArgs == 1);
 llvm::Value *V = FnArgs[FirstIRArg];
@@ -2414,8 +2414,8 @@ void CodeGenFunction::EmitFunctionProlog
 break;
   }
 
-  Address Alloca = CreateMemTemp(Ty, getContext().getDeclAlign(Arg),
- Arg->getName());
+  Address Alloca = CreateMemTemp(
+  Arg->getType(), getContext().getDeclAlign(Arg), Arg->getName());
 
   // Pointer to store into.
   Address Ptr = emitAddressAtOffset(*this, Alloca, ArgI);
@@ -2461,9 +2461,9 @@ void CodeGenFunction::EmitFunctionProlog
   }
 
   // Match to what EmitParmDecl is expecting for this type.
-  if (CodeGenFunction::hasScalarEvaluationKind(Ty)) {
+  if (CodeGenFunction::hasScalarEvaluationKind(Arg->getType())) {
 llvm::Value *V =
-  EmitLoadOfScalar(Alloca, false, Ty, Arg->getLocStart());
+EmitLoadOfScalar(Alloca, false, Arg->getType(), 
Arg->getLocStart());
 if (isPromoted)
   V = emitArgumentDemotion(*this, Arg, V);
 ArgVals.push_back(ParamValue::forDirect(V));

Modified: cfe/trunk/test/CodeGen/kr-func-promote.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/kr-func-promote.c?rev=321296&r1=321295&r2=321296&view=diff
==
--- cfe/trunk/test/CodeGen/kr-func-promote.c (original)
+++ cfe/trunk/test/CodeGen/kr-func-promote.c Thu Dec 21 11:42:37 2017
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck 
%s
-// CHECK: i32 @a(i32)
+// CHECK: i32 @a(i32
 
 int a();
 int a(x) short x; {return x;}

Added: cfe/trunk/test/CodeGen/transparent-union-redecl.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/transparent-union-redecl.c?rev=321296&view=auto
==
--- cfe/trunk/test/CodeGen/transparent-union-redecl.c (added)
+++ cfe/trunk/test/CodeGen/transparent-union-redecl.c Thu Dec 21 11:42:37 2017
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -Werror -triple i386-linux -emit-llvm -o - %s | FileCheck %s
+
+// Test that different order of declarations is acceptable and that
+// implementing different redeclarations is acceptable.
+// rdar://problem/34949329
+
+typedef union {
+  int i;
+  float f;
+} TU __attribute__((transparent_union));
+
+// CHECK-LABEL: define void @f0(i32 %tu.coerce)
+// CHECK: %tu = alloca %union.TU, align 4
+// CHECK: %coerce.dive = getelementptr inbounds %union.

r321306 - Revert "[CodeGen] Fix crash when a function taking transparent union is redeclared."

2017-12-21 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Dec 21 12:52:59 2017
New Revision: 321306

URL: http://llvm.org/viewvc/llvm-project?rev=321306&view=rev
Log:
Revert "[CodeGen] Fix crash when a function taking transparent union is 
redeclared."

This reverts commit r321296. It caused performance regressions
FAIL: imp.execution_time
FAIL: 2007-01-04-KNR-Args.execution_time
FAIL: sse_expandfft.execution_time
FAIL: sse_stepfft.execution_time


Removed:
cfe/trunk/test/CodeGen/transparent-union-redecl.c
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/test/CodeGen/kr-func-promote.c
cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance-vtordisps.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
cfe/trunk/test/Sema/transparent-union.c

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=321306&r1=321305&r2=321306&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Dec 21 12:52:59 2017
@@ -2317,7 +2317,7 @@ void CodeGenFunction::EmitFunctionProlog
 
   // If we have the trivial case, handle it with no muss and fuss.
   if (!isa(ArgI.getCoerceToType()) &&
-  ArgI.getCoerceToType() == ConvertType(Arg->getType()) &&
+  ArgI.getCoerceToType() == ConvertType(Ty) &&
   ArgI.getDirectOffset() == 0) {
 assert(NumIRArgs == 1);
 llvm::Value *V = FnArgs[FirstIRArg];
@@ -2414,8 +2414,8 @@ void CodeGenFunction::EmitFunctionProlog
 break;
   }
 
-  Address Alloca = CreateMemTemp(
-  Arg->getType(), getContext().getDeclAlign(Arg), Arg->getName());
+  Address Alloca = CreateMemTemp(Ty, getContext().getDeclAlign(Arg),
+ Arg->getName());
 
   // Pointer to store into.
   Address Ptr = emitAddressAtOffset(*this, Alloca, ArgI);
@@ -2461,9 +2461,9 @@ void CodeGenFunction::EmitFunctionProlog
   }
 
   // Match to what EmitParmDecl is expecting for this type.
-  if (CodeGenFunction::hasScalarEvaluationKind(Arg->getType())) {
+  if (CodeGenFunction::hasScalarEvaluationKind(Ty)) {
 llvm::Value *V =
-EmitLoadOfScalar(Alloca, false, Arg->getType(), 
Arg->getLocStart());
+  EmitLoadOfScalar(Alloca, false, Ty, Arg->getLocStart());
 if (isPromoted)
   V = emitArgumentDemotion(*this, Arg, V);
 ArgVals.push_back(ParamValue::forDirect(V));

Modified: cfe/trunk/test/CodeGen/kr-func-promote.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/kr-func-promote.c?rev=321306&r1=321305&r2=321306&view=diff
==
--- cfe/trunk/test/CodeGen/kr-func-promote.c (original)
+++ cfe/trunk/test/CodeGen/kr-func-promote.c Thu Dec 21 12:52:59 2017
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck 
%s
-// CHECK: i32 @a(i32
+// CHECK: i32 @a(i32)
 
 int a();
 int a(x) short x; {return x;}

Removed: cfe/trunk/test/CodeGen/transparent-union-redecl.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/transparent-union-redecl.c?rev=321305&view=auto
==
--- cfe/trunk/test/CodeGen/transparent-union-redecl.c (original)
+++ cfe/trunk/test/CodeGen/transparent-union-redecl.c (removed)
@@ -1,36 +0,0 @@
-// RUN: %clang_cc1 -Werror -triple i386-linux -emit-llvm -o - %s | FileCheck %s
-
-// Test that different order of declarations is acceptable and that
-// implementing different redeclarations is acceptable.
-// rdar://problem/34949329
-
-typedef union {
-  int i;
-  float f;
-} TU __attribute__((transparent_union));
-
-// CHECK-LABEL: define void @f0(i32 %tu.coerce)
-// CHECK: %tu = alloca %union.TU, align 4
-// CHECK: %coerce.dive = getelementptr inbounds %union.TU, %union.TU* %tu, i32 
0, i32 0
-// CHECK: store i32 %tu.coerce, i32* %coerce.dive, align 4
-void f0(TU tu) {}
-void f0(int i);
-
-// CHECK-LABEL: define void @f1(i32 %tu.coerce)
-// CHECK: %tu = alloca %union.TU, align 4
-// CHECK: %coerce.dive = getelementptr inbounds %union.TU, %union.TU* %tu, i32 
0, i32 0
-// CHECK: store i32 %tu.coerce, i32* %coerce.dive, align 4
-void f1(int i);
-void f1(TU tu) {}
-
-// CHECK-LABEL: define void @f2(i32 %i)
-// CHECK: %i.addr = alloca i32, align 4
-// CHECK: store i32 %i, i32* %i.addr, align 4
-void f2(TU tu);
-void f2(int i) {}
-
-// CHECK-LABEL: define void @f3(i32 %i)
-// CHECK: %i.addr = alloca i32, align 4
-// CHECK: store i32 %i, i32* %i.addr, align 4
-void f3(int i) {}
-void f3(TU tu);

Modified: 
cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual

r321660 - [Sema] Don't emit the -Wstrict-prototypes warning for variadic functions.

2018-01-02 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Jan  2 10:02:19 2018
New Revision: 321660

URL: http://llvm.org/viewvc/llvm-project?rev=321660&view=rev
Log:
[Sema] Don't emit the -Wstrict-prototypes warning for variadic functions.

rdar://problem/33251668

Reviewers: arphaman, ahatanak

Reviewed By: arphaman

Subscribers: ptitei, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Sema/warn-strict-prototypes.c

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=321660&r1=321659&r2=321660&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Jan  2 10:02:19 2018
@@ -4767,7 +4767,7 @@ static TypeSourceInfo *GetFullTypeForDec
 break;
   case DeclaratorChunk::Function: {
 const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
-if (FTI.NumParams == 0)
+if (FTI.NumParams == 0 && !FTI.isVariadic)
   S.Diag(DeclType.Loc, diag::warn_strict_prototypes)
   << IsBlock
   << FixItHint::CreateInsertion(FTI.getRParenLoc(), "void");

Modified: cfe/trunk/test/Sema/warn-strict-prototypes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-strict-prototypes.c?rev=321660&r1=321659&r2=321660&view=diff
==
--- cfe/trunk/test/Sema/warn-strict-prototypes.c (original)
+++ cfe/trunk/test/Sema/warn-strict-prototypes.c Tue Jan  2 10:02:19 2018
@@ -65,3 +65,9 @@ void foo11(p, p2) int p; int p2; {}
 void __attribute__((cdecl)) foo12(d) // expected-warning {{this old-style 
function definition is not preceded by a prototype}}
   short d;
 {}
+
+// No warnings for variadic functions. Overloadable attribute is required
+// to avoid err_ellipsis_first_param error.
+// rdar://problem/33251668
+void foo13(...) __attribute__((overloadable));
+void foo13(...) __attribute__((overloadable)) {}


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


r321890 - Fix TLS support check for Darwin 32-bit simulator targets.

2018-01-05 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Jan  5 12:20:03 2018
New Revision: 321890

URL: http://llvm.org/viewvc/llvm-project?rev=321890&view=rev
Log:
Fix TLS support check for Darwin 32-bit simulator targets.

Also instead of checking architecture explicitly, use recently added
"simulator" environment in the triple.

rdar://problem/35083787

Reviewers: arphaman, bob.wilson

Reviewed By: arphaman

Subscribers: gparker42, cfe-commits

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

Modified:
cfe/trunk/lib/Basic/Targets/OSTargets.h
cfe/trunk/test/Sema/darwin-tls.c

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=321890&r1=321889&r2=321890&view=diff
==
--- cfe/trunk/lib/Basic/Targets/OSTargets.h (original)
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h Fri Jan  5 12:20:03 2018
@@ -95,16 +95,22 @@ public:
 if (Triple.isMacOSX())
   this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
 else if (Triple.isiOS()) {
-  // 64-bit iOS supported it from 8 onwards, 32-bit from 9 onwards.
-  if (Triple.getArch() == llvm::Triple::x86_64 ||
-  Triple.getArch() == llvm::Triple::aarch64)
+  // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
+  // 32-bit simulator from 10 onwards.
+  if (Triple.isArch64Bit())
 this->TLSSupported = !Triple.isOSVersionLT(8);
-  else if (Triple.getArch() == llvm::Triple::x86 ||
-   Triple.getArch() == llvm::Triple::arm ||
-   Triple.getArch() == llvm::Triple::thumb)
-this->TLSSupported = !Triple.isOSVersionLT(9);
-} else if (Triple.isWatchOS())
-  this->TLSSupported = !Triple.isOSVersionLT(2);
+  else if (Triple.isArch32Bit()) {
+if (!Triple.isSimulatorEnvironment())
+  this->TLSSupported = !Triple.isOSVersionLT(9);
+else
+  this->TLSSupported = !Triple.isOSVersionLT(10);
+  }
+} else if (Triple.isWatchOS()) {
+  if (!Triple.isSimulatorEnvironment())
+this->TLSSupported = !Triple.isOSVersionLT(2);
+  else
+this->TLSSupported = !Triple.isOSVersionLT(3);
+}
 
 this->MCountName = "\01mcount";
   }

Modified: cfe/trunk/test/Sema/darwin-tls.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/darwin-tls.c?rev=321890&r1=321889&r2=321890&view=diff
==
--- cfe/trunk/test/Sema/darwin-tls.c (original)
+++ cfe/trunk/test/Sema/darwin-tls.c Fri Jan  5 12:20:03 2018
@@ -1,12 +1,18 @@
 // RUN: not %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.6 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.7 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple arm64-apple-ios7.1 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple arm64-apple-ios8.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios8.3 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios9.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
 // RUN: %clang_cc1 -fsyntax-only -triple armv7-apple-ios9.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+// RUN: not %clang_cc1 -fsyntax-only -triple i386-apple-ios9.0-simulator %s 
2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-ios10.0-simulator %s 2>&1 
| FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7k-apple-watchos1.0 %s 2>&1 
| FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple thumbv7k-apple-watchos2.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+// RUN: not %clang_cc1 -fsyntax-only -triple i386-apple-watchos2.0-simulator 
%s 2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-watchos3.0-simulator %s 
2>&1 | FileCheck %s --check-prefix TLS
 
 
 __thread int a;


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


r322240 - [Lex] Inline a variable in test in preparation for more similar tests. NFC.

2018-01-10 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Jan 10 15:37:29 2018
New Revision: 322240

URL: http://llvm.org/viewvc/llvm-project?rev=322240&view=rev
Log:
[Lex] Inline a variable in test in preparation for more similar tests. NFC.

Modified:
cfe/trunk/unittests/Lex/LexerTest.cpp

Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=322240&r1=322239&r2=322240&view=diff
==
--- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
+++ cfe/trunk/unittests/Lex/LexerTest.cpp Wed Jan 10 15:37:29 2018
@@ -474,8 +474,7 @@ TEST_F(LexerTest, GetBeginningOfTokenWit
 }
 
 TEST_F(LexerTest, AvoidPastEndOfStringDereference) {
-  std::vector LexedTokens = Lex("  //  \\\n");
-  EXPECT_TRUE(LexedTokens.empty());
+  EXPECT_TRUE(Lex("  //  \\\n").empty());
 }
 
 TEST_F(LexerTest, StringizingRasString) {


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


[libcxx] r326383 - [libcxx] Fix last_write_time test for filesystems that don't support very small times.

2018-02-28 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Feb 28 15:27:40 2018
New Revision: 326383

URL: http://llvm.org/viewvc/llvm-project?rev=326383&view=rev
Log:
[libcxx] Fix last_write_time test for filesystems that don't support very small 
times.

APFS minimum supported file write time is -2^63 nanoseconds, which doesn't go
as far as `file_time_type::min()` that is equal to -2^63 microseconds on macOS.

This change doesn't affect filesystems that support `file_time_type` range only
for in-memory file time representation but not for on-disk representation. Such
filesystems are considered as `SupportsMinTime`.

rdar://problem/35865151

Reviewers: EricWF, Hahnfeld

Subscribers: jkorous-apple, mclow.lists, cfe-commits, christof

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


Modified:

libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp

Modified: 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp?rev=326383&r1=326382&r2=326383&view=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
 Wed Feb 28 15:27:40 2018
@@ -116,12 +116,31 @@ bool TestSupportsMaxTime() {
 return !ec && new_write_time > max_sec - 1;
 }
 
+bool TestSupportsMinTime() {
+using namespace std::chrono;
+using Lim = std::numeric_limits;
+auto min_sec = 
duration_cast(file_time_type::min().time_since_epoch()).count();
+if (min_sec < Lim::min()) return false;
+std::error_code ec;
+std::time_t old_write_time, new_write_time;
+{ // WARNING: Do not assert in this scope.
+  scoped_test_env env;
+  const path file = env.create_file("file", 42);
+  old_write_time = LastWriteTime(file);
+  file_time_type tp = file_time_type::min();
+  fs::last_write_time(file, tp, ec);
+  new_write_time = LastWriteTime(file);
+}
+return !ec && new_write_time < min_sec + 1;
+}
+
 #if defined(__clang__)
 #pragma clang diagnostic pop
 #endif
 
 static const bool SupportsNegativeTimes = TestSupportsNegativeTimes();
 static const bool SupportsMaxTime = TestSupportsMaxTime();
+static const bool SupportsMinTime = TestSupportsMinTime();
 
 } // end namespace
 
@@ -140,6 +159,8 @@ static const bool SupportsMaxTime = Test
 // (B) 'tp' is non-negative or the filesystem supports negative times.
 // (C) 'tp' is not 'file_time_type::max()' or the filesystem supports the max
 // value.
+// (D) 'tp' is not 'file_time_type::min()' or the filesystem supports the min
+// value.
 inline bool TimeIsRepresentableByFilesystem(file_time_type tp) {
 using namespace std::chrono;
 using Lim = std::numeric_limits;
@@ -148,6 +169,7 @@ inline bool TimeIsRepresentableByFilesys
 if (sec < Lim::min() || sec > Lim::max())   return false;
 else if (microsec < 0 && !SupportsNegativeTimes) return false;
 else if (tp == file_time_type::max() && !SupportsMaxTime) return false;
+else if (tp == file_time_type::min() && !SupportsMinTime) return false;
 return true;
 }
 
@@ -355,20 +377,20 @@ TEST_CASE(test_write_min_time)
 TEST_CHECK(!ec);
 TEST_CHECK(tt >= new_time);
 TEST_CHECK(tt < new_time + Sec(1));
-}
 
-ec = GetTestEC();
-last_write_time(p, Clock::now());
+ec = GetTestEC();
+last_write_time(p, Clock::now());
 
-new_time = file_time_type::min() + MicroSec(1);
+new_time = file_time_type::min() + MicroSec(1);
 
-last_write_time(p, new_time, ec);
-tt = last_write_time(p);
+last_write_time(p, new_time, ec);
+tt = last_write_time(p);
 
-if (TimeIsRepresentableByFilesystem(new_time)) {
-TEST_CHECK(!ec);
-TEST_CHECK(tt >= new_time);
-TEST_CHECK(tt < new_time + Sec(1));
+if (TimeIsRepresentableByFilesystem(new_time)) {
+TEST_CHECK(!ec);
+TEST_CHECK(tt >= new_time);
+TEST_CHECK(tt < new_time + Sec(1));
+}
 }
 }
 


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


[libcxx] r334431 - Mark the test using to require c++experimental.

2018-06-11 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon Jun 11 12:42:27 2018
New Revision: 334431

URL: http://llvm.org/viewvc/llvm-project?rev=334431&view=rev
Log:
Mark the test using  to require c++experimental.

When built against the old libc++ version the test was causing linker error

Undefined symbols for architecture x86_64:
  "std::experimental::fundamentals_v1::pmr::new_delete_resource()", referenced 
from:
  void test_evil() in 
construct_piecewise_pair_evil.pass.cpp.o
  void test_evil() in 
construct_piecewise_pair_evil.pass.cpp.o
  void test_evil() in 
construct_piecewise_pair_evil.pass.cpp.o
  void test_evil() in 
construct_piecewise_pair_evil.pass.cpp.o
  void test_evil() in 
construct_piecewise_pair_evil.pass.cpp.o
  void test_evil() in 
construct_piecewise_pair_evil.pass.cpp.o
  void test_evil() in 
construct_piecewise_pair_evil.pass.cpp.o
  ...


Modified:

libcxx/trunk/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair_evil.pass.cpp

Modified: 
libcxx/trunk/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair_evil.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair_evil.pass.cpp?rev=334431&r1=334430&r2=334431&view=diff
==
--- 
libcxx/trunk/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair_evil.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair_evil.pass.cpp
 Mon Jun 11 12:42:27 2018
@@ -7,6 +7,7 @@
 //
 
//===--===//
 
+// REQUIRES: c++experimental
 // UNSUPPORTED: c++98, c++03
 
 // 


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


r345212 - [VFS] Remove 'ignore-non-existent-contents' attribute for YAML-based VFS.

2018-10-24 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Oct 24 15:39:38 2018
New Revision: 345212

URL: http://llvm.org/viewvc/llvm-project?rev=345212&view=rev
Log:
[VFS] Remove 'ignore-non-existent-contents' attribute for YAML-based VFS.

'ignore-non-existent-contents' stopped working after r342232 in a way
that the actual attribute value isn't used and it works as if it is
always `true`.

Common use case for VFS iteration is iterating through files in umbrella
directories for modules. Ability to detect if some VFS entries point to
non-existing files is nice but non-critical. Instead of adding back
support for `'ignore-non-existent-contents': false` I am removing the
attribute, because such scenario isn't used widely enough and stricter
checks don't provide enough value to justify the maintenance.

rdar://problem/45176119

Reviewers: bruno

Reviewed By: bruno

Subscribers: hiraditya, dexonsmith, sammccall, cfe-commits

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

Modified:
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
cfe/trunk/test/Modules/crash-vfs-headermaps.m
cfe/trunk/test/Modules/crash-vfs-include-pch.m
cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m
cfe/trunk/test/Modules/crash-vfs-relative-incdir.m
cfe/trunk/test/Modules/crash-vfs-run-reproducer.m
cfe/trunk/test/VFS/Inputs/MissingVFS/vfsoverlay.yaml
cfe/trunk/test/VFS/Inputs/Nonmodular/nonmodular-headers.yaml
cfe/trunk/test/VFS/Inputs/bar-headers.yaml
cfe/trunk/test/VFS/Inputs/vfsoverlay2.yaml

Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=345212&r1=345211&r2=345212&view=diff
==
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Wed Oct 24 15:39:38 
2018
@@ -156,10 +156,6 @@ void ModuleDependencyCollector::writeFil
   // allows crash reproducer scripts to work across machines.
   VFSWriter.setOverlayDir(VFSDir);
 
-  // Do not ignore non existent contents otherwise we might skip something
-  // that should have been collected here.
-  VFSWriter.setIgnoreNonExistentContents(false);
-
   // Explicitly set case sensitivity for the YAML writer. For that, find out
   // the sensitivity at the path where the headers all collected to.
   VFSWriter.setCaseSensitivity(isCaseSensitivePath(VFSDir));

Modified: cfe/trunk/test/Modules/crash-vfs-headermaps.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-headermaps.m?rev=345212&r1=345211&r2=345212&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-headermaps.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-headermaps.m Wed Oct 24 15:39:38 2018
@@ -32,7 +32,6 @@
 // CHECKYAML: 'case-sensitive':
 // CHECKYAML-NEXT: 'use-external-names': 'false',
 // CHECKYAML-NEXT: 'overlay-relative': 'true',
-// CHECKYAML-NEXT: 'ignore-non-existent-contents': 'false'
 // CHECKYAML: 'type': 'directory'
 // CHECKYAML: 'name': "/[[PATH:.*]]/Foo.framework/Headers",
 // CHECKYAML-NEXT: 'contents': [

Modified: cfe/trunk/test/Modules/crash-vfs-include-pch.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-include-pch.m?rev=345212&r1=345211&r2=345212&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-include-pch.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-include-pch.m Wed Oct 24 15:39:38 2018
@@ -33,7 +33,6 @@ void g() { double x = DBL_MAX; }
 // CHECKYAML: 'case-sensitive':
 // CHECKYAML-NEXT: 'use-external-names': 'false',
 // CHECKYAML-NEXT: 'overlay-relative': 'true',
-// CHECKYAML-NEXT: 'ignore-non-existent-contents': 'false'
 // CHECKYAML: 'type': 'directory'
 // CHECKYAML: 'name': "/[[PATH:.*]]/out",
 // CHECKYAML-NEXT: 'contents': [

Modified: cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m?rev=345212&r1=345211&r2=345212&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m Wed Oct 24 15:39:38 2018
@@ -36,7 +36,6 @@
 // CHECKYAML: 'case-sensitive':
 // CHECKYAML-NEXT: 'use-external-names': 'false',
 // CHECKYAML-NEXT: 'overlay-relative': 'true',
-// CHECKYAML-NEXT: 'ignore-non-existent-contents': 'false'
 // CHECKYAML: 'type': 'directory'
 // CHECKYAML: 'name': "/[[PATH:.*]]/example"
 // CHECKYAML: 'contents': [

Modified: cfe/trunk/test/Modules/crash-vfs-relative-incdir.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-relative-incdir.m?rev=345212&r1=345211&r2=345212&view=diff
==
--- cfe/trunk/test/

r345432 - [VFS] Add property 'fallthrough' that controls fallback to real file system.

2018-10-26 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Oct 26 15:16:24 2018
New Revision: 345432

URL: http://llvm.org/viewvc/llvm-project?rev=345432&view=rev
Log:
[VFS] Add property 'fallthrough' that controls fallback to real file system.

Default property value 'true' preserves current behavior. Value 'false' can be
used to create VFS "root", file system that gives better control over which
files compiler can use during compilation as there are no unpredictable
accesses to real file system.

Non-fallthrough use case changes how we treat multiple VFS overlay
files. Instead of all of them being at the same level just above a real
file system, now they are nested and subsequent overlays can refer to
files in previous overlays.

Change is done both in LLVM and Clang, corresponding LLVM commit is r345431.

rdar://problem/39465552

Reviewers: bruno, benlangmuir

Reviewed By: bruno

Subscribers: dexonsmith, cfe-commits, hiraditya

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


Added:
cfe/trunk/test/VFS/Inputs/Broken.framework/
cfe/trunk/test/VFS/Inputs/Broken.framework/Headers/
cfe/trunk/test/VFS/Inputs/Broken.framework/Headers/Error.h
cfe/trunk/test/VFS/Inputs/Broken.framework/Modules/
cfe/trunk/test/VFS/Inputs/Broken.framework/Modules/module.modulemap
cfe/trunk/test/VFS/Inputs/Broken.framework/VFSHeaders/
cfe/trunk/test/VFS/Inputs/Broken.framework/VFSHeaders/A.h
cfe/trunk/test/VFS/Inputs/vfsroot.yaml
cfe/trunk/test/VFS/vfsroot-include.c
cfe/trunk/test/VFS/vfsroot-module.m
cfe/trunk/test/VFS/vfsroot-with-overlay.c
Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=345432&r1=345431&r2=345432&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Oct 26 15:16:24 2018
@@ -3297,25 +3297,27 @@ IntrusiveRefCntPtr Overlay(
-  new llvm::vfs::OverlayFileSystem(BaseFS));
+  IntrusiveRefCntPtr Result = BaseFS;
   // earlier vfs files are on the bottom
   for (const auto &File : CI.getHeaderSearchOpts().VFSOverlayFiles) {
 llvm::ErrorOr> Buffer =
-BaseFS->getBufferForFile(File);
+Result->getBufferForFile(File);
 if (!Buffer) {
   Diags.Report(diag::err_missing_vfs_overlay_file) << File;
   continue;
 }
 
 IntrusiveRefCntPtr FS = llvm::vfs::getVFSFromYAML(
-std::move(Buffer.get()), /*DiagHandler*/ nullptr, File);
-if (FS)
-  Overlay->pushOverlay(FS);
-else
+std::move(Buffer.get()), /*DiagHandler*/ nullptr, File,
+/*DiagContext*/ nullptr, Result);
+if (!FS) {
   Diags.Report(diag::err_invalid_vfs_overlay) << File;
+  continue;
+}
+
+Result = FS;
   }
-  return Overlay;
+  return Result;
 }
 
 } // namespace clang

Added: cfe/trunk/test/VFS/Inputs/Broken.framework/Headers/Error.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Broken.framework/Headers/Error.h?rev=345432&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Broken.framework/Headers/Error.h (added)
+++ cfe/trunk/test/VFS/Inputs/Broken.framework/Headers/Error.h Fri Oct 26 
15:16:24 2018
@@ -0,0 +1,3 @@
+// Error.h
+
+#error Should not include this header in a module

Added: cfe/trunk/test/VFS/Inputs/Broken.framework/Modules/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Broken.framework/Modules/module.modulemap?rev=345432&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Broken.framework/Modules/module.modulemap (added)
+++ cfe/trunk/test/VFS/Inputs/Broken.framework/Modules/module.modulemap Fri Oct 
26 15:16:24 2018
@@ -0,0 +1,6 @@
+framework module Broken [extern_c] {
+  umbrella "Headers"
+  export *
+  module * { export * }
+}
+

Added: cfe/trunk/test/VFS/Inputs/Broken.framework/VFSHeaders/A.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Broken.framework/VFSHeaders/A.h?rev=345432&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Broken.framework/VFSHeaders/A.h (added)
+++ cfe/trunk/test/VFS/Inputs/Broken.framework/VFSHeaders/A.h Fri Oct 26 
15:16:24 2018
@@ -0,0 +1 @@
+// A.h

Added: cfe/trunk/test/VFS/Inputs/vfsroot.yaml
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/vfsroot.yaml?rev=345432&view=auto
==
--- cfe/trunk/test/VFS/Inputs/vfsroot.yaml (added)
+++ cfe/trunk/test/VFS/Inputs/vfsroot.yaml Fri Oct 26 15:16:24 2018
@@ -0,0 +1,55 @@
+{
+  'version': 0,
+  'use-external-names': false,
+  'fallthrough': false,
+  'roots': [
+{ 'name': '/tests', 'type': 

r351232 - [MSVC Compat] Fix typo correction for inclusion directives.

2019-01-15 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Jan 15 12:08:23 2019
New Revision: 351232

URL: http://llvm.org/viewvc/llvm-project?rev=351232&view=rev
Log:
[MSVC Compat] Fix typo correction for inclusion directives.

In MSVC compatibility mode we were checking not the typo corrected
filename but the original filename.

Reviewers: christylee, compnerd

Reviewed By: christylee

Subscribers: jkorous, dexonsmith, sammccall, hokein, cfe-commits

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

Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Preprocessor/include-likely-typo.c

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=351232&r1=351231&r2=351232&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Jan 15 12:08:23 2019
@@ -1813,9 +1813,17 @@ void Preprocessor::HandleIncludeDirectiv
   return Filename;
 };
 StringRef TypoCorrectionName = CorrectTypoFilename(Filename);
+SmallString<128> NormalizedTypoCorrectionPath;
+if (LangOpts.MSVCCompat) {
+  NormalizedTypoCorrectionPath = TypoCorrectionName.str();
+#ifndef _WIN32
+  llvm::sys::path::native(NormalizedTypoCorrectionPath);
+#endif
+}
 File = LookupFile(
 FilenameLoc,
-LangOpts.MSVCCompat ? NormalizedPath.c_str() : TypoCorrectionName,
+LangOpts.MSVCCompat ? NormalizedTypoCorrectionPath.c_str()
+: TypoCorrectionName,
 isAngled, LookupFrom, LookupFromFile, CurDir,
 Callbacks ? &SearchPath : nullptr,
 Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped);

Modified: cfe/trunk/test/Preprocessor/include-likely-typo.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-likely-typo.c?rev=351232&r1=351231&r2=351232&view=diff
==
--- cfe/trunk/test/Preprocessor/include-likely-typo.c (original)
+++ cfe/trunk/test/Preprocessor/include-likely-typo.c Tue Jan 15 12:08:23 2019
@@ -1,3 +1,4 @@
 // RUN: %clang_cc1 %s -verify
+// RUN: %clang_cc1 -fms-compatibility %s -verify
 
 #include "" // expected-error 
{{'' file not found, did you mean 
'empty_file_to_include.h'?}}


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


r351402 - [Frontend] Make WrapperFrontendAction call WrappedAction.PrepareToExecuteAction.

2019-01-16 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Jan 16 16:20:43 2019
New Revision: 351402

URL: http://llvm.org/viewvc/llvm-project?rev=351402&view=rev
Log:
[Frontend] Make WrapperFrontendAction call WrappedAction.PrepareToExecuteAction.

Fixes `-emit-header-module` when GenerateHeaderModuleAction is wrapped
by another frontend action.

rdar://problem/47302588

Reviewers: rsmith, arphaman

Reviewed By: arphaman

Subscribers: jkorous, dexonsmith, cfe-commits

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

Modified:
cfe/trunk/include/clang/Frontend/FrontendAction.h
cfe/trunk/lib/Frontend/FrontendAction.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendAction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendAction.h?rev=351402&r1=351401&r2=351402&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendAction.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendAction.h Wed Jan 16 16:20:43 2019
@@ -305,6 +305,7 @@ class WrapperFrontendAction : public Fro
   std::unique_ptr WrappedAction;
 
 protected:
+  bool PrepareToExecuteAction(CompilerInstance &CI) override;
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) override;
   bool BeginInvocation(CompilerInstance &CI) override;

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=351402&r1=351401&r2=351402&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Wed Jan 16 16:20:43 2019
@@ -1045,6 +1045,9 @@ PreprocessorFrontendAction::CreateASTCon
   llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
 }
 
+bool WrapperFrontendAction::PrepareToExecuteAction(CompilerInstance &CI) {
+  return WrappedAction->PrepareToExecuteAction(CI);
+}
 std::unique_ptr
 WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) {


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


r345897 - [CodeGen] Move `emitConstant` from ScalarExprEmitter to CodeGenFunction. NFC.

2018-11-01 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Nov  1 14:57:05 2018
New Revision: 345897

URL: http://llvm.org/viewvc/llvm-project?rev=345897&view=rev
Log:
[CodeGen] Move `emitConstant` from ScalarExprEmitter to CodeGenFunction. NFC.

The goal is to use `emitConstant` in more places. Didn't move
`ComplexExprEmitter::emitConstant` because it returns a different type.

Reviewers: rjmccall, ahatanak

Reviewed By: rjmccall

Subscribers: dexonsmith, erik.pilkington, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=345897&r1=345896&r2=345897&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Nov  1 14:57:05 2018
@@ -1491,6 +1491,16 @@ CodeGenFunction::tryEmitAsConstant(const
   return ConstantEmission();
 }
 
+llvm::Value *CodeGenFunction::emitScalarConstant(
+const CodeGenFunction::ConstantEmission &Constant, Expr *E) {
+  assert(Constant && "not a constant");
+  if (Constant.isReference())
+return EmitLoadOfLValue(Constant.getReferenceLValue(*this, E),
+E->getExprLoc())
+.getScalarVal();
+  return Constant.getValue();
+}
+
 llvm::Value *CodeGenFunction::EmitLoadOfScalar(LValue lvalue,
SourceLocation Loc) {
   return EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatile(),

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=345897&r1=345896&r2=345897&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Nov  1 14:57:05 2018
@@ -466,19 +466,10 @@ public:
 return CGF.getOrCreateOpaqueRValueMapping(E).getScalarVal();
   }
 
-  Value *emitConstant(const CodeGenFunction::ConstantEmission &Constant,
-  Expr *E) {
-assert(Constant && "not a constant");
-if (Constant.isReference())
-  return EmitLoadOfLValue(Constant.getReferenceLValue(CGF, E),
-  E->getExprLoc());
-return Constant.getValue();
-  }
-
   // l-values.
   Value *VisitDeclRefExpr(DeclRefExpr *E) {
 if (CodeGenFunction::ConstantEmission Constant = CGF.tryEmitAsConstant(E))
-  return emitConstant(Constant, E);
+  return CGF.emitScalarConstant(Constant, E);
 return EmitLoadOfLValue(E);
   }
 
@@ -1714,7 +1705,7 @@ Value *ScalarExprEmitter::VisitConvertVe
 Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) {
   if (CodeGenFunction::ConstantEmission Constant = CGF.tryEmitAsConstant(E)) {
 CGF.EmitIgnoredExpr(E->getBase());
-return emitConstant(Constant, E);
+return CGF.emitScalarConstant(Constant, E);
   } else {
 llvm::APSInt Value;
 if (E->EvaluateAsInt(Value, CGF.getContext(), Expr::SE_AllowSideEffects)) {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=345897&r1=345896&r2=345897&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Nov  1 14:57:05 2018
@@ -3524,6 +3524,7 @@ public:
 
   ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr);
   ConstantEmission tryEmitAsConstant(const MemberExpr *ME);
+  llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E);
 
   RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e,
 AggValueSlot slot = AggValueSlot::ignored());


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


r345903 - [CodeGen] Fix assertion on referencing constexpr Obj-C object with ARC.

2018-11-01 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Nov  1 15:50:08 2018
New Revision: 345903

URL: http://llvm.org/viewvc/llvm-project?rev=345903&view=rev
Log:
[CodeGen] Fix assertion on referencing constexpr Obj-C object with ARC.

Failed assertion is
> Assertion failed: ((ND->isUsed(false) || !isa(ND) || 
> !E->getLocation().isValid()) && "Should not use decl without marking it 
> used!"), function EmitDeclRefLValue, file 
> llvm-project/clang/lib/CodeGen/CGExpr.cpp, line 2437.

`EmitDeclRefLValue` mentions
> // A DeclRefExpr for a reference initialized by a constant expression can
> // appear without being odr-used. Directly emit the constant initializer.

The fix is to use the similar approach for non-references as for references. It
is achieved by trying to emit a constant before we attempt to load non-odr-used
variable as LValue.

rdar://problem/40650504

Reviewers: ahatanak, rjmccall

Reviewed By: rjmccall

Subscribers: dexonsmith, erik.pilkington, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjCXX/arc-constexpr.mm

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=345903&r1=345902&r2=345903&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Thu Nov  1 15:50:08 2018
@@ -2447,27 +2447,36 @@ void CodeGenFunction::EmitObjCAutoreleas
 EHStack.pushCleanup(NormalCleanup, Ptr);
 }
 
-static TryEmitResult tryEmitARCRetainLoadOfScalar(CodeGenFunction &CGF,
-  LValue lvalue,
-  QualType type) {
-  switch (type.getObjCLifetime()) {
+static bool shouldRetainObjCLifetime(Qualifiers::ObjCLifetime lifetime) {
+  switch (lifetime) {
   case Qualifiers::OCL_None:
   case Qualifiers::OCL_ExplicitNone:
   case Qualifiers::OCL_Strong:
   case Qualifiers::OCL_Autoreleasing:
-return TryEmitResult(CGF.EmitLoadOfLValue(lvalue,
-  SourceLocation()).getScalarVal(),
- false);
+return true;
 
   case Qualifiers::OCL_Weak:
-return TryEmitResult(CGF.EmitARCLoadWeakRetained(lvalue.getAddress()),
- true);
+return false;
   }
 
   llvm_unreachable("impossible lifetime!");
 }
 
 static TryEmitResult tryEmitARCRetainLoadOfScalar(CodeGenFunction &CGF,
+  LValue lvalue,
+  QualType type) {
+  llvm::Value *result;
+  bool shouldRetain = shouldRetainObjCLifetime(type.getObjCLifetime());
+  if (shouldRetain) {
+result = CGF.EmitLoadOfLValue(lvalue, SourceLocation()).getScalarVal();
+  } else {
+assert(type.getObjCLifetime() == Qualifiers::OCL_Weak);
+result = CGF.EmitARCLoadWeakRetained(lvalue.getAddress());
+  }
+  return TryEmitResult(result, !shouldRetain);
+}
+
+static TryEmitResult tryEmitARCRetainLoadOfScalar(CodeGenFunction &CGF,
   const Expr *e) {
   e = e->IgnoreParens();
   QualType type = e->getType();
@@ -2501,6 +2510,16 @@ static TryEmitResult tryEmitARCRetainLoa
   cast(e)->getOpcode() == BO_Assign)
 return TryEmitResult(CGF.EmitScalarExpr(e), false);
 
+  // Try to emit code for scalar constant instead of emitting LValue and
+  // loading it because we are not guaranteed to have an l-value. One of such
+  // cases is DeclRefExpr referencing non-odr-used constant-evaluated variable.
+  if (const auto *decl_expr = dyn_cast(e)) {
+auto *DRE = const_cast(decl_expr);
+if (CodeGenFunction::ConstantEmission constant = 
CGF.tryEmitAsConstant(DRE))
+  return TryEmitResult(CGF.emitScalarConstant(constant, DRE),
+   !shouldRetainObjCLifetime(type.getObjCLifetime()));
+  }
+
   return tryEmitARCRetainLoadOfScalar(CGF, CGF.EmitLValue(e), type);
 }
 

Modified: cfe/trunk/test/CodeGenObjCXX/arc-constexpr.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-constexpr.mm?rev=345903&r1=345902&r2=345903&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/arc-constexpr.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/arc-constexpr.mm Thu Nov  1 15:50:08 2018
@@ -1,18 +1,51 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -o - 
-std=c++11 %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc 
-fobjc-runtime-has-weak -o - -std=c++11 %s | FileCheck %s
 
 // CHECK: %[[TYPE:[a-z0-9]+]] = type opaque
 // CHECK: @[[CFSTRING:[a-z0-9_]+]] = private global 
%struct.__NSConstantString_tag
+@class NSString;
 
-// CHECK: define void @_Z5test1v
+// CHECK-LABEL: define void @_Z5test1v
 // CHECK:   %[[ALLOCA:[A-Z]+]] = alloca %[[TYPE]]*
 // CH

r346200 - [CodeGenCXX] XFAIL test for ASAN on Darwin.

2018-11-05 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon Nov  5 18:16:28 2018
New Revision: 346200

URL: http://llvm.org/viewvc/llvm-project?rev=346200&view=rev
Log:
[CodeGenCXX] XFAIL test for ASAN on Darwin.

The test hits stack overflow trying to instantiate recursive templates.
It is observed with ASAN and not with a regular build because ASAN
increases stack frame size.

rdar://problem/45009892

Reviewers: george.karpenkov, lebedev.ri

Reviewed By: george.karpenkov

Subscribers: dexonsmith, rjmccall, cfe-commits

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

Modified:
cfe/trunk/test/CodeGenCXX/castexpr-basepathsize-threshold.cpp

Modified: cfe/trunk/test/CodeGenCXX/castexpr-basepathsize-threshold.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/castexpr-basepathsize-threshold.cpp?rev=346200&r1=346199&r2=346200&view=diff
==
--- cfe/trunk/test/CodeGenCXX/castexpr-basepathsize-threshold.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/castexpr-basepathsize-threshold.cpp Mon Nov  5 
18:16:28 2018
@@ -3,6 +3,10 @@
 // https://bugs.llvm.org/show_bug.cgi?id=38356
 // We only check that we do not crash.
 
+// ASAN increases stack usage, so we are hitting stack overflow before reaching
+// recursive template instantiation limit.
+// XFAIL: darwin && asan
+
 template 
 struct d : d {};
 template 


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


r347012 - [VFS] Implement `RedirectingFileSystem::getRealPath`.

2018-11-15 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Nov 15 17:18:04 2018
New Revision: 347012

URL: http://llvm.org/viewvc/llvm-project?rev=347012&view=rev
Log:
[VFS] Implement `RedirectingFileSystem::getRealPath`.

It fixes the case when Objective-C framework is added as a subframework
through a symlink. When parent framework infers a module map and fails
to detect a symlink, it would add a subframework as a submodule. And
when we parse module map for the subframework, we would encounter an
error like

> error: umbrella for module 'WithSubframework.Foo' already covers this 
> directory

By implementing `getRealPath` "an egregious but useful hack" in
`ModuleMap::inferFrameworkModule` works as expected.

LLVM commit is r347009.

rdar://problem/45821279

Reviewers: bruno, benlangmuir, erik.pilkington

Reviewed By: bruno

Subscribers: hiraditya, dexonsmith, JDevlieghere, cfe-commits, llvm-commits

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


Added:
cfe/trunk/test/VFS/subframework-symlink.m

Added: cfe/trunk/test/VFS/subframework-symlink.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/subframework-symlink.m?rev=347012&view=auto
==
--- cfe/trunk/test/VFS/subframework-symlink.m (added)
+++ cfe/trunk/test/VFS/subframework-symlink.m Thu Nov 15 17:18:04 2018
@@ -0,0 +1,23 @@
+// REQUIRES: shell
+
+// Test that when a subframework is a symlink to another framework, we don't
+// add it as a submodule to the enclosing framework. We also need to make clang
+// to infer module for the enclosing framework. For this we don't have
+// a module map for the framework itself but have it in a parent directory.
+//
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'framework module * {}' > %t/module.modulemap
+// RUN: mkdir -p %t/WithSubframework.framework/Headers
+// RUN: echo '#include ' > 
%t/WithSubframework.framework/Headers/WithSubframework.h
+// RUN: cp -R %S/Inputs/Foo.framework %t
+// RUN: mkdir -p %t/WithSubframework.framework/Frameworks
+// RUN: ln -s %t/Foo.framework %t/WithSubframework.framework/Frameworks
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache1 -F %t -fsyntax-only %s
+
+// Adding VFS overlay shouldn't change this behavior.
+//
+// RUN: sed -e "s:INPUT_DIR:/InvalidPath:g" -e "s:OUT_DIR:/InvalidPath:g" 
%S/Inputs/vfsoverlay.yaml > %t/overlay.yaml
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache2 -F %t -fsyntax-only %s -ivfsoverlay 
%t/overlay.yaml
+
+#import 


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


r348641 - [Preprocessor] Don't avoid entering included files after hitting a fatal error.

2018-12-07 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Dec  7 12:29:54 2018
New Revision: 348641

URL: http://llvm.org/viewvc/llvm-project?rev=348641&view=rev
Log:
[Preprocessor] Don't avoid entering included files after hitting a fatal error.

Change in r337953 violated the contract for `CXTranslationUnit_KeepGoing`:

> Do not stop processing when fatal errors are encountered.

Use different approach to fix long processing times with multiple inclusion
cycles. Instead of stopping preprocessing for fatal errors, do this after
reaching the max allowed include depth and only for the files that were
processed already. It is likely but not guaranteed those files cause a cycle.

rdar://problem/46108547

Reviewers: erik.pilkington, arphaman

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, ilya-biryukov, Dmitry.Kozhevnikov

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


Added:
cfe/trunk/test/Index/Inputs/cycle.h
cfe/trunk/test/Index/keep-going-include-cycle.c
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Index/keep-going.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=348641&r1=348640&r2=348641&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Dec  7 12:29:54 2018
@@ -319,6 +319,10 @@ class Preprocessor {
   /// This is used when loading a precompiled preamble.
   std::pair SkipMainFilePreamble;
 
+  /// Whether we hit an error due to reaching max allowed include depth. Allows
+  /// to avoid hitting the same error over and over again.
+  bool HasReachedMaxIncludeDepth = false;
+
 public:
   struct PreambleSkipInfo {
 SourceLocation HashTokenLoc;

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=348641&r1=348640&r2=348641&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Dec  7 12:29:54 2018
@@ -1707,6 +1707,7 @@ void Preprocessor::HandleIncludeDirectiv
   // Check that we don't have infinite #include recursion.
   if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
 Diag(FilenameTok, diag::err_pp_include_too_deep);
+HasReachedMaxIncludeDepth = true;
 return;
   }
 
@@ -1855,10 +1856,11 @@ void Preprocessor::HandleIncludeDirectiv
   if (PPOpts->SingleFileParseMode)
 ShouldEnter = false;
 
-  // Any diagnostics after the fatal error will not be visible. As the
-  // compilation failed already and errors in subsequently included files won't
-  // be visible, avoid preprocessing those files.
-  if (ShouldEnter && Diags->hasFatalErrorOccurred())
+  // If we've reached the max allowed include depth, it is usually due to an
+  // include cycle. Don't enter already processed files again as it can lead to
+  // reaching the max allowed include depth again.
+  if (ShouldEnter && HasReachedMaxIncludeDepth && File &&
+  HeaderInfo.getFileInfo(File).NumIncludes)
 ShouldEnter = false;
 
   // Determine whether we should try to import the module for this #include, if

Added: cfe/trunk/test/Index/Inputs/cycle.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/cycle.h?rev=348641&view=auto
==
--- cfe/trunk/test/Index/Inputs/cycle.h (added)
+++ cfe/trunk/test/Index/Inputs/cycle.h Fri Dec  7 12:29:54 2018
@@ -0,0 +1 @@
+#include "cycle.h"

Added: cfe/trunk/test/Index/keep-going-include-cycle.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/keep-going-include-cycle.c?rev=348641&view=auto
==
--- cfe/trunk/test/Index/keep-going-include-cycle.c (added)
+++ cfe/trunk/test/Index/keep-going-include-cycle.c Fri Dec  7 12:29:54 2018
@@ -0,0 +1,10 @@
+#include "cycle.h"
+#include "foo.h"
+
+// RUN: env CINDEXTEST_KEEP_GOING=1 c-index-test -test-print-type -I%S/Inputs 
%s 2> %t.stderr.txt | FileCheck %s
+// RUN: FileCheck -check-prefix CHECK-DIAG %s < %t.stderr.txt
+
+// Verify that we don't stop preprocessing after an include cycle.
+// CHECK: VarDecl=global_var:1:12 [type=int] [typekind=Int] [isPOD=1]
+
+// CHECK-DIAG: cycle.h:1:10: error: #include nested too deeply

Modified: cfe/trunk/test/Index/keep-going.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/keep-going.cpp?rev=348641&r1=348640&r2=348641&view=diff
==
--- cfe/trunk/test/Index/keep-going.cpp (original)
+++ cfe/trunk/test/Index/keep-going.cpp Fri Dec  7 12:29:54 2018
@@ -9,11 +9,18 @@ class B : public A { };
 
 class C : public A { };
 
-// R

r354942 - [index] Improve indexing support for MSPropertyDecl.

2019-02-26 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Feb 26 17:04:53 2019
New Revision: 354942

URL: http://llvm.org/viewvc/llvm-project?rev=354942&view=rev
Log:
[index] Improve indexing support for MSPropertyDecl.

Currently the symbol for MSPropertyDecl has kind `SymbolKind::Unknown`
which can trip up various indexing tools.

rdar://problem/46764224

Reviewers: akyrtzi, benlangmuir, jkorous

Reviewed By: jkorous

Subscribers: dexonsmith, cfe-commits, jkorous, jdoerfert, arphaman

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


Added:
cfe/trunk/test/Index/ms-property.cpp
Modified:
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/lib/Index/IndexSymbol.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=354942&r1=354941&r2=354942&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Tue Feb 26 17:04:53 2019
@@ -324,6 +324,7 @@ public:
   }
 
   bool VisitMSPropertyDecl(const MSPropertyDecl *D) {
+TRY_DECL(D, IndexCtx.handleDecl(D));
 handleDeclarator(D);
 return true;
   }

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=354942&r1=354941&r2=354942&view=diff
==
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Tue Feb 26 17:04:53 2019
@@ -324,6 +324,14 @@ SymbolInfo index::getSymbolInfo(const De
   Info.Kind = SymbolKind::Variable;
   Info.Lang = SymbolLanguage::CXX;
   break;
+case Decl::MSProperty:
+  Info.Kind = SymbolKind::InstanceProperty;
+  if (const CXXRecordDecl *CXXRec =
+  dyn_cast(D->getDeclContext())) {
+if (!CXXRec->isCLike())
+  Info.Lang = SymbolLanguage::CXX;
+  }
+  break;
 default:
   break;
 }

Added: cfe/trunk/test/Index/ms-property.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/ms-property.cpp?rev=354942&view=auto
==
--- cfe/trunk/test/Index/ms-property.cpp (added)
+++ cfe/trunk/test/Index/ms-property.cpp Tue Feb 26 17:04:53 2019
@@ -0,0 +1,32 @@
+// RUN: c-index-test core -print-source-symbols -- -fms-extensions 
-fno-ms-compatibility %s | FileCheck %s
+
+// CHECK: [[@LINE+1]]:8 | struct/C++ | Simple | [[Simple_USR:.*]] | 
 | Def | rel: 0
+struct Simple {
+  int GetX() const;
+  // CHECK: [[@LINE-1]]:7 | instance-method/C++ | GetX | [[GetX_USR:.*]] | 
__ZNK6Simple4GetXEv | Decl,RelChild | rel: 1
+  // CHECK-NEXT: RelChild | Simple | [[Simple_USR]]
+
+  void PutX(int i);
+  // CHECK: [[@LINE-1]]:8 | instance-method/C++ | PutX | [[PutX_USR:.*]] | 
__ZN6Simple4PutXEi | Decl,RelChild | rel: 1
+  // CHECK-NEXT: RelChild | Simple | [[Simple_USR]]
+
+  __declspec(property(get=GetX, put=PutX)) int propX;
+  // CHECK: [[@LINE-1]]:48 | instance-property/C++ | propX | [[propX_USR:.*]] 
|  | Def,RelChild | rel: 1
+  // CHECK-NEXT: RelChild | Simple | [[Simple_USR]]
+};
+
+// CHECK: [[@LINE+1]]:5 | function/C | test | [[test_USR:.*]] | __Z4testv | 
Def | rel: 0
+int test() {
+  Simple s;
+  s.propX = 5;
+  // CHECK: [[@LINE-1]]:5 | instance-property/C++ | propX | [[propX_USR]] | 
 | Ref,RelCont | rel: 1
+  // CHECK-NEXT: RelCont | test | [[test_USR]]
+  // CHECK: [[@LINE-3]]:5 | instance-method/C++ | PutX | [[PutX_USR]] | 
__ZN6Simple4PutXEi | Ref,Call,RelCall,RelCont | rel: 1
+  // CHECK-NEXT: RelCall,RelCont | test | [[test_USR]]
+
+  return s.propX;
+  // CHECK: [[@LINE-1]]:12 | instance-property/C++ | propX | [[propX_USR]] | 
 | Ref,RelCont | rel: 1
+  // CHECK-NEXT: RelCont | test | [[test_USR]]
+  // CHECK: [[@LINE-3]]:12 | instance-method/C++ | GetX | [[GetX_USR]] | 
__ZNK6Simple4GetXEv | Ref,Call,RelCall,RelCont | rel: 1
+  // CHECK-NEXT: RelCall,RelCont | test | [[test_USR]]
+}


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


r354946 - [index] Fixup for r354942. Specify target in test to achieve stable mangling.

2019-02-26 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Feb 26 17:37:43 2019
New Revision: 354946

URL: http://llvm.org/viewvc/llvm-project?rev=354946&view=rev
Log:
[index] Fixup for r354942. Specify target in test to achieve stable mangling.

Modified:
cfe/trunk/test/Index/ms-property.cpp

Modified: cfe/trunk/test/Index/ms-property.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/ms-property.cpp?rev=354946&r1=354945&r2=354946&view=diff
==
--- cfe/trunk/test/Index/ms-property.cpp (original)
+++ cfe/trunk/test/Index/ms-property.cpp Tue Feb 26 17:37:43 2019
@@ -1,4 +1,4 @@
-// RUN: c-index-test core -print-source-symbols -- -fms-extensions 
-fno-ms-compatibility %s | FileCheck %s
+// RUN: c-index-test core -print-source-symbols -- -target 
x86_64-apple-darwin10 -fms-extensions -fno-ms-compatibility %s | FileCheck %s
 
 // CHECK: [[@LINE+1]]:8 | struct/C++ | Simple | [[Simple_USR:.*]] | 
 | Def | rel: 0
 struct Simple {


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


r355166 - [CodeGen] Fix calling llvm.var.annotation outside of a basic block.

2019-02-28 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Feb 28 18:15:39 2019
New Revision: 355166

URL: http://llvm.org/viewvc/llvm-project?rev=355166&view=rev
Log:
[CodeGen] Fix calling llvm.var.annotation outside of a basic block.

When we have an annotated local variable after a function returns, we
generate IR that fails verification with the error

> Instruction referencing instruction not embedded in a basic block!

And it means that bitcast referencing alloca doesn't have a parent basic
block.

Fix by checking if we are at an unreachable point and skip emitting
annotations. This approach is similar to the way we emit variable
initializer and debug info.

rdar://problem/46200420

Reviewers: rjmccall

Reviewed By: rjmccall

Subscribers: aprantl, jkorous, dexonsmith, cfe-commits

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


Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGen/annotations-builtin.c
cfe/trunk/test/CodeGen/annotations-var.c

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=355166&r1=355165&r2=355166&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Feb 28 18:15:39 2019
@@ -1577,7 +1577,7 @@ CodeGenFunction::EmitAutoVarAlloca(const
 (void)DI->EmitDeclareOfAutoVariable(&D, address.getPointer(), Builder);
   }
 
-  if (D.hasAttr())
+  if (D.hasAttr() && HaveInsertPoint())
 EmitVarAnnotations(&D, address.getPointer());
 
   // Make sure we call @llvm.lifetime.end.

Modified: cfe/trunk/test/CodeGen/annotations-builtin.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/annotations-builtin.c?rev=355166&r1=355165&r2=355166&view=diff
==
--- cfe/trunk/test/CodeGen/annotations-builtin.c (original)
+++ cfe/trunk/test/CodeGen/annotations-builtin.c Thu Feb 28 18:15:39 2019
@@ -43,4 +43,7 @@ int main(int argc, char **argv) {
 // CHECK: call i32 @llvm.annotation.i32
 // CHECK: inttoptr {{.*}} to i8**
 return 0;
+
+int after_return = __builtin_annotation(argc, "annotation_a");
+// CHECK-NOT: call i32 @llvm.annotation.i32
 }

Modified: cfe/trunk/test/CodeGen/annotations-var.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/annotations-var.c?rev=355166&r1=355165&r2=355166&view=diff
==
--- cfe/trunk/test/CodeGen/annotations-var.c (original)
+++ cfe/trunk/test/CodeGen/annotations-var.c Thu Feb 28 18:15:39 2019
@@ -39,10 +39,19 @@ void local(void) {
 // LOCAL-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr 
inbounds ([15 x i8], [15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), 
i32 33)
 }
 
+void local_after_return(void) {
+return;
+int localvar __attribute__((annotate("localvar_after_return"))) = 3;
+// Test we are not emitting instructions like bitcast or call outside of a 
basic block.
+// LOCAL-LABEL: define void @local_after_return()
+// LOCAL:  [[LOCALVAR:%.*]] = alloca i32,
+// LOCAL-NEXT: ret void
+}
+
 void undef(void) {
 int undefvar __attribute__((annotate("undefvar_ann_0")));
 // UNDEF-LABEL: define void @undef()
 // UNDEF:  [[UNDEFVAR:%.*]] = alloca i32,
 // UNDEF-NEXT: [[T0:%.*]] = bitcast i32* [[UNDEFVAR]] to i8*
-// UNDEF-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr 
inbounds ([15 x i8], [15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), 
i32 43)
+// UNDEF-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr 
inbounds ([15 x i8], [15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), 
i32 52)
 }


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


r357298 - [Sema] Fix assertion when `auto` parameter in lambda has an attribute.

2019-03-29 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Mar 29 11:47:07 2019
New Revision: 357298

URL: http://llvm.org/viewvc/llvm-project?rev=357298&view=rev
Log:
[Sema] Fix assertion when `auto` parameter in lambda has an attribute.

Fixes the assertion
> no Attr* for AttributedType*
> UNREACHABLE executed at llvm-project/clang/lib/Sema/SemaType.cpp:298!

In `TypeProcessingState::getAttributedType` we put into `AttrsForTypes`
types with `auto` but later in
`TypeProcessingState::takeAttrForAttributedType` we use transformed
types and that's why cannot find `Attr` corresponding to
`AttributedType`.

Fix by keeping `AttrsForTypes` up to date after replacing `AutoType`.

rdar://problem/47689465

Reviewers: rsmith, arphaman, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: jkorous, dexonsmith, jdoerfert, cfe-commits

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


Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaCXX/auto-cxx0x.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=357298&r1=357297&r2=357298&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Mar 29 11:47:07 2019
@@ -255,6 +255,23 @@ namespace {
   return T;
 }
 
+/// Completely replace the \c auto in \p TypeWithAuto by
+/// \p Replacement. Also replace \p TypeWithAuto in \c TypeAttrPair if
+/// necessary.
+QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement) {
+  QualType T = sema.ReplaceAutoType(TypeWithAuto, Replacement);
+  if (auto *AttrTy = TypeWithAuto->getAs()) {
+// Attributed type still should be an attributed type after 
replacement.
+auto *NewAttrTy = cast(T.getTypePtr());
+for (TypeAttrPair &A : AttrsForTypes) {
+  if (A.first == AttrTy)
+A.first = NewAttrTy;
+}
+AttrsForTypesSorted = false;
+  }
+  return T;
+}
+
 /// Extract and remove the Attr* for a given attributed type.
 const Attr *takeAttrForAttributedType(const AttributedType *AT) {
   if (!AttrsForTypesSorted) {
@@ -2938,7 +2955,7 @@ static QualType GetDeclSpecTypeForDeclar
 // template type parameter.
 // FIXME: Retain some type sugar to indicate that this was written
 // as 'auto'.
-T = SemaRef.ReplaceAutoType(
+T = state.ReplaceAutoType(
 T, QualType(CorrespondingTemplateParam->getTypeForDecl(), 0));
   }
   break;

Modified: cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/auto-cxx0x.cpp?rev=357298&r1=357297&r2=357298&view=diff
==
--- cfe/trunk/test/SemaCXX/auto-cxx0x.cpp (original)
+++ cfe/trunk/test/SemaCXX/auto-cxx0x.cpp Fri Mar 29 11:47:07 2019
@@ -15,3 +15,11 @@ void g() {
   // expected-error@-2 {{'auto' not allowed in lambda parameter}}
 #endif
 }
+
+void rdar47689465() {
+  int x = 0;
+  [](auto __attribute__((noderef)) *){}(&x);
+#if __cplusplus == 201103L
+  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+#endif
+}


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


r359713 - [Parser] Avoid correcting delayed typos in array subscript multiple times.

2019-05-01 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed May  1 12:24:50 2019
New Revision: 359713

URL: http://llvm.org/viewvc/llvm-project?rev=359713&view=rev
Log:
[Parser] Avoid correcting delayed typos in array subscript multiple times.

We correct some typos in `ActOnArraySubscriptExpr` and
`ActOnOMPArraySectionExpr`, so when their result is `ExprError`, we can
end up correcting delayed typos in the same expressions again. In
general it is OK but when `NumTypos` is incorrect, we can hit the
assertion

> Assertion failed: (Entry != DelayedTypos.end() && "Failed to get the state 
> for a TypoExpr!"), function getTypoExprState, file 
> clang/lib/Sema/SemaLookup.cpp, line 5219.

Fix by replacing some subscript `ExprResult` with typo-corrected expressions
instead of keeping the original expressions. Thus if original expressions
contained `TypoExpr`, we'll use corrected expressions instead of trying to
correct them again.

rdar://problem/47403222

Reviewers: rsmith, erik.pilkington, majnemer

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, cfe-commits

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


Added:
cfe/trunk/test/SemaObjC/typo-correction-subscript.m
Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/test/SemaCXX/typo-correction.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=359713&r1=359712&r2=359713&view=diff
==
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed May  1 12:24:50 2019
@@ -1582,7 +1582,9 @@ Parser::ParsePostfixExpressionSuffix(Exp
 
   SourceLocation RLoc = Tok.getLocation();
 
-  ExprResult OrigLHS = LHS;
+  LHS = Actions.CorrectDelayedTyposInExpr(LHS);
+  Idx = Actions.CorrectDelayedTyposInExpr(Idx);
+  Length = Actions.CorrectDelayedTyposInExpr(Length);
   if (!LHS.isInvalid() && !Idx.isInvalid() && !Length.isInvalid() &&
   Tok.is(tok::r_square)) {
 if (ColonLoc.isValid()) {
@@ -1594,12 +1596,6 @@ Parser::ParsePostfixExpressionSuffix(Exp
 }
   } else {
 LHS = ExprError();
-  }
-  if (LHS.isInvalid()) {
-(void)Actions.CorrectDelayedTyposInExpr(OrigLHS);
-(void)Actions.CorrectDelayedTyposInExpr(Idx);
-(void)Actions.CorrectDelayedTyposInExpr(Length);
-LHS = ExprError();
 Idx = ExprError();
   }
 

Modified: cfe/trunk/test/SemaCXX/typo-correction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=359713&r1=359712&r2=359713&view=diff
==
--- cfe/trunk/test/SemaCXX/typo-correction.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction.cpp Wed May  1 12:24:50 2019
@@ -678,7 +678,7 @@ namespace {
 struct a0is0 {};
 struct b0is0 {};
 int g() {
-  0 [ // expected-error {{subscripted value is not an array}}
+  0 [
   sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
 };
 }

Added: cfe/trunk/test/SemaObjC/typo-correction-subscript.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/typo-correction-subscript.m?rev=359713&view=auto
==
--- cfe/trunk/test/SemaObjC/typo-correction-subscript.m (added)
+++ cfe/trunk/test/SemaObjC/typo-correction-subscript.m Wed May  1 12:24:50 2019
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only 
-Wno-objc-root-class %s -verify -disable-free
+
+@class Dictionary;
+
+@interface Test
+@end
+@implementation Test
+// rdar://problem/47403222
+- (void)rdar47403222:(Dictionary *)opts {
+  [self undeclaredMethod:undeclaredArg];
+  // expected-error@-1{{no visible @interface for 'Test' declares the selector 
'undeclaredMethod:'}}
+  opts[(__bridge id)undeclaredKey] = 0;
+  // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}}
+}
+@end


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


r342517 - Add a callback for `__has_include` and use it for dependency scanning.

2018-09-18 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Sep 18 16:27:02 2018
New Revision: 342517

URL: http://llvm.org/viewvc/llvm-project?rev=342517&view=rev
Log:
Add a callback for `__has_include` and use it for dependency scanning.

This adds a preprocessor callback for the `__has_include` and
`__has_include_next` directives.

Successful checking for the presence of a header should add it to the list of
header dependencies so this overrides the callback in the dependency scanner.

Patch by Pete Cooper with some additions by me.

rdar://problem/39545636

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

Added:
cfe/trunk/test/Frontend/dependency-gen-has-include.c
Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/lib/Frontend/DependencyFile.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=342517&r1=342516&r2=342517&view=diff
==
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Tue Sep 18 16:27:02 2018
@@ -276,6 +276,12 @@ public:
SourceRange Range) {
   }
 
+  /// Hook called when a '__has_include' or '__has_include_next' directive is
+  /// read.
+  virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool 
IsAngled,
+  const FileEntry *File,
+  SrcMgr::CharacteristicKind FileType) {}
+
   /// Hook called when a source range is skipped.
   /// \param Range The SourceRange that was skipped. The range begins at the
   /// \#if/\#else directive and ends after the \#endif/\#else directive.
@@ -443,6 +449,13 @@ public:
 Second->PragmaDiagnostic(Loc, Namespace, mapping, Str);
   }
 
+  void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
+  const FileEntry *File,
+  SrcMgr::CharacteristicKind FileType) override {
+First->HasInclude(Loc, FileName, IsAngled, File, FileType);
+Second->HasInclude(Loc, FileName, IsAngled, File, FileType);
+  }
+
   void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo 
*Name,
  SourceLocation StateLoc, unsigned State) override 
{
 First->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State);

Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=342517&r1=342516&r2=342517&view=diff
==
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Tue Sep 18 16:27:02 2018
@@ -200,6 +200,10 @@ public:
   const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override;
 
+  void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled,
+  const FileEntry *File,
+  SrcMgr::CharacteristicKind FileType) override;
+
   void EndOfMainFile() override {
 OutputDependencyFile();
   }
@@ -328,6 +332,17 @@ void DFGImpl::InclusionDirective(SourceL
   }
 }
 
+void DFGImpl::HasInclude(SourceLocation Loc, StringRef SpelledFilename,
+ bool IsAngled, const FileEntry *File,
+ SrcMgr::CharacteristicKind FileType) {
+  if (!File)
+return;
+  StringRef Filename = File->getName();
+  if (!FileMatchesDepCriteria(Filename.data(), FileType))
+return;
+  AddFilename(llvm::sys::path::remove_leading_dotslash(Filename));
+}
+
 bool DFGImpl::AddFilename(StringRef Filename) {
   if (FilesSet.insert(Filename).second) {
 Files.push_back(Filename);

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=342517&r1=342516&r2=342517&view=diff
==
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Sep 18 16:27:02 2018
@@ -23,6 +23,7 @@
 #include "clang/Lex/CodeCompletionHandler.h"
 #include "clang/Lex/DirectoryLookup.h"
 #include "clang/Lex/ExternalPreprocessorSource.h"
+#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
@@ -1242,6 +1243,13 @@ static bool EvaluateHasIncludeCommon(Tok
   PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, 
LookupFromFile,
 CurDir, nullptr, nullptr, nullptr, nullptr);
 
+  if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {
+SrcMgr::CharacteristicKind FileType = SrcMgr::C_User;
+if (File)
+  FileType = PP.getHeaderSearchInfo().getFileDirFlavor(File);
+Callbacks->HasInclude(FilenameLoc, Filename, isAngled, File, FileType);
+  }
+
   // Ge

r353231 - [Preprocessor] Add a note with framework location for "file not found" error.

2019-02-05 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Feb  5 14:34:55 2019
New Revision: 353231

URL: http://llvm.org/viewvc/llvm-project?rev=353231&view=rev
Log:
[Preprocessor] Add a note with framework location for "file not found" error.

When a framework with the same name is available at multiple framework
search paths, we use the first matching location. If a framework at this
location doesn't have all the headers, it can be confusing for
developers because they see only an error `'Foo/Foo.h' file not found`,
can find the complete framework with required header, and don't know the
incomplete framework was used instead.

Add a note explaining a framework without required header was found.
Also mention framework directory path to make it easier to find the
incomplete framework.

rdar://problem/39246514

Reviewers: arphaman, erik.pilkington, jkorous

Reviewed By: jkorous

Subscribers: jkorous, dexonsmith, cfe-commits

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


Added:
cfe/trunk/test/Preprocessor/include-header-missing-in-framework.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/include/clang/Lex/DirectoryLookup.h
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=353231&r1=353230&r2=353231&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Feb  5 14:34:55 2019
@@ -418,6 +418,8 @@ def err_pp_file_not_found_angled_include
   "'%0' file not found with  include; use \"quotes\" instead">;
 def err_pp_file_not_found_typo_not_fatal
 : Error<"'%0' file not found, did you mean '%1'?">;
+def note_pp_framework_without_header : Note<
+  "did not find header '%0' in framework '%1' (loaded from '%2')">;
 def err_pp_error_opening_file : Error<
   "error opening file '%0': %1">, DefaultFatal;
 def err_pp_empty_filename : Error<"empty filename">;

Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=353231&r1=353230&r2=353231&view=diff
==
--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)
+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Tue Feb  5 14:34:55 2019
@@ -170,6 +170,9 @@ public:
   /// set to true if the file is located in a framework that has been
   /// user-specified to be treated as a system framework.
   ///
+  /// \param [out] IsFrameworkFound For a framework directory set to true if
+  /// specified '.framework' directory is found.
+  ///
   /// \param [out] MappedName if this is a headermap which maps the filename to
   /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this
   /// vector and point Filename to it.
@@ -180,6 +183,7 @@ public:
   Module *RequestingModule,
   ModuleMap::KnownHeader *SuggestedModule,
   bool &InUserSpecifiedSystemFramework,
+  bool &IsFrameworkFound,
   bool &HasBeenMapped,
   SmallVectorImpl &MappedName) const;
 
@@ -190,7 +194,8 @@ private:
   SmallVectorImpl *RelativePath,
   Module *RequestingModule,
   ModuleMap::KnownHeader *SuggestedModule,
-  bool &InUserSpecifiedSystemFramework) const;
+  bool &InUserSpecifiedSystemFramework,
+  bool &IsFrameworkFound) const;
 
 };
 

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=353231&r1=353230&r2=353231&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Tue Feb  5 14:34:55 2019
@@ -142,22 +142,22 @@ public:
   virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0;
 };
 
+/// This structure is used to record entries in our framework cache.
+struct FrameworkCacheEntry {
+  /// The directory entry which should be used for the cached framework.
+  const DirectoryEntry *Directory;
+
+  /// Whether this framework has been "user-specified" to be treated as if it
+  /// were a system framework (even if it was found outside a system framework
+  /// directory).
+  bool I

r353577 - [CodeGen][ObjC] Fix assert on calling `__builtin_constant_p` with ObjC objects.

2019-02-08 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Feb  8 15:02:13 2019
New Revision: 353577

URL: http://llvm.org/viewvc/llvm-project?rev=353577&view=rev
Log:
[CodeGen][ObjC] Fix assert on calling `__builtin_constant_p` with ObjC objects.

When we are calling `__builtin_constant_p` with ObjC objects of
different classes, we hit the assertion

> Assertion failed: (isa(Val) && "cast() argument of incompatible 
> type!"), function cast, file include/llvm/Support/Casting.h, line 254.

It happens because LLVM types for `ObjCInterfaceType` are opaque and
have no name (see `CodeGenTypes::ConvertType`). As the result, for
different ObjC classes we have different `is_constant` intrinsics with
the same name `llvm.is.constant.p0s_s`. When we try to reuse an
intrinsic with the same name, we fail because of type mismatch.

Fix by bitcasting `ObjCObjectPointerType` to `id` prior to passing as an
argument to `__builtin_constant_p`. This results in using intrinsic
`llvm.is.constant.p0i8` and correct types.

rdar://problem/47499250

Reviewers: rjmccall, ahatanak, void

Reviewed By: void, ahatanak

Subscribers: ddunbar, jkorous, hans, dexonsmith, cfe-commits

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


Added:
cfe/trunk/test/CodeGenObjC/builtin-constant-p.m
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=353577&r1=353576&r2=353577&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Feb  8 15:02:13 2019
@@ -1982,6 +1982,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   return RValue::get(ConstantInt::get(ResultType, 0));
 
 Value *ArgValue = EmitScalarExpr(Arg);
+if (ArgType->isObjCObjectPointerType()) {
+  // Convert Objective-C objects to id because we cannot distinguish 
between
+  // LLVM types for Obj-C classes as they are opaque.
+  ArgType = CGM.getContext().getObjCIdType();
+  ArgValue = Builder.CreateBitCast(ArgValue, ConvertType(ArgType));
+}
 Function *F =
 CGM.getIntrinsic(Intrinsic::is_constant, ConvertType(ArgType));
 Value *Result = Builder.CreateCall(F, ArgValue);

Added: cfe/trunk/test/CodeGenObjC/builtin-constant-p.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/builtin-constant-p.m?rev=353577&view=auto
==
--- cfe/trunk/test/CodeGenObjC/builtin-constant-p.m (added)
+++ cfe/trunk/test/CodeGenObjC/builtin-constant-p.m Fri Feb  8 15:02:13 2019
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -O3 
-disable-llvm-passes -o - %s | FileCheck %s
+
+// Test that can call `__builtin_constant_p` with instances of different
+// Objective-C classes.
+// rdar://problem/47499250
+@class Foo;
+@class Bar;
+
+extern void callee(void);
+
+// CHECK-LABEL: define void @test(%0* %foo, %1* %bar)
+void test(Foo *foo, Bar *bar) {
+  // CHECK: [[ADDR_FOO:%.*]] = bitcast %0* %{{.*}} to i8*
+  // CHECK-NEXT: call i1 @llvm.is.constant.p0i8(i8* [[ADDR_FOO]])
+  // CHECK: [[ADDR_BAR:%.*]] = bitcast %1* %{{.*}} to i8*
+  // CHECK-NEXT: call i1 @llvm.is.constant.p0i8(i8* [[ADDR_BAR]])
+  if (__builtin_constant_p(foo) && __builtin_constant_p(bar))
+callee();
+}
+
+// Test other Objective-C types.
+// CHECK-LABEL: define void @test_more(i8* %object, i8* %klass)
+void test_more(id object, Class klass) {
+  // CHECK: call i1 @llvm.is.constant.p0i8(i8* %{{.*}})
+  // CHECK: call i1 @llvm.is.constant.p0i8(i8* %{{.*}})
+  if (__builtin_constant_p(object) && __builtin_constant_p(klass))
+callee();
+}


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


[clang-tools-extra] r354069 - [clang-tidy] Mention language version in test explicitly.

2019-02-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Feb 14 14:37:30 2019
New Revision: 354069

URL: http://llvm.org/viewvc/llvm-project?rev=354069&view=rev
Log:
[clang-tidy] Mention language version in test explicitly.

"modernize-use-using" check is applicable only to C++11 and later. Spell it out
to avoid relying on default language version.

rdar://problem/47932196

Modified:
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp?rev=354069&r1=354068&r2=354069&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp Thu Feb 
14 14:37:30 2019
@@ -8,7 +8,7 @@
 // RUN: cp -r %S/Inputs/mock-libcxx %t/
 //
 // Pretend clang is installed beside the mock library that we provided.
-// RUN: echo '[{"directory":"%t","command":"%t/mock-libcxx/bin/clang++ 
-stdlib=libc++ -target x86_64-apple-darwin -c test.cpp","file":"test.cpp"}]' | 
sed -e 's/\\/\//g' > %t/compile_commands.json
+// RUN: echo '[{"directory":"%t","command":"%t/mock-libcxx/bin/clang++ 
-stdlib=libc++ -std=c++11 -target x86_64-apple-darwin -c 
test.cpp","file":"test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
 // RUN: cp "%s" "%t/test.cpp"
 // RUN: clang-tidy -header-filter='.*' -system-headers 
-checks='-*,modernize-use-using'  "%t/test.cpp" | FileCheck %s
 // CHECK: mock_vector:{{[0-9]+}}:{{[0-9]+}}: warning: use 'using' instead of 
'typedef'


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


r354084 - [Driver][Darwin] Emit an error when using -pg on OS without support for it.

2019-02-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Feb 14 15:50:44 2019
New Revision: 354084

URL: http://llvm.org/viewvc/llvm-project?rev=354084&view=rev
Log:
[Driver][Darwin] Emit an error when using -pg on OS without support for it.

Instead of letting a program fail at runtime, emit an error during
compilation.

rdar://problem/12206955

Reviewers: dexonsmith, bob.wilson, steven_wu

Reviewed By: steven_wu

Subscribers: jkorous, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/test/Driver/darwin-ld.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=354084&r1=354083&r2=354084&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Feb 14 15:50:44 
2019
@@ -96,6 +96,8 @@ def err_drv_clang_unsupported : Error<
   "the clang compiler does not support '%0'">;
 def err_drv_clang_unsupported_opt_cxx_darwin_i386 : Error<
   "the clang compiler does not support '%0' for C++ on Darwin/i386">;
+def err_drv_clang_unsupported_opt_pg_darwin: Error<
+  "the clang compiler does not support -pg option on %select{Darwin|versions 
of OS X 10.9 and later}0">;
 def err_drv_clang_unsupported_opt_faltivec : Error<
   "the clang compiler does not support '%0', %1">;
 def err_drv_command_failed : Error<

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=354084&r1=354083&r2=354084&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Thu Feb 14 15:50:44 2019
@@ -2289,22 +2289,27 @@ void Darwin::addStartObjectFileArgs(cons
   }
 } else {
   if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) {
-if (Args.hasArg(options::OPT_static) ||
-Args.hasArg(options::OPT_object) ||
-Args.hasArg(options::OPT_preload)) {
-  CmdArgs.push_back("-lgcrt0.o");
-} else {
-  CmdArgs.push_back("-lgcrt1.o");
+if (isTargetMacOS() && isMacosxVersionLT(10, 9)) {
+  if (Args.hasArg(options::OPT_static) ||
+  Args.hasArg(options::OPT_object) ||
+  Args.hasArg(options::OPT_preload)) {
+CmdArgs.push_back("-lgcrt0.o");
+  } else {
+CmdArgs.push_back("-lgcrt1.o");
 
-  // darwin_crt2 spec is empty.
+// darwin_crt2 spec is empty.
+  }
+  // By default on OS X 10.8 and later, we don't link with a crt1.o
+  // file and the linker knows to use _main as the entry point.  But,
+  // when compiling with -pg, we need to link with the gcrt1.o file,
+  // so pass the -no_new_main option to tell the linker to use the
+  // "start" symbol as the entry point.
+  if (isTargetMacOS() && !isMacosxVersionLT(10, 8))
+CmdArgs.push_back("-no_new_main");
+} else {
+  getDriver().Diag(diag::err_drv_clang_unsupported_opt_pg_darwin)
+  << isTargetMacOS();
 }
-// By default on OS X 10.8 and later, we don't link with a crt1.o
-// file and the linker knows to use _main as the entry point.  But,
-// when compiling with -pg, we need to link with the gcrt1.o file,
-// so pass the -no_new_main option to tell the linker to use the
-// "start" symbol as the entry point.
-if (isTargetMacOS() && !isMacosxVersionLT(10, 8))
-  CmdArgs.push_back("-no_new_main");
   } else {
 if (Args.hasArg(options::OPT_static) ||
 Args.hasArg(options::OPT_object) ||

Modified: cfe/trunk/test/Driver/darwin-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld.c?rev=354084&r1=354083&r2=354084&view=diff
==
--- cfe/trunk/test/Driver/darwin-ld.c (original)
+++ cfe/trunk/test/Driver/darwin-ld.c Thu Feb 14 15:50:44 2019
@@ -203,6 +203,14 @@
 // LINK_PG: -lgcrt1.o
 // LINK_PG: -no_new_main
 
+// RUN: %clang -target i386-apple-darwin13 -pg -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_PG_NO_SUPPORT_OSX %s < %t.log
+// LINK_PG_NO_SUPPORT_OSX: error: the clang compiler does not support -pg 
option on versions of OS X
+
+// RUN: %clang -target x86_64-apple-ios5.0 -pg -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_PG_NO_SUPPORT %s < %t.log
+// LINK_PG_NO_SUPPORT: error: the clang compiler does not support -pg option 
on Darwin
+
 // Check that clang links with libgcc_s.1 for iOS 4 and earlier, but not arm64.
 // RUN: %clang -target arm

r354164 - [ObjC] Fix non-canonical types preventing type arguments substitution.

2019-02-15 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Feb 15 12:17:45 2019
New Revision: 354164

URL: http://llvm.org/viewvc/llvm-project?rev=354164&view=rev
Log:
[ObjC] Fix non-canonical types preventing type arguments substitution.

`QualType::substObjCTypeArgs` doesn't go past non-canonical types and as
the result misses some of the substitutions like `ObjCTypeParamType`.

Update `SimpleTransformVisitor` to traverse past the type sugar.

Reviewers: ahatanak, erik.pilkington

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, cfe-commits

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


Modified:
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/test/SemaObjC/parameterized_classes_subst.m

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=354164&r1=354163&r2=354164&view=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri Feb 15 12:17:45 2019
@@ -752,6 +752,17 @@ public:
 
 #define TRIVIAL_TYPE_CLASS(Class) \
   QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
+#define SUGARED_TYPE_CLASS(Class) \
+  QualType Visit##Class##Type(const Class##Type *T) { \
+if (!T->isSugared()) \
+  return QualType(T, 0); \
+QualType desugaredType = recurse(T->desugar()); \
+if (desugaredType.isNull()) \
+  return {}; \
+if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \
+  return QualType(T, 0); \
+return desugaredType; \
+  }
 
   TRIVIAL_TYPE_CLASS(Builtin)
 
@@ -955,8 +966,8 @@ public:
 return Ctx.getParenType(innerType);
   }
 
-  TRIVIAL_TYPE_CLASS(Typedef)
-  TRIVIAL_TYPE_CLASS(ObjCTypeParam)
+  SUGARED_TYPE_CLASS(Typedef)
+  SUGARED_TYPE_CLASS(ObjCTypeParam)
 
   QualType VisitAdjustedType(const AdjustedType *T) {
 QualType originalType = recurse(T->getOriginalType());
@@ -987,15 +998,15 @@ public:
 return Ctx.getDecayedType(originalType);
   }
 
-  TRIVIAL_TYPE_CLASS(TypeOfExpr)
-  TRIVIAL_TYPE_CLASS(TypeOf)
-  TRIVIAL_TYPE_CLASS(Decltype)
-  TRIVIAL_TYPE_CLASS(UnaryTransform)
+  SUGARED_TYPE_CLASS(TypeOfExpr)
+  SUGARED_TYPE_CLASS(TypeOf)
+  SUGARED_TYPE_CLASS(Decltype)
+  SUGARED_TYPE_CLASS(UnaryTransform)
   TRIVIAL_TYPE_CLASS(Record)
   TRIVIAL_TYPE_CLASS(Enum)
 
   // FIXME: Non-trivial to implement, but important for C++
-  TRIVIAL_TYPE_CLASS(Elaborated)
+  SUGARED_TYPE_CLASS(Elaborated)
 
   QualType VisitAttributedType(const AttributedType *T) {
 QualType modifiedType = recurse(T->getModifiedType());
@@ -1030,7 +1041,7 @@ public:
   }
 
   // FIXME: Non-trivial to implement, but important for C++
-  TRIVIAL_TYPE_CLASS(TemplateSpecialization)
+  SUGARED_TYPE_CLASS(TemplateSpecialization)
 
   QualType VisitAutoType(const AutoType *T) {
 if (!T->isDeduced())
@@ -1049,7 +1060,7 @@ public:
   }
 
   // FIXME: Non-trivial to implement, but important for C++
-  TRIVIAL_TYPE_CLASS(PackExpansion)
+  SUGARED_TYPE_CLASS(PackExpansion)
 
   QualType VisitObjCObjectType(const ObjCObjectType *T) {
 QualType baseType = recurse(T->getBaseType());
@@ -1107,6 +1118,7 @@ public:
   }
 
 #undef TRIVIAL_TYPE_CLASS
+#undef SUGARED_TYPE_CLASS
 };
 
 } // namespace

Modified: cfe/trunk/test/SemaObjC/parameterized_classes_subst.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/parameterized_classes_subst.m?rev=354164&r1=354163&r2=354164&view=diff
==
--- cfe/trunk/test/SemaObjC/parameterized_classes_subst.m (original)
+++ cfe/trunk/test/SemaObjC/parameterized_classes_subst.m Fri Feb 15 12:17:45 
2019
@@ -104,6 +104,12 @@ __attribute__((objc_root_class))
 @property (nonatomic,retain) ViewType view;
 @end
 
+@interface TypedefTypeParam : NSObject
+typedef T AliasT;
+- (void)test:(AliasT)object;
+// expected-note@-1 {{parameter 'object' here}}
+@end
+
 // --
 // Nullability
 // --
@@ -190,6 +196,7 @@ void test_message_send_param(
MutableSetOfArrays *mutStringArraySet,
NSMutableSet *mutSet,
MutableSetOfArrays *mutArraySet,
+   TypedefTypeParam *typedefTypeParam,
void (^block)(void)) {
   Window *window;
 
@@ -199,6 +206,7 @@ void test_message_send_param(
   [mutStringArraySet addObject: window]; // expected-warning{{parameter of 
type 'NSArray *'}}
   [mutSet addObject: window]; // expected-warning{{parameter of incompatible 
type 'id'}}
   [mutArraySet addObject: window]; // expected-warning{{parameter of 
incompatible type 'id'}}
+  [typedefTypeParam test: window]; // expected-warning{{parameter of type 
'NSString *'}}
   [block addObject: window]; // expected-warning{{parameter of incompatible 
type 'id'}}
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.or

r354180 - [ObjC] For type substitution in generics use a regular recursive type visitor.

2019-02-15 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Feb 15 14:14:58 2019
New Revision: 354180

URL: http://llvm.org/viewvc/llvm-project?rev=354180&view=rev
Log:
[ObjC] For type substitution in generics use a regular recursive type visitor.

Switch to the inheritance-based visitor from the lambda-based visitor to
allow both preorder and postorder customizations during type
transformation. NFC intended.

Reviewers: ahatanak, erik.pilkington

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, cfe-commits

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


Modified:
cfe/trunk/lib/AST/Type.cpp

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=354180&r1=354179&r2=354180&view=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri Feb 15 14:14:58 2019
@@ -723,25 +723,30 @@ const ObjCObjectPointerType *ObjCObjectP
   return ctx.getObjCObjectPointerType(obj)->castAs();
 }
 
-template
-static QualType simpleTransform(ASTContext &ctx, QualType type, F &&f);
-
 namespace {
 
-/// Visitor used by simpleTransform() to perform the transformation.
-template
-struct SimpleTransformVisitor
- : public TypeVisitor, QualType> {
+/// Visitor used to perform a simple type transformation that does not change
+/// the semantics of the type.
+template 
+struct SimpleTransformVisitor : public TypeVisitor {
   ASTContext &Ctx;
-  F &&TheFunc;
 
   QualType recurse(QualType type) {
-return simpleTransform(Ctx, type, std::move(TheFunc));
+// Split out the qualifiers from the type.
+SplitQualType splitType = type.split();
+
+// Visit the type itself.
+QualType result = static_cast(this)->Visit(splitType.Ty);
+if (result.isNull())
+  return result;
+
+// Reconstruct the transformed type by applying the local qualifiers
+// from the split type.
+return Ctx.getQualifiedType(result, splitType.Quals);
   }
 
 public:
-  SimpleTransformVisitor(ASTContext &ctx, F &&f)
-  : Ctx(ctx), TheFunc(std::move(f)) {}
+  explicit SimpleTransformVisitor(ASTContext &ctx) : Ctx(ctx) {}
 
   // None of the clients of this transformation can occur where
   // there are dependent types, so skip dependent types.
@@ -1121,220 +1126,205 @@ public:
 #undef SUGARED_TYPE_CLASS
 };
 
-} // namespace
-
-/// Perform a simple type transformation that does not change the
-/// semantics of the type.
-template
-static QualType simpleTransform(ASTContext &ctx, QualType type, F &&f) {
-  // Transform the type. If it changed, return the transformed result.
-  QualType transformed = f(type);
-  if (transformed.getAsOpaquePtr() != type.getAsOpaquePtr())
-return transformed;
-
-  // Split out the qualifiers from the type.
-  SplitQualType splitType = type.split();
-
-  // Visit the type itself.
-  SimpleTransformVisitor visitor(ctx, std::forward(f));
-  QualType result = visitor.Visit(splitType.Ty);
-  if (result.isNull())
-return result;
-
-  // Reconstruct the transformed type by applying the local qualifiers
-  // from the split type.
-  return ctx.getQualifiedType(result, splitType.Quals);
-}
-
-/// Substitute the given type arguments for Objective-C type
-/// parameters within the given type, recursively.
-QualType QualType::substObjCTypeArgs(
-   ASTContext &ctx,
-   ArrayRef typeArgs,
-   ObjCSubstitutionContext context) const {
-  return simpleTransform(ctx, *this,
- [&](QualType type) -> QualType {
-SplitQualType splitType = type.split();
+struct SubstObjCTypeArgsVisitor
+: public SimpleTransformVisitor {
+  using BaseType = SimpleTransformVisitor;
+
+  ArrayRef TypeArgs;
+  ObjCSubstitutionContext SubstContext;
+
+  SubstObjCTypeArgsVisitor(ASTContext &ctx, ArrayRef typeArgs,
+   ObjCSubstitutionContext context)
+  : BaseType(ctx), TypeArgs(typeArgs), SubstContext(context) {}
 
+  QualType VisitObjCTypeParamType(const ObjCTypeParamType *OTPTy) {
 // Replace an Objective-C type parameter reference with the corresponding
 // type argument.
-if (const auto *OTPTy = dyn_cast(splitType.Ty)) {
-  ObjCTypeParamDecl *typeParam = OTPTy->getDecl();
-  // If we have type arguments, use them.
-  if (!typeArgs.empty()) {
-QualType argType = typeArgs[typeParam->getIndex()];
-if (OTPTy->qual_empty())
-  return ctx.getQualifiedType(argType, splitType.Quals);
-
-// Apply protocol lists if exists.
-bool hasError;
-SmallVector protocolsVec;
-protocolsVec.append(OTPTy->qual_begin(),
-OTPTy->qual_end());
-ArrayRef protocolsToApply = protocolsVec;
-QualType resultTy = ctx.applyObjCProtocolQualifiers(argType,
-protocolsToApply, hasError, true/*allowOnPointerType*/);
+ObjCTypeParamDecl *typeParam = OTPTy->getDecl();
+// If we have type arguments, use

r354189 - [ObjC generics] Fix applying `__kindof` to the type parameter.

2019-02-15 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Feb 15 17:01:08 2019
New Revision: 354189

URL: http://llvm.org/viewvc/llvm-project?rev=354189&view=rev
Log:
[ObjC generics] Fix applying `__kindof` to the type parameter.

Fixes the warning about incompatible pointer types on assigning to a
subclass of type argument an expression of type `__kindof TypeParam`.

We already have a mechanism in `ASTContext::canAssignObjCInterfaces`
that handles `ObjCObjectType` with `__kindof`. But it wasn't triggered
because during type substitution `__kindof TypeParam` was represented as
`AttributedType` with attribute `ObjCKindOf` and equivalent type
`TypeArg`. For assignment type checking we use canonical types so
attributed type was desugared and the attribute was ignored.

The fix is in checking transformed `AttributedType` and pushing
`__kindof` down into `ObjCObjectType` when necessary.

rdar://problem/38514910

Reviewers: ahatanak, erik.pilkington, doug.gregor

Reviewed By: doug.gregor

Subscribers: jkorous, dexonsmith, manmanren, jordan_rose, doug.gregor, 
cfe-commits

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


Modified:
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/test/SemaObjC/kindof.m

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=354189&r1=354188&r2=354189&view=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri Feb 15 17:01:08 2019
@@ -1297,6 +1297,42 @@ struct SubstObjCTypeArgsVisitor
 
 return BaseType::VisitObjCObjectType(objcObjectType);
   }
+
+  QualType VisitAttributedType(const AttributedType *attrType) {
+QualType newType = BaseType::VisitAttributedType(attrType);
+if (newType.isNull())
+  return {};
+
+const auto *newAttrType = dyn_cast(newType.getTypePtr());
+if (!newAttrType || newAttrType->getAttrKind() != attr::ObjCKindOf)
+  return newType;
+
+// Find out if it's an Objective-C object or object pointer type;
+QualType newEquivType = newAttrType->getEquivalentType();
+const ObjCObjectPointerType *ptrType =
+newEquivType->getAs();
+const ObjCObjectType *objType = ptrType
+? ptrType->getObjectType()
+: 
newEquivType->getAs();
+if (!objType)
+  return newType;
+
+// Rebuild the "equivalent" type, which pushes __kindof down into
+// the object type.
+newEquivType = Ctx.getObjCObjectType(
+objType->getBaseType(), objType->getTypeArgsAsWritten(),
+objType->getProtocols(),
+// There is no need to apply kindof on an unqualified id type.
+/*isKindOf=*/objType->isObjCUnqualifiedId() ? false : true);
+
+// If we started with an object pointer type, rebuild it.
+if (ptrType)
+  newEquivType = Ctx.getObjCObjectPointerType(newEquivType);
+
+// Rebuild the attributed type.
+return Ctx.getAttributedType(newAttrType->getAttrKind(),
+ newAttrType->getModifiedType(), newEquivType);
+  }
 };
 
 struct StripObjCKindOfTypeVisitor

Modified: cfe/trunk/test/SemaObjC/kindof.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/kindof.m?rev=354189&r1=354188&r2=354189&view=diff
==
--- cfe/trunk/test/SemaObjC/kindof.m (original)
+++ cfe/trunk/test/SemaObjC/kindof.m Fri Feb 15 17:01:08 2019
@@ -384,9 +384,17 @@ void testNullability() {
 }
 @end
 
+// ---
+// __kindof on type parameters
+// ---
+
 @interface NSGeneric : NSObject
 - (void)test:(__kindof ObjectType)T; // expected-note{{passing argument to 
parameter 'T' here}}
 - (void)mapUsingBlock:(id (^)(__kindof ObjectType))block;
+@property (copy) ObjectType object;
+@property (copy) __kindof ObjectType kindof_object;
+
+@property (copy) __kindof ObjectType _Nonnull nonnull_kindof_object;
 @end
 @implementation NSGeneric
 - (void)test:(id)T {
@@ -395,6 +403,11 @@ void testNullability() {
 }
 @end
 
+@interface NSDefaultGeneric : NSObject
+@property (copy) ObjectType object;
+@property (copy) __kindof ObjectType kindof_object;
+@end
+
 void testGeneric(NSGeneric *generic) {
   NSObject *NSObject_obj;
   // Assign from NSObject_obj to __kindof NSString*.
@@ -403,6 +416,45 @@ void testGeneric(NSGeneric *g
   [generic test:NSString_str];
 }
 
+void testGenericAssignment() {
+  NSMutableString *NSMutableString_str;
+  NSNumber *NSNumber_obj;
+
+  NSGeneric *generic;
+  NSMutableString_str = generic.object; // expected-warning{{incompatible 
pointer types}}
+  NSNumber_obj = generic.object; // expected-warning{{incompatible pointer 
types}}
+  NSMutableString_str = generic.kindof_object;
+  NSNumber_obj = generic.kindof_object; // expected-warning{{incompatibl

r313323 - [Sema] Correct typos in LHS, RHS before building a binop expression.

2017-09-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Sep 14 17:08:37 2017
New Revision: 313323

URL: http://llvm.org/viewvc/llvm-project?rev=313323&view=rev
Log:
[Sema] Correct typos in LHS, RHS before building a binop expression.

Specifically, typo correction should be done before dispatching between
different kinds of binary operations like pseudo-object assignment,
overloaded binary operation, etc.

Without this change we hit an assertion

Assertion failed: 
(!LHSExpr->hasPlaceholderType(BuiltinType::PseudoObject)), function 
CheckAssignmentOperands

when in Objective-C we reference a property without `self` and there are
2 equally good typo correction candidates: ivar and a class name. In
this case LHS expression in `BuildBinOp` is

CXXDependentScopeMemberExpr
`-TypoExpr

and instead of handling Obj-C property assignment as pseudo-object
assignment, we call `CreateBuiltinBinOp` which corrects typo to

ObjCPropertyRefExpr ''

but cannot handle pseudo-objects and asserts about it (indirectly,
through `CheckAssignmentOperands`).

rdar://problem/33102722

Reviewers: rsmith, ahatanak, majnemer

Reviewed By: ahatanak

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/typo-correction.m
cfe/trunk/test/SemaObjCXX/typo-correction.mm

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=313323&r1=313322&r2=313323&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 14 17:08:37 2017
@@ -11269,6 +11269,26 @@ static NamedDecl *getDeclFromExpr(Expr *
   return nullptr;
 }
 
+static std::pair
+CorrectDelayedTyposInBinOp(Sema &S, BinaryOperatorKind Opc, Expr *LHSExpr,
+   Expr *RHSExpr) {
+  ExprResult LHS = LHSExpr, RHS = RHSExpr;
+  if (!S.getLangOpts().CPlusPlus) {
+// C cannot handle TypoExpr nodes on either side of a binop because it
+// doesn't handle dependent types properly, so make sure any TypoExprs have
+// been dealt with before checking the operands.
+LHS = S.CorrectDelayedTyposInExpr(LHS);
+RHS = S.CorrectDelayedTyposInExpr(RHS, [Opc, LHS](Expr *E) {
+  if (Opc != BO_Assign)
+return ExprResult(E);
+  // Avoid correcting the RHS to the same Expr as the LHS.
+  Decl *D = getDeclFromExpr(E);
+  return (D && D == getDeclFromExpr(LHS.get())) ? ExprError() : E;
+});
+  }
+  return std::make_pair(LHS, RHS);
+}
+
 /// CreateBuiltinBinOp - Creates a new built-in binary operation with
 /// operator @p Opc at location @c TokLoc. This routine only supports
 /// built-in operations; ActOnBinOp handles overloaded operators.
@@ -11301,21 +11321,9 @@ ExprResult Sema::CreateBuiltinBinOp(Sour
   ExprValueKind VK = VK_RValue;
   ExprObjectKind OK = OK_Ordinary;
 
-  if (!getLangOpts().CPlusPlus) {
-// C cannot handle TypoExpr nodes on either side of a binop because it
-// doesn't handle dependent types properly, so make sure any TypoExprs have
-// been dealt with before checking the operands.
-LHS = CorrectDelayedTyposInExpr(LHSExpr);
-RHS = CorrectDelayedTyposInExpr(RHSExpr, [Opc, LHS](Expr *E) {
-  if (Opc != BO_Assign)
-return ExprResult(E);
-  // Avoid correcting the RHS to the same Expr as the LHS.
-  Decl *D = getDeclFromExpr(E);
-  return (D && D == getDeclFromExpr(LHS.get())) ? ExprError() : E;
-});
-if (!LHS.isUsable() || !RHS.isUsable())
-  return ExprError();
-  }
+  std::tie(LHS, RHS) = CorrectDelayedTyposInBinOp(*this, Opc, LHSExpr, 
RHSExpr);
+  if (!LHS.isUsable() || !RHS.isUsable())
+return ExprError();
 
   if (getLangOpts().OpenCL) {
 QualType LHSTy = LHSExpr->getType();
@@ -11729,6 +11737,13 @@ static ExprResult BuildOverloadedBinOp(S
 ExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc,
 BinaryOperatorKind Opc,
 Expr *LHSExpr, Expr *RHSExpr) {
+  ExprResult LHS, RHS;
+  std::tie(LHS, RHS) = CorrectDelayedTyposInBinOp(*this, Opc, LHSExpr, 
RHSExpr);
+  if (!LHS.isUsable() || !RHS.isUsable())
+return ExprError();
+  LHSExpr = LHS.get();
+  RHSExpr = RHS.get();
+
   // We want to end up calling one of checkPseudoObjectAssignment
   // (if the LHS is a pseudo-object), BuildOverloadedBinOp (if
   // both expressions are overloadable or either is type-dependent),

Modified: cfe/trunk/test/SemaObjC/typo-correction.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/typo-correction.m?rev=313323&r1=313322&r2=313323&view=diff
==
--- cfe/trunk/test/SemaObjC/typo-correction.m (original)
+++ cfe/trunk/test/SemaObjC/typo-correction.m Thu Sep 14 17:08:37 2017
@@ -51,3 +51,23 @@ __attribute__ (( __objc_root_class__ ))
 }
 @end
 
+// rdar://pr

r313386 - [Sema] Error out early for tags defined inside an enumeration.

2017-09-15 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Sep 15 12:51:42 2017
New Revision: 313386

URL: http://llvm.org/viewvc/llvm-project?rev=313386&view=rev
Log:
[Sema] Error out early for tags defined inside an enumeration.

This fixes PR28903 by avoiding access check for inner enum constant. We
are performing access check because one enum constant references another
and because enum is defined in CXXRecordDecl. But access check doesn't
work because FindDeclaringClass doesn't expect more than one EnumDecl
and because inner enum has access AS_none due to not being an immediate
child of a record.

The change detects an enum is defined in wrong place and allows to skip
parsing its body. Access check is skipped together with body parsing.
There was no crash in C, added test case to cover the new error.

rdar://problem/28530809

Reviewers: rnk, doug.gregor, rsmith

Reviewed By: doug.gregor

Subscribers: cfe-commits

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/enum.c
cfe/trunk/test/SemaCXX/enum.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313386&r1=313385&r2=313386&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 15 12:51:42 
2017
@@ -1335,6 +1335,8 @@ def err_type_defined_in_alias_template :
   "%0 cannot be defined in a type alias template">;
 def err_type_defined_in_condition : Error<
   "%0 cannot be defined in a condition">;
+def err_type_defined_in_enum : Error<
+  "%0 cannot be defined in an enumeration">;
 
 def note_pure_virtual_function : Note<
   "unimplemented pure virtual method %0 in %1">;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313386&r1=313385&r2=313386&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 15 12:51:42 2017
@@ -13928,6 +13928,12 @@ CreateNewDecl:
 Invalid = true;
   }
 
+  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) {
+Diag(New->getLocation(), diag::err_type_defined_in_enum)
+  << Context.getTagDeclType(New);
+Invalid = true;
+  }
+
   // Maybe add qualifier info.
   if (SS.isNotEmpty()) {
 if (SS.isSet()) {

Modified: cfe/trunk/test/Sema/enum.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=313386&r1=313385&r2=313386&view=diff
==
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Fri Sep 15 12:51:42 2017
@@ -123,3 +123,14 @@ int NegativeShortTest[NegativeShort == -
 // PR24610
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
+
+// PR28903
+struct PR28903 {
+  enum {
+PR28903_A = (enum { // expected-error-re {{'enum PR28903::(anonymous at 
{{.*}})' cannot be defined in an enumeration}}
+  PR28903_B,
+  PR28903_C = PR28903_B
+})0
+  };
+  int makeStructNonEmpty;
+};

Modified: cfe/trunk/test/SemaCXX/enum.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=313386&r1=313385&r2=313386&view=diff
==
--- cfe/trunk/test/SemaCXX/enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum.cpp Fri Sep 15 12:51:42 2017
@@ -110,3 +110,13 @@ enum { overflow = 123456 * 234567 };
 // expected-warning@-2 {{not an integral constant expression}}
 // expected-note@-3 {{value 28958703552 is outside the range of representable 
values}}
 #endif
+
+// PR28903
+struct PR28903 {
+  enum {
+PR28903_A = (enum { // expected-error-re {{'PR28903::(anonymous enum at 
{{.*}})' cannot be defined in an enumeration}}
+  PR28903_B,
+  PR28903_C = PR28903_B
+})
+  };
+};


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


r313894 - [fixup][Sema] Allow in C to define tags inside enumerations.

2017-09-21 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Sep 21 10:41:30 2017
New Revision: 313894

URL: http://llvm.org/viewvc/llvm-project?rev=313894&view=rev
Log:
[fixup][Sema] Allow in C to define tags inside enumerations.

Fix for too aggressive error err_type_defined_in_enum introduced in
r313386. Defining tags inside enumerations is prohibited in C++ but
allowed in C.

Reviewers: aaron.ballman, rnk, doug.gregor

Reviewed By: rnk

Subscribers: alberto_magni, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/enum.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313894&r1=313893&r2=313894&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep 21 10:41:30 2017
@@ -13916,7 +13916,8 @@ CreateNewDecl:
 Invalid = true;
   }
 
-  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) {
+  if (!Invalid && getLangOpts().CPlusPlus && TUK == TUK_Definition &&
+  DC->getDeclKind() == Decl::Enum) {
 Diag(New->getLocation(), diag::err_type_defined_in_enum)
   << Context.getTagDeclType(New);
 Invalid = true;

Modified: cfe/trunk/test/Sema/enum.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=313894&r1=313893&r2=313894&view=diff
==
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Thu Sep 21 10:41:30 2017
@@ -125,9 +125,10 @@ enum Color { Red, Green, Blue }; // expe
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
 
 // PR28903
+// In C it is valid to define tags inside enums.
 struct PR28903 {
   enum {
-PR28903_A = (enum { // expected-error-re {{'enum PR28903::(anonymous at 
{{.*}})' cannot be defined in an enumeration}}
+PR28903_A = (enum {
   PR28903_B,
   PR28903_C = PR28903_B
 })0


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


r313896 - [Sema] Fix using old initializer during switch statement transformation.

2017-09-21 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Sep 21 10:58:27 2017
New Revision: 313896

URL: http://llvm.org/viewvc/llvm-project?rev=313896&view=rev
Log:
[Sema] Fix using old initializer during switch statement transformation.

It fixes a crash in CodeGen when we are trying to generate code for
initializer expression created before template instantiation, like

CallExpr ''
|-UnresolvedLookupExpr '' lvalue (ADL) = 'parse'
`-DeclRefExpr 'Buffer' lvalue ParmVar 'buffer' 'Buffer'

rdar://problem/33888545

Reviewers: rsmith, ahatanak

Reviewed By: ahatanak

Subscribers: aemerson, kristof.beyls, cfe-commits

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


Added:
cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp
Modified:
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=313896&r1=313895&r2=313896&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Sep 21 10:58:27 2017
@@ -6601,8 +6601,7 @@ TreeTransform::TransformSwitchS
 
   // Rebuild the switch statement.
   StmtResult Switch
-= getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
-  S->getInit(), Cond);
+= getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
   if (Switch.isInvalid())
 return StmtError();
 

Added: cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp?rev=313896&view=auto
==
--- cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp Thu Sep 21 
10:58:27 2017
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -std=c++1z -verify -emit-llvm-only %s
+// expected-no-diagnostics
+
+// rdar://problem/33888545
+template  class Buffer {};
+
+class A {
+public:
+  int status;
+};
+
+template  A parse(Buffer buffer);
+
+template
+void init_in_if(Buffer buffer) {
+  if (A a = parse(buffer); a.status > 0) {
+  }
+}
+
+template
+void init_in_switch(Buffer buffer) {
+  switch (A a = parse(buffer); a.status) {
+default:
+  break;
+  }
+}
+
+void test() {
+  Buffer<10> buffer;
+  init_in_if(buffer);
+  init_in_switch(buffer);
+}


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


r313906 - [Sema] Prevent InstantiateClass from checking unrelated exception specs.

2017-09-21 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Sep 21 12:54:12 2017
New Revision: 313906

URL: http://llvm.org/viewvc/llvm-project?rev=313906&view=rev
Log:
[Sema] Prevent InstantiateClass from checking unrelated exception specs.

Sema::InstantiateClass should check only exception specs added during
class instantiation and ignore already present delayed specs. This fixes
a case where we instantiate a class before parsing member initializers,
check exceptions for a different class and fail to find a member
initializer. Which is required for comparing exception specs for
explicitly-defaulted and implicit default constructor. With the fix we
are still checking exception specs but only after member initializers
are present.

Removing errors in crash-unparsed-exception.cpp is acceptable according
to discussion in PR24000 because other compilers accept code in
crash-unparsed-exception.cpp as valid.

rdar://problem/34167492

Reviewers: davide, rsmith

Reviewed By: rsmith

Subscribers: dim, cfe-commits

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


Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaTemplate/crash-unparsed-exception.cpp
cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=313906&r1=313905&r2=313906&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Sep 21 12:54:12 2017
@@ -10503,6 +10503,36 @@ public:
   SmallVector DelayedDllExportClasses;
 
 private:
+  class SavePendingParsedClassStateRAII {
+  public:
+SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); }
+
+~SavePendingParsedClassStateRAII() {
+  assert(S.DelayedExceptionSpecChecks.empty() &&
+ "there shouldn't be any pending delayed exception spec checks");
+  assert(S.DelayedDefaultedMemberExceptionSpecs.empty() &&
+ "there shouldn't be any pending delayed defaulted member "
+ "exception specs");
+  assert(S.DelayedDllExportClasses.empty() &&
+ "there shouldn't be any pending delayed DLL export classes");
+  swapSavedState();
+}
+
+  private:
+Sema &S;
+decltype(DelayedExceptionSpecChecks) SavedExceptionSpecChecks;
+decltype(DelayedDefaultedMemberExceptionSpecs)
+SavedDefaultedMemberExceptionSpecs;
+decltype(DelayedDllExportClasses) SavedDllExportClasses;
+
+void swapSavedState() {
+  SavedExceptionSpecChecks.swap(S.DelayedExceptionSpecChecks);
+  SavedDefaultedMemberExceptionSpecs.swap(
+  S.DelayedDefaultedMemberExceptionSpecs);
+  SavedDllExportClasses.swap(S.DelayedDllExportClasses);
+}
+  };
+
   /// \brief Helper class that collects misaligned member designations and
   /// their location info for delayed diagnostics.
   struct MisalignedMember {

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=313906&r1=313905&r2=313906&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Sep 21 12:54:12 2017
@@ -2026,12 +2026,11 @@ Sema::InstantiateClass(SourceLocation Po
   bool MergeWithParentScope = 
!Instantiation->isDefinedOutsideFunctionOrMethod();
   LocalInstantiationScope Scope(*this, MergeWithParentScope);
 
-  // All dllexported classes created during instantiation should be fully
-  // emitted after instantiation completes. We may not be ready to emit any
-  // delayed classes already on the stack, so save them away and put them back
-  // later.
-  decltype(DelayedDllExportClasses) ExportedClasses;
-  std::swap(ExportedClasses, DelayedDllExportClasses);
+  // Some class state isn't processed immediately but delayed till class
+  // instantiation completes. We may not be ready to handle any delayed state
+  // already on the stack as it might correspond to a different class, so save
+  // it now and put it back later.
+  SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this);
 
   // Pull attributes from the pattern onto the instantiation.
   InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
@@ -2118,9 +2117,6 @@ Sema::InstantiateClass(SourceLocation Po
   // default arg exprs for default constructors if necessary now.
   ActOnFinishCXXNonNestedClass(Instantiation);
 
-  // Put back the delayed exported classes that we moved out of the way.
-  std::swap(ExportedClasses, DelayedDllExportClasses);
-
   // Instantiate late parsed attributes, and attach them to their decls.
   // See Sema::InstantiateAttrs
   for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),

Modified: cfe/trunk/test/SemaTemplate

Re: r313386 - [Sema] Error out early for tags defined inside an enumeration.

2017-09-22 Thread Volodymyr Sapsai via cfe-commits


> On Sep 21, 2017, at 15:17, Richard Smith  wrote:
> 
> On 15 September 2017 at 12:51, Volodymyr Sapsai via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: vsapsai
> Date: Fri Sep 15 12:51:42 2017
> New Revision: 313386
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=313386&view=rev 
> <http://llvm.org/viewvc/llvm-project?rev=313386&view=rev>
> Log:
> [Sema] Error out early for tags defined inside an enumeration.
> 
> This fixes PR28903 by avoiding access check for inner enum constant. We
> are performing access check because one enum constant references another
> and because enum is defined in CXXRecordDecl. But access check doesn't
> work because FindDeclaringClass doesn't expect more than one EnumDecl
> and because inner enum has access AS_none due to not being an immediate
> child of a record.
> 
> The change detects an enum is defined in wrong place and allows to skip
> parsing its body. Access check is skipped together with body parsing.
> There was no crash in C, added test case to cover the new error.
> 
> rdar://problem/28530809
> 
> Reviewers: rnk, doug.gregor, rsmith
> 
> Reviewed By: doug.gregor
> 
> Subscribers: cfe-commits
> 
> Differential Revision: https://reviews.llvm.org/D37089 
> <https://reviews.llvm.org/D37089>
> 
> 
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Sema/enum.c
> cfe/trunk/test/SemaCXX/enum.cpp
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313386&r1=313385&r2=313386&view=diff
>  
> <http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313386&r1=313385&r2=313386&view=diff>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 15 12:51:42 
> 2017
> @@ -1335,6 +1335,8 @@ def err_type_defined_in_alias_template :
>"%0 cannot be defined in a type alias template">;
>  def err_type_defined_in_condition : Error<
>"%0 cannot be defined in a condition">;
> +def err_type_defined_in_enum : Error<
> +  "%0 cannot be defined in an enumeration">;
> 
>  def note_pure_virtual_function : Note<
>"unimplemented pure virtual method %0 in %1">;
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313386&r1=313385&r2=313386&view=diff
>  
> <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313386&r1=313385&r2=313386&view=diff>
> ==
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 15 12:51:42 2017
> @@ -13928,6 +13928,12 @@ CreateNewDecl:
>  Invalid = true;
>}
> 
> +  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) {
> +Diag(New->getLocation(), diag::err_type_defined_in_enum)
> +  << Context.getTagDeclType(New);
> +Invalid = true;
> +  }
> 
> This looks like the wrong fix. As noted elsewhere, this is wrong in C. And in 
> C++, the relevant context is a type-specifier, which should be rejected due 
> to the check 7 lines above.
> 
> It looks like the actual bug is that we don't consider the type within a C99 
> compound literal to be a type-specifier. The fact that the context is an 
> enumeration is irrelevant.

At which point can we detect IsTypeSpecifier should be true? Which in turn 
boils down to DeclSpecContext should be DSC_type_specifier. Currently we have 
DeclSpecContext DSC_normal because it is a default argument in 
Parser::ParseSpecifierQualifierList. Which is called from

#4  clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, 
bool, bool, clang::OpaquePtr&, clang::SourceLocation&) at 
llvm-project/clang/lib/Parse/ParseExpr.cpp:2375
#5  clang::Parser::ParseCastExpression(bool, bool, bool&, 
clang::Parser::TypeCastState, bool) at 
llvm-project/clang/lib/Parse/ParseExpr.cpp:768
#6  clang::Parser::ParseCastExpression(bool, bool, 
clang::Parser::TypeCastState, bool) at 
llvm-project/clang/lib/Parse/ParseExpr.cpp:521
#7  
clang::Parser::ParseConstantExpressionInExprEvalContext(clang::Parser::TypeCastState)
 at llvm-project/clang/lib/Parse/ParseExpr.cpp:201

I have considered using TypeCas

r364664 - [ODRHash] Fix null pointer dereference for ObjC selectors with empty slots.

2019-06-28 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Jun 28 10:42:17 2019
New Revision: 364664

URL: http://llvm.org/viewvc/llvm-project?rev=364664&view=rev
Log:
[ODRHash] Fix null pointer dereference for ObjC selectors with empty slots.

`Selector::getIdentifierInfoForSlot` returns NULL if a slot has no
corresponding identifier. Add a boolean to the hash and a NULL check.

rdar://problem/51615164

Reviewers: rtrieu

Reviewed By: rtrieu

Subscribers: dexonsmith, cfe-commits, jkorous

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


Modified:
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/test/Modules/odr_hash.mm

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=364664&r1=364663&r2=364664&view=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Fri Jun 28 10:42:17 2019
@@ -71,8 +71,13 @@ void ODRHash::AddDeclarationNameImpl(Dec
 AddBoolean(S.isKeywordSelector());
 AddBoolean(S.isUnarySelector());
 unsigned NumArgs = S.getNumArgs();
+ID.AddInteger(NumArgs);
 for (unsigned i = 0; i < NumArgs; ++i) {
-  AddIdentifierInfo(S.getIdentifierInfoForSlot(i));
+  const IdentifierInfo *II = S.getIdentifierInfoForSlot(i);
+  AddBoolean(II);
+  if (II) {
+AddIdentifierInfo(II);
+  }
 }
 break;
   }

Modified: cfe/trunk/test/Modules/odr_hash.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.mm?rev=364664&r1=364663&r2=364664&view=diff
==
--- cfe/trunk/test/Modules/odr_hash.mm (original)
+++ cfe/trunk/test/Modules/odr_hash.mm Fri Jun 28 10:42:17 2019
@@ -57,6 +57,14 @@
 @interface Interface3 
 @end
 
+@interface EmptySelectorSlot
+- (void)method:(int)arg;
+- (void)method:(int)arg :(int)empty;
+
+- (void)multiple:(int)arg1 args:(int)arg2 :(int)arg3;
+- (void)multiple:(int)arg1 :(int)arg2 args:(int)arg3;
+@end
+
 #endif
 
 #if defined(FIRST)
@@ -289,6 +297,29 @@ Invalid3 i3;
 }  // namespace ObjCTypeParam
 }  // namespace Types
 
+namespace CallMethods {
+#if defined(FIRST)
+void invalid1(EmptySelectorSlot *obj) {
+  [obj method:0];
+}
+void invalid2(EmptySelectorSlot *obj) {
+  [obj multiple:0 args:0 :0];
+}
+#elif defined(SECOND)
+void invalid1(EmptySelectorSlot *obj) {
+  [obj method:0 :0];
+}
+void invalid2(EmptySelectorSlot *obj) {
+  [obj multiple:0 :0 args:0];
+}
+#endif
+// expected-error@second.h:* {{'CallMethods::invalid1' has different 
definitions in different modules; definition in module 'SecondModule' first 
difference is function body}}
+// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
+
+// expected-error@second.h:* {{'CallMethods::invalid2' has different 
definitions in different modules; definition in module 'SecondModule' first 
difference is function body}}
+// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
+}  // namespace CallMethods
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST


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


r360625 - Make language option `GNUAsm` discoverable with `__has_extension` macro.

2019-05-13 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon May 13 15:11:10 2019
New Revision: 360625

URL: http://llvm.org/viewvc/llvm-project?rev=360625&view=rev
Log:
Make language option `GNUAsm` discoverable with `__has_extension` macro.

This can be used for better support of `-fno-gnu-inline-asm` builds.

rdar://problem/49540880

Reviewers: aaron.ballman, rsmith

Reviewed By: aaron.ballman

Subscribers: eraman, jkorous, dexonsmith, craig.topper, cfe-commits

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


Modified:
cfe/trunk/include/clang/Basic/Features.def
cfe/trunk/test/Parser/asm.c
cfe/trunk/test/Parser/no-gnu-inline-asm.c

Modified: cfe/trunk/include/clang/Basic/Features.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Features.def?rev=360625&r1=360624&r2=360625&view=diff
==
--- cfe/trunk/include/clang/Basic/Features.def (original)
+++ cfe/trunk/include/clang/Basic/Features.def Mon May 13 15:11:10 2019
@@ -248,6 +248,7 @@ EXTENSION(cxx_variable_templates, LangOp
 EXTENSION(overloadable_unmarked, true)
 EXTENSION(pragma_clang_attribute_namespaces, true)
 EXTENSION(pragma_clang_attribute_external_declaration, true)
+EXTENSION(gnu_asm, LangOpts.GNUAsm)
 
 #undef EXTENSION
 #undef FEATURE

Modified: cfe/trunk/test/Parser/asm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/asm.c?rev=360625&r1=360624&r2=360625&view=diff
==
--- cfe/trunk/test/Parser/asm.c (original)
+++ cfe/trunk/test/Parser/asm.c Mon May 13 15:11:10 2019
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+#if !__has_extension(gnu_asm)
+#error Extension 'gnu_asm' should be available by default
+#endif
+
 void f1() {
   // PR7673: Some versions of GCC support an empty clobbers section.
   asm ("ret" : : :);

Modified: cfe/trunk/test/Parser/no-gnu-inline-asm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/no-gnu-inline-asm.c?rev=360625&r1=360624&r2=360625&view=diff
==
--- cfe/trunk/test/Parser/no-gnu-inline-asm.c (original)
+++ cfe/trunk/test/Parser/no-gnu-inline-asm.c Mon May 13 15:11:10 2019
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 %s -triple i686-apple-darwin -verify -fsyntax-only 
-fno-gnu-inline-asm
 
+#if __has_extension(gnu_asm)
+#error Expected extension 'gnu_asm' to be disabled
+#endif
+
 asm ("INST r1, 0"); // expected-error {{GNU-style inline assembly is disabled}}
 
 void foo() __asm("__foo_func"); // AsmLabel is OK


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


r360630 - [X86] Make `x86intrin.h`, `immintrin.h` includable with `-fno-gnu-inline-asm`.

2019-05-13 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon May 13 15:40:11 2019
New Revision: 360630

URL: http://llvm.org/viewvc/llvm-project?rev=360630&view=rev
Log:
[X86] Make `x86intrin.h`, `immintrin.h` includable with `-fno-gnu-inline-asm`.

Currently `immintrin.h` includes `pconfigintrin.h` and `sgxintrin.h`
which contain inline assembly. It causes failures when building with the
flag `-fno-gnu-inline-asm`.

Fix by excluding functions with inline assembly when this extension is
disabled. So far there was no need to support `_pconfig_u32`,
`_enclu_u32`, `_encls_u32`, `_enclv_u32` on platforms that require
`-fno-gnu-inline-asm`. But if developers start using these functions,
they'll have compile-time undeclared identifier errors which is
preferrable to runtime errors.

rdar://problem/49540880

Reviewers: craig.topper, GBuella, rnk, echristo

Reviewed By: rnk

Subscribers: jkorous, dexonsmith, cfe-commits

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


Modified:
cfe/trunk/lib/Headers/immintrin.h
cfe/trunk/lib/Headers/pconfigintrin.h
cfe/trunk/lib/Headers/sgxintrin.h
cfe/trunk/test/Modules/compiler_builtins_x86.c

Modified: cfe/trunk/lib/Headers/immintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/immintrin.h?rev=360630&r1=360629&r2=360630&view=diff
==
--- cfe/trunk/lib/Headers/immintrin.h (original)
+++ cfe/trunk/lib/Headers/immintrin.h Mon May 13 15:40:11 2019
@@ -421,7 +421,7 @@ _storebe_i64(void * __P, long long __D)
 #include 
 #endif
 
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && __has_extension(gnu_asm)
 /* Define the default attributes for these intrinsics */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
 #ifdef __cplusplus
@@ -503,6 +503,6 @@ _InterlockedCompareExchange64_HLERelease
 
 #undef __DEFAULT_FN_ATTRS
 
-#endif /* _MSC_VER */
+#endif /* defined(_MSC_VER) && __has_extension(gnu_asm) */
 
 #endif /* __IMMINTRIN_H */

Modified: cfe/trunk/lib/Headers/pconfigintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/pconfigintrin.h?rev=360630&r1=360629&r2=360630&view=diff
==
--- cfe/trunk/lib/Headers/pconfigintrin.h (original)
+++ cfe/trunk/lib/Headers/pconfigintrin.h Mon May 13 15:40:11 2019
@@ -16,6 +16,8 @@
 
 #define __PCONFIG_KEY_PROGRAM 0x0001
 
+#if __has_extension(gnu_asm)
+
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS \
   __attribute__((__always_inline__, __nodebug__,  __target__("pconfig")))
@@ -33,4 +35,6 @@ _pconfig_u32(unsigned int __leaf, __SIZE
 
 #undef __DEFAULT_FN_ATTRS
 
+#endif /* __has_extension(gnu_asm) */
+
 #endif

Modified: cfe/trunk/lib/Headers/sgxintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/sgxintrin.h?rev=360630&r1=360629&r2=360630&view=diff
==
--- cfe/trunk/lib/Headers/sgxintrin.h (original)
+++ cfe/trunk/lib/Headers/sgxintrin.h Mon May 13 15:40:11 2019
@@ -14,6 +14,8 @@
 #ifndef __SGXINTRIN_H
 #define __SGXINTRIN_H
 
+#if __has_extension(gnu_asm)
+
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS \
   __attribute__((__always_inline__, __nodebug__,  __target__("sgx")))
@@ -53,4 +55,6 @@ _enclv_u32(unsigned int __leaf, __SIZE_T
 
 #undef __DEFAULT_FN_ATTRS
 
+#endif /* __has_extension(gnu_asm) */
+
 #endif

Modified: cfe/trunk/test/Modules/compiler_builtins_x86.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/compiler_builtins_x86.c?rev=360630&r1=360629&r2=360630&view=diff
==
--- cfe/trunk/test/Modules/compiler_builtins_x86.c (original)
+++ cfe/trunk/test/Modules/compiler_builtins_x86.c Mon May 13 15:40:11 2019
@@ -1,6 +1,8 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -triple i686-unknown-unknown -fsyntax-only -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t %s -verify -ffreestanding
 // RUN: %clang_cc1 -triple i686-unknown-unknown -fsyntax-only -fmodules 
-fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s 
-verify -ffreestanding
+// RUN: %clang_cc1 -triple i686-unknown-unknown -fsyntax-only -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t %s -verify -ffreestanding 
-fno-gnu-inline-asm
+// RUN: %clang_cc1 -triple i686--windows -fsyntax-only -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t %s -verify -ffreestanding 
-fno-gnu-inline-asm -fms-extensions -fms-compatibility-version=17.00
 // expected-no-diagnostics
 
 #include


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


r361779 - [Preprocessor] Fix crash emitting note with framework location for "file not found" error.

2019-05-27 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon May 27 12:15:30 2019
New Revision: 361779

URL: http://llvm.org/viewvc/llvm-project?rev=361779&view=rev
Log:
[Preprocessor] Fix crash emitting note with framework location for "file not 
found" error.

A filename can be remapped with a header map to point to a framework
header and we can find the corresponding framework without the header.
But if the original filename doesn't have a remapped framework name,
we'll fail to find its location and will dereference a null pointer
during diagnostics emission.

Fix by tracking remappings better and emit the note only if a framework
is found before any of the remappings.

rdar://problem/48883447

Reviewers: arphaman, erik.pilkington, jkorous

Reviewed By: arphaman

Subscribers: dexonsmith, cfe-commits

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

Added:
cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/

cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json

cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
Modified:
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Lex/HeaderSearch.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=361779&r1=361778&r2=361779&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Mon May 27 12:15:30 2019
@@ -392,8 +392,9 @@ public:
   /// true.
   ///
   /// \param IsFrameworkFound If non-null, will be set to true if a framework 
is
-  /// found in any of searched SearchDirs. Doesn't guarantee the requested file
-  /// is found.
+  /// found in any of searched SearchDirs. Will be set to false if a framework
+  /// is found only through header maps. Doesn't guarantee the requested file 
is
+  /// found.
   const FileEntry *LookupFile(
   StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
   const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir,

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=361779&r1=361778&r2=361779&view=diff
==
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Mon May 27 12:15:30 2019
@@ -869,7 +869,10 @@ const FileEntry *HeaderSearch::LookupFil
 *IsMapped = true;
 }
 if (IsFrameworkFound)
-  *IsFrameworkFound |= IsFrameworkFoundInDir;
+  // Because we keep a filename remapped for subsequent search directory
+  // lookups, ignore IsFrameworkFoundInDir after the first remapping and 
not
+  // just for remapping in a current search directory.
+  *IsFrameworkFound |= (IsFrameworkFoundInDir && !CacheLookup.MappedName);
 if (!FE) continue;
 
 CurDir = &SearchDirs[i];

Added: 
cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json?rev=361779&view=auto
==
--- 
cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
 (added)
+++ 
cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
 Mon May 27 12:15:30 2019
@@ -0,0 +1,7 @@
+{
+  "mappings" :
+{
+ "RemappedHeader.h" : "TestFramework/RemappedHeader.h",
+ "TestFramework/BeforeRemapping.h" : "TestFramework/AfterRemapping.h"
+}
+}

Added: 
cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c?rev=361779&view=auto
==
--- 
cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
 (added)
+++ 
cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
 Mon May 27 12:15:30 2019
@@ -0,0 +1,20 @@
+// RUN: rm -f %t.hmap
+// RUN: %hmaptool write 
%S/Inputs/include-header-missing-in-framework/TestFramework.hmap.json %t.hmap
+// RUN: %clang_cc1 -fsyntax-only -F %S/Inputs -I %t.hmap -verify %s 
-DLATE_REMAPPING
+// RUN: %clang_cc1 -fsyntax-only -I %t.hmap -F %S/Inputs -verify %s
+
+// The test is similar to 'include-header-missing-in-framework.c' but covers
+// the case when a header is remapped to a framework-like path with a .hmap
+// file. And we can find the framework but not the header.
+
+#ifdef LATE_REMAPPING
+// Framework is found before remapping.
+#include 
+// expected-error@-1 {{'TestFramework/BeforeRemapping.h' file no

r349848 - [CodeGen] Fix assertion on emitting cleanup for object with inlined inherited constructor and non-trivial destructor.

2018-12-20 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Dec 20 14:43:26 2018
New Revision: 349848

URL: http://llvm.org/viewvc/llvm-project?rev=349848&view=rev
Log:
[CodeGen] Fix assertion on emitting cleanup for object with inlined inherited 
constructor and non-trivial destructor.

Fixes assertion
> Assertion failed: (isa(Val) && "cast() argument of incompatible 
> type!"), function cast, file llvm/Support/Casting.h, line 255.

It was triggered by trying to cast `FunctionDecl` to `CXXMethodDecl` as
`CGF.CurCodeDecl` in `CallBaseDtor::Emit`. It was happening because
cleanups were emitted in `ScalarExprEmitter::VisitExprWithCleanups`
after destroying `InlinedInheritingConstructorScope`, so
`CodeGenFunction.CurCodeDecl` didn't correspond to expected cleanup decl.

Fix the assertion by emitting cleanups before leaving
`InlinedInheritingConstructorScope` and changing `CurCodeDecl`.

Test cases based on a patch by Shoaib Meenai.

Fixes PR36748.

rdar://problem/45805151

Reviewers: rsmith, rjmccall

Reviewed By: rjmccall

Subscribers: jkorous, dexonsmith, cfe-commits, smeenai, compnerd

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


Added:
cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp
cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=349848&r1=349847&r2=349848&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Dec 20 14:43:26 2018
@@ -2208,6 +2208,7 @@ void CodeGenFunction::EmitInlinedInherit
   GlobalDecl GD(Ctor, CtorType);
   InlinedInheritingConstructorScope Scope(*this, GD);
   ApplyInlineDebugLocation DebugScope(*this, GD);
+  RunCleanupsScope RunCleanups(*this);
 
   // Save the arguments to be passed to the inherited constructor.
   CXXInheritedCtorInitExprArgs = Args;

Added: cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp?rev=349848&view=auto
==
--- cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp Thu Dec 20 
14:43:26 2018
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -fcxx-exceptions 
-fexceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=EXCEPTIONS
+
+// PR36748
+// rdar://problem/45805151
+
+// Classes to verify order of destroying function parameters.
+struct S1 {
+  ~S1();
+};
+struct S2 {
+  ~S2();
+};
+
+struct Base {
+  // Use variadic args to cause inlining the inherited constructor.
+  Base(const S1&, const S2&, const char *fmt, ...) {}
+};
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor() {}
+};
+struct Inheritor : public NonTrivialDtor, public Base {
+  using Base::Base;
+};
+
+void f() {
+  Inheritor(S1(), S2(), "foo");
+  // CHECK-LABEL: define void @_Z1fv
+  // CHECK: %[[TMP1:.*]] = alloca %struct.S1
+  // CHECK: %[[TMP2:.*]] = alloca %struct.S2
+  // CHECK: call void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, ...) 
@_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* dereferenceable(1) 
%[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* {{.*}})
+  // CHECK-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // CHECK-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // CHECK-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS-LABEL: define void @_Z1fv
+  // EXCEPTIONS: %[[TMP1:.*]] = alloca %struct.S1
+  // EXCEPTIONS: %[[TMP2:.*]] = alloca %struct.S2
+  // EXCEPTIONS: invoke void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, 
...) @_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* 
dereferenceable(1) %[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* 
{{.*}})
+  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]]
+
+  // EXCEPTIONS: [[CONT]]:
+  // EXCEPTIONS-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS: [[LPAD]]:
+  // EXCEPTIONS: call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* 
{{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+}

Added: cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm?rev=349848&view=auto
==
--- cfe/trunk/test/CodeGenObj

r349853 - [CodeGen] Fix a test from r349848 by replacing `objc_` with `llvm.objc.`

2018-12-20 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Dec 20 15:26:29 2018
New Revision: 349853

URL: http://llvm.org/viewvc/llvm-project?rev=349853&view=rev
Log:
[CodeGen] Fix a test from r349848 by replacing `objc_` with `llvm.objc.`

Modified:
cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm

Modified: cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm?rev=349853&r1=349852&r2=349853&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm Thu Dec 20 
15:26:29 2018
@@ -23,7 +23,7 @@ void f() {
 }
 // CHECK-LABEL: define void @_Z1fv
 // CHECK:   %[[TMP:.*]] = call i8* @_Z1gv()
-// CHECK:   {{.*}} = call i8* @objc_retainAutoreleasedReturnValue(i8* 
%[[TMP]])
+// CHECK:   {{.*}} = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* 
%[[TMP]])
 // CHECK:   call void (%struct.Base*, i8*, ...) 
@_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}})
 // CHECK-NEXT:  call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
 
@@ -37,7 +37,7 @@ void f() {
 // CHECK:   call void @_ZN6StrongD2Ev(%struct.Strong* {{.*}})
 
 // CHECK-LABEL: define linkonce_odr void @_ZN6StrongD2Ev(%struct.Strong* 
{{.*}})
-// CHECK:   call void @objc_storeStrong(i8** {{.*}}, i8* null)
+// CHECK:   call void @llvm.objc.storeStrong(i8** {{.*}}, i8* null)
 
 // CHECK-LABEL: define linkonce_odr void @_ZN9InheritorD2Ev(%struct.Inheritor* 
{{.*}})
 // CHECK:   call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* 
{{.*}})


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


r371655 - Fix -Wnonportable-include-path suppression for header maps with absolute paths.

2019-09-11 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Sep 11 13:39:04 2019
New Revision: 371655

URL: http://llvm.org/viewvc/llvm-project?rev=371655&view=rev
Log:
Fix -Wnonportable-include-path suppression for header maps with absolute paths.

In `DirectoryLookup::LookupFile` parameter `HasBeenMapped` doesn't cover
the case when clang finds a file through a header map but doesn't remap
the lookup filename because the target path is an absolute path. As a
result, -Wnonportable-include-path suppression for header maps
introduced in r301592 wasn't triggered.

Change parameter `HasBeenMapped` to `IsInHeaderMap` and use parameter
`MappedName` to track the filename remapping. This way we can handle
both relative and absolute paths in header maps, and account for their
specific properties, like filename remapping being a property preserved
across lookups in multiple directories.

rdar://problem/39516483

Reviewers: dexonsmith, bruno

Reviewed By: dexonsmith

Subscribers: jkorous, cfe-commits, ributzka

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

Added:
cfe/trunk/test/Preprocessor/Inputs/nonportable-hmaps/headers/foo/Bar.h
cfe/trunk/test/Preprocessor/Inputs/nonportable-hmaps/headers/foo/Baz.h
Modified:
cfe/trunk/include/clang/Lex/DirectoryLookup.h
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/test/Preprocessor/Inputs/nonportable-hmaps/foo.hmap.json
cfe/trunk/test/Preprocessor/nonportable-include-with-hmap.c

Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=371655&r1=371654&r2=371655&view=diff
==
--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)
+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Wed Sep 11 13:39:04 2019
@@ -183,7 +183,7 @@ public:
  SmallVectorImpl *RelativePath, Module *RequestingModule,
  ModuleMap::KnownHeader *SuggestedModule,
  bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound,
- bool &HasBeenMapped, SmallVectorImpl &MappedName) const;
+ bool &IsInHeaderMap, SmallVectorImpl &MappedName) const;
 
 private:
   Optional DoFrameworkLookup(

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=371655&r1=371654&r2=371655&view=diff
==
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Sep 11 13:39:04 2019
@@ -341,9 +341,10 @@ Optional DirectoryLookup::
 SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath,
 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
 bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound,
-bool &HasBeenMapped, SmallVectorImpl &MappedName) const {
+bool &IsInHeaderMap, SmallVectorImpl &MappedName) const {
   InUserSpecifiedSystemFramework = false;
-  HasBeenMapped = false;
+  IsInHeaderMap = false;
+  MappedName.clear();
 
   SmallString<1024> TmpDir;
   if (isNormalDir()) {
@@ -377,6 +378,8 @@ Optional DirectoryLookup::
   if (Dest.empty())
 return None;
 
+  IsInHeaderMap = true;
+
   auto FixupSearchPath = [&]() {
 if (SearchPath) {
   StringRef SearchPathRef(getName());
@@ -393,10 +396,8 @@ Optional DirectoryLookup::
   // ("Foo.h" -> "Foo/Foo.h"), in which case continue header lookup using the
   // framework include.
   if (llvm::sys::path::is_relative(Dest)) {
-MappedName.clear();
 MappedName.append(Dest.begin(), Dest.end());
 Filename = StringRef(MappedName.begin(), MappedName.size());
-HasBeenMapped = true;
 Optional Result = HM->LookupFile(Filename, HS.getFileMgr());
 if (Result) {
   FixupSearchPath();
@@ -883,18 +884,22 @@ Optional HeaderSearch::Loo
   // Check each directory in sequence to see if it contains this file.
   for (; i != SearchDirs.size(); ++i) {
 bool InUserSpecifiedSystemFramework = false;
-bool HasBeenMapped = false;
+bool IsInHeaderMap = false;
 bool IsFrameworkFoundInDir = false;
 Optional File = SearchDirs[i].LookupFile(
 Filename, *this, IncludeLoc, SearchPath, RelativePath, 
RequestingModule,
 SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
-HasBeenMapped, MappedName);
-if (HasBeenMapped) {
+IsInHeaderMap, MappedName);
+if (!MappedName.empty()) {
+  assert(IsInHeaderMap && "MappedName should come from a header map");
   CacheLookup.MappedName =
-  copyString(Filename, LookupFileCache.getAllocator());
-  if (IsMapped)
-*IsMapped = true;
+  copyString(MappedName, LookupFileCache.getAllocator());
 }
+if (IsMapped)
+  // A filename is mapped when a header map remapped it to a relative path
+  // used in subsequent header search or to an absolute path pointing to an
+  // existin

r371665 - Fix up a test updated in r371655 - require case-insensitive file system.

2019-09-11 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Sep 11 14:19:27 2019
New Revision: 371665

URL: http://llvm.org/viewvc/llvm-project?rev=371665&view=rev
Log:
Fix up a test updated in r371655 - require case-insensitive file system.

On case-sensitive file systems include with wrong case is not found instead of
showing a warning.

Modified:
cfe/trunk/test/Preprocessor/nonportable-include-with-hmap.c

Modified: cfe/trunk/test/Preprocessor/nonportable-include-with-hmap.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/nonportable-include-with-hmap.c?rev=371665&r1=371664&r2=371665&view=diff
==
--- cfe/trunk/test/Preprocessor/nonportable-include-with-hmap.c (original)
+++ cfe/trunk/test/Preprocessor/nonportable-include-with-hmap.c Wed Sep 11 
14:19:27 2019
@@ -1,4 +1,5 @@
 // REQUIRES: shell
+// REQUIRES: case-insensitive-filesystem
 
 // RUN: rm -f %t.hmap
 // RUN: sed -e "s:INPUTS_DIR:%S/Inputs:g" \


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


r372191 - [Timers] Fix printing some `-ftime-report` sections twice. Fixes PR40328.

2019-09-17 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Sep 17 17:05:45 2019
New Revision: 372191

URL: http://llvm.org/viewvc/llvm-project?rev=372191&view=rev
Log:
[Timers] Fix printing some `-ftime-report` sections twice. Fixes PR40328.

Starting from r324788 timer groups aren't cleared automatically when
printed out. As a result some timer groups were printed one more time.
For example, "Pass execution timing report" was printed again in
`ManagedStatic` destructor, "DWARF Emission" in
`ManagedStatic NamedGroupedTimers` destructor.

Fix by clearing timer groups manually.

Reviewers: thegameg, george.karpenkov

Reviewed By: thegameg

Subscribers: aprantl, jkorous, dexonsmith, ributzka, aras-p, cfe-commits

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

Modified:
cfe/trunk/tools/driver/cc1_main.cpp
cfe/trunk/tools/driver/cc1as_main.cpp
cfe/trunk/tools/driver/driver.cpp

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=372191&r1=372190&r2=372191&view=diff
==
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Tue Sep 17 17:05:45 2019
@@ -253,6 +253,7 @@ int cc1_main(ArrayRef Argv
   // If any timers were active but haven't been destroyed yet, print their
   // results now.  This happens in -disable-free mode.
   llvm::TimerGroup::printAll(llvm::errs());
+  llvm::TimerGroup::clearAll();
 
   if (llvm::timeTraceProfilerEnabled()) {
 SmallString<128> Path(Clang->getFrontendOpts().OutputFile);

Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=372191&r1=372190&r2=372191&view=diff
==
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Tue Sep 17 17:05:45 2019
@@ -609,6 +609,7 @@ int cc1as_main(ArrayRef Ar
   // If any timers were active but haven't been destroyed yet, print their
   // results now.
   TimerGroup::printAll(errs());
+  TimerGroup::clearAll();
 
   return !!Failed;
 }

Modified: cfe/trunk/tools/driver/driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=372191&r1=372190&r2=372191&view=diff
==
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Tue Sep 17 17:05:45 2019
@@ -499,6 +499,7 @@ int main(int argc_, const char **argv_)
   // If any timers were active but haven't been destroyed yet, print their
   // results now.  This happens in -disable-free mode.
   llvm::TimerGroup::printAll(llvm::errs());
+  llvm::TimerGroup::clearAll();
 
 #ifdef _WIN32
   // Exit status should not be negative on Win32, unless abnormal termination.


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


r330041 - Fix evaluation of `__has_include_next` during -frewrite-includes.

2018-04-13 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Apr 13 10:43:15 2018
New Revision: 330041

URL: http://llvm.org/viewvc/llvm-project?rev=330041&view=rev
Log:
Fix evaluation of `__has_include_next` during -frewrite-includes.

`__has_include_next` requires correct DirectoryLookup for being
evaluated correctly. We were using Preprocessor::GetCurDirLookup() but
we were calling it after the preprocessor finished its work. And in this
case CurDirLookup is always nullptr which makes `__has_include_next`
behave as `__has_include`.

Fix by storing and using CurDirLookup when preprocessor enters a file,
not when we rewrite the includes.

rdar://problem/36305026

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: jkorous-apple, cfe-commits

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

Added:
cfe/trunk/test/Frontend/Inputs/NextIncludes/
cfe/trunk/test/Frontend/Inputs/NextIncludes/rewrite-includes9.h
cfe/trunk/test/Frontend/Inputs/rewrite-includes9.h
Modified:
cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/test/Frontend/rewrite-includes.c

Modified: cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp?rev=330041&r1=330040&r2=330041&view=diff
==
--- cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp Fri Apr 13 10:43:15 
2018
@@ -32,8 +32,10 @@ class InclusionRewriter : public PPCallb
   struct IncludedFile {
 FileID Id;
 SrcMgr::CharacteristicKind FileType;
-IncludedFile(FileID Id, SrcMgr::CharacteristicKind FileType)
-: Id(Id), FileType(FileType) {}
+const DirectoryLookup *DirLookup;
+IncludedFile(FileID Id, SrcMgr::CharacteristicKind FileType,
+ const DirectoryLookup *DirLookup)
+: Id(Id), FileType(FileType), DirLookup(DirLookup) {}
   };
   Preprocessor &PP; ///< Used to find inclusion directives.
   SourceManager &SM; ///< Used to read and manage source files.
@@ -54,7 +56,8 @@ class InclusionRewriter : public PPCallb
 public:
   InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers,
 bool UseLineDirectives);
-  void Process(FileID FileId, SrcMgr::CharacteristicKind FileType);
+  void Process(FileID FileId, SrcMgr::CharacteristicKind FileType,
+   const DirectoryLookup *DirLookup);
   void setPredefinesBuffer(const llvm::MemoryBuffer *Buf) {
 PredefinesBuffer = Buf;
   }
@@ -156,8 +159,9 @@ void InclusionRewriter::FileChanged(Sour
 // we didn't reach this file (eg: the main file) via an inclusion directive
 return;
   FileID Id = FullSourceLoc(Loc, SM).getFileID();
-  auto P = FileIncludes.insert(std::make_pair(
-  LastInclusionLocation.getRawEncoding(), IncludedFile(Id, NewFileType)));
+  auto P = FileIncludes.insert(
+  std::make_pair(LastInclusionLocation.getRawEncoding(),
+ IncludedFile(Id, NewFileType, PP.GetCurDirLookup(;
   (void)P;
   assert(P.second && "Unexpected revisitation of the same include directive");
   LastInclusionLocation = SourceLocation();
@@ -408,7 +412,7 @@ bool InclusionRewriter::HandleHasInclude
   Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
   // FIXME: Why don't we call PP.LookupFile here?
   const FileEntry *File = PP.getHeaderSearchInfo().LookupFile(
-  Filename, SourceLocation(), isAngled, nullptr, CurDir, Includers, 
nullptr,
+  Filename, SourceLocation(), isAngled, Lookup, CurDir, Includers, nullptr,
   nullptr, nullptr, nullptr, nullptr);
 
   FileExists = File != nullptr;
@@ -418,7 +422,8 @@ bool InclusionRewriter::HandleHasInclude
 /// Use a raw lexer to analyze \p FileId, incrementally copying parts of it
 /// and including content of included files recursively.
 void InclusionRewriter::Process(FileID FileId,
-SrcMgr::CharacteristicKind FileType) {
+SrcMgr::CharacteristicKind FileType,
+const DirectoryLookup *DirLookup) {
   bool Invalid;
   const MemoryBuffer &FromFile = *SM.getBuffer(FileId, &Invalid);
   assert(!Invalid && "Attempting to process invalid inclusion");
@@ -475,7 +480,7 @@ void InclusionRewriter::Process(FileID F
<< Mod->getFullModuleName(true) << "\n";
 
   // Include and recursively process the file.
-  Process(Inc->Id, Inc->FileType);
+  Process(Inc->Id, Inc->FileType, Inc->DirLookup);
 
   if (Mod)
 OS << "#pragma clang module end /*"
@@ -532,11 +537,10 @@ void InclusionRewriter::Process(FileID F
   // Rewrite __has_include_next(x)
 } else if (RawToken.getIdentifierInfo()->isStr(
"__has_include_next")) {
-  const DirectoryLookup *Lookup = PP.GetCurDirLookup();
- 

[libcxx] r330885 - [libcxx] func.wrap.func.con: Unset function before destroying anything

2018-04-25 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Apr 25 16:38:41 2018
New Revision: 330885

URL: http://llvm.org/viewvc/llvm-project?rev=330885&view=rev
Log:
[libcxx] func.wrap.func.con: Unset function before destroying anything

Be defensive against a reentrant std::function::operator=(nullptr_t), in case
the held function object has a non-trivial destructor.  Destroying the function
object in-place can lead to the destructor being called twice.

Patch by Duncan P. N. Exon Smith. C++03 support by Volodymyr Sapsai.

rdar://problem/32836603

Reviewers: EricWF, mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits, arphaman

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

Added:

libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp

libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign_reentrant.pass.cpp
Modified:
libcxx/trunk/include/__functional_03
libcxx/trunk/include/functional

Modified: libcxx/trunk/include/__functional_03
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__functional_03?rev=330885&r1=330884&r2=330885&view=diff
==
--- libcxx/trunk/include/__functional_03 (original)
+++ libcxx/trunk/include/__functional_03 Wed Apr 25 16:38:41 2018
@@ -600,7 +600,10 @@ template
 function<_Rp()>&
 function<_Rp()>::operator=(const function& __f)
 {
-function(__f).swap(*this);
+if (__f)
+function(__f).swap(*this);
+else
+*this = nullptr;
 return *this;
 }
 
@@ -608,11 +611,12 @@ template
 function<_Rp()>&
 function<_Rp()>::operator=(nullptr_t)
 {
-if (__f_ == (__base*)&__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if (__t == (__base*)&__buf_)
+__t->destroy();
+else if (__t)
+__t->destroy_deallocate();
 return *this;
 }
 
@@ -876,7 +880,10 @@ template
 function<_Rp(_A0)>&
 function<_Rp(_A0)>::operator=(const function& __f)
 {
-function(__f).swap(*this);
+if (__f)
+function(__f).swap(*this);
+else
+*this = nullptr;
 return *this;
 }
 
@@ -884,11 +891,12 @@ template
 function<_Rp(_A0)>&
 function<_Rp(_A0)>::operator=(nullptr_t)
 {
-if (__f_ == (__base*)&__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if (__t == (__base*)&__buf_)
+__t->destroy();
+else if (__t)
+__t->destroy_deallocate();
 return *this;
 }
 
@@ -1152,7 +1160,10 @@ template&
 function<_Rp(_A0, _A1)>::operator=(const function& __f)
 {
-function(__f).swap(*this);
+if (__f)
+function(__f).swap(*this);
+else
+*this = nullptr;
 return *this;
 }
 
@@ -1160,11 +1171,12 @@ template&
 function<_Rp(_A0, _A1)>::operator=(nullptr_t)
 {
-if (__f_ == (__base*)&__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if (__t == (__base*)&__buf_)
+__t->destroy();
+else if (__t)
+__t->destroy_deallocate();
 return *this;
 }
 
@@ -1428,7 +1440,10 @@ template&
 function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f)
 {
-function(__f).swap(*this);
+if (__f)
+function(__f).swap(*this);
+else
+*this = nullptr;
 return *this;
 }
 
@@ -1436,11 +1451,12 @@ template&
 function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t)
 {
-if (__f_ == (__base*)&__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if (__t == (__base*)&__buf_)
+__t->destroy();
+else if (__t)
+__t->destroy_deallocate();
 return *this;
 }
 

Modified: libcxx/trunk/include/functional
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/functional?rev=330885&r1=330884&r2=330885&view=diff
==
--- libcxx/trunk/include/functional (original)
+++ libcxx/trunk/include/functional Wed Apr 25 16:38:41 2018
@@ -1818,11 +1818,7 @@ template
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
-__f_ = 0;
+*this = nullptr;
 if (__f.__f_ == 0)
 __f_ = 0;
 else if ((void *)__f.__f_ == &__f.__buf_)
@@ -1842,11 +1838,12 @@ template
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
 {
-if ((void *)__f_ == &__buf_)
-__f_->destroy();
-else if (__f_)
-__f_->destroy_deallocate();
+__base* __t = __f_;
 __f_ = 0;
+if ((void *)__t == &__buf_)
+__t->destroy();
+else if (__t)
+__t->destr

r331319 - Track skipped files in dependency scanning.

2018-05-01 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue May  1 16:59:33 2018
New Revision: 331319

URL: http://llvm.org/viewvc/llvm-project?rev=331319&view=rev
Log:
Track skipped files in dependency scanning.

It's possible for a header to be a symlink to another header. In this
case both will be represented by clang::FileEntry with the same UID and
they'll use the same clang::HeaderFileInfo.

If you include both headers and use some single-inclusion mechanism
like a header guard or #import, one header will get a FileChanged
callback, and another FileSkipped.

So that we get an accurate dependency file, we therefore need to also
implement the FileSkipped callback in dependency scanning.

Patch by Pete Cooper.

Reviewers: bruno, pete

Reviewed By: bruno

Subscribers: cfe-commits, jkorous, vsapsai

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


Added:
cfe/trunk/test/Frontend/Inputs/SystemHeaderPrefix/with-header-guard.h
cfe/trunk/test/Frontend/dependency-gen-symlink.c
Modified:
cfe/trunk/lib/Frontend/DependencyFile.cpp

Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=331319&r1=331318&r2=331319&view=diff
==
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Tue May  1 16:59:33 2018
@@ -185,6 +185,10 @@ public:
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
+
+  void FileSkipped(const FileEntry &SkippedFile, const Token &FilenameTok,
+   SrcMgr::CharacteristicKind FileType) override;
+
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
@@ -288,6 +292,16 @@ void DFGImpl::FileChanged(SourceLocation
   if (!FileMatchesDepCriteria(Filename.data(), FileType))
 return;
 
+  AddFilename(llvm::sys::path::remove_leading_dotslash(Filename));
+}
+
+void DFGImpl::FileSkipped(const FileEntry &SkippedFile,
+  const Token &FilenameTok,
+  SrcMgr::CharacteristicKind FileType) {
+  StringRef Filename = SkippedFile.getName();
+  if (!FileMatchesDepCriteria(Filename.data(), FileType))
+return;
+
   AddFilename(llvm::sys::path::remove_leading_dotslash(Filename));
 }
 

Added: cfe/trunk/test/Frontend/Inputs/SystemHeaderPrefix/with-header-guard.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/Inputs/SystemHeaderPrefix/with-header-guard.h?rev=331319&view=auto
==
--- cfe/trunk/test/Frontend/Inputs/SystemHeaderPrefix/with-header-guard.h 
(added)
+++ cfe/trunk/test/Frontend/Inputs/SystemHeaderPrefix/with-header-guard.h Tue 
May  1 16:59:33 2018
@@ -0,0 +1,3 @@
+#ifndef HEADER_GUARD
+#define HEADER_GUARD
+#endif

Added: cfe/trunk/test/Frontend/dependency-gen-symlink.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen-symlink.c?rev=331319&view=auto
==
--- cfe/trunk/test/Frontend/dependency-gen-symlink.c (added)
+++ cfe/trunk/test/Frontend/dependency-gen-symlink.c Tue May  1 16:59:33 2018
@@ -0,0 +1,24 @@
+// REQUIRES: shell
+
+// Basic test
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+// RUN: mkdir %t.dir/a
+// RUN: mkdir %t.dir/b
+// RUN: echo "#ifndef HEADER_A" > %t.dir/a/header.h
+// RUN: echo "#define HEADER_A" >> %t.dir/a/header.h
+// RUN: echo "#endif" >> %t.dir/a/header.h
+// RUN: ln -s %t.dir/a/header.h %t.dir/b/header.h
+
+// RUN: %clang_cc1 -dependency-file %t.dir/file.deps -MT %s.o %s -fsyntax-only 
-I %t.dir -isystem %S/Inputs/SystemHeaderPrefix
+// RUN: FileCheck -input-file=%t.dir/file.deps %s
+// CHECK: dependency-gen-symlink.c.o
+// CHECK: dependency-gen-symlink.c
+// CHECK: a/header.h
+// CHECK: b/header.h
+// CHECK-NOT: with-header-guard.h
+#include "a/header.h"
+#include "b/header.h"
+// System header shouldn't be included in dependencies.
+#include 
+#include 


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


r331378 - Emit an error when mixing and

2018-05-02 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed May  2 10:50:43 2018
New Revision: 331378

URL: http://llvm.org/viewvc/llvm-project?rev=331378&view=rev
Log:
Emit an error when mixing  and 

Atomics in C and C++ are incompatible at the moment and mixing the
headers can result in confusing error messages.

Emit an error explicitly telling about the incompatibility. Introduce
the macro `__ALLOW_STDC_ATOMICS_IN_CXX__` that allows to choose in C++
between C atomics and C++ atomics.

rdar://problem/27435938

Reviewers: rsmith, EricWF, mclow.lists

Reviewed By: mclow.lists

Subscribers: jkorous-apple, christof, bumblebritches57, JonChesterfield, 
smeenai, cfe-commits

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

Added:
cfe/trunk/test/Headers/stdatomic.cpp
Modified:
cfe/trunk/lib/Headers/stdatomic.h

Modified: cfe/trunk/lib/Headers/stdatomic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stdatomic.h?rev=331378&r1=331377&r2=331378&view=diff
==
--- cfe/trunk/lib/Headers/stdatomic.h (original)
+++ cfe/trunk/lib/Headers/stdatomic.h Wed May  2 10:50:43 2018
@@ -31,6 +31,10 @@
 # include_next 
 #else
 
+#if !defined(__ALLOW_STDC_ATOMICS_IN_CXX__) && defined(__cplusplus)
+#error " is incompatible with the C++ standard library; define 
__ALLOW_STDC_ATOMICS_IN_CXX__ to proceed."
+#endif
+
 #include 
 #include 
 

Added: cfe/trunk/test/Headers/stdatomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/stdatomic.cpp?rev=331378&view=auto
==
--- cfe/trunk/test/Headers/stdatomic.cpp (added)
+++ cfe/trunk/test/Headers/stdatomic.cpp Wed May  2 10:50:43 2018
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify
+// RUN: %clang_cc1 -D__ALLOW_STDC_ATOMICS_IN_CXX__ %s -verify
+
+#include 
+
+#ifndef __ALLOW_STDC_ATOMICS_IN_CXX__
+// expected-error@stdatomic.h:* {{ is incompatible with the C++ 
standard library}}
+#else
+// expected-no-diagnostics
+#endif


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


[libcxx] r331379 - Emit an error when mixing and

2018-05-02 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed May  2 10:56:45 2018
New Revision: 331379

URL: http://llvm.org/viewvc/llvm-project?rev=331379&view=rev
Log:
Emit an error when mixing  and 

Atomics in C and C++ are incompatible at the moment and mixing the
headers can result in confusing error messages.

Emit an error explicitly telling about the incompatibility. Introduce
the macro `__ALLOW_STDC_ATOMICS_IN_CXX__` that allows to choose in C++
between C atomics and C++ atomics.

rdar://problem/27435938

Reviewers: rsmith, EricWF, mclow.lists

Reviewed By: mclow.lists

Subscribers: jkorous-apple, christof, bumblebritches57, JonChesterfield, 
smeenai, cfe-commits

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

Added:
libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp
Modified:
libcxx/trunk/include/atomic

Modified: libcxx/trunk/include/atomic
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=331379&r1=331378&r2=331379&view=diff
==
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Wed May  2 10:56:45 2018
@@ -555,6 +555,9 @@ void atomic_signal_fence(memory_order m)
 #if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
 #error  is not implemented
 #endif
+#ifdef __ALLOW_STDC_ATOMICS_IN_CXX__
+#error  is incompatible with the C++ standard library
+#endif
 
 #if _LIBCPP_STD_VER > 14
 # define __cpp_lib_atomic_is_always_lock_free 201603L

Added: libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp?rev=331379&view=auto
==
--- libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp (added)
+++ libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp Wed May  2 
10:56:45 2018
@@ -0,0 +1,28 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+//
+// 
+
+// Test that including  fails to compile when we want to use C atomics
+// in C++ and have corresponding macro defined.
+
+// MODULES_DEFINES: __ALLOW_STDC_ATOMICS_IN_CXX__
+#ifndef __ALLOW_STDC_ATOMICS_IN_CXX__
+#define __ALLOW_STDC_ATOMICS_IN_CXX__
+#endif
+
+#include 
+// expected-error@atomic:* {{ is incompatible with the C++ 
standard library}}
+
+int main()
+{
+}
+


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


r331392 - Revert "Emit an error when mixing and "

2018-05-02 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed May  2 12:52:07 2018
New Revision: 331392

URL: http://llvm.org/viewvc/llvm-project?rev=331392&view=rev
Log:
Revert "Emit an error when mixing  and "

It reverts r331378 as it caused test failures

ThreadSanitizer-x86_64 :: Darwin/gcd-groups-destructor.mm
ThreadSanitizer-x86_64 :: Darwin/libcxx-shared-ptr-stress.mm
ThreadSanitizer-x86_64 :: Darwin/xpc-race.mm

Only clang part of the change is reverted, libc++ part remains as is because it
emits error less aggressively.

Removed:
cfe/trunk/test/Headers/stdatomic.cpp
Modified:
cfe/trunk/lib/Headers/stdatomic.h

Modified: cfe/trunk/lib/Headers/stdatomic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stdatomic.h?rev=331392&r1=331391&r2=331392&view=diff
==
--- cfe/trunk/lib/Headers/stdatomic.h (original)
+++ cfe/trunk/lib/Headers/stdatomic.h Wed May  2 12:52:07 2018
@@ -31,10 +31,6 @@
 # include_next 
 #else
 
-#if !defined(__ALLOW_STDC_ATOMICS_IN_CXX__) && defined(__cplusplus)
-#error " is incompatible with the C++ standard library; define 
__ALLOW_STDC_ATOMICS_IN_CXX__ to proceed."
-#endif
-
 #include 
 #include 
 

Removed: cfe/trunk/test/Headers/stdatomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/stdatomic.cpp?rev=331391&view=auto
==
--- cfe/trunk/test/Headers/stdatomic.cpp (original)
+++ cfe/trunk/test/Headers/stdatomic.cpp (removed)
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 %s -verify
-// RUN: %clang_cc1 -D__ALLOW_STDC_ATOMICS_IN_CXX__ %s -verify
-
-#include 
-
-#ifndef __ALLOW_STDC_ATOMICS_IN_CXX__
-// expected-error@stdatomic.h:* {{ is incompatible with the C++ 
standard library}}
-#else
-// expected-no-diagnostics
-#endif


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


r335638 - [Sema] Fix infinite typo correction loop.

2018-06-26 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Jun 26 10:56:48 2018
New Revision: 335638

URL: http://llvm.org/viewvc/llvm-project?rev=335638&view=rev
Log:
[Sema] Fix infinite typo correction loop.

NumTypos guard value ~0U doesn't prevent from creating new delayed typos. When
you create new delayed typos during typo correction, value ~0U wraps around to
0. When NumTypos is 0 we can miss some typos and treat an expression as it can
be typo-corrected. But if the expression is still invalid after correction, we
can get stuck in infinite loop trying to correct it.

Fix by not using value ~0U so that NumTypos correctly reflects the number of
typos.

rdar://problem/38642201

Reviewers: arphaman, majnemer, rsmith

Reviewed By: rsmith

Subscribers: rsmith, nicholas, cfe-commits

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


Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/Sema/typo-correction.c

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=335638&r1=335637&r2=335638&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Jun 26 10:56:48 2018
@@ -7727,12 +7727,8 @@ Sema::CorrectDelayedTyposInExpr(Expr *E,
   if (E && !ExprEvalContexts.empty() && ExprEvalContexts.back().NumTypos &&
   (E->isTypeDependent() || E->isValueDependent() ||
E->isInstantiationDependent())) {
-auto TyposInContext = ExprEvalContexts.back().NumTypos;
-assert(TyposInContext < ~0U && "Recursive call of 
CorrectDelayedTyposInExpr");
-ExprEvalContexts.back().NumTypos = ~0U;
 auto TyposResolved = DelayedTypos.size();
 auto Result = TransformTypos(*this, InitDecl, Filter).Transform(E);
-ExprEvalContexts.back().NumTypos = TyposInContext;
 TyposResolved -= DelayedTypos.size();
 if (Result.isInvalid() || Result.get() != E) {
   ExprEvalContexts.back().NumTypos -= TyposResolved;

Modified: cfe/trunk/test/Sema/typo-correction.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typo-correction.c?rev=335638&r1=335637&r2=335638&view=diff
==
--- cfe/trunk/test/Sema/typo-correction.c (original)
+++ cfe/trunk/test/Sema/typo-correction.c Tue Jun 26 10:56:48 2018
@@ -87,3 +87,16 @@ __attribute__((overloadable)) void func_
 void overloadable_callexpr(int arg) {
func_overloadable(ar); //expected-error{{use of undeclared identifier}}
 }
+
+// rdar://problem/38642201
+struct rdar38642201 {
+  int fieldName;
+};
+
+void rdar38642201_callee(int x, int y);
+void rdar38642201_caller() {
+  struct rdar38642201 structVar;
+  rdar38642201_callee(
+  structVar1.fieldName1.member1, //expected-error{{use of undeclared 
identifier 'structVar1'}}
+  structVar2.fieldName2.member2); //expected-error{{use of undeclared 
identifier 'structVar2'}}
+}


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


r374202 - [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2019-10-09 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Oct  9 12:29:13 2019
New Revision: 374202

URL: http://llvm.org/viewvc/llvm-project?rev=374202&view=rev
Log:
[ObjC generics] Fix not inheriting type bounds in categories/extensions.

When a category/extension doesn't repeat a type bound, corresponding
type parameter is substituted with `id` when used as a type argument. As
a result, in the added test case it was causing errors like

> type argument 'T' (aka 'id') does not satisfy the bound ('id') of 
> type parameter 'T'

We are already checking that type parameters should be consistent
everywhere (see `checkTypeParamListConsistency`) and update
`ObjCTypeParamDecl` to have correct underlying type. And when we use the
type parameter as a method return type or a method parameter type, it is
substituted to the bounded type. But when we use the type parameter as a
type argument, we check `ObjCTypeParamType` that ignores the updated
underlying type and remains `id`.

Fix by desugaring `ObjCTypeParamType` to the underlying type, the same
way we are doing with `TypedefType`.

rdar://problem/54329242

Reviewers: erik.pilkington, ahatanak

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, ributzka, cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/test/SemaObjC/parameterized_classes_subst.m

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=374202&r1=374201&r2=374202&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Oct  9 12:29:13 2019
@@ -5569,7 +5569,7 @@ class ObjCTypeParamType : public Type,
 
 public:
   bool isSugared() const { return true; }
-  QualType desugar() const { return getCanonicalTypeInternal(); }
+  QualType desugar() const;
 
   static bool classof(const Type *T) {
 return T->getTypeClass() == ObjCTypeParam;

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=374202&r1=374201&r2=374202&view=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Wed Oct  9 12:29:13 2019
@@ -663,6 +663,10 @@ ObjCTypeParamType::ObjCTypeParamType(con
   initialize(protocols);
 }
 
+QualType ObjCTypeParamType::desugar() const {
+  return getDecl()->getUnderlyingType();
+}
+
 ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
ArrayRef typeArgs,
ArrayRef protocols,

Modified: cfe/trunk/test/SemaObjC/parameterized_classes_subst.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/parameterized_classes_subst.m?rev=374202&r1=374201&r2=374202&view=diff
==
--- cfe/trunk/test/SemaObjC/parameterized_classes_subst.m (original)
+++ cfe/trunk/test/SemaObjC/parameterized_classes_subst.m Wed Oct  9 12:29:13 
2019
@@ -467,3 +467,17 @@ void bar(MyMutableDictionary>
+- (ParameterizedContainer *)inInterface;
+@end
+@interface ParameterizedContainer (Cat)
+- (ParameterizedContainer *)inCategory;
+@end
+@interface ParameterizedContainer ()
+- (ParameterizedContainer *)inExtension;
+@end


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


r374581 - [Stats] Convert some ad-hoc header search stats to ALWAYS_ENABLED_STATISTIC.

2019-10-11 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Oct 11 11:22:34 2019
New Revision: 374581

URL: http://llvm.org/viewvc/llvm-project?rev=374581&view=rev
Log:
[Stats] Convert some ad-hoc header search stats to ALWAYS_ENABLED_STATISTIC.

rdar://problem/55715134

Reviewers: dsanders, bogner, rtereshin

Reviewed By: dsanders

Subscribers: hiraditya, jkorous, dexonsmith, ributzka, cfe-commits, llvm-commits

Tags: #llvm

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

Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=374581&r1=374580&r2=374581&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Fri Oct 11 11:22:34 2019
@@ -232,10 +232,6 @@ class FileManager : public RefCountedBas
   ///
   unsigned NextFileUID;
 
-  // Statistics.
-  unsigned NumDirLookups, NumFileLookups;
-  unsigned NumDirCacheMisses, NumFileCacheMisses;
-
   // Caching.
   std::unique_ptr StatCache;
 

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=374581&r1=374580&r2=374581&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Oct 11 11:22:34 2019
@@ -250,12 +250,6 @@ class HeaderSearch {
   /// Entity used to look up stored header file information.
   ExternalHeaderFileInfoSource *ExternalSource = nullptr;
 
-  // Various statistics we track for performance analysis.
-  unsigned NumIncluded = 0;
-  unsigned NumMultiIncludeFileOptzn = 0;
-  unsigned NumFrameworkLookups = 0;
-  unsigned NumSubFrameworkLookups = 0;
-
 public:
   HeaderSearch(std::shared_ptr HSOpts,
SourceManager &SourceMgr, DiagnosticsEngine &Diags,
@@ -544,8 +538,6 @@ public:
   const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir,
bool IsFramework);
 
-  void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
-
   /// Determine whether there is a module map that may map the header
   /// with the given file name to a (sub)module.
   /// Always returns false if modules are disabled.

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=374581&r1=374580&r2=374581&view=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Fri Oct 11 11:22:34 2019
@@ -18,9 +18,10 @@
 
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemStatCache.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -35,6 +36,14 @@
 
 using namespace clang;
 
+#define DEBUG_TYPE "file-search"
+
+ALWAYS_ENABLED_STATISTIC(NumDirLookups, "Number of directory lookups.");
+ALWAYS_ENABLED_STATISTIC(NumFileLookups, "Number of file lookups.");
+ALWAYS_ENABLED_STATISTIC(NumDirCacheMisses,
+ "Number of directory cache misses.");
+ALWAYS_ENABLED_STATISTIC(NumFileCacheMisses, "Number of file cache misses.");
+
 
//===--===//
 // Common logic.
 
//===--===//
@@ -43,9 +52,6 @@ FileManager::FileManager(const FileSyste
  IntrusiveRefCntPtr FS)
 : FS(std::move(FS)), FileSystemOpts(FSO), SeenDirEntries(64),
   SeenFileEntries(64), NextFileUID(0) {
-  NumDirLookups = NumFileLookups = 0;
-  NumDirCacheMisses = NumFileCacheMisses = 0;
-
   // If the caller doesn't provide a virtual file system, just grab the real
   // file system.
   if (!this->FS)

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=374581&r1=374580&r2=374581&view=diff
==
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Oct 11 11:22:34 2019
@@ -27,6 +27,7 @@
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Capacity.h"
@@ -46,6 +47,16 @@
 
 using namespace clang;
 

r374596 - [ObjC] Remove default parameter no caller was providing. NFC intended.

2019-10-11 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Oct 11 14:21:02 2019
New Revision: 374596

URL: http://llvm.org/viewvc/llvm-project?rev=374596&view=rev
Log:
[ObjC] Remove default parameter no caller was providing. NFC intended.

Currently there is no need to make ObjCTypeParamType have a canonical type
different from the one in corresponding ObjCTypeParamDecl. So remove the
corresponding unused API.

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

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=374596&r1=374595&r2=374596&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Oct 11 14:21:02 2019
@@ -1503,8 +1503,7 @@ public:
  bool isKindOf) const;
 
   QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
-ArrayRef protocols,
-QualType Canonical = QualType()) const;
+ArrayRef protocols) const;
 
   bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=374596&r1=374595&r2=374596&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Oct 11 14:21:02 2019
@@ -4714,8 +4714,7 @@ ASTContext::applyObjCProtocolQualifiers(
 
 QualType
 ASTContext::getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
-   ArrayRef protocols,
-   QualType Canonical) const {
+ ArrayRef protocols) const 
{
   // Look in the folding set for an existing type.
   llvm::FoldingSetNodeID ID;
   ObjCTypeParamType::Profile(ID, Decl, protocols);
@@ -4724,16 +4723,14 @@ ASTContext::getObjCTypeParamType(const O
   ObjCTypeParamTypes.FindNodeOrInsertPos(ID, InsertPos))
 return QualType(TypeParam, 0);
 
-  if (Canonical.isNull()) {
-// We canonicalize to the underlying type.
-Canonical = getCanonicalType(Decl->getUnderlyingType());
-if (!protocols.empty()) {
-  // Apply the protocol qualifers.
-  bool hasError;
-  Canonical = getCanonicalType(applyObjCProtocolQualifiers(
-  Canonical, protocols, hasError, true /*allowOnPointerType*/));
-  assert(!hasError && "Error when apply protocol qualifier to bound type");
-}
+  // We canonicalize to the underlying type.
+  QualType Canonical = getCanonicalType(Decl->getUnderlyingType());
+  if (!protocols.empty()) {
+// Apply the protocol qualifers.
+bool hasError;
+Canonical = getCanonicalType(applyObjCProtocolQualifiers(
+Canonical, protocols, hasError, true /*allowOnPointerType*/));
+assert(!hasError && "Error when apply protocol qualifier to bound type");
   }
 
   unsigned size = sizeof(ObjCTypeParamType);


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


r375031 - Replace platform-dependent `stat` with `llvm::sys::fs::status`. NFC intended.

2019-10-16 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Oct 16 12:12:34 2019
New Revision: 375031

URL: http://llvm.org/viewvc/llvm-project?rev=375031&view=rev
Log:
Replace platform-dependent `stat` with `llvm::sys::fs::status`. NFC intended.

Reviewers: bruno, sammccall

Reviewed By: sammccall

Subscribers: jkorous, dexonsmith, arphaman, ributzka, cfe-commits

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

Modified:
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=375031&r1=375030&r2=375031&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Oct 16 12:12:34 2019
@@ -50,8 +50,6 @@
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
-#include 
 #include 
 #include 
 
@@ -1389,16 +1387,16 @@ static void writeTimestampFile(StringRef
 /// Prune the module cache of modules that haven't been accessed in
 /// a long time.
 static void pruneModuleCache(const HeaderSearchOptions &HSOpts) {
-  struct stat StatBuf;
+  llvm::sys::fs::file_status StatBuf;
   llvm::SmallString<128> TimestampFile;
   TimestampFile = HSOpts.ModuleCachePath;
   assert(!TimestampFile.empty());
   llvm::sys::path::append(TimestampFile, "modules.timestamp");
 
   // Try to stat() the timestamp file.
-  if (::stat(TimestampFile.c_str(), &StatBuf)) {
+  if (std::error_code EC = llvm::sys::fs::status(TimestampFile, StatBuf)) {
 // If the timestamp file wasn't there, create one now.
-if (errno == ENOENT) {
+if (EC == std::errc::no_such_file_or_directory) {
   writeTimestampFile(TimestampFile);
 }
 return;
@@ -1406,7 +1404,8 @@ static void pruneModuleCache(const Heade
 
   // Check whether the time stamp is older than our pruning interval.
   // If not, do nothing.
-  time_t TimeStampModTime = StatBuf.st_mtime;
+  time_t TimeStampModTime =
+  llvm::sys::toTimeT(StatBuf.getLastModificationTime());
   time_t CurrentTime = time(nullptr);
   if (CurrentTime - TimeStampModTime <= 
time_t(HSOpts.ModuleCachePruneInterval))
 return;
@@ -1438,11 +1437,11 @@ static void pruneModuleCache(const Heade
 
   // Look at this file. If we can't stat it, there's nothing interesting
   // there.
-  if (::stat(File->path().c_str(), &StatBuf))
+  if (llvm::sys::fs::status(File->path(), StatBuf))
 continue;
 
   // If the file has been used recently enough, leave it there.
-  time_t FileAccessTime = StatBuf.st_atime;
+  time_t FileAccessTime = 
llvm::sys::toTimeT(StatBuf.getLastAccessedTime());
   if (CurrentTime - FileAccessTime <=
   time_t(HSOpts.ModuleCachePruneAfter)) {
 continue;

Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=375031&r1=375030&r2=375031&view=diff
==
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Wed Oct 16 12:12:34 2019
@@ -803,8 +803,8 @@ clang_codeCompleteAt_Impl(CXTranslationU
   os << arg << ".pth";
 }
 pchName.push_back('\0');
-struct stat stat_results;
-if (stat(pchName.str().c_str(), &stat_results) == 0)
+llvm::sys::fs::file_status stat_results;
+if (!llvm::sys::fs::status(pchName, stat_results))
   usesPCH = true;
 continue;
   }


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


Re: r374202 - [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2019-10-21 Thread Volodymyr Sapsai via cfe-commits
That error looks strange and confusing to me too. My guess is that my change 
exposed some bug with literals. I’ve tried

 NSDictionary* videoSettingsDictionary2 = [NSDictionary
dictionaryWithObject:@(best_fourcc)
forKey:(id)kCVPixelBufferPixelFormatTypeKey];

and

@interface GenericTest  : NSObject
- (void)test:(const KeyType  _Nonnull)key;
@end

void anotherTest(GenericTest *t) {
  [t test:(id)kCVPixelBufferPixelFormatTypeKey];
}

But they didn’t trigger the error. I need more time to investigate the issue 
but in the meantime you can fix the build by casting to the corresponding 
constant type, something like

  (NSString *)kCVPixelBufferPixelFormatTypeKey : @(best_fourcc)

Thanks,
Volodymyr

> On Oct 21, 2019, at 14:37, Hans Wennborg  wrote:
> 
> Hi Volodymyr,
> 
> This broke the Chrome build in an interesting way. Here's a reduced repro:
> 
> 
> $ cat /tmp/a.mm
> #import 
> 
> void f(int width, int height) {
>  FourCharCode best_fourcc = kCMPixelFormat_422YpCbCr8_yuvs;
>  NSDictionary* videoSettingsDictionary = @{
>(id)kCVPixelBufferPixelFormatTypeKey : @(best_fourcc),
>  };
> }
> 
> $ build.release/bin/clang++ -isysroot
> /work/chromium/src/build/mac_files/xcode_binaries/Contents/Developer/Platforms/MacOSX.platform/Developer/SDK
> s/MacOSX10.14.sdk -c /tmp/a.mm
> 
> /tmp/a.mm:6:5: error: cannot initialize a parameter of type
> 'KeyType  _Nonnull const' (aka 'const id') with an rvalue
> of type 'id'
>(id)kCVPixelBufferPixelFormatTypeKey : @(best_fourcc),
>^~~~
> 1 error generated.
> 
> 
> To me, the "cannot initialize a parameter of type [nanana] (aka 'const
> id') with an rvalue of type 'id'" message looks strange, but I'm not
> an Obj-C expert. Is this expected behaviour, and if so how should we
> change our code?
> 
> Thanks,
> Hans
> 
> On Wed, Oct 9, 2019 at 12:26 PM Volodymyr Sapsai via cfe-commits
>  wrote:
>> 
>> Author: vsapsai
>> Date: Wed Oct  9 12:29:13 2019
>> New Revision: 374202
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=374202&view=rev
>> Log:
>> [ObjC generics] Fix not inheriting type bounds in categories/extensions.
>> 
>> When a category/extension doesn't repeat a type bound, corresponding
>> type parameter is substituted with `id` when used as a type argument. As
>> a result, in the added test case it was causing errors like
>> 
>>> type argument 'T' (aka 'id') does not satisfy the bound ('id') 
>>> of type parameter 'T'
>> 
>> We are already checking that type parameters should be consistent
>> everywhere (see `checkTypeParamListConsistency`) and update
>> `ObjCTypeParamDecl` to have correct underlying type. And when we use the
>> type parameter as a method return type or a method parameter type, it is
>> substituted to the bounded type. But when we use the type parameter as a
>> type argument, we check `ObjCTypeParamType` that ignores the updated
>> underlying type and remains `id`.
>> 
>> Fix by desugaring `ObjCTypeParamType` to the underlying type, the same
>> way we are doing with `TypedefType`.
>> 
>> rdar://problem/54329242
>> 
>> Reviewers: erik.pilkington, ahatanak
>> 
>> Reviewed By: erik.pilkington
>> 
>> Subscribers: jkorous, dexonsmith, ributzka, cfe-commits
>> 
>> Differential Revision: https://reviews.llvm.org/D66696
>> 
>> Modified:
>>cfe/trunk/include/clang/AST/Type.h
>>cfe/trunk/lib/AST/Type.cpp
>>cfe/trunk/test/SemaObjC/parameterized_classes_subst.m
>> 
>> Modified: cfe/trunk/include/clang/AST/Type.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=374202&r1=374201&r2=374202&view=diff
>> ==
>> --- cfe/trunk/include/clang/AST/Type.h (original)
>> +++ cfe/trunk/include/clang/AST/Type.h Wed Oct  9 12:29:13 2019
>> @@ -5569,7 +5569,7 @@ class ObjCTypeParamType : public Type,
>> 
>> public:
>>   bool isSugared() const { return true; }
>> -  QualType desugar() const { return getCanonicalTypeInternal(); }
>> +  QualType desugar() const;
>> 
>>   static bool classof(const Type *T) {
>> return T->getTypeClass() == ObjCTypeParam;
>> 
>> Modified: cfe/trunk/lib/AST/Type.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=374202&r1=374201&r2=374202&view=diff
>> ===

[clang] 03559c6 - [diagtool] Install diagtool when LLVM_INSTALL_TOOLCHAIN_ONLY is ON.

2020-05-29 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2020-05-29T16:25:06-07:00
New Revision: 03559c684a9bfe4de142fa4a7d2ef1edf08a8ad3

URL: 
https://github.com/llvm/llvm-project/commit/03559c684a9bfe4de142fa4a7d2ef1edf08a8ad3
DIFF: 
https://github.com/llvm/llvm-project/commit/03559c684a9bfe4de142fa4a7d2ef1edf08a8ad3.diff

LOG: [diagtool] Install diagtool when LLVM_INSTALL_TOOLCHAIN_ONLY is ON.

Not sure about other platforms but `install-xcode-toolchain` was already
including diagtool in the toolchain. This change makes it possible to
install diagtool during Apple's 2-stage build.

Instead of dropping `if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)` conditional
I've switched to `add_clang_tool` which handles install targets. Also a
few other clang tools like clang-format, clang-scan-deps are using this
macro, so it is good to be consistent.

rdar://problem/15386909

Reviewed By: JDevlieghere

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

Added: 


Modified: 
clang/tools/diagtool/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/diagtool/CMakeLists.txt 
b/clang/tools/diagtool/CMakeLists.txt
index a95444be40ee..b49619c075c7 100644
--- a/clang/tools/diagtool/CMakeLists.txt
+++ b/clang/tools/diagtool/CMakeLists.txt
@@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-add_clang_executable(diagtool
+add_clang_tool(diagtool
   diagtool_main.cpp
   DiagTool.cpp
   DiagnosticNames.cpp
@@ -17,15 +17,3 @@ clang_target_link_libraries(diagtool
   clangBasic
   clangFrontend
   )
-
-if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
-  install(TARGETS diagtool
-COMPONENT diagtool
-RUNTIME DESTINATION bin)
-
-  if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(install-diagtool
-  DEPENDS diagtool
-  COMPONENT diagtool)
-  endif()
-endif()



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


[clang] a8c8b62 - [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2020-04-03 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2020-04-03T16:29:02-07:00
New Revision: a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7

URL: 
https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7
DIFF: 
https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7.diff

LOG: [ObjC generics] Fix not inheriting type bounds in categories/extensions.

When a category/extension doesn't repeat a type bound, corresponding
type parameter is substituted with `id` when used as a type argument. As
a result, in the added test case it was causing errors like

> type argument 'T' (aka 'id') does not satisfy the bound ('id') of 
> type parameter 'T'

We are already checking that type parameters should be consistent
everywhere (see `checkTypeParamListConsistency`) and update
`ObjCTypeParamDecl` to have correct underlying type. And when we use the
type parameter as a method return type or a method parameter type, it is
substituted to the bounded type. But when we use the type parameter as a
type argument, we check `ObjCTypeParamType` that wasn't updated and
remains `id`.

Fix by updating not only `ObjCTypeParamDecl` UnderlyingType but also
TypeForDecl as we use the underlying type to create a canonical type for
`ObjCTypeParamType` (see `ASTContext::getObjCTypeParamType`).

This is a different approach to fixing the issue. The previous one was
02c2ab3d8872416589bd1a6ca3dfb96ba373a3b9 which was reverted in
4c539e8da1b3de38a53ef3f7497f5c45a3243b61. The problem with the previous
approach was that `ObjCTypeParamType::desugar` was returning underlying
type for `ObjCTypeParamDecl` without applying any protocols stored in
`ObjCTypeParamType`. It caused inconsistencies in comparing types before
and after desugaring.

rdar://problem/54329242

Reviewed By: erik.pilkington

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/test/SemaObjC/parameterized_classes_collection_literal.m
clang/test/SemaObjC/parameterized_classes_subst.m

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 6813ab58874e..6360f18217c7 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1442,6 +1442,8 @@ class ASTContext : public RefCountedBase {
 
   QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
 ArrayRef protocols) const;
+  void adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig,
+ObjCTypeParamDecl *New) const;
 
   bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
 

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1e81e0a67b4d..06dcb6fa0580 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4874,6 +4874,17 @@ ASTContext::getObjCTypeParamType(const ObjCTypeParamDecl 
*Decl,
   return QualType(newType, 0);
 }
 
+void ASTContext::adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig,
+  ObjCTypeParamDecl *New) const {
+  New->setTypeSourceInfo(getTrivialTypeSourceInfo(Orig->getUnderlyingType()));
+  // Update TypeForDecl after updating TypeSourceInfo.
+  auto NewTypeParamTy = cast(New->getTypeForDecl());
+  SmallVector protocols;
+  protocols.append(NewTypeParamTy->qual_begin(), NewTypeParamTy->qual_end());
+  QualType UpdatedTy = getObjCTypeParamType(New, protocols);
+  New->setTypeForDecl(UpdatedTy.getTypePtr());
+}
+
 /// ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's
 /// protocol list adopt all protocols in QT's qualified-id protocol
 /// list.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 3428437c3146..7c65378261ad 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3534,6 +3534,7 @@ void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID 
&ID,
 const ObjCTypeParamDecl *OTPDecl,
 ArrayRef protocols) {
   ID.AddPointer(OTPDecl);
+  ID.AddPointer(OTPDecl->getUnderlyingType().getAsOpaquePtr());
   ID.AddInteger(protocols.size());
   for (auto proto : protocols)
 ID.AddPointer(proto);

diff  --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 934e1a23141c..6db57898e378 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -938,8 +938,7 @@ static bool checkTypeParamListConsistency(Sema &S,
 
   // Override the new type parameter's bound type with the previous type,
   // so that it's consistent.
-  newTypeParam->setTypeSourceInfo(
-
S.Context.getTrivialTypeSourceInfo(prevTypeParam->getUnderlyingType()));
+  S.Context.adjustObjCTypeParamBoundT

Re: [clang] a8c8b62 - [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2020-04-06 Thread Volodymyr Sapsai via cfe-commits
Is there anything special in the builedbot configuration? Are you still 
observing intermittent failures?

I’m double checking if we see similar failures internally but so far looks like 
everything is working fine. I’ve only seen a single failure 
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/18616
 
<http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/18616>

At the moment I don’t know what might be causing the non-determinism. The type 
checking depends on the parsing order. We rely that

@interface ParameterizedContainer (Cat)

is parsed before

- (ParameterizedContainer *)inCategory;

So we check type parameter T is consistent with original @interface before 
using it. What is also confusing is that there is only a single error. I  
expect both a category and an extension to have same errors.

> On Apr 5, 2020, at 10:10, Nico Weber  wrote:
> 
> The test here flakily fails, maybe 1 in 10 times: 
> http://45.33.8.238/mac/11180/step_7.txt 
> <http://45.33.8.238/mac/11180/step_7.txt>
> 
> error: 'error' diagnostics seen but not expected: 
>   File 
> /Users/thakis/src/llvm-project/clang/test/SemaObjC/parameterized_classes_subst.m
>  Line 479: type argument 'T' (aka 'id') does not satisfy the bound 
> ('id') of type parameter 'T'
> error: 'note' diagnostics seen but not expected: 
>   File 
> /Users/thakis/src/llvm-project/clang/test/SemaObjC/parameterized_classes_subst.m
>  Line 475: type parameter 'T' declared here
> 2 errors generated.
> 
> Maybe if this is emitted depends on the order of something in a data 
> structure that has no deterministic order, or similar?
> 
> On Fri, Apr 3, 2020 at 7:29 PM Volodymyr Sapsai via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> 
> Author: Volodymyr Sapsai
> Date: 2020-04-03T16:29:02-07:00
> New Revision: a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7
> 
> URL: 
> https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7
>  
> <https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7>
> DIFF: 
> https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7.diff
>  
> <https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7.diff>
> 
> LOG: [ObjC generics] Fix not inheriting type bounds in categories/extensions.
> 
> When a category/extension doesn't repeat a type bound, corresponding
> type parameter is substituted with `id` when used as a type argument. As
> a result, in the added test case it was causing errors like
> 
> > type argument 'T' (aka 'id') does not satisfy the bound ('id') 
> > of type parameter 'T'
> 
> We are already checking that type parameters should be consistent
> everywhere (see `checkTypeParamListConsistency`) and update
> `ObjCTypeParamDecl` to have correct underlying type. And when we use the
> type parameter as a method return type or a method parameter type, it is
> substituted to the bounded type. But when we use the type parameter as a
> type argument, we check `ObjCTypeParamType` that wasn't updated and
> remains `id`.
> 
> Fix by updating not only `ObjCTypeParamDecl` UnderlyingType but also
> TypeForDecl as we use the underlying type to create a canonical type for
> `ObjCTypeParamType` (see `ASTContext::getObjCTypeParamType`).
> 
> This is a different approach to fixing the issue. The previous one was
> 02c2ab3d8872416589bd1a6ca3dfb96ba373a3b9 which was reverted in
> 4c539e8da1b3de38a53ef3f7497f5c45a3243b61. The problem with the previous
> approach was that `ObjCTypeParamType::desugar` was returning underlying
> type for `ObjCTypeParamDecl` without applying any protocols stored in
> `ObjCTypeParamType`. It caused inconsistencies in comparing types before
> and after desugaring.
> 
> rdar://problem/54329242
> 
> Reviewed By: erik.pilkington
> 
> Differential Revision: https://reviews.llvm.org/D72872 
> <https://reviews.llvm.org/D72872>
> 
> Added: 
> 
> 
> Modified: 
> clang/include/clang/AST/ASTContext.h
> clang/lib/AST/ASTContext.cpp
> clang/lib/AST/Type.cpp
> clang/lib/Sema/SemaDeclObjC.cpp
> clang/test/SemaObjC/parameterized_classes_collection_literal.m
> clang/test/SemaObjC/parameterized_classes_subst.m
> 
> Removed: 
> 
> 
> 
> 
> diff  --git a/clang/include/clang/AST/ASTContext.h 
> b/clang/include/clang/AST/ASTContext.h
> index 6813ab58874e..6360f18217c7 100644
> --- a/clang/include/clang/AST/ASTContext.h
>

[clang] 8fb7cfc - Revert "[ObjC generics] Fix not inheriting type bounds in categories/extensions."

2020-04-07 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2020-04-07T17:41:30-07:00
New Revision: 8fb7cfcea97af440830d256cc18ccd978f218e1d

URL: 
https://github.com/llvm/llvm-project/commit/8fb7cfcea97af440830d256cc18ccd978f218e1d
DIFF: 
https://github.com/llvm/llvm-project/commit/8fb7cfcea97af440830d256cc18ccd978f218e1d.diff

LOG: Revert "[ObjC generics] Fix not inheriting type bounds in 
categories/extensions."

This reverts commit a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7. It causes
intermittent

Clang :: SemaObjC/parameterized_classes_subst.m

test failures on various bots.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/test/SemaObjC/parameterized_classes_collection_literal.m
clang/test/SemaObjC/parameterized_classes_subst.m

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 6360f18217c7..6813ab58874e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1442,8 +1442,6 @@ class ASTContext : public RefCountedBase {
 
   QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
 ArrayRef protocols) const;
-  void adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig,
-ObjCTypeParamDecl *New) const;
 
   bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
 

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 06dcb6fa0580..1e81e0a67b4d 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4874,17 +4874,6 @@ ASTContext::getObjCTypeParamType(const ObjCTypeParamDecl 
*Decl,
   return QualType(newType, 0);
 }
 
-void ASTContext::adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig,
-  ObjCTypeParamDecl *New) const {
-  New->setTypeSourceInfo(getTrivialTypeSourceInfo(Orig->getUnderlyingType()));
-  // Update TypeForDecl after updating TypeSourceInfo.
-  auto NewTypeParamTy = cast(New->getTypeForDecl());
-  SmallVector protocols;
-  protocols.append(NewTypeParamTy->qual_begin(), NewTypeParamTy->qual_end());
-  QualType UpdatedTy = getObjCTypeParamType(New, protocols);
-  New->setTypeForDecl(UpdatedTy.getTypePtr());
-}
-
 /// ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's
 /// protocol list adopt all protocols in QT's qualified-id protocol
 /// list.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 7c65378261ad..3428437c3146 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3534,7 +3534,6 @@ void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID 
&ID,
 const ObjCTypeParamDecl *OTPDecl,
 ArrayRef protocols) {
   ID.AddPointer(OTPDecl);
-  ID.AddPointer(OTPDecl->getUnderlyingType().getAsOpaquePtr());
   ID.AddInteger(protocols.size());
   for (auto proto : protocols)
 ID.AddPointer(proto);

diff  --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 6db57898e378..934e1a23141c 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -938,7 +938,8 @@ static bool checkTypeParamListConsistency(Sema &S,
 
   // Override the new type parameter's bound type with the previous type,
   // so that it's consistent.
-  S.Context.adjustObjCTypeParamBoundType(prevTypeParam, newTypeParam);
+  newTypeParam->setTypeSourceInfo(
+
S.Context.getTrivialTypeSourceInfo(prevTypeParam->getUnderlyingType()));
   continue;
 }
 
@@ -965,7 +966,8 @@ static bool checkTypeParamListConsistency(Sema &S,
 }
 
 // Update the new type parameter's bound to match the previous one.
-S.Context.adjustObjCTypeParamBoundType(prevTypeParam, newTypeParam);
+newTypeParam->setTypeSourceInfo(
+  S.Context.getTrivialTypeSourceInfo(prevTypeParam->getUnderlyingType()));
   }
 
   return false;

diff  --git a/clang/test/SemaObjC/parameterized_classes_collection_literal.m 
b/clang/test/SemaObjC/parameterized_classes_collection_literal.m
index 034d2e8da217..472746e09db9 100644
--- a/clang/test/SemaObjC/parameterized_classes_collection_literal.m
+++ b/clang/test/SemaObjC/parameterized_classes_collection_literal.m
@@ -29,9 +29,7 @@ + (instancetype)arrayWithObjects:(const T [])objects 
count:(NSUInteger)cnt;
 @end
 
 @interface NSDictionary : NSObject 
-+ (instancetype)dictionaryWithObjects:(const V [])objects
-  forKeys:(const K  [])keys
-count:(NSUInteger)cnt;
++ (instancetype)dictionaryWithObjects:(const V [])objects forKeys:(const K 
[])keys count:(NSUInteger)cnt;
 @end
 
 void testArrayLiteral(void) {
@@ -52,9 +50,3 @@ void testDictionaryLiteral(void) {
 @"world" : @"blah" // expected-wa

Re: [clang] a8c8b62 - [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2020-04-07 Thread Volodymyr Sapsai via cfe-commits
Can reproduce test failure locally, reverted in 
8fb7cfcea97af440830d256cc18ccd978f218e1d

Thanks for noticing the problem and pointing me to it.

> On Apr 6, 2020, at 23:28, Mikael Holmén  wrote:
> 
> We see flakiness in the test in our bots too. Fails one time and then
> passes again.
> 
> /Mikael
> 
> On Mon, 2020-04-06 at 21:03 -0400, Nico Weber via cfe-commits wrote:
>> This isn't bot-dependent, it's been flaking on many different bots
>> over the last few days. Here's one from just now: 
>> http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/34705
>> 
>> On Mon, Apr 6, 2020 at 4:40 PM Volodymyr Sapsai 
>> wrote:
>>> Is there anything special in the builedbot configuration? Are you
>>> still observing intermittent failures?
>>> 
>>> I’m double checking if we see similar failures internally but so
>>> far looks like everything is working fine. I’ve only seen a single
>>> failure 
>>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/18616
>>> 
>>> At the moment I don’t know what might be causing the non-
>>> determinism. The type checking depends on the parsing order. We
>>> rely that
>>> 
>>> @interface ParameterizedContainer (Cat)
>>> 
>>> is parsed before
>>> 
>>> - (ParameterizedContainer *)inCategory;
>>> 
>>> So we check type parameter T is consistent with original @interface
>>> before using it. What is also confusing is that there is only a
>>> single error. I  expect both a category and an extension to have
>>> same errors.
>>> 
>>>> On Apr 5, 2020, at 10:10, Nico Weber  wrote:
>>>> 
>>>> The test here flakily fails, maybe 1 in 10 times: 
>>>> http://45.33.8.238/mac/11180/step_7.txt
>>>> 
>>>> error: 'error' diagnostics seen but not expected: 
>>>>  File /Users/thakis/src/llvm-
>>>> project/clang/test/SemaObjC/parameterized_classes_subst.m Line
>>>> 479: type argument 'T' (aka 'id') does not satisfy the bound
>>>> ('id') of type parameter 'T'
>>>> error: 'note' diagnostics seen but not expected: 
>>>>  File /Users/thakis/src/llvm-
>>>> project/clang/test/SemaObjC/parameterized_classes_subst.m Line
>>>> 475: type parameter 'T' declared here
>>>> 2 errors generated.
>>>> 
>>>> Maybe if this is emitted depends on the order of something in a
>>>> data structure that has no deterministic order, or similar?
>>>> 
>>>> On Fri, Apr 3, 2020 at 7:29 PM Volodymyr Sapsai via cfe-commits <
>>>> cfe-commits@lists.llvm.org> wrote:
>>>>> Author: Volodymyr Sapsai
>>>>> Date: 2020-04-03T16:29:02-07:00
>>>>> New Revision: a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7
>>>>> 
>>>>> URL: 
>>>>> https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7
>>>>> DIFF: 
>>>>> https://github.com/llvm/llvm-project/commit/a8c8b627f23f204fb621bd2a8c495cfc8bc16ae7.diff
>>>>> 
>>>>> LOG: [ObjC generics] Fix not inheriting type bounds in
>>>>> categories/extensions.
>>>>> 
>>>>> When a category/extension doesn't repeat a type bound,
>>>>> corresponding
>>>>> type parameter is substituted with `id` when used as a type
>>>>> argument. As
>>>>> a result, in the added test case it was causing errors like
>>>>> 
>>>>>> type argument 'T' (aka 'id') does not satisfy the bound
>>>>> ('id') of type parameter 'T'
>>>>> 
>>>>> We are already checking that type parameters should be
>>>>> consistent
>>>>> everywhere (see `checkTypeParamListConsistency`) and update
>>>>> `ObjCTypeParamDecl` to have correct underlying type. And when
>>>>> we use the
>>>>> type parameter as a method return type or a method parameter
>>>>> type, it is
>>>>> substituted to the bounded type. But when we use the type
>>>>> parameter as a
>>>>> type argument, we check `ObjCTypeParamType` that wasn't updated
>>>>> and
>>>>> remains `id`.
>>>>> 
>>>>> Fix by updating not only `ObjCTypeParamDecl` UnderlyingType but
>>&

[clang] 65f5887 - [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2020-04-24 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2020-04-24T16:32:28-07:00
New Revision: 65f58878e72a40d68ef3899c766846ee9ec7cf29

URL: 
https://github.com/llvm/llvm-project/commit/65f58878e72a40d68ef3899c766846ee9ec7cf29
DIFF: 
https://github.com/llvm/llvm-project/commit/65f58878e72a40d68ef3899c766846ee9ec7cf29.diff

LOG: [ObjC generics] Fix not inheriting type bounds in categories/extensions.

When a category/extension doesn't repeat a type bound, corresponding
type parameter is substituted with `id` when used as a type argument. As
a result, in the added test case it was causing errors like

> type argument 'T' (aka 'id') does not satisfy the bound ('id') of 
> type parameter 'T'

We are already checking that type parameters should be consistent
everywhere (see `checkTypeParamListConsistency`) and update
`ObjCTypeParamDecl` to have correct underlying type. And when we use the
type parameter as a method return type or a method parameter type, it is
substituted to the bounded type. But when we use the type parameter as a
type argument, we check `ObjCTypeParamType` that wasn't updated and
remains `id`.

Fix by updating not only `ObjCTypeParamDecl` UnderlyingType but also
TypeForDecl as we use the underlying type to create a canonical type for
`ObjCTypeParamType` (see `ASTContext::getObjCTypeParamType`).

This is a different approach to fixing the issue. The previous one was
02c2ab3d8872416589bd1a6ca3dfb96ba373a3b9 which was reverted in
4c539e8da1b3de38a53ef3f7497f5c45a3243b61. The problem with the previous
approach was that `ObjCTypeParamType::desugar` was returning underlying
type for `ObjCTypeParamDecl` without applying any protocols stored in
`ObjCTypeParamType`. It caused inconsistencies in comparing types before
and after desugaring.

Re-applying after fixing intermittent test failures.

rdar://problem/54329242

Reviewed By: erik.pilkington

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/test/SemaObjC/parameterized_classes_collection_literal.m
clang/test/SemaObjC/parameterized_classes_subst.m

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index dedbd857819d..82b8a51b9551 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1459,6 +1459,8 @@ class ASTContext : public RefCountedBase {
 
   QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
 ArrayRef protocols) const;
+  void adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig,
+ObjCTypeParamDecl *New) const;
 
   bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
 

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 322b14ce641a..cf746d9b947a 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5605,6 +5605,7 @@ class ObjCTypeParamType : public Type,
   void Profile(llvm::FoldingSetNodeID &ID);
   static void Profile(llvm::FoldingSetNodeID &ID,
   const ObjCTypeParamDecl *OTPDecl,
+  QualType CanonicalType,
   ArrayRef protocols);
 
   ObjCTypeParamDecl *getDecl() const { return OTPDecl; }

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fffcfac60ca7..47834d41b919 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4898,7 +4898,7 @@ ASTContext::getObjCTypeParamType(const ObjCTypeParamDecl 
*Decl,
  ArrayRef protocols) const 
{
   // Look in the folding set for an existing type.
   llvm::FoldingSetNodeID ID;
-  ObjCTypeParamType::Profile(ID, Decl, protocols);
+  ObjCTypeParamType::Profile(ID, Decl, Decl->getUnderlyingType(), protocols);
   void *InsertPos = nullptr;
   if (ObjCTypeParamType *TypeParam =
   ObjCTypeParamTypes.FindNodeOrInsertPos(ID, InsertPos))
@@ -4924,6 +4924,17 @@ ASTContext::getObjCTypeParamType(const ObjCTypeParamDecl 
*Decl,
   return QualType(newType, 0);
 }
 
+void ASTContext::adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig,
+  ObjCTypeParamDecl *New) const {
+  New->setTypeSourceInfo(getTrivialTypeSourceInfo(Orig->getUnderlyingType()));
+  // Update TypeForDecl after updating TypeSourceInfo.
+  auto NewTypeParamTy = cast(New->getTypeForDecl());
+  SmallVector protocols;
+  protocols.append(NewTypeParamTy->qual_begin(), NewTypeParamTy->qual_end());
+  QualType UpdatedTy = getObjCTypeParamType(New, protocols);
+  New->setTypeForDecl(UpdatedTy.getTypePtr());
+}
+
 /// ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's
 /// protocol list adopt all protocols in 

[clang] 6a3469f - [ObjC] Add compatibility mode for type checking of qualified id block parameters.

2020-05-14 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2020-05-14T12:08:19-07:00
New Revision: 6a3469f58d0c230e86043f6975f048968334dfa4

URL: 
https://github.com/llvm/llvm-project/commit/6a3469f58d0c230e86043f6975f048968334dfa4
DIFF: 
https://github.com/llvm/llvm-project/commit/6a3469f58d0c230e86043f6975f048968334dfa4.diff

LOG: [ObjC] Add compatibility mode for type checking of qualified id block 
parameters.

Commit 73152a2ec20766ac45673a129bf1f5fc97ca9bbe fixed type checking for
blocks with qualified id parameters. But there are existing APIs in
Apple SDKs relying on the old type checking behavior. Specifically,
these are APIs using NSItemProviderCompletionHandler in
Foundation/NSItemProvider.h. To keep existing code working and to allow
developers to use affected APIs introduce a compatibility mode that
enables the previous and the fixed type checking. This mode is enabled
only on Darwin platforms.

Reviewed By: jyknight, ahatanak

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/CC1Options.td
clang/lib/AST/ASTContext.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/darwin-objc-options.m
clang/test/SemaObjC/block-type-safety.m

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c582a58e731f..e94305da46ba 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -278,6 +278,9 @@ LANGOPT(ObjCAutoRefCount , 1, 0, "Objective-C automated 
reference counting")
 LANGOPT(ObjCWeakRuntime , 1, 0, "__weak support in the ARC runtime")
 LANGOPT(ObjCWeak, 1, 0, "Objective-C __weak in ARC and MRC files")
 LANGOPT(ObjCSubscriptingLegacyRuntime , 1, 0, "Subscripting support in 
legacy ObjectiveC runtime")
+BENIGN_LANGOPT(CompatibilityQualifiedIdBlockParamTypeChecking, 1, 0,
+   "compatibility mode for type checking block parameters "
+   "involving qualified id types")
 LANGOPT(CFProtectionBranch , 1, 0, "Control-Flow Branch Protection enabled")
 LANGOPT(FakeAddressSpaceMap , 1, 0, "OpenCL fake address space map")
 ENUM_LANGOPT(AddressSpaceMapMangling , AddrSpaceMapMangling, 2, ASMM_Target, 
"OpenCL address space map mangling mode")

diff  --git a/clang/include/clang/Driver/CC1Options.td 
b/clang/include/clang/Driver/CC1Options.td
index 526a51085ce7..9d2bfbf949ef 100644
--- a/clang/include/clang/Driver/CC1Options.td
+++ b/clang/include/clang/Driver/CC1Options.td
@@ -813,6 +813,9 @@ def fsigned_wchar : Flag<["-"], "fsigned-wchar">,
   HelpText<"Use a signed type for wchar_t">;
 def fno_signed_wchar : Flag<["-"], "fno-signed-wchar">,
   HelpText<"Use an unsigned type for wchar_t">;
+def fcompatibility_qualified_id_block_param_type_checking : Flag<["-"], 
"fcompatibility-qualified-id-block-type-checking">,
+  HelpText<"Allow using blocks with parameters of more specific type than "
+   "the type system guarantees when a parameter is qualified id">;
 
 // FIXME: Remove these entirely once functionality/tests have been excised.
 def fobjc_gc_only : Flag<["-"], "fobjc-gc-only">, Group,

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 8f3858126253..c457a5537168 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8599,10 +8599,18 @@ bool ASTContext::canAssignObjCInterfacesInBlockPointer(
   RHSOPT->isObjCQualifiedIdType());
   }
 
-  if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType())
-return finish(ObjCQualifiedIdTypesAreCompatible(
-(BlockReturnType ? LHSOPT : RHSOPT),
-(BlockReturnType ? RHSOPT : LHSOPT), false));
+  if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) {
+if (getLangOpts().CompatibilityQualifiedIdBlockParamTypeChecking)
+  // Use for block parameters previous type checking for compatibility.
+  return finish(ObjCQualifiedIdTypesAreCompatible(LHSOPT, RHSOPT, false) ||
+// Or corrected type checking as in non-compat mode.
+(!BlockReturnType &&
+ ObjCQualifiedIdTypesAreCompatible(RHSOPT, LHSOPT, 
false)));
+else
+  return finish(ObjCQualifiedIdTypesAreCompatible(
+  (BlockReturnType ? LHSOPT : RHSOPT),
+  (BlockReturnType ? RHSOPT : LHSOPT), false));
+  }
 
   const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType();
   const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType();

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index f6e93eecb460..3bf7f9cbc139 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2376,6 +2376,10 @@ void Darwin::addClangTargetOptions(const 
llvm::op

[libcxx] r318862 - [libcxx] Make std::basic_istream::getline 0-terminate input array in case of error.

2017-11-22 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Nov 22 10:52:36 2017
New Revision: 318862

URL: http://llvm.org/viewvc/llvm-project?rev=318862&view=rev
Log:
[libcxx] Make std::basic_istream::getline 0-terminate input array in case of 
error.

It covers the cases when the sentry object returns false and when an exception
was thrown. Corresponding standard paragraph is C++14 [istream.unformatted]p21:
  In any case, if n is greater than zero, it then stores a null character
  (using charT()) into the next successive location of the array.

Patch by Reimar Döffinger.


Modified:
libcxx/trunk/include/istream

libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp

libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp

Modified: libcxx/trunk/include/istream
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/istream?rev=318862&r1=318861&r2=318862&view=diff
==
--- libcxx/trunk/include/istream (original)
+++ libcxx/trunk/include/istream Wed Nov 22 10:52:36 2017
@@ -1069,16 +1069,18 @@ basic_istream<_CharT, _Traits>::getline(
 this->rdbuf()->sbumpc();
 ++__gc_;
 }
-if (__n > 0)
-*__s = char_type();
 if (__gc_ == 0)
__err |= ios_base::failbit;
 this->setstate(__err);
 }
+if (__n > 0)
+*__s = char_type();
 #ifndef _LIBCPP_NO_EXCEPTIONS
 }
 catch (...)
 {
+if (__n > 0)
+*__s = char_type();
 this->__set_badbit_and_consider_rethrow();
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS

Modified: 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp?rev=318862&r1=318861&r2=318862&view=diff
==
--- 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp
 Wed Nov 22 10:52:36 2017
@@ -14,6 +14,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 template 
 struct testbuf
 : public std::basic_streambuf
@@ -59,7 +61,33 @@ int main()
 assert(!is.fail());
 assert(std::string(s) == " ");
 assert(is.gcount() == 1);
+// Check that even in error case the buffer is properly 0-terminated.
+is.getline(s, 5);
+assert( is.eof());
+assert( is.fail());
+assert(std::string(s) == "");
+assert(is.gcount() == 0);
+}
+#ifndef TEST_HAS_NO_EXCEPTIONS
+{
+testbuf sb(" ");
+std::istream is(&sb);
+char s[5] = "test";
+is.exceptions(std::istream::eofbit | std::istream::badbit);
+try
+{
+is.getline(s, 5);
+assert(false);
+}
+catch (std::ios_base::failure&)
+{
+}
+assert( is.eof());
+assert( is.fail());
+assert(std::string(s) == " ");
+assert(is.gcount() == 1);
 }
+#endif
 {
 testbuf sb(L"  \n\n ");
 std::wistream is(&sb);
@@ -79,5 +107,31 @@ int main()
 assert(!is.fail());
 assert(std::wstring(s) == L" ");
 assert(is.gcount() == 1);
+// Check that even in error case the buffer is properly 0-terminated.
+is.getline(s, 5);
+assert( is.eof());
+assert( is.fail());
+assert(std::wstring(s) == L"");
+assert(is.gcount() == 0);
+}
+#ifndef TEST_HAS_NO_EXCEPTIONS
+{
+testbuf sb(L" ");
+std::wistream is(&sb);
+wchar_t s[5] = L"test";
+is.exceptions(std::wistream::eofbit | std::wistream::badbit);
+try
+{
+is.getline(s, 5);
+assert(false);
+}
+catch (std::ios_base::failure&)
+{
+}
+assert( is.eof());
+assert( is.fail());
+assert(std::wstring(s) == L" ");
+assert(is.gcount() == 1);
 }
+#endif
 }

Modified: 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp?rev=318862&r1=318861&r2=318862&view=diff
==
--- 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp
 (original)
+++ 
libcxx/trunk

[libcxx] r318863 - [libcxx][fixup] Mark std::basic_istream::getline tests as failing for previous libcxx versions.

2017-11-22 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Wed Nov 22 11:36:54 2017
New Revision: 318863

URL: http://llvm.org/viewvc/llvm-project?rev=318863&view=rev
Log:
[libcxx][fixup] Mark std::basic_istream::getline tests as failing for previous 
libcxx versions.

r318862 added a fix for 0-termination input array in case of an error. Previous
libcxx versions don't have the fix and corresponding tests should be failing.


Modified:

libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp

libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp

Modified: 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp?rev=318863&r1=318862&r2=318863&view=diff
==
--- 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp
 Wed Nov 22 11:36:54 2017
@@ -7,6 +7,14 @@
 //
 
//===--===//
 
+// XFAIL: with_system_cxx_lib=macosx10.13
+// XFAIL: with_system_cxx_lib=macosx10.12
+// XFAIL: with_system_cxx_lib=macosx10.11
+// XFAIL: with_system_cxx_lib=macosx10.10
+// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: with_system_cxx_lib=macosx10.8
+// XFAIL: with_system_cxx_lib=macosx10.7
+
 // 
 
 // basic_istream& getline(char_type* s, streamsize n);

Modified: 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp?rev=318863&r1=318862&r2=318863&view=diff
==
--- 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp
 Wed Nov 22 11:36:54 2017
@@ -7,6 +7,14 @@
 //
 
//===--===//
 
+// XFAIL: with_system_cxx_lib=macosx10.13
+// XFAIL: with_system_cxx_lib=macosx10.12
+// XFAIL: with_system_cxx_lib=macosx10.11
+// XFAIL: with_system_cxx_lib=macosx10.10
+// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: with_system_cxx_lib=macosx10.8
+// XFAIL: with_system_cxx_lib=macosx10.7
+
 // 
 
 // basic_istream& getline(char_type* s, streamsize n, char_type 
delim);


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


Re: [PATCH] Ensure std::getline always 0-terminates string.

2017-11-22 Thread Volodymyr Sapsai via cfe-commits
On Nov 20, 2017, at 23:59, Reimar Döffinger  wrote:
> 
> On 21.11.2017, at 03:54, Volodymyr Sapsai  > wrote:
>> 
>>> If (exceptions()&badbit) != 0 then the exception is rethrown.
>> And looks like libstdc++ rethrows exception even if badbit is not set.
> 
> Thanks for looking all that up, I was in a hurry.
> 
>> If you feel comfortable, I can finish exception tests myself and commit the 
>> patch. How does it sound?
> 
> That would be very welcome if you don't mind.
> I don't have much time over to spend on this most days.
> 
> Thanks,
> Reimar Döffinger

Committed in r318862 and r318863 (the latter one is my mistake). Thanks for 
contributing the fix.

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


[clang] 246c5a9 - [ODRHash diagnostics] Transform method `ASTReader::diagnoseOdrViolations` into a class `ODRDiagsEmitter`. NFC.

2022-09-02 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-09-02T16:20:05-07:00
New Revision: 246c5a994b753fb52b2d3b70687039afef7a106e

URL: 
https://github.com/llvm/llvm-project/commit/246c5a994b753fb52b2d3b70687039afef7a106e
DIFF: 
https://github.com/llvm/llvm-project/commit/246c5a994b753fb52b2d3b70687039afef7a106e.diff

LOG: [ODRHash diagnostics] Transform method `ASTReader::diagnoseOdrViolations` 
into a class `ODRDiagsEmitter`. NFC.

Preparing to use diagnostics about ODR hash mismatches outside of ASTReader.

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

Added: 


Modified: 
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c97301957cb60..89c7fb36aa57f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -260,6 +260,7 @@ class CXXRecordDecl : public RecordDecl {
   friend class ASTWriter;
   friend class DeclContext;
   friend class LambdaExpr;
+  friend class ODRDiagsEmitter;
 
   friend void FunctionDecl::setPure(bool);
   friend void TagDecl::startDefinition();

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 19a18a2ef4030..22f317dc6b3f7 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1845,10 +1845,6 @@ class ASTReader
   /// if the declaration is not from a module file.
   ModuleFile *getOwningModuleFile(const Decl *D);
 
-  /// Get the best name we know for the module that owns the given
-  /// declaration, or an empty string if the declaration is not from a module.
-  std::string getOwningModuleNameForDiagnostic(const Decl *D);
-
   /// Returns the source location for the decl \p ID.
   SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
 

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index e7dea40a16100..eef8f9fdb07f1 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9186,19 +9186,6 @@ void ASTReader::visitTopLevelModuleMaps(
   }
 }
 
-std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) {
-  // If we know the owning module, use it.
-  if (Module *M = D->getImportedOwningModule())
-return M->getFullModuleName();
-
-  // Otherwise, use the name of the top-level module the decl is within.
-  if (ModuleFile *M = getOwningModuleFile(D))
-return M->ModuleName;
-
-  // Not from a module.
-  return {};
-}
-
 void ASTReader::finishPendingActions() {
   while (!PendingIdentifierInfos.empty() || !PendingFunctionTypes.empty() ||
  !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() ||
@@ -9446,6 +9433,114 @@ void ASTReader::finishPendingActions() {
   PendingMergedDefinitionsToDeduplicate.clear();
 }
 
+namespace clang {
+class ODRDiagsEmitter {
+public:
+  ODRDiagsEmitter(DiagnosticsEngine &Diags, const ASTContext &Context,
+  const LangOptions &LangOpts)
+  : Diags(Diags), Context(Context), LangOpts(LangOpts) {}
+
+  /// Diagnose ODR mismatch between 2 FunctionDecl.
+  ///
+  /// Returns true if found a mismatch and diagnosed it.
+  bool diagnoseMismatch(const FunctionDecl *FirstFunction,
+const FunctionDecl *SecondFunction) const;
+
+  /// Diagnose ODR mismatch between 2 EnumDecl.
+  ///
+  /// Returns true if found a mismatch and diagnosed it.
+  bool diagnoseMismatch(const EnumDecl *FirstEnum,
+const EnumDecl *SecondEnum) const;
+
+  /// Diagnose ODR mismatch between 2 CXXRecordDecl.
+  ///
+  /// Returns true if found a mismatch and diagnosed it.
+  /// To compare 2 declarations with merged and identical definition data
+  /// you need to provide pre-merge definition data in \p SecondDD.
+  bool
+  diagnoseMismatch(const CXXRecordDecl *FirstRecord,
+   const CXXRecordDecl *SecondRecord,
+   const struct CXXRecordDecl::DefinitionData *SecondDD) const;
+
+  /// Get the best name we know for the module that owns the given
+  /// declaration, or an empty string if the declaration is not from a module.
+  static std::string getOwningModuleNameForDiagnostic(const Decl *D);
+
+private:
+  using DeclHashes = llvm::SmallVector, 4>;
+
+  // Used with err_module_odr_violation_mismatch_decl and
+  // note_module_odr_violation_mismatch_decl
+  // This list should be the same Decl's as in ODRHash::isDeclToBeProcessed
+  enum ODRMismatchDecl {
+EndOfClass,
+PublicSpecifer,
+PrivateSpecifer,
+ProtectedSpecifer,
+StaticAssert,
+Field,
+CXXMethod,
+TypeAlias,
+TypeDef,
+Var,
+Friend,
+FunctionTemplate,
+Other
+  };
+
+  struct DiffResult {
+const Decl *FirstDecl = nullpt

[clang] [Modules] [HeaderSearch] Don't reenter headers if it is pragma once (PR #76119)

2023-12-23 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

I'll need to test this change on the real code to see the consequences. Sorry, 
I'll be able to do that in January only.

https://github.com/llvm/llvm-project/pull/76119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 017c068 - [ODRHash diagnostics] Move repetetive code at lambda calls into lambdas themselves. NFC.

2022-06-29 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-06-29T13:24:55-07:00
New Revision: 017c068f7899b895e654c8efc1c4d02d940dbf8a

URL: 
https://github.com/llvm/llvm-project/commit/017c068f7899b895e654c8efc1c4d02d940dbf8a
DIFF: 
https://github.com/llvm/llvm-project/commit/017c068f7899b895e654c8efc1c4d02d940dbf8a.diff

LOG: [ODRHash diagnostics] Move repetetive code at lambda calls into lambdas 
themselves. NFC.

It helps to avoid copy-paste mistakes and makes custom code paths more
noticeable.

Not funnelling all diagnostic through `ODRDiagDeclError` because plan to
break down `err_module_odr_violation_mismatch_decl_diff` into smaller
pieces instead of making it bigger and bigger.

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

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 36d7f4186af68..f15e0bcce3318 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9690,34 +9690,29 @@ void ASTReader::diagnoseOdrViolations() {
   // These lambdas have the common portions of the ODR diagnostics.  This
   // has the same return as Diag(), so addition parameters can be passed
   // in with operator<<
-  auto ODRDiagDeclError = [this](NamedDecl *FirstRecord, StringRef FirstModule,
- SourceLocation Loc, SourceRange Range,
- ODRMismatchDeclDifference DiffType) {
-return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_
diff )
-   << FirstRecord << FirstModule.empty() << FirstModule << Range
-   << DiffType;
-  };
-  auto ODRDiagDeclNote = [this](StringRef SecondModule, SourceLocation Loc,
-SourceRange Range, ODRMismatchDeclDifference 
DiffType) {
-return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_
diff )
-   << SecondModule << Range << DiffType;
-  };
-
-  auto ODRDiagField = [this, &ODRDiagDeclError, &ODRDiagDeclNote,
-   &ComputeQualTypeODRHash, &ComputeODRHash](
+  auto ODRDiagField = [this, &ComputeQualTypeODRHash, &ComputeODRHash](
   NamedDecl *FirstRecord, StringRef FirstModule,
   StringRef SecondModule, FieldDecl *FirstField,
   FieldDecl *SecondField) {
+auto DiagError = [FirstRecord, FirstField, FirstModule,
+  this](ODRMismatchDeclDifference DiffType) {
+  return Diag(FirstField->getLocation(),
+  diag::err_module_odr_violation_mismatch_decl_
diff )
+ << FirstRecord << FirstModule.empty() << FirstModule
+ << FirstField->getSourceRange() << DiffType;
+};
+auto DiagNote = [SecondField, SecondModule,
+ this](ODRMismatchDeclDifference DiffType) {
+  return Diag(SecondField->getLocation(),
+  diag::note_module_odr_violation_mismatch_decl_
diff )
+ << SecondModule << SecondField->getSourceRange() << DiffType;
+};
+
 IdentifierInfo *FirstII = FirstField->getIdentifier();
 IdentifierInfo *SecondII = SecondField->getIdentifier();
 if (FirstII->getName() != SecondII->getName()) {
-  ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(),
-   FirstField->getSourceRange(), FieldName)
-  << FirstII;
-  ODRDiagDeclNote(SecondModule, SecondField->getLocation(),
-  SecondField->getSourceRange(), FieldName)
-  << SecondII;
-
+  DiagError(FieldName) << FirstII;
+  DiagNote(FieldName) << SecondII;
   return true;
 }
 
@@ -9728,25 +9723,16 @@ void ASTReader::diagnoseOdrViolations() {
 QualType SecondType = SecondField->getType();
 if (ComputeQualTypeODRHash(FirstType) !=
 ComputeQualTypeODRHash(SecondType)) {
-  ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(),
-   FirstField->getSourceRange(), FieldTypeName)
-  << FirstII << FirstType;
-  ODRDiagDeclNote(SecondModule, SecondField->getLocation(),
-  SecondField->getSourceRange(), FieldTypeName)
-  << SecondII << SecondType;
-
+  DiagError(FieldTypeName) << FirstII << FirstType;
+  DiagNote(FieldTypeName) << SecondII << SecondType;
   return true;
 }
 
 const bool IsFirstBitField = FirstField->isBitField();
 const bool IsSecondBitField = SecondField->isBitField();
 if (IsFirstBitField != IsSecondBitField) {
-  ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(),
-   FirstField->getSourceRange(), FieldSingleBitField)
-  << FirstII << IsFirstBitField;
-  ODRDiagDeclNote(SecondModule, SecondField->getLocation(),
-  SecondField->getSourceRange(), FieldSingleBitField)
- 

[clang] 3514131 - [ODRHash diagnostics] Fix typos. NFC.

2022-06-29 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-06-29T14:59:37-07:00
New Revision: 3514131219ffdc94c0c61c5b585b53e97501fbea

URL: 
https://github.com/llvm/llvm-project/commit/3514131219ffdc94c0c61c5b585b53e97501fbea
DIFF: 
https://github.com/llvm/llvm-project/commit/3514131219ffdc94c0c61c5b585b53e97501fbea.diff

LOG: [ODRHash diagnostics] Fix typos. NFC.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSerializationKinds.td
clang/lib/Serialization/ASTReader.cpp
clang/test/Modules/odr_hash.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index 33eba6cf0c3f2..251242e46fe5d 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -355,7 +355,7 @@ def err_module_odr_violation_enum : Error<
   "enum with specified type %4|"
   "enum with %4 element%s4|"
   "%ordinal4 element has name %5|"
-  "%ordinal4 element %5 %select{has|does not have}6 an initilizer|"
+  "%ordinal4 element %5 %select{has|does not have}6 an initializer|"
   "%ordinal4 element %5 has an initializer|"
   "}3">;
 

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index f15e0bcce3318..6bfd81634f50b 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10636,7 +10636,7 @@ void ASTReader::diagnoseOdrViolations() {
 
 // Compare the hash generated to the hash stored.  A 
diff erence means
 // that a body was present in the original source.  Due to merging,
-// the stardard way of detecting a body will not work.
+// the standard way of detecting a body will not work.
 const bool HasFirstBody =
 ComputeCXXMethodODRHash(FirstMethod) != FirstMethod->getODRHash();
 const bool HasSecondBody =
@@ -11166,8 +11166,8 @@ void ASTReader::diagnoseOdrViolations() {
   DifferentSpecifiedTypes,
   DifferentNumberEnumConstants,
   EnumConstantName,
-  EnumConstantSingleInitilizer,
-  EnumConstantDifferentInitilizer,
+  EnumConstantSingleInitializer,
+  EnumConstantDifferentInitializer,
 };
 
 // If we've already pointed out a specific problem with this enum, don't
@@ -11301,18 +11301,18 @@ void ASTReader::diagnoseOdrViolations() {
   continue;
 
 if (!FirstInit || !SecondInit) {
-  ODRDiagError(FirstEnumConstant, EnumConstantSingleInitilizer)
+  ODRDiagError(FirstEnumConstant, EnumConstantSingleInitializer)
   << I + 1 << FirstEnumConstant << (FirstInit != nullptr);
-  ODRDiagNote(SecondEnumConstant, EnumConstantSingleInitilizer)
+  ODRDiagNote(SecondEnumConstant, EnumConstantSingleInitializer)
   << I + 1 << SecondEnumConstant << (SecondInit != nullptr);
   Diagnosed = true;
   break;
 }
 
 if (ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) {
-  ODRDiagError(FirstEnumConstant, EnumConstantDifferentInitilizer)
+  ODRDiagError(FirstEnumConstant, EnumConstantDifferentInitializer)
   << I + 1 << FirstEnumConstant;
-  ODRDiagNote(SecondEnumConstant, EnumConstantDifferentInitilizer)
+  ODRDiagNote(SecondEnumConstant, EnumConstantDifferentInitializer)
   << I + 1 << SecondEnumConstant;
   Diagnosed = true;
   break;

diff  --git a/clang/test/Modules/odr_hash.cpp b/clang/test/Modules/odr_hash.cpp
index 81899943bc64c..aed08c1a3a044 100644
--- a/clang/test/Modules/odr_hash.cpp
+++ b/clang/test/Modules/odr_hash.cpp
@@ -3300,7 +3300,7 @@ enum E7 { x71 = 0 };
 enum E7 { x71 };
 #else
 E7 e7;
-// expected-error@second.h:* {{'Enums::E7' has 
diff erent definitions in 
diff erent modules; definition in module 'SecondModule' first 
diff erence is 1st element 'x71' has an initilizer}}
+// expected-error@second.h:* {{'Enums::E7' has 
diff erent definitions in 
diff erent modules; definition in module 'SecondModule' first 
diff erence is 1st element 'x71' has an initializer}}
 // expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x71' does 
not have an initializer}}
 #endif
 
@@ -3310,7 +3310,7 @@ enum E8 { x81 };
 enum E8 { x81 = 0 };
 #else
 E8 e8;
-// expected-error@second.h:* {{'Enums::E8' has 
diff erent definitions in 
diff erent modules; definition in module 'SecondModule' first 
diff erence is 1st element 'x81' does not have an initilizer}}
+// expected-error@second.h:* {{'Enums::E8' has 
diff erent definitions in 
diff erent modules; definition in module 'SecondModule' first 
diff erence is 1st element 'x81' does not have an initializer}}
 // expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x81' has 
an initializer}}
 #endif
 



___
cfe-commits maili

[clang] 15cb180 - [ODRHash diagnostics] Split `err_module_odr_violation_mismatch_decl_diff` into per-entity diagnostics. NFC.

2022-06-30 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-06-30T18:40:46-07:00
New Revision: 15cb180dcbf84701f3af47983e223d0beaac3c9b

URL: 
https://github.com/llvm/llvm-project/commit/15cb180dcbf84701f3af47983e223d0beaac3c9b
DIFF: 
https://github.com/llvm/llvm-project/commit/15cb180dcbf84701f3af47983e223d0beaac3c9b.diff

LOG: [ODRHash diagnostics] Split `err_module_odr_violation_mismatch_decl_diff` 
into per-entity diagnostics. NFC.

We'll need to add more cases for Objective-C entities and adding
everything to `err_module_odr_violation_mismatch_decl_diff` makes it
harder to work with over time.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSerializationKinds.td
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index 251242e46fe5..0bd3734a4a04 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -177,20 +177,13 @@ def note_module_odr_violation_mismatch_decl : Note<"but 
in '%0' found "
   "protected access specifier|static assert|field|method|type alias|typedef|"
   "data member|friend declaration|function template}1">;
 
-def err_module_odr_violation_mismatch_decl_
diff  : Error<
+def err_module_odr_violation_record : Error<
   "%q0 has 
diff erent definitions in 
diff erent modules; first 
diff erence is "
   "%select{definition in module '%2'|defined here}1 found "
   "%select{"
   "static assert with condition|"
   "static assert with message|"
   "static assert with %select{|no }4message|"
-  "field %4|"
-  "field %4 with type %5|"
-  "%select{non-|}5bitfield %4|"
-  "bitfield %4 with one width expression|"
-  "%select{non-|}5mutable field %4|"
-  "field %4 with %select{no|an}5 initalizer|"
-  "field %4 with an initializer|"
   "%select{method %5|constructor|destructor}4|"
   "%select{method %5|constructor|destructor}4 "
 "is %select{not deleted|deleted}6|"
@@ -226,13 +219,6 @@ def err_module_odr_violation_mismatch_decl_
diff  : Error<
 "with %select{no body|body}6|"
   "%select{method %5|constructor|destructor}4 "
 "with body|"
-  "%select{typedef|type alias}4 name %5|"
-  "%select{typedef|type alias}4 %5 with underlying type %6|"
-  "data member with name %4|"
-  "data member %4 with type %5|"
-  "data member %4 with%select{out|}5 an initializer|"
-  "data member %4 with an initializer|"
-  "data member %4 %select{is constexpr|is not constexpr}5|"
   "friend %select{class|function}4|"
   "friend %4|"
   "friend function %4|"
@@ -250,18 +236,11 @@ def err_module_odr_violation_mismatch_decl_
diff  : Error<
 "being a template parameter pack|"
   "}3">;
 
-def note_module_odr_violation_mismatch_decl_
diff  : Note<"but in '%0' found "
+def note_module_odr_violation_record : Note<"but in '%0' found "
   "%select{"
   "static assert with 
diff erent condition|"
   "static assert with 
diff erent message|"
   "static assert with %select{|no }2message|"
-  "field %2|"
-  "field %2 with type %3|"
-  "%select{non-|}3bitfield %2|"
-  "bitfield %2 with 
diff erent width expression|"
-  "%select{non-|}3mutable field %2|"
-  "field %2 with %select{no|an}3 initializer|"
-  "field %2 with a 
diff erent initializer|"
   "%select{method %3|constructor|destructor}2|"
   "%select{method %3|constructor|destructor}2 "
 "is %select{not deleted|deleted}4|"
@@ -297,13 +276,6 @@ def note_module_odr_violation_mismatch_decl_
diff  : Note<"but in '%0' found "
 "with %select{no body|body}4|"
   "%select{method %3|constructor|destructor}2 "
 "with 
diff erent body|"
-  "%select{typedef|type alias}2 name %3|"
-  "%select{typedef|type alias}2 %3 with 
diff erent underlying type %4|"
-  "data member with name %2|"
-  "data member %2 with 
diff erent type %3|"
-  "data member %2 with%select{out|}3 an initializer|"
-  "data member %2 with a 
diff erent initializer|"
-  "data member %2 %select{is constexpr|is not constexpr}3|"
   "friend %select{class|function}2|"
   "friend %2|"
   "friend function %2|"
@@ -321,6 +293,61 @@ def note_module_odr_violation_mismatch_decl_
diff  : Note<"but in '%0' found "
 "being a template parameter pack|"
   "}1">;
 
+def err_module_odr_violation_field : Error<
+  "%q0 has 
diff erent definitions in 
diff erent modules; first 
diff erence is "
+  "%select{definition in module '%2'|defined here}1 found "
+  "%select{"
+  "field %4|"
+  "field %4 with type %5|"
+  "%select{non-|}5bitfield %4|"
+  "bitfield %4 with one width expression|"
+  "%select{non-|}5mutable field %4|"
+  "field %4 with %select{no|an}5 initalizer|"
+  "field %4 with an initializer"
+  "}3">;
+def note_module_odr_violation_field : Note<"but in '%0' found "
+  "%select{"
+  "field %2|"
+  "field %2 with type %3|"
+  "%select{non-|}3bitfield %2|"

[clang] 2ceb9c3 - [ODRHash diagnostics] Move common code for calculating diag locations in `DiagnoseODRMismatch` into a lambda. NFC.

2022-06-30 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-06-30T19:39:22-07:00
New Revision: 2ceb9c347f14e81a8c71d644724cefd10fce6eaf

URL: 
https://github.com/llvm/llvm-project/commit/2ceb9c347f14e81a8c71d644724cefd10fce6eaf
DIFF: 
https://github.com/llvm/llvm-project/commit/2ceb9c347f14e81a8c71d644724cefd10fce6eaf.diff

LOG: [ODRHash diagnostics] Move common code for calculating diag locations in 
`DiagnoseODRMismatch` into a lambda. NFC.

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

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 37371eff28ef..d853805bf97e 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10012,34 +10012,35 @@ void ASTReader::diagnoseOdrViolations() {
 }
   };
 
-  auto DiagnoseODRMismatch =
-  [this](DiffResult &DR, NamedDecl *FirstRecord, StringRef FirstModule,
- NamedDecl *SecondRecord, StringRef SecondModule) {
-SourceLocation FirstLoc;
-SourceRange FirstRange;
-auto *FirstTag = dyn_cast(FirstRecord);
-if (DR.FirstDiffType == EndOfClass && FirstTag) {
-  FirstLoc = FirstTag->getBraceRange().getEnd();
-} else {
-  FirstLoc = DR.FirstDecl->getLocation();
-  FirstRange = DR.FirstDecl->getSourceRange();
-}
-Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl)
-<< FirstRecord << FirstModule.empty() << FirstModule << FirstRange
-<< DR.FirstDiffType;
-
-SourceLocation SecondLoc;
-SourceRange SecondRange;
-auto *SecondTag = dyn_cast(SecondRecord);
-if (DR.SecondDiffType == EndOfClass && SecondTag) {
-  SecondLoc = SecondTag->getBraceRange().getEnd();
-} else {
-  SecondLoc = DR.SecondDecl->getLocation();
-  SecondRange = DR.SecondDecl->getSourceRange();
-}
-Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl)
-<< SecondModule << SecondRange << DR.SecondDiffType;
-  };
+  auto DiagnoseODRMismatch = [this](DiffResult &DR, NamedDecl *FirstRecord,
+StringRef FirstModule,
+NamedDecl *SecondRecord,
+StringRef SecondModule) {
+auto GetMismatchedDeclLoc = [](const NamedDecl *Container,
+   ODRMismatchDecl DiffType, const Decl *D) {
+  SourceLocation Loc;
+  SourceRange Range;
+  auto *Tag = dyn_cast(Container);
+  if (DiffType == EndOfClass && Tag) {
+Loc = Tag->getBraceRange().getEnd();
+  } else {
+Loc = D->getLocation();
+Range = D->getSourceRange();
+  }
+  return std::make_pair(Loc, Range);
+};
+
+auto FirstDiagInfo =
+GetMismatchedDeclLoc(FirstRecord, DR.FirstDiffType, DR.FirstDecl);
+Diag(FirstDiagInfo.first, diag::err_module_odr_violation_mismatch_decl)
+<< FirstRecord << FirstModule.empty() << FirstModule
+<< FirstDiagInfo.second << DR.FirstDiffType;
+
+auto SecondDiagInfo =
+GetMismatchedDeclLoc(SecondRecord, DR.SecondDiffType, DR.SecondDecl);
+Diag(SecondDiagInfo.first, diag::note_module_odr_violation_mismatch_decl)
+<< SecondModule << SecondDiagInfo.second << DR.SecondDiffType;
+  };
 
   // Issue any pending ODR-failure diagnostics.
   for (auto &Merge : OdrMergeFailures) {



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


[clang] a621b0a - [clang][NFC] Remove unused parameter in `Sema::ActOnDuplicateDefinition`.

2022-03-28 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-03-28T12:07:28-07:00
New Revision: a621b0af9cd03bce079a2a6f4d72a6471ca1bb85

URL: 
https://github.com/llvm/llvm-project/commit/a621b0af9cd03bce079a2a6f4d72a6471ca1bb85
DIFF: 
https://github.com/llvm/llvm-project/commit/a621b0af9cd03bce079a2a6f4d72a6471ca1bb85.diff

LOG: [clang][NFC] Remove unused parameter in `Sema::ActOnDuplicateDefinition`.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 817df4e108433..53ac1d011d9e1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3254,8 +3254,7 @@ class Sema final {
   /// Perform ODR-like check for C/ObjC when merging tag types from modules.
   /// Differently from C++, actually parse the body and reject / error out
   /// in case of a structural mismatch.
-  bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev,
-SkipBodyInfo &SkipBody);
+  bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody);
 
   typedef void *SkippedDefinitionContext;
 

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index c0fb7e0df1b61..f07758197205f 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4870,7 +4870,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
 Decl *D = SkipBody.CheckSameAsPrevious ? SkipBody.New : TagDecl;
 ParseEnumBody(StartLoc, D);
 if (SkipBody.CheckSameAsPrevious &&
-!Actions.ActOnDuplicateDefinition(DS, TagDecl, SkipBody)) {
+!Actions.ActOnDuplicateDefinition(TagDecl, SkipBody)) {
   DS.SetTypeSpecError();
   return;
 }

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 1bb43f56422d7..342ee896bee18 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2049,8 +2049,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   // Parse the definition body.
   ParseStructUnionBody(StartLoc, TagType, cast(D));
   if (SkipBody.CheckSameAsPrevious &&
-  !Actions.ActOnDuplicateDefinition(DS, TagOrTempResult.get(),
-SkipBody)) {
+  !Actions.ActOnDuplicateDefinition(TagOrTempResult.get(), SkipBody)) {
 DS.SetTypeSpecError();
 return;
   }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4051ab29fb26f..298d4fc17617b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16703,8 +16703,7 @@ void Sema::ActOnTagStartDefinition(Scope *S, Decl 
*TagD) {
   AddPushedVisibilityAttribute(Tag);
 }
 
-bool Sema::ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev,
-SkipBodyInfo &SkipBody) {
+bool Sema::ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody) {
   if (!hasStructuralCompatLayout(Prev, SkipBody.New))
 return false;
 



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


[clang] 29444f0 - [modules] Merge ObjC interface ivars with anonymous types.

2022-04-04 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-04-04T18:48:30-07:00
New Revision: 29444f0444c6d3586969fd6fbe49c8188c02c244

URL: 
https://github.com/llvm/llvm-project/commit/29444f0444c6d3586969fd6fbe49c8188c02c244
DIFF: 
https://github.com/llvm/llvm-project/commit/29444f0444c6d3586969fd6fbe49c8188c02c244.diff

LOG: [modules] Merge ObjC interface ivars with anonymous types.

Without the fix ivars with anonymous types can trigger errors like

> error: 'TestClass::structIvar' from module 'Target' is not present in 
> definition of 'TestClass' provided earlier
> [...]
> note: declaration of 'structIvar' does not match

It happens because types of ivars from different modules are considered
to be different. And it is caused by not merging anonymous `TagDecl`
from different modules.

To fix that I've changed `serialization::needsAnonymousDeclarationNumber`
to handle anonymous `TagDecl` inside `ObjCInterfaceDecl`. But that's not
sufficient as C code inside `ObjCInterfaceDecl` doesn't use interface
decl as a decl context but switches to its parent (TranslationUnit in
most cases).  I'm changing that to make `ObjCContainerDecl` the lexical
decl context but keeping the semantic decl context intact.

Test "check-dup-decls-inside-objc.m" doesn't reflect a change in
functionality but captures the existing behavior to prevent regressions.

rdar://85563013

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

Added: 
clang/test/Modules/merge-anon-record-definition-in-objc.m
clang/test/SemaObjC/check-dup-decls-inside-objc.m

Modified: 
clang/lib/Parse/ParseObjc.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/AST/ast-dump-decl.mm

Removed: 




diff  --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 719513e7bda09..c56fcb8cc3cfe 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -1871,9 +1871,9 @@ void Parser::HelperActionsForIvarDeclarations(Decl 
*interfaceDecl, SourceLocatio
   if (!RBraceMissing)
 T.consumeClose();
 
-  Actions.ActOnObjCContainerStartDefinition(interfaceDecl);
+  assert(getObjCDeclContext() == interfaceDecl &&
+ "Ivars should have interfaceDecl as their decl context");
   Actions.ActOnLastBitfield(T.getCloseLocation(), AllIvarDecls);
-  Actions.ActOnObjCContainerFinishDefinition();
   // Call ActOnFields() even if we don't have any decls. This is useful
   // for code rewriting tools that need to be aware of the empty list.
   Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, AllIvarDecls,
@@ -1908,8 +1908,7 @@ void Parser::ParseObjCClassInstanceVariables(Decl 
*interfaceDecl,
   assert(Tok.is(tok::l_brace) && "expected {");
   SmallVector AllIvarDecls;
 
-  ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope);
-  ObjCDeclContextSwitch ObjCDC(*this);
+  ParseScope ClassScope(this, Scope::DeclScope | Scope::ClassScope);
 
   BalancedDelimiterTracker T(*this, tok::l_brace);
   T.consumeOpen();
@@ -1973,13 +1972,13 @@ void Parser::ParseObjCClassInstanceVariables(Decl 
*interfaceDecl,
 }
 
 auto ObjCIvarCallback = [&](ParsingFieldDeclarator &FD) {
-  Actions.ActOnObjCContainerStartDefinition(interfaceDecl);
+  assert(getObjCDeclContext() == interfaceDecl &&
+ "Ivar should have interfaceDecl as its decl context");
   // Install the declarator into the interface decl.
   FD.D.setObjCIvar(true);
   Decl *Field = Actions.ActOnIvar(
   getCurScope(), FD.D.getDeclSpec().getSourceRange().getBegin(), FD.D,
   FD.BitfieldSize, visibility);
-  Actions.ActOnObjCContainerFinishDefinition();
   if (Field)
 AllIvarDecls.push_back(Field);
   FD.complete(Field);

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1e25346fde6f6..0b5b530bc756c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16059,9 +16059,20 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, 
TagUseKind TUK,
   // with C structs, unions, and enums when looking for a matching
   // tag declaration or definition. See the similar lookup tweak
   // in Sema::LookupName; is there a better way to deal with this?
-  while (isa(SearchDC) || isa(SearchDC))
+  while (isa(SearchDC))
+SearchDC = SearchDC->getParent();
+} else if (getLangOpts().CPlusPlus) {
+  // Inside ObjCContainer want to keep it as a lexical decl context but go
+  // past it (most often to TranslationUnit) to find the semantic decl
+  // context.
+  while (isa(SearchDC))
 SearchDC = SearchDC->getParent();
 }
+  } else if (getLangOpts().CPlusPlus) {
+// Don't use ObjCContainerDecl as the semantic decl context for anonymous
+// TagDecl the same way as we skip it for named TagDecl.
+while (isa(SearchDC))
+  SearchDC = SearchDC->getPa

[clang] 766a08d - [Frontend] Only compile modules if not already finalized

2021-07-15 Thread Volodymyr Sapsai via cfe-commits

Author: Ben Barham
Date: 2021-07-15T18:27:08-07:00
New Revision: 766a08df12c111b15ed51d0fcac06042d2f68cd6

URL: 
https://github.com/llvm/llvm-project/commit/766a08df12c111b15ed51d0fcac06042d2f68cd6
DIFF: 
https://github.com/llvm/llvm-project/commit/766a08df12c111b15ed51d0fcac06042d2f68cd6.diff

LOG: [Frontend] Only compile modules if not already finalized

It was possible to re-add a module to a shared in-memory module cache
when search paths are changed. This can eventually cause a crash if the
original module is referenced after this occurs.
  1. Module A depends on B
  2. B exists in two paths C and D
  3. First run only has C on the search path, finds A and B and loads
 them
  4. Second run adds D to the front of the search path. A is loaded and
 contains a reference to the already compiled module from C. But
 searching finds the module from D instead, causing a mismatch
  5. B and the modules that depend on it are considered out of date and
 thus rebuilt
  6. The recompiled module A is added to the in-memory cache, freeing
 the previously inserted one

This can never occur from a regular clang process, but is very easy to
do through the API - whether through the use of a shared case or just
running multiple compilations from a single `CompilerInstance`. Update
the compilation to return early if a module is already finalized so that
the pre-condition in the in-memory module cache holds.

Resolves rdar://78180255

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

Added: 
clang/unittests/Serialization/ModuleCacheTest.cpp

Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticSerializationKinds.td
clang/include/clang/Serialization/ASTReader.h
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Serialization/ASTReader.cpp
clang/unittests/Serialization/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index eea5d8eaa10a1..4dff3379ed35b 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -111,6 +111,8 @@ def err_module_cycle : Error<"cyclic dependency in module 
'%0': %1">,
   DefaultFatal;
 def err_module_prebuilt : Error<
   "error in loading module '%0' from prebuilt module path">, DefaultFatal;
+def err_module_rebuild_finalized : Error<
+  "cannot rebuild module '%0' as it is already finalized">, DefaultFatal;
 def note_pragma_entered_here : Note<"#pragma entered here">;
 def note_decl_hiding_tag_type : Note<
   "%1 %0 is hidden by a non-type declaration of %0 here">;

diff  --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index ce48833a87030..bf3221be004de 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -69,6 +69,9 @@ def err_module_file_not_module : Error<
   "AST file '%0' was not built as a module">, DefaultFatal;
 def err_module_file_missing_top_level_submodule : Error<
   "module file '%0' is missing its top-level submodule">, DefaultFatal;
+def note_module_file_conflict : Note<
+  "this is generally caused by modules with the same name found in multiple "
+  "paths">;
 
 def remark_module_import : Remark<
   "importing module '%0'%select{| into '%3'}2 from '%1'">,

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 6932d9c86d0cc..4819a5aecefaf 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1401,6 +1401,9 @@ class ASTReader
   llvm::iterator_range
   getModulePreprocessedEntities(ModuleFile &Mod) const;
 
+  bool canRecoverFromOutOfDate(StringRef ModuleFileName,
+   unsigned ClientLoadCapabilities);
+
 public:
   class ModuleDeclIterator
   : public llvm::iterator_adaptor_base<

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index a6e2329c8864a..c642af1849bc4 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1054,6 +1054,15 @@ compileModuleImpl(CompilerInstance &ImportingInstance, 
SourceLocation ImportLoc,
   [](CompilerInstance &) {}) {
   llvm::TimeTraceScope TimeScope("Module Compile", ModuleName);
 
+  // Never compile a module that's already finalized - this would cause the
+  // existing module to be freed, causing crashes if it is later referenced
+  if (ImportingInstance.getModuleCache().isPCMFinal(ModuleFileName)) {
+ImportingInstance.getDiagnostics().Report(
+ImportLoc, diag::err_module_rebuild_finalized)
+<< ModuleName;
+return false;
+  }
+
   // Construct a compiler in

[clang] fa4a0f1 - [modules] Add a flag for TagDecl if it was a definition demoted to a declaration.

2022-02-14 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-02-14T16:04:40-08:00
New Revision: fa4a0f1d31e2f797c3e27eb7cad15755e46a4726

URL: 
https://github.com/llvm/llvm-project/commit/fa4a0f1d31e2f797c3e27eb7cad15755e46a4726
DIFF: 
https://github.com/llvm/llvm-project/commit/fa4a0f1d31e2f797c3e27eb7cad15755e46a4726.diff

LOG: [modules] Add a flag for TagDecl if it was a definition demoted to a 
declaration.

For redeclaration chains we maintain an invariant of having only a
single definition in the chain. In a single translation unit we make
sure not to create duplicates. But modules are separate translation
units and they can contain definitions for the same symbol
independently. When we load such modules together, we need to demote
duplicate definitions to keep the AST invariants.

Some AST clients are interested in distinguishing
declaration-that-was-demoted-from-definition and
declaration-that-was-never-a-definition. For that purpose introducing
`IsThisDeclarationADemotedDefinition`. No functional change intended.

rdar://84677782

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

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/lib/AST/Decl.cpp
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 862e8899d2751..7611bac83419d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3486,6 +3486,24 @@ class TagDecl : public TypeDecl,
   /// parameters.
   bool isDependentType() const { return isDependentContext(); }
 
+  /// Whether this declaration was a definition in some module but was forced
+  /// to be a declaration.
+  ///
+  /// Useful for clients checking if a module has a definition of a specific
+  /// symbol and not interested in the final AST with deduplicated definitions.
+  bool isThisDeclarationADemotedDefinition() const {
+return TagDeclBits.IsThisDeclarationADemotedDefinition;
+  }
+
+  /// Mark a definition as a declaration and maintain information it _was_
+  /// a definition.
+  void demoteThisDefinitionToDeclaration() {
+assert(isCompleteDefinition() &&
+   "Should demote definitions only, not forward declarations");
+setCompleteDefinition(false);
+TagDeclBits.IsThisDeclarationADemotedDefinition = true;
+  }
+
   /// Starts the definition of this tag declaration.
   ///
   /// This method should be invoked at the beginning of the definition

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 06d2f17d14300..a89f776248c1f 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1443,10 +1443,14 @@ class DeclContext {
 /// Has the full definition of this type been required by a use somewhere 
in
 /// the TU.
 uint64_t IsCompleteDefinitionRequired : 1;
+
+/// Whether this tag is a definition which was demoted due to
+/// a module merge.
+uint64_t IsThisDeclarationADemotedDefinition : 1;
   };
 
   /// Number of non-inherited bits in TagDeclBitfields.
-  enum { NumTagDeclBits = 9 };
+  enum { NumTagDeclBits = 10 };
 
   /// Stores the bits used by EnumDecl.
   /// If modified NumEnumDeclBit and the accessor

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 060a6d1ad5ed5..030da7f55fac4 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4301,6 +4301,7 @@ TagDecl::TagDecl(Kind DK, TagKind TK, const ASTContext 
&C, DeclContext *DC,
   setEmbeddedInDeclarator(false);
   setFreeStanding(false);
   setCompleteDefinitionRequired(false);
+  TagDeclBits.IsThisDeclarationADemotedDefinition = false;
 }
 
 SourceLocation TagDecl::getOuterLocStart() const {

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 1ab26e58a4040..25d7e9e6a2e68 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -773,7 +773,7 @@ void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
 }
 if (OldDef) {
   Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
-  ED->setCompleteDefinition(false);
+  ED->demoteThisDefinitionToDeclaration();
   Reader.mergeDefinitionVisibility(OldDef, ED);
   if (OldDef->getODRHash() != ED->getODRHash())
 Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
@@ -828,7 +828,7 @@ void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
 }
 if (OldDef) {
   Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef));
-  RD->setCompleteDefinition(false);
+  RD->demoteThisDefinitionToDeclaration();
   Reader.mergeDefinitionVisibility(OldDef, RD);
 } else {
   OldDef = RD;



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

[clang] 4604db9 - [ASTStructuralEquivalence] Add support for comparing ObjCCategoryDecl.

2022-04-22 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-04-22T16:51:19-07:00
New Revision: 4604db9493ffb22e1f411d907f163bf021193d84

URL: 
https://github.com/llvm/llvm-project/commit/4604db9493ffb22e1f411d907f163bf021193d84
DIFF: 
https://github.com/llvm/llvm-project/commit/4604db9493ffb22e1f411d907f163bf021193d84.diff

LOG: [ASTStructuralEquivalence] Add support for comparing ObjCCategoryDecl.

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

Added: 


Modified: 
clang/include/clang/Testing/CommandLineArgs.h
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/Testing/CommandLineArgs.cpp
clang/unittests/AST/MatchVerifier.h
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 




diff  --git a/clang/include/clang/Testing/CommandLineArgs.h 
b/clang/include/clang/Testing/CommandLineArgs.h
index fe2103a3dce21..e668781ee2ce1 100644
--- a/clang/include/clang/Testing/CommandLineArgs.h
+++ b/clang/include/clang/Testing/CommandLineArgs.h
@@ -29,6 +29,7 @@ enum TestLanguage {
   Lang_CXX17,
   Lang_CXX20,
   Lang_OpenCL,
+  Lang_OBJC,
   Lang_OBJCXX
 };
 

diff  --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 05f3470a179d2..b15036a11ad92 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1242,10 +1242,10 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   return true;
 }
 
-/// Determine structural equivalence of two fields.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
- FieldDecl *Field1, FieldDecl *Field2) {
-  const auto *Owner2 = cast(Field2->getDeclContext());
+ FieldDecl *Field1, FieldDecl *Field2,
+ QualType Owner2Type) {
+  const auto *Owner2 = cast(Field2->getDeclContext());
 
   // For anonymous structs/unions, match up the anonymous struct/union type
   // declarations directly, so that we don't go off searching for anonymous
@@ -1265,7 +1265,7 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   Context.Diag2(
   Owner2->getLocation(),
   Context.getApplicableDiagnostic(diag::err_odr_tag_type_inconsistent))
-  << Context.ToCtx.getTypeDeclType(Owner2);
+  << Owner2Type;
   Context.Diag2(Field2->getLocation(), diag::note_odr_field_name)
   << Field2->getDeclName();
   Context.Diag1(Field1->getLocation(), diag::note_odr_field_name)
@@ -1280,7 +1280,7 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   Context.Diag2(
   Owner2->getLocation(),
   Context.getApplicableDiagnostic(diag::err_odr_tag_type_inconsistent))
-  << Context.ToCtx.getTypeDeclType(Owner2);
+  << Owner2Type;
   Context.Diag2(Field2->getLocation(), diag::note_odr_field)
   << Field2->getDeclName() << Field2->getType();
   Context.Diag1(Field1->getLocation(), diag::note_odr_field)
@@ -1296,6 +1296,14 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   return true;
 }
 
+/// Determine structural equivalence of two fields.
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ FieldDecl *Field1, FieldDecl *Field2) {
+  const auto *Owner2 = cast(Field2->getDeclContext());
+  return IsStructurallyEquivalent(Context, Field1, Field2,
+  Context.ToCtx.getTypeDeclType(Owner2));
+}
+
 /// Determine structural equivalence of two methods.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  CXXMethodDecl *Method1,
@@ -1610,6 +1618,7 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   }
 
   // Check the fields for consistency.
+  QualType D2Type = Context.ToCtx.getTypeDeclType(D2);
   RecordDecl::field_iterator Field2 = D2->field_begin(),
  Field2End = D2->field_end();
   for (RecordDecl::field_iterator Field1 = D1->field_begin(),
@@ -1628,7 +1637,7 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   return false;
 }
 
-if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
+if (!IsStructurallyEquivalent(Context, *Field1, *Field2, D2Type))
   return false;
   }
 
@@ -1934,6 +1943,126 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   return true;
 }
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ ObjCIvarDecl *D1, ObjCIvarDecl *D2,
+ QualType Owner2Type) {
+  if (D1->getAccessControl() != D2->getAccessControl())
+return false;
+
+  return IsStructurallyEquivalent(Context, cast(D

[clang] a7f9f2f - [fixup] Handle enum constant `Lang_OBJC` introduced in 4604db94.

2022-04-22 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-04-22T17:59:17-07:00
New Revision: a7f9f2fea506fa213e4ce9c6230a816cd5bcfa38

URL: 
https://github.com/llvm/llvm-project/commit/a7f9f2fea506fa213e4ce9c6230a816cd5bcfa38
DIFF: 
https://github.com/llvm/llvm-project/commit/a7f9f2fea506fa213e4ce9c6230a816cd5bcfa38.diff

LOG: [fixup] Handle enum constant `Lang_OBJC` introduced in 4604db94.

Added: 


Modified: 
clang/lib/Testing/CommandLineArgs.cpp

Removed: 




diff  --git a/clang/lib/Testing/CommandLineArgs.cpp 
b/clang/lib/Testing/CommandLineArgs.cpp
index c04702f689028..bf517e2dd312e 100644
--- a/clang/lib/Testing/CommandLineArgs.cpp
+++ b/clang/lib/Testing/CommandLineArgs.cpp
@@ -72,6 +72,9 @@ std::vector getCC1ArgsForTesting(TestLanguage 
Lang) {
   case Lang_CXX20:
 Args = {"-std=c++20"};
 break;
+  case Lang_OBJC:
+Args = {"-xobjective-c"};
+break;
   case Lang_OBJCXX:
 Args = {"-xobjective-c++"};
 break;



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


[clang] d32c685 - [modules] Merge equivalent extensions and diagnose ivar redeclarations for extensions loaded from different modules.

2022-04-27 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-04-27T15:52:59-07:00
New Revision: d32c685e1012785c0d2824214740f973d30e1daa

URL: 
https://github.com/llvm/llvm-project/commit/d32c685e1012785c0d2824214740f973d30e1daa
DIFF: 
https://github.com/llvm/llvm-project/commit/d32c685e1012785c0d2824214740f973d30e1daa.diff

LOG: [modules] Merge equivalent extensions and diagnose ivar redeclarations for 
extensions loaded from different modules.

Emitting metadata for the same ivar multiple times can lead to
miscompilations. Objective-C runtime adds offsets to calculate ivar
position in memory and presence of duplicate offsets causes wrong final
position thus overwriting unrelated memory.

Such a situation is impossible with modules disabled as clang diagnoses
ivar redeclarations during sema checks after parsing
(`Sema::ActOnFields`). Fix the case with modules enabled by checking
during deserialization if ivar is already declared. We also support
a use case where the same category ends up in multiple modules. We
don't want to treat this case as ivar redeclaration and instead merge
corresponding ivars.

rdar://83468070

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

Added: 
clang/test/Modules/merge-extension-ivars.m
clang/test/Modules/redecl-ivars.m

Modified: 
clang/include/clang/AST/DeclObjC.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/AST/DeclObjC.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclObjC.h 
b/clang/include/clang/AST/DeclObjC.h
index 110b7dc0c6f2..59a2cf5de234 100644
--- a/clang/include/clang/AST/DeclObjC.h
+++ b/clang/include/clang/AST/DeclObjC.h
@@ -1951,7 +1951,10 @@ class ObjCIvarDecl : public FieldDecl {
   /// in; this is either the interface where the ivar was declared, or the
   /// interface the ivar is conceptually a part of in the case of synthesized
   /// ivars.
-  const ObjCInterfaceDecl *getContainingInterface() const;
+  ObjCInterfaceDecl *getContainingInterface();
+  const ObjCInterfaceDecl *getContainingInterface() const {
+return const_cast(this)->getContainingInterface();
+  }
 
   ObjCIvarDecl *getNextIvar() { return NextIvar; }
   const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
@@ -2885,15 +2888,16 @@ 
ObjCInterfaceDecl::filtered_category_iterator::operator++() {
 }
 
 inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) {
-  return Cat->isUnconditionallyVisible();
+  return !Cat->isInvalidDecl() && Cat->isUnconditionallyVisible();
 }
 
 inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) {
-  return Cat->IsClassExtension() && Cat->isUnconditionallyVisible();
+  return !Cat->isInvalidDecl() && Cat->IsClassExtension() &&
+ Cat->isUnconditionallyVisible();
 }
 
 inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) {
-  return Cat->IsClassExtension();
+  return !Cat->isInvalidDecl() && Cat->IsClassExtension();
 }
 
 } // namespace clang

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index d46a6c4500f4..8e8e40a5cd37 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1106,6 +1106,18 @@ class ASTReader
   /// been completed.
   std::deque PendingDeclContextInfos;
 
+  template 
+  using DuplicateObjCDecls = std::pair;
+
+  /// When resolving duplicate ivars from Objective-C extensions we don't error
+  /// out immediately but check if can merge identical extensions. Not checking
+  /// extensions for equality immediately because ivar deserialization isn't
+  /// over yet at that point.
+  llvm::SmallMapVector,
+   llvm::SmallVector, 4>,
+   2>
+  PendingObjCExtensionIvarRedeclarations;
+
   /// The set of NamedDecls that have been loaded, but are members of a
   /// context that has been merged into another context where the corresponding
   /// declaration is either missing or has not yet been loaded.

diff  --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index f15dd78929e2..15c545b59c81 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -1647,6 +1647,11 @@ ObjCIvarDecl 
*ObjCInterfaceDecl::all_declared_ivar_begin() {
 
   ObjCIvarDecl *curIvar = nullptr;
   if (!data().IvarList) {
+// Force ivar deserialization upfront, before building IvarList.
+(void)ivar_empty();
+for (const auto *Ext : known_extensions()) {
+  (void)Ext->ivar_empty();
+}
 if (!ivar_empty()) {
   ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
   data().IvarList = *I; ++I;
@@ -1838,8 +1843,8 @@ ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext 
&C, unsigned ID) {
   ObjCIvarDecl::None, nullptr, false);
 }
 
-const ObjCInterface

[clang] 3b762b3 - [clang][NFC] In parts of Objective-C Sema use Obj-C-specific types instead of `Decl`.

2022-05-05 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-05-05T19:19:41-07:00
New Revision: 3b762b3ab8d205cd6a7d42c96d39d5f4f701f2ab

URL: 
https://github.com/llvm/llvm-project/commit/3b762b3ab8d205cd6a7d42c96d39d5f4f701f2ab
DIFF: 
https://github.com/llvm/llvm-project/commit/3b762b3ab8d205cd6a7d42c96d39d5f4f701f2ab.diff

LOG: [clang][NFC] In parts of Objective-C Sema use Obj-C-specific types instead 
of `Decl`.

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

Added: 


Modified: 
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseObjc.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclObjC.cpp

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 8f28eb30ad1dc..99fe375f9145f 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -447,7 +447,9 @@ class Parser : public CodeCompletionHandler {
 return Actions.incrementMSManglingNumber();
   }
 
-  Decl  *getObjCDeclContext() const { return Actions.getObjCDeclContext(); }
+  ObjCContainerDecl *getObjCDeclContext() const {
+return Actions.getObjCDeclContext();
+  }
 
   // Type forwarding.  All of these are statically 'void*', but they may all be
   // 
diff erent actual classes based on the actions in place.
@@ -1001,18 +1003,18 @@ class Parser : public CodeCompletionHandler {
   /// back.
   class ObjCDeclContextSwitch {
 Parser &P;
-Decl *DC;
+ObjCContainerDecl *DC;
 SaveAndRestore WithinObjCContainer;
   public:
 explicit ObjCDeclContextSwitch(Parser &p)
   : P(p), DC(p.getObjCDeclContext()),
 WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) {
   if (DC)
-
P.Actions.ActOnObjCTemporaryExitContainerContext(cast(DC));
+P.Actions.ActOnObjCTemporaryExitContainerContext(DC);
 }
 ~ObjCDeclContextSwitch() {
   if (DC)
-P.Actions.ActOnObjCReenterContainerContext(cast(DC));
+P.Actions.ActOnObjCReenterContainerContext(DC);
 }
   };
 
@@ -1614,11 +1616,12 @@ class Parser : public CodeCompletionHandler {
   SmallVectorImpl &protocolIdents,
   SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
 
-  void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation 
atLoc,
+  void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
+SourceLocation atLoc,
 BalancedDelimiterTracker &T,
 SmallVectorImpl &AllIvarDecls,
 bool RBraceMissing);
-  void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
+  void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
tok::ObjCKeywordKind visibility,
SourceLocation atLoc);
   bool ParseObjCProtocolReferences(SmallVectorImpl &P,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 44fbffdda3900..27603f0b891f3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3285,7 +3285,7 @@ class Sema final {
   /// Invoked when we enter a tag definition that we're skipping.
   SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
 
-  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
+  void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl);
 
   /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
   /// C++ record definition's base-specifiers clause and are starting its
@@ -3309,8 +3309,8 @@ class Sema final {
   /// scope for parsing/looking-up C constructs.
   ///
   /// Must be followed by a call to \see ActOnObjCReenterContainerContext
-  void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
-  void ActOnObjCReenterContainerContext(DeclContext *DC);
+  void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx);
+  void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx);
 
   /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
   /// error parsing the definition of a tag.
@@ -9738,7 +9738,7 @@ class Sema final {
 SourceLocation rAngleLoc);
   void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList);
 
-  Decl *ActOnStartClassInterface(
+  ObjCInterfaceDecl *ActOnStartClassInterface(
   Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName,
   SourceLocation ClassLoc, ObjCTypeParamList *typeParamList,
   IdentifierInfo *SuperName, SourceLocation SuperLoc,
@@ -9772,13 +9772,13 @@ class Sema final {
 SourceLocation &PLoc, SourceLocation PrevLoc,
 const ObjCList &PList);
 
-  Decl *ActOnStartProtocolInterface(
+  ObjCProtocolDecl *ActOnStartProtocolInterface(
   SourceLocati

[clang] f693874 - [ODRHash diagnostics] Preparation to minimize subsequent diffs. NFC.

2022-07-19 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-07-19T16:29:33-07:00
New Revision: f693874c53c1b3d3a322de98c1c7557d69157d3d

URL: 
https://github.com/llvm/llvm-project/commit/f693874c53c1b3d3a322de98c1c7557d69157d3d
DIFF: 
https://github.com/llvm/llvm-project/commit/f693874c53c1b3d3a322de98c1c7557d69157d3d.diff

LOG: [ODRHash diagnostics] Preparation to minimize subsequent diffs. NFC.

Specifically, making the following changes:
* Turn lambdas calculating ODR hashes into static functions.
* Move `ODRCXXRecordDifference` where it is used.
* Rename some variables and move some lines of code.
* Replace `auto` with explicit type when the deduced type is not mentioned.
* Add `const` for unmodified objects, so we can pass them to more functions.

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

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 04ade0a3b9d0..76281d26b2ae 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9445,6 +9445,31 @@ void ASTReader::finishPendingActions() {
   PendingMergedDefinitionsToDeduplicate.clear();
 }
 
+static unsigned computeODRHash(QualType Ty) {
+  ODRHash Hasher;
+  Hasher.AddQualType(Ty);
+  return Hasher.CalculateHash();
+}
+
+static unsigned computeODRHash(const Stmt *S) {
+  ODRHash Hasher;
+  Hasher.AddStmt(S);
+  return Hasher.CalculateHash();
+}
+
+static unsigned computeODRHash(const Decl *D) {
+  assert(D);
+  ODRHash Hasher;
+  Hasher.AddSubDecl(D);
+  return Hasher.CalculateHash();
+}
+
+static unsigned computeODRHash(const TemplateArgument &TA) {
+  ODRHash Hasher;
+  Hasher.AddTemplateArgument(TA);
+  return Hasher.CalculateHash();
+}
+
 void ASTReader::diagnoseOdrViolations() {
   if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty() &&
   PendingFunctionOdrMergeFailures.empty() &&
@@ -9584,42 +9609,6 @@ void ASTReader::diagnoseOdrViolations() {
   // we're producing our diagnostics.
   Deserializing RecursionGuard(this);
 
-  // Common code for hashing helpers.
-  ODRHash Hash;
-  auto ComputeQualTypeODRHash = [&Hash](QualType Ty) {
-Hash.clear();
-Hash.AddQualType(Ty);
-return Hash.CalculateHash();
-  };
-
-  auto ComputeODRHash = [&Hash](const Stmt *S) {
-assert(S);
-Hash.clear();
-Hash.AddStmt(S);
-return Hash.CalculateHash();
-  };
-
-  auto ComputeSubDeclODRHash = [&Hash](const Decl *D) {
-assert(D);
-Hash.clear();
-Hash.AddSubDecl(D);
-return Hash.CalculateHash();
-  };
-
-  auto ComputeTemplateArgumentODRHash = [&Hash](const TemplateArgument &TA) {
-Hash.clear();
-Hash.AddTemplateArgument(TA);
-return Hash.CalculateHash();
-  };
-
-  auto ComputeTemplateParameterListODRHash =
-  [&Hash](const TemplateParameterList *TPL) {
-assert(TPL);
-Hash.clear();
-Hash.AddTemplateParameterList(TPL);
-return Hash.CalculateHash();
-  };
-
   // Used with err_module_odr_violation_mismatch_decl and
   // note_module_odr_violation_mismatch_decl
   // This list should be the same Decl's as in ODRHash::isDeclToBeProcessed
@@ -9639,49 +9628,13 @@ void ASTReader::diagnoseOdrViolations() {
 Other
   };
 
-  // Used with err_module_odr_violation_record and
-  // note_module_odr_violation_record
-  enum ODRCXXRecordDifference {
-StaticAssertCondition,
-StaticAssertMessage,
-StaticAssertOnlyMessage,
-MethodName,
-MethodDeleted,
-MethodDefaulted,
-MethodVirtual,
-MethodStatic,
-MethodVolatile,
-MethodConst,
-MethodInline,
-MethodNumberParameters,
-MethodParameterType,
-MethodParameterName,
-MethodParameterSingleDefaultArgument,
-MethodParameterDifferentDefaultArgument,
-MethodNoTemplateArguments,
-MethodDifferentNumberTemplateArguments,
-MethodDifferentTemplateArgument,
-MethodSingleBody,
-MethodDifferentBody,
-FriendTypeFunction,
-FriendType,
-FriendFunction,
-FunctionTemplateDifferentNumberParameters,
-FunctionTemplateParameterDifferentKind,
-FunctionTemplateParameterName,
-FunctionTemplateParameterSingleDefaultArgument,
-FunctionTemplateParameterDifferentDefaultArgument,
-FunctionTemplateParameterDifferentType,
-FunctionTemplatePackParameter,
-  };
-
   // These lambdas have the common portions of the ODR diagnostics.  This
   // has the same return as Diag(), so addition parameters can be passed
   // in with operator<<
-  auto ODRDiagField = [this, &ComputeQualTypeODRHash, &ComputeODRHash](
-  NamedDecl *FirstRecord, StringRef FirstModule,
-  StringRef SecondModule, FieldDecl *FirstField,
-  FieldDecl *SecondField) {
+  auto ODRDiagField = [this](NamedDecl *FirstRecord, StringRef FirstModule,
+

  1   2   3   4   >