Misc. merge fixes (C++)

This commit is contained in:
Martin Kinkelin 2023-11-05 13:44:05 +01:00
parent 48809250d8
commit a053480010
17 changed files with 49 additions and 75 deletions

View file

@ -339,7 +339,7 @@ int createStaticLibrary() {
if (useInternalArchiver) { if (useInternalArchiver) {
const auto fullArgs = const auto fullArgs =
getFullArgs(tool.c_str(), args, global.params.verbose); getFullArgs(tool.c_str(), args, global.params.v.verbose);
const int exitCode = const int exitCode =
isTargetMSVC ? internalLib(fullArgs) : internalAr(fullArgs); isTargetMSVC ? internalLib(fullArgs) : internalAr(fullArgs);
@ -350,7 +350,7 @@ int createStaticLibrary() {
} }
// invoke external archiver // invoke external archiver
return executeToolAndWait(Loc(), tool, args, global.params.verbose); return executeToolAndWait(Loc(), tool, args, global.params.v.verbose);
} }
const char *getPathToProducedStaticLibrary() { const char *getPathToProducedStaticLibrary() {

View file

@ -85,16 +85,16 @@ cl::opt<DLLImport, true> dllimport(
"-fvisibility=public)"))); "-fvisibility=public)")));
static cl::opt<bool, true> verbose("v", cl::desc("Verbose"), cl::ZeroOrMore, static cl::opt<bool, true> verbose("v", cl::desc("Verbose"), cl::ZeroOrMore,
cl::location(global.params.verbose)); cl::location(global.params.v.verbose));
static cl::opt<bool, true> static cl::opt<bool, true>
vcolumns("vcolumns", vcolumns("vcolumns",
cl::desc("Print character (column) numbers in diagnostics"), cl::desc("Print character (column) numbers in diagnostics"),
cl::ZeroOrMore, cl::location(global.params.showColumns)); cl::ZeroOrMore, cl::location(global.params.v.showColumns));
static cl::opt<bool, true> static cl::opt<bool, true>
vgc("vgc", cl::desc("List all gc allocations including hidden ones"), vgc("vgc", cl::desc("List all gc allocations including hidden ones"),
cl::ZeroOrMore, cl::location(global.params.vgc)); cl::ZeroOrMore, cl::location(global.params.v.gc));
// Dummy data type for custom parsers where the help output shouldn't display // Dummy data type for custom parsers where the help output shouldn't display
// any value. // any value.
@ -106,14 +106,14 @@ struct VTemplatesParser : public cl::parser<DummyDataType> {
bool parse(cl::Option &O, llvm::StringRef /*ArgName*/, llvm::StringRef Arg, bool parse(cl::Option &O, llvm::StringRef /*ArgName*/, llvm::StringRef Arg,
DummyDataType & /*Val*/) { DummyDataType & /*Val*/) {
global.params.vtemplates = true; global.params.v.templates = true;
if (Arg.empty()) { if (Arg.empty()) {
return false; return false;
} }
if (Arg == "list-instances") { if (Arg == "list-instances") {
global.params.vtemplatesListInstances = true; global.params.v.templatesListInstances = true;
return false; return false;
} }
@ -136,23 +136,23 @@ static cl::opt<bool, true> verbose_cg_ast("vcg-ast", cl::ZeroOrMore, cl::Hidden,
cl::location(global.params.vcg_ast)); cl::location(global.params.vcg_ast));
static cl::opt<unsigned, true> errorLimit( static cl::opt<unsigned, true> errorLimit(
"verrors", cl::ZeroOrMore, cl::location(global.params.errorLimit), "verrors", cl::ZeroOrMore, cl::location(global.params.v.errorLimit),
cl::desc("Limit the number of error messages (0 means unlimited)")); cl::desc("Limit the number of error messages (0 means unlimited)"));
static cl::opt<bool, true> static cl::opt<bool, true>
showGaggedErrors("verrors-spec", cl::ZeroOrMore, showGaggedErrors("verrors-spec", cl::ZeroOrMore,
cl::location(global.params.showGaggedErrors), cl::location(global.params.v.showGaggedErrors),
cl::desc("Show errors from speculative compiles such as " cl::desc("Show errors from speculative compiles such as "
"__traits(compiles,...)")); "__traits(compiles,...)"));
static cl::opt<bool, true> printErrorContext( static cl::opt<bool, true> printErrorContext(
"verrors-context", cl::ZeroOrMore, "verrors-context", cl::ZeroOrMore,
cl::location(global.params.printErrorContext), cl::location(global.params.v.printErrorContext),
cl::desc( cl::desc(
"Show error messages with the context of the erroring source line")); "Show error messages with the context of the erroring source line"));
static cl::opt<MessageStyle, true> verrorStyle( static cl::opt<MessageStyle, true> verrorStyle(
"verror-style", cl::ZeroOrMore, cl::location(global.params.messageStyle), "verror-style", cl::ZeroOrMore, cl::location(global.params.v.messageStyle),
cl::desc( cl::desc(
"Set the style for file/line number annotations on compiler messages"), "Set the style for file/line number annotations on compiler messages"),
cl::values( cl::values(
@ -165,7 +165,7 @@ static cl::opt<MessageStyle, true> verrorStyle(
static cl::opt<unsigned, true> static cl::opt<unsigned, true>
verrorSupplements("verror-supplements", cl::ZeroOrMore, verrorSupplements("verror-supplements", cl::ZeroOrMore,
cl::location(global.params.errorSupplementLimit), cl::location(global.params.v.errorSupplementLimit),
cl::desc("Limit the number of supplemental messages for " cl::desc("Limit the number of supplemental messages for "
"each error (0 means unlimited)")); "each error (0 means unlimited)"));
@ -178,10 +178,6 @@ static cl::opt<Diagnostic, true> warnings(
"Enable warnings as messages (compilation will continue)")), "Enable warnings as messages (compilation will continue)")),
cl::init(DIAGNOSTICoff)); cl::init(DIAGNOSTICoff));
static cl::opt<bool, true> warningsObsolete(
"wo", cl::ZeroOrMore, cl::location(global.params.obsolete),
cl::desc("Enable warnings about use of obsolete features"));
static cl::opt<bool, true> ignoreUnsupportedPragmas( static cl::opt<bool, true> ignoreUnsupportedPragmas(
"ignore", cl::desc("Ignore unsupported pragmas"), cl::ZeroOrMore, "ignore", cl::desc("Ignore unsupported pragmas"), cl::ZeroOrMore,
cl::location(global.params.ignoreUnsupportedPragmas)); cl::location(global.params.ignoreUnsupportedPragmas));
@ -760,7 +756,7 @@ void createClashingOptions() {
// Step 2. Add the LDC options. // Step 2. Add the LDC options.
new cl::opt<bool, true, FlagParser<bool>>( new cl::opt<bool, true, FlagParser<bool>>(
"color", cl::ZeroOrMore, cl::location(global.params.color), "color", cl::ZeroOrMore, cl::location(global.params.v.color),
cl::desc("(*) Force colored console output")); cl::desc("(*) Force colored console output"));
new cl::opt<bool, true>("ffast-math", cl::ZeroOrMore, cl::location(fFastMath), new cl::opt<bool, true>("ffast-math", cl::ZeroOrMore, cl::location(fFastMath),
cl::desc("Set @fastmath for all functions.")); cl::desc("Set @fastmath for all functions."));

View file

@ -144,7 +144,7 @@ FileName runCPreprocessor(FileName csrcfile, const Loc &loc, bool &ifile,
args.push_back(ipath.toChars()); args.push_back(ipath.toChars());
} }
const int status = executeToolAndWait(loc, cc, args, global.params.verbose); const int status = executeToolAndWait(loc, cc, args, global.params.v.verbose);
if (status) { if (status) {
errorSupplemental(loc, "C preprocessor failed for file '%s'", csrcfile.toChars()); errorSupplemental(loc, "C preprocessor failed for file '%s'", csrcfile.toChars());
fatal(); fatal();

View file

@ -594,12 +594,7 @@ void translateArgs(const llvm::SmallVectorImpl<const char *> &ldmdArgs,
* -revert * -revert
* -w * -w
* -wi * -wi
*/ * -O
else if (strcmp(p + 1, "wo") == 0) {
ldcArgs.push_back("-wo");
ldcArgs.push_back("-wi"); // DMD overrides a previous `-w` to `-wi`; LDC doesn't
}
/* -O
* -o- * -o-
* -od * -od
* -of * -of

View file

@ -756,7 +756,7 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
argsBuilder.build(outputPath, defaultLibNames); argsBuilder.build(outputPath, defaultLibNames);
const auto fullArgs = const auto fullArgs =
getFullArgs("lld", argsBuilder.args, global.params.verbose); getFullArgs("lld", argsBuilder.args, global.params.v.verbose);
// CanExitEarly == true means that LLD can and will call `exit()` when // CanExitEarly == true means that LLD can and will call `exit()` when
// errors occur. // errors occur.
@ -861,5 +861,5 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
// try to call linker // try to call linker
return executeToolAndWait(Loc(), tool, argsBuilder->args, return executeToolAndWait(Loc(), tool, argsBuilder->args,
global.params.verbose); global.params.v.verbose);
} }

View file

@ -268,7 +268,8 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
#if LDC_WITH_LLD #if LDC_WITH_LLD
if (useInternalLLDForLinking() || if (useInternalLLDForLinking() ||
(useInternalToolchain && opts::linker.empty())) { (useInternalToolchain && opts::linker.empty())) {
const auto fullArgs = getFullArgs("lld-link", args, global.params.verbose); const auto fullArgs =
getFullArgs("lld-link", args, global.params.v.verbose);
const bool canExitEarly = false; const bool canExitEarly = false;
const bool success = lld::coff::link(fullArgs const bool success = lld::coff::link(fullArgs
@ -302,5 +303,5 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
#endif #endif
} }
return executeToolAndWait(Loc(), linker, args, global.params.verbose); return executeToolAndWait(Loc(), linker, args, global.params.v.verbose);
} }

View file

@ -326,8 +326,8 @@ int runProgram() {
assert(!gExePath.empty()); assert(!gExePath.empty());
// Run executable // Run executable
int status = int status = executeToolAndWait(Loc(), gExePath, opts::runargs,
executeToolAndWait(Loc(), gExePath, opts::runargs, global.params.verbose); global.params.v.verbose);
if (status < 0) { if (status < 0) {
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
error(Loc(), "program received signal %d", -status); error(Loc(), "program received signal %d", -status);

View file

@ -139,8 +139,9 @@ void printVersion(llvm::raw_ostream &OS) {
} }
// Helper function to handle -d-debug=* and -d-version=* // Helper function to handle -d-debug=* and -d-version=*
void processVersions(std::vector<std::string> &list, const char *type, template <typename Condition>
unsigned &globalLevel, Strings *&globalIDs) { void processVersions(const std::vector<std::string> &list, const char *type,
unsigned &globalLevel) {
for (const auto &i : list) { for (const auto &i : list) {
const char *value = i.c_str(); const char *value = i.c_str();
if (isdigit(value[0])) { if (isdigit(value[0])) {
@ -155,12 +156,9 @@ void processVersions(std::vector<std::string> &list, const char *type,
} else { } else {
char *cstr = mem.xstrdup(value); char *cstr = mem.xstrdup(value);
if (Identifier::isValidIdentifier(cstr)) { if (Identifier::isValidIdentifier(cstr)) {
if (!globalIDs) Condition::addGlobalIdent(cstr);
globalIDs = createStrings();
globalIDs->push(cstr);
continue;
} else { } else {
error(Loc(), "Invalid %s identifier or level: '%s'", type, i.c_str()); error(Loc(), "Invalid %s identifier or level: '%s'", type, cstr);
} }
} }
} }
@ -324,7 +322,7 @@ void parseCommandLine(Strings &sourceFiles) {
// - path to compiler binary // - path to compiler binary
// - version number // - version number
// - used config file // - used config file
if (global.params.verbose) { if (global.params.v.verbose) {
message("binary %s", exe_path::getExePath().c_str()); message("binary %s", exe_path::getExePath().c_str());
message("version %s (DMD %s, LLVM %s)", ldc::ldc_version, message("version %s (DMD %s, LLVM %s)", ldc::ldc_version,
ldc::dmd_version, ldc::llvm_version); ldc::dmd_version, ldc::llvm_version);
@ -416,10 +414,9 @@ void parseCommandLine(Strings &sourceFiles) {
opts::initializeSanitizerOptionsFromCmdline(); opts::initializeSanitizerOptionsFromCmdline();
processVersions(debugArgs, "debug", global.params.debuglevel, processVersions<DebugCondition>(debugArgs, "debug", global.params.debuglevel);
global.params.debugids); processVersions<VersionCondition>(versions, "version",
processVersions(versions, "version", global.params.versionlevel, global.params.versionlevel);
global.params.versionids);
for (const auto &id : transitions) for (const auto &id : transitions)
parseTransitionOption(global.params, id.c_str()); parseTransitionOption(global.params, id.c_str());
@ -449,11 +446,6 @@ void parseCommandLine(Strings &sourceFiles) {
global.params.allInst = true; global.params.allInst = true;
} }
// -wo implies at least -wi (print the warnings)
if (global.params.obsolete && global.params.warnings == DIAGNOSTICoff) {
global.params.warnings = DIAGNOSTICinform;
}
global.params.output_o = global.params.output_o =
(opts::output_o == cl::BOU_UNSET && (opts::output_o == cl::BOU_UNSET &&
!(opts::output_bc || opts::output_ll || opts::output_s || !(opts::output_bc || opts::output_ll || opts::output_s ||
@ -1136,8 +1128,6 @@ int cppmain() {
global.compileEnv.previewIn = global.params.previewIn; global.compileEnv.previewIn = global.params.previewIn;
global.compileEnv.ddocOutput = global.params.ddoc.doOutput; global.compileEnv.ddocOutput = global.params.ddoc.doOutput;
global.compileEnv.shortenedMethods = global.params.shortenedMethods;
global.compileEnv.obsolete = global.params.obsolete;
if (opts::fTimeTrace) { if (opts::fTimeTrace) {
initializeTimeTrace(opts::fTimeTraceGranularity, 0, opts::allArguments[0]); initializeTimeTrace(opts::fTimeTraceGranularity, 0, opts::allArguments[0]);
@ -1268,7 +1258,7 @@ void codegenModules(Modules &modules) {
if (m->filetype == FileType::dhdr) if (m->filetype == FileType::dhdr)
continue; continue;
if (global.params.verbose) if (global.params.v.verbose)
message("code %s", m->toChars()); message("code %s", m->toChars());
const auto atCompute = hasComputeAttr(m); const auto atCompute = hasComputeAttr(m);

View file

@ -148,7 +148,7 @@ static void assemble(const std::string &asmpath, const std::string &objpath) {
appendTargetArgsForGcc(args); appendTargetArgsForGcc(args);
// Run the compiler to assembly the program. // Run the compiler to assembly the program.
int R = executeToolAndWait(Loc(), getGcc(), args, global.params.verbose); int R = executeToolAndWait(Loc(), getGcc(), args, global.params.v.verbose);
if (R) { if (R) {
error(Loc(), "Error while invoking external assembler."); error(Loc(), "Error while invoking external assembler.");
fatal(); fatal();

View file

@ -330,7 +330,7 @@ bool setupMsvcEnvironmentImpl(
if (!rollback) // check for availability only if (!rollback) // check for availability only
return true; return true;
if (global.params.verbose) if (global.params.v.verbose)
message("Prepending to environment variables:"); message("Prepending to environment variables:");
const auto prependToEnvVar = const auto prependToEnvVar =
@ -348,7 +348,7 @@ bool setupMsvcEnvironmentImpl(
head += entry; head += entry;
} }
if (global.params.verbose) if (global.params.v.verbose)
message(" %s += %.*s", key, (int)head.size(), head.data()); message(" %s += %.*s", key, (int)head.size(), head.data());
llvm::SmallVector<wchar_t, 1024> wvalue; llvm::SmallVector<wchar_t, 1024> wvalue;
@ -372,7 +372,7 @@ bool setupMsvcEnvironmentImpl(
prependToEnvVar("LIB", L"LIB", libPaths); prependToEnvVar("LIB", L"LIB", libPaths);
prependToEnvVar("PATH", L"PATH", binPaths); prependToEnvVar("PATH", L"PATH", binPaths);
if (global.params.verbose) { if (global.params.v.verbose) {
const auto end = std::chrono::steady_clock::now(); const auto end = std::chrono::steady_clock::now();
message("MSVC setup took %lld microseconds", message("MSVC setup took %lld microseconds",
std::chrono::duration_cast<std::chrono::microseconds>(end - begin) std::chrono::duration_cast<std::chrono::microseconds>(end - begin)

View file

@ -3234,7 +3234,7 @@ struct AsmProcessor {
if (isIntExp(e1) && (!e2 || isIntExp(e2))) { if (isIntExp(e1) && (!e2 || isIntExp(e2))) {
Expression *e = createExpressionForIntOp(stmt->loc, op, e1, e2); Expression *e = createExpressionForIntOp(stmt->loc, op, e1, e2);
e = expressionSemantic(e, sc); e = expressionSemantic(e, sc);
return e->ctfeInterpret(); return ctfeInterpret(e);
} }
stmt->error("expected integer operand(s) for `%s`", Token::toChars(op)); stmt->error("expected integer operand(s) for `%s`", Token::toChars(op));
@ -3793,7 +3793,7 @@ struct AsmProcessor {
// parse primary: DMD allows 'MyAlign' (const int) but not '2+2' // parse primary: DMD allows 'MyAlign' (const int) but not '2+2'
// GAS is padding with NOPs last time I checked. // GAS is padding with NOPs last time I checked.
Expression *e = parseAsmExp()->ctfeInterpret(); Expression *e = ctfeInterpret(parseAsmExp());
uinteger_t align = e->toUInteger(); uinteger_t align = e->toUInteger();
if ((align & (align - 1)) == 0) { if ((align & (align - 1)) == 0) {

View file

@ -114,10 +114,4 @@ void print(const char *fmt, ...) {
va_end(va); va_end(va);
} }
} }
void attention(const Loc &loc, const char *fmt, ...) {
va_list va;
va_start(va, fmt);
vwarning(loc, fmt, va);
va_end(va);
}
} }

View file

@ -105,8 +105,6 @@ inline void enable() { _Logger_enabled = true; }
inline void disable() { _Logger_enabled = false; } inline void disable() { _Logger_enabled = false; }
inline bool enabled() { return _Logger_enabled; } inline bool enabled() { return _Logger_enabled; }
void attention(Loc loc, const char *fmt, ...) IS_PRINTF(2);
struct LoggerScope { struct LoggerScope {
LoggerScope() { Logger::indent(); } LoggerScope() { Logger::indent(); }
~LoggerScope() { Logger::undent(); } ~LoggerScope() { Logger::undent(); }

View file

@ -250,7 +250,7 @@ struct LazyFunctionDeclarer {
StorageClass stc = paramsSTC.empty() ? 0 : paramsSTC[i]; StorageClass stc = paramsSTC.empty() ? 0 : paramsSTC[i];
Type *paramTy = paramTypes[i].get(loc); Type *paramTy = paramTypes[i].get(loc);
params->push( params->push(
Parameter::create(stc, paramTy, nullptr, nullptr, nullptr)); Parameter::create(Loc(), stc, paramTy, nullptr, nullptr, nullptr));
} }
} }
Type *returnTy = returnType.get(loc); Type *returnTy = returnType.get(loc);
@ -454,7 +454,8 @@ static Type *rt_dg1() {
return dg_t; return dg_t;
auto params = createParameters(); auto params = createParameters();
params->push(Parameter::create(0, Type::tvoidptr, nullptr, nullptr, nullptr)); params->push(
Parameter::create(Loc(), 0, Type::tvoidptr, nullptr, nullptr, nullptr));
auto fty = TypeFunction::create(params, Type::tint32, VARARGnone, LINK::d); auto fty = TypeFunction::create(params, Type::tint32, VARARGnone, LINK::d);
dg_t = TypeDelegate::create(fty); dg_t = TypeDelegate::create(fty);
return dg_t; return dg_t;
@ -467,8 +468,10 @@ static Type *rt_dg2() {
return dg2_t; return dg2_t;
auto params = createParameters(); auto params = createParameters();
params->push(Parameter::create(0, Type::tvoidptr, nullptr, nullptr, nullptr)); params->push(
params->push(Parameter::create(0, Type::tvoidptr, nullptr, nullptr, nullptr)); Parameter::create(Loc(), 0, Type::tvoidptr, nullptr, nullptr, nullptr));
params->push(
Parameter::create(Loc(), 0, Type::tvoidptr, nullptr, nullptr, nullptr));
auto fty = TypeFunction::create(params, Type::tint32, VARARGnone, LINK::d); auto fty = TypeFunction::create(params, Type::tint32, VARARGnone, LINK::d);
dg2_t = TypeDelegate::create(fty); dg2_t = TypeDelegate::create(fty);
return dg2_t; return dg2_t;

View file

@ -36,6 +36,7 @@
#include "dmd/mtype.h" #include "dmd/mtype.h"
#include "dmd/scope.h" #include "dmd/scope.h"
#include "dmd/template.h" #include "dmd/template.h"
#include "dmd/typinf.h"
#include "gen/arrays.h" #include "gen/arrays.h"
#include "gen/classes.h" #include "gen/classes.h"
#include "gen/irstate.h" #include "gen/irstate.h"
@ -57,16 +58,12 @@
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
// in dmd/typinf.d:
void genTypeInfo(Expression *e, const Loc &loc, Type *torig, Scope *sc, bool genObjCode = true);
TypeInfoDeclaration *getOrCreateTypeInfoDeclaration(const Loc &loc, Type *forType) { TypeInfoDeclaration *getOrCreateTypeInfoDeclaration(const Loc &loc, Type *forType) {
IF_LOG Logger::println("getOrCreateTypeInfoDeclaration(): %s", IF_LOG Logger::println("getOrCreateTypeInfoDeclaration(): %s",
forType->toChars()); forType->toChars());
LOG_SCOPE LOG_SCOPE
// the `genObjCode` parameter is unused by LDC genTypeInfo(nullptr, loc, forType, nullptr);
genTypeInfo(nullptr, loc, forType, nullptr, false);
return forType->vtinfo; return forType->vtinfo;
} }

View file

@ -48,7 +48,7 @@ StructLiteralExp *getLdcAttributesStruct(Expression *attr) {
// attributes are struct literals that may be constructed using a CTFE // attributes are struct literals that may be constructed using a CTFE
// function. // function.
unsigned prevErrors = global.startGagging(); unsigned prevErrors = global.startGagging();
auto e = attr->ctfeInterpret(); auto e = ctfeInterpret(attr);
if (global.endGagging(prevErrors)) { if (global.endGagging(prevErrors)) {
return nullptr; return nullptr;
} }

View file

@ -128,7 +128,7 @@ void IrGlobal::define() {
Logger::println("Defining global: %s", V->toChars()); Logger::println("Defining global: %s", V->toChars());
LOG_SCOPE LOG_SCOPE
if (global.params.vtls && V->isThreadlocal() && if (global.params.v.tls && V->isThreadlocal() &&
!(V->storage_class & STCtemp)) { !(V->storage_class & STCtemp)) {
message("%s: `%s` is thread local", V->loc.toChars(), V->toChars()); message("%s: `%s` is thread local", V->loc.toChars(), V->toChars());
} }