Skip to content
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

Misc. LLVM 18 fixes #4605

Merged
merged 7 commits into from
Mar 28, 2024
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: 8 additions & 0 deletions driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ void ArgsBuilder::addLinker() {
//////////////////////////////////////////////////////////////////////////////

void ArgsBuilder::addUserSwitches() {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif

// additional linker and cc switches (preserve order across both lists)
for (unsigned ilink = 0, icc = 0;;) {
unsigned linkpos = ilink < opts::linkerSwitches.size()
Expand Down Expand Up @@ -664,6 +668,10 @@ void ArgsBuilder::addUserSwitches() {
break;
}
}

#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 8 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ void tryParse(const llvm::SmallVectorImpl<const char *> &args, size_t i,
}

bool tryParseLowmem(const llvm::SmallVectorImpl<const char *> &args) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif

bool lowmem = false;
for (size_t i = 1; i < args.size(); ++i) {
if (args::isRunArg(args[i]))
Expand All @@ -206,6 +210,10 @@ bool tryParseLowmem(const llvm::SmallVectorImpl<const char *> &args) {
}
}
return lowmem;

#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
}

const char *
Expand Down
4 changes: 4 additions & 0 deletions driver/targetmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@

#include "gen/optimizer.h"

#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif

#ifdef LDC_LLVM_SUPPORTS_MACHO_DWARF_LINE_AS_REGULAR_SECTION
// LDC-LLVM >= 6.0.1:
// On Mac, emit __debug_line section in __DWARF segment as regular (non-debug)
Expand Down
1 change: 0 additions & 1 deletion driver/toobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ using CodeGenFileType = llvm::CodeGenFileType;
#if LDC_LLVM_VER >= 1800
constexpr llvm::CodeGenFileType CGFT_AssemblyFile = CodeGenFileType::AssemblyFile;
constexpr llvm::CodeGenFileType CGFT_ObjectFile = CodeGenFileType::ObjectFile;
constexpr llvm::CodeGenFileType CGFT_Null = CodeGenFileType::Null;
#endif

#if LDC_LLVM_VER < 1700
Expand Down
8 changes: 8 additions & 0 deletions gen/asm-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class ConstraintsBuilder {
// Appends a constraint string expression with an optional prefix.
// Returns true if the string describes an indirect operand.
bool append(Expression *e, char prefix = 0) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif

auto se = e->isStringExp();
assert(se);
llvm::StringRef code = peekString(se);
Expand Down Expand Up @@ -90,6 +94,10 @@ class ConstraintsBuilder {
str << ',';

return isIndirect;

#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
}

// Might set `isIndirect` to true (but never resets to false).
Expand Down
10 changes: 10 additions & 0 deletions gen/declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ class CodegenVisitor : public Visitor {
void visit(PragmaDeclaration *decl) override {
const auto &triple = *global.params.targetTriple;

#if LDC_LLVM_VER >= 1800
#define endswith ends_with
#define startswith starts_with
#endif

if (decl->ident == Id::lib) {
assert(!irs->dcomputetarget);
llvm::StringRef name = getPragmaStringArg(decl);
Expand Down Expand Up @@ -466,6 +471,11 @@ class CodegenVisitor : public Visitor {
}
}
visit(static_cast<AttribDeclaration *>(decl));

#if LDC_LLVM_VER >= 1800
#undef endswith
#undef startswith
#endif
}

//////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 8 additions & 0 deletions gen/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ bool eraseDummyAfterReturnBB(llvm::BasicBlock *bb) {
* to be found.
*/
void emulateWeakAnyLinkageForMSVC(IrFunction *irFunc, LINK linkage) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif

LLFunction *func = irFunc->getLLVMFunc();

const bool isWin32 = global.params.targetTriple->isArch32Bit();
Expand Down Expand Up @@ -952,6 +956,10 @@ void emulateWeakAnyLinkageForMSVC(IrFunction *irFunc, LINK linkage) {
// declaration
irFunc->setLLVMFunc(newFunc);
func->replaceNonMetadataUsesWith(newFunc);

#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
}

} // anonymous namespace
Expand Down
2 changes: 1 addition & 1 deletion gen/passes/DLLImportRelocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ struct Impl {
t = st->getElementType(i);
else if (ArrayType *at = dyn_cast<ArrayType>(t))
t = at->getElementType();
else if (PointerType *pt = dyn_cast<PointerType>(t))
else if (dyn_cast<PointerType>(t))
llvm_unreachable("Shouldn't be trying to GEP a pointer in initializer");
}

Expand Down
1 change: 0 additions & 1 deletion gen/pgo_ASTbased.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ llvm::cl::opt<bool, false, opts::FlagParser<bool>> enablePGOIndirectCalls(
#if LDC_LLVM_VER >= 1800
namespace llvm::support {
const auto little = llvm::endianness::little;
const auto big = llvm::endianness::big;
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion gen/tocall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ static LLType *getPtrToAtomicType(LLType *type) {
#if LDC_LLVM_VER < 1800
return LLType::getIntNPtrTy(gIR->context(), static_cast<unsigned>(N));
#else
return LLPointerType::getIntNPtrTy(gIR->context(), static_cast<unsigned>(N));
return LLType::getIntNTy(gIR->context(), static_cast<unsigned>(N))
->getPointerTo();
#endif
default:
return nullptr;
Expand Down
8 changes: 8 additions & 0 deletions gen/uda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ void applyAttrTarget(StructLiteralExp *sle, llvm::Function *func,
// The current implementation here does not do any checking of the specified
// string and simply passes all to llvm.

#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif

checkStructElems(sle, {Type::tstring});
llvm::StringRef targetspec = getFirstElemString(sle);

Expand Down Expand Up @@ -375,6 +379,10 @@ void applyAttrTarget(StructLiteralExp *sle, llvm::Function *func,
llvm::join(features.begin(), features.end(), ","));
irFunc->targetFeaturesOverridden = true;
}

#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
}

void applyAttrAssumeUsed(IRState &irs, StructLiteralExp *sle,
Expand Down
8 changes: 8 additions & 0 deletions ir/iraggr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ bool IrAggr::useDLLImport() const {
//////////////////////////////////////////////////////////////////////////////

LLConstant *IrAggr::getInitSymbol(bool define) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif

if (!init) {
const auto irMangle = getIRMangledInitSymbolName(aggrdecl);

Expand Down Expand Up @@ -107,6 +111,10 @@ LLConstant *IrAggr::getInitSymbol(bool define) {
}

return init;

#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions tests/sanitizers/fsanitize_address.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// RUN: %ldc -c -output-ll -g -fsanitize=address,thread -of=%t.tsan.ll %s && FileCheck %s --check-prefix=wTSAN < %t.tsan.ll
// RUN: %ldc -c -output-ll -g -fsanitize=address -fsanitize=thread -of=%t.tsan.ll %s && FileCheck %s --check-prefix=wTSAN < %t.tsan.ll

void foo() {
void foo(size_t a) {
// wTSAN: call {{.*}}_tsan_func_entry
// CHECK: call {{.*}}_asan_stack_malloc
// wTSAN: {{(call|invoke)}} {{.*}}_asan_stack_malloc
int[10] i;
// CHECK: call {{.*}}_asan_report_store
// wTSAN: {{(call|invoke)}} {{.*}}_asan_report_store
i[0] = 1;
i[a] = 1;
}
3 changes: 2 additions & 1 deletion tests/sanitizers/fsanitize_fuzzer.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ bool FuzzMe(const ubyte* data, size_t dataSize)
}

// CHECK-LABEL: define{{.*}} @{{.*}}allocInt
void allocInt() {
void allocInt(size_t i) {
// wASAN: call {{.*}}_asan_stack_malloc
int[10] a;
a[i] = 1;
}

// CHECK-LABEL: define{{.*}} @{{.*}}foo
Expand Down
7 changes: 7 additions & 0 deletions tools/ldc-profdata/llvm-profdata-18.1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3269,3 +3269,10 @@ int llvm_profdata_main(int argc, char **argvNonConst,
<< ": Unknown command. Run llvm-profdata --help for usage.\n";
return 1;
}

// LDC manually added `main` function, which is generated by CMake in LLVM's build. See LLVM's llvm-driver-template.cpp.in
#include "llvm/Support/InitLLVM.h"
int main(int argc, char **argv) {
llvm::InitLLVM X(argc, argv);
return llvm_profdata_main(argc, argv, {argv[0], nullptr, false});
}
25 changes: 25 additions & 0 deletions tools/ldc-profgen/ldc-profgen-18.1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

set(LLVM_LINK_COMPONENTS
AllTargetsDescs
AllTargetsDisassemblers
AllTargetsInfos
DebugInfoDWARF
Core
MC
IPO
MCDisassembler
Object
ProfileData
Support
Symbolize
TargetParser
)

add_llvm_tool(llvm-profgen
llvm-profgen.cpp
PerfReader.cpp
CSPreInliner.cpp
ProfiledBinary.cpp
ProfileGenerator.cpp
MissingFrameInferrer.cpp
)
Loading
Loading