Skip to content

fix GetVariableOffset for templated static variable #629

New issue

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

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

Already on GitHub? Sign in to your account

Conversation

Vipul-Cariappa
Copy link
Collaborator

@Vipul-Cariappa Vipul-Cariappa commented Jun 13, 2025

This is a bug report.

template <typename T>
struct ClassWithStatic {
    static T const ref_value;
};
template <typename T>
T constexpr ClassWithStatic<T>::ref_value = 42;

ClassWithStatic<int> x;
Cpp::GetVariableOffset(x.ref_val); // FAILS

Will help fix a test in cppyy.

Copy link
Contributor

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

@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/templ-class-static-dm branch from 510222c to aa78f32 Compare June 13, 2025 14:02
Copy link
Contributor

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

@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/templ-class-static-dm branch from aa78f32 to 517b64d Compare July 15, 2025 12:43
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

@@ -1492,7 +1492,8 @@ intptr_t GetVariableOffset(compat::Interpreter& I, Decl* D,
#ifdef CPPINTEROP_USE_CLING
cling::Interpreter::PushTransactionRAII RAII(&getInterp());
#endif // CPPINTEROP_USE_CLING
getSema().InstantiateVariableDefinition(SourceLocation(), VD);
getSema().InstantiateVariableDefinition(SourceLocation(), VD, true,
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 "llvm::sys::DynamicLibrary" is directly included [misc-include-cleaner]

lib/CppInterOp/CppInterOp.cpp:40:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <llvm/Support/DynamicLibrary.h>
+ #if CLANG_VERSION_MAJOR >= 19

@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/templ-class-static-dm branch from 517b64d to 8c515ca Compare August 1, 2025 10:01
Copy link
Contributor

github-actions bot commented Aug 1, 2025

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

Copy link

codecov bot commented Aug 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.67%. Comparing base (b7ab5ae) to head (8c515ca).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #629      +/-   ##
==========================================
+ Coverage   79.64%   79.67%   +0.03%     
==========================================
  Files           9        9              
  Lines        3930     3931       +1     
==========================================
+ Hits         3130     3132       +2     
+ Misses        800      799       -1     
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 87.82% <100.00%> (+0.05%) ⬆️
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 87.82% <100.00%> (+0.05%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Vipul-Cariappa Vipul-Cariappa changed the title [MRE] cant resolve static variable offset for templated class fix GetVariableOffset for templated static variable Aug 1, 2025
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!

@Vipul-Cariappa Vipul-Cariappa merged commit e8c9c41 into compiler-research:main Aug 2, 2025
42 checks passed
@Vipul-Cariappa Vipul-Cariappa deleted the bug/templ-class-static-dm branch August 2, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants