r333498 - Sema: Add a flag for rejecting member pointers with incomplete base types.

Mike Edwards via cfe-commits cfe-commits at lists.llvm.org
Tue May 29 21:35:24 PDT 2018


Ah, sorry I just saw 333501 and this already passed on the bot.  All green
again.  Thanks for the quick patch, sorry for the noise.

-Mike

On Tue, May 29, 2018 at 9:33 PM, Mike Edwards <mike at sqlby.me> wrote:

> Hi Peter,
> Would you please have a look at:
> http://green.lab.llvm.org/green/job/clang-stage1-cmake-
> RA-incremental/48945/
>
> It looks like this commit cause a test failure on the Green Dragon
> Incremental Builder.
>
> Thanks,
> Mike
>
> On Tue, May 29, 2018 at 8:40 PM, Peter Collingbourne via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
>
>> Author: pcc
>> Date: Tue May 29 20:40:04 2018
>> New Revision: 333498
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=333498&view=rev
>> Log:
>> Sema: Add a flag for rejecting member pointers with incomplete base types.
>>
>> Codebases that need to be compatible with the Microsoft ABI can pass
>> this flag to avoid issues caused by the lack of a fixed ABI for
>> incomplete member pointers.
>>
>> Differential Revision: https://reviews.llvm.org/D47503
>>
>> Added:
>>     cfe/trunk/test/Driver/complete-member-pointers.cpp
>>     cfe/trunk/test/SemaCXX/complete-member-pointers.cpp
>> Modified:
>>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>     cfe/trunk/include/clang/Basic/LangOptions.def
>>     cfe/trunk/include/clang/Driver/Options.td
>>     cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>>     cfe/trunk/lib/Sema/SemaType.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/DiagnosticSemaKinds.td?rev=333498&r1=333497&r2=333498&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 29
>> 20:40:04 2018
>> @@ -6350,6 +6350,8 @@ def err_bad_memptr_rhs : Error<
>>  def err_bad_memptr_lhs : Error<
>>    "left hand operand to %0 must be a %select{|pointer to }1class "
>>    "compatible with the right hand operand, but is %2">;
>> +def err_memptr_incomplete : Error<
>> +  "member pointer has incomplete base type %0">;
>>  def warn_exception_caught_by_earlier_handler : Warning<
>>    "exception of type %0 will be caught by earlier handler">,
>>    InGroup<Exceptions>;
>>
>> Modified: cfe/trunk/include/clang/Basic/LangOptions.def
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/LangOptions.def?rev=333498&r1=333497&r2=333498&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/include/clang/Basic/LangOptions.def (original)
>> +++ cfe/trunk/include/clang/Basic/LangOptions.def Tue May 29 20:40:04
>> 2018
>> @@ -247,6 +247,10 @@ ENUM_LANGOPT(AddressSpaceMapMangling , A
>>  LANGOPT(IncludeDefaultHeader, 1, 0, "Include default header file for
>> OpenCL")
>>  BENIGN_LANGOPT(DelayedTemplateParsing , 1, 0, "delayed template
>> parsing")
>>  LANGOPT(BlocksRuntimeOptional , 1, 0, "optional blocks runtime")
>> +LANGOPT(
>> +    CompleteMemberPointers, 1, 0,
>> +    "Require member pointer base types to be complete at the point where
>> the "
>> +    "type's inheritance model would be determined under the Microsoft
>> ABI")
>>
>>  ENUM_LANGOPT(GC, GCMode, 2, NonGC, "Objective-C Garbage Collection mode")
>>  ENUM_LANGOPT(ValueVisibilityMode, Visibility, 3, DefaultVisibility,
>>
>> Modified: cfe/trunk/include/clang/Driver/Options.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Driver/Options.td?rev=333498&r1=333497&r2=333498&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/include/clang/Driver/Options.td (original)
>> +++ cfe/trunk/include/clang/Driver/Options.td Tue May 29 20:40:04 2018
>> @@ -782,6 +782,12 @@ def fcomment_block_commands : CommaJoine
>>  def fparse_all_comments : Flag<["-"], "fparse-all-comments">,
>> Group<f_clang_Group>, Flags<[CC1Option]>;
>>  def fcommon : Flag<["-"], "fcommon">, Group<f_Group>;
>>  def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">,
>> Group<f_Group>;
>> +def fcomplete_member_pointers : Flag<["-"],
>> "fcomplete-member-pointers">, Group<f_clang_Group>,
>> +   Flags<[CoreOption, CC1Option]>,
>> +   HelpText<"Require member pointer base types to be complete if they
>> would be significant under the Microsoft ABI">;
>> +def fno_complete_member_pointers : Flag<["-"],
>> "fno-complete-member-pointers">, Group<f_clang_Group>,
>> +   Flags<[CoreOption]>,
>> +   HelpText<"Do not require member pointer base types to be complete if
>> they would be significant under the Microsoft ABI">;
>>  def fconstant_cfstrings : Flag<["-"], "fconstant-cfstrings">,
>> Group<f_Group>;
>>  def fconstant_string_class_EQ : Joined<["-"],
>> "fconstant-string-class=">, Group<f_Group>;
>>  def fconstexpr_depth_EQ : Joined<["-"], "fconstexpr-depth=">,
>> Group<f_Group>;
>>
>> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Too
>> lChains/Clang.cpp?rev=333498&r1=333497&r2=333498&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue May 29 20:40:04 2018
>> @@ -4784,6 +4784,10 @@ void Clang::ConstructJob(Compilation &C,
>>        CmdArgs.push_back("-fforce-enable-int128");
>>    }
>>
>> +  if (Args.hasFlag(options::OPT_fcomplete_member_pointers,
>> +                   options::OPT_fno_complete_member_pointers, false))
>> +    CmdArgs.push_back("-fcomplete-member-pointers");
>> +
>>    // Finally add the compile command to the compilation.
>>    if (Args.hasArg(options::OPT__SLASH_fallback) &&
>>        Output.getType() == types::TY_Object &&
>>
>> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/
>> CompilerInvocation.cpp?rev=333498&r1=333497&r2=333498&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
>> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue May 29 20:40:04
>> 2018
>> @@ -2754,6 +2754,8 @@ static void ParseLangArgs(LangOptions &O
>>            << A->getAsString(Args) << A->getValue();
>>      }
>>    }
>> +
>> +  Opts.CompleteMemberPointers = Args.hasArg(OPT_fcomplete_memb
>> er_pointers);
>>  }
>>
>>  static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
>>
>> Modified: cfe/trunk/lib/Sema/SemaType.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaT
>> ype.cpp?rev=333498&r1=333497&r2=333498&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaType.cpp Tue May 29 20:40:04 2018
>> @@ -7585,11 +7585,17 @@ bool Sema::RequireCompleteTypeImpl(Sourc
>>    //  assert(!T->isDependentType() &&
>>    //         "Can't ask whether a dependent type is complete");
>>
>> -  // We lock in the inheritance model once somebody has asked us to
>> ensure
>> -  // that a pointer-to-member type is complete.
>> -  if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
>> -    if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>()) {
>> -      if (!MPTy->getClass()->isDependentType()) {
>> +  if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>()) {
>> +    if (!MPTy->getClass()->isDependentType()) {
>> +      if (getLangOpts().CompleteMemberPointers &&
>> +          !MPTy->getClass()->getAsCXXRecordDecl()->isBeingDefined() &&
>> +          RequireCompleteType(Loc, QualType(MPTy->getClass(), 0),
>> +                              diag::err_memptr_incomplete))
>> +        return true;
>> +
>> +      // We lock in the inheritance model once somebody has asked us to
>> ensure
>> +      // that a pointer-to-member type is complete.
>> +      if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
>>          (void)isCompleteType(Loc, QualType(MPTy->getClass(), 0));
>>          assignInheritanceModel(*this, MPTy->getMostRecentCXXRecordDe
>> cl());
>>        }
>>
>> Added: cfe/trunk/test/Driver/complete-member-pointers.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/co
>> mplete-member-pointers.cpp?rev=333498&view=auto
>> ============================================================
>> ==================
>> --- cfe/trunk/test/Driver/complete-member-pointers.cpp (added)
>> +++ cfe/trunk/test/Driver/complete-member-pointers.cpp Tue May 29
>> 20:40:04 2018
>> @@ -0,0 +1,7 @@
>> +// RUN: %clangxx -### -c %s -o %t.o -target x86_64-unknown-linux 2>&1 |
>> FileCheck --check-prefix=NOFLAG %s
>> +// RUN: %clangxx -### -c %s -o %t.o -target x86_64-unknown-linux
>> -fcomplete-member-pointers 2>&1 | FileCheck %s
>> +// RUN: %clangxx -### -c %s -o %t.o -target x86_64-unknown-linux
>> -fcomplete-member-pointers -fno-complete-member-pointers 2>&1 | FileCheck
>> --check-prefix=NOFLAG %s
>> +// RUN: %clang_cl -### /c %s /Fo%t.o -target x86_64-pc-win32
>> -fcomplete-member-pointers 2>&1 | FileCheck %s
>> +
>> +// CHECK: "-fcomplete-member-pointers"
>> +// NOFLAG-NOT: "-fcomplete-member-pointers"
>>
>> Added: cfe/trunk/test/SemaCXX/complete-member-pointers.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/
>> complete-member-pointers.cpp?rev=333498&view=auto
>> ============================================================
>> ==================
>> --- cfe/trunk/test/SemaCXX/complete-member-pointers.cpp (added)
>> +++ cfe/trunk/test/SemaCXX/complete-member-pointers.cpp Tue May 29
>> 20:40:04 2018
>> @@ -0,0 +1,15 @@
>> +// RUN: %clang_cc1 -verify -fsyntax-only -fcomplete-member-pointers %s
>> +
>> +struct S; // expected-note {{forward declaration of 'S'}}
>> +typedef int S::*t;
>> +t foo; // expected-error {{member pointer has incomplete base type 'S'}}
>> +
>> +struct S2 {
>> +  int S2::*foo;
>> +};
>> +int S2::*bar;
>> +
>> +template <typename T>
>> +struct S3 {
>> +  int T::*foo;
>> +};
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180529/76584dfb/attachment-0001.html>


More information about the cfe-commits mailing list