Skip to content

[clang] Objective-C encoding of BOOL* is wrong #87490

@madsmtm

Description

@madsmtm

The following program:

#import <stdio.h>

typedef signed char BOOL;
typedef signed char TYPEDEF;

int main() {
    printf("signed char* encoding: %s\n", @encode(signed char*));
    printf("TYPEDEF* encoding: %s\n", @encode(TYPEDEF*));
    printf("BOOL* encoding: %s\n", @encode(BOOL*));
    return 0;
}

Is supposed to output the following on x86_64 (godbolt Clang 15, Godbolt GCC 13.2):

signed char* encoding: *
TYPEDEF* encoding: *
BOOL* encoding: ^c

But since Clang 16, it outputs (godbolt Clang 18):

signed char* encoding: *
TYPEDEF* encoding: *
BOOL* encoding: *

Clang seemingly has code to support this, see

// This returns true if a type has been typedefed to BOOL:
// typedef <type> BOOL;
static bool isTypeTypedefedAsBOOL(QualType T) {
if (const auto *TT = dyn_cast<TypedefType>(T))
if (IdentifierInfo *II = TT->getDecl()->getIdentifier())
return II->isStr("BOOL");
return false;
}
and
if (PointeeTy->isCharType()) {
// char pointer types should be encoded as '*' unless it is a
// type that has been typedef'd to 'BOOL'.
if (!isTypeTypedefedAsBOOL(PointeeTy)) {
S += '*';
return;
}
, but for some reason these code paths are now no longer correctly triggered?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"objective-c

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions