Skip to content

Accessing inline array inside a struct causes compilation error (pointer decay issue) #534

@cjbarre

Description

@cjbarre

jank health check

─ system ───────────────────────────────────────────────────────────────────────────────────────────
─ ✅ operating system: macos
─ ✅ default triple: arm64-apple-darwin24.6.0

─ jank install ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank version: jank-0.1-a948bdcdd0ac13ada091abaa210a153896770a43
─ ✅ jank resource dir: ../lib/jank/0.1 (not found)
─ ✅ jank resolved resource dir: /Users/cam/Documents/code/jank/compiler+runtime/build/../lib/jank/0.1 (ignored for dev build)
─ ✅ jank user cache dir: /Users/cam/.cache/jank/arm64-apple-darwin24.6.0-684c4c7d8472f958c11d94a1f3e546c03230afc12ff10ff5eee3408d3688e52f (not found)

─ clang install ────────────────────────────────────────────────────────────────────────────────────
─ ✅ configured clang path: /Users/cam/Documents/code/jank/compiler+runtime/build/llvm-install/usr/local/bin/clang++ (found)
─ ✅ configured clang resource dir: /Users/cam/Documents/code/jank/compiler+runtime/build/llvm-install/usr/local/lib/clang/21 (found)

─ jank runtime ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank runtime initialized
─ ✅ jank pch path: /Users/cam/.cache/jank/arm64-apple-darwin24.6.0-684c4c7d8472f958c11d94a1f3e546c03230afc12ff10ff5eee3408d3688e52f (found)
─ ✅ jank can jit compile c++
─ ✅ jank can jit compile llvm ir
ld: warning: ignoring duplicate libraries: '-lc++'
ld: warning: search path '/Users/cam/Documents/code/jank/compiler+runtime/build/../lib/jank/0.1/lib' not found
ld: warning: reexported library with install name '@rpath/libunwind.1.dylib' found at '/Users/cam/Documents/code/jank/compiler+runtime/build/llvm-install/usr/local/lib/libunwind.1.0.dylib' couldn't be matched with any parent library and will be linked directly
─ ✅ jank can aot compile working binaries

─ support ──────────────────────────────────────────────────────────────────────────────────────────
If you're having issues with jank, please either ask the jank community on the Clojurians Slack or report the issue on Github.

─ Slack: https://clojurians.slack.com/archives/C03SRH97FDK
─ Github: https://github.com/jank-lang/jank

Description of the issue with reproduction steps

Minimal Repro:

(cpp/raw
 "typedef struct a {
    float b[3];
  } a;
  
  a make_a(void) {
    a result = { .b = {1.0f, 2.0f, 3.0f} };
    return result;
  }")

(let [a (cpp/make_a)
      b (cpp/.-b a)])

Stack trace

In file included from <<< inputs >>>:1:
input_line_4:7:23: error: expected ')'
7 | new (ret) (float[3]) (&((a)obj)->b);
| ^
input_line_4:7:14: note: to match this '('
7 | new (ret) (float[3]) (&((a)obj)->b);
| ^
input_line_4:7:27: error: cannot initialize an array element of type 'float' with an rvalue of type
'float ()[3]'
7 | new (ret) (float[3]
) (&((a*)obj)->b);
| ^~~~~~~~~~~~~
TClingCallFunc::make_wrapper:Failed to compile
==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
attribute((used)) attribute((annotate("__cling__ptrcheck(off)")))
extern "C" [[gnu::always_inline]]
inline void clojure_core_G__24083([[gnu::nonnull]] void* obj, int nargs, void** args, [[gnu::nonnull]] void* ret)
{
new (ret) (float[3]) (&((a)obj)->b);
}
#pragma clang diagnostic pop
==== SOURCE END ====
zsh: segmentation fault jank run inline-pointer-decay.jank

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions