From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.140.178.6 with SMTP id y6mr3352604qhy.14.1464973496333; Fri, 03 Jun 2016 10:04:56 -0700 (PDT) X-Received: by 10.157.18.196 with SMTP id g62mr67078otg.3.1464973496294; Fri, 03 Jun 2016 10:04:56 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!p34no2209310qgp.1!news-out.google.com!z5ni82qge.0!nntp.google.com!q32no3228773qgq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 3 Jun 2016 10:04:56 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2.126.2.142; posting-account=L2-UcQkAAAAfd_BqbeNHs3XeM0jTXloS NNTP-Posting-Host: 2.126.2.142 References: <369391051.486634184.002061.laguest-archeia.com@nntp.aioe.org> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <718de74d-ab15-4eee-983f-b78d8f8070f1@googlegroups.com> Subject: Re: no code generation for c strings From: Lucretia Injection-Date: Fri, 03 Jun 2016 17:04:56 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:30586 Date: 2016-06-03T10:04:56-07:00 List-Id: On Friday, 3 June 2016 17:30:14 UTC+1, Simon Wright wrote: > "Dmitry A. Kazakov" writes: > > > On 03/06/2016 10:14, Luke A. Guest wrote: > > > >> What I would like to have is have the compiler recognise that I've declared > >> a static char_array and just not generate a call to the secondary stack to > >> allocate a new string. Is this actually possible? -O2/3 still generate the > >> call. > >> > >> S : constant char_array := to_c ("hello" & nul); > > > > S : constant char_array := "hello" & char'val (0); > > GCC 6.1.0: > > with Interfaces.C; > package Char_Arrays is > use type Interfaces.C.char; > use type Interfaces.C.char_array; > S : constant Interfaces.C.char_array := > "hello" & Interfaces.C.char'Val (0); > end Char_Arrays; > > generates (x86_64-apple-darwin15) > > .globl _char_arrays__s > .const > .align 3 > _char_arrays__s: > .ascii "hello\0" > .space 2 > .globl _char_arrays_E > .data > .align 1 > _char_arrays_E: > .space 2 > .subsections_via_symbols > > & similar for arm-eabi. Interesting, I tried this and dumped the asm, similar there, but as soon as you add more code, it just gets confusing, because it never references the actual label for the string anywhere. with Interfaces.C; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Ada.Text_Io; use Ada.Text_Io; procedure C_Str is package C renames Interfaces.C; use type Interfaces.C.char; use type Interfaces.C.char_array; -- S1 : constant Interfaces.C.char_array := Interfaces.C.To_C ("hello" & Nul, Append_Nul => False); -- S2 : constant C.char_array := C.To_C ("hello"); S3 : constant C.char_array := "hello" & C.char'Val (0); begin -- Put_Line (C.To_Ada (S3)); null; end C_Str; gnatmake -gnatG c_str.adb -cargs -S gcc -c -gnatG -S c_str.adb Source recreated from tree for C_Str (body) ------------------------------------------- with ada; with ada; with ada.ada__characters; with interfaces; with interfaces.interfaces__c; with ada.ada__characters.ada__characters__latin_1; use ada.ada__characters.ada__characters__latin_1; with ada.ada__text_io; use ada.ada__text_io; procedure c_str is c___XRP_interfaces__c___XE : _renaming_type; package c renames interfaces.interfaces__c; use type interfaces.interfaces__c.interfaces__c__char; use type interfaces.interfaces__c.interfaces__c__char_array; subtype c_str__Ts3S is interfaces__c__char_array (0 .. 5); s3 : constant interfaces__c__char_array (0 .. 5) := "hello["00"]"; begin null; return; end c_str; gnatmake: "c_str.ali" WARNING: ALI or object file not found after compile gnatmake: "c_str.adb" compilation error .file "c_str.adb" .text .globl _ada_c_str .type _ada_c_str, @function _ada_c_str: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 nop nop popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1: .size _ada_c_str, .-_ada_c_str .section .rodata .align 8 .type s3.3058, @object .size s3.3058, 8 s3.3058: .string "hello" .zero 2 .ident "GCC: (GNU) 4.9.2" .section .note.GNU-stack,"",@progbits