Skip to content
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
9 changes: 6 additions & 3 deletions gen/asmstmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,13 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState *p) {

// we use a simple static counter to make sure the new end labels are
// unique
static size_t uniqueLabelsId = 0;
std::ostringstream asmGotoEndLabel;
printLabelName(asmGotoEndLabel, fdmangle, "_llvm_asm_end");
asmGotoEndLabel << uniqueLabelsId++;
{
static size_t uniqueLabelsId = 0;
std::string suffix = "_llvm_asm_end";
suffix += std::to_string(uniqueLabelsId++);
printLabelName(asmGotoEndLabel, fdmangle, suffix.c_str());
}

// initialize the setter statement we're going to build
auto outSetterStmt = new IRAsmStmt;
Expand Down
6 changes: 4 additions & 2 deletions gen/llvmhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,8 +1372,10 @@ bool isLLVMUnsigned(Type *t) {

void printLabelName(std::ostream &target, const char *func_mangle,
const char *label_name) {
target << gTargetMachine->getMCAsmInfo()->getPrivateGlobalPrefix().str()
<< func_mangle << "_" << label_name;
// note: quotes needed for Unicode
target << '"'
<< gTargetMachine->getMCAsmInfo()->getPrivateGlobalPrefix().str()
<< func_mangle << "_" << label_name << '"';
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion runtime/druntime/src/core/internal/array/construction.d
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ T[] _d_newarrayU(T)(size_t length, bool isShared=false) @trusted
if (length == 0 || elemSize == 0)
return null;

/+ LDC: don't blind the optimizer; core.checkedint.mulu is basically an intrinsic
version (D_InlineAsm_X86)
{
asm pure nothrow @nogc
Expand All @@ -379,7 +380,7 @@ T[] _d_newarrayU(T)(size_t length, bool isShared=false) @trusted
jnc Lcontinue ;
}
}
else
else+/
{
import core.checkedint : mulu;

Expand Down
53 changes: 53 additions & 0 deletions tests/compilable/gh4927.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %ldc -c %s

alias T = int;

T[] arrayAlloc(size_t size);

T[] Σ(size_t length)
{
size_t elemSize = T.sizeof;
size_t arraySize;

if (length == 0 || elemSize == 0)
return null;

version (D_InlineAsm_X86)
{
asm pure nothrow @nogc
{
mov EAX, elemSize ;
mul EAX, length ;
mov arraySize, EAX ;
jnc Lcontinue ;
}
}
else version (D_InlineAsm_X86_64)
{
asm pure nothrow @nogc
{
mov RAX, elemSize ;
mul RAX, length ;
mov arraySize, RAX ;
jnc Lcontinue ;
}
}
else
{
import core.checkedint : mulu;

bool overflow = false;
arraySize = mulu(elemSize, length, overflow);
if (!overflow)
goto Lcontinue;
}

Loverflow:
assert(0);

Lcontinue:
auto arr = arrayAlloc(arraySize);
if (!arr.ptr)
goto Loverflow;
return arr;
}