atilaneves/dpp

pythonh: Function type does not match previously declared function with the same mangled name: `stat64`

andre2007 opened this issue · 5 comments

This dockerfile

FROM python:3.7

RUN apt-get update && apt-get upgrade -y \
    && apt-get install --no-install-recommends -y curl gcc clang-7 libclang-7-dev python3 python3-dev xz-utils \
    && ln -s /usr/bin/clang-7 /usr/bin/clang

WORKDIR /tmp
RUN curl -OL https://github.com/ldc-developers/ldc/releases/download/v1.22.0/ldc2-1.22.0-linux-x86_64.tar.xz \
    && tar -xf ldc2-1.22.0-linux-x86_64.tar.xz --strip-components=1 -C /

RUN echo '#include <python3.7/Python.h>' > pythonh.dpp
RUN DFLAGS="-L=-L/usr/lib/llvm-7/lib/" dub run dpp -- pythonh.dpp \
    --preprocess-only

will produce a file pythonh.d which contains this coding

pragma(mangle, "stat64") int stat64_(const(char)*, stat64*) @nogc nothrow;
int fstat(int, stat*) @nogc nothrow;
pragma(mangle, "stat64") int stat_(const(char)*, stat*) @nogc nothrow;

LDC2 complains:

pythonh.d(150): Error: Function type does not match previously declared function with the same mangled name: stat64
pythonh.d(150): Previous IR type: i32 (i8*, %pythonh.stat64*)
pythonh.d(150): New IR type: i32 (i8*, %pythonh.stat*)

Ah. I never noticed it before because I only ever used dmd on the result and ldc is a bit more of a stickler wrt duplicate symbols. A workaround for now is to use dmd instead.

For some reason libclang is returning "stat64" as the mangling for "stat" even though, as C linkage functions, they don't mangle!

I'm racking my head how to solve this without having to try and reduce the issue with libclang. There's no good way to know if the cursor is C or C++ (thereby avoiding any mangling whatsoever if not needed, as is the case here). There's a function to get the language, but it returns "C" for any and all functions regardless of them being extern "C" or not. There's a function to get linkage, but it doesn't do what you'd expect and basically tells you if a cursor is extern or not.

If my understanding is correct, with this pr it will be a deprecation warning also with DMD dlang/dmd#8429