cross-checking external declarations / debug info for declarations

I am interested in putting together a tool which can verify that an external declaration conforms with the actual definition.

A.c:
extern int32_t foo();
Int bar() { return foo(); }

B.c:
int64_t foo() { … }

I had thought that I could use the debug information but the debug information in A.o does not include the type of the declaration “foo”, just the type of bar.

Is there a way to include declarations as well as definitions such as a above? It appears there is a notion of “retained” types, perhaps I add a flag to retain declarations?

Perhaps a different approach?

Thanks
—david

Have you considered creating a clang-based tool?

I'd approach this by creating a RecursiveASTVisitor, overriding VisitFuncDecl,
and dumping out the return / param types. You can mark extern decls in some
way, sort the output, and check for inconsistencies.

One advantage over looking at IR is that you don't have to use the extern'd
decl in a TU to have it show up.

vedant

Hi Vendant,

Thanks for the suggestion, I had not considered that you.

A real advantage to working with debug info is that the tool could be
implemented as a linker plugin which would avoid dealing with
false-positives in a large code pass which may include multiple versions
of some libraries. But after poking into the code that determines what
debug info to emit, a small change there looks to he non-trivial.

‹david

On 12/8/16, 5:50 PM, "vsk@apple.com on behalf of Vedant Kumar"

I am interested in putting together a tool which can verify that an external declaration conforms with the actual definition.

A.c:
extern int32_t foo();
Int bar() { return foo(); }

B.c:
int64_t foo() { … }

I had thought that I could use the debug information but the debug information in A.o does not include the type of the declaration “foo”, just the type of bar.

Is there a way to include declarations as well as definitions such as a above? It appears there is a notion of “retained” types, perhaps I add a flag to retain declarations?

You should take a look at

https://reviews.llvm.org/D18565

which implements (almost?) all that you're asking for.

-- adrian

Great, thanks Adrian, I will try it.

On 12/9/16, 9:00 AM, "aprantl@apple.com on behalf of Adrian Prantl"

We are probably not visiting forward declarations in CGDebugInfo. You would probably need to visit them and call something like CGDebugInfo::getFunctionForwardDeclaration() on each declaration.

-- adrian

I was able to add a call to EmitFunctionDecl in
lib/CodeGen/CodeGenModule.cpp and then needed a corresponding LLVM change
to handle Subprogram¹s in the retained type vector.

The diff D18565 is marked Abandoned. What is the future plans for
supporting full-type consumers?

On 12/9/16, 2:24 PM, "aprantl@apple.com on behalf of Adrian Prantl"

I proposed the patch to work around a preceived issue where we thought that dtrace wouldn't be able to find debug info for certain data structures in XNU otherwise. It turned out that this was a red herring, and with the motivation for the patch gone, I decided to abandon it. Feel free to take over the patch!

-- adrian