Issue 71207
Summary Incorrect AST on M2 Mac
Labels new issue
Assignees
Reporter briandw
    Clang on my mac M2 is producing an incorrect AST dump.

`clang  -Xclang -ast-dump -fsyntax-only`
 for the following code:
`#include <stdio.h>

// Define the function pointer type for printing
typedef void (*print_func_t)(const char *);

// Define the print function
void print_string(const char *str) {
 printf("%s", str);
}

// Define the macro that uses the function pointer
#define CALL_PRINT_FUNC(print_func, str) (print_func)(str)

// Function that calls the macro with the function pointer
void call_macro_with_func_pointer(const char *str) {
 CALL_PRINT_FUNC(print_string, str);
}

// Example usage
int main(void) {
    call_macro_with_func_pointer("Hello, World!");
 return 0;
}`
as seen here
https://godbolt.org/z/4v9Mhhn5o

should end with:
`-FunctionDecl <line:20:1, line:23:1> line:20:5 main 'int (void)'
  `-CompoundStmt <col:16, line:23:1>
    |-CallExpr <line:21:5, col:49> 'void'
    | |-ImplicitCastExpr <col:5> 'void (*)(const char *)' <FunctionToPointerDecay>
    | | `-DeclRefExpr <col:5> 'void (const char *)' Function 0xbab6f88 'call_macro_with_func_pointer' 'void (const char *)'
    | `-ImplicitCastExpr <col:34> 'const char *' <NoOp>
    | `-ImplicitCastExpr <col:34> 'char *' <ArrayToPointerDecay>
    | `-StringLiteral <col:34> 'char[14]' lvalue "Hello, World!"
 `-ReturnStmt <line:22:5, col:12>
      `-IntegerLiteral <col:12> 'int' 0
`

On my mac M2 it ends with :
`
| |-ParmVarDecl 0x11f8c2828 <col:29, col:34> col:46 'char *restrict'
| |-ParmVarDecl 0x11f8c28a0 <col:48> col:54 'size_t':'unsigned long'
| |-ParmVarDecl 0x11f8c2920 <col:56> col:59 'int'
| |-ParmVarDecl 0x11f8c2998 <col:61> col:67 'size_t':'unsigned long'
| |-ParmVarDecl 0x11f8c2a18 <line:71:8, col:19> col:31 'const char *restrict'
| `-ParmVarDecl 0x11f8c2a90 <col:33> col:40 'va_list':'char *'
|-TypedefDecl 0x11f8c2e30 </private/tmp/51d772ea0bc946e8a17da6e326b3f752.c:5:1, col:42> col:16 print_func_t 'void (*)(const char *)'
| `-PointerType 0x11f8c2dd0 'void (*)(const char *)'
|   `-ParenType 0x11f8c2d70 'void (const char *)' sugar
|     `-FunctionProtoType 0x11f8aee90 'void (const char *)' cdecl
|       |-BuiltinType 0x11f81e870 'void'
|       `-PointerType 0x12007cab0 'const char *'
|         `-QualType 0x11f81e8b1 'const char' const
|           `-BuiltinType 0x11f81e8b0 'char'
`-FunctionDecl 0x11f8c2f30 <line:8:1, line:25:2> line:8:6 print_string 'void (const char *)'
  |-ParmVarDecl 0x11f8c2ea0 <col:19, col:31> col:31 str 'const char *'
  `-CompoundStmt 0x11f8c3000 <col:36, line:25:2>
2 warnings and 2 errors generated.
`

Missing the functions call_macro_with_func_pointer, and main!

clang --version
Homebrew clang version 17.0.1
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to