Changeset 3f024c9


Ignore:
Timestamp:
May 4, 2018, 11:01:48 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
7d0a3ba
Parents:
f3152ab
Message:

Mangle function pointers the same as functions to prevent function/function-pointer overloading

Location:
src/SymTab
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    rf3152ab r3f024c9  
    2626#include "Common/SemanticError.h"  // for SemanticError
    2727#include "Common/utility.h"        // for cloneAll
     28#include "GenPoly/GenPoly.h"
    2829#include "InitTweak/InitTweak.h"   // for isConstructor, isCopyFunction, isC...
    2930#include "Mangler.h"               // for Mangler
     
    377378        }
    378379
     380        bool isFunction( DeclarationWithType * decl ) {
     381                return GenPoly::getFunctionType( decl->get_type() );
     382        }
     383
     384        bool isObject( DeclarationWithType * decl ) {
     385                return ! isFunction( decl );
     386        }
     387
     388        bool isDefinition( DeclarationWithType * decl ) {
     389                if ( FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ) ) {
     390                        // a function is a definition if it has a body
     391                        return func->statements;
     392                } else {
     393                        // an object is a definition if it is not marked extern.
     394                        // both objects must be marked extern
     395                        return ! decl->get_storageClasses().is_extern;
     396                }
     397        }
     398
    379399        bool addedIdConflicts( Indexer::IdData & existing, DeclarationWithType *added, BaseSyntaxNode * deleteStmt, Indexer::ConflictFunction handleConflicts ) {
    380400                // if we're giving the same name mangling to things of different types then there is something wrong
    381                 assert( (dynamic_cast<ObjectDecl*>( added ) && dynamic_cast<ObjectDecl*>( existing.id ) )
    382                         || (dynamic_cast<FunctionDecl*>( added ) && dynamic_cast<FunctionDecl*>( existing.id ) ) );
     401                assert( (isObject( added ) && isObject( existing.id ) )
     402                        || ( isFunction( added ) && isFunction( existing.id ) ) );
    383403
    384404                if ( LinkageSpec::isOverridable( existing.id->get_linkage() ) ) {
     
    394414                        }
    395415
    396                         // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
    397                         // we should ignore outermost pointer qualifiers, except _Atomic?
    398                         FunctionDecl * newentry = dynamic_cast< FunctionDecl * >( added );
    399                         FunctionDecl * oldentry = dynamic_cast< FunctionDecl * >( existing.id );
    400                         if ( newentry && oldentry ) {
    401                                 if ( newentry->get_statements() && oldentry->get_statements() ) {
     416                        if ( isDefinition( added ) && isDefinition( existing.id ) ) {
     417                                if ( isFunction( added ) ) {
    402418                                        return handleConflicts( existing, "duplicate function definition for " );
    403                                 } // if
    404                         } else {
    405                                 // two objects with the same mangled name defined in the same scope.
    406                                 // both objects must be marked extern or both must be intrinsic for this to be okay
    407                                 // xxx - perhaps it's actually if either is intrinsic then this is okay?
    408                                 //       might also need to be same storage class?
    409                                 ObjectDecl * newobj = dynamic_cast< ObjectDecl * >( added );
    410                                 ObjectDecl * oldobj = dynamic_cast< ObjectDecl * >( existing.id );
    411                                 if ( ! newobj->get_storageClasses().is_extern && ! oldobj->get_storageClasses().is_extern ) {
     419                                } else {
    412420                                        return handleConflicts( existing, "duplicate object definition for " );
    413421                                } // if
  • src/SymTab/Mangler.cc

    rf3152ab r3f024c9  
    179179                        void Mangler::postvisit( PointerType * pointerType ) {
    180180                                printQualifiers( pointerType );
    181                                 mangleName << "P";
     181                                // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers
     182                                if ( ! dynamic_cast<FunctionType *>( pointerType->base ) ) mangleName << "P";
    182183                                maybeAccept( pointerType->base, *visitor );
    183184                        }
Note: See TracChangeset for help on using the changeset viewer.