Re: [PATCH] RE: [cfe-dev] missing return statement for non-void functions in C++

2015-08-13 Thread Gabriel Dos Reis via cfe-commits
Please make such programs crash early and often.  They are a nightmare to
maintain.  Make them blow in the face of the original authors; not after
they are gone.

-- Gaby

On Thu, Aug 13, 2015 at 11:18 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Thu, Aug 13, 2015 at 1:52 AM, Sjoerd Meijer 
> wrote:
>
>> Hi Richard,
>>
>> Thanks for reviewing. Agree, that was a bit confusing. More specifically,
>>
>> the warning message was confusing (i.e. wrong). This patch is for
>> compiling .c
>>
>> input in C++ mode. The new flag should be ignored for C++ **input**, and
>> indeed
>>
>> not when it is in C++ *mode* as the warning message said earlier. So I
>> have
>>
>> changed the warning message accordingly and hope that solves it, see
>> attached
>>
>> patch.
>>
>
> What is the distinction you're trying to draw here? This patch still
> doesn't make sense to me. This flag is only meaningful when compiling as
> C++. You ignore it when compiling as C but produce a warning that says it's
> ignored when compiling as C++.
>
>
>> Cheers.
>>
>>
>>
>> *From:* meta...@gmail.com [mailto:meta...@gmail.com] *On Behalf Of *Richard
>> Smith
>> *Sent:* 12 August 2015 23:06
>> *To:* Sjoerd Meijer
>> *Cc:* Hal Finkel; Marshall Clow; cfe-commits
>>
>> *Subject:* Re: [PATCH] RE: [cfe-dev] missing return statement for
>> non-void functions in C++
>>
>>
>>
>> This patch seems a bit confused. You warn that the flag is ignored in
>> C++, but it only has an effect in C++. You have a testcase with a .c
>> extension that is built with -x c++.
>>
>>
>>
>> On Wed, Aug 12, 2015 at 5:23 AM, Sjoerd Meijer 
>> wrote:
>>
>> [ + cfe-commits@lists.llvm.org ]
>>
>>
>>
>> Hi,
>>
>> The functionality is now available under a flag, see attached patch. Note
>> that the flag is ignored in C++ mode, so it will help the use case of
>> compiling (legacy) C code with a C++ compiler.
>>
>> Cheers,
>>
>> Sjoerd.
>>
>>
>>
>> *From:* Sjoerd Meijer [mailto:sjoerd.mei...@arm.com
>> ]
>> *Sent:* 03 August 2015 11:40
>> *To:* 'Richard Smith'
>> *Cc:* Hal Finkel; Marshall Clow; cfe-...@cs.uiuc.edu Developers; cfe
>> commits
>> *Subject:* RE: [PATCH] RE: [cfe-dev] missing return statement for
>> non-void functions in C++
>>
>>
>>
>> Hi Richard,
>>
>>
>>
>> I agree with your conclusions and will start preparing a patch for option
>> 3) under a flag that is off by default; this enables folks to build/run C
>> code in C++. I actually think option 2) would be a good one too, but as it
>> is already available under a flag I also don’t see how useful it is
>> combining options 2) and 3) with another (or one more) flag that is off by
>> default.
>>
>>
>>
>> Cheers.
>>
>>
>>
>> *From:* meta...@gmail.com [mailto:meta...@gmail.com ] *On
>> Behalf Of *Richard Smith
>> *Sent:* 31 July 2015 19:46
>> *To:* Sjoerd Meijer
>> *Cc:* Hal Finkel; Marshall Clow; cfe-...@cs.uiuc.edu Developers; cfe
>> commits
>> *Subject:* Re: [PATCH] RE: [cfe-dev] missing return statement for
>> non-void functions in C++
>>
>>
>>
>> On Fri, Jul 31, 2015 at 7:35 AM, Sjoerd Meijer 
>> wrote:
>>
>> Hi, I am not sure if we came to a conclusion. Please find attached a
>> patch. It simply removes the two lines that insert an unreachable statement
>> (which cause removal of the return statement). Please note that at -O0 the
>> trap instruction is still generated. Is this something we could live with?
>>
>>
>>
>> I don't think this is an improvement:
>>
>>
>>
>> This doesn't satisfy the folks who want an 'unreachable' for better code
>> size and optimization, and it doesn't satisfy the folks who want a
>> guaranteed trap for security, and it doesn't satisfy the folks who want
>> their broken code to limp along (because it'll still trap at -O0), and it
>> is at best a minor improvement for the folks who want missing returns to be
>> more easily debuggable (with -On, the code goes wrong in the caller, or
>> appears to work, rather than falling into an unrelated function, and
>> debugging this with -O0 was already easy).
>>
>>
>>
>> I think there are three options that are defensible here:
>>
>> 1) The status quo: this is UB and we treat it as such and optimize on
>> that basis, but provide a trap as a convenience at -O0
>>
>> 2) The secure approach: this is UB but we always trap
>>
>> 3) Define the behavior to return 'undef' for C types: this allows
>> questionable C code that has UB in C++ to keep working when built with a
>> C++ compiler
>>
>>
>>
>> Note that (3) can be combined with either (1) or (2). (2) is already
>> available via the 'return' sanitizer. So this really reduces to: in those
>> cases where C says it's OK so long as the caller doesn't look at the
>> returned value (and where the return type doesn't have a non-trivial copy
>> constructor or destructor, isn't a reference, and so on), should we attempt
>> to preserve the C behaviour? I would be OK with putting that behind a `-f`
>> flag (perhaps `-fstrict-return` or similar) to support those folks who want
>> to build C 

Re: r256535 - Revert "[TrailingObjects] Use a different technique to determine if a getDecl"

2015-12-28 Thread Gabriel Dos Reis via cfe-commits
James, if this wasn't already done, please file a bug against MSVC so this
can be fixed in future releases.

On Mon, Dec 28, 2015 at 8:46 PM, James Y Knight via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: jyknight
> Date: Mon Dec 28 22:46:43 2015
> New Revision: 256535
>
> URL: http://llvm.org/viewvc/llvm-project?rev=256535&view=rev
> Log:
> Revert "[TrailingObjects] Use a different technique to determine if a
> getDecl"
>
> This reverts commit r256534.
>
> Failed to build on MSVC with error:
> clang/ASTMatchers/ASTMatchersInternal.h(572): error C2228: left of
> '.getDecl' must have class/struct/union
> type is 'add_rvalue_reference<_Ty>::type'
>
> (
> http://lab.llvm.org:8011/builders/lldb-x86-win7-msvc/builds/13873/steps/build/logs/stdio
> )
>
> Modified:
> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=256535&r1=256534&r2=256535&view=diff
>
> ==
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Mon Dec 28
> 22:46:43 2015
> @@ -558,19 +558,22 @@ bool matchesFirstInPointerRange(const Ma
>return false;
>  }
>
> -/// Metafunction to determine if type T has a member called
> -/// getDecl.
> -///
> -/// There is a default template inheriting from "false_type". Then, a
> -/// partial specialization inherits from "true_type". However, this
> -/// specialization will only exist when the call to getDecl() isn't an
> -/// error -- it vanishes by SFINAE when the member doesn't exist.
> -template  struct type_sink_to_void { typedef void type; };
> -template  struct has_getDecl :
> std::false_type {};
> -template 
> -struct has_getDecl<
> -T, typename
> type_sink_to_void().getDecl())>::type>
> -: std::true_type {};
> +/// \brief Metafunction to determine if type T has a member called
> getDecl.
> +template  struct has_getDecl {
> +  struct Default { int getDecl; };
> +  struct Derived : T, Default { };
> +
> +  template struct CheckT;
> +
> +  // If T::getDecl exists, an ambiguity arises and CheckT will
> +  // not be instantiable. This makes f(...) the only available
> +  // overload.
> +  template
> +  static char (&f(CheckT*))[1];
> +  template static char (&f(...))[2];
> +
> +  static bool const value = sizeof(f(nullptr)) == 2;
> +};
>
>  /// \brief Matches overloaded operators with a specific name.
>  ///
>
>
> ___
> 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