Skip to content

Commit 9eea6c2

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 2d3215b + 1a770a3 commit 9eea6c2

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

lib/IRGen/GenClangDecl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ IRGenModule::getAddrOfClangGlobalDecl(clang::GlobalDecl global,
113113
}
114114

115115
void IRGenModule::finalizeClangCodeGen() {
116+
// Ensure that code is emitted for any `PragmaCommentDecl`s. (These are
117+
// always guaranteed to be directly below the TranslationUnitDecl.)
118+
// In Clang, this happens automatically during the Sema phase, but here we
119+
// need to take care of it manually because our Clang CodeGenerator is not
120+
// attached to Clang Sema as an ASTConsumer.
121+
for (const auto *D : ClangASTContext->getTranslationUnitDecl()->decls()) {
122+
if (const auto *PCD = dyn_cast<clang::PragmaCommentDecl>(D)) {
123+
emitClangDecl(PCD);
124+
}
125+
}
126+
116127
ClangCodeGen->HandleTranslationUnit(
117128
*const_cast<clang::ASTContext *>(ClangASTContext));
118129
}

lib/IRGen/GenClass.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -813,24 +813,24 @@ llvm::Value *irgen::emitClassAllocation(IRGenFunction &IGF, SILType selfType,
813813
auto &classLayout = classTI.getClassLayout(IGF.IGM, selfType,
814814
/*forBackwardDeployment=*/false);
815815

816-
llvm::Value *size, *alignMask;
817-
if (classLayout.isFixedSize()) {
818-
size = IGF.IGM.getSize(classLayout.getSize());
819-
alignMask = IGF.IGM.getSize(classLayout.getAlignMask());
820-
} else {
821-
std::tie(size, alignMask)
822-
= emitClassResilientInstanceSizeAndAlignMask(IGF,
823-
selfType.getClassOrBoundGenericClass(),
824-
metadata);
825-
}
826-
827816
llvm::Type *destType = classLayout.getType()->getPointerTo();
828817
llvm::Value *val = nullptr;
829818
if (llvm::Value *Promoted = stackPromote(IGF, classLayout, StackAllocSize,
830819
TailArrays)) {
831820
val = IGF.Builder.CreateBitCast(Promoted, IGF.IGM.RefCountedPtrTy);
832821
val = IGF.emitInitStackObjectCall(metadata, val, "reference.new");
833822
} else {
823+
llvm::Value *size, *alignMask;
824+
if (classLayout.isFixedSize()) {
825+
size = IGF.IGM.getSize(classLayout.getSize());
826+
alignMask = IGF.IGM.getSize(classLayout.getAlignMask());
827+
} else {
828+
std::tie(size, alignMask)
829+
= emitClassResilientInstanceSizeAndAlignMask(IGF,
830+
selfType.getClassOrBoundGenericClass(),
831+
metadata);
832+
}
833+
834834
// Allocate the object on the heap.
835835
std::tie(size, alignMask)
836836
= appendSizeForTailAllocatedArrays(IGF, size, alignMask, TailArrays);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#pragma comment(lib, "transitive-module")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "autolink-coff-c-pragma-transitive.h"
2+
3+
#pragma comment(lib, "module")

test/IRGen/Inputs/module.modulemap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module AutolinkCoffCPragma {
2+
header "autolink-coff-c-pragma.h"
3+
export *
4+
}
5+
6+
module AutolinkCoffCPragmaTransitive {
7+
header "autolink-coff-c-pragma-transitive.h"
8+
export *
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Tests that a `#pragma comment(lib, ...)` in a C header imported as a module
2+
// causes a corresponding `/DEFAULTLIB` directive to be emitted.
3+
//
4+
// We test that this is true also for C headers included transitively from
5+
// another C header.
6+
7+
// RUN: %swift -module-name Swift -target x86_64-unknown-windows-msvc -I %S/Inputs -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=CHECK-MSVC-IR
8+
// RUN: %swift -module-name Swift -target x86_64-unknown-windows-msvc -I %S/Inputs -S %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=CHECK-MSVC-ASM
9+
10+
// REQUIRES: CODEGENERATOR=X86
11+
12+
import AutolinkCoffCPragma
13+
14+
// CHECK-MSVC-IR: !llvm.linker.options = !{!{{[0-9]+}}, !{{[0-9]+}}}
15+
// CHECK-MSVC-IR-DAG: !{{[0-9]+}} = !{!"/DEFAULTLIB:module.lib"}
16+
// CHECK-MSVC-IR-DAG: !{{[0-9]+}} = !{!"/DEFAULTLIB:transitive-module.lib"}
17+
18+
// CHECK-MSVC-ASM: .section .drectve
19+
// CHECK-MSVC-ASM-DAG: .ascii " /DEFAULTLIB:module.lib"
20+
// CHECK-MSVC-ASM-DAG: .ascii " /DEFAULTLIB:transitive-module.lib"

0 commit comments

Comments
 (0)