Skip to content

Commit 4e56d81

Browse files
committed
[embedded] Mark all functions as 'nounwind' in embedded Swift, add dependency tests
1 parent 36dd2c9 commit 4e56d81

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,10 @@ void IRGenModule::constructInitialFnAttributes(
14441444
Attrs.addAttribute(llvm::Attribute::StackProtectReq);
14451445
Attrs.addAttribute("stack-protector-buffer-size", llvm::utostr(8));
14461446
}
1447+
1448+
if (Context.LangOpts.hasFeature(Feature::Embedded)) {
1449+
Attrs.addAttribute(llvm::Attribute::NoUnwind);
1450+
}
14471451
}
14481452

14491453
llvm::AttributeList IRGenModule::constructInitialAttributes() {

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,10 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f)
18461846
CurFn->addFnAttr(llvm::Attribute::NoInline);
18471847
}
18481848

1849+
if (IGM.Context.LangOpts.hasFeature(Feature::Embedded)) {
1850+
CurFn->addFnAttr(llvm::Attribute::NoUnwind);
1851+
}
1852+
18491853
auto optMode = f->getOptimizationMode();
18501854
if (optMode != OptimizationMode::NotSet &&
18511855
optMode != f->getModule().getOptions().OptMode) {

test/embedded/dependencies.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -enable-experimental-feature Embedded %s -c -o %t/a.o
3+
4+
// backslash is not doing anything, just to make the grep not match its own line
5+
// RUN: grep DEP-%target-os %s | sed 's#// DEP-%target-os: ##' | sort > %t/expected-dependencies.txt
6+
// RUN: %llvm-nm --undefined-only --format=just-symbols %t/a.out | sort > %t/actual-dependencies.txt
7+
// RUN: diff -u %t/expected-dependencies.txt %t/actual-dependencies.txt
8+
9+
// DEP-macosx: ___stack_chk_fail
10+
// DEP-macosx: ___stack_chk_guard
11+
// DEP-macosx: _free
12+
// DEP-macosx: _posix_memalign
13+
// DEP-macosx: _printf
14+
// DEP-macosx: _putchar
15+
// DEP-macosx: dyld_stub_binder
16+
17+
// DEP-linux-gnu: __stack_chk_fail
18+
// DEP-linux-gnu: __stack_chk_guard
19+
// DEP-linux-gnu: free
20+
// DEP-linux-gnu: posix_memalign
21+
// DEP-linux-gnu: putchar
22+
23+
// REQUIRES: swift_in_compiler
24+
// REQUIRES: executable_test
25+
// REQUIRES: optimized_stdlib
26+
// REQUIRES: OS=macosx || OS=linux-gnu
27+
28+
@_silgen_name("putchar")
29+
func putchar(_: UInt8)
30+
31+
public func print(_ s: StaticString, terminator: StaticString = "\n") {
32+
var p = s.utf8Start
33+
while p.pointee != 0 {
34+
putchar(p.pointee)
35+
p += 1
36+
}
37+
p = terminator.utf8Start
38+
while p.pointee != 0 {
39+
putchar(p.pointee)
40+
p += 1
41+
}
42+
}
43+
44+
print("Hello Embedded Swift!") // CHECK: Hello Embedded Swift!

0 commit comments

Comments
 (0)