Skip to content

[LLDB] Cast to pointer-to-array-of-typeof-variable doesn't work #152113

@jacobef

Description

@jacobef

p *(typeof(*s)(*)[3])s, where s is a pointer to (say) 3 elements, does not work.

System: M1 Macbook Air, macOS Sequoia 15.6 (24G84), see below for clang and lldb versions.
Reproduction:

$ clang --version
Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: arm64-apple-darwin24.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ lldb --version
lldb-1700.0.9.502
Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
$ cat > repro.c <<EOF
> int main(void) {
> char *s = "abc";
> }
> EOF
$ clang -g repro.c -o repro
$ lldb ./repro
(lldb) target create "./repro"
Current executable set to '/Users/friedman/Coding/Misc/repro' (arm64).
(lldb) break set -n main
Breakpoint 1: where = repro`main + 4 at repro.c:2:7, address = 0x000000010000037c
(lldb) run
Process 3984 launched: '/Users/friedman/Coding/Misc/repro' (arm64)
Process 3984 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000010000037c repro`main at repro.c:2:7
   1   	int main(void) {
-> 2   	char *s = "abc";
   3   	}
Target 0: (repro) stopped.
(lldb) step
Process 3984 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x0000000100000388 repro`main at repro.c:3:1
   1   	int main(void) {
   2   	char *s = "abc";
-> 3   	}
Target 0: (repro) stopped.
(lldb) p *(typeof(*s)(*)[3])s
                       ˄
                       ╰─ error: expected expression

This also reproduces with LLDB 20.1.8, installed via Homebrew.
Notably, p *(char(*)[3])s works fine; this is only a problem with typeof.
*(typeof(*s)(*)[3])s is in fact a valid expression, i.e. LLDB is incorrect to reject it, because the following compiles fine in clang:

int main(void) {
    char *s = "abc";
    *(typeof(*s)(*)[3])s;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    lldbquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions