Clang returns Parameter names instead of Arguments

Hello,

I want to print the arguments passed to a function. But clang returns Parameter names used in the function definition. Here is my code:

if (CallExpr *call = dyn_cast(st))
{
LangOptions LangOpts;
LangOpts.CPlusPlus = true;
PrintingPolicy Policy(LangOpts);

for(int i=0, j=call->getNumArgs(); i<j; i++)
{
std::string TypeS;
raw_string_ostream raw(TypeS);
call->getArg(i)->printPretty(raw, 0, Policy);
errs() << raw.str() << “\n”;
}
}
Example:
int iArgument = 123;
char cArgument = ‘c’;
foo(iArgument, cArgument);
For this code, it should print iArgument and cArgument, but it is printing the names of the parameters given in function definition.

Please tell what might be the problem.

Also, I am able to get the arguments’ name when I am using a simple C++ code. But when I start using another library’s API (for that I am specifying compile_commands.json file), this presents problems.

That’s pretty weird. I would also not expect it to happen and I would also like to know the answer.

Hello,

I want to print the arguments passed to a function. But clang returns
Parameter names used in the function definition. Here is my code:

if (CallExpr *call = dyn_cast<CallExpr>(st))
{
    LangOptions LangOpts;
    LangOpts.CPlusPlus = true;
    PrintingPolicy Policy(LangOpts);

    for(int i=0, j=call->getNumArgs(); i<j; i++)
    {
        std::string TypeS;
        raw_string_ostream raw(TypeS);
        call->getArg(i)->printPretty(raw, 0, Policy);
        errs() << raw.str() << "\n";
    }
}
Example:
int iArgument = 123;
char cArgument = 'c';
foo(iArgument, cArgument);
For this code, it should print iArgument and cArgument, but it is printing
the names of the parameters given in function definition.

Please tell what might be the problem.

I cannot reproduce this issue. Are you testing with ToT, or some other
version of Clang?

Also, I am able to get the arguments' name when I am using a simple C++
code. But when I start using another library's API (for that I am specifying
compile_commands.json file), this presents problems.

Can you give some steps to reproduce? Is it possible that the other
library's API is what's causing the problem?

~Aaron

I am working with clang version 3.8. I have a MPI program which is causing the problem. Version 4.9.3 of mpiCC. I guess you will be able to reproduce the problem with a simple mpi program.

Also, I use this compile_commands.json file:

[
{
“directory”: “~/Dropbox/CLANG_MPI_LLVM/MPI”,
“command”: “mpiCC -I/usr/include/mpi BasicMPIProgram.cpp”,
“file”: “~/Dropbox/CLANG_MPI_LLVM/MPI/BasicMPIProgram.cpp”
}
]

And this to run the clang tool on a mpi source file: ./tool -p ~/Dropbox/CLANG_MPI_LLVM/MPI BasicMPIProgram.cpp

Hi Dhriti,

when applying analysis scripts on an MPI project,
I experienced problems in case mpicc|mpic++ is denoted
as the used compiler in the compile_commands.json file.
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 is used for an MPI project.
A possible workaround could be to use the scan-build intercept script
as described here: https://github.com/0ax1/MPI-Checker/tree/master/examples,
to generate the compilation database.

-Alex

Hello,

I used intercept-build to generate the compilation database for an MPI program but I am not able to get the argument names.

This is the compile_commands.json file:

[
{
“command”: “c++ -c -I/usr/include/mpi -I/usr/lib/openmpi/include -I/usr/lib/openmpi/include/openmpi -pthread BasicMPIProgram.cpp”,
“directory”: “/home/dhriti/Dropbox/CLANG_MPI_LLVM/MPI”,
“file”: “/home/dhriti/Dropbox/CLANG_MPI_LLVM/MPI/BasicMPIProgram.cpp”
}
]

Hi,

this was rather a blind guess what might fix this
behavior but obviously this is related to sth. else.
If possible, maybe you could also try a different MPI
implementation (and/or version).

-Alex