[PATCH] in C mode, __builtin_va_start tries to accept a reference, sees a record, decides it's a C++ class, then crashes because it isn't

Anton Korobeynikov anton at korobeynikov.info
Mon Aug 5 15:23:43 PDT 2013


Please consider reading http://llvm.org/docs/DeveloperPolicy.html#making-a-patch

On Mon, Aug 5, 2013 at 6:46 PM, Artyom Skrobov <Artyom.Skrobov at arm.com> wrote:
> diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
> index 4072550..07875c4 100644
> --- a/lib/Sema/SemaInit.cpp
> +++ b/lib/Sema/SemaInit.cpp
> @@ -3424,15 +3424,18 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S,
>      return OR_No_Viable_Function;
>
>    const RecordType *T2RecordType = 0;
> +  RecordDecl *T2RecordDecl = 0;
>    if ((T2RecordType = T2->getAs<RecordType>()) &&
> +      (T2RecordDecl = T2RecordType->getDecl()) &&
> +      isa<CXXRecordDecl>(T2RecordDecl) &&
>        !S.RequireCompleteType(Kind.getLocation(), T2, 0)) {
>      // The type we're converting from is a class type, enumerate its conversion
>      // functions.
> -    CXXRecordDecl *T2RecordDecl = cast<CXXRecordDecl>(T2RecordType->getDecl());
> +    CXXRecordDecl *T2CXXRecordDecl = cast<CXXRecordDecl>(T2RecordDecl);
>
>      std::pair<CXXRecordDecl::conversion_iterator,
>                CXXRecordDecl::conversion_iterator>
> -      Conversions = T2RecordDecl->getVisibleConversionFunctions();
> +      Conversions = T2CXXRecordDecl->getVisibleConversionFunctions();
>      for (CXXRecordDecl::conversion_iterator
>             I = Conversions.first, E = Conversions.second; I != E; ++I) {
>        NamedDecl *D = *I;
> diff --git a/test/Sema/va_start_arm.c b/test/Sema/va_start_arm.c
> new file mode 100644
> index 0000000..f3be7f2
> --- /dev/null
> +++ b/test/Sema/va_start_arm.c
> @@ -0,0 +1,7 @@
> +// RUN: %clang_cc1 -triple armv7 -verify %s
> +typedef struct __va_list_tag {} __va_list_tag;
> +
> +void test(int n, ...) {
> +    __va_list_tag ap1;
> +    __builtin_va_start(ap1, n); // expected-error {{non-const lvalue reference to type '__builtin_va_list' cannot bind to a value of unrelated type '__va_list_tag' (aka 'struct __va_list_tag')}}
> +}
>
> -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



-- 
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University




More information about the cfe-commits mailing list