Changeset c0453ca3


Ignore:
Timestamp:
Apr 30, 2018, 11:07:21 AM (3 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
1a3eab8
Parents:
1da2250
Message:

Remove reference type mangling to prevent reference and non-reference overloading

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Mangler.cc

    r1da2250 rc0453ca3  
    3535                namespace {
    3636                        /// Mangles names to a unique C identifier
    37                         struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler> {
     37                        struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler>, public WithGuards {
    3838                                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams );
    3939                                Mangler( const Mangler & ) = delete;
     
    7070                                bool typeMode;                  ///< Produce a unique mangled name for a type
    7171                                bool mangleGenericParams;       ///< Include generic parameters in name mangling if true
     72                                bool inFunctionType = false;    ///< Include type qualifiers if false.
    7273
    7374                                void mangleDecl( DeclarationWithType *declaration );
     
    189190
    190191                        void Mangler::postvisit( ReferenceType * refType ) {
     192                                // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload.
     193                                // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.),
     194                                // by pretending every reference type is a function parameter.
     195                                GuardValue( inFunctionType );
     196                                inFunctionType = true;
    191197                                printQualifiers( refType );
    192                                 mangleName << "R";
    193198                                maybeAccept( refType->base, *visitor );
    194199                        }
     
    206211                                printQualifiers( functionType );
    207212                                mangleName << "F";
     213                                // turn on inFunctionType so that printQualifiers does not print most qualifiers for function parameters,
     214                                // since qualifiers on outermost parameter type do not differentiate function types, e.g.,
     215                                // void (*)(const int) and void (*)(int) are the same type, but void (*)(const int *) and void (*)(int *) are different
     216                                GuardValue( inFunctionType );
     217                                inFunctionType = true;
    208218                                std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() );
    209219                                acceptAll( returnTypes, *visitor );
     
    304314                                // skip if not including qualifiers
    305315                                if ( typeMode ) return;
    306 
    307316                                if ( ! type->get_forall().empty() ) {
    308317                                        std::list< std::string > assertionNames;
     
    337346                                        mangleName << "_";
    338347                                } // if
    339                                 if ( type->get_const() ) {
    340                                         mangleName << "C";
    341                                 } // if
    342                                 if ( type->get_volatile() ) {
    343                                         mangleName << "V";
    344                                 } // if
     348                                if ( ! inFunctionType ) {
     349                                        // these qualifiers do not distinguish the outermost type of a function parameter
     350                                        if ( type->get_const() ) {
     351                                                mangleName << "C";
     352                                        } // if
     353                                        if ( type->get_volatile() ) {
     354                                                mangleName << "V";
     355                                        } // if
     356                                        // Removed due to restrict not affecting function compatibility in GCC
     357                                        // if ( type->get_isRestrict() ) {
     358                                        //      mangleName << "E";
     359                                        // } // if
     360                                        if ( type->get_atomic() ) {
     361                                                mangleName << "A";
     362                                        } // if
     363                                }
    345364                                if ( type->get_mutex() ) {
    346365                                        mangleName << "M";
    347366                                } // if
    348                                 // Removed due to restrict not affecting function compatibility in GCC
    349                 //              if ( type->get_isRestrict() ) {
    350                 //                      mangleName << "E";
    351                 //              } // if
    352367                                if ( type->get_lvalue() ) {
    353368                                        // mangle based on whether the type is lvalue, so that the resolver can differentiate lvalues and rvalues
    354369                                        mangleName << "L";
    355370                                }
    356                                 if ( type->get_atomic() ) {
    357                                         mangleName << "A";
    358                                 } // if
     371
     372                                if ( inFunctionType ) {
     373                                        // turn off inFunctionType so that types can be differentiated for nested qualifiers
     374                                        GuardValue( inFunctionType );
     375                                        inFunctionType = false;
     376                                }
    359377                        }
    360378                }       // namespace
  • src/tests/.expect/KRfunctions.x64.txt

    r1da2250 rc0453ca3  
    5353    __attribute__ ((unused)) signed int *___retval_f8__Pi_1;
    5454}
    55 signed int *const __f9__FCPi_PiiPi__1(signed int *__a__Pi_1, signed int __b__i_1, signed int *__c__Pi_1){
     55signed int *const __f9__FPi_PiiPi__1(signed int *__a__Pi_1, signed int __b__i_1, signed int *__c__Pi_1){
    5656    __attribute__ ((unused)) signed int *const ___retval_f9__CPi_1;
    5757}
     
    7777    __attribute__ ((unused)) signed int ___retval_f15__i_1;
    7878}
    79 const signed int __fred__FCi___1(){
     79const signed int __fred__Fi___1(){
    8080    __attribute__ ((unused)) const signed int ___retval_fred__Ci_1;
    8181    signed int *(*__x__PFPi_ii__2)(signed int __anonymous_object4, signed int __anonymous_object5);
     
    8585    ((void)(__x__PFPi_ii__2=(((void)(_tmp_cp_ret2=__f10__FPFPi_ii__iPiPid__1(3, (&__a__i_2), (&__b__i_2), 3.5))) , _tmp_cp_ret2)));
    8686    ((void)(_tmp_cp_ret2) /* ^?{} */);
    87     const signed int __f1__FCi_iPiPi__2(signed int __a__i_2, signed int *__b__Pi_2, signed int *__c__Pi_2){
     87    const signed int __f1__Fi_iPiPi__2(signed int __a__i_2, signed int *__b__Pi_2, signed int *__c__Pi_2){
    8888        __attribute__ ((unused)) const signed int ___retval_f1__Ci_2;
    8989    }
    90     const signed int __f2__FCi_iii__2(signed int __a__i_2, signed int __b__i_2, signed int __c__i_2){
     90    const signed int __f2__Fi_iii__2(signed int __a__i_2, signed int __b__i_2, signed int __c__i_2){
    9191        __attribute__ ((unused)) const signed int ___retval_f2__Ci_2;
    9292    }
  • src/tests/.expect/attributes.x64.txt

    r1da2250 rc0453ca3  
    251251__attribute__ ((used,used,used)) const signed int __vd5__A0Ci_1[((unsigned long int )5)];
    252252__attribute__ ((used,used,unused,used)) const signed int __vd6__A0Ci_1[((unsigned long int )5)];
    253 __attribute__ ((used,used,used,used)) const signed int (*__vd7__PFCi___1)();
    254 __attribute__ ((used,used,unused,used,used)) const signed int (*__vd8__PFCi___1)();
     253__attribute__ ((used,used,used,used)) const signed int (*__vd7__PFi___1)();
     254__attribute__ ((used,used,unused,used,used)) const signed int (*__vd8__PFi___1)();
    255255__attribute__ ((unused,used)) signed int __f1__Fi___1();
    256256__attribute__ ((unused)) signed int __f1__Fi___1(){
    257257    __attribute__ ((unused)) signed int ___retval_f1__i_1;
    258258}
    259 __attribute__ ((unused,unused,unused,used)) signed int **const __f2__FCPPi___1();
    260 __attribute__ ((unused,unused,unused)) signed int **const __f2__FCPPi___1(){
     259__attribute__ ((unused,unused,unused,used)) signed int **const __f2__FPPi___1();
     260__attribute__ ((unused,unused,unused)) signed int **const __f2__FPPi___1(){
    261261    __attribute__ ((unused)) signed int **const ___retval_f2__CPPi_1;
    262262}
  • src/tests/.expect/declarationSpecifier.x64.txt

    r1da2250 rc0453ca3  
    447447}
    448448static volatile const struct __anonymous15 __x36__CV14s__anonymous15_1;
    449 static inline volatile const signed int __f11__FCVi___1();
    450 static inline volatile const signed int __f12__FCVi___1();
    451 static inline volatile const signed int __f13__FCVi___1();
    452 static inline volatile const signed int __f14__FCVi___1();
    453 static inline volatile const signed int __f15__FCVi___1();
    454 static inline volatile const signed int __f16__FCVi___1();
    455 static inline volatile const signed int __f17__FCVi___1();
    456 static inline volatile const signed int __f18__FCVi___1();
    457 static inline volatile const signed short int __f21__FCVs___1();
    458 static inline volatile const signed short int __f22__FCVs___1();
    459 static inline volatile const signed short int __f23__FCVs___1();
    460 static inline volatile const signed short int __f24__FCVs___1();
    461 static inline volatile const signed short int __f25__FCVs___1();
    462 static inline volatile const signed short int __f26__FCVs___1();
    463 static inline volatile const signed short int __f27__FCVs___1();
    464 static inline volatile const signed short int __f28__FCVs___1();
     449static inline volatile const signed int __f11__Fi___1();
     450static inline volatile const signed int __f12__Fi___1();
     451static inline volatile const signed int __f13__Fi___1();
     452static inline volatile const signed int __f14__Fi___1();
     453static inline volatile const signed int __f15__Fi___1();
     454static inline volatile const signed int __f16__Fi___1();
     455static inline volatile const signed int __f17__Fi___1();
     456static inline volatile const signed int __f18__Fi___1();
     457static inline volatile const signed short int __f21__Fs___1();
     458static inline volatile const signed short int __f22__Fs___1();
     459static inline volatile const signed short int __f23__Fs___1();
     460static inline volatile const signed short int __f24__Fs___1();
     461static inline volatile const signed short int __f25__Fs___1();
     462static inline volatile const signed short int __f26__Fs___1();
     463static inline volatile const signed short int __f27__Fs___1();
     464static inline volatile const signed short int __f28__Fs___1();
    465465struct __anonymous16 {
    466466    signed int __i__i_1;
     
    489489    ((void)((*___dst__R14s__anonymous16_1).__i__i_1=__i__i_1) /* ?{} */);
    490490}
    491 static inline volatile const struct __anonymous16 __f31__FCV14s__anonymous16___1();
     491static inline volatile const struct __anonymous16 __f31__F14s__anonymous16___1();
    492492struct __anonymous17 {
    493493    signed int __i__i_1;
     
    516516    ((void)((*___dst__R14s__anonymous17_1).__i__i_1=__i__i_1) /* ?{} */);
    517517}
    518 static inline volatile const struct __anonymous17 __f32__FCV14s__anonymous17___1();
     518static inline volatile const struct __anonymous17 __f32__F14s__anonymous17___1();
    519519struct __anonymous18 {
    520520    signed int __i__i_1;
     
    543543    ((void)((*___dst__R14s__anonymous18_1).__i__i_1=__i__i_1) /* ?{} */);
    544544}
    545 static inline volatile const struct __anonymous18 __f33__FCV14s__anonymous18___1();
     545static inline volatile const struct __anonymous18 __f33__F14s__anonymous18___1();
    546546struct __anonymous19 {
    547547    signed int __i__i_1;
     
    570570    ((void)((*___dst__R14s__anonymous19_1).__i__i_1=__i__i_1) /* ?{} */);
    571571}
    572 static inline volatile const struct __anonymous19 __f34__FCV14s__anonymous19___1();
     572static inline volatile const struct __anonymous19 __f34__F14s__anonymous19___1();
    573573struct __anonymous20 {
    574574    signed int __i__i_1;
     
    597597    ((void)((*___dst__R14s__anonymous20_1).__i__i_1=__i__i_1) /* ?{} */);
    598598}
    599 static inline volatile const struct __anonymous20 __f35__FCV14s__anonymous20___1();
     599static inline volatile const struct __anonymous20 __f35__F14s__anonymous20___1();
    600600struct __anonymous21 {
    601601    signed int __i__i_1;
     
    624624    ((void)((*___dst__R14s__anonymous21_1).__i__i_1=__i__i_1) /* ?{} */);
    625625}
    626 static inline volatile const struct __anonymous21 __f36__FCV14s__anonymous21___1();
     626static inline volatile const struct __anonymous21 __f36__F14s__anonymous21___1();
    627627struct __anonymous22 {
    628628    signed int __i__i_1;
     
    651651    ((void)((*___dst__R14s__anonymous22_1).__i__i_1=__i__i_1) /* ?{} */);
    652652}
    653 static inline volatile const struct __anonymous22 __f37__FCV14s__anonymous22___1();
     653static inline volatile const struct __anonymous22 __f37__F14s__anonymous22___1();
    654654struct __anonymous23 {
    655655    signed int __i__i_1;
     
    678678    ((void)((*___dst__R14s__anonymous23_1).__i__i_1=__i__i_1) /* ?{} */);
    679679}
    680 static inline volatile const struct __anonymous23 __f38__FCV14s__anonymous23___1();
    681 static inline volatile const signed short int __f41__FCVs___1();
    682 static inline volatile const signed short int __f42__FCVs___1();
    683 static inline volatile const signed short int __f43__FCVs___1();
    684 static inline volatile const signed short int __f44__FCVs___1();
    685 static inline volatile const signed short int __f45__FCVs___1();
    686 static inline volatile const signed short int __f46__FCVs___1();
    687 static inline volatile const signed short int __f47__FCVs___1();
    688 static inline volatile const signed short int __f48__FCVs___1();
     680static inline volatile const struct __anonymous23 __f38__F14s__anonymous23___1();
     681static inline volatile const signed short int __f41__Fs___1();
     682static inline volatile const signed short int __f42__Fs___1();
     683static inline volatile const signed short int __f43__Fs___1();
     684static inline volatile const signed short int __f44__Fs___1();
     685static inline volatile const signed short int __f45__Fs___1();
     686static inline volatile const signed short int __f46__Fs___1();
     687static inline volatile const signed short int __f47__Fs___1();
     688static inline volatile const signed short int __f48__Fs___1();
    689689signed int __main__Fi_iPPCc__1(signed int __argc__i_1, const char **__argv__PPCc_1){
    690690    __attribute__ ((unused)) signed int ___retval_main__i_1;
  • src/tests/.expect/functions.x64.txt

    r1da2250 rc0453ca3  
    4646    __attribute__ ((unused)) signed int ___retval_fII1__i_1;
    4747}
    48 const signed int __fII2__FCi_i__1(signed int __i__i_1){
     48const signed int __fII2__Fi_i__1(signed int __i__i_1){
    4949    __attribute__ ((unused)) const signed int ___retval_fII2__Ci_1;
    5050}
     
    5252    __attribute__ ((unused)) signed int ___retval_fII3__i_1;
    5353}
    54 extern const signed int __fII4__FCi_i__1(signed int __i__i_1){
     54extern const signed int __fII4__Fi_i__1(signed int __i__i_1){
    5555    __attribute__ ((unused)) const signed int ___retval_fII4__Ci_1;
    5656}
     
    5858    __attribute__ ((unused)) signed int *___retval_fII5__Pi_1;
    5959}
    60 signed int *const __fII6__FCPi___1(){
     60signed int *const __fII6__FPi___1(){
    6161    __attribute__ ((unused)) signed int *const ___retval_fII6__CPi_1;
    6262}
     
    7676    __attribute__ ((unused)) signed int ___retval_fO2__i_1;
    7777}
    78 const signed int __fO3__FCi_i__1(signed int __i__i_1){
     78const signed int __fO3__Fi_i__1(signed int __i__i_1){
    7979    __attribute__ ((unused)) const signed int ___retval_fO3__Ci_1;
    8080}
     
    8282    __attribute__ ((unused)) signed int ___retval_fO4__i_1;
    8383}
    84 extern const signed int __fO5__FCi_i__1(signed int __i__i_1){
     84extern const signed int __fO5__Fi_i__1(signed int __i__i_1){
    8585    __attribute__ ((unused)) const signed int ___retval_fO5__Ci_1;
    8686}
     
    176176signed int __f11__Fi_i__1(signed int __anonymous_object16);
    177177signed int __f12__Fi___1(void);
    178 const double __bar1__FCd___1();
    179 const double __bar2__FCd_i__1(signed int __anonymous_object17);
    180 const double __bar3__FCd_d__1(double __anonymous_object18);
    181 const double __foo__FCd___1(void);
    182 const double __foo__FCd_i__1(signed int __anonymous_object19);
    183 const double __foo__FCd_d__1(double __anonymous_object20){
     178const double __bar1__Fd___1();
     179const double __bar2__Fd_i__1(signed int __anonymous_object17);
     180const double __bar3__Fd_d__1(double __anonymous_object18);
     181const double __foo__Fd___1(void);
     182const double __foo__Fd_i__1(signed int __anonymous_object19);
     183const double __foo__Fd_d__1(double __anonymous_object20){
    184184    __attribute__ ((unused)) const double ___retval_foo__Cd_1;
    185185    ((void)((*((double *)(&___retval_foo__Cd_1)))=3.0) /* ?{} */);
     
    224224    __attribute__ ((unused)) const signed int *___retval_f1__PCi_1;
    225225}
    226 static const signed int __f2__FCi___1(void){
    227     __attribute__ ((unused)) const signed int ___retval_f2__Ci_1;
    228 }
    229 static inline signed int *const __f3__FCPi___1(void){
     226static const signed int *__f2__FPCi___1(void){
     227    __attribute__ ((unused)) const signed int *___retval_f2__PCi_1;
     228}
     229static inline signed int *const __f3__FPi___1(void){
    230230    __attribute__ ((unused)) signed int *const ___retval_f3__CPi_1;
    231231}
     
    234234    signed int field_1;
    235235};
    236 static inline const struct _conc__tuple2_3 __f4__FCTPii____1(void){
     236static inline const struct _conc__tuple2_3 __f4__FTPii____1(void){
    237237    __attribute__ ((unused)) const struct _conc__tuple2_3 ___retval_f4__CTPii__1;
    238238}
    239 static const struct _conc__tuple2_3 __f5__FCTPiCi____1(void){
     239static const struct _conc__tuple2_3 __f5__FTPiCi____1(void){
    240240    __attribute__ ((unused)) const struct _conc__tuple2_3 ___retval_f5__CTPiCi__1;
    241241}
    242 signed int __f__Fi_PFi__PFPi__PFPPi__PFPCPi__PFCPCPi__PiPiPPiPPiPPPiPPPiPPCPiPPCPiPCPCPiPCPCPi__1(signed int (*__anonymous_object27)(), signed int *(*__anonymous_object28)(), signed int **(*__anonymous_object29)(), signed int *const *(*__anonymous_object30)(), signed int *const *const (*__anonymous_object31)(), signed int *__anonymous_object32, signed int __anonymous_object33[((unsigned long int )10)], signed int **__anonymous_object34, signed int *__anonymous_object35[((unsigned long int )10)], signed int ***__anonymous_object36, signed int **__anonymous_object37[((unsigned long int )10)], signed int *const **__anonymous_object38, signed int *const *__anonymous_object39[((unsigned long int )10)], signed int *const *const *__anonymous_object40, signed int *const *const __anonymous_object41[((unsigned long int )10)]);
    243 signed int __f__Fi_PFi__PFPi__PFPPi__PFPCPi__PFCPCPi__PiPiPPiPPiPPPiPPPiPPCPiPPCPiPCPCPiPCPCPi__1(signed int (*__anonymous_object42)(), signed int *(*__anonymous_object43)(), signed int **(*__anonymous_object44)(), signed int *const *(*__anonymous_object45)(), signed int *const *const (*__anonymous_object46)(), signed int *__anonymous_object47, signed int __anonymous_object48[((unsigned long int )10)], signed int **__anonymous_object49, signed int *__anonymous_object50[((unsigned long int )10)], signed int ***__anonymous_object51, signed int **__anonymous_object52[((unsigned long int )10)], signed int *const **__anonymous_object53, signed int *const *__anonymous_object54[((unsigned long int )10)], signed int *const *const *__anonymous_object55, signed int *const *const __anonymous_object56[((unsigned long int )10)]){
     242signed int __f__Fi_PFi__PFPi__PFPPi__PFPCPi__PFPCPi__PiPiPPiPPiPPPiPPPiPPCPiPPCPiPCPCPiPCPCPi__1(signed int (*__anonymous_object27)(), signed int *(*__anonymous_object28)(), signed int **(*__anonymous_object29)(), signed int *const *(*__anonymous_object30)(), signed int *const *const (*__anonymous_object31)(), signed int *__anonymous_object32, signed int __anonymous_object33[((unsigned long int )10)], signed int **__anonymous_object34, signed int *__anonymous_object35[((unsigned long int )10)], signed int ***__anonymous_object36, signed int **__anonymous_object37[((unsigned long int )10)], signed int *const **__anonymous_object38, signed int *const *__anonymous_object39[((unsigned long int )10)], signed int *const *const *__anonymous_object40, signed int *const *const __anonymous_object41[((unsigned long int )10)]);
     243signed int __f__Fi_PFi__PFPi__PFPPi__PFPCPi__PFPCPi__PiPiPPiPPiPPPiPPPiPPCPiPPCPiPCPCPiPCPCPi__1(signed int (*__anonymous_object42)(), signed int *(*__anonymous_object43)(), signed int **(*__anonymous_object44)(), signed int *const *(*__anonymous_object45)(), signed int *const *const (*__anonymous_object46)(), signed int *__anonymous_object47, signed int __anonymous_object48[((unsigned long int )10)], signed int **__anonymous_object49, signed int *__anonymous_object50[((unsigned long int )10)], signed int ***__anonymous_object51, signed int **__anonymous_object52[((unsigned long int )10)], signed int *const **__anonymous_object53, signed int *const *__anonymous_object54[((unsigned long int )10)], signed int *const *const *__anonymous_object55, signed int *const *const __anonymous_object56[((unsigned long int )10)]){
    244244    __attribute__ ((unused)) signed int ___retval_f__i_1;
    245245}
  • src/tests/functions.c

    r1da2250 rc0453ca3  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // functions.c -- 
    8 // 
     6//
     7// functions.c --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Wed Aug 17 08:39:58 2016
     
    1212// Last Modified On : Wed Jan 17 22:44:12 2018
    1313// Update Count     : 12
    14 // 
     14//
    1515
    1616// ANSI function definitions
     
    123123
    124124static const int * f1() {}
    125 static [ const int ] f2() {}
     125static [ * const int ] f2() {}
    126126static inline [ const * int ] f3() {}
    127127static inline [ const [ * int, int ] ] f4() {}
Note: See TracChangeset for help on using the changeset viewer.