Re: [PATCH] D31363: [libc++] Remove cmake glob for source files

2017-10-04 Thread Duncan P. N. Exon Smith via cfe-commits
Thanks correct.

> On Oct 4, 2017, at 18:49, Shoaib Meenai via Phabricator via cfe-commits 
>  wrote:
> 
> smeenai added subscribers: zturner, rjmccall.
> smeenai added a comment.
> 
> @rjmccall, this adds a libc++ build dependency on LLVM's cmake modules. There 
> were some issues when @zturner had added a similar dependency for his work on 
> lit. To confirm, Apple still cares about the use case of building libc++ 
> without having any LLVM cmake modules available (either from source or from 
> an LLVM installation), right?
> 
> 
> https://reviews.llvm.org/D31363
> 
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


Re: [PATCH] D31363: [libc++] Remove cmake glob for source files

2017-10-04 Thread Duncan P. N. Exon Smith via cfe-commits
I haven't looked at the patch.  If this is guarded behind NOT 
LIBCXX_STANDALONE_BUILD checks, then it's probably fine.

> On Oct 4, 2017, at 21:36, Zachary Turner  wrote:
> 
> This doesn’t match up with what beanz said. While I assume Duncan is the 
> final word, can we get some confirmation from beanz that everyone is on the 
> same page?
> 
> (Note that libcxx already uses some of LLVM’s cmake, but it’s behind some NOT 
> LIBCXX_STANDALONE_BUILD checks)
> 
> Assuming the answer remains no, what can we do to make code sharing and reuse 
> easier? There’s clearly a need to reuse certain low level things and not keep 
> reinventing the wheel 
> On Wed, Oct 4, 2017 at 9:22 PM Duncan P. N. Exon Smith  > wrote:
> Thanks correct.
> 
> > On Oct 4, 2017, at 18:49, Shoaib Meenai via Phabricator via cfe-commits 
> > mailto:cfe-commits@lists.llvm.org>> wrote:
> >
> > smeenai added subscribers: zturner, rjmccall.
> > smeenai added a comment.
> >
> > @rjmccall, this adds a libc++ build dependency on LLVM's cmake modules. 
> > There were some issues when @zturner had added a similar dependency for his 
> > work on lit. To confirm, Apple still cares about the use case of building 
> > libc++ without having any LLVM cmake modules available (either from source 
> > or from an LLVM installation), right?
> >
> >
> > https://reviews.llvm.org/D31363 
> >
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org 
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> > 
> 

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


Re: r284060 - Implement MS _BitScan intrinsics

2017-06-07 Thread Duncan P. N. Exon Smith via cfe-commits
[... excuse the necromancy...]

Hi Albert (and Reid and David),

This commit is breaking some uses of -fms-extensions on Apple platforms.  In 
particular, Brian and Erik (CC'ed) build against a version of the Windows SDK 
on Apple platforms.  _BitScanReverse is expected to be 32-bit, matching 
Windows/LLP64, even though long is 64-bit on Darwin/LP64.

One idea we've had for fixing this is to use "int" instead of "long" for these 
intrinsics, either:
- all the time, or
- when in LP64 mode (e.g., Darwin + -fms-extensions).

Any other ideas?

Thanks,
Duncan

> On Oct 12, 2016, at 15:01, Albert Gutowski via cfe-commits 
>  wrote:
> 
> Author: agutowski
> Date: Wed Oct 12 17:01:05 2016
> New Revision: 284060
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=284060&view=rev
> Log:
> Implement MS _BitScan intrinsics
> 
> Summary: _BitScan intrinsics (and some others, for example _Interlocked and 
> _bittest) are supposed to work on both ARM and x86. This is an attempt to 
> isolate them, avoiding repeating their code or writing separate function for 
> each builtin.
> 
> Reviewers: hans, thakis, rnk, majnemer
> 
> Subscribers: RKSimon, cfe-commits, aemerson
> 
> Differential Revision: https://reviews.llvm.org/D25264
> 
> Modified:
>cfe/trunk/include/clang/Basic/BuiltinsARM.def
>cfe/trunk/include/clang/Basic/BuiltinsX86.def
>cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
>cfe/trunk/lib/Basic/Targets.cpp
>cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>cfe/trunk/lib/CodeGen/CodeGenFunction.h
>cfe/trunk/lib/Headers/intrin.h
>cfe/trunk/test/CodeGen/ms-intrinsics.c
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsARM.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsARM.def?rev=284060&r1=284059&r2=284060&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsARM.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsARM.def Wed Oct 12 17:01:05 2016
> @@ -18,6 +18,10 @@
> #   define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
> #endif
> 
> +#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN)
> +#  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
> BUILTIN(ID, TYPE, ATTRS)
> +#endif
> +
> // In libgcc
> BUILTIN(__clear_cache, "vv*v*", "i")
> 
> @@ -129,5 +133,11 @@ LANGBUILTIN(_MoveFromCoprocessor2, "UiIU
> LANGBUILTIN(_MoveToCoprocessor, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)
> LANGBUILTIN(_MoveToCoprocessor2, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)
> 
> +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +
> #undef BUILTIN
> #undef LANGBUILTIN
> +#undef TARGET_HEADER_BUILTIN
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=284060&r1=284059&r2=284060&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Oct 12 17:01:05 2016
> @@ -2028,6 +2028,10 @@ TARGET_BUILTIN(__builtin_ia32_selectpd_5
> TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "", "mwaitx")
> TARGET_BUILTIN(__builtin_ia32_mwaitx, "vUiUiUi", "", "mwaitx")
> 
> +// MSVC
> +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +
> TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> TARGET_HEADER_BUILTIN(_ReadBarrier,  "v", "nh", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> TARGET_HEADER_BUILTIN(_WriteBarrier, "v", "nh", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86_64.def?rev=284060&r1=284059&r2=284060&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86_64.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86_64.def Wed Oct 12 17:01:05 2016
> @@ -22,6 +22,9 @@
> #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
> BUILTIN(ID, TYPE, ATTRS)
> #endif
> 
> +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +
> TARGET_HEADER_BUILTIN(__mulh,  "LLiLLiLLi","nch", "intrin.h", 
> ALL_MS_L

Re: r284060 - Implement MS _BitScan intrinsics

2017-06-12 Thread Duncan P. N. Exon Smith via cfe-commits

> On Jun 12, 2017, at 12:44, Reid Kleckner  wrote:
> 
>> On Wed, Jun 7, 2017 at 7:31 PM, Saleem Abdulrasool  
>> wrote:
>> I'm worried about changing this signature all the time.  I suspect that it 
>> will cause the following to be emitted for valid code:
>> 
>> warning: incompatible pointer types passing 'unsigned long *' to parameter 
>> of type 'unsigned int *' [-Wincompatible-pointer-types]
>> 
>> Switching the signature on LP64 sounds much better to me.
> 
> Right, we have to do this. It needs to be `long` on Windows.

SGTM.  We'll go that way.

> On Jun 8, 2017, at 12:21, Erik Schwiebert  wrote:
> 
> It’s probably also better to not try to infer our weird desired behavior. It 
> should probably be controlled by a specific driver directive, like 
> “-fms-extensions-lp64-intrinsics” or something like that. Using a new 
> directive means that nobody can accidentally get this behavior if they for 
> some reason do want LLP64 behavior with Windows intrinsics.

This seems overly complicated.  Is there a customer that:
- is on LP64,
- is using -fms-extensions,
- is using these intrinsics, and
- wants them to be 64-bit longs instead of 32-bit ints?
Put another way: who would use these intrinsics on LP64 and *not* want to mimic 
LLP64?

If everyone using the intrinsics on LP64 is going to have to specify 
-fms-extensions-lp64-intrinsics, then we should just imply it.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305418 - AST: Add missing break at end of switch

2017-06-14 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Wed Jun 14 16:26:31 2017
New Revision: 305418

URL: http://llvm.org/viewvc/llvm-project?rev=305418&view=rev
Log:
AST: Add missing break at end of switch

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

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=305418&r1=305417&r2=305418&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Jun 14 16:26:31 2017
@@ -8547,6 +8547,7 @@ static QualType DecodeTypeFromStr(const
 HowLong = 2;
 break;
   }
+  break;
 }
   }
 


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


Re: [libcxx] r276238 - Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459

2017-06-15 Thread Duncan P. N. Exon Smith via cfe-commits

> On Jul 20, 2016, at 22:31, Marshall Clow via cfe-commits 
>  wrote:
> 
> Modified: libcxx/trunk/include/string
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=276238&r1=276237&r2=276238&view=diff
> ==
> 
> @@ -435,6 +461,7 @@ basic_string operator "" s( co
> */
> 
> #include <__config>
> +#include 

This breaks the following, valid, C++14 code:

#include 
#include 
using namespace std;
using std::experimental::string_view;
void f() { string_view sv; }

Should  #include  even when we're not in C++17 mode?  Why?

> #include 
> #include 
> #include   // For EOF.

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


Re: [libcxx] r276238 - Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459

2017-06-15 Thread Duncan P. N. Exon Smith via cfe-commits
I just started working on a patch to add #if guards, and the first interesting 
thing I found was the basic_string constructor:

> template 
> template 
> basic_string<_CharT, _Traits, _Allocator>::basic_string(
>  const _Tp& __t, size_type __pos, size_type __n, const 
> allocator_type& __a,
>typename 
> enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 
> void>::type *)
> : __r_(__second_tag(), __a)
> {
>   __self_view __sv = __self_view(__t).substr(__pos, __n);
> __init(__sv.data(), __sv.size());
> #if _LIBCPP_DEBUG_LEVEL >= 2
> __get_db()->__insert_c(this);
> #endif
> }

I suppose the decision was made so that std::string could take advantage of it.

Is it a conforming extension?

> On Jun 15, 2017, at 18:35, Eric Fiselier  wrote:
> 
> It *shouldn't* include , that's a given.
> 
> IIRC, and Marshall would know better, I believe it was untenable to
> maintain a version of  that didn't depend on  after 
> making
> the changes required for C++17.
> 
> However inspecting  now it does seem possible that the entanglement
> is avoidable.Though it's also likely I'm just not seeing the whole picture. 
> 
> /Eric
> 
> On Thu, Jun 15, 2017 at 6:42 PM, Duncan P. N. Exon Smith 
> mailto:dexonsm...@apple.com>> wrote:
> 
> > On Jul 20, 2016, at 22:31, Marshall Clow via cfe-commits 
> > mailto:cfe-commits@lists.llvm.org>> wrote:
> >
> > Modified: libcxx/trunk/include/string
> > URL: 
> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=276238&r1=276237&r2=276238&view=diff
> >  
> > 
> > ==
> >
> > @@ -435,6 +461,7 @@ basic_string operator "" s( co
> > */
> >
> > #include <__config>
> > +#include 
> 
> This breaks the following, valid, C++14 code:
> 
> #include 
> #include 
> using namespace std;
> using std::experimental::string_view;
> void f() { string_view sv; }
> 
> Should  #include  even when we're not in C++17 mode?  
> Why?
> 
> > #include 
> > #include 
> > #include   // For EOF.
> 
> 

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


Re: [libcxx] r276238 - Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459

2017-06-15 Thread Duncan P. N. Exon Smith via cfe-commits
Ah, also the enable_if for same:

> template
> _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
> basic_string(const _Tp& __t, size_type __pos, size_type __n,
>  const allocator_type& __a = allocator_type(),
>  typename 
> enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 
> void>::type* = 0);

(Even if it is a conforming extension, it's fairly user hostile.  Doesn't mean 
it's necessarily wrong, but...)

> On Jun 15, 2017, at 19:38, Duncan P. N. Exon Smith via cfe-commits 
>  wrote:
> 
> I just started working on a patch to add #if guards, and the first 
> interesting thing I found was the basic_string constructor:
> 
>> template 
>> template 
>> basic_string<_CharT, _Traits, _Allocator>::basic_string(
>>  const _Tp& __t, size_type __pos, size_type __n, const 
>> allocator_type& __a,
>>   typename 
>> enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 
>> void>::type *)
>> : __r_(__second_tag(), __a)
>> {
>>  __self_view __sv = __self_view(__t).substr(__pos, __n);
>> __init(__sv.data(), __sv.size());
>> #if _LIBCPP_DEBUG_LEVEL >= 2
>> __get_db()->__insert_c(this);
>> #endif
>> }
> 
> I suppose the decision was made so that std::string could take advantage of 
> it.
> 
> Is it a conforming extension?
> 
>> On Jun 15, 2017, at 18:35, Eric Fiselier > <mailto:e...@efcs.ca>> wrote:
>> 
>> It *shouldn't* include , that's a given.
>> 
>> IIRC, and Marshall would know better, I believe it was untenable to
>> maintain a version of  that didn't depend on  after 
>> making
>> the changes required for C++17.
>> 
>> However inspecting  now it does seem possible that the entanglement
>> is avoidable.Though it's also likely I'm just not seeing the whole picture. 
>> 
>> /Eric
>> 
>> On Thu, Jun 15, 2017 at 6:42 PM, Duncan P. N. Exon Smith 
>> mailto:dexonsm...@apple.com>> wrote:
>> 
>> > On Jul 20, 2016, at 22:31, Marshall Clow via cfe-commits 
>> > mailto:cfe-commits@lists.llvm.org>> wrote:
>> >
>> > Modified: libcxx/trunk/include/string
>> > URL: 
>> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=276238&r1=276237&r2=276238&view=diff
>> >  
>> > <http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=276238&r1=276237&r2=276238&view=diff>
>> > ==
>> >
>> > @@ -435,6 +461,7 @@ basic_string operator "" s( co
>> > */
>> >
>> > #include <__config>
>> > +#include 
>> 
>> This breaks the following, valid, C++14 code:
>> 
>> #include 
>> #include 
>> using namespace std;
>> using std::experimental::string_view;
>> void f() { string_view sv; }
>> 
>> Should  #include  even when we're not in C++17 mode?  
>> Why?
>> 
>> > #include 
>> > #include 
>> > #include   // For EOF.
>> 
>> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


Re: [libcxx] r276238 - Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459

2017-06-15 Thread Duncan P. N. Exon Smith via cfe-commits
On Jun 15, 2017, at 19:42, Eric Fiselier  wrote:On Thu, Jun 15, 2017 at 8:38 PM, Duncan P. N. Exon Smith  wrote:I just started working on a patch to add #if guards, and the first interesting thing I found was the basic_string constructor:template template basic_string<_CharT, _Traits, _Allocator>::basic_string(             const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,			 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)    : __r_(__second_tag(), __a){	__self_view __sv = __self_view(__t).substr(__pos, __n);    __init(__sv.data(), __sv.size());#if _LIBCPP_DEBUG_LEVEL >= 2    __get_db()->__insert_c(this);#endif}That constructor was added in C++17, so removing it along with string_view should be OK.Assuming we don't use it to implement older constructors using a single template. I suppose the decision was made so that std::string could take advantage of it.Is it a conforming extension?No, because it can change the meaning of otherwise well defined code, as you pointed out initially. Let me know if this patch is along the right lines.  If so, I'll finish it up and put it on phab.experimental/filesystem/path.cpp doesn't compile, since experimental/filesystem uses things like operator+=(string, string_view) extensively.  But I'd like an early opinion on the approach before I dig in.In string, the only function that needed to be rewritten was string::compare(size, size, string, size, size).  I'm nervous that filesystem will be a bigger job.

avoid-string-view-in-cxx14.patch
Description: Binary data
 On Jun 15, 2017, at 18:35, Eric Fiselier  wrote:It *shouldn't* include , that's a given.IIRC, and Marshall would know better, I believe it was untenable tomaintain a version of  that didn't depend on  after makingthe changes required for C++17.However inspecting  now it does seem possible that the entanglementis avoidable.Though it's also likely I'm just not seeing the whole picture. /EricOn Thu, Jun 15, 2017 at 6:42 PM, Duncan P. N. Exon Smith wrote:> On Jul 20, 2016, at 22:31, Marshall Clow via cfe-commits  wrote:>> Modified: libcxx/trunk/include/string> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=276238&r1=276237&r2=276238&view=diff> ==>> @@ -435,6 +461,7 @@ basic_string operator "" s( co> */>> #include <__config>> +#include This breaks the following, valid, C++14 code:    #include     #include     using namespace std;    using std::experimental::string_view;    void f() { string_view sv; }Should  #include  even when we're not in C++17 mode?  Why?> #include > #include > #include   // For EOF.___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r276238 - Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459

2017-06-15 Thread Duncan P. N. Exon Smith via cfe-commits
Your suggestion is essentially to replace experimental/string_view with 
something like:

namespace std { inline namespace __1 { namespace experimental {
  template 
  using basic_string_view = _VSTD::basic_string_view;
}}}

That breaks:
1. User compiles 1.cpp with older toolchain.  1.cpp implements 
foo(std::experimental::string_view).
2. User compiles 2.cpp with newer toolchain.  2.cpp calls 
foo(std::experimental::string_view).
3. User links 1.o with 2.o.

I'm not sure if this matters.

> On Jun 15, 2017, at 21:55, Eric Fiselier  wrote:
> 
> I would also want to do serious performance analysis on this patch. Does 
> removing the string_view overloads cause less optimal overloads to be chosen? 
> Perhaps allocating ones?
> That would be really unfortunate, and I'm not sure that's in the best 
> interest of our users at large.

Less optimal compared to what?  C++17 code?

> /Eric
> 
> On Thu, Jun 15, 2017 at 10:51 PM, Duncan P. N. Exon Smith 
> mailto:dexonsm...@apple.com>> wrote:
> 
>> On Jun 15, 2017, at 19:42, Eric Fiselier > > wrote:
>> 
>> 
>> 
>> On Thu, Jun 15, 2017 at 8:38 PM, Duncan P. N. Exon Smith 
>> mailto:dexonsm...@apple.com>> wrote:
>> I just started working on a patch to add #if guards, and the first 
>> interesting thing I found was the basic_string constructor:
>> 
>>> template 
>>> template 
>>> basic_string<_CharT, _Traits, _Allocator>::basic_string(
>>>  const _Tp& __t, size_type __pos, size_type __n, const 
>>> allocator_type& __a,
>>>  typename 
>>> enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 
>>> void>::type *)
>>> : __r_(__second_tag(), __a)
>>> {
>>> __self_view __sv = __self_view(__t).substr(__pos, __n);
>>> __init(__sv.data(), __sv.size());
>>> #if _LIBCPP_DEBUG_LEVEL >= 2
>>> __get_db()->__insert_c(this);
>>> #endif
>>> }
>> 
>> 
>> That constructor was added in C++17, so removing it along with string_view 
>> should be OK.
>> Assuming we don't use it to implement older constructors using a single 
>> template.
>> 
>>  
>> I suppose the decision was made so that std::string could take advantage of 
>> it.
>> 
>> Is it a conforming extension?
>> 
>> No, because it can change the meaning of otherwise well defined code, as you 
>> pointed out initially. 
> 
> Let me know if this patch is along the right lines.  If so, I'll finish it up 
> and put it on phab.
> 
> experimental/filesystem/path.cpp doesn't compile, since 
> experimental/filesystem uses things like operator+=(string, string_view) 
> extensively.  But I'd like an early opinion on the approach before I dig in.
> 
> In string, the only function that needed to be rewritten was 
> string::compare(size, size, string, size, size).  I'm nervous that filesystem 
> will be a bigger job.
> 
> 
> 
>>  
>> 
>>> On Jun 15, 2017, at 18:35, Eric Fiselier >> > wrote:
>>> 
>>> It *shouldn't* include , that's a given.
>>> 
>>> IIRC, and Marshall would know better, I believe it was untenable to
>>> maintain a version of  that didn't depend on  after 
>>> making
>>> the changes required for C++17.
>>> 
>>> However inspecting  now it does seem possible that the entanglement
>>> is avoidable.Though it's also likely I'm just not seeing the whole picture. 
>>> 
>>> /Eric
>>> 
>>> On Thu, Jun 15, 2017 at 6:42 PM, Duncan P. N. Exon Smith 
>>> mailto:dexonsm...@apple.com>>wrote:
>>> 
>>> > On Jul 20, 2016, at 22:31, Marshall Clow via cfe-commits 
>>> > mailto:cfe-commits@lists.llvm.org>> wrote:
>>> >
>>> > Modified: libcxx/trunk/include/string
>>> > URL: 
>>> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=276238&r1=276237&r2=276238&view=diff
>>> >  
>>> > 
>>> > ==
>>> >
>>> > @@ -435,6 +461,7 @@ basic_string operator "" s( co
>>> > */
>>> >
>>> > #include <__config>
>>> > +#include 
>>> 
>>> This breaks the following, valid, C++14 code:
>>> 
>>> #include 
>>> #include 
>>> using namespace std;
>>> using std::experimental::string_view;
>>> void f() { string_view sv; }
>>> 
>>> Should  #include  even when we're not in C++17 mode?  
>>> Why?
>>> 
>>> > #include 
>>> > #include 
>>> > #include   // For EOF.
> 
> 
> 

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


Re: r284060 - Implement MS _BitScan intrinsics

2017-06-16 Thread Duncan P. N. Exon Smith via cfe-commits

> On Jun 16, 2017, at 11:02, Reid Kleckner  wrote:
> 
> We should fix it.

Agreed.

> We just need a new character code in the builtin function prototype encoding. 
> Currently there is no encoding for a portable int32_t that magically becomes 
> "long" on 32-bit Windows. The closest thing we have is 'W', which is used by 
> Neon intrinsics to select between "long" and "long long". It was added in 
> r202004.

Yup, I saw the 'W' as well.  That's the same approach I was using in a patch 
yesterday morning (I picked lowercase L ('l'), but there may be a better 
choice).  Likely Bruno will follow up with a working patch soon (I hit some 
problems with tests and then got tied up).

> On Fri, Jun 16, 2017 at 10:28 AM, Erik Schwiebert  > wrote:
> We (Office developers for Apple platforms at Microsoft) would prefer to have 
> the intrinsics work properly for LP64, as that will generate the most optimal 
> and efficient code. That said, we understand that this may be odd to 
> implement from the compiler's perspective and can work around it if the 
> intrinsics are not supported for ms-extensions+LP64. At the end of the day we 
> need the compiler to clearly adopt one of those two options, and not sit 
> somewhere in the middle as it currently does. We don't turn on any flags 
> other than -fms-extensions; we don’t attempt to define MSC_VER and we do 
> conditionalize code based on __clang__ so the code is aware it is being 
> compiled by clang vs MSVC.
> 
> So I think we'd prefer what Duncan and Apple are offering to do, but if the 
> larger clang community thinks that is a bad idea and wants to explicitly 
> disable the intrinsics, we could live with that.
> 
> Thanks,
> Schwieb
> 
> -Original Message-
> From: Erik Schwiebert
> Sent: Friday, June 16, 2017 8:49 AM
> To: 'Bruno Cardoso Lopes'  >; Brian Kelley  >; Tomasz Kukielka  >
> Cc: dexonsm...@apple.com ; Reid Kleckner 
> mailto:r...@google.com>>; cfe-commits 
> mailto:cfe-commits@lists.llvm.org>>
> Subject: RE: r284060 - Implement MS _BitScan intrinsics
> 
> Adding Brian and Tomasz. I'm pretty sure we have the Windows SDK intrinsics 
> headers. I'm not sure which method we'd prefer, so I'll walk down the hall 
> and ask them. Tomasz is our header maestro (because we play crazy 
> #include_next games so we can use both Windows and macOS SDKs!)
> 
> We'll get back to you ASAP.
> 
> Schwieb
> 
> -Original Message-
> From: Bruno Cardoso Lopes [mailto:bruno.card...@gmail.com 
> ]
> Sent: Thursday, June 15, 2017 4:41 PM
> To: Erik Schwiebert mailto:eri...@microsoft.com>>
> Cc: dexonsm...@apple.com ; Reid Kleckner 
> mailto:r...@google.com>>; cfe-commits 
> mailto:cfe-commits@lists.llvm.org>>
> Subject: Re: r284060 - Implement MS _BitScan intrinsics
> 
> On Tue, Jun 13, 2017 at 8:13 PM, Bruno Cardoso Lopes
> mailto:bruno.card...@gmail.com>> wrote:
> > On Mon, Jun 12, 2017 at 2:01 PM, Erik Schwiebert via cfe-commits
> > mailto:cfe-commits@lists.llvm.org>> wrote:
> >> SGTM too. Regarding Duncan's last question -- I can't think of any such 
> >> customer. :) If you all think the right thing for clang to do is to infer 
> >> LLP64 behavior on LP64 (Darwin) + ms_extensions, then that is fine with me!
> 
> Thinking more about this; what if we mark such builtins as unsupported
> for "LP64 (Darwin) + ms_extensions" and then you provide the
> definitions via intrin.h (we can generate a compiler macro for this
> scenario and conditionalize the include_next as we do for _MSC_VER)?
> Do you use this header at all? Are there any other MS related flags
> that get passed to the compiler?
> 
> > SGTM as well!
> >
> >>
> >> Thanks all!
> >> Schwieb
> >>
> >> -Original Message-
> >> From: dexonsm...@apple.com  
> >> [mailto:dexonsm...@apple.com ]
> >> Sent: Monday, June 12, 2017 1:55 PM
> >> To: Reid Kleckner mailto:r...@google.com>>
> >> Cc: Saleem Abdulrasool  >> >; Albert Gutowski  >> >; David Majnemer  >> >; cfe-commits 
> >> mailto:cfe-commits@lists.llvm.org>>; Erik 
> >> Schwiebert mailto:eri...@microsoft.com>>
> >> Subject: Re: r284060 - Implement MS _BitScan intrinsics
> >>
> >>
> >>> On Jun 12, 2017, at 12:44, Reid Kleckner  >>> > wrote:
> >>>
>  On Wed, Jun 7, 2017 at 7:31 PM, Saleem Abdulrasool 
>  mailto:compn...@compnerd.org>> wrote:
>  I'm worried about changing this signature all the time.  I suspect that 
>  it will cause the following to be emitted for valid code:
> 
>  warning: incompatible pointer types passing 'unsigned long *' to 
>  parameter of type 'unsigned int *' [-Wincompatible-pointer-types]
> 
>  Switching the signa

[libcxx] r305647 - any: Add availability for experimental::bad_any_cast

2017-06-18 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sun Jun 18 09:52:26 2017
New Revision: 305647

URL: http://llvm.org/viewvc/llvm-project?rev=305647&view=rev
Log:
any: Add availability for experimental::bad_any_cast

As a follow up to r302172, add missing availability for bad_any_cast.

rdar://problem/32161524

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/experimental/any
libcxx/trunk/test/std/experimental/any/any.class/any.assign/copy.pass.cpp
libcxx/trunk/test/std/experimental/any/any.class/any.assign/move.pass.cpp
libcxx/trunk/test/std/experimental/any/any.class/any.assign/value.pass.cpp
libcxx/trunk/test/std/experimental/any/any.class/any.cons/copy.pass.cpp
libcxx/trunk/test/std/experimental/any/any.class/any.cons/move.pass.cpp
libcxx/trunk/test/std/experimental/any/any.class/any.cons/value.pass.cpp

libcxx/trunk/test/std/experimental/any/any.class/any.modifiers/clear.pass.cpp
libcxx/trunk/test/std/experimental/any/any.class/any.modifiers/swap.pass.cpp
libcxx/trunk/test/support/experimental_any_helpers.h

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=305647&r1=305646&r2=305647&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Sun Jun 18 09:52:26 2017
@@ -1154,6 +1154,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
   __attribute__((availability(watchos,strict,introduced=3.0)))
 #define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((unavailable))
 #define _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH __attribute__((unavailable))
+#define _LIBCPP_AVAILABILITY_BAD_ANY_CAST __attribute__((unavailable))
 #define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS   
\
   __attribute__((availability(macosx,strict,introduced=10.12)))
\
   __attribute__((availability(ios,strict,introduced=10.0)))
\
@@ -1179,6 +1180,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #define _LIBCPP_AVAILABILITY_SHARED_MUTEX
 #define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
 #define _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH
+#define _LIBCPP_AVAILABILITY_BAD_ANY_CAST
 #define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS
 #define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE
 #define _LIBCPP_AVAILABILITY_FUTURE_ERROR
@@ -1191,9 +1193,12 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #ifdef _LIBCPP_NO_EXCEPTIONS
 #define _LIBCPP_AVAILABILITY_DYNARRAY
 #define _LIBCPP_AVAILABILITY_FUTURE
+#define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
 #else
 #define _LIBCPP_AVAILABILITY_DYNARRAY _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH
 #define _LIBCPP_AVAILABILITY_FUTURE _LIBCPP_AVAILABILITY_FUTURE_ERROR
+#define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
\
+  _LIBCPP_AVAILABILITY_BAD_ANY_CAST
 #endif
 
 // Availability of stream API in the dylib got dropped and re-added.  The

Modified: libcxx/trunk/include/experimental/any
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/any?rev=305647&r1=305646&r2=305647&view=diff
==
--- libcxx/trunk/include/experimental/any (original)
+++ libcxx/trunk/include/experimental/any Sun Jun 18 09:52:26 2017
@@ -89,7 +89,7 @@ inline namespace fundamentals_v1 {
 
 _LIBCPP_BEGIN_NAMESPACE_LFTS
 
-class _LIBCPP_EXCEPTION_ABI bad_any_cast : public bad_cast
+class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : 
public bad_cast
 {
 public:
 virtual const char* what() const _NOEXCEPT;
@@ -98,6 +98,7 @@ public:
 #if _LIBCPP_STD_VER > 11// C++ > 11
 
 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
+_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
 void __throw_bad_any_cast()
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
@@ -506,7 +507,7 @@ void swap(any & __lhs, any & __rhs) _NOE
 }
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
 _ValueType any_cast(any const & __v)
 {
 static_assert(
@@ -522,7 +523,7 @@ _ValueType any_cast(any const & __v)
 }
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
 _ValueType any_cast(any & __v)
 {
 static_assert(
@@ -537,7 +538,7 @@ _ValueType any_cast(any & __v)
 }
 
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
 _ValueType any_cast(any && __v)
 {
 static_assert(

Modified: 
libcxx/trunk/test/std/experimental/any/any.class/any.assign/copy.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/any/any.class/any.assign/copy.pass.cpp?rev=305647&r1=305646&r2=305647&view=diff
==
--- libcxx/trunk/test/std/experimental/any/any.class/any.assign/copy.pass.cpp 
(original)
+++ libcxx/trunk/tes

[libcxx] r305648 - func.wrap.func.con: Fix test comment

2017-06-18 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sun Jun 18 10:34:47 2017
New Revision: 305648

URL: http://llvm.org/viewvc/llvm-project?rev=305648&view=rev
Log:
func.wrap.func.con: Fix test comment

This tests moving `function`, not `const function`.

Modified:

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

Modified: 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp?rev=305648&r1=305647&r2=305648&view=diff
==
--- 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
 Sun Jun 18 10:34:47 2017
@@ -12,7 +12,7 @@
 // class function
 
 // function(const function&  f);
-// function(const function&& f);
+// function(function&& f);
 
 #include 
 #include 


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


[libcxx] r305649 - iostreams: Fix deployment target for streams dylib support

2017-06-18 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sun Jun 18 11:50:23 2017
New Revision: 305649

URL: http://llvm.org/viewvc/llvm-project?rev=305649&view=rev
Log:
iostreams: Fix deployment target for streams dylib support

Fix an off-by-one in r302172, which triggered building local versions of
the iostreams when deploying to `<= macOS 10.9`, when it should have
been `< macOS 10.9`.  10.9 had the dylib support.

This defines `_LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE` less
often, reducing code size for users with deployment targets of exactly
macOS 10.9 or iOS 7.0.

rdar://problem/32233981

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=305649&r1=305648&r2=305649&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Sun Jun 18 11:50:23 2017
@@ -1207,9 +1207,9 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 //availability(ios,introduced=7.0)
 #if defined(_LIBCPP_USE_AVAILABILITY_APPLE) && 
\
 ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&
\
-  __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1090) ||
\
+  __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1090) || 
\
  (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) &&   
\
-  __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ <= 7))
+  __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 7))
 #define _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
 #endif
 


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


Re: [libcxx] r276238 - Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459

2017-06-18 Thread Duncan P. N. Exon Smith via cfe-commits

> On 2017-Jun-16, at 05:58, Duncan Exon Smith  wrote:
> 
> 
> On Jun 15, 2017, at 22:22, Eric Fiselier mailto:e...@efcs.ca>> 
> wrote:
> 
>> 
>> 
>> On Thu, Jun 15, 2017 at 11:00 PM, Duncan P. N. Exon Smith 
>> mailto:dexonsm...@apple.com>> wrote:
>> Your suggestion is essentially to replace experimental/string_view with 
>> something like:
>> 
>> namespace std { inline namespace __1 { namespace experimental {
>>   template 
>>   using basic_string_view = _VSTD::basic_string_view;
>> }}}
>> 
>> That breaks:
>> 1. User compiles 1.cpp with older toolchain.  1.cpp implements 
>> foo(std::experimental::string_view).
>> 2. User compiles 2.cpp with newer toolchain.  2.cpp calls 
>> foo(std::experimental::string_view).
>> 3. User links 1.o with 2.o.
>> 
>> I'm not sure if this matters.
>> 
>> It can't matter.  are allowed to break both their API and 
>> ABI as needed.
>> 
>> Also I was suggesting 
>> 
>>namespace std { namespace experimental {
>>  using std::basic_string_view;
>>  using std::string_view;
>>   }}
>>  
>> This approach will break code that expects experimental::string_view and 
>> std::string_view are different types:
>> Example:
>> 
>>   void foo(std::string_view);
>>   void foo(std::experimental::string_view);
>>   foo(std::string_view{}); // ambiguous

FTR, it also breaks code that relies on string_view::clear(), which disappeared.

>>> On Jun 15, 2017, at 21:55, Eric Fiselier >> > wrote:
>>> 
>>> I would also want to do serious performance analysis on this patch. Does 
>>> removing the string_view overloads cause less optimal overloads to be 
>>> chosen? Perhaps allocating ones?
>>> That would be really unfortunate, and I'm not sure that's in the best 
>>> interest of our users at large.
>> 
>> Less optimal compared to what?  C++17 code?
>> 
>> Not sure yet, I'm trying to figure out what types the `const Tp&` overloads
>> are attempting to soak up. Is it only string_view? 
> 
> The type trait restricts it to things convertible to string_view that are not 
> const char *.

I had a bit of a look at experimental/filesystem, and it relies pretty heavily 
on the string/string_view conversions.  I still feel like this approach might 
be "the right one", but perhaps it's not worth it.

>>> /Eric
>>> 
>>> On Thu, Jun 15, 2017 at 10:51 PM, Duncan P. N. Exon Smith 
>>> mailto:dexonsm...@apple.com>> wrote:
>>> 
 On Jun 15, 2017, at 19:42, Eric Fiselier >>> > wrote:
 
 
 
 On Thu, Jun 15, 2017 at 8:38 PM, Duncan P. N. Exon Smith 
 mailto:dexonsm...@apple.com>> wrote:
 I just started working on a patch to add #if guards, and the first 
 interesting thing I found was the basic_string constructor:
 
> template 
> template 
> basic_string<_CharT, _Traits, _Allocator>::basic_string(
>  const _Tp& __t, size_type __pos, size_type __n, const 
> allocator_type& __a,
>typename 
> enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 
> void>::type *)
> : __r_(__second_tag(), __a)
> {
>   __self_view __sv = __self_view(__t).substr(__pos, __n);
> __init(__sv.data(), __sv.size());
> #if _LIBCPP_DEBUG_LEVEL >= 2
> __get_db()->__insert_c(this);
> #endif
> }
 
 
 That constructor was added in C++17, so removing it along with string_view 
 should be OK.
 Assuming we don't use it to implement older constructors using a single 
 template.
 
  
 I suppose the decision was made so that std::string could take advantage 
 of it.
 
 Is it a conforming extension?
 
 No, because it can change the meaning of otherwise well defined code, as 
 you pointed out initially. 
>>> 
>>> Let me know if this patch is along the right lines.  If so, I'll finish it 
>>> up and put it on phab.
>>> 
>>> experimental/filesystem/path.cpp doesn't compile, since 
>>> experimental/filesystem uses things like operator+=(string, string_view) 
>>> extensively.  But I'd like an early opinion on the approach before I dig in.
>>> 
>>> In string, the only function that needed to be rewritten was 
>>> string::compare(size, size, string, size, size).  I'm nervous that 
>>> filesystem will be a bigger job.
>>> 
>>> 
>>> 
  
 
> On Jun 15, 2017, at 18:35, Eric Fiselier  > wrote:
> 
> It *shouldn't* include , that's a given.
> 
> IIRC, and Marshall would know better, I believe it was untenable to
> maintain a version of  that didn't depend on  after 
> making
> the changes required for C++17.
> 
> However inspecting  now it does seem possible that the 
> entanglement
> is avoidable.Though it's also likely I'm just not seeing the whole 
> picture. 
> 
> /Eric
> 
> On Thu, Jun 15, 2017 at 6:42 PM, Duncan P. N. Exon Smith 
> mailto:dexonsm...@apple.com>>wrote:
> 
> > 

Re: [libcxx] r276238 - Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459

2017-06-18 Thread Duncan P. N. Exon Smith via cfe-commits

> On 2017-Jun-18, at 10:46, Duncan P. N. Exon Smith  
> wrote:
> 
>> 
>> On 2017-Jun-16, at 05:58, Duncan Exon Smith > > wrote:
>> 
>> 
>> On Jun 15, 2017, at 22:22, Eric Fiselier > > wrote:
>> 
>>> 
>>> 
>>> On Thu, Jun 15, 2017 at 11:00 PM, Duncan P. N. Exon Smith 
>>> mailto:dexonsm...@apple.com>> wrote:
>>> Your suggestion is essentially to replace experimental/string_view with 
>>> something like:
>>> 
>>> namespace std { inline namespace __1 { namespace experimental {
>>>   template 
>>>   using basic_string_view = _VSTD::basic_string_view;
>>> }}}
>>> 
>>> That breaks:
>>> 1. User compiles 1.cpp with older toolchain.  1.cpp implements 
>>> foo(std::experimental::string_view).
>>> 2. User compiles 2.cpp with newer toolchain.  2.cpp calls 
>>> foo(std::experimental::string_view).
>>> 3. User links 1.o with 2.o.
>>> 
>>> I'm not sure if this matters.
>>> 
>>> It can't matter.  are allowed to break both their API and 
>>> ABI as needed.
>>> 
>>> Also I was suggesting 
>>> 
>>>namespace std { namespace experimental {
>>>  using std::basic_string_view;
>>>  using std::string_view;
>>>   }}
>>>  
>>> This approach will break code that expects experimental::string_view and 
>>> std::string_view are different types:
>>> Example:
>>> 
>>>   void foo(std::string_view);
>>>   void foo(std::experimental::string_view);
>>>   foo(std::string_view{}); // ambiguous
> 
> FTR, it also breaks code that relies on string_view::clear(), which 
> disappeared.

More importantly, it breaks code that relies on string_view::to_string().  This 
one matters, since a "true" std::experimental::string_view wouldn't have the 
implicit conversions.

> 
 On Jun 15, 2017, at 21:55, Eric Fiselier >>> > wrote:
 
 I would also want to do serious performance analysis on this patch. Does 
 removing the string_view overloads cause less optimal overloads to be 
 chosen? Perhaps allocating ones?
 That would be really unfortunate, and I'm not sure that's in the best 
 interest of our users at large.
>>> 
>>> Less optimal compared to what?  C++17 code?
>>> 
>>> Not sure yet, I'm trying to figure out what types the `const Tp&` overloads
>>> are attempting to soak up. Is it only string_view? 
>> 
>> The type trait restricts it to things convertible to string_view that are 
>> not const char *.
> 
> I had a bit of a look at experimental/filesystem, and it relies pretty 
> heavily on the string/string_view conversions.  I still feel like this 
> approach might be "the right one", but perhaps it's not worth it.
> 
 /Eric
 
 On Thu, Jun 15, 2017 at 10:51 PM, Duncan P. N. Exon Smith 
 mailto:dexonsm...@apple.com>> wrote:
 
> On Jun 15, 2017, at 19:42, Eric Fiselier  > wrote:
> 
> 
> 
> On Thu, Jun 15, 2017 at 8:38 PM, Duncan P. N. Exon Smith 
> mailto:dexonsm...@apple.com>> wrote:
> I just started working on a patch to add #if guards, and the first 
> interesting thing I found was the basic_string constructor:
> 
>> template 
>> template 
>> basic_string<_CharT, _Traits, _Allocator>::basic_string(
>>  const _Tp& __t, size_type __pos, size_type __n, const 
>> allocator_type& __a,
>>   typename 
>> enable_if<__can_be_converted_to_string_view<_CharT, _Traits, 
>> _Tp>::value, void>::type *)
>> : __r_(__second_tag(), __a)
>> {
>>  __self_view __sv = __self_view(__t).substr(__pos, __n);
>> __init(__sv.data(), __sv.size());
>> #if _LIBCPP_DEBUG_LEVEL >= 2
>> __get_db()->__insert_c(this);
>> #endif
>> }
> 
> 
> That constructor was added in C++17, so removing it along with 
> string_view should be OK.
> Assuming we don't use it to implement older constructors using a single 
> template.
> 
>  
> I suppose the decision was made so that std::string could take advantage 
> of it.
> 
> Is it a conforming extension?
> 
> No, because it can change the meaning of otherwise well defined code, as 
> you pointed out initially. 
 
 Let me know if this patch is along the right lines.  If so, I'll finish it 
 up and put it on phab.
 
 experimental/filesystem/path.cpp doesn't compile, since 
 experimental/filesystem uses things like operator+=(string, string_view) 
 extensively.  But I'd like an early opinion on the approach before I dig 
 in.
 
 In string, the only function that needed to be rewritten was 
 string::compare(size, size, string, size, size).  I'm nervous that 
 filesystem will be a bigger job.
 
 
 
>  
> 
>> On Jun 15, 2017, at 18:35, Eric Fiselier > > wrote:
>> 
>> It *shouldn't* include , that's a given.
>> 
>> IIRC, and Marshall would know better, I believe it was untenable to

[libcxx] r305661 - path: Use string_view_t consistently

2017-06-18 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sun Jun 18 23:27:41 2017
New Revision: 305661

URL: http://llvm.org/viewvc/llvm-project?rev=305661&view=rev
Log:
path: Use string_view_t consistently

Most of filesystem/path.cpp uses string_view_t. This fixes the two spots
that use string_view directly.

https://reviews.llvm.org/D34332

Modified:
libcxx/trunk/src/experimental/filesystem/path.cpp

Modified: libcxx/trunk/src/experimental/filesystem/path.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/path.cpp?rev=305661&r1=305660&r2=305661&view=diff
==
--- libcxx/trunk/src/experimental/filesystem/path.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/path.cpp Sun Jun 18 23:27:41 2017
@@ -261,7 +261,8 @@ private:
 string_view_pair separate_filename(string_view_t const & s) {
 if (s == "." || s == ".." || s.empty()) return string_view_pair{s, ""};
 auto pos = s.find_last_of('.');
-if (pos == string_view_t::npos) return string_view_pair{s, string_view{}};
+if (pos == string_view_t::npos)
+return string_view_pair{s, string_view_t{}};
 return string_view_pair{s.substr(0, pos), s.substr(pos)};
 }
 
@@ -396,7 +397,7 @@ int path::__compare(string_view_t __s) c
 size_t hash_value(const path& __p) noexcept {
   auto PP = PathParser::CreateBegin(__p.native());
   size_t hash_value = 0;
-  std::hash hasher;
+  std::hash hasher;
   while (PP) {
 hash_value = __hash_combine(hash_value, hasher(*PP));
 ++PP;


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


Re: r305719 - [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods

2017-06-20 Thread Duncan P. N. Exon Smith via cfe-commits

> On Jun 19, 2017, at 10:53, Alex Lorenz via cfe-commits 
>  wrote:
> 
> Author: arphaman
> Date: Mon Jun 19 12:53:21 2017
> New Revision: 305719
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=305719&view=rev
> Log:
> [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods
> 
> This change avoid a crash that occurred when skipping to EOF while parsing an
> ObjC interface/implementation.
> 
> rdar://31963299
> 
> Differential Revision: https://reviews.llvm.org/D34185
> 
> Added:
>cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
>cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> Modified:
>cfe/trunk/lib/Parse/ParseObjc.cpp
> 
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=305719&r1=305718&r2=305719&view=diff
> ==
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jun 19 12:53:21 2017
> @@ -3627,6 +3627,14 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   SourceLocation OrigLoc = Tok.getLocation();
> 
>   assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
> +  // Store an artificial EOF token to ensure that we don't run off the end of
> +  // the method's body when we come to parse it.
> +  Token Eof;
> +  Eof.startToken();
> +  Eof.setKind(tok::eof);
> +  Eof.setEofData(MCDecl);
> +  Eof.setLocation(OrigLoc);
> +  LM.Toks.push_back(Eof);
>   // Append the current token at the end of the new token stream so that it
>   // doesn't get lost.
>   LM.Toks.push_back(Tok);
> @@ -3658,7 +3666,7 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   Actions.ActOnDefaultCtorInitializers(MCDecl);
> ParseFunctionStatementBody(MCDecl, BodyScope);
>   }
> -  
> +
>   if (Tok.getLocation() != OrigLoc) {
> // Due to parsing error, we either went over the cached tokens or
> // there are still cached tokens left. If it's the latter case skip the
> @@ -3670,4 +3678,6 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
> ConsumeAnyToken();
>   }
> +  // Clean up the remaining EOF token.
> +  ConsumeAnyToken();
> }
> 
> Added: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305719&view=auto
> ==
> --- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Mon Jun 19 
> 12:53:21 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@implementation ClassC // expected-error {{missing '@end'}} // 
> expected-error {{expected '}'}} // expected-warning {{cannot find interface 
> declaration for 'ClassC'}}

I believe you can split these expectations over multiple lines.  Something like 
this seems more readable:

@implementation ClassC \
  // expected-error {{missing '@end'}} \
  // expected-error {{expected '}'}}   \
  // expected-warning {{cannot find interface declaration for 'ClassC'}}

> +
> +@end
> 
> Added: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305719&view=auto
> ==
> --- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Mon Jun 19 12:53:21 
> 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@interface ClassC // expected-error {{missing '@end'}} // expected-error 
> {{expected '}'}}

Same recommendation as above.

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

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


r355294 - Modules: Document that ReadASTCore exits its final loop via `return`, NFC

2019-03-03 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sun Mar  3 12:17:53 2019
New Revision: 355294

URL: http://llvm.org/viewvc/llvm-project?rev=355294&view=rev
Log:
Modules: Document that ReadASTCore exits its final loop via `return`, NFC

The final loop never breaks.  Document that by following it with
llvm_unreachable.

Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=355294&r1=355293&r2=355294&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun Mar  3 12:17:53 2019
@@ -4257,7 +4257,7 @@ ASTReader::ReadASTCore(StringRef FileNam
 }
   }
 
-  return Success;
+  llvm_unreachable("unexpected break; expected return");
 }
 
 ASTReader::ASTReadResult


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


r355477 - Modules: Add -Rmodule-import

2019-03-05 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Tue Mar  5 18:50:46 2019
New Revision: 355477

URL: http://llvm.org/viewvc/llvm-project?rev=355477&view=rev
Log:
Modules: Add -Rmodule-import

Add a remark for importing modules.  Depending on whether this is a
direct import (into the TU being built by this compiler instance) or
transitive import (into an already-imported module), the diagnostic has
two forms:

importing module 'Foo' from 'path/to/Foo.pcm'
importing module 'Foo' into 'Bar' from 'path/to/Foo.pcm'

Also drop a redundant FileCheck invocation in Rmodule-build.m that was
using -Reverything, since the notes from -Rmodule-import were confusing
it.

https://reviews.llvm.org/D58891

Added:
cfe/trunk/test/Modules/Inputs/Rmodule-import/
cfe/trunk/test/Modules/Inputs/Rmodule-import/A.h
cfe/trunk/test/Modules/Inputs/Rmodule-import/B.h
cfe/trunk/test/Modules/Inputs/Rmodule-import/C.h
cfe/trunk/test/Modules/Inputs/Rmodule-import/D.h
cfe/trunk/test/Modules/Inputs/Rmodule-import/module.modulemap
cfe/trunk/test/Modules/Rmodule-import.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Modules/Rmodule-build.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=355477&r1=355476&r2=355477&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Mar  5 18:50:46 2019
@@ -351,6 +351,7 @@ def MismatchedReturnTypes : DiagGroup<"m
 def MismatchedTags : DiagGroup<"mismatched-tags">;
 def MissingFieldInitializers : DiagGroup<"missing-field-initializers">;
 def ModuleBuild : DiagGroup<"module-build">;
+def ModuleImport : DiagGroup<"module-import">;
 def ModuleConflict : DiagGroup<"module-conflict">;
 def ModuleFileExtension : DiagGroup<"module-file-extension">;
 def NewlineEOF : DiagGroup<"newline-eof">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=355477&r1=355476&r2=355477&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Tue Mar  5 
18:50:46 2019
@@ -72,6 +72,10 @@ def note_module_file_imported_by : Note<
 def err_module_file_not_module : Error<
   "AST file '%0' was not built as a module">, DefaultFatal;
 
+def remark_module_import : Remark<
+  "importing module '%0'%select{| into '%3'}2 from '%1'">,
+  InGroup;
+
 def err_imported_module_not_found : Error<
 "module '%0' in AST file '%1' (imported by AST file '%2') "
 "is not defined in any loaded module map file; "

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=355477&r1=355476&r2=355477&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Mar  5 18:50:46 2019
@@ -2610,6 +2610,9 @@ ASTReader::ReadControlBlock(ModuleFile &
 
 case MODULE_NAME:
   F.ModuleName = Blob;
+  Diag(diag::remark_module_import)
+  << F.ModuleName << F.FileName << (ImportedBy ? true : false)
+  << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef());
   if (Listener)
 Listener->ReadModuleName(F.ModuleName);
 
@@ -4141,6 +4144,9 @@ ASTReader::ReadASTCore(StringRef FileNam
 
   switch (AddResult) {
   case ModuleManager::AlreadyLoaded:
+Diag(diag::remark_module_import)
+<< M->ModuleName << M->FileName << (ImportedBy ? true : false)
+<< (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef());
 return Success;
 
   case ModuleManager::NewlyLoaded:

Added: cfe/trunk/test/Modules/Inputs/Rmodule-import/A.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/Rmodule-import/A.h?rev=355477&view=auto
==
--- cfe/trunk/test/Modules/Inputs/Rmodule-import/A.h (added)
+++ cfe/trunk/test/Modules/Inputs/Rmodule-import/A.h Tue Mar  5 18:50:46 2019
@@ -0,0 +1,2 @@
+// A
+#include "B.h"

Added: cfe/trunk/test/Modules/Inputs/Rmodule-import/B.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/Rmodule-import/B.h?rev=355477&view=auto
==
--- cfe/trunk/test/Modules/Inputs/Rmodule-import/B.h (added)
+++ cfe/trunk/test/Modules/Inputs/Rmodule-import/B.h Tue Mar  5 18:50:46 2019
@@ -0,0 +1,2 

r355482 - Fix slashes in path references in -Rmodule-import test from r355477

2019-03-05 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Tue Mar  5 21:42:56 2019
New Revision: 355482

URL: http://llvm.org/viewvc/llvm-project?rev=355482&view=rev
Log:
Fix slashes in path references in -Rmodule-import test from r355477

Fixup for r355477 to fix the Windows bot:
  
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/16217

Modified:
cfe/trunk/test/Modules/Rmodule-import.m

Modified: cfe/trunk/test/Modules/Rmodule-import.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Rmodule-import.m?rev=355482&r1=355481&r2=355482&view=diff
==
--- cfe/trunk/test/Modules/Rmodule-import.m (original)
+++ cfe/trunk/test/Modules/Rmodule-import.m Tue Mar  5 21:42:56 2019
@@ -14,33 +14,33 @@
 // RUN: FileCheck %s -implicit-check-not "remark:"
 
 #include "A.h" // \
-   expected-remark-re{{building module 'A' as '{{.*}}/A.pcm'}} \
+   expected-remark-re{{building module 'A' as '{{.*[/\\]}}A.pcm'}} \
expected-remark{{finished building module 'A'}} \
-   expected-remark-re{{importing module 'A' from '{{.*}}/A.pcm'}} \
-   expected-remark-re{{importing module 'B' into 'A' from '{{.*}}/B.pcm'}} \
-   expected-remark-re{{importing module 'C' into 'B' from '{{.*}}/C.pcm'}}
+   expected-remark-re{{importing module 'A' from '{{.*[/\\]}}A.pcm'}} \
+   expected-remark-re{{importing module 'B' into 'A' from '{{.*[/\\]}}B.pcm'}} 
\
+   expected-remark-re{{importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'}}
 // CHECK: remark: building module 'A'
 // CHECK: remark: building module 'B'
 // CHECK: remark: building module 'C'
 // CHECK: remark: finished building module 'C'
-// CHECK: remark: importing module 'C' from '{{.*}}/C.pcm'
+// CHECK: remark: importing module 'C' from '{{.*[/\\]}}C.pcm'
 // CHECK: remark: finished building module 'B'
-// CHECK: remark: importing module 'B' from '{{.*}}/B.pcm'
-// CHECK: remark: importing module 'C' into 'B' from '{{.*}}/C.pcm'
+// CHECK: remark: importing module 'B' from '{{.*[/\\]}}B.pcm'
+// CHECK: remark: importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'
 // CHECK: remark: finished building module 'A'
-// CHECK: remark: importing module 'A' from '{{.*}}/A.pcm'
-// CHECK: remark: importing module 'B' into 'A' from '{{.*}}/B.pcm'
-// CHECK: remark: importing module 'C' into 'B' from '{{.*}}/C.pcm'
+// CHECK: remark: importing module 'A' from '{{.*[/\\]}}A.pcm'
+// CHECK: remark: importing module 'B' into 'A' from '{{.*[/\\]}}B.pcm'
+// CHECK: remark: importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'
 #include "B.h" // \
-   expected-remark-re{{importing module 'B' from '{{.*}}/B.pcm'}}
-// CHECK: remark: importing module 'B' from '{{.*}}/B.pcm'
+   expected-remark-re{{importing module 'B' from '{{.*[/\\]}}B.pcm'}}
+// CHECK: remark: importing module 'B' from '{{.*[/\\]}}B.pcm'
 #include "C.h" // \
-   expected-remark-re{{importing module 'C' from '{{.*}}/C.pcm'}}
-// CHECK: remark: importing module 'C' from '{{.*}}/C.pcm'
+   expected-remark-re{{importing module 'C' from '{{.*[/\\]}}C.pcm'}}
+// CHECK: remark: importing module 'C' from '{{.*[/\\]}}C.pcm'
 @import D; // \
-   expected-remark-re{{building module 'D' as '{{.*}}/D.pcm'}} \
+   expected-remark-re{{building module 'D' as '{{.*[/\\]}}D.pcm'}} \
expected-remark{{finished building module 'D'}} \
-   expected-remark-re{{importing module 'D' from '{{.*}}/D.pcm'}}
+   expected-remark-re{{importing module 'D' from '{{.*[/\\]}}D.pcm'}}
 // CHECK: remark: building module 'D'
 // CHECK: remark: finished building module 'D'
-// CHECK: remark: importing module 'D' from '{{.*}}/D.pcm'
+// CHECK: remark: importing module 'D' from '{{.*[/\\]}}D.pcm'


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


r355777 - Modules: Rename MemoryBufferCache to InMemoryModuleCache

2019-03-09 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Mar  9 09:33:56 2019
New Revision: 355777

URL: http://llvm.org/viewvc/llvm-project?rev=355777&view=rev
Log:
Modules: Rename MemoryBufferCache to InMemoryModuleCache

Change MemoryBufferCache to InMemoryModuleCache, moving it from Basic to
Serialization.  Another patch will start using it to manage module build
more explicitly, but this is split out because it's mostly mechanical.

Because of the move to Serialization we can no longer abuse the
Preprocessor to forward it to the ASTReader.  Besides the rename and
file move, that means Preprocessor::Preprocessor has one fewer parameter
and ASTReader::ASTReader has one more.

Added:
cfe/trunk/include/clang/Serialization/InMemoryModuleCache.h
cfe/trunk/lib/Serialization/InMemoryModuleCache.cpp
cfe/trunk/unittests/Serialization/
cfe/trunk/unittests/Serialization/CMakeLists.txt
cfe/trunk/unittests/Serialization/InMemoryModuleCacheTest.cpp
Removed:
cfe/trunk/include/clang/Basic/MemoryBufferCache.h
cfe/trunk/lib/Basic/MemoryBufferCache.cpp
cfe/trunk/unittests/Basic/MemoryBufferCacheTest.cpp
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/include/clang/Serialization/ModuleManager.h
cfe/trunk/lib/Basic/CMakeLists.txt
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/CMakeLists.txt
cfe/trunk/lib/Serialization/GeneratePCH.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp
cfe/trunk/test/Modules/outofdate-rebuild.m
cfe/trunk/unittests/Basic/CMakeLists.txt
cfe/trunk/unittests/Basic/SourceManagerTest.cpp
cfe/trunk/unittests/CMakeLists.txt
cfe/trunk/unittests/Lex/HeaderSearchTest.cpp
cfe/trunk/unittests/Lex/LexerTest.cpp
cfe/trunk/unittests/Lex/PPCallbacksTest.cpp
cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp

Removed: cfe/trunk/include/clang/Basic/MemoryBufferCache.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/MemoryBufferCache.h?rev=355776&view=auto
==
--- cfe/trunk/include/clang/Basic/MemoryBufferCache.h (original)
+++ cfe/trunk/include/clang/Basic/MemoryBufferCache.h (removed)
@@ -1,79 +0,0 @@
-//===- MemoryBufferCache.h - Cache for loaded memory buffers *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H
-#define LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H
-
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
-#include "llvm/ADT/StringMap.h"
-#include 
-
-namespace llvm {
-class MemoryBuffer;
-} // end namespace llvm
-
-namespace clang {
-
-/// Manage memory buffers across multiple users.
-///
-/// Ensures that multiple users have a consistent view of each buffer.  This is
-/// used by \a CompilerInstance when building PCMs to ensure that each \a
-/// ModuleManager sees the same files.
-///
-/// \a finalizeCurrentBuffers() should be called before creating a new user.
-/// This locks in the current buffers, ensuring that no buffer that has already
-/// been accessed can be purged, preventing use-after-frees.
-class MemoryBufferCache : public llvm::RefCountedBase {
-  struct BufferEntry {
-std::unique_ptr Buffer;
-
-/// Track the timeline of when this was added to the cache.
-unsigned Index;
-  };
-
-  /// Cache of buffers.
-  llvm::StringMap Buffers;
-
-  /// Monotonically increasing index.
-  unsigned NextIndex = 0;
-
-  /// Bumped to prevent "older" buffers from being removed.
-  unsigned FirstRemovableIndex = 0;
-
-public:
-  /// Store the Buffer under the Filename.
-  ///
-  /// \pre There is not already buffer is not already in the cache.
-  /// \return a reference to the buffer as a convenience.
-  llvm::MemoryBuffer &addBuffer(llvm::StringRef Filename,
-std::unique_ptr Buffer);
-
-  /// Try to remove a buffer from the cache.
-  ///
-  /// \return false on success, iff \c !isBufferFinal().
-  bool tryToRemoveBuffer(llvm::StringRef Filename);
-
-  /// Get a pointer to the buffer if it exists; else nullptr.
-  llvm::MemoryBuffer *looku

r355778 - Modules: Invalidate out-of-date PCMs as they're discovered

2019-03-09 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Mar  9 09:44:01 2019
New Revision: 355778

URL: http://llvm.org/viewvc/llvm-project?rev=355778&view=rev
Log:
Modules: Invalidate out-of-date PCMs as they're discovered

Leverage the InMemoryModuleCache to invalidate a module the first time
it fails to import (and to lock a module as soon as it's built or
imported successfully).  For implicit module builds, this optimizes
importing deep graphs where the leaf module is out-of-date; see example
near the end of the commit message.

Previously the cache finalized ("locked in") all modules imported so far
when starting a new module build.  This was sufficient to prevent
loading two versions of the same module, but was somewhat arbitrary and
hard to reason about.

Now the cache explicitly tracks module state, where each module must be
one of:

- Unknown: module not in the cache (yet).
- Tentative: module in the cache, but not yet fully imported.
- ToBuild: module found on disk could not be imported; need to build.
- Final: module in the cache has been successfully built or imported.

Preventing repeated failed imports avoids variation in builds based on
shifting filesystem state.  Now it's guaranteed that a module is loaded
from disk exactly once.  It now seems safe to remove
FileManager::invalidateCache, but I'm leaving that for a later commit.

The new, precise logic uncovered a pre-existing problem in the cache:
the map key is the module filename, and different contexts use different
filenames for the same PCM file.  (In particular, the test
Modules/relative-import-path.c does not build without this commit.
r223577 started using a relative path to describe a module's base
directory when importing it within another module.  As a result, the
module cache sees an absolute path when (a) building the module or
importing it at the top-level, and a relative path when (b) importing
the module underneath another one.)

The "obvious" fix is to resolve paths using FileManager::getVirtualFile
and change the map key for the cache to a FileEntry, but some contexts
(particularly related to ASTUnit) have a shorter lifetime for their
FileManager than the InMemoryModuleCache.  This is worth pursuing
further in a later commit; perhaps by tying together the FileManager and
InMemoryModuleCache lifetime, or moving the in-memory PCM storage into a
VFS layer.

For now, use the PCM's base directory as-written for constructing the
filename to check the ModuleCache.

Example
===

To understand the build optimization, first consider the build of a
module graph TU -> A -> B -> C -> D with an empty cache:

TU builds A'
   A' builds B'
  B' builds C'
 C' builds D'
imports D'
  B' imports C'
 imports D'
   A' imports B'
  imports C'
  imports D'
TU imports A'
   imports B'
   imports C'
   imports D'

If we build TU again, where A, B, C, and D are in the cache and D is
out-of-date, we would previously get this build:

TU imports A
   imports B
   imports C
   imports D (out-of-date)
TU builds A'
   A' imports B
  imports C
  imports D (out-of-date)
  builds B'
  B' imports C
 imports D (out-of-date)
 builds C'
 C' imports D (out-of-date)
builds D'
imports D'
  B' imports C'
 imports D'
   A' imports B'
  imports C'
  imports D'
 TU imports A'
imports B'
imports C'
imports D'

After this commit, we'll immediateley invalidate A, B, C, and D when we
first observe that D is out-of-date, giving this build:

TU imports A
   imports B
   imports C
   imports D (out-of-date)
TU builds A' // The same graph as an empty cache.
   A' builds B'
  B' builds C'
 C' builds D'
imports D'
  B' imports C'
 imports D'
   A' imports B'
  imports C'
  imports D'
TU imports A'
   imports B'
   imports C'
   imports D'

The new build matches what we'd naively expect, pretty closely matching
the original build with the empty cache.

rdar://problem/48545366

Added:
cfe/trunk/test/Modules/Inputs/implicit-invalidate-chain/
cfe/trunk/test/Modules/Inputs/implicit-invalidate-chain/A.h
cfe/trunk/test/Modules/Inputs/implicit-invalidate-chain/B.h
cfe/trunk/test/Modules/Inputs/implicit-invalidate-chain/C.h
cfe/trunk/test/Modules/Inputs/implicit-invalidate-chain/module.modulemap
cfe/trunk/test/Modules/Inputs/relative-import-path/
cfe/trunk/test/Modules/Inputs/relative-import-path/A.h
cfe/trunk/test/Modules/Inputs/relative-import-path/B.h
cfe/trunk/test/Modules/Inputs/relative-import-path/C.h
cfe/trunk/test/Modules/Inputs/relative-import-path/module.modulemap
cfe/trunk/test/Modules/implicit-invalidate-chain.c
cfe/trunk/test/Modules/relative-import-

r355779 - Fix slashes in path references in -Rmodule-import test from r355778

2019-03-09 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Mar  9 11:33:32 2019
New Revision: 355779

URL: http://llvm.org/viewvc/llvm-project?rev=355779&view=rev
Log:
Fix slashes in path references in -Rmodule-import test from r355778

Fixup for r355778 to fix all the Windows bots.  Apparently I already
forgot the lesson from r355482 :/.

Modified:
cfe/trunk/test/Modules/implicit-invalidate-chain.c
cfe/trunk/test/Modules/relative-import-path.c

Modified: cfe/trunk/test/Modules/implicit-invalidate-chain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/implicit-invalidate-chain.c?rev=355779&r1=355778&r2=355779&view=diff
==
--- cfe/trunk/test/Modules/implicit-invalidate-chain.c (original)
+++ cfe/trunk/test/Modules/implicit-invalidate-chain.c Sat Mar  9 11:33:32 2019
@@ -33,35 +33,35 @@
 // RUN: FileCheck %s -implicit-check-not "remark:"
 
 #include "A.h" // \
-   expected-remark-re{{importing module 'A' from '{{.*}}/A.pcm'}} \
-   expected-remark-re{{importing module 'B' into 'A' from '{{.*}}/B.pcm'}} \
-   expected-remark-re{{importing module 'C' into 'B' from '{{.*}}/C.pcm'}} \
-   expected-remark-re{{importing module 'D' into 'C' from '{{.*}}/D.pcm'}} \
-   expected-remark-re{{building module 'A' as '{{.*}}/A.pcm'}} \
+   expected-remark-re{{importing module 'A' from '{{.*[/\\]}}A.pcm'}} \
+   expected-remark-re{{importing module 'B' into 'A' from '{{.*[/\\]}}B.pcm'}} 
\
+   expected-remark-re{{importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'}} 
\
+   expected-remark-re{{importing module 'D' into 'C' from '{{.*[/\\]}}D.pcm'}} 
\
+   expected-remark-re{{building module 'A' as '{{.*[/\\]}}A.pcm'}} \
expected-remark{{finished building module 'A'}} \
-   expected-remark-re{{importing module 'A' from '{{.*}}/A.pcm'}} \
-   expected-remark-re{{importing module 'B' into 'A' from '{{.*}}/B.pcm'}} \
-   expected-remark-re{{importing module 'C' into 'B' from '{{.*}}/C.pcm'}} \
-   expected-remark-re{{importing module 'D' into 'C' from '{{.*}}/D.pcm'}}
-// CHECK: remark: importing module 'A' from '{{.*}}/A.pcm'
-// CHECK: remark: importing module 'B' into 'A' from '{{.*}}/B.pcm'
-// CHECK: remark: importing module 'C' into 'B' from '{{.*}}/C.pcm'
-// CHECK: remark: importing module 'D' into 'C' from '{{.*}}/D.pcm'
+   expected-remark-re{{importing module 'A' from '{{.*[/\\]}}A.pcm'}} \
+   expected-remark-re{{importing module 'B' into 'A' from '{{.*[/\\]}}B.pcm'}} 
\
+   expected-remark-re{{importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'}} 
\
+   expected-remark-re{{importing module 'D' into 'C' from '{{.*[/\\]}}D.pcm'}}
+// CHECK: remark: importing module 'A' from '{{.*[/\\]}}A.pcm'
+// CHECK: remark: importing module 'B' into 'A' from '{{.*[/\\]}}B.pcm'
+// CHECK: remark: importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'
+// CHECK: remark: importing module 'D' into 'C' from '{{.*[/\\]}}D.pcm'
 // CHECK: remark: building module 'A'
 // CHECK: remark: building module 'B'
 // CHECK: remark: building module 'C'
 // CHECK: remark: building module 'D'
 // CHECK: remark: finished building module 'D'
-// CHECK: remark: importing module 'D' from '{{.*}}/D.pcm'
+// CHECK: remark: importing module 'D' from '{{.*[/\\]}}D.pcm'
 // CHECK: remark: finished building module 'C'
-// CHECK: remark: importing module 'C' from '{{.*}}/C.pcm'
-// CHECK: remark: importing module 'D' into 'C' from '{{.*}}/D.pcm'
+// CHECK: remark: importing module 'C' from '{{.*[/\\]}}C.pcm'
+// CHECK: remark: importing module 'D' into 'C' from '{{.*[/\\]}}D.pcm'
 // CHECK: remark: finished building module 'B'
-// CHECK: remark: importing module 'B' from '{{.*}}/B.pcm'
-// CHECK: remark: importing module 'C' into 'B' from '{{.*}}/C.pcm'
-// CHECK: remark: importing module 'D' into 'C' from '{{.*}}/D.pcm'
+// CHECK: remark: importing module 'B' from '{{.*[/\\]}}B.pcm'
+// CHECK: remark: importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'
+// CHECK: remark: importing module 'D' into 'C' from '{{.*[/\\]}}D.pcm'
 // CHECK: remark: finished building module 'A'
-// CHECK: remark: importing module 'A' from '{{.*}}/A.pcm'
-// CHECK: remark: importing module 'B' into 'A' from '{{.*}}/B.pcm'
-// CHECK: remark: importing module 'C' into 'B' from '{{.*}}/C.pcm'
-// CHECK: remark: importing module 'D' into 'C' from '{{.*}}/D.pcm'
+// CHECK: remark: importing module 'A' from '{{.*[/\\]}}A.pcm'
+// CHECK: remark: importing module 'B' into 'A' from '{{.*[/\\]}}B.pcm'
+// CHECK: remark: importing module 'C' into 'B' from '{{.*[/\\]}}C.pcm'
+// CHECK: remark: importing module 'D' into 'C' from '{{.*[/\\]}}D.pcm'

Modified: cfe/trunk/test/Modules/relative-import-path.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/relative-import-path.c?rev=355779&r1=355778&r2=355779&view=diff
==
--- cfe/trunk/test/Modules/relative-import-path.c (original)
+++ cfe/trunk/test/Modules/relative-import-path.c

r355780 - Stop relying on allocator behaviour in modules unit test

2019-03-09 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Mar  9 12:15:01 2019
New Revision: 355780

URL: http://llvm.org/viewvc/llvm-project?rev=355780&view=rev
Log:
Stop relying on allocator behaviour in modules unit test

Another fixup for r355778 for Windows bots, this time to stop
accidentally relying on allocator behaviour for the test to pass.

Modified:
cfe/trunk/unittests/Serialization/InMemoryModuleCacheTest.cpp

Modified: cfe/trunk/unittests/Serialization/InMemoryModuleCacheTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Serialization/InMemoryModuleCacheTest.cpp?rev=355780&r1=355779&r2=355780&view=diff
==
--- cfe/trunk/unittests/Serialization/InMemoryModuleCacheTest.cpp (original)
+++ cfe/trunk/unittests/Serialization/InMemoryModuleCacheTest.cpp Sat Mar  9 
12:15:01 2019
@@ -71,12 +71,15 @@ TEST(InMemoryModuleCacheTest, addBuiltPC
 }
 
 TEST(InMemoryModuleCacheTest, tryToDropPCM) {
-  auto B = getBuffer(1);
-  auto *RawB = B.get();
+  auto B1 = getBuffer(1);
+  auto B2 = getBuffer(2);
+  auto *RawB1 = B1.get();
+  auto *RawB2 = B2.get();
+  ASSERT_NE(RawB1, RawB2);
 
   InMemoryModuleCache Cache;
   EXPECT_EQ(InMemoryModuleCache::Unknown, Cache.getPCMState("B"));
-  EXPECT_EQ(RawB, &Cache.addPCM("B", std::move(B)));
+  EXPECT_EQ(RawB1, &Cache.addPCM("B", std::move(B1)));
   EXPECT_FALSE(Cache.tryToDropPCM("B"));
   EXPECT_EQ(nullptr, Cache.lookupPCM("B"));
   EXPECT_EQ(InMemoryModuleCache::ToBuild, Cache.getPCMState("B"));
@@ -90,17 +93,13 @@ TEST(InMemoryModuleCacheTest, tryToDropP
   EXPECT_DEATH(Cache.finalizePCM("B"), "Trying to finalize a dropped PCM");
 #endif
 
-  B = getBuffer(2);
-  ASSERT_NE(RawB, B.get());
-  RawB = B.get();
-
   // Add a new one.
-  EXPECT_EQ(RawB, &Cache.addBuiltPCM("B", std::move(B)));
+  EXPECT_EQ(RawB2, &Cache.addBuiltPCM("B", std::move(B2)));
   EXPECT_TRUE(Cache.isPCMFinal("B"));
 
   // Can try to drop again, but this should error and do nothing.
   EXPECT_TRUE(Cache.tryToDropPCM("B"));
-  EXPECT_EQ(RawB, Cache.lookupPCM("B"));
+  EXPECT_EQ(RawB2, Cache.lookupPCM("B"));
 }
 
 TEST(InMemoryModuleCacheTest, finalizePCM) {


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


r355950 - Modules: Add LangOptions::CacheGeneratedPCH

2019-03-12 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Tue Mar 12 11:38:04 2019
New Revision: 355950

URL: http://llvm.org/viewvc/llvm-project?rev=355950&view=rev
Log:
Modules: Add LangOptions::CacheGeneratedPCH

Add an option to cache the generated PCH in the ModuleCache when
emitting it.  This protects clients that build PCHs and read them in the
same process, allowing them to avoid race conditions between parallel
jobs the same way that Clang's implicit module build system does.

rdar://problem/48740787

Modified:
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GeneratePCH.cpp
cfe/trunk/unittests/Frontend/FrontendActionTest.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=355950&r1=355949&r2=355950&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Tue Mar 12 11:38:04 2019
@@ -154,6 +154,7 @@ BENIGN_ENUM_LANGOPT(CompilingModule, Com
 "compiling a module interface")
 BENIGN_LANGOPT(CompilingPCH, 1, 0, "building a pch")
 BENIGN_LANGOPT(BuildingPCHWithObjectFile, 1, 0, "building a pch which has a 
corresponding object file")
+BENIGN_LANGOPT(CacheGeneratedPCH, 1, 0, "cache generated PCH files in memory")
 COMPATIBLE_LANGOPT(ModulesDeclUse, 1, 0, "require declaration of module 
uses")
 BENIGN_LANGOPT(ModulesSearchAll  , 1, 1, "searching even non-imported modules 
to find unresolved references")
 COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "requiring declaration of 
module uses and all headers to be in modules")

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=355950&r1=355949&r2=355950&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Tue Mar 12 11:38:04 2019
@@ -570,7 +570,8 @@ public:
   /// the module but currently is merely a random 32-bit number.
   ASTFileSignature WriteAST(Sema &SemaRef, const std::string &OutputFile,
 Module *WritingModule, StringRef isysroot,
-bool hasErrors = false);
+bool hasErrors = false,
+bool ShouldCacheASTInMemory = false);
 
   /// Emit a token.
   void AddToken(const Token &Tok, RecordDataImpl &Record);
@@ -974,6 +975,7 @@ class PCHGenerator : public SemaConsumer
   llvm::BitstreamWriter Stream;
   ASTWriter Writer;
   bool AllowASTWithErrors;
+  bool ShouldCacheASTInMemory;
 
 protected:
   ASTWriter &getWriter() { return Writer; }
@@ -985,7 +987,8 @@ public:
StringRef OutputFile, StringRef isysroot,
std::shared_ptr Buffer,
ArrayRef> Extensions,
-   bool AllowASTWithErrors = false, bool IncludeTimestamps = true);
+   bool AllowASTWithErrors = false, bool IncludeTimestamps = true,
+   bool ShouldCacheASTInMemory = false);
   ~PCHGenerator() override;
 
   void InitializeSema(Sema &S) override { SemaPtr = &S; }

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=355950&r1=355949&r2=355950&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Tue Mar 12 11:38:04 2019
@@ -112,7 +112,7 @@ GeneratePCHAction::CreateASTConsumer(Com
   CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
   FrontendOpts.ModuleFileExtensions,
   CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
-  FrontendOpts.IncludeTimestamps));
+  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, InFile, OutputFile, std::move(OS), Buffer));
 
@@ -176,6 +176,8 @@ GenerateModuleAction::CreateASTConsumer(
   CI.getFrontendOpts().ModuleFileExtensions,
   /*AllowASTWithErrors=*/false,
   /*IncludeTimestamps=*/
+  +CI.getFrontendOpts().BuildingImplicitModule,
+  /*ShouldCacheASTInMemory=*/
   +CI.getFrontendOpts().BuildingImplicitModule));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, InFile, OutputFile, std::move(OS), Buffer));

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=355950&r1=355949&r2=355950&vi

[clang-tools-extra] r357037 - Frontend: Remove CompilerInstance::VirtualFileSystem, NFC

2019-03-26 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Tue Mar 26 15:18:52 2019
New Revision: 357037

URL: http://llvm.org/viewvc/llvm-project?rev=357037&view=rev
Log:
Frontend: Remove CompilerInstance::VirtualFileSystem, NFC

Remove CompilerInstance::VirtualFileSystem and
CompilerInstance::setVirtualFileSystem, instead relying on the VFS in
the FileManager.  CompilerInstance and its clients already went to some
trouble to make these match.  Now they are guaranteed to match.

As part of this, I added a VFS parameter (defaults to nullptr) to
CompilerInstance::createFileManager, to avoid repeating construction
logic in clients that just wanted to customize the VFS.

https://reviews.llvm.org/D59377

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

Modified: clang-tools-extra/trunk/clangd/Compiler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Compiler.cpp?rev=357037&r1=357036&r2=357037&view=diff
==
--- clang-tools-extra/trunk/clangd/Compiler.cpp (original)
+++ clang-tools-extra/trunk/clangd/Compiler.cpp Tue Mar 26 15:18:52 2019
@@ -95,7 +95,7 @@ prepareCompilerInstance(std::unique_ptr<
   if (auto VFSWithRemapping = createVFSFromCompilerInvocation(
   Clang->getInvocation(), Clang->getDiagnostics(), VFS))
 VFS = VFSWithRemapping;
-  Clang->setVirtualFileSystem(VFS);
+  Clang->createFileManager(VFS);
 
   Clang->setTarget(TargetInfo::CreateTargetInfo(
   Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));


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


r357037 - Frontend: Remove CompilerInstance::VirtualFileSystem, NFC

2019-03-26 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Tue Mar 26 15:18:52 2019
New Revision: 357037

URL: http://llvm.org/viewvc/llvm-project?rev=357037&view=rev
Log:
Frontend: Remove CompilerInstance::VirtualFileSystem, NFC

Remove CompilerInstance::VirtualFileSystem and
CompilerInstance::setVirtualFileSystem, instead relying on the VFS in
the FileManager.  CompilerInstance and its clients already went to some
trouble to make these match.  Now they are guaranteed to match.

As part of this, I added a VFS parameter (defaults to nullptr) to
CompilerInstance::createFileManager, to avoid repeating construction
logic in clients that just wanted to customize the VFS.

https://reviews.llvm.org/D59377

Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=357037&r1=357036&r2=357037&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Tue Mar 26 15:18:52 2019
@@ -175,6 +175,10 @@ class FileManager : public RefCountedBas
   void fillRealPathName(FileEntry *UFE, llvm::StringRef FileName);
 
 public:
+  /// Construct a file manager, optionally with a custom VFS.
+  ///
+  /// \param FS if non-null, the VFS to use.  Otherwise uses
+  /// llvm::vfs::getRealFileSystem().
   FileManager(const FileSystemOptions &FileSystemOpts,
   IntrusiveRefCntPtr FS = nullptr);
   ~FileManager();

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=357037&r1=357036&r2=357037&view=diff
==
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Tue Mar 26 15:18:52 2019
@@ -82,9 +82,6 @@ class CompilerInstance : public ModuleLo
   /// Auxiliary Target info.
   IntrusiveRefCntPtr AuxTarget;
 
-  /// The virtual file system.
-  IntrusiveRefCntPtr VirtualFileSystem;
-
   /// The file manager.
   IntrusiveRefCntPtr FileMgr;
 
@@ -382,20 +379,8 @@ public:
   /// @name Virtual File System
   /// {
 
-  bool hasVirtualFileSystem() const { return VirtualFileSystem != nullptr; }
-
   llvm::vfs::FileSystem &getVirtualFileSystem() const {
-assert(hasVirtualFileSystem() &&
-   "Compiler instance has no virtual file system");
-return *VirtualFileSystem;
-  }
-
-  /// Replace the current virtual file system.
-  ///
-  /// \note Most clients should use setFileManager, which will implicitly reset
-  /// the virtual file system to the one contained in the file manager.
-  void setVirtualFileSystem(IntrusiveRefCntPtr FS) {
-VirtualFileSystem = std::move(FS);
+return *getFileManager().getVirtualFileSystem();
   }
 
   /// }
@@ -645,7 +630,8 @@ public:
   /// Create the file manager and replace any existing one with it.
   ///
   /// \return The new file manager on success, or null on failure.
-  FileManager *createFileManager();
+  FileManager *
+  createFileManager(IntrusiveRefCntPtr VFS = nullptr);
 
   /// Create the source manager and replace any existing one with it.
   void createSourceManager(FileManager &FileMgr);

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=357037&r1=357036&r2=357037&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Mar 26 15:18:52 2019
@@ -1078,28 +1078,29 @@ bool ASTUnit::Parse(std::shared_ptrgetVirtualFileSystem() &&
+   "VFS passed to Parse and VFS in FileMgr are different");
+
   auto CCInvocation = std::make_shared(*Invocation);
   if (OverrideMainBuffer) {
 assert(Preamble &&
"No preamble was built, but OverrideMainBuffer is not null");
-IntrusiveRefCntPtr OldVFS = VFS;
 Preamble->AddImplicitPreamble(*CCInvocation, VFS, 
OverrideMainBuffer.get());
-if (OldVFS != VFS && FileMgr) {
-  assert(OldVFS == FileMgr->getVirtualFileSystem() &&
- "VFS passed to Parse and VFS in FileMgr are different");
-  FileMgr = new FileManager(FileMgr->getFileSystemOpts(), VFS);
-}
+// VFS may have changed...
   }
 
   // Create the compiler instance to use for building the AST.
   std::unique_ptr Clang(
   new CompilerInstance(std::move(PCHContainerOps)));
-  if (FileMgr && VFS) {
-assert(VFS == FileMgr->getVirtualFileSystem() &&
-   "VFS passed to Parse and VFS in FileMgr are different");
-  } else if (VFS) {
-Clang

[clang-tools-extra] r357038 - Basic: Return a reference from FileManager::getVirtualFileSystem, NFC

2019-03-26 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Tue Mar 26 15:32:06 2019
New Revision: 357038

URL: http://llvm.org/viewvc/llvm-project?rev=357038&view=rev
Log:
Basic: Return a reference from FileManager::getVirtualFileSystem, NFC

FileManager constructs a VFS in its constructor if it isn't passed one,
and there's no way to reset it.  Make that contract clear by returning a
reference from its accessor.

https://reviews.llvm.org/D59388

Modified:
clang-tools-extra/trunk/clang-move/Move.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clangd/SourceCode.cpp

Modified: clang-tools-extra/trunk/clang-move/Move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/Move.cpp?rev=357038&r1=357037&r2=357038&view=diff
==
--- clang-tools-extra/trunk/clang-move/Move.cpp (original)
+++ clang-tools-extra/trunk/clang-move/Move.cpp Tue Mar 26 15:32:06 2019
@@ -87,8 +87,7 @@ std::string MakeAbsolutePath(StringRef C
 std::string MakeAbsolutePath(const SourceManager &SM, StringRef Path) {
   llvm::SmallString<128> AbsolutePath(Path);
   if (std::error_code EC =
-  SM.getFileManager().getVirtualFileSystem()->makeAbsolute(
-  AbsolutePath))
+  
SM.getFileManager().getVirtualFileSystem().makeAbsolute(AbsolutePath))
 llvm::errs() << "Warning: could not make absolute file: '" << EC.message()
  << '\n';
   // Handle symbolic link path cases.

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=357038&r1=357037&r2=357038&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Tue Mar 26 15:32:06 2019
@@ -362,7 +362,7 @@ ClangTidyASTConsumerFactory::CreateASTCo
   auto WorkingDir = Compiler.getSourceManager()
 .getFileManager()
 .getVirtualFileSystem()
-->getCurrentWorkingDirectory();
+.getCurrentWorkingDirectory();
   if (WorkingDir)
 Context.setCurrentBuildDirectory(WorkingDir.get());
 
@@ -555,7 +555,7 @@ void handleErrors(llvm::ArrayRef BaseFS) {
   ErrorReporter Reporter(Context, Fix, BaseFS);
   llvm::vfs::FileSystem &FileSystem =
-  *Reporter.getSourceManager().getFileManager().getVirtualFileSystem();
+  Reporter.getSourceManager().getFileManager().getVirtualFileSystem();
   auto InitialWorkingDir = FileSystem.getCurrentWorkingDirectory();
   if (!InitialWorkingDir)
 llvm::report_fatal_error("Cannot get current working path.");

Modified: clang-tools-extra/trunk/clangd/SourceCode.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.cpp?rev=357038&r1=357037&r2=357038&view=diff
==
--- clang-tools-extra/trunk/clangd/SourceCode.cpp (original)
+++ clang-tools-extra/trunk/clangd/SourceCode.cpp Tue Mar 26 15:32:06 2019
@@ -265,7 +265,7 @@ llvm::Optional getCanonical
   llvm::SmallString<128> FilePath = F->getName();
   if (!llvm::sys::path::is_absolute(FilePath)) {
 if (auto EC =
-SourceMgr.getFileManager().getVirtualFileSystem()->makeAbsolute(
+SourceMgr.getFileManager().getVirtualFileSystem().makeAbsolute(
 FilePath)) {
   elog("Could not turn relative path '{0}' to absolute: {1}", FilePath,
EC.message());


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


r357038 - Basic: Return a reference from FileManager::getVirtualFileSystem, NFC

2019-03-26 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Tue Mar 26 15:32:06 2019
New Revision: 357038

URL: http://llvm.org/viewvc/llvm-project?rev=357038&view=rev
Log:
Basic: Return a reference from FileManager::getVirtualFileSystem, NFC

FileManager constructs a VFS in its constructor if it isn't passed one,
and there's no way to reset it.  Make that contract clear by returning a
reference from its accessor.

https://reviews.llvm.org/D59388

Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Tooling/Tooling.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=357038&r1=357037&r2=357038&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Tue Mar 26 15:32:06 2019
@@ -221,9 +221,7 @@ public:
   FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
   const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
 
-  IntrusiveRefCntPtr getVirtualFileSystem() const {
-return FS;
-  }
+  llvm::vfs::FileSystem &getVirtualFileSystem() const { return *FS; }
 
   /// Retrieve a file entry for a "virtual" file that acts as
   /// if there were a file with the given name on disk.

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=357038&r1=357037&r2=357038&view=diff
==
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Tue Mar 26 15:32:06 2019
@@ -380,7 +380,7 @@ public:
   /// {
 
   llvm::vfs::FileSystem &getVirtualFileSystem() const {
-return *getFileManager().getVirtualFileSystem();
+return getFileManager().getVirtualFileSystem();
   }
 
   /// }

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=357038&r1=357037&r2=357038&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Mar 26 15:32:06 2019
@@ -1079,7 +1079,7 @@ bool ASTUnit::Parse(std::shared_ptrgetVirtualFileSystem() &&
+assert(VFS == &FileMgr->getVirtualFileSystem() &&
"VFS passed to Parse and VFS in FileMgr are different");
 
   auto CCInvocation = std::make_shared(*Invocation);
@@ -1097,7 +1097,7 @@ bool ASTUnit::Parse(std::shared_ptrgetVirtualFileSystem() == VFS)
+  if (VFS && FileMgr && &FileMgr->getVirtualFileSystem() == VFS)
 Clang->setFileManager(&*FileMgr);
   else
 FileMgr = Clang->createFileManager(std::move(VFS));
@@ -1690,7 +1690,7 @@ std::unique_ptr ASTUnit::LoadFr
 
   if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps),
   PrecompilePreambleAfterNParses,
-  AST->FileMgr->getVirtualFileSystem()))
+  &AST->FileMgr->getVirtualFileSystem()))
 return nullptr;
   return AST;
 }
@@ -1797,7 +1797,7 @@ bool ASTUnit::Reparse(std::shared_ptrgetVirtualFileSystem();
+VFS = &FileMgr->getVirtualFileSystem();
   }
 
   clearFileLevelDecls();
@@ -2211,18 +2211,18 @@ void ASTUnit::CodeComplete(
   if (Preamble) {
 std::string CompleteFilePath(File);
 
-auto VFS = FileMgr.getVirtualFileSystem();
-auto CompleteFileStatus = VFS->status(CompleteFilePath);
+auto &VFS = FileMgr.getVirtualFileSystem();
+auto CompleteFileStatus = VFS.status(CompleteFilePath);
 if (CompleteFileStatus) {
   llvm::sys::fs::UniqueID CompleteFileID = 
CompleteFileStatus->getUniqueID();
 
   std::string MainPath(OriginalSourceFile);
-  auto MainStatus = VFS->status(MainPath);
+  auto MainStatus = VFS.status(MainPath);
   if (MainStatus) {
 llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID();
 if (CompleteFileID == MainID && Line > 1)
   OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
-  PCHContainerOps, Inv, VFS, false, Line - 1);
+  PCHContainerOps, Inv, &VFS, false, Line - 1);
   }
 }
   }
@@ -2233,7 +2233,8 @@ void ASTUnit::CodeComplete(
 assert(Preamble &&
"No preamble was built, but OverrideMainBuffer is not null");
 
-auto VFS = FileMgr.getVirtualFileSystem();
+IntrusiveRefCntPtr VFS

r361708 - Add missing newline at end of file

2019-05-25 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat May 25 15:38:02 2019
New Revision: 361708

URL: http://llvm.org/viewvc/llvm-project?rev=361708&view=rev
Log:
Add missing newline at end of file

Modified:
cfe/trunk/unittests/Tooling/Syntax/TokensTest.cpp

Modified: cfe/trunk/unittests/Tooling/Syntax/TokensTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/Syntax/TokensTest.cpp?rev=361708&r1=361707&r2=361708&view=diff
==
--- cfe/trunk/unittests/Tooling/Syntax/TokensTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/Syntax/TokensTest.cpp Sat May 25 15:38:02 2019
@@ -651,4 +651,4 @@ TEST_F(TokenBufferTest, TokensToFileRang
   // We don't test assertion failures because death tests are slow.
 }
 
-} // namespace
\ No newline at end of file
+} // namespace


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


r330174 - Remove GC-related warning terminology

2018-04-16 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Mon Apr 16 21:25:18 2018
New Revision: 330174

URL: http://llvm.org/viewvc/llvm-project?rev=330174&view=rev
Log:
Remove GC-related warning terminology

ObjC-GC isn't used any more; clean up this warning text.

rdar://problem/39049693

Modified:
cfe/trunk/docs/DiagnosticsReference.rst
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/SemaObjC/property-10.m
cfe/trunk/test/SemaObjC/property.m

Modified: cfe/trunk/docs/DiagnosticsReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/DiagnosticsReference.rst?rev=330174&r1=330173&r2=330174&view=diff
==
--- cfe/trunk/docs/DiagnosticsReference.rst (original)
+++ cfe/trunk/docs/DiagnosticsReference.rst Mon Apr 16 21:25:18 2018
@@ -7556,7 +7556,7 @@ This diagnostic is enabled by default.
 **Diagnostic text:**
 
 
++
-|:warning:`warning:` |nbsp| :diagtext:`default property attribute 'assign' not 
appropriate for non-GC object`|
+|:warning:`warning:` |nbsp| :diagtext:`default property attribute 'assign' not 
appropriate for object`|
 
++
 
 
++

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=330174&r1=330173&r2=330174&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Apr 16 21:25:18 
2018
@@ -1032,7 +1032,7 @@ def warn_objc_pointer_masking : Warning<
 def warn_objc_pointer_masking_performSelector : 
Warning,
   InGroup;
 def warn_objc_property_default_assign_on_object : Warning<
-  "default property attribute 'assign' not appropriate for non-GC object">,
+  "default property attribute 'assign' not appropriate for object">,
   InGroup;
 def warn_property_attr_mismatch : Warning<
   "property attribute in class extension does not match the primary class">,

Modified: cfe/trunk/test/SemaObjC/property-10.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-10.m?rev=330174&r1=330173&r2=330174&view=diff
==
--- cfe/trunk/test/SemaObjC/property-10.m (original)
+++ cfe/trunk/test/SemaObjC/property-10.m Mon Apr 16 21:25:18 2018
@@ -24,7 +24,7 @@
 @property(unsafe_unretained, copy, retain) id p4_3; // expected-error 
{{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}}, 
expected-error {{property attributes 'unsafe_unretained' and 'retain' are 
mutually exclusive}} 
 @property(unsafe_unretained, copy, strong) id s4_3; // expected-error 
{{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}}, 
expected-error {{property attributes 'unsafe_unretained' and 'strong' are 
mutually exclusive}} 
 
-@property id p4; // expected-warning {{no 'assign', 'retain', or 'copy' 
attribute is specified - 'assign' is assumed}}, expected-warning {{default 
property attribute 'assign' not appropriate for non-GC object}}
+@property id p4; // expected-warning {{no 'assign', 'retain', or 'copy' 
attribute is specified - 'assign' is assumed}}, expected-warning {{default 
property attribute 'assign' not appropriate for object}}
 
 @property(nonatomic,copy) int (^includeMailboxCondition)(); 
 @property(nonatomic,copy) int (*includeMailboxCondition2)(); // expected-error 
{{property with 'copy' attribute must be of object type}}

Modified: cfe/trunk/test/SemaObjC/property.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property.m?rev=330174&r1=330173&r2=330174&view=diff
==
--- cfe/trunk/test/SemaObjC/property.m (original)
+++ cfe/trunk/test/SemaObjC/property.m Mon Apr 16 21:25:18 2018
@@ -6,7 +6,7 @@
int name;
 }
 @property int d1;
-@property id  prop_id; // expected-warning {{no 'assign', 'retain', or 'copy' 
attribute is specified - 'assign' is assumed}}, expected-warning {{default 
property attribute 'assign' not appropriate for non-GC object}}
+@property id  prop_id; // expected-warning {{no 'assign', 'retain', or 'copy' 
attribute is specified - 'assign' is assumed}}, expected-warning {{default 
property attribute 'assign' not appropriate for object}}
 @property int name;
 @end
 


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


r330177 - Fix malformed table introduced by r330174

2018-04-16 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Mon Apr 16 22:48:36 2018
New Revision: 330177

URL: http://llvm.org/viewvc/llvm-project?rev=330177&view=rev
Log:
Fix malformed table introduced by r330174

http://lab.llvm.org:8011/builders/clang-sphinx-docs/builds/23573

Modified:
cfe/trunk/docs/DiagnosticsReference.rst

Modified: cfe/trunk/docs/DiagnosticsReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/DiagnosticsReference.rst?rev=330177&r1=330176&r2=330177&view=diff
==
--- cfe/trunk/docs/DiagnosticsReference.rst (original)
+++ cfe/trunk/docs/DiagnosticsReference.rst Mon Apr 16 22:48:36 2018
@@ -7555,9 +7555,9 @@ This diagnostic is enabled by default.
 
 **Diagnostic text:**
 
-++
++-+
 |:warning:`warning:` |nbsp| :diagtext:`default property attribute 'assign' not 
appropriate for object`|
-++
++-+
 
 
++
 |:warning:`warning:` |nbsp| :diagtext:`no 'assign', 'retain', or 'copy' 
attribute is specified - 'assign' is assumed`|


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


Re: [PATCH] D48675: [libc++abi] Limit libc++ header search to specified paths

2018-06-27 Thread Duncan P. N. Exon Smith via cfe-commits
Please close this and open a new one.  Adding cfe-commits after the fact will 
fail to send the patch/description to cfe-commits, and not everyone is on 
llvm-commits.

> On Jun. 27, 2018, at 14:29, Shoaib Meenai via Phabricator 
>  wrote:
> 
> smeenai edited subscribers, added: cfe-commits; removed: llvm-commits.
> smeenai added a comment.
> 
> Huh, this went to llvm-commits instead of cfe-commits automatically. I guess 
> the auto mailing list subscribing doesn't work great with the monorepo?
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D48675
> 
> 
> 

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


Re: [PATCH] D24826: [LTO] Add -flto-jobs=N to control backend parallelism

2016-09-22 Thread Duncan P. N. Exon Smith via cfe-commits

> On 2016-Sep-22, at 09:53, Teresa Johnson  wrote:
> 
> tejohnson added a comment.
> 
> In https://reviews.llvm.org/D24826#549788, @mehdi_amini wrote:
> 
>> The Gold path looks fine. 
>> On OSX, we would have the clang driver relying on a LLVM cl::opt, for which 
>> I don't think there is any precedent. CC Duncan for advice.
> 
> 
> I do see other uses of -mllvm in lib/Driver/Tools.cpp, but are you talking 
> about something else?

I think this is okay, since clang is talking to the same version of 
libLTO.dylib.  I feel like there might be another case where clang talks to 
libLTO.dylib through ld64 using -mllvm... perhaps, -O0?

Let's ask around though to be sure.

> 
>> Also I don't think the same option should be used for the parallel LTO 
>> codegen: it actually does not generate the same binary, which should deserve 
>> a dedicated opt-in (What if I mix ThinLTO and LTO, and I don't want // 
>> codegen?)
> 
> 
> Ok good point. I can change this to -fthinlto_jobs. However, while the two 
> parallel settings are separate in the LTO API, currently the gold-plugin jobs 
> option controls both, so I will need to do a preparatory gold-plugin patch to 
> split this into thinlto_jobs and lto_jobs. On the libLTO/ld64 path, looks 
> like the current -mllvm -threads only affects ThinLTO so there is no work to 
> do there.

I actually like -flto-jobs=N better for this.  I expect "jobs" not to affect 
output at all.

I think the current parallel FullLTO CodeGen (where it *does* affect output) 
should have a special name that calls this out, perhaps -flto-partitions=N?  
-flto-slices=N?  -flto-random-partitions=N?  Is it urgent to add that flag now 
though?

Note that I imagine someone will parallelizing FullLTO the hard way in the 
future, which won't affect output.  That implementation should use -flto-jobs=N.

> 
> https://reviews.llvm.org/D24826
> 
> 
> 

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


Re: [PATCH] D17469: [libcxx] Add deployment knobs to tests (for Apple platforms)

2016-09-26 Thread Duncan P. N. Exon Smith via cfe-commits
Correct.  I haven't had a chance to get back to this.  I'm aiming to pick it up 
again in the next week or two, but if this is specifically blocking you, feel 
free to rebase and commit on my behalf.

> On 2016-Sep-26, at 13:39, Eugene Zelenko  wrote:
> 
> Eugene.Zelenko added a subscriber: Eugene.Zelenko.
> Eugene.Zelenko added a comment.
> 
> Looks like patch was not committed.
> 
> 
> https://reviews.llvm.org/D17469
> 
> 
> 

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


r320271 - Update Clang CMake cache to use cxx-headers, NFC

2017-12-09 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Dec  9 15:44:42 2017
New Revision: 320271

URL: http://llvm.org/viewvc/llvm-project?rev=320271&view=rev
Log:
Update Clang CMake cache to use cxx-headers, NFC

Apparently libcxx-headers is going away.  Fixes PR35584.

Modified:
cfe/trunk/cmake/caches/Apple-stage2.cmake

Modified: cfe/trunk/cmake/caches/Apple-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Apple-stage2.cmake?rev=320271&r1=320270&r2=320271&view=diff
==
--- cfe/trunk/cmake/caches/Apple-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Apple-stage2.cmake Sat Dec  9 15:44:42 2017
@@ -61,7 +61,7 @@ set(LLVM_DISTRIBUTION_COMPONENTS
   LTO
   clang-format
   clang-headers
-  libcxx-headers
+  cxx-headers
   ${LLVM_TOOLCHAIN_TOOLS}
   CACHE STRING "")
 


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


[clang] [llvm] [clang] NFC: Remove `{File, Directory}Entry::getName()` (PR #74910)

2023-12-11 Thread Duncan P . N . Exon Smith via cfe-commits

https://github.com/dexonsmith approved this pull request.

Amazing! LGTM, once the branch is clear.

https://github.com/llvm/llvm-project/pull/74910
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bfi precision (PR #66285)

2023-10-28 Thread Duncan P . N . Exon Smith via cfe-commits

dexonsmith wrote:

Interesting. Probably `Value::getMetadata()` could/should call 
`DenseMap::find()` instead of `operator[]()` and assert that it's found before 
dereferencing, because `Value::hasMetadata()` (which, IIRC, consults a bit 
stored in `Value`) has already promised something will be there. Probably 
you'll find me on the git-blame for this...

Your plan SGTM!

https://github.com/llvm/llvm-project/pull/66285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 37e7cf7 - Driver: Make macOS the default target OS for -arch arm64

2022-03-18 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2022-03-18T13:36:47-07:00
New Revision: 37e7cf7f1c6920d33a4a5dd3f0a415a61dd24731

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

LOG: Driver: Make macOS the default target OS for -arch arm64

This is a follow up to 565603cc94d79a8d0de6df840fd53714899fb890,
which made macOS the default target OS for `-arch arm64` when
running on an Apple Silicon Mac. Now it'll be the default when
running on an Intel Mac too.

clang/test/Driver/apple-arm64-arch.c was a bit odd before: it was added
for the above commit, but tested the inverse behaviour and XFAIL'ed on
Apple Silicon. This inverts it to the (new) behaviour (that's now
correct regardless) and removes the XFAIL.

Radar-Id: rdar://90500294

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/apple-arm64-arch.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index a11cd3fbaa71c..47eb14ffb83e4 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1886,16 +1886,9 @@ inferDeploymentTargetFromArch(DerivedArgList &Args, 
const Darwin &Toolchain,
   llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
 
   StringRef MachOArchName = Toolchain.getMachOArchName(Args);
-  if (MachOArchName == "arm64" || MachOArchName == "arm64e") {
-#if __arm64__
-// A clang running on an Apple Silicon mac defaults
-// to building for mac when building for arm64 rather than
-// defaulting to iOS.
+  if (MachOArchName == "arm64" || MachOArchName == "arm64e")
 OSTy = llvm::Triple::MacOSX;
-#else
-OSTy = llvm::Triple::IOS;
-#endif
-  } else if (MachOArchName == "armv7" || MachOArchName == "armv7s")
+  else if (MachOArchName == "armv7" || MachOArchName == "armv7s")
 OSTy = llvm::Triple::IOS;
   else if (MachOArchName == "armv7k" || MachOArchName == "arm64_32")
 OSTy = llvm::Triple::WatchOS;

diff  --git a/clang/test/Driver/apple-arm64-arch.c 
b/clang/test/Driver/apple-arm64-arch.c
index a37346b1a9bb0..a111260b38a6b 100644
--- a/clang/test/Driver/apple-arm64-arch.c
+++ b/clang/test/Driver/apple-arm64-arch.c
@@ -2,6 +2,5 @@
 // RUN:   FileCheck %s
 //
 // REQUIRES: system-darwin
-// XFAIL: apple-silicon-mac
 //
-// CHECK: "-triple" "arm64-apple-ios{{[0-9.]+}}"
+// CHECK: "-triple" "arm64-apple-macosx{{[0-9.]+}}"



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


[clang] 2d13386 - Frontend: Delete output streams before closing CompilerInstance outputs

2022-04-28 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2022-04-28T19:07:40-07:00
New Revision: 2d133867833fe8eb20c11377ff1221f71afc1db3

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

LOG: Frontend: Delete output streams before closing CompilerInstance outputs

Delete the output streams coming from
CompilerInstance::createOutputFile() and friends once writes are
finished. Concretely, replacing `OS->flush()` with `OS.reset()` in:

- `ExtractAPIAction::EndSourceFileAction()`
- `PrecompiledPreambleAction::setEmittedPreamblePCH()`
- `cc1_main()'s support for `-ftime-trace`

This fixes theoretical bugs related to proxy streams, which may have
cleanups to run in their destructor. For example, a proxy that
CompilerInstance sometimes uses is `buffer_ostream`, which wraps a
`raw_ostream` lacking pwrite support and adds it. `flush()` does not
promise that output is complete; `buffer_ostream` needs to wait until
the destructor to forward anything so that it can service later calls to
`pwrite()`. If the destructor isn't called then the proxied stream
hasn't received any content.

This also protects against some logic bugs, triggering a null
dereference on a later attempt to write to the stream.

No tests, since in practice these particular code paths never use
use `buffer_ostream`; you need to be writing a binary file to a
pipe (such as stdout) to hit it, but `-extract-api` writes a text file
and the other two use computed filenames that will never (in practice)
be a pipe. This is effectively NFC, for now.

But I have some other patches in the works that add guard rails,
crashing if the stream hasn't been destructed by the time the
CompilerInstance is told to keep the output file, since in most cases
this is a problem.

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

Added: 


Modified: 
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/Frontend/PrecompiledPreamble.cpp
clang/tools/driver/cc1_main.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 0217c656cbb04..b1de2674b622b 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -793,7 +793,7 @@ void ExtractAPIAction::EndSourceFileAction() {
   // FIXME: Make the kind of APISerializer configurable.
   SymbolGraphSerializer SGSerializer(*API, ProductName);
   SGSerializer.serialize(*OS);
-  OS->flush();
+  OS.reset();
 }
 
 std::unique_ptr

diff  --git a/clang/lib/Frontend/PrecompiledPreamble.cpp 
b/clang/lib/Frontend/PrecompiledPreamble.cpp
index 341ea6121637d..d5aab4aedadd6 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -248,7 +248,7 @@ class PrecompilePreambleAction : public ASTFrontendAction {
 if (FileOS) {
   *FileOS << Buffer->Data;
   // Make sure it hits disk now.
-  FileOS->flush();
+  FileOS.reset();
 }
 
 this->HasEmittedPreamblePCH = true;

diff  --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f648adeba4834..5adc07154f88c 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -260,8 +260,7 @@ int cc1_main(ArrayRef Argv, const char 
*Argv0, void *MainAddr) {
 Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
   llvm::timeTraceProfilerWrite(*profilerOutput);
-  // FIXME(ibiryukov): make profilerOutput flush in destructor instead.
-  profilerOutput->flush();
+  profilerOutput.reset();
   llvm::timeTraceProfilerCleanup();
   Clang->clearOutputFiles(false);
 }



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


[clang] c1e17c7 - ExtractAPI: Use %clang_cc1 and -verify in enum.c

2022-05-03 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2022-05-03T11:57:24-07:00
New Revision: c1e17c7dfedd27b95c8c2fba2b6473c7348f0e77

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

LOG: ExtractAPI: Use %clang_cc1 and -verify in enum.c

Fix one test (enum.c) in ExtractAPI to use %clang_cc1 and -verify
instead of calling the full driver and FileCheck. This is an example for
my comment from https://reviews.llvm.org/D121873.

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

Added: 


Modified: 
clang/test/ExtractAPI/enum.c

Removed: 




diff  --git a/clang/test/ExtractAPI/enum.c b/clang/test/ExtractAPI/enum.c
index a14666a037471..8c06d850dbdaf 100644
--- a/clang/test/ExtractAPI/enum.c
+++ b/clang/test/ExtractAPI/enum.c
@@ -2,17 +2,14 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
 // RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: %clang -extract-api -target arm64-apple-macosx \
-// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c-header %t/input.h -o %t/output.json -verify
 
 // Generator version is not consistent across test runs, normalize it.
 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
 // RUN: %t/output.json >> %t/output-normalized.json
 // RUN: 
diff  %t/reference.output.json %t/output-normalized.json
 
-// CHECK-NOT: error:
-// CHECK-NOT: warning:
-
 //--- input.h
 /// Kinds of vehicles
 enum Vehicle {
@@ -37,6 +34,7 @@ enum {
 enum {
   OtherConstant = 2
 };
+// expected-no-diagnostics
 
 //--- reference.output.json.in
 {



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


[clang-tools-extra] Bfi precision (PR #66285)

2023-10-26 Thread Duncan P . N . Exon Smith via cfe-commits

dexonsmith wrote:

Seems awkward to pessimize as "cold" when there's no real data (no PGO, no 
other marking). What happens if you change the cold call threshold to 0% when 
there's no PGO data? (I.e., never assume a call is cold without actual evidence)

https://github.com/llvm/llvm-project/pull/66285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bfi precision (PR #66285)

2023-10-26 Thread Duncan P . N . Exon Smith via cfe-commits

dexonsmith wrote:

Not entirely accidental. When BPI/BFI first landed it was heavily profiled to 
be sure it didn't pessimize non-PGO code. I don't see why we'd suddenly be okay 
with pessimizing it.

Under 2% isn't hard to hit for hot path code. Lots of functions will have 
strings of early exit conditions.

https://github.com/llvm/llvm-project/pull/66285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Bfi precision (PR #66285)

2023-10-26 Thread Duncan P . N . Exon Smith via cfe-commits

dexonsmith wrote:

Not entirely accidental. When BPI/BFI first landed it was heavily profiled to 
be sure it didn't pessimize non-PGO code. I don't see why we'd suddenly be okay 
with pessimizing it.

Under 2% isn't hard to hit for hot path code. Lots of functions will have 
strings of early exit conditions.

https://github.com/llvm/llvm-project/pull/66285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bfi precision (PR #66285)

2023-10-26 Thread Duncan P . N . Exon Smith via cfe-commits

dexonsmith wrote:

> Seems this got introduced in https://reviews.llvm.org/D34312 with the rough 
> idea that we shouldn't inline into parts of the code that 
> `_builtin_expect(...)` deems unlikely. Which makes sense when you express it 
> like this, but I guess numeric thresholds can go wrong...

Heh, yeah, the premise seems correct, but a percentage-based numeric threshold 
doesn't seem right. You kind of want a flag for the block. Or a special value, 
like "freq=0", which indicates "annotation says this is cold".

https://github.com/llvm/llvm-project/pull/66285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r369861 - FileManager: Factor duplicated code in getBufferForFile, NFC

2019-08-24 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Aug 24 18:18:35 2019
New Revision: 369861

URL: http://llvm.org/viewvc/llvm-project?rev=369861&view=rev
Log:
FileManager: Factor duplicated code in getBufferForFile, NFC

Incidentally, this also unifies the two versions (removing an
unnecessary call to `SmallString::c_str`).

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

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=369861&r1=369860&r2=369861&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Sat Aug 24 18:18:35 2019
@@ -311,8 +311,15 @@ public:
   getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
bool ShouldCloseOpenFile = true);
   llvm::ErrorOr>
-  getBufferForFile(StringRef Filename, bool isVolatile = false);
+  getBufferForFile(StringRef Filename, bool isVolatile = false) {
+return getBufferForFileImpl(Filename, /*FileSize=*/-1, isVolatile);
+  }
 
+private:
+  llvm::ErrorOr>
+  getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile);
+
+public:
   /// Get the 'stat' information for the given \p Path.
   ///
   /// If the path is relative, it will be resolved against the WorkingDir of 
the

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=369861&r1=369860&r2=369861&view=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Sat Aug 24 18:18:35 2019
@@ -447,27 +447,22 @@ FileManager::getBufferForFile(const File
   }
 
   // Otherwise, open the file.
+  return getBufferForFileImpl(Filename, FileSize, isVolatile);
+}
 
+llvm::ErrorOr>
+FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
+  bool isVolatile) {
   if (FileSystemOpts.WorkingDir.empty())
 return FS->getBufferForFile(Filename, FileSize,
 /*RequiresNullTerminator=*/true, isVolatile);
 
-  SmallString<128> FilePath(Entry->getName());
+  SmallString<128> FilePath(Filename);
   FixupRelativePath(FilePath);
   return FS->getBufferForFile(FilePath, FileSize,
   /*RequiresNullTerminator=*/true, isVolatile);
 }
 
-llvm::ErrorOr>
-FileManager::getBufferForFile(StringRef Filename, bool isVolatile) {
-  if (FileSystemOpts.WorkingDir.empty())
-return FS->getBufferForFile(Filename, -1, true, isVolatile);
-
-  SmallString<128> FilePath(Filename);
-  FixupRelativePath(FilePath);
-  return FS->getBufferForFile(FilePath.c_str(), -1, true, isVolatile);
-}
-
 /// getStatValue - Get the 'stat' information for the specified path,
 /// using the cache to accelerate it if possible.  This returns true
 /// if the path points to a virtual file or does not exist, or returns


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


r369943 - FileManager: Use llvm::Expected in new getFileRef API

2019-08-26 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Mon Aug 26 11:29:51 2019
New Revision: 369943

URL: http://llvm.org/viewvc/llvm-project?rev=369943&view=rev
Log:
FileManager: Use llvm::Expected in new getFileRef API

`FileManager::getFileRef` is a modern API which we expect to convert to
over time.  We should modernize the error handling as well, using
`llvm::Expected` instead of `llvm::ErrorOr`, to help clients that care
about errors to ensure nothing is missed.

However, not all clients care.  I've also added another path for those
that don't:

- `FileEntryRef` is now copy- and move-assignable (using a pointer
  instead of a reference).
- `FileManager::getOptionalFileRef` returns an `llvm::Optional` instead
  of `llvm::Expected`.
- Added an `llvm::expectedToOptional` utility in case this is useful
  elsewhere.

https://reviews.llvm.org/D66705

Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Lex/HeaderMap.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=369943&r1=369942&r2=369943&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Mon Aug 26 11:29:51 2019
@@ -110,26 +110,27 @@ public:
 /// accessed by the FileManager's client.
 class FileEntryRef {
 public:
+  FileEntryRef() = delete;
   FileEntryRef(StringRef Name, const FileEntry &Entry)
-  : Name(Name), Entry(Entry) {}
+  : Name(Name), Entry(&Entry) {}
 
   const StringRef getName() const { return Name; }
 
-  const FileEntry &getFileEntry() const { return Entry; }
+  const FileEntry &getFileEntry() const { return *Entry; }
 
-  off_t getSize() const { return Entry.getSize(); }
+  off_t getSize() const { return Entry->getSize(); }
 
-  unsigned getUID() const { return Entry.getUID(); }
+  unsigned getUID() const { return Entry->getUID(); }
 
   const llvm::sys::fs::UniqueID &getUniqueID() const {
-return Entry.getUniqueID();
+return Entry->getUniqueID();
   }
 
-  time_t getModificationTime() const { return Entry.getModificationTime(); }
+  time_t getModificationTime() const { return Entry->getModificationTime(); }
 
 private:
   StringRef Name;
-  const FileEntry &Entry;
+  const FileEntry *Entry;
 };
 
 /// Implements support for file system lookup, file system caching,
@@ -284,9 +285,17 @@ public:
   ///
   /// \param CacheFailure If true and the file does not exist, we'll cache
   /// the failure to find this file.
-  llvm::ErrorOr getFileRef(StringRef Filename,
- bool OpenFile = false,
- bool CacheFailure = true);
+  llvm::Expected getFileRef(StringRef Filename,
+  bool OpenFile = false,
+  bool CacheFailure = true);
+
+  /// Get a FileEntryRef if it exists, without doing anything on error.
+  llvm::Optional getOptionalFileRef(StringRef Filename,
+  bool OpenFile = false,
+  bool CacheFailure = true) {
+return llvm::expectedToOptional(
+getFileRef(Filename, OpenFile, CacheFailure));
+  }
 
   /// Returns the current file system options
   FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=369943&r1=369942&r2=369943&view=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Mon Aug 26 11:29:51 2019
@@ -187,10 +187,10 @@ FileManager::getFile(StringRef Filename,
   auto Result = getFileRef(Filename, openFile, CacheFailure);
   if (Result)
 return &Result->getFileEntry();
-  return Result.getError();
+  return llvm::errorToErrorCode(Result.takeError());
 }
 
-llvm::ErrorOr
+llvm::Expected
 FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
   ++NumFileLookups;
 
@@ -199,7 +199,8 @@ FileManager::getFileRef(StringRef Filena
   SeenFileEntries.insert({Filename, std::errc::no_such_file_or_directory});
   if (!SeenFileInsertResult.second) {
 if (!SeenFileInsertResult.first->second)
-  return SeenFileInsertResult.first->second.getError();
+  return llvm::errorCodeToError(
+  SeenFileInsertResult.first->second.getError());
 // Construct and return and FileEntryRef, unless it's a redirect to another
 // filename.
 SeenFileEntryOrRedirect Value = *SeenFileInsertResult.first->second;
@@ -230,7 +231,7 @@ FileManager::getFileRef(StringRef Filena
 else
   SeenFileEntries.erase(Filen

r369958 - ContentCache: Drop getBuffer's dependency on SourceManager

2019-08-26 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Mon Aug 26 13:32:05 2019
New Revision: 369958

URL: http://llvm.org/viewvc/llvm-project?rev=369958&view=rev
Log:
ContentCache: Drop getBuffer's dependency on SourceManager

Refactor ContentCache::IsSystemFile to IsFileVolatile, checking
SourceManager::userFilesAreVolatile at construction time.  This is a
step toward lowering ContentCache down from SourceManager to
FileManager.

No functionality change intended.

https://reviews.llvm.org/D66713

Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=369958&r1=369957&r2=369958&view=diff
==
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Mon Aug 26 13:32:05 2019
@@ -140,9 +140,9 @@ namespace SrcMgr {
 /// exist.
 unsigned BufferOverridden : 1;
 
-/// True if this content cache was initially created for a source
-/// file considered as a system one.
-unsigned IsSystemFile : 1;
+/// True if this content cache was initially created for a source file
+/// considered to be volatile (likely to change between stat and open).
+unsigned IsFileVolatile : 1;
 
 /// True if this file may be transient, that is, if it might not
 /// exist at some later point in time when this content entry is used,
@@ -152,15 +152,15 @@ namespace SrcMgr {
 ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {}
 
 ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
-  : Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt),
-BufferOverridden(false), IsSystemFile(false), IsTransient(false) {}
+: Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt),
+  BufferOverridden(false), IsFileVolatile(false), IsTransient(false) {}
 
 /// The copy ctor does not allow copies where source object has either
 /// a non-NULL Buffer or SourceLineCache.  Ownership of allocated memory
 /// is not transferred, so this is a logical error.
 ContentCache(const ContentCache &RHS)
-  : Buffer(nullptr, false), BufferOverridden(false), IsSystemFile(false),
-IsTransient(false) {
+: Buffer(nullptr, false), BufferOverridden(false),
+  IsFileVolatile(false), IsTransient(false) {
   OrigEntry = RHS.OrigEntry;
   ContentsEntry = RHS.ContentsEntry;
 
@@ -185,7 +185,7 @@ namespace SrcMgr {
 ///
 /// \param Invalid If non-NULL, will be set \c true if an error occurred.
 const llvm::MemoryBuffer *getBuffer(DiagnosticsEngine &Diag,
-const SourceManager &SM,
+FileManager &FM,
 SourceLocation Loc = SourceLocation(),
 bool *Invalid = nullptr) const;
 
@@ -986,8 +986,8 @@ public:
   return getFakeBufferForRecovery();
 }
 
-return Entry.getFile().getContentCache()->getBuffer(Diag, *this, Loc,
-Invalid);
+return Entry.getFile().getContentCache()->getBuffer(Diag, getFileManager(),
+Loc, Invalid);
   }
 
   const llvm::MemoryBuffer *getBuffer(FileID FID,
@@ -1001,9 +1001,8 @@ public:
   return getFakeBufferForRecovery();
 }
 
-return Entry.getFile().getContentCache()->getBuffer(Diag, *this,
-SourceLocation(),
-Invalid);
+return Entry.getFile().getContentCache()->getBuffer(
+Diag, getFileManager(), SourceLocation(), Invalid);
   }
 
   /// Returns the FileEntry record for the provided FileID.

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=369958&r1=369957&r2=369958&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Aug 26 13:32:05 2019
@@ -8503,8 +8503,9 @@ Expected ASTImporter::Import(Fil
 if (ToID.isInvalid() || IsBuiltin) {
   // FIXME: We want to re-use the existing MemoryBuffer!
   bool Invalid = true;
-  const llvm::MemoryBuffer *FromBuf = Cache->getBuffer(
-  FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid);
+  const llvm::MemoryBuffer *FromBuf =
+  Cache->getBuffer(FromContext.getDiagnostics(),
+   FromSM.getFileManager(), SourceLocation{}, 
&Invalid);
   if (!FromBuf || Invalid)
 // FIXME: Use a n

r370488 - FileManager: Remove ShouldCloseOpenFile argument from getBufferForFile, NFC

2019-08-30 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Fri Aug 30 09:56:26 2019
New Revision: 370488

URL: http://llvm.org/viewvc/llvm-project?rev=370488&view=rev
Log:
FileManager: Remove ShouldCloseOpenFile argument from getBufferForFile, NFC

Remove this dead code.  We always close it.

Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=370488&r1=370487&r2=370488&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Fri Aug 30 09:56:26 2019
@@ -317,8 +317,7 @@ public:
   /// Open the specified file as a MemoryBuffer, returning a new
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr>
-  getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
-   bool ShouldCloseOpenFile = true);
+  getBufferForFile(const FileEntry *Entry, bool isVolatile = false);
   llvm::ErrorOr>
   getBufferForFile(StringRef Filename, bool isVolatile = false) {
 return getBufferForFileImpl(Filename, /*FileSize=*/-1, isVolatile);

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=370488&r1=370487&r2=370488&view=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Fri Aug 30 09:56:26 2019
@@ -426,8 +426,7 @@ void FileManager::fillRealPathName(FileE
 }
 
 llvm::ErrorOr>
-FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
-  bool ShouldCloseOpenFile) {
+FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile) {
   uint64_t FileSize = Entry->getSize();
   // If there's a high enough chance that the file have changed since we
   // got its size, force a stat before opening it.
@@ -440,10 +439,7 @@ FileManager::getBufferForFile(const File
 auto Result =
 Entry->File->getBuffer(Filename, FileSize,
/*RequiresNullTerminator=*/true, isVolatile);
-// FIXME: we need a set of APIs that can make guarantees about whether a
-// FileEntry is open or not.
-if (ShouldCloseOpenFile)
-  Entry->closeFile();
+Entry->closeFile();
 return Result;
   }
 

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=370488&r1=370487&r2=370488&view=diff
==
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Fri Aug 30 09:56:26 2019
@@ -185,9 +185,7 @@ ModuleManager::addModule(StringRef FileN
   Buf = llvm::MemoryBuffer::getSTDIN();
 } else {
   // Get a buffer of the file and close the file descriptor when done.
-  Buf = FileMgr.getBufferForFile(NewModule->File,
- /*isVolatile=*/false,
- /*ShouldClose=*/true);
+  Buf = FileMgr.getBufferForFile(NewModule->File, /*isVolatile=*/false);
 }
 
 if (!Buf) {


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


r370546 - ASTReader: Bypass overridden files when reading PCHs

2019-08-30 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Fri Aug 30 15:59:25 2019
New Revision: 370546

URL: http://llvm.org/viewvc/llvm-project?rev=370546&view=rev
Log:
ASTReader: Bypass overridden files when reading PCHs

If contents of a file that is part of a PCM are overridden when reading
it, but weren't overridden when the PCM was being built, the ASTReader
will emit an error.  Now it creates a separate FileEntry for recovery,
bypassing the overridden content instead of discarding it.  The
pre-existing testcase clang/test/PCH/remap-file-from-pch.cpp confirms
that the new recovery method works correctly.

This resolves a long-standing FIXME to avoid hypothetically invalidating
another precompiled module that's already using the overridden contents.

This also removes ContentCache-related API that would be unsafe to use
across `CompilerInstance`s in an implicit modules build.  This helps to
unblock us sinking it from SourceManager into FileManager in the future,
which would allow us to delete `InMemoryModuleCache`.

https://reviews.llvm.org/D66710

Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/unittests/Basic/FileManagerTest.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=370546&r1=370545&r2=370546&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Fri Aug 30 15:59:25 2019
@@ -116,6 +116,8 @@ public:
 
   const StringRef getName() const { return Name; }
 
+  bool isValid() const { return Entry->isValid(); }
+
   const FileEntry &getFileEntry() const { return *Entry; }
 
   off_t getSize() const { return Entry->getSize(); }
@@ -128,6 +130,13 @@ public:
 
   time_t getModificationTime() const { return Entry->getModificationTime(); }
 
+  friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) {
+return LHS.Entry == RHS.Entry && LHS.Name == RHS.Name;
+  }
+  friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) {
+return !(LHS == RHS);
+  }
+
 private:
   StringRef Name;
   const FileEntry *Entry;
@@ -158,6 +167,10 @@ class FileManager : public RefCountedBas
   /// The virtual files that we have allocated.
   SmallVector, 4> VirtualFileEntries;
 
+  /// A set of files that bypass the maps and uniquing.  They can have
+  /// conflicting filenames.
+  SmallVector, 0> BypassFileEntries;
+
   /// A cache that maps paths to directory entries (either real or
   /// virtual) we have looked up, or an error that occurred when we looked up
   /// the directory.
@@ -314,6 +327,16 @@ public:
   const FileEntry *getVirtualFile(StringRef Filename, off_t Size,
   time_t ModificationTime);
 
+  /// Retrieve a FileEntry that bypasses VFE, which is expected to be a virtual
+  /// file entry, to access the real file.  The returned FileEntry will have
+  /// the same filename as FE but a different identity and its own stat.
+  ///
+  /// This should be used only for rare error recovery paths because it
+  /// bypasses all mapping and uniquing, blindly creating a new FileEntry.
+  /// There is no attempt to deduplicate these; if you bypass the same file
+  /// twice, you get two new file entries.
+  llvm::Optional getBypassFile(FileEntryRef VFE);
+
   /// Open the specified file as a MemoryBuffer, returning a new
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr>
@@ -353,11 +376,6 @@ public:
   void GetUniqueIDMapping(
 SmallVectorImpl &UIDToFiles) const;
 
-  /// Modifies the size and modification time of a previously created
-  /// FileEntry. Use with caution.
-  static void modifyFileEntry(FileEntry *File, off_t Size,
-  time_t ModificationTime);
-
   /// Retrieve the canonical name for a given directory.
   ///
   /// This is a very expensive operation, despite its results being cached,

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=370546&r1=370545&r2=370546&view=diff
==
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Fri Aug 30 15:59:25 2019
@@ -952,11 +952,12 @@ public:
 return false;
   }
 
-  /// Disable overridding the contents of a file, previously enabled
-  /// with #overrideFileContents.
+  /// Bypass the overridden contents of a file.  This creates a new FileEntry
+  /// and initializes the content cache for it.  Returns nullptr if there is no
+  /// such file in the filesystem.
   ///
   /// This should be cal

Re: r369943 - FileManager: Use llvm::Expected in new getFileRef API

2019-09-05 Thread Duncan P. N. Exon Smith via cfe-commits


> On Sep 4, 2019, at 17:39, David Blaikie  wrote:
> 
> 
> 
> On Mon, Aug 26, 2019 at 11:28 AM Duncan P. N. Exon Smith via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: dexonsmith
> Date: Mon Aug 26 11:29:51 2019
> New Revision: 369943
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=369943&view=rev 
> <http://llvm.org/viewvc/llvm-project?rev=369943&view=rev>
> Log:
> FileManager: Use llvm::Expected in new getFileRef API
> 
> `FileManager::getFileRef` is a modern API which we expect to convert to
> over time.  We should modernize the error handling as well, using
> `llvm::Expected` instead of `llvm::ErrorOr`, to help clients that care
> about errors to ensure nothing is missed.
> 
> However, not all clients care.  I've also added another path for those
> that don't:
> 
> - `FileEntryRef` is now copy- and move-assignable (using a pointer
>   instead of a reference).
> - `FileManager::getOptionalFileRef` returns an `llvm::Optional` instead
>   of `llvm::Expected`.
> - Added an `llvm::expectedToOptional` utility in case this is useful
>   elsewhere.
> 
> I'd hesitate to add new general constructs that swallow errors like this - 
> keeping them manually written might help avoid their use becoming too common.
> 
> On that note/direction - are there enough callers of getFileRef that don't 
> care about errors that it's really impractical for them to each explicitly 
> swallow the errors?

`getFileRef` is intended to eventually supplant `getFile` which has many users. 
 Most of them don't care about the error, they just want to know whether or not 
they have a file entry.  If it makes sense to change them at some point that's 
great, but I think having them use `getOptionalFileRef` makes it easy to track 
down (and potentially change) the ones that are ignoring the specific error, 
without requiring a ton of boilerplate at each call site in the meantime.  An 
un-posted version of the patch changed all the current call sites of getFileRef 
to handle/ignore the error explicitly and it looked like I was making the code 
worse.

That said, as long as we have the getOptionalFileRef API, I don't feel strongly 
about the llvm::expectedToOptional utility.  The points in favour are that it 
aligns well with llvm::errorToBool, it reduces boilerplate, and it seems both 
explicit and grep'able.  Maybe that's not compelling enough though.___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 51f3432 - Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, almost NFC

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T12:52:17-08:00
New Revision: 51f3432f4b5217b35dc2694c6e46d6cfc7defad6

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

LOG: Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, 
almost NFC

Clarify the logic for using the preamble (and overriding the main file
buffer) in `ASTUnit::CodeComplete` by factoring out a couple of lambdas
(`getUniqueID` and `hasSameUniqueID`).  While refactoring the logic,
hoist the check for `Line > 1` and locally check if the filenames are
equal (both to avoid unnecessary `stat` calls) and skip copying out the
filenames to `std::string`.

Besides fewer calls to `stat`, there's no functionality change here.

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

Added: 


Modified: 
clang/lib/Frontend/ASTUnit.cpp

Removed: 




diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index c8ac7eaa9ab8..d9154e9b459e 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -2237,28 +2237,30 @@ void ASTUnit::CodeComplete(
 = new AugmentedCodeCompleteConsumer(*this, Consumer, CodeCompleteOpts);
   Clang->setCodeCompletionConsumer(AugmentedConsumer);
 
+  auto getUniqueID =
+  [&FileMgr](StringRef Filename) -> Optional {
+if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
+  return Status->getUniqueID();
+return None;
+  };
+
+  auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) {
+if (LHS == RHS)
+  return true;
+if (auto LHSID = getUniqueID(LHS))
+  if (auto RHSID = getUniqueID(RHS))
+return *LHSID == *RHSID;
+return false;
+  };
+
   // If we have a precompiled preamble, try to use it. We only allow
   // the use of the precompiled preamble if we're if the completion
   // point is within the main file, after the end of the precompiled
   // preamble.
   std::unique_ptr OverrideMainBuffer;
-  if (Preamble) {
-std::string CompleteFilePath(File);
-
-auto &VFS = FileMgr.getVirtualFileSystem();
-auto CompleteFileStatus = VFS.status(CompleteFilePath);
-if (CompleteFileStatus) {
-  llvm::sys::fs::UniqueID CompleteFileID = 
CompleteFileStatus->getUniqueID();
-
-  std::string MainPath(OriginalSourceFile);
-  auto MainStatus = VFS.status(MainPath);
-  if (MainStatus) {
-llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID();
-if (CompleteFileID == MainID && Line > 1)
-  OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
-  PCHContainerOps, Inv, &VFS, false, Line - 1);
-  }
-}
+  if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) {
+OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
+PCHContainerOps, Inv, &FileMgr.getVirtualFileSystem(), false, Line - 
1);
   }
 
   // If the main file has been overridden due to the use of a preamble,



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


[clang] b85c6e5 - ARCMigrate: Use hash_combine in the DenseMapInfo for EditEntry

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T13:46:21-08:00
New Revision: b85c6e5bcd1a9de941c318f9a5dc742818752a56

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

LOG: ARCMigrate: Use hash_combine in the DenseMapInfo for EditEntry

Simplify the DenseMapInfo for `EditEntry` by migrating from
`FoldingSetNodeID` to `llvm::hash_combine`. Besides the cleanup, this
reduces the diff for a future patch which changes the type of one of the
fields.

There should be no real functionality change here, although I imagine
the hash value will churn since its a different hashing infrastructure.

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

Added: 


Modified: 
clang/lib/ARCMigrate/ObjCMT.cpp

Removed: 




diff  --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index ef2985d16d23..dfc0d9353165 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -2054,12 +2054,8 @@ template<> struct DenseMapInfo {
 return Entry;
   }
   static unsigned getHashValue(const EditEntry& Val) {
-llvm::FoldingSetNodeID ID;
-ID.AddPointer(Val.File);
-ID.AddInteger(Val.Offset);
-ID.AddInteger(Val.RemoveLen);
-ID.AddString(Val.Text);
-return ID.ComputeHash();
+return (unsigned)llvm::hash_combine(Val.File, Val.Offset, Val.RemoveLen,
+Val.Text);
   }
   static bool isEqual(const EditEntry &LHS, const EditEntry &RHS) {
 return LHS.File == RHS.File &&



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


[clang-tools-extra] 5207f19 - ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T17:33:19-08:00
New Revision: 5207f19d103dc3e0ec974fa64d2c031d84d497a8

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

LOG: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`,
and remove a couple of now-unnecessary `release()` calls.

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

Added: 


Modified: 
clang-tools-extra/clangd/support/ThreadsafeFS.cpp
clang/lib/Tooling/AllTUsExecution.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp 
b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
index cadda8efa095..ae9450f17411 100644
--- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -87,8 +87,7 @@ RealThreadsafeFS::viewImpl() const {
   // Avoid using memory-mapped files.
   // FIXME: Try to use a similar approach in Sema instead of relying on
   //propagation of the 'isVolatile' flag through all layers.
-  return new VolatileFileSystem(
-  llvm::vfs::createPhysicalFileSystem().release());
+  return new VolatileFileSystem(llvm::vfs::createPhysicalFileSystem());
 }
 } // namespace clangd
 } // namespace clang

diff  --git a/clang/lib/Tooling/AllTUsExecution.cpp 
b/clang/lib/Tooling/AllTUsExecution.cpp
index 7707c99c21d0..5565da9b548a 100644
--- a/clang/lib/Tooling/AllTUsExecution.cpp
+++ b/clang/lib/Tooling/AllTUsExecution.cpp
@@ -124,7 +124,7 @@ llvm::Error AllTUsToolExecutor::execute(
 // Each thread gets an indepent copy of a VFS to allow 
diff erent
 // concurrent working directories.
 IntrusiveRefCntPtr FS =
-llvm::vfs::createPhysicalFileSystem().release();
+llvm::vfs::createPhysicalFileSystem();
 ClangTool Tool(Compilations, {Path},
std::make_shared(), FS);
 Tool.appendArgumentsAdjuster(Action.second);

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index f10b60252715..63264b0dda2d 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -154,7 +154,7 @@ DependencyScanningWorker::DependencyScanningWorker(
 : Format(Service.getFormat()) {
   DiagOpts = new DiagnosticOptions();
   PCHContainerOps = std::make_shared();
-  RealFS = llvm::vfs::createPhysicalFileSystem().release();
+  RealFS = llvm::vfs::createPhysicalFileSystem();
   if (Service.canSkipExcludedPPRanges())
 PPSkipMappings =
 std::make_unique();

diff  --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h 
b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
index 173fad3aeafa..dcd35253c5f2 100644
--- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -58,6 +58,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -175,6 +176,11 @@ template  class IntrusiveRefCntPtr {
 S.Obj = nullptr;
   }
 
+  template 
+  IntrusiveRefCntPtr(std::unique_ptr S) : Obj(S.release()) {
+retain();
+  }
+
   template 
   IntrusiveRefCntPtr(const IntrusiveRefCntPtr &S) : Obj(S.get()) {
 retain();

diff  --git a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp 
b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
index 3d8041fcbf48..f69239162e3a 100644
--- a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
+++ b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
@@ -42,6 +42,17 @@ TYPED_TEST(IntrusiveRefCntPtrTest, 
RefCountedBaseCopyDoesNotLeak) {
   EXPECT_EQ(0, NumInstances);
 }
 
+TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) {
+  EXPECT_EQ(0, NumInstances);
+  {
+auto S1 = std::make_unique();
+IntrusiveRefCntPtr R1 = std::move(S1);
+EXPECT_EQ(1, NumInstances);
+EXPECT_EQ(S1, nullptr);
+  }
+  EXPECT_EQ(0, NumInstances);
+}
+
 struct InterceptRefCounted : public RefCountedBase {
   InterceptRefCounted(bool *Released, bool *Retained)
 : Released(Released), Retained(Retained) {}



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


[clang] 2878e96 - Basic: Add hashing support for FileEntryRef and DirectoryEntryRef

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T18:10:53-08:00
New Revision: 2878e965af27ce037378a4f0409e89039108c09f

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

LOG: Basic: Add hashing support for FileEntryRef and DirectoryEntryRef

Allow hashing FileEntryRef and DirectoryEntryRef via `hash_value`, and
use that to implement `DenseMapInfo`. This hash should be equal whenever
the entry is the same (the name used to reference it is not relevant).

Also add `DirectoryEntryRef::isSameRef` to simplify the implementation
and facilitate testing.

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

Added: 


Modified: 
clang/include/clang/Basic/DirectoryEntry.h
clang/include/clang/Basic/FileEntry.h
clang/unittests/Basic/FileEntryTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
index 4e229962bdcc..e0f4ae28321a 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -15,6 +15,8 @@
 #define LLVM_CLANG_BASIC_DIRECTORYENTRY_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorOr.h"
@@ -46,10 +48,19 @@ class DirectoryEntryRef {
 
   StringRef getName() const { return ME->getKey(); }
 
+  /// Hash code is based on the DirectoryEntry, not the specific named
+  /// reference.
+  friend llvm::hash_code hash_value(DirectoryEntryRef Ref) {
+return llvm::hash_value(&Ref.getDirEntry());
+  }
+
   using MapEntry = llvm::StringMapEntry>;
 
   const MapEntry &getMapEntry() const { return *ME; }
 
+  /// Check if RHS referenced the file in exactly the same way.
+  bool isSameRef(DirectoryEntryRef RHS) const { return ME == RHS.ME; }
+
   DirectoryEntryRef() = delete;
   DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {}
 
@@ -80,6 +91,20 @@ class DirectoryEntryRef {
   DirectoryEntryRef(optional_none_tag) : ME(nullptr) {}
   bool hasOptionalValue() const { return ME; }
 
+  friend struct llvm::DenseMapInfo;
+  struct dense_map_empty_tag {};
+  struct dense_map_tombstone_tag {};
+
+  // Private constructors for use by DenseMapInfo.
+  DirectoryEntryRef(dense_map_empty_tag)
+  : ME(llvm::DenseMapInfo::getEmptyKey()) {}
+  DirectoryEntryRef(dense_map_tombstone_tag)
+  : ME(llvm::DenseMapInfo::getTombstoneKey()) {}
+  bool isSpecialDenseMapKey() const {
+return isSameRef(DirectoryEntryRef(dense_map_empty_tag())) ||
+   isSameRef(DirectoryEntryRef(dense_map_tombstone_tag()));
+  }
+
   const MapEntry *ME;
 };
 
@@ -164,6 +189,38 @@ static_assert(
 "Optional should be trivially copyable");
 
 } // end namespace optional_detail
+
+/// Specialisation of DenseMapInfo for DirectoryEntryRef.
+template <> struct DenseMapInfo {
+  static inline clang::DirectoryEntryRef getEmptyKey() {
+return clang::DirectoryEntryRef(
+clang::DirectoryEntryRef::dense_map_empty_tag());
+  }
+
+  static inline clang::DirectoryEntryRef getTombstoneKey() {
+return clang::DirectoryEntryRef(
+clang::DirectoryEntryRef::dense_map_tombstone_tag());
+  }
+
+  static unsigned getHashValue(clang::DirectoryEntryRef Val) {
+return hash_value(Val);
+  }
+
+  static bool isEqual(clang::DirectoryEntryRef LHS,
+  clang::DirectoryEntryRef RHS) {
+// Catch the easy cases: both empty, both tombstone, or the same ref.
+if (LHS.isSameRef(RHS))
+  return true;
+
+// Confirm LHS and RHS are valid.
+if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey())
+  return false;
+
+// It's safe to use operator==.
+return LHS == RHS;
+  }
+};
+
 } // end namespace llvm
 
 namespace clang {

diff  --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index 75158d44bf5a..8db5446aa8d4 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -16,6 +16,8 @@
 
 #include "clang/Basic/DirectoryEntry.h"
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -88,6 +90,12 @@ class FileEntryRef {
 return !(LHS == RHS);
   }
 
+  /// Hash code is based on the FileEntry, not the specific named reference,
+  /// just like operator==.
+  friend llvm::hash_code hash_value(FileEntryRef Ref) {
+return llvm::hash_value(&Ref.getFileEntry());
+  }
+
   struct MapValue;
 
   /// Type used in the StringMap.
@@ -154,6 +162,20 @@ class FileEntryRef {
   FileEntryRef(optional_none_tag) : ME(nullptr) {}
   bool hasOptionalValue() const { return ME; }
 
+  friend struct l

[clang] 8278922 - Frontend: Migrate to FileEntryRef in VerifyDiagnosticConsumer.cpp, NFC

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T11:51:43-08:00
New Revision: 82789228c65317ceea3fdcc08c573c5ca780021e

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

LOG: Frontend: Migrate to FileEntryRef in VerifyDiagnosticConsumer.cpp, NFC

Add a `FileEntryRef` overload of `SourceManager::translateFile`, and
migrate `ParseDirective` in VerifyDiagnosticConsumer.cpp to use it and
the corresponding overload of `createFileID`.

No functionality change here.

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

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 459bd088f0d7..05edc98f9ec8 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1582,6 +1582,9 @@ class SourceManager : public 
RefCountedBase {
   /// If the source file is included multiple times, the FileID will be the
   /// first inclusion.
   FileID translateFile(const FileEntry *SourceFile) const;
+  FileID translateFile(FileEntryRef SourceFile) const {
+return translateFile(&SourceFile.getFileEntry());
+  }
 
   /// Get the source location in \p FID for the given line:col.
   /// Returns null location if \p FID is not a file SLocEntry.

diff  --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp 
b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index a10a3dd8a446..0503ae46a15f 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -554,10 +554,9 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, 
SourceManager &SM,
 continue;
   }
 
-  const FileEntry *FE = &File->getFileEntry();
-  FileID FID = SM.translateFile(FE);
+  FileID FID = SM.translateFile(*File);
   if (FID.isInvalid())
-FID = SM.createFileID(FE, Pos, SrcMgr::C_User);
+FID = SM.createFileID(*File, Pos, SrcMgr::C_User);
 
   if (PH.Next(Line) && Line > 0)
 ExpectedLoc = SM.translateLineCol(FID, Line, 1);



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


[clang] a5c89bb - Frontend: Migrate to FileEntryRef in CompilerInstance::InitializeSourceManager, NFC

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T13:28:29-08:00
New Revision: a5c89bb02195a97aa71a406d9864098c764f

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

LOG: Frontend: Migrate to FileEntryRef in 
CompilerInstance::InitializeSourceManager, NFC

Use `FileManager::getVirtualFileRef` to get the virtual file for stdin,
and add an overload of `SourceManager::overrideFileContents` that takes
a `FileEntryRef`, migrating `CompilerInstance::InitializeSourceManager`.

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

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 05edc98f9ec8..e067cd8fad83 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -958,6 +958,10 @@ class SourceManager : public RefCountedBase 
{
   /// data in the given source file.
   void overrideFileContents(const FileEntry *SourceFile,
 std::unique_ptr Buffer);
+  void overrideFileContents(FileEntryRef SourceFile,
+std::unique_ptr Buffer) {
+overrideFileContents(&SourceFile.getFileEntry(), std::move(Buffer));
+  }
 
   /// Override the given source file with another one.
   ///

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index fa3d50aeedfe..92e5208b193b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -891,8 +891,8 @@ bool CompilerInstance::InitializeSourceManager(const 
FrontendInputFile &Input,
 }
 std::unique_ptr SB = std::move(SBOrErr.get());
 
-const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
-   SB->getBufferSize(), 0);
+FileEntryRef File = FileMgr.getVirtualFileRef(SB->getBufferIdentifier(),
+  SB->getBufferSize(), 0);
 SourceMgr.setMainFileID(
 SourceMgr.createFileID(File, SourceLocation(), Kind));
 SourceMgr.overrideFileContents(File, std::move(SB));



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


[clang] 898d61b - ARCMigrate: Migrate ObjCMT.cpp over to FileEntryRef

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T14:16:05-08:00
New Revision: 898d61b3cff5d79870d964c76d82764fef73efbb

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

LOG: ARCMigrate: Migrate ObjCMT.cpp over to FileEntryRef

Migrate ObjCMT.cpp from using `const FileEntry*` to `FileEntryRef`. This
is one of the blockers for changing `SourceManager` to use
`FileEntryRef`.

This adds an initial version of `SourceManager::getFileEntryRefForID`,
which uses to `FileEntry::getLastRef`; after `SourceManager` switches,
`SourceManager::getFileEntryForID` will need to call this function.

This also adds uses of `FileEntryRef` as a key in a `DenseMap`, and a
call to `hash_value(Optional)` in `DenseMapInfo`; support for
these were added in prep commits.

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

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/ARCMigrate/ObjCMT.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index e067cd8fad83..a43b47662180 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1033,6 +1033,13 @@ class SourceManager : public 
RefCountedBase {
 return nullptr;
   }
 
+  /// Returns the FileEntryRef for the provided FileID.
+  Optional getFileEntryRefForID(FileID FID) const {
+if (auto *Entry = getFileEntryForID(FID))
+  return Entry->getLastRef();
+return None;
+  }
+
   /// Returns the filename for the provided FileID, unless it's a built-in
   /// buffer that's not represented by a filename.
   ///

diff  --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index dfc0d9353165..68a51a49c718 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -156,7 +156,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
 return WhiteListFilenames.find(llvm::sys::path::filename(Path))
 != WhiteListFilenames.end();
   }
-  bool canModifyFile(const FileEntry *FE) {
+  bool canModifyFile(Optional FE) {
 if (!FE)
   return false;
 return canModifyFile(FE->getName());
@@ -164,7 +164,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
   bool canModifyFile(FileID FID) {
 if (FID.isInvalid())
   return false;
-return canModifyFile(PP.getSourceManager().getFileEntryForID(FID));
+return canModifyFile(PP.getSourceManager().getFileEntryRefForID(FID));
   }
 
   bool canModify(const Decl *D) {
@@ -1964,7 +1964,7 @@ void 
ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
 I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
 FileID FID = I->first;
 RewriteBuffer &buf = I->second;
-const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
+Optional file = 
Ctx.getSourceManager().getFileEntryRefForID(FID);
 assert(file);
 SmallString<512> newText;
 llvm::raw_svector_ostream vecOS(newText);
@@ -2034,7 +2034,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance 
&CI, StringRef InFile) {
 
 namespace {
 struct EditEntry {
-  const FileEntry *File = nullptr;
+  Optional File;
   unsigned Offset = 0;
   unsigned RemoveLen = 0;
   std::string Text;
@@ -2127,9 +2127,8 @@ class RemapFileParser {
   StringRef Val = ValueString->getValue(ValueStorage);
 
   if (Key == "file") {
-auto FE = FileMgr.getFile(Val);
-if (FE)
-  Entry.File = *FE;
+if (auto File = FileMgr.getOptionalFileRef(Val))
+  Entry.File = File;
 else
   Ignore = true;
   } else if (Key == "offset") {
@@ -2155,7 +2154,7 @@ static bool reportDiag(const Twine &Err, 
DiagnosticsEngine &Diag) {
   return true;
 }
 
-static std::string applyEditsToTemp(const FileEntry *FE,
+static std::string applyEditsToTemp(FileEntryRef FE,
 ArrayRef Edits,
 FileManager &FileMgr,
 DiagnosticsEngine &Diag) {
@@ -2199,8 +2198,8 @@ static std::string applyEditsToTemp(const FileEntry *FE,
 
   SmallString<64> TempPath;
   int FD;
-  if (fs::createTemporaryFile(path::filename(FE->getName()),
-  path::extension(FE->getName()).drop_front(), FD,
+  if (fs::createTemporaryFile(path::filename(FE.getName()),
+  path::extension(FE.getName()).drop_front(), FD,
   TempPath)) {
 reportDiag("Could not create file: " + TempPath.str(), Diag);
 return std::string();
@@ -2228,7 +2227,7 @@ bool arcmt::getFileRemappingsFromFileList(
   new DiagnosticsEngine(DiagID, new DiagnosticOptions,
 DiagClient, /*ShouldOwnClient=*/false)

[clang] c3ff993 - Remove RemappedFiles param from ASTUnit::LoadFromASTFile, NFC

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T14:44:31-08:00
New Revision: c3ff9939bf7efeb11da49f100a277b4d8bbeff9f

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

LOG: Remove RemappedFiles param from ASTUnit::LoadFromASTFile, NFC

This parameter is always set to `None`. Remove it.

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

Added: 


Modified: 
clang/include/clang/Frontend/ASTUnit.h
clang/lib/Frontend/ASTUnit.cpp
clang/tools/c-index-test/core_main.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/ASTUnit.h 
b/clang/include/clang/Frontend/ASTUnit.h
index 5bee57042ca6..6cf9f3ff936f 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -688,14 +688,15 @@ class ASTUnit {
   /// lifetime is expected to extend past that of the returned ASTUnit.
   ///
   /// \returns - The initialized ASTUnit or null if the AST failed to load.
-  static std::unique_ptr LoadFromASTFile(
-  const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
-  WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
-  const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false,
-  bool OnlyLocalDecls = false, ArrayRef RemappedFiles = None,
-  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
-  bool AllowASTWithCompilerErrors = false,
-  bool UserFilesAreVolatile = false);
+  static std::unique_ptr
+  LoadFromASTFile(const std::string &Filename,
+  const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad,
+  IntrusiveRefCntPtr Diags,
+  const FileSystemOptions &FileSystemOpts,
+  bool UseDebugInfo = false, bool OnlyLocalDecls = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowASTWithCompilerErrors = false,
+  bool UserFilesAreVolatile = false);
 
 private:
   /// Helper function for \c LoadFromCompilerInvocation() and

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index d9154e9b459e..51851a5bac83 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -758,9 +758,8 @@ std::unique_ptr ASTUnit::LoadFromASTFile(
 const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
 const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
-bool OnlyLocalDecls, ArrayRef RemappedFiles,
-CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors,
-bool UserFilesAreVolatile) {
+bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
+bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
   std::unique_ptr AST(new ASTUnit(true));
 
   // Recover resources if we crash before exiting this method.
@@ -793,9 +792,6 @@ std::unique_ptr ASTUnit::LoadFromASTFile(
  /*Target=*/nullptr));
   AST->PPOpts = std::make_shared();
 
-  for (const auto &RemappedFile : RemappedFiles)
-AST->PPOpts->addRemappedFile(RemappedFile.first, RemappedFile.second);
-
   // Gather Info for preprocessor construction later on.
 
   HeaderSearch &HeaderInfo = *AST->HeaderInfo;

diff  --git a/clang/tools/c-index-test/core_main.cpp 
b/clang/tools/c-index-test/core_main.cpp
index c6d59d703d17..ed0d99b9d199 100644
--- a/clang/tools/c-index-test/core_main.cpp
+++ b/clang/tools/c-index-test/core_main.cpp
@@ -262,7 +262,7 @@ static bool printSourceSymbolsFromModule(StringRef 
modulePath,
   std::unique_ptr AU = ASTUnit::LoadFromASTFile(
   std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags,
   FileSystemOpts, /*UseDebugInfo=*/false,
-  /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None,
+  /*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
   /*AllowASTWithCompilerErrors=*/true,
   /*UserFilesAreVolatile=*/false);
   if (!AU) {

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 95ff9aa35bfa..aa888a380048 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -3475,7 +3475,7 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex 
CIdx,
   std::unique_ptr AU = ASTUnit::LoadFromASTFile(
   ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(),
   ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false,
-  CXXIdx->getOnlyLocalDecls(), None, CaptureDiagsKind::All,
+  CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All,
   /*AllowASTWithCompilerErrors=*/true,
   /*UserFilesAreVolatile=*/true);
   *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU));



___

[clang] 75a95bc - clang-format: Migrate createInMemoryFile to FileEntryRef, NFC

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T15:00:53-08:00
New Revision: 75a95bc80eae0c539b342f2cb19a92a0de02d2e1

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

LOG: clang-format: Migrate createInMemoryFile to FileEntryRef, NFC

Added: 


Modified: 
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 121c9626b261..a1b42a6d0940 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -178,7 +178,7 @@ static FileID createInMemoryFile(StringRef FileName, 
MemoryBufferRef Source,
  SourceManager &Sources, FileManager &Files,
  llvm::vfs::InMemoryFileSystem *MemFS) {
   MemFS->addFileNoOwn(FileName, 0, Source);
-  auto File = Files.getFile(FileName);
+  auto File = Files.getOptionalFileRef(FileName);
   assert(File && "File not added to MemFS?");
   return Sources.createFileID(*File, SourceLocation(), SrcMgr::C_User);
 }



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


[clang] 347e1f6 - Frontend: Use a getVirtualFileRef for a named pipe main file, NFC

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T16:17:14-08:00
New Revision: 347e1f621355d9b58901f3579fde91783c24ca29

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

LOG: Frontend: Use a getVirtualFileRef for a named pipe main file, NFC

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 92e5208b193b..17875a2ed85b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -868,8 +868,8 @@ bool CompilerInstance::InitializeSourceManager(const 
FrontendInputFile &Input,
   FileMgr.getBufferForFile(&File.getFileEntry(), /*isVolatile=*/true);
   if (MB) {
 // Create a new virtual file that will have the correct size.
-const FileEntry *FE =
-FileMgr.getVirtualFile(InputFile, (*MB)->getBufferSize(), 0);
+FileEntryRef FE =
+FileMgr.getVirtualFileRef(InputFile, (*MB)->getBufferSize(), 0);
 SourceMgr.overrideFileContents(FE, std::move(*MB));
 SourceMgr.setMainFileID(
 SourceMgr.createFileID(FE, SourceLocation(), Kind));



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


[clang] 2ea8c69 - Tooling: Migrate to FileEntryRef in clang::tooling::applyAllReplacements, NFC

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T16:31:38-08:00
New Revision: 2ea8c69eff07c491c7cb14dd46afd30529b89d91

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

LOG: Tooling: Migrate to FileEntryRef in clang::tooling::applyAllReplacements, 
NFC

Migrate to the `FileEntryRef` overload of `SourceManager::createFileID`.

Added: 


Modified: 
clang/lib/Tooling/Core/Replacement.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Core/Replacement.cpp 
b/clang/lib/Tooling/Core/Replacement.cpp
index ab8e20539559..30e1923bf1cb 100644
--- a/clang/lib/Tooling/Core/Replacement.cpp
+++ b/clang/lib/Tooling/Core/Replacement.cpp
@@ -591,7 +591,7 @@ llvm::Expected applyAllReplacements(StringRef 
Code,
   Rewriter Rewrite(SourceMgr, LangOptions());
   InMemoryFileSystem->addFile(
   "", 0, llvm::MemoryBuffer::getMemBuffer(Code, ""));
-  FileID ID = SourceMgr.createFileID(*Files.getFile(""),
+  FileID ID = SourceMgr.createFileID(*Files.getOptionalFileRef(""),
  SourceLocation(),
  clang::SrcMgr::C_User);
   for (auto I = Replaces.rbegin(), E = Replaces.rend(); I != E; ++I) {



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


[clang-tools-extra] 028e55d - clangd: Migrate to FileEntryRef in TweakTests, NFC

2020-12-09 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-09T17:00:42-08:00
New Revision: 028e55d2d411f19e193e3d5df589162a317ab5f1

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

LOG: clangd: Migrate to FileEntryRef in TweakTests, NFC

Added: 


Modified: 
clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp
index cb0b38dc99ec..8c8dc5530e09 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp
@@ -53,7 +53,7 @@ TEST(FileEdits, AbsolutePath) {
   SourceManager SM(DE, FM);
 
   for (const auto *Path : RelPaths) {
-auto FID = SM.createFileID(*FM.getFile(Path), SourceLocation(),
+auto FID = SM.createFileID(*FM.getOptionalFileRef(Path), SourceLocation(),
clang::SrcMgr::C_User);
 auto Res = Tweak::Effect::fileEdit(SM, FID, tooling::Replacements());
 ASSERT_THAT_EXPECTED(Res, llvm::Succeeded());



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


[clang] 0978c83 - Basic: Initialize FileEntry's fields inline, almost NFC

2020-12-10 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-10T13:57:21-08:00
New Revision: 0978c83e6fcc7a8aea18e24eb3b2ad5523581757

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

LOG: Basic: Initialize FileEntry's fields inline, almost NFC

Initialize most of FileEntry's fields inline (all the ones that can be).
The only functionality change is to avoid leaving some fields
uninitialized.

Added: 


Modified: 
clang/include/clang/Basic/FileEntry.h
clang/lib/Basic/FileEntry.cpp
clang/unittests/Basic/FileEntryTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index 8db5446aa8d4..aa7bedec44ac 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -328,13 +328,13 @@ class FileEntry {
   friend class FileManager;
 
   std::string RealPathName;   // Real path to the file; could be empty.
-  off_t Size; // File size in bytes.
-  time_t ModTime; // Modification time of file.
-  const DirectoryEntry *Dir;  // Directory file lives in.
+  off_t Size = 0; // File size in bytes.
+  time_t ModTime = 0; // Modification time of file.
+  const DirectoryEntry *Dir = nullptr; // Directory file lives in.
   llvm::sys::fs::UniqueID UniqueID;
-  unsigned UID;   // A unique (small) ID for the file.
-  bool IsNamedPipe;
-  bool IsValid;   // Is this \c FileEntry initialized and valid?
+  unsigned UID = 0; // A unique (small) ID for the file.
+  bool IsNamedPipe = false;
+  bool IsValid = false; // Is this \c FileEntry initialized and valid?
 
   /// The open file, if it is owned by the \p FileEntry.
   mutable std::unique_ptr File;

diff  --git a/clang/lib/Basic/FileEntry.cpp b/clang/lib/Basic/FileEntry.cpp
index 29218c7e0ec8..2efdcbbd46aa 100644
--- a/clang/lib/Basic/FileEntry.cpp
+++ b/clang/lib/Basic/FileEntry.cpp
@@ -16,7 +16,7 @@
 
 using namespace clang;
 
-FileEntry::FileEntry() : UniqueID(0, 0), IsNamedPipe(false), IsValid(false) {}
+FileEntry::FileEntry() : UniqueID(0, 0) {}
 
 FileEntry::~FileEntry() = default;
 

diff  --git a/clang/unittests/Basic/FileEntryTest.cpp 
b/clang/unittests/Basic/FileEntryTest.cpp
index 3cc01870b800..a3e03e6c7c29 100644
--- a/clang/unittests/Basic/FileEntryTest.cpp
+++ b/clang/unittests/Basic/FileEntryTest.cpp
@@ -55,6 +55,17 @@ struct RefMaps {
   }
 };
 
+TEST(FileEntryTest, Constructor) {
+  FileEntry FE;
+  EXPECT_EQ(0U, FE.getSize());
+  EXPECT_EQ(0, FE.getModificationTime());
+  EXPECT_EQ(nullptr, FE.getDir());
+  EXPECT_EQ(0U, FE.getUniqueID().getDevice());
+  EXPECT_EQ(0U, FE.getUniqueID().getFile());
+  EXPECT_EQ(false, FE.isNamedPipe());
+  EXPECT_EQ(false, FE.isValid());
+}
+
 TEST(FileEntryTest, FileEntryRef) {
   RefMaps Refs;
   FileEntryRef R1 = Refs.addFile("1");



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


[clang] 494aacd - Tooling: Migrate some tests to FileEntryRef, NFC

2020-12-10 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-10T18:05:03-08:00
New Revision: 494aacd72c6a85a6d586fa58a8481e13b68acf24

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

LOG: Tooling: Migrate some tests to FileEntryRef, NFC

Migrate to the `FileEntryRef` overload of `SourceManager::createFileID`
(using `FileManager::getOptionalFileRef`) in RefactoringTest.cpp and
RewriterTestContext.h.

No functionality change.

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

Added: 


Modified: 
clang/unittests/Tooling/RefactoringTest.cpp
clang/unittests/Tooling/RewriterTestContext.h

Removed: 




diff  --git a/clang/unittests/Tooling/RefactoringTest.cpp 
b/clang/unittests/Tooling/RefactoringTest.cpp
index 97a26a71deec..d239aba31d1d 100644
--- a/clang/unittests/Tooling/RefactoringTest.cpp
+++ b/clang/unittests/Tooling/RefactoringTest.cpp
@@ -608,7 +608,7 @@ class FlushRewrittenFilesTest : public ::testing::Test {
 llvm::raw_fd_ostream OutStream(FD, true);
 OutStream << Content;
 OutStream.close();
-auto File = Context.Files.getFile(Path);
+auto File = Context.Files.getOptionalFileRef(Path);
 assert(File);
 
 StringRef Found =

diff  --git a/clang/unittests/Tooling/RewriterTestContext.h 
b/clang/unittests/Tooling/RewriterTestContext.h
index ae2d2baa0fdc..a618ebd3a865 100644
--- a/clang/unittests/Tooling/RewriterTestContext.h
+++ b/clang/unittests/Tooling/RewriterTestContext.h
@@ -70,7 +70,7 @@ class RewriterTestContext {
 llvm::MemoryBuffer::getMemBuffer(Content);
 InMemoryFileSystem->addFile(Name, 0, std::move(Source));
 
-auto Entry = Files.getFile(Name);
+auto Entry = Files.getOptionalFileRef(Name);
 assert(Entry);
 return Sources.createFileID(*Entry, SourceLocation(), SrcMgr::C_User);
   }
@@ -87,7 +87,7 @@ class RewriterTestContext {
 llvm::raw_fd_ostream OutStream(FD, true);
 OutStream << Content;
 OutStream.close();
-auto File = Files.getFile(Path);
+auto File = Files.getOptionalFileRef(Path);
 assert(File);
 
 StringRef Found =



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


[clang] a600432 - Frontend: Migrate to FileEntryRef in TextDiagnosticTest, NFC

2020-12-11 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-11T17:06:28-08:00
New Revision: a60043219907b8f370263b7d3d4827b83388d8cf

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

LOG: Frontend: Migrate to FileEntryRef in TextDiagnosticTest, NFC

Migrate over to the `FileEntryRef` overloads of
`SourceManager::createFileID` and `overrideFileContents` (using
`getVirtualFileRef`) in `TextDiagnostic`'s `ShowLine` test.

No functionality change.

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

Added: 


Modified: 
clang/unittests/Frontend/TextDiagnosticTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/TextDiagnosticTest.cpp 
b/clang/unittests/Frontend/TextDiagnosticTest.cpp
index 1e05104d9388..220cff6643d5 100644
--- a/clang/unittests/Frontend/TextDiagnosticTest.cpp
+++ b/clang/unittests/Frontend/TextDiagnosticTest.cpp
@@ -46,7 +46,7 @@ TEST(TextDiagnostic, ShowLine) {
   // Create a dummy file with some contents to produce a test SourceLocation.
   const llvm::StringRef file_path = "main.cpp";
   const llvm::StringRef main_file_contents = "some\nsource\ncode\n";
-  const clang::FileEntry &fe = *FileMgr.getVirtualFile(
+  const clang::FileEntryRef fe = FileMgr.getVirtualFileRef(
   file_path,
   /*Size=*/static_cast(main_file_contents.size()),
   /*ModificationTime=*/0);
@@ -55,11 +55,11 @@ TEST(TextDiagnostic, ShowLine) {
   buffer.append(main_file_contents.begin(), main_file_contents.end());
   auto file_contents = std::make_unique(
   std::move(buffer), file_path);
-  SrcMgr.overrideFileContents(&fe, std::move(file_contents));
+  SrcMgr.overrideFileContents(fe, std::move(file_contents));
 
   // Create the actual file id and use it as the main file.
   clang::FileID fid =
-  SrcMgr.createFileID(&fe, SourceLocation(), clang::SrcMgr::C_User);
+  SrcMgr.createFileID(fe, SourceLocation(), clang::SrcMgr::C_User);
   SrcMgr.setMainFileID(fid);
 
   // Create the source location for the test diagnostic.



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


[clang] 8c86197 - clang-import-test: Clean up error output for files that cannot be found

2020-12-11 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-11T17:07:58-08:00
New Revision: 8c86197de3cba4257f26133e837d64e5f8ece210

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

LOG: clang-import-test: Clean up error output for files that cannot be found

Pass on the filesystem error string `FileManager::getFileRef` in
`clang-import-test`'s `ParseSource` function. Also include "error:" and
a newline in the output. As a side effect, migrate to the `FileEntryRef`
overload of `SourceManager::createFileID`.

No real functionality change here, just slightly better output on error.

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

Added: 


Modified: 
clang/test/Import/missing-import/test.c
clang/tools/clang-import-test/clang-import-test.cpp

Removed: 




diff  --git a/clang/test/Import/missing-import/test.c 
b/clang/test/Import/missing-import/test.c
index acf6389cc5fc..9a16c2bf4ac8 100644
--- a/clang/test/Import/missing-import/test.c
+++ b/clang/test/Import/missing-import/test.c
@@ -1,5 +1,5 @@
 // RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | 
FileCheck %s
-// CHECK: {{.*}}Couldn't open{{.*}}Inputs/S.c{{.*}}
+// CHECK: error: No such file or directory: {{.*}}Inputs/S.c{{$}}
 void expr() {
   struct S MyS;
   void *MyPtr = &MyS;

diff  --git a/clang/tools/clang-import-test/clang-import-test.cpp 
b/clang/tools/clang-import-test/clang-import-test.cpp
index eca3012957a3..5e84c5f97851 100644
--- a/clang/tools/clang-import-test/clang-import-test.cpp
+++ b/clang/tools/clang-import-test/clang-import-test.cpp
@@ -289,10 +289,11 @@ CIAndOrigins BuildIndirect(CIAndOrigins &CI) {
 llvm::Error ParseSource(const std::string &Path, CompilerInstance &CI,
 ASTConsumer &Consumer) {
   SourceManager &SM = CI.getSourceManager();
-  auto FE = CI.getFileManager().getFile(Path);
+  auto FE = CI.getFileManager().getFileRef(Path);
   if (!FE) {
 return llvm::make_error(
-llvm::Twine("Couldn't open ", Path), std::error_code());
+llvm::Twine(llvm::toString(FE.takeError())) + ": " + Path,
+std::error_code());
   }
   SM.setMainFileID(SM.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
   ParseAST(CI.getPreprocessor(), &Consumer, CI.getASTContext());
@@ -360,7 +361,7 @@ int main(int argc, const char **argv) {
   for (auto I : Imports) {
 llvm::Expected ImportCI = Parse(I, {}, false, false);
 if (auto E = ImportCI.takeError()) {
-  llvm::errs() << llvm::toString(std::move(E));
+  llvm::errs() << "error: " << llvm::toString(std::move(E)) << "\n";
   exit(-1);
 }
 ImportCIs.push_back(std::move(*ImportCI));
@@ -379,7 +380,7 @@ int main(int argc, const char **argv) {
   Parse(Expression, (Direct && !UseOrigins) ? ImportCIs : IndirectCIs,
 DumpAST, DumpIR);
   if (auto E = ExpressionCI.takeError()) {
-llvm::errs() << llvm::toString(std::move(E));
+llvm::errs() << "error: " << llvm::toString(std::move(E)) << "\n";
 exit(-1);
   }
   Forget(*ExpressionCI, (Direct && !UseOrigins) ? ImportCIs : IndirectCIs);



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


[clang] e095959 - Fixup for 8c86197de3cba4257f26133e837d64e5f8ece210 to avoid making it platform-dependent

2020-12-11 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-11T17:34:00-08:00
New Revision: e095959e0c23e250d6ad1dbe3612291736d12e1a

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

LOG: Fixup for 8c86197de3cba4257f26133e837d64e5f8ece210 to avoid making it 
platform-dependent

Added: 


Modified: 
clang/tools/clang-import-test/clang-import-test.cpp

Removed: 




diff  --git a/clang/tools/clang-import-test/clang-import-test.cpp 
b/clang/tools/clang-import-test/clang-import-test.cpp
index 5e84c5f97851..df173cf49f35 100644
--- a/clang/tools/clang-import-test/clang-import-test.cpp
+++ b/clang/tools/clang-import-test/clang-import-test.cpp
@@ -291,9 +291,9 @@ llvm::Error ParseSource(const std::string &Path, 
CompilerInstance &CI,
   SourceManager &SM = CI.getSourceManager();
   auto FE = CI.getFileManager().getFileRef(Path);
   if (!FE) {
+llvm::consumeError(FE.takeError());
 return llvm::make_error(
-llvm::Twine(llvm::toString(FE.takeError())) + ": " + Path,
-std::error_code());
+llvm::Twine("No such file or directory: ", Path), std::error_code());
   }
   SM.setMainFileID(SM.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
   ParseAST(CI.getPreprocessor(), &Consumer, CI.getASTContext());



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


[clang] a40db55 - Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef

2020-12-14 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-14T14:35:11-08:00
New Revision: a40db5502b2515a6f2f1676b5d7a655ae0f41179

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

LOG: Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef

Migrate `HeaderSearch::LoadedModuleMaps` and a number of APIs over to
`FileEntryRef`. This should have no functionality change. Note that two
`FileEntryRef`s hash the same if they point at the same `FileEntry`.

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

Added: 


Modified: 
clang-tools-extra/modularize/ModularizeUtilities.cpp
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/ModuleMap.cpp

Removed: 




diff  --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp 
b/clang-tools-extra/modularize/ModularizeUtilities.cpp
index 200370c135df..7470c324bbdb 100644
--- a/clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -258,22 +258,22 @@ std::error_code 
ModularizeUtilities::loadProblemHeaderList(
 std::error_code ModularizeUtilities::loadModuleMap(
 llvm::StringRef InputPath) {
   // Get file entry for module.modulemap file.
-  auto ModuleMapEntryOrErr =
-SourceMgr->getFileManager().getFile(InputPath);
+  auto ExpectedModuleMapEntry =
+SourceMgr->getFileManager().getFileRef(InputPath);
 
   // return error if not found.
-  if (!ModuleMapEntryOrErr) {
+  if (!ExpectedModuleMapEntry) {
 llvm::errs() << "error: File \"" << InputPath << "\" not found.\n";
-return ModuleMapEntryOrErr.getError();
+return errorToErrorCode(ExpectedModuleMapEntry.takeError());
   }
-  const FileEntry *ModuleMapEntry = *ModuleMapEntryOrErr;
+  FileEntryRef ModuleMapEntry = *ExpectedModuleMapEntry;
 
   // Because the module map parser uses a ForwardingDiagnosticConsumer,
   // which doesn't forward the BeginSourceFile call, we do it explicitly here.
   DC.BeginSourceFile(*LangOpts, nullptr);
 
   // Figure out the home directory for the module map file.
-  const DirectoryEntry *Dir = ModuleMapEntry->getDir();
+  const DirectoryEntry *Dir = ModuleMapEntry.getDir();
   StringRef DirName(Dir->getName());
   if (llvm::sys::path::filename(DirName) == "Modules") {
 DirName = llvm::sys::path::parent_path(DirName);

diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 93d6ea72270a..8ea81226cf77 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -239,7 +239,7 @@ class HeaderSearch {
 
   /// Set of module map files we've already loaded, and a flag indicating
   /// whether they were valid or not.
-  llvm::DenseMap LoadedModuleMaps;
+  llvm::DenseMap LoadedModuleMaps;
 
   /// Uniqued set of framework names, which is used to track which
   /// headers were included as framework headers.
@@ -560,8 +560,8 @@ class HeaderSearch {
 
   /// Try to find a module map file in the given directory, returning
   /// \c nullptr if none is found.
-  const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir,
-   bool IsFramework);
+  Optional lookupModuleMapFile(const DirectoryEntry *Dir,
+ bool IsFramework);
 
   /// Determine whether there is a module map that may map the header
   /// with the given file name to a (sub)module.
@@ -603,8 +603,8 @@ class HeaderSearch {
   ///used to resolve paths within the module (this is required when
   ///building the module from preprocessed source).
   /// \returns true if an error occurred, false otherwise.
-  bool loadModuleMapFile(const FileEntry *File, bool IsSystem,
- FileID ID = FileID(), unsigned *Offset = nullptr,
+  bool loadModuleMapFile(FileEntryRef File, bool IsSystem, FileID ID = 
FileID(),
+ unsigned *Offset = nullptr,
  StringRef OriginalModuleMapFile = StringRef());
 
   /// Collect the set of all known, top-level modules.
@@ -794,8 +794,7 @@ class HeaderSearch {
 LMM_InvalidModuleMap
   };
 
-  LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File,
-bool IsSystem,
+  LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
 const DirectoryEntry *Dir,
 FileID ID = FileID(),
 unsigned *Offset = nullptr);

diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 6827408f10a3..1d7ce5fc2320 100644
--- a/clan

[clang] 90d056c - AST: Silence an instance of -Wsign-compare, NFC

2020-12-14 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-14T14:36:59-08:00
New Revision: 90d056ceb97d5e3242a37dfc1c9f6bf11af9a053

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

LOG: AST: Silence an instance of -Wsign-compare, NFC

Looks this this was added by 68f53960e17d93c3a2727164dac4e54140bd98ba.

Added: 


Modified: 
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 40340cb6f9bc..de0705d3019b 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6096,7 +6096,7 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
TypedefWithAttribute) {
   FirstDeclMatcher().match(TU, typedefDecl(hasName("X")));
   auto *ToD = Import(FromD, Lang_CXX17);
   ASSERT_TRUE(ToD);
-  ASSERT_EQ(ToD->getAttrs().size(), 1);
+  ASSERT_EQ(ToD->getAttrs().size(), 1U);
   auto *ToAttr = dyn_cast(ToD->getAttrs()[0]);
   ASSERT_TRUE(ToAttr);
   EXPECT_EQ(ToAttr->getAnnotation(), "A");



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


[clang] b61f288 - Add comment to closing brace of anonymous namespace, NFC

2020-12-14 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-14T14:38:12-08:00
New Revision: b61f288a58e40430a739900ab74df61e711a2c55

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

LOG: Add comment to closing brace of anonymous namespace, NFC

Added: 


Modified: 
clang/unittests/Frontend/OutputStreamTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/OutputStreamTest.cpp 
b/clang/unittests/Frontend/OutputStreamTest.cpp
index 6a867bf053cb..5f23d782499b 100644
--- a/clang/unittests/Frontend/OutputStreamTest.cpp
+++ b/clang/unittests/Frontend/OutputStreamTest.cpp
@@ -100,4 +100,5 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) {
   EXPECT_TRUE(!VerboseBuffer.empty());
   EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
 }
-}
+
+} // anonymous namespace



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


[clang] 0eb4378 - Frontend: Fix confusing comment at call to clearOutputFiles, NFC

2020-12-15 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-15T14:21:37-08:00
New Revision: 0eb4378290ffcd5da650217df3ac3b8c473d5ed6

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

LOG: Frontend: Fix confusing comment at call to clearOutputFiles, NFC

Fix the comment in front of `compileModuleImpl`'s call to
`CompilerInstance::clearOutputFiles`. The purpose of this call is to
delete any stray temporary files after the module generation thread
crashes.

The comment is from f545f67de3a1bfdbbfad88acde5b540ce3b82f4f, and
was associated with manually deleting a generated module map. Then
13afbf42d830dd43febbeb0855aa359ca9dbfbf9 added this `clearOutputFiles`
call between the comment and the code it referenced. Finally,
1f76c4e8101b9beaf8f1b10a57faa80256ab2b05 started sending the generated
module map directly to the SourceManager instead of putting it on disk,
deleting the call that the comment referenced.

No functionality change.

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 17875a2ed85b..69e2e554d018 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1182,10 +1182,8 @@ compileModuleImpl(CompilerInstance &ImportingInstance, 
SourceLocation ImportLoc,
 diag::remark_module_build_done)
 << ModuleName;
 
-  // Delete the temporary module map file.
-  // FIXME: Even though we're executing under crash protection, it would still
-  // be nice to do this with RemoveFileOnSignal when we can. However, that
-  // doesn't make sense for all clients, so clean this up manually.
+  // Delete any remaining temporary files related to Instance, in case the
+  // module generation thread crashed.
   Instance.clearOutputFiles(/*EraseFiles=*/true);
 
   return !Instance.getDiagnostics().hasErrorOccurred();



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


Re: [PATCH] D92975: Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef

2020-12-15 Thread Duncan P. N. Exon Smith via cfe-commits
Thanks for reverting; sorry I missed your email.

> On 2020 Dec  14, at 19:27, Nico Weber via Phabricator 
>  wrote:
> 
> thakis added a comment.
> 
> The revert helped, check-clang is no longer failing on Windows.
> 
> 
> Repository:
>  rG LLVM Github Monorepo
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D92975/new/
> 
> https://reviews.llvm.org/D92975
> 

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


[clang] 245218b - Basic: Support named pipes natively in SourceManager and FileManager

2020-12-23 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-23T14:57:41-08:00
New Revision: 245218bb355599771ba43a0fe1449d1670f2666c

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

LOG: Basic: Support named pipes natively in SourceManager and FileManager

Handle named pipes natively in SourceManager and FileManager, removing a
call to `SourceManager::overrideFileContents` in
`CompilerInstance::InitializeSourceManager` (removing a blocker for
sinking the content cache to FileManager (which will incidently sink
this new named pipe logic with it)).

SourceManager usually checks if the file entry's size matches the
eventually loaded buffer, but that's now skipped for named pipes since
the `stat` won't reflect the full size.  Since we can't trust
`ContentsEntry->getSize()`, we also need shift the check for files that
are too large until after the buffer is loaded... and load the buffer
immediately in `createFileID` so that no client gets a bad value from
`ContentCache::getSize`. `FileManager::getBufferForFile` also needs to
treat these files as volatile when loading the buffer.

Native support in SourceManager / FileManager means that named pipes can
also be `#include`d, and clang/test/Misc/dev-fd-fs.c was expanded to
check for that.

This is a new version of 3b18a594c7717a328c33b9c1eba675e9f4bd367c, which
was reverted in b34632201987eed369bb7ef4646f341b901c95b8 since it was
missing the `SourceManager` changes.

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

Added: 


Modified: 
clang/lib/Basic/FileManager.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/test/Misc/dev-fd-fs.c

Removed: 




diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index c0d3685001ee..f3afe6dd5f48 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -489,7 +489,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool 
isVolatile,
   uint64_t FileSize = Entry->getSize();
   // If there's a high enough chance that the file have changed since we
   // got its size, force a stat before opening it.
-  if (isVolatile)
+  if (isVolatile || Entry->isNamedPipe())
 FileSize = -1;
 
   StringRef Filename = Entry->getName();

diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index b71b2be0cc41..d2c0de5006c4 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -115,23 +115,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, 
FileManager &FM,
   // return paths.
   IsBufferInvalid = true;
 
-  // Check that the file's size fits in an 'unsigned' (with room for a
-  // past-the-end value). This is deeply regrettable, but various parts of
-  // Clang (including elsewhere in this file!) use 'unsigned' to represent file
-  // offsets, line numbers, string literal lengths, and so on, and fail
-  // miserably on large source files.
-  if ((uint64_t)ContentsEntry->getSize() >=
-  std::numeric_limits::max()) {
-if (Diag.isDiagnosticInFlight())
-  Diag.SetDelayedDiagnostic(diag::err_file_too_large,
-ContentsEntry->getName());
-else
-  Diag.Report(Loc, diag::err_file_too_large)
-<< ContentsEntry->getName();
-
-return None;
-  }
-
   auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile);
 
   // If we were unable to open the file, then we are in an inconsistent
@@ -153,9 +136,31 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, 
FileManager &FM,
 
   Buffer = std::move(*BufferOrError);
 
-  // Check that the file's size is the same as in the file entry (which may
+  // Check that the file's size fits in an 'unsigned' (with room for a
+  // past-the-end value). This is deeply regrettable, but various parts of
+  // Clang (including elsewhere in this file!) use 'unsigned' to represent file
+  // offsets, line numbers, string literal lengths, and so on, and fail
+  // miserably on large source files.
+  //
+  // Note: ContentsEntry could be a named pipe, in which case
+  // ContentsEntry::getSize() could have the wrong size. Use
+  // MemoryBuffer::getBufferSize() instead.
+  if (Buffer->getBufferSize() >= std::numeric_limits::max()) {
+if (Diag.isDiagnosticInFlight())
+  Diag.SetDelayedDiagnostic(diag::err_file_too_large,
+ContentsEntry->getName());
+else
+  Diag.Report(Loc, diag::err_file_too_large)
+<< ContentsEntry->getName();
+
+return None;
+  }
+
+  // Unless this is a named pipe (in which case we can handle a mismatch),
+  // check that the file's size is the same as in the file entry (which may
   // have come from a stat cache).
-  if (Buffer->getBufferSize() != (size_t)ContentsEntry->

[clang] 3ee43ad - Basic: Add native support for stdin to SourceManager and FileManager

2020-12-23 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-23T15:18:50-08:00
New Revision: 3ee43adfb20d5dc56b7043b314bd22f457c55483

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

LOG: Basic: Add native support for stdin to SourceManager and FileManager

Add support for stdin to SourceManager and FileManager. Adds
FileManager::getSTDIN, which adds a FileEntryRef for `` and reads
the MemoryBuffer, which is stored as `FileEntry::Content`.

Eventually the other buffers in `ContentCache` will sink to here as well
-- we probably usually want to load/save a MemoryBuffer eagerly -- but
it's happening early for stdin to get rid of
CompilerInstance::InitializeSourceManager's final call to
`SourceManager::overrideFileContents`.

clang/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp
relies on building a module from stdin; supporting that requires setting
ContentCache::BufferOverridden.

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

Added: 


Modified: 
clang/include/clang/Basic/FileEntry.h
clang/include/clang/Basic/FileManager.h
clang/lib/Basic/FileEntry.cpp
clang/lib/Basic/FileManager.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index aa7bedec44ac..6e91b42e18b7 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -25,6 +25,9 @@
 #include "llvm/Support/FileSystem/UniqueID.h"
 
 namespace llvm {
+
+class MemoryBuffer;
+
 namespace vfs {
 
 class File;
@@ -67,6 +70,7 @@ class FileEntryRef {
   inline unsigned getUID() const;
   inline const llvm::sys::fs::UniqueID &getUniqueID() const;
   inline time_t getModificationTime() const;
+  inline bool isNamedPipe() const;
   inline void closeFile() const;
 
   /// Check if the underlying FileEntry is the same, intentially ignoring
@@ -339,6 +343,9 @@ class FileEntry {
   /// The open file, if it is owned by the \p FileEntry.
   mutable std::unique_ptr File;
 
+  /// The file content, if it is owned by the \p FileEntry.
+  std::unique_ptr Content;
+
   // First access name for this FileEntry.
   //
   // This is Optional only to allow delayed construction (FileEntryRef has no
@@ -390,6 +397,8 @@ time_t FileEntryRef::getModificationTime() const {
   return getFileEntry().getModificationTime();
 }
 
+bool FileEntryRef::isNamedPipe() const { return getFileEntry().isNamedPipe(); }
+
 void FileEntryRef::closeFile() const { getFileEntry().closeFile(); }
 
 } // end namespace clang

diff  --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 449aec2b3541..974771a8f8f3 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -99,6 +99,9 @@ class FileManager : public RefCountedBase {
   std::unique_ptr>>
   SeenBypassFileEntries;
 
+  /// The file entry for stdin, if it has been accessed through the 
FileManager.
+  Optional STDIN;
+
   /// The canonical names of files and directories .
   llvm::DenseMap CanonicalNames;
 
@@ -217,6 +220,14 @@ class FileManager : public RefCountedBase {
   bool OpenFile = false,
   bool CacheFailure = true);
 
+  /// Get the FileEntryRef for stdin, returning an error if stdin cannot be
+  /// read.
+  ///
+  /// This reads and caches stdin before returning. Subsequent calls return the
+  /// same file entry, and a reference to the cached input is returned by calls
+  /// to getBufferForFile.
+  llvm::Expected getSTDIN();
+
   /// Get a FileEntryRef if it exists, without doing anything on error.
   llvm::Optional getOptionalFileRef(StringRef Filename,
   bool OpenFile = false,

diff  --git a/clang/lib/Basic/FileEntry.cpp b/clang/lib/Basic/FileEntry.cpp
index 2efdcbbd46aa..5ee9bef9523e 100644
--- a/clang/lib/Basic/FileEntry.cpp
+++ b/clang/lib/Basic/FileEntry.cpp
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "clang/Basic/FileEntry.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang;

diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index f3afe6dd5f48..6e9d5d7fb422 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -338,6 +338,25 @@ FileManager::getFileRef(StringRef Filename, bool openFile, 
bool CacheFailure) {
   return ReturnedRef;
 }
 
+llvm::Expected FileManager::getSTDIN() {
+  // Only read stdin once.
+  if (STDIN)
+return *STDIN;
+
+  std::unique_ptr Content;
+  if (auto ContentOrError = llvm

[clang] 77a9e0a - Basic: Split out DirectoryEntry.h, NFC

2020-11-04 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-04T14:11:57-05:00
New Revision: 77a9e0a4af5aea3795ed79a0db61ee5b19b837e4

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

LOG: Basic: Split out DirectoryEntry.h, NFC

Move `DirectoryEntry` and `DirectoryEntryRef` into their own header,
similar to the creation of FileEntry.h. No functionality change here,
just preparing to include it in more places to allow wider adoption of
`DirectoryEntryRef` without requiring all of `FileManager.h`.

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

Added: 
clang/include/clang/Basic/DirectoryEntry.h

Modified: 
clang/include/clang/Basic/FileManager.h

Removed: 




diff  --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
new file mode 100644
index ..7c634709ca9b
--- /dev/null
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -0,0 +1,56 @@
+//===- clang/Basic/DirectoryEntry.h - Directory references --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_BASIC_DIRECTORYENTRY_H
+#define LLVM_CLANG_BASIC_DIRECTORYENTRY_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ErrorOr.h"
+
+namespace clang {
+
+/// Cached information about one directory (either on disk or in
+/// the virtual file system).
+class DirectoryEntry {
+  friend class FileManager;
+
+  // FIXME: We should not be storing a directory entry name here.
+  StringRef Name; // Name of the directory.
+
+public:
+  StringRef getName() const { return Name; }
+};
+
+/// A reference to a \c DirectoryEntry  that includes the name of the directory
+/// as it was accessed by the FileManager's client.
+class DirectoryEntryRef {
+public:
+  const DirectoryEntry &getDirEntry() const { return *Entry->getValue(); }
+
+  StringRef getName() const { return Entry->getKey(); }
+
+private:
+  friend class FileManager;
+
+  DirectoryEntryRef(
+  llvm::StringMapEntry> *Entry)
+  : Entry(Entry) {}
+
+  const llvm::StringMapEntry> *Entry;
+};
+
+} // end namespace clang
+
+#endif // LLVM_CLANG_BASIC_DIRECTORYENTRY_H

diff  --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 224f87ffcb26..d7135a4f0ac3 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_BASIC_FILEMANAGER_H
 #define LLVM_CLANG_BASIC_FILEMANAGER_H
 
+#include "clang/Basic/DirectoryEntry.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/FileSystemOptions.h"
 #include "clang/Basic/LLVM.h"
@@ -42,36 +43,6 @@ namespace clang {
 
 class FileSystemStatCache;
 
-/// Cached information about one directory (either on disk or in
-/// the virtual file system).
-class DirectoryEntry {
-  friend class FileManager;
-
-  // FIXME: We should not be storing a directory entry name here.
-  StringRef Name; // Name of the directory.
-
-public:
-  StringRef getName() const { return Name; }
-};
-
-/// A reference to a \c DirectoryEntry  that includes the name of the directory
-/// as it was accessed by the FileManager's client.
-class DirectoryEntryRef {
-public:
-  const DirectoryEntry &getDirEntry() const { return *Entry->getValue(); }
-
-  StringRef getName() const { return Entry->getKey(); }
-
-private:
-  friend class FileManager;
-
-  DirectoryEntryRef(
-  llvm::StringMapEntry> *Entry)
-  : Entry(Entry) {}
-
-  const llvm::StringMapEntry> *Entry;
-};
-
 /// Implements support for file system lookup, file system caching,
 /// and directory search management.
 ///



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


[clang] 6e73cfa - Basic: Change Module::Umbrella to a PointerUnion, NFC

2020-11-04 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-04T16:19:39-05:00
New Revision: 6e73cfa8363d43689f77b0e4e4c2787ae6ae3fb6

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

LOG: Basic: Change Module::Umbrella to a PointerUnion, NFC

Change `Module::Umbrella` from a `const void *` to a `PointerUnion` of
`FileEntry` and `DirectoryEntry`. We can drop the `HasUmbrellaDir` bit
(since `PointerUnion` includes that).

This change makes it safer to update to `FileEntryRef` and
`DirectoryEntryRef` in a future patch.

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

Added: 


Modified: 
clang/include/clang/Basic/Module.h
clang/lib/Basic/Module.cpp
clang/lib/Lex/ModuleMap.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 5a4975f25b72..82ea1f462949 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_BASIC_MODULE_H
 #define LLVM_CLANG_BASIC_MODULE_H
 
+#include "clang/Basic/DirectoryEntry.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -44,8 +45,6 @@ class raw_ostream;
 
 namespace clang {
 
-class DirectoryEntry;
-class FileEntry;
 class FileManager;
 class LangOptions;
 class TargetInfo;
@@ -134,7 +133,7 @@ class Module {
   std::string PresumedModuleMapFile;
 
   /// The umbrella header or directory.
-  const void *Umbrella = nullptr;
+  llvm::PointerUnion Umbrella;
 
   /// The module signature.
   ASTFileSignature Signature;
@@ -303,9 +302,6 @@ class Module {
   /// to a regular (public) module map.
   unsigned ModuleMapIsPrivate : 1;
 
-  /// Whether Umbrella is a directory or header.
-  unsigned HasUmbrellaDir : 1;
-
   /// Describes the visibility of the various names within a
   /// particular module.
   enum NameVisibilityKind {
@@ -548,15 +544,16 @@ class Module {
   /// Retrieve the header that serves as the umbrella header for this
   /// module.
   Header getUmbrellaHeader() const {
-if (!HasUmbrellaDir)
-  return Header{UmbrellaAsWritten,
-static_cast(Umbrella)};
+if (auto *FE = Umbrella.dyn_cast())
+  return Header{UmbrellaAsWritten, FE};
 return Header{};
   }
 
   /// Determine whether this module has an umbrella directory that is
   /// not based on an umbrella header.
-  bool hasUmbrellaDir() const { return Umbrella && HasUmbrellaDir; }
+  bool hasUmbrellaDir() const {
+return Umbrella && Umbrella.is();
+  }
 
   /// Add a top-level header associated with this module.
   void addTopHeader(const FileEntry *File);

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 68c1d0f77f22..8a8c400c9503 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -44,7 +44,7 @@ Module::Module(StringRef Name, SourceLocation DefinitionLoc, 
Module *Parent,
   InferSubmodules(false), InferExplicitSubmodules(false),
   InferExportWildcard(false), ConfigMacrosExhaustive(false),
   NoUndeclaredIncludes(false), ModuleMapIsPrivate(false),
-  HasUmbrellaDir(false), NameVisibility(Hidden) {
+  NameVisibility(Hidden) {
   if (Parent) {
 IsAvailable = Parent->isAvailable();
 IsUnimportable = Parent->isUnimportable();
@@ -247,7 +247,7 @@ Module::DirectoryName Module::getUmbrellaDir() const {
   if (Header U = getUmbrellaHeader())
 return {"", U.Entry->getDir()};
 
-  return {UmbrellaAsWritten, static_cast(Umbrella)};
+  return {UmbrellaAsWritten, Umbrella.dyn_cast()};
 }
 
 void Module::addTopHeader(const FileEntry *File) {

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index c47a3a0f14c4..cb49173757d8 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1125,7 +1125,6 @@ void ModuleMap::setUmbrellaHeader(Module *Mod, const 
FileEntry *UmbrellaHeader,
   Twine NameAsWritten) {
   Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
   Mod->Umbrella = UmbrellaHeader;
-  Mod->HasUmbrellaDir = false;
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
 
@@ -1137,7 +1136,6 @@ void ModuleMap::setUmbrellaHeader(Module *Mod, const 
FileEntry *UmbrellaHeader,
 void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
Twine NameAsWritten) {
   Mod->Umbrella = UmbrellaDir;
-  Mod->HasUmbrellaDir = true;
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   UmbrellaDirs[UmbrellaDir] = Mod;
 }



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


[clang] c56ec7b - Tooling: Remove dead code for ToolingInvocation::mapVirtualFile

2020-11-09 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-09T15:45:35-05:00
New Revision: c56ec7bedeb8b90cfef4c3ea8db3addfa34fde68

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

LOG: Tooling: Remove dead code for ToolingInvocation::mapVirtualFile

Follows through on c4cb3b10dc8c50e46c9fb1b7ae95e3c3c94975d3's FIXME
dating back to 2015. Anyone using this should migrate to
InMemoryFileSystem and/or ClangTool::mapVirtualFile.

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

Added: 


Modified: 
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/Tooling.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 4fb0c18be95e..8b3b2e5ad002 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -265,21 +265,12 @@ class ToolInvocation {
 this->DiagConsumer = DiagConsumer;
   }
 
-  /// Map a virtual file to be used while running the tool.
-  ///
-  /// \param FilePath The path at which the content will be mapped.
-  /// \param Content A null terminated buffer of the file's content.
-  // FIXME: remove this when all users have migrated!
-  void mapVirtualFile(StringRef FilePath, StringRef Content);
-
   /// Run the clang invocation.
   ///
   /// \returns True if there were no errors during execution.
   bool run();
 
  private:
-  void addFileMappingsTo(SourceManager &SourceManager);
-
   bool runInvocation(const char *BinaryName,
  driver::Compilation *Compilation,
  std::shared_ptr Invocation,
@@ -290,8 +281,6 @@ class ToolInvocation {
   bool OwnsAction;
   FileManager *Files;
   std::shared_ptr PCHContainerOps;
-  // Maps  -> .
-  llvm::StringMap MappedFileContents;
   DiagnosticConsumer *DiagConsumer = nullptr;
 };
 

diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index b0d3f5caf67a..063f4df2da5f 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -319,12 +319,6 @@ ToolInvocation::~ToolInvocation() {
 delete Action;
 }
 
-void ToolInvocation::mapVirtualFile(StringRef FilePath, StringRef Content) {
-  SmallString<1024> PathStorage;
-  llvm::sys::path::native(FilePath, PathStorage);
-  MappedFileContents[PathStorage] = Content;
-}
-
 bool ToolInvocation::run() {
   std::vector Argv;
   for (const std::string &Str : CommandLine)
@@ -359,14 +353,6 @@ bool ToolInvocation::run() {
 return false;
   std::unique_ptr Invocation(
   newInvocation(&Diagnostics, *CC1Args, BinaryName));
-  // FIXME: remove this when all users have migrated!
-  for (const auto &It : MappedFileContents) {
-// Inject the code as the given file name into the preprocessor options.
-std::unique_ptr Input =
-llvm::MemoryBuffer::getMemBuffer(It.getValue());
-Invocation->getPreprocessorOpts().addRemappedFile(It.getKey(),
-  Input.release());
-  }
   return runInvocation(BinaryName, Compilation.get(), std::move(Invocation),
std::move(PCHContainerOps));
 }



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


[clang] dbfa69c - Port some floating point options to new option marshalling infrastructure

2020-11-09 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Jan Svoboda
Date: 2020-11-09T18:00:10-05:00
New Revision: dbfa69c5024cfe58b8029a3766ec46c857cddb1e

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

LOG: Port some floating point options to new option marshalling infrastructure

This ports a number of OpenCL and fast-math flags for floating point
over to the new marshalling infrastructure.

As part of this, `Opt{In,Out}FFlag` were enhanced to allow other flags to
imply them, via `DefaultAnyOf<>`. For example:
```
defm signed_zeros : OptOutFFlag<"signed-zeros", ...,
  "LangOpts->NoSignedZero",
  DefaultAnyOf<[cl_no_signed_zeros, menable_unsafe_fp_math]>>;
```
defines `-fsigned-zeros` (`false`) and `-fno-signed-zeros` (`true`)
linked to the keypath `LangOpts->NoSignedZero`, defaulting to `false`,
but set to `true` implicitly if one of `-cl-no-signed-zeros` or
`-menable-unsafe-fp-math` is on.

Note that the initial patch was written Daniel Grumberg.

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

Added: 
llvm/unittests/Option/OptionMarshallingTest.cpp

Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp
llvm/include/llvm/Option/OptParser.td
llvm/unittests/Option/CMakeLists.txt
llvm/unittests/Option/Opts.td
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 1d203f8489eb..3788ae87f6b9 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -274,6 +274,9 @@ BENIGN_LANGOPT(DebuggerObjCLiteral , 1, 0, "debugger 
Objective-C literals and su
 BENIGN_LANGOPT(SpellChecking , 1, 1, "spell-checking")
 LANGOPT(SinglePrecisionConstants , 1, 0, "treating double-precision floating 
point constants as single precision constants")
 LANGOPT(FastRelaxedMath , 1, 0, "OpenCL fast relaxed math")
+BENIGN_LANGOPT(CLNoSignedZero , 1, 0, "Permit Floating Point optimization 
without regard to signed zeros")
+COMPATIBLE_LANGOPT(CLUnsafeMath , 1, 0, "Unsafe Floating Point Math")
+COMPATIBLE_LANGOPT(CLFiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined 
macro")
 /// FP_CONTRACT mode (on/off/fast).
 BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP 
contraction type")
 COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating 
point")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 33cfa72c0888..e13946f98ea4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -245,9 +245,11 @@ def clang_ignored_gcc_optimization_f_Group : OptionGroup<
 // Args.hasArg(OPT_ffoo) is used to check that the flag is enabled.
 // This is useful if the option is usually disabled.
 multiclass OptInFFlag flags=[]> {
+  string help="", list flags=[], code 
keypath="",
+  DefaultAnyOf defaults = DefaultAnyOf<[]>> {
   def f#NAME : Flag<["-"], "f"#name>, Flags,
-   Group, HelpText;
+   Group, HelpText,
+   MarshallingInfoFlag;
   def fno_#NAME : Flag<["-"], "fno-"#name>, Flags,
Group, HelpText;
 }
@@ -255,11 +257,13 @@ multiclass OptInFFlag flags=[]> {
+   string help="", list flags=[], code 
keypath="",
+   DefaultAnyOf defaults = DefaultAnyOf<[]>> {
   def f#NAME : Flag<["-"], "f"#name>, Flags,
Group, HelpText;
   def fno_#NAME : Flag<["-"], "fno-"#name>, Flags,
-   Group, HelpText;
+   Group, HelpText,
+   MarshallingInfoFlag;
 }
 
 /
@@ -563,27 +567,36 @@ def cl_opt_disable : Flag<["-"], "cl-opt-disable">, 
Group, Flags<[
 def cl_strict_aliasing : Flag<["-"], "cl-strict-aliasing">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. This option is added for compatibility with OpenCL 
1.0.">;
 def cl_single_precision_constant : Flag<["-"], 
"cl-single-precision-constant">, Group, Flags<[CC1Option]>,
-  HelpText<"OpenCL only. Treat double precision floating-point constant as 
single precision constant.">;
+  HelpText<"OpenCL only. Treat double precision floating-point constant as 
single precision constant.">,
+  MarshallingInfoFlag<"LangOpts->SinglePrecisionConstants">;
 def cl_finite_math_only : Flag<["-"], "cl-finite-math-only">, 
Group, Flags<[CC1Option]>,
-  HelpText<"OpenCL only. Allow floating-point optimizations that assume 
arguments and results are not NaNs or +-Inf.">;
+  HelpText<"OpenCL only. Allow floating-point optimizations that assume 
arguments and results are not NaNs or +-Inf.">,
+  MarshallingInfoFlag<"L

[clang] 4e9af3d - Frontend: Skip namespace around createVFSFromCompilerInvocation definition, NFC

2020-11-11 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-11T16:15:06-05:00
New Revision: 4e9af3d47847c68b0ffa8a062ae029702b06214d

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

LOG: Frontend: Skip namespace around createVFSFromCompilerInvocation 
definition, NFC

Qualify definitions with `clang::` rather than opening/closing a namespace.

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index d3516f5bf1a4..b2ce88f6cf6b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4024,16 +4024,15 @@ void CompilerInvocation::generateCC1CommandLine(
 #undef OPTION_WITH_MARSHALLING_FLAG
 }
 
-namespace clang {
-
 IntrusiveRefCntPtr
-createVFSFromCompilerInvocation(const CompilerInvocation &CI,
-DiagnosticsEngine &Diags) {
+clang::createVFSFromCompilerInvocation(const CompilerInvocation &CI,
+   DiagnosticsEngine &Diags) {
   return createVFSFromCompilerInvocation(CI, Diags,
  llvm::vfs::getRealFileSystem());
 }
 
-IntrusiveRefCntPtr createVFSFromCompilerInvocation(
+IntrusiveRefCntPtr
+clang::createVFSFromCompilerInvocation(
 const CompilerInvocation &CI, DiagnosticsEngine &Diags,
 IntrusiveRefCntPtr BaseFS) {
   if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty())
@@ -4061,5 +4060,3 @@ IntrusiveRefCntPtr 
createVFSFromCompilerInvocation(
   }
   return Result;
 }
-
-} // namespace clang



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


[clang] 4c55c3b - Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC

2020-11-11 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-11T17:19:51-05:00
New Revision: 4c55c3b66dea3a1d6058392e1e96e166d318a2ff

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

LOG: Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC

Avoid requiring an actual MemoryBuffer in ComputePreambleBounds, when
a MemoryBufferRef will do just fine.

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

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/Preamble.cpp
clang/include/clang/Frontend/PrecompiledPreamble.h
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/PrecompiledPreamble.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 24678a3cc1bc..1d85439f53af 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1104,7 +1104,7 @@ bool 
semaCodeComplete(std::unique_ptr Consumer,
   // overriding the preamble will break sema completion. Fortunately we can 
just
   // skip all includes in this case; these completions are really simple.
   PreambleBounds PreambleRegion =
-  ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
+  ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
   bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
   if (Input.Patch)
 Input.Patch->apply(*CI);

diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index 8e1ad7242eb0..f4f82be81cde 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -249,8 +249,7 @@ scanPreamble(llvm::StringRef Contents, const 
tooling::CompileCommand &Cmd) {
   // This means we're scanning (though not preprocessing) the preamble section
   // twice. However, it's important to precisely follow the preamble bounds 
used
   // elsewhere.
-  auto Bounds =
-  ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
+  auto Bounds = ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
   auto PreambleContents =
   llvm::MemoryBuffer::getMemBufferCopy(Contents.substr(0, Bounds.Size));
   auto Clang = prepareCompilerInstance(
@@ -322,8 +321,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
   // without those.
   auto ContentsBuffer =
   llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName);
-  auto Bounds =
-  ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0);
+  auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), *ContentsBuffer, 0);
 
   trace::Span Tracer("BuildPreamble");
   SPAN_ATTACH(Tracer, "File", FileName);
@@ -376,8 +374,7 @@ bool isPreambleCompatible(const PreambleData &Preamble,
   const CompilerInvocation &CI) {
   auto ContentsBuffer =
   llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName);
-  auto Bounds =
-  ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0);
+  auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), *ContentsBuffer, 0);
   auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
   return compileCommandsAreEqual(Inputs.CompileCommand,
  Preamble.CompileCommand) &&

diff  --git a/clang/include/clang/Frontend/PrecompiledPreamble.h 
b/clang/include/clang/Frontend/PrecompiledPreamble.h
index 99faf60f1a44..cea39bfec95d 100644
--- a/clang/include/clang/Frontend/PrecompiledPreamble.h
+++ b/clang/include/clang/Frontend/PrecompiledPreamble.h
@@ -41,7 +41,7 @@ class PCHContainerOperations;
 
 /// Runs lexer to compute suggested preamble bounds.
 PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts,
- const llvm::MemoryBuffer *Buffer,
+ const llvm::MemoryBufferRef &Buffer,
  unsigned MaxLines);
 
 class PreambleCallbacks;

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0728fee49d78..e1aa3682a2b7 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1317,9 +1317,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
   if (!MainFileBuffer)
 return nullptr;
 
-  PreambleBounds Bounds =
-  ComputePreambleBounds(*PreambleInvocationIn.getLangOpts(),
-MainFileBuffer.get(), MaxLines);
+  PreambleBounds Bounds = ComputePreambleBounds(
+  *PreambleInvocationIn.getLangOpts(), *MainFileBuffer, MaxLines);
   if (!Bounds.Size)
 return nullptr;
 

diff  --git a/clang/lib/Frontend/PrecompiledPreamble.cpp 
b/clang/lib/Frontend/PrecompiledPreamble.cpp
index 87cd9169c78c..0f4259900ec2 100644
--- a/clang/lib/Frontend/PrecompiledPreamble

[clang] d87fd09 - Serialization: Hoist the check for in-flight diagnostics in ASTReader::getInputFile, NFC

2020-11-13 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-13T13:26:37-05:00
New Revision: d87fd096ac3eb27f376c0182ed5e3034ce240861

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

LOG: Serialization: Hoist the check for in-flight diagnostics in 
ASTReader::getInputFile, NFC

This logic seems easier to follow without the `Error()` helper, and
checking `DiagnosticsEngine::isDiagnosticInFlight` just once up front.

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

Added: 


Modified: 
clang/include/clang/Serialization/ASTReader.h
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 29c4f15e57b0..94491e45b55b 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1450,8 +1450,6 @@ class ASTReader
   void Error(StringRef Msg) const;
   void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
  StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const;
-  void Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
- unsigned Select) const;
   void Error(llvm::Error &&Err) const;
 
 public:

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index f3ecb1e51368..6e09fa464940 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1246,12 +1246,6 @@ void ASTReader::Error(unsigned DiagID, StringRef Arg1, 
StringRef Arg2,
 Diag(DiagID) << Arg1 << Arg2 << Arg3;
 }
 
-void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
-  unsigned Select) const {
-  if (!Diags.isDiagnosticInFlight())
-Diag(DiagID) << Arg1 << Arg2 << Select;
-}
-
 void ASTReader::Error(llvm::Error &&Err) const {
   Error(toString(std::move(Err)));
 }
@@ -2395,7 +2389,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned 
ID, bool Complain) {
   auto FileChange = HasInputFileChanged();
   // For an overridden file, there is nothing to validate.
   if (!Overridden && FileChange != ModificationType::None) {
-if (Complain) {
+if (Complain && !Diags.isDiagnosticInFlight()) {
   // Build a list of the PCH imports that got us here (in reverse).
   SmallVector ImportStack(1, &F);
   while (!ImportStack.back()->ImportedBy.empty())
@@ -2406,17 +2400,17 @@ InputFile ASTReader::getInputFile(ModuleFile &F, 
unsigned ID, bool Complain) {
   unsigned DiagnosticKind =
   moduleKindForDiagnostic(ImportStack.back()->Kind);
   if (DiagnosticKind == 0)
-Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName,
-  (unsigned)FileChange);
+Diag(diag::err_fe_pch_file_modified)
+<< Filename << TopLevelPCHName << FileChange;
   else if (DiagnosticKind == 1)
-Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName,
-  (unsigned)FileChange);
+Diag(diag::err_fe_module_file_modified)
+<< Filename << TopLevelPCHName << FileChange;
   else
-Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName,
-  (unsigned)FileChange);
+Diag(diag::err_fe_ast_file_modified)
+<< Filename << TopLevelPCHName << FileChange;
 
   // Print the import stack.
-  if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
+  if (ImportStack.size() > 1) {
 Diag(diag::note_pch_required_by)
   << Filename << ImportStack[0]->FileName;
 for (unsigned I = 1; I < ImportStack.size(); ++I)
@@ -2424,8 +2418,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned 
ID, bool Complain) {
 << ImportStack[I-1]->FileName << ImportStack[I]->FileName;
   }
 
-  if (!Diags.isDiagnosticInFlight())
-Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
+  Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
 }
 
 IsOutOfDate = true;



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


[clang] b764a62 - Serialization: Rename three AST diagnostics, NFC

2020-11-13 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-13T14:09:00-05:00
New Revision: b764a62f02e146bed96cf2231bd1db2d9d4fb72c

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

LOG: Serialization: Rename three AST diagnostics, NFC

All three diagnostics have a select between "PCH", "module", and "AST"
in the text. The most generic of these is "AST", so rename them from
`err_module_...` to `err_ast_...`.

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

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 f46470c3f..2720e85df6f5f 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -63,12 +63,12 @@ def err_pch_with_compiler_errors : Error<
 
 def err_module_file_conflict : Error<
   "module '%0' is defined in both '%1' and '%2'">, DefaultFatal;
-def err_module_file_not_found : Error<
+def err_ast_file_not_found : Error<
   "%select{PCH|module|AST}0 file '%1' not found%select{|: %3}2">, DefaultFatal;
-def err_module_file_out_of_date : Error<
+def err_ast_file_out_of_date : Error<
   "%select{PCH|module|AST}0 file '%1' is out of date and "
   "needs to be rebuilt%select{|: %3}2">, DefaultFatal;
-def err_module_file_invalid : Error<
+def err_ast_file_invalid : Error<
   "file '%1' is not a valid precompiled %select{PCH|module|AST}0 file">, 
DefaultFatal;
 def note_module_file_imported_by : Note<
   "imported by %select{|module '%2' in }1'%0'">;

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 6e09fa464940a..31831b7a5bfe2 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4505,9 +4505,9 @@ ASTReader::ReadASTCore(StringRef FileName,
   return Missing;
 
 // Otherwise, return an error.
-Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type)
-  << FileName << !ErrorStr.empty()
-  << ErrorStr;
+Diag(diag::err_ast_file_not_found)
+<< moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty()
+<< ErrorStr;
 return Failure;
 
   case ModuleManager::OutOfDate:
@@ -4517,9 +4517,9 @@ ASTReader::ReadASTCore(StringRef FileName,
   return OutOfDate;
 
 // Otherwise, return an error.
-Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type)
-<< FileName << !ErrorStr.empty()
-<< ErrorStr;
+Diag(diag::err_ast_file_out_of_date)
+<< moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty()
+<< ErrorStr;
 return Failure;
   }
 
@@ -4540,7 +4540,7 @@ ASTReader::ReadASTCore(StringRef FileName,
 
   // Sniff for the signature.
   if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) {
-Diag(diag::err_module_file_invalid)
+Diag(diag::err_ast_file_invalid)
 << moduleKindForDiagnostic(Type) << FileName << std::move(Err);
 return Failure;
   }



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


[clang] a2f2c2f - Serialization: Merge three diagnostics to simplify ASTReader::getInputFile, NFC

2020-11-13 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-13T16:23:04-05:00
New Revision: a2f2c2f3a46351bc5478acd290258d318af2cd88

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

LOG: Serialization: Merge three diagnostics to simplify 
ASTReader::getInputFile, NFC

Clean up the logic for `err_fe_{pch,module,ast}_file_modified` to use a
`select` like other ASTReader diagnostics. There should be no
functionality change here, just a cleanup.

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

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 2720e85df6f5..ce48833a8703 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -17,17 +17,10 @@ def err_fe_pch_malformed : Error<
 "malformed or corrupted AST file: '%0'">, DefaultFatal;
 def err_fe_pch_malformed_block : Error<
 "malformed block record in PCH file: '%0'">, DefaultFatal;
-def err_fe_pch_file_modified : Error<
-"file '%0' has been modified since the precompiled header '%1' was built"
-": %select{size|mtime|content}2 changed">,
-DefaultFatal;
-def err_fe_module_file_modified : Error<
-"file '%0' has been modified since the module file '%1' was built"
-": %select{size|mtime|content}2 changed">,
-DefaultFatal;
 def err_fe_ast_file_modified : Error<
-"file '%0' has been modified since the AST file '%1' was built"
-": %select{size|mtime|content}2 changed">,
+"file '%0' has been modified since the "
+"%select{precompiled header|module file|AST file}1 '%2' was built"
+": %select{size|mtime|content}3 changed">,
 DefaultFatal;
 def err_fe_pch_file_overridden : Error<
 "file '%0' from the precompiled header has been overridden">;

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 31831b7a5bfe..600454399f68 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2397,17 +2397,9 @@ InputFile ASTReader::getInputFile(ModuleFile &F, 
unsigned ID, bool Complain) {
 
   // The top-level PCH is stale.
   StringRef TopLevelPCHName(ImportStack.back()->FileName);
-  unsigned DiagnosticKind =
-  moduleKindForDiagnostic(ImportStack.back()->Kind);
-  if (DiagnosticKind == 0)
-Diag(diag::err_fe_pch_file_modified)
-<< Filename << TopLevelPCHName << FileChange;
-  else if (DiagnosticKind == 1)
-Diag(diag::err_fe_module_file_modified)
-<< Filename << TopLevelPCHName << FileChange;
-  else
-Diag(diag::err_fe_ast_file_modified)
-<< Filename << TopLevelPCHName << FileChange;
+  Diag(diag::err_fe_ast_file_modified)
+  << Filename << moduleKindForDiagnostic(ImportStack.back()->Kind)
+  << TopLevelPCHName << FileChange;
 
   // Print the import stack.
   if (ImportStack.size() > 1) {



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


[clang] cfde3ed - Frontend: Remove unused parameter from ASTUnit::LoadFromCompilerInvocationAction, NFC

2020-11-13 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-13T17:47:17-05:00
New Revision: cfde3edeae4730aa44642c4835bcfa5a857ea8d4

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

LOG: Frontend: Remove unused parameter from 
ASTUnit::LoadFromCompilerInvocationAction, NFC

Drop `IncludeBriefCommentsInCodeCompletion` since it is always `false`.

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

Added: 


Modified: 
clang/include/clang/Frontend/ASTUnit.h
clang/lib/Frontend/ASTUnit.cpp
clang/tools/libclang/Indexing.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/ASTUnit.h 
b/clang/include/clang/Frontend/ASTUnit.h
index 50ab86ebad97..5595b8c7bcae 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -756,7 +756,6 @@ class ASTUnit {
   CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
   unsigned PrecompilePreambleAfterNParses = 0,
   bool CacheCodeCompletionResults = false,
-  bool IncludeBriefCommentsInCodeCompletion = false,
   bool UserFilesAreVolatile = false,
   std::unique_ptr *ErrAST = nullptr);
 

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index e1aa3682a2b7..a112117d1c06 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1520,8 +1520,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
 ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
 unsigned PrecompilePreambleAfterNParses, bool CacheCodeCompletionResults,
-bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile,
-std::unique_ptr *ErrAST) {
+bool UserFilesAreVolatile, std::unique_ptr *ErrAST) {
   assert(CI && "A CompilerInvocation is required");
 
   std::unique_ptr OwnAST;
@@ -1544,8 +1543,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
 AST->PreambleRebuildCountdown = PrecompilePreambleAfterNParses;
   AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete;
   AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
-  AST->IncludeBriefCommentsInCodeCompletion
-= IncludeBriefCommentsInCodeCompletion;
+  AST->IncludeBriefCommentsInCodeCompletion = false;
 
   // Recover resources if we crash before exiting this method.
   llvm::CrashRecoveryContextCleanupRegistrar

diff  --git a/clang/tools/libclang/Indexing.cpp 
b/clang/tools/libclang/Indexing.cpp
index f0303fdcd825..0e83ec6ca799 100644
--- a/clang/tools/libclang/Indexing.cpp
+++ b/clang/tools/libclang/Indexing.cpp
@@ -617,9 +617,7 @@ static CXErrorCode clang_indexSourceFile_Impl(
   std::move(CInvok), CXXIdx->getPCHContainerOperations(), Diags,
   IndexAction.get(), UPtr, Persistent, CXXIdx->getClangResourcesPath(),
   OnlyLocalDecls, CaptureDiagnostics, PrecompilePreambleAfterNParses,
-  CacheCodeCompletionResults,
-  /*IncludeBriefCommentsInCodeCompletion=*/false,
-  /*UserFilesAreVolatile=*/true);
+  CacheCodeCompletionResults, /*UserFilesAreVolatile=*/true);
   if (DiagTrap.hasErrorOccurred() && CXXIdx->getDisplayDiagnostics())
 printDiagsToStderr(UPtr);
 



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


[clang] d07b290 - DependencyScanning: pull factory function into MinimizedVFS, NFC

2020-10-12 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-12T17:25:10-04:00
New Revision: d07b290e4b7c55823895e88b683de4178ffc66db

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

LOG: DependencyScanning: pull factory function into MinimizedVFS, NFC

Avoid need for getBufferPtr API, simplifying another patch. No
functionality change.

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Removed: 




diff  --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index b1b87e7fa573..63eab82820cc 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -217,9 +217,11 @@ class MinimizedVFSFile final : public llvm::vfs::File {
llvm::vfs::Status Stat)
   : Buffer(std::move(Buffer)), Stat(std::move(Stat)) {}
 
-  llvm::ErrorOr status() override { return Stat; }
+  static llvm::ErrorOr>
+  create(const CachedFileSystemEntry *Entry,
+ ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings);
 
-  const llvm::MemoryBuffer *getBufferPtr() const { return Buffer.get(); }
+  llvm::ErrorOr status() override { return Stat; }
 
   llvm::ErrorOr>
   getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator,
@@ -234,9 +236,11 @@ class MinimizedVFSFile final : public llvm::vfs::File {
   llvm::vfs::Status Stat;
 };
 
-llvm::ErrorOr>
-createFile(const CachedFileSystemEntry *Entry,
-   ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings) {
+} // end anonymous namespace
+
+llvm::ErrorOr> MinimizedVFSFile::create(
+const CachedFileSystemEntry *Entry,
+ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings) {
   if (Entry->isDirectory())
 return llvm::ErrorOr>(
 std::make_error_code(std::errc::is_a_directory));
@@ -248,14 +252,12 @@ createFile(const CachedFileSystemEntry *Entry,
/*RequiresNullTerminator=*/false),
   *Entry->getStatus());
   if (!Entry->getPPSkippedRangeMapping().empty() && PPSkipMappings)
-(*PPSkipMappings)[Result->getBufferPtr()] =
+(*PPSkipMappings)[Result->Buffer.get()] =
 &Entry->getPPSkippedRangeMapping();
   return llvm::ErrorOr>(
   std::unique_ptr(std::move(Result)));
 }
 
-} // end anonymous namespace
-
 llvm::ErrorOr>
 DependencyScanningWorkerFilesystem::openFileForRead(const Twine &Path) {
   SmallString<256> OwnedFilename;
@@ -265,5 +267,5 @@ DependencyScanningWorkerFilesystem::openFileForRead(const 
Twine &Path) {
   getOrCreateFileSystemEntry(Filename);
   if (!Result)
 return Result.getError();
-  return createFile(Result.get(), PPSkipMappings);
+  return MinimizedVFSFile::create(Result.get(), PPSkipMappings);
 }



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


[clang] 69feac1 - Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, NFC

2020-10-12 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-12T17:39:01-04:00
New Revision: 69feac12d0539a7cc19cbda906d46f67029486e1

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

LOG: Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, 
NFC

This is a prep patch for changing SourceManager to return
`Optional` instead of `MemoryBuffer`. With that change the
address of the MemoryBuffer will be gone, so instead use the start of the
buffer as the key for this map.

No functionality change intended, as it's expected that the pointer identity
matches between the buffers and the buffer data.

Radar-Id: rdar://70139990
Differential Revision: https://reviews.llvm.org/D89136

Added: 


Modified: 

clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Removed: 




diff  --git 
a/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h 
b/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
index 893b7ba7a9f5..1a0d5ed57b28 100644
--- 
a/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
+++ 
b/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
@@ -23,8 +23,7 @@ using PreprocessorSkippedRangeMapping = 
llvm::DenseMap;
 /// The datastructure that holds the mapping between the active memory buffers
 /// and the individual skip mappings.
 using ExcludedPreprocessorDirectiveSkipMapping =
-llvm::DenseMap;
+llvm::DenseMap;
 
 } // end namespace clang
 

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index e4b901a950ae..57349d4a439d 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -380,7 +380,10 @@ Optional 
Preprocessor::getSkippedRangeForExcludedConditionalBlock(
   std::pair HashFileOffset =
   SourceMgr.getDecomposedLoc(HashLoc);
   const llvm::MemoryBuffer *Buf = SourceMgr.getBuffer(HashFileOffset.first);
-  auto It = ExcludedConditionalDirectiveSkipMappings->find(Buf);
+  if (!Buf)
+return None;
+  auto It =
+  ExcludedConditionalDirectiveSkipMappings->find(Buf->getBufferStart());
   if (It == ExcludedConditionalDirectiveSkipMappings->end())
 return None;
 

diff  --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 63eab82820cc..1c10b7d727a5 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -252,7 +252,7 @@ llvm::ErrorOr> 
MinimizedVFSFile::create(
/*RequiresNullTerminator=*/false),
   *Entry->getStatus());
   if (!Entry->getPPSkippedRangeMapping().empty() && PPSkipMappings)
-(*PPSkipMappings)[Result->Buffer.get()] =
+(*PPSkipMappings)[Result->Buffer->getBufferStart()] =
 &Entry->getPPSkippedRangeMapping();
   return llvm::ErrorOr>(
   std::unique_ptr(std::move(Result)));



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


[clang] e7fe3c6 - Basic: Simplify SourceManager::getBuffer overload, NFC

2020-10-13 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-13T17:52:59-04:00
New Revision: e7fe3c6dfede8d5781bd000741c3dea7088307a4

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

LOG: Basic: Simplify SourceManager::getBuffer overload, NFC

Avoid duplicating code unnecessarily. No functionality change.

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 5c666c1760b4..1e6a800f1d55 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -979,17 +979,7 @@ class SourceManager : public RefCountedBase 
{
 
   const llvm::MemoryBuffer *getBuffer(FileID FID,
   bool *Invalid = nullptr) const {
-bool MyInvalid = false;
-const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid);
-if (MyInvalid || !Entry.isFile()) {
-  if (Invalid)
-*Invalid = true;
-
-  return getFakeBufferForRecovery();
-}
-
-return Entry.getFile().getContentCache()->getBuffer(
-Diag, getFileManager(), SourceLocation(), Invalid);
+return getBuffer(FID, SourceLocation(), Invalid);
   }
 
   /// Returns the FileEntry record for the provided FileID.



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


[clang] d758f79 - clang/Basic: Replace ContentCache::getBuffer with Optional semantics

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T15:55:18-04:00
New Revision: d758f79e5d381bd4f5122193a9538d89c907c812

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

LOG: clang/Basic: Replace ContentCache::getBuffer with Optional semantics

Remove `ContentCache::getBuffer`, which always returned a
dereferenceable `MemoryBuffer*` and had a `bool*Invalid` out parameter,
and replace it with:

- `ContentCache::getBufferOrNone`, which returns
  `Optional`. This is the new API that consumers should
  use. Later it could be renamed to `getBuffer`, but intentionally using
  a different name to root out any unexpected callers.
- `ContentCache::getBufferPointer`, which returns `MemoryBuffer*` with
  "optional" semantics. This is `private` to avoid growing callers and
  `SourceManager` has temporarily been made a `friend` to access it.
  Later paches will update the transitive callers to not need a raw
  pointer, and eventually this will be deleted.

No functionality change intended here.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang/include/clang/Basic/SourceManager.h
clang/lib/AST/ASTImporter.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 079d57477216..2b137d0b5113 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -305,22 +305,8 @@ static bool IsNOLINTFound(StringRef NolintDirectiveText, 
StringRef Line,
 
 static llvm::Optional getBuffer(const SourceManager &SM, FileID 
File,
bool AllowIO) {
-  // This is similar to the implementation of SourceManager::getBufferData(),
-  // but uses ContentCache::getRawBuffer() rather than getBuffer() if
-  // AllowIO=false, to avoid triggering file I/O if the file contents aren't
-  // already mapped.
-  bool CharDataInvalid = false;
-  const SrcMgr::SLocEntry &Entry = SM.getSLocEntry(File, &CharDataInvalid);
-  if (CharDataInvalid || !Entry.isFile())
-return llvm::None;
-  const SrcMgr::ContentCache *Cache = Entry.getFile().getContentCache();
-  const llvm::MemoryBuffer *Buffer =
-  AllowIO ? Cache->getBuffer(SM.getDiagnostics(), SM.getFileManager(),
- SourceLocation(), &CharDataInvalid)
-  : Cache->getRawBuffer();
-  if (!Buffer || CharDataInvalid)
-return llvm::None;
-  return Buffer->getBuffer();
+  return AllowIO ? SM.getBufferDataOrNone(File)
+ : SM.getBufferDataIfLoaded(File);
 }
 
 static bool LineIsMarkedWithNOLINT(const SourceManager &SM, SourceLocation Loc,

diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 1e6a800f1d55..e34fe4577aae 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -184,13 +184,21 @@ namespace SrcMgr {
 ///
 /// \param Loc If specified, is the location that invalid file diagnostics
 ///   will be emitted at.
+llvm::Optional
+getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
+SourceLocation Loc = SourceLocation()) const;
+
+  private:
+/// Returns pointer to memory buffer.
 ///
-/// \param Invalid If non-NULL, will be set \c true if an error occurred.
-const llvm::MemoryBuffer *getBuffer(DiagnosticsEngine &Diag,
-FileManager &FM,
-SourceLocation Loc = SourceLocation(),
-bool *Invalid = nullptr) const;
+/// TODO: SourceManager needs access to this for now, but once that's done
+/// we should remove this API.
+const llvm::MemoryBuffer *getBufferPointer(DiagnosticsEngine &Diag,
+   FileManager &FM,
+   SourceLocation Loc) const;
+friend class clang::SourceManager;
 
+  public:
 /// Returns the size of the content encapsulated by this
 /// ContentCache.
 ///
@@ -958,10 +966,27 @@ class SourceManager : public 
RefCountedBase {
   // FileID manipulation methods.
   
//======//
 
+  /// Return the buffer for the specified FileID.
+  ///
+  /// If there is an error opening this buffer the first time, return None.
+  llvm::Optional
+  getBufferOrNone(FileID FID, SourceLocation Loc = SourceLocation()) const {
+bool MyInvalid = false;
+const SrcMg

[clang] 54c1bca - clang/Basic: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T22:42:56-04:00
New Revision: 54c1bcab90102481fe43b73f8547d47446ba2163

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

LOG: clang/Basic: Stop using SourceManager::getBuffer, NFC

Update clang/lib/Basic to stop relying on a `MemoryBuffer*`, using the
`MemoryBufferRef` from `getBufferOrNone` or `getBufferOrFake` instead of
`getBuffer`.

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

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/lib/Basic/Diagnostic.cpp
clang/lib/Basic/SourceLocation.cpp
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index e34fe4577aae..2156a013e53b 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -980,6 +980,17 @@ class SourceManager : public RefCountedBase 
{
 Diag, getFileManager(), Loc);
   }
 
+  /// Return the buffer for the specified FileID.
+  ///
+  /// If there is an error opening this buffer the first time, this
+  /// manufactures a temporary buffer and returns it.
+  llvm::MemoryBufferRef
+  getBufferOrFake(FileID FID, SourceLocation Loc = SourceLocation()) const {
+if (auto B = getBufferOrNone(FID, Loc))
+  return *B;
+return getFakeBufferForRecovery()->getMemBufferRef();
+  }
+
   /// Return the buffer for the specified FileID.
   ///
   /// If there is an error opening this buffer the first time, this

diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 661eabf9bc7c..ba8c2fb4731d 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -265,7 +265,8 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager 
&SrcMgr,
   PrintedOuterHeading = true;
 
   llvm::errs() << "File " << &File << " : " << SrcMgr.getBuffer(ID)->getBufferIdentifier();
+   << ">: " << 
SrcMgr.getBufferOrFake(ID).getBufferIdentifier();
+
   if (F.second.Parent) {
 std::pair Decomp =
 SrcMgr.getDecomposedIncludedLoc(ID);

diff  --git a/clang/lib/Basic/SourceLocation.cpp 
b/clang/lib/Basic/SourceLocation.cpp
index c1fa406909fe..8cb0899ea39d 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -245,7 +245,7 @@ const char *FullSourceLoc::getCharacterData(bool *Invalid) 
const {
 
 StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
   assert(isValid());
-  return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer();
+  return SrcMgr->getBufferData(SrcMgr->getFileID(*this), Invalid);
 }
 
 std::pair FullSourceLoc::getDecomposedLoc() const {

diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 1e1915198cd0..61e186e6aa48 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1228,12 +1228,11 @@ const char 
*SourceManager::getCharacterData(SourceLocation SL,
 /// this is significantly cheaper to compute than the line number.
 unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
 bool *Invalid) const {
-  bool MyInvalid = false;
-  const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid);
+  llvm::Optional MemBuf = getBufferOrNone(FID);
   if (Invalid)
-*Invalid = MyInvalid;
+*Invalid = !MemBuf;
 
-  if (MyInvalid)
+  if (!MemBuf)
 return 1;
 
   // It is okay to request a position just past the end of the buffer.
@@ -1509,7 +1508,10 @@ StringRef SourceManager::getBufferName(SourceLocation 
Loc,
bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return "";
 
-  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
+  auto B = getBufferOrNone(getFileID(Loc));
+  if (Invalid)
+*Invalid = !B;
+  return B ? B->getBufferIdentifier() : "";
 }
 
 /// getPresumedLoc - This method returns the "presumed" location of a
@@ -2047,8 +2049,8 @@ bool 
SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
   // If we arrived here, the location is either in a built-ins buffer or
   // associated with global inline asm. PR5662 and PR22576 are examples.
 
-  StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier();
-  StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier();
+  StringRef LB = getBufferOrFake(LOffs.first).getBufferIdentifier();
+  StringRef RB = getBufferOrFake(ROffs.first).getBufferIdentifier();
   bool LIsBuiltins = LB == "";
   bool RIsBuiltins = RB == "";
   // Sort built-in before non-built-in.



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

[clang] 63af242 - clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T23:31:28-04:00
New Revision: 63af2422798188d70a411f76b0f06ab63a783a0d

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

LOG: clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC

Update clang/lib/Frontend to use a `MemoryBufferRef` from
`getBufferOrFake` instead of `MemoryBuffer*` from `getBuffer`, with the
exception of `FrontendInputFile`, which I'm leaving for later.

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

Added: 


Modified: 
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/Rewrite/HTMLPrint.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Frontend/Rewrite/RewriteObjC.cpp

Removed: 




diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 92654dbe8a10..9a806d7c9af8 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -450,7 +450,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance 
&CI, bool IsSystem,
PresumedModuleMapFile))
 return true;
 
-  if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)
+  if (SrcMgr.getBufferOrFake(ModuleMapID).getBufferSize() == Offset)
 Offset = 0;
 
   return false;

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 77a88f696abc..ec5caceba207 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -805,11 +805,9 @@ void PrintPreprocessedAction::ExecuteAction() {
   // concern, so if we scan for too long, we'll just assume the file should
   // be opened in binary mode.
   bool BinaryMode = true;
-  bool InvalidFile = false;
   const SourceManager& SM = CI.getSourceManager();
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
- &InvalidFile);
-  if (!InvalidFile) {
+  if (llvm::Optional Buffer =
+  SM.getBufferOrNone(SM.getMainFileID())) {
 const char *cur = Buffer->getBufferStart();
 const char *end = Buffer->getBufferEnd();
 const char *next = (cur != end) ? cur + 1 : end;
@@ -937,12 +935,12 @@ void DumpCompilerOptionsAction::ExecuteAction() {
 void PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction() {
   CompilerInstance &CI = getCompilerInstance();
   SourceManager &SM = CI.getPreprocessor().getSourceManager();
-  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
+  llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(SM.getMainFileID());
 
   llvm::SmallString<1024> Output;
   llvm::SmallVector Toks;
   if (minimizeSourceToDependencyDirectives(
-  FromFile->getBuffer(), Output, Toks, &CI.getDiagnostics(),
+  FromFile.getBuffer(), Output, Toks, &CI.getDiagnostics(),
   SM.getLocForStartOfFile(SM.getMainFileID( {
 assert(CI.getDiagnostics().hasErrorOccurred() &&
"no errors reported for failure");

diff  --git a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp 
b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp
index 982e56cebbca..1388c2e1faab 100644
--- a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp
+++ b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp
@@ -70,7 +70,7 @@ void HTMLPrinter::HandleTranslationUnit(ASTContext &Ctx) {
   if (Entry)
 Name = Entry->getName();
   else
-Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier();
+Name = R.getSourceMgr().getBufferOrFake(FID).getBufferIdentifier();
 
   html::AddLineNumbers(R, FID);
   html::AddHeaderFooterInternalBuiltinCSS(R, FID, Name);

diff  --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index c0c81221b234..9d5366bb161e 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -702,9 +702,9 @@ void RewriteModernObjC::InitializeCommon(ASTContext 
&context) {
 
   // Get the ID and start/end of the main file.
   MainFileID = SM->getMainFileID();
-  const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
-  MainFileStart = MainBuf->getBufferStart();
-  MainFileEnd = MainBuf->getBufferEnd();
+  llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID);
+  MainFileStart = MainBuf.getBufferStart();
+  MainFileEnd = MainBuf.getBufferEnd();
 
   Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
 }

diff  --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
index 990509a84b06..3caf9a672062 100644
--- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -631,9 +631,9 @@ void RewriteObjC::InitializeCommon(ASTCo

[clang] dde4e03 - clang/CodeGen: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-14T23:32:43-04:00
New Revision: dde4e0318c4cd2054ed241bf248fdddb8d1973e3

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

LOG: clang/CodeGen: Stop using SourceManager::getBuffer, NFC

Update `clang/lib/CodeGen` to use a `MemoryBufferRef` from
`getBufferOrNone` instead of `MemoryBuffer*` from `getBuffer`. No
functionality change here.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CodeGenAction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 71ebd268f630..8280fe718f26 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -374,9 +374,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<32> 
&Checksum) const {
 return None;
 
   SourceManager &SM = CGM.getContext().getSourceManager();
-  bool Invalid;
-  const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
-  if (Invalid)
+  Optional MemBuffer = SM.getBufferOrNone(FID);
+  if (!MemBuffer)
 return None;
 
   llvm::MD5 Hash;

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 5ea2fc23ee11..871cdb7dac3b 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1122,11 +1122,10 @@ void CodeGenAction::ExecuteAction() {
 if (BA != Backend_EmitNothing && !OS)
   return;
 
-bool Invalid;
 SourceManager &SM = CI.getSourceManager();
 FileID FID = SM.getMainFileID();
-const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid);
-if (Invalid)
+Optional MainFile = SM.getBufferOrNone(FID);
+if (!MainFile)
   return;
 
 TheModule = loadModule(*MainFile);
@@ -1141,8 +1140,7 @@ void CodeGenAction::ExecuteAction() {
   TheModule->setTargetTriple(TargetOpts.Triple);
 }
 
-EmbedBitcode(TheModule.get(), CodeGenOpts,
- MainFile->getMemBufferRef());
+EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
 
 LLVMContext &Ctx = TheModule->getContext();
 Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,



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


[clang] af4fb41 - clang/StaticAnalyzer: Stop using SourceManager::getBuffer

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-15T00:34:24-04:00
New Revision: af4fb416bd355960ce93f271a0591f24f58d25ec

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

LOG: clang/StaticAnalyzer: Stop using SourceManager::getBuffer

Update clang/lib/StaticAnalyzer to stop relying on a `MemoryBuffer*`,
using the `MemoryBufferRef` from `getBufferOrNone` or the
`Optional` from `getBufferOrFake`, depending on whether
there's logic for checking validity of the buffer. The change to
clang/lib/StaticAnalyzer/Core/IssueHash.cpp is potentially a
functionality change, since the logic was wrong (it checked for
`nullptr`, which was never returned by the old API), but if that was
reachable the new behaviour should be better.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/IssueHash.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
index 252377f24bd7..28d3e058fee2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
@@ -1141,10 +1141,9 @@ void 
EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
 SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
   }
 
-  bool Invalid = false;
-  const llvm::MemoryBuffer *BF =
-  Mgr.getSourceManager().getBuffer(SLInfo.first, SL, &Invalid);
-  if (Invalid)
+  llvm::Optional BF =
+  Mgr.getSourceManager().getBufferOrNone(SLInfo.first, SL);
+  if (!BF)
 return;
 
   Lexer TheLexer(SL, LangOptions(), BF->getBufferStart(),

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 72be4e81c83d..ebad1d1b67b4 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1570,9 +1570,8 @@ static Optional getLengthOnSingleLine(const 
SourceManager &SM,
   if (FID != SM.getFileID(ExpansionRange.getEnd()))
 return None;
 
-  bool Invalid;
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, &Invalid);
-  if (Invalid)
+  Optional Buffer = SM.getBufferOrNone(FID);
+  if (!Buffer)
 return None;
 
   unsigned BeginOffset = SM.getFileOffset(ExpansionRange.getBegin());

diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index bc7c41d039c4..68f1007569cd 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -786,8 +786,8 @@ void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID 
BugFileID,
   if (LPosInfo.first != BugFileID)
 return;
 
-  const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
-  const char* FileStart = Buf->getBufferStart();
+  llvm::MemoryBufferRef Buf = SM.getBufferOrFake(LPosInfo.first);
+  const char *FileStart = Buf.getBufferStart();
 
   // Compute the column number.  Rewind from the current position to the start
   // of the line.
@@ -797,7 +797,7 @@ void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID 
BugFileID,
 
   // Compute LineEnd.
   const char *LineEnd = TokInstantiationPtr;
-  const char* FileEnd = Buf->getBufferEnd();
+  const char *FileEnd = Buf.getBufferEnd();
   while (*LineEnd != '\n' && LineEnd != FileEnd)
 ++LineEnd;
 

diff  --git a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp 
b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
index e7497f3fbdaa..2bea1593110a 100644
--- a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -120,7 +120,8 @@ static std::string GetEnclosingDeclContextSignature(const 
Decl *D) {
   return "";
 }
 
-static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line) {
+static StringRef GetNthLineOfFile(llvm::Optional Buffer,
+  int Line) {
   if (!Buffer)
 return "";
 
@@ -135,7 +136,7 @@ static std::string NormalizeLine(const SourceManager &SM, 
FullSourceLoc &L,
  const LangOptions &LangOpts) {
   static StringRef Whitespaces = " \t\n";
 
-  StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
+  StringRef Str = GetNthLineOfFile(SM.getBufferOrNone(L.getFileID(), L),
L.getExpansionLineNumber());
   StringRef::size_type col = Str.find_first_not_of(Whitespaces);
   if (col

[clang] 0065198 - clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC

2020-10-14 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-15T00:35:16-04:00
New Revision: 006519816689acef5fd971955e21b7ab17ae65d9

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

LOG: clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC

Update clang-tools-extra, clang/tools, clang/unittests to migrate from
`SourceManager::getBuffer`, which returns an always dereferenceable
`MemoryBuffer*`, to `getBufferOrNone` or `getBufferOrFake`, both of
which return a `MemoryBufferRef`, depending on whether the call site was
checking for validity of the buffer. No functionality change intended.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/modularize/PreprocessorTracker.cpp
clang/tools/clang-diff/ClangDiff.cpp
clang/tools/clang-import-test/clang-import-test.cpp
clang/tools/libclang/CIndex.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
index 9b34f5ab55a7..3874a52e7e20 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
@@ -54,10 +54,10 @@ void SuspiciousSemicolonCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   SourceLocation LocEnd = Semicolon->getEndLoc();
   FileID FID = SM.getFileID(LocEnd);
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, LocEnd);
+  llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, LocEnd);
   Lexer Lexer(SM.getLocForStartOfFile(FID), Ctxt.getLangOpts(),
-  Buffer->getBufferStart(), SM.getCharacterData(LocEnd) + 1,
-  Buffer->getBufferEnd());
+  Buffer.getBufferStart(), SM.getCharacterData(LocEnd) + 1,
+  Buffer.getBufferEnd());
   if (Lexer.LexFromRawLexer(Token))
 return;
 

diff  --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index b84e4d525d8c..5d3d3c46edb4 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -794,14 +794,14 @@ static bool areExprsFromDifferentMacros(const Expr 
*LhsExpr,
   SM.getDecomposedLoc(SM.getExpansionLoc(Lsr.getBegin()));
   std::pair RsrLocInfo =
   SM.getDecomposedLoc(SM.getExpansionLoc(Rsr.getBegin()));
-  const llvm::MemoryBuffer *MB = SM.getBuffer(LsrLocInfo.first);
+  llvm::MemoryBufferRef MB = SM.getBufferOrFake(LsrLocInfo.first);
 
-  const char *LTokenPos = MB->getBufferStart() + LsrLocInfo.second;
-  const char *RTokenPos = MB->getBufferStart() + RsrLocInfo.second;
+  const char *LTokenPos = MB.getBufferStart() + LsrLocInfo.second;
+  const char *RTokenPos = MB.getBufferStart() + RsrLocInfo.second;
   Lexer LRawLex(SM.getLocForStartOfFile(LsrLocInfo.first), LO,
-MB->getBufferStart(), LTokenPos, MB->getBufferEnd());
+MB.getBufferStart(), LTokenPos, MB.getBufferEnd());
   Lexer RRawLex(SM.getLocForStartOfFile(RsrLocInfo.first), LO,
-MB->getBufferStart(), RTokenPos, MB->getBufferEnd());
+MB.getBufferStart(), RTokenPos, MB.getBufferEnd());
 
   Token LTok, RTok;
   do { // Compare the expressions token-by-token.

diff  --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 53cebc32bb38..3e3f8dbf02ff 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -140,7 +140,8 @@ SourceLocation StaticAssertCheck::getLastParenLoc(const 
ASTContext *ASTCtx,
   const LangOptions &Opts = ASTCtx->getLangOpts();
   const SourceManager &SM = ASTCtx->getSourceManager();
 
-  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getFileID(AssertLoc));
+  llvm::Optional Buffer =
+  SM.getBufferOrNone(SM.getFileID(AssertLoc));
   if (!Buffer)
 return SourceLocation();
 

diff  --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index 1cecfa31da34..18165a619adf 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-

[clang] 59a3b1a - clang-format: Assert in-memory file created in createInMemoryFile, NFC

2020-10-16 Thread Duncan P . N . Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-10-16T10:20:32-04:00
New Revision: 59a3b1afb28541d5bf37445b028bfd711e3c556a

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

LOG: clang-format: Assert in-memory file created in createInMemoryFile, NFC

`SourceManager::createFileID` asserts that the given `FileEntry` is not
null, so remove the logic that passed in `nullptr`. Since we just added
the file to an in-memory FS via an API that cannot fail, use
`llvm_unreachable` on the error path. Didn't use an `assert` since it
seems cleaner semantically to check the error (and better,
hypothetically, for updating the API to use `Expected` instead of
`ErrorOr`).

I noticed this incidentally while auditing calls to `createFileID`.

Added: 


Modified: 
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 8dd55d99e2a0..3a7247deab46 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -179,8 +179,8 @@ static FileID createInMemoryFile(StringRef FileName, 
MemoryBuffer *Source,
  llvm::vfs::InMemoryFileSystem *MemFS) {
   MemFS->addFileNoOwn(FileName, 0, Source);
   auto File = Files.getFile(FileName);
-  return Sources.createFileID(File ? *File : nullptr, SourceLocation(),
-  SrcMgr::C_User);
+  assert(File && "File not added to MemFS?");
+  return Sources.createFileID(*File, SourceLocation(), SrcMgr::C_User);
 }
 
 // Parses : input to a pair of line numbers.



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


[clang] ac40a2d - Serialization: Change InputFile to use FileEntryRef and add getVirtualFileRef, NFC

2020-11-30 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-30T14:04:48-08:00
New Revision: ac40a2d8f16b8a8c68fc811d67f647740e965cb8

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

LOG: Serialization: Change InputFile to use FileEntryRef and add 
getVirtualFileRef, NFC

Change the `InputFile` class to store `Optional` instead
of `FileEntry*`. This paged in a few API changes:

- Added `FileManager::getVirtualFileRef`, and converted `getVirtualFile`
  to a wrapper of it.
- Updated `SourceManager::bypassFileContentsOverride` to take
  `FileEntryRef` and return `Optional`
  (`ASTReader::getInputFile` is the only caller).

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

Added: 


Modified: 
clang/include/clang/Basic/FileManager.h
clang/include/clang/Basic/SourceManager.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/Basic/FileManager.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index d7135a4f0ac3..449aec2b3541 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -239,6 +239,9 @@ class FileManager : public RefCountedBase {
   /// if there were a file with the given name on disk.
   ///
   /// The file itself is not accessed.
+  FileEntryRef getVirtualFileRef(StringRef Filename, off_t Size,
+ time_t ModificationTime);
+
   const FileEntry *getVirtualFile(StringRef Filename, off_t Size,
   time_t ModificationTime);
 

diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index b231644330ed..459bd088f0d7 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -35,6 +35,7 @@
 #define LLVM_CLANG_BASIC_SOURCEMANAGER_H
 
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"
@@ -60,8 +61,6 @@ namespace clang {
 class ASTReader;
 class ASTWriter;
 class FileManager;
-class FileEntry;
-class FileEntryRef;
 class LineTableInfo;
 class SourceManager;
 
@@ -982,11 +981,11 @@ class SourceManager : public 
RefCountedBase {
   }
 
   /// Bypass the overridden contents of a file.  This creates a new FileEntry
-  /// and initializes the content cache for it.  Returns nullptr if there is no
+  /// and initializes the content cache for it.  Returns None if there is no
   /// such file in the filesystem.
   ///
   /// This should be called before parsing has begun.
-  const FileEntry *bypassFileContentsOverride(const FileEntry &File);
+  Optional bypassFileContentsOverride(FileEntryRef File);
 
   /// Specify that a file is transient.
   void setFileIsTransient(const FileEntry *SourceFile);

diff  --git a/clang/include/clang/Serialization/ModuleFile.h 
b/clang/include/clang/Serialization/ModuleFile.h
index a309c1143350..a641a26661ae 100644
--- a/clang/include/clang/Serialization/ModuleFile.h
+++ b/clang/include/clang/Serialization/ModuleFile.h
@@ -67,13 +67,13 @@ class InputFile {
 OutOfDate = 2,
 NotFound = 3
   };
-  llvm::PointerIntPair Val;
+  llvm::PointerIntPair Val;
 
 public:
   InputFile() = default;
 
-  InputFile(const FileEntry *File,
-bool isOverridden = false, bool isOutOfDate = false) {
+  InputFile(FileEntryRef File, bool isOverridden = false,
+bool isOutOfDate = false) {
 assert(!(isOverridden && isOutOfDate) &&
"an overridden cannot be out-of-date");
 unsigned intVal = 0;
@@ -81,7 +81,7 @@ class InputFile {
   intVal = Overridden;
 else if (isOutOfDate)
   intVal = OutOfDate;
-Val.setPointerAndInt(File, intVal);
+Val.setPointerAndInt(&File.getMapEntry(), intVal);
   }
 
   static InputFile getNotFound() {
@@ -90,7 +90,11 @@ class InputFile {
 return File;
   }
 
-  const FileEntry *getFile() const { return Val.getPointer(); }
+  OptionalFileEntryRefDegradesToFileEntryPtr getFile() const {
+if (auto *P = Val.getPointer())
+  return FileEntryRef(*P);
+return None;
+  }
   bool isOverridden() const { return Val.getInt() == Overridden; }
   bool isOutOfDate() const { return Val.getInt() == OutOfDate; }
   bool isNotFound() const { return Val.getInt() == NotFound; }

diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 38d9403eadb9..ef0c69ae0107 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -335,9 +335,13 @@ FileManager::getFileRef(StringRef Filename, bool openFile, 
bool CacheFailure) {
   return ReturnedRef;
 }
 
-const FileEntry *
-Fil

[clang] 1b042de - FileManager: Add FileEntryRef::getDir, returning DirectoryEntryRef

2020-11-30 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-30T14:50:46-08:00
New Revision: 1b042de5b29af4869a77ecbc632029fba0313dec

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

LOG: FileManager: Add FileEntryRef::getDir, returning DirectoryEntryRef

Add `FileEntryRef::getDir`, which returns a `DirectoryEntryRef`. This
includes a few changes:

- Customize `OptionalStorage` so that `Optional` is
  pointer-sized (like the change made to `Optional`).
  Factored out a common class, `FileMgr::MapEntryOptionalStorage`, to
  reduce the code duplication.
- Store an `Optional` in `FileEntryRef::MapValue`.
  This is set if and only if `MapValue` has a real `FileEntry`.
- Change `FileManager::getFileRef` and `getVirtualFileRef` to use
  `getDirectoryRef` and store it in the `StringMap` for `FileEntryRef`.

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

Added: 


Modified: 
clang/include/clang/Basic/DirectoryEntry.h
clang/include/clang/Basic/FileEntry.h
clang/lib/Basic/FileManager.cpp
clang/unittests/Basic/FileEntryTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
index 7c634709ca9b..a6ec5f89aa28 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -20,6 +20,11 @@
 #include "llvm/Support/ErrorOr.h"
 
 namespace clang {
+namespace FileMgr {
+
+template  class MapEntryOptionalStorage;
+
+} // end namespace FileMgr
 
 /// Cached information about one directory (either on disk or in
 /// the virtual file system).
@@ -37,20 +42,109 @@ class DirectoryEntry {
 /// as it was accessed by the FileManager's client.
 class DirectoryEntryRef {
 public:
-  const DirectoryEntry &getDirEntry() const { return *Entry->getValue(); }
+  const DirectoryEntry &getDirEntry() const { return *ME->getValue(); }
+
+  StringRef getName() const { return ME->getKey(); }
+
+  using MapEntry = llvm::StringMapEntry>;
 
-  StringRef getName() const { return Entry->getKey(); }
+  const MapEntry &getMapEntry() const { return *ME; }
+
+  DirectoryEntryRef() = delete;
+  DirectoryEntryRef(MapEntry &ME) : ME(&ME) {}
 
 private:
-  friend class FileManager;
+  friend class FileMgr::MapEntryOptionalStorage;
+  struct optional_none_tag {};
 
-  DirectoryEntryRef(
-  llvm::StringMapEntry> *Entry)
-  : Entry(Entry) {}
+  // Private constructor for use by OptionalStorage.
+  DirectoryEntryRef(optional_none_tag) : ME(nullptr) {}
+  bool hasOptionalValue() const { return ME; }
 
-  const llvm::StringMapEntry> *Entry;
+  const MapEntry *ME;
 };
 
+namespace FileMgr {
+
+/// Customized storage for refs derived from map entires in FileManager, using
+/// the private optional_none_tag to keep it to the size of a single pointer.
+template  class MapEntryOptionalStorage {
+  using optional_none_tag = typename RefTy::optional_none_tag;
+  RefTy MaybeRef;
+
+public:
+  MapEntryOptionalStorage() : MaybeRef(optional_none_tag()) {}
+
+  template 
+  explicit MapEntryOptionalStorage(llvm::optional_detail::in_place_t,
+   ArgTypes &&...Args)
+  : MaybeRef(std::forward(Args)...) {}
+
+  void reset() { MaybeRef = optional_none_tag(); }
+
+  bool hasValue() const { return MaybeRef.hasOptionalValue(); }
+
+  RefTy &getValue() LLVM_LVALUE_FUNCTION {
+assert(hasValue());
+return MaybeRef;
+  }
+  RefTy const &getValue() const LLVM_LVALUE_FUNCTION {
+assert(hasValue());
+return MaybeRef;
+  }
+#if LLVM_HAS_RVALUE_REFERENCE_THIS
+  RefTy &&getValue() && {
+assert(hasValue());
+return std::move(MaybeRef);
+  }
+#endif
+
+  template  void emplace(Args &&...args) {
+MaybeRef = RefTy(std::forward(args)...);
+  }
+
+  MapEntryOptionalStorage &operator=(RefTy Ref) {
+MaybeRef = Ref;
+return *this;
+  }
+};
+
+} // end namespace FileMgr
 } // end namespace clang
 
+namespace llvm {
+namespace optional_detail {
+
+/// Customize OptionalStorage to use DirectoryEntryRef and
+/// its optional_none_tag to keep it the size of a single pointer.
+template <>
+class OptionalStorage
+: public clang::FileMgr::MapEntryOptionalStorage 
{
+  using StorageImpl =
+  clang::FileMgr::MapEntryOptionalStorage;
+
+public:
+  OptionalStorage() = default;
+
+  template 
+  explicit OptionalStorage(in_place_t, ArgTypes &&...Args)
+  : StorageImpl(in_place_t{}, std::forward(Args)...) {}
+
+  OptionalStorage &operator=(clang::DirectoryEntryRef Ref) {
+StorageImpl::operator=(Ref);
+return *this;
+  }
+};
+
+static_assert(sizeof(Optional) ==
+  sizeof(clang::DirectoryEntryRef),
+  "Optional must avoid size overhead");
+
+static_assert(
+std::is_trivially_copyable>::value,
+"Optional should be trivially copyable");
+

[clang] 94f537c - Remove dead code added in ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9, NFC

2020-11-30 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-30T14:50:46-08:00
New Revision: 94f537c6b2bb55c8e058a9989d02ab0d68a0c61a

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

LOG: Remove dead code added in ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9, NFC

This was a copy/paste bug; `M0` is never referenced later.

Added: 


Modified: 
clang/unittests/Basic/FileEntryTest.cpp

Removed: 




diff  --git a/clang/unittests/Basic/FileEntryTest.cpp 
b/clang/unittests/Basic/FileEntryTest.cpp
index b759d3ea36d6..f2619a21def7 100644
--- a/clang/unittests/Basic/FileEntryTest.cpp
+++ b/clang/unittests/Basic/FileEntryTest.cpp
@@ -92,7 +92,6 @@ TEST(FileEntryTest, equals) {
   EXPECT_NE(&R2.getFileEntry(), R1);
   EXPECT_NE(R1, R2);
 
-  OptionalFileEntryRefDegradesToFileEntryPtr M0;
   OptionalFileEntryRefDegradesToFileEntryPtr M1 = R1;
 
   EXPECT_EQ(M1, &R1.getFileEntry());



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


[clang] f85db7f - Lex: Update Module::findHeader to return FileEntryRef, NFC

2020-11-30 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-11-30T17:13:03-08:00
New Revision: f85db7f7ba683b2450892fde247311d7a48adbd0

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

LOG: Lex: Update Module::findHeader to return FileEntryRef, NFC

Update `Module::findHeader` to return `Optional` and
fix its one caller.

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

Added: 


Modified: 
clang/include/clang/Lex/ModuleMap.h
clang/lib/Lex/ModuleMap.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 5b164039080b..f6423e5b4258 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -328,10 +328,9 @@ class ModuleMap {
   /// \param NeedsFramework If M is not a framework but a missing header would
   ///be found in case M was, set it to true. False otherwise.
   /// \return The resolved file, if any.
-  const FileEntry *findHeader(Module *M,
-  const Module::UnresolvedHeaderDirective &Header,
-  SmallVectorImpl &RelativePathName,
-  bool &NeedsFramework);
+  Optional
+  findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
+ SmallVectorImpl &RelativePathName, bool &NeedsFramework);
 
   /// Resolve the given header directive.
   ///

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index cb49173757d8..28dd7ed969ad 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -171,23 +171,23 @@ static void appendSubframeworkPaths(Module *Mod,
 llvm::sys::path::append(Path, "Frameworks", Paths[I-1] + ".framework");
 }
 
-const FileEntry *ModuleMap::findHeader(
+Optional ModuleMap::findHeader(
 Module *M, const Module::UnresolvedHeaderDirective &Header,
 SmallVectorImpl &RelativePathName, bool &NeedsFramework) {
   // Search for the header file within the module's home directory.
   auto *Directory = M->Directory;
   SmallString<128> FullPathName(Directory->getName());
 
-  auto GetFile = [&](StringRef Filename) -> const FileEntry * {
-auto File = SourceMgr.getFileManager().getFile(Filename);
-if (!File ||
-(Header.Size && (*File)->getSize() != *Header.Size) ||
-(Header.ModTime && (*File)->getModificationTime() != *Header.ModTime))
-  return nullptr;
+  auto GetFile = [&](StringRef Filename) -> Optional {
+auto File =
+expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename));
+if (!File || (Header.Size && File->getSize() != *Header.Size) ||
+(Header.ModTime && File->getModificationTime() != *Header.ModTime))
+  return None;
 return *File;
   };
 
-  auto GetFrameworkFile = [&]() -> const FileEntry * {
+  auto GetFrameworkFile = [&]() -> Optional {
 unsigned FullPathLength = FullPathName.size();
 appendSubframeworkPaths(M, RelativePathName);
 unsigned RelativePathLength = RelativePathName.size();
@@ -195,7 +195,7 @@ const FileEntry *ModuleMap::findHeader(
 // Check whether this file is in the public headers.
 llvm::sys::path::append(RelativePathName, "Headers", Header.FileName);
 llvm::sys::path::append(FullPathName, RelativePathName);
-if (auto *File = GetFile(FullPathName))
+if (auto File = GetFile(FullPathName))
   return File;
 
 // Check whether this file is in the private headers.
@@ -227,7 +227,7 @@ const FileEntry *ModuleMap::findHeader(
   // Lookup for normal headers.
   llvm::sys::path::append(RelativePathName, Header.FileName);
   llvm::sys::path::append(FullPathName, RelativePathName);
-  auto *NormalHdrFile = GetFile(FullPathName);
+  auto NormalHdrFile = GetFile(FullPathName);
 
   if (!NormalHdrFile && Directory->getName().endswith(".framework")) {
 // The lack of 'framework' keyword in a module declaration it's a simple
@@ -241,7 +241,7 @@ const FileEntry *ModuleMap::findHeader(
   << Header.FileName << M->getFullModuleName();
   NeedsFramework = true;
 }
-return nullptr;
+return None;
   }
 
   return NormalHdrFile;
@@ -251,18 +251,18 @@ void ModuleMap::resolveHeader(Module *Mod,
   const Module::UnresolvedHeaderDirective &Header,
   bool &NeedsFramework) {
   SmallString<128> RelativePathName;
-  if (const FileEntry *File =
+  if (Optional File =
   findHeader(Mod, Header, RelativePathName, NeedsFramework)) {
 if (Header.IsUmbrella) {
-  const DirectoryEntry *UmbrellaDir = File->getDir();
+  const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry();
   if (Module *UmbrellaMod = UmbrellaDirs[UmbrellaDir])
 Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash)

  1   2   3   4   5   >