Skip to content

GCC Compatibility #787

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

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open

GCC Compatibility #787

wants to merge 2 commits into from

Conversation

fabianbs96
Copy link
Member

Make phasar compile with gcc (g++-11 and g++-13) and uncover (and fix) two bugs related to json ser/de with LLVMAliasSet and LLVMBasedICFG that were not detected until now, because of nlohmann's implicit conversions feature.

…related to json ser/de with LLVMAliasSet and LLVMBasedICFG that were not detected untio now, because of nlohmann's implicit conversions feature
@fabianbs96 fabianbs96 self-assigned this Aug 3, 2025
@fabianbs96 fabianbs96 added bug Something isn't working technical debt labels Aug 3, 2025
@fabianbs96 fabianbs96 marked this pull request as ready for review August 3, 2025 14:38
@fabianbs96 fabianbs96 requested a review from sritejakv August 3, 2025 14:38
CMakeLists.txt Outdated
@@ -82,6 +82,11 @@ option(PHASAR_BUILD_MODULES "Build C++20 modules for phasar" OFF)

include(CheckCXXCompilerFlag)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Match clang's behavior, when handling naming collisions, such as "using l_t = l_t;"
string(APPEND CMAKE_CXX_FLAGS " -fpermissive")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would highly advice against adding permissive here. Permissive turns many actual errors into warnings/nothing. It is not recommended to be turned on.

Either we should fine another fix for the collisions or, even better, just fix them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree.
Fixed it

Comment on lines 59 to +60
static constexpr auto isLLVMZeroValue = [](const llvm::Value *V) noexcept {
return V == getInstance();
return isZeroValueHelper(V);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the underlying reason to have a lambda here instead of a normal static member?

Copy link
Member Author

Choose a reason for hiding this comment

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

The original reason was to make it easier to pass this as callback to other functions, such as in here or here.

Not sure whether it is worth it in the end though.

@@ -36,6 +36,10 @@ class LLVMZeroValue : public llvm::GlobalVariable {
LLVMZeroValue(llvm::Module &Mod);

static constexpr llvm::StringLiteral LLVMZeroValueInternalName = "zero_value";
static bool isZeroValueHelper(const llvm::Value *V) noexcept {
// Need this helper function to make gcc happy
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the problem here for gcc?

Copy link
Member Author

Choose a reason for hiding this comment

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

For gcc, the type LLVMZeroValue is incomplete in the lambda, so it cannot perform the implicit conversion to pointer-to-base for the comparison V == getInstance()

@@ -942,6 +942,14 @@ class IDEInstInteractionAnalysisT

inline l_t join(l_t Lhs, l_t Rhs) override { return joinImpl(Lhs, Rhs); }

struct IIAAKillOrReplaceEF;
struct IIAAAddLabelsEF;
// These friend declarations are needed to make gcc happy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you maybe add the problem here in the comment, it's a bit hard to figure out why you needed this here.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

struct IIAAKillOrReplaceEF;
struct IIAAAddLabelsEF;
// These friend declarations are needed to make gcc happy
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume making them hidden friends was not an option because you would need the full def. for the implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, we can simplify this, as we only need the friend on the IIA analysis class, not on the edge-functions.
Thanks for pointing that out!

Changed it.

@fabianbs96 fabianbs96 requested a review from vulder August 21, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants