-
Notifications
You must be signed in to change notification settings - Fork 10.5k
ClangImporter: enhance the importer to alias declarations #81840
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 all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
compnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#if defined(UNICODE) | ||
#define F FW | ||
#define V VW | ||
#else | ||
#define F FA | ||
#define V VA | ||
#endif | ||
|
||
#if defined(_WIN32) | ||
#define ALIASES_ABI /**/ | ||
#else | ||
#define ALIASES_ABI __attribute__((__visibility__("default"))) | ||
#endif | ||
|
||
extern ALIASES_ABI const unsigned int VA; | ||
extern ALIASES_ABI const unsigned long long VW; | ||
|
||
ALIASES_ABI void FA(unsigned int); | ||
ALIASES_ABI void FW(unsigned long long); | ||
|
||
#define InvalidCall DoesNotExist | ||
|
||
extern ALIASES_ABI float UIA; | ||
extern ALIASES_ABI double UIW; | ||
|
||
#if defined(UNICODE) | ||
#define UI UIW | ||
#else | ||
#define UI UIA | ||
#endif | ||
|
||
enum { | ||
ALPHA = 0, | ||
#define ALPHA ALPHA | ||
BETA = 1, | ||
#define BETA BETA | ||
}; | ||
|
||
enum { | ||
_CLOCK_MONOTONIC __attribute__((__swift_name__("CLOCK_MONOTONIC"))), | ||
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC | ||
} _clock_t; | ||
|
||
enum : int { | ||
overloaded, | ||
}; | ||
#define overload overloaded | ||
extern const int const_overloaded __attribute__((__swift_name__("overload"))); | ||
|
||
void variadic(int count, ...); | ||
#define aliased_variadic variadic |
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 |
---|---|---|
|
@@ -275,3 +275,7 @@ module CommonName { | |
module "Weird C Module" { | ||
header "WeirdCModule.h" | ||
} | ||
|
||
module Aliases { | ||
header "Aliases.h" | ||
} |
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,20 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules | ||
|
||
import Aliases | ||
|
||
func f() { | ||
InvalidCall() // expected-error{{cannot find 'InvalidCall' in scope}} | ||
} | ||
|
||
func g() { | ||
V = 32 // expected-error{{cannot assign to value: 'V' is a get-only property}} | ||
} | ||
|
||
func h() { | ||
let _ = overload // expected-error{{ambiguous use of 'overload'}} | ||
} | ||
|
||
func i() { | ||
aliased_variadic(0, 0) // expected-error{{cannot find 'aliased_variadic' in scope}} | ||
} |
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,64 @@ | ||
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules %s | ||
// RUN: %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -Osize -emit-ir -o - %s | %FileCheck %s -check-prefix CHECK-ANSI-IR | ||
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules %s -Xcc -DUNICODE | ||
// RUN: %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -Osize -emit-ir -o - %s -Xcc -DUNICODE | %FileCheck %s -check-prefix CHECK-UNICODE-IR | ||
// RUN: not %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -c %s -DINVALID -o /dev/null 2>&1 | %FileCheck --dry-run %s -check-prefix CHECK-INVALID | ||
|
||
// expected-no-diagnostics | ||
|
||
import Aliases | ||
|
||
public func f() { | ||
F(V) | ||
} | ||
|
||
public func g() { | ||
UI = 32 | ||
} | ||
|
||
// CHECK-ANSI-IR: @VA = external {{(dso_local )?}}local_unnamed_addr constant i32 | ||
// CHECK-ANSI-IR: @UIA = external {{(dso_local )?}}local_unnamed_addr global float | ||
|
||
// CHECK-ANSI-IR: define {{.*}}swiftcc void @"$s5Alias1fyyF"(){{.*}}{ | ||
// CHECK-ANSI-IR: entry: | ||
// CHECK-ANSI-IR: %0 = load i32, ptr @VA | ||
// CHECK-ANSI-IR: tail call void @FA(i32 %0) | ||
// CHECK-ANSI-IR: ret void | ||
// CHECK-ANSI-IR: } | ||
|
||
// CHECK-ANSI-IR: declare {{.*}}void @FA(i32 noundef) | ||
// CHECK-ANSI-IR-NOT: declare {{.*}}void @FW(i64 noundef) | ||
|
||
// CHECK-ANSI-IR: define {{.*}}swiftcc void @"$s5Alias1gyyF"(){{.*}}{ | ||
// CHECK-ANSI-IR: entry: | ||
// CHECK-ANSI-IR: store float 3.200000e+01, ptr @UIA | ||
// CHECK-ANSI-IR: ret void | ||
// CHECK-ANSI-IR: } | ||
|
||
// CHECK-UNICODE-IR: @VW = external {{(dso_local )?}}local_unnamed_addr constant i64 | ||
// CHECK-UNICODE-IR: @UIW = external {{(dso_local )?}}local_unnamed_addr global double | ||
|
||
// CHECK-UNICODE-IR: define {{.*}}swiftcc void @"$s5Alias1fyyF"(){{.*}}{ | ||
// CHECK-UNICODE-IR: entry: | ||
// CHECK-UNICODE-IR: %0 = load i64, ptr @VW | ||
// CHECK-UNICODE-IR: tail call void @FW(i64 %0) | ||
// CHECK-UNICODE-IR: ret void | ||
// CHECK-UNICODE-IR: } | ||
|
||
// CHECK-UNICODE-IR: declare {{(dso_local )?}}void @FW(i64 noundef) | ||
// CHECK-UNICODE-IR-NOT: declare {{(dso_local )?}}void @FA(i32 noundef) | ||
|
||
// CHECK-UNICODE-IR: define {{.*}}swiftcc void @"$s5Alias1gyyF"(){{.*}}{ | ||
// CHECK-UNICODE-IR: entry: | ||
// CHECK-UNICODE-IR: store double 3.200000e+01, ptr @UIW | ||
// CHECK-UNICODE-IR: ret void | ||
// CHECK-UNICODE-IR: } | ||
|
||
func h() { | ||
let _ = CLOCK_MONOTONIC | ||
} | ||
|
||
#if INVALID | ||
let _ = ALPHA | ||
// CHECK-INVALID: error: global variable declaration does not bind any variables | ||
#endif |
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.