This is an archive of the discontinued LLVM Phabricator instance.

Added a C-API binding to query the LLVM version
ClosedPublic

Authored by wjakob on Dec 5 2022, 5:12 PM.

Details

Summary

The LLVM C bindings currently offer no way to query the version string
dynamically. This is a useful feature in situations where a program
isn't compiled against a specific version of LLVM but rather loads it
dynamically (e.g. using dlopen()).

In situations where the shared library filename doesn't reveal the
version (e.g. LLVM-C.dll) and to adapt to version-specific API
differences, it is then useful to be able to query the version string by
calling the proposed LLVMGetVersion function.

Diff Detail

Event Timeline

wjakob created this revision.Dec 5 2022, 5:12 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
wjakob requested review of this revision.Dec 5 2022, 5:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2022, 5:12 PM
wjakob added a comment.EditedDec 5 2022, 5:17 PM

Dear LLVM developers -- this is my first contribution to the LLVM project, I hope I got it right.

Note that I am adding a new C-API function, and that should in principle be covered by tests. However, it was not sure to me where such a test would be added.

The only systematic tests of the C API I could find were really specific to certain components like ./unittests/Passes/PassBuilderBindingsTest.cpp or unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp. I am open to any suggestions.

nikic added a subscriber: nikic.Dec 6 2022, 2:40 AM

There are tests for the C API in llvm/tools/llvm-c-test, but maybe this is a bit inconvenient in this case. It would be possible to add a new unit test file like llvm/unittests/IR/Core.cpp or so as well.

wjakob added a comment.Dec 6 2022, 2:19 PM

I added a testcase and ran arcanist again, which created a child differential D139460. I hope that's right.

nikic added a comment.Dec 6 2022, 11:35 PM

I added a testcase and ran arcanist again, which created a child differential D139460. I hope that's right.

The tests should be part of the same differential revision. I don't use arcanist, but you probably need to squash the two commits locally.

wjakob updated this revision to Diff 480788.EditedDec 6 2022, 11:54 PM

Thanks, that sounds more reasonable. I closed the other differential and updated this one with a squashed commit.

nikic added inline comments.Dec 7 2022, 12:19 AM
llvm/include/llvm-c/Core.h
490

nit: Variable names should be upper case.

llvm/unittests/IR/CoreBindings.cpp
17

nit: Unnecessary newline.

nikic added a reviewer: nikic.Dec 7 2022, 12:19 AM
wjakob updated this revision to Diff 480801.Dec 7 2022, 1:02 AM

Removed superfluous newline.

wjakob updated this revision to Diff 480802.Dec 7 2022, 1:04 AM

Changed variable case

nikic accepted this revision.Dec 7 2022, 1:17 AM

LGTM. What Name <email> should be used for the commit?

This revision is now accepted and ready to land.Dec 7 2022, 1:17 AM
wjakob added a comment.Dec 7 2022, 2:04 AM

Thank you. Please use

Wenzel Jakob <wenzel.jakob@epfl.ch>

This revision was landed with ongoing or failed builds.Dec 7 2022, 2:18 AM
This revision was automatically updated to reflect the committed changes.