Skip to content

IRGen: Don't output the full file path in the withoutActuallyEscaping… #22479

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/IRGen/GenHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Path.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
Expand Down Expand Up @@ -1332,7 +1333,12 @@ llvm::Value *IRGenFunction::emitIsEscapingClosureCall(
auto loc = SILLocation::decode(sourceLoc, IGM.Context.SourceMgr);
auto line = llvm::ConstantInt::get(IGM.Int32Ty, loc.Line);
auto col = llvm::ConstantInt::get(IGM.Int32Ty, loc.Column);
auto filename = IGM.getAddrOfGlobalString(loc.Filename);

// Only output the filepath in debug mode. It is going to leak into the
// executable. This is the same behavior as asserts.
auto filename = IGM.IRGen.Opts.shouldOptimize()
? IGM.getAddrOfGlobalString("")
: IGM.getAddrOfGlobalString(loc.Filename);
auto filenameLength =
llvm::ConstantInt::get(IGM.Int32Ty, loc.Filename.size());
auto type = llvm::ConstantInt::get(IGM.Int32Ty, verificationType);
Expand Down
14 changes: 13 additions & 1 deletion test/IRGen/closure.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CAPTURE
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT

// REQUIRES: CPU=x86_64

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

// -- partial_apply context metadata

// 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*) }
// 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*) }

func a(i i: Int) -> (Int) -> Int {
return { x in i }
Expand Down Expand Up @@ -65,3 +69,11 @@ func useClosure(_ cl : () -> ()) {}
func no_capture_descriptor(_ c: C, _ d: C, _ e: C, _ f: C, _ g: C) {
useClosure( { _ = c ; _ = d ; _ = e ; _ = f ; _ = g })
}

// CHECK-LABEL: define hidden swiftcc { i8*, %swift.refcounted* } @"$s7closure9letEscape1fyycyyXE_tF"(i8*, %swift.opaque*)
// CHECK: call i1 @swift_isEscapingClosureAtFileLocation(%swift.refcounted* {{.*}}, i8* getelementptr inbounds ({{.*}} [[FILENAME]]
// OPT-LABEL: define hidden swiftcc { i8*, %swift.refcounted* } @"$s7closure9letEscape1fyycyyXE_tF"(i8*, %swift.opaque*)
// OPT: call i1 @swift_isEscapingClosureAtFileLocation(%swift.refcounted* {{.*}}, i8* getelementptr inbounds ({{.*}} [[FILENAME]]
func letEscape(f: () -> ()) -> () -> () {
return withoutActuallyEscaping(f) { return $0 }
}