llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.71k stars 10.94k forks source link

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

Open madsmtm opened 3 months ago

madsmtm commented 3 months ago

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 https://github.com/llvm/llvm-project/blob/2bf7ddf06f773277fcfef58a3cd8c32a161ce36a/clang/lib/AST/ASTContext.cpp#L7696-L7704 and https://github.com/llvm/llvm-project/blob/2bf7ddf06f773277fcfef58a3cd8c32a161ce36a/clang/lib/AST/ASTContext.cpp#L8356-L8362, but for some reason these code paths are now no longer correctly triggered?

llvmbot commented 3 months ago

@llvm/issue-subscribers-clang-frontend

Author: Mads Marquart (madsmtm)

The following program: ```objective-c #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](https://godbolt.org/z/dYrsheGd9), [Godbolt GCC 13.2](https://godbolt.org/z/zaj3hdqPo)): ``` signed char* encoding: * TYPEDEF* encoding: * BOOL* encoding: ^c ``` But since Clang 16, it outputs ([godbolt Clang 18](https://godbolt.org/z/9efxrnf3a)): ``` signed char* encoding: * TYPEDEF* encoding: * BOOL* encoding: * ``` --- Clang seemingly has code to support this, see https://github.com/llvm/llvm-project/blob/2bf7ddf06f773277fcfef58a3cd8c32a161ce36a/clang/lib/AST/ASTContext.cpp#L7696-L7704 and https://github.com/llvm/llvm-project/blob/2bf7ddf06f773277fcfef58a3cd8c32a161ce36a/clang/lib/AST/ASTContext.cpp#L8356-L8362, but for some reason these code paths are now no longer correctly triggered?