Bug 12909 - ambiguity in mangling vector types
Summary: ambiguity in mangling vector types
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: 4.5.0
Assignee: Jason Merrill
URL:
Keywords: ABI, assemble-failure
: 25963 41959 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-11-05 09:48 UTC by jbeulich
Modified: 2010-05-22 04:04 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-03-05 15:08:00


Attachments
g++.dg/abi/mangle40.C assembly file from x86_64-apple-darwin10 (645 bytes, text/plain)
2010-03-04 02:32 UTC, Jack Howarth
Details
patch to fix mangle41.C on darwin (504 bytes, patch)
2010-03-04 15:21 UTC, Jason Merrill
Details | Diff
revised mangle-darwin patch (570 bytes, text/plain)
2010-03-05 02:31 UTC, Jack Howarth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jbeulich 2003-11-05 09:48:51 UTC
Since only the base type and the fact that it is a vector, but not the number of
elements in it is encoded in the mangling of vector types, vector types with
identical base types but different element counts (e.g. V4SI and V2SI) mangle
the same. Thus the code below passes the compiler successfully, but fails the
assembly stage (Error: symbol `_Z4testU8__vectorj' is already defined):

typedef unsigned __attribute__((__mode__(__V2SI__))) __mm64i;
typedef unsigned __attribute__((__mode__(__V4SI__))) __mm128i;

__mm64i test(__mm64i n) {
	return n;
}

__mm128i test(__mm128i n) {
	return n;
}
Comment 1 Andrew Pinski 2003-11-05 14:23:09 UTC
I can confirm this on the mainline (20031104).
Comment 2 Andrew Pinski 2006-01-26 01:13:12 UTC
*** Bug 25963 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2009-11-05 23:26:23 UTC
*** Bug 41959 has been marked as a duplicate of this bug. ***
Comment 4 Jason Merrill 2010-02-03 20:43:05 UTC
Subject: Bug 12909

Author: jason
Date: Wed Feb  3 20:42:35 2010
New Revision: 156481

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156481
Log:
	PR c++/12909
	* mangle.c (write_type) [VECTOR_TYPE]: Change mangling.

Added:
    trunk/gcc/testsuite/g++.dg/abi/mangle36.C
Modified:
    trunk/gcc/common.opt
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/mangle.c
    trunk/gcc/testsuite/ChangeLog
    trunk/include/demangle.h
    trunk/libiberty/ChangeLog
    trunk/libiberty/cp-demangle.c
    trunk/libiberty/testsuite/demangle-expected

Comment 5 Jason Merrill 2010-02-03 22:01:43 UTC
Fixed for 4.5 with -fabi-version=4 or =0.  I still want to implement a transition scheme.
Comment 6 Jason Merrill 2010-02-24 19:26:53 UTC
Subject: Bug 12909

Author: jason
Date: Wed Feb 24 19:26:38 2010
New Revision: 157052

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157052
Log:
	PR c++/12909
	* mangle.c (write_type): Give -Wabi warning for old vector mangling.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/mangle.c

Comment 7 Jason Merrill 2010-03-03 19:02:06 UTC
Subject: Bug 12909

Author: jason
Date: Wed Mar  3 19:01:36 2010
New Revision: 157201

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157201
Log:
	PR c++/12909
	* mangle.c: Include cgraph.h.
	(mangle_decl): If the mangled name will change in a later
	ABI version, make the later mangled name an alias.
	* method.c (make_alias_for): Copy DECL_ARGUMENTS.
	* Make-lang.in (mangle.o): Depend on cgraph.h.

Added:
    trunk/gcc/testsuite/g++.dg/abi/mangle40.C
    trunk/gcc/testsuite/g++.dg/abi/mangle41.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/Make-lang.in
    trunk/gcc/cp/mangle.c
    trunk/gcc/cp/method.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Jason Merrill 2010-03-03 19:02:21 UTC
Subject: Bug 12909

Author: jason
Date: Wed Mar  3 19:01:46 2010
New Revision: 157202

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157202
Log:
	PR c++/12909
	* method.c (make_alias_for): Handle VAR_DECL, too.
	* decl2.c (vague_linkage_p): Rename from vague_linkage_fn_p.
	* tree.c (no_linkage_check): Adjust.
	* decl.c (maybe_commonize_var): Adjust.
	* mangle.c (mangle_decl): Adjust.
	* cp-tree.h: Adjust.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/decl2.c
    trunk/gcc/cp/mangle.c
    trunk/gcc/cp/method.c
    trunk/gcc/cp/tree.c

Comment 9 Jason Merrill 2010-03-03 19:02:35 UTC
Subject: Bug 12909

Author: jason
Date: Wed Mar  3 19:01:58 2010
New Revision: 157203

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157203
Log:
	PR c++/12909
	* cgraph.h (varpool_node): Add extra_name field.
	* varpool.c (varpool_extra_name_alias): New.
	(varpool_assemble_decl): Emit extra name aliases.
	(varpool_mark_needed_node): Look past an extra name alias.
cp/
	* mangle.c (mangle_decl): Handle VAR_DECL, too.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cgraph.h
    trunk/gcc/cp/mangle.c
    trunk/gcc/testsuite/g++.dg/abi/mangle40.C
    trunk/gcc/varpool.c

Comment 10 Jason Merrill 2010-03-03 19:02:48 UTC
Subject: Bug 12909

Author: jason
Date: Wed Mar  3 19:02:08 2010
New Revision: 157204

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157204
Log:
	PR c++/12909
	* lto-streamer.h (LTO_tags): Add LTO_var_decl_alias.
	* lto-streamer-in.c (lto_input_tree): Read it.
	* lto-streamer-out.c (output_unreferenced_globals): Write it.

Added:
    trunk/gcc/testsuite/g++.dg/lto/20100302.h
    trunk/gcc/testsuite/g++.dg/lto/20100302_0.C
    trunk/gcc/testsuite/g++.dg/lto/20100302_1.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lto-streamer-in.c
    trunk/gcc/lto-streamer-out.c
    trunk/gcc/lto-streamer.h
    trunk/gcc/testsuite/ChangeLog

Comment 11 Jason Merrill 2010-03-03 19:05:02 UTC
As fixed as it reasonably can be until we switch to -fabi-version=4.  We now have a new mangling enabled with that flag, an error in the compiler for this situation, a warning with -Wabi about the old mangling, and forward-compatibility aliases so that code built with ABI v4 can link against definitions compiled with ABI v2.
Comment 12 Jack Howarth 2010-03-04 02:28:17 UTC
FAIL: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_Z1fIDv4_fEvT_
FAIL: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_ZN1AIDv4_fE1tE
FAIL: g++.dg/abi/mangle41.C  (test for errors, line 6)
FAIL: g++.dg/abi/mangle41.C  (test for warnings, line 7)

are failing on x86_64-apple-darwin10.
Comment 13 Jack Howarth 2010-03-04 02:30:51 UTC
/sw/src/fink.build/gcc45-4.4.999-20100303/darwin_objdir/gcc/testsuite/g++/../../g++ -B/sw/src/fink.build/gcc45-4.4.999-20100303/darwin_objdir/gcc/testsuite/g++/../../ /sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/gcc/testsuite/g++.dg/abi/mangle40.C  -nostdinc++ -I/sw/src/fink.build/gcc45-4.4.999-20100303/darwin_objdir/x86_64-apple-darwin10.3.0/libstdc++-v3/include/x86_64-apple-darwin10.3.0 -I/sw/src/fink.build/gcc45-4.4.999-20100303/darwin_objdir/x86_64-apple-darwin10.3.0/libstdc++-v3/include -I/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/libstdc++-v3/libsupc++ -I/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/libstdc++-v3/include/backward -I/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/libstdc++-v3/testsuite/util -fmessage-length=0  -mavx -Wabi -fabi-version=2  -S  -o mangle40.s
/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/gcc/testsuite/g++.dg/abi/mangle40.C: In instantiation of ‘void f(T) [with T = float __vector[4]]’:
/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/gcc/testsuite/g++.dg/abi/mangle40.C:25:18:   instantiated from here
/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/gcc/testsuite/g++.dg/abi/mangle40.C:21:6: warning: the mangled name of ‘void f(T) [with T = float __vector[4]]’ will change in a future version of GCC
/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/gcc/testsuite/g++.dg/abi/mangle40.C: In instantiation of ‘float __vector[4] A<float __vector[4]>::t’:
/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/gcc/testsuite/g++.dg/abi/mangle40.C:26:1:   instantiated from here
/sw/src/fink.build/gcc45-4.4.999-20100303/gcc-4.5-20100303/gcc/testsuite/g++.dg/abi/mangle40.C:18:9: warning: the mangled name of ‘A<float __vector[4]>::t’ will change in a future version of GCC

Comment 14 Jack Howarth 2010-03-04 02:32:21 UTC
Created attachment 20017 [details]
g++.dg/abi/mangle40.C assembly file from x86_64-apple-darwin10
Comment 15 Jason Merrill 2010-03-04 15:21:35 UTC
Created attachment 20022 [details]
patch to fix mangle41.C on darwin

Ah, it seems darwin doesn't define ASM_OUTPUT_DEF.  Does this patch fix mangle41.C?
Comment 16 Jack Howarth 2010-03-05 00:48:53 UTC
The patch doesn't allow a bootstrap. I get...

/sw/src/fink.build/gcc45-4.4.999-20100304/darwin_objdir/./prev-gcc/xgcc -B/sw/src/fink.build/gcc45-4.4.999-20100304/darwin_objdir/./prev-gcc/ -B/sw/lib/gcc4.5/x86_64-apple-darwin10.3.0/bin/ -B/sw/lib/gcc4.5/x86_64-apple-darwin10.3.0/bin/ -B/sw/lib/gcc4.5/x86_64-apple-darwin10.3.0/lib/ -isystem /sw/lib/gcc4.5/x86_64-apple-darwin10.3.0/include -isystem /sw/lib/gcc4.5/x86_64-apple-darwin10.3.0/sys-include    -c  -g -O2 -gtoggle -DIN_GCC   -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -Wold-style-definition -Wc++-compat -fno-common  -DHAVE_CONFIG_H -I. -Icp -I../../gcc-4.5-20100304/gcc -I../../gcc-4.5-20100304/gcc/cp -I../../gcc-4.5-20100304/gcc/../include -I../../gcc-4.5-20100304/gcc/../libcpp/include -I/sw/include -I/sw/include  -I../../gcc-4.5-20100304/gcc/../libdecnumber -I../../gcc-4.5-20100304/gcc/../libdecnumber/dpd -I../libdecnumber -I/sw/include  -I/sw/include -DCLOOG_PPL_BACKEND   -I/sw/include ../../gcc-4.5-20100304/gcc/cp/cp-objcp-common.c -o cp/cp-objcp-common.o
cc1: warnings being treated as errors
../../gcc-4.5-20100304/gcc/cp/mangle.c: In function 'mangle_decl':
../../gcc-4.5-20100304/gcc/cp/mangle.c:3065:17: error: unused variable 'alias'
../../gcc-4.5-20100304/gcc/cp/mangle.c:3065:12: error: unused variable 'id2'
../../gcc-4.5-20100304/gcc/cp/mangle.c:3064:11: error: unused variable 'save_ver'
make[3]: *** [cp/mangle.o] Error 1
Comment 17 Jack Howarth 2010-03-05 02:31:42 UTC
Created attachment 20023 [details]
revised mangle-darwin patch
Comment 18 Jack Howarth 2010-03-05 02:33:31 UTC
(In reply to comment #17)
> Created an attachment (id=20023) [edit]
> revised mangle-darwin patch
> 

This revised patch bootstraps on x86_64-apple-darwin10 and
eliminates the mangle41.c failures. We are still left with the failures...

FAIL: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_Z1fIDv4_fEvT_
FAIL: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_ZN1AIDv4_fE1tE

Does the mangle40.s assembly provide any clues?
Comment 19 Jason Merrill 2010-03-05 23:00:14 UTC
I just checked in a change to mangle40.C.  Did it fix the darwin failures?
Comment 20 Jack Howarth 2010-03-06 03:45:03 UTC
(In reply to comment #19)
> I just checked in a change to mangle40.C.  Did it fix the darwin failures?
> 

No. I still get...

Executing on host: /sw/src/fink.build/gcc45-4.4.999-20100305/darwin_objdir/gcc/testsuite/g++/../../g++ -B/sw/src/fink.build/gcc45-4.4.999-20100305/darwin_objdir/gcc/testsuite/g++/../../ /sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C  -nostdinc++ -I/sw/src/fink.build/gcc45-4.4.999-20100305/darwin_objdir/x86_64-apple-darwin10.3.0/libstdc++-v3/include/x86_64-apple-darwin10.3.0 -I/sw/src/fink.build/gcc45-4.4.999-20100305/darwin_objdir/x86_64-apple-darwin10.3.0/libstdc++-v3/include -I/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/libstdc++-v3/libsupc++ -I/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/libstdc++-v3/include/backward -I/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/libstdc++-v3/testsuite/util -fmessage-length=0  -mavx -Wabi -fabi-version=2  -S  -o mangle40.s    (timeout = 300)
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C: In instantiation of 'void f(T) [with T = float __vector[4]]':
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:27:18:   instantiated from here
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:23:6: warning: the mangled name of 'void f(T) [with T = float __vector[4]]' will change in a future version of GCC
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C: In instantiation of 'float __vector[4] A<float __vector[4]>::t':
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:28:1:   instantiated from here
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:20:9: warning: the mangled name of 'A<float __vector[4]>::t' will change in a future version of GCC
output is:
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C: In instantiation of 'void f(T) [with T = float __vector[4]]':
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:27:18:   instantiated from here
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:23:6: warning: the mangled name of 'void f(T) [with T = float __vector[4]]' will change in a future version of GCC
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C: In instantiation of 'float __vector[4] A<float __vector[4]>::t':
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:28:1:   instantiated from here
/sw/src/fink.build/gcc45-4.4.999-20100305/gcc-4.5-20100305/gcc/testsuite/g++.dg/abi/mangle40.C:20:9: warning: the mangled name of 'A<float __vector[4]>::t' will change in a future version of GCC

PASS: g++.dg/abi/mangle40.C  (test for warnings, line 20)
PASS: g++.dg/abi/mangle40.C  (test for warnings, line 23)
PASS: g++.dg/abi/mangle40.C (test for excess errors)
FAIL: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_Z1fIDv4_fEvT_
PASS: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_Z1fIU8__vectorfEvT_
FAIL: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_ZN1AIDv4_fE1tE
PASS: g++.dg/abi/mangle40.C scan-assembler weak[^\n]*_ZN1AIU8__vectorfE1tE

However the mangle41.C failures are gone.
Comment 21 Jason Merrill 2010-03-07 05:36:30 UTC
Hmm, that's odd.  Why would Darwin satisfy dg-require-alias when it doesn't have ASM_OUTPUT_DEF?
Comment 22 Jack Howarth 2010-05-22 04:04:56 UTC
It appears that dg-require-alias doesn't report the absence of alias support if only weak alias support is detected...

# If this target does not support the "alias" attribute, skip this
# test.

proc dg-require-alias { args } {
    set alias_available [ check_alias_available ]
    if { $alias_available == -1 } {
        upvar name name
        unresolved "$name"
    }
    if { $alias_available < 2 } {
        upvar dg-do-what dg-do-what
        set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
    }
}

in lib/target-supports-dg.exp and...

# proc check_alias_available { }
###############################

# Determine if the target toolchain supports the alias attribute.

# Returns 2 if the target supports aliases.  Returns 1 if the target
# only supports weak aliased.  Returns 0 if the target does not
# support aliases at all.  Returns -1 if support for aliases could not
# be determined.

in lib/target-supports.exp.