Skip to content

Commit 9212cbf

Browse files
committed
IRGen: Don't output the full file path in the noescape closure verification
At Odebug we print the full path to the file and in optimized mode no file name will be included. This mirrors what we do in Swift's asserts. rdar://47880964
1 parent 093d483 commit 9212cbf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/Support/ErrorHandling.h"
1919
#include "llvm/Support/Compiler.h"
20+
#include "llvm/Support/Path.h"
2021
#include "llvm/IR/DerivedTypes.h"
2122
#include "llvm/IR/Function.h"
2223
#include "llvm/IR/GlobalVariable.h"
@@ -1332,7 +1333,12 @@ llvm::Value *IRGenFunction::emitIsEscapingClosureCall(
13321333
auto loc = SILLocation::decode(sourceLoc, IGM.Context.SourceMgr);
13331334
auto line = llvm::ConstantInt::get(IGM.Int32Ty, loc.Line);
13341335
auto col = llvm::ConstantInt::get(IGM.Int32Ty, loc.Column);
1335-
auto filename = IGM.getAddrOfGlobalString(loc.Filename);
1336+
1337+
// Only output the filepath in debug mode. It is going to leak into the
1338+
// executable. This is the same behavior as asserts.
1339+
auto filename = IGM.IRGen.Opts.shouldOptimize()
1340+
? IGM.getAddrOfGlobalString("")
1341+
: IGM.getAddrOfGlobalString(loc.Filename);
13361342
auto filenameLength =
13371343
llvm::ConstantInt::get(IGM.Int32Ty, loc.Filename.size());
13381344
auto type = llvm::ConstantInt::get(IGM.Int32Ty, verificationType);

test/IRGen/closure.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
22
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CAPTURE
3+
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT
34

45
// REQUIRES: CPU=x86_64
56

7+
// CHECK-DAG: [[FILENAME:@[0-9]+]] = {{.*}} c"{{.*}}closure.swift\00"
8+
// OPT: [[FILENAME:@[0-9]+]] = {{.*}} [1 x i8] zeroinitializer
9+
610
// -- partial_apply context metadata
711

8-
// CHECK: [[METADATA:@.*]] = private constant %swift.full_boxmetadata { void (%swift.refcounted*)* @objectdestroy, i8** null, %swift.type { i64 1024 }, i32 16, i8* bitcast ({ i32, i32, i32, i32 }* @"\01l__swift5_reflection_descriptor" to i8*) }
12+
// CHECK-DAG: [[METADATA:@.*]] = private constant %swift.full_boxmetadata { void (%swift.refcounted*)* @objectdestroy, i8** null, %swift.type { i64 1024 }, i32 16, i8* bitcast ({ i32, i32, i32, i32 }* @"\01l__swift5_reflection_descriptor" to i8*) }
913

1014
func a(i i: Int) -> (Int) -> Int {
1115
return { x in i }
@@ -65,3 +69,11 @@ func useClosure(_ cl : () -> ()) {}
6569
func no_capture_descriptor(_ c: C, _ d: C, _ e: C, _ f: C, _ g: C) {
6670
useClosure( { _ = c ; _ = d ; _ = e ; _ = f ; _ = g })
6771
}
72+
73+
// CHECK-LABEL: define hidden swiftcc { i8*, %swift.refcounted* } @"$s7closure9letEscape1fyycyyXE_tF"(i8*, %swift.opaque*)
74+
// CHECK: call i1 @swift_isEscapingClosureAtFileLocation(%swift.refcounted* {{.*}}, i8* getelementptr inbounds ({{.*}} [[FILENAME]]
75+
// OPT-LABEL: define hidden swiftcc { i8*, %swift.refcounted* } @"$s7closure9letEscape1fyycyyXE_tF"(i8*, %swift.opaque*)
76+
// OPT: call i1 @swift_isEscapingClosureAtFileLocation(%swift.refcounted* {{.*}}, i8* getelementptr inbounds ({{.*}} [[FILENAME]]
77+
func letEscape(f: () -> ()) -> () -> () {
78+
return withoutActuallyEscaping(f) { return $0 }
79+
}

0 commit comments

Comments
 (0)