Skip to content

Commit df4f507

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:0bc7cd4d5122 into amd-gfx:94601047c932
Local branch amd-gfx 9460104 Merged main:7b97d5048a8f into amd-gfx:3ab181f6d3ad Remote branch main 0bc7cd4 [flang] Add runtimes using --dependent-lib on MSVC targets (llvm#72519)
2 parents 9460104 + 0bc7cd4 commit df4f507

File tree

88 files changed

+7741
-7083
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+7741
-7083
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -977,47 +977,11 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
977977
return true;
978978
}
979979

980-
void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
980+
void tools::addFortranRuntimeLibs(const ToolChain &TC,
981981
llvm::opt::ArgStringList &CmdArgs) {
982-
if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
983-
CmdArgs.push_back(Args.MakeArgString(
984-
"/DEFAULTLIB:" + TC.getCompilerRTBasename(Args, "builtins")));
985-
unsigned RTOptionID = options::OPT__SLASH_MT;
986-
if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
987-
RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())
988-
.Case("static", options::OPT__SLASH_MT)
989-
.Case("static_dbg", options::OPT__SLASH_MTd)
990-
.Case("dll", options::OPT__SLASH_MD)
991-
.Case("dll_dbg", options::OPT__SLASH_MDd)
992-
.Default(options::OPT__SLASH_MT);
993-
}
994-
switch (RTOptionID) {
995-
case options::OPT__SLASH_MT:
996-
CmdArgs.push_back("/DEFAULTLIB:libcmt");
997-
CmdArgs.push_back("Fortran_main.static.lib");
998-
CmdArgs.push_back("FortranRuntime.static.lib");
999-
CmdArgs.push_back("FortranDecimal.static.lib");
1000-
break;
1001-
case options::OPT__SLASH_MTd:
1002-
CmdArgs.push_back("/DEFAULTLIB:libcmtd");
1003-
CmdArgs.push_back("Fortran_main.static_dbg.lib");
1004-
CmdArgs.push_back("FortranRuntime.static_dbg.lib");
1005-
CmdArgs.push_back("FortranDecimal.static_dbg.lib");
1006-
break;
1007-
case options::OPT__SLASH_MD:
1008-
CmdArgs.push_back("/DEFAULTLIB:msvcrt");
1009-
CmdArgs.push_back("Fortran_main.dynamic.lib");
1010-
CmdArgs.push_back("FortranRuntime.dynamic.lib");
1011-
CmdArgs.push_back("FortranDecimal.dynamic.lib");
1012-
break;
1013-
case options::OPT__SLASH_MDd:
1014-
CmdArgs.push_back("/DEFAULTLIB:msvcrtd");
1015-
CmdArgs.push_back("Fortran_main.dynamic_dbg.lib");
1016-
CmdArgs.push_back("FortranRuntime.dynamic_dbg.lib");
1017-
CmdArgs.push_back("FortranDecimal.dynamic_dbg.lib");
1018-
break;
1019-
}
1020-
} else {
982+
// These are handled earlier on Windows by telling the frontend driver to add
983+
// the correct libraries to link against as dependents in the object file.
984+
if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
1021985
CmdArgs.push_back("-lFortran_main");
1022986
CmdArgs.push_back("-lFortranRuntime");
1023987
CmdArgs.push_back("-lFortranDecimal");

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
116116
bool IsOffloadingHost = false, bool GompNeedsRT = false);
117117

118118
/// Adds Fortran runtime libraries to \p CmdArgs.
119-
void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args,
119+
void addFortranRuntimeLibs(const ToolChain &TC,
120120
llvm::opt::ArgStringList &CmdArgs);
121121

122122
/// Adds the path for the Fortran runtime libraries to \p CmdArgs.

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
678678
// to generate executables.
679679
if (getToolChain().getDriver().IsFlangMode()) {
680680
addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
681-
addFortranRuntimeLibs(getToolChain(), Args, CmdArgs);
681+
addFortranRuntimeLibs(getToolChain(), CmdArgs);
682682
}
683683

684684
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))

clang/lib/Driver/ToolChains/DragonFly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
153153
// AddRunTimeLibs).
154154
if (D.IsFlangMode()) {
155155
addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
156-
addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
156+
addFortranRuntimeLibs(ToolChain, CmdArgs);
157157
CmdArgs.push_back("-lm");
158158
}
159159

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,59 @@ void Flang::AddAArch64TargetArgs(const ArgList &Args,
204204
}
205205
}
206206

207+
static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
208+
ArgStringList &CmdArgs) {
209+
assert(TC.getTriple().isKnownWindowsMSVCEnvironment() &&
210+
"can only add VS runtime library on Windows!");
211+
if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
212+
CmdArgs.push_back(Args.MakeArgString(
213+
"--dependent-lib=" + TC.getCompilerRTBasename(Args, "builtins")));
214+
}
215+
unsigned RTOptionID = options::OPT__SLASH_MT;
216+
if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
217+
RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())
218+
.Case("static", options::OPT__SLASH_MT)
219+
.Case("static_dbg", options::OPT__SLASH_MTd)
220+
.Case("dll", options::OPT__SLASH_MD)
221+
.Case("dll_dbg", options::OPT__SLASH_MDd)
222+
.Default(options::OPT__SLASH_MT);
223+
}
224+
switch (RTOptionID) {
225+
case options::OPT__SLASH_MT:
226+
CmdArgs.push_back("-D_MT");
227+
CmdArgs.push_back("--dependent-lib=libcmt");
228+
CmdArgs.push_back("--dependent-lib=Fortran_main.static.lib");
229+
CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
230+
CmdArgs.push_back("--dependent-lib=FortranDecimal.static.lib");
231+
break;
232+
case options::OPT__SLASH_MTd:
233+
CmdArgs.push_back("-D_MT");
234+
CmdArgs.push_back("-D_DEBUG");
235+
CmdArgs.push_back("--dependent-lib=libcmtd");
236+
CmdArgs.push_back("--dependent-lib=Fortran_main.static_dbg.lib");
237+
CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
238+
CmdArgs.push_back("--dependent-lib=FortranDecimal.static_dbg.lib");
239+
break;
240+
case options::OPT__SLASH_MD:
241+
CmdArgs.push_back("-D_MT");
242+
CmdArgs.push_back("-D_DLL");
243+
CmdArgs.push_back("--dependent-lib=msvcrt");
244+
CmdArgs.push_back("--dependent-lib=Fortran_main.dynamic.lib");
245+
CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
246+
CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic.lib");
247+
break;
248+
case options::OPT__SLASH_MDd:
249+
CmdArgs.push_back("-D_MT");
250+
CmdArgs.push_back("-D_DEBUG");
251+
CmdArgs.push_back("-D_DLL");
252+
CmdArgs.push_back("--dependent-lib=msvcrtd");
253+
CmdArgs.push_back("--dependent-lib=Fortran_main.dynamic_dbg.lib");
254+
CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
255+
CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic_dbg.lib");
256+
break;
257+
}
258+
}
259+
207260
void Flang::addTargetOptions(const ArgList &Args,
208261
ArgStringList &CmdArgs) const {
209262
const ToolChain &TC = getToolChain();
@@ -267,6 +320,10 @@ void Flang::addTargetOptions(const ArgList &Args,
267320
}
268321
}
269322

323+
if (Triple.isKnownWindowsMSVCEnvironment()) {
324+
processVSRuntimeLibrary(TC, Args, CmdArgs);
325+
}
326+
270327
// TODO: Add target specific flags, ABI, mtune option etc.
271328
}
272329

clang/lib/Driver/ToolChains/FreeBSD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
310310
// AddRunTimeLibs).
311311
if (D.IsFlangMode()) {
312312
addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
313-
addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
313+
addFortranRuntimeLibs(ToolChain, CmdArgs);
314314
if (Profiling)
315315
CmdArgs.push_back("-lm_p");
316316
else

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
564564
// AddRunTimeLibs).
565565
if (D.IsFlangMode()) {
566566
addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
567-
addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
567+
addFortranRuntimeLibs(ToolChain, CmdArgs);
568568
CmdArgs.push_back("-lm");
569569
}
570570

clang/lib/Driver/ToolChains/Haiku.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA,
118118
// AddRunTimeLibs).
119119
if (D.IsFlangMode()) {
120120
addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
121-
addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
121+
addFortranRuntimeLibs(ToolChain, CmdArgs);
122122
}
123123

124124
CmdArgs.push_back("-lgcc");

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
131131

132132
if (C.getDriver().IsFlangMode()) {
133133
addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
134-
addFortranRuntimeLibs(TC, Args, CmdArgs);
134+
addFortranRuntimeLibs(TC, CmdArgs);
135135

136136
// Inform the MSVC linker that we're generating a console application, i.e.
137137
// one with `main` as the "user-defined" entry point. The `main` function is

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
249249

250250
if (C.getDriver().IsFlangMode()) {
251251
addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
252-
addFortranRuntimeLibs(TC, Args, CmdArgs);
252+
addFortranRuntimeLibs(TC, CmdArgs);
253253
}
254254

255255
// TODO: Add profile stuff here

clang/lib/Driver/ToolChains/NetBSD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
325325
// AddRunTimeLibs).
326326
if (D.IsFlangMode()) {
327327
addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
328-
addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
328+
addFortranRuntimeLibs(ToolChain, CmdArgs);
329329
CmdArgs.push_back("-lm");
330330
}
331331

clang/lib/Driver/ToolChains/OpenBSD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
237237
// AddRunTimeLibs).
238238
if (D.IsFlangMode()) {
239239
addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
240-
addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
240+
addFortranRuntimeLibs(ToolChain, CmdArgs);
241241
if (Profiling)
242242
CmdArgs.push_back("-lm_p");
243243
else

clang/lib/Driver/ToolChains/Solaris.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
226226
// these dependencies need to be listed before the C runtime below.
227227
if (D.IsFlangMode()) {
228228
addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
229-
addFortranRuntimeLibs(getToolChain(), Args, CmdArgs);
229+
addFortranRuntimeLibs(getToolChain(), CmdArgs);
230230
CmdArgs.push_back("-lm");
231231
}
232232
if (Args.hasArg(options::OPT_fstack_protector) ||

clang/test/CodeGen/SystemZ/align-systemz.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ void func (void)
2525
s = es;
2626
}
2727

28+
// Test that a global variable with an incomplete type gets the minimum
29+
// alignment of 2 per the ABI if no alignment was specified by user.
30+
//
31+
// CHECK-DAG: @VarNoAl {{.*}} align 2
32+
// CHECK-DAG: @VarExplAl1 {{.*}} align 1
33+
// CHECK-DAG: @VarExplAl4 {{.*}} align 4
34+
struct incomplete_ty;
35+
extern struct incomplete_ty VarNoAl;
36+
extern struct incomplete_ty __attribute__((aligned(1))) VarExplAl1;
37+
extern struct incomplete_ty __attribute__((aligned(4))) VarExplAl4;
38+
struct incomplete_ty *fun0 (void) { return &VarNoAl; }
39+
struct incomplete_ty *fun1 (void) { return &VarExplAl1; }
40+
struct incomplete_ty *fun2 (void) { return &VarExplAl4; }
2841

2942
// The SystemZ ABI aligns __int128_t to only eight bytes.
3043

clang/test/Driver/systemz-alignment.c

Lines changed: 0 additions & 32 deletions
This file was deleted.

flang/include/flang/Lower/BoxAnalyzer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
382382

383383
/// Run the analysis on `sym`.
384384
void analyze(const Fortran::semantics::Symbol &sym) {
385+
if (Fortran::semantics::IsProcedurePointer(sym))
386+
return;
385387
if (symIsArray(sym)) {
386388
bool isConstant = !isAssumedSize(sym);
387389
llvm::SmallVector<int64_t> lbounds;

flang/include/flang/Lower/CallInterface.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class CallInterface {
111111
CharBoxValueAttribute, // BoxChar with VALUE
112112
// Passing a character procedure as a <procedure address, result length>
113113
// tuple.
114-
CharProcTuple
114+
CharProcTuple,
115+
BoxProcRef
115116
};
116117
/// Different properties of an entity that can be passed/returned.
117118
/// One-to-One mapping with PassEntityBy but for
@@ -124,7 +125,8 @@ class CallInterface {
124125
CharProcTuple,
125126
Box,
126127
MutableBox,
127-
Value
128+
Value,
129+
BoxProcRef
128130
};
129131

130132
using FortranEntity = typename PassedEntityTypes<T>::FortranEntity;

flang/include/flang/Lower/ConvertProcedureDesignator.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
namespace mlir {
2121
class Location;
22+
class Value;
23+
class Type;
2224
}
2325
namespace fir {
2426
class ExtendedValue;
@@ -29,6 +31,9 @@ class EntityWithAttributes;
2931
namespace Fortran::evaluate {
3032
struct ProcedureDesignator;
3133
}
34+
namespace Fortran::semantics {
35+
class Symbol;
36+
}
3237

3338
namespace Fortran::lower {
3439
class AbstractConverter;
@@ -50,5 +55,10 @@ hlfir::EntityWithAttributes convertProcedureDesignatorToHLFIR(
5055
const Fortran::evaluate::ProcedureDesignator &proc,
5156
Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx);
5257

58+
/// Generate initialization for procedure pointer to procedure target.
59+
mlir::Value
60+
convertProcedureDesignatorInitialTarget(Fortran::lower::AbstractConverter &,
61+
mlir::Location,
62+
const Fortran::semantics::Symbol &sym);
5363
} // namespace Fortran::lower
5464
#endif // FORTRAN_LOWER_CONVERT_PROCEDURE_DESIGNATOR_H

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder,
677677
/// to keep all the lower bound and explicit parameter information.
678678
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
679679
const fir::ExtendedValue &exv);
680+
681+
/// Generate Null BoxProc for procedure pointer null initialization.
682+
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc,
683+
mlir::Type boxType);
680684
} // namespace fir::factory
681685

682686
#endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H

flang/include/flang/Optimizer/Builder/HLFIRTools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class Entity : public mlir::Value {
5858
bool isValue() const { return isFortranValue(*this); }
5959
bool isVariable() const { return !isValue(); }
6060
bool isMutableBox() const { return hlfir::isBoxAddressType(getType()); }
61+
bool isProcedurePointer() const {
62+
return hlfir::isBoxProcAddressType(getType());
63+
}
6164
bool isBoxAddressOrValue() const {
6265
return hlfir::isBoxAddressOrValueType(getType());
6366
}

flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ inline bool isBoxAddressType(mlir::Type type) {
6767
return type && type.isa<fir::BaseBoxType>();
6868
}
6969

70+
/// Is this a fir.boxproc address type?
71+
inline bool isBoxProcAddressType(mlir::Type type) {
72+
type = fir::dyn_cast_ptrEleTy(type);
73+
return type && type.isa<fir::BoxProcType>();
74+
}
75+
7076
/// Is this a fir.box or fir.class address or value type?
7177
inline bool isBoxAddressOrValueType(mlir::Type type) {
7278
return fir::unwrapRefType(type).isa<fir::BaseBoxType>();

0 commit comments

Comments
 (0)