Where is clang_CompileCommand_getNumMappedSources?

Hi all,

I’m trying a quick experiment with clang-c and I’ve noticed something that seems weird. If I compile the program at the end of this email like so

$ g++ -Iclang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.04/include -g -Wall tc.cpp -Lclang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.04/lib -lclang -o tc
tc.cpp:21: error: undefined reference to ‘clang_CompileCommand_getNumMappedSources’

I’m a tad baffled by this because the complimentary functions clang_CompileCommand_getMappedSourcePath and clang_CompileCommand_getMappedSourceContent do exist.

In the pre-built package I’m using (4.0.0, see above), it seems the thing doesn’t exist at all?

$ strings clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.04/lib/* | grep clang_CompileCommand | sort -u
clang_CompileCommand_getArg
clang_CompileCommand_getDirectory
clang_CompileCommand_getFilename
clang_CompileCommand_getMappedSourceContent
clang_CompileCommand_getMappedSourcePath
clang_CompileCommand_getNumArgs
clang_CompileCommands_dispose
clang_CompileCommands_getCommand
clang_CompileCommands_getSize

Am I going crazy? Where is it? :slight_smile:

tc.cpp:
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <clang-c/CXCompilationDatabase.h>

int main() {
CXCompilationDatabase db;
CXCompilationDatabase_Error err;
const char *build_dir;

build_dir = “.”;
db = clang_CompilationDatabase_fromDirectory(build_dir, &err);

if (err != CXCompilationDatabase_NoError) {
exit(1);
}

CXCompileCommands cmds = clang_CompilationDatabase_getAllCompileCommands(db);
unsigned num_commands = clang_CompileCommand_getNumArgs(cmds);
assert(num_commands > 0);
printf("%d\n", clang_CompileCommand_getNumMappedSources(clang_CompileCommands_getCommand(cmds, 0)));

return 0;
}

Kind regards & TIA,

/Charlie.

Hi Charlie,

looks like the function ‘clang_CompileCommand_getNumMappedSources’ hasn’t been added to the libclang exports file in libclang.exports so isn’t exposed externally in libclang.so. Patch c519ef864 added the other 2 complimentary functions but missed ‘*_getNumMappedSources’.

Thanks,

Ranjeet

Note that clang_CompileCommand_getNumMappedSources and the 2 complementary functions should return 0 / empty strings because the mapped sources aren’t currently used in Clang. In fact, there’s a patch at https://reviews.llvm.org/D32351 that removes them completely (but preserves the libclang API). So while the fact that clang_CompileCommand_getNumMappedSources is not exposed in the exports file is bug, should it really be fixed if it was not (and if that patch will land won’t be) used by anyone?

+Val

Note that clang_CompileCommand_getNumMappedSources and the 2 complementary functions should return 0 / empty strings because the mapped sources aren’t currently used in Clang. In fact, there’s a patch at https://reviews.llvm.org/D32351 that removes them completely (but preserves the libclang API). So while the fact that clang_CompileCommand_getNumMappedSources is not exposed in the exports file is bug, should it really be fixed if it was not (and if that patch will land won’t be) used by anyone?

I agree that we should either delete it or fix it. Generally, with an API like this, people will only use it once it works :slight_smile: The idea is that if you have non-file-system means to get your code in, you cannot do that without this API.

Looping in a libclang user (Val) to give an opinion on why this might / might not be a useful feature to have.