From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10967 invoked by alias); 30 Jan 2011 21:02:19 -0000 Received: (qmail 10958 invoked by uid 22791); 30 Jan 2011 21:02:19 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_CP,TW_OV,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from vm-emlprdomr-03.its.yale.edu (HELO vm-emlprdomr-03.its.yale.edu) (130.132.50.144) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 30 Jan 2011 21:02:14 +0000 Received: from [192.168.1.100] (cpe-69-200-237-227.nyc.res.rr.com [69.200.237.227]) (authenticated bits=0) by vm-emlprdomr-03.its.yale.edu (8.14.4/8.14.4) with ESMTP id p0UL2C4j031304 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Sun, 30 Jan 2011 16:02:12 -0500 Subject: Re: GCC Internals: built-in functions? Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii From: Amittai Aviram In-Reply-To: Date: Sun, 30 Jan 2011 21:07:00 -0000 Cc: gcc-help@gcc.gnu.org Content-Transfer-Encoding: quoted-printable Message-Id: <189DEF72-E802-4454-81A2-08D7C1D1BF24@yale.edu> References: To: Jonathan Wakely X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg00473.txt.bz2 On Jan 30, 2011, at 3:57 PM, Jonathan Wakely wrote: > On 30 January 2011 20:45, Amittai Aviram wrote: >> On this GCC Internals page >>=20 >> http://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Arc= hitecture_3_4 >>=20 >> I found the following in the "GCC Initialization" section: >>=20 >> "GCC built-in functions are the functions that are evaluated at compile = time. For example, if the size argument of a strcpy() function is a constan= t then GCC replaces the function call with the required number of assignmen= ts." >>=20 >> I was curious about this, so I tried compiling to assembly (-S) a very s= imple program: >>=20 >> #include >> #include >> #include >>=20 >> int main(void) { >>=20 >> char s1[0x10]; >> char * s0 =3D "HELLO"; >> strcpy(s1, s0); >> printf("%s %s\n", s0, s1); >> return EXIT_SUCCESS; >> } >>=20 >> But the resulting assembly code simply calls strcpy with the two argumen= ts, just as I would have expected had I not read the above sentence: >>=20 >> movq $.LC0, -40(%rbp) >> movq -40(%rbp), %rdx >> leaq -32(%rbp), %rax >> movq %rdx, %rsi >> movq %rax, %rdi >> call strcpy >>=20 >> (Here, .LC0 labels the string "HELLO".) >>=20 >> So what does that sentence actually mean and what am I missing? Thanks! >=20 > strcpy has no 'size' parameter, I assume it's meant to say strncpy I tried it with strncpy and with __builtin_strncpy, with exactly the same r= esults, i.e., the assembly code still calls strncpy with three arguments. Amittai Aviram PhD Student in Computer Science Yale University 646 483 2639 amittai.aviram@yale.edu http://www.amittai.com