Skip to content

Fix symbol visibility issues for C API #440

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 8, 2025

Conversation

Gnimuc
Copy link
Contributor

@Gnimuc Gnimuc commented Jan 12, 2025

Add the missing CINDEX_LINKAGE macros for C APIs

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.15%. Comparing base (54c9482) to head (f2d2dd9).
Report is 44 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #440   +/-   ##
=======================================
  Coverage   71.15%   71.15%           
=======================================
  Files           9        9           
  Lines        3550     3550           
=======================================
  Hits         2526     2526           
  Misses       1024     1024           
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mcbarton
Copy link
Collaborator

mcbarton commented Jan 12, 2025

@Gnimuc Your PR which added the cpi was largely untested (see #438 (comment)). Would you mind putting in a PR which tests your C API so can get our total test coverage back up?

@Gnimuc
Copy link
Contributor Author

Gnimuc commented Jan 12, 2025

@Gnimuc Your PR which added the cpi was largely untested (see #438 (comment)). Would you mind putting in a PR which tests your C API so can get our total test coverage back up?

@mcbarton

Half of the untested lines are copied from libclang:

https://app.codecov.io/gh/compiler-research/CppInterOp/blob/main/lib%2FInterpreter%2FCXCppInterOp.cpp#L156

Since those C interfaces are just thin wrappers, I think a more practical way to improve the coverage of the project is adding CXCppInterOp.cpp to the ignore path of CodeCov.

@mcbarton
Copy link
Collaborator

@Gnimuc Your PR which added the cpi was largely untested (see #438 (comment)). Would you mind putting in a PR which tests your C API so can get our total test coverage back up?

@mcbarton

Half of the untested lines are copied from libclang:

https://app.codecov.io/gh/compiler-research/CppInterOp/blob/main/lib%2FInterpreter%2FCXCppInterOp.cpp#L156

Since those C interfaces are just thin wrappers, I think a more practical way to improve the coverage of the project is adding CXCppInterOp.cpp to the ignore path of CodeCov.

@vgvassilev What do you think of @Gnimuc suggestion?

@vgvassilev
Copy link
Contributor

I don't have a strong opinion. Generally it is good to have tests especially for the things that are not in libclang.

@mcbarton
Copy link
Collaborator

@Gnimuc I gave it some thought and think it would still be better to have the tests. Hopefully given they are just thin wrappers then I believe it shouldn't be too much to get tests written with them too. Then we can guarantee everything is working as expected.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@Gnimuc
Copy link
Contributor Author

Gnimuc commented Jan 19, 2025

@vgvassilev Is it OK to turn off warning C4273 as error?

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm modulo the comment.

@vgvassilev
Copy link
Contributor

@vgvassilev Is it OK to turn off warning C4273 as error?

Do we understand why the warning fires and why it is not relevant?

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -270,7 +270,8 @@ static inline compat::Interpreter* getInterpreter(const CXInterpreterImpl* I) {
return I->Interp.get();
}

CXInterpreter clang_createInterpreter(const char* const* argv, int argc) {
CINDEX_LINKAGE CXInterpreter clang_createInterpreter(const char* const* argv,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "CINDEX_LINKAGE" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang-c/Platform.h>
+ #include <cstring>

return static_cast<CXInterpreterImpl*>(I)->Interp.release();
}

enum CXErrorCode clang_Interpreter_undo(CXInterpreter I, unsigned int N) {
CINDEX_LINKAGE enum CXErrorCode clang_Interpreter_undo(CXInterpreter I,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "CXErrorCode" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang-c/CXErrorCode.h>
+ #include <cstring>

@@ -584,22 +588,26 @@
return clang::cxscope::MakeCXScope(D, getNewTU(tmpl));
}

CXObject clang_allocate(unsigned int n) { return ::operator new(n); }
CINDEX_LINKAGE CXObject clang_allocate(unsigned int n) {
return ::operator new(n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "operator new" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:17:

- #include "clang-c/CXString.h"
+ #include <new>
+ #include "clang-c/CXString.h"


void clang_deallocate(CXObject address) { ::operator delete(address); }
CINDEX_LINKAGE void clang_deallocate(CXObject address) {
::operator delete(address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "operator delete" is directly included [misc-include-cleaner]

  ::operator delete(address);
    ^

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@Gnimuc
Copy link
Contributor Author

Gnimuc commented Jan 19, 2025

@vgvassilev Is it OK to turn off warning C4273 as error?

Do we understand why the warning fires and why it is not relevant?

It turns out that the CINDEX_LINKAGE is not correctly triggered in the CMake configuration. I added a small fix to work around the problem.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@@ -133,6 +133,8 @@ else()
LINK_LIBS
${link_libs}
)

target_compile_definitions(clangCppInterOp PUBLIC "_CINDEX_LIB_") # workaround for the use of `CINDEX_LINKAGE`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using CLANG_ABI from clang/Support/Compiler.h?

@Gnimuc Gnimuc mentioned this pull request Mar 8, 2025
4 tasks
@vgvassilev vgvassilev merged commit 16c67f9 into compiler-research:main Mar 8, 2025
59 checks passed
@anutosh491 anutosh491 mentioned this pull request Mar 11, 2025
3 tasks
@Gnimuc Gnimuc deleted the c-api-visibility branch March 13, 2025 00:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants