From patchwork Thu Jan 16 19:54:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 311840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1BC682C0082 for ; Fri, 17 Jan 2014 06:54:24 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=B20S7FnogJtxTXHbwYcbfNbW7gWLzf9Xavewz8e3u+f6iU LccJxrKh7S18UL+kl1Kj2v+/yBR1XKN8SQUit+jdeyxlN5E2uBYy3M+tEIBHeuUd lnpY3o0rhHE0N2OfkVeixeg90L8g+cZuIpjYULzTjP0LC29FaBhL1JUmTey78= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=uRdqWLB3n7BtmCFaE8n7FT9yuxg=; b=w9fOqSudyvbAVFl1cA05 sv5dGHGDcw4z3jkBXyYP6CWmsaGf77DHp06rDmV1CSoWwU+BfFnebcriZn3IHEK7 Lz/FJsI2xGVH1Mg70YvNsuDgvgJp1bfar+GX/5+avajqeVKm/aXJtGNTl1xcnWPe Ma/Hrk1/yZZnnB7s4FBnmjo= Received: (qmail 22727 invoked by alias); 16 Jan 2014 19:54:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 22716 invoked by uid 89); 16 Jan 2014 19:54:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Jan 2014 19:54:16 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0GJsFKl016686 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 16 Jan 2014 14:54:15 -0500 Received: from [10.10.116.20] ([10.10.116.20]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0GJsEGD009556 for ; Thu, 16 Jan 2014 14:54:14 -0500 Message-ID: <52D838E6.4030402@redhat.com> Date: Thu, 16 Jan 2014 14:54:14 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/59821 (builtin_LINE in default args) The testcase noted that builtin_LINE used in a default argument was getting the location of the call in one case, and the location of the function declaration in another. The way it is used in default arguments suggests that the intent is for it to have the location of the call. This patch updates the EXPR_LOCATION of calls to builtin_LINE and builtin_FILE to match the location where the default argument is expanded, so that the result is consistent. Tested x86_64-pc-linux-gnu, applying to trunk. commit 4088607eba17cb79c9bda0d5e2829705c75386b8 Author: Jason Merrill Date: Thu Jan 16 13:54:35 2014 -0500 PR c++/59821 * tree.c (bot_manip): Update the location of builtin_LINE and builtin_FILE calls. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 7aad1eb..ce41c3b 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2306,7 +2306,20 @@ bot_manip (tree* tp, int* walk_subtrees, void* data) /* Make a copy of this node. */ t = copy_tree_r (tp, walk_subtrees, NULL); if (TREE_CODE (*tp) == CALL_EXPR) - set_flags_from_callee (*tp); + { + set_flags_from_callee (*tp); + + /* builtin_LINE and builtin_FILE get the location where the default + argument is expanded, not where the call was written. */ + tree callee = get_callee_fndecl (*tp); + if (callee && DECL_BUILT_IN (callee)) + switch (DECL_FUNCTION_CODE (callee)) + { + case BUILT_IN_FILE: + case BUILT_IN_LINE: + SET_EXPR_LOCATION (*tp, input_location); + } + } return t; } diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 84fd594..8568316 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -8726,6 +8726,8 @@ means that the compiler can assume for @code{x}, set to @code{arg}, that @deftypefn {Built-in Function} int __builtin_LINE () This function is the equivalent to the preprocessor @code{__LINE__} macro and returns the line number of the invocation of the built-in. +In a C++ default argument for a function F, it gets the line number of +the call to F. @end deftypefn @deftypefn {Built-in Function} {const char *} __builtin_FUNCTION () @@ -8736,6 +8738,8 @@ macro and returns the function name the invocation of the built-in is in. @deftypefn {Built-in Function} {const char *} __builtin_FILE () This function is the equivalent to the preprocessor @code{__FILE__} macro and returns the file name the invocation of the built-in is in. +In a C++ default argument for a function F, it gets the file name of +the call to F. @end deftypefn @deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end}) diff --git a/gcc/testsuite/g++.dg/ext/builtin-line1.C b/gcc/testsuite/g++.dg/ext/builtin-line1.C new file mode 100644 index 0000000..21a4f59 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin-line1.C @@ -0,0 +1,17 @@ +// __builtin_LINE gets the location where the default argument is expanded. +// { dg-do run } + +#include +struct Foo +{ + int line; + Foo( int line = __builtin_LINE() ) + : line( line ) + {} +}; + +int main() +{ + assert (Foo().line == __LINE__); + assert ((new Foo)->line == __LINE__); +}