-
Notifications
You must be signed in to change notification settings - Fork 2
Feature: Add @linkage_name attribute #676
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a2233c
feat(attributes): add support for @linkage_name attribute and validat…
LindonAliu 6743bba
refactor(DuplicateFunctionChecker): consolidate duplicate function ch…
LindonAliu 3369617
test: update error messages to clarify attribute references for dupli…
LindonAliu 44d6c58
tests: add functional tests for @linkage_name attribute in LLVM IR ge…
LindonAliu 8459db6
test: remove obsolete linkage_name validation tests
LindonAliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // | ||
| // RUN: not gluc -c %s -o %t.o 2>&1 | FileCheck -v %s | ||
| // | ||
| // Test duplicate linkage names and conflicts with no_mangling functions | ||
|
|
||
| // Test 1: Two functions with the same linkage name should fail | ||
| @linkage_name("duplicate_name") | ||
| func firstFunction(); | ||
|
|
||
| // CHECK: error: duplicate function with linkage_name 'duplicate_name' | ||
| @linkage_name("duplicate_name") | ||
| func secondFunction(param: Int); | ||
|
|
||
| // Test 2: @linkage_name function conflicting with @no_mangling function | ||
| @no_mangling | ||
| func conflict_func(); | ||
|
|
||
| // CHECK: error: function with linkage_name 'conflict_func' conflicts with a no_mangling function | ||
| @linkage_name("conflict_func") | ||
| func anotherFunction(); | ||
|
|
||
| // Test 3: @no_mangling function conflicting with existing @linkage_name | ||
| @linkage_name("existing_name") | ||
| func existingLinkage(); | ||
|
|
||
| // CHECK: error: function with no_mangling conflicts with a function using linkage_name 'existing_name' | ||
| @no_mangling | ||
| func existing_name(); | ||
|
|
||
| // CHECK: error: Attributes '@linkage_name' and '@no_mangling' are mutually exclusive | ||
| @linkage_name("custom_name") | ||
| @no_mangling | ||
| func conflictingAttributes(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // | ||
|
LindonAliu marked this conversation as resolved.
Outdated
|
||
| // RUN: gluc -c %s -o %s.o > /dev/null | ||
| // | ||
| // Test valid uses of @linkage_name attribute (should parse and validate without errors) | ||
|
|
||
| // Valid function prototype with linkage_name | ||
| @linkage_name("custom_hello") | ||
| func world(); | ||
|
|
||
| // Valid function definition with linkage_name | ||
| @linkage_name("implementation_name") | ||
| func myFunction() { | ||
| return; | ||
| } | ||
|
|
||
| // Valid function with parameters and linkage_name | ||
| @linkage_name("param_func") | ||
| func withParams(a: Int, b: Double) -> Int { | ||
| return a; | ||
| } | ||
|
|
||
| // Multiple functions with different linkage names (should be fine) | ||
| @linkage_name("func1") | ||
| func function1(); | ||
|
|
||
| @linkage_name("func2") | ||
| func function2(); | ||
|
|
||
| @linkage_name("func3") | ||
| func function3(x: Int); | ||
|
|
||
| // Function without linkage_name mixed with ones that have it (should be fine) | ||
| func normalFunction() { | ||
| return; | ||
| } | ||
|
|
||
| // Call the functions using their original names (not linkage names) | ||
| func testCalls() { | ||
| world(); // calls the function with linkage name "custom_hello" | ||
| myFunction(); | ||
| let result = withParams(42, 3.14); | ||
| function1(); | ||
| function2(); | ||
| function3(100); | ||
| normalFunction(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // | ||
| // RUN: not gluc %s 2>&1 | FileCheck %s | ||
| // | ||
| // Test that @linkage_name attribute parameter validation works correctly | ||
|
|
||
| // Test 1: @linkage_name requires a string parameter | ||
| // CHECK: error: Attribute '@linkage_name' expects a parameter of type LiteralExpr | ||
| @linkage_name | ||
| func missingParam(); | ||
|
|
||
| // Test 2: @linkage_name with integer parameter (should fail) | ||
| // CHECK: error: Attribute '@linkage_name' expects a string literal, not a numeric or other literal type | ||
| @linkage_name(42) | ||
| func wrongParamType(); | ||
|
|
||
| // Test 3: @linkage_name with empty string (should fail) | ||
| // CHECK: error: Linkage name cannot be empty | ||
| @linkage_name("") | ||
| func emptyLinkageName(); | ||
|
|
||
| // Test 4: @linkage_name on wrong declaration type (should fail on structs) | ||
| // CHECK: error: Attribute '@linkage_name' is not valid on structs | ||
| @linkage_name("test") | ||
| struct InvalidOnStruct { | ||
| data: UInt64 | ||
| } | ||
|
|
||
| // Test 5: @linkage_name on wrong declaration type (should fail on variables) | ||
| // CHECK: error: Attribute '@linkage_name' is not valid on global variables | ||
| @linkage_name("test") | ||
| var invalidOnVar: Int = 5; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.