./ldc-1.28.0-src/0000755000175000017500000000000014141774371013505 5ustar matthiasmatthias./ldc-1.28.0-src/tests/0000755000175000017500000000000014141774365014652 5ustar matthiasmatthias./ldc-1.28.0-src/tests/compilable/0000755000175000017500000000000014141774365016761 5ustar matthiasmatthias./ldc-1.28.0-src/tests/compilable/gh2849.d0000644000175000017500000000020314141774365020046 0ustar matthiasmatthias// RUN: %ldc -c %s extern(C++): __gshared const int dblreg = 1; pragma(mangle, dblreg.mangleof) extern __gshared const int bla; ./ldc-1.28.0-src/tests/compilable/no-integrated-as.d0000644000175000017500000000041514141774365022267 0ustar matthiasmatthias// RUN: %ldc -no-integrated-as %s // We currently rely on gcc/clang; no MSVC toolchain support yet. // UNSUPPORTED: Windows module noIntegratedAs; void main() { import std.stdio; writeln("This object is assembled externally and linked to an executable."); } ./ldc-1.28.0-src/tests/compilable/gh2859.d0000644000175000017500000000014714141774365020056 0ustar matthiasmatthias// RUN: %ldc -c %s void foo() { static struct S { int a; } S s; const aa = [1 : &s.a]; } ./ldc-1.28.0-src/tests/compilable/gh3250.d0000644000175000017500000000015614141774365020040 0ustar matthiasmatthias// RUN: %ldc -c %s struct Q { auto func(uint[3] a, uint[3] b, uint c) { return this; } } ./ldc-1.28.0-src/tests/compilable/gh2777.d0000644000175000017500000000015214141774365020051 0ustar matthiasmatthias// RUN: %ldc -c -singleobj %s %S/inputs/gh2777b.d int main(string[] args); void reset() { main(null); } ./ldc-1.28.0-src/tests/compilable/gh1741.d0000644000175000017500000000030514141774365020037 0ustar matthiasmatthias// Explicitly target Linux x86_64. // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-pc-linux-gnu -c %s %S/inputs/gh1741b.d struct S { C c; } class C { @property s() { return S(); } } ./ldc-1.28.0-src/tests/compilable/gh3162.d0000644000175000017500000000026314141774365020041 0ustar matthiasmatthias// RUN: %ldc -run %s shared struct Queue { int[int] map; } void main() { auto queue = Queue(); ( cast(int[int]) queue.map )[1] = 2; assert(queue.map[1] == 2); } ./ldc-1.28.0-src/tests/compilable/gh3243.d0000644000175000017500000000011714141774365020037 0ustar matthiasmatthias// RUN: %ldc -c %s %S/inputs/foo/bla.di %S/inputs/bar/bla.di import foo, bar; ./ldc-1.28.0-src/tests/compilable/objc_gh2388.d0000644000175000017500000000031414141774365021044 0ustar matthiasmatthias// REQUIRES: Darwin // RUN: %ldc -c -singleobj %s %S/objc_gh2387.d void alloc() { NSObject o; o.alloc(); } extern (Objective-C): interface NSObject { NSObject alloc() @selector("alloc"); } ./ldc-1.28.0-src/tests/compilable/gh2988.d0000644000175000017500000000027314141774365020061 0ustar matthiasmatthias// RUN: %ldc -c %s import core.simd; float4 getVector() { return float4(1.0f); } void foo() { // front-end implicitly casts from float4 to float[4] float x = getVector()[0]; } ./ldc-1.28.0-src/tests/compilable/ctfe_math.d0000644000175000017500000000453214141774365021064 0ustar matthiasmatthias// Tests CTFE-ability of some common std.math functions. // RUN: %ldc -c %s import std.math; mixin template Func1(string name) { enum r = mixin(name ~ "(0.5L)"); pragma(msg, name ~ "(0.5L) = " ~ r.stringof); enum d = mixin(name ~ "(0.5)"); pragma(msg, name ~ "(0.5) = " ~ d.stringof); enum f = mixin(name ~ "(0.5f)"); pragma(msg, name ~ "(0.5f) = " ~ f.stringof); } mixin template Func2(string name) { enum r = mixin(name ~ "(0.5L, -2.5L)"); pragma(msg, name ~ "(0.5L, -2.5L) = " ~ r.stringof); enum d = mixin(name ~ "(0.5, -2.5)"); pragma(msg, name ~ "(0.5, -2.5) = " ~ d.stringof); enum f = mixin(name ~ "(0.5f, -2.5f)"); pragma(msg, name ~ "(0.5f, -2.5f) = " ~ f.stringof); } mixin template Func2_int(string name) { enum r = mixin(name ~ "(0.5L, 2)"); pragma(msg, name ~ "(0.5L, 2) = " ~ r.stringof); enum d = mixin(name ~ "(0.5, 2)"); pragma(msg, name ~ "(0.5, 2) = " ~ d.stringof); enum f = mixin(name ~ "(0.5f, 2)"); pragma(msg, name ~ "(0.5f, 2) = " ~ f.stringof); } mixin template Func3(string name) { enum r = mixin(name ~ "(0.5L, -2.5L, 6.25L)"); pragma(msg, name ~ "(0.5L, -2.5L, 6.25L) = " ~ r.stringof); enum d = mixin(name ~ "(0.5, -2.5, 6.25)"); pragma(msg, name ~ "(0.5, -2.5, 6.25) = " ~ d.stringof); enum f = mixin(name ~ "(0.5f, -2.5f, 6.25f)"); pragma(msg, name ~ "(0.5f, -2.5f, 6.25f) = " ~ f.stringof); } void main() { { mixin Func1!"isNaN"; } { mixin Func1!"isInfinity"; } { mixin Func1!"isFinite"; } { mixin Func1!"abs"; } { mixin Func1!"fabs"; } { mixin Func1!"sqrt"; } { mixin Func1!"sin"; } { mixin Func1!"cos"; } { mixin Func1!"tan"; } { mixin Func1!"cosh"; } { mixin Func1!"asinh"; } { mixin Func1!"acosh"; } { mixin Func1!"atanh"; } { mixin Func1!"ceil"; } { mixin Func1!"floor"; } { mixin Func1!"round"; } { mixin Func1!"trunc"; } { mixin Func1!"rint"; } { mixin Func1!"nearbyint"; } { mixin Func1!"exp"; } { mixin Func1!"exp2"; } { mixin Func2_int!"ldexp"; } { mixin Func1!"log"; } { mixin Func1!"log2"; } { mixin Func1!"log10"; } { mixin Func2!"pow"; } { mixin Func2_int!"pow"; } { mixin Func2!"fmin"; } { mixin Func2!"fmax"; } { mixin Func2!"copysign"; } { mixin Func3!"fma"; } static assert(2.0 ^^ 8 == 256.0); } ./ldc-1.28.0-src/tests/compilable/gh3496.d0000644000175000017500000000023714141774365020054 0ustar matthiasmatthias// RUN: %ldc -c %s interface I { static void staticFoo(); final void finalFoo(); } void foo() { I.staticFoo(); (new class I{}).finalFoo(); } ./ldc-1.28.0-src/tests/compilable/gh3324.d0000644000175000017500000000015714141774365020043 0ustar matthiasmatthias// RUN: %ldc -c %s extern (C++) interface I { extern (System) void func(); } void foo(I i) { i.func(); } ./ldc-1.28.0-src/tests/compilable/gh1906.d0000644000175000017500000000010314141774365020036 0ustar matthiasmatthias// RUN: %ldc -c -I%S/inputs %s import gh1906b; class C : Base {} ./ldc-1.28.0-src/tests/compilable/gh3194.d0000644000175000017500000000017214141774365020045 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -c %s import ldc.gccbuiltins_x86; // should be importable by non-installed compiler ./ldc-1.28.0-src/tests/compilable/gh2458.d0000644000175000017500000000045014141774365020046 0ustar matthiasmatthias// Make sure llvm_expect() is supported during CTFE. // RUN: %ldc -c %s import ldc.intrinsics : llvm_expect; int notZero(int x) { if (llvm_expect(x == 0, false)) return 666; return x; } void main() { static assert(notZero(0) == 666); static assert(notZero(1) == 1); } ./ldc-1.28.0-src/tests/compilable/gh1933.d0000644000175000017500000000212114141774365020040 0ustar matthiasmatthias// See Github issue 1933. // RUN: %ldc -c -release -g -O0 %s // RUN: %ldc -c -release -g -O3 %s ptrdiff_t countUntil(T, N)(T haystack, N needle) { ptrdiff_t result; foreach (elem; haystack) { if (elem == needle) return result; result++; } return -1; } bool foo(alias pred, N)(N haystack) { foreach (elem; haystack) { if (pred(elem)) return true; } return false; } struct MatchTree { struct Tag { } struct Terminal { string[] varNames; } Tag[] m_terminalTags; Terminal term; void rebuildGraph() { MatchGraphBuilder builder; uint process() { auto aaa = m_terminalTags.length; foreach (t; builder.m_nodes) { auto bbb = term.varNames.countUntil(t.var); assert(m_terminalTags.foo!(u => t.index)); } return 0; } } } struct MatchGraphBuilder { struct TerminalTag { size_t index; string var; } TerminalTag[] m_nodes; } ./ldc-1.28.0-src/tests/compilable/gh2033.d0000644000175000017500000000057214141774365020040 0ustar matthiasmatthias// RUN: %ldc -c %s void foo(const(uint)[4] arg) { // The front-end coerces the explicit and following implicit cast // (implicit: int[4] -> const(int[4])) into a single CastExp with // differing types CastExp::to and CastExp::type. // Make sure the repainting code performing the implicit cast // handles static arrays. const copy = cast(int[4]) arg; } ./ldc-1.28.0-src/tests/compilable/gh2415.d0000644000175000017500000000034714141774365020044 0ustar matthiasmatthias// RUN: %ldc -c %s struct Row { float val; ref float opIndex(int i) { return val; } } struct Matrix { Row row; ref Row opIndex(int i) { return row; } } void main() { Matrix matrix; matrix[1][2] += 0.0; } ./ldc-1.28.0-src/tests/compilable/gh2932.d0000644000175000017500000000062614141774365020050 0ustar matthiasmatthias// RUN: %ldc -c -allinst %s import std.algorithm; extern __gshared int[] array; void funcWithNoFrame() { int local; // lambda is codegen'd pragma(msg, typeof(array.map!(e => local))); } void funcWithFrame() { int capturedVar, local; int nestedFunc() { return capturedVar; } // lambda is codegen'd with `-allinst` static assert(__traits(compiles, array.map!(e => local))); } ./ldc-1.28.0-src/tests/compilable/objc_gh2387.d0000644000175000017500000000030114141774365021037 0ustar matthiasmatthias// REQUIRES: Darwin // RUN: %ldc -c %s extern (Objective-C) interface NSView { void setWantsLayer(bool value) @selector("setWantsLayer:"); } void foo(NSView v) { v.setWantsLayer(true); } ./ldc-1.28.0-src/tests/compilable/captured_nonpassed_params.d0000644000175000017500000000107314141774365024353 0ustar matthiasmatthias// Some ABIs don't pass empty static arrays or empty PODs as arguments. // This can get hairy, e.g., if such a parameter is captured. // RUN: %ldc -c -g %s struct EmptyPOD {} EmptyPOD emptyPOD(EmptyPOD e) { EmptyPOD nested() { return e; } nested(); return e; } int[0] emptySArray(int[0] a) { int[0] nested() { return a; } nested(); return a; } void tuple() { auto test(T...)(T params) { auto nested() { return params[0]; } nested(); return params[0]; } test(EmptyPOD()); int[0] a; test(a); } ./ldc-1.28.0-src/tests/compilable/gh2996.d0000644000175000017500000000047114141774365020060 0ustar matthiasmatthias// RUN: %ldc -c %s struct Table { RCArray _elems; void update(int x) { auto e = _elems[0 .. x][x == 0 ? x : $]; } } struct RCArray { int[] _arr; inout opSlice(size_t, size_t) { return _arr; } const length() { return _arr.length; } const opDollar() { return length; } } ./ldc-1.28.0-src/tests/compilable/gh2422.d0000644000175000017500000000013414141774365020034 0ustar matthiasmatthias// RUN: %ldc -c -I%S/inputs %s import gh2422a; void main() { auto aa = ["": new Empty]; } ./ldc-1.28.0-src/tests/compilable/arch64bit_abi32bit_gh3802.d0000644000175000017500000000153214141774365023367 0ustar matthiasmatthias// Tests compilation for 64-bit architecture with 32-bit word size ABI. // Triple examples: mips64el-linux-gnuabin32, x86_64-linux-gnux32 // Targeting x86 because that's the most widely available target in our CI/developer systems. // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux-gnux32 -O -c %s static assert((void*).sizeof == 4); static assert(size_t.sizeof == 4); static assert(ptrdiff_t.sizeof == 4); version (D_LP64) static assert(0); version (D_X32) { /* expected */ } else static assert(0); bool equals(string lhs, string rhs) { foreach (const i; 0 .. lhs.length) {} return false; } // test _d_array_slice_copy optimization IR pass (requires -O) auto test_ArraySliceCopyOpt() { static void copy(int[] a, int[] b) { a[] = b[]; } int[2] a = [1, 2]; int[2] b = [3, 4]; copy(a, b); return a; } ./ldc-1.28.0-src/tests/compilable/dcompute.d0000644000175000017500000000216514141774365020752 0ustar matthiasmatthias// Tests that // - we don't try to link with one file on the commandline that is @compute // - turning on debugging doesn't ICE // - don't analyse uninstantiated templates // - typeid generated for hashing of struct (typeid(const(T))) is ignored and does not error // - if (__ctfe) and if (!__ctfe) don't cause errors // REQUIRES: target_NVPTX // RUN: %ldc -mdcompute-targets=cuda-350 -g %s @compute(CompileFor.deviceOnly) module dcompute; import ldc.dcompute; @kernel void foo() { if (__ctfe) { auto a = new int; } if (__ctfe) { auto a = new int; } else {} if (!__ctfe) { } else { auto a = new int; } } struct AutoIndexed(T) { T p = void; alias U = typeof(*T); @property U index() { return p[0]; } @property void index(U t) { p[0] = t; } @disable this(); void opAssign(U u) { index = u; } alias index this; } alias aagf = AutoIndexed!(GlobalPointer!(float)); @kernel void auto_index_test(aagf a, aagf b, aagf c) { a = b + c; } ./ldc-1.28.0-src/tests/compilable/gh2808.d0000644000175000017500000000057114141774365020051 0ustar matthiasmatthias// RUN: %ldc -c %s void gh2808() { extern(C) void DoubleArrayToAnyArray(void* arg0) { auto dg = () => { auto r = arg0; }; } auto local = 123; auto arg = () { return local; }(); DoubleArrayToAnyArray(null); } void gh3234() { int i; void nested() { ++i; } extern (C++) class Visitor { void visit() { nested(); } } } ./ldc-1.28.0-src/tests/compilable/gh2471.d0000644000175000017500000000126614141774365020047 0ustar matthiasmatthias// RUN: %ldc -c %s struct Iterator(T : T[]) { alias ThisType = Iterator!(T[]); alias ItemType = T; this(T[] container, size_t index = 0) { container_ = container; index_ = index; } U opCast(U)() const if (is(U == ItemType)) { return this ? container_[index_] : ItemType.init; } ref ThisType opUnary(string op)() if (op == "++" || op == "--") { mixin(op ~ "index_;"); return this; } @property ItemType value() const { return container_[index_]; } alias value this; private T[] container_ = null; private size_t index_ = 0; } void main() { string test = "abcde"; auto it = Iterator!string(test); char ch = it++; } ./ldc-1.28.0-src/tests/compilable/inputs/0000755000175000017500000000000014141774365020303 5ustar matthiasmatthias./ldc-1.28.0-src/tests/compilable/inputs/gh1741b.d0000644000175000017500000000002514141774365021522 0ustar matthiasmatthiasimport gh1741; S s; ./ldc-1.28.0-src/tests/compilable/inputs/gh1906b.d0000644000175000017500000000010714141774365021526 0ustar matthiasmatthiasclass Base { auto foo() { return this; } abstract int bar(); } ./ldc-1.28.0-src/tests/compilable/inputs/gh2777b.d0000644000175000017500000000004614141774365021537 0ustar matthiasmatthiasint main(string[] args) { return 0; } ./ldc-1.28.0-src/tests/compilable/inputs/foo/0000755000175000017500000000000014141774365021066 5ustar matthiasmatthias./ldc-1.28.0-src/tests/compilable/inputs/foo/bla.di0000644000175000017500000000001414141774365022135 0ustar matthiasmatthiasmodule foo; ./ldc-1.28.0-src/tests/compilable/inputs/gh2422a.d0000644000175000017500000000002014141774365021511 0ustar matthiasmatthiasclass Empty { } ./ldc-1.28.0-src/tests/compilable/inputs/bar/0000755000175000017500000000000014141774365021047 5ustar matthiasmatthias./ldc-1.28.0-src/tests/compilable/inputs/bar/bla.di0000644000175000017500000000001414141774365022116 0ustar matthiasmatthiasmodule bar; ./ldc-1.28.0-src/tests/plugins/0000755000175000017500000000000014141774365016333 5ustar matthiasmatthias./ldc-1.28.0-src/tests/plugins/addFuncEntryCall/0000755000175000017500000000000014141774365021515 5ustar matthiasmatthias./ldc-1.28.0-src/tests/plugins/addFuncEntryCall/addFuncEntryCallPass.cpp0000644000175000017500000000406614141774365026240 0ustar matthiasmatthias//===-- addFuncEntryCallPass.cpp - Optimize druntime calls ----------------===// // // LDC – the LLVM D compiler // // This file is distributed under the University of Illinois Open Source // License. See the LICENSE file for details. // //===----------------------------------------------------------------------===// #include "llvm/Pass.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" using namespace llvm; namespace { class FuncEntryCallPass : public FunctionPass { Value *funcToCallUponEntry = nullptr; public: static char ID; FuncEntryCallPass() : FunctionPass(ID) {} bool doInitialization(Module &M) override; bool runOnFunction(Function &F) override; }; } char FuncEntryCallPass::ID = 0; bool FuncEntryCallPass::doInitialization(Module &M) { // Add fwd declaration of the `void __test_funcentrycall(void)` function. auto functionType = FunctionType::get(Type::getVoidTy(M.getContext()), false); funcToCallUponEntry = M.getOrInsertFunction("__test_funcentrycall", functionType) #if LLVM_VERSION >= 900 .getCallee() #endif ; return true; } bool FuncEntryCallPass::runOnFunction(Function &F) { // Add call to `__test_funcentrycall(void)` at the start of _every_ function // (this includes e.g. `ldc.register_dso`!) llvm::BasicBlock &block = F.getEntryBlock(); IRBuilder<> builder(&block, block.begin()); #if LLVM_VERSION >= 1100 builder.CreateCall(FunctionCallee(cast(funcToCallUponEntry))); #else builder.CreateCall(funcToCallUponEntry); #endif return true; } static void addFuncEntryCallPass(const PassManagerBuilder &, legacy::PassManagerBase &PM) { PM.add(new FuncEntryCallPass()); } // Registration of the plugin's pass is done by the plugin's static constructor. static RegisterStandardPasses RegisterFuncEntryCallPass0(PassManagerBuilder::EP_EnabledOnOptLevel0, addFuncEntryCallPass); ./ldc-1.28.0-src/tests/plugins/addFuncEntryCall/testPlugin.d0000644000175000017500000000052614141774365024023 0ustar matthiasmatthias// REQUIRES: Plugins // RUN: %gnu_make -f %S/Makefile // RUN: %ldc -c -output-ll -plugin=./addFuncEntryCallPass.so -of=%t.ll %s // RUN: FileCheck %s < %t.ll // CHECK: define {{.*}}testfunction int testfunction(int i) { // CHECK-NEXT: call {{.*}}__test_funcentrycall return i * 2; } // CHECK-DAG: declare {{.*}}__test_funcentrycall ./ldc-1.28.0-src/tests/plugins/addFuncEntryCall/Makefile0000644000175000017500000000134414141774365023157 0ustar matthiasmatthias # ROOT_DIR = directory where Makefile sits MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) ROOT_DIR := $(dir $(MAKEFILE_PATH)) LLVM_CONFIG ?= llvm-config CXXFLAGS ?= -O3 CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) -fno-rtti -fpic CXXFLAGS += -DLLVM_VERSION=$(LLVM_VERSION) # Remove all warning flags (they may or may not be supported by the compiler) CXXFLAGS := $(filter-out -W%,$(CXXFLAGS)) CXXFLAGS := $(filter-out -fcolor-diagnostics,$(CXXFLAGS)) ifeq "$(shell uname)" "Darwin" CXXFLAGS += -Wl,-flat_namespace -Wl,-undefined,suppress endif PASSLIB = addFuncEntryCallPass all: $(PASSLIB) $(PASSLIB): $(ROOT_DIR)$(PASSLIB).cpp $(CXX) $(CXXFLAGS) -shared $< -o $@.so .NOTPARALLEL: clean clean: rm -f $(PASSLIB).so ./ldc-1.28.0-src/tests/plugins/lit.local.cfg0000644000175000017500000000041614141774365020676 0ustar matthiasmatthiasimport os import platform import re if (config.plugins_supported): config.available_features.add('Plugins') config.environment['LLVM_CONFIG'] = os.path.join(config.llvm_tools_dir, 'llvm-config') config.environment['LLVM_VERSION'] = str(config.llvm_version) ./ldc-1.28.0-src/tests/lit.site.cfg.in0000644000175000017500000002164014141774365017476 0ustar matthiasmatthiasimport lit.formats import lit.util import os import sys import platform import string import re import subprocess import glob from distutils.version import LooseVersion # Cmake Boolean options ON = True OFF = False ## Auto-initialized variables by cmake: config.ldc2_bin = "@LDC2_BIN@" config.ldcprofdata_bin = "@LDCPROFDATA_BIN@" config.ldcprunecache_bin = "@LDCPRUNECACHE_BIN@" config.ldc2_bin_dir = "@LDC2_BIN_DIR@" config.ldc2_lib_dir = "@LDC2_LIB_DIR@" config.ldc2_runtime_dir = "@RUNTIME_DIR@" config.test_source_root = "@TESTS_IR_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.llvm_version = @LDC_LLVM_VER@ config.llvm_targetsstr = "@LLVM_TARGETS_TO_BUILD@" config.default_target_bits = @DEFAULT_TARGET_BITS@ config.with_PGO = True config.dynamic_compile = @LDC_DYNAMIC_COMPILE@ config.plugins_supported = @LDC_ENABLE_PLUGINS@ config.gnu_make_bin = "@GNU_MAKE_BIN@" config.ldc_host_arch = "@LLVM_NATIVE_ARCH@" config.ldc_with_lld = @LDC_WITH_LLD@ config.spirv_enabled = @LLVM_SPIRV_FOUND@ config.rt_supports_sanitizers = @RT_SUPPORT_SANITIZERS@ config.shared_rt_libs_only = "@BUILD_SHARED_LIBS@" == "ON" config.name = 'LDC' # testFormat: The test format to use to interpret tests. config.test_format = lit.formats.ShTest(execute_external=False) # suffixes: A list of file extensions to treat as test files. This is overriden # by individual lit.local.cfg files in the test subdirectories. config.suffixes = ['.d', ] # excludes: A list of directories to exclude from the testsuite. The 'inputs' # subdirectories contain auxiliary inputs for various tests in their parent # directories. config.excludes = [ 'inputs', 'd2', 'CMakeLists.txt', 'runlit.py', ] # Exclude profile test dir when PGO is disabled if not config.with_PGO: config.excludes.append('PGO') # Exclude dynamic compilation tests when it's disabled if not config.dynamic_compile: config.excludes.append('dynamiccompile') # Explicit forwarding of environment variables env_cc = os.environ.get('CC', '') if env_cc: config.environment['CC'] = env_cc env_cxx = os.environ.get('CXX', '') if env_cxx: config.environment['CXX'] = env_cxx if (platform.system() == 'Windows'): config.environment['VSINSTALLDIR'] = os.environ['VSINSTALLDIR'] config.environment['PATH'] = os.environ['PATH'] config.environment['LIB'] = os.environ['LIB'] # Define available features so that we can disable tests depending on LLVM version config.available_features.add("llvm%d" % config.llvm_version) # LLVM version history: 3.9, 4.0, 5.0, ... # config.llvm_version: 309, 400, 500, ... # plusoneable_llvmversion: 39, 40, 50, ... plusoneable_llvmversion = config.llvm_version // 10 + config.llvm_version%10 for version in range(60, plusoneable_llvmversion+1): config.available_features.add("atleast_llvm%d0%d" % (version//10, version%10)) for version in range(plusoneable_llvmversion, 131): config.available_features.add("atmost_llvm%d0%d" % (version//10, version%10)) # Define OS as available feature (Windows, Darwin, Linux, FreeBSD...) config.available_features.add(platform.system()) # Define available features based on what LLVM can target # Examples: 'target_X86', 'target_ARM', 'target_PowerPC', 'target_AArch64' for t in config.llvm_targetsstr.split(';'): config.available_features.add('target_' + t) if config.spirv_enabled: config.available_features.add('target_SPIRV') if config.rt_supports_sanitizers: config.available_features.add('RTSupportsSanitizers') # Add specific features for Windows x86/x64 testing if (platform.system() == 'Windows') and (config.default_target_bits == 32): config.available_features.add('Windows_x86') if (platform.system() == 'Windows') and (config.default_target_bits == 64): config.available_features.add('Windows_x64') # Define available features based on host arch # Examples: 'host_X86', 'host_ARM', 'host_PowerPC', 'host_AArch64' if (config.ldc_host_arch != ''): config.available_features.add('host_' + config.ldc_host_arch) # Add "LTO" feature if linker support and LTO plugin are available if (platform.system() == 'Windows'): canDoLTO = config.ldc_with_lld elif (platform.system() == 'Darwin'): canDoLTO = os.path.exists('@LLVM_LIBRARY_DIRS@/libLTO.dylib') else: canDoLTO = os.path.exists('@LLVM_LIBRARY_DIRS@/LLVMgold.so') if canDoLTO: config.available_features.add('LTO') if config.ldc_with_lld: config.available_features.add('internal_lld') # Add "link_WebAssembly" feature if we can link wasm (-link-internally or wasm-ld in PATH). if config.ldc_with_lld: config.available_features.add('link_WebAssembly') else: try: if (subprocess.call(["wasm-ld", "--version"]) == 0): config.available_features.add('link_WebAssembly') except OSError: pass config.target_triple = '(unused)' # test_exec_root: The root path where tests should be run. config.test_exec_root = os.path.dirname(__file__) # add test root dir to the path (FileCheck might sit there) path = os.path.pathsep.join( (config.test_source_root, config.environment['PATH']) ) config.environment['PATH'] = path # Add LDC and LLVM bin dir to the path # Give priority to LDC's version of LLVM tools (we need FileCheck with certain bug fixes) path = os.path.pathsep.join( (config.ldc2_bin_dir, config.llvm_tools_dir, config.environment['PATH']) ) config.environment['PATH'] = path # Add substitutions config.substitutions.append( ('%ldc', config.ldc2_bin) ) config.substitutions.append( ('%gnu_make', config.gnu_make_bin) ) config.substitutions.append( ('%profdata', config.ldcprofdata_bin) ) config.substitutions.append( ('%prunecache', config.ldcprunecache_bin) ) config.substitutions.append( ('%llvm-spirv', os.path.join(config.llvm_tools_dir, 'llvm-spirv')) ) config.substitutions.append( ('%runtimedir', config.ldc2_runtime_dir ) ) # Add platform-dependent file extension substitutions if (platform.system() == 'Windows'): # add LDC lib dir to the path so app will be able to find jit.dll # TODO: Something more robust path = os.path.pathsep.join( (config.ldc2_lib_dir, config.environment['PATH']) ) config.environment['PATH'] = path config.substitutions.append( ('%obj', '.obj') ) config.substitutions.append( ('%exe', '.exe') ) config.substitutions.append( ('%lib', '.lib') ) config.substitutions.append( ('%so', '.dll') ) config.substitutions.append( ('%diff_binary ', 'fc /b ') ) else: config.substitutions.append( ('%obj', '.o') ) config.substitutions.append( ('%exe', '') ) config.substitutions.append( ('%lib', '.a') ) if (platform.system() == 'Darwin'): config.substitutions.append( ('%so', '.dylib') ) else: config.substitutions.append( ('%so', '.so') ) config.substitutions.append( ('%diff_binary ', 'cmp -s ') ) # Add cdb substitution if (platform.system() == 'Windows') and (config.default_target_bits == 32): cdb = os.environ['WindowsSDKDir'] + 'Debuggers\\x86\\cdb.exe' config.substitutions.append( ('%arch', 'x86') ) if (platform.system() == 'Windows') and (config.default_target_bits == 64): cdb = os.environ['WindowsSDKDir'] + 'Debuggers\\x64\\cdb.exe' config.substitutions.append( ('%arch', 'x64') ) if (platform.system() == 'Windows') and os.path.isfile( cdb ): config.available_features.add('cdb') config.substitutions.append( ('%cdb', '"' + cdb.replace('\\', '\\\\') + '"') ) # Check whether GDB is present if (platform.system() != 'Windows') and lit.util.which('gdb', config.environment['PATH']): config.available_features.add('gdb') gdb_dflags = '' command = ['gdb', '--version'] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) text = p.stdout.readline() m = re.compile('[^0-9]*([0-9]+[0-9.]*).*').match(text) if m is not None: gdb_version = m.group(1) if LooseVersion(gdb_version) < LooseVersion('7.8'): gdb_dflags = '-dwarf-version=2' elif LooseVersion(gdb_version) >= LooseVersion('8.0'): config.available_features.add('atleast_gdb80') config.substitutions.append( ('%_gdb_dflags', gdb_dflags) ) # Add substitutions for functionality across different LLVM versions if config.llvm_version >= 800: config.substitutions.append( ('%disable_fp_elim', '-frame-pointer=all') ) config.substitutions.append( ('%enable_fp_elim', '-frame-pointer=none') ) else: config.substitutions.append( ('%disable_fp_elim', '-disable-fp-elim') ) config.substitutions.append( ('%enable_fp_elim', '-disable-fp-elim=false') ) if 'LD_LIBRARY_PATH' in os.environ: libs = [] for lib_path in [s for s in os.environ['LD_LIBRARY_PATH'].split(':') if s]: for pattern in ['*ldc-jit*','*druntime-ldc*','*phobos2-ldc*']: libs += glob.glob(os.path.join(lib_path, pattern)) if libs: print('Warning: LDC runtime libs found in LD_LIBRARY_PATH:') for l in libs: print(l) ./ldc-1.28.0-src/tests/instrument/0000755000175000017500000000000014141774365017062 5ustar matthiasmatthias./ldc-1.28.0-src/tests/instrument/finstrument_functions.d0000644000175000017500000000163214141774365023677 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -finstrument-functions -of=%t.ll %s && FileCheck %s < %t.ll void fun0 () { // CHECK-LABEL: define{{.*}} @{{.*}}4fun0FZv // CHECK: [[RET1:%[0-9]]] = call i8* @llvm.returnaddress(i32 0) // CHECK: call void @__cyg_profile_func_enter{{.*}}4fun0FZv{{.*}}[[RET1]] // CHECK: [[RET2:%[0-9]]] = call i8* @llvm.returnaddress(i32 0) // CHECK: call void @__cyg_profile_func_exit{{.*}}4fun0FZv{{.*}}[[RET2]] // CHECK-NEXT: ret return; } pragma(LDC_profile_instr, false) int fun1 (int x) { // CHECK-LABEL: define{{.*}} @{{.*}}4fun1FiZi // CHECK-NOT: __cyg_profile_func_enter // CHECK-NOT: __cyg_profile_func_exit return 42; } bool fun2 (int x) { // CHECK-LABEL: define{{.*}} @{{.*}}4fun2FiZb if (x < 10) // CHECK: call void @__cyg_profile_func_exit // CHECK-NEXT: ret return true; // CHECK: call void @__cyg_profile_func_exit // CHECK-NEXT: ret return false; } ./ldc-1.28.0-src/tests/instrument/xray_check_pipeline.d0000644000175000017500000000053714141774365023241 0ustar matthiasmatthias// Check that the LLVM pipeline is set up correctly to generate XRay sleds. // If we have the XRay runtime lib for this platform, then we can also do machinecodegen: // REQUIRES: XRay_RT // RUN: %ldc -c -output-s -betterC -fxray-instrument -fxray-instruction-threshold=1 -of=%t.s %s && FileCheck %s < %t.s // CHECK: xray_sled void instrument() { } ./ldc-1.28.0-src/tests/instrument/xray_instrument_threshold.d0000644000175000017500000000045414141774365024561 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -fxray-instrument -fxray-instruction-threshold=543 -of=%t.ll %s && FileCheck %s < %t.ll // CHECK-LABEL: define{{.*}} @{{.*}}10instrument // CHECK-SAME: #[[INSTR:[0-9]+]] void instrument() { } // CHECK-DAG: attributes #[[INSTR]] ={{.*}} "xray-instruction-threshold"="543" ./ldc-1.28.0-src/tests/instrument/xray_simple_execution.d0000644000175000017500000000102014141774365023637 0ustar matthiasmatthias// Check basic execution of XRay to verify the basic system is working. // REQUIRES: Linux // REQUIRES: XRay_RT // REQUIRES: atleast_llvm700 // RUN: %ldc -fxray-instrument -fxray-instruction-threshold=1 %s -of=%t%exe // RUN: env XRAY_OPTIONS="patch_premain=true xray_mode=xray-basic verbosity=1" %t%exe 2>&1 | FileCheck %s // This last command should give some output on stderr, one line of which containing: // CHECK: XRay: Log file // If stderr is empty, things are not working. void foo() { } void main() { foo(); } ./ldc-1.28.0-src/tests/instrument/xray_instrument.d0000644000175000017500000000102014141774365022473 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -fxray-instrument -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; // CHECK-LABEL: define{{.*}} @{{.*}}10instrument // CHECK-SAME: #[[INSTR:[0-9]+]] void instrument() { } // CHECK-LABEL: define{{.*}} @{{.*}}15dont_instrument // CHECK-SAME: #[[DONT_INSTR:[0-9]+]] void dont_instrument() { pragma(LDC_profile_instr, false); } // CHECK-DAG: attributes #[[INSTR]] ={{.*}} "xray-instruction-threshold"= // CHECK-DAG: attributes #[[DONT_INSTR]] ={{.*}} "function-instrument"="xray-never" ./ldc-1.28.0-src/tests/instrument/coverage_cycle_gh2177.d0000644000175000017500000000046714141774365023207 0ustar matthiasmatthias// Test that `-cov` does not lead to harmless import cycle errors. // Github issue 2177 // RUN: %ldc -cov=100 -Iinputs %s %S/inputs/coverage_cycle_input.d -of=%t%exe // RUN: %t%exe module coverage_cycle_gh2177; import inputs.coverage_cycle_input; static this() { int i; } int main () { return 0; } ./ldc-1.28.0-src/tests/instrument/coverage_main_gh2163.d0000644000175000017500000000003314141774365023014 0ustar matthiasmatthias// RUN: %ldc -main -cov %s ./ldc-1.28.0-src/tests/instrument/lit.local.cfg0000644000175000017500000000027414141774365021427 0ustar matthiasmatthiasimport platform # Add "XRay_RT" feature on non-Windows, assuming the compiler-rt libraries are available if (platform.system() != 'Windows'): config.available_features.add('XRay_RT') ./ldc-1.28.0-src/tests/instrument/xray_link.d0000644000175000017500000000061414141774365021230 0ustar matthiasmatthias// REQUIRES: XRay_RT // fails on macOS with LLVM 11 due to a linker error, see // https://github.com/llvm/llvm-test-suite/commit/2c3c4a6286d453f763c0245c6536ddd368f0db99 // XFAIL: Darwin && atleast_llvm1100 // RUN: %ldc -fxray-instrument -fxray-instruction-threshold=1 -of=%t%exe %s -vv | FileCheck %s void foo() { } void main() { foo(); } // CHECK: Linking with: // CHECK-NEXT: rt.xray ./ldc-1.28.0-src/tests/instrument/inputs/0000755000175000017500000000000014141774365020404 5ustar matthiasmatthias./ldc-1.28.0-src/tests/instrument/inputs/coverage_cycle_input.d0000644000175000017500000000010314141774365024734 0ustar matthiasmatthiasmodule inputs.coverage_cycle_input; import coverage_cycle_gh2177; ./ldc-1.28.0-src/tests/codegen/0000755000175000017500000000000014141774365016256 5ustar matthiasmatthias./ldc-1.28.0-src/tests/codegen/inlineIR_math.d0000644000175000017500000000664114141774365021154 0ustar matthiasmatthias// Tests inline IR + math optimizations // REQUIRES: target_X86 // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: %ldc -mtriple=x86_64-linux-gnu -mattr=+fma -O3 -release -c -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s import ldc.attributes; import ldc.llvmasm; // Test that internal @inline.ir.*" functions for the inlined IR pieces are always inlined and are not present as a global symbol // LLVM-NOT: @inline.ir. // LLVM-NOT: alwaysinline // __ir should inherit the enclosing function attributes, thus preserving the enclosing function attributes after inlining. // LLVM-LABEL: define{{.*}} @dot // LLVM-SAME: #[[UNSAFEFPMATH:[0-9]+]] // ASM-LABEL: dot: @llvmAttr("unsafe-fp-math", "true") extern (C) double dot(double[] a, double[] b) { double s = 0; // ASM: vfmadd{{[123][123][123]}}pd foreach (size_t i; 0 .. a.length) { s = __ir!(`%p = fmul fast double %0, %1 %r = fadd fast double %p, %2 ret double %r`, double)(a[i], b[i], s); } return s; } // LLVM-LABEL: define{{.*}} @features // LLVM-SAME: #[[FEAT:[0-9]+]] @target("fma") extern (C) double features(double[] a, double[] b) { double s = 0; foreach (size_t i; 0 .. a.length) { s = __ir!(`%p = fmul fast double %0, %1 %r = fadd fast double %p, %2 ret double %r`, double)(a[i], b[i], s); } return s; } // Test that inline IR works when calling function has special attributes defined for its parameters // LLVM-LABEL: define{{.*}} @dot160 // ASM-LABEL: dot160: extern (C) double dot160(double[160] a, double[160] b) { double s = 0; // ASM-NOT: vfmadd foreach (size_t i; 0 .. a.length) { s = __ir!(`%p = fmul double %0, %1 %r = fadd double %p, %2 ret double %r`, double)(a[i], b[i], s); } return s; } // Test inline IR alias defined outside any function alias __ir!(`%p = fmul fast double %0, %1 %r = fadd fast double %p, %2 ret double %r`, double, double, double, double) muladdFast; alias __ir!(`%p = fmul double %0, %1 %r = fadd double %p, %2 ret double %r`, double, double, double, double) muladd; // LLVM-LABEL: define{{.*}} @aliasInlineUnsafe // LLVM-SAME: #[[UNSAFEFPMATH]] // ASM-LABEL: aliasInlineUnsafe: @llvmAttr("unsafe-fp-math", "true") extern (C) double aliasInlineUnsafe(double[] a, double[] b) { double s = 0; // ASM: vfmadd{{[123][123][123]}}pd foreach (size_t i; 0 .. a.length) { s = muladdFast(a[i], b[i], s); } return s; } // LLVM-LABEL: define{{.*}} @aliasInlineSafe // LLVM-SAME: #[[NO_UNSAFEFPMATH:[0-9]+]] // ASM-LABEL: aliasInlineSafe: extern (C) double aliasInlineSafe(double[] a, double[] b) { double s = 0; // ASM-NOT: vfmadd{{[123][123][123]}}pd foreach (size_t i; 0 .. a.length) { s = muladd(a[i], b[i], s); } return s; } // Make sure an enclosing function's 'noinline' attribute isn't copied to // the inlined IR function (having 'alwaysinline') (issue #1711). double neverInlinedEnclosingFunction() { pragma(inline, false); return muladd(1.0, 2.0, 3.0); } // LLVM: attributes #[[UNSAFEFPMATH]] ={{.*}} "unsafe-fp-math"="true" // LLVM: attributes #[[FEAT]] ={{.*}} "target-features"="{{.*}}+fma{{.*}}" // LLVM: attributes #[[NO_UNSAFEFPMATH]] = // LLVM-NOT: "unsafe-fp-math"="true" ./ldc-1.28.0-src/tests/codegen/attr_targetoptions.d0000644000175000017500000000160614141774365022362 0ustar matthiasmatthias// REQUIRES: atleast_llvm800 // Tests that our TargetMachine options are added as function attributes // RUN: %ldc -c -output-ll -of=%t.ll %s // RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll %s -O2 // RUN: FileCheck %s --check-prefix=COMMON --check-prefix=NO_FP < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll %s -O2 %disable_fp_elim // RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll %s %enable_fp_elim -mattr=test // RUN: FileCheck %s --check-prefix=COMMON --check-prefix=NO_FP --check-prefix=ATTR < %t.ll // COMMON: define{{.*}} @{{.*}}3fooFZv{{.*}} #[[KEYVALUE:[0-9]+]] void foo() { } // COMMON: attributes #[[KEYVALUE]] // COMMON-DAG: "target-cpu"= // WITH_FP-DAG: "frame-pointer"="all" // NO_FP-DAG: "frame-pointer"="none" // ATTR-DAG: "target-features"="{{[^"]*}}+test ./ldc-1.28.0-src/tests/codegen/attr_target_x86.d0000644000175000017500000000367014141774365021456 0ustar matthiasmatthias// Tests @target attribute for x86 // REQUIRES: target_X86 // RUN: %ldc -O -c -mcpu=i386 -mtriple=i386-linux-gnu -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: %ldc -O -c -mcpu=i386 -mtriple=i386-linux-gnu -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s import ldc.attributes; // LLVM-LABEL: define{{.*}} void @{{.*}}foo // ASM-LABEL: _D15attr_target_x863fooFPfQcfZv: void foo(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM-NOT: addps } // LLVM-LABEL: define{{.*}} void @{{.*}}foo_sse // LLVM-SAME: #[[SSE:[0-9]+]] // ASM-LABEL: _D15attr_target_x867foo_sseFPfQcfZv: @(target("sse")) void foo_sse(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM: addps } // Make sure that no-sse overrides sse (attribute sorting). Also tests multiple @target attribs. // LLVM-LABEL: define{{.*}} void @{{.*}}foo_nosse // LLVM-SAME: #[[NOSSE:[0-9]+]] // ASM-LABEL: _D15attr_target_x869foo_nosseFPfQcfZv: @(target("no-sse\n , \tsse ")) void foo_nosse(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM-NOT: addps } // LLVM-LABEL: define{{.*}} void @{{.*}}bar_nosse // LLVM-SAME: #[[NOSSE]] // ASM-LABEL: _D15attr_target_x869bar_nosseFPfQcfZv: @(target("sse")) @(target(" no-sse")) void bar_nosse(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM-NOT: addps } // LLVM-LABEL: define{{.*}} void @{{.*}}haswell // LLVM-SAME: #[[HSW:[0-9]+]] // ASM-LABEL: _D15attr_target_x867haswellFPfQcfZv: @(target("arch=haswell ")) void haswell(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM: vaddps } // LLVM-DAG: attributes #[[SSE]] = {{.*}} "target-features"="+sse" // LLVM-DAG: attributes #[[NOSSE]] = {{.*}} "target-features"="+sse,-sse" // LLVM-DAG: attributes #[[HSW]] = {{.*}} "target-cpu"="haswell" ./ldc-1.28.0-src/tests/codegen/attr_allocsize_diag.d0000644000175000017500000000214614141774365022431 0ustar matthiasmatthias// Test ldc.attributes.allocSize diagnostics // RUN: not %ldc -d-version=NORMAL %s 2>&1 | FileCheck %s --check-prefix=NORMAL // RUN: not %ldc -d-version=THIS %s 2>&1 | FileCheck %s --check-prefix=THIS import ldc.attributes; version(NORMAL) { // NORMAL: attr_allocsize_diag.d([[@LINE+2]]): Error: `@ldc.attributes.allocSize.sizeArgIdx=2` too large for function `my_calloc` with 2 arguments. // NORMAL: attr_allocsize_diag.d([[@LINE+1]]): Error: `@ldc.attributes.allocSize.numArgIdx=2` too large for function `my_calloc` with 2 arguments. extern (C) void* my_calloc(size_t num, size_t size) @allocSize(2, 2) { return null; } } version(THIS) { // Test function type with hidden `this` argument class A { // THIS: attr_allocsize_diag.d([[@LINE+2]]): Error: `@ldc.attributes.allocSize.sizeArgIdx=4` too large for function `this_calloc` with 4 arguments. // THIS: attr_allocsize_diag.d([[@LINE+1]]): Error: `@ldc.attributes.allocSize.numArgIdx=4` too large for function `this_calloc` with 4 arguments. void* this_calloc(int size, int b, size_t num, int c) @allocSize(4, 4) { return null; } } } ./ldc-1.28.0-src/tests/codegen/align_class.d0000644000175000017500000000252514141774365020706 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s struct S16 { align(16) int a; } class D { align(32) int d = 0xDD; } // CHECK: %align_class.D = type { [5 x i8*]*, i8*, [{{(16|24)}} x i8], i32 } class E : D { S16 s16 = S16(0xEE); } // CHECK: %align_class.E = type { [5 x i8*]*, i8*, [{{(16|24)}} x i8], i32, [12 x i8], %align_class.S16 } class F : D { align(64) int f = 0xFF; } // CHECK: %align_class.F = type { [5 x i8*]*, i8*, [{{(16|24)}} x i8], i32, [28 x i8], i32 } extern(C++) class CppClass { align(32) int a = 0xAA; } // CHECK: %align_class.CppClass = type { [0 x i8*]*, [{{(24|28)}} x i8], i32 } void main() { scope d = new D; // CHECK: = alloca %align_class.D, align 32 static assert(D.d.offsetof == 32); assert(d.d == 0xDD); scope e = new E; // CHECK: = alloca %align_class.E, align 32 static assert(E.d.offsetof == 32); assert(e.d == 0xDD); static assert(E.s16.offsetof == 48); assert(e.s16.a == 0xEE); scope f = new F; // CHECK: = alloca %align_class.F, align 64 static assert(F.d.offsetof == 32); assert(f.d == 0xDD); static assert(F.f.offsetof == 64); assert(f.f == 0xFF); scope cppClass = new CppClass; // CHECK: = alloca %align_class.CppClass, align 32 static assert(CppClass.a.offsetof == 32); assert(cppClass.a == 0xAA); } ./ldc-1.28.0-src/tests/codegen/checkaction_halt.d0000644000175000017500000000043114141774365021704 0ustar matthiasmatthias// RUN: %ldc -checkaction=halt -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // CHECK: define {{.*}}_D16checkaction_halt3foo void foo(int x) { assert(x, "msg"); // CHECK: assertFailed: // CHECK-NEXT: call void @llvm.trap() // CHECK-NEXT: unreachable } ./ldc-1.28.0-src/tests/codegen/gh2346.d0000644000175000017500000000453414141774365017346 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // Make sure the LL struct is packed due to an unnatural overall alignment of 1. // CHECK-DAG: %gh2346.UnalignedUInt = type <{ i32 }> struct UnalignedUInt { align(1) uint a; } static assert(UnalignedUInt.alignof == 1); static assert(UnalignedUInt.sizeof == 4); // Then there's no need to pack naturally aligned containers. // CHECK-DAG: %gh2346.Container = type { i8, %gh2346.UnalignedUInt } struct Container { ubyte one; UnalignedUInt two; } static assert(Container.alignof == 1); static assert(Container.sizeof == 5); static assert(Container.two.offsetof == 1); // CHECK-DAG: %gh2346.UnalignedUInt2 = type <{ i32 }> struct UnalignedUInt2 { align(2) uint a; } static assert(UnalignedUInt2.alignof == 2); static assert(UnalignedUInt2.sizeof == 4); // CHECK-DAG: %gh2346.Container2 = type { i8, [1 x i8], %gh2346.UnalignedUInt2 } struct Container2 { ubyte one; UnalignedUInt2 two; } static assert(Container2.alignof == 2); static assert(Container2.sizeof == 6); static assert(Container2.two.offsetof == 2); // CHECK-DAG: %gh2346.PackedContainer2 = type <{ i8, %gh2346.UnalignedUInt2 }> struct PackedContainer2 { ubyte one; align(1) UnalignedUInt2 two; } static assert(PackedContainer2.alignof == 1); static assert(PackedContainer2.sizeof == 5); static assert(PackedContainer2.two.offsetof == 1); // CHECK-DAG: %gh2346.WeirdContainer = type { i8, [1 x i8], %gh2346.UnalignedUInt, [2 x i8] } align(4) struct WeirdContainer { ubyte one; align(2) UnalignedUInt two; } static assert(WeirdContainer.alignof == 4); static assert(WeirdContainer.sizeof == 8); static assert(WeirdContainer.two.offsetof == 2); // CHECK-DAG: %gh2346.ExplicitlyUnalignedUInt2 = type <{ i32 }> align(2) struct ExplicitlyUnalignedUInt2 { uint a; } static assert(ExplicitlyUnalignedUInt2.alignof == 2); static assert(ExplicitlyUnalignedUInt2.sizeof == 4); // CHECK-DAG: %gh2346.AnotherContainer = type { i8, [1 x i8], %gh2346.ExplicitlyUnalignedUInt2 } struct AnotherContainer { ubyte one; ExplicitlyUnalignedUInt2 two; } static assert(AnotherContainer.alignof == 2); static assert(AnotherContainer.sizeof == 6); static assert(AnotherContainer.two.offsetof == 2); // reference all types void foo() { Container a; Container2 b; PackedContainer2 c; WeirdContainer d; AnotherContainer e; } ./ldc-1.28.0-src/tests/codegen/llvm_used_1.d0000644000175000017500000000161314141774365020636 0ustar matthiasmatthias// Test that llvm.used is emitted correctly when multiple D modules are compiled into one LLVM module. // REQUIRES: target_X86 // Explicitly use OS X triple, so that llvm.used is used for moduleinfo globals. // RUN: %ldc -c -output-ll -O3 %S/inputs/module_ctor.d %s -of=%t.ll -mtriple=x86_64-apple-macosx && FileCheck --check-prefix=LLVM %s < %t.ll // RUN: %ldc -O3 %S/inputs/module_ctor.d -run %s | FileCheck --check-prefix=EXECUTE %s // There was a bug where llvm.used was emitted more than once, whose symptom was that suffixed versions would appear: e.g. `@llvm.used.3`. // Expect 4 llvm.used entries - 2 ModuleInfos refs + ldc.dso_{c,d}tor refs. // LLVM-NOT: @llvm.used. // LLVM: @llvm.used = appending global [4 x i8*] // LLVM-NOT: @llvm.used. // EXECUTE: ctor // EXECUTE: main // EXECUTE: dtor import core.stdc.stdio; static ~this() { puts("dtor\n"); } void main() { puts("main\n"); }./ldc-1.28.0-src/tests/codegen/ctor_initarray_gh2883.d0000644000175000017500000000042714141774365022462 0ustar matthiasmatthias// REQUIRES: target_AArch64 // RUN: %ldc -mtriple=aarch64-unknown-linux -output-s -of=%t.s %s // RUN: FileCheck %s < %t.s // CHECK-NOT: .ctors // CHECK-NOT: .dtors // CHECK: .section .init_array // CHECK: .section .fini_array // No code needed to generate asm for a module. ./ldc-1.28.0-src/tests/codegen/array_equals_memcmp.d0000644000175000017500000000657114141774365022462 0ustar matthiasmatthias// Tests that static array (in)equality is optimized to a memcmp call when valid. // More importantly: test that memcmp is _not_ used when it is not valid. // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix=LLVM < %t.ll // RUN: %ldc -O3 -c -output-s -of=%t.s %s && FileCheck %s --check-prefix=ASM < %t.s // RUN: %ldc -O3 -run %s module mod; struct ThreeBytes { byte a; byte b; byte c; } align(4) struct ThreeBytesAligned { byte a; byte b; byte c; } struct Packed { byte a; byte b; byte c; byte d; } struct PackedPacked { Packed a; Packed b; } struct WithPadding { int b; byte a; } // LLVM-LABEL: define{{.*}} @{{.*}}two_uints bool two_uints(ref uint[2] a, const ref uint[2] b) { // LLVM: call i32 @memcmp({{.*}}, {{.*}}, i{{32|64}} 8) return a == b; } // LLVM-LABEL: define{{.*}} @{{.*}}unequal_two_uints bool unequal_two_uints(ref uint[2] a, uint[2] b) { // LLVM: call i32 @memcmp({{.*}}, {{.*}}, i{{32|64}} 8) return a != b; } // LLVM-LABEL: define{{.*}} @{{.*}}two_floats bool two_floats(float[2] a, float[2] b) { // LLVM-NOT: memcmp return a == b; } // LLVM-LABEL: define{{.*}} @{{.*}}four_bools // ASM-LABEL: four_bools{{.*}}: bool four_bools(bool[4] a, bool[4] b) { // LLVM: call i32 @memcmp({{.*}}, {{.*}}, i{{32|64}} 4) // Make sure that LLVM recognizes and optimizes-out the call to memcmp for 4 byte arrays: // ASM-NOT: {{(mem|b)cmp}} return a == b; } // LLVM-LABEL: define{{.*}} @{{.*}}array_of_array // ASM-LABEL: array_of_array{{.*}}: bool array_of_array(byte[3][3] a, const byte[3][3] b) { // LLVM: call i32 @memcmp({{.*}}, {{.*}}, i{{32|64}} 9) return a == b; } // LLVM-LABEL: define{{.*}} @{{.*}}int3_short3 bool int3_short3(int[3] a, short[3] b) { // LLVM-NOT: memcmp return a == b; // LLVM-LABEL: ret i1 } // LLVM-LABEL: define{{.*}} @{{.*}}pointer3 bool pointer3(int*[3] a, int*[3] b) { // LLVM: call i32 @memcmp({{.*}}, {{.*}}, i{{32|64}} {{12|24}}) return a == b; } // LLVM-LABEL: define{{.*}} @{{.*}}enum3 enum E : char { a, b, c, d, e, f }; bool enum3(E[3] a, E[3] b) { // LLVM: call i32 @memcmp({{.*}}, {{.*}}, i{{32|64}} 3) return a == b; } class K {} // LLVM-LABEL: define{{.*}} @{{.*}}klass2 bool klass2(K[2] a, K[2] b) { // LLVM-NOT: memcmp return a == b; // LLVM-LABEL: ret i1 } void main() { uint[2] a = [1, 2]; uint[2] b = [1, 2]; uint[2] c = [2, 1]; assert(two_uints(a, a)); assert(two_uints(a, b)); assert(!two_uints(a, c)); assert(!unequal_two_uints(a, b)); assert(unequal_two_uints(a, c)); assert( two_floats([1.0f, 2.0f], [1.0f, 2.0f])); assert(!two_floats([1.0f, 2.0f], [2.0f, 1.0f])); assert( four_bools([true, false, true, false], [true, false, true, false])); assert(!four_bools([true, false, true, false], [true, false, true, true])); assert( array_of_array([[1,2,3],[4,5,6],[7,8,9]],[[1,2,3],[4,5,6],[7,8,9]])); assert(!array_of_array([[1,2,3],[4,5,6],[7,8,9]],[[6,6,6],[4,5,6],[7,8,9]])); assert( int3_short3([1, 2, 3], [1, 2, 3])); assert(!int3_short3([1, 2, 3], [3, 2, 3])); int aaa = 666; int bbb = 333; assert( pointer3([&aaa, &bbb, &aaa], [&aaa, &bbb, &aaa])); assert(!pointer3([&aaa, &bbb, &aaa], [&bbb, &bbb, &aaa])); assert( enum3([E.a, E.e, E.b], [E.a, E.e, E.b])); assert(!enum3([E.a, E.e, E.b], [E.a, E.e, E.f])); } ./ldc-1.28.0-src/tests/codegen/static_typeid_gh1540.d0000644000175000017500000000172714141774365022267 0ustar matthiasmatthias// Tests correct codegen for static variables initialized with typeid(A) // Test for Github issue 1540 // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll class C { } interface I { } struct S { } // CHECK-DAG: _D{{.*}}1C7__ClassZ{{\"?}} = global %object.TypeInfo_Class // CHECK-DAG: _D{{.*}}classvarC14TypeInfo_Class{{\"?}} = thread_local global %object.TypeInfo_Class* {{.*}}1C7__ClassZ auto classvar = typeid(C); // CHECK-DAG: _D{{.*}}TypeInfo_C{{.*}}1I6__initZ{{\"?}} = linkonce_odr global %object.TypeInfo_Interface // CHECK-DAG: _D{{.*}}interfacevarC18TypeInfo_Interface{{\"?}} = thread_local global %object.TypeInfo_Interface* {{.*}}TypeInfo_C{{.*}}1I6__initZ auto interfacevar = typeid(I); // CHECK-DAG: _D{{.*}}TypeInfo_S{{.*}}1S6__initZ{{\"?}} = linkonce_odr global %object.TypeInfo_Struct // CHECK-DAG: _D{{.*}}structvarC15TypeInfo_Struct{{\"?}} = thread_local global %object.TypeInfo_Struct* {{.*}}TypeInfo_S{{.*}}1S6__initZ auto structvar = typeid(S); ./ldc-1.28.0-src/tests/codegen/avr.d0000644000175000017500000000065214141774365017216 0ustar matthiasmatthias// REQUIRES: target_AVR // RUN: %ldc -mtriple=avr -betterC -output-ll -of=%t.ll %s && FileCheck %s < %t.ll version (AVR) {} else static assert(0); version (D_SoftFloat) {} else static assert(0); // make sure TLS globals are emitted as regular __gshared globals: // CHECK: @_D3avr13definedGlobali = global i32 123 int definedGlobal = 123; // CHECK: @_D3avr14declaredGlobali = external global i32 extern int declaredGlobal; ./ldc-1.28.0-src/tests/codegen/array_equals_memcmp_dyn.d0000644000175000017500000000410714141774365023325 0ustar matthiasmatthias// Tests that dynamic array (in)equality is optimized to a memcmp call when valid. // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix=LLVM < %t.ll // RUN: %ldc -c -output-s -O3 -of=%t.s %s && FileCheck %s --check-prefix=ASM < %t.s // RUN: %ldc -O0 -run %s // RUN: %ldc -O3 -run %s module mod; // LLVM-LABEL: define{{.*}} @{{.*}}static_dynamic // ASM-LABEL: static_dynamic{{.*}}: bool static_dynamic(const bool[4] a, bool[] b) { // LLVM: call i32 @memcmp( // Also test that LLVM recognizes and optimizes-out the call to memcmp for 4 byte arrays: // ASM-NOT: {{(mem|b)cmp}} return a == b; } // LLVM-LABEL: define{{.*}} @{{.*}}inv_dynamic_dynamic // ASM-LABEL: inv_dynamic_dynamic{{.*}}: bool inv_dynamic_dynamic(bool[] a, const bool[] b) { // The front-end turns this into a call to druntime template function `object.__equals!(const(bool), const(bool)).__equals(const(bool)[], const(bool)[])` // After optimization (inlining), it should boil down to a length check and a call to memcmp. // ASM: {{(mem|b)cmp}} return a != b; } // LLVM-LABEL: define{{.*}} @{{.*}}_D4core8internal5array8equality__T8__equals // ASM-LABEL: _D4core8internal5array8equality__T8__equals{{.*}}: // LLVM-LABEL: define{{.*}} @_Dmain // ASM-LABEL: _Dmain: void main() { assert( static_dynamic([true, false, true, false], [true, false, true, false])); assert(!static_dynamic([true, false, true, false], [true, false, true, true])); assert(!static_dynamic([true, false, true, false], [true, false, true, false, true])); assert(!static_dynamic([true, false, true, false], [true, false, true])); assert(!inv_dynamic_dynamic([true, false, true, false], [true, false, true, false])); assert( inv_dynamic_dynamic([true, false, true, false], [true, false, true, true])); assert( inv_dynamic_dynamic([true, false], [true])); assert( inv_dynamic_dynamic([true, false, true, false], [true, false, true])); // Make sure that comparing zero-length arrays with ptr=null is allowed. bool* ptr = null; assert(!inv_dynamic_dynamic(ptr[0..0], ptr[0..0])); } ./ldc-1.28.0-src/tests/codegen/frame_pointer_x86.d0000644000175000017500000000163014141774365021762 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s // RUN: FileCheck %s --check-prefixes=COMMON,FP < %t.s // RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -O2 // RUN: FileCheck %s --check-prefixes=COMMON,NO_FP < %t.s // RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -O2 %disable_fp_elim // RUN: FileCheck %s --check-prefixes=COMMON,FP < %t.s // RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s %enable_fp_elim // RUN: FileCheck %s --check-prefixes=COMMON,NO_FP < %t.s // COMMON-LABEL: _D17frame_pointer_x8613inlineAsmLeafFZv: // COMMON: pushq %rbp // COMMON-LABEL: _D17frame_pointer_x8616inlineAsmNonLeafFZv: // COMMON: pushq %rbp // COMMON-LABEL: _D17frame_pointer_x863fooFZv: // FP: pushq %rbp // NO_FP-NOT: pushq %rbp void externalFunc(); void inlineAsmLeaf() { asm { nop; } } void inlineAsmNonLeaf() { asm { nop; } externalFunc(); } void foo() {} ./ldc-1.28.0-src/tests/codegen/inline_ir_noparams.d0000644000175000017500000000064314141774365022276 0ustar matthiasmatthias// RUN: %ldc -O -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // CHECK: define {{.*}}11unreachableFZv void unreachable() { import ldc.llvmasm; // CHECK-NEXT: unreachable __ir!("unreachable", void)(); // CHECK-NEXT: } } extern bool flag; // CHECK: define {{.*}}3bar int bar() { int r = 123; if (flag) { r = 456; unreachable(); } // CHECK: ret i32 123 return r; } ./ldc-1.28.0-src/tests/codegen/inlining_staticvar.d0000644000175000017500000000340414141774365022313 0ustar matthiasmatthias// Test cross-module inlining involving static variables // RUN: %ldc %s -I%S -c -output-ll -O3 -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -I%S -c -output-ll -enable-inlining -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll // RUN: %ldc -I%S -enable-inlining %S/inputs/inlinables_staticvar.d -run %s // RUN: %ldc -I%S -O3 %S/inputs/inlinables_staticvar.d -run %s import inputs.inlinables_staticvar; import ldc.attributes; extern (C): // simplify mangling for easier matching // Functions are intentionally split and @weak to thwart LLVM constant folding. void checkModuleScope_1() @weak { addToModuleScopeInline(7); } void checkModuleScope_2() @weak { addToModuleScopeOutline(101); assert(equalModuleScope(7+101)); } void checkInsideFunc_1() @weak { assert(addAndCheckInsideFunc(0, 7)); } void checkInsideFunc_2() @weak { assert(addAndCheckInsideFuncIndirect(7, 101)); assert(addAndCheckInsideFunc(7+101, 9)); } void checkInsideNestedFunc_1() @weak { assert(addAndCheckInsideNestedFunc(0, 7)); } void checkInsideNestedFunc_2() @weak { assert(addAndCheckInsideNestedFuncIndirect(7, 101)); assert(addAndCheckInsideNestedFunc(7+101, 9)); } void checkNestedStruct_1() @weak { assert(addAndCheckNestedStruct(0, 7)); } void checkNestedStruct_2() @weak { assert(addAndCheckNestedStructIndirect(7, 101)); assert(addAndCheckNestedStruct(7+101, 9)); } // OPT0-LABEL: define{{.*}} @_Dmain( // OPT3-LABEL: define{{.*}} @_Dmain( extern(D) void main() { checkModuleScope_1(); checkModuleScope_2(); checkInsideFunc_1(); checkInsideFunc_2(); checkInsideNestedFunc_1(); checkInsideNestedFunc_2(); checkNestedStruct_1(); checkNestedStruct_2(); } ./ldc-1.28.0-src/tests/codegen/inlining_gh3126.d0000644000175000017500000000255714141774365021235 0ustar matthiasmatthias// Tests that functions are cross-module inlined when emitting multiple object // files. // Generate unoptimized IR for 2 source files as separate compilation units (in both orders). // RUN: %ldc -c -output-ll %s %S/inputs/inlinables.d -od=%t && FileCheck %s < %t/inlining_gh3126.ll // RUN: %ldc -c -output-ll %S/inputs/inlinables.d %s -od=%t && FileCheck %s < %t/inlining_gh3126.ll // Now test with another source file making use of inputs.inlinables instead of compiling that module directly. // RUN: %ldc -c -output-ll -I%S %s %S/inlining_imports_pragma.d -od=%t && FileCheck %s < %t/inlining_gh3126.ll // RUN: %ldc -c -output-ll -I%S %S/inlining_imports_pragma.d %s -od=%t && FileCheck %s < %t/inlining_gh3126.ll import inputs.inlinables; // no other function definitions (always_inline_chain*, call_template_foo); // allow template_foo to be instantiated in here though // CHECK-NOT: always_inline_chain // CHECK-NOT: call_template_foo // CHECK: define {{.*}}_D15inlining_gh31263fooFZi int foo() { // CHECK-NEXT: ret i32 345 return always_inline_chain0(); } // CHECK-NOT: always_inline_chain // CHECK-NOT: call_template_foo // CHECK: define {{.*}}_D15inlining_gh31263barFZi int bar() { // no calls to [call_]template_foo // CHECK-NOT: call {{.*}}template_foo return call_template_foo(123); } // CHECK-NOT: always_inline_chain // CHECK-NOT: call_template_foo ./ldc-1.28.0-src/tests/codegen/attr_fastmath.d0000644000175000017500000000214114141774365021262 0ustar matthiasmatthias// Test @fastmath // RUN: %ldc -O0 -release -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; // CHECK-LABEL: define{{.*}} @notfast // CHECK-SAME: #[[ATTR_NOTFAST:[0-9]+]] extern (C) double notfast(double a, double b) { @fastmath double nested_fast(double a, double b) { return a * b; } // CHECK-NOT: fmul fast return a * b; } // CHECK-LABEL: define{{.*}} @{{.*}}nested_fast // CHECK: fmul fast // CHECK-LABEL: define{{.*}} @fast // CHECK-SAME: #[[ATTR_FAST:[0-9]+]] @fastmath extern (C) double fast(double a, double b) { double c; double nested_slow(double a, double b) { return a * b; } // Also test new scopes when generating the IR. try { // CHECK: fmul fast c += a * b; } catch (Throwable) { // CHECK: fmul fast return a * b; } // CHECK: fmul fast return c + a * b; } // CHECK-LABEL: define{{.*}} @{{.*}}nested_slow // CHECK-NOT: fmul fast // CHECK-DAG: attributes #[[ATTR_FAST]] ={{.*}} "unsafe-fp-math"="true" // CHECK-NOT: attributes #[[ATTR_NOTFAST]] ={{.*}} "unsafe-fp-math"="true" ./ldc-1.28.0-src/tests/codegen/gh2729.d0000644000175000017500000000052714141774365017351 0ustar matthiasmatthias// RUN: %ldc -run %s ulong[2] foo(ulong a, ulong b) @nogc nothrow pure @safe { import ldc.simd; return inlineIR!(` %agg1 = insertvalue [2 x i64] undef, i64 %0, 0 %agg2 = insertvalue [2 x i64] %agg1, i64 %1, 1 ret [2 x i64] %agg2`, ulong[2])(a, b); } void main() { assert(foo(123, 456) == [ 123, 456 ]); } ./ldc-1.28.0-src/tests/codegen/inlining_pragma.d0000644000175000017500000000313514141774365021563 0ustar matthiasmatthias// Test inlining of functions marked with pragma(inline) // RUN: %ldc %s -I%S -c -output-ll -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPTNONE < %t.O0.ll // RUN: %ldc %s -I%S -c -output-ll -O3 -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll extern (C): // simplify mangling for easier matching int dummy; // OPTNONE-LABEL: define{{.*}} @never_inline // OPTNONE-SAME: #[[NEVER:[0-9]+]] pragma(inline, false) int never_inline() { dummy = 111; return 222; } int external(); // OPTNONE-LABEL: define{{.*}} @always_inline // OPTNONE-SAME: #[[ALWAYS:[0-9]+]] pragma(inline, true) int always_inline() { int a; foreach (i; 1 .. 10) { foreach (ii; 1 .. 10) { foreach (iii; 1 .. 10) { a += i * external(); } } } dummy = 444; return a; } // OPTNONE-LABEL: define{{.*}} @foo // OPTNONE-SAME: #[[FOO:[0-9]+]] int foo() { return 333; } // OPT3-LABEL: define{{.*}} @call_always_inline int call_always_inline() { // OPT3-NOT: call {{.*}} @always_inline() // OPT3: ret return always_inline(); } // OPT3-LABEL: define{{.*}} @call_never_inline int call_never_inline() { // OPT3: call {{.*}} @never_inline() // OPT3: ret return never_inline(); } // OPTNONE-NOT: attributes #[[FOO]] ={{.*}} alwaysinline // OPTNONE-NOT: attributes #[[FOO]] ={{.*}} noinline // OPTNONE-NOT: attributes #[[NEVER]] ={{.*}} alwaysinline // OPTNONE-NOT: attributes #[[ALWAYS]] ={{.*}} noinline // OPTNONE-DAG: attributes #[[NEVER]] ={{.*}} noinline // OPTNONE-DAG: attributes #[[ALWAYS]] ={{.*}} alwaysinline ./ldc-1.28.0-src/tests/codegen/fvisibility_dll.d0000644000175000017500000000242014141774365021611 0ustar matthiasmatthias// Tests that -fvisibility=public for Windows targets exports defined symbols // (dllexport) without explicit `export` visibility, and that linking an app // against such a DLL via import library works as expected. // REQUIRES: Windows // generate DLL and import lib (public visibility by default) // RUN: %ldc %S/inputs/fvisibility_dll_lib.d -betterC -shared -of=%t_lib.dll // compile, link and run the app; `-dllimport=all` for dllimporting data symbols // RUN: %ldc %s -I%S/inputs -betterC -dllimport=all %t_lib.lib -of=%t.exe // RUN: %t.exe import fvisibility_dll_lib; // test manual 'relocation' of references to dllimported globals in static data initializers: __gshared int* dllimportRef = &dllGlobal; __gshared void* castDllimportRef = &dllGlobal; immutable void*[2] arrayOfRefs = [ null, cast(immutable) &dllGlobal ]; struct MyStruct { int* dllimportRef = &dllGlobal; // init symbol references dllimported global } extern(C) void main() { assert(dllGlobal == 123); const x = dllSum(1, 2); assert(x == 3); dllWeakFoo(); scope c = new MyClass; assert(c.myInt == 456); assert(dllimportRef == &dllGlobal); assert(castDllimportRef == &dllGlobal); assert(arrayOfRefs[1] == &dllGlobal); assert(MyStruct.init.dllimportRef == &dllGlobal); } ./ldc-1.28.0-src/tests/codegen/fence_pragma.d0000644000175000017500000000051114141774365021027 0ustar matthiasmatthias// RUN: %ldc %s -c -output-ll -of=%t.ll && FileCheck %s < %t.ll import ldc.intrinsics; void fun0 () { llvm_memory_fence(DefaultOrdering, SynchronizationScope.CrossThread); // CHECK: fence seq_cst llvm_memory_fence(DefaultOrdering, SynchronizationScope.SingleThread); // CHECK: fence syncscope("singlethread") seq_cst } ./ldc-1.28.0-src/tests/codegen/gh1843.d0000644000175000017500000000032714141774365017343 0ustar matthiasmatthias// Just make sure LDC doesn't necessarily enforce the .ll extension (issue #1843). // RUN: %ldc -output-ll -of=%t.myIR %s && FileCheck %s < %t.myIR // CHECK: define{{.*}} void @{{.*}}_D6gh18433fooFZv void foo() {} ./ldc-1.28.0-src/tests/codegen/inlining_invariants_gh1678.d0000644000175000017500000000102414141774365023471 0ustar matthiasmatthias// RUN: %ldc --enable-inlining -of=%t%exe %s // https://github.com/ldc-developers/ldc/issues/1678 import std.datetime; // Extra test that fail when a simple frontend change is tried that names __invariant using the line and column number. class A { mixin(genInv("666")); mixin(genInv("777")); } string genInv(string a) { return "invariant() { }"; } void main() { auto currentTime = Clock.currTime(); auto timeString = currentTime.toISOExtString(); auto restoredTime = SysTime.fromISOExtString(timeString); }./ldc-1.28.0-src/tests/codegen/gh2515.d0000644000175000017500000000322414141774365017337 0ustar matthiasmatthias// For scope-allocated class objects, make sure the _d_callfinalizer() // druntime call is elided if the object has no dtors and no monitor. // RUN: %ldc -O3 -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import core.stdc.stdio : printf; class Base { int val = 123; void foo() { val *= 3; } void bar() { synchronized(this) val *= 2; } } class WithDtor : Base { ~this() {} } class WithImplicitDtor : Base { static struct S { int val; ~this() {} } S s; } // CHECK: define{{.*}} void @{{.*}}_D6gh251516noDtor_noMonitorFZv void noDtor_noMonitor() { scope b = new Base(); b.foo(); printf("%d\n", b.val); // CHECK-NOT: _d_callfinalizer // CHECK: ret void } // CHECK: define{{.*}} void @{{.*}}_D6gh251518noDtor_withMonitorFZv void noDtor_withMonitor() { scope b = new Base(); b.bar(); printf("%d\n", b.val); // CHECK: _d_callfinalizer // CHECK: ret void } // CHECK: define{{.*}} void @{{.*}}_D6gh25158withDtorFZv void withDtor() { scope Base b = new WithDtor(); b.foo(); printf("%d\n", b.val); // CHECK: _d_callfinalizer // CHECK: ret void } // CHECK: define{{.*}} void @{{.*}}_D6gh251516withImplicitDtorFZv void withImplicitDtor() { scope Base b = new WithImplicitDtor(); b.foo(); printf("%d\n", b.val); // CHECK: _d_callfinalizer // CHECK: ret void } /* Test a C++ class as well, which as of 2.077 isn't implicitly delete()d. */ extern(C++) class CppClass { int val = 666; } // CHECK: define{{.*}} void @{{.*}}_D6gh25158cppClassFZv void cppClass() { scope c = new CppClass(); printf("%d\n", c.val); // CHECK-NOT: _d_callfinalizer // CHECK: ret void } ./ldc-1.28.0-src/tests/codegen/array_literal_gh1924.d0000644000175000017500000000414314141774365022255 0ustar matthiasmatthias// RUN: %ldc -c -O3 -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -d-version=RUN -run %s // CHECK-LABEL: define{{.*}} @{{.*}}simple2d auto simple2d() { // CHECK: _d_newarrayU // CHECK: _d_newarrayU // CHECK-NOT: _d_newarrayU // CHECK: ret { return [[1.0]]; } // GitHub issue #1925 // CHECK-LABEL: define{{.*}} @{{.*}}make2d auto make2d() { // CHECK: _d_newarrayU // CHECK-NOT: _d_newarrayU double[][1] a = [[1.0]]; // CHECK: ret return a; } // CHECK-LABEL: define{{.*}} @{{.*}}make3d auto make3d() { // CHECK: _d_newarrayU // CHECK: _d_newarrayU // CHECK-NOT: _d_newarrayU int[][1][] a = [[[1]]]; // CHECK: ret { return a; } struct S { auto arr = [[321]]; } // CHECK-LABEL: define{{.*}} @{{.*}}makeS auto makeS() { // CHECK: _d_newarrayU // CHECK: _d_newarrayU // CHECK-NOT: _d_newarrayU // CHECK: ret return S(); } mixin template A() { auto a = [1, 2, 3]; auto b = [[1, 2, 3]]; } version (RUN) { void main() { { auto a = simple2d(); auto b = simple2d(); assert(a.ptr !is b.ptr); assert(a[0].ptr !is b[0].ptr); } { auto a = make2d(); auto b = make2d(); assert(a.ptr !is b.ptr); assert(a[0].ptr !is b[0].ptr); } { auto a = make3d(); auto b = make3d(); assert(a.ptr !is b.ptr); assert(a[0].ptr !is b[0].ptr); assert(a[0][0].ptr !is b[0][0].ptr); } { enum e = [[1.0]]; auto a = e; auto b = e; assert(a.ptr !is b.ptr); assert(a[0].ptr !is b[0].ptr); } { auto a = makeS(); auto b = makeS(); assert(a.arr.ptr !is b.arr.ptr); assert(a.arr[0].ptr !is b.arr[0].ptr); } { mixin A!() a0; mixin A!() a1; assert(a0.a.ptr !is a1.a.ptr); assert(a0.b.ptr !is a1.b.ptr); assert(a0.b[0].ptr !is a1.b[0].ptr); } } } ./ldc-1.28.0-src/tests/codegen/gc2stack.d0000644000175000017500000000353614141774365020133 0ustar matthiasmatthias// RUN: %ldc -O2 -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -O2 -disable-gc2stack -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix NOOPT < %t.ll class Bar { int i; } // CHECK: define int foo1() { // NOOPT: call{{.*}}_d_newarrayT // CHECK-NOT: _d_newarrayT int[] i = new int[5]; i[3] = 42; // CHECK: ret return i[3]; } // CHECK: define int foo2() { // NOOPT: call{{.*}}_d_allocmemoryT // CHECK-NOT: _d_allocmemoryT int* i = new int; *i = 42; // CHECK: ret return *i; } // CHECK: define int foo3() { // NOOPT: call{{.*}}_d_allocclass // CHECK-NOT: _d_allocclass Bar i = new Bar; i.i = 42; // CHECK: ret return i.i; } int[] bar1() { // CHECK: _d_newarrayT int[] i = new int[5]; // CHECK: ret return i; } int* bar2() { // CHECK: _d_allocmemoryT int* i = new int; // CHECK: ret return i; } Bar bar3() { // CHECK: _d_allocclass Bar i = new Bar; // CHECK: ret return i; } extern void fun(int[]); extern void fun(int*); extern void fun(Bar); // CHECK: define int baz1() { // CHECK: _d_newarrayT int[] i = new int[5]; fun(i); i[3] = 42; // CHECK: ret return i[3]; } // CHECK: define int baz2() { // CHECK: _d_allocmemoryT int* i = new int; fun(i); *i = 42; // CHECK: ret return *i; } // CHECK: define int baz3() { // CHECK: _d_allocclass Bar i = new Bar; fun(i); i.i = 42; // CHECK: ret return i.i; } __gshared int[] p1; __gshared int* p2; __gshared Bar p3; // CHECK: define int bzz1() { // CHECK: _d_newarrayT int[] i = new int[5]; p1 = i; i[3] = 42; // CHECK: ret return i[3]; } // CHECK: define int bzz2() { // CHECK: _d_allocmemoryT int* i = new int; p2 = i; *i = 42; // CHECK: ret return *i; } // CHECK: define int bzz3() { // CHECK: _d_allocclass Bar i = new Bar; p3 = i; i.i = 42; // CHECK: ret return i.i; } ./ldc-1.28.0-src/tests/codegen/dcompute_cu_addrspaces.d0000644000175000017500000000261314141774365023125 0ustar matthiasmatthias// REQUIRES: target_NVPTX // RUN: %ldc -c -mdcompute-targets=cuda-350 -m64 -mdcompute-file-prefix=addrspace -output-ll -output-o %s && FileCheck %s --check-prefix=LL < addrspace_cuda350_64.ll && FileCheck %s --check-prefix=PTX < addrspace_cuda350_64.ptx @compute(CompileFor.deviceOnly) module dcompute_cu_addrspaces; import ldc.dcompute; // LL: %"ldc.dcompute.Pointer!(AddrSpace.Private, float).Pointer" = type { float addrspace(5)* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Global, float).Pointer" = type { float addrspace(1)* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Shared, float).Pointer" = type { float addrspace(3)* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Constant, immutable(float)).Pointer" = type { float addrspace(4)* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Generic, float).Pointer" = type { float* } void foo(PrivatePointer!float f) { // LL: load float, float addrspace(5)* // PTX: ld.local.f32 float g = *f; } void foo(GlobalPointer!float f) { // LL: load float, float addrspace(1)* // PTX: ld.global.f32 float g = *f; } void foo(SharedPointer!float f) { // LL: load float, float addrspace(3)* // PTX: ld.shared.f32 float g = *f; } void foo(ConstantPointer!float f) { // LL: load float, float addrspace(4)* // PTX: ld.const.f32 float g = *f; } void foo(GenericPointer!float f) { // LL: load float, float* // PTX: ld.f32 float g = *f; } ./ldc-1.28.0-src/tests/codegen/array_equals_memcmp_2.d0000644000175000017500000000055014141774365022672 0ustar matthiasmatthias// Tests that static array (in)equality of unequal lengths is optimized to `false`. // RUN: %ldc -c -O3 -output-ll -of=%t.ll %s && FileCheck %s --check-prefix=LLVM < %t.ll // LLVM-LABEL: define{{.*}} @{{.*}}different_lengths // ASM-LABEL: different_lengths{{.*}}: bool different_lengths(bool[4] a, bool[3] b) { // LLVM: ret i1 false return a == b; } ./ldc-1.28.0-src/tests/codegen/nested_lazy_gh2302.d0000644000175000017500000000066714141774365021742 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s void foo() { auto impl(T)(lazy T field) { // Make sure `field` is a closure variable with delegate type (LL struct). // CHECK: %nest.impl = type { { i8*, i32 (i8*)* } } auto ff() { return field; } auto a = field; return ff() + a; } auto r = impl(123); assert(r == 246); } void main() { foo(); } ./ldc-1.28.0-src/tests/codegen/dcompute_host_and_device.d0000644000175000017500000000463614141774365023452 0ustar matthiasmatthias// Check that we can generate code for both the host and device in one compiler invocation // REQUIRES: target_NVPTX // RUN: %ldc -c -mdcompute-targets=cuda-350 -m64 -output-ll -mdcompute-file-prefix=host_and_device -Iinputs -output-o %s %S/inputs/kernel.d // RUN: FileCheck %s --check-prefix=PTX < host_and_device_cuda350_64.ptx // RUN: FileCheck %s --check-prefix=LL < dcompute_host_and_device.ll import inputs.kernel : k_foo; import ldc.dcompute; int tlGlobal; __gshared int gGlobal; void main(string[] args) { tlGlobal = 0; gGlobal = 0; string s = foo.mangleof; string k_s = k_foo.mangleof; GlobalPointer!float global_x; foo(global_x); } void foo(GlobalPointer!float x_in) { // LL-LABEL: foo SharedPointer!float shared_x; PrivatePointer!float private_x; ConstantPointer!float const_x; // LL: [[s_load_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[s_addr_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[s_store_reg:%[0-9]*]] = load float, float* [[s_addr_reg]] // LL: store float [[s_store_reg]], float* [[s_load_reg]] *shared_x = *x_in; // LL: [[p_load_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[p_addr_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[p_store_reg:%[0-9]*]] = load float, float* [[p_addr_reg]] // LL: store float [[p_store_reg]], float* [[p_load_reg]] *private_x = *x_in; // LL: [[c_load_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[c_addr_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[c_store_reg:%[0-9]*]] = load float, float* [[c_addr_reg]] // LL: store float [[c_store_reg]], float* [[c_load_reg]] *x_in = *const_x; // LL: [[g1_load_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[g1_addr_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[g1_store_reg:%[0-9]*]] = load float, float* [[g1_addr_reg]] // LL: store float [[g1_store_reg]], float* [[g1_load_reg]] *x_in = *shared_x; // LL: [[g2_load_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[g2_addr_reg:%[0-9]*]] = load float*, float** {{%[0-9]*}} // LL: [[g2_store_reg:%[0-9]*]] = load float, float* [[g2_addr_reg]] // LL: store float [[g2_store_reg]], float* [[g2_load_reg]] *x_in = *private_x; } // PTX-LABEL: k_foo // PTX: ld.global.f32 // PTX: st.shared.f32 // PTX: st.local.f32 // PTX: ld.const.f32 // PTX: ld.shared.f32 // PTX: ld.local.f32 ./ldc-1.28.0-src/tests/codegen/varargs.d0000644000175000017500000000034414141774365020071 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // Make sure typesafe variadics are not lowered to LLVM variadics. void typesafe(size_t[2] a...) {} // CHECK: define{{.*}}typesafe // CHECK-NOT: ... // CHECK-SAME: { ./ldc-1.28.0-src/tests/codegen/zerolengtharray_gh1611.d0000644000175000017500000000150214141774365022630 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll struct A0 { ubyte[0] zerolen; } // CHECK-DAG: %{{.*}}.A0 = type { [1 x i8] } struct uint_0_uint { uint a = 111; ubyte[0] zerolen; uint c = 333; } // CHECK-DAG: %{{.*}}.uint_0_uint = type { i32, i32 } // No tests for codegen with e.g. uint_0_uint yet, because codegen could be much improved. // I think codegen should be the same as for // struct uint_uint // { // uint a = 111; // uint c = 333; // } // CHECK-LABEL: define{{.*}}fooA0{{.*}} { auto fooA0() { return A0(); // Intentionally a regexp to not match "sret" // CHECK: {{ ret }} } // CHECK-LABEL: define{{.*}}foo_uint_0_uint auto foo_uint_0_uint() { return uint_0_uint(); // Intentionally a regexp to not match "sret" // CHECK: {{ ret }} } ./ldc-1.28.0-src/tests/codegen/gh3221.d0000644000175000017500000000050114141774365017325 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes: assumeUsed; union U { ubyte a; uint b; } // CHECK: @{{.*}}_D6gh32211uSQk1U{{.*}} = global { i32 } { i32 12345 } // CHECK: @llvm.used = appending global // CHECK-SAME: _D6gh32211uSQk1U @assumeUsed __gshared U u = { b: 12345 }; ./ldc-1.28.0-src/tests/codegen/array_catassign_gh2588.d0000644000175000017500000000026514141774365022605 0ustar matthiasmatthias// RUN: %ldc -run %s int work(ref int[] array) { array ~= 123; return 456; } void main() { int[] array; array ~= work(array); assert(array == [ 123, 456 ]); } ./ldc-1.28.0-src/tests/codegen/sret_thunk_gh3329.d0000644000175000017500000000111714141774365021610 0ustar matthiasmatthias// RUN: %ldc -run %s extern(C) int printf(const(char)* format, ...); struct NoPOD { size_t x; ~this() {} } interface I { NoPOD doIt(size_t arg); } __gshared C c; class C : I { this() { c = this; printf("c: %p\n", c); } NoPOD doIt(size_t arg) { printf("doIt this: %p; arg: %p\n", this, arg); assert(this == c); assert(arg == 0x2A); return NoPOD(arg << 4); } } void main() { I i = new C; printf("i: %p\n", i); NoPOD r = i.doIt(0x2A); printf("&r: %p\n", &r); assert(r.x == 0x2A0); } ./ldc-1.28.0-src/tests/codegen/nothrow.d0000644000175000017500000000330214141774365020121 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll struct S { ~this() nothrow {} void foo() nothrow { throw new Error("foo"); } } struct Throwing { ~this() {} void bar() { throw new Exception("bar"); } } // CHECK-LABEL: define{{.*}} @{{.*}}_D7nothrow15inTryCatchErrorFZv void inTryCatchError() { try { // make sure the nothrow functions S.foo() and S.~this() // are invoked in try-blocks with at least 1 catch block S a; // CHECK: invoke {{.*}}_D7nothrow1S3fooMFNbZv{{.*}} %a a.foo(); // CHECK: invoke {{.*}}_D7nothrow1S6__dtorMFNbZv{{.*}} %a } catch (Error) {} } // CHECK-LABEL: define{{.*}} @{{.*}}_D7nothrow19inTryCatchExceptionFZv void inTryCatchException() { // make sure the nothrow functions are never invoked // CHECK-NOT: invoke {{.*}}_D7nothrow1S3fooMFNbZv // CHECK-NOT: invoke {{.*}}_D7nothrow1S6__dtorMFNbZv try { S a; a.foo(); } catch (Exception) {} } // CHECK-LABEL: define{{.*}} @{{.*}}_D7nothrow12inTryFinallyFZv void inTryFinally() { // make sure the nothrow functions are never invoked // CHECK-NOT: invoke {{.*}}_D7nothrow1S3fooMFNbZv // CHECK-NOT: invoke {{.*}}_D7nothrow1S6__dtorMFNbZv try { S a; a.foo(); } finally { S b; b.foo(); } } // CHECK-LABEL: define{{.*}} @{{.*}}_Dmain void main() { // make sure the nothrow functions are never invoked // CHECK-NOT: invoke {{.*}}_D7nothrow1S3fooMFNbZv // CHECK-NOT: invoke {{.*}}_D7nothrow1S6__dtorMFNbZv Throwing t; S a; a.foo(); t.bar(); { S b; t.bar(); b.foo(); S().foo(); } } ./ldc-1.28.0-src/tests/codegen/attr_llvmFMF_contract.d0000644000175000017500000000130714141774365022656 0ustar matthiasmatthias// Tests the @ldc.attributes.llvmFastMathFlag("contract") UDA // Also tests that adding this attribute indeed leads to LLVM optimizing it to a fused multiply-add for a simple case. // REQUIRES: target_X86 // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: %ldc -betterC -mtriple=x86_64-linux-gnu -mattr=+fma -O3 -release -c -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s import ldc.attributes; // LLVM-LABEL: define{{.*}} @{{.*}}contract // ASM-LABEL: contract: @llvmFastMathFlag("contract") extern(C) double contract(double a, double b, double c) { // LLVM: fmul contract double // LLVM: fadd contract double // ASM: vfmadd return a * b + c; } ./ldc-1.28.0-src/tests/codegen/static_array_huge.d0000644000175000017500000000047014141774365022121 0ustar matthiasmatthias// Tests that static arrays can be large (> 16MB) // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // CHECK: Stuff = type { [209715200 x i8] } struct Stuff { byte[1024*1024*200] a; } Stuff stuff; // CHECK: hugeArrayG209715200g{{\"?}} ={{.*}} [209715200 x i8] byte[1024*1024*200] hugeArray; ./ldc-1.28.0-src/tests/codegen/attr_llvmattr.d0000644000175000017500000000104314141774365021320 0ustar matthiasmatthias// Tests @llvmAttr attribute // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; extern (C): // For easier name mangling // CHECK: define{{.*}} @keyvalue{{.*}} #[[KEYVALUE:[0-9]+]] @(llvmAttr("key", "value")) void keyvalue() { } // CHECK: define{{.*}} @keyonly{{.*}} #[[KEYONLY:[0-9]+]] @(llvmAttr("keyonly")) void keyonly() { } // CHECK-DAG: attributes #[[KEYVALUE]] = {{.*}} "key"="value" // CHECK-NOT: attributes #[[KEYONLY]] = {{.*}} "keyonly"= // CHECK-DAG: attributes #[[KEYONLY]] = {{.*}} "keyonly" ./ldc-1.28.0-src/tests/codegen/attr_weak_external.d0000644000175000017500000000045314141774365022310 0ustar matthiasmatthias// Test that an imported @weak function does not result in an extern_weak reference. // RUN: %ldc -c -I%S -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import inputs.attr_weak_external_input: weak_definition_seven; void foo() { auto a = &weak_definition_seven; } // CHECK-NOT: extern_weak ./ldc-1.28.0-src/tests/codegen/dmd_inline_asm_ip.d0000644000175000017500000000055414141774365022061 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -output-s -x86-asm-syntax=intel -mtriple=x86_64-linux-gnu -of=%t.s %s // RUN: FileCheck %s < %t.s // CHECK: _D17dmd_inline_asm_ip3fooFZm ulong foo() { asm { // CHECK: mov eax, dword ptr [eip] mov EAX, [EIP]; // CHECK-NEXT: mov rax, qword ptr [rip] mov RAX, [RIP]; ret; } } ./ldc-1.28.0-src/tests/codegen/attr_targetoptions_fp.d0000644000175000017500000000105614141774365023046 0ustar matthiasmatthias// See Github issue #1860 // RUN: %ldc -c -output-ll -of=%t.ll -float-abi=soft %s && FileCheck --check-prefix=SOFT %s < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll -float-abi=softfp %s && FileCheck --check-prefix=HARD %s < %t.ll // SOFT: define{{.*}} @{{.*}}3fooFZv{{.*}} #[[KEYVALUE:[0-9]+]] // HARD: define{{.*}} @{{.*}}3fooFZv{{.*}} #[[KEYVALUE:[0-9]+]] void foo() { } // SOFT: attributes #[[KEYVALUE]] // SOFT-DAG: "target-features"="{{.*}}+soft-float{{.*}}" // HARD: attributes #[[KEYVALUE]] // HARD-NOT: "target-features"="{{.*}}+soft-float{{.*}}" ./ldc-1.28.0-src/tests/codegen/funcliteral_defaultarg_gh1634.d0000644000175000017500000000135614141774365024132 0ustar matthiasmatthias// Test function literal as default argument // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s module mod; // CHECK-LABEL: define{{.*}} @{{.*}}D3mod3fooFPFZiZi int foo(int function() d = () { return 123; }) { return d(); } // CHECK-LABEL: define{{.*}} @{{.*}}D3mod8call_fooFZi int call_foo() { // CHECK: call {{.*}}D3mod3fooFPFZiZi{{.*}}D3mod9__lambda5FNaNbNiNfZi return foo(); } // The lambda is defined by the first call to foo with default arguments. // CHECK-LABEL: define{{.*}} @{{.*}}D3mod9__lambda5FNaNbNiNfZi // CHECK: ret i32 123 // CHECK-LABEL: define{{.*}} @{{.*}}Dmain void main() { // CHECK: call {{.*}}D3mod3fooFPFZiZi{{.*}}D3mod9__lambda5FNaNbNiNfZi assert(foo() == 123); } ./ldc-1.28.0-src/tests/codegen/pragma_no_typeinfo.d0000644000175000017500000000175314141774365022311 0ustar matthiasmatthias// Make sure the LDC_no_typeinfo pragma prevents TypeInfo emission. // RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll pragma(LDC_no_moduleinfo); // prevent ModuleInfo from referencing class TypeInfos // CHECK: _D50TypeInfo_S18pragma_no_typeinfo18StructWithTypeInfo6__initZ = linkonce_odr global %object.TypeInfo_Struct struct StructWithTypeInfo {} // force emission auto ti = typeid(StructWithTypeInfo); // CHECK: _D18pragma_no_typeinfo17ClassWithTypeInfo7__ClassZ = global %object.TypeInfo_Class class ClassWithTypeInfo {} // CHECK: _D18pragma_no_typeinfo21InterfaceWithTypeInfo11__InterfaceZ = global %object.TypeInfo_Class interface InterfaceWithTypeInfo {} pragma(LDC_no_typeinfo): // CHECK-NOT: _D48TypeInfo_S18pragma_no_typeinfo16StructNoTypeInfo6__initZ struct StructNoTypeInfo {} // CHECK-NOT: _D18pragma_no_typeinfo15ClassNoTypeInfo7__ClassZ class ClassNoTypeInfo {} // CHECK-NOT: _D18pragma_no_typeinfo19InterfaceNoTypeInfo11__InterfaceZ interface InterfaceNoTypeInfo {} ./ldc-1.28.0-src/tests/codegen/linker_directives_mac.d0000644000175000017500000000060514141774365022751 0ustar matthiasmatthias// RUN: %ldc -mtriple=x86_64-apple-darwin -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // REQUIRES: target_X86 // CHECK: !llvm.linker.options = !{!0, !1, !2} // CHECK: !0 = !{!"-lmylib"} pragma(lib, "mylib"); // CHECK: !1 = !{!"-myflag"} pragma(linkerDirective, "-myflag"); // CHECK: !2 = !{!"-framework", !"CoreFoundation"} pragma(linkerDirective, "-framework", "CoreFoundation"); ./ldc-1.28.0-src/tests/codegen/hashed_mangling.d0000644000175000017500000000311214141774365021530 0ustar matthiasmatthias// Test hashing of symbols above hash threshold // RUN: %ldc -hash-threshold=90 -g -c -output-ll -of=%t90.ll %s && FileCheck %s --check-prefix HASH90 < %t90.ll // RUN: %ldc -hash-threshold=90 -run %s // Don't use Phobos functions in this test, because the test hashthreshold is too low for an unhashed libphobos. module one.two.three; // HASH90-DAG: define{{.*}} @externCfunctions_are_not_hashed_externCfunctions_are_not_hashed_externCfunctions_are_not_hashed extern (C) int externCfunctions_are_not_hashed_externCfunctions_are_not_hashed_externCfunctions_are_not_hashed() { return 95; } auto s(T)(T t) { // HASH90-DAG: define{{.*}} @{{(\"\\01_?)?}}_D3one3two5three__T1sTiZQfFNaNbNiNfiZSQBkQBjQBi__TQBfTiZQBlFiZ__T6ResultTiZQk // HASH90-DAG: define{{.*}} @{{(\"\\01_?)?}}_D3one3two5three3L1633_182fab6f09ff014d9f4a578edf9609981sZ // HASH90-DAG: define{{.*}} @{{(\"\\01_?)?}}_D3one3two5three3L2333_9b5306e5c42722cd2cb93ae6beb422346Result3fooZ struct Result(T) { void foo(){} } return Result!int(); } auto klass(T)(T t) { class Result(T) { // HASH90-DAG: define{{.*}} @{{(\"\\01_?)?}}_D3one3two5three__T5klassTiZQjFiZ__T6ResultTiZQk3fooMFZv // HASH90-DAG: define{{.*}} @{{(\"\\01_?)?}}_D3one3two5three3L3433_de737f3d65ae58efa925cffda52cd8da6Result3fooZ void foo(){} } return new Result!int(); } void main() { assert( externCfunctions_are_not_hashed_externCfunctions_are_not_hashed_externCfunctions_are_not_hashed() == 95); auto x = 1.s.s.s.s; x.foo; auto y = 1.klass.klass.klass.klass; y.foo; } ./ldc-1.28.0-src/tests/codegen/const_cond_labels.d0000644000175000017500000000635214141774365022104 0ustar matthiasmatthias// Make sure that the dead code of an `if` (and `else if`) is elminated when the condition is constant // _only_ if the block does not contain any labels. // For example, // int a = 1; // if (false) { // L1: // a = 2; // } else { // goto L1; // } // assert(a == 2); // Note that a label is conssidered anything that lets us jump inside the body // of the statement _apart from_ the actual statement (e.g. the `if). // That generally is a normal label, but also specific cases for switch // statements (see last tests). // RUN: %ldc -O0 -output-ll -of=%t.ll %s && FileCheck %s < %t.ll extern(C): //to avoid name mangling. // CHECK-LABEL: @foo void foo() { // CHECK: %a = alloca // CHECK: br int a; if (0) { L1: a = 1; } else { goto L1; } } // CHECK-LABEL: @bar void bar(int a, int b) { int c; if (0) { switch (a) { case 10: while (b) { L2: // CHECK: store i32 10, i32* %c c = 10; } default: assert(0); } } else { goto L2; } } // CHECK-LABEL: @without_goto void without_goto(int a, int b) { int c; if (0) { switch (a) { case 10: while (b) { L2: // CHECK: store i32 10, i32* %c c = 10; } default: assert(0); } } else { a = 2; } } // CHECK-LABEL: @fourth void fourth(int a, int b, int c) { int j, d; if (a) { goto L3; } else if (false) { for (j = 0; j <= c; ++j) { // Can't `goto` in a foreach because // it always declares a variable. L3: foreach (i; 0..b) { // CHECK: store i32 10, i32* %d d = 10; } } } } // If a switch is outside the body of a statement "to-be-elided" // but a case statement of it is inside that body, then that // case acts as a label because we can jump inside the body without // using the statement (i.e. using the switch to jump to the case). // CHECK-LABEL: @case_as_label void case_as_label(int a, int b) { // Note the `CHECK-NOT` trickery. // CHECK-NOT: store i32 2, i32* %c // CHECK: store i32 3, i32* %c // CHECK-NOT: store i32 2, i32* %c // CHECK: store i32 4, i32* %c // CHECK-NOT: store i32 2, i32* %c int c; switch (a) { case 1: // Can elide if (false) { final switch (b) { case 2: c = 2; } } case 2: // Can't elide if (false) { case 3: c = 3; } // Can't elide if (false) { default: c = 4; } } } // CHECK-LABEL: @case_as_label2 void case_as_label2(int a, int b) { // CHECK: store i32 2, i32* %c // CHECK: store i32 3, i32* %c int c; final switch (a) { // Can't elide if (false) { final switch (b) { case 2: c = 2; } // Test that `switch` in higher or equal nesting level // with a `case` does not impact the handling of `case`s. case 1: c = 3; } } } ./ldc-1.28.0-src/tests/codegen/static_array_init.d0000644000175000017500000000770714141774365022146 0ustar matthiasmatthias// RUN: %ldc -output-ll %s -of=%t.ll // RUN: FileCheck %s < %t.ll void bytes_scalar() { immutable(byte)[32] myBytes = 123; // CHECK: define {{.*}}_D17static_array_init12bytes_scalarFZv // CHECK-NEXT: %myBytes = alloca [32 x i8], align 1 // CHECK-NEXT: %1 = bitcast [32 x i8]* %myBytes to i8* // CHECK-NEXT: call void @llvm.memset{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8 123, i{{(32|64)}} 32 } void bytes_scalar(byte arg) { immutable(byte)[32] myBytes = arg; // CHECK: define {{.*}}_D17static_array_init12bytes_scalarFgZv // CHECK-NEXT: %arg = alloca i8, align 1 // CHECK-NEXT: %myBytes = alloca [32 x i8], align 1 // CHECK-NEXT: store i8 %arg_arg, i8* %arg // CHECK-NEXT: %1 = bitcast [32 x i8]* %myBytes to i8* // CHECK-NEXT: %2 = load {{.*}}i8* %arg // CHECK-NEXT: call void @llvm.memset{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8 %2, i{{(32|64)}} 32 } void ints_scalar() { const(int[32]) myInts = 123; // CHECK: define {{.*}}_D17static_array_init11ints_scalarFZv // CHECK: arrayinit.cond: // CHECK-NEXT: %[[I1:[0-9]+]] = load {{.*i(32|64)}}* %arrayinit.itr // CHECK-NEXT: %arrayinit.condition = icmp ne i{{(32|64)}} %[[I1]], 32 // CHECK: store i32 123, i32* %arrayinit.arrayelem } void ints_scalar(int arg) { const(int[32]) myInts = arg; // CHECK: define {{.*}}_D17static_array_init11ints_scalarFiZv // CHECK: arrayinit.cond: // CHECK-NEXT: %[[I2:[0-9]+]] = load {{.*i(32|64)}}* %arrayinit.itr // CHECK-NEXT: %arrayinit.condition = icmp ne i{{(32|64)}} %[[I2]], 32 // CHECK: %[[E2:[0-9]+]] = load {{.*}}i32* %arg // CHECK-NEXT: store i32 %[[E2]], i32* %arrayinit.arrayelem } void bytes() { immutable(byte[4]) myBytes = [ 1, 2, 3, 4 ]; // CHECK: define {{.*}}_D17static_array_init5bytesFZv // CHECK-NEXT: %myBytes = alloca [4 x i8], align 1 // CHECK-NEXT: store [4 x i8] c"\01\02\03\04", [4 x i8]* %myBytes } void bytes(byte[] arg) { const(byte)[4] myBytes = arg; // CHECK: define {{.*}}_D17static_array_init5bytesFAgZv // CHECK: %myBytes = alloca [4 x i8], align 1 // CHECK: %1 = bitcast [4 x i8]* %myBytes to i8* // CHECK: call void @llvm.memcpy{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8*{{[a-z0-9 ]*}} %.ptr, i{{(32|64)}} 4 } void ints() { immutable(int)[4] myInts = [ 1, 2, 3, 4 ]; // CHECK: define {{.*}}_D17static_array_init4intsFZv // CHECK-NEXT: %myInts = alloca [4 x i32], align 4 // CHECK-NEXT: store [4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32]* %myInts } void ints(ref int[4] arg) { const(int[4]) myInts = arg; // CHECK: define {{.*}}_D17static_array_init4intsFKG4iZv // CHECK-NEXT: %myInts = alloca [4 x i32], align 4 // CHECK-NEXT: %1 = bitcast [4 x i32]* %myInts to i32* // CHECK-NEXT: %2 = bitcast i32* %1 to i8* // CHECK-NEXT: %3 = bitcast [4 x i32]* %arg to i32* // CHECK-NEXT: %4 = bitcast i32* %3 to i8* // CHECK-NEXT: call void @llvm.memcpy{{.*}}(i8*{{[a-z0-9 ]*}} %2, i8*{{[a-z0-9 ]*}} %4, i{{(32|64)}} 16 } void bytes_scalar_2d() { immutable(byte)[4][8] myBytes = 123; // CHECK: define {{.*}}_D17static_array_init15bytes_scalar_2dFZv // CHECK-NEXT: %myBytes = alloca [8 x [4 x i8]], align 1 // CHECK-NEXT: %1 = bitcast [8 x [4 x i8]]* %myBytes to [32 x i8]* // CHECK-NEXT: %2 = bitcast [32 x i8]* %1 to i8* // CHECK-NEXT: call void @llvm.memset{{.*}}(i8*{{[a-z0-9 ]*}} %2, i8 123, i{{(32|64)}} 32 } void ints_scalar_2d(immutable int arg) { const(int[4])[8] myInts = arg; // CHECK: define {{.*}}_D17static_array_init14ints_scalar_2dFyiZv // CHECK: arrayinit.cond: // CHECK-NEXT: %[[I3:[0-9]+]] = load {{.*i(32|64)}}* %arrayinit.itr // CHECK-NEXT: %arrayinit.condition = icmp ne i{{(32|64)}} %[[I3]], 32 // CHECK: %[[E3:[0-9]+]] = load {{.*}}i32* %arg // CHECK-NEXT: store i32 %[[E3]], i32* %arrayinit.arrayelem } ./ldc-1.28.0-src/tests/codegen/union.d0000644000175000017500000001226714141774365017563 0ustar matthiasmatthias// Tests LL types and constant initializers of init symbols and globals of // structs with and without overlapping (union) fields. // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s struct S { char c; // default initializer: 0xff uint ui; bool[2] bools; // make sure the 2 bools are extended to 2 bytes bool b = true; // scalar bool too char[2][1] multidim; // multidimensional init based on a single 0xff char } // CHECK-DAG: %union.S = type { i8, [3 x i8], i32, [2 x i8], i8, [1 x [2 x i8]], [3 x i8] } // CHECK-DAG: @{{.*}}_D5union1S6__initZ{{\"?}} = constant %union.S { i8 -1, [3 x i8] zeroinitializer, i32 0, [2 x i8] zeroinitializer, i8 1, [1 x [2 x i8]] {{\[}}[2 x i8] c"\FF\FF"], [3 x i8] zeroinitializer } // CHECK-DAG: @{{.*}}_D5union8defaultSSQq1S{{\"?}} = global %union.S { i8 -1, [3 x i8] zeroinitializer, i32 0, [2 x i8] zeroinitializer, i8 1, [1 x [2 x i8]] {{\[}}[2 x i8] c"\FF\FF"], [3 x i8] zeroinitializer } __gshared S defaultS; // CHECK-DAG: @{{.*}}_D5union9explicitSSQr1S{{\"?}} = global %union.S { i8 3, [3 x i8] zeroinitializer, i32 56, [2 x i8] c"\00\01", i8 0, [1 x [2 x i8]] {{\[}}[2 x i8] c"\FF\FF"], [3 x i8] zeroinitializer } __gshared S explicitS = { 3, 56, [false, true], false /* implicit multidim */ }; struct SWithUnion { char c; S nested; union { struct { ubyte ub = 6; ushort us = 33; align(8) ulong ul = 666; } struct { uint ui1; uint ui2 = 84; ulong ul_dummy; ulong last = 123; } } } // CHECK-DAG: %union.SWithUnion = type { i8, [3 x i8], %union.S, [4 x i8], i8, [1 x i8], i16, i32, i64, i64 } // CHECK-DAG: @{{.*}}_D5union10SWithUnion6__initZ{{\"?}} = constant %union.SWithUnion { i8 -1, [3 x i8] zeroinitializer, %union.S { i8 -1, [3 x i8] zeroinitializer, i32 0, [2 x i8] zeroinitializer, i8 1, [1 x [2 x i8]] {{\[}}[2 x i8] c"\FF\FF"], [3 x i8] zeroinitializer }, [4 x i8] zeroinitializer, i8 6, [1 x i8] zeroinitializer, i16 33, i32 84, i64 666, i64 123 } // CHECK-DAG: @{{.*}}_D5union17defaultSWithUnionSQBa10SWithUnion{{\"?}} = global %union.SWithUnion { i8 -1, [3 x i8] zeroinitializer, %union.S { i8 -1, [3 x i8] zeroinitializer, i32 0, [2 x i8] zeroinitializer, i8 1, [1 x [2 x i8]] {{\[}}[2 x i8] c"\FF\FF"], [3 x i8] zeroinitializer }, [4 x i8] zeroinitializer, i8 6, [1 x i8] zeroinitializer, i16 33, i32 84, i64 666, i64 123 } __gshared SWithUnion defaultSWithUnion; // CHECK-DAG: @{{.*}}_D5union28explicitCompatibleSWithUnionSQBl10SWithUnion{{\"?}} = global %union.SWithUnion { i8 -1, [3 x i8] zeroinitializer, %union.S { i8 -1, [3 x i8] zeroinitializer, i32 0, [2 x i8] zeroinitializer, i8 1, [1 x [2 x i8]] {{\[}}[2 x i8] c"\FF\FF"], [3 x i8] zeroinitializer }, [4 x i8] zeroinitializer, i8 6, [1 x i8] zeroinitializer, i16 33, i32 84, i64 53, i64 123 } __gshared SWithUnion explicitCompatibleSWithUnion = { ul_dummy: 53 }; // ul_dummy is an alias for dominant ul // If a dominated union field is initialized and it isn't an alias for a dominant field, // the regular LL type cannot be used, and an anonymous one is used instead. // CHECK-DAG: @{{.*}}_D5union30explicitIncompatibleSWithUnionSQBn10SWithUnion{{\"?}} = global { i8, [3 x i8], %union.S, [4 x i8], i32, i32, i64, i64 } { i8 -1, [3 x i8] zeroinitializer, %union.S { i8 -1, [3 x i8] zeroinitializer, i32 0, [2 x i8] zeroinitializer, i8 1, [1 x [2 x i8]] {{\[}}[2 x i8] c"\FF\FF"], [3 x i8] zeroinitializer }, [4 x i8] zeroinitializer, i32 23, i32 84, i64 666, i64 123 } __gshared SWithUnion explicitIncompatibleSWithUnion = { ui1: 23 }; // // ui1 dominated by ub and us struct Quat { static struct Vec { int x; } union { Vec v; struct { float x; } } static Quat identity() { Quat q; q.x = 1.0f; return q; } } // T.init may feature explicit initializers for dominated members in nested unions (GitHub issue #2108). // In that case, the init constant has an anonymous LL type as well. // CHECK-DAG: @{{.*}}_D5union33QuatContainerWithIncompatibleInit6__initZ{{\"?}} = constant { { float } } { { float } { float 1.000000e+00 } } struct QuatContainerWithIncompatibleInit { Quat q = Quat.identity; } void main() { // test dynamic literals too { SWithUnion s = { 'y' }; assert(s.c == 'y'); assert(s.nested == S.init); assert(s.ub == 6); assert(s.us == 33); assert(s.ui2 == 84); assert(s.ul == 666); assert(s.last == 123); } { SWithUnion s = { ul_dummy: 53 }; assert(s.c == char.init); assert(s.nested == S.init); assert(s.ub == 6); assert(s.us == 33); assert(s.ui2 == 84); assert(s.ul_dummy == 53); assert(s.last == 123); } { SWithUnion s = { ui1: 23 }; assert(s.c == char.init); assert(s.nested == S.init); assert(s.ui1 == 23); assert(s.ui2 == 84); assert(s.ul == 666); assert(s.last == 123); } { QuatContainerWithIncompatibleInit c; assert(c.q.x == 1.0f); } } ./ldc-1.28.0-src/tests/codegen/gh3520.d0000644000175000017500000000146714141774365017343 0ustar matthiasmatthias// Tests EH with exception types with previously identical `TypeInfo_Class.name` // (due to template args not being fully qualified - fixed since D v2.098). // RUN: %ldc -run %s struct Foo(T) { static class MyException : Exception { this() { super(null); } } } void throwAndCatch() { struct S {} Foo!S f; try { throw new f.MyException(); } catch (f.MyException) {} // issue 3501: 1st static TypeDescriptor } void doThrow() { struct S {} Foo!S f1; throw new f1.MyException(); } void throwAndDontCatchAnother() { struct S {} Foo!S f2; try { doThrow(); } catch (f2.MyException) { assert(0); } // issue 3501: 2nd static TypeDescriptor catch (Exception) { return; } assert(0); } void main() { throwAndCatch(); throwAndDontCatchAnother(); } ./ldc-1.28.0-src/tests/codegen/attr_fastmath_x86.d0000644000175000017500000000074714141774365022001 0ustar matthiasmatthias// Test vectorized fused multiply-add in a simple dot product routine // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux-gnu -mattr=+fma -O3 -release -c -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s import ldc.attributes; // ASM-LABEL: dot: @fastmath extern (C) double dot(double[] a, double[] b) { double s = 0; // ASM: vfmadd{{[123][123][123]}}pd foreach (size_t i; 0 .. a.length) { s += a[i] * b[i]; } return s; // ASM: ret } ./ldc-1.28.0-src/tests/codegen/dmd_inline_asm_fp_types.d0000644000175000017500000000166714141774365023310 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -output-s -mtriple=x86_64-windows-msvc -of=%t_msvc.s %s // RUN: FileCheck --check-prefix=COMMON --check-prefix=MSVC %s < %t_msvc.s // RUN: %ldc -output-s -mtriple=x86_64-linux-gnu -of=%t_linux.s %s // RUN: FileCheck --check-prefix=COMMON --check-prefix=LINUX %s < %t_linux.s // COMMON: _D23dmd_inline_asm_fp_types3fooFfdeZv void foo(float a, double b, real c) { asm { // COMMON: flds fld a; // COMMON-NEXT: fldl fld b; // MSVC-NEXT: fldl // LINUX-NEXT: fldt fld c; ret; } } // COMMON: _D23dmd_inline_asm_fp_types3barFPvZv void bar(void* ptr) { asm { // COMMON: flds fld float ptr [ptr]; // COMMON-NEXT: fldl fld double ptr [ptr]; // MSVC-NEXT: fldl // LINUX-NEXT: fldt fld real ptr [ptr]; // COMMON-NEXT: fldt fld extended ptr [ptr]; ret; } } ./ldc-1.28.0-src/tests/codegen/asm_data_directives.d0000644000175000017500000000263614141774365022424 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s // RUN: FileCheck %s < %t.s // CHECK: _D19asm_data_directives14_rdrand32_stepFPkZi: int _rdrand32_step(uint* r) { int ret; asm { // CHECK: movl -12(%rbp), %eax mov EAX, ret; // CHECK-NEXT: .byte 15 // CHECK-NEXT: .byte 199 // CHECK-NEXT: .byte 240 db 0x0F, 0xC7, 0xF0; // rdrand EAX // CHECK-NEXT: movl %eax, -12(%rbp) mov ret, EAX; } if (ret != 0) { *r = ret; return 1; } return 0; } // CHECK: _D19asm_data_directives3fooFZv: void foo() { asm { // CHECK: .byte 1 // CHECK-NEXT: .byte 128 db 1, 0x80; // CHECK-NEXT: .short 2 // CHECK-NEXT: .short 256 ds 2, 0x100; // CHECK-NEXT: .long 3 // CHECK-NEXT: .long 65536 di 3, 0x10000; // CHECK-NEXT: .quad 4 // CHECK-NEXT: .quad 4294967296 dl 4, 0x100000000; // CHECK-NEXT: .long 1065353216 // CHECK-NEXT: .long 1069547520 df 1.0f, 1.5f; // CHECK-NEXT: .quad 4607182418800017408 // CHECK-NEXT: .quad 4609434218613702656 dd 1.0, 1.5; // CHECK-NEXT: .quad -9223372036854775808 // CHECK-NEXT: .short 16383 // CHECK-NEXT: .quad -4611686018427387904 // CHECK-NEXT: .short 16383 de 1.0L, 1.5L; } } ./ldc-1.28.0-src/tests/codegen/attr_llvmFMF.d0000644000175000017500000000250714141774365020764 0ustar matthiasmatthias// Test @ldc.attributes.llvmFastMathFlag UDA // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: not %ldc -c -w -d-version=WARNING %s 2>&1 | FileCheck %s --check-prefix WARNING import ldc.attributes; version(WARNING) { // WARNING: attr_llvmFMF.d(11): Warning: ignoring unrecognized flag parameter `unrecognized` for `@ldc.attributes.llvmFastMathFlag` @llvmFastMathFlag("unrecognized") void foo() {} } // LLVM-LABEL: define{{.*}} @notfast // LLVM-SAME: #[[ATTR_NOTFAST:[0-9]+]] extern (C) double notfast(double a, double b) { @llvmFastMathFlag("fast") double nested_fast(double a, double b) { return a * b; } // LLVM: fmul double return a * b; } // LLVM-LABEL: define{{.*}} @{{.*}}nested_fast // LLVM: fmul fast double // LLVM-LABEL: define{{.*}} @{{.*}}nnan_arcp @llvmFastMathFlag("nnan") @llvmFastMathFlag("arcp") double nnan_arcp(double a, double b) { // LLVM: fmul nnan arcp double return a * b; } // LLVM-LABEL: define{{.*}} @{{.*}}ninf_nsz @llvmFastMathFlag("ninf") @llvmFastMathFlag("nsz") double ninf_nsz(double a, double b) { // LLVM: fmul ninf nsz double return a * b; } // LLVM-LABEL: define{{.*}} @{{.*}}cleared @llvmFastMathFlag("ninf") @llvmFastMathFlag("clear") double cleared(double a, double b) { // LLVM: fmul double return a * b; } ./ldc-1.28.0-src/tests/codegen/no_abi_blit_for_nonpod.d0000644000175000017500000000067114141774365023113 0ustar matthiasmatthias// Tests that a small non-POD isn't implicitly blit when being passed to/ // returned from a called function. // RUN: %ldc -run %s struct S { S* self; this(this) { self = &this; } ~this() { assert(self == &this); } } S foo(S param) { return param; // copy-construct return value // destruct param } void main() { S s; s.self = &s; S r = foo(s); // copy-construct tmp arg from s // destruct r and s } ./ldc-1.28.0-src/tests/codegen/inlining_leakdefinitions.d0000644000175000017500000000370714141774365023471 0ustar matthiasmatthias// Test that inlining does not leak definitions without marking them as available_externally // "Leaking" = symbols definitions in .o file that shouldn't be declarations instead (undefined symbols). // RUN: %ldc %s -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -I%S -c -output-ll -release -enable-inlining -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll // RUN: %ldc -I%S -enable-inlining -enable-cross-module-inlining %S/inputs/inlinables.d -run %s // RUN: %ldc -I%S -O3 -enable-cross-module-inlining %S/inputs/inlinables.d -run %s import inputs.inlinables; extern (C): // simplify mangling for easier matching // Check that the global variables that are added due to "available_externally // inlining" do not have initializers, i.e. they are declared only and not definined. // OPT3-DAG: @module_variable = external thread_local{{.*}} global i32, align // OPT3-DAG: @{{.*}}write_function_static_variableUiZ15static_func_vari{{\"?}} = external thread_local{{.*}} global i32, align // OPT0-LABEL: define{{.*}} @call_class_function( // OPT3-LABEL: define{{.*}} @call_class_function( int call_class_function(A a) { // There should be only one call to "virtual_func". // OPT3: call // OPT3-NOT: call return a.final_func(); // There should be a return from an LLVM variable (not a direct value) // OPT0: ret i32 % // OPT3: ret i32 % } // OPT0-LABEL: define{{.*}} @dont_leak_module_variables( // OPT3-LABEL: define{{.*}} @dont_leak_module_variables( void dont_leak_module_variables() { write_module_variable(987); write_function_static_variable(167); get_typeid_A(); // OPT0: ret void // OPT3: ret void } // OPT0-LABEL: define{{.*}} @main( // OPT3-LABEL: define{{.*}} @main( int main() { dont_leak_module_variables(); return 0; // OPT0: ret i32 0 // OPT3: ret i32 0 } ./ldc-1.28.0-src/tests/codegen/gh2235.d0000644000175000017500000000066514141774365017344 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s // CHECK-DAG: %gh2235.Foo = type <{ align(2) struct Foo { long y; byte z; } // CHECK-DAG: %gh2235.Bar = type <{ class Bar { union { bool b; Foo foo; } byte x; void set(Foo f) { x = 99; foo = f; } } void main() { Bar bar = new Bar(); Foo f; bar.set(f); assert(bar.x == 99); } ./ldc-1.28.0-src/tests/codegen/noplt.d0000644000175000017500000000035314141774365017560 0ustar matthiasmatthias// RUN: %ldc --output-ll --fno-plt -of=%t.ll %s && FileCheck %s -check-prefix=CHECK-NOPLT < %t.ll // CHECK-NOPLT: Function Attrs: nonlazybind // CHECK-NOPLT-NEXT: declare {{.*}} @{{.*}}3foo int foo(); int bar() { return foo(); } ./ldc-1.28.0-src/tests/codegen/gh2131.d0000644000175000017500000000061114141774365017326 0ustar matthiasmatthias// RUN: %ldc -O3 -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // CHECK: define {{.*}}zeroext {{.*}}@{{.*}}_D6gh21313foo // CHECK-SAME: i1 zeroext %x_arg bool foo(bool x, ref bool o) { // CHECK-NOT: and i8 // CHECK: load i8{{.*}}, !range ![[META:[0-9]+]] // CHECK-NOT: and i8 o |= x; // CHECK: ret return o; } // CHECK: ![[META]] = {{.*}}!{i8 0, i8 2} ./ldc-1.28.0-src/tests/codegen/rvo.d0000644000175000017500000000065114141774365017233 0ustar matthiasmatthias// RUN: %ldc -run %s struct S { int x; S* self; this(int x) { this.x = x; self = &this; } ~this() { assert(self is &this); } } S makeS() { return S(2); // one form of RVO: .ctor(2) } S nrvo() { S ret = makeS(); return ret; } S rvo() { return makeS(); } void main() { auto s = makeS(); auto nrvo = nrvo(); auto rvo = rvo(); } ./ldc-1.28.0-src/tests/codegen/simd_unaligned.d0000644000175000017500000000417614141774365021415 0ustar matthiasmatthias// Tests unaligned load and stores of SIMD types // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s import core.simd; import ldc.simd; // CHECK-LABEL: define{{.*}} @{{.*}}loads void loads(void *p) { // CHECK: load <4 x float>{{.*}} align 1 loadUnaligned!float4(cast(float*)p); const float[4] f4buf = void; immutable double[2] f8buf = void; ubyte[16] u1buf = void; ushort[8] u2buf = void; uint[4] u4buf = void; ulong[2] u8buf = void; byte[16] i1buf = void; short[8] i2buf = void; int[4] i4buf = void; long[2] i8buf = void; // CHECK: load <4 x float>{{.*}} align 1 loadUnaligned!float4(f4buf.ptr); // CHECK: load <2 x double>{{.*}} align 1 loadUnaligned!double2(f8buf.ptr); // CHECK: load <16 x i8>{{.*}} align 1 loadUnaligned!ubyte16(u1buf.ptr); // CHECK: load <8 x i16>{{.*}} align 1 loadUnaligned!ushort8(u2buf.ptr); // CHECK: load <4 x i32>{{.*}} align 1 loadUnaligned!uint4(u4buf.ptr); // CHECK: load <2 x i64>{{.*}} align 1 loadUnaligned!ulong2(u8buf.ptr); // CHECK: load <16 x i8>{{.*}} align 1 loadUnaligned!byte16(i1buf.ptr); // CHECK: load <8 x i16>{{.*}} align 1 loadUnaligned!short8(i2buf.ptr); // CHECK: load <4 x i32>{{.*}} align 1 loadUnaligned!int4(i4buf.ptr); // CHECK: load <2 x i64>{{.*}} align 1 loadUnaligned!long2(i8buf.ptr); } // CHECK-LABEL: define{{.*}} @{{.*}}stores void stores(void *p) { float8 f8 = void; int8 i8 = void; // CHECK: store <8 x float>{{.*}} align 1 storeUnaligned!float8(f8, cast(float*)p); // CHECK: store <8 x i32>{{.*}} align 1 storeUnaligned!int8(i8, cast(int*)p); } void checkStore(int *a) { immutable int4 v = [0, 10, 20, 30]; // CHECK: store <4 x i32>{{.*}} align 1 storeUnaligned!int4(v, a); assert(v.array == a[0..4]); } void main() { loads(getMisalignedPtr()); stores(getMisalignedPtr()); checkStore(cast(int*)getMisalignedPtr()); } import ldc.attributes; align(32) char[100] dummy = void; void* getMisalignedPtr() @weak // disallows reasoning and inlining of this function { return &dummy[1]; }; ./ldc-1.28.0-src/tests/codegen/gh1728.d0000644000175000017500000000054614141774365017350 0ustar matthiasmatthias// RUN: %ldc -run %s struct OpApply { int opApply(int delegate(int) cb) { return cb(42); } } struct Bolinha { int a; this(ref OpApply moviadao) { foreach(int b; moviadao) { this.a = b; return; } } } void main() { OpApply range; const s = Bolinha(range); assert(s.a == 42); } ./ldc-1.28.0-src/tests/codegen/unknown_critical_section_size.d0000644000175000017500000000033514141774365024553 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64 -c -w %s // no target OS version (FreeStanding) {} else static assert(0); void foo() { __gshared int global; synchronized { global += 10; } } ./ldc-1.28.0-src/tests/codegen/gh2537.d0000644000175000017500000000123614141774365017344 0ustar matthiasmatthias// RUN: %ldc -run %s void main() { int[string] aa = [ "one": 123 ]; typeof(null) nul; auto sum = nul + nul; auto diff = nul - nul; assert(aa + nul == aa); assert(nul + aa == aa); assert(aa - nul == aa); assert(nul - aa == aa); static assert(!__traits(compiles, nul * nul)); static assert(!__traits(compiles, aa * nul)); static assert(!__traits(compiles, nul / nul)); static assert(!__traits(compiles, aa / nul)); static assert(!__traits(compiles, nul % nul)); static assert(!__traits(compiles, aa % nul)); static assert(!__traits(compiles, nul & nul)); static assert(!__traits(compiles, aa | nul)); } ./ldc-1.28.0-src/tests/codegen/export_aggregate_symbols.d0000644000175000017500000000466214141774365023532 0ustar matthiasmatthias// Tests -fvisibility={default,hidden} for special symbols generated for // aggregates on non-Windows targets. // UNSUPPORTED: Windows // RUN: %ldc %s -shared -fvisibility=default -of=lib%t_default%so // RUN: nm -g lib%t_default%so | FileCheck -check-prefix=DEFAULT -check-prefix=BOTH %s // RUN: %ldc %s -shared -fvisibility=hidden -of=lib%t_hidden%so // RUN: nm -g lib%t_hidden%so | FileCheck -check-prefix=HIDDEN -check-prefix=BOTH %s // DEFAULT: _D24export_aggregate_symbols8DefaultC11__interface24export_aggregate_symbols8DefaultI{{.*}}__vtblZ // HIDDEN-NOT: _D24export_aggregate_symbols8DefaultC11__interface24export_aggregate_symbols8DefaultI{{.*}}__vtblZ // DEFAULT: _D24export_aggregate_symbols8DefaultC16__interfaceInfosZ // HIDDEN-NOT: _D24export_aggregate_symbols8DefaultC16__interfaceInfosZ // DEFAULT: _D24export_aggregate_symbols8DefaultC6__initZ // HIDDEN-NOT: _D24export_aggregate_symbols8DefaultC6__initZ // DEFAULT: _D24export_aggregate_symbols8DefaultC6__vtblZ // HIDDEN-NOT: _D24export_aggregate_symbols8DefaultC6__vtblZ // DEFAULT: _D24export_aggregate_symbols8DefaultC7__ClassZ // HIDDEN-NOT: _D24export_aggregate_symbols8DefaultC7__ClassZ class DefaultC : DefaultI { void foo() {} } // DEFAULT: _D24export_aggregate_symbols8DefaultI11__InterfaceZ // HIDDEN-NOT: _D24export_aggregate_symbols8DefaultI11__InterfaceZ interface DefaultI { void foo(); } // DEFAULT: _D24export_aggregate_symbols8DefaultS6__initZ // HIDDEN-NOT: _D24export_aggregate_symbols8DefaultS6__initZ struct DefaultS { int nonZero = 1; } // BOTH: _D24export_aggregate_symbols9ExportedC11__interface24export_aggregate_symbols9ExportedI{{.*}}__vtblZ // BOTH: _D24export_aggregate_symbols9ExportedC16__interfaceInfosZ // BOTH: _D24export_aggregate_symbols9ExportedC6__initZ // BOTH: _D24export_aggregate_symbols9ExportedC6__vtblZ // BOTH: _D24export_aggregate_symbols9ExportedC7__ClassZ export class ExportedC : ExportedI { void foo() {} } // BOTH: _D24export_aggregate_symbols9ExportedI11__InterfaceZ export interface ExportedI { void foo(); } // BOTH: _D24export_aggregate_symbols9ExportedS6__initZ export struct ExportedS { int nonZero = 1; } // struct TypeInfos: // DEFAULT: _D45TypeInfo_S24export_aggregate_symbols8DefaultS6__initZ // HIDDEN-NOT: _D45TypeInfo_S24export_aggregate_symbols8DefaultS6__initZ auto ti_defaultS = typeid(DefaultS); // BOTH: _D46TypeInfo_S24export_aggregate_symbols9ExportedS6__initZ auto ti_exportedS = typeid(ExportedS); ./ldc-1.28.0-src/tests/codegen/const_struct_export.d0000644000175000017500000000177614141774365022571 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // CHECK: @.immutablearray{{.*}} = internal constant [2 x void ()*] {{.*}}exportedFunction // CHECK-NOT: @.immutablearray{{.*}} [2 x void ()*] {{.*}}importedFunction // CHECK: @.immutablearray{{.*}} = internal constant [2 x i32*] {{.*}}exportedVariable // CHECK-NOT: @.immutablearray{{.*}} [2 x i32*] {{.*}}importedVariable export void exportedFunction() {} export void importedFunction(); export immutable int exportedVariable = 1; export immutable int importedVariable; void foo () { immutable auto exportedFuncs = [ &exportedFunction, &exportedFunction ]; immutable auto importedFuncs = [ &importedFunction, &importedFunction ]; // CHECK: store void ()* @{{.*}}D19const_struct_export16importedFunctionFZv immutable auto exportedVars = [ &exportedVariable, &exportedVariable ]; immutable auto importedVars = [ &importedVariable, &importedVariable ]; // CHECK: store i32* @{{.*}}D19const_struct_export16importedVariable } ./ldc-1.28.0-src/tests/codegen/in_place_construct_asm.d0000644000175000017500000000134014141774365023137 0ustar matthiasmatthias// Tests in-place construction of structs returned by inline assembly (issue #1823). // Target Win64 for simplicity (e.g., 4x32-bit struct not returned in memory for non-Windows x64). // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-pc-windows-msvc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.llvmasm; // CHECK-LABEL: define{{.*}} @{{.*}}_D22in_place_construct_asm14inlineAssemblyFkkZv void inlineAssembly(uint eax, uint ecx) { // CHECK: store %"ldc.llvmasm.__asmtuple_t!(uint, uint, uint, uint).__asmtuple_t" %3, %"ldc.llvmasm.__asmtuple_t!(uint, uint, uint, uint).__asmtuple_t"* %r auto r = __asmtuple!(uint, uint, uint, uint) ("cpuid", "={eax},={ebx},={ecx},={edx},{eax},{ecx}", eax, ecx); } ./ldc-1.28.0-src/tests/codegen/betterC_typeinfo.d0000644000175000017500000000053714141774365021735 0ustar matthiasmatthias// Make sure the file can be compiled and linked successfully with -betterC. // Also test that druntime and Phobos aren't in the linker command line. // RUN: %ldc -betterC %s -v > %t.log // RUN: FileCheck %s < %t.log // CHECK-NOT: druntime-ldc // CHECK-NOT: phobos2-ldc struct MyStruct { int a; } extern (C) void main() { auto s = MyStruct(); } ./ldc-1.28.0-src/tests/codegen/inferred_outputname.d0000644000175000017500000000121714141774365022503 0ustar matthiasmatthias// Make sure the inferred output filename is based on the first (source or // object) file, and independent from its module declaration. // If it works on Windows, it will work on other platforms too, and it // simplifies things a bit. // REQUIRES: Windows // 1) 2 object files compiled separately: // RUN: %ldc -c %S/inputs/foo.d -of=%t-dir/foo%obj // RUN: %ldc %s %t-dir/foo%obj -vv | FileCheck %s // 2) singleObj build with external object file and 2 source files: // RUN: %ldc %t-dir/foo%obj %s %S/inputs/attr_weak_input.d -vv | FileCheck %s // CHECK: Linking with: // CHECK-NEXT: '/OUT:inferred_outputname.exe' module modulename; void main() {} ./ldc-1.28.0-src/tests/codegen/export_marked_symbols1.d0000644000175000017500000000154414141774365023124 0ustar matthiasmatthias// Tests -fvisibility={default,hidden} for function definitions and // (non-extern) globals on non-Windows targets. // UNSUPPORTED: Windows // RUN: %ldc %s -betterC -shared -fvisibility=default -of=lib%t_default%so // RUN: nm -g lib%t_default%so | FileCheck -check-prefix=DEFAULT %s // RUN: %ldc %s -betterC -shared -fvisibility=hidden -of=lib%t_hidden%so // RUN: nm -g lib%t_hidden%so | FileCheck -check-prefix=HIDDEN %s extern(C) export int test__exportedFun() { return 42; } // DEFAULT: test__exportedFun // HIDDEN: test__exportedFun extern(C) export int test__exportedVar; // DEFAULT: test__exportedVar // HIDDEN: test__exportedVar extern(C) int test__nonExportedFun() { return 101; } // DEFAULT: test__nonExportedFun // HIDDEN-NOT: test__nonExportedFun extern(C) int test__nonExportedVar; // DEFAULT: test__nonExportedVar // HIDDEN-NOT: test__nonExportedVar ./ldc-1.28.0-src/tests/codegen/export_marked_symbols_thin_lto.d0000644000175000017500000000076414141774365024746 0ustar matthiasmatthias// Tests that mismatching symbol visibilities between declarations and definitions // work with thin LTO. // REQUIRES: LTO // RUN: %ldc %S/inputs/export_marked_symbols_lib.d -c -fvisibility=hidden -flto=thin -of=%t_lib%obj // RUN: %ldc %s -I%S/inputs -flto=thin -of=%t%exe %t_lib%obj import export_marked_symbols_lib; void main() { exportedGlobal = 1; normalGlobal = 2; // declared in this module with default visibility, defined as hidden exportedFoo(); normalFoo(); // ditto } ./ldc-1.28.0-src/tests/codegen/wasi.d0000644000175000017500000000205414141774365017367 0ustar matthiasmatthias// REQUIRES: atleast_llvm900, target_WebAssembly, link_WebAssembly // emit textual IR *and* compile & link // RUN: %ldc -mtriple=wasm32-unknown-wasi -output-ll -output-o -of=%t.wasm %s // RUN: FileCheck %s < %t.ll // test predefined versions: version (WASI) {} else static assert(0); version (CRuntime_WASI) {} else static assert(0); // make sure TLS globals are emitted as regular __gshared globals: // CHECK: @_D4wasi13definedGlobali = global i32 123 int definedGlobal = 123; // CHECK: @_D4wasi14declaredGlobali = external global i32 extern int declaredGlobal; // make sure the ModuleInfo ref is emitted into the __minfo section: // CHECK: @_D4wasi11__moduleRefZ = linkonce_odr hidden global %object.ModuleInfo* {{.*}}, section "__minfo" // CHECK: @llvm.used = appending global [1 x i8*] [i8* {{.*}} @_D4wasi11__moduleRefZ // test the magic linker symbols via linkability of the following: extern(C) extern __gshared { void* __start___minfo; void* __stop___minfo; } extern(C) void _start() { auto size = __stop___minfo - __start___minfo; } ./ldc-1.28.0-src/tests/codegen/attr_assumeused.d0000644000175000017500000000054514141774365021637 0ustar matthiasmatthias// Tests @assumeUsed attribute // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // CHECK: @llvm.used = appending global {{.*}} @some_function {{.*}} @some_variable static import ldc.attributes; extern (C): // For easier name mangling @(ldc.attributes.assumeUsed) void some_function() { } @(ldc.attributes.assumeUsed) int some_variable; ./ldc-1.28.0-src/tests/codegen/complex_identity_gh2918.d0000644000175000017500000000052614141774365023010 0ustar matthiasmatthias// RUN: %ldc -run %s void main() { creal f1 = +0.0 + 0.0i; creal f2 = +0.0 - 0.0i; creal f3 = -0.0 + 0.0i; creal f4 = +0.0 + 0.0i; assert(f1 !is f2); assert(f1 !is f3); assert(f2 !is f3); assert(f1 is f4); assert(!(f1 is f2)); assert(!(f1 is f3)); assert(!(f2 is f3)); assert(!(f1 !is f4)); } ./ldc-1.28.0-src/tests/codegen/return_statement.d0000644000175000017500000000053114141774365022025 0ustar matthiasmatthias// RUN: %ldc -run %s struct S { __gshared int numDtor; int a; ~this() { ++numDtor; a = 0; } ref int val() return { return a; } } S make() { return S(2); } int call() { return make().val; } int literal() { return S(123).val; } void main() { assert(call() == 2); assert(literal() == 123); assert(S.numDtor == 2); } ./ldc-1.28.0-src/tests/codegen/nested_gh2960.d0000644000175000017500000000122614141774365020705 0ustar matthiasmatthias// RUN: %ldc -run %s template listDir(alias handler) { struct NestedStruct { void callHandler() { handler(); } } class NestedClass { void callHandler() { handler(); } } void nestedFunc() { handler(); } void listDir() { int a = 123; void foo() { assert(a == 123); } // pass local listDir() frame as context foo(); // pass parent context for sibling symbols: NestedStruct().callHandler(); (new NestedClass).callHandler(); nestedFunc(); } } void main() { int magic = 0xDEADBEEF; listDir!(() { assert(magic == 0xDEADBEEF); })(); } ./ldc-1.28.0-src/tests/codegen/gh1433.d0000644000175000017500000000334514141774365017341 0ustar matthiasmatthias// RUN: %ldc -run %s @safe: int step; int[] globalArray; void reset(int initialStep) { step = initialStep; globalArray = [ -1, -2, -3, -4 ]; } int[] getBaseSlice() { assert(step++ == 0); return globalArray; } ref int[] getBaseSliceRef() { assert(step++ == 0); return globalArray; } int getLowerBound(size_t dollar) { assert(step++ == 1); assert(dollar == 4); globalArray = null; return 1; } int getUpperBound(size_t dollar, size_t expectedDollar) { assert(step++ == 2); assert(dollar == expectedDollar); globalArray = [ 1, 2, 3 ]; return 3; } // https://github.com/ldc-developers/ldc/issues/1433 void main() { reset(0); auto r = getBaseSlice()[getLowerBound($) .. getUpperBound($, 4)]; assert(r == [ -2, -3 ]); // old buffer // LDC and GDC treat $ as lvalue and load .length each time it is accessed // DMD apparently treats it as rvalue and loads it once at the beginning (=> wrong bounds check) version(DigitalMars) enum expectedDollar = 4; else enum expectedDollar = 0; reset(1); r = globalArray[getLowerBound($) .. getUpperBound($, expectedDollar)]; assert(r == [ 2, 3 ]); // new buffer reset(0); r = getBaseSliceRef()[getLowerBound($) .. getUpperBound($, expectedDollar)]; version(DigitalMars) assert(r == [ -2, -3 ]); // old buffer else assert(r == [ 2, 3 ]); // new buffer testBoundsCheck(); } void testBoundsCheck() @trusted // @trusted needed for catching Errors, otherwise @safe { import core.exception : RangeError; reset(1); try { auto r = globalArray[getLowerBound($) .. 2]; // null[1 .. 2] assert(0); // fails for DMD } catch (RangeError) {} } ./ldc-1.28.0-src/tests/codegen/inlining_stdlib.d0000644000175000017500000000207414141774365021576 0ustar matthiasmatthias// Test inlining of some standard library functions // RUN: %ldc %s -c -output-ll -release -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll // RUN: %ldc %s -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll extern (C): // simplify mangling for easier matching // OPT0-LABEL: define{{.*}} @foo( // OPT3-LABEL: define{{.*}} @foo( int foo(size_t i) { // core.bitop.bsf() is force-inlined import core.bitop; // OPT0: call {{.*}} @llvm.cttz // OPT3: call {{.*}} @llvm.cttz return bsf(i); // OPT0: ret // OPT3: ret } // OPT0-LABEL: define{{.*}} @ggg( // OPT3-LABEL: define{{.*}} @ggg( double ggg(double r) { // std.math.nextDown() is inlined when optimizing import std.math; // OPT0: call {{.*}} @{{.*}}D3std4math10operations8nextDown // OPT3: call {{.*}} @{{.*}}D3std4math10operations6nextUp return nextDown(r); // OPT0: ret // OPT3: ret } // OPT0: declare {{.*}}D3std4math10operations8nextDown // OPT3: declare {{.*}}D3std4math10operations6nextUp ./ldc-1.28.0-src/tests/codegen/const_cond.d0000644000175000017500000000261114141774365020554 0ustar matthiasmatthias// Make sure that the dead code of an `if` (and `else if`) is elminated when the condition is constant. // If the condition value is constant, there are two cases: // 1) It is 0 (false) -> Generate the else block (if it exists) with no branching. // 2) It is non-0 (true) -> Generate the if block with no branching. // Also, verify it _does_ generate correct code when it is not constant. // RUN: %ldc -O0 -output-ll -of=%t.ll %s && FileCheck %s < %t.ll extern(C): //to avoid name mangling. // CHECK-LABEL: @foo void foo() { // CHECK-NOT: %a = alloca // CHECK: %b = alloca // CHECK-NOT: br // CHECK-NOT: store i32 1, i32* %a // CHECK: store i32 2, i32* %b if (0) { int a = 1; } else { int b = 2; } } // CHECK-LABEL: @bar void bar() { // CHECK-NOT: %a = alloca // CHECK: store i32 2, i32* %b if (0) { int a = 1; } else if(1) { int b = 2; } } // CHECK-LABEL: @only_ret void only_ret() { // CHECK-NEXT: ret void // CHECK-NEXT: } if (1 && (2 - 2)) { int a = 1; } } // CHECK-LABEL: @only_ret2 void only_ret2() { // CHECK-NEXT: ret void // CHECK-NEXT: } if (0) { int a = 1; } else if(0) { int b = 2; } } // CHECK-LABEL: @gen_br void gen_br(immutable int a) { // CHECK-COUNT-1: br if (a) { int b = 1; } } ./ldc-1.28.0-src/tests/codegen/attr_param.d0000644000175000017500000000111714141774365020555 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; // CHECK: define{{.*}} @{{.*}}3foo // CHECK-SAME: i8*{{.*}} noalias %p_arg void foo(@llvmAttr("noalias") void* p) {} // CHECK: define{{.*}} @{{.*}}3bar // CHECK-SAME: [16 x float]*{{.*}} noalias dereferenceable(64) %kernel // CHECK-SAME: float*{{.*}} noalias %data_arg void bar(@restrict float* data, @restrict ref const float[16] kernel) {} // CHECK: define{{.*}} @{{.*}}14classReference // CHECK-SAME: %object.Object*{{.*}} noalias %obj_arg void classReference(@restrict Object obj) {} ./ldc-1.28.0-src/tests/codegen/array_equals_memcmp_neverinvoke.d0000644000175000017500000000134214141774365025064 0ustar matthiasmatthias// Tests that memcmp array comparisons `call` memcmp instead of `invoke`. // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix=LLVM < %t.ll // When the user defines memcmp, it overrides the prototype defined by LDC. // The user's prototype does not have the nounwind attribute, and a call to memcmp may become `invoke`. extern(C) int memcmp(void*, void*, size_t); void foo(); // Test that memcmp is not `invoked` // LLVM-LABEL: define{{.*}} @{{.*}}never_invoke void never_invoke(bool[2] a, bool[2] b) { try { // LLVM: call i32 @memcmp({{.*}}, {{.*}}, i{{32|64}} 2) auto result = a == b; foo(); // Compiler has to assume that this may throw } catch (Exception e) { } } ./ldc-1.28.0-src/tests/codegen/vector_init.d0000644000175000017500000000426414141774365020756 0ustar matthiasmatthias// Make sure vector initializer llvm::Constants are generated correctly (GitHub #2101). // RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll alias D2 = __vector(double[2]); // CHECK: @{{.*}}_D11vector_init12ImplicitInit6__initZ{{\"?}} = // CHECK-SAME: { <2 x double> } struct ImplicitInit { D2 a; } // CHECK: @{{.*}}_D11vector_init12ExplicitInit6__initZ{{\"?}} = // CHECK-SAME: { <2 x double> } struct ExplicitInit { D2 a = D2.init; } // CHECK: @{{.*}}_D11vector_init10SplatValue6__initZ{{\"?}} = // CHECK-SAME: { <2 x double> } struct SplatValue { D2 a = 1.0; } // CHECK: @{{.*}}_D11vector_init13ElementValues6__initZ{{\"?}} = // CHECK-SAME: { <2 x double> } struct ElementValues { D2 a = [1.0, 2.0]; } // CHECK: define {{.*}}_D11vector_init3foo void foo() { alias void16 = __vector(void[16]); alias short8 = __vector(short[8]); // CHECK-NEXT: %v16 = alloca <16 x i8> // CHECK-NEXT: %s8 = alloca <8 x i16> // CHECK-NEXT: %d2 = alloca <2 x double> // CHECK-NEXT: store <16 x i8> zeroinitializer, <16 x i8>* %v16 // CHECK-NEXT: store <8 x i16> , <8 x i16>* %s8 // CHECK-NEXT: store <2 x double> , <2 x double>* %d2 // CHECK-NEXT: ret void void16 v16; short8 s8 = [1, 2, 3, 4, 5, 6, 7, 8]; D2 d2 = 1.5; } // https://github.com/ldc-developers/ldc/issues/3418 // CHECK: define {{.*}}_D11vector_init3bar void bar(const ref float[4] floats, const(int)[] ints) { alias float4 = __vector(float[4]); alias int4 = __vector(int[4]); // CHECK: %[[f:[0-9]+]] = bitcast <4 x float>* %f to i8* // CHECK: call void @llvm.memcpy{{.*}}(i8*{{[^,]*}} %[[f]] auto f = cast(float4) floats; // CHECK: %[[i:[0-9]+]] = bitcast <4 x i32>* %i to i8* // CHECK: call void @llvm.memcpy{{.*}}(i8*{{[^,]*}} %[[i]] auto i = cast(int4) ints; // CHECK: fptosi // CHECK: fptosi // CHECK: fptosi // CHECK: fptosi auto converted = cast(int4) floats; } ./ldc-1.28.0-src/tests/codegen/cmpxchg.d0000644000175000017500000000130014141774365020046 0ustar matthiasmatthias// RUN: %ldc -O -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import core.atomic; // CHECK: define {{.*}}_D7cmpxchg3fooFiZb bool foo(int cmp) { static shared int g; // CHECK-NEXT: %1 = cmpxchg i32* // CHECK-NEXT: %2 = extractvalue { i32, i1 } %1, 1 // CHECK-NEXT: ret i1 %2 return cas(&g, cmp, 456); } // CHECK: define {{.*}}_D7cmpxchg3barFdZd double bar(double cmp) { static shared double g; // CHECK-NEXT: %1 = bitcast double %cmp_arg to i64 // CHECK-NEXT: %2 = cmpxchg weak i64* casWeak(&g, &cmp, 456.0); // CHECK-NEXT: %3 = extractvalue { i64, i1 } %2, 0 // CHECK-NEXT: %4 = bitcast i64 %3 to double // CHECK-NEXT: ret double %4 return cmp; } ./ldc-1.28.0-src/tests/codegen/gh3692.d0000644000175000017500000000372414141774365017353 0ustar matthiasmatthias// https://github.com/ldc-developers/ldc/issues/3692 // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux-gnu -output-ll -of=%t.ll %s // RUN: FileCheck %s < %t.ll // D `int[3]` rewritten to LL `{ i64, i32 }` for SysV ABI - mismatching size and alignment // CHECK: define void @_D6gh36924takeFG3iZv({ i64, i32 } %a_arg) void take(int[3] a) { // the `{ i64, i32 }` size is 16 bytes, so we need a padded alloca (with 8-bytes alignment) // CHECK-NEXT: %.BaseBitcastABIRewrite_param_storage = alloca { i64, i32 }, align 8 // CHECK-NEXT: store { i64, i32 } %a_arg, { i64, i32 }* %.BaseBitcastABIRewrite_param_storage // CHECK-NEXT: %a = bitcast { i64, i32 }* %.BaseBitcastABIRewrite_param_storage to [3 x i32]* } // CHECK: define void @_D6gh36924passFZv() void pass() { // CHECK-NEXT: %arrayliteral = alloca [3 x i32], align 4 // we need an extra padded alloca with proper alignment // CHECK-NEXT: %.BaseBitcastABIRewrite_padded_arg_storage = alloca { i64, i32 }, align 8 // CHECK: %.BaseBitcastABIRewrite_arg = load { i64, i32 }, { i64, i32 }* %.BaseBitcastABIRewrite_padded_arg_storage take([1, 2, 3]); } // D `int[4]` rewritten to LL `{ i64, i64 }` for SysV ABI - mismatching alignment only // CHECK: define void @_D6gh36925take4FG4iZv({ i64, i64 } %a_arg) void take4(int[4] a) { // the alloca should have 8-bytes alignment, even though a.alignof == 4 // CHECK-NEXT: %a = alloca [4 x i32], align 8 // CHECK-NEXT: %1 = bitcast [4 x i32]* %a to { i64, i64 }* // CHECK-NEXT: store { i64, i64 } %a_arg, { i64, i64 }* %1 } // CHECK: define void @_D6gh36925pass4FZv() void pass4() { // CHECK-NEXT: %arrayliteral = alloca [4 x i32], align 4 // we need an extra alloca with 8-bytes alignment // CHECK-NEXT: %.BaseBitcastABIRewrite_padded_arg_storage = alloca { i64, i64 }, align 8 // CHECK: %.BaseBitcastABIRewrite_arg = load { i64, i64 }, { i64, i64 }* %.BaseBitcastABIRewrite_padded_arg_storage take4([1, 2, 3, 4]); } ./ldc-1.28.0-src/tests/codegen/mangling_real_real.d0000644000175000017500000000162114141774365022225 0ustar matthiasmatthias// Tests that repeated `real` return types are treated as built-in types in C++ mangling (no substitution). // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix=LINUX < %t.ll // RUN: %ldc -mtriple=x86_64-android -c -output-ll -of=%t.android.ll %s && FileCheck %s --check-prefix=ANDROID < %t.android.ll // RUN: %ldc -mtriple=x86_64-windows -c -output-ll -of=%t.windows.ll %s && FileCheck %s --check-prefix=WINDOWS < %t.windows.ll import core.stdc.config; // LINUX: define {{.*}}Z8withrealee // ANDROID: define {{.*}}Z8withrealgg // WINDOWS: define {{.*}}?withreal@@YAXOO@Z extern (C++) void withreal(real a, real b) { } // LINUX: define {{.*}}Z15withclongdoubleee // ANDROID: define {{.*}}Z15withclongdoublegg // WINDOWS: define {{.*}}?withclongdouble@@YAXOO@Z extern (C++) void withclongdouble(c_long_double a, c_long_double b) { } ./ldc-1.28.0-src/tests/codegen/vector_ops.d0000644000175000017500000000217214141774365020610 0ustar matthiasmatthias// RUN: %ldc -run %s import core.simd; void main() { static void testGenericOps(T)() { const T v = [ 1, -2, 3, -4 ]; assert(-v == [ -1, 2, -3, 4 ]); assert(+v == v); T v2 = v; assert(v2 == v && !(v2 != v)); assert(v2 is v && !(v2 !is v)); v2[0] = 0; assert(v2 != v && !(v2 == v)); assert(v2 !is v && !(v2 is v)); assert(v + v == [ 2, -4, 6, -8 ]); assert(v - v == T(0)); assert(v * v == [ 1, 4, 9, 16 ]); assert(v / v == T(1)); assert(v % T(3) == [ 1, -2, 0, -1 ]); } testGenericOps!float4(); testGenericOps!int4(); const float4 nan = float.nan; assert(nan != nan && !(nan == nan)); assert(nan is nan && !(nan !is nan)); const int4 i = [ 1, 2, 3, 4 ]; assert(i << i == [ 2, 8, 24, 64 ]); const int4 a = [ 0b1, 0b10, 0b101, 0b100011 ]; const int4 b = 0b110; assert((a & b) == [ 0, 0b10, 0b100, 0b10 ]); assert((a | b) == [ 0b111, 0b110, 0b111, 0b100111 ]); assert((a ^ b) == [ 0b111, 0b100, 0b11, 0b100101 ]); assert(~a == [ ~0b1, ~0b10, ~0b101, ~0b100011 ]); } ./ldc-1.28.0-src/tests/codegen/simd_alignment.d0000644000175000017500000000110714141774365021414 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -O3 -of=%t.ll %s && FileCheck %s < %t.ll import core.simd; struct S17237 { bool a; struct { bool b; int8 c; } } int4 globalIntFour; // CHECK-DAG: globalIntFour{{.*}} = {{.*}} align 16 S17237 globalStruct; // CHECK-DAG: @{{.*}}globalStruct{{.*}}S17237{{\"?}} = {{.*}} zeroinitializer{{(, comdat)?}}, align 32 // CHECK-LABEL: define <8 x i32> @foo( extern(C) int8 foo(S17237* s) { // CHECK: %[[GEP:[0-9]]] = getelementptr {{.*}}S17237* %s_arg // CHECK: = load {{.*}}<8 x i32>* %[[GEP]], align 32 return s.c; } ./ldc-1.28.0-src/tests/codegen/in_place_construct.d0000644000175000017500000001063714141774365022310 0ustar matthiasmatthias// Tests in-place construction of variables. // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // 256 bits, returned via sret: struct S { long a, b, c, d; } // CHECK-LABEL: define{{.*}} @{{.*}}_D18in_place_construct13returnLiteralFZSQBm1S S returnLiteral() { // make sure the literal is emitted directly into the sret pointee // CHECK: %1 = getelementptr inbounds {{.*}}%in_place_construct.S* %.sret_arg, i32 0, i32 0 // CHECK: store i64 1, i64* %1 // CHECK: %2 = getelementptr inbounds {{.*}}%in_place_construct.S* %.sret_arg, i32 0, i32 1 // CHECK: store i64 2, i64* %2 // CHECK: %3 = getelementptr inbounds {{.*}}%in_place_construct.S* %.sret_arg, i32 0, i32 2 // CHECK: store i64 3, i64* %3 // CHECK: %4 = getelementptr inbounds {{.*}}%in_place_construct.S* %.sret_arg, i32 0, i32 3 // CHECK: store i64 4, i64* %4 return S(1, 2, 3, 4); } // CHECK-LABEL: define{{.*}} @{{.*}}_D18in_place_construct12returnRValueFZSQBl1S S returnRValue() { // make sure the sret pointer is forwarded // CHECK: call {{.*}}_D18in_place_construct13returnLiteralFZSQBm1S // CHECK-SAME: %in_place_construct.S* {{.*}} %.sret_arg return returnLiteral(); } // CHECK-LABEL: define{{.*}} @{{.*}}_D18in_place_construct10returnNRVOFZSQBj1S S returnNRVO() { // make sure NRVO zero-initializes the sret pointee directly // CHECK: %1 = bitcast %in_place_construct.S* %.sret_arg to i8* // CHECK: call void @llvm.memset.{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8 0, const S r; return r; } // CHECK-LABEL: define{{.*}} @{{.*}}_D18in_place_construct15withOutContractFZSQBo1S S withOutContract() out { assert(__result.a == 0); } body { // make sure NRVO zero-initializes the sret pointee directly // CHECK: %1 = bitcast %in_place_construct.S* %.sret_arg to i8* // CHECK: call void @llvm.memset.{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8 0, const S r; return r; // make sure `__result` inside the out contract is just an alias to the sret pointee // CHECK: %2 = getelementptr inbounds {{.*}}%in_place_construct.S* %.sret_arg, i32 0, i32 0 // CHECK: %3 = load {{.*}}i64* %2 // CHECK: %4 = icmp eq i64 %3, 0 } // CHECK-LABEL: define{{.*}} @{{.*}}_D18in_place_construct7structsFZv void structs() { // CHECK: %literal = alloca %in_place_construct.S // CHECK: %a = alloca %in_place_construct.S // CHECK: %b = alloca %in_place_construct.S // CHECK: %c = alloca %in_place_construct.S // make sure the literal is emitted directly into the lvalue // CHECK: %1 = getelementptr inbounds {{.*}}%in_place_construct.S* %literal, i32 0, i32 0 // CHECK: store i64 5, i64* %1 // CHECK: %2 = getelementptr inbounds {{.*}}%in_place_construct.S* %literal, i32 0, i32 1 // CHECK: store i64 6, i64* %2 // CHECK: %3 = getelementptr inbounds {{.*}}%in_place_construct.S* %literal, i32 0, i32 2 // CHECK: store i64 7, i64* %3 // CHECK: %4 = getelementptr inbounds {{.*}}%in_place_construct.S* %literal, i32 0, i32 3 // CHECK: store i64 8, i64* %4 const literal = S(5, 6, 7, 8); // make sure the variables are in-place constructed via sret // CHECK: call {{.*}}_D18in_place_construct13returnLiteralFZSQBm1S // CHECK-SAME: %in_place_construct.S* {{.*}} %a const a = returnLiteral(); // CHECK: call {{.*}}_D18in_place_construct12returnRValueFZSQBl1S // CHECK-SAME: %in_place_construct.S* {{.*}} %b const b = returnRValue(); // CHECK: call {{.*}}_D18in_place_construct10returnNRVOFZSQBj1S // CHECK-SAME: %in_place_construct.S* {{.*}} %c const c = returnNRVO(); withOutContract(); } // CHECK-LABEL: define{{.*}} @{{.*}}_D18in_place_construct12staticArraysFZv void staticArrays() { // CHECK: %sa = alloca [2 x i32] // make sure static array literals are in-place constructed too // CHECK: store [2 x i32] [i32 1, i32 2], [2 x i32]* %sa const(int[2]) sa = [ 1, 2 ]; } struct Container { S s; } // CHECK-LABEL: define{{.*}} @{{.*}}_D18in_place_construct19hierarchyOfLiteralsFZv void hierarchyOfLiterals() { // CHECK: %sa = alloca [1 x %in_place_construct.Container] // CHECK: store [1 x %in_place_construct.Container] [%in_place_construct.Container { %in_place_construct.S { i64 11, i64 12, i64 13, i64 14 } }], [1 x %in_place_construct.Container]* %sa Container[1] sa = [ Container(S(11, 12, 13, 14)) ]; } // CHECK-LABEL: define{{.*}} @{{.*}}_Dmain void main() { structs(); staticArrays(); hierarchyOfLiterals(); } ./ldc-1.28.0-src/tests/codegen/vector_abi_x86.d0000644000175000017500000000160314141774365021245 0ustar matthiasmatthias// Makes sure an optimized trivial function taking and returning a vector // takes and returns it directly in XMM0, with no memory indirections. // REQUIRES: host_X86 // RUN: %ldc -O -output-s -m32 -of=%t_32.s %s -mattr=+sse2 // RUN: FileCheck --check-prefix=COMMON %s < %t_32.s // RUN: %ldc -O -output-s -m64 -of=%t_64.s %s // RUN: FileCheck --check-prefix=COMMON --check-prefix=X64 %s < %t_64.s import core.simd; // COMMON: _D14vector_abi_x863foo int4 foo(int4 param) { // COMMON-NOT: mov // COMMON: paddd // COMMON-SAME: %xmm0 return param + 3; // COMMON-NOT: mov // COMMON: ret } version (X86_64) { struct Int4 { int4 v; } // X64: _D14vector_abi_x863barFSQw4Int4ZQj Int4 bar(Int4 param) { // X64-NOT: mov // X64: paddd // X64-SAME: %xmm0 return Int4(param.v + 3); // X64-NOT: mov // X64: ret } } ./ldc-1.28.0-src/tests/codegen/discard_value_names_ir2obj_cache.d0000644000175000017500000000133014141774365025002 0ustar matthiasmatthias// Test value name discarding in conjunction with the compile cache: local variable name changes should still give a cache hit. // Create and then empty the cache for correct testing when running the test multiple times. // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir // RUN: %prunecache -f %t-dir --max-bytes=1 // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -d-version=FIRST -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -vv | FileCheck --check-prefix=MUST_HIT %s // MUST_HIT: Cache object found! // NO_HIT-NOT: Cache object found! version (FIRST) { int foo(int a) { return a + 2; } } else { int foo(int differentname) { return differentname + 2; } } ./ldc-1.28.0-src/tests/codegen/asm_constraints.d0000644000175000017500000000025514141774365021634 0ustar matthiasmatthias// RUN: not %ldc -c -w %s 2>&1 | FileCheck %s void main () { import ldc.llvmasm : __asm; // CHECK: Error: inline asm constraints are invalid __asm("", "]["); } ./ldc-1.28.0-src/tests/codegen/export_naked_gh2648.d0000644000175000017500000000045114141774365022110 0ustar matthiasmatthias// RUN: %ldc -shared -of=%t.dll %s // RUN: dumpbin /exports %t.dll | FileCheck %s // REQUIRES: Windows export { // CHECK-DAG: _D19export_naked_gh264812exportNormal void exportNormal() { } // CHECK-DAG: _D19export_naked_gh264811exportNaked void exportNaked() { asm { naked; } } } ./ldc-1.28.0-src/tests/codegen/pragma_LDC_extern_weak.d0000644000175000017500000000116014141774365022746 0ustar matthiasmatthias// Test pragma(LDC_extern_weak) on function declarations. // RUN: %ldc -d-version=DECLARATION -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll --check-prefix=DECLARATION // RUN: not %ldc -d-version=DEFINITION %s 2>&1 | FileCheck %s --check-prefix=DEFINITION version(DECLARATION) { // DECLARATION: declare{{.*}} extern_weak {{.*}}weakreffunction pragma(LDC_extern_weak) extern(C) void weakreffunction(); } version(DEFINITION) { // DEFINITION: Error: `LDC_extern_weak` cannot be applied to function definitions pragma(LDC_extern_weak) extern(C) void weakreffunction() {}; } void foo() { auto a = &weakreffunction; } ./ldc-1.28.0-src/tests/codegen/inlining_disablecross.d0000644000175000017500000000111014141774365022760 0ustar matthiasmatthias// Test disabling of cross-module inlining // RUN: %ldc %s -I%S -c -output-ll -enable-cross-module-inlining -O0 -of=%t.ENA.ll && FileCheck %s < %t.ENA.ll // RUN: %ldc %s -I%S -c -output-ll -disable-cross-module-inlining -O3 -of=%t.DIS.ll && FileCheck %s < %t.DIS.ll import inputs.inlinables; extern (C): // simplify mangling for easier matching // CHECK-LABEL: define{{.*}} @call_easily_inlinable( int call_easily_inlinable(int i) { // CHECK: call {{.*}} @easily_inlinable( return easily_inlinable(i); // CHECK: ret } // CHECK-DAG: declare {{.*}} @easily_inlinable( ./ldc-1.28.0-src/tests/codegen/cov_modes.d0000644000175000017500000000462214141774365020405 0ustar matthiasmatthias// Test the different modes of -cov instrumentation code // RUN: %ldc --cov --output-ll -of=%t.ll %s && FileCheck --check-prefix=ALL --check-prefix=DEFAULT %s < %t.ll // RUN: %ldc --cov --cov-increment=boolean --cov-increment=default --output-ll -of=%t.default.ll %s && FileCheck --check-prefix=ALL --check-prefix=DEFAULT %s < %t.default.ll // RUN: %ldc --cov --cov-increment=atomic --output-ll -of=%t.atomic.ll %s && FileCheck --check-prefix=ALL --check-prefix=ATOMIC %s < %t.atomic.ll // RUN: %ldc --cov --cov-increment=non-atomic --output-ll -of=%t.nonatomic.ll %s && FileCheck --check-prefix=ALL --check-prefix=NONATOMIC %s < %t.nonatomic.ll // RUN: %ldc --cov --cov-increment=boolean --output-ll -of=%t.boolean.ll %s && FileCheck --check-prefix=ALL --check-prefix=BOOLEAN %s < %t.boolean.ll // REQUIRES: Linux // RUN: mkdir %t // RUN: mkdir %t/atomic && %ldc --cov --cov-increment=atomic --run %s --DRT-covopt="dstpath:%t/atomic" // RUN: mkdir %t/nonatomic && %ldc --cov --cov-increment=non-atomic --run %s --DRT-covopt="dstpath:%t/nonatomic" // RUN: mkdir %t/boolean && %ldc --cov --cov-increment=boolean --run %s --DRT-covopt="dstpath:%t/boolean" // Some sed xargs magic to replace '/' with '-' in the filename, and replace the extension '.d' with '.lst' // RUN: echo %s | sed -e "s,/,-,g" -e "s,\(.*\).d,\1.lst," | xargs printf "%%s%%s" "%t/atomic/" | xargs cat | FileCheck --check-prefix=ATOMIC_LST %s // RUN: echo %s | sed -e "s,/,-,g" -e "s,\(.*\).d,\1.lst," | xargs printf "%%s%%s" "%t/nonatomic/" | xargs cat | FileCheck --check-prefix=NONATOMIC_LST %s // RUN: echo %s | sed -e "s,/,-,g" -e "s,\(.*\).d,\1.lst," | xargs printf "%%s%%s" "%t/boolean/" | xargs cat | FileCheck --check-prefix=BOOLEAN_LST %s void f2() { } // ALL-LABEL: define{{.*}} void @{{.*}}f1 void f1() { // DEFAULT: atomicrmw add {{.*}}@_d_cover_data, {{.*}} monotonic // ATOMIC: atomicrmw add {{.*}}@_d_cover_data, {{.*}} monotonic // NONATOMIC: load {{.*}}@_d_cover_data, {{.*}} !nontemporal // NONATOMIC: store {{.*}}@_d_cover_data, {{.*}} !nontemporal // BOOLEAN: store {{.*}}@_d_cover_data, {{.*}} !nontemporal // ALL-LABEL: call{{.*}} @{{.*}}f2 f2(); } void main() { foreach (i; 0..10) f1(); // ATOMIC_LST: {{^ *}}10| f1(); // NONATOMIC_LST: {{^ *}}10| f1(); // BOOLEAN_LST: {{^ *}}1| f1(); } ./ldc-1.28.0-src/tests/codegen/asm_gcc.d0000644000175000017500000000540714141774365020025 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux-gnu -output-ll -of=%t.ll %s // RUN: FileCheck %s < %t.ll // CHECK: define void @_D7asm_gcc5cpuidFZv void cpuid() { uint max_extended_cpuid; // CHECK: %1 = call i32 asm sideeffect "cpuid", "={eax},{eax},~{ebx},~{ecx},~{edx}"(i32 -2147483648), !srcloc // CHECK-NEXT: store i32 %1, i32* %max_extended_cpuid asm { "cpuid" : "=eax" (max_extended_cpuid) : "eax" (0x8000_0000) : "ebx", "ecx", "edx"; } } // CHECK: define void @_D7asm_gcc14multipleOutputFZv void multipleOutput() { // CHECK-NEXT: %r = alloca [4 x i32] uint[4] r = void; // CHECK-NEXT: %1 = getelementptr {{.*}} %r, i32 0, i64 0 // CHECK-NEXT: %2 = getelementptr {{.*}} %r, i32 0, i64 1 // CHECK-NEXT: %3 = getelementptr {{.*}} %r, i32 0, i64 2 // CHECK-NEXT: %4 = getelementptr {{.*}} %r, i32 0, i64 3 // CHECK-NEXT: %5 = call { i32, i32, i32, i32 } asm sideeffect "cpuid", "={eax},={ebx},={ecx},={edx},{eax}"(i32 2), !srcloc // CHECK-NEXT: %6 = extractvalue { i32, i32, i32, i32 } %5, 0 // CHECK-NEXT: store i32 %6, i32* %1 // CHECK-NEXT: %7 = extractvalue { i32, i32, i32, i32 } %5, 1 // CHECK-NEXT: store i32 %7, i32* %2 // CHECK-NEXT: %8 = extractvalue { i32, i32, i32, i32 } %5, 2 // CHECK-NEXT: store i32 %8, i32* %3 // CHECK-NEXT: %9 = extractvalue { i32, i32, i32, i32 } %5, 3 // CHECK-NEXT: store i32 %9, i32* %4 asm { "cpuid" : "=eax" (r[0]), "=ebx" (r[1]), "=ecx" (r[2]), "=edx" (r[3]) : "eax" (2); } } // CHECK: define void @_D7asm_gcc14indirectOutputFkZv void indirectOutput(uint eax) { // CHECK-NEXT: %eax = alloca i32 // CHECK-NEXT: %r = alloca [4 x i32] // CHECK-NEXT: store i32 %eax_arg, i32* %eax uint[4] r = void; // CHECK-NEXT: %1 = load i32, i32* %eax // CHECK-NEXT: call void asm sideeffect "cpuid // CHECK-SAME: "=*m,{eax},~{eax},~{ebx},~{ecx},~{edx}"([4 x i32]* %r, i32 %1), !srcloc asm { `cpuid movl %%eax, %0 movl %%ebx, 4%0 movl %%ecx, 8%0 movl %%edx, 12%0` : "=m" (r) : "eax" (eax) : "eax", "ebx", "ecx", "edx"; } } // CHECK: define void @_D7asm_gcc13indirectInputFkZv void indirectInput(uint eax) { // CHECK-NEXT: %eax = alloca i32 // CHECK-NEXT: store i32 %eax_arg, i32* %eax // CHECK-NEXT: call void asm sideeffect "movl %eax, $0", "*m,~{eax}"(i32* %eax), !srcloc asm { "movl %%eax, %0" : : "m" (eax) : "eax"; } } // CHECK: define void @_D7asm_gcc15specialNamesX86FZv void specialNamesX86() { byte b; short s; int i; long l; // CHECK: = call { i8, i16, i32, i64 } asm sideeffect "nop", "={ax},={bx},={cx},={dx},{si},{di}"(i16 %1, i64 2), !srcloc asm { "nop" : "=a" (b), "=b" (s), "=c" (i), "=d" (l) : "S" (short(1)), "D" (2L); } } ./ldc-1.28.0-src/tests/codegen/in_place_construct_temporaries.d0000644000175000017500000000307014141774365024713 0ustar matthiasmatthias// from https://issues.dlang.org/show_bug.cgi?id=20321 // Restrict to x86[_64] hosts for now, as the ABI must not perform any implicit // blits (e.g., via LLVM byval attribute) for non-PODs. // REQUIRES: host_X86 // RUN: %ldc -run %s version (Win32) { // ABI needs *a lot* of work: https://github.com/ldc-developers/ldc/pull/3204#discussion_r339300174 void main() {} } else: __gshared bool success = true; /** Container with internal pointer */ struct Container { long[3] data; void* p; this(int) { p = &data[0]; } this(ref inout Container) inout { p = &data[0]; } /** Ensure the internal pointer is correct */ void check(int line = __LINE__) { if (p != &data[0]) { import core.stdc.stdio : printf; printf("Check failed in line %d\n", line); success = false; } } } void func(Container c) { c.check(); } // error Container get() { auto a = Container(1); auto b = a; a.check(); // ok b.check(); // ok // no nrvo if (1) return a; else return b; } Container get2() out(r){} do { auto v = Container(1); v.check(); // ok return v; } int main() { Container v = Container(1); v.check(); // ok func(v); auto r = get(); r.check(); // error auto r2 = get2(); r.check(); // error Container[1] slit = [v]; slit[0].check(); // error Container[] dlit = [v]; dlit[0].check(); // error auto b = B(v); b.m.check(); // error return success ? 0 : 1; } struct B { Container m; } ./ldc-1.28.0-src/tests/codegen/inlining_imports.d0000644000175000017500000000172514141774365022014 0ustar matthiasmatthias// Test inlining of imported functions // RUN: %ldc %s -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll import inputs.inlinables; extern (C): // simplify mangling for easier matching // Simple functions for reference. int foo() { return goo(); } int goo() { return 1; } // OPT3-LABEL: define{{.*}} @call_easily_inlinable( int call_easily_inlinable(int i) { // OPT3-NOT: call {{.*}} @easily_inlinable( return easily_inlinable(i); // OPT3: ret i32 2 } // OPT3-LABEL: define{{.*}} @call_class_function( int call_class_function(A a) { // OPT3-NOT: call return a.final_class_function(); // OPT3: ret i32 12345 } // OPT3-LABEL: define{{.*}} @call_weak_function( int call_weak_function() { // OPT3: call return weak_function(); // OPT3-NOT: 654 // Test for function end `}` to prevent matching "654" elsewhere (e.g. the LDC version git hash) // OPT3: } } ./ldc-1.28.0-src/tests/codegen/dcompute_cl_addrspaces.d0000644000175000017500000000531614141774365023117 0ustar matthiasmatthias// See GH issue #2709 // REQUIRES: target_SPIRV // RUN: %ldc -c -mdcompute-targets=ocl-220 -m64 -mdcompute-file-prefix=addrspace -output-ll -output-o %s && FileCheck %s --check-prefix=LL < addrspace_ocl220_64.ll \ // RUN: && %llvm-spirv -to-text addrspace_ocl220_64.spv && FileCheck %s --check-prefix=SPT < addrspace_ocl220_64.spt @compute(CompileFor.deviceOnly) module dcompute_cl_addrspaces; import ldc.dcompute; // LL: %"ldc.dcompute.Pointer!(AddrSpace.Private, float).Pointer" = type { float* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Global, float).Pointer" = type { float addrspace(1)* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Shared, float).Pointer" = type { float addrspace(2)* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Constant, immutable(float)).Pointer" = type { float addrspace(3)* } // LL: %"ldc.dcompute.Pointer!(AddrSpace.Generic, float).Pointer" = type { float addrspace(4)* } // SPT-DAG: 2 TypeVoid [[VOID_ID:[0-9]+]] // SPT-DAG: 3 TypeFloat [[FLOAT_ID:[0-9]+]] 32 //See section 3.7 of the SPIR-V Specification for the numbers in the 4th column. // SPT-DAG: 4 TypePointer [[SHARED_FLOAT_POINTER_ID:[0-9]+]] 4 [[FLOAT_ID]] // SPT-DAG: 4 TypePointer [[CONSTANT_FLOAT_POINTER_ID:[0-9]+]] 0 [[FLOAT_ID]] // SPT-DAG: 4 TypePointer [[GLOBAL_FLOAT_POINTER_ID:[0-9]+]] 5 [[FLOAT_ID]] // SPT-DAG: 4 TypePointer [[GENERIC_FLOAT_POINTER_ID:[0-9]+]] 8 [[FLOAT_ID]] // SPT-DAG: 4 TypePointer [[PRIVATE_FLOAT_POINTER_ID:[0-9]+]] 7 [[FLOAT_ID]] //void function({ T addrspace(n)* }) // SPT-DAG: 4 TypeFunction [[FOO_PRIVATE:[0-9]+]] [[VOID_ID]] [[PRIVATE_FLOAT_POINTER_ID]] // SPT-DAG: 4 TypeFunction [[FOO_GLOBAL:[0-9]+]] [[VOID_ID]] [[GLOBAL_FLOAT_POINTER_ID]] // SPT-DAG: 4 TypeFunction [[FOO_SHARED:[0-9]+]] [[VOID_ID]] [[SHARED_FLOAT_POINTER_ID]] // SPT-DAG: 4 TypeFunction [[FOO_CONSTANT:[0-9]+]] [[VOID_ID]] [[CONSTANT_FLOAT_POINTER_ID]] // SPT-DAG: 4 TypeFunction [[FOO_GENERIC:[0-9]+]] [[VOID_ID]] [[GENERIC_FLOAT_POINTER_ID]] void foo(PrivatePointer!float f) { // LL: load float, float* // SPT-DAG: 5 Function [[VOID_ID]] {{[0-9]+}} 0 [[FOO_PRIVATE]] float g = *f; } void foo(GlobalPointer!float f) { // LL: load float, float addrspace(1)* // SPT-DAG: 5 Function [[VOID_ID]] {{[0-9]+}} 0 [[FOO_GLOBAL]] float g = *f; } void foo(SharedPointer!float f) { // LL: load float, float addrspace(2)* // SPT-DAG: 5 Function [[VOID_ID]] {{[0-9]+}} 0 [[FOO_SHARED]] float g = *f; } void foo(ConstantPointer!float f) { // LL: load float, float addrspace(3)* // SPT-DAG: 5 Function [[VOID_ID]] {{[0-9]+}} 0 [[FOO_CONSTANT]] float g = *f; } void foo(GenericPointer!float f) { // LL: load float, float addrspace(4)* // SPT-DAG: 5 Function [[VOID_ID]] {{[0-9]+}} 0 [[FOO_GENERIC]] float g = *f; } ./ldc-1.28.0-src/tests/codegen/inlining_leakdefinitions_asm.d0000644000175000017500000000233014141774365024320 0ustar matthiasmatthias// Test that inlining does not leak definitions without marking them as available_externally // "Leaking" = symbols definitions in .o file that shouldn't be declarations instead (undefined symbols). // REQUIRES: target_X86 // RUN: %ldc %s -mtriple=x86_64-linux-gnu -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -mtriple=x86_64-linux-gnu -I%S -c -output-ll -release -enable-inlining -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll import inputs.inlinables_asm; extern (C): // simplify mangling for easier matching // Inlined naked asm func could end up as global symbols, definitely bad! // (would give multiple definition linker error) // OPT0-NOT: module asm {{.*}}.globl{{.*}}_naked_asm_func // OPT3-NOT: module asm {{.*}}.globl{{.*}}_naked_asm_func // OPT0-LABEL: define{{.*}} @asm_func( // OPT3-LABEL: define{{.*}} @asm_func( void asm_func() { naked_asm_func(); // OPT0: ret void // OPT3: ret void } // OPT0-LABEL: define{{.*}} @main( // OPT3-LABEL: define{{.*}} @main( int main() { asm_func(); return 0; // OPT0: ret i32 0 // OPT3: ret i32 0 } ./ldc-1.28.0-src/tests/codegen/vector_intrinsics_gh2962.d0000644000175000017500000000051514141774365023174 0ustar matthiasmatthias// REQUIRES: host_X86 // RUN: %ldc -run %s import core.simd; import ldc.intrinsics; void main() { const float4 f = [ 1, -2, 3, -4 ]; const abs = llvm_fabs(f); assert(abs == [ 1, 2, 3, 4 ]); const int4 i = [ 0b0, 0b10, 0b101, 0b100011 ]; const numOnes = llvm_ctpop(i); assert(numOnes == [ 0, 1, 2, 3 ]); } ./ldc-1.28.0-src/tests/codegen/asm_labels.d0000644000175000017500000000106714141774365020531 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s // RUN: FileCheck %s < %t.s // CHECK: _D10asm_labels3fooFiZv: void foo(int a) { asm { // CHECK: jmp .L_D10asm_labels3fooFiZv_label jmp label; // CHECK-NEXT: .L_D10asm_labels3fooFiZv_label: label: ret; } } // CHECK: _D10asm_labels3fooFkZv: void foo(uint a) { asm { // CHECK: jmp .L_D10asm_labels3fooFkZv_label jmp label; // CHECK-NEXT: .L_D10asm_labels3fooFkZv_label: label: ret; } } ./ldc-1.28.0-src/tests/codegen/discard_value_names_gh1749.d0000644000175000017500000000153614141774365023423 0ustar matthiasmatthias// Test value name discarding when creating non-textual IR. // RUN: %ldc %S/inputs/input_discard_valuename.d -c -output-ll -of=%t.bar.ll && FileCheck %S/inputs/input_discard_valuename.d < %t.bar.ll // Output a bitcode file (i.e. with discarded names) and input it into a second LDC command that outputs textual IR. // RUN: %ldc %S/inputs/input_discard_valuename.d -g -c -output-bc -of=%t.bar.bc \ // RUN: && %ldc %s %t.bar.bc -g -c -output-ll -of=%t.ll && FileCheck %s < %t.ll // IR imported from the bitcode file should not have local value names: // CHECK-LABEL: define{{.*}} @foo // CHECK: %localfoovar // CHECK-LABEL: define{{.*}} @bar // CHECK-NOT: %localbarvar // But the imported IR should still have debug names: // CHECK: DILocalVariable{{.*}}"localfoovar" // CHECK: DILocalVariable{{.*}}"localbarvar" extern(C) void foo() { int localfoovar; } ./ldc-1.28.0-src/tests/codegen/export.d0000644000175000017500000000166214141774365017751 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s // RUN: FileCheck %s < %t.ll // REQUIRES: Windows export { // non-TLS: __gshared { // CHECK: @{{.*}}exportedGlobal{{.*}} = dllexport void* exportedGlobal; // CHECK: @{{.*}}importedGlobal{{.*}} = external dllimport extern void* importedGlobal; } // TLS: unsupported => linker errors version (all) { // CHECK: @{{.*}}exportedTlsGlobal{{.*}} = thread_local // CHECK-NOT: dllexport void* exportedTlsGlobal; // CHECK: @{{.*}}importedTlsGlobal{{.*}} = external thread_local // CHECK-NOT: dllimport extern void* importedTlsGlobal; } // CHECK: define dllexport {{.*}}_D6export11exportedFooFZv void exportedFoo() {} // CHECK: declare // CHECK-NOT: dllimport // CHECK-SAME: _D6export11importedFooFZv void importedFoo(); } void bar() { exportedFoo(); importedFoo(); } ./ldc-1.28.0-src/tests/codegen/complex_postexpr_gh1806.d0000644000175000017500000000063214141774365023034 0ustar matthiasmatthias// RUN: %ldc -run %s void runTest(T)() { { T v = 1.0 + 1.0i; assert(v++ == 1.0 + 1.0i); assert(v-- == 2.0 + 1.0i); assert(v == 1.0 + 1.0i); } { T v = 1.0 + 1.0i; assert(++v == 2.0 + 1.0i); assert(--v == 1.0 + 1.0i); assert(v == 1.0 + 1.0i); } } void main () { runTest!cfloat(); runTest!cdouble(); runTest!creal(); } ./ldc-1.28.0-src/tests/codegen/inline_ir.d0000644000175000017500000000114614141774365020375 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.llvmasm; alias __irEx!("", "store i32 %1, i32* %0, !nontemporal !0", "!0 = !{i32 1}", void, int*, int) nontemporalStore; alias __irEx!("!0 = !{i32 1}", "%i = load i32, i32* %0, !nontemporal !0\nret i32 %i", "", int, const int*) nontemporalLoad; int foo(const int* src) { // CHECK: %{{.*}} = load i32, i32* {{.*}} !nontemporal ![[METADATA:[0-9]+]] return nontemporalLoad(src); } void bar(int* dst, int val) { // CHECK: store i32 {{.*}} !nontemporal ![[METADATA]] nontemporalStore(dst, val); } // CHECK: ![[METADATA]] = !{i32 1}./ldc-1.28.0-src/tests/codegen/atomicrmw.d0000644000175000017500000000146514141774365020433 0ustar matthiasmatthias// RUN: %ldc -c -de -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import core.atomic; void main() { shared ubyte x = 3; ubyte r; r = atomicOp!"+="(x, uint(257)); assert(x == r); // CHECK: = atomicrmw add i8* r = atomicOp!"+="(x, int(-263)); assert(x == r); // CHECK: = atomicrmw add i8* r = atomicOp!"-="(x, ushort(257)); assert(x == r); // CHECK: = atomicrmw sub i8* r = atomicOp!"-="(x, short(-263)); assert(x == r); // CHECK: = atomicrmw sub i8* r = atomicOp!"&="(x, ubyte(255)); assert(x == r); // CHECK: = atomicrmw and i8* r = atomicOp!"|="(x, short(3)); assert(x == r); // CHECK: = atomicrmw or i8* r = atomicOp!"^="(x, int(3)); assert(x == r); // CHECK: = atomicrmw xor i8* r = atomicOp!"+="(x, 1.0f); assert(x == r); // CHECK: = cmpxchg weak i8* } ./ldc-1.28.0-src/tests/codegen/ptr_16_bit.d0000644000175000017500000000030114141774365020366 0ustar matthiasmatthias// REQUIRES: target_MSP430 // RUN: %ldc -mtriple=msp430 -o- %s void* ptr; static assert(ptr.sizeof == 2); version(D_P16) {} else static assert(0); version(MSP430) {} else static assert(0); ./ldc-1.28.0-src/tests/codegen/export_marked_symbols2.d0000644000175000017500000000135514141774365023125 0ustar matthiasmatthias// Tests that -fvisibility=hidden doesn't affect imported and fwd declared symbols, // so that they can still be linked in from a shared library. // UNSUPPORTED: Windows // RUN: %ldc %S/inputs/export_marked_symbols_lib.d -shared -of=%t_lib%so // RUN: %ldc %s -I%S/inputs -fvisibility=hidden -of=%t%exe %t_lib%so // RUN: %ldc %s -I%S/inputs -fvisibility=hidden -of=%t%exe %t_lib%so -d-version=DECLARE_MANUALLY version (DECLARE_MANUALLY) { extern(C++): export extern __gshared int exportedGlobal; extern __gshared int normalGlobal; export void exportedFoo(); void normalFoo(); } else { import export_marked_symbols_lib; } void main() { exportedGlobal = 1; normalGlobal = 2; exportedFoo(); normalFoo(); } ./ldc-1.28.0-src/tests/codegen/linker_directives_linux.d0000644000175000017500000000056214141774365023352 0ustar matthiasmatthias// RUN: %ldc -mtriple=x86_64-linux-gnu -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // REQUIRES: target_X86 // CHECK: !llvm.dependent-libraries = !{!0} // CHECK: !0 = !{!"mylib"} pragma(lib, "mylib"); // silently ignored because not (yet?) embeddable in ELF object file: pragma(linkerDirective, "-myflag"); pragma(linkerDirective, "-framework", "CoreFoundation"); ./ldc-1.28.0-src/tests/codegen/gh3346.d0000644000175000017500000000027314141774365017343 0ustar matthiasmatthias// RUN: %ldc -run %s import core.thread; void foo() {} shared static this() { auto f = new Fiber(&foo); // depends on shared static this in core.thread.osthread. } void main() {} ./ldc-1.28.0-src/tests/codegen/cpp_interface.d0000644000175000017500000000016414141774365021226 0ustar matthiasmatthias// RUN: %ldc -c %s extern(C++) interface XUnknown {} class ComObject : XUnknown {} class DComObject : ComObject {} ./ldc-1.28.0-src/tests/codegen/export_crossModuleInlining.d0000644000175000017500000000066014141774365024015 0ustar matthiasmatthias// Make sure exported functions can be cross-module inlined without exporting the local function copy. // RUN: %ldc -O -release -enable-cross-module-inlining -output-ll -of=%t.ll -I%S/inputs %s // RUN: FileCheck %s < %t.ll import export2; // CHECK-NOT: _D7export23fooFZi // CHECK: define {{.*}}_D26export_crossModuleInlining3barFZi int bar() { // CHECK-NEXT: ret i32 666 return foo(); } // CHECK-NOT: _D7export23fooFZi ./ldc-1.28.0-src/tests/codegen/attr_naked.d0000644000175000017500000000147114141774365020542 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-pc-linux-gnu -O -output-s -of=%t.s %s && FileCheck %s < %t.s import ldc.attributes; import ldc.llvmasm; // Without -O, LLVM (6) dumps the 2 params to stack for Linux x64 (but doesn't for Win64). // Clang is no different though. // CHECK: withParams: extern(C) int withParams(int param1, void* param2) @naked { // CHECK-NEXT: .cfi_startproc // CHECK-NEXT: #APP // CHECK-NEXT: xorl %eax, %eax // CHECK-NEXT: #NO_APP // CHECK-NEXT: retq return __asm!int("xor %eax, %eax", "={eax}"); } // CHECK: _D10attr_naked8noReturnFZv: void noReturn() @naked { // CHECK-NEXT: .cfi_startproc // CHECK-NEXT: #APP // CHECK-NEXT: jmpq *%rax // CHECK-NEXT: #NO_APP __asm("jmp *%rax", ""); // CHECK-NOT: retq // CHECK: .cfi_endproc } ./ldc-1.28.0-src/tests/codegen/mangling_gh1519.d0000644000175000017500000000115614141774365021220 0ustar matthiasmatthias// Test for Github issue 1519 // Check that .mangleof strings do not contain any char 0x01. // LDC may prepend 0x01 to prevent LLVM from modifying the symbol name, but it should not appear in user code. // RUN: %ldc -c %s extern (C) void fooC() { } extern (C++) void fooCpp() { } extern (D) void fooD() { } void aliasTemplate(alias F)() { F(); } void main() { import std.algorithm; static assert(all!"a != '\1'"(fooC.mangleof)); static assert(all!"a != '\1'"(fooCpp.mangleof)); static assert(all!"a != '\1'"(fooD.mangleof)); static assert(all!"a != '\1'"(aliasTemplate!fooCpp.mangleof)); } ./ldc-1.28.0-src/tests/codegen/vastart_vaend_gh1744.d0000644000175000017500000000235214141774365022264 0ustar matthiasmatthias// Test that va_end is called when returning from a variadic function. // Because the IR is kind of ugly, testing at -O0 is very brittle. Instead we // test that at -O3, LLVM was able to analyse the function correctly and // optimize-out the va_start and va_end calls and remove the call to // return_two (Github #1744). // RUN: %ldc %s -c -output-ll -O3 -of=%t.O3.ll \ // RUN: && FileCheck %s --check-prefix OPT3 < %t.O3.ll module mod; // OPT3-LABEL: define {{.*}} @{{.*}}void_three_return_paths void void_three_return_paths(int a, ...) { // OPT3: call void @llvm.va_start({{.*}} %[[VA:[0-9]+]]) // OPT3-NOT: return_two return_two(); if (a > 0) { throw new Exception(""); return; } // There are two control paths (normal return, exception resume) that // should call va_end. // OPT3: call void @llvm.va_end({{.*}} %[[VA]]) // OPT3: call void @llvm.va_end({{.*}} %[[VA]]) } // OPT3-LABEL: define {{.*}} @{{.*}}return_two int return_two(...) { // OPT3-NOT: va_start // OPT3-NOT: va_end // OPT3: ret i32 2 return 2; } // Github #1744: // OPT3-LABEL: define {{.*}} @{{.*}}two_four int two_four() { // OPT3-NOT: return_two // OPT3: ret i32 8 return return_two() * 4; } ./ldc-1.28.0-src/tests/codegen/mangling.d0000644000175000017500000000473614141774365020231 0ustar matthiasmatthias// Makes sure T.mangleof and pragma(mangle, …) are in sync. // inputs/mangling_definitions.d features C/C++/D symbols and validates their .mangleof. // This module forward-declares these symbols, using an identical pragma(mangle, …) string, // and references the symbols in main(). // Compile both modules separately and make sure the 2 objects can be linked successfully. // RUN: %ldc %S/inputs/mangling_definitions.d -c -of=%t-dir/mangling_definitions%obj // RUN: %ldc %t-dir/mangling_definitions%obj -run %s module mangling; // Variables: extern(C) pragma(mangle, "cGlobal") extern __gshared int decl_cGlobal; version(CRuntime_Microsoft) enum cppGlobalMangle = "?cppGlobal@cpp_vars@@3HA"; else enum cppGlobalMangle = "_ZN8cpp_vars9cppGlobalE"; extern(C++, decl_cpp_vars) pragma(mangle, cppGlobalMangle) extern __gshared int decl_cppGlobal; pragma(mangle, "_D11definitions7dGlobali") extern __gshared int decl_dGlobal; // Functions: extern(C) pragma(mangle, "cFunc") int decl_cFunc(double a); version(CRuntime_Microsoft) enum cppFuncMangle = "?cppFunc@cpp_funcs@@YAHN@Z"; else enum cppFuncMangle = "_ZN9cpp_funcs7cppFuncEd"; extern(C++, decl_cpp_funcs) pragma(mangle, cppFuncMangle) int decl_cppFunc(double a); pragma(mangle, "_D11definitions5dFuncFdZi") int decl_dFunc(double a); // Naked functions: version(D_InlineAsm_X86) version = AsmX86; else version(D_InlineAsm_X86_64) version = AsmX86; version(AsmX86) { extern(C) pragma(mangle, "naked_cFunc") int decl_naked_cFunc(double a); version(CRuntime_Microsoft) enum nakedCppFuncMangle = "?naked_cppFunc@cpp_naked_funcs@@YAHN@Z"; else enum nakedCppFuncMangle = "_ZN15cpp_naked_funcs13naked_cppFuncEd"; extern(C++, decl_cpp_naked_funcs) pragma(mangle, nakedCppFuncMangle) int decl_naked_cppFunc(double a); pragma(mangle, "_D11definitions11naked_dFuncFdZi") int decl_naked_dFunc(double a); } // Interfacing with C via pragma(mangle, …), without having to take care // of a potential target-specific C prefix (underscore on Win32 and OSX): extern(C) pragma(mangle, "cos") double decl_cos(double x); void main() { assert(decl_cGlobal == 1); assert(decl_cppGlobal == 2); assert(decl_dGlobal == 3); assert(decl_cFunc(1.0) == 1); assert(decl_cppFunc(2.0) == 2); assert(decl_dFunc(3.0) == 3); version(AsmX86) { decl_naked_cFunc(1.0); decl_naked_cppFunc(2.0); decl_naked_dFunc(3.0); } assert(decl_cos(0.0) == 1.0); } ./ldc-1.28.0-src/tests/codegen/indirect_byval_rewrite.d0000644000175000017500000000251114141774365023161 0ustar matthiasmatthias// Ensures efficient indirect by-value passing via IndirectByvalRewrite. // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-windows-msvc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll struct Big { size_t a, b; } struct WithPostblit { Big b; this(this) {} } Big makeBig() { return Big(123, 456); } void foo(Big, WithPostblit, Big, WithPostblit); // CHECK: define {{.*}}_D22indirect_byval_rewrite3bar void bar() { // CHECK: %bigLValue = alloca %indirect_byval_rewrite.Big Big bigLValue; // CHECK-NEXT: %withPostblitLValue = alloca %indirect_byval_rewrite.WithPostblit WithPostblit withPostblitLValue; // * 1st arg: bigLValue bitcopy, copied by IndirectByvalRewrite // CHECK-NEXT: %.hidden_copy_for_IndirectByvalRewrite = alloca %indirect_byval_rewrite.Big // * 2nd arg: temporary withPostblitLValue copy (copied by frontend, incl. postblit) // CHECK-NEXT: %__copytmp{{[0-9]*}} = alloca %indirect_byval_rewrite.WithPostblit // * 3rd arg: sret temporary filled by makeBig() // CHECK-NEXT: %.sret_tmp = alloca %indirect_byval_rewrite.Big // * 4th arg: WithPostblit() literal // CHECK-NEXT: %.structliteral = alloca %indirect_byval_rewrite.WithPostblit foo(bigLValue, withPostblitLValue, makeBig(), WithPostblit()); // no more allocas! // CHECK-NOT: alloca // CHECK: ret void } ./ldc-1.28.0-src/tests/codegen/gh2865.d0000644000175000017500000000037414141774365017352 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll void foo() { // CHECK: %1 = getelementptr {{.*}}_D6gh28653fooFZv{{.*}} to i8*), i32 -10 // CHECK-NEXT: %2 = ptrtoint i8* %1 to i{{32|64}} auto addr = (cast(size_t) &foo) - 10; } ./ldc-1.28.0-src/tests/codegen/assign_struct_init_without_stack.d0000644000175000017500000001026414141774365025311 0ustar matthiasmatthias// Tests minimal use of temporaries in non-optimized builds for struct and array assignment. // Tests `.init` assignment in particular. // RUN: %ldc -output-ll %s -of=%t.ll && FileCheck %s < %t.ll void opaque(); FloatStruct opaque(FloatStruct); FloatStruct opaqueret(); struct FloatStruct { float[10] data; } FloatStruct globalStruct; // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack3fooFZv void foo() { globalStruct = FloatStruct.init; // There should be only one memcpy. // CHECK: call void @llvm.memcpy // CHECK-NEXT: ret void } // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack3hhhFZv void hhh() { globalStruct = FloatStruct([1, 0, 0, 0, 0, 0, 0, 0, 0, 42]); // Future work: test optimized codegen (at -O0) } // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack3gggFZv void ggg() { globalStruct = opaqueret(); // opaque() could be accessing globalStruct, in-place assignment not possible. // CHECK: sret_tmp = alloca %assign_struct_init_without_stack.FloatStruct // CHECK: call {{.*}}opaqueret // CHECK: call void @llvm.memcpy // CHECK-NEXT: ret void } // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack5localFZv void local() { FloatStruct local; local = opaque(local); // Not possible to do in-place assignment, so temporary must be created. // CHECK: local = alloca %assign_struct_init_without_stack.FloatStruct // CHECK: sret_tmp = alloca %assign_struct_init_without_stack.FloatStruct // CHECK: call {{.*}}opaque // CHECK: call void @llvm.memcpy // CHECK-NEXT: ret void } // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack5arrayFZv void array() { int[5] arr = [0,1,2,3,4]; // Future work: test optimized codegen (at -O0) } // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack6array2FKG3iZv void array2(ref int[3] a) { a = [4, a[0], 6]; // There should be a temporary! // CHECK: alloca [3 x i32] // CHECK: call void @llvm.memcpy // CHECK-NEXT: ret void } struct OpAssignStruct { float[10] data; ubyte a; ref OpAssignStruct opAssign(R)(auto ref R rhs) return { return this; } } OpAssignStruct globalOpAssignStruct; OpAssignStruct globalOpAssignStruct2; // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack16tupleassignByValFZv void tupleassignByVal() { globalOpAssignStruct = OpAssignStruct.init; // There should be one memcpy to a temporary. // CHECK: alloca %assign_struct_init_without_stack.OpAssignStruct // CHECK: call void @llvm.memcpy // CHECK-NOT: memcpy // CHECK: call{{.*}} %assign_struct_init_without_stack.OpAssignStruct* @{{.*}}_D32assign_struct_init_without_stack14OpAssignStruct__T8opAssignTSQCmQBhZQsMFNaNbNcNiNjNfQyZQBb // CHECK-NEXT: ret void } // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack16tupleassignByRefFZv void tupleassignByRef() { globalOpAssignStruct = globalOpAssignStruct2; // There should not be a memcpy. // CHECK-NOT: memcpy // CHECK: call{{.*}} %assign_struct_init_without_stack.OpAssignStruct* @{{.*}}_D32assign_struct_init_without_stack14OpAssignStruct__T8opAssignTSQCmQBhZQsMFNaNbNcNiNjNfKQzZQBc // CHECK-NEXT: ret void } struct DtorStruct { float[10] data; ~this() { opaque(); } } struct CtorStruct { float[10] data; this(int i) { opaque(); } } DtorStruct dtorStruct; CtorStruct ctorStruct; // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack4ctorFZv void ctor() { ctorStruct = ctorStruct.init; // There is no dtor, so can be optimized to only a memcpy. // CHECK-NEXT: call void @llvm.memcpy // CHECK-NEXT: ret void } // CHECK-LABEL: define{{.*}} @{{.*}}_D32assign_struct_init_without_stack4dtorFZv void dtor() { dtorStruct = dtorStruct.init; // There should be a temporary and a call to opAssign // CHECK: alloca %assign_struct_init_without_stack.DtorStruct // CHECK: call void @llvm.memcpy{{.*}}_D32assign_struct_init_without_stack10DtorStruct6__initZ // CHECK-NEXT: call {{.*}}_D32assign_struct_init_without_stack10DtorStruct8opAssignMFNcNjSQCkQBfZQi // CHECK-NEXT: ret void } ./ldc-1.28.0-src/tests/codegen/exception_stack_trace.d0000644000175000017500000000164714141774365022774 0ustar matthiasmatthias// RUN: %ldc -g %disable_fp_elim -link-defaultlib-debug %s -of=%t%exe // RUN: %t%exe | FileCheck %s void bar() { throw new Exception("lala"); } void foo() { bar(); } void main() { try { foo(); } catch (Exception e) { import core.stdc.stdio; auto s = e.toString(); printf("%.*s\n", s.length, s.ptr); } } // CHECK: object.Exception@{{.*}}exception_stack_trace.d(6): lala // CHECK-NEXT: ---------------- /* Hiding all frames up to and including the first _d_throw_exception() * one doesn't work reliably on all platforms, so don't enforce * CHECK-*NEXT* for the bar() frame. * On Win32, the bar() frame is missing altogether. * So be very generous and only check for 2 consecutive lines containing * 'exception_stack_trace' each (in function name and/or source file). */ // CHECK: exception_stack_trace{{.*$}} // CHECK-NEXT: exception_stack_trace{{.*$}} ./ldc-1.28.0-src/tests/codegen/nested_gh3556.d0000644000175000017500000000173214141774365020711 0ustar matthiasmatthias// https://github.com/ldc-developers/ldc/issues/3556 // RUN: %ldc -run %s class C { int counter = 1; void test1() { assert(counter == 1); ++counter; } void run1() { class C2 { int counter2 = 11; class C3 { void run3() { test1(); test2(); ++counter; ++counter2; } } void test2() { assert(counter == 2); ++counter; assert(counter2 == 11); ++counter2; } void run2() { auto c3 = new C3; c3.run3(); ++counter; ++counter2; } } auto c2 = new C2; c2.run2(); assert(c2.counter2 == 14); ++counter; } } void main() { auto c = new C; c.run1(); assert(c.counter == 6); } ./ldc-1.28.0-src/tests/codegen/attr_weak.d0000644000175000017500000000106614141774365020407 0ustar matthiasmatthias// Test linking+running a program with @weak functions // RUN: %ldc -O3 %S/inputs/attr_weak_input.d -c -of=%t-dir/attr_weak_input%obj // RUN: %ldc -O3 %s %t-dir/attr_weak_input%obj -of=%t%exe // RUN: %t%exe import ldc.attributes; // should take precedence over and not conflict with weak attr_weak_input.return_two extern(C) int return_two() { return 123; } // should be overridden by strong attr_weak_input.return_seven extern(C) @weak int return_seven() { return 456; } void main() { assert( return_two() == 123 ); assert( return_seven() == 7 ); } ./ldc-1.28.0-src/tests/codegen/ffastmath.d0000644000175000017500000000054514141774365020404 0ustar matthiasmatthias// Test -ffast-math // RUN: %ldc -ffast-math -O0 -release -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; // CHECK-LABEL: define{{.*}} @foo // CHECK-SAME: #[[ATTR:[0-9]+]] extern (C) double foo(double a, double b) { // CHECK: fmul fast return a * b; } // CHECK-DAG: attributes #[[ATTR]] ={{.*}} "unsafe-fp-math"="true" ./ldc-1.28.0-src/tests/codegen/inlining_imports_pragma.d0000644000175000017500000000240714141774365023341 0ustar matthiasmatthias// Test inlining of functions marked with pragma(inline) in an imported module // O0 and O3 should behave the same for these tests with explicit inlining directives by the user. // RUN: %ldc %s -I%S -c -output-ll -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPTNONE < %t.O0.ll // RUN: %ldc %s -I%S -c -output-ll -O3 -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll import inputs.inlinables; extern (C): // simplify mangling for easier matching // OPTNONE-LABEL: define{{.*}} @call_never_inline( // OPT3-LABEL: define{{.*}} @call_never_inline( int call_never_inline() { // OPTNONE: call {{.*}} @never_inline() // OPT3: call {{.*}} @never_inline() return never_inline(); } // OPTNONE-DAG: declare {{.*}} @never_inline() // OPTNONE-LABEL: define{{.*}} @call_always_inline( // OPT3-LABEL: define{{.*}} @call_always_inline( int call_always_inline() { // OPTNONE-NOT: call {{.*}} @always_inline() // OPT3-NOT: call {{.*}} @always_inline() return always_inline(); // OPTNONE: ret // OPT3: ret } // OPTNONE-LABEL: define{{.*}} @call_inline_chain( // OPT3-LABEL: define{{.*}} @call_inline_chain( int call_inline_chain() { // OPTNONE-NOT: call // OPT3-NOT: call return always_inline_chain0(); // OPTNONE: ret // OPT3: ret } ./ldc-1.28.0-src/tests/codegen/call_args_evalorder.d0000644000175000017500000000124214141774365022414 0ustar matthiasmatthias// RUN: %ldc -run %s void checkInt(int a, int b, int c) { assert(a == 1); assert(b == 2); assert(c == 3); } int incrementBy2AndReturn2(ref int a) { a += 2; return 2; } // --- struct BigStruct { long[33] blub; int v; this(int v) { this.v = v; } } void checkBigStruct(BigStruct a, BigStruct b, BigStruct c) { assert(a.v == 1); assert(b.v == 2); assert(c.v == 3); } BigStruct incrementBy2AndReturn2(ref BigStruct a) { a.v += 2; return BigStruct(2); } // --- void main() { int a = 1; checkInt(a, incrementBy2AndReturn2(a), a); auto s = BigStruct(1); checkBigStruct(s, incrementBy2AndReturn2(s), s); } ./ldc-1.28.0-src/tests/codegen/attributes.d0000644000175000017500000000200014141774365020601 0ustar matthiasmatthias// Tests LDC-specific attributes // RUN: %ldc -O -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; //---- @(section) ----------------------------------------------------- // CHECK-DAG: @{{.*}}mySectionedGlobali{{.*}} section ".mySection" @(section(".mySection")) int mySectionedGlobal; // CHECK-DAG: define{{.*}} void @{{.*}}sectionedfoo{{.*}} section "funcSection" @(section("funcSection")) void sectionedfoo() {} //--------------------------------------------------------------------- //--------------------------------------------------------------------- //---- @(weak) -------------------------------------------------------- // CHECK-DAG: @{{.*}}myWeakGlobali{{\"?}} = weak @(ldc.attributes.weak) int myWeakGlobal; // CHECK-DAG: define{{.*}} {{(weak .*void @.*_D)|(void @.*_D6__weak)}}10attributes8weakFuncFZv @weak void weakFunc() {} //--------------------------------------------------------------------- // CHECK-LABEL: define{{.*}} i32 @_Dmain void main() { sectionedfoo(); } ./ldc-1.28.0-src/tests/codegen/no_init_symbols_for_zeroinit_structs.d0000644000175000017500000000042614141774365026214 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s // RUN: FileCheck %s < %t.ll module mod; // CHECK-NOT: _D3mod5Empty6__initZ struct Empty {} // CHECK-NOT: _D3mod7WithInt6__initZ struct WithInt { int a; } // CHECK-NOT: _D3mod13WithZeroFloat6__initZ struct WithZeroFloat { float a = 0; } ./ldc-1.28.0-src/tests/codegen/inlining_templates.d0000644000175000017500000000275414141774365022320 0ustar matthiasmatthias// Test inlining of templates // Templates that would otherwise not be codegenned, _should_ be codegenned for inlining when pragma(inline, true) is specified. // RUN: %ldc %s -I%S -c -output-ll -release -enable-inlining -enable-cross-module-inlining -O0 -of=%t.O0.ll && FileCheck %s < %t.O0.ll // RUN: %ldc -singleobj %S/inputs/inlinables.d %s -I%S -c -output-ll -release -enable-inlining -enable-cross-module-inlining -O0 -of=%t.singleobj.O0.ll && FileCheck %s < %t.singleobj.O0.ll // Test linking too. // Separate compilation // RUN: %ldc -c -enable-inlining -enable-cross-module-inlining %S/inputs/inlinables.d -of=%t.inlinables%obj \ // RUN: && %ldc -I%S -enable-inlining -enable-cross-module-inlining %t.inlinables%obj %s -of=%t%exe // Singleobj compilation // RUN: %ldc -I%S -enable-inlining -enable-cross-module-inlining -singleobj %S/inputs/inlinables.d %s -of=%t2%exe import inputs.inlinables; int foo(int i) { return call_template_foo(i); } // Call a function calling std.exception.enforce with default __FILE__ template parameter. // Make sure the symbol is inlined/defined and not declared (which will lead to linker errors if the location // of the stdlib is different from where LDC was built from) void ggg() { call_enforce_with_default_template_params(); } void main() { } // CHECK-NOT: declare {{.*}}template_foo // CHECK-NOT: declare {{.*}}call_enforce_with_default_template_params // CHECK-NOT: declare {{.*}}__lambda // CHECK-NOT: declare {{.*}}_D3std9exception__T7enforce ./ldc-1.28.0-src/tests/codegen/array_equals_null.d0000644000175000017500000000120514141774365022143 0ustar matthiasmatthias// Tests that array (in)equality with null is optimized to a length check // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s // CHECK-LABEL: define{{.*}} @{{.*}}isNull bool isNull(int[] arg) { // CHECK-NOT: call // CHECK-NOT: invoke // CHECK: icmp eq i{{32|64}} %.len, 0 return arg == null; } // CHECK-LABEL: define{{.*}} @{{.*}}isNotNull bool isNotNull(int[] arg) { // CHECK-NOT: call // CHECK-NOT: invoke // CHECK: icmp ne i{{32|64}} %.len, 0 return arg != null; } void main() { int[3] i3 = [ 0, 1, 2 ]; assert(isNull(i3[0..0])); assert(isNotNull(i3[0..1])); } ./ldc-1.28.0-src/tests/codegen/asm_gcc_no_fp.d0000644000175000017500000000105614141774365021202 0ustar matthiasmatthias// Makes sure the frame pointer isn't enforced for GCC-style asm. // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-linux-gnu -mattr=avx -O -output-s -of=%t.s %s // RUN: FileCheck %s < %t.s alias byte32 = __vector(byte[32]); // CHECK: _D13asm_gcc_no_fp3xorFNhG32gQgZQj: byte32 xor(byte32 a, byte32 b) { // CHECK-NEXT: .cfi_startproc byte32 r; // CHECK-NEXT: #APP // CHECK-NEXT: vxorps %ymm0, %ymm1, %ymm0 // CHECK-NEXT: #NO_APP asm { "vxorps %0, %1, %2" : "=v" (r) : "v" (a), "v" (b); } // CHECK-NEXT: retq return r; } ./ldc-1.28.0-src/tests/codegen/linker_directives_win.d0000644000175000017500000000063014141774365023004 0ustar matthiasmatthias// RUN: %ldc -mtriple=x86_64-pc-windows-msvc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // REQUIRES: target_X86 // CHECK: !llvm.linker.options = !{!0, !1, !2} // CHECK: !0 = !{!"/DEFAULTLIB:\22mylib\22"} pragma(lib, "mylib"); // CHECK: !1 = !{!"-myflag"} pragma(linkerDirective, "-myflag"); // CHECK: !2 = !{!"-framework", !"CoreFoundation"} pragma(linkerDirective, "-framework", "CoreFoundation"); ./ldc-1.28.0-src/tests/codegen/gh3553.d0000644000175000017500000000043314141774365017341 0ustar matthiasmatthias// https://github.com/ldc-developers/ldc/issues/3553 // RUN: %ldc -run %s auto makeDelegate(alias fn)(long l) { auto callIt() { return fn() * l; } return &callIt; } void main() { int i = 7; auto dg = makeDelegate!(() => i)(3); assert(dg() == 21); } ./ldc-1.28.0-src/tests/codegen/variadic_thunk_gh2613.d0000644000175000017500000000050614141774365022411 0ustar matthiasmatthias// RUN: %ldc -run %s interface Stream { void write(...); } class OutputStream : Stream { void write(...) { import core.vararg; auto arg = va_arg!string(_argptr); assert(arg == "Hello world"); } } void main() { Stream stream = new OutputStream; stream.write("Hello world"); } ./ldc-1.28.0-src/tests/codegen/array_alloc_gh3041.d0000644000175000017500000000057114141774365021704 0ustar matthiasmatthias// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // CHECK-LABEL: define{{.*}} @{{.*}}3foo void[] foo() { // CHECK-NEXT: %.gc_mem = call {{.*}} @_d_newarrayT // CHECK-NEXT: %.ptr = extractvalue {{.*}} %.gc_mem, 1 // CHECK-NEXT: %1 = insertvalue {{.*}} { i{{32|64}} 3, i8* undef }, i8* %.ptr, 1 // CHECK-NEXT: ret {{.*}} %1 return new void[3]; } ./ldc-1.28.0-src/tests/codegen/attr_allocsize.d0000644000175000017500000000230114141774365021436 0ustar matthiasmatthias// Test ldc.attributes.allocSize // RUN: %ldc -O3 -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; // CHECK-LABEL: define{{.*}}@{{.*}}my_calloc // CHECK-SAME: #[[ATTR0:[0-9]+]] extern (C) void* my_calloc(size_t num, size_t size) @allocSize(1, 0) { return null; } // CHECK-LABEL: define{{.*}}@{{.*}}my_malloc // CHECK-SAME: #[[ATTR1:[0-9]+]] extern (C) void* my_malloc(int a, int b, size_t size, int c) @allocSize(2) { return null; } // Test the reversed parameter order of D calling convention // CHECK-LABEL: define{{.*}}@{{.*}}Dlinkage_calloc // CHECK-SAME: #[[ATTR2:[0-9]+]] extern (D) void* Dlinkage_calloc(int size, int b, size_t num, int c) @allocSize(0, 2) { return null; } // Test function type with hidden `this` argument class A { // CHECK-LABEL: define{{.*}}@{{.*}}this_calloc // CHECK-SAME: #[[ATTR3:[0-9]+]] void* this_calloc(int size, int b, size_t num, int c) @allocSize(0, 2) { return null; } } // CHECK-DAG: attributes #[[ATTR0]] ={{.*}} allocsize(1,0) // CHECK-DAG: attributes #[[ATTR1]] ={{.*}} allocsize(2) // CHECK-DAG: attributes #[[ATTR2]] ={{.*}} allocsize(3,1) // CHECK-DAG: attributes #[[ATTR3]] ={{.*}} allocsize(4,2) ./ldc-1.28.0-src/tests/codegen/switch_ICE_gh1638.d0000644000175000017500000000047014141774365021405 0ustar matthiasmatthias// Test for ICE bug Github issue 1638 // Don't make any changes/additions to this file without consulting GH #1638 first. // RUN: %ldc -I%S %S/inputs/switch_ICE_gh1638_bar.d %s -c // RUN: %ldc -I%S %s %S/inputs/switch_ICE_gh1638_bar.d -c import switch_ICE_gh1638_bar; int main() { return T().fun(123); } ./ldc-1.28.0-src/tests/codegen/lambdas_gh3648b.d0000644000175000017500000000143614141774365021177 0ustar matthiasmatthias// Tests that *imported* lambdas and contained globals are emitted as linkonce_odr. // RUN: %ldc -output-ll -of=%t.ll %s -I%S && FileCheck %s < %t.ll import lambdas_gh3648; void foo() { bar(); bar_inlined(); } // the global variables should be defined as linkonce_odr: // CHECK: _D14lambdas_gh36489__lambda5FZ10global_bari{{.*}} = linkonce_odr thread_local global // CHECK: _D14lambdas_gh36489__lambda6FZ18global_bar_inlinedOi{{.*}} = linkonce_odr global // foo() should only call one lambda: // CHECK: define {{.*}}_D15lambdas_gh3648b3fooFZv // CHECK-NEXT: call {{.*}}__lambda5 // CHECK-NEXT: ret void // bar() should be defined as linkonce_odr: // CHECK: define linkonce_odr {{.*}}__lambda5 // bar_inlined() should NOT have made it to the .ll: // CHECK-NOT: define {{.*}}__lambda6 ./ldc-1.28.0-src/tests/codegen/const_struct.d0000644000175000017500000000354414141774365021163 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s struct S0 { uint x; } struct S1 { S0 y; this(this) { y.x = 1; } } struct S2 { S1[3] z; } struct C0 { int *x; } void testNested() { int x; // The 'x' here is accessed via the nested context pointer struct N1 { ~this() { ++x; } } struct N0 { N1[3] x; } { N0 n; } assert(x == 3); } // CHECK: @.immutablearray{{.*}} = internal constant [4 x i32] // CHECK: @.immutablearray{{.*}} = internal constant [2 x float] // CHECK: @.immutablearray{{.*}} = internal constant [2 x double] // CHECK: @.immutablearray{{.*}} = internal constant [2 x { i{{32|64}}, i8* }] // CHECK: @.immutablearray{{.*}} = internal constant [1 x %const_struct.S2] // CHECK: @.immutablearray{{.*}} = internal constant [2 x i32*] {{.*}}globVar // CHECK: @.immutablearray{{.*}} = internal constant [2 x void ()*] {{.*}}Dmain void main () { // Simple types immutable int[] aA = [ 1, 2, 3, 4 ]; immutable float[] aB = [ 3.14, 3.33 ]; immutable double[] aC = [ 3.14, 3.33 ]; immutable string[] aD = [ "one", "two" ]; // Complex type immutable S2[] aE = [ { [ { { 42 } }, { { 43 } }, { { 44 } } ] } ]; // Complex type with non-constant initializer // CHECK: %.gc_mem = call { i{{32|64}}, i8* } @_d_newarrayU // CHECK-SAME: @{{.*}}_D29TypeInfo_yAS12const_struct2C06__initZ immutable C0[] aF = [ { new int(42) }, { new int(24) } ]; // Pointer types static immutable int globVar; immutable auto globalVariables = [ &globVar, &globVar ]; immutable auto functionPointers = [ &main, &main ]; // Pointer arrays with non-const initializer immutable int localVar; immutable auto locA = [ &localVar, &localVar ]; // CHECK: %.gc_mem{{.*}} = call { i{{32|64}}, i8* } @_d_newarrayU // CHECK-SAME: @{{.*}}_D13TypeInfo_yAPi6__initZ testNested(); } ./ldc-1.28.0-src/tests/codegen/lambdas_gh3648.d0000644000175000017500000000236214141774365021034 0ustar matthiasmatthias// Tests that lambdas and contained globals are emitted as linkonce_odr. // RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll enum bar = () { static int global_bar; }; enum bar_inlined = () { pragma(inline, true); shared static int global_bar_inlined; }; void foo() { bar(); bar_inlined(); (x) // template { __gshared int lambda_templ; return x + lambda_templ; }(123); } // the global variables should be defined as linkonce_odr: // CHECK: _D14lambdas_gh36489__lambda5FZ10global_bari{{.*}} = linkonce_odr thread_local global // CHECK: _D14lambdas_gh36489__lambda6FZ18global_bar_inlinedOi{{.*}} = linkonce_odr global // CHECK: _D14lambdas_gh36483fooFZ__T9__lambda1TiZQnFiZ12lambda_templi{{.*}} = linkonce_odr global // foo() should only call two lambdas: // CHECK: define {{.*}}_D14lambdas_gh36483fooFZv // CHECK-NEXT: call {{.*}}__lambda5 // CHECK-NEXT: call {{.*}}__T9__lambda1 // CHECK-NEXT: ret void // bar() should be defined as linkonce_odr: // CHECK: define linkonce_odr {{.*}}__lambda5 // bar_inlined() should NOT have made it to the .ll: // CHECK-NOT: define {{.*}}__lambda6 // the template lambda instance should be defined as linkonce_odr: // CHECK: define linkonce_odr {{.*}}__T9__lambda1 ./ldc-1.28.0-src/tests/codegen/dcompute_cl_images.d0000644000175000017500000000450414141774365022251 0ustar matthiasmatthias// REQUIRES: target_SPIRV // RUN: %ldc -c -mdcompute-targets=ocl-220 -m64 -I%S/inputs -mdcompute-file-prefix=%t -output-ll -output-o %s && FileCheck %s < %t_ocl220_64.ll @compute(CompileFor.deviceOnly) module dcompute_cl_images; import ldc.dcompute; import ldc.opencl; // CHECK-DAG: %opencl.image1d_ro_t = type opaque // CHECK-DAG: %opencl.image1d_wo_t = type opaque // CHECK-DAG: %"ldc.dcompute.Pointer!(AddrSpace.Global, image1d_ro_t).Pointer" = type { %opencl.image1d_ro_t addrspace(1)* } // CHECK-DAG: %"ldc.dcompute.Pointer!(AddrSpace.Global, image1d_wo_t).Pointer" = type { %opencl.image1d_wo_t addrspace(1)* } // CHECK-DAG: %"ldc.dcompute.Pointer!(AddrSpace.Shared, sampler_t).Pointer" = type { %opencl.sampler_t addrspace(2)* } // CHECK-DAG: %opencl.sampler_t = type opaque pragma(mangle,"__translate_sampler_initializer") Sampler makeSampler(int); pragma(mangle,"_Z11read_imagef11ocl_image1d_ro11ocl_sampleri") __vector(float[4]) read(GlobalPointer!image1d_ro_t, Sampler, int); pragma(mangle,"_Z12write_imagef11ocl_image1d_woiDv4_f") void write(GlobalPointer!image1d_wo_t,int,__vector(float[4])); @kernel void img(GlobalPointer!image1d_ro_t src, GlobalPointer!image1d_wo_t dst) { // CHECK: %{{[0-9+]}} = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 0) {{.*}} // CHECK: %{{[0-9+]}} = call spir_func <4 x float> @_Z11read_imagef11ocl_image1d_ro11ocl_sampleri(%opencl.image1d_ro_t addrspace(1)* %.DComputePointerRewrite_arg, %opencl.sampler_t addrspace(2)* %.DComputePointerRewrite_arg1, i32 0) {{.*}} auto x = src.read(makeSampler(0), 0); // CHECK: call spir_func void @_Z12write_imagef11ocl_image1d_woiDv4_f(%opencl.image1d_wo_t addrspace(1)* %.DComputePointerRewrite_arg2, i32 0, <4 x float> %{{[0-9+]}}) dst.write(0,x); } @kernel void img2(GlobalPointer!image1d_ro_t src, Sampler samp) { // CHECK: %{{[0-9+]}} = call spir_func <4 x float> @_Z11read_imagef11ocl_image1d_ro11ocl_sampleri(%opencl.image1d_ro_t addrspace(1)* %.DComputePointerRewrite_arg, %opencl.sampler_t addrspace(2)* %.DComputePointerRewrite_arg1, i32 0) {{.*}} auto x = src.read(samp, 0); } // metadata // CHECK: !{{[0-9+]}} = !{!"read_only", !"write_only"} // CHECK: !{{[0-9+]}} = !{!"image1d_ro_t", !"image1d_wo_t"} // CHECK: !{{[0-9+]}} = !{!"read_only", !"none"} // CHECK: !{{[0-9+]}} = !{!"image1d_ro_t", !"sampler_t"} ./ldc-1.28.0-src/tests/codegen/inbounds.d0000644000175000017500000000352314141774365020247 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll struct S { float x, y; }; extern(C): // Avoid name mangling // IndexExp in static array with const exp // CHECK-LABEL: @foo1 int foo1(int[3] a) { // CHECK: getelementptr inbounds [3 x i32] return a[1]; } // IndexExp in static array with variable exp // CHECK-LABEL: @foo2 int foo2(int[3] a, int i) { // CHECK: getelementptr inbounds [3 x i32] return a[i]; } // IndexExp in pointer // CHECK-LABEL: @foo3 int foo3(int* p, int i) { // CHECK: getelementptr inbounds return p[i]; } // PostExp in pointer // CHECK-LABEL: @foo4 int foo4(int* p) { // CHECK: getelementptr inbounds return *p++; } // PreExp in pointer // CHECK-LABEL: @foo5 int foo5(int* p) { // CHECK: getelementptr inbounds return *++p; } // Add offset to pointer // CHECK-LABEL: @foo6 int foo6(int* p, int i) { // CHECK: getelementptr inbounds return *(p + i); } // Subtract offset from pointer // CHECK-LABEL: @foo7 int foo7(int* p, int i) { // CHECK: getelementptr inbounds return *(p - i); } // Struct field // CHECK-LABEL: @foo8 float foo8(S s) { // CHECK: getelementptr inbounds return s.y; } // IndexExp in dynamic array with const exp // CHECK-LABEL: @foo9 int foo9(int[] a) { // CHECK: getelementptr inbounds i32, i32* return a[1]; } // IndexExp in dynamic array with variable exp // CHECK-LABEL: @foo10 int foo10(int[] a, int i) { // CHECK: getelementptr inbounds i32, i32* return a[i]; } // SliceExp for static array with const lower bound // CHECK-LABEL: @foo11 int[] foo11(ref int[3] a) { // CHECK: getelementptr inbounds i32, i32* return a[1 .. $]; } // SliceExp for dynamic array with variable lower bound // CHECK-LABEL: @foo12 int[] foo12(int[] a, int i) { // CHECK: getelementptr inbounds i32, i32* return a[i .. $]; } ./ldc-1.28.0-src/tests/codegen/attr_optstrat.d0000644000175000017500000000252514141774365021341 0ustar matthiasmatthias// RUN: %ldc -I%S -c -output-ll -O3 -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; extern (C): // For easier name mangling int glob1; int easily_inlinable(int i) { glob1 = i; return 2; } // CHECK-LABEL: define{{.*}} @call_easily_inlinable( // CHECK-SAME: #[[OPTNONE:[0-9]+]] @optStrategy("none") int call_easily_inlinable(int i) { // CHECK: call {{.*}} @easily_inlinable( return easily_inlinable(i); } pragma(inline, true) int always_inline() { return 321; } // CHECK-LABEL: define{{.*}} @call_always_inline( @optStrategy("none") int call_always_inline() { // CHECK-NOT: call {{.*}} @always_inline() return always_inline(); // CHECK: ret i32 321 } // optnone functions should not be inlined. int glob2; @optStrategy("none") void optnone_function(int i) { glob2 = i; } // CHECK-LABEL: define{{.*}} @call_optnone( void call_optnone() { // CHECK: call {{.*}} @optnone_function optnone_function(1); } // CHECK-LABEL: define{{.*}} @foo( // CHECK-SAME: #[[OPTSIZE:[0-9]+]] @optStrategy("optsize") void foo() { } // CHECK-LABEL: define{{.*}} @foo2( // CHECK-SAME: #[[MINSIZE:[0-9]+]] @optStrategy("minsize") void foo2() { } // CHECK-DAG: attributes #[[OPTNONE]] = {{.*}} noinline {{.*}} optnone // CHECK-DAG: attributes #[[OPTSIZE]] = {{.*}} optsize // CHECK-DAG: attributes #[[MINSIZE]] = {{.*}} minsize ./ldc-1.28.0-src/tests/codegen/gh3094.d0000644000175000017500000000030414141774365017336 0ustar matthiasmatthias// RUN: %ldc -run %s int bar() { return 0; } void foo(void delegate() sink) { return (bar(), sink()); } void main() { bool called; foo(() { called = true; }); assert(called); } ./ldc-1.28.0-src/tests/codegen/inputs/0000755000175000017500000000000014141774365017600 5ustar matthiasmatthias./ldc-1.28.0-src/tests/codegen/inputs/foo.d0000644000175000017500000000001614141774365020525 0ustar matthiasmatthiasvoid bar() {} ./ldc-1.28.0-src/tests/codegen/inputs/export2.d0000644000175000017500000000004114141774365021343 0ustar matthiasmatthiasexport int foo() { return 666; } ./ldc-1.28.0-src/tests/codegen/inputs/kernel.d0000644000175000017500000000050314141774365021223 0ustar matthiasmatthias@compute(CompileFor.deviceOnly) module inputs.kernel; import ldc.dcompute; @kernel void k_foo(GlobalPointer!float x_in) { SharedPointer!float shared_x; PrivatePointer!float private_x; ConstantPointer!float const_x; *shared_x = *x_in; *private_x = *x_in; *x_in = *const_x; *x_in = *shared_x; *x_in = *private_x; } ./ldc-1.28.0-src/tests/codegen/inputs/mangling_definitions.d0000644000175000017500000000306414141774365024137 0ustar matthiasmatthiasmodule definitions; // variables: extern(C) __gshared int cGlobal = 1; static assert(cGlobal.mangleof == "cGlobal"); extern(C++, cpp_vars) __gshared int cppGlobal = 2; version(CRuntime_Microsoft) static assert(cppGlobal.mangleof == "?cppGlobal@cpp_vars@@3HA"); else static assert(cppGlobal.mangleof == "_ZN8cpp_vars9cppGlobalE"); __gshared int dGlobal = 3; static assert(dGlobal.mangleof == "_D11definitions7dGlobali"); // functions: extern(C) int cFunc(double a) { return cGlobal; } static assert(cFunc.mangleof == "cFunc"); extern(C++, cpp_funcs) int cppFunc(double a) { return cppGlobal; } version(CRuntime_Microsoft) static assert(cppFunc.mangleof == "?cppFunc@cpp_funcs@@YAHN@Z"); else static assert(cppFunc.mangleof == "_ZN9cpp_funcs7cppFuncEd"); int dFunc(double a) { return dGlobal; } static assert(dFunc.mangleof == "_D11definitions5dFuncFdZi"); // naked functions: version(D_InlineAsm_X86) version = AsmX86; else version(D_InlineAsm_X86_64) version = AsmX86; version(AsmX86) { extern(C) int naked_cFunc(double a) { asm { naked; ret; } } static assert(naked_cFunc.mangleof == "naked_cFunc"); extern(C++, cpp_naked_funcs) int naked_cppFunc(double a) { asm { naked; ret; } } version(CRuntime_Microsoft) static assert(naked_cppFunc.mangleof == "?naked_cppFunc@cpp_naked_funcs@@YAHN@Z"); else static assert(naked_cppFunc.mangleof == "_ZN15cpp_naked_funcs13naked_cppFuncEd"); int naked_dFunc(double a) { asm { naked; ret; } } static assert(naked_dFunc.mangleof == "_D11definitions11naked_dFuncFdZi"); } ./ldc-1.28.0-src/tests/codegen/inputs/inlinables_staticvar.d0000644000175000017500000000400514141774365024144 0ustar matthiasmatthiasmodule inputs.inlinables_staticvar; /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ private int atModuleScope; pragma(inline, true) void addToModuleScopeInline(int i) { atModuleScope += i; } pragma(inline, false) void addToModuleScopeOutline(int i) { atModuleScope += i; } pragma(inline, false) bool equalModuleScope(int i) { return atModuleScope == i; } /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ pragma(inline, true) bool addAndCheckInsideFunc(int checkbefore, int increment) { static int insideFunc; if (insideFunc != checkbefore) return false; insideFunc += increment; return true; } pragma(inline, false) bool addAndCheckInsideFuncIndirect(int checkbefore, int increment) { return addAndCheckInsideFunc(checkbefore, increment); } /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ pragma(inline, true) bool addAndCheckInsideNestedFunc(int checkbefore, int increment) { pragma(inline, true) bool addCheckNested(int checkbefore, int increment) { static int insideFunc; if (insideFunc != checkbefore) return false; insideFunc += increment; return true; } return addCheckNested(checkbefore, increment); } pragma(inline, false) bool addAndCheckInsideNestedFuncIndirect(int checkbefore, int increment) { return addAndCheckInsideNestedFunc(checkbefore, increment); } /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ pragma(inline, true) bool addAndCheckNestedStruct(int checkbefore, int increment) { struct NestedStruct { static int structValue; } if (NestedStruct.structValue != checkbefore) return false; NestedStruct.structValue += increment; return true; } pragma(inline, false) bool addAndCheckNestedStructIndirect(int checkbefore, int increment) { return addAndCheckNestedStruct(checkbefore, increment); } /+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ ./ldc-1.28.0-src/tests/codegen/inputs/attr_weak_input.d0000644000175000017500000000016714141774365023151 0ustar matthiasmatthiasimport ldc.attributes; extern(C) @weak int return_two() { return 2; } extern(C) int return_seven() { return 7; } ./ldc-1.28.0-src/tests/codegen/inputs/switch_ICE_gh1638_bar.d0000644000175000017500000000061714141774365023556 0ustar matthiasmatthias// Don't make any changes/additions to this file without consulting Github issue 1638 first. module switch_ICE_gh1638_bar; struct S(T) { auto fun = (T a) { T r; switch (a) { case 1: r = 1; break; default: return 0; } return r * 2; }; } alias T = S!int; void f(int a) { int r = T().fun(a); } ./ldc-1.28.0-src/tests/codegen/inputs/module_ctor.d0000644000175000017500000000007714141774365022265 0ustar matthiasmatthiasimport core.stdc.stdio; static this() { puts("ctor\n"); } ./ldc-1.28.0-src/tests/codegen/inputs/attr_weak_external_input.d0000644000175000017500000000022014141774365025041 0ustar matthiasmatthiasimport ldc.attributes; extern(C) @weak int weak_definition_four() { return 4; } extern(C) @weak int weak_definition_seven() { return 7; } ./ldc-1.28.0-src/tests/codegen/inputs/fvisibility_dll_lib.d0000644000175000017500000000033414141774365023763 0ustar matthiasmatthiasimport ldc.attributes; __gshared int dllGlobal = 123; double dllSum(double a, double b) { return a + b; } void dllWeakFoo() @weak {} // extern(C++) for -betterC extern(C++) class MyClass { int myInt = 456; } ./ldc-1.28.0-src/tests/codegen/inputs/inlinables.d0000644000175000017500000000327114141774365022070 0ustar matthiasmatthiasmodule inputs.inlinables; import ldc.attributes; extern (C): // simplify mangling for easier function name matching int easily_inlinable(int i) { if (i > 0) return easily_inlinable(i - 1); return 2; } pragma(inline, false) int never_inline() { return 1; } @weak int external() { return 1; } pragma(inline, true) int always_inline() { int a; foreach (i; 1 .. 10) { foreach (ii; 1 .. 10) { foreach (iii; 1 .. 10) { a += i * external(); } } } return a; } pragma(inline, true) int always_inline_chain0() { return always_inline_chain1(); } pragma(inline, true) int always_inline_chain1() { return always_inline_chain2(); } pragma(inline, true) int always_inline_chain2() { return 345; } class A { int virtual_func() { return 12345; } pragma(inline, true) final int final_func() { return virtual_func(); } final int final_class_function() { return 12345; } } // Weak-linkage functions can not be inlined. @weak int weak_function() { return 654; } int module_variable = 666; pragma(inline, true) void write_module_variable(int i) { module_variable = i; } pragma(inline, true) void write_function_static_variable(int i) { static int static_func_var = 5; static_func_var = i; } pragma(inline, true) auto get_typeid_A() { return typeid(A); } pragma(inline, true) int call_template_foo(int i) { return template_foo(i); } pragma(inline, true) T template_foo(T)(T i) { return i; } void call_enforce_with_default_template_params() { import std.exception; enforce(true, { assert(0); }); } ./ldc-1.28.0-src/tests/codegen/inputs/export_marked_symbols_lib.d0000644000175000017500000000030614141774365025206 0ustar matthiasmatthiasextern(C++): // so that we can manually declare the symbols in another module too export __gshared int exportedGlobal; __gshared int normalGlobal; export void exportedFoo() {} void normalFoo() {} ./ldc-1.28.0-src/tests/codegen/inputs/input_discard_valuename.d0000644000175000017500000000044414141774365024634 0ustar matthiasmatthias// CHECK-LABEL: define{{.*}} @bar( extern(C) void bar() { // CHECK: localbarvar int localbarvar; } // Make sure we can use inline IR in non-textual IR compiles: double inlineIR(double a) { import ldc.llvmasm: __ir; auto s = __ir!(`ret double %0`, double)(a); return s; } ./ldc-1.28.0-src/tests/codegen/inputs/inlinables_asm.d0000644000175000017500000000037014141774365022725 0ustar matthiasmatthiasmodule inputs.inlinables_asm; import ldc.attributes; extern (C): // simplify mangling for easier function name matching pragma(inline, true) extern (C) void naked_asm_func() { asm pure nothrow @nogc { naked; nop; } } ./ldc-1.28.0-src/tests/codegen/asm_output.d0000644000175000017500000000051214141774365020621 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: %ldc -c -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s // Try to keep these very simple checks independent of architecture. // ASM: foofoofoofoo: extern(C) int foofoofoofoo() { // LLVM: ret i32 42 return 42; } ./ldc-1.28.0-src/tests/codegen/func_contracts_gh1543.d0000644000175000017500000000223714141774365022435 0ustar matthiasmatthias// Test the combination of `out` arguments with in- and out-contracts. // Github issue #1543, https://github.com/ldc-developers/ldc/issues/1543 // RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -run %s module mod; class Bar { void failMe(out int some) in { assert(some == 0); } out { assert(some == 123); } body { some = 123; } } // Bar.failMe codegen order = function, in-contract __require function, out-contract __ensure function // CHECK-LABEL: define {{.*}} @{{.*}}Bar6failMe // CHECK-SAME: i32* dereferenceable(4) %some // CHECK: store i32 0, i32* %some // CHECK: call {{.*}} @{{.*}}Bar6failMeMFJiZ9__require // CHECK: call {{.*}} @{{.*}}Bar6failMeMFJiZ8__ensure // CHECK: } // CHECK-LABEL: define {{.*}} @{{.*}}Bar6failMeMFJiZ9__require // CHECK-SAME: i32* dereferenceable(4) %some // CHECK-NOT: store {{.*}} %some // CHECK: } // CHECK-LABEL: define {{.*}} @{{.*}}Bar6failMeMFJiZ8__ensure // CHECK-SAME: i32* dereferenceable(4) %some // CHECK-NOT: store {{.*}} %some // CHECK: } void main() { int some; auto b = new Bar; b.failMe(some); assert(some == 123); } ./ldc-1.28.0-src/tests/codegen/attr_weak_lto.d0000644000175000017500000000125014141774365021260 0ustar matthiasmatthias// Test importing a @weak function with LTO // REQUIRES: LTO // RUN: %ldc -c %S/inputs/attr_weak_external_input.d -of=%t.external.thin%obj -flto=thin // RUN: %ldc -I%S -of=%t.thin%exe -flto=thin %s %t.external.thin%obj // RUN: %t.thin%exe // RUN: %ldc -c %S/inputs/attr_weak_external_input.d -of=%t.external.full%obj -flto=full // RUN: %ldc -I%S -of=%t.full%exe -flto=full %s %t.external.full%obj // RUN: %t.full%exe import inputs.attr_weak_external_input: weak_definition_seven; // Forward declaration intentionally without `@weak` extern(C) int weak_definition_four(); void main() { assert(&weak_definition_four != null); assert(&weak_definition_seven != null); } ./ldc-1.28.0-src/tests/codegen/output_s_affect_codegen.d0000644000175000017500000000104214141774365023276 0ustar matthiasmatthias // Check object files are identical regardless -output-s option // RUN: %ldc -c -O3 -output-s -output-o -of=%t1.o %s && %ldc -c -O3 -output-o -of=%t2.o %s && %diff_binary %t1.o %t2.o import core.simd; import ldc.simd; alias Vec = Vector!(float[4]); extern void foo(float*); // Just some random sufficiently complex code Vec bar(Vec v) { float[4] val; Vec ret; storeUnaligned!Vec(v,val.ptr); foo(val.ptr); ret = loadUnaligned!Vec(val.ptr); return ret; } Vec baz(Vec v) { return bar(bar(bar(bar(bar(bar(v)))))); } ./ldc-1.28.0-src/tests/codegen/gh3208.d0000644000175000017500000000064314141774365017341 0ustar matthiasmatthias// older LLVM versions fail the test for longer vectors // REQUIRES: atleast_llvm700 // RUN: %ldc -run %s void test(int length)() { __vector(byte[length]) a = 123, b = a; assert(a == b && !(a != b)); assert(a is b && !(a !is b)); b[0] = 0; assert(a != b && !(a == b)); assert(a !is b && !(a is b)); } void main() { static foreach (length; [16, 32, 64, 128, 256]) test!length(); } ./ldc-1.28.0-src/tests/codegen/align.d0000644000175000017500000000632114141774365017517 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // Fails on Windows_x86, see https://github.com/ldc-developers/ldc/issues/1356 // XFAIL: Windows_x86 align(32) struct Outer { int a = 1; } // CHECK-DAG: _D5align5Outer6__initZ = constant %align.Outer {{.*}}, align 32 struct Inner { align(32) int a = 1; } // CHECK-DAG: _D5align5Inner6__initZ = constant %align.Inner {{.*}}, align 32 align(1) ubyte globalByte1; // CHECK-DAG: _D5align11globalByte1h = {{.*}} align 1 static Outer globalOuter; // CHECK-DAG: _D5align11globalOuterSQu5Outer = {{.*}} align 32 static Inner globalInner; // CHECK-DAG: _D5align11globalInnerSQu5Inner = {{.*}} align 32 Outer passAndReturnOuterByVal(Outer arg) { return arg; } // CHECK: define{{.*}} void @{{.*}}_D5align23passAndReturnOuterByValFSQBh5OuterZQl /* the 32-bit x86 ABI substitutes the sret attribute by inreg */ // CHECK-SAME: %align.Outer* {{noalias sret.*|inreg noalias}} align 32 %.sret_arg /* How the arg is passed by value is ABI-specific, but the pointer must be aligned. * When the argument is passed as a byte array and copied into a stack alloc, that stack alloca must be aligned. */ // CHECK: {{(align 32 %arg|%arg = alloca %align.Outer, align 32)}} Inner passAndReturnInnerByVal(Inner arg) { return arg; } // CHECK: define{{.*}} void @{{.*}}_D5align23passAndReturnInnerByValFSQBh5InnerZQl // CHECK-SAME: %align.Inner* {{noalias sret.*|inreg noalias}} align 32 %.sret_arg // CHECK: {{(align 32 %arg|%arg = alloca %align.Inner, align 32)}} void main() { Outer outer; // CHECK: %outer = alloca %align.Outer, align 32 Inner inner; // CHECK: %inner = alloca %align.Inner, align 32 align(1) byte byte1; // CHECK: %byte1 = alloca i8, align 1 align(16) byte byte16; // CHECK: %byte16 = alloca i8, align 16 align(64) Outer outer64; // CHECK: %outer64 = alloca %align.Outer, align 64 align(128) Inner inner128; // CHECK: %inner128 = alloca %align.Inner, align 128 alias Byte8 = align(8) byte; Byte8 byte8; // Can aliases contain align(x) ? // C HECK: %byte8 = alloca i8, align 8 // C HECK: %byte8 = alloca i8, align 1 align(16) Outer outeroverride; // Yet undecided if align() should override type alignment: // C HECK: %outeroverride = alloca %align.Outer, align 16 // C HECK: %outeroverride = alloca %align.Outer, align 32 // CHECK: %.sret_tmp{{.*}} = alloca %align.Outer, align 32 // CHECK: %.sret_tmp{{.*}} = alloca %align.Inner, align 32 outer = passAndReturnOuterByVal(outer); // CHECK: call{{.*}} void @{{.*}}_D5align23passAndReturnOuterByValFSQBh5OuterZQl // CHECK-SAME: %align.Outer* {{noalias sret.*|inreg noalias}} align 32 %.sret_tmp // The argument is either passed by aligned (optimizer hint) pointer or as an array of i32/64 and copied into an aligned stack slot inside the callee. // CHECK-SAME: {{(align 32 %|\[[0-9]+ x i..\])}} inner = passAndReturnInnerByVal(inner); // CHECK: call{{.*}} void @{{.*}}_D5align23passAndReturnInnerByValFSQBh5InnerZQl // CHECK-SAME: %align.Inner* {{noalias sret.*|inreg noalias}} align 32 %.sret_tmp // The argument is either passed by aligned (optimizer hint) pointer or as an array of i32/64 and copied into an aligned stack slot inside the callee. // CHECK-SAME: {{(align 32 %|\[[0-9]+ x i..\])}} } ./ldc-1.28.0-src/tests/runlit.py0000755000175000017500000000106514141774365016546 0ustar matthiasmatthias#!/usr/bin/env python3 # wrapper to run lit from commandline from __future__ import print_function if __name__=='__main__': try: import lit.main except ImportError: import sys sys.exit('Package lit cannot be imported.\n' \ 'Lit can be installed using: \'python -m pip install -U lit\'\n' \ '(Python versions older than 2.7.9 or 3.4 do not have pip installed, see:\n' \ 'https://pip.pypa.io/en/latest/installing/)') print("Lit version: ", lit.__version__) lit.main.main() ./ldc-1.28.0-src/tests/semantic/0000755000175000017500000000000014141774365016455 5ustar matthiasmatthias./ldc-1.28.0-src/tests/semantic/target_traits_diag.d0000644000175000017500000000154314141774365022465 0ustar matthiasmatthias// Tests diagnostics of __traits(targetCPU) and __traits(targetHasFeature, ...) // RUN: not %ldc -c -w %s 2>&1 | FileCheck %s void main() { // CHECK: Warning: ignoring arguments for __traits targetCPU enum a = __traits(targetCPU, 1); // CHECK: Error: __traits targetHasFeature expects one argument, not 0 enum b = __traits(targetHasFeature); // CHECK: Error: __traits targetHasFeature expects one argument, not 2 enum c = __traits(targetHasFeature, "fma", 1); // CHECK: Error: expression expected as argument of __traits targetHasFeature enum d = __traits(targetHasFeature, main); // CHECK: Error: string expected as argument of __traits targetHasFeature instead of 1 enum e = __traits(targetHasFeature, 1); // CHECK: 夜畔' is not a recognized feature for this target (ignoring feature) enum f = __traits(targetHasFeature, "夜畔"); } ./ldc-1.28.0-src/tests/semantic/target_traits.d0000644000175000017500000000467314141774365021510 0ustar matthiasmatthias// Tests LDC-specific target __traits // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-apple-darwin -mcpu=nehalem -d-version=CPU_NEHALEM -c %s // RUN: %ldc -mtriple=i686-pc-linux -mcpu=pentium -mattr=+fma -d-version=ATTR_FMA -c %s // RUN: %ldc -mtriple=i686-pc-linux -mcpu=pentium -mattr=+fma,-sse -d-version=ATTR_FMA_MINUS_SSE -c %s // RUN: %ldc -mtriple=x86_64-apple-darwin -mcpu=haswell -d-version=CPU_HASWELL -c %s // Important: LLVM's default CPU selection already enables some features (like sse3) void main() { version (CPU_NEHALEM) { static assert(__traits(targetCPU) == "nehalem"); static assert(__traits(targetHasFeature, "sse3")); static assert(__traits(targetHasFeature, "sse4.1")); static assert(!__traits(targetHasFeature, "avx")); static assert(!__traits(targetHasFeature, "sse4")); static assert(!__traits(targetHasFeature, "sse4a")); static assert(!__traits(targetHasFeature, "unrecognized feature")); version(D_AVX) static assert(false); version(D_AVX2) static assert(false); } version (ATTR_FMA) { static assert(__traits(targetHasFeature, "sse")); static assert(__traits(targetHasFeature, "sse2")); static assert(__traits(targetHasFeature, "sse3")); static assert(__traits(targetHasFeature, "sse4.1")); static assert(__traits(targetHasFeature, "fma")); static assert(__traits(targetHasFeature, "avx")); static assert(!__traits(targetHasFeature, "avx2")); static assert(!__traits(targetHasFeature, "unrecognized feature")); version(D_AVX) {} else static assert(false); version(D_AVX2) static assert(false); } version (ATTR_FMA_MINUS_SSE) { // All implied features must be enabled for targetHasFeature to return true static assert(!__traits(targetHasFeature, "fma")); version(D_AVX) static assert(false); version(D_AVX2) static assert(false); } version (CPU_HASWELL) { static assert(__traits(targetHasFeature, "sse")); static assert(__traits(targetHasFeature, "sse2")); static assert(__traits(targetHasFeature, "sse3")); static assert(__traits(targetHasFeature, "sse4.1")); static assert(__traits(targetHasFeature, "avx")); static assert(__traits(targetHasFeature, "avx2")); version(D_AVX) {} else static assert(false); version(D_AVX2) {} else static assert(false); } } ./ldc-1.28.0-src/tests/semantic/traits_initSymbol.d0000644000175000017500000000202414141774365022337 0ustar matthiasmatthias// RUN: %ldc -run %s struct Zero { int x; } struct NonZero { long x = 1; } class C { short x = 123; } void main() { auto zeroInit = __traits(initSymbol, Zero); static assert(is(typeof(zeroInit) == const(void[]))); assert(zeroInit.ptr is null && zeroInit.length == Zero.sizeof); auto nonZeroInit = __traits(initSymbol, NonZero); static assert(is(typeof(nonZeroInit) == const(void[]))); assert(nonZeroInit.ptr !is null && nonZeroInit.length == NonZero.sizeof); assert(cast(const(long[])) nonZeroInit == [1L]); auto cInit = __traits(initSymbol, C); static assert(is(typeof(cInit) == const(void[]))); assert(cInit.ptr !is null && cInit.length == __traits(classInstanceSize, C)); scope c = new C; import core.stdc.string; assert(memcmp(cast(void*) c, cInit.ptr, cInit.length) == 0); static assert(!__traits(compiles, __traits(initSymbol, int))); static assert(!__traits(compiles, __traits(initSymbol, Zero[1]))); static assert(!__traits(compiles, __traits(initSymbol, 123))); } ./ldc-1.28.0-src/tests/semantic/dcompute_asm.d0000644000175000017500000000067714141774365021314 0ustar matthiasmatthias// Test that the "asm" statement is not allowed for DCompute code. // "asm" is only allowed for X86, so we must explicitly target X86 in this test. // REQUIRES: target_X86 // RUN: not %ldc -mtriple=x86_64-linux-gnu -o- %s 2>&1 | FileCheck %s @compute(CompileFor.deviceOnly) module tests.semaintic.dcompute; import ldc.dcompute; void func() { //CHECK: dcompute_asm.d([[@LINE+1]]): Error: asm not allowed in `@compute` code asm {ret;} } ./ldc-1.28.0-src/tests/semantic/dcompute.d0000644000175000017500000000562714141774365020454 0ustar matthiasmatthias// RUN: not %ldc -o- -verrors=0 -I%S %s 2>&1 | FileCheck %s @compute(CompileFor.deviceOnly) module tests.semaintic.dcompute; import ldc.dcompute; import inputs.notatcompute : somefunc; extern(C) bool perhaps(); //CHECK: dcompute.d([[@LINE+1]]): Error: {{.*}} interfaces and classes not allowed in `@compute` code interface I {} //CHECK: dcompute.d([[@LINE+1]]): Error: {{.*}} interfaces and classes not allowed in `@compute` code class C : Throwable { this() { super(""); } } //CHECK: dcompute.d([[@LINE+1]]): Error: {{.*}} global variables not allowed in `@compute` code C c; void func() { //CHECK: dcompute.d([[@LINE+1]]): Error: {{.*}} associative arrays not allowed in `@compute` code int[int] foo; //CHECK: dcompute.d([[@LINE+1]]): Error: array literal in `@compute` code not allowed auto bar = [0, 1, 2]; //CHECK: dcompute.d([[@LINE+1]]): Error: cannot use `new` in `@compute` code auto baz = new int; //CHECK: dcompute.d([[@LINE+1]]): Error: cannot use `delete` in `@compute` code delete baz; //CHECK: dcompute.d([[@LINE+1]]): Error: {{.*}} interfaces and classes not allowed in `@compute` code I i; //CHECK: dcompute.d([[@LINE+1]]): Error: {{.*}} interfaces and classes not allowed in `@compute` code C cc; int[] quux; //CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code quux.length = 1; //CHECK: dcompute.d([[@LINE+1]]): Error: cannot use operator `~=` in `@compute` code quux ~= 42; //CHECK: dcompute.d([[@LINE+1]]): Error: cannot use operator `~` in `@compute` code cast(void) (quux ~ 1); //CHECK: dcompute.d([[@LINE+1]]): Error: typeinfo not available in `@compute` code cast(void) typeid(int); //CHECK: dcompute.d([[@LINE+1]]): Error: cannot use `synchronized` in `@compute` code synchronized {} //CHECK: dcompute.d([[@LINE+1]]): Error: string literals not allowed in `@compute` code auto s = "geaxsese"; //CHECK: dcompute.d([[@LINE+1]]): Error: cannot `switch` on strings in `@compute` code switch(s) { default: break; } //CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code somefunc(); if (__dcompute_reflect(ReflectTarget.Host,0)) //CHECK-NOT: Error: somefunc(); //CHECK: dcompute.d([[@LINE+1]]): Error: no exceptions in `@compute` code try { func1(); } catch(C c) { } if (perhaps()) //CHECK: dcompute.d([[@LINE+1]]): Error: no exceptions in `@compute` code throw c; //CHECK-NOT: Error: try { func1(); } finally { func2(); } //CHECK-NOT: Error: scope(exit) func2(); } void func1() {} void func2() {} //CHECK: dcompute.d([[@LINE+1]]): Error: pragma `lib` linking additional libraries not supported in `@compute` code pragma(lib, "bar"); ./ldc-1.28.0-src/tests/semantic/target_traits_dcompute.d0000644000175000017500000000045214141774365023377 0ustar matthiasmatthias// Tests LDC-specific target __traits // RUN: %ldc -c %s -mdcompute-targets=cuda-350 -mdcompute-file-prefix=testing // REQUIRES: target_NVPTX static assert([ __traits(getTargetInfo, "dcomputeTargets") ] == ["cuda-350"]); static assert(__traits(getTargetInfo, "dcomputeFilePrefix") == "testing"); ./ldc-1.28.0-src/tests/semantic/inputs/0000755000175000017500000000000014141774365017777 5ustar matthiasmatthias./ldc-1.28.0-src/tests/semantic/inputs/notatcompute.d0000644000175000017500000000007714141774365022672 0ustar matthiasmatthiasmodule tests.semantic.inputs.notatcompute; void somefunc() {} ./ldc-1.28.0-src/tests/linking/0000755000175000017500000000000014141774365016305 5ustar matthiasmatthias./ldc-1.28.0-src/tests/linking/fullystatic.d0000644000175000017500000000062214141774365021015 0ustar matthiasmatthias/* Make sure -static overrides -link-defaultlib-shared. * We only care about the default libs in the linker command line; * make sure linking fails in all cases (no main()) as linking would * fail if there are no static default libs (BUILD_SHARED_LIBS=ON). */ // RUN: not %ldc -v -static -link-defaultlib-shared %s | FileCheck %s // CHECK-NOT: druntime-ldc-shared // CHECK-NOT: phobos2-ldc-shared ./ldc-1.28.0-src/tests/linking/fulllto_1.d0000644000175000017500000000035014141774365020351 0ustar matthiasmatthias// Test full LTO commandline flag // REQUIRES: LTO // RUN: %ldc %s -of=%t%obj -c -flto=full -vv | FileCheck %s // RUN: %ldc -flto=full -run %s // CHECK: Writing LLVM bitcode // CHECK-NOT: Creating module summary void main() { } ./ldc-1.28.0-src/tests/linking/linker_switches.d0000644000175000017500000000054414141774365021652 0ustar matthiasmatthias// Test if global order of flags passed with -Xcc, -L and pragma(lib) is preserved // UNSUPPORTED: Windows // RUN: %ldc %s --gcc=echo -Xcc=-Wl,-DOPT1,-DOPT2 -L-L/usr/lib -L--defsym -Lfoo=5 -Xcc -DOPT3 | FileCheck %s // CHECK: -Wl,-DOPT1,-DOPT2 -L/usr/lib -Xlinker --defsym -Xlinker foo=5 -DOPT3 {{.*}}-lpthread pragma(lib, "pthread"); void main() { } ./ldc-1.28.0-src/tests/linking/thinlto_1.d0000644000175000017500000000035714141774365020360 0ustar matthiasmatthias// Test ThinLTO commandline flag // REQUIRES: LTO // RUN: %ldc %s -of=%t%obj -c -flto=thin -vv | FileCheck %s // RUN: %ldc -flto=thin -run %s // CHECK: Writing LLVM bitcode // CHECK: Creating module summary for ThinLTO void main() { } ./ldc-1.28.0-src/tests/linking/ir2obj_caching_flags2.d0000644000175000017500000000261114141774365022553 0ustar matthiasmatthias// Test that certain cmdline flags result in different cache objects, even though the LLVM IR may be the same. // Test a few fsanitize-coverage options. // Note that the NO_HIT tests should change the default setting of the tested flag. // Create and then empty the cache for correct testing when running the test multiple times. // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir // RUN: %prunecache -f %t-dir --max-bytes=1 // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -g -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -fsanitize-coverage=trace-pc-guard -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -fsanitize-coverage=8bit-counters -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -fsanitize-coverage=trace-cmp -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -g -vv | FileCheck --check-prefix=MUST_HIT %s // The last test is a MUST_HIT test (hits with the first compile invocation), to make sure that the cache wasn't pruned somehow which could effectively disable some NO_HIT tests. // MUST_HIT: Cache object found! // NO_HIT: Cache object not found. // Could hit is used for cases where we could have a cache hit, but currently we don't: a "TODO" item. // COULD_HIT: Cache object void main() {} ./ldc-1.28.0-src/tests/linking/betterc_cleanups.d0000644000175000017500000000110214141774365021766 0ustar matthiasmatthias// RUN: %ldc -betterC -run %s > %t.stdout // RUN: FileCheck %s < %t.stdout import core.stdc.stdio; void notNothrow() { printf("notNothrow\n"); } struct WithDtor { ~this() { printf("destructing\n"); } } void foo(WithDtor a, bool skip) { if (skip) return; notNothrow(); } extern(C) int main() { WithDtor a; scope(exit) printf("exiting\n"); foo(a, true); // CHECK: destructing foo(a, false); // CHECK-NEXT: notNothrow // CHECK-NEXT: destructing return 0; // CHECK-NEXT: exiting // CHECK-NEXT: destructing } ./ldc-1.28.0-src/tests/linking/thinlto_asm_x86.d0000644000175000017500000000065714141774365021510 0ustar matthiasmatthias// ThinLTO: Test inline assembly functions with thinlto // REQUIRES: LTO // REQUIRES: host_X86 // Naked DMD-style asm (LLVM module-level inline assembly) with LTO on Windows // is only supported since LLVM 9. // REQUIRES: !Windows || atleast_llvm900 // RUN: %ldc -flto=thin %S/inputs/asm_x86.d -c -of=%t_input%obj // RUN: %ldc -flto=thin -I%S %s %t_input%obj import inputs.asm_x86; int main() { return simplefunction(); } ./ldc-1.28.0-src/tests/linking/ir2obj_cache_pruning.d0000644000175000017500000000104114141774365022522 0ustar matthiasmatthias// Test recognition of -cache-prune-* commandline flags // RUN: %ldc %s -cache=%t-dir -cache-prune // RUN: %ldc %s -cache=%t-dir -cache-prune-interval=10 -cache-prune-maxbytes=10000 // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-interval=0 // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-maxbytes=10000 // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-expiration=10000 // RUN: %ldc %s -cache=%t-dir -cache-prune-maxpercentage=50 // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-maxpercentage=150 void main() { } ./ldc-1.28.0-src/tests/linking/link_bitcode.d0000644000175000017500000000136614141774365021106 0ustar matthiasmatthias// Test linking with an LLVM bitcode file // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input.d -of=%t.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_import.d -of=%t2.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input3.d -of=%t3.bc // RUN: %ldc -c -singleobj -output-bc %t.bc %t3.bc %s // RUN: %ldc -c -singleobj -I%S %t.bc %s %S/inputs/link_bitcode_input3.d // RUN: %ldc -c -singleobj -I%S %t.bc %S/inputs/link_bitcode_input3.d %s // RUN: %ldc -c -I%S %t.bc %S/inputs/link_bitcode_input3.d %s // RUN: %ldc %t.bc %t2.bc %t3.bc -run %s // RUN: %ldc %t.bc %S/inputs/link_bitcode_import.d %t3.bc -run %s // Defined in input/link_bitcode_input.d extern(C) int return_seven(); void main() { assert( return_seven() == 7 ); } ./ldc-1.28.0-src/tests/linking/ir2obj_caching.d0000644000175000017500000000072714141774365021323 0ustar matthiasmatthias// Test recognition of -cache commandline flag // RUN: %ldc -cache=%t-dir %s -vv | FileCheck --check-prefix=FIRST %s // RUN: %ldc -cache=%t-dir %s -vv | FileCheck --check-prefix=SECOND %s // FIRST: Use IR-to-Object cache in {{.*}}-dir // Don't check whether the object is in the cache on the first run, because if this test is ran twice the cache will already be there. // SECOND: Use IR-to-Object cache in {{.*}}-dir // SECOND: Cache object found! void main() { } ./ldc-1.28.0-src/tests/linking/thinlto_modulecdtors_2.d0000644000175000017500000000044714141774365023145 0ustar matthiasmatthias// REQUIRES: LTO // UNSUPPORTED: FreeBSD // RUN: %ldc -flto=thin -O3 %S/inputs/thinlto_ctor.d -run %s | FileCheck --check-prefix=EXECUTE %s // EXECUTE: ctor // EXECUTE: main // EXECUTE: dtor import core.stdc.stdio; static ~this() { puts("dtor\n"); } void main() { puts("main\n"); } ./ldc-1.28.0-src/tests/linking/link_bitcode_libs.d0000644000175000017500000000137514141774365022117 0ustar matthiasmatthias// Test passing of LLVM bitcode file with Linker Options set // Linker Options are currently only set on Windows platform, so we must (cross-)compile to Windows // REQUIRES: target_X86 // RUN: %ldc -mtriple=x86_64-windows -c -output-bc %S/inputs/link_bitcode_libs_input.d -of=%t.bc \ // RUN: && %ldc -mtriple=x86_64-windows -c -singleobj -output-ll %t.bc %s -of=%t.ll \ // RUN: && FileCheck %s < %t.ll pragma(lib, "library_one"); pragma(lib, "library_two"); // CHECK: !llvm.linker.options = !{![[ATTR_LIB1:[0-9]+]], ![[ATTR_LIB2:[0-9]+]], ![[ATTR_LIB3:[0-9]+]], ![[ATTR_LIB4:[0-9]+]]} // CHECK: ![[ATTR_LIB1]]{{.*}}library_one // CHECK: ![[ATTR_LIB2]]{{.*}}library_two // CHECK: ![[ATTR_LIB3]]{{.*}}imported_one // CHECK: ![[ATTR_LIB4]]{{.*}}imported_two ./ldc-1.28.0-src/tests/linking/thinlto_modulecdtors.d0000644000175000017500000000051514141774365022720 0ustar matthiasmatthias// ThinLTO: Test that module ctors/dtors are called // REQUIRES: LTO // UNSUPPORTED: FreeBSD // RUN: %ldc -flto=thin -O3 -run %s | FileCheck %s // CHECK: ctor // CHECK: main // CHECK: dtor import core.stdc.stdio; static this() { puts("ctor\n"); } static ~this() { puts("dtor\n"); } void main() { puts("main\n"); } ./ldc-1.28.0-src/tests/linking/betterc.d0000644000175000017500000000050414141774365020101 0ustar matthiasmatthias// RUN: %ldc -betterC -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll // RUN: %ldc -betterC -run %s // CHECK-NOT: ModuleInfoZ // CHECK-NOT: ModuleRefZ // CHECK-NOT: call void @ldc.register_dso extern (C) int main(int argc, char** argv) { assert(argc == 1); // make sure we can link against C assert return 0; } ./ldc-1.28.0-src/tests/linking/rt_options.d0000644000175000017500000000024714141774365020655 0ustar matthiasmatthias// RUN: %ldc -run %s extern(C) __gshared string[] rt_options = [ "key=value" ]; void main() { import rt.config; assert(rt_configOption("key") == "value"); } ./ldc-1.28.0-src/tests/linking/platformlib.d0000644000175000017500000000134214141774365020765 0ustar matthiasmatthias// Make sure -platformlib overrides the default platform libraries list. // RUN: %ldc %s -platformlib= -gcc=echo -linker=echo | FileCheck --check-prefix=EMPTY %s // EMPTY-NOT: -lrt // EMPTY-NOT: -ldl // EMPTY-NOT: -lpthread // EMPTY-NOT: -lm // EMPTY-NOT: kernel32 // EMPTY-NOT: user32 // EMPTY-NOT: gdi32 // EMPTY-NOT: winspool // EMPTY-NOT: shell32 // EMPTY-NOT: ole32 // EMPTY-NOT: oleaut32 // EMPTY-NOT: uuid // EMPTY-NOT: comdlg32 // EMPTY-NOT: advapi32 // EMPTY-NOT: oldnames // EMPTY-NOT: legacy_stdio_definitions // RUN: %ldc %s -platformlib=myPlatformLib1,myPlatformLib2 -gcc=echo -linker=echo | FileCheck --check-prefix=CUSTOM %s // CUSTOM: {{(-lmyPlatformLib1 -lmyPlatformLib2)|(myPlatformLib1.lib myPlatformLib2.lib)}} ./ldc-1.28.0-src/tests/linking/ir2obj_caching_retrieval.d0000644000175000017500000000146114141774365023374 0ustar matthiasmatthias// Test recognition of -cache-retrieval commandline flag // RUN: %ldc -c -of=%t%obj -cache=%t-dir %s -vv | FileCheck --check-prefix=FIRST %s // RUN: %ldc -c -of=%t%obj -cache=%t-dir %s -cache-retrieval=copy -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %t%obj // RUN: %ldc -c -of=%t%obj -cache=%t-dir %s -cache-retrieval=link -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %t%obj // RUN: %ldc -c -of=%t%obj -cache=%t-dir %s -cache-retrieval=hardlink -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %t%obj // FIRST: Use IR-to-Object cache in {{.*}}-dir // Don't check whether the object is in the cache on the first run, because if this test is ran twice the cache will already be there. // MUST_HIT: Use IR-to-Object cache in {{.*}}-dir // MUST_HIT: Cache object found! void main() { } ./ldc-1.28.0-src/tests/linking/link_internally.d0000644000175000017500000000023114141774365021644 0ustar matthiasmatthias// REQUIRES: Windows // REQUIRES: internal_lld // RUN: %ldc -link-internally -run %s void main() { import std.stdio; writeln("Hello world"); } ./ldc-1.28.0-src/tests/linking/ir2obj_caching_flags1.d0000644000175000017500000000761214141774365022560 0ustar matthiasmatthias// Test that certain cmdline flags result in different cache objects, even though the LLVM IR may be the same. // Note that the NO_HIT tests should change the default setting of the tested flag. // Create and then empty the cache for correct testing when running the test multiple times. // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir // RUN: %prunecache -f %t-dir --max-bytes=1 // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -g -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -O -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -O3 -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -O2 -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -O4 -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc -O5 %s -c -of=%t%obj -cache=%t-dir -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -Os -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -Oz -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -disable-d-passes -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -disable-simplify-drtcalls -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -disable-simplify-libcalls -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -disable-gc2stack -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -enable-inlining -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -strip-debug -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -disable-loop-unrolling -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -disable-loop-vectorization -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -disable-slp-vectorization -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -vectorize-loops -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -v -wi -d -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -D -H -I. -J. -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -d-version=Irrelevant -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -unittest -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %s -cache=%t-dir -lib -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc -cache=%t-dir -vv -run %s | FileCheck --check-prefix=COULD_HIT %s // RUN: %ldc -cache=%t-dir -vv -run %s a b | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -g -vv | FileCheck --check-prefix=MUST_HIT %s // The last test is a MUST_HIT test (hits with the first compile invocation), to make sure that the cache wasn't pruned somehow which could effectively disable some NO_HIT tests. // MUST_HIT: Cache object found! // NO_HIT: Cache object not found. // Could hit is used for cases where we could have a cache hit, but currently we don't: a "TODO" item. // COULD_HIT: Cache object void main() {} ./ldc-1.28.0-src/tests/linking/inputs/0000755000175000017500000000000014141774365017627 5ustar matthiasmatthias./ldc-1.28.0-src/tests/linking/inputs/thinlto_ctor.d0000644000175000017500000000007714141774365022510 0ustar matthiasmatthiasimport core.stdc.stdio; static this() { puts("ctor\n"); } ./ldc-1.28.0-src/tests/linking/inputs/asm_x86.d0000644000175000017500000000014714141774365021263 0ustar matthiasmatthiasvoid foo() { asm { naked; ret; } } int simplefunction() { return 1; } ./ldc-1.28.0-src/tests/linking/inputs/link_bitcode_input.d0000644000175000017500000000025714141774365023645 0ustar matthiasmatthiasmodule inputs.link_bitcode_input; extern(C) int return_seven() { return 7; } import inputs.link_bitcode_import; void bar() { SomeStrukt r = {1}; takeStrukt(&r); } ./ldc-1.28.0-src/tests/linking/inputs/link_bitcode_input3.d0000644000175000017500000000020314141774365023717 0ustar matthiasmatthiasmodule inputs.link_bitcode_input3; import inputs.link_bitcode_import; void foo() { SomeStrukt r = {0}; takeStrukt(&r); } ./ldc-1.28.0-src/tests/linking/inputs/link_bitcode_import.d0000644000175000017500000000017314141774365024015 0ustar matthiasmatthiasmodule inputs.link_bitcode_import; extern(C) struct SomeStrukt { int i; } extern(C) void takeStrukt(SomeStrukt*) {}; ./ldc-1.28.0-src/tests/linking/inputs/link_bitcode_libs_input.d0000644000175000017500000000014114141774365024646 0ustar matthiasmatthiasmodule inputs.link_bitcode_libs_input; pragma(lib, "imported_one"); pragma(lib, "imported_two");./ldc-1.28.0-src/tests/linking/ir2obj_cache_pruning2.d0000644000175000017500000000327414141774365022616 0ustar matthiasmatthias// Test cache pruning for size // This test assumes that the `void main(){}` object file size is below 200_000 bytes and above 200_000/2, // such that rebuilding with version(NEW_OBJ_FILE) will clear the cache of all but the latest object file. // RUN: %ldc %s -cache=%t-dir // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-interval=0 -d-version=SLEEP // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-interval=0 -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-interval=0 -vv -d-version=NEW_OBJ_FILE | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-interval=0 -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc -d-version=SLEEP -run %s // RUN: %ldc %s -c -of=%t%obj -cache=%t-dir -cache-prune-interval=0 -cache-prune-maxbytes=200000 -vv | FileCheck --check-prefix=MUST_HIT %s // RUN: %ldc %t%obj // RUN: %ldc %s -cache=%t-dir -d-version=SLEEP -vv | FileCheck --check-prefix=NO_HIT %s // RUN: %ldc -d-version=SLEEP -run %s // RUN: %ldc %s -cache=%t-dir -cache-prune-interval=1 -cache-prune-maxbytes=200000 -d-version=NEW_OBJ_FILE // RUN: %ldc %s -cache=%t-dir -cache-prune -cache-prune-interval=0 -vv | FileCheck --check-prefix=NO_HIT %s // MUST_HIT: Cache object found! // NO_HIT-NOT: Cache object found! void main() { // Add non-zero static data to guarantee a binary size larger than 200_000/2. static byte[120_000] dummy = 1; version (NEW_OBJ_FILE) { auto a = __TIME__; } version (SLEEP) { // Sleep for 4 seconds, so we are sure that the cache object file timestamps are "aging". import core.thread; Thread.sleep( dur!"seconds"(4) ); } } ./ldc-1.28.0-src/tests/linking/linker_empty.d0000644000175000017500000000035714141774365021161 0ustar matthiasmatthias// Check that the user can override LDC passing `-fuse-ld` to `cc`. // REQUIRES: target_X86 // RUN: %ldc --gcc=echo --mtriple=x86_64-linux --linker= %s | FileCheck %s // CHECK-NOT: -fuse-ld // CHECK: linker_empty // CHECK-NOT: -fuse-ld ./ldc-1.28.0-src/tests/driver/0000755000175000017500000000000014141774365016145 5ustar matthiasmatthias./ldc-1.28.0-src/tests/driver/gh2073.d0000644000175000017500000000043014141774365017221 0ustar matthiasmatthias// RUN: %ldc -mcpu=help 2>&1 | FileCheck %s // RUN: %ldc -mattr=help 2>&1 | FileCheck %s // RUN: %ldc -mcpu=help -mattr=help 2>&1 | FileCheck %s // CHECK: Available CPUs for this target: // CHECK: Available features for this target: // CHECK-NOT: Available CPUs for this target: ./ldc-1.28.0-src/tests/driver/config_diag.d0000644000175000017500000000054314141774365020545 0ustar matthiasmatthias// RUN: not %ldc -conf=%S/inputs/noswitches.conf %s 2>&1 | FileCheck %s --check-prefix=NOSWITCHES // NOSWITCHES: Could not look up switches in {{.*}}noswitches.conf // RUN: not %ldc -conf=%S/inputs/section_aaa.conf %s 2>&1 | FileCheck %s --check-prefix=NO_SEC // NO_SEC: No matching section for triple '{{.*}}' in {{.*}}section_aaa.conf void foo() { } ./ldc-1.28.0-src/tests/driver/include_imports.d0000644000175000017500000000131414141774365021511 0ustar matthiasmatthias// Make sure that -i includes an imported custom module, but excludes // druntime and Phobos modules. // Make sure it links and check the -v output: // RUN: %ldc -I%S -i %s -v | FileCheck %s // CHECK-NOT: {{^code .*}} // CHECK: {{^code include_imports2}} // CHECK-NOT: {{^code .*}} // CHECK: {{^code include_imports}} // CHECK-NOT: {{^code .*}} static import core.stdc.math; // druntime static import std.math; // Phobos import ldc.attributes : assumeUsed; // LDC-specific druntime import inputs.include_imports2 : bar; @assumeUsed void test(string s, double x) { const r1 = core.stdc.math.log(x); const r2 = std.math.log(x); bar(); } void main() { test("abc", 0.5); } ./ldc-1.28.0-src/tests/driver/ftime-trace.d0000644000175000017500000000156614141774365020522 0ustar matthiasmatthias// Test --ftime-trace functionality // RUN: %ldc --ftime-trace --ftime-trace-file=%t.1 --ftime-trace-granularity=1 %s && FileCheck --check-prefix=ALL --check-prefix=FINE %s < %t.1 // RUN: %ldc --ftime-trace --ftime-trace-file=%t.2 --ftime-trace-granularity=20000 %s && FileCheck --check-prefix=ALL --check-prefix=COARSE %s < %t.2 // RUN: %ldc --ftime-trace --ftime-trace-file=- --ftime-trace-granularity=20000 %s | FileCheck --check-prefix=ALL --check-prefix=COARSE %s // ALL: traceEvents module ftimetrace; // FINE: stdio // FINE: ftime-trace.d:[[@LINE+1]] import std.stdio; int ctfe() { int sum; foreach (i; 0..100) { sum += i; } return sum; } // COARSE-NOT: foo // FINE: foo // FINE: ftime-trace.d:[[@LINE+1]] int foo() { enum s = ctfe(); return s; } void main() { foo(); } // ALL-DAG: ExecuteCompiler // FINE-DAG: Linking executable ./ldc-1.28.0-src/tests/driver/drt_options_in_rsp_file.d0000644000175000017500000000014014141774365023222 0ustar matthiasmatthias// RUN: %ldc -c %s @%S/inputs/drt_options_in_rsp_file.rsp | FileCheck %s // CHECK: GC summary: ./ldc-1.28.0-src/tests/driver/gh1945.d0000644000175000017500000000023514141774365017233 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -c %s -v -march=x86 | FileCheck %s // RUN: %ldc -c %s -v -march x86 | FileCheck %s // CHECK: config {{.*}}.conf (i686- ./ldc-1.28.0-src/tests/driver/mscrtlib.d0000644000175000017500000000120014141774365020122 0ustar matthiasmatthias// On Windows, re-test dmd-testsuite's runnable\eh.d with all 4 MS C runtime variants. // In case of failures, it's very likely that the EH terminate hook in druntime's // ldc.eh.msvc.msvc_eh_terminate() needs to be adapted. // REQUIRES: Windows // RUN: %ldc -mscrtlib=libcmt -run "%S\..\d2\dmd-testsuite\runnable\eh.d" // RUN: %ldc -mscrtlib=libcmtd -link-defaultlib-debug -run "%S\..\d2\dmd-testsuite\runnable\eh.d" // RUN: %ldc -mscrtlib=msvcrt -link-defaultlib-debug -run "%S\..\d2\dmd-testsuite\runnable\eh.d" // RUN: %ldc -mscrtlib=msvcrtd -run "%S\..\d2\dmd-testsuite\runnable\eh.d" ./ldc-1.28.0-src/tests/driver/save_optimization_record.d0000644000175000017500000000133414141774365023415 0ustar matthiasmatthias// Automatic output filename generation from LL output file // RUN: %ldc -c -betterC -O3 -g -fsave-optimization-record -output-ll -of=%t.1.ll %s \ // RUN: && FileCheck %s --check-prefix=LLVM < %t.1.ll \ // RUN: && FileCheck %s --check-prefix=YAML < %t.1.opt.yaml // Explicit filename specified // RUN: %ldc -c -betterC -O3 -g -fsave-optimization-record=%t.abcdefg -output-ll -of=%t.ll %s \ // RUN: && FileCheck %s --check-prefix=LLVM < %t.ll \ // RUN: && FileCheck %s --check-prefix=YAML < %t.abcdefg int alwaysInlined(int a) { return a; } int foo() { // LLVM: 8329424 // YAML: File: {{.*}}save_optimization_record.d{{.*[[:space:]]?.*}}Line: [[@LINE+1]] return 8329423 + alwaysInlined(1); } // LLVM: !DILocation(line ./ldc-1.28.0-src/tests/driver/post_switches.d0000644000175000017500000000117314141774365021212 0ustar matthiasmatthias// RUN: not %ldc -I=%runtimedir/src -conf=%S/inputs/post_switches.conf %s -v -L-user-passed-switch | FileCheck %s // CHECK: -normal-switch // CHECK-SAME: -normal-two-switch // CHECK-SAME: -user-passed-switch // CHECK-SAME: -post-switch // CHECK-SAME: -post-two-switch // RUN: not %ldc -I=%runtimedir/src -conf=%S/inputs/post_switches.conf -v -L-user-passed-switch -run %s -L-after-run | FileCheck %s --check-prefix=WITHrUN // WITHrUN: -normal-switch // WITHrUN-SAME: -normal-two-switch // WITHrUN-SAME: -user-passed-switch // WITHrUN-SAME: -post-switch // WITHrUN-SAME: -post-two-switch // WITHrUN-NOT: -after-run void main() { } ./ldc-1.28.0-src/tests/driver/missing_tool.d0000644000175000017500000000027714141774365021026 0ustar matthiasmatthias// Test that LDC complains about a missing tool. // RUN: not %ldc %s -gcc=IdontExist -linker=IdontExist 2>&1 | FileCheck %s // CHECK: Error: cannot find program `IdontExist` void main() {} ./ldc-1.28.0-src/tests/driver/cleanup_obj_gh3643.d0000644000175000017500000000032414141774365021570 0ustar matthiasmatthiasmodule tests.driver.cleanup_obj; // REQUIRES: target_X86 // RUN: %ldc -cleanup-obj -oq -gcc=echo -mtriple=x86_64-linux %s | FileCheck %s // CHECK: objtmp-ldc-{{([a-zA-Z0-9]{6})[/\\]}}tests.driver.cleanup_obj.o ./ldc-1.28.0-src/tests/driver/gh1941.d0000644000175000017500000000012614141774365017226 0ustar matthiasmatthias// RUN: %ldc -c %s @%S/gh1941.rsp 2>&1 | FileCheck %s // CHECK: 'foo.conf' not found ./ldc-1.28.0-src/tests/driver/float_abi.d0000644000175000017500000000211614141774365020232 0ustar matthiasmatthias// REQUIRES: target_ARM // RUN: %ldc -c -o- %s -mtriple=armv7-linux-android -float-abi=soft -d-version=SOFT // RUN: %ldc -c -o- %s -mtriple=armv7-linux-android -float-abi=softfp -d-version=SOFTFP // RUN: %ldc -c -o- %s -mtriple=armv7-linux-gnueabihf -d-version=HARD version (SOFT) { version (ARM_SoftFloat) {} else static assert(0); version (ARM_SoftFP) static assert(0); version (ARM_HardFloat) static assert(0); version (D_SoftFloat) {} else static assert(0); version (D_HardFloat) static assert(0); } else version (SOFTFP) { version (ARM_SoftFloat) static assert(0); version (ARM_SoftFP) {} else static assert(0); version (ARM_HardFloat) static assert(0); version (D_SoftFloat) static assert(0); version (D_HardFloat) {} else static assert(0); } else version (HARD) { version (ARM_SoftFloat) static assert(0); version (ARM_SoftFP) static assert(0); version (ARM_HardFloat) {} else static assert(0); version (D_SoftFloat) static assert(0); version (D_HardFloat) {} else static assert(0); } else static assert(0); ./ldc-1.28.0-src/tests/driver/config_diag_x86.d0000644000175000017500000000034514141774365021252 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: %ldc -conf=%S/inputs/override_default.conf -mtriple=x86-apple-windows-msvc -c -o- %s | FileCheck %s --check-prefix=OVERRIDE_DEFAULT // OVERRIDE_DEFAULT: LDC - the LLVM D compiler void foo() { } ./ldc-1.28.0-src/tests/driver/cli_preparsing.d0000644000175000017500000000102214141774365021306 0ustar matthiasmatthias// REQUIRES: target_X86 // RUN: not %ldc -o- -conf= %s 2>&1 | FileCheck --check-prefix=NO_CONF %s // RUN: not %ldc -o- --conf "" %s 2>&1 | FileCheck --check-prefix=NO_CONF %s // NO_CONF: Error: cannot find source code for runtime library file 'object.d' // RUN: %ldc -v -o- -mtriple x86_64-vendor-windows-msvc %s 2>&1 | FileCheck --check-prefix=TRIPLE %s // RUN: %ldc -v -o- --mtriple=x86_64-vendor-windows-msvc %s 2>&1 | FileCheck --check-prefix=TRIPLE %s // TRIPLE: config // TRIPLE-SAME: (x86_64-vendor-windows-msvc) ./ldc-1.28.0-src/tests/driver/gh1941.rsp0000644000175000017500000000001714141774365017606 0ustar matthiasmatthias-conf=foo.conf ./ldc-1.28.0-src/tests/driver/inputs/0000755000175000017500000000000014141774365017467 5ustar matthiasmatthias./ldc-1.28.0-src/tests/driver/inputs/override_default.conf0000644000175000017500000000014214141774365023656 0ustar matthiasmatthiasdefault: { switches = [ "" ]; }; x86-apple-windows-msvc: { switches = [ "-version" ]; }; ./ldc-1.28.0-src/tests/driver/inputs/section_aaa.conf0000644000175000017500000000004114141774365022577 0ustar matthiasmatthiasaaa: { switches = [ "" ]; }; ./ldc-1.28.0-src/tests/driver/inputs/drt_options_in_rsp_file.rsp0000644000175000017500000000002614141774365025130 0ustar matthiasmatthias--DRT-gcopt=profile:1 ./ldc-1.28.0-src/tests/driver/inputs/include_imports2.d0000644000175000017500000000001614141774365023113 0ustar matthiasmatthiasvoid bar() {} ./ldc-1.28.0-src/tests/driver/inputs/noswitches.conf0000644000175000017500000000001614141774365022521 0ustar matthiasmatthiasdefault: { }; ./ldc-1.28.0-src/tests/driver/inputs/post_switches.conf0000644000175000017500000000026514141774365023237 0ustar matthiasmatthiasdefault: { switches = [ "-L-normal-switch", "-L-normal-two-switch" ]; post-switches = [ "-L-post-switch", "-L-post-two-switch" ]; }; ./ldc-1.28.0-src/tests/CMakeLists.txt0000644000175000017500000000140714141774365017414 0ustar matthiasmatthiasset( LDC2_BIN ${PROJECT_BINARY_DIR}/bin/${LDC_EXE} ) set( LDCPROFDATA_BIN ${PROJECT_BINARY_DIR}/bin/ldc-profdata ) set( LDCPRUNECACHE_BIN ${PROJECT_BINARY_DIR}/bin/${LDCPRUNECACHE_EXE} ) set( LLVM_TOOLS_DIR ${LLVM_ROOT_DIR}/bin ) set( LDC2_BIN_DIR ${PROJECT_BINARY_DIR}/bin ) set( LDC2_LIB_DIR ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} ) set( TESTS_IR_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) set( PYTHON_EXE python3) if(WIN32) set(PYTHON_EXE python) endif() if(CMAKE_SIZEOF_VOID_P EQUAL 8) set( DEFAULT_TARGET_BITS 64 ) else() set( DEFAULT_TARGET_BITS 32 ) endif() configure_file(lit.site.cfg.in lit.site.cfg ) configure_file(runlit.py runlit.py COPYONLY) add_test(NAME lit-tests COMMAND ${PYTHON_EXE} runlit.py -v . ) ./ldc-1.28.0-src/tests/d2/0000755000175000017500000000000014141774367015161 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/src/0000755000175000017500000000000014141774365015746 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/src/osmodel.mak0000644000175000017500000000270614141774365020107 0ustar matthiasmatthias# osmodel.mak # # Detects and sets the macros: # # OS = one of {osx,linux,freebsd,openbsd,netbsd,dragonflybsd,solaris} # MODEL = one of { 32, 64 } # MODEL_FLAG = one of { -m32, -m64 } # # Note: # Keep this file in sync between druntime, phobos, and dmd repositories! # Source: https://github.com/dlang/dmd/blob/master/osmodel.mak ifeq (,$(OS)) uname_S:=$(shell uname -s) ifeq (Darwin,$(uname_S)) OS:=osx endif ifeq (Linux,$(uname_S)) OS:=linux endif ifeq (FreeBSD,$(uname_S)) OS:=freebsd endif ifeq (OpenBSD,$(uname_S)) OS:=openbsd endif ifeq (NetBSD,$(uname_S)) OS:=netbsd endif ifeq (DragonFly,$(uname_S)) OS:=dragonflybsd endif ifeq (Solaris,$(uname_S)) OS:=solaris endif ifeq (SunOS,$(uname_S)) OS:=solaris endif ifeq (,$(OS)) $(error Unrecognized or unsupported OS for uname: $(uname_S)) endif endif # When running make from XCode it may set environment var OS=MACOS. # Adjust it here: ifeq (MACOS,$(OS)) OS:=osx endif ifeq (,$(MODEL)) ifeq ($(OS), solaris) uname_M:=$(shell isainfo -n) else uname_M:=$(shell uname -m) endif ifneq (,$(findstring $(uname_M),x86_64 amd64)) MODEL:=64 endif ifneq (,$(findstring $(uname_M),i386 i586 i686)) MODEL:=32 endif ifeq (,$(MODEL)) $(warning Cannot figure 32/64 model from uname -m: $(uname_M)) endif endif ifneq (,$(MODEL)) ifneq (default,$(MODEL)) MODEL_FLAG:=-m$(MODEL) endif endif ./ldc-1.28.0-src/tests/d2/dmd-testsuite/0000755000175000017500000000000014141774367017754 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/0000755000175000017500000000000014141774366022062 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_21217.d0000644000175000017500000000275314141774365023727 0ustar matthiasmatthias/* REQUIRED_ARGS: -HC=verbose -c -o- PERMUTE_ARGS: TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler v$n$ #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif struct Foo final { int32_t a; enum : int32_t { b = 2 }; // Ignored enum `dtoh_21217.Foo.c` because it is `private`. protected: enum : int32_t { d = 4 }; enum : int32_t { e = 5 }; public: enum : int32_t { f = 6 }; enum : int32_t { g = 7 }; private: enum class Bar { a = 1, b = 2, }; // Ignored enum `dtoh_21217.Foo.h` because it is `private`. public: Foo() : a(1) { } Foo(int32_t a) : a(a) {} }; --- */ extern(C++) struct Foo { int a = 1; enum b = 2; private enum c = 3; protected enum d = 4; package enum e = 5; public enum f = 6; export enum g = 7; private enum Bar { a = 1, b = 2 } private enum h = Bar.a; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21661.d0000644000175000017500000000142014141774365023602 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21661 module pkg.pkg2.mod; immutable x = 1; enum e = pkg.pkg2.mod.x; // Some checks static assert( pkg.stringof == "package pkg" ); static assert( pkg.pkg2.stringof == "package pkg2"); static assert( pkg.pkg2.mod.stringof == "module mod" ); static assert(pkg.pkg2.mod.x.stringof == "x" ); alias p1 = pkg; alias p2 = pkg.pkg2; alias m = pkg.pkg2.mod; alias v = pkg.pkg2.mod.x; static assert( p1.stringof == "package pkg" ); static assert( p2.stringof == "package pkg2"); static assert( m.stringof == "module mod" ); static assert(p1.pkg2.mod.stringof == "module mod" ); static assert( p2.mod.stringof == "module mod" ); static assert( v.stringof == "x" ); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20744.d0000644000175000017500000000042014141774365023602 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20744 struct A { struct S {} void f(@S int = 3); alias fun = Issue20744!f; } template Issue20744(func...) { static if (is(typeof(func[0]) PT == __parameters)) { alias Issue20744 = (PT args) {}; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test12567b.d0000644000175000017500000000013414141774365023752 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: deprecated("message") module test12567b; void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15856.d0000644000175000017500000000023714141774365023620 0ustar matthiasmatthias// REQUIRED_ARGS: -de // PERMUTE_ARGS: // EXTRA_FILES: imports/a15856.d class Foo { import imports.a15856; struct Bar { c_long a; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test313d.d0000644000175000017500000000035614141774365023604 0ustar matthiasmatthias// first imported as package // COMPILED_IMPORTS: imports/pkgmod313/mod.d // EXTRA_FILES: imports/pkgmod313/package.d // REQUIRED_ARGS: -de import imports.pkgmod313; // then as package module void test() { imports.pkgmod313.foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue21813b.d0000644000175000017500000000034014141774365024114 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21813 Target.OS defaultTargetOS() { return Target.OS.linux; } struct Target { enum OS { linux } OS os = defaultTargetOS(); @property isPOSIX() scope @nogc { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19145.d0000644000175000017500000000036214141774365023612 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19415 struct S { int x; S foo() return { return S(x); } this(this) @disable; } S bar() { S s; return s; // Error: struct `S` is not copyable because it is annotated with @disable } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test12496.d0000644000175000017500000000035014141774365023611 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=12496 final abstract class T1 { final abstract class C(uint value) { } alias Child = C!2; } void main() { static assert(__traits(isSame, __traits(parent, T1.Child), T1)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test62.d0000644000175000017500000000015214141774365023353 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/test62a.d import imports.test62a; struct S { } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/jsonCompilerInfo.d0000644000175000017500000000022714141774365025507 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -o- -Xi=compilerInfo -Xf- // TRANSFORM_OUTPUT: sanitize_json // TEST_OUTPUT_FILE: extra-files/jsonCompilerInfo.json ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19652.d0000644000175000017500000000036514141774365023620 0ustar matthiasmatthiasstruct Base { int i; } struct A { Base base; alias base this; } struct B { A a; alias a this; } auto asGeneric(inout ref Base block) @nogc { return █ } B* thingie; auto foo() { return asGeneric(*thingie); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test313e.d0000644000175000017500000000042314141774365023600 0ustar matthiasmatthias// first resolved as package, then created as module (with name package) // COMPILED_IMPORTS: imports/pkgmod313/mod.d imports/pkgmod313/package.d // REQUIRED_ARGS: -de import imports.pkgmod313; // then imported as package module void test() { imports.pkgmod313.foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test313b.d0000644000175000017500000000014314141774365023574 0ustar matthiasmatthias// REQUIRED_ARGS: -de void test1() { import core.stdc.stdio; core.stdc.stdio.printf(""); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/jsonStdout.d0000644000175000017500000000141014141774365024376 0ustar matthiasmatthias/* PERMUTE_ARGS: REQUIRED_ARGS: -o- -Xf=- -Xi=compilerInfo -Xi=modules TRANSFORM_OUTPUT: sanitize_json TEST_OUTPUT: ---- { "compilerInfo": { "__VERSION__": 0, "architectures": [ "VALUES_REMOVED_FOR_TEST" ], "interface": "dmd", "platforms": [ "VALUES_REMOVED_FOR_TEST" ], "predefinedVersions": [ "VALUES_REMOVED_FOR_TEST" ], "size_t": 0, "supportedFeatures": { "includeImports": true }, "vendor": "VALUE_REMOVED_FOR_TEST", "version": "VALUE_REMOVED_FOR_TEST" }, "modules": [ { "file": "VALUE_REMOVED_FOR_TEST", "kind": "module", "members": [] } ] } ---- */ ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice13071.d0000644000175000017500000000021114141774365023354 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: T foo(T)() { __gshared int[] bar = []; return T.init; } void main() { foo!char(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17130.d0000644000175000017500000000056114141774365023603 0ustar matthiasmatthiasclass Base { this() shared {} this() {} } class Derived1 : Base { this() { // implicit super(); } } class Derived2 : Base { // implicit this() } class Base2 { this() shared {} } class Derived3 : Base2 { // implicit this() shared } void test() { auto d2 = new Derived2; auto d3 = new shared(Derived3); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_ignored.d0000644000175000017500000000674214141774365024704 0ustar matthiasmatthias/++ REQUIRED_ARGS: -HC=verbose -c -o- -d PERMUTE_ARGS: TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler v$n$ #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif #if !defined(_d_real) # define _d_real long double #endif class WithImaginary { public: float memberIf; double memberId; _d_real memberIr; _Complex float memberCf; _Complex double memberCd; _Complex _d_real memberCr; _d_dynamicArray< float > nested; // Ignored function dtoh_ignored.WithImaginary.onReturn because its return type cannot be mapped to C++ private: virtual void __vtable_slot_0(); // Ignored function dtoh_ignored.WithImaginary.onParam because one of its parameters has type `ifloat` which cannot be mapped to C++ virtual void __vtable_slot_1(); }; template struct WithImaginaryTemplate final { // Ignoring var member alignment 0 float member; // Ignored function onReturn because its return type cannot be mapped to C++ // Ignored function onParam because one of its parameters has type `ifloat` which cannot be mapped to C++ // Ignoring var onVariable alignment 0 // Ignored variable onVariable because its type cannot be mapped to C++ WithImaginaryTemplate() { } }; extern WithImaginaryTemplate instance; // Ignored variable dtoh_ignored.onVariable because its type cannot be mapped to C++ // Ignored variable dtoh_ignored.onVariablePointer because its type cannot be mapped to C++ // Ignored variable dtoh_ignored.onVariableSlice because its type cannot be mapped to C++ // Ignored variable dtoh_ignored.onVariableArray because its type cannot be mapped to C++ extern void* onVariableAssocArray; // Ignored variable dtoh_ignored.onVariableFunction because its type cannot be mapped to C++ // Ignored variable dtoh_ignored.onVariableFunctionParam because its type cannot be mapped to C++ // Ignored variable dtoh_ignored.onVariableDelegate because its type cannot be mapped to C++ // Ignored function dtoh_ignored.myExit because its return type cannot be mapped to C++ --- +/ extern (C++): class WithImaginary { ifloat memberIf; idouble memberId; ireal memberIr; cfloat memberCf; cdouble memberCd; creal memberCr; ifloat[] nested; ifloat onReturn() { return 0i; } void onParam(ifloat) {} } struct WithImaginaryTemplate(T) { ifloat member; ifloat onReturn() { return 0i; } void onParam(ifloat) { } __gshared ifloat onVariable; } __gshared WithImaginaryTemplate!int instance; __gshared ifloat onVariable; __gshared ifloat** onVariablePointer; __gshared ifloat[] onVariableSlice; __gshared ifloat[2] onVariableArray; __gshared ifloat[int] onVariableAssocArray; __gshared ifloat function() onVariableFunction; __gshared void function(ifloat) onVariableFunctionParam; __gshared ifloat delegate() onVariableDelegate; noreturn myExit() { assert(false); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice11300.d0000644000175000017500000000016114141774365023351 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/ice11300a.d module ice11300; import imports.ice11300a; enum value = 42; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20906.d0000644000175000017500000000043014141774365023603 0ustar matthiasmatthias/* REQUIRED_ARGS: -O * No divide-by-zero constant folding errors * https://issues.dlang.org/show_bug.cgi?id=20906 */ int test12() { int x = 0; int a = x && 1 / x; int b = !x || 1 / x; int c = x ? 1 / x : 1; int d = !x ? 1 : 1 / x; return a | b | c; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protattr.d0000644000175000017500000000043214141774365024104 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // EXTRA_FILES: protection/basic/mod1.d protection/basic/tests.d protection/subpkg/explicit.d protection/subpkg/tests.d protection/subpkg2/tests.d // PERMUTE_ARGS: import protection.basic.tests; import protection.subpkg.tests; import protection.subpkg2.tests; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b16244.d0000644000175000017500000000015214141774365023046 0ustar matthiasmatthiasstruct Foo { void bar()(typeof(cast()this) x) { } } void main() { Foo x; x.bar(x); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testheader2.d0000644000175000017500000000035314141774365024441 0ustar matthiasmatthias/* EXTRA_SOURCES: extra-files/header2.d REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/testheader2.di PERMUTE_ARGS: OUTPUT_FILES: ${RESULTS_DIR}/compilable/testheader2.di TEST_OUTPUT_FILE: extra-files/header2.di */ void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test10073.d0000644000175000017500000000046614141774365023606 0ustar matthiasmatthiasstruct Arr(T) { T[] dArr; alias dArr this; bool opEquals(Arr!T d) { foreach (idx, it; d) { if (this[idx] != it) { return false; } } return true; } } class Bar { Arr!Foo fooQ; } class Foo {} // NG ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test1170.d0000644000175000017500000000053714141774365023523 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=1170 type x; mixin("alias int type;"); // https://issues.dlang.org/show_bug.cgi?id=10739 template DECLARE_HANDLE() { struct HINTERNET { int h; } } const INTERNET_INVALID_STATUS_CALLBACK = cast(INTERNET_STATUS_CALLBACK) -1; mixin DECLARE_HANDLE; alias void function(HINTERNET) INTERNET_STATUS_CALLBACK; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21743.d0000644000175000017500000000063614141774365023613 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21743 struct A { int foo(int a) { return a; } string foo()(string b) { return b; } } alias ov = __traits(getOverloads, A.init, "foo", true); // member function works static assert(ov[0](1) == 1); // member template used to fail with the gagged error: // 'need this for foo of type pure nothrow @nogc @safe string(string b)' static assert(ov[1]("a") == "a"); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_output_filenames.sh0000755000175000017500000000510214141774365026623 0ustar matthiasmatthias#!/usr/bin/env bash dir=${RESULTS_DIR}/compilable output_file=${dir}/ldc_output_filenames.sh.out rm -f ${output_file} function bailout { cat ${output_file} rm -f ${output_file} exit 1 } # 3 object files, 2 with same name # -of (implying -singleobj); additionally make sure object file extension is NOT enforced $DMD -m${MODEL} -Icompilable/extra-files/ldc_output_filenames -of${dir}/myObj.myExt -c compilable/extra-files/ldc_output_filenames/{main.d,foo.d,imp/foo.d} >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; rm ${dir}/myObj.myExt >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; # -op $DMD -m${MODEL} -Icompilable/extra-files/ldc_output_filenames -od${dir} -c -op compilable/extra-files/ldc_output_filenames/{main.d,foo.d,imp/foo.d} >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; rm ${dir}/compilable/extra-files/ldc_output_filenames/{main${OBJ},foo${OBJ},imp/foo${OBJ}} >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; # -oq $DMD -m${MODEL} -Icompilable/extra-files/ldc_output_filenames -od${dir} -c -oq compilable/extra-files/ldc_output_filenames/{main.d,foo.d,imp/foo.d} >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; rm ${dir}/{ldc_output_filenames${OBJ},foo${OBJ},imp.foo${OBJ}} >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; # -o- $DMD -m${MODEL} -Icompilable/extra-files/ldc_output_filenames -o- compilable/extra-files/ldc_output_filenames/{main.d,foo.d,imp/foo.d} >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; # Make sure the default file extension is appended if the user's # -of doesn't contain any (LDMD only). # args: <-of filename> function buildAndDelete { $DMD -m${MODEL} -Icompilable/extra-files/ldc_output_filenames -of${dir}/$2 "$1" compilable/extra-files/ldc_output_filenames/{main.d,foo.d,imp/foo.d} >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; rm ${dir}/$3 >> ${output_file} if [ $? -ne 0 ]; then bailout; fi; } # executable EXE_EXTENSION= if [[ "$OS" == win* ]]; then EXE_EXTENSION=.exe; fi; buildAndDelete "" executable executable${EXE_EXTENSION} buildAndDelete "" executable.myExt executable.myExt # static library LIB_EXTENSION=.a if [[ "$OS" == win* ]]; then LIB_EXTENSION=.lib; fi; buildAndDelete "-lib" staticLib staticLib${LIB_EXTENSION} buildAndDelete "-lib" staticLib.myExt staticLib.myExt # shared library SO_EXTENSION=.so if [[ "$OS" == win* ]]; then SO_EXTENSION=.dll; elif [ "$OS" == "osx" ]; then SO_EXTENSION=.dylib; fi; buildAndDelete "-shared" sharedLib sharedLib${SO_EXTENSION} buildAndDelete "-shared" sharedLib.myExt sharedLib.myExt ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_breaks_verbose.d0000644000175000017500000000046514141774365030122 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o- -transition=vmarkdown // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_breaks_verbose.html // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_breaks_verbose.html /++ Thematic Breaks ___ - - - *** +/ module ddoc_markdown_breaks; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16225.d0000644000175000017500000000030014141774365023576 0ustar matthiasmatthias// REQUIRED_ARGS: -O -m64 // PERMUTE_ARGS: // https://issues.dlang.org/show_bug.cgi?id=16225 struct C { hash_t foo( ) { int y; return ((cast(ubyte*)&y)[1]); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice11054.d0000644000175000017500000000023014141774365023354 0ustar matthiasmatthias// EXTRA_FILES: imports/ice11054a.d import imports.ice11054a; static assert(!__traits(compiles, tuple())); E[] appender(A : E, E)() { return E; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/noreturn3.d0000644000175000017500000001177614141774365024201 0ustar matthiasmatthias/* REQUIRED_ARGS: -w -o- -d More complex examples from the DIP https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md */ alias noreturn = typeof(*null); static assert (!is(noreturn == void)); void initialize() { noreturn a; noreturn b = noreturn.init; } void foo(const noreturn); void foo(const int); noreturn bar(); void overloads() { noreturn n; foo(n); foo(bar()); } // /*****************************************************************************/ auto inferNoreturn(int i) { if (i < 0) return assert(false); else if (i == 0) return assert(false); else return assert(false); } auto inferReturn(int i) { if (i < 0) return assert(false); else if (i == 0) return i; else return assert(false); } // /*****************************************************************************/ // // https://issues.dlang.org/show_bug.cgi?id=22004 alias fun22004 = _ => {}(); alias gun22004 = _ => assert(0); auto bun22004(bool b) { if (b) return gun22004(0); else return fun22004(0); } static assert(is(typeof(bun22004(true)) == void)); // // Reversed order auto bun22004_reversed(bool b) { if (b) return fun22004(0); else return gun22004(0); } static assert(is(typeof(bun22004_reversed(true)) == void)); // /*****************************************************************************/ // // Also works fine with non-void types and ref inference int global; auto ref forwardOrExit(ref int num) { if (num) return num; else return assert(false); } static assert( is(typeof(forwardOrExit(global)) == int)); // // Must not infer ref due to the noreturn rvalue static assert(!is(typeof(&forwardOrExit(global)))); auto ref forwardOrExit2(ref int num) { if (num) return assert(false); else return num; } static assert( is(typeof(forwardOrExit2(global)) == int)); // // Must not infer ref due to the noreturn rvalue static assert(!is(typeof(&forwardOrExit2(global)))); /*****************************************************************************/ void inference() { auto inf = cast(noreturn) 1; static assert(is(typeof(inf) == noreturn)); noreturn n; auto c = cast(const shared noreturn) n; static assert(is(typeof(c) == const shared noreturn)); static assert(is(typeof(n) == noreturn)); auto c2 = cast(immutable noreturn) n; static assert(is(typeof(c) == const shared noreturn)); static assert(is(typeof(c2) == immutable noreturn)); static assert(is(typeof(n) == noreturn)); } /******************************************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21957 // Calculate proper alignment and size for noreturn members enum longPad = long.alignof - int.sizeof; struct BasicStruct { int firstInt; noreturn noRet; long lastLong; } static assert(BasicStruct.sizeof == (int.sizeof + longPad + long.sizeof)); static assert(BasicStruct.firstInt.offsetof == 0); static assert(BasicStruct.noRet.offsetof == 4); static assert(BasicStruct.lastLong.offsetof == (4 + longPad)); struct AlignedStruct { int firstInt; align(16) noreturn noRet; long lastLong; } static assert(AlignedStruct.sizeof == 32); static assert(AlignedStruct.firstInt.offsetof == 0); static assert(AlignedStruct.noRet.offsetof == 16); static assert(AlignedStruct.lastLong.offsetof == 16); union BasicUnion { int firstInt; noreturn noRet; long lastLong; } static assert(BasicUnion.sizeof == 8); static assert(BasicUnion.firstInt.offsetof == 0); static assert(BasicUnion.noRet.offsetof == 0); static assert(BasicUnion.lastLong.offsetof == 0); union AlignedUnion { int firstInt; align(16) noreturn noRet; long lastLong; } static assert(AlignedUnion.sizeof == 16); static assert(AlignedUnion.firstInt.offsetof == 0); static assert(AlignedUnion.noRet.offsetof == 0); static assert(AlignedUnion.lastLong.offsetof == 0); class BasicClass { int firstInt; noreturn noRet; long lastLong; } enum objectMemberSize = __traits(classInstanceSize, Object); static assert(__traits(classInstanceSize, BasicClass) == objectMemberSize + (int.sizeof + longPad + long.sizeof)); static assert(BasicClass.firstInt.offsetof == objectMemberSize + 0); static assert(BasicClass.noRet.offsetof == objectMemberSize + 4); static assert(BasicClass.lastLong.offsetof == objectMemberSize + (4 + longPad)); class AlignedClass { int firstInt; align(16) noreturn noRet; long lastLong; } enum offset = (objectMemberSize + 4 + 16) & ~15; static assert(__traits(classInstanceSize, AlignedClass) == offset + 8); static assert(AlignedClass.firstInt.offsetof == objectMemberSize + 0); static assert(AlignedClass.noRet.offsetof == offset); static assert(AlignedClass.lastLong.offsetof == offset); struct EmptyStruct { noreturn noRet; } static assert(EmptyStruct.sizeof == 1); static assert(EmptyStruct.noRet.offsetof == 0); struct EmptyStruct2 { noreturn[4] noRet; } static assert(EmptyStruct2.sizeof == 1); static assert(EmptyStruct2.noRet.offsetof == 0); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/compile1.d0000644000175000017500000005510114141774365023741 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/a12506.d /* TEST_OUTPUT: --- compilable/compile1.d(229): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead --- */ /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=1748 // class template with stringof struct S1748(T) {} static assert(S1748!int.stringof == "S1748!int"); class C1748(T) {} static assert(C1748!int.stringof == "C1748!int"); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=2354 // pragma + single semicolon DeclarationBlock version(all) pragma(inline, true); else pragma(inline, false); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=2438 alias void delegate() Dg2438; alias typeof(Dg2438.ptr) CP2438a; alias typeof(Dg2438.funcptr) FP2438a; static assert(is(CP2438a == void*)); static assert(is(FP2438a == void function())); alias typeof(Dg2438.init.ptr) CP2438b; alias typeof(Dg2438.init.funcptr) FP2438b; static assert(is(CP2438b == void*)); static assert(is(FP2438b == void function())); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=4225 struct Foo4225 { enum x = Foo4225(); static Foo4225 opCall() { return Foo4225.init; } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=5996 // ICE(expression.c) template T5996(T) { auto bug5996() { if (anyOldGarbage) {} return 2; } } static assert(!is(typeof(T5996!(int).bug5996()))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8532 // segfault(mtype.c) - type inference + pure auto segfault8532(Y, R ...)(R r, Y val) pure { return segfault8532(r, val); } static assert(!is(typeof( segfault8532(1,2,3)))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8982 // ICE(ctfeexpr.c) __parameters with error in default value template ice8982(T) { void bug8982(ref const int v = 7){} static if (is(typeof(bug8982) P == __parameters)) { enum eval8982 = ((P[0..1] g) => g[0])(); } } static assert(!is(ice8982!(int))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8801 // ICE assigning to __ctfe static assert(!is(typeof( { bool __ctfe= true; }))); static assert(!is(typeof( { __ctfe |= true; }))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=5932 // https://issues.dlang.org/show_bug.cgi?id=6675 // ICE(s2ir.c), ICE(glue.c) void bug3932(T)() { static assert( 0 ); func5932( 7 ); } void func5932(T)( T val ) { void onStandardMsg() { foreach( t; T ) { } } } static assert(!is(typeof( { bug3932!(int)(); }() ))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=6650 // ICE(glue.c) or wrong-code auto bug6650(X)(X y) { X q; q = "abc"; return y; } static assert(!is(typeof(bug6650!(int)(6)))); static assert(!is(typeof(bug6650!(int)(18)))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=14710 // VC-built DMD crashes on templated variadic function IFTI void bug14710a(T)(T val, T[] arr...) { } void bug14710b() { bug14710a("", ""); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=6661 // Templates instantiated only through is(typeof()) shouldn't cause errors template bug6661(Q) { int qutz(Q y) { Q q = "abc"; return 67; } static assert(qutz(13).sizeof!=299); const Q blaz = 6; } static assert(!is(typeof(bug6661!(int).blaz))); template bug6661x(Q) { int qutz(Q y) { Q q = "abc"; return 67; } } // should pass, but doesn't in current //static assert(!is(typeof(bug6661x!(int)))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=6599 // ICE(constfold.c) or segfault string bug6599extraTest(string x) { return x ~ "abc"; } template Bug6599(X) { class Orbit { Repository repository = Repository(); } struct Repository { string fileProtocol = "file://"; string blah = bug6599extraTest("abc"); string source = fileProtocol ~ "/usr/local/orbit/repository"; } } static assert(!is(typeof(Bug6599!int))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8422 // TypeTuple of tuples can't be read at compile time template TypeTuple8422(TList...) { alias TList TypeTuple8422; } struct S8422 { int x; } void test8422() { enum a = S8422(1); enum b = S8422(2); enum c = [1,2,3]; foreach(t; TypeTuple8422!(b, a)) { enum u = t; } foreach(t; TypeTuple8422!(c)) { enum v = t; } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=6096 // ICE(el.c) with -O cdouble c6096; int bug6096() { if (c6096) return 0; return 1; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=7681 // Segfault static assert( !is(typeof( (){ undefined ~= delegate(){}; return 7; }()))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8639 // Buffer overflow void t8639(alias a)() {} void bug8639() { t8639!({auto r = -real.max;})(); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=7751 // Segfault static assert( !is(typeof( (){ bar[]r; r ~= []; return 7; }()))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=7639 // Segfault static assert( !is(typeof( (){ enum foo = [ str : "functions", ]; }))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11991 void main() { int Throwable; int object; try { } catch(.object.Throwable) { } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11939 void test11939() { scope(failure) { import object : Object; } throw new Exception(""); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=5796 template A(B) { pragma(lib, "missing ;") enum X = 0; } static assert(!is(typeof(A!(int)))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=6720 void bug6720() { } static assert(!is(typeof( cast(bool)bug6720() ))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=1099 template Mix1099(int a) { alias typeof(this) ThisType; static assert (ThisType.init.tupleof.length == 2); } struct Foo1099 { mixin Mix1099!(0); int foo; mixin Mix1099!(1); int bar; mixin Mix1099!(2); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8788 // super() and return class B8788 { this ( ) { } } class C8788(int test) : B8788 { this ( int y ) { // TESTS WHICH SHOULD PASS static if (test == 1) { if (y == 3) { super(); return; } super(); return; } else static if (test == 2) { if (y == 3) { super(); return; } super(); } else static if (test == 3) { if (y > 3) { if (y == 7) { super(); return; } super(); return; } super(); } else static if (test == 4) { if (y > 3) { if (y == 7) { super(); return; } else if (y> 5) super(); else super(); return; } super(); } // TESTS WHICH SHOULD FAIL else static if (test == 5) { if (y == 3) { super(); return; } return; // no super } else static if (test == 6) { if (y > 3) { if (y == 7) { super(); return; } super(); } super(); // two calls } else static if (test == 7) { if (y == 3) { return; // no super } super(); } else static if (test == 8) { if (y > 3) { if (y == 7) { return; // no super } super(); return; } super(); } else static if (test == 9) { if (y > 3) { if (y == 7) { super(); return; } else if (y> 5) super(); else return; // no super return; } super(); } } } static assert( is(typeof( { new C8788!(1)(0); } ))); static assert( is(typeof( { new C8788!(2)(0); } ))); static assert( is(typeof( { new C8788!(3)(0); } ))); static assert( is(typeof( { new C8788!(4)(0); } ))); static assert(!is(typeof( { new C8788!(5)(0); } ))); static assert(!is(typeof( { new C8788!(6)(0); } ))); static assert(!is(typeof( { new C8788!(7)(0); } ))); static assert(!is(typeof( { new C8788!(8)(0); } ))); static assert(!is(typeof( { new C8788!(9)(0); } ))); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=4967 // https://issues.dlang.org/show_bug.cgi?id=7058 enum Bug7058 bug7058 = { 1.5f, 2}; static assert(bug7058.z == 99); struct Bug7058 { float x = 0; float y = 0; float z = 99; } /***************************************************/ void test12094() { auto n = null; int *a; int[int] b; int[] c; auto u = true ? null : a; auto v = true ? null : b; auto w = true ? null : c; auto x = true ? n : a; auto y = true ? n : b; auto z = true ? n : c; a = n; b = n; c = n; } /***************************************************/ template test8163(T...) { struct Point { T fields; } enum N = 2; // N>=2 triggers the bug extern Point[N] bar(); void foo() { Point[N] _ = bar(); } } alias test8163!(long) _l; alias test8163!(double) _d; alias test8163!(float, float) _ff; alias test8163!(int, int) _ii; alias test8163!(int, float) _if; alias test8163!(ushort, ushort, ushort, ushort) _SSSS; alias test8163!(ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte) _BBBBBBBB; alias test8163!(ubyte, ubyte, ushort, float) _BBSf; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=4757 auto foo4757(T)(T) { static struct Bar(T) { void spam() { foo4757(1); } } return Bar!T(); } void test4757() { foo4757(1); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=9348 void test9348() { @property Object F(int E)() { return null; } assert(F!0 !is null); assert(F!0 !in [new Object():1]); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=9690 @disable { void dep9690() {} void test9690() { dep9690(); // OK void inner() { dep9690(); // OK <- NG } } } /+ LDC_FIXME: See discussion at D-Programming-Language/dmd#2175. /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=9987 static if (is(object.ModuleInfo == struct)) { struct ModuleInfo {} static assert(!is(object.ModuleInfo == ModuleInfo)); static assert(object.ModuleInfo.sizeof != ModuleInfo.sizeof); } static if (is(object.ModuleInfo == class)) { class ModuleInfo {} static assert(!is(object.ModuleInfo == ModuleInfo)); static assert(__traits(classInstanceSize, object.ModuleInfo) != __traits(classInstanceSize, ModuleInfo)); } +/ /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=10158 class Outer10158 { static struct Inner { int f; } void test() { static assert( Inner.f .offsetof == 0); // OK <- NG static assert((Inner.f).offsetof == 0); // OK } } void test10158() { static assert(Outer10158.Inner.f.offsetof == 0); // OK } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=10326 class C10326 { int val; invariant { assert(val == 0); } invariant() { assert(val == 0); } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11042 static if ((true || error) == true ) {} else { static assert(0); } static if ((false && error) == false) {} else { static assert(0); } static assert ((true || error) == true ); static assert ((false && error) == false); int f11042a1()() if ((true || error) == true ) { return 0; } enum x11042a1 = f11042a1(); int f11042b1()() if ((false && error) == false) { return 0; } enum x11042b1 = f11042b1(); static if (is(typeof(true || error)) == false) {} else { static assert(0); } static if (is(typeof(false && error)) == false) {} else { static assert(0); } static assert (is(typeof(true || error)) == false); static assert (is(typeof(false && error)) == false); int f11042a2()() if (is(typeof(true || error)) == false) { return 0; } enum x11042a2 = f11042a2(); int f11042b2()() if (is(typeof(false && error)) == false) { return 0; } enum x11042b2 = f11042b2(); static if (__traits(compiles, true || error) == false) {} else { static assert(0); } static if (__traits(compiles, false && error) == false) {} else { static assert(0); } static assert (__traits(compiles, true || error) == false); static assert (__traits(compiles, false && error) == false); int f11042a3()() if (__traits(compiles, true || error) == false) { return 0; } enum x11042a3 = f11042a3(); int f11042b3()() if (__traits(compiles, false && error) == false) { return 0; } enum x11042b3 = f11042b3(); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11554 enum E11554; static assert(is(E11554 == enum)); struct Bro11554(N...) {} static assert(!is(E11554 unused : Bro11554!M, M...)); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12302 template isCallable12302(T...) if (T.length == 1) { static if (is(typeof(& T[0].opCall) == delegate)) enum bool isCallable12302 = true; else static if (is(typeof(& T[0].opCall) V : V*) && is(V == function)) enum bool isCallable12302 = true; else enum bool isCallable12302 = true; } class A12302 { struct X {} X x; auto opDispatch(string s, TArgs...)(TArgs args) { mixin("return x."~s~"(args);"); } } A12302 func12302() { return null; } enum b12302 = isCallable12302!func12302; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12476 template A12476(T) { } struct S12476(T) { alias B = A12476!T; } class C12476(T) { alias B = A12476!T; } struct Bar12476(alias Foo) { Foo!int baz; alias baz this; } alias Identity12476(alias A) = A; alias sb12476 = Identity12476!(Bar12476!S12476.B); alias cb12476 = Identity12476!(Bar12476!C12476.B); static assert(__traits(isSame, sb12476, A12476!int)); static assert(__traits(isSame, cb12476, A12476!int)); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12506 import imports.a12506; private bool[9] r12506a = f12506!(i => true)(); // OK private immutable bool[9] r12506b = f12506!(i => true)(); // OK <- error /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12555 class A12555(T) { Undef12555 error; } static assert(!__traits(compiles, { class C : A12555!C { } })); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11622 class A11622(T) { B11622!T foo() { return new B11622!T; } } class B11622(T) : T { } static assert(!__traits(compiles, { class C : A11622!C { } })); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12688 void writeln12688(A...)(A) {} struct S12688 { int foo() @property { return 1; } } void test12688() { S12688 s; s.foo.writeln12688; // ok (s.foo).writeln12688; // ok <- ng } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12703 struct S12703 { this(int) {} } final class C12703 { S12703 s = S12703(1); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12799 struct A12799 { int a; enum C = A12799.sizeof; enum D = C; // OK <- Error } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=13236 enum bug13286 = is(typeof({ struct S { S x; } })); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=13280 struct S13280 { alias U = ubyte; alias T1 = ubyte[this.sizeof]; // ok alias T2 = const U[this.sizeof]; // ok alias T3 = const ubyte[this.sizeof]; // ok <- error } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=13481 mixin template Mix13481(void function() callback) { static this() { callback(); } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=13564 class E13564(T) { int pos; } class C13564(T) { struct S { ~this() { C13564!int c; c.element.pos = 0; } } E13564!T element; } void test13564() { auto c = new C13564!int(); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=14166 struct Proxy14166(T) { T* ptr; ref deref() { return *ptr; } alias deref this; } struct Test14166 { auto opIndex() { return this; } auto opIndex(int) { return 1; } } template Elem14166a(R) { alias Elem14166a = typeof(R.init[][0]); } template Elem14166b(R) { alias Elem14166b = typeof(R.init[0]); } void test14166() { alias T = Proxy14166!Test14166; static assert(is(Elem14166a!T == int)); // rejects-valid case static assert(is(Elem14166b!T == int)); // regression case } // other related cases struct S14166 { int x; double y; int[] a; S14166 opUnary(string op : "++")() { return this; } } S14166 s14166; struct X14166 { this(int) { } X14166 opAssign(int) { return this; } } X14166[int] aa14166; X14166[int] makeAA14166() { return aa14166; } struct Tup14166(T...) { T field; alias field this; } Tup14166!(int, int) tup14166; Tup14166!(int, int) makeTup14166() { return tup14166; } alias TT14166(T...) = T; static assert(is(typeof((s14166.x += 1) = 2) == int)); // ok <- error static assert(is(typeof(s14166.a.length += 2) == size_t)); // ok <- error static assert(is(typeof(s14166++) == S14166)); // ok <- error static assert(is(typeof(s14166.x ^^ 2) == int)); // ok <- error static assert(is(typeof(s14166.y ^^= 2.5) == double)); // ok <- error static assert(is(typeof(makeAA14166()[0] = 1) == X14166)); // ok <- error static assert(is(typeof(tup14166.field = makeTup14166()) == TT14166!(int, int))); // ok <- error /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=14388 @property immutable(T)[] idup14388(T)(T[] a) { alias U = immutable(T); U[] res; foreach (ref e; a) res ~= e; return res; } struct Data14388(A14388 a) { auto foo() { return Data14388!a.init; // [B] } } struct A14388 { struct Item {} immutable(Item)[] items; this(int dummy) { items = [Item()].idup14388; } } void test14388() { auto test = Data14388!(A14388(42)).init.foo(); // [A] /* * A(42) is interpreter to a struct literal A([immutable(Item)()]). * The internal VarDeclaration with STCmanifest for the Data's template parameteter 'a' * calls syntaxCopy() on its ((ExpInitializer *)init)->exp in VarDeclaration::semantic(), * and 'immutable(Item)()'->syntaxCopy() had incorrectly removed the qualifier. * Then, the arguments of two Data template instances at [A] and [B] had become unmatch, * and the second instantiation had created the AST duplication. */ } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=15163 void function() func15164(int[] arr) { return () { }; } void test15163() { auto arr = [[0]]; func15164(arr[0])(); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=3438 import core.vararg; struct S3438_1 { this(int x, int y = 1) { } } struct S3438_2 { this(int x, ...) { } } struct S3438_3 { this(int x, int[] arr...) { } } struct S3438_4 { this(...) { } } struct S3438_5 { this(int[] arr...) { } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=15362 void func15362() { assert(true); assert(true,); assert(true, "So true"); assert(true, "Very, very true",); static assert(true); static assert(true,); static assert(true, "So true"); static assert(true, "Very, very true",); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=15799 interface I15799 { void funA(); void funB(int n) in { assert(n); }; // Semicolon is not a part of function declaration. It's an empty declaration. } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21163 struct B21163 { void function(scope int) fp; } B21163 b21163 = { (scope int x){} }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11624 interface I11624 { void foo(); } static assert(!__traits(compiles, { static class C11624 : I11624 { } })); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20596.d0000644000175000017500000000063014141774365023612 0ustar matthiasmatthias// PERMUTE_ARGS: -preview=dip1000 // https://issues.dlang.org/show_bug.cgi?id=20596 struct S(T) { void delegate() dg; this(scope void delegate() dg) { this.dg = dg; } } @nogc void fooTemplate() { int num; void foo() { int dummy = num; } scope s = S!int(&foo); } void test3032() @nogc { int n = 1; scope fp = (){ n = 10; }; // no closure fp(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16492.d0000644000175000017500000000226114141774365023614 0ustar matthiasmatthias// ARG_SETS: -debug; -o-; -debug -preview=dip1000 // https://issues.dlang.org/show_bug.cgi?id=16492 void mayCallGC(); void test() @nogc pure { debug new int(1); debug { mayCallGC(); auto b = [1, 2, 3]; b ~= 4; } } void debugSafe() @safe { debug unsafeSystem(); debug unsafeTemplated(); } void unsafeSystem() @system {} void unsafeTemplated()() { int[] arr; auto b = arr.ptr; } void debugSafe2() @safe { char[] arr1, arr2; debug unsafeDIP1000Lifetime(arr1, arr2); char* ptr; char[] arr; debug ptr = arr.ptr; } void unsafeDIP1000Lifetime()(ref char[] p, scope char[] s) { p = s; } void test2() nothrow { debug throw new Exception(""); } void test3() nothrow { debug { foreach (_; 0 .. 10) { if (1) { throw new Exception(""); } } } } void test4() nothrow { debug throwException(); } void test5() nothrow { debug willThrowException(); } void willThrowException()() { throwException(); } void throwException() { throw new Exception(""); } void test6() nothrow { debug { () {throw new Exception("");}(); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21680.d0000644000175000017500000000034314141774365023606 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21680 struct Unique { alias ValueType = typeof({ return field; }()); /* Error: need `this` for `field` of type `int` */ int field; static assert(is(ValueType == int)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test11563.d0000644000175000017500000000045314141774365023607 0ustar matthiasmatthias// EXTRA_FILES: imports/test11563core_bitop.d imports/test11563std_array.d imports/test11563std_range.d imports/test11563std_traits.d import imports.test11563std_traits; interface J : I {} // comment out to let compilation succeed struct A { } static assert(moduleName!A == "b"); interface I {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8038.d0000644000175000017500000000016414141774365023531 0ustar matthiasmatthiastemplate t(T){alias T t;} t!(#line 10 t!( int, ) ) i; t!( t!(#line 10 int, ) ) j; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/vgc3.d0000644000175000017500000000223514141774365023072 0ustar matthiasmatthias// REQUIRED_ARGS: -vgc -o- // PERMUTE_ARGS: /***************** AssignExp *******************/ /* TEST_OUTPUT: --- compilable/vgc3.d(16): vgc: setting `length` may cause a GC allocation compilable/vgc3.d(17): vgc: setting `length` may cause a GC allocation compilable/vgc3.d(18): vgc: setting `length` may cause a GC allocation --- */ void testArrayLength(int[] a) { a.length = 3; a.length += 1; a.length -= 1; } /***************** CallExp *******************/ void barCall(); /* TEST_OUTPUT: --- --- */ void testCall() { auto fp = &barCall; (*fp)(); barCall(); } /****************** Closure ***********************/ @nogc void takeDelegate2(scope int delegate() dg) {} @nogc void takeDelegate3( int delegate() dg) {} /* TEST_OUTPUT: --- compilable/vgc3.d(51): vgc: using closure causes GC allocation compilable/vgc3.d(63): vgc: using closure causes GC allocation --- */ auto testClosure1() { int x; int bar() { return x; } return &bar; } void testClosure2() { int x; int bar() { return x; } takeDelegate2(&bar); // no error } void testClosure3() { int x; int bar() { return x; } takeDelegate3(&bar); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17548.d0000644000175000017500000000030714141774365023616 0ustar matthiasmatthias// REQUIRED_ARGS: -c // EXTRA_FILES: imports/fwdref2_test17548.d module test17548; struct S1 { void foo(scope S2 arg) {} int myField; } enum cnst = 4321; import imports.fwdref2_test17548; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15402.d0000644000175000017500000000014614141774365023602 0ustar matthiasmatthias// REQUIRED_ARGS: -de struct S { package int field; } void test() { S s; s.field = 1; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test12567d.d0000644000175000017500000000016614141774365023761 0ustar matthiasmatthias// REQUIRED_ARGS: -d // EXTRA_FILES: imports/a12567.d // PERMUTE_ARGS: import imports.a12567; void main() { foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9278b.d0000644000175000017500000000033214141774365023677 0ustar matthiasmatthias// PERMUTE_ARGS: // Works fine here //struct datum { float num = 0.0; } datum emitOne() { datum t; return t; } const dataArr = [emitOne()]; // A very bad day struct datum { float num = 0.0; } void main(){} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test3673.d0000644000175000017500000000143714141774365023535 0ustar matthiasmatthiasclass Base {} class Foo(T) if (is(T == int)) : Base { } class Bar(T) : Base if (is(T == bool)) { } interface OutputRange(T...) if (T.length == 1) { void put(T[0] value); } interface OutputRange(T...) : OutputRange!(T[0]), OutputRange!(T[1 .. $]) if (T.length > 1) { } alias OutputRange!(int, float) OR; class COR : OR { void put(int) { } void put(float) { } } class A {}; class B(T) : A if (true) {} class C(T) if (false) : A {} alias Foo!int FooInt; alias Bar!bool BarBool; static assert(!__traits(compiles, Foo!bool)); static assert(!__traits(compiles, Bar!int)); void main() { auto fi = new FooInt; auto bb = new BarBool; auto cor = new COR; auto a = new A(); auto b = new B!int(); static assert(!__traits(compiles, new C!int())); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtorfields.d0000644000175000017500000000145314141774365024370 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=dtorfields // // https://issues.dlang.org/show_bug.cgi?id=21709 // PERMUTE_ARGS: -betterC /****************************************** * https://issues.dlang.org/show_bug.cgi?id=20934 */ struct HasDtor { ~this() {} } struct Disable { HasDtor member; this() @disable; } extern(C++) class Extern { HasDtor member; this(); } /****************************************** * https://issues.dlang.org/show_bug.cgi?id=21213 */ class Parent { this() nothrow pure @nogc @safe {} } class Child : Parent { HasDtor member; } /****************************************** * https://issues.dlang.org/show_bug.cgi?id=21225 */ struct NothrowConstructed { ~this() {} } struct NothrowConstructor { NothrowConstructed member; this(int) pure nothrow {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/aggr_alignment.d0000644000175000017500000000251214141774365025204 0ustar matthiasmatthiasstruct S1 // overall alignment: max(1, 1) = 1 { byte[5] bytes; struct // overall alignment: max(1, 1) = 1 { byte byte1; align(1) int int1; } } static assert(S1.int1.offsetof == 6); static assert(S1.alignof == 1); static assert(S1.sizeof == 10); class C2 // overall alignment: max(vtbl.alignof, monitor.alignof, 1, 2) { byte[5] bytes; struct // overall alignment: max(1, 2) = 2 { byte byte1; align(2) int int1; } } enum payloadOffset = C2.bytes.offsetof; static assert(C2.int1.offsetof == payloadOffset + 8); static assert(C2.alignof == size_t.sizeof); static assert(__traits(classInstanceSize, C2) == payloadOffset + 12); align(8) struct PaddedStruct { bool flag; align(2) S1 s1; } static assert(PaddedStruct.s1.offsetof == 2); static assert(PaddedStruct.alignof == 8); static assert(PaddedStruct.sizeof == 16); align(1) struct UglyStruct { bool flag; int i; ubyte u; } static assert(UglyStruct.i.offsetof == 4); static assert(UglyStruct.alignof == 1); static assert(UglyStruct.sizeof == 9); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=19914 // https://issues.dlang.org/show_bug.cgi?id=19915 class TemplatedClass(T) { align T field; } mixin TemplatedClass!(string); alias TCint = TemplatedClass!(int); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc2.d0000644000175000017500000000137514141774365023227 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** * Summary * * Description1 * * Description2 * * Description3 * * Macros: * WIKI = StdStream * meemie * See_Also: * Things to see also. * * And more things. */ /* */ module std.test; /// A base class for stream exceptions. class StreamException: Exception { /** Construct a StreamException with given error message msg. * Params: * msg = the $(RED red) $(BLUE blue) $(GREEN green) $(YELLOW yellow). * foo = next parameter which is a much longer * message spanning multiple * lines. */ this(string msg, int foo) { super(msg); } /********** stars ***************/ int stars; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test66.d0000644000175000017500000000030614141774365023360 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/test66a.d import imports.test66a; alias int TOK; enum { TOKmax }; struct Token { static char[][TOKmax] tochars; } class Lexer { Token token; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testdip1008.d0000644000175000017500000000034714141774365024217 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -preview=dip1008 int bar() { try { throw new Exception("message"); } catch (Exception e) { return 7; } } void foo() { enum r = bar(); static assert(r == 7); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/nestedtempl1.d0000644000175000017500000000034414141774365024634 0ustar matthiasmatthiasclass K { class B(alias a) { } class D(alias a) : B!a { } class E(alias a) : B!1 { } } void main() { int a; auto k = new K; auto d = k.new K.D!a; auto e = k.new K.E!a; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/0000755000175000017500000000000014133640042024230 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/issue20796/0000755000175000017500000000000014141774365026007 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/issue20796/package.d0000644000175000017500000000006714141774365027552 0ustar matthiasmatthiasmodule issue20796; package(issue20796) void foo() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/subpkg2/0000755000175000017500000000000014141774365025624 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/subpkg2/tests.d0000644000175000017500000000020114141774365027124 0ustar matthiasmatthiasmodule protection.subpkg2.tests; import pkg = protection.subpkg.explicit; static assert (is(typeof(pkg.commonAncestorFoo()))); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/basic/0000755000175000017500000000000014141774365025330 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/basic/tests.d0000644000175000017500000000125214141774365026637 0ustar matthiasmatthiasmodule protection.basic.tests; import protection.basic.mod1; static assert ( is(typeof(publicFoo()))); static assert ( is(typeof(packageFoo()))); static assert (!is(typeof(privateFoo()))); static assert ( is(typeof(Test.init.publicFoo()))); static assert (!is(typeof(Test.init.protectedFoo()))); static assert ( is(typeof(Test.init.packageFoo()))); static assert (!is(typeof(Test.init.privateFoo()))); class Deriv : Test { void stub() { static assert ( is(typeof(this.publicFoo()))); static assert ( is(typeof(this.protectedFoo()))); static assert ( is(typeof(this.packageFoo()))); static assert (!is(typeof(this.privateFoo()))); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/basic/mod1.d0000644000175000017500000000040214141774365026331 0ustar matthiasmatthiasmodule protection.basic.mod1; public void publicFoo() {} package void packageFoo() {} private void privateFoo() {} class Test { public void publicFoo(); protected void protectedFoo(); package void packageFoo(); private void privateFoo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/issue21726/0000755000175000017500000000000014141774365026001 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/issue21726/typecons.d0000644000175000017500000000041014141774365030005 0ustar matthiasmatthiasmodule protection.issue21726.typecons; import protection.issue21726.format : issuePkgSym; import protection.issue21726.format : protectionPkgSym; static assert(!__traits(compiles, { import protection.issue21726.format : formatPkgSym; })); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/issue21726/format/0000755000175000017500000000000014141774365027271 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/issue21726/format/package.d0000644000175000017500000000027414141774365031034 0ustar matthiasmatthiasmodule protection.issue21726.format; package(protection.issue21726.format): package(protection.issue21726) int issuePkgSym; package(protection) int protectionPkgSym(); int formatPkgSym; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/issue21726/package.d0000644000175000017500000000003614141774365027540 0ustar matthiasmatthiasmodule protection.issue21726; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/subpkg/0000755000175000017500000000000014141774365025542 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/subpkg/explicit.d0000644000175000017500000000020014141774365027520 0ustar matthiasmatthiasmodule protection.subpkg.explicit; package(protection) void commonAncestorFoo(); package(protection.subpkg) void samePkgFoo(); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/subpkg/tests.d0000644000175000017500000000060214141774365027047 0ustar matthiasmatthiasmodule protection.subpkg.tests; import crosspkg = protection.basic.mod1; static assert ( is(typeof(crosspkg.publicFoo()))); static assert (!is(typeof(crosspkg.packageFoo()))); static assert (!is(typeof(crosspkg.privateFoo()))); import samepkg = protection.subpkg.explicit; static assert ( is(typeof(samepkg.commonAncestorFoo()))); static assert ( is(typeof(samepkg.samePkgFoo()))); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/bug/0000755000175000017500000000000014141774365025024 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/bug/bug14275.d0000644000175000017500000000033114141774365026346 0ustar matthiasmatthiasmodule protection.bug.bug14275; import protection.aggregate.mod14275; // https://issues.dlang.org/show_bug.cgi?id=14275 void main() { Foo f; f.foo(); static assert (!is(typeof(f.foo2()))); bar(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/aggregate/0000755000175000017500000000000014141774365026175 5ustar matthiasmatthias./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/protection/aggregate/mod14275.d0000644000175000017500000000024214141774365027522 0ustar matthiasmatthiasmodule protection.aggregate.mod14275; public struct Foo { package(protection) void foo() {} package void foo2() {} } package(protection) void bar() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9436.d0000644000175000017500000000025214141774365023532 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test9436interp.d // EXTRA_FILES: imports/test9436aggr.d imports/test9436node.d imports/test9436type.d // this is a dummy module for test 9436. ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b19775.d0000644000175000017500000000055214141774365023066 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19775 enum x1 = 42; enum ident(alias a, args...) = mixin(a, args); //enum x2 = ident!("x1"); //FIXME - empty args enum x2 = x1; enum x3 = ident!("x", 2); enum x4 = ident!('x', "", 3); enum x5 = ident!("", 'x', 4); //static assert(x2 == 42); static assert(x3 == 42); static assert(x4 == 42); static assert(x5 == 42); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_355.d0000644000175000017500000000025414141774365024727 0ustar matthiasmatthiasstruct S { uint x; } template MakeS(uint x) { const MakeS = S(x); } struct S2 { alias .MakeS MakeS; } void f() { S2 s2; auto n = s2.MakeS!(0); //////////// XXX }./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16570.d0000644000175000017500000000020114141774365023601 0ustar matthiasmatthiasstatic immutable int _a = 0; enum Regression { a = _a, } static assert(is(typeof(Regression.a) == immutable(Regression))); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix21585.d0000644000175000017500000000120114141774365023413 0ustar matthiasmatthias/* TEST_OUTPUT: --- i int d double Pi int* --- */ pragma(msg, 1.mangleof, " ", __traits(toType, 1.mangleof)); pragma(msg, (1.0).mangleof, " ", __traits(toType, (1.0).mangleof)); pragma(msg, (int*).mangleof, " ", __traits(toType, (int*).mangleof)); template Type(T) { alias Type = T; } Type!(__traits(toType, 1.mangleof)) j = 3; alias T = Type!(__traits(toType, 1.mangleof)); static assert(is(T == int)); __traits(toType, "i") x = 7; static assert(is(Type!(__traits(toType, 1.mangleof)) == int)); static assert(is(Type!(__traits(toType, (1.0).mangleof)) == double)); static assert(is(Type!(__traits(toType, (int*).mangleof)) == int*)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test3004.d0000644000175000017500000000100614141774365023511 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=3004 /* REQUIRED_ARGS: -ignore -v LDC: additionally exclude 'GC stats' line TRANSFORM_OUTPUT: remove_lines("^(predefs|binary|version|config|DFLAG|parse|import|semantic|entry|function object|GC stats|\s*$)") TEST_OUTPUT: --- pragma GNU_attribute (__error) pragma GNU_attribute (__error) code test3004 --- */ extern(C) int printf(char*, ...); pragma(GNU_attribute, flatten) void test() { printf("Hello GNU world!\n".dup.ptr); } pragma(GNU_attribute, flatten); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8543.d0000644000175000017500000000137014141774365023532 0ustar matthiasmatthias static if (__traits(compiles, __vector(float[4]))) { struct vfloat { public: __vector(float[4]) f32; this(float X) nothrow { f32.ptr[0] = X; f32.ptr[1] = X; f32.ptr[2] = X; f32.ptr[3] = X; } this(float X, float Y, float Z, float W) nothrow { f32.array[0] = X; f32.array[1] = Y; f32.array[2] = Z; f32.array[3] = W; } this(float[4] values) nothrow { f32.array = values; } } immutable GvfGlobal_ThreeA = vfloat(3.0f); immutable GvfGlobal_ThreeB = vfloat(3.0f, 3.0f, 3.0f, 3.0f); immutable GvfGlobal_ThreeC = vfloat([3.0f, 3.0f, 3.0f, 3.0f]); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice11596.d0000644000175000017500000000042214141774365023372 0ustar matthiasmatthias// PERMUTE_ARGS: -inline -release -g -O -version=X version(X) alias M = real; else alias M = int[2]; /* or other T[n] with n != 1 */ struct S { M m; } S f() { assert(false); } class C { S[1] ss; /* Here, size doesn't matter. */ this() { ss[] = f(); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/shared_destructor.d0000644000175000017500000000032314141774365025750 0ustar matthiasmatthiasstruct MaybeShared { this(this T)() { } ~this() { } } void main() { { auto aboutToDie = MaybeShared(); } { auto aboutToDie = shared MaybeShared(); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice12956.d0000644000175000017500000000115514141774365023377 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: template isCallable(T...) { static if (is(typeof(& T[0].opCall) == delegate)) { enum bool isCallable = true; } else static if (is(typeof(& T[0].opCall) V : V*) && is(V == function)) { enum bool isCallable = true; } else enum bool isCallable = false; } @property auto injectChain(Injectors...)() { return &ChainTemplates!(Injectors); } template ChainTemplates(Templates...) { alias Head = Templates[0]; alias Tail = Templates[1..$]; alias Head!(Tail) ChainTemplates; } static assert(!isCallable!(injectChain)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16572.d0000644000175000017500000000022114141774365023605 0ustar matthiasmatthiasclass K { inout(int) f() inout { return var; } void bug() { auto d = &f; d(); } int var; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test50.d0000644000175000017500000000022014141774365023344 0ustar matthiasmatthias// COMPILED_IMPORTS: imports/test50a.d // PERMUTE_ARGS: import imports.test50a; class Bar : Foo { alias typeof(Foo.tupleof) Bleh; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test11980.d0000644000175000017500000000005514141774365023610 0ustar matthiasmatthiasvoid start() {} pragma(startaddress, start); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddocbackticks.d0000644000175000017500000000140514141774365025016 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /++ Closely related to std.datetime is `core.time`, and some of the time types used in std.datetime come from there - such as $(CXREF time, Duration), $(CXREF time, TickDuration), and $(CXREF time, FracSec). core.time is publically imported into std.datetime, it isn't necessary to import it separately. +/ module ddocbackticks; /// This should produce `inline code`. void test() {} /// But `this should NOT be inline' /// /// However, restarting on a new line should be `inline again`. void test2() {} /// This `int foo;` should show highlight on foo, but not int. void foo() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test14747.d0000644000175000017500000000141114141774365023611 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: -w int foo(Args...)() { int x; foreach (arg; Args) { static if(is(arg == int)) { return 0; } static if(is(arg == long)) { // fallthrough ++x; // this statement might be unreachable, but // UnrollStatement does not warn that. } } // no return } void main() { auto r1 = foo!(int)(); // return auto r2 = foo!(int, long)(); // return -> fallthrough (it's unreachable) auto r3 = foo!(long, int)(); // fallthough -> return static assert(!__traits(compiles, foo!(long)())); // fallthough static assert(!__traits(compiles, foo!(long, long)())); // fallthough -> fallthough } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice13792.d0000644000175000017500000000007114141774365023372 0ustar matthiasmatthiasenum E; void main() { E* p; // ICE in glue layer } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/header18365.d0000644000175000017500000000121014141774365024057 0ustar matthiasmatthias/* REQUIRED_ARGS: -c -o- -Hf${RESULTS_DIR}/compilable/header18365.di PERMUTE_ARGS: OUTPUT_FILES: ${RESULTS_DIR}/compilable/header18365.di TEST_OUTPUT: --- === ${RESULTS_DIR}/compilable/header18365.di // D import file generated from 'compilable/header18365.d' struct FullCaseEntry { dchar[3] seq; ubyte n; ubyte size; ubyte entry_len; auto const pure nothrow @nogc @property @trusted value() return { return seq[0..entry_len]; } } --- */ struct FullCaseEntry { dchar[3] seq; ubyte n, size; ubyte entry_len; @property auto value() const @trusted pure nothrow @nogc return { return seq[0 .. entry_len]; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/minimal2.d0000644000175000017500000000076414141774365023745 0ustar matthiasmatthias// DFLAGS: // REQUIRED_ARGS: -defaultlib= // EXTRA_SOURCES: extra-files/minimal/object.d // This test ensures that interfaces and classes can be used in a minimal // runtime as long as they only contain static members. // This should compile, but will not link and run properly without // a thread-local storage (TLS) implementation. interface I { static int i; } class A : I { static int a; } class B : A { static int b; } void main() { B.i = 32; B.a = 42; B.b = 52; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b16697.d0000644000175000017500000000127114141774365023065 0ustar matthiasmatthiasstatic assert(!is( float == __vector)); static assert(!is( float[1] == __vector)); static assert(!is( float[4] == __vector)); version (LDC) { /* very permissive wrt. vector types */ } else { static assert(!is(__vector(float[3]) == __vector)); static assert(!is(__vector(float[5]) == __vector)); } static if (__traits(compiles, __vector(float[4]))) { static assert(is(__vector(float[4]) == __vector)); static assert(is(__vector(float[4]) X == __vector) && is(X == float[4])); } static if (__traits(compiles, __vector(byte[16]))) { static assert(is(__vector(byte[16]) X == __vector) && is(X == byte[16])); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18951b.d0000644000175000017500000000016714141774365023763 0ustar matthiasmatthias// EXTRA_FILES: test18951a.d module compilable.test18951b; import test18951a; void test() { A.foo(new Object); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test313g.d0000644000175000017500000000064314141774365023606 0ustar matthiasmatthias// REQUIRED_ARGS: -de // COMPILED_IMPORTS: imports/g313.d // EXTRA_FILES: imports/g313public.d imports/g313staticif.d imports/g313stringmixin.d imports/g313templatemixin.d import imports.g313; void test15900() { // publically imported modules from g313 should be available here imports.g313public.bug(); imports.g313staticif.bug(); imports.g313stringmixin.bug(); imports.g313templatemixin.bug(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc10236.d0000644000175000017500000000316514141774365023540 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o- /* TEST_OUTPUT: --- compilable/ddoc10236.d(35): Warning: Ddoc: parameter count mismatch, expected 2, got 1 compilable/ddoc10236.d(47): Warning: Ddoc: function declaration has no parameter 'y' compilable/ddoc10236.d(59): Warning: Ddoc: function declaration has no parameter 'y' compilable/ddoc10236.d(59): Warning: Ddoc: parameter count mismatch, expected 1, got 2 compilable/ddoc10236.d(71): Warning: Ddoc: parameter count mismatch, expected 2, got 0 compilable/ddoc10236.d(71): Note that the format is `param = description` --- */ /*********************************** * foo_good does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_good(int x, int y) { } /*********************************** * foo_count_mismatch does this. * Params: * x = is for this * and not for that */ void foo_count_mismatch(int x, int y) // Warning: Ddoc: parameter count mismatch { } /*********************************** * foo_no_param_y does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_no_param_y(int x, int z) // Warning: Ddoc: function declaration has no parameter 'y' { } /*********************************** * foo_count_mismatch_no_param_y does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_count_mismatch_no_param_y(int x) { } /*********************************** * foo_count_mismatch_wrong_format does this. * Params: * x : is for this * and not for that * y : is for that */ void foo_count_mismatch_wrong_format(int x, int y) { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/rvalueref.d0000644000175000017500000000040214141774365024215 0ustar matthiasmatthias/* REQUIRED_ARGS: -preview=rvaluerefparam */ struct AS { string get() @safe @nogc pure nothrow { return _s; } alias get this; @disable this(this); string _s; } void popFront(ref string) { } static assert(!is(typeof((R r) => r.popFront))); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test22224.d0000644000175000017500000000011514141774365023576 0ustar matthiasmatthias// REQUIRED_ARGS: -profile -c import core.stdc.stdarg; void error(...) { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test4090.d0000644000175000017500000002453714141774365023535 0ustar matthiasmatthiasvoid test4090a() { // for the mutable elements { int[] arr = [1,2,3]; // inference + qualifier foreach ( x; arr) static assert(is(typeof(x) == int)); foreach ( const x; arr) static assert(is(typeof(x) == const int)); foreach (immutable x; arr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach ( ref x; arr) static assert(is(typeof(x) == int)); foreach ( const ref x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (immutable ref x; arr) {} })); // with exact type + qualifier foreach ( int x; arr) static assert(is(typeof(x) == int)); foreach ( const int x; arr) static assert(is(typeof(x) == const int)); foreach (immutable int x; arr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref foreach ( ref int x; arr) static assert(is(typeof(x) == int)); foreach ( const ref int x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (immutable ref int x; arr) {} })); // convertible type + qualifier foreach ( double x; arr) static assert(is(typeof(x) == double)); foreach ( const double x; arr) static assert(is(typeof(x) == const double)); foreach (immutable double x; arr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach ( ref double x; arr) {} })); static assert(!__traits(compiles, { foreach ( const ref double x; arr) {} })); static assert(!__traits(compiles, { foreach (immutable ref double x; arr) {} })); } // for the immutable elements { immutable(int)[] iarr = [1,2,3]; // inference + qualifier foreach ( x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach ( const x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (immutable x; iarr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach ( ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach ( const ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (immutable ref x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier foreach ( int x; iarr) static assert(is(typeof(x) == int)); foreach ( const int x; iarr) static assert(is(typeof(x) == const int)); foreach (immutable int x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref static assert(!__traits(compiles, { foreach ( ref int x; iarr) {} })); foreach ( const ref int x; iarr) static assert(is(typeof(x) == const int)); foreach (immutable ref int x; iarr) static assert(is(typeof(x) == immutable int)); // convertible type + qualifier foreach ( double x; iarr) static assert(is(typeof(x) == double)); foreach ( const double x; iarr) static assert(is(typeof(x) == const double)); foreach (immutable double x; iarr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach (ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (const ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (immutable ref double x; iarr) {} })); } } void test4090b() { // for the key { int[] arr = [1,2,3]; // inference + qualifier foreach ( i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const i, x; arr) static assert(is(typeof(i) == const size_t)); foreach (immutable i, x; arr) static assert(is(typeof(i) == immutable size_t)); // inference + qualifier + ref foreach ( ref i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const ref i, x; arr) static assert(is(typeof(i) == const size_t)); static assert(!__traits(compiles, { foreach (immutable ref i, x; arr) {} })); // with exact type + qualifier foreach ( size_t i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const size_t i, x; arr) static assert(is(typeof(i) == const size_t)); foreach (immutable size_t i, x; arr) static assert(is(typeof(i) == immutable size_t)); // with exact type + qualifier + ref foreach ( ref size_t i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const ref size_t i, x; arr) static assert(is(typeof(i) == const size_t)); static assert(!__traits(compiles, { foreach (immutable ref size_t i, x; arr) {} })); } // for the mutable elements { int[] arr = [1,2,3]; // inference + qualifier foreach (i, x; arr) static assert(is(typeof(x) == int)); foreach (i, const x; arr) static assert(is(typeof(x) == const int)); foreach (i, immutable x; arr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach (i, ref x; arr) static assert(is(typeof(x) == int)); foreach (i, const ref x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (i, immutable ref x; arr) {} })); // with exact type + qualifier foreach (i, int x; arr) static assert(is(typeof(x) == int)); foreach (i, const int x; arr) static assert(is(typeof(x) == const int)); foreach (i, immutable int x; arr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref foreach (i, ref int x; arr) static assert(is(typeof(x) == int)); foreach (i, const ref int x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (i, immutable ref int x; arr) {} })); // convertible type + qualifier foreach (i, double x; arr) static assert(is(typeof(x) == double)); foreach (i, const double x; arr) static assert(is(typeof(x) == const double)); foreach (i, immutable double x; arr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach (i, ref double x; arr) {} })); static assert(!__traits(compiles, { foreach (i, const ref double x; arr) {} })); static assert(!__traits(compiles, { foreach (i, immutable ref double x; arr) {} })); } // for the immutable elements { immutable(int)[] iarr = [1,2,3]; // inference + qualifier foreach (i, x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, const x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, immutable x; iarr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach (i, ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, const ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, immutable ref x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier foreach (i, int x; iarr) static assert(is(typeof(x) == int)); foreach (i, const int x; iarr) static assert(is(typeof(x) == const int)); foreach (i, immutable int x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref static assert(!__traits(compiles, { foreach (i, ref int x; iarr) {} })); foreach (i, const ref int x; iarr) static assert(is(typeof(x) == const int)); foreach (i, immutable ref int x; iarr) static assert(is(typeof(x) == immutable int)); // convertible type + qualifier foreach (i , double x; iarr) static assert(is(typeof(x) == double)); foreach (i, const double x; iarr) static assert(is(typeof(x) == const double)); foreach (i, immutable double x; iarr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach (i, ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (i, const ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (i, immutable ref double x; iarr) {} })); } } void test4090c() { foreach ( x; 1..11) static assert(is(typeof(x) == int)); foreach ( const x; 1..11) static assert(is(typeof(x) == const int)); foreach (immutable x; 1..11) static assert(is(typeof(x) == immutable int)); foreach ( int x; 1..11) static assert(is(typeof(x) == int)); foreach ( const int x; 1..11) static assert(is(typeof(x) == const int)); foreach (immutable int x; 1..11) static assert(is(typeof(x) == immutable int)); foreach ( ref x; 1..11) static assert(is(typeof(x) == int)); foreach ( const ref x; 1..11) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (immutable ref x; 1..11) {} })); foreach ( double x; 1..11) static assert(is(typeof(x) == double)); foreach ( const double x; 1..11) static assert(is(typeof(x) == const double)); foreach (immutable double x; 1..11) static assert(is(typeof(x) == immutable double)); foreach ( ref double x; 1..11) static assert(is(typeof(x) == double)); foreach ( const ref double x; 1..11) static assert(is(typeof(x) == const double)); static assert(!__traits(compiles, { foreach (immutable ref double x; 1..11) {} })); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/nogc.d0000644000175000017500000000501014141774365023150 0ustar matthiasmatthias// REQUIRED_ARGS: -o- /***************** Covariance ******************/ class C1 { void foo() @nogc; void bar(); } class D1 : C1 { override void foo(); // no error override void bar() @nogc; // no error } /******************************************/ // __traits(compiles) static assert(__traits(compiles, new Object())); void foo_compiles() {} @nogc void test_compiles() { auto fp = &foo_compiles; static assert(!__traits(compiles, foo_compiles())); static assert(!__traits(compiles, fp())); static assert(!__traits(compiles, (*fp)())); static assert(!__traits(compiles, [1,2,3])); static assert(!__traits(compiles, [1:1, 2:2])); struct Struct {} static assert(!__traits(compiles, new int)); static assert(!__traits(compiles, new Struct())); static assert(!__traits(compiles, new Object())); int* p; static assert(!__traits(compiles, delete p)); int[int] aa; static assert(!__traits(compiles, aa[0])); int[] a; static assert(!__traits(compiles, a.length = 1)); static assert(!__traits(compiles, a.length += 1)); static assert(!__traits(compiles, a.length -= 1)); static assert(!__traits(compiles, a ~= 1)); static assert(!__traits(compiles, a ~ a)); } /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=12630 void test12630() @nogc { // All of these declarations should cause no errors. static const ex1 = new Exception("invalid"); //enum ex2 = new Exception("invalid"); static const arr1 = [[1,2], [3, 4]]; enum arr2 = [[1,2], [3, 4]]; //static const aa1 = [1:1, 2:2]; enum aa2 = [1:1, 2:2]; //static const v1 = aa1[1]; enum v2 = aa2[1]; Object o; //static const del1 = (delete o).sizeof; //enum del2 = (delete o).sizeof; int[] a; static const len1 = (a.length = 1).sizeof; enum len2 = (a.length = 1).sizeof; static const cata1 = (a ~= 1).sizeof; enum cata2 = (a ~= 1).sizeof; static const cat1 = (a ~ a).sizeof; enum cat2 = (a ~ a).sizeof; } /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=12642 static if (is(__vector(ulong[2]))) { import core.simd; ulong2 test12642() @nogc { return [0, 0]; } } /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=13550 auto foo13550() @nogc { static int[] bar() { return new int[2]; } return &bar; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/version.d0000644000175000017500000000030314141774365023707 0ustar matthiasmatthias/* REQUIRED_ARGS: */ version (D_ModuleInfo) { } else { static assert(0); } version (D_Exceptions) { } else { static assert(0); } version (D_TypeInfo) { } else { static assert(0); }./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/bug20796.d0000644000175000017500000000014414141774365023412 0ustar matthiasmatthias// EXTRA_SOURCES: protection/issue20796/package.d // https://issues.dlang.org/show_bug.cgi?id=20796 ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test14962.d0000644000175000017500000000131014141774365023606 0ustar matthiasmatthiastemplate map(fun...) { auto map(R)(R r) { return MapResult!(fun, R)(r); } } struct MapResult(alias fun, R) { R _input; @property bool empty() { return _input.length == 0; } @property auto front() { return fun(_input[0]); } void popFront() { _input = _input[1..$]; } } struct Foo { int baz(int v) { static int id; return v + id++; } void bar() { auto arr1 = [1, 2, 3]; auto arr2 = [4, 5, 6]; arr1.map!( // lambda1 i => arr2.map!( // lambda2 j => baz(i + j) ) ); } } void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9526.d0000644000175000017500000000074014141774365023534 0ustar matthiasmatthiastemplate forward(args...) { @property fwd()() { return args[0]; } static assert(__traits(compiles, { auto ex = fwd; })); alias fwd forward; } void initializeClassInstance(C, Args...)(C chunk, auto ref Args args) { chunk.__ctor(forward!args); } void main() { static int si = 0; static class C { this(int) { ++si; } } void[__traits(classInstanceSize, C)] buff = void; auto c = cast(C) buff.ptr; initializeClassInstance(c, 0); assert(si); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16080.d0000644000175000017500000000030214141774365023577 0ustar matthiasmatthias// REQUIRED_ARGS: -lib -Icompilable/imports // COMPILED_IMPORTS: extra-files/test16080b.d // EXTRA_FILES: imports/imp16080.d // https://issues.dlang.org/show_bug.cgi?id=16080 import imp16080; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testcontracts.d0000644000175000017500000000516614141774365025136 0ustar matthiasmatthias// COMPILED_IMPORTS: imports/testcontracts.d import imports.testcontracts; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=3602 class Derived3602 : Base3602 { override void method(int x, int y) in { assert(x > 0); assert(y > 0); } do { } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=5230 class Derived5230 : Base5230 { override int method() { return 69; } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=17502 class Foo17502 { auto foo() out {} do {} auto bar() out { assert (__result > 5); } do { return 6; } auto bar_2() out (res) { assert (res > 5); } do { return 6; } int concrete() out { assert(__result > 5); } do { return 6; } int concrete_2() out(res) { assert (res > 5); } do { return 6; } void void_foo() out {} do {} auto void_auto() out {} do {} } /***************************************************/ // Order of declaration: (A), (C : B), (B : A) class A17502 { int method(int p) in { assert(p > 5); } out(res) { assert(res > 5); } do { return p; } } class C17502 : B17502 { override int method(int p) in { assert(p > 3); } do { return p * 2; } } class B17502 : A17502 { override int method(int p) in { assert(p > 2); } do { return p * 3; } } /***************************************************/ // Order of declaration: (X : Y), (Y : Z), (Z) class X17502 : Y17502 { override int method(int p) in { assert(p > 3); } do { return p * 2; } } class Y17502 : Z17502 { override int method(int p) in { assert(p > 2); } do { return p * 3; } } class Z17502 { int method(int p) in { assert(p > 5); } out(res) { assert(res > 5); } do { return p; } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=17893 final class Foo17893(T) { extern(C) void maythrow(); void bar() in { maythrow(); } do { } } Foo17893!int foo17893; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=15984 alias Bar15984 = extern (C) void function(void*); final class C15984 { void foo(Bar15984 bar) in { assert(bar); } do {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice10431b.d0000644000175000017500000000013514141774365023520 0ustar matthiasmatthiasstruct X(alias Y) { } struct A { int[] data; } alias X!(A([])) X1; alias X!(A([])) X2; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/99bottles.d0000644000175000017500000003276114141774365024075 0ustar matthiasmatthias// written by Don Clugston: // http://www.digitalmars.com/d/archives/digitalmars/D/announce/4374.html // http://www.99-bottles-of-beer.net/language-d-1212.html // Generates the "99 bottles of beer" song at compile time, // using the template metaprograming facilities of D. // No executable is generated. No libraries are used. // Illustrates template default values, template string value parameters, // compile-time concatenation of constant strings, static if. module bottles99; template decimaldigit(int n) { const string decimaldigit = "0123456789"[n..n+1]; } template itoa(ulong n) { static if ( n < 10L ) const string itoa = decimaldigit!(n); else const string itoa = itoa!( n / 10L ) ~ decimaldigit!( n % 10L ); } template showHowMany(int n, string where, bool needcapital = false) { static if ( n > 1 ) const string showHowMany = itoa!(n) ~ " bottles of beer" ~ where ~ "\n"; else static if ( n == 1 ) const string showHowMany = "1 bottle of beer" ~ where ~ "\n"; else static if ( needcapital ) const string showHowMany = "No more bottles of beer" ~ where ~ "\n"; else const string showHowMany = "no more bottles of beer" ~ where ~ "\n"; } template beer(int maxbeers, int n = maxbeers) { static if ( n > 0 ) const string beer = showHowMany!(n, " on the wall,", true) ~ showHowMany!(n, ".") ~ "Take one down and pass it around, " ~ "\n" ~ showHowMany!( n - 1 , " on the wall.") ~ "\n" ~ beer!(maxbeers, n - 1); // recurse for subsequent verses. else const string beer = showHowMany!(n, " on the wall,", true) ~ showHowMany!(n, ".") ~ "Go to the store and buy some more, " ~ "\n" ~ showHowMany!( maxbeers, " on the wall."); } enum expected = `99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall. 98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around, 97 bottles of beer on the wall. 97 bottles of beer on the wall, 97 bottles of beer. Take one down and pass it around, 96 bottles of beer on the wall. 96 bottles of beer on the wall, 96 bottles of beer. Take one down and pass it around, 95 bottles of beer on the wall. 95 bottles of beer on the wall, 95 bottles of beer. Take one down and pass it around, 94 bottles of beer on the wall. 94 bottles of beer on the wall, 94 bottles of beer. Take one down and pass it around, 93 bottles of beer on the wall. 93 bottles of beer on the wall, 93 bottles of beer. Take one down and pass it around, 92 bottles of beer on the wall. 92 bottles of beer on the wall, 92 bottles of beer. Take one down and pass it around, 91 bottles of beer on the wall. 91 bottles of beer on the wall, 91 bottles of beer. Take one down and pass it around, 90 bottles of beer on the wall. 90 bottles of beer on the wall, 90 bottles of beer. Take one down and pass it around, 89 bottles of beer on the wall. 89 bottles of beer on the wall, 89 bottles of beer. Take one down and pass it around, 88 bottles of beer on the wall. 88 bottles of beer on the wall, 88 bottles of beer. Take one down and pass it around, 87 bottles of beer on the wall. 87 bottles of beer on the wall, 87 bottles of beer. Take one down and pass it around, 86 bottles of beer on the wall. 86 bottles of beer on the wall, 86 bottles of beer. Take one down and pass it around, 85 bottles of beer on the wall. 85 bottles of beer on the wall, 85 bottles of beer. Take one down and pass it around, 84 bottles of beer on the wall. 84 bottles of beer on the wall, 84 bottles of beer. Take one down and pass it around, 83 bottles of beer on the wall. 83 bottles of beer on the wall, 83 bottles of beer. Take one down and pass it around, 82 bottles of beer on the wall. 82 bottles of beer on the wall, 82 bottles of beer. Take one down and pass it around, 81 bottles of beer on the wall. 81 bottles of beer on the wall, 81 bottles of beer. Take one down and pass it around, 80 bottles of beer on the wall. 80 bottles of beer on the wall, 80 bottles of beer. Take one down and pass it around, 79 bottles of beer on the wall. 79 bottles of beer on the wall, 79 bottles of beer. Take one down and pass it around, 78 bottles of beer on the wall. 78 bottles of beer on the wall, 78 bottles of beer. Take one down and pass it around, 77 bottles of beer on the wall. 77 bottles of beer on the wall, 77 bottles of beer. Take one down and pass it around, 76 bottles of beer on the wall. 76 bottles of beer on the wall, 76 bottles of beer. Take one down and pass it around, 75 bottles of beer on the wall. 75 bottles of beer on the wall, 75 bottles of beer. Take one down and pass it around, 74 bottles of beer on the wall. 74 bottles of beer on the wall, 74 bottles of beer. Take one down and pass it around, 73 bottles of beer on the wall. 73 bottles of beer on the wall, 73 bottles of beer. Take one down and pass it around, 72 bottles of beer on the wall. 72 bottles of beer on the wall, 72 bottles of beer. Take one down and pass it around, 71 bottles of beer on the wall. 71 bottles of beer on the wall, 71 bottles of beer. Take one down and pass it around, 70 bottles of beer on the wall. 70 bottles of beer on the wall, 70 bottles of beer. Take one down and pass it around, 69 bottles of beer on the wall. 69 bottles of beer on the wall, 69 bottles of beer. Take one down and pass it around, 68 bottles of beer on the wall. 68 bottles of beer on the wall, 68 bottles of beer. Take one down and pass it around, 67 bottles of beer on the wall. 67 bottles of beer on the wall, 67 bottles of beer. Take one down and pass it around, 66 bottles of beer on the wall. 66 bottles of beer on the wall, 66 bottles of beer. Take one down and pass it around, 65 bottles of beer on the wall. 65 bottles of beer on the wall, 65 bottles of beer. Take one down and pass it around, 64 bottles of beer on the wall. 64 bottles of beer on the wall, 64 bottles of beer. Take one down and pass it around, 63 bottles of beer on the wall. 63 bottles of beer on the wall, 63 bottles of beer. Take one down and pass it around, 62 bottles of beer on the wall. 62 bottles of beer on the wall, 62 bottles of beer. Take one down and pass it around, 61 bottles of beer on the wall. 61 bottles of beer on the wall, 61 bottles of beer. Take one down and pass it around, 60 bottles of beer on the wall. 60 bottles of beer on the wall, 60 bottles of beer. Take one down and pass it around, 59 bottles of beer on the wall. 59 bottles of beer on the wall, 59 bottles of beer. Take one down and pass it around, 58 bottles of beer on the wall. 58 bottles of beer on the wall, 58 bottles of beer. Take one down and pass it around, 57 bottles of beer on the wall. 57 bottles of beer on the wall, 57 bottles of beer. Take one down and pass it around, 56 bottles of beer on the wall. 56 bottles of beer on the wall, 56 bottles of beer. Take one down and pass it around, 55 bottles of beer on the wall. 55 bottles of beer on the wall, 55 bottles of beer. Take one down and pass it around, 54 bottles of beer on the wall. 54 bottles of beer on the wall, 54 bottles of beer. Take one down and pass it around, 53 bottles of beer on the wall. 53 bottles of beer on the wall, 53 bottles of beer. Take one down and pass it around, 52 bottles of beer on the wall. 52 bottles of beer on the wall, 52 bottles of beer. Take one down and pass it around, 51 bottles of beer on the wall. 51 bottles of beer on the wall, 51 bottles of beer. Take one down and pass it around, 50 bottles of beer on the wall. 50 bottles of beer on the wall, 50 bottles of beer. Take one down and pass it around, 49 bottles of beer on the wall. 49 bottles of beer on the wall, 49 bottles of beer. Take one down and pass it around, 48 bottles of beer on the wall. 48 bottles of beer on the wall, 48 bottles of beer. Take one down and pass it around, 47 bottles of beer on the wall. 47 bottles of beer on the wall, 47 bottles of beer. Take one down and pass it around, 46 bottles of beer on the wall. 46 bottles of beer on the wall, 46 bottles of beer. Take one down and pass it around, 45 bottles of beer on the wall. 45 bottles of beer on the wall, 45 bottles of beer. Take one down and pass it around, 44 bottles of beer on the wall. 44 bottles of beer on the wall, 44 bottles of beer. Take one down and pass it around, 43 bottles of beer on the wall. 43 bottles of beer on the wall, 43 bottles of beer. Take one down and pass it around, 42 bottles of beer on the wall. 42 bottles of beer on the wall, 42 bottles of beer. Take one down and pass it around, 41 bottles of beer on the wall. 41 bottles of beer on the wall, 41 bottles of beer. Take one down and pass it around, 40 bottles of beer on the wall. 40 bottles of beer on the wall, 40 bottles of beer. Take one down and pass it around, 39 bottles of beer on the wall. 39 bottles of beer on the wall, 39 bottles of beer. Take one down and pass it around, 38 bottles of beer on the wall. 38 bottles of beer on the wall, 38 bottles of beer. Take one down and pass it around, 37 bottles of beer on the wall. 37 bottles of beer on the wall, 37 bottles of beer. Take one down and pass it around, 36 bottles of beer on the wall. 36 bottles of beer on the wall, 36 bottles of beer. Take one down and pass it around, 35 bottles of beer on the wall. 35 bottles of beer on the wall, 35 bottles of beer. Take one down and pass it around, 34 bottles of beer on the wall. 34 bottles of beer on the wall, 34 bottles of beer. Take one down and pass it around, 33 bottles of beer on the wall. 33 bottles of beer on the wall, 33 bottles of beer. Take one down and pass it around, 32 bottles of beer on the wall. 32 bottles of beer on the wall, 32 bottles of beer. Take one down and pass it around, 31 bottles of beer on the wall. 31 bottles of beer on the wall, 31 bottles of beer. Take one down and pass it around, 30 bottles of beer on the wall. 30 bottles of beer on the wall, 30 bottles of beer. Take one down and pass it around, 29 bottles of beer on the wall. 29 bottles of beer on the wall, 29 bottles of beer. Take one down and pass it around, 28 bottles of beer on the wall. 28 bottles of beer on the wall, 28 bottles of beer. Take one down and pass it around, 27 bottles of beer on the wall. 27 bottles of beer on the wall, 27 bottles of beer. Take one down and pass it around, 26 bottles of beer on the wall. 26 bottles of beer on the wall, 26 bottles of beer. Take one down and pass it around, 25 bottles of beer on the wall. 25 bottles of beer on the wall, 25 bottles of beer. Take one down and pass it around, 24 bottles of beer on the wall. 24 bottles of beer on the wall, 24 bottles of beer. Take one down and pass it around, 23 bottles of beer on the wall. 23 bottles of beer on the wall, 23 bottles of beer. Take one down and pass it around, 22 bottles of beer on the wall. 22 bottles of beer on the wall, 22 bottles of beer. Take one down and pass it around, 21 bottles of beer on the wall. 21 bottles of beer on the wall, 21 bottles of beer. Take one down and pass it around, 20 bottles of beer on the wall. 20 bottles of beer on the wall, 20 bottles of beer. Take one down and pass it around, 19 bottles of beer on the wall. 19 bottles of beer on the wall, 19 bottles of beer. Take one down and pass it around, 18 bottles of beer on the wall. 18 bottles of beer on the wall, 18 bottles of beer. Take one down and pass it around, 17 bottles of beer on the wall. 17 bottles of beer on the wall, 17 bottles of beer. Take one down and pass it around, 16 bottles of beer on the wall. 16 bottles of beer on the wall, 16 bottles of beer. Take one down and pass it around, 15 bottles of beer on the wall. 15 bottles of beer on the wall, 15 bottles of beer. Take one down and pass it around, 14 bottles of beer on the wall. 14 bottles of beer on the wall, 14 bottles of beer. Take one down and pass it around, 13 bottles of beer on the wall. 13 bottles of beer on the wall, 13 bottles of beer. Take one down and pass it around, 12 bottles of beer on the wall. 12 bottles of beer on the wall, 12 bottles of beer. Take one down and pass it around, 11 bottles of beer on the wall. 11 bottles of beer on the wall, 11 bottles of beer. Take one down and pass it around, 10 bottles of beer on the wall. 10 bottles of beer on the wall, 10 bottles of beer. Take one down and pass it around, 9 bottles of beer on the wall. 9 bottles of beer on the wall, 9 bottles of beer. Take one down and pass it around, 8 bottles of beer on the wall. 8 bottles of beer on the wall, 8 bottles of beer. Take one down and pass it around, 7 bottles of beer on the wall. 7 bottles of beer on the wall, 7 bottles of beer. Take one down and pass it around, 6 bottles of beer on the wall. 6 bottles of beer on the wall, 6 bottles of beer. Take one down and pass it around, 5 bottles of beer on the wall. 5 bottles of beer on the wall, 5 bottles of beer. Take one down and pass it around, 4 bottles of beer on the wall. 4 bottles of beer on the wall, 4 bottles of beer. Take one down and pass it around, 3 bottles of beer on the wall. 3 bottles of beer on the wall, 3 bottles of beer. Take one down and pass it around, 2 bottles of beer on the wall. 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no more bottles of beer on the wall. No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall. `; static assert(beer!(99) == expected); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20842.d0000644000175000017500000000047614141774365023614 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20842 struct A { int i; @disable this(ref A); } A a = { i: 123 }; struct B { int i; @disable this(); } B b = { i: 123 }; union C { int i; @disable this(ref C); } C c = { i: 123 }; union D { int i; @disable this(); } D d = { i: 123 }; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test12511.d0000644000175000017500000000024314141774365023576 0ustar matthiasmatthias// EXTRA_FILES: imports/a12511.d module test12511; import imports.a12511; public class B { static void bar() { A.foo(0); } } void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16747.d0000644000175000017500000000024314141774365023615 0ustar matthiasmatthias/* PERMUTE_ARGS: */ class C { @safe ~this() { } } class D : C { } void fwd() @safe { scope o = new Object(); scope c = new C(); scope d = new D(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/mixin.d0000644000175000017500000000102214141774365023345 0ustar matthiasmatthias/* REQUIRED_ARGS: -mixin=${RESULTS_DIR}/runnable/mixin.mixin -o- OUTPUT_FILES: ${RESULTS_DIR}/runnable/mixin.mixin TEST_OUTPUT: ---- === ${RESULTS_DIR}/runnable/mixin.mixin // expansion at compilable/mixin.d(14) int x = 123; int y; int z = x + y; ---- https://issues.dlang.org/show_bug.cgi?id=1870 https://issues.dlang.org/show_bug.cgi?id=12790 */ #line 1 string get() { return "int x =\n 123;\r\n" ~ q{ int y; int z = x + y;}; } void main() { mixin(get()); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test12009.d0000644000175000017500000000072314141774365023603 0ustar matthiasmatthiasstruct RefCounted(T) { struct RefCountedStore { private struct Impl { T _payload; } private Impl* _store; } RefCountedStore _refCounted; ~this() { import core.stdc.stdlib : free; } } struct GroupBy(R) { struct SharedInput { Group unused; } struct Group { private RefCounted!SharedInput _allGroups; } } void main() { GroupBy!(int[]) g1; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17853.d0000644000175000017500000000023414141774365023614 0ustar matthiasmatthias// Switch with no braces & empty case should compile int main() { int ob = 1; final switch (ob) case 0: case 1: break; return ob; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue19243.sh0000644000175000017500000000226014141774365024150 0ustar matthiasmatthias#! /usr/bin/env bash # this test would require -link-defaultlib-shared, which isn't available with BUILD_SHARED_LIBS=OFF # DISABLED: LDC # bypassing this test: # - on windows # - on FreeBSD 32 bits # test fails looling for liborig.so; don't know why but shouldn't block fixing all other platforms # - on Circle CI with no_pic. (need PIC to run the test) if [[ $OS = *"win"* ]]; then exit 0; fi if [[ $OS = *"freebsd"* ]] && [[ $MODEL = *"32"* ]]; then exit 0; fi if [ ${PIC:-1} == "0" ]; then exit 0; fi TEST_DIR=${OUTPUT_BASE} ORIG_D=$TEST_DIR/orig.d ORIG_SO=$TEST_DIR/liborig${SOEXT} OVERRIDE_D=$TEST_DIR/override.d OVERRIDE_SO=$TEST_DIR/liboverride${SOEXT} APP_D=$TEST_DIR/app.d mkdir -p $TEST_DIR cat << EOF | $DMD -m$MODEL -fPIC -shared -of$ORIG_SO - import core.stdc.stdio; extern(C) int func() { printf("liborig\n"); return 1; } EOF cat << EOF | $DMD -m$MODEL -fPIC -shared -of$OVERRIDE_SO - import core.stdc.stdio; extern(C) int func() { printf("liboverride\n"); return 2; } EOF cat << EOF | LD_LIBRARY_PATH=$TEST_DIR $DMD -m$MODEL -L-L$TEST_DIR -L$OVERRIDE_SO -run - extern(C) int func(); pragma(lib, "orig"); void main() { assert(func() == 2); } EOF ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6013.d0000644000175000017500000000067314141774365023525 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/test6013.d import imports.test6013; static assert(__traits(compiles, public_alias_value)); static assert(!__traits(compiles, private_alias_value)); static assert(__traits(compiles, public_alias_func())); static assert(!__traits(compiles, private_alias_func())); static assert(__traits(compiles, () { public_alias_type val; })); static assert(!__traits(compiles, () { private_alias_type val; })); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16083.d0000644000175000017500000000050514141774365023607 0ustar matthiasmatthiastemplate Alias(Stuff...) { alias Alias = Stuff; } enum A { a = 0 } enum B { b = 0 } enum C { c = "abc" } enum D { d = "abc" } static assert(is(typeof(Alias!(A.a)[0]) == A)); static assert(is(typeof(Alias!(B.b)[0]) == B)); static assert(is(typeof(Alias!(C.c)[0]) == C)); static assert(is(typeof(Alias!(D.d)[0]) == D)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17906.d0000644000175000017500000000021514141774365023612 0ustar matthiasmatthias// REQUIRED_ARGS: -de // https://issues.dlang.org/show_bug.cgi?id=18647 deprecated void main () { Object o = new Object; delete o; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15784.d0000644000175000017500000000107114141774365023615 0ustar matthiasmatthias// PERMUTE_ARGS: template AddField(T) { T b; this(Args...)(T b, auto ref Args args) { this.b = b; this(args); } } template construcotrs() { int a; this(int a) { this.a = a; } } class B { mixin construcotrs; mixin AddField!(string); } class C : B { this(A...)(A args) { // The called super ctor is an overload set. super(args); } } struct S { mixin construcotrs; mixin AddField!(string); } void main() { auto s = S("bar", 15); auto c = new C("bar", 15); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/pr9471.d0000644000175000017500000000034514141774365023176 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/pr9471a.d imports/pr9471b.d imports/pr9471c.d imports/pr9471d.d import imports.pr9471a; import imports.pr9471b; static assert (__traits(getVirtualIndex, ClassDeclaration.isBaseOf) == 7); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue17167.sh0000755000175000017500000000126714141774365024164 0ustar matthiasmatthias#!/usr/bin/env bash # Test that file paths larger than 248 characters can be used # Test CRLF and mixed line ending handling in D lexer. test_dir=${OUTPUT_BASE}/uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu mkdir -p "$test_dir" bin_base=${test_dir}/${TEST_NAME} bin="$bin_base$OBJ" src="$bin_base.d" echo 'void main() {}' > "${src}" # Only compile, not link, since optlink can't handle long file names $DMD -m"${MODEL}" "${DFLAGS}" -c -of"${bin}" "${src}" rm_retry -r "${OUTPUT_BASE}" ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue21203.d0000644000175000017500000001365014141774365023753 0ustar matthiasmatthias template ScopeClass(C , string name = C.stringof) //if (is(C == class) && __traits(getLinkage, C) == "C++") { //enum name = C.stringof; enum ns = __traits(getCppNamespaces,C); extern(C++, class) { extern(C++,(ns)) { pragma(mangle, C, name) struct ScopeClass { char[__traits(classInstanceSize, C)] buffer; //... all the things ... } } } } // Basic tests extern(C++) { class MyClassA {} void funa(ScopeClass!MyClassA); // mangles MyClass void funb(const ScopeClass!MyClassA); // mangles const MyClass void func(ref ScopeClass!MyClassA); // mangles MyClass& void fund(ref const ScopeClass!MyClassA); // mangles const MyClass& void fune(const(ScopeClass!MyClassA)*); } version (Posix) { static assert(funa.mangleof == "_Z4funa8MyClassA"); static assert(funb.mangleof == "_Z4funb8MyClassA"); static assert(func.mangleof == "_Z4funcR8MyClassA"); static assert(fund.mangleof == "_Z4fundRK8MyClassA"); static assert(fune.mangleof == "_Z4funePK8MyClassA"); } else version (CppRuntime_Microsoft) { static assert(funa.mangleof == "?funa@@YAXVMyClassA@@@Z"); static assert(funb.mangleof == "?funb@@YAXVMyClassA@@@Z"); static if (size_t.sizeof == ulong.sizeof) { static assert(func.mangleof == "?func@@YAXAEAVMyClassA@@@Z"); static assert(fund.mangleof == "?fund@@YAXAEBVMyClassA@@@Z"); static assert(fune.mangleof == "?fune@@YAXPEBVMyClassA@@@Z"); } else { static assert(func.mangleof == "?func@@YAXAAVMyClassA@@@Z"); static assert(fund.mangleof == "?fund@@YAXABVMyClassA@@@Z"); static assert(fune.mangleof == "?fune@@YAXPBVMyClassA@@@Z"); } } //Basic tests with a namespace extern(C++, "ns") { class MyClassB {} void funf(ScopeClass!MyClassB); // mangles MyClass void fung(const ScopeClass!MyClassB); // mangles const MyClass void funh(ref ScopeClass!MyClassB); // mangles MyClass& void funi(ref const ScopeClass!MyClassB); // mangles const MyClass& void funj(const(ScopeClass!MyClassB)*); } version (Posix) { static assert(funf.mangleof == "_ZN2ns4funfENS_8MyClassBE"); static assert(fung.mangleof == "_ZN2ns4fungENS_8MyClassBE"); static assert(funh.mangleof == "_ZN2ns4funhERNS_8MyClassBE"); static assert(funi.mangleof == "_ZN2ns4funiERKNS_8MyClassBE"); static assert(funj.mangleof == "_ZN2ns4funjEPKNS_8MyClassBE"); } else version (CppRuntime_Microsoft) { static assert(funf.mangleof == "?funf@ns@@YAXVMyClassB@1@@Z"); static assert(fung.mangleof == "?fung@ns@@YAXVMyClassB@1@@Z"); static if (size_t.sizeof == ulong.sizeof) { static assert(funh.mangleof == "?funh@ns@@YAXAEAVMyClassB@1@@Z"); static assert(funi.mangleof == "?funi@ns@@YAXAEBVMyClassB@1@@Z"); static assert(funj.mangleof == "?funj@ns@@YAXPEBVMyClassB@1@@Z"); } else { static assert(funh.mangleof == "?funh@ns@@YAXAAVMyClassB@1@@Z"); static assert(funi.mangleof == "?funi@ns@@YAXABVMyClassB@1@@Z"); static assert(funj.mangleof == "?funj@ns@@YAXPBVMyClassB@1@@Z"); } } //Templates extern(C++) { void funTempl(T)(); class MyClassC {} alias funTemplA = funTempl!(ScopeClass!MyClassC); alias funTemplB = funTempl!(const ScopeClass!MyClassC); alias funTemplC = funTempl!(const(ScopeClass!MyClassC)*); // N.B funTempl!([const] ref ScopeClass!MyClassC) is not permissable in D } version (Posix) { static assert(funTemplA.mangleof == "_Z8funTemplI8MyClassCEvv"); static assert(funTemplB.mangleof == "_Z8funTemplIK8MyClassCEvv"); static assert(funTemplC.mangleof == "_Z8funTemplIPK8MyClassCEvv"); } else version (CppRuntime_Microsoft) { static assert(funTemplA.mangleof == "??$funTempl@VMyClassC@@@@YAXXZ"); static assert(funTemplB.mangleof == "??$funTempl@$$CBVMyClassC@@@@YAXXZ"); static if (size_t.sizeof == ulong.sizeof) static assert(funTemplC.mangleof == "??$funTempl@PEBVMyClassC@@@@YAXXZ"); else static assert(funTemplC.mangleof == "??$funTempl@PBVMyClassC@@@@YAXXZ"); } template _function(F) { extern(C++, "std") { extern(C++, struct) pragma(mangle, "function") class _function { } } } template FunctionOf(F) { F f; alias FunctionOf = typeof(*f); } extern(C++) void funk(ScopeClass!(_function!(FunctionOf!(void function(int))),"function") a ){ } version (Posix) { static assert(funk.mangleof == "_Z4funkSt8functionIFviEE"); } else version (CppRuntime_Microsoft) { static assert(funk.mangleof == "?funk@@YAXV?$function@$$A6AXH@Z@std@@@Z"); } extern(C++, "ns") { pragma(mangle, "function") class _function2 { public final void test(); } } version (Posix) { static assert(_function2.test.mangleof == "_ZN2ns8function4testEv"); } else version (CppRuntime_Microsoft) { static if (size_t.sizeof == ulong.sizeof) static assert(_function2.test.mangleof == "?test@function@ns@@QEAAXXZ"); else static assert(_function2.test.mangleof == "?test@function@ns@@QAEXXZ"); } extern(C++, "ns") { template _function3(T) { pragma(mangle, _function3, "function") class _function3 { public final void test(); } } } version (Posix) { static assert(_function3!(int).test.mangleof == "_ZN2ns8functionIiE4testEv"); } else version (CppRuntime_Microsoft) { static if (size_t.sizeof == ulong.sizeof) static assert(_function3!(int).test.mangleof == "?test@?$function@H@ns@@QEAAXXZ"); else static assert(_function3!(int).test.mangleof == "?test@?$function@H@ns@@QAEXXZ"); } extern(C++) { struct Foo {} pragma(mangle, Foo) struct Foo_Doppelganger {} void funl(Foo_Doppelganger f); } version (Posix) { static assert(funl.mangleof == "_Z4funl3Foo"); } else version (CppRuntime_Microsoft) { static assert(funl.mangleof == "?funl@@YAXUFoo@@@Z"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19746.d0000644000175000017500000000053414141774365023622 0ustar matthiasmatthias// REQUIRED_ARGS: -Icompilable/imports // EXTRA_FILES: imports/test19746a.d imports/test19746b.d imports/test19746c.d imports/test19746d.d import test19746c; import test19746b: Frop; template Base(T) { static if (is(T == super)) alias Base = Object; } class Foo { class Nested: Base!Foo { } void func(Frop) { } void thunk() { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc9497a.d0000644000175000017500000000036614141774365023642 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc9497a.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** foo function. Args: $(XYZ arg1, arg2) */ void foo() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddocYear.d0000644000175000017500000000023414141774365023757 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocYear-postscript.sh /// $(YEAR) int year; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21742.d0000644000175000017500000000041314141774365023603 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21742 int foo()() { return 0; } struct B { int foo()() { return 0; } } static assert(is(typeof(foo) == void)); // failed, gagged error: expression B().foo()() has no type static assert(is(typeof(B().foo) == void)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18578.d0000644000175000017500000000007114141774365023620 0ustar matthiasmatthiasenum Foo { foo1 } enum Bar : Foo { bar } void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/derivedarray.d0000644000175000017500000000774114141774365024720 0ustar matthiasmatthias// PERMUTE_ARGS: class C {} class D : C {} void dynamicarrays() { C[] a; D[] b; const(C)[] c; const(D)[] d; immutable(C)[] e; immutable(D)[] f; static assert( __traits(compiles, a = a)); static assert(!__traits(compiles, a = b)); static assert(!__traits(compiles, a = c)); static assert(!__traits(compiles, a = d)); static assert(!__traits(compiles, a = e)); static assert(!__traits(compiles, a = f)); static assert(!__traits(compiles, b = a)); static assert( __traits(compiles, b = b)); static assert(!__traits(compiles, b = c)); static assert(!__traits(compiles, b = d)); static assert(!__traits(compiles, b = e)); static assert(!__traits(compiles, b = f)); static assert( __traits(compiles, c = a)); static assert( __traits(compiles, c = b)); static assert( __traits(compiles, c = c)); static assert( __traits(compiles, c = d)); static assert( __traits(compiles, c = e)); static assert( __traits(compiles, c = f)); static assert(!__traits(compiles, d = a)); static assert( __traits(compiles, d = b)); static assert(!__traits(compiles, d = c)); static assert( __traits(compiles, d = d)); static assert(!__traits(compiles, d = e)); static assert( __traits(compiles, d = f)); static assert(!__traits(compiles, e = a)); static assert(!__traits(compiles, e = b)); static assert(!__traits(compiles, e = c)); static assert(!__traits(compiles, e = d)); static assert( __traits(compiles, e = e)); static assert( __traits(compiles, e = f)); static assert(!__traits(compiles, f = a)); static assert(!__traits(compiles, f = b)); static assert(!__traits(compiles, f = c)); static assert(!__traits(compiles, f = d)); static assert(!__traits(compiles, f = e)); static assert( __traits(compiles, f = f)); } void statictodynamicarrays() { C[] a; D[] b; const(C)[] c; const(D)[] d; immutable(C)[] e; immutable(D)[] f; C[1] sa; D[1] sb; const(C)[1] sc = void; const(D)[1] sd = void; immutable(C)[1] se = void; immutable(D)[1] sf = void; static assert( __traits(compiles, a = sa)); static assert(!__traits(compiles, a = sb)); static assert(!__traits(compiles, a = sc)); static assert(!__traits(compiles, a = sd)); static assert(!__traits(compiles, a = se)); static assert(!__traits(compiles, a = sf)); static assert(!__traits(compiles, b = sa)); static assert( __traits(compiles, b = sb)); static assert(!__traits(compiles, b = sc)); static assert(!__traits(compiles, b = sd)); static assert(!__traits(compiles, b = se)); static assert(!__traits(compiles, b = sf)); static assert( __traits(compiles, c = sa)); static assert( __traits(compiles, c = sb)); static assert( __traits(compiles, c = sc)); static assert( __traits(compiles, c = sd)); static assert( __traits(compiles, c = se)); static assert( __traits(compiles, c = sf)); static assert(!__traits(compiles, d = sa)); static assert( __traits(compiles, d = sb)); static assert(!__traits(compiles, d = sc)); static assert( __traits(compiles, d = sd)); static assert(!__traits(compiles, d = se)); static assert( __traits(compiles, d = sf)); static assert(!__traits(compiles, e = sa)); static assert(!__traits(compiles, e = sb)); static assert(!__traits(compiles, e = sc)); static assert(!__traits(compiles, e = sd)); static assert( __traits(compiles, e = se)); static assert( __traits(compiles, e = sf)); static assert(!__traits(compiles, f = sa)); static assert(!__traits(compiles, f = sb)); static assert(!__traits(compiles, f = sc)); static assert(!__traits(compiles, f = sd)); static assert(!__traits(compiles, f = se)); static assert( __traits(compiles, f = sf)); } void staticarrays() { C[1] sa; D[1] sb; const(C)[1] sc = sa; const(D)[1] sd = sb; sa = sb; static assert(!__traits(compiles, sb = sa)); } void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice9663.d0000644000175000017500000000015614141774365023320 0ustar matthiasmatthias// REQUIRED_ARGS: -wi void main() { int[1] a; int[] b = [1]; a = 1; b[] = a; b = a; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b18489.d0000644000175000017500000000017214141774365023065 0ustar matthiasmatthias// REQUIRED_ARGS: -O -m64 import core.simd; double dot (double2 a) { return a.ptr[0] * a.ptr[1]; } void main () { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21501a.d0000644000175000017500000000103614141774365023737 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test21501b.d imports/test21501c.d // https://issues.dlang.org/show_bug.cgi?id=21501 module test21501a; import imports.test21501b; import imports.test21501c; alias Identity(alias T) = T; struct A { alias a = imports.test21501c.C; const int b = imports.test21501c.D; // fixed alias c = Identity!(mixin(q{imports.test21501c.C})); // fixed const int d = Identity!(mixin(q{imports.test21501c.D})); // fixed static assert(is(a == c) && is(a == int)); static assert(b == d && b == 1); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8041.d0000644000175000017500000000030214141774365023515 0ustar matthiasmatthias// PERMUTE_ARGS: struct Foo { } void main() { static Foo sf; // ok __gshared Foo gf; // was: Error: non-constant expression gf = 0 __gshared int[1][1] arr; // dup: Issue 6089 } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6999.d0000644000175000017500000000050614141774365023547 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=6999: inout in front of return type struct A { inout: inout(int) foo() { return 0; } } struct B { inout { inout(int) foo() { return 0; } } } struct C { inout inout(int) foo() { return 0; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix21647.d0000644000175000017500000000114614141774365023422 0ustar matthiasmatthias/* REQUIRED_ARGS: -preview=rvaluerefparam TEST_OUTPUT: --- cast(void)0 cast(void)0 void cast(void)0 cast(void)0 cast(void)0 void --- */ // https://issues.dlang.org/show_bug.cgi?id=21647 void foo() { return cast(void)1; } void main(){} alias V = void; void test1() { pragma(msg, foo()); } void test2() { pragma(msg, main()); } void test3() { pragma(msg, V); } pragma(msg, foo()); pragma(msg, main()); pragma(msg, V); /*************************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8255 struct G {} struct F(T) { void f(ref T) {} } pragma(msg, F!G().f(G.init)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9369.d0000644000175000017500000000002314141774365023533 0ustar matthiasmatthiasDdoc --- a=1; --- ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_TemplateDeclaration.d0000644000175000017500000001456014141774365027173 0ustar matthiasmatthias/* REQUIRED_ARGS: -HC -c -o- PERMUTE_ARGS: TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif typedef uint$?:32=32|64=64$_t size_t; struct Outer final { int32_t a; struct Member final { typedef int32_t Nested; Member() { } }; Outer() : a() { } Outer(int32_t a) : a(a) {} }; enum : int32_t { SomeOtherLength = 1 }; struct ActualBuffer final { ActualBuffer() { } }; template struct A final { // Ignoring var x alignment 0 T x; // Ignoring var Enum alignment 0 enum : int32_t { Enum = 42 }; // Ignoring var GsharedNum alignment 0 static int32_t GsharedNum; // Ignoring var MemNum alignment 0 const int32_t MemNum; void foo(); A() { } }; template struct NotInstantiated final { // Ignoring var noInit alignment 0 // Ignoring var missingSem alignment 0 NotInstantiated() { } }; struct B final { A x; B() : x() { } B(A x) : x(x) {} }; template struct Foo final { // Ignoring var val alignment 0 T val; Foo() { } }; template struct Bar final { // Ignoring var v alignment 0 Foo v; Bar() { } }; template struct Array final { typedef Array This; typedef typeof(1 + 2) Int; typedef typeof(T::a) IC; Array(size_t dim); ~Array(); void get() const; template bool opCast() const; // Ignoring var i alignment 0 typename T::Member i; // Ignoring var j alignment 0 typename Outer::Member::Nested j; void visit(typename T::Member::Nested i); Array() { } }; template extern T foo(U u); extern A > aaint; template class Parent { // Ignoring var parentMember alignment 0 public: T parentMember; void parentFinal(); virtual void parentVirtual(); }; template class Child final : public Parent { // Ignoring var childMember alignment 0 public: T childMember; void parentVirtual(); T childFinal(); }; extern void withDefTempl(A a = A(2, 13)); template extern void withDefTempl2(A a = static_cast>(A(2))); class ChildInt : public Parent { }; struct HasMixins final { void foo(int32_t t); HasMixins() { } }; template struct HasMixinsTemplate final { void foo(T t); HasMixinsTemplate() { } }; extern HasMixinsTemplate hmti; template struct NotAA final { // Ignoring var length alignment 0 enum : int32_t { length = 12 }; // Ignoring var buffer alignment 0 T buffer[length]; // Ignoring var otherBuffer alignment 0 T otherBuffer[SomeOtherLength]; // Ignoring var calcBuffer alignment 0 T calcBuffer[foo(1)]; NotAA() { } }; template struct BufferTmpl final { // Ignoring var buffer alignment 0 Buffer buffer; // Ignoring var buffer2 alignment 0 Buffer buffer2; BufferTmpl() { } }; struct ImportedBuffer final { typedef ActualBuffer Buffer; ActualBuffer buffer2; ImportedBuffer() { } }; --- */ extern (C++) struct A(T) { T x; enum Enum = 42; __gshared GsharedNum = 43; immutable MemNum = 13; void foo() {} } // Invalid declarations accepted because it's not instantiated extern (C++) struct NotInstantiated(T) { enum T noInit; enum missingSem = T.init; } extern (C++) struct B { A!int x; } // https://issues.dlang.org/show_bug.cgi?id=20604 extern(C++) { struct Foo (T) { T val; } struct Bar (T) { Foo!T v; } } extern (C++) struct Array(T) { alias This = typeof(this); alias Int = typeof(1 + 2); alias IC = typeof(T.a); this(size_t dim) pure nothrow {} @disable this(this); ~this() {} void get() const {} bool opCast(T)() const pure nothrow @nogc @safe if (is(T == bool)) { return str.ptr !is null; } T.Member i; Outer.Member.Nested j; void visit(T.Member.Nested i) {} } struct Outer { int a; static struct Member { alias Nested = int; } } // alias AO = Array!Outer; extern(C++) T foo(T, U)(U u) { return T.init; } extern(C++) __gshared A!(A!int) aaint; extern(C++) class Parent(T) { T parentMember; final void parentFinal() {} void parentVirtual() {} } extern(C++) final class Child(T) : Parent!T { T childMember; override void parentVirtual() {} T childFinal() { return T.init; } } extern(C++) void withDefTempl(A!int a = A!int(2)) {} extern(C++) void withDefTempl2(T)(A!T a = A!T(2)) {} extern(C++) alias withDefTempl2Inst = withDefTempl2!int; extern(C++) class ChildInt : Parent!int {} /****************************************************** * Mixins */ extern (C++): mixin template MixinA(T) { void foo(T t) {} } mixin template MixinB() {} struct HasMixins { mixin MixinA!int; mixin MixinB; } struct HasMixinsTemplate(T) { mixin MixinA!T; mixin MixinB; } __gshared HasMixinsTemplate!bool hmti; /// Declarations that look like associative arrays extern(D) enum SomeOtherLength = 1; struct NotAA(T) { private: enum length = 12; public: T[length] buffer; T[SomeOtherLength] otherBuffer; T[foo(1)] calcBuffer; } // Same name but hidden by the template paramter extern (D) struct Buffer {} extern (D) struct ActualBuffer {} struct BufferTmpl(Buffer) { Buffer buffer; mixin BufferMixin!(); } struct ImportedBuffer { alias Buffer = ActualBuffer; mixin BufferMixin!(); } mixin template BufferMixin() { Buffer buffer2; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/sharedopt.d0000644000175000017500000000033714141774365024222 0ustar matthiasmatthias// REQUIRED_ARGS: -O void _d_critical_term() { for (auto p = head; p; p = p.next) destroyMutex(p.i); } shared S* head; struct S { S* next; int i; } void destroyMutex(int i); struct Mutex { int i; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8513.d0000644000175000017500000000121114141774365023521 0ustar matthiasmatthiasinterface I_Foo { void i_outer(); } class C_Foo { void c_outer() { } } class Bar { interface I_Foo { void i_inner(); } class C_Foo { void c_inner() { } } class Impl1 : C_Foo, I_Foo { override void i_inner() { } override void c_inner() { } } class Impl2 : C_Foo, .I_Foo { override void i_outer() { } override void c_inner() { } } class Impl3 : .C_Foo, I_Foo { override void i_inner() { } override void c_outer() { } } class Impl4 : .C_Foo, .I_Foo { override void i_outer() { } override void c_outer() { } } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix22252.c0000644000175000017500000000035714141774365023415 0ustar matthiasmatthias /* Test conversion of parameter types: * array of T => pointer to T * function => pointer to function */ int test1(int a[]) { return *a; } int test2(int a[3]) { return *a; } int test3(int fp()) { return (*fp)(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9680.sh0000755000175000017500000000122514141774365023726 0ustar matthiasmatthias#!/usr/bin/env bash if [ "${OS}" == "windows" ]; then kinds=( main winmain dllmain ) else kinds=( main ) fi for kind in "${kinds[@]}" do file_name=${TEST_NAME}${kind} src_file=${EXTRA_FILES}/${file_name}.d expect_file=${EXTRA_FILES}/${file_name}.out output_file=${RESULTS_TEST_DIR}/${file_name}.log rm_retry ${output_file}{,.2} $DMD -m${MODEL} -v -o- ${src_file} > ${output_file} grep "^entry ${kind}" ${output_file} > ${output_file}.2 if [ `wc -c ${output_file}.2 | while read a b; do echo $a; done` -eq 0 ]; then echo "Error: not found expected entry point '${kind}' in ${src_file}" exit 1; fi rm_retry ${output_file}{,.2} done ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc14383.d0000644000175000017500000000036114141774365023542 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** * Module docs. */ module ddoc14383; /// Ddoc'd unittest unittest { int iShouldAppearInTheDocs; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19315.d0000644000175000017500000000062414141774365023612 0ustar matthiasmatthias//https://issues.dlang.org/show_bug.cgi?id=19315 void main() { #line 100 "file.d" enum code = q{ #line 10 }; static assert(__LINE__ == 103); static assert(__FILE__ == "file.d"); #line 200 "file2.d" enum code2 = q{ q{ #line 5 } #line 9 "foo.d" }; static assert(__LINE__ == 206); static assert(__FILE__ == "file2.d"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18251.d0000644000175000017500000000054014141774365023605 0ustar matthiasmatthias// REQUIRED_ARGS: -unittest -de auto test18251(T)(T t) if (!__traits(isDeprecated, T)) { return T.init; } unittest { auto b = test18251(2); } deprecated auto test18251(T)(T t) // deprecated storage class got lost when expanding. if (__traits(isDeprecated, T)) { return T.init; } deprecated unittest { auto b = test18251(2 + 2i); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc7656.d0000644000175000017500000000061714141774365023473 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc7656; /** -------- int x; // This is a $ comment (and here is some int y; // more information about that comment) -------- */ void main() { } /** (Regression check) Example: ---- assert(add(1, 1) == 2); ---- */ int add(int a, int b) { return a + b; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19936.d0000644000175000017500000000051314141774365023620 0ustar matthiasmatthias// REQUIRED_ARGS: -de struct Bla { deprecated("bla") int get() { return 5; } alias get this; } void main() { Bla[] blaArray; // ~= should not try to call `.get`, because there's no indication that // `blaArray` has any kind of opAppendAssign related overload in the first place. blaArray ~= Bla(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21659.d0000644000175000017500000000043614141774365023617 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21659 // Compiler-recognized ident enum __c_ulonglong : ulong; private union EndianSwapper(T) { T value; ubyte[T.sizeof] array; static assert(T.sizeof == ulong.sizeof); } void main () { EndianSwapper!(__c_ulonglong) val; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test14198.d0000644000175000017500000000022114141774365023607 0ustar matthiasmatthias/* REQUIRED_ARGS: runnable/extra-files/test14198.d -Irunnable/extra-files PERMUTE_ARGS: -version=bug14198 LINK: */ module compilable.test14198; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16107.d0000644000175000017500000000033114141774365023601 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=16107 bool check() { bool result = false; result |= false; if (result) goto ret; result |= false; if (result) {} ret: return true; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/mixintempl.d0000644000175000017500000000045414141774365024417 0ustar matthiasmatthias struct TypeObj { alias This = typeof(this); mixin template MixinTempl() { int value; } } ref TypeObj Obj() { static TypeObj a; return a; } void func() { mixin Obj.This.MixinTempl; // ok mixin Obj.MixinTempl; // fixed: "MixinTempl!()" is not defined } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6089.d0000644000175000017500000000007414141774365023535 0ustar matthiasmatthias// PERMUTE_ARGS: void main() { extern int[1][1] foo; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/json_nosource.sh0000755000175000017500000000017314141774365025307 0ustar matthiasmatthias#!/usr/bin/env bash $DMD -Xi=compilerInfo -Xf=${OUTPUT_BASE}.out ./compilable/extra-files/json-postscript.sh json_nosource ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19833.d0000644000175000017500000000062014141774365023613 0ustar matthiasmatthiasstruct S { template Temp(int x) { enum xxx = x; } } alias TT = __traits(getMember, S, "Temp"); enum x = TT!2.xxx; static assert(x == 2); class A { mixin temp!("uint"); mixin temp!("float"); mixin template temp(string source) { private enum inner(string s) = s; } } class B { alias member = __traits(getMember, A, __traits(allMembers, A)[0]); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test1878a.d0000644000175000017500000000040314141774365023673 0ustar matthiasmatthiasvoid main() { ubyte from, to; foreach(i; from..to) { static assert(is(typeof(i) == ubyte)); } foreach(i; 'a'..'l') { static assert(is(typeof(i) == char)); } foreach(i; 'א' .. 'ת') { static assert(is(typeof(i) == wchar)); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/deprecate12979a.d0000644000175000017500000000041514141774365024737 0ustar matthiasmatthias// REQUIRED_ARGS: -dw // PERMUTE_ARGS: /* DISABLED: LDC_not_x86 TEST_OUTPUT: --- compilable/deprecate12979a.d(13): Deprecation: `asm` statement is assumed to throw - mark it with `nothrow` if it does not --- */ void foo() nothrow { asm { ret; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice14075.d0000644000175000017500000000040614141774365023367 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: struct Foo { auto opAssign(this X)(ref typeof(this)); auto opAssign(this X, V)(ref V) if (!is(V == typeof(this))); } void test() { Foo src; const(Foo) target; static if (is(typeof(target = src))) {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc10366.d0000644000175000017500000000046714141774365023546 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /// struct S(T) { /// void method() {} public { /// struct Nested { /// void nestedMethod() {} } } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15802.d0000644000175000017500000000017614141774365023611 0ustar matthiasmatthiasextern(C++) { template Foo(T) { static int boo(); } } void main() { string s = Foo!(int).boo.mangleof; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue20705.d0000644000175000017500000000045614141774365023761 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=rvaluerefparam struct Foo { int[] a; } void bar (T) (const ref T arg) {} T foo (T) (ref T arg) { return arg; } void goo()(ref long x) { x = 1; } void main () { bar(Foo([42])); auto x = foo(Foo([42])); int y; static assert(!__traits(compiles, goo(y))); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9672.d0000644000175000017500000000022414141774365023533 0ustar matthiasmatthias// EXTRA_FILES: imports/test9672a.d module test9672; // node import imports.test9672a; // interpret mixin template ForwardCtor() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test22388.d0000644000175000017500000000072514141774365023620 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22388 void setTimer(void delegate()) @system; void setTimer(void delegate() @safe) @safe; void setTimer2(void delegate() @safe) @safe; void setTimer2(void delegate()) @system; void main() @safe { setTimer(() => assert(false)); alias lambda = () => assert(false); setTimer(lambda); // Reversed order setTimer2(() => assert(false)); alias lambda2 = () => assert(false); setTimer2(lambda2); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue21882.d0000644000175000017500000000046014141774365023763 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=dip1021 // https://issues.dlang.org/show_bug.cgi?id=21882 bool buildPath() { struct ByCodeUnitImpl { auto opIndex(size_t) { } } return isRandomAccessRange!ByCodeUnitImpl; } enum isRandomAccessRange(R) = is(typeof(lvalueOf!R[1])); ref T lvalueOf(T)(); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix17123.d0000644000175000017500000000025714141774365023416 0ustar matthiasmatthias/* PERMUTE_ARGS: https://issues.dlang.org/show_bug.cgi?id=17123 */ void test() { char[256] buffer; char[] delegate() read = () { return buffer[]; }; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/needsmod.d0000644000175000017500000000024714141774365024027 0ustar matthiasmatthias// ARG_SETS: -i // ARG_SETS: -i=. // ARG_SETS: -i=imports // ARG_SETS: -i=imports.foofunc // PERMUTE_ARGS: // LINK: import imports.foofunc; void main() { foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/pr9383.d0000644000175000017500000000061714141774365023202 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=dip1000 // https://github.com/dlang/dmd/pull/9383 void test() @safe { int[1] a = [1]; cartesianProduct(a[]); } auto cartesianProduct(RR...)(RR ranges) { static struct Result { RR current; void popFront() scope @safe { foreach (ref r; current) { } } } return Result(ranges); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/verrors_spec.d0000644000175000017500000000040414141774365024740 0ustar matthiasmatthias/* PERMUTE_ARGS: REQUIRED_ARGS: -verrors=spec TEST_OUTPUT: --- (spec:1) compilable/verrors_spec.d(13): Error: cannot implicitly convert expression `& i` of type `int*` to `int` --- */ void foo(int i) { int p; bool b = __traits(compiles, {p = &i;}); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15225.d0000644000175000017500000000037514141774365023611 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=15225 alias foo = (int x) => x + 1; alias foo = (string x) => x ~ x; alias foo = (float x) => x - x; static assert( foo(1) == 2 ); static assert( foo("a") == "aa"); static assert(foo(2.0f) == 0.0f); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc6.d0000644000175000017500000000054514141774365023231 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** * */ struct MyStruct(T) { static if( true ) { void MyStruct() {} } } void main() { } /+ 23 C:\code\d\bugs>dmd -D -o- 148_1.d 148_1.d(6): Error: static if conditional cannot be at global scope +/ ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21830.d0000644000175000017500000000056714141774365023613 0ustar matthiasmatthias// REQUIRED_ARGS: -de -unittest deprecated struct OldS21830 { } struct NewS21830 { } static if (1) { auto test21830(T)(T t) if (is(T == NewS21830)) { return T.init; } } deprecated auto test21830(T)(T t) if (is(T == OldS21830)) { return T.init; } unittest { auto b = test21830(NewS21830()); // error here about using test21830!OldS21830 } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/previewall.d0000644000175000017500000000030314141774365024374 0ustar matthiasmatthias// ARG_SETS: -preview=all // ARG_SETS: -transition=all // ARG_SETS: -revert=all import core.stdc.stdio; void main (string[] args) { if (args.length == 42) printf("Hello World\n"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testcov1.d0000644000175000017500000000042514141774365023777 0ustar matthiasmatthias// COMPILED_IMPORTS: imports/testcov1a.d imports/testcov1b.d // PERMUTE_ARGS: // REQUIRED_ARGS: -cov -Icompilable/imports import core.stdc.string; import testcov1a; version(D_Coverage) { // Good } else { static assert(0, "Missing 'D_Coverage' version identifier"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test7815.d0000644000175000017500000000305214141774365023532 0ustar matthiasmatthias// REQUIRED_ARGS: -o- mixin template Helpers() { static if (is(Flags!Move)) { Flags!Move flags; } else { pragma(msg, "X: ", __traits(derivedMembers, Flags!Move)); } } template Flags(T) { mixin({ int defs = 1; foreach (name; __traits(derivedMembers, Move)) { defs++; } if (defs) { return "struct Flags { bool x; }"; } else { return ""; } }()); } struct Move { int a; mixin Helpers!(); } enum a7815 = Move.init.flags; /+ This originally was an invalid case: When the Move struct member is analyzed: 1. mixin Helpers!() is instantiated. 2. In Helpers!(), static if and its condition is(Flags!Move)) evaluated. 3. In Flags!Move, string mixin evaluates and CTFE lambda. 4. __traits(derivedMembers, Move) tries to see the member of Move. 4a. mixin Helpers!() member is analyzed. 4b. `static if (is(Flags!Move))` in Helpers!() is evaluated 4c. The Flags!Move instantiation is already in progress, so it cannot be resolved. 4d. `static if` fails because Flags!Move cannot be determined as a type. 5. __traits(derivedMembers, Move) returns a 1-length tuple("a"). 6. The lambda in Flags!Move returns a string "struct Flags {...}", then Flags!Move is instantiated to a new struct Flags. 7. Finally Move struct does not have flags member, then the `enum a7815` definition will fail in its initializer. Now, static if will behave like a string mixin: it is invisible during its own expansion. +/ ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc4899.d0000644000175000017500000000102314141774365023471 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o- /* TEST_OUTPUT: --- compilable/ddoc4899.d(18): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses. compilable/ddoc4899.d(19): Warning: Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses. --- */ /++ (See accompanying file LICENSE_1_0.txt or copy at foo:) +/ module d; /** ( */ int a; /** ) */ int b; void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9434.d0000644000175000017500000000034414141774365023532 0ustar matthiasmatthias// EXTRA_FILES: test9435.d import test9435;//semantic; template Visitors() { mixin Semantic!(typeof(this)); } class Node { mixin Visitors; } class Expression : Node { } class BinaryExp(TokenType op) : Expression { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15668.d0000644000175000017500000000016414141774365023620 0ustar matthiasmatthiasvoid foo ( int line = __LINE__ ) ( string msg = "" ) { static assert (line == 8); } void main() { foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9274.d0000644000175000017500000000077414141774365023543 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=9274 struct S { float[] arr; alias arr this; } static assert(!is(S == float[])); // ok static assert(!is(S == T[], T)); // fails static assert(is(S : float[])); static assert(is(S : T[], T)); //https://issues.dlang.org/show_bug.cgi?id=9274 struct A(T) {} struct B { A!int _a; alias _a this; } static assert(!is(B == A!int)); // OK static assert(!is(B == A!X, X)); // assertion fails static assert(is(B : A!int)); static assert(is(B : A!X, X)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test4375.d0000644000175000017500000001653314141774365023540 0ustar matthiasmatthias// REQUIRED_ARGS: -unittest // https://issues.dlang.org/show_bug.cgi?id=4375 // disallow dangling else void main() { if (true) { if (false) { assert(1); } else { assert(2); } } if (true) { if (false) assert(7); } else assert(8); if (true) { if (false) assert(9); else assert(10); } { if (true) assert(11); else assert(12); } { label1: if (true) assert(13); else assert(14); } if (true) foreach (i; 0 .. 5) { if (true) assert(17); else assert(18); } if (true) { foreach (i; 0 .. 5) if (true) assert(18.1); } else assert(18.2); if (true) assert(19); else assert(20); if (true) assert(21); else if (false) assert(22); else assert(23); version (A) { if (true) assert(26); } else assert(27); version (A) { if (true) assert(28); else assert(29); } version (A) assert(30); else version (B) assert(31); else assert(32); static if (true) { static if (true) assert(35); } else assert(36); static if (true) { static if (true) assert(37); else assert(38); } static if (true) assert(39); else static if (true) assert(40); else assert(41); switch (4) { case 0: if (true) assert(42); else assert(43); break; case 1: .. case 5: if (true) assert(44); else assert(45); break; default: if (true) assert(46); else assert(47); break; } // (o_O) switch (1) default: if (true) assert(113); else assert(114); // (o_O) final switch (1) case 1: if (true) assert(117); else assert(118); mixin(q{ if (true) assert(56); else assert(57); }); while (false) if (true) assert(66); else assert(67); if (true) while (false) assert(68); else assert(69); do if (true) assert(72); else assert(73); while (false); if (true) do if (true) assert(74); else assert(75); while (false); for ( if (true) // (o_O) assert(78); else assert(79); false; false ) if (true) assert(80); else assert(81); if (true) for (if (true) assert(84); else assert(85); false;) assert(86); if (true) if (true) if (true) if (true) if (true) assert(87); auto x = new C; if (true) while (false) for (;;) scope (exit) synchronized (x) assert(88); else assert(89); if (true) while (false) for (;;) { scope (exit) synchronized (x) if (true) assert(90); else assert(89); } if (true) while (false) for (;;) scope (exit) synchronized (x) if (true) assert(90); else assert(89); else assert(12); with (x) if (false) assert(92); else assert(93); try if (true) assert(94); else assert(95); catch (Exception e) if (true) assert(96); else assert(97); finally if (true) assert(98); else assert(99); if (true) try if (true) assert(100); else assert(101); finally assert(102); if (true) try assert(109); catch(Exception e) if (true) assert(110); else assert(112); finally assert(111); static struct F { static if (true) int x; else int y; static if (true) { static if (false) int z; } else int w; static if (true) int t; else static if (false) int u; else int v; } if (true) if (true) assert(113); else assert(114); else assert(115); static if (true) static if (true) assert(116); else assert(117); else assert(118); } unittest { if (true) assert(50); else assert(51); } class C { invariant() { if (true) assert(58); else assert(59); } int f() in { if (true) assert(60); else assert(61); } out(res) { if (true) assert(62); else assert(63); } do { if (true) assert(64); else assert(65); return 0; } } enum q = q{ if(true) if(true) assert(54.1); else assert(55.2); }; static if (true) struct F0 {} else static if (true) struct F1 {} else struct F2 {} static if (true) { static if (false) struct F3 {} } else struct F4 {} version(A) { version(B) struct F5 {} } else struct F6 {} version(A) { version(B) struct F5a {} else struct F5b {} } version (C) struct F5c {} else struct F5d {} struct F7 { static if (true) int x; else float x; private: static if (true) int y; else float y; } template F8() { static if (true) int x; else float x; } static if (true) align(1) static if (false) struct F9 {} static if (true) align(1) { extern(C) pure static if (false) void F10(){} else void F11(){} } void f() { int[] x; static if (5 > 0) version (Y) scope (failure) foreach (i, e; x) while (i > 20) with (e) if (e < 0) synchronized(e) assert(1); else assert(2); else x = null; else x = null; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue20362.d0000644000175000017500000000023514141774365023753 0ustar matthiasmatthiasvoid main() { string str; stringify((chars) {str ~= chars; }); } void stringify(scope void delegate(scope const char[]) sink) { sink("oops"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17793.d0000644000175000017500000000033514141774365023621 0ustar matthiasmatthias// LDC: don't enforce -mcpu // required_args: -mcpu=avx2 import core.simd; static if (__traits(compiles, double4)) { double4 foo(); void test(double[4]); void main() { test(foo().array); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16002.d0000644000175000017500000000203514141774365023576 0ustar matthiasmatthias// EXTRA_FILES: imports/plainpackage/plainmodule.d imports/pkgmodule/package.d imports/pkgmodule/plainmodule.d module test.compilable.test16002; import imports.plainpackage.plainmodule; import imports.pkgmodule.plainmodule; struct MyStruct; alias a = imports.plainpackage; alias b = imports.pkgmodule.plainmodule; static assert(is(imports.plainpackage == package)); static assert(is(a == package)); static assert(!is(imports.plainpackage.plainmodule == package)); static assert(!is(b == package)); static assert(is(imports.pkgmodule == package)); static assert(!is(MyStruct == package)); static assert(!is(imports.plainpackage == module)); static assert(!is(a == module)); static assert(is(imports.plainpackage.plainmodule == module)); static assert(is(b == module)); // This is supposed to work even though we haven't directly imported imports.pkgmodule. static assert(is(imports.pkgmodule == module)); static assert(!is(MyStruct == module)); static assert(!is(imports.nonexistent == package)); static assert(!is(imports.nonexistent == module)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testsctreturn.d0000644000175000017500000000054214141774365025160 0ustar matthiasmatthias/* REQUIRED_ARGS: -preview=dip1000 * This case winds up calling buildScopeRef() with stc having only STC.return_ set. */ struct PackedPtrImpl(size_t bits) { pure nothrow: this(inout(size_t)* ptr) inout @safe @nogc { origin = ptr; } size_t* origin; } void test() { size_t* p; const ppi = const(PackedPtrImpl!(3))(p); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test10056.d0000644000175000017500000000242714141774365023606 0ustar matthiasmatthiasvoid main() { alias Zoo = Foo10056!(false, false, 1); } struct Foo10056(bool S, bool L, size_t N) { string bar() { Appender10056!(string) w; char[] buf; put10056(w, buf); return ""; } public bool opEquals(T)(T other) //const //If you add const, also fails to compile with 2.062. { alias Foo10056!(typeof(this), T, "CMP") P; return false; } } template Foo10056(T, U, string OP) { static if (T.ISEMPTY && U.ISEMPTY) enum bool S = false; else enum bool S = false; alias Foo10056 = Foo10056!(false, false, 0); } /**********************************************/ void put10056(R, E)(ref R r, E e) { static if (is(typeof(r.put(e)))) { r.put(e); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } struct Appender10056(A : T[], T) { private template canPutItem(U) { enum bool canPutItem = is(U : T); } private template canPutRange(R) { enum bool canPutRange = is(typeof(Appender10056.init.put(R.init[0]))); } void put(U)(U item) if (canPutItem!U) { char[T.sizeof == 1 ? 4 : 2] encoded; put(encoded[]); } void put(R)(R items) if (canPutRange!R) { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix22180.d0000644000175000017500000000020014141774365023401 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22180 align(8) { int x; } //pragma(msg, x.alignof); static assert(x.alignof == 8); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_names.d0000644000175000017500000001362614141774365024357 0ustar matthiasmatthias/+ REQUIRED_ARGS: -HC -c -o- PERMUTE_ARGS: TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif struct Outer final { static Outer* outerPtr; static Middle::Inner* outerToInnerPtr; static Middle::InnerTmpl* outerToInnerTmplPtr; struct Middle final { static Outer* middleOuterPtr; static Middle* middlePtr; static Inner* middleInnerPtr; struct Inner final { static Outer* innerOuterPtr; static Middle* innerPtr; static Inner* innerInnerPtr; static InnerTmpl* innerInnerTmplPtr; Inner() { } }; template struct InnerTmpl final { // Ignoring var innerTmplOuterPtr alignment 0 static Outer* innerTmplOuterPtr; // Ignoring var innerTmplPtr alignment 0 static Middle* innerTmplPtr; // Ignoring var innerTmplInnerPtr alignment 0 static Inner* innerTmplInnerPtr; // Ignoring var innerTmplInnerTmplPtr alignment 0 static InnerTmpl* innerTmplInnerTmplPtr; InnerTmpl() { } }; Middle() { } }; template struct MiddleTmpl final { // Ignoring var middleTmplPtr alignment 0 static MiddleTmpl* middleTmplPtr; // Ignoring var middleTmplInnerTmplPtr alignment 0 static MiddleTmpl* middleTmplInnerTmplPtr; struct Inner final { // Ignoring var ptr alignment 0 static Inner* ptr; // Ignoring var ptr2 alignment 0 static MiddleTmpl* ptr2; Inner() { } }; template struct InnerTmpl final { // Ignoring var innerTmplPtr alignment 0 static InnerTmpl* innerTmplPtr; // Ignoring var innerTmplPtrDiff alignment 0 static InnerTmpl* innerTmplPtrDiff; // Ignoring var middleTmplInnerTmplPtr alignment 0 static MiddleTmpl* middleTmplInnerTmplPtr; // Ignoring var a alignment 0 static T a; static U bar(); InnerTmpl() { } }; MiddleTmpl() { } }; Outer() { } }; --- +/ extern(C++): struct Outer { __gshared Outer* outerPtr; __gshared Middle.Inner* outerToInnerPtr; __gshared Middle.InnerTmpl!int* outerToInnerTmplPtr; static struct Middle { __gshared Outer* middleOuterPtr; __gshared Middle* middlePtr; __gshared Inner* middleInnerPtr; static struct Inner { __gshared Outer* innerOuterPtr; __gshared Middle* innerPtr; __gshared Inner* innerInnerPtr; __gshared InnerTmpl!int* innerInnerTmplPtr; } static struct InnerTmpl(U) { __gshared Outer* innerTmplOuterPtr; __gshared Middle* innerTmplPtr; __gshared Inner* innerTmplInnerPtr; __gshared InnerTmpl* innerTmplInnerTmplPtr; } } static struct MiddleTmpl(T) { __gshared MiddleTmpl!T* middleTmplPtr; __gshared MiddleTmpl!T.Inner* middleTmplInnerTmplPtr; static struct Inner { __gshared Inner* ptr; __gshared MiddleTmpl!T.Inner* ptr2; } static struct InnerTmpl(U) { __gshared InnerTmpl* innerTmplPtr; __gshared InnerTmpl!char* innerTmplPtrDiff; __gshared MiddleTmpl!T.Inner* middleTmplInnerTmplPtr; __gshared T a; static U bar() { return U.init; } } } } /+ TEST_OUTPUT: --- extern Outer::Middle::Inner inner; extern Outer::Middle::InnerTmpl innerTmpl; extern Outer::MiddleTmpl::Inner middleTmpl; extern Outer::MiddleTmpl::InnerTmpl bothTmpl; --- +/ __gshared Outer.Middle.Inner inner; __gshared Outer.Middle.InnerTmpl!int innerTmpl; __gshared Outer.MiddleTmpl!int.Inner middleTmpl; __gshared Outer.MiddleTmpl!int.InnerTmpl!double bothTmpl; /+ TEST_OUTPUT: --- typedef Outer::MiddleTmpl::InnerTmpl FullTmplInst; template using FullTmpl = Outer::MiddleTmpl::InnerTmpl; --- +/ alias FullTmplInst = Outer.MiddleTmpl!int.InnerTmpl!double; alias FullTmpl = Outer.MiddleTmpl!int.InnerTmpl; /+ TEST_OUTPUT: --- extern void dotId(int32_t a = Outer::MiddleTmpl::InnerTmpl::a); --- +/ void dotId( int a = Outer.MiddleTmpl!int.InnerTmpl!double.a ) {} /+ TEST_OUTPUT: --- extern void castExp(double a = (double) Outer::MiddleTmpl::InnerTmpl::a); --- +/ void castExp( double a = Outer.MiddleTmpl!int.InnerTmpl!double.a ) {} /+ TEST_OUTPUT: --- extern void structLit(Outer::MiddleTmpl::InnerTmpl a = Outer::MiddleTmpl::InnerTmpl()); --- +/ void structLit( Outer.MiddleTmpl!int.InnerTmpl!double a = Outer.MiddleTmpl!int.InnerTmpl!double() ) {} /+ TEST_OUTPUT: --- extern void callExp(double a = Outer::MiddleTmpl::InnerTmpl::bar()); --- +/ void callExp( double a = Outer.MiddleTmpl!int.InnerTmpl!double.bar() ) {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/union_initialization.d0000644000175000017500000000103414141774365026463 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20068 union B { int i; int* p; @safe this(int* p) { // Error: cannot access pointers in @safe code that overlap other fields this.p = p; } } /**************************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21229 struct NeedsInit { int var; @disable this(); } union Union { NeedsInit ni; } union Proxy { Union union_; } struct S { Union union_; Proxy proxy; this(NeedsInit arg) { union_.ni = arg; proxy.union_.ni = arg; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19574.d0000644000175000017500000000036014141774365023616 0ustar matthiasmatthias static assert( Foo(10).bar.value == 10 ); extern(C++, "ns") { struct Foo { Bar!Foo bar; this( int v ) { bar.value = v; } } } extern(C++, "ns") { struct Bar(T) { int value; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc8739.d0000644000175000017500000000044414141774365023474 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc8739; /// void delegate(int a) dg; /// void delegate(int b) dg2; /// void delegate(int c)[] dg3; /// void delegate(int d)* dg4; void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21850.d0000644000175000017500000000107114141774365023604 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21850 struct Strukt2 { this(int* _block) { } } struct Strukt { int* block; Strukt2 foo() { return Strukt2(null); } alias foo this; } bool wrapper(T)(ref T a, ref T b) { return doesPointTo(a, b); } void johan() pure { Strukt a; Strukt b; assert(wrapper(a, b)); // error wrapper is not pure assert(doesPointTo(a, b)); // fine } bool doesPointTo(S, T)(S , T) { return false; } bool doesPointTo(S)(shared S) { return false; } bool mayPointTo(){ return false; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/checkimports3.d0000644000175000017500000000035214141774365025004 0ustar matthiasmatthias/* REQUIRED_ARGS: -de EXTRA_FILES: imports/checkimports3a.d imports/checkimports3b.d imports/checkimports3c.d */ import imports.checkimports3a; import imports.checkimports3b; import imports.checkimports3c; void test() { foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8631.d0000644000175000017500000000043014141774365023524 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -de class B { int foo() immutable { return 2; } int foo() const { return 2; } } class D : B { override int foo() immutable { return 2; } int foo() const shared { return 2; } override int foo() const { return 2; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test13582b.d0000644000175000017500000000031614141774365023752 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/test13582.d module test13582b; deprecated void foo() { import imports.test13582; } deprecated struct S { import imports.test13582; } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue19724.sh0000755000175000017500000000242114141774365024156 0ustar matthiasmatthias#! /usr/bin/env bash if [[ $OS != linux ]]; then exit 0; fi TEST_DIR=${OUTPUT_BASE} # create two libraries with the first depending on the second # so that if they're given the wrong order on the commandline, # linking would ordinarily fail D_LIBFILE1=$TEST_DIR/first.d D_LIBFILE2=$TEST_DIR/second.d D_LIB1=$TEST_DIR/libfirst.a D_LIB2=$TEST_DIR/libsecond.a # call from D D_FILE=$TEST_DIR/test.d APP=$TEST_DIR/test mkdir -p $TEST_DIR cat >$D_LIBFILE1 <$D_LIBFILE2 <$D_FILE <loc; int cmp; - if (e1->op == TOKnull && e2->op == TOKnull) + if (e1->op == TOKnull || e2->op == TOKnull) { - cmp = 1; + cmp = (e1->op == TOKnull && e2->op == TOKnull) ? 1 : 0; } else if (e1->op == TOKsymoff && e2->op == TOKsymoff) { */ bool isNull(string str) { return str is null; } const bool test = isNull("hello!"); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/depmsg.d0000644000175000017500000000342314141774365023507 0ustar matthiasmatthias/* REQUIRED_ARGS: -dw TEST_OUTPUT: --- compilable/depmsg.d(39): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message! compilable/depmsg.d(39): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message! compilable/depmsg.d(40): Deprecation: class `depmsg.main.Inner.B` is deprecated - With message! compilable/depmsg.d(40): Deprecation: class `depmsg.main.Inner.B` is deprecated - With message! compilable/depmsg.d(41): Deprecation: interface `depmsg.main.Inner.C` is deprecated - With message! compilable/depmsg.d(41): Deprecation: interface `depmsg.main.Inner.C` is deprecated - With message! compilable/depmsg.d(42): Deprecation: union `depmsg.main.Inner.D` is deprecated - With message! compilable/depmsg.d(42): Deprecation: union `depmsg.main.Inner.D` is deprecated - With message! compilable/depmsg.d(43): Deprecation: enum `depmsg.main.Inner.E` is deprecated - With message! compilable/depmsg.d(43): Deprecation: enum `depmsg.main.Inner.E` is deprecated - With message! compilable/depmsg.d(45): Deprecation: alias `depmsg.main.Inner.G` is deprecated - With message! compilable/depmsg.d(46): Deprecation: variable `depmsg.main.Inner.H` is deprecated - With message! compilable/depmsg.d(47): Deprecation: class `depmsg.main.Inner.I()` is deprecated - With message! --- */ void main() { class Inner { deprecated("With message!") { struct A { } class B { } interface C { } union D { } enum E { e }; //typedef int F; alias int G; static int H; template I() { class I {} } } } with(Inner) { A a; B b; C c; D d; E e; //F f; G g; auto h = H; I!() i; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b17111.d0000644000175000017500000000032514141774365023042 0ustar matthiasmatthiasalias TestType = ubyte; void test(immutable TestType a, immutable TestType b, TestType c) { switch(c) { case a: break; case (cast(ushort)b): break; default: assert(false); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18020.d0000644000175000017500000000020014141774365023570 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=18020 void bug(T)(T t) { t.opCmp(t); } alias bugi = bug!(typeof(new class{}));./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17373.d0000644000175000017500000000206614141774365023616 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=17373 interface Foo { void visit (int); } interface Bar { void visit(double); } interface FooBar : Foo, Bar {} static assert(__traits(getOverloads, FooBar, "visit").length == 2); interface Fbar { void visit(char); void visit(double); } interface Triple : Foo, Bar, Fbar {} static assert(__traits(getOverloads, Triple, "visit").length == 3); interface InheritanceMadness : FooBar, Triple {} static assert(__traits(getOverloads, Triple, "visit").length == 3); interface Simple { int square(int); real square(real); } static assert(__traits(getOverloads, Simple, "square").length == 2); // https://issues.dlang.org/show_bug.cgi?id=19064 interface InputStream {} interface OutputStream{} interface Stream : InputStream, OutputStream{} interface ConnectionStream : Stream { @property bool connected() const; void close(); } static assert(__traits(getOverloads, ConnectionStream, "connected").stringof == "tuple(connected)"); static assert(__traits(getOverloads, ConnectionStream, "close").stringof == "tuple(close)"); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testCpCtor.d0000644000175000017500000000040314141774365024315 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19870 struct T { int i; this(ref return scope inout typeof(this) src) inout @safe pure nothrow @nogc { i = src.i; } } struct S { T t; } void main() { T a; S b = S(a); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue16020.d0000644000175000017500000000173514141774365023755 0ustar matthiasmatthiasmodule issue16020; alias F1 = const(int)(); const(int) f1(){return 42;} static assert (is(F1 == typeof(f1))); alias F2 = float(float); float f2(float p){return p;} static assert (is(F2 == typeof(f2))); alias F3 = void(); void f3(){} static assert (is(F3 == typeof(f3))); alias void F41() @safe; alias F42 = void() @safe; alias F43 = @safe void(); static assert (is(F41 == F42)); static assert (is(F43 == F42)); alias void F51() @system; alias F52 = void() @safe; static assert (!is(F51 == F52)); alias F61 = int() const shared; alias int F62() const shared ; alias F63 = const shared int(); static assert (is(F61 == F62)); static assert (is(F63 == F62)); alias F71 = int() immutable inout; alias int F72() immutable inout; alias F73 = immutable inout int(); static assert (is(F71 == F72)); static assert (is(F73 == F72)); alias FunTemplate(T) = void(T t); alias Specialized = FunTemplate!int; alias Compared = void(int); static assert(is(Specialized == Compared)); void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test10375.d0000644000175000017500000000042214141774365023603 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // EXTRA_FILES: imports/test10375a.d import imports.test10375a; void packIt(Pack)(Pack p){ } //3 void main() { alias p = packIt!(int); p(2); // OK <- NG packIt(2); // OK <- NG packIt!(int)(2); // OK <- NG } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test14831.d0000644000175000017500000000260714141774365023613 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=14831 void main() { { int x; static assert(x.mangleof == "_D9test148314mainFZ1xi"); } { int x; static assert(x.mangleof == "_D9test148314mainFZ4__S11xi"); } { static int y = 0; static assert(y.mangleof == "_D9test148314mainFZ1yi"); } { static int y = 0; static assert(y.mangleof == "_D9test148314mainFZ4__S11yi"); } { void f() {} static assert(f.mangleof == "_D9test148314mainFZ1fMFNaNbNiNfZv"); } { void f() {} static assert(f.mangleof == "_D9test148314mainFZ4__S11fMFNaNbNiNfZv"); } { struct S {} static assert(S.mangleof == "S9test148314mainFZ1S"); } { struct S {} static assert(S.mangleof == "S9test148314mainFZ4__S11S"); } { class C {} static assert(C.mangleof == "C9test148314mainFZ1C"); } { class C {} static assert(C.mangleof == "C9test148314mainFZ4__S11C"); } { enum E { a } static assert(E.mangleof == "E9test148314mainFZ1E"); static assert(E.a.mangleof == "_D9test148314mainFZ1E1aEQwQoFZQl"); } { enum E { a } static assert(E.mangleof == "E9test148314mainFZ4__S11E"); static assert(E.a.mangleof == "_D9test148314mainFZ4__S11E1aEQBbQuFZ4__S1Qr"); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue9884.d0000644000175000017500000000056414141774365023720 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=9884 module issue9884; const(int)[] data; static this() { data = new int[10]; foreach (ref x; data) x = 1; data[] = 1; } struct Foo { static const(int)[] data; static this() { this.data = new int[10]; foreach (ref x; this.data) x = 1; this.data[] = 1; } } void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/bug6963.d0000644000175000017500000000312214141774365023331 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: /* TEST_OUTPUT: --- output foo: 1e: pure nothrow @nogc @safe void(int x) output foo: 3e: pure nothrow @nogc @safe void(int x) --- */ alias void function(int) pure nothrow @safe @nogc FuncPtrType; void foo1a(X)(X x) {} void foo1b(X)(X x) {} void foo1c(X)(X x) {} void foo1d(X)(X x) {} void foo1e(X)(X x) {} // module level declaration with type inference auto fptr1 = &foo1a!int; static assert(is(typeof(fptr1) == FuncPtrType)); // array initializer auto fptrlist1 = [&foo1b!int]; static assert(is(typeof(fptrlist1) == FuncPtrType[])); // static assert static assert(is(typeof(&foo1c!int) == FuncPtrType)); // static if static if(is(typeof(&foo1d!int) PF)) static assert(is(PF == FuncPtrType)); else static assert(0); // pragma test pragma(msg, "output foo: 1e: ", typeof(foo1e!int).stringof); void foo2a(X)(X x) {} void foo2b(X)(X x) {} void foo2c(X)(X x) {} FuncPtrType fptr3 = &foo2a!int; // most similar to original issue FuncPtrType[] fptrlist3 = [&foo2b!int]; struct S{ FuncPtrType fp; } S s = { &foo2c!int }; void foo3a(X)(X x) {} void foo3b(X)(X x) {} void foo3c(X)(X x) {} void foo3d(X)(X x) {} void foo3e(X)(X x) {} void main() { auto fptr2 = &foo3a!int; static assert(is(typeof(fptr2) == FuncPtrType)); auto fptrlist2 = [&foo3b!int]; static assert(is(typeof(fptrlist2) == FuncPtrType[])); static assert(is(typeof(&foo1c!int) == FuncPtrType)); static if(is(typeof(&foo1d!int) PF)) static assert(is(PF == FuncPtrType)); else static assert(0); pragma(msg, "output foo: 3e: ", typeof(foo3e!int)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test12979b.d0000644000175000017500000000124414141774365023764 0ustar matthiasmatthias// REQUIRED_ARGS: -w -de // DISABLED: LDC_not_x86 void foo() pure nothrow @nogc @safe { asm pure nothrow @nogc @trusted { ret; } } void bar()() { asm pure nothrow @nogc @trusted { ret; } } static assert(__traits(compiles, () pure nothrow @nogc @safe => bar())); void baz()() { asm { ret; } } // wait for deprecation of asm pure inference // static assert(!__traits(compiles, () pure => baz())); static assert(!__traits(compiles, () nothrow => baz())); // wait for deprecation of asm @nogc inference // static assert(!__traits(compiles, () @nogc => baz())); static assert(!__traits(compiles, () @safe => baz())); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/aliasassign.d0000644000175000017500000000154514141774365024531 0ustar matthiasmatthiastemplate AliasSeq(T...) { alias AliasSeq = T; } template Unqual(T) { static if (is(T U == const U)) alias Unqual = U; else static if (is(T U == immutable U)) alias Unqual = U; else alias Unqual = T; } template staticMap(alias F, T...) { alias A = AliasSeq!(); static foreach (t; T) A = AliasSeq!(A, F!t); // what's tested alias staticMap = A; } alias TK = staticMap!(Unqual, int, const uint); //pragma(msg, TK); static assert(is(TK == AliasSeq!(int, uint))); /**************************************************/ template reverse(T...) { alias A = AliasSeq!(); static foreach (t; T) A = AliasSeq!(t, A); // what's tested alias reverse = A; } enum X2 = 3; alias TK2 = reverse!(int, const uint, X2); //pragma(msg, TK2); static assert(TK2[0] == 3); static assert(is(TK2[1] == const(uint))); static assert(is(TK2[2] == int)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15519_x.d0000644000175000017500000000015014141774365024135 0ustar matthiasmatthias// EXTRA_FILES: test15519_y.d import test15519_y; extern(C++, ns) { class X { test15519_y.ns.Y v; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18468.d0000644000175000017500000000013414141774365023616 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=18468 @safe void main() { synchronized {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test14954.d0000644000175000017500000000053414141774365023616 0ustar matthiasmatthias/* https://issues.dlang.org/show_bug.cgi?id=14954 EXTRA_SOURCES: imports/test14954_implementation.d LINK: // LDC: conflicting globals `blah` (of different types) when compiling to a single object file DISABLED: LDC */ extern(C) struct UndeclaredStruct; extern(C) __gshared extern UndeclaredStruct blah; __gshared auto p = &blah; void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17349.d0000644000175000017500000000134614141774365023621 0ustar matthiasmatthias /* REQUIRED_ARGS: PERMUTE_ARGS: */ // https://issues.dlang.org/show_bug.cgi?id=16538 const(int) retConst1(); int retConst2(); auto retConst = [&retConst1, &retConst2]; const(int*) retConstPtr1(); const(int)* retConstPtr2(); auto retConstPtr = [&retConstPtr1, &retConstPtr2]; void constArray1(const(int)[1]); void constArray2(const(int[1])); auto constArray = [&constArray1, &constArray2]; const(int)[] retConstSlice1(); const(int[]) retConstSlice2(); auto retConstSlice = [&retConstSlice1, &retConstSlice2]; void constSlice1(const(int)[]); void constSlice2(const(int[])); auto constSlice = [&constSlice1, &constSlice2]; void ptrToConst1(const(int)*); void ptrToConst2(const(int*)); auto ptrToConst = [&ptrToConst1, &ptrToConst2]; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/sw_transition_field.d0000644000175000017500000000114614141774365026276 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -transition=field /* TEST_OUTPUT: --- compilable/sw_transition_field.d(15): `sw_transition_field.S1.ix` is `immutable` field compilable/sw_transition_field.d(16): `sw_transition_field.S1.cx` is `const` field compilable/sw_transition_field.d(21): `sw_transition_field.S2!(immutable(int)).S2.f` is `immutable` field compilable/sw_transition_field.d(21): `sw_transition_field.S2!(const(int)).S2.f` is `const` field --- */ struct S1 { immutable int ix = 1; const int cx = 2; } struct S2(F) { F f = F.init; } alias S2!(immutable int) S2I; alias S2!( const int) S2C; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fwdref21063.d0000644000175000017500000000057314141774365024104 0ustar matthiasmatthiastemplate Info(T, int line) { static assert(__traits(getLinkage, T) == "C++"); alias Info = void; } // Forward reference static assert(__traits(getLinkage, Klass) == "C++"); alias info1 = Info!(Klass, __LINE__); extern (C++) class Klass { void derp() {} } // Backward reference static assert(__traits(getLinkage, Klass) == "C++"); alias info2 = Info!(Klass, __LINE__); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19656.d0000644000175000017500000000035714141774365023625 0ustar matthiasmatthias/* PERMUTE_ARGS: EXTRA_FILES: imports/test19656a.d imports/test19656b.d imports/test19656c.d */ import imports.test19656a; import imports.test19656c: Thud; class Foo { Foo[Foo] _map; void func (Thud ) { } void thunk () { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/rdeps7016.d0000644000175000017500000000077414141774365023671 0ustar matthiasmatthias/* PERMUTE_ARGS: REQUIRED_ARGS: -deps -Icompilable/extra-files COMPILED_IMPORTS: extra-files/rdeps7016a.d extra-files/rdeps7016b.d TRANSFORM_OUTPUT: remove_lines("druntime") TEST_OUTPUT: --- depsImport rdeps7016 ($p:rdeps7016.d$) : private : rdeps7016a ($p:rdeps7016a.d$) depsImport rdeps7016a ($p:rdeps7016a.d$) : private : rdeps7016b ($p:rdeps7016b.d$) depsImport rdeps7016b ($p:rdeps7016b.d$) : private : rdeps7016 ($p:rdeps7016.d$) --- */ module rdeps7016; import rdeps7016a; void main() { f(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice11906.d0000644000175000017500000000034514141774365023371 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: nothrow /*extern(Windows) */export int GetModuleHandleA(const char* lpModuleName); void main() { /*extern(Windows) */int function(const char*) f; assert(f != &GetModuleHandleA); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15898.d0000644000175000017500000000115114141774365023622 0ustar matthiasmatthias// REQUIRED_ARGS: -O // https://issues.dlang.org/show_bug.cgi?id=15898 int addAssignSimple(int[] , const(int)[] ) { uint c; return c; } void mulKaratsuba(int[] result, const(int)[] x, const(int)[] y, int[] ) { const(int)[] y1 = y; int[] newscratchbuff; int[] resultHigh = result; bool ysmaller2 = x.length >= y1.length; newscratchbuff[0..y1.length] = resultHigh; mulKaratsuba( resultHigh[1..$], ysmaller2 ? x[1..$] : y1, ysmaller2 ? y1 : x, newscratchbuff[y1.length..$] ); addAssignSimple(resultHigh[1..$], newscratchbuff[0..y1.length]); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice12002.d0000644000175000017500000000070714141774365023357 0ustar matthiasmatthias// REQUIRED_ARGS: -inline // PERMUTE_ARGS: void doFormat(void delegate(dchar) putc, TypeInfo[] arguments) { void formatArg(char fc) { const(char)* prefix = ""; void putstr(const char[] s) { //if (flags & FL0pad) { while (*prefix) putc(*prefix++); } foreach (dchar c; s) putc(c); } putstr(null); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test7754.d0000644000175000017500000000061214141774365023533 0ustar matthiasmatthias/* REQUIRED_ARGS: -H -Hd${RESULTS_DIR}/compilable PERMUTE_ARGS: -d -dw OUTPUT_FILES: ${RESULTS_DIR}/compilable/test7754.di TEST_OUTPUT: --- === ${RESULTS_DIR}/compilable/test7754.di // D import file generated from 'compilable/test7754.d' struct Foo(T) { shared static this() { } static this() { } } --- */ struct Foo(T) { shared static this() { } static this() { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8717.d0000644000175000017500000000340414141774365023535 0ustar matthiasmatthiasmodule test8717; struct SPR { private: enum e = 1; immutable int ii = 1; immutable static int sii = 1; static int sf() { return 1; } int f() const { return 1; } } static assert(SPR.e == 1); //static assert(SPR.ii == 1); static assert(SPR.sii == 1); static assert(SPR.sf() == 1); static assert(SPR.init.e == 1); static assert(SPR.init.ii == 1); static assert(SPR.init.sii == 1); static assert(SPR.sf() == 1); static assert(SPR.init.f() == 1); static if(SPR.e != 1) { static assert(0); } //static if(SPR.ii != 1) { static assert(0); } static if(SPR.sii != 1) { static assert(0); } static if(SPR.sf() != 1) { static assert(0); } static if(SPR.init.e != 1) { static assert(0); } static if(SPR.init.ii != 1) { static assert(0); } static if(SPR.init.sii != 1) { static assert(0); } static if(SPR.sf() != 1) { static assert(0); } static if(SPR.init.f() != 1) { static assert(0); } struct SPT { protected: enum e = 1; immutable int ii = 1; immutable static int sii = 1; static int sf() { return 1; } int f() const { return 1; } } static assert(SPT.e == 1); //static assert(SPT.ii == 1); static assert(SPT.sii == 1); static assert(SPT.sf() == 1); static assert(SPT.init.e == 1); static assert(SPT.init.ii == 1); static assert(SPT.init.sii == 1); static assert(SPT.sf() == 1); static assert(SPT.init.f() == 1); static if(SPT.e != 1) { static assert(0); } //static if(SPT.ii != 1) { static assert(0); } static if(SPT.sii != 1) { static assert(0); } static if(SPT.sf() != 1) { static assert(0); } static if(SPT.init.e != 1) { static assert(0); } static if(SPT.init.ii != 1) { static assert(0); } static if(SPT.init.sii != 1) { static assert(0); } static if(SPT.sf() != 1) { static assert(0); } static if(SPT.init.f() != 1) { static assert(0); } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b20885.d0000644000175000017500000000037314141774365023061 0ustar matthiasmatthiasmodule b20885; struct S { alias P = void*; } void main() { alias P = void*; alias PP = void**; PP[1] a = null; if (const void** b = a[0]){} // OK if (const P* b = a[0]){} // NG if (const S.P* b = a[0]){} // NG } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/const.d0000644000175000017500000000212214141774365023351 0ustar matthiasmatthias static assert(2.0 * 3.0 == 6 ); static assert(2.0 * 3.0i == 6i); static assert(2.0i * 3.0 == 6i); static assert(2.0i * 3.0i == -6 ); static assert(2.0 * (4.0 + 3.0i) == 8 + 6i); static assert(2.0i * (4.0 + 3.0i) == 8i - 6 ); static assert((4.0 + 3.0i) * 2.0 == 8 + 6i); static assert((4.0 + 3.0i) * 2.0i == 8i - 6 ); static assert((4.0 + 3.0i) * (5 + 7i) == -1 + 43i ); static assert((2.0).re == 2); static assert((2.0i).re == 0); static assert((3+2.0i).re == 3); static assert((4.0i).im == 4); static assert((2.0i).im == 2); static assert((3+2.0i).im == 2); static assert(6.0 / 2.0 == 3); static assert(6i / 2i == 3); static assert(6 / 2i == -3i); static assert(6i / 2 == 3i); static assert((6 + 4i) / 2 == 3 + 2i); static assert((6 + 4i) / 2i == -3i + 2); //static assert(2 / (6 + 4i) == -3i); //static assert(2i / (6 + 4i) == 3i); //static assert((1 + 2i) / (6 + 4i) == 3i); static assert(6.0 % 2.0 == 0); static assert(6.0 % 3.0 == 0); static assert(6.0 % 4.0 == 2); static assert(6.0i % 2.0i == 0); static assert(6.0i % 3.0i == 0); static assert(6.0i % 4.0i == 2i); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19409.d0000644000175000017500000000025414141774365023615 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19409 module test.foo; static if (__traits(compiles, __traits(identifier, test.foo))) {} // fails else { static assert(0); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testDIP37a.d0000644000175000017500000000030614141774365024054 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -Icompilable/extra-files // COMPILED_IMPORTS: extra-files/pkgDIP37/datetime/package.d // COMPILED_IMPORTS: extra-files/pkgDIP37/datetime/common.d void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8296.d0000644000175000017500000000041114141774365023532 0ustar matthiasmatthiasstruct bar2 { int i; @disable this(); this(int i) { this.i = i; } } class InnerBar { bar2 b; this() { b = bar2(0); } } struct bar1 { InnerBar b; } class Foo { bar1 m_bar1; } void main(string[] args) { auto foo = new Foo(); }./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20488.d0000644000175000017500000000035714141774365023620 0ustar matthiasmatthiasmodule test20488; // https://issues.dlang.org/show_bug.cgi?id=20488 struct Bar { void opDispatch(string s, Args...) (Args args) { } void fun() { (bool[int]).init.length; this.f((int[int]).init.length); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testDIP42.d0000644000175000017500000000503414141774365023712 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: // enum ident(tpl) = Initializer; enum isIntegral(T) = is(T == int) || is(T == long); static assert( isIntegral!int); static assert( isIntegral!long); static assert(!isIntegral!double); static assert(!isIntegral!(int[])); version(none) { enum allSatisfy(alias pred, TL...) = TL.length == 0 || (pred!(TL[0]) && allSatisfy!(pred, TL[1..$])), anySatisfy(alias pred, TL...) = TL.length != 0 && (pred!(TL[0]) || anySatisfy!(pred, TL[1..$])) || false; static assert( allSatisfy!(isIntegral, int, long)); static assert(!allSatisfy!(isIntegral, int, double)); static assert( anySatisfy!(isIntegral, int, double)); static assert(!anySatisfy!(isIntegral, int[], double)); } void test1() { // statement enum isIntegral2(T) = is(T == int) || is(T == long); static assert(isIntegral2!int); } /******************************************/ // alias ident(tpl) = Type; alias TypeTuple(TL...) = TL; static assert(is(TypeTuple!(int, long)[0] == int)); static assert(is(TypeTuple!(int, long)[1] == long)); alias Id(T) = T, Id(alias A) = A; static assert(is(Id!int == int)); static assert(__traits(isSame, Id!TypeTuple, TypeTuple)); void test2() { // statement alias TypeTuple2(TL...) = TL; static assert(is(TypeTuple2!(int, long)[0] == int)); static assert(is(TypeTuple2!(int, long)[1] == long)); alias IdT(T) = T, IdA(alias A) = A; static assert(is(IdT!int == int)); static assert(__traits(isSame, IdA!TypeTuple, TypeTuple)); } /******************************************/ // template auto declaration auto tynameLen(T) = T.stringof.length; void test3() { assert(tynameLen!int == 3); assert(tynameLen!long == 4); tynameLen!int = 4; tynameLen!long = 5; assert(tynameLen!int == 4); assert(tynameLen!long == 5); // statement auto tynameLen2(T) = T.stringof.length; assert(tynameLen2!int == 3); assert(tynameLen2!long == 4); tynameLen2!int = 4; tynameLen2!long = 5; assert(tynameLen2!int == 4); assert(tynameLen2!long == 5); } /******************************************/ // template variable declaration static T math_pi(T) = cast(T)3.1415; enum bool isFloatingPoint(T) = is(T == float) || is(T == double); static assert( isFloatingPoint!double); static assert(!isFloatingPoint!string); void main() { assert(math_pi!int == 3); assert(math_pi!double == 3.1415); enum bool isFloatingPoint2(T) = is(T == float) || is(T == double); static assert( isFloatingPoint2!double); static assert(!isFloatingPoint2!string); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testheader17125.d0000644000175000017500000000101714141774365024755 0ustar matthiasmatthias/* EXTRA_SOURCES: extra-files/header17125.d PERMUTE_ARGS: REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/testheader17125.di OUTPUT_FILES: ${RESULTS_DIR}/compilable/testheader17125.di TEST_OUTPUT: --- === ${RESULTS_DIR}/compilable/testheader17125.di // D import file generated from 'compilable/extra-files/header17125.d' void func1(real value = 103500.0L); void func2(real value = 520199.0F); void func3(real value = 970000.0); void func4(real value = 102450.0F); void func5(real value = 412502.0L); --- */ void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b9490.d0000644000175000017500000000110414141774365022771 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=9490 class A { int[1] arr; this() { assert(arr.length); assert((arr).length); } } class C { struct Foo { int a; void funcToo(){} } Foo foo; auto get(){return foo;} void test() { // Error: need 'this' to access member a (foo).a = 1; (foo).funcToo(); (get()).a = 2; } } struct S { int i; } struct S1 { S s; } void f(int) { } void main() { S1 s1; f(s1.s.tupleof); // OK f((s1.s).tupleof); // Error: need 'this' to access member s } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue21662.d0000644000175000017500000000012214141774365023752 0ustar matthiasmatthiasstruct S { @disable this(); } extern __gshared S a; extern S[2] b; void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc14778.d0000644000175000017500000000126214141774365023553 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc14778; /// docs for Z template Z14778(T) { /// docs for E enum E; /// docs for x enum x = 1.0; /// docs for mv auto mv = 1; /// docs for wv inout wv = 3; /// doc for cv const cv = "a"; /// docs for wcv inout const wcv = "ab"; /// doc for sv shared sv = 1.4142; /// doc for swv shared inout swv = 3.14; /// doc for scv shared const scv = new Object(); /// docs for swcv shared inout const swcv = undefined; /// doc for iv immutable iv = [1,2,3]; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue12520.d0000644000175000017500000000122414141774365023747 0ustar matthiasmatthiasmodule issue12520; // https://issues.dlang.org/show_bug.cgi?id=12520 alias Seq(T...) = T; static assert( Seq!() == Seq!() ); static assert( Seq!(1) == Seq!(1) ); static assert((Seq!() != Seq!()) == false); static assert((Seq!(1) != Seq!(1)) == false); static assert( Seq!() != Seq!(1) ); static assert( Seq!(1) != Seq!() ); static assert( Seq!(0) != Seq!(1) ); static assert( Seq!(0,1) != Seq!() ); static assert((Seq!() == Seq!(1)) == false); static assert((Seq!(1) == Seq!()) == false); static assert((Seq!(0) == Seq!(1)) == false); static assert((Seq!(0,1) == Seq!()) == false); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_links.d0000644000175000017500000000176014141774365026245 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_links.html // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_links.html /++ # Links [D Site]: https://dlang.org 'D lives here' [unused reference]: https://nowhere.com A link to [printf]. A link to [the base object][Object]. Not a link because it's an associative array: int[Object]. An inline link to [the D homepage](https://dlang.org). A reference link to [the **D** homepage][d site]. Not a reference link because it [links to nothing][nonexistent]. A simple link to [dub]. A slightly less simple link to [dub][]. An image: ![D-Man](https://dlang.org/images/d3.png) Another image: ![D-Man again][dman-error] [dub]: [dman-error]: https://dlang.org/images/dman-error.jpg $(P [tour]: https://tour.dlang.org Here's a [reference to the tour][tour] inside a macro. ) +/ module test.compilable.ddoc_markdown_links; import core.stdc.stdio; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20138.d0000644000175000017500000000122214141774365023600 0ustar matthiasmatthiasalias C = const int; static assert(is(shared(C) U == shared U) && is(U == C)); static assert(is(shared(C) == shared U, U) && is(U == C)); alias I = inout int; static assert(is(shared(I) U == shared U) && is(U == I)); static assert(is(shared(I) == shared U, U) && is(U == I)); alias IC = inout const int; static assert(is(shared(IC) U == shared U) && is(U == IC)); static assert(is(shared(IC) == shared U, U) && is(U == IC)); alias S = shared int; static assert(is(const(S) U == const U) && is(U == shared int)); static assert(is(inout(S) U == inout U) && is(U == shared int)); static assert(is(inout(const S) U == inout(const U)) && is(U == shared int)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21828.d0000644000175000017500000000040514141774365023611 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21828 struct S { enum E { e1 = 0, } E e; enum S s1 = S(E.e1); } SE se; enum SE { e1 = S.s1 } // reduced case, forward references just assume int value E e; enum E { a = "x" } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test10992b.d0000644000175000017500000000032614141774365023755 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -unittest version(none) {} else { unittest { } unittest { } unittest { } } void main() { static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 3); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testimport12242.d0000644000175000017500000000162514141774365025037 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/imp12242a.d imports/imp12242a1.d imports/imp12242a2.d imports/imp12242b.d imports/imp12242b1.d imports/imp12242b2.d module testimport12242; import imports.imp12242a; // test // stripA == OverloadSet import imports.imp12242a1; // std.string // stripA == template import imports.imp12242b1; // std.string // stripB == template import imports.imp12242b; // test // stripB == OverloadSet void main() { static assert(stripA(" af ") == 1); static assert(" af ".stripA() == 1); // UFCS (1) static assert(" af ".stripA == 1); // UFCS (2) static assert(stripB(" af ") == 1); static assert(" af ".stripB() == 1); // UFCS (1) static assert(" af ".stripB == 1); // UFCS (2) static assert(foo!int == 1); static assert(foo!long == 2); static assert(foo!float == 3); static assert(foo!real == 4); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20420.d0000644000175000017500000000034314141774365023575 0ustar matthiasmatthias// REQUIRED_ARGS: -inline // https://issues.dlang.org/show_bug.cgi?id=20420 struct S { ~this(); } class C { this(S, int) {} } int i(); C create() { return new C(S(), i()); } auto test() { auto c = create(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/cpp_abi_tag_unused.d0000644000175000017500000000046514141774365026046 0ustar matthiasmatthias/* DISABLED: win32 win64 REQUIRED_ARGS: -extern-std=c++11 */ #line 100 // Make sure that bad things don't happen if the user isn't using // `core.attribute`'s definition struct gnuAbiTag { string[] args; } extern(C++): @gnuAbiTag(["42"]) struct A {} __gshared A a; static assert(a.mangleof == "a"); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16013b.d0000644000175000017500000000045014141774365023741 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=16013 S s; /* Only this line has changed from above. */ struct RefCounted { void opAssign(RefCounted rhs) {} void opAssign(S rhs) {} S refCountedPayload() { return S.init; } alias refCountedPayload this; } struct S { RefCounted s; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc3.d0000644000175000017500000000261514141774365023226 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc3.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** * Summary * * Description1 * * Description2 * * Description3 * * Macros: * WIKI = StdStream * meemie * ARG0 = $0 * ARG1 = $1 * ARG2 = $2 * ARG3 = $3 * PLUS = $+ * TROW = $(TR $(TCOL $1,$+)) * TCOL = $(TD $1) $(TCOL $+) * LPAREN = ( * See_Also: * Things to see also. * * And more things $(BR) * 'arg1, arg2, arg3' : $(ARG0 arg1, arg2, arg3). $(BR) * 'arg2, arg3' : $(PLUS arg1, arg2, arg3). $(BR) * 'arg1' : $(ARG1 arg1, arg2, arg3). $(BR) * 'arg2' : $(ARG2 arg1, arg2, arg3). $(BR) * 'arg3' : $(ARG3 arg1, arg2, arg3). $(BR) */ /** * Things to see also $(HELLO). * * $(TABLE * $(TROW 1, 2, 3) * $(TROW 4, 5, 6) * ) * * $(D_CODE $(B pragma)( $(I name) ); $(B pragma)( $(I name) , $(I option) [ $(I option) ] ); $(U $(LPAREN)) ) */ /* */ module std.test; /// A base class for stream exceptions. class StreamException: Exception { /** Construct a StreamException with given error message msg. * Params: * msg = the $(RED red) $(BLUE blue) $(GREEN green) $(YELLOW yellow). * foo = next parameter which is a much longer * message spanning multiple * lines. */ this(string msg, int foo) { super(msg); } /********** stars ***************/ int stars; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20530.d0000644000175000017500000000345114141774365023602 0ustar matthiasmatthias// EXTRA_FILES: imports/test20530a.d imports/plainpackage/plainmodule.d imports/pkgmodule/package.d imports/pkgmodule/plainmodule.d module mod; static assert(is(mod == module)); static assert(is(mixin("mod") == module)); static assert(!is(mod == package)); static assert(!is(mixin("mod") == package)); import imports.test20530a; static assert(is(imports == package)); static assert(is(mixin("imports") == package)); static assert(!is(imports == module)); static assert(!is(mixin("imports") == module)); import imports.plainpackage.plainmodule; import imports.pkgmodule.plainmodule; struct MyStruct; alias a = mixin("imports.plainpackage"); alias b = mixin("imports.pkgmodule.plainmodule"); static assert(is(mixin("imports.plainpackage") == package)); static assert(is(mixin("a") == package)); static assert(!is(mixin("imports.plainpackage.plainmodule") == package)); static assert(!is(mixin("b") == package)); static assert(is(mixin("imports.pkgmodule") == package)); mixin("static assert(is(imports.pkgmodule == package));"); static assert(!is(mixin("MyStruct") == package)); static assert(!is(mixin("imports.plainpackage") == module)); static assert(!is(mixin("a") == module)); static assert(is(mixin("imports.plainpackage.plainmodule") == module)); static assert(is(mixin("b") == module)); static assert(is(mixin("imports.pkgmodule") == module)); mixin("static assert(is(imports.pkgmodule == module));"); static assert(!is(mixin("MyStruct") == module)); static assert(!is(mixin("imports.nonexistent") == package)); static assert(!is(mixin("imports.nonexistent") == module)); // this won't work due to mixin argument .stringof expansion, // it will expand to mixin(package imports.pkgmodule). Issue 20519. //static assert(is(mixin(imports.pkgmodule) == package)); //static assert(is(mixin(imports.pkgmodule) == module)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/objc_interface_final_19654.d0000644000175000017500000000023414141774365027103 0ustar matthiasmatthias// DISABLED: LDC // EXTRA_OBJC_SOURCES: import core.attribute : selector; extern (Objective-C) interface Bar { final void foo() @selector("foo") {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ob1.d0000644000175000017500000000433614141774365022715 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=dip1021 /* Should compile successfully */ struct Allocation { int* ptr; size_t length; } void canFind(scope Allocation); int* malloc(); void free(int*); void pitcher(); void borrow(scope int*); void borrow2c(const scope int*, const scope int*); void out1(out int*); /*****************************/ @live int* foo1(int* p) { return p; // consumes owner } @live int* foo2() { int* p = null; return p; // consumes owner } @live int* foo3(int* p) { scope int* q = p; // borrows from p return p; // use of p ends borrow in q } @live int* foo4(int* p) { scope int* bq = p; // borrow scope const int* cq = p; // const borrow return p; // ends both borrows } /*******************************/ @live void foo5() { auto p = malloc(); scope(exit) free(p); pitcher(); } /*******************************/ void deallocate(int* ptr, size_t length) @live { canFind(Allocation(ptr, length)); // canFind() borrows ptr free(ptr); } /*******************************/ @live int* test1() { auto p = malloc(); scope b = p; return p; } @live int* test2() { auto p = malloc(); auto q = p; return q; } @live void test3() { auto p = malloc(); free(p); } @live void test4() { auto p = malloc(); borrow(p); free(p); } @live void test5() { auto p = malloc(); scope q = p; borrow2c(p, p); free(p); } @live void test6() { int* p = void; out1(p); // initialize free(p); // consume } /*******************************/ void zoo1(int); @live void zoo2() { int* p = malloc(); zoo1(*p); // does not consume p free(p); } @live void zoo3() { int** p = cast(int**)malloc(); free(*p); // consumes p } @live void zoo4() { int[] a = malloc()[0 .. 1]; zoo1(a[0]); // does not consume a free(a.ptr); // consumes a } @live void zoo5() { int*[] a = (cast(int**)malloc())[0 .. 1]; free(a[0]); // consumes a } struct S { int i; int* p; } @live void zoo6() { S* s = cast(S*)malloc(); zoo1(s.i); // does not consume s free(cast(int*)s); } @live void zoo7() { S* s = cast(S*)malloc(); free(s.p); // consumes s } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test22133.d0000644000175000017500000000077714141774365023613 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22133 struct Slice { bool empty() const; int front() const; void popFront()() // note: requires a mutable Slice {} } enum isInputRange1(R) = is(typeof((R r) => r.popFront)); enum isInputRange2(R) = __traits(compiles, (R r) => r.popFront); static assert(isInputRange1!( Slice) == true); static assert(isInputRange1!(const Slice) == false); static assert(isInputRange2!( Slice) == true); static assert(isInputRange2!(const Slice) == false); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc4162.d0000644000175000017500000000035414141774365023456 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /// interface A { /// static void staticHello() { } /// final void hello() { } } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_expressions.d0000644000175000017500000000452714141774365025636 0ustar matthiasmatthias/+ REQUIRED_ARGS: -o- -HC TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif extern int32_t foo(); extern int32_t* somePtr; extern void insertedCast(double a = (double) foo()); extern void explicitCast(int32_t b = foo()); extern void requiredCast(void* ptr = (void*) foo()); extern void stcCast(const int32_t* const ci = (const int32_t* const) somePtr); --- +/ extern (C++): int foo() { return 0; } __gshared int* somePtr; void insertedCast(double a = foo()) {} void explicitCast(int b = cast(int) foo()) {} void requiredCast(void* ptr = cast(void*) foo()) {} void stcCast(const int* ci = cast(immutable) somePtr) {} /+ TEST_OUTPUT: --- template extern T insertedTmpl(double a = static_cast(foo())); template extern T explicitTmpl(int32_t b = (int32_t) foo()); template extern T requiredTmpl(void* ptr = (void*) foo()); template extern T stcCastTmpl(int32_t* ci = (int32_t*) somePtr); template extern T paramCastTmpl(int32_t* ci = (T) somePtr); --- +/ T insertedTmpl(T)(double a = foo()) {} T explicitTmpl(T)(int b = cast(int) foo()) {} T requiredTmpl(T)(void* ptr = cast(void*) foo()) {} T stcCastTmpl(T)(const int* ci = cast(immutable) somePtr) {} T paramCastTmpl(T)(const int* ci = cast(T) somePtr) {} /+ TEST_OUTPUT: --- struct Data final { static Data* pt; static int32_t* bar(); Data() { } }; extern void useData(bool a = !Data::pt, bool b = Data::bar() == nullptr, bool c = Data::bar() != nullptr); --- +/ struct Data { __gshared Data* pt; static int* bar() { return null; } } void useData( bool a = !Data.pt, bool b = Data.bar() is null, bool c = Data.bar() !is null ) {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21832.d0000644000175000017500000000042014141774365023601 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/imp21832.d int test21832a() { import imports.imp21832 : fun; // function 'fun' is deprecated return fun(0); } int test21832b() { import imports.imp21832 : tpl; // template 'tpl' is deprecated return tpl(0); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6395.d0000644000175000017500000000025314141774365023534 0ustar matthiasmatthias// REQUIRED_ARGS: -Icompilable/extra-files // EXTRA_SOURCES: b6395.d // EXTRA_FILES: extra-files/c6395.d // https://issues.dlang.org/show_bug.cgi?id=6395 import c6395; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6056a.d0000644000175000017500000000013514141774365023666 0ustar matthiasmatthiasalias const(typeof('c')*) A; alias const(typeof(0)*) B; static assert(is(B == const(int*))); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_AnonDeclaration.d0000644000175000017500000000317414141774365026312 0ustar matthiasmatthias/* REQUIRED_ARGS: -HC -c -o- PERMUTE_ARGS: TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif struct S final { union { int32_t x; char c[4$?:32=u|64=LLU$]; }; struct { int32_t y; double z; extern "C" void foo(); void bar(); }; struct { int32_t outerPrivate; }; struct { int32_t innerPrivate; int32_t innerBar; }; S() { } }; extern void foo(); --- */ extern (C++) struct S { union { int x; char[4] c; } struct { int y; double z; extern(C) void foo() {} extern(C++) void bar() {} } // Private not emitted because AnonDeclaration has no protection private struct { int outerPrivate; } public struct { // Private cannot be exported to C++ private int innerPrivate; int innerBar; } } extern (D) { extern(C++) void foo() {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc5.d0000644000175000017500000000061414141774365023225 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** Test module */ module test; /// class to test DDOC on members class TestMembers(TemplateArg) { public: /** a static method Params: idx = index */ static void PublicStaticMethod(int idx) { } } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15578.d0000644000175000017500000000036214141774365023620 0ustar matthiasmatthias// DISABLED: LDC // broken for dmd, too: https://issues.dlang.org/show_bug.cgi?id=15943 __gshared private: int j; extern(C++, ns) int k; void f() { j = 0; // works as expected k = 0; // Error: variable foo.ns.k is private } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testcstuff1.c0000644000175000017500000002370414141774365024506 0ustar matthiasmatthias// check the expression parser _Static_assert(0 == 0, "ok"); _Static_assert(0 != 1, "ok"); _Static_assert(1 + 2 == 3, "ok"); _Static_assert(1 - 2 == -1, "ok"); _Static_assert(3 * 4 == 12, "ok"); _Static_assert(10 / 2 == 5, "ok"); _Static_assert(10 % 3 == 1, "ok"); _Static_assert(2 << 3 == 16, "ok"); _Static_assert(16 >> 3 == 2, "ok"); _Static_assert((2 | 1) == 3, "ok"); _Static_assert((3 & 1) == 1, "ok"); _Static_assert((3 ^ 1) == 2, "ok"); _Static_assert(-(3 ^ 1) == -+2, "ok"); _Static_assert(~1 == 0xFFFFFFFE, "ok"); _Static_assert(!3 == 0, "ok"); _Static_assert(!0 == 1, "ok"); _Static_assert(6.0f == 6.0, "in"); _Static_assert(6.0F == 6.0, "in"); _Static_assert(6.0l == 6.0, "in"); _Static_assert(6.0L == 6.0, "in"); _Static_assert(sizeof(char) == 1, "ok"); _Static_assert(sizeof(char signed) == 1, "ok"); _Static_assert(sizeof(unsigned char) == 1, "ok"); _Static_assert(sizeof(short) == 2, "ok"); _Static_assert(sizeof(int short) == 2, "ok"); _Static_assert(sizeof(signed short) == 2, "ok"); _Static_assert(sizeof(signed short int) == 2, "ok"); _Static_assert(sizeof(short unsigned) == 2, "ok"); _Static_assert(sizeof(unsigned short int) == 2, "ok"); _Static_assert(sizeof(int) == 4, "ok"); _Static_assert(sizeof(signed) == 4, "ok"); _Static_assert(sizeof(signed int) == 4, "ok"); _Static_assert(sizeof(int unsigned) == 4, "ok"); _Static_assert(sizeof(unsigned) == 4, "ok"); _Static_assert(sizeof(long) >= 4, "ok"); _Static_assert(sizeof(signed long) >= 4, "ok"); _Static_assert(sizeof(int long) <= 8, "ok"); _Static_assert(sizeof(long signed int) <= 8, "ok"); _Static_assert(sizeof(int unsigned long) >= 4, "ok"); _Static_assert(sizeof(long unsigned) <= 8, "ok"); _Static_assert(sizeof(long long) == 8, "ok"); _Static_assert(sizeof(int long long) == 8, "ok"); _Static_assert(sizeof(long signed long) == 8, "ok"); _Static_assert(sizeof(long long signed int) == 8, "ok"); _Static_assert(sizeof(unsigned long long) == 8, "ok"); _Static_assert(sizeof(int long unsigned long) == 8, "ok"); _Static_assert(sizeof(float) == 4, "ok"); _Static_assert(sizeof(double) == 8, "ok"); //_Static_assert(sizeof(long double) == 8 || sizeof(long double) == 10 || sizeof(long double) == 16, "ok"); _Static_assert(sizeof(const restrict volatile char volatile restrict const) == 1, "ok"); _Static_assert(sizeof(int*) == 8 || 4 == sizeof(char*), "ok"); _Static_assert(sizeof(int[10][20]) == 20 * (10 * 4), "ok"); /**********************************************/ _Static_assert(07 == 7, "ok"); _Static_assert(071 == 57, "ok"); _Static_assert(0 == 0, "ok"); _Static_assert(1u == 1l, "ok"); _Static_assert(1U == 1L, "ok"); _Static_assert(1Ul == 1L, "ok"); _Static_assert(1ull == 1LL, "ok"); _Static_assert(1llu == 1ull, "ok"); _Static_assert(sizeof(1) == 4, "ok"); _Static_assert(sizeof(0x1) == 4, "ok"); _Static_assert(sizeof(1u) == 4, "ok"); _Static_assert(sizeof(0x1u) == 4, "ok"); _Static_assert(sizeof(1l) == 4 || sizeof(1l) == 8, "ok"); _Static_assert(sizeof(1ul) == 4 || sizeof(1ul) == 8, "ok"); _Static_assert(sizeof(0x1l) == 4 || sizeof(0x1L) == 8, "ok"); _Static_assert(sizeof(0x1ul) == 4 || sizeof(0x1UL) == 8, "ok"); _Static_assert(sizeof(1ll) == 8, "ok"); _Static_assert(sizeof(1ull) == 8, "ok"); _Static_assert(sizeof(0x1ull) == 8, "ok"); _Static_assert(sizeof(0x8000000000000000LL) == 8, "ok"); _Static_assert(sizeof(0x1LL) == 8, "ok"); _Static_assert(sizeof(0x8000000000000000) == 8, "ok"); _Static_assert(sizeof(0x7FFFFFFF00000000) == 8, "ok"); _Static_assert(sizeof(9223372036854775808) == 8, "ok"); _Static_assert(sizeof(9223372032559808512) == 8, "ok"); _Static_assert(sizeof(0xFFFFFFFF00000000U) == 8, "ok"); _Static_assert(sizeof(0x8000000000000000L) == 8, "ok"); /**********************************************/ int f1(i, j) int i; int j; { return i + 3; } _Static_assert(f1(4, 2) == 7, "ok"); /**********************************************/ enum E1 { M1, M2, M3, M4 = 7, M5, }; enum E2 { M6 }; _Static_assert(M3 == 2, "ok"); _Static_assert(M5 == 8, "ok"); /**********************************************/ int s1(int i) { while (i < 10) ++i; return i; } _Static_assert(s1(3) == 10, "s1(3) == 10"); int s2(int i) { for (; i < 10; ++i); return i; } _Static_assert(s2(3) == 10, "s2(3) == 10"); int s3(int i) { do { ++i; } while (i < 10); return i; } _Static_assert(s3(3) == 10, "s3(3) == 10"); int s4(int i) { switch (i) { case 1: break; case 2+1: i = 10; break; default: i = 11; break; } return i; } _Static_assert(s4(1) == 1, "s4(1) == 1"); _Static_assert(s4(3) == 10, "s4(3) == 10"); _Static_assert(s4(5) == 11, "s4(5) == 11"); int s5(int i) { if (i == 3) return 4; else return 5; } _Static_assert(s5(3) == 4, "s5(3) == 4"); _Static_assert(s5(4) == 5, "s5(4) == 5"); /********************************/ void tokens() <% char c = 'c'; unsigned short w = L'w'; //unsigned short* ws = L"wstring"; int LLL1[1]; int LLL2<:1:>; %> /********************************/ int testexpinit() { int i = 1; int j = { 2 }; int k = { 3 , }; return i + j + k; } _Static_assert(testexpinit() == 1 + 2 + 3, "ok"); /********************************/ // Character literals _Static_assert(sizeof('a') == 4, "ok"); _Static_assert(sizeof(u'a') == 4, "ok"); _Static_assert(sizeof(U'a') == 4, "ok"); _Static_assert('a' == 0x61, "ok"); _Static_assert('ab' == 0x6162, "ok"); _Static_assert('abc' == 0x616263, "ok"); _Static_assert('abcd' == 0x61626364, "ok"); _Static_assert(u'a' == 0x61, "ok"); _Static_assert(u'ab' == 0x610062, "ok"); _Static_assert(U'a' == 0x61, "ok"); _Static_assert(u'\u1234' == 0x1234, "ok"); _Static_assert(U'\U00011234' == 0x11234, "ok"); _Static_assert(L'\u1234' == 0x1234, "ok"); /********************************/ void test__func__() { _Static_assert((sizeof __func__) == 13, "ok"); } void teststringtype() { char* p = "hello"; unsigned short* up = u"hello"; unsigned int* Up = U"hello"; } /********************************/ char s[] = "hello"; _Static_assert(sizeof(s) == 6, "in"); /********************************/ struct SA { int a, b, *const c, d[50]; }; int test1(int i) { L1: ++i; L2: { --i; } return i; } _Static_assert(test1(5) == 5, "ok"); void test2() { int; int (*xi); int (*fp)(void); int (* const volatile restrict fp2)(void); void* pv; char c, d; short sh; int j; long l; signed s; unsigned u; //_Complex double co; _Bool b; typedef int TI; //extern int ei; static int si; _Thread_local int tli; auto int ai; register int reg; const int ci; volatile int vi; restrict int ri; // _Atomic(int) ai; // _Alignas(c) ac; void * const volatile restrict q; inline int f(); _Noreturn void g(); _Static_assert(1, "ok"); } void test3(int i) { for (i = 0; ;) { } for (int j = 0; ;) { continue; } if (i == 3) i = 4; else i = 5; if (i == 4) i = 6; goto L1; L1: ; { L2: } } void test4(int i) { i = 4, i = 5; float f = 1.0f + 3; double d = 1.0 + 4; char c = 'c'; //char* s = __func__; int* p = &i; i = *p; _Static_assert(sizeof 3 == 4, "ok"); _Static_assert(sizeof(3) == 4, "ok"); _Static_assert(_Alignof(int) == 4, "ok"); _Static_assert((int)3 == 3, "ok"); _Static_assert(sizeof p[0] == 4, "ok"); _Static_assert(1 && 2, "ok"); _Static_assert((1 ? 2 : 3) == 2, "ok"); _Static_assert((0 ? 2 : 3) == 3, "ok"); i += 2; i -= 2; i *= 2; i /= 2; i %= 2; i &= 2; i |= 2; i ^= 2; i <<= 2; i >>= 2; i++; i--; p[0]++; *p = 3; (++i); long long ll = 12L; ll = 12UL; long double ld = 1.0L; const char* s = "hello" "betty"; } /********************************/ void parenExp(int a, int b) { char* q = (char*)"hello"; if (!(a == b)) a = b; if ((int)3 == 3); a = b; if ((a) == b) a = b; a = (int) (1 << (b)); typedef int t; int* p; a = a + (t)*p; } /********************************/ struct SS { int a; }; int tests1() { struct SS s; return s.a; } int tests2() { struct T { int a; }; struct T t; return t.a; } void* tests3() { struct T1 *p; return p; } int tests4() { struct S { int b; } a, *p; a.b = 3; p = &a; return p->b; } int test5() { struct { int a; }; struct S { int a; struct { int b, c; }; } s; return s.a + s.b + s.c; } /********************************/ int test16997() { /* Exhaustively test all signed and unsigned byte promotions for * - + and ~ */ for (int i = 0; i < 256; ++i) { unsigned char c = (unsigned char)i; int i1 = (int) (~c); int i2 = (int) (~(int) c); //printf("%d, %d\n", i1, i2); if (i1 != i2) return 0; i1 = (int) (+c); i2 = (int) (+(int) c); if (i1 != i2) return 0; i1 = (int) (-c); i2 = (int) (-(int) c); if (i1 != i2) return 0; } for (int i = 0; i < 256; ++i) { signed char c = (signed char)i; int i1 = (int) (~c); int i2 = (int) (~(int) c); //printf("%d, %d\n", i1, i2); if (i1 != i2) return 0; i1 = (int) (+c); i2 = (int) (+(int) c); if (i1 != i2) return 0; i1 = (int) (-c); i2 = (int) (-(int) c); if (i1 != i2) return 0; } return 1; } _Static_assert(test16997(), "in"); /********************************/ struct SH { int a; }; int SH; int SJ; struct SJ { int a; }; void testtags() { struct SH h; h.a = SH; struct SJ j; j.a = SJ; struct SK { int a; }; int SK; struct SK k; k.a = SK; int SL; struct SL { int a; }; struct SL l; l.a = SL; } /********************************/ int printf(const char*, ...); int main() { printf("hello world\n"); } #line 1000 %:line 1010 # 1020 "cstuff1.c" 1 2 3 4 # 1030 struct S21944 { int var; #1040 "cstuff1.c" 3 4 }; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_454.d0000644000175000017500000000012014141774365024717 0ustar matthiasmatthiasimport std.file; void main() { auto a = dirEntries("","",SpanMode.depth); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc648.d0000644000175000017500000000250614141774365023404 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc648; /// Mixin declaration mixin template Mixin1() { /// struct S struct S { } } /// class A class A { /// field x int x; /// no docs for mixin statement (only for expanded members) mixin Mixin1!(); } /// class AB class AB { /// field x int x; // no docs for mixin or its contents, must be a ddoc comment mixin Mixin1!(); } /// Mixin declaration2 mixin template Mixin2() { /// struct S2 struct S2 { } } /// Mixin declaration3 mixin template Mixin3() { /// another field int f; /// no docs for mixin statement (only for expanded members) mixin Mixin2!(); } /// class B1 class B1 { /// no docs for mixin statement (only for expanded members) mixin Mixin3!(); } /// Mixin declaration3 mixin template Mixin4() { /// another field int f; // no docs at all for non-ddoc comment mixin Mixin2!(); } /// class B2 class B2 { /// no docs for mixin statement (only for expanded members) mixin Mixin4!(); } /// no docs for mixin statement (only for expanded members) mixin Mixin3!(); /// struct TS(T) { mixin template MT() { } mixin MT; /// avoid calling semantic /// int field; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue20915.d0000644000175000017500000000040114141774365023752 0ustar matthiasmatthiasmodule issue20915; // prior to the PR adding this test case, // locally defined version and debug idents were included. version = illegal; debug = illegal; alias Seq(T...) = T; static assert (__traits(allMembers, issue20915) == Seq!("object", "Seq")); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue15574.sh0000644000175000017500000000205614141774365024156 0ustar matthiasmatthias#! /usr/bin/env bash if [[ $OS = *"win"* ]]; then exit 0; fi if [ $LIBEXT = ".a" ]; then LIB_PREFIX=lib else LIB_PREFIX= fi TEST_DIR=${OUTPUT_BASE} C_FILE=$TEST_DIR/square.c C_LIB=$TEST_DIR/${LIB_PREFIX}csquare${LIBEXT} D_FILE=$TEST_DIR/square.d D_LIB=$TEST_DIR/${LIB_PREFIX}dsquare${LIBEXT} APP_FILE=$TEST_DIR/app.d APP=$TEST_DIR/app${EXE} mkdir -p $TEST_DIR cat >$C_FILE <$D_FILE <$APP_FILE < goo(1))); static assert(__traits(compiles, () => goo(1))); auto goo(T)(T a) { struct SInside { T foo() { return a; } } SInside res; lazyfun(a); return res; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testfwdref.d0000644000175000017500000003242214141774365024406 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/fwdref9514.d imports/fwdref12201a.d /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=6766 class Foo6766 { this(int x) { } void test(Foo6766 foo = new Foo6766(1)) { } } struct Bar6766 { this(int x) { } void test(Bar6766 bar = Bar6766(1)) { } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8609 struct Tuple8609(T) { T arg; } // ---- struct Foo8609a { Bar8609a b; } struct Bar8609a { int x; Tuple8609!(Foo8609a) spam() { return Tuple8609!(Foo8609a)(); } } // ---- struct Foo8609b { Bar8609b b; } struct Bar8609b { int x; Tuple8609!(Foo8609b[1]) spam() { return Tuple8609!(Foo8609b[1])(); } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=8698 interface IRoot8698a {} interface IClass8698a : IRoot8698a { } struct Struct8698a { } class Class8698a : IClass8698a { alias Struct8698a Value; } void test8698a(Class8698a.Value) { } //interface IRoot8698a {} // ---- //interface IRoot8698b {} interface IClass8698b : IRoot8698b { } struct Struct8698b { } class Class8698b : IClass8698b { alias Struct8698b Value; } void test8698b(Class8698b.Value) { } interface IRoot8698b {} /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=9514 template TStructHelpers9514a() { void opEquals(Foo9514a) { auto n = FieldNames9514a!(); } } struct Foo9514a { mixin TStructHelpers9514a!(); } import imports.fwdref9514 : find9514; // selective import without aliasing template FieldNames9514a() { static if (find9514!`true`([1])) enum int FieldNames9514a = 1; } // ---- template TStructHelpers9514b() { void opEquals(Foo9514b) { auto n = FieldNames9514b!(); } } struct Foo9514b { mixin TStructHelpers9514b!(); } import imports.fwdref9514 : foo9514 = find9514; // selective import with aliasing template FieldNames9514b() { static if (foo9514!`true`([1])) enum int FieldNames9514b = 1; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=10015 struct S10015(T) { alias X = int; } alias Y10015 = s10015.X; S10015!int s10015; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=10101 int front10101(int); mixin template reflectRange10101() { static if (is(typeof(this.front10101))) { int x; } } struct S10101(R) { R r_; typeof(r_.front10101) front10101() @property { return r_.front10101; } mixin reflectRange10101; } void test10101() { S10101!(int) s; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11019 class A11019 { A11019 View() { return null; } } class B11019 : A11019 { override D11019 View() { return null; } } class D11019 : B11019 {} /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=11166 template Tup11166(T...) { alias Tup11166 = T; } struct S11166a { enum S11166a a = S11166a(0); enum S11166a b = S11166a(1); this(long value) { } long value; // only triggered when private and a template instance. private alias types = Tup11166!(a, b); } struct S11166b { enum S11166b a = S11166b(0); enum S11166b b = S11166b(1); // not at the last of members alias types = Tup11166!(a, b); this(long value) { } long value; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12152 class A12152 { alias Y = B12152.X; } class B12152 : A12152 { alias int X; } static assert(is(A12152.Y == int)); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12201 template T12201() { alias imports.fwdref12201a.FILE* FP; } struct S12201a { mixin T12201; import imports.fwdref12201a; } union U12201 { mixin T12201; import imports.fwdref12201a; } class C12201 { mixin T12201; import imports.fwdref12201a; } interface I12201 { mixin T12201; import imports.fwdref12201a; } template TI12201() { mixin T12201; import imports.fwdref12201a; } mixin template TM12201() { mixin T12201; import imports.fwdref12201a; } struct S12201b { alias ti = TI12201!(); mixin TM12201; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12531 struct Node12531(T) { T _val; } void test12531() { static struct Foo { Node12531!Foo* node; } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12543 class C12543; static assert(C12543.sizeof == (void*).sizeof); static assert(C12543.alignof == (void*).sizeof); static assert(C12543.mangleof == "C10testfwdref6C12543"); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=14010 enum E14010; static assert(E14010.mangleof == "E10testfwdref6E14010"); struct S14010; static assert(S14010.mangleof == "S10testfwdref6S14010"); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12983 alias I12983 = int; class B12983(T) { alias MyC = C12983!string; } class C12983(T) : B12983!float { void m() { f12983(0); } } alias MyB12983 = B12983!float; void f12983(); void f12983(I12983); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=12984 class B12984a { alias MyD = D12984a!int; } class C12984a : B12984a { } class D12984a(T) { alias MyE = E12984a!float; } class E12984a(T) : D12984a!int { void m() { auto c = new C12984a(); } } static assert(__traits(classInstanceSize, B12984a) == (void*).sizeof * 2); static assert(__traits(classInstanceSize, C12984a) == (void*).sizeof * 2); // ---- class B12984b { int b; alias MyD = D12984b!int; } class C12984b : B12984b { int c; } class D12984b(T) { int d; alias MyE = E12984b!float; } class E12984b(T) : D12984b!int { int e; void m() { auto c = new C12984b(); } } static assert(__traits(classInstanceSize, B12984b) == (void*).sizeof * 2 + int.sizeof); static assert(__traits(classInstanceSize, C12984b) == (void*).sizeof * 2 + int.sizeof * 2); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=14390 class B14390a { alias MyD = D14390a!int; } class C14390a : B14390a { void f(int) {} } class D14390a(T) { alias MyE = E14390a!float; } class E14390a(T) : D14390a!int { void m() { auto c = new C14390a(); } } class B14390b { alias MyD = D14390b!int; } class C14390b : B14390b { static struct S {} } class D14390b(T) { alias MyE = E14390b!float; } class E14390b(T) : D14390b!int { void m() { auto c = new C14390b(); } } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=13860 /* TEST_OUTPUT: --- pure nothrow @nogc @safe void() pure nothrow @nogc @safe void() --- */ struct Foo13860(Bar...) { Bar bars; auto baz(size_t d)() {} pragma(msg, typeof(baz!0)); } auto bar13860(S, R)(S s, R r) { pragma(msg, typeof(Foo13860!().baz!0)); } void test13860() { int[] x; int[] y; x.bar13860(y); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=14083 class NBase14083 { int foo(NA14083 a) { return 1; } int foo(NB14083 a) { return 2; } } class NA14083 : NBase14083 { int v; this(int v) { this.v = v; } } class NB14083 : NBase14083 { override int foo(NA14083 a) { return a.v; } } class TBase14083(T) { int foo(TA14083!T a) { return 1; } int foo(TB14083!T a) { return 2; } } class TA14083(T) : TBase14083!T { T v; this(T v) { this.v = v; } } class TB14083(T) : TBase14083!T { override int foo(TA14083!T a) { return a.v; } } static assert( { NA14083 na = new NA14083(10); NB14083 nb = new NB14083(); assert(na.foo(na) == 1); assert(na.foo(nb) == 2); assert(nb.foo(na) == 10); TA14083!int ta = new TA14083!int(10); TB14083!int tb = new TB14083!int(); assert(ta.foo(ta) == 1); assert(ta.foo(tb) == 2); assert(tb.foo(ta) == 10); return true; }()); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=14549 string foo14549(T)() { static if (T.tupleof.length >= 0) return ""; } class Frop14549 { mixin(foo14549!(typeof(this))); static if (__traits(compiles, undefined)) { } else { int bar = 0; } static if (!__traits(isVirtualMethod, this.bar)) {} } // ---- // regression case template Mix14549() { mixin(code14549!(typeof(this))); } template code14549(T) { enum string code14549 = q{ static if (!__traits(isVirtualMethod, "boo")) {} }; } class Bar14549 { mixin Mix14549; int boo; } // ---- // https://issues.dlang.org/show_bug.cgi?id=14609 // regression case interface Foo14609(T) { static if (is(T == int)) public int bar(); } class Frop14609 : Foo14609!int { public int bar() { return 0; } } /***************************************************/ // test case 1, comes from Phobos /* TEST_OUTPUT: --- +alias Alias12540 +anySatisfy, T.length == 1 +isStaticArray +T.stringof in StaticArrayTypeOf -T.stringof in StaticArrayTypeOf -isStaticArray +hasElaborateCpCtor S == struct or else -hasElaborateCpCtor S == struct or else -anySatisfy, T.length == 1 -alias Alias12540 --- */ template anySatisfy15726x(alias F, T...) { //static if (T.length == 1) //{ pragma(msg, "+anySatisfy, T.length == 1"); enum anySatisfy15726x = F!(T[0]); pragma(msg, "-anySatisfy, T.length == 1"); //} } template StaticArrayTypeOf15726x(T) { alias X = T; static if (is(X : E[n], E, size_t n)) { //alias StaticArrayTypeOf15726x = X; } else { pragma(msg, "+T.stringof in StaticArrayTypeOf"); // Fixed: T.stringof (T == Class12540) should not invoke // T.size() in ClassDeclaration.search(). static assert(0, T.stringof~" is not a static array type"); pragma(msg, "-T.stringof in StaticArrayTypeOf"); } } //enum bool isStaticArray(T) = is(StaticArrayTypeOf15726x!T); template isStaticArray15726x(T) { pragma(msg, "+isStaticArray"); enum bool isStaticArray15726x = is(StaticArrayTypeOf15726x!T); pragma(msg, "-isStaticArray"); } template hasElaborateCpCtor15726x(S) { static if (isStaticArray15726x!S && S.length) { //pragma(msg, "X+"); enum bool hasElaborateCpCtor15726x = hasElaborateCpCtor15726x!(typeof(S.init[0])); //pragma(msg, "X-"); } else { pragma(msg, "+hasElaborateCpCtor S == struct or else"); static if (is(S == struct)) { enum bool hasElaborateCpCtor15726x = true; //enum hasElaborateCpCtor15726x = hasMember!(S, "__postblit") // || anySatisfy15726x!(.hasElaborateCpCtor15726x, FieldTypeTuple!S); } else { enum bool hasElaborateCpCtor15726x = false; } pragma(msg, "-hasElaborateCpCtor S == struct or else"); } } struct VariantN15726x(AllowedTypesParam...) { alias AllowedTypes = AllowedTypesParam; static if (!AllowedTypes.length || anySatisfy15726x!(hasElaborateCpCtor15726x, AllowedTypes)) { } } template Algebraic15726x(T) { alias Algebraic15726x = VariantN15726x!(T); } void test15726x() { static struct DummyScope { pragma(msg, "+alias Alias12540"); alias Alias12540 = Algebraic15726x!Class12540; pragma(msg, "-alias Alias12540"); static class Class12540 { Alias12540 entity; } } } /***************************************************/ // test case 2, comes from Phobos struct RefCounted15726y(T) { struct RefCountedStore { struct Impl { T _payload; } Impl* _store; } RefCountedStore _refCounted; this(this) {} ~this() { _refCounted._store._payload.__xdtor(); } } struct RangeT15726y(A) { A[1] _outer_; alias RC = RangeT15726y!(const(A)); } struct Array15726y(T) { struct Payload { ~this(); } alias Data = RefCounted15726y!(Payload); Data _data; alias Range = RangeT15726y!Array15726y; } void test15726y() { alias Range = RangeT15726y!(Array15726y!int); Range r; r = r; // opAssign } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=15726 struct RC15726(T) { struct Impl { T _payload; } Impl* _store; ~this() { destroy15726a(_store._payload); } } // ---- struct Con15726a(T) { alias Stmt15726a = .Stmt15726a!T; } struct Stmt15726a(T) { alias Con15726a = .Con15726a!T; RC15726!Payload data; struct Payload { Con15726a con; } } Con15726a!int x15726a; void destroy15726a(T)(ref T obj) @trusted { auto buf = (cast(ubyte*)&obj)[0 .. T.sizeof]; } // ---- struct Util15726b(C, S) {} struct Con15726b(T) { alias Util15726b = .Util15726b!(Con15726b!T, Stmt15726b!T); } struct Stmt15726b(T) { struct Payload { Con15726b!T con; } RC15726!Payload data; } Con15726b!int x15726b; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc9155.d0000644000175000017500000000247514141774365023473 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc9155; /++ + Note: + test document note + 2nd line + Example: + --- + import std.stdio; //& + writeln("Hello world!"); + if (test) { + writefln("D programming language"); + } + + algorithm; + + xxx; //comment + yyy; + /* test + * comment + */ + + // Create MIME Base64 with CRLF, per line 76. +File f = File("./text.txt", "r"); +uint line = 0; + // The ElementType of data is not aggregation type +foreach (encoded; Base64.encoder(data)) + --- +/ /** -------------------------------------------------------- wstring ws; transcode("hello world",ws); // transcode from UTF-8 to UTF-16 -------------------------------------------------------- */ /** * Example: * --- * import std.stdio; //& * writeln("Hello world!"); * if (test) { * writefln("D programming language"); * } * * algorithm; * * xxx; //comment * yyy; * /+ test * + comment * +/ * --- */ /** ---- #!/usr/bin/env rdmd // Computes average line length for standard input. import std.stdio; ---- */ /** --- writefln(q"EOS This is a multi-line heredoc string EOS" ); --- */ void foo(){} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16563.d0000644000175000017500000000020214141774365023604 0ustar matthiasmatthiasvoid test16563() { align(1) struct S { uint i; ubyte b; static assert(S.sizeof == 5); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/cdcmp.d0000644000175000017500000001320614141774365023316 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -O // POST_SCRIPT: compilable/extra-files/objdump-postscript.sh // only testing on SYSV-ABI, but backend code is identical across platforms // DISABLED: win32 win64 osx linux32 freebsd32 freebsd64 LDC bool test_ltz(ubyte x) { return x < 0; } bool test_lez(ubyte x) { return x <= 0; } bool test_eqz(ubyte x) { return x == 0; } bool test_nez(ubyte x) { return x != 0; } bool test_gez(ubyte x) { return x >= 0; } bool test_gtz(ubyte x) { return x > 0; } bool test_ltz(byte x) { return x < 0; } bool test_lez(byte x) { return x <= 0; } bool test_eqz(byte x) { return x == 0; } bool test_nez(byte x) { return x != 0; } bool test_gez(byte x) { return x >= 0; } bool test_gtz(byte x) { return x > 0; } bool test_ltz(ushort x) { return x < 0; } bool test_lez(ushort x) { return x <= 0; } bool test_eqz(ushort x) { return x == 0; } bool test_nez(ushort x) { return x != 0; } bool test_gez(ushort x) { return x >= 0; } bool test_gtz(ushort x) { return x > 0; } bool test_ltz(short x) { return x < 0; } bool test_lez(short x) { return x <= 0; } bool test_eqz(short x) { return x == 0; } bool test_nez(short x) { return x != 0; } bool test_gez(short x) { return x >= 0; } bool test_gtz(short x) { return x > 0; } bool test_ltz(uint x) { return x < 0; } bool test_lez(uint x) { return x <= 0; } bool test_eqz(uint x) { return x == 0; } bool test_nez(uint x) { return x != 0; } bool test_gez(uint x) { return x >= 0; } bool test_gtz(uint x) { return x > 0; } bool test_ltz(int x) { return x < 0; } bool test_lez(int x) { return x <= 0; } bool test_eqz(int x) { return x == 0; } bool test_nez(int x) { return x != 0; } bool test_gez(int x) { return x >= 0; } bool test_gtz(int x) { return x > 0; } bool test_ltz(ulong x) { return x < 0; } bool test_lez(ulong x) { return x <= 0; } bool test_eqz(ulong x) { return x == 0; } bool test_nez(ulong x) { return x != 0; } bool test_gez(ulong x) { return x >= 0; } bool test_gtz(ulong x) { return x > 0; } bool test_ltz(long x) { return x < 0; } bool test_lez(long x) { return x <= 0; } bool test_eqz(long x) { return x == 0; } bool test_nez(long x) { return x != 0; } bool test_gez(long x) { return x >= 0; } bool test_gtz(long x) { return x > 0; } bool test_ltz(float x) { return x < 0; } bool test_lez(float x) { return x <= 0; } bool test_eqz(float x) { return x == 0; } bool test_nez(float x) { return x != 0; } bool test_gez(float x) { return x >= 0; } bool test_gtz(float x) { return x > 0; } bool test_ltz(double x) { return x < 0; } bool test_lez(double x) { return x <= 0; } bool test_eqz(double x) { return x == 0; } bool test_nez(double x) { return x != 0; } bool test_gez(double x) { return x >= 0; } bool test_gtz(double x) { return x > 0; } /* ----------------------------------- */ bool test_lt(ubyte x, ubyte y) { return x < y; } bool test_le(ubyte x, ubyte y) { return x <= y; } bool test_eq(ubyte x, ubyte y) { return x == y; } bool test_ne(ubyte x, ubyte y) { return x != y; } bool test_ge(ubyte x, ubyte y) { return x >= y; } bool test_gt(ubyte x, ubyte y) { return x > y; } bool test_lt(byte x, byte y) { return x < y; } bool test_le(byte x, byte y) { return x <= y; } bool test_eq(byte x, byte y) { return x == y; } bool test_ne(byte x, byte y) { return x != y; } bool test_ge(byte x, byte y) { return x >= y; } bool test_gt(byte x, byte y) { return x > y; } bool test_lt(ushort x, ushort y) { return x < y; } bool test_le(ushort x, ushort y) { return x <= y; } bool test_eq(ushort x, ushort y) { return x == y; } bool test_ne(ushort x, ushort y) { return x != y; } bool test_ge(ushort x, ushort y) { return x >= y; } bool test_gt(ushort x, ushort y) { return x > y; } bool test_lt(short x, short y) { return x < y; } bool test_le(short x, short y) { return x <= y; } bool test_eq(short x, short y) { return x == y; } bool test_ne(short x, short y) { return x != y; } bool test_ge(short x, short y) { return x >= y; } bool test_gt(short x, short y) { return x > y; } bool test_lt(uint x, uint y) { return x < y; } bool test_le(uint x, uint y) { return x <= y; } bool test_eq(uint x, uint y) { return x == y; } bool test_ne(uint x, uint y) { return x != y; } bool test_ge(uint x, uint y) { return x >= y; } bool test_gt(uint x, uint y) { return x > y; } bool test_lt(int x, int y) { return x < y; } bool test_le(int x, int y) { return x <= y; } bool test_eq(int x, int y) { return x == y; } bool test_ne(int x, int y) { return x != y; } bool test_ge(int x, int y) { return x >= y; } bool test_gt(int x, int y) { return x > y; } bool test_lt(ulong x, ulong y) { return x < y; } bool test_le(ulong x, ulong y) { return x <= y; } bool test_eq(ulong x, ulong y) { return x == y; } bool test_ne(ulong x, ulong y) { return x != y; } bool test_ge(ulong x, ulong y) { return x >= y; } bool test_gt(ulong x, ulong y) { return x > y; } bool test_lt(long x, long y) { return x < y; } bool test_le(long x, long y) { return x <= y; } bool test_eq(long x, long y) { return x == y; } bool test_ne(long x, long y) { return x != y; } bool test_ge(long x, long y) { return x >= y; } bool test_gt(long x, long y) { return x > y; } bool test_lt(float x, float y) { return x < y; } bool test_le(float x, float y) { return x <= y; } bool test_eq(float x, float y) { return x == y; } bool test_ne(float x, float y) { return x != y; } bool test_ge(float x, float y) { return x >= y; } bool test_gt(float x, float y) { return x > y; } bool test_lt(double x, double y) { return x < y; } bool test_le(double x, double y) { return x <= y; } bool test_eq(double x, double y) { return x == y; } bool test_ne(double x, double y) { return x != y; } bool test_ge(double x, double y) { return x >= y; } bool test_gt(double x, double y) { return x > y; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6777.d0000644000175000017500000000016514141774365023542 0ustar matthiasmatthiasstruct S {} class C { S s; alias s this; } void main() { auto c = new C; auto p = cast(void*) c; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b16967.d0000644000175000017500000000100014141774365023053 0ustar matthiasmatthias/* * REQUIRED_ARGS: -c * TEST_OUTPUT: --- compilable/b16967.d(16): Deprecation: switch case fallthrough - use 'goto default;' if intended compilable/b16967.d(26): Deprecation: switch case fallthrough - use 'goto default;' if intended --- */ int foo(int x) in { switch (x) { case 1: assert(x != 0); default: break; } } out(v) { switch(v) { case 42: assert(x != 0); default: break; } } do { return 42; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_tables.d0000644000175000017500000000163014141774365026373 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_tables.html // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_tables.html /++ # Tables | Rounding mode | rndint(4.5) | rndint(5.5) | rndint(-4.5) | Notes | | ------------- | ----------: | ----------: | -----------: | ----- | | Round to nearest | 4 | 6 | -4 | Ties round to an even number | | Round down | 4 | 5 | -5 |   | | Round up | 5 | 6 | -4 |   | | Round to zero | 4 | 5 | -4 |   | this|that ----|---- cell|cell
sell | abc | def | | --- | --- | | bar | | *bar* | baz | boo | > | quote | > | ----- | > | table | * | list | | ---- | | table | | default | left | center | right | | --- | :-- | :--: | --: | Look Ma, a table without a body! | not | a | table | | -- | | wrong number of header columns | +/ module test.compilable.ddoc_markdown_tables; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_257.d0000644000175000017500000000017314141774365024730 0ustar matthiasmatthiasclass Baz { this(Bar[] a) {} } class Foo { Bar[] foo(){ return []; } } class Bar { Foo bar(){ return null; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test12624.d0000644000175000017500000000077014141774365023610 0ustar matthiasmatthias// REQUIRED_ARGS: -lib -Icompilable/extra-files // EXTRA_FILES: extra-files/imp12624.d // https://issues.dlang.org/show_bug.cgi?id=12624 struct SysTime { import imp12624; Rebindable!(immutable TimeZone) _timezone = UTC(); } class TimeZone { this(string , string , string ) immutable {} } class UTC : TimeZone { static immutable(UTC) opCall() { return _utc; } this() immutable { super("UTC", "UTC", "UTC"); } static _utc = new immutable(UTC); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19266.sh0000644000175000017500000000031014141774365023776 0ustar matthiasmatthias#!/usr/bin/env bash if [ "${OS}" == "windows" ]; then # break out of bash to get Windows paths cmd //c $(echo $DMD | tr / \\) -c \\\\.\\%CD%\\compilable\\extra-files\\test19266.d -deps=nul: fi ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19754.d0000644000175000017500000000143714141774365023624 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19754 void test19754() { shared int x; static assert((cast(int*) &x) == &(cast() x)); (cast() x) = 5; (cast() x) += 3; const int x1; static assert(&x1 == &(cast() x1)); (cast() x1) = 5; (cast() x1) *= 3; immutable int x2; static assert(&x2 == &(cast() x2)); (cast() x2) = 5; (cast() x2) &= 3; int[4] a; (cast(long[2]) a)[0] = 5; (cast(long[2]) a)[0] += 3; static if (is(__vector(int[4]))) { __vector(int[4]) v; (cast(int[4]) v)[0] = 5; (cast(int[4]) v)[0] += 3; } } // https://issues.dlang.org/show_bug.cgi?id=20608 void foo(T...)(auto ref T args) {} struct Tuple { int expand; } void test20608() { enum tup = Tuple(); foo(tup.expand); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testDIP37_10354.d0000644000175000017500000000056414141774365024455 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -o- -Icompilable/extra-files // EXTRA_FILES: extra-files/pkgDIP37_10354/mbar.d // EXTRA_FILES: extra-files/pkgDIP37_10354/mfoo.d // EXTRA_FILES: extra-files/pkgDIP37_10354/package.d module testDIP37_10354; import pkgDIP37_10354.mfoo; void main() { import pkgDIP37_10354; foo!string(); // OK bar!string(); // OK <- ICE } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test13858.d0000644000175000017500000000037114141774365023617 0ustar matthiasmatthias// REQUIRED_ARGS: -w // https://issues.dlang.org/show_bug.cgi?id=13858 void foo() { assert(0); } void main() { int x = 0; LSwitch: switch (x) { case 0: break LSwitch; default: return; } foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test11720.d0000644000175000017500000000125614141774365023604 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=11720 void test11720() { foo(); bar(); } alias TypeTuple(T...) = T; void foo()() { foreach (T; TypeTuple!(int, double)) { static temp = T.stringof; } } void bar() { foreach (T; TypeTuple!(int, double)) { static temp = T.stringof; } } /*********************************************/ // https://issues.dlang.org/show_bug.cgi?id=18266 void test18266() { foreach (i; 0 .. 10) { struct S { int x; } auto s = S(i); } foreach (i; 11 .. 20) { struct S { int y; } auto s = S(i); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17819.d0000644000175000017500000000071514141774365023622 0ustar matthiasmatthiasstatic if (__traits(allMembers, __traits(parent,{}))[0]=="object") { enum test = 0; } static foreach (m; __traits(allMembers, __traits(parent,{}))) { mixin("enum new"~m~"=`"~m~"`;"); } static assert([__traits(allMembers, __traits(parent,{}))] == ["object", "test", "newobject", "newWorld", "newBuildStuff", "World", "BuildStuff"]); struct World { mixin BuildStuff; } template BuildStuff() { static foreach(elem; __traits(allMembers, typeof(this))) {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_256.d0000644000175000017500000000010514141774365024722 0ustar matthiasmatthiasbool foo(void delegate() a, void delegate() b) { return a < b; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test11137.d0000644000175000017500000000011214141774365023574 0ustar matthiasmatthias// REQUIRED_ARGS: -ofC:\test.exeC:\test.exe module test; void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/interpret5.d0000644000175000017500000000076514141774365024337 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21927 /* TEST_OUTPUT: --- T1(Args...) T1!() T2(Args2...) T2!() this.T2(Args2...) this.T2!() --- */ template T1(Args...) {} pragma(msg, T1); // TOK.template_ pragma(msg, T1!()); // TOK.scope_ struct S { template T2(Args2...) {} pragma(msg, S.T2); // TOK.template_ pragma(msg, S.T2!()); // TOK.scope_ void fun() { pragma(msg, this.T2); // TOK.dotTemplateDeclaration pragma(msg, this.T2!()); // TOK.dot } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test55.d0000644000175000017500000000041214141774365023354 0ustar matthiasmatthias// COMPILE_SEPARATELY // COMPILED_IMPORTS: imports/test55a.d // PERMUTE_ARGS: -dw // REQUIRED_ARGS: -d public import imports.test55a; class Queue { alias int ListHead; Arm a; } class MessageQueue : Queue { } class Queue2 { alias int ListHead; Arm2 a; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue16472.d0000644000175000017500000000147614141774365023772 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=16472 enum e() = 0; template t(alias v = e!()) {} //Error alias dummy = t!(e!()); template E(F){ enum E { K = F(1) } } struct S(F = float, alias e_ = E!double.K) {} S!float x; // Error: E!double.K is used as a type alias T = E!double.K; struct S2(F = float, alias e_ = T) {} S2!float y; // alias makes it okay... struct S3(F = float, alias e_ = (E!double.K)) {} S3!float z; // just putting parens make it okay as well... wat!? // for coverage template G(T) { struct G { alias I = int; static int i; } } struct H(F = float, alias e_ = G!double) {} H!float a; struct H1(F = float, alias e_ = G!double.I) {} H1!float b; // https://issues.dlang.org/show_bug.cgi?id=21795 // struct H2(F = float, alias e_ = G!double.i) {} // H2!float c; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21794.d0000644000175000017500000000174014141774365023616 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21794 /* TEST_OUTPUT: --- 0 0u 0L 0LU 0.0F 0.0 0.0L --- */ bool fun(void* p) { const x = cast(ulong)p; return 1; } static assert(fun(null)); T fun2(T)(void* p) { const x = cast(T)p; return x; } // These were an error before, they were returning a NullExp instead of IntegerExp/RealExp static assert(fun2!int(null) == 0); static assert(fun2!uint(null) == 0); static assert(fun2!long(null) == 0); static assert(fun2!ulong(null) == 0); static assert(fun2!float(null) == 0); static assert(fun2!double(null) == 0); static assert(fun2!real(null) == 0); // These were printing 'null' instead of the corresponding number const i = cast(int)null; const ui = cast(uint)null; const l = cast(long)null; const ul = cast(ulong)null; const f = cast(float)null; const d = cast(double)null; const r = cast(real)null; pragma(msg, i); pragma(msg, ui); pragma(msg, l); pragma(msg, ul); pragma(msg, f); pragma(msg, d); pragma(msg, r); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16460.d0000644000175000017500000000035114141774365023605 0ustar matthiasmatthias// EXTRA_FILES: imports/imp16460.d module imports.test16460; void bug() { auto d1 = (){ import imports.imp16460; return val; }; enum d2 = (){ import imports.imp16460; return val; }; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15907.d0000644000175000017500000000062214141774365023613 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/imp15907.d // PERMUTE_ARGS: import imports.imp15907; struct S { private int a; } void test() { process(S()); } static assert(allMembers!S == ["a"]); enum sz = __traits(getMember, imports.imp15907, "PrivateStruct").sizeof; static assert(__traits(hasMember, imports.imp15907, "privateVar")); typeof(__traits(getMember, PublicStruct, "S").init) s; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15464.d0000644000175000017500000000026714141774365023616 0ustar matthiasmatthiasclass C15464 { static immutable field = 0; } struct S15464 { this(int i) { } } void issue15464(T)() @S15464(T.field) { } void main() { issue15464!C15464(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice15333.d0000644000175000017500000000031114141774365023360 0ustar matthiasmatthias// EXTRA_SOURCES: imports/a15333.d module ice15333; void map(alias fun)() {} struct IdentifierResolver(alias handler) { void resolve() { map!((a) {}); handler(true); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix22322.c0000644000175000017500000000016014141774365023403 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22322 struct S { float f; double d; long double ld; }; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_verbose.d0000644000175000017500000000661014141774365024714 0ustar matthiasmatthias/* REQUIRED_ARGS: -HC=verbose -o- -Icompilable/extra-files PERMUTE_ARGS: EXTRA_FILES: extra-files/dtoh_imports.d extra-files/dtoh_imports2.d TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler v$n$ #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif extern void importFunc(); // Ignored function dtoh_verbose.foo because of linkage // Ignored variable dtoh_verbose.i because of linkage // Ignored function dtoh_verbose.bar because of linkage // Ignored struct dtoh_verbose.S because of linkage // Ignored class dtoh_verbose.C because of linkage // Ignored function dtoh_verbose.bar because it is extern // Ignored variable dtoh_verbose.i1 because of linkage // Ignored template dtoh_verbose.templ(T)(T t) because of linkage // Ignored alias dtoh_verbose.inst because of linkage // Ignored enum dtoh_verbose.arrayOpaque because of its base type // Ignored renamed import `myFunc = importFunc` because `using` only supports types struct A final { // Ignored renamed import `myFunc = importFunc` because `using` only supports types A() { } }; struct Hidden final { // Ignored function dtoh_verbose.Hidden.hidden because it is private Hidden() { } }; // Ignored alias dtoh_verbose.D because of linkage class Visitor { public: virtual void stat(); // Ignored dtoh_verbose.Visitor.bar because `using` cannot rename functions in aggregates // Ignored dtoh_verbose.Visitor.unused because free functions cannot be aliased in C++ }; extern void unused(); // Ignored variable dtoh_verbose.and because its name is a special operator in C++ template struct FullImportTmpl final { // Ignored `dtoh_imports` because it's inside of a template declaration FullImportTmpl() { } }; template struct SelectiveImportsTmpl final { // Ignored `__anonymous` because it's inside of a template declaration SelectiveImportsTmpl() { } }; --- */ void foo() {} extern (D) { int i; } void bar(); struct S {} class C {} extern(C++) void bar(); int i1; void templ(T)(T t) {} alias inst = templ!int; extern(C++) enum arrayOpaque : int[4]; public import dtoh_imports : myFunc = importFunc; extern(C++) struct A { public import dtoh_imports : myFunc = importFunc; } extern(C++) struct Hidden { private void hidden() {} } private { enum PI = 4; } alias D = size_t delegate (size_t x); extern(C++) T foo(T) = T.init; extern(C++) class Visitor { void stat() {} // Ignored because those cannot be represented in C++ alias bar = stat; alias unused = .unused; } extern(C++) void unused() {} extern(C++) __gshared bool and; extern(C++) struct FullImportTmpl(T) { public import dtoh_imports; } extern(C++) struct SelectiveImportsTmpl(T) { public import dtoh_imports : importFunc, aliasName = ImportsC; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test1673.d0000644000175000017500000000251214141774365023526 0ustar matthiasmatthiasmodule test1673; template Foo(T...) { } template Bar(T...) { template Doo(T...) { } } template Tuple(T...) { alias Tuple = T; } void main() { static assert( __traits(isTemplate, Foo)); static assert(!__traits(isTemplate, Foo!int)); static assert(!__traits(isTemplate, main)); static assert( __traits(isTemplate, Bar)); static assert(!__traits(isTemplate, Bar!int)); static assert( __traits(isTemplate, Bar!(int).Doo)); static assert(!__traits(isTemplate, Bar!(int).Doo!int)); alias Tup = Tuple!(Foo, Foo!int, Bar, Bar!int, Bar!(int).Doo, Bar!(int).Doo!int); static assert( __traits(isTemplate, Tup[0])); static assert(!__traits(isTemplate, Tup[1])); static assert( __traits(isTemplate, Tup[2])); static assert(!__traits(isTemplate, Tup[3])); static assert( __traits(isTemplate, Tup[4])); static assert(!__traits(isTemplate, Tup[5])); } /// test overloads void foo_over() { } void foo_over(T : int)(T) { } void foo_over(T : float)(T) { } static assert(__traits(isTemplate, foo_over)); /// ditto void bar_over() { } void bar_over(int) { } static assert(!__traits(isTemplate, bar_over)); /// alias to overloads alias a_foo_over = foo_over; static assert(__traits(isTemplate, a_foo_over)); /// ditto alias a_bar_over = bar_over; static assert(!__traits(isTemplate, a_bar_over)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc198.d0000644000175000017500000000071114141774365023400 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc198.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc198; /// interface I1 { } /// class C1 { } /// class Foo : C1, I1 { } /// enum X { x = 1 } /// enum Y : X { y = X.x } /// struct S1 { } /// enum enS : S1 { a = S1() } // disabled until class enums are possible // enum enC : C1 { a = new C1() } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16088.d0000644000175000017500000000030214141774365023607 0ustar matthiasmatthias// REQUIRED_ARGS: -Jcompilable/imports/ // EXTRA_FILES: imports/imp16088.d // https://issues.dlang.org/show_bug.cgi?id=16088 void bar(string x) {} auto foo() { import("imp16088.d").bar; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b21285.d0000644000175000017500000000124714141774365023055 0ustar matthiasmatthias// REQUIRED_ARGS: -unittest // Issue 21285 - Delegate covariance broken between 2.092 and 2.094 (git master). unittest { string path; int bank; static string path2; static int bank2; // delegates auto a = [ (string arg) { path = arg; }, (string arg) { bank = 1; throw new Exception(""); } ]; // functions auto ab = [ (string arg) { path2 = arg; }, (string arg) { bank2 = 1; throw new Exception(""); } ]; alias dg = void delegate(string) pure @safe; alias fn = void function(string) @safe; static assert(is(typeof(a[0]) == dg)); static assert(is(typeof(ab[0]) == fn)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix20416.d0000644000175000017500000000066114141774365023414 0ustar matthiasmatthias/* REQUIRED_ARGS: -preview=dip1000 */ /********************************************/ // https://issues.dlang.org/show_bug.cgi?id=20416 alias P = int*; ref P foo(return ref P); P bar() { P result; return foo(result); } /********************************************/ // https://issues.dlang.org/show_bug.cgi?id=20416 struct S { string x; ref S foo() return; } S bar2() { S result; return result.foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b19432.d0000644000175000017500000000016114141774365023050 0ustar matthiasmatthias void main(){ enum a = 18446744073709551615; // 2^^64 - 1 ulong b = 18446744073709551615; // 2^^64 - 1 } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17970.d0000644000175000017500000000045714141774365023623 0ustar matthiasmatthiasshared struct Shared { static Shared make() { return Shared(); } ~this() { } } shared struct Foo { ~this() { } } struct Inner { ~this() {} } struct Outer { shared(Inner) inner; } void main() { Foo x = Foo(); auto s = Shared.make(); Outer _; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/scope.d0000644000175000017500000000677614141774365023357 0ustar matthiasmatthias/* REQUIRED_ARGS: -preview=dip1000 */ struct Cache { ubyte[1] v; ubyte[] set(ubyte[1] v) return { return this.v[] = v[]; } } /*********************************/ // https://github.com/dlang/dmd/pull/9220 @safe: struct OnlyResult { private this(Values)(scope ref Values values) { this.s = values; } string s; } auto only(Values)(Values vv) { return OnlyResult(vv); } void test() @nogc @safe pure { only(null); } /************************************/ // https://github.com/dlang/dmd/pull/9220 auto callWrappedOops(scope string dArgs) { string callWrappedImpl() { return dArgs; } } /************************************/ struct Constant { int* member; this(Repeat!(int*) grid) @safe { foreach(ref x; grid) member = x; foreach(ref x; grid) x = member; } int* foo(return scope Repeat!(int*) grid) @safe { foreach(ref x; grid) x = member; foreach(ref x; grid) return x; return null; } alias Repeat(T...) = T; } /************************************/ // https://issues.dlang.org/show_bug.cgi?id=19387 struct C { void* u; this(this) @safe { } } struct S { C c; } void foo(scope S s) @safe { } void bar(scope S s) @safe { foo(s); } /************************************/ // https://issues.dlang.org/show_bug.cgi?id=20675 struct D { int pos; char* p; } void test(scope ref D d) @safe { D[] da; da ~= D(d.pos, null); } /************************************/ void withEscapes() { static D get() @safe; with (get()) { } } /************************************/ // https://issues.dlang.org/show_bug.cgi?id=20682 int f1_20682(return scope ref D d) @safe { return d.pos; } ref int f2_20682(return scope ref D d) @safe { return d.pos; } void test_20682(scope ref D d) @safe { int[] a; a ~= f1_20682(d); a ~= f2_20682(d); a ~= cast(int) d.p; } // Phobos failure void formattedWrite(immutable char[2] args) @safe { scope immutable char[] val = args; } void ctfeRead(const ubyte[2] array) @safe { short result; foreach_reverse (b; array) result = cast(short) ((result << 8) | b); foreach (b; array) result = cast(short) ((result << 8) | b); } void demangle() @safe { static struct DotSplitter { const(char)[] s; @safe: @property bool empty() const { return !s.length; } @property const(char)[] front() const return { immutable i = indexOfDot(); return s; } void popFront() {} private ptrdiff_t indexOfDot() const { return -1; } } foreach (comp; DotSplitter("")) { const copy = comp; } } void fileCtor() @safe { static struct S { int i; } // static S get() // { // return S(); // } with (S()) { int* ptr = &i; } } // Missing test coverage int*[4] testArray() @safe { return typeof(return).init; } /************************************/ // https://issues.dlang.org/show_bug.cgi?id=21209 void testForeach(T)(const(T)[] ts) { static int g; g++; // force impure for https://issues.dlang.org/show_bug.cgi?id=20150 foreach (c; ts) { } foreach_reverse(c0; ts) { foreach(c1; ts) { } } } @safe void main21209() { char[10] cs; float[10] fs; testForeach(cs); testForeach(fs); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19954.d0000644000175000017500000000033114141774365023616 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19954 template AliasSeq(TList...) { alias AliasSeq = TList; } void fun(string[]){} void main() { fun(cast(string[])AliasSeq!""); auto a = cast(char[][])""; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9435.d0000644000175000017500000000036614141774365023537 0ustar matthiasmatthias// EXTRA_FILES: test9434.d import test9434;//expression; enum TokenType { Dot } template Tok(string type) { enum Tok = TokenType.Dot; } template Semantic(T) { invariant(){} } template Semantic(T) if (is(T == BinaryExp!(Tok!"."))) { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test7172.d0000644000175000017500000000150214141774365023524 0ustar matthiasmatthiasvoid main() { abstract class AbstractC{} static assert(!__traits(compiles, { new AbstractC(); })); final class FinalC{} static assert(!__traits(compiles, { class D : FinalC{} })); scope class ScopeC{} // static assert(!__traits(compiles, { auto sc = new ScopeC(); })); static assert( __traits(compiles, { scope sc = new ScopeC(); })); synchronized class SyncC{ void f(){} } static assert(SyncC.f.mangleof[$-13..$] == "5SyncC1fMOFZv"); @safe class SCx{ void f(){} } @trusted class SCy{ void f(){} } @system class SCz{ void f(){} } static assert(SCx.f.mangleof[$-12..$] == "3SCx1fMFNfZv"); // Nf: FuncAttrSafe static assert(SCy.f.mangleof[$-12..$] == "3SCy1fMFNeZv"); // Ne: FuncAttrTrusted static assert(SCz.f.mangleof[$-10..$] == "3SCz1fMFZv"); // (none) } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20388.d0000644000175000017500000000027014141774365023611 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20388 void main() { foo!(mixin("(int a) { return a; }"))(); foo!(mixin("1+1"))(); foo!(mixin(0))(); } void foo(alias t)() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test13194.d0000644000175000017500000000023614141774365023610 0ustar matthiasmatthiasmodule test13194; class C13194 { static Object o = void; } struct S13194 { static Object o = void; } union U13194 { static Object o = void; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18775.d0000644000175000017500000000045314141774365023623 0ustar matthiasmatthias// REQUIRED_ARGS: -de struct Foo { } struct Bar { deprecated @property Foo foo() { return Foo.init; } alias foo this; } void test(Bar bar) { } void main() { Bar bar; // test lookup will be satisfied via ufcs, not alias, so it must not deprecation warn foo! bar.test; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_quote.d0000644000175000017500000000266414141774365026266 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_quote.html // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_quote.html /++ # Quote Blocks > “It seems to me that most of the ‘new’ programming languages fall into one of two categories: Those from academia with radical new paradigms and those from large corporations with a focus on RAD and the web. Maybe it’s time for a new language born out of practical experience implementing compilers.” -- Michael > Great, just what I need.. another D in programming. -- Segfault > To D, or not to D. -- Willeam NerdSpeare > "What I am going to tell you about is what we teach our programming students in the third or fourth year of graduate school... It is my task to convince you not to turn away because you don't understand it. You see my programming students don't understand it... That is because I don't understand it. Nobody does." -- Richard Deeman Here's a bit of text between quotes. > This is a quote > > And this is a nested quote > This is a quote with a > symbol in it > This is a quote with a continuation > This quote - is ended by this list > This quote ### is ended by this heading > This quote is ended by a thematic break: ____ > This quote ``` is ended by this code ``` > ### Some things inside a quote block: > ___ > --- > Some code > --- > - a list +/ module test.compilable.ddoc_markdown_code; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17752.d0000644000175000017500000000036614141774365023620 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=17752 // REQUIRED_ARGS: -de void main (string[] args) { switch (args.length) { // initialization not done on purpose is allowed int x = void; default: break; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17215.d0000644000175000017500000000017014141774365023603 0ustar matthiasmatthias// REQUIRED_ARGS: -O version (X86_64): alias vec = __vector(int[4]); vec binop(vec a) { vec b = a; return b; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20296.d0000644000175000017500000000016314141774365023610 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20296 extern (C++) void foo(T...)(T args) { } alias F = foo!(char*); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc7715.d0000644000175000017500000000037714141774365023472 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc7656; /** $1 $2 --- string s = "$1$2 $ $4"; --- */ void foo(){} /// void test(string a = ")") {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fieldwise.d0000644000175000017500000000032614141774365024202 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=dip1000 -preview=fieldwise // EXTRA_FILES: imports/impfieldwise.d import imports.impfieldwise; @safe: bool test(S s, S t) { return s == t; // comparison can access fields for == } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19750.d0000644000175000017500000000032714141774365023615 0ustar matthiasmatthias// REQUIRED_ARGS: -Icompilable/imports // EXTRA_FILES: imports/test19750a.d imports/test19750b.d imports/test19750c.d imports/test19750d.d import test19750b; class Foo { import test19750a; void func (Bar ) {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testDIP37_10302.d0000644000175000017500000000042314141774365024440 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -Icompilable/extra-files // COMPILED_IMPORTS: extra-files/pkgDIP37_10302/liba.d // COMPILED_IMPORTS: extra-files/pkgDIP37_10302/libb.d // EXTRA_FILES: extra-files/pkgDIP37_10302/package.d module test; import pkgDIP37_10302; void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17146.d0000644000175000017500000000027514141774365023614 0ustar matthiasmatthias// REQUIRED_ARGS: -O -inline // https://issues.dlang.org/show_bug.cgi?id=17146 struct S { int[] a; int b; } void foo() { S[] s; if (s[$-1] == S.init) {} } void bar() { foo(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice10770.d0000644000175000017500000000015314141774365023364 0ustar matthiasmatthiasenum E1 : int; static assert(is(E1 e == enum) && is(e == int)); enum E2; static assert(is(E2 e == enum)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8922f.d0000644000175000017500000000062614141774365023704 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/bug8922.d void test() { import renamed = imports.bug8922; enum x = __traits(parent, renamed).stringof; static assert(x == "package imports"); static assert(!__traits(compiles, __traits(parent, imports))); static assert(!__traits(compiles, __traits(parent, bug8922))); static assert(!__traits(compiles, __traits(parent, imports.bug8922))); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/a3682.d0000644000175000017500000000057114141774365022774 0ustar matthiasmatthias// COMPILED_IMPORTS: imports/b3682.d // PERMUTE_ARGS: // https://issues.dlang.org/show_bug.cgi?id=3682 struct Tuple(Types...) { Tuple!(Types[0..1]) slice()() { Tuple!(Types[0..1]) x; return x; } void fail() { Tuple!(float, double, int) a; auto s = a.slice(); static assert(is(typeof(s) == Tuple!(float))); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6319.d0000644000175000017500000000016414141774365023531 0ustar matthiasmatthias// REQUIRED_ARGS: -debug int x; void main() pure { debug { { x = 0; } } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/vcg-ast-arraylength.d0000644000175000017500000000107514141774365026113 0ustar matthiasmatthiasmodule vcg_ast_arraylength; // REQUIRED_ARGS: -vcg-ast -o- // PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/vcg-ast-arraylength-postscript.sh void main() { int[] arr = [1, 2, 3]; // may use runtime call arr.length = 100; // should convert to arr = arr[0 .. 0]; arr.length = 0; // https://issues.dlang.org/show_bug.cgi?id=21678 int[] f; int[] a; a.length = f.length = 0; const x = 0; a.length = f.length = x; static assert(is(typeof(a.length = 0) == size_t)); static assert(is(typeof(a.length = f.length = 0) == size_t)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_code_verbose.d0000644000175000017500000000050114141774365027554 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- -transition=vmarkdown // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_code_verbose.html // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_code_verbose.html /++ Code: ``` ruby red RWBY ``` +/ module test.compilable.ddoc_markdown_code_verbose; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21330.d0000644000175000017500000000055214141774365023600 0ustar matthiasmatthias/* REQUIRED_ARGS: -unittest TEST_OUTPUT: --- tuple(__unittest_L14_C5_1, __unittest_L14_C5_2) tuple(__unittest_L14_C5_2) --- */ // https://issues.dlang.org/show_bug.cgi?id=21330 module test21330; mixin template Test() { unittest { } } mixin Test; mixin Test tm; pragma(msg, __traits(getUnitTests, test21330)); pragma(msg, __traits(getUnitTests, tm)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test11225a.d0000644000175000017500000000020314141774365023734 0ustar matthiasmatthias/* EXTRA_FILES: imports/test11225b.d imports/test11225c.d TEST_OUTPUT: --- WORKS --- */ import imports.test11225b; interface I {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testlibmain.d0000644000175000017500000000007014141774365024536 0ustar matthiasmatthias// REQUIRED_ARGS: -lib // PERMUTE_ARGS: void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15618.d0000644000175000017500000000044414141774365023614 0ustar matthiasmatthiasclass Base { ~this() {} size_t x = 4; } interface Interface { int Method(); } class Derived : Base, Interface { size_t y = 5; int Method() { return 3; } } static assert(Derived.x.offsetof == (void*).sizeof * 2); static assert(Derived.y.offsetof == (void*).sizeof * 4); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b12504.d0000644000175000017500000000217214141774365023045 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=12504 void main() { { int[0xFF + 1] sta; foreach (ubyte i; 0 .. sta.length) {} foreach (ubyte i, x; sta) {} } { int[0x7F + 1] sta; foreach (byte i; 0 .. sta.length) {} foreach (byte i, x; sta) {} } { int[0xFFFF + 1] sta; foreach (ushort i; 0 .. sta.length) {} foreach (ushort i, x; sta) {} } { int[0x7FFF + 1] sta; foreach (short i; 0 .. sta.length) {} foreach (short i, x; sta) {} } { immutable int[0xFF + 1] sta; static foreach (ubyte i; 0 .. sta.length) {} static foreach (ubyte i, x; sta) {} } { immutable int[0x7F + 1] sta; static foreach (byte i; 0 .. sta.length) {} static foreach (byte i, x; sta) {} } { immutable int[0xFFFF + 1] sta; static foreach (ushort i; 0 .. sta.length) {} static foreach (ushort i, x; sta) {} } { immutable int[0x7FFF + 1] sta; static foreach (short i; 0 .. sta.length) {} static foreach (short i, x; sta) {} } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9029.d0000644000175000017500000000151414141774365023532 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=9029 enum NameOf(alias S) = S.stringof; static assert(NameOf!int == "int"); enum BothMatch(alias S) = "alias"; enum BothMatch(T) = "type"; void foo9029() { } struct Struct { } static assert(BothMatch!int == "type"); static assert(BothMatch!(void function()) == "type"); static assert(BothMatch!BothMatch == "alias"); static assert(BothMatch!Struct == "type"); static assert(BothMatch!foo9029 == "alias"); static assert(BothMatch!5 == "alias"); // https://issues.dlang.org/show_bug.cgi?id=19884 mixin template genCtEvaluate() { void evaluate(alias op)() { } } struct S { mixin genCtEvaluate!() mixinEval; alias evaluate = mixinEval.evaluate; void evaluate() { } } alias List(Ops...) = Ops; void main() { S g; foreach (op; List!(0)) { g.evaluate!op(); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b16346.d0000644000175000017500000000013214141774365023047 0ustar matthiasmatthiasenum A { B } static assert(is(typeof(A.B) == A)); static assert(is(typeof(A(A.B)) == A)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20661.d0000644000175000017500000000053614141774365023610 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20661 class Context { size_t[const(Key)] aa; /* Error: AA key type Key does not have bool opEquals(ref const Key) const */ bool* checkAll; } struct Key { Context context; bool opEquals(ref const Key other) @safe const { auto c = context.checkAll; return true; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc9305.d0000644000175000017500000000444214141774365023464 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc9305; /** foo() */ void foo(alias p = (a => a))() {} /* ret / prm / body */ /* _ / _ / expr */ template X(alias pred = x => x) {} /// /* _ / _ / stmt */ template X(alias pred = (x){ int y; return y; }) {} /// ditto /* _ / x / expr */ template X(alias pred = (int x) => x) {} /// ditto /* _ / x / stmt */ template X(alias pred = (int x){ int y; return y; }) {} /// ditto /* x / _ / expr */ /* x / _ / stmt */ /* x / x / expr */ /* x / x / stmt */ /* _ / _ / expr */ template X(alias pred = function (x) => x) {} /// /* _ / _ / stmt */ template X(alias pred = function (x){ return x + 1; }) {} /// ditto /* _ / x / expr */ template X(alias pred = function (int x) => x) {} /// ditto /* _ / x / stmt */ template X(alias pred = function (int x){ return x + 1; }) {} /// ditto /* x / _ / expr */ template X(alias pred = function int(x) => x) {} /// ditto /* x / _ / stmt */ template X(alias pred = function int(x){ return x + 1; }) {} /// ditto /* x / x / expr */ template X(alias pred = function int(int x) => x) {} /// ditto /* x / x / stmt */ template X(alias pred = function int(int x){ return x + 1; }) {} /// ditto /* _ / _ / expr */ template X(alias pred = delegate (x) => x) {} /// /* _ / _ / stmt */ template X(alias pred = delegate (x){ return x + 1; }) {} /// ditto /* _ / x / expr */ template X(alias pred = delegate (int x) => x) {} /// ditto /* _ / x / stmt */ template X(alias pred = delegate (int x){ return x + 1; }) {} /// ditto /* x / _ / expr */ template X(alias pred = delegate int(x) => x) {} /// ditto /* x / _ / stmt */ template X(alias pred = delegate int(x){ return x + 1; }) {} /// ditto /* x / x / expr */ template X(alias pred = delegate int(int x) => x) {} /// ditto /* x / x / stmt */ template X(alias pred = delegate int(int x){ return x + 1; }) {} /// ditto ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testcstuff2.c0000644000175000017500000003002114141774365024475 0ustar matthiasmatthias// check bugs in the expression parser // DISABLED: LDC // unsupported initializer lists /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21931 typedef long int T21931a; typedef T21931a T21931b; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21933 struct S21933 { void *opaque; }; int test21933(struct S21933 *); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21934 typedef int T21934 asm("realtype"); int init21934 asm("realsym") = 1; int var21934 asm("realvsym"); int fun21934() asm("realfun"); void test21934() { typedef int asmreg; register asmreg r1 asm("r1"); // asm ignored by C compiler, should be disallowed? asmreg r2 asm("r2"); register asmreg r3 asm("r3") = 3; // asm ignored by C compiler, should be disallowed? asmreg r4 asm("r4") = 4; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21937 __attribute__(()) int test21937a(); int test21937b() __attribute__(( , nothrow, hot, aligned(2), )); int test21937c() __attribute__((nothrow , leaf)) __attribute__((noreturn)); __attribute__((noinline)) void test21937d() { typedef int attr_var_t; attr_var_t attr_local __attribute__((unused)); } __attribute__((aligned)) int test21937e; int test21937f __attribute__((aligned)); struct __attribute__((packed)) S21937a { __attribute__((deprecated("msg"))) char c; int i __attribute__((deprecated)); }; struct S21937b { __attribute__((deprecated("msg"))) char c; int i __attribute__((deprecated)); } __attribute__((packed)); enum __attribute__((aligned)) E21937a { E21937a_A, }; enum E21937b { E21937b_A, } __attribute__((aligned)); typedef int T21937a __attribute__((unused)); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21945 typedef struct { long var; } S21945; S21945 test21945a; typedef enum { E21945_member, } E21945; E21945 test21945b; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21948 void test21948() { typedef int myint; typedef struct { int f; } mystruct; myint var1; myint var2 = 12; mystruct var3; // Uncomment when bug fixed https://issues.dlang.org/show_bug.cgi?id=21979 //mystruct var4 = { 34 }; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21963 union U21963 { int iv; float fv; }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21965 struct { int var; }; typedef struct { int var; }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21967 const int test21967a(void); const int *test21967b(void); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21968 struct S21968 { struct inner *data[16]; }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21970 extern int test21970a; extern char *test21970b; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21973 struct S21973 { int field; struct { int nested; }; }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21977 int test21977a; _Thread_local int test21977b; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21982 struct S21982 { int field; }; struct S21982 test21982; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21992 void test21992(int var) { var = (var) & 1234; var = (var) * 1234; var = (var) + 1234; var = (var) - 1234; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22028 struct S22028 { struct nested { int field; }; const int cfield; _Static_assert(1 == 1, "ok"); }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22060 struct S22060; typedef struct S22060 T22060a; struct S22060; typedef struct S22060 T22060b; struct S22060; struct S22060 { int _flags; }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22061 union S22061 { int field; }; typedef union S22061 S22061; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22063 typedef struct S22063_t { int field; } S22063; void test22063() { // BUG: no definition of struct //struct S22063_t v1 = { 0 }; // BUG: cannot implicitly cast from integer to pointer. struct S22063_t *v2 = (struct S22063_t *)0; S22063 v3 = { 0 }; S22063 *v4 = (S22063 *)0; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22066 void test22066() { int var = 0; (var)++; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22067 void test22067() { union U { int value; char *ptr; char array[4]; } var; union U *pvar = &var; var.value = 0xabcdef; var.array[0]++; (*var.ptr)--; ++(*pvar).value; --(*pvar).array[3]; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22073 struct S22073a { int field; }; struct S22073b { const char *field; }; _Static_assert((struct S22073a){6789}.field == 6789, "ok"); _Static_assert((struct S22073b){"zxcv"}.field[2] == 'c', "ok"); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22079 struct S22079 { int a, b, c; }; _Static_assert(sizeof(struct S22079){1,2,3} == sizeof(int)*3, "ok"); _Static_assert(sizeof(struct S22079){1,2,3}.a == sizeof(int), "ok"); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22080 int F22080(const char *); int test22080() { int (*fun)(const char *) = &F22080; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22086 typedef union U22086 U22086; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22088 void test22088() { int *p; int i; p = i; i = p; void *pv; p = pv; pv = p; long long ll; ll = i; i = ll; char c; c = i; i = c; float f; f = i; i = f; double d; d = i; i = d; long double ld; ld = i; i = ld; c = ld; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22102 void fun22102(int var); typedef int int22102; void test22102() { int22102(var); fun22102(var); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22103 void test22103a(char *const argv[restrict]); void test22103b(char *const argv[restrict 4]); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22106 typedef struct S22106 { int field; } S22106_t; struct T22106 { struct S22106 f1; S22106_t f2; }; void testS22106() { struct S22106 v1; S22106_t v2; } int S22106; // not a redeclaration of 'struct S22106' /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22160 typedef struct testcstuff2 testcstuff2; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22182 int test22182a(int x) { return (int)(x); } typedef struct S22182 { int x; } S22182; int test22182b(S22182* b) { return ((S22182*)(b))->x; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22196 __attribute__((static, unsigned, long, const, extern, register, typedef, short, inline, _Noreturn, volatile, signed, auto, restrict, _Complex, _Thread_local, int, char, float, double, void, _Bool, _Atomic)) int test22196(); /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22245 struct S22245 { int i; }; int test22245() { struct S22245 s; return sizeof(s.i); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22262 void test22262(unsigned char *buf) { if (buf == 0) return; if (0 == buf) return; if (buf == 1) return; if (2 == buf) return; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22264 typedef int T22264; unsigned long test22264(crc, buf, len) unsigned long crc; const T22264 *buf; T22264 len; { return len; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22274 void test22274(compr, comprLen, uncompr, uncomprLen) unsigned *compr, *uncompr; signed comprLen, uncomprLen; { } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22375 typedef struct S22375S { unsigned short a, b, c, d; } S22375; static const S22375 s22375[10] = { {0, 0, 0, 0}, {4, 4, 8, 4}, {4, 5, 16, 8}, {4, 6, 32, 32}, {4, 4, 16, 16}, {8, 16, 32, 32}, {8, 16, 128, 128}, {8, 32, 128, 256}, {32, 128, 258, 1024}, {32, 258, 258, 4096} }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22399 struct S22399a { unsigned short f1; }; struct S22399b { const struct S22399a *f1; }; const struct S22399a C22399[1] = { {12} }; const struct S22399b C22399b = {C22399}; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22400 typedef struct S22400 { unsigned short f1; } S22400_t; struct S22400b { const S22400_t *f1; }; const S22400_t C22400[1] = { {12} }; const struct S22400b C22400b = {C22400}; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22402 typedef struct { short c; } S22402a; typedef struct { S22402a *a; S22402a b[1]; } S22402b; int test22402a(S22402a *a, S22402a b[1]) { return a - b; } int test22402b(S22402b *s) { return s->a - s->b; } int test22402c(S22402a *a) { S22402a b[1]; return a - b; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22403 extern unsigned test22403a(const char *p); void test22403() { test22403a(0); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22404 typedef enum { E22404_FLAG } E22404; int test22404a(E22404 e); int test22404() { test22404a(E22404_FLAG); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22405 struct S22405 { int const * p; int *q; }; void test22405(struct S22405 *s) { s->p = (const int *)(s->q); } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22406 int test22406(int a) { switch (a) { case 1: return -1; case 2: return -2; case 3: return -3; } return 0; } /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22407 typedef int (*T22407) (int a); int test22407(int a); T22407 table22407[1] = { test22407 }; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22409 struct S22409; typedef struct S22409 { int f1; } S22409_t; /***************************************************/ // https://issues.dlang.org/show_bug.cgi?id=22413 int test22413(void) { char msg[] = "ok"; return msg[0] | msg[1]; } /***************************************************/ int test(char *dest) { int x; return dest == x; } /***************************************************/ ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test13242.d0000644000175000017500000000112614141774365023601 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // EXTRA_FILES: imports/test13242a.d imports/test13242b.d /* TEST_OUTPUT: --- main +alias apiSym1 a.expensiveArgs: 1 a.expensiveTemplate: 1 -alias apiSym1 +alias apiSym3 b.expensiveArgs: 3 b.expensiveTemplate: 3 -alias apiSym3 --- */ import imports.test13242a; void main() { pragma(msg, "main"); cheapFunc(); pragma(msg, "+alias apiSym1"); alias apiSym1 = .apiSym1; pragma(msg, "-alias apiSym1"); // imports.test13242a.apiSym2 is not analyzed. pragma(msg, "+alias apiSym3"); alias apiSym3 = .apiSym3; pragma(msg, "-alias apiSym3"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test1353.d0000644000175000017500000000032014141774365023514 0ustar matthiasmatthias class A {} interface B {} interface C {} interface D(X) {} void fun() { class T : typeof(new A), .B, const(C), D!int {} version(none) { class U : int, float, __vector(int[3]) {} } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test6534.d0000644000175000017500000000507314141774365023534 0ustar matthiasmatthiasvoid main() { class MC{ int x; } const class CC{ int x; } static assert(is(typeof( CC.x) == const)); immutable class IC{ int x; } static assert(is(typeof( IC.x) == immutable)); shared class SC{ int x; } static assert(is(typeof( SC.x) == shared)); shared const class SCC{ int x; } static assert(is(typeof(SCC.x) == shared) && is(typeof(SCC.x) == const)); struct MS{ int x; } const struct CS{ int x; } static assert(is(typeof( CS.x) == const)); immutable struct IS{ int x; } static assert(is(typeof( IS.x) == immutable)); shared struct SS{ int x; } static assert(is(typeof( SS.x) == shared)); shared const struct SCS{ int x; } static assert(is(typeof(SCS.x) == shared) && is(typeof(SCS.x) == const)); union MU{ int x; } const union CU{ int x; } static assert(is(typeof( CU.x) == const)); immutable union IU{ int x; } static assert(is(typeof( IU.x) == immutable)); shared union SU{ int x; } static assert(is(typeof( SU.x) == shared)); shared const union SCU{ int x; } static assert(is(typeof(SCU.x) == shared) && is(typeof(SCU.x) == const)); static class S_MC{ int x; } const static class S_CC{ int x; } static assert(is(typeof( S_CC.x) == const)); immutable static class S_IC{ int x; } static assert(is(typeof( S_IC.x) == immutable)); shared static class S_SC{ int x; } static assert(is(typeof( S_SC.x) == shared)); shared const static class S_SCC{ int x; } static assert(is(typeof(S_SCC.x) == shared) && is(typeof(S_SCC.x) == const)); static struct S_MS{ int x; } const static struct S_CS{ int x; } static assert(is(typeof( S_CS.x) == const)); immutable static struct S_IS{ int x; } static assert(is(typeof( S_IS.x) == immutable)); shared static struct S_SS{ int x; } static assert(is(typeof( S_SS.x) == shared)); shared const static struct S_SCS{ int x; } static assert(is(typeof(S_SCS.x) == shared) && is(typeof(S_SCS.x) == const)); static union S_MU{ int x; } const static union S_CU{ int x; } static assert(is(typeof( S_CU.x) == const)); immutable static union S_IU{ int x; } static assert(is(typeof( S_IU.x) == immutable)); shared static union S_SU{ int x; } static assert(is(typeof( S_SU.x) == shared)); shared const static union S_SCU{ int x; } static assert(is(typeof(S_SCU.x) == shared) && is(typeof(S_SCU.x) == const)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/mixinTemplateMangling.d0000644000175000017500000000212114141774365026517 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20012 mixin template mixinFoo() { extern(C) void cFoo() {} extern(C) int cVar; extern(D) int dVar; void dFoo() {} mixin(`mixin mixinBar;`); // test nesting and interaction with string mixins } mixin mixinFoo; mixin template mixinBar() { extern(C) void cBar() {} void dBar() {} } static assert(cFoo.mangleof == "cFoo"); static assert(dFoo.mangleof == "_D21mixinTemplateMangling8__mixin54dFooFZv"); static assert(cVar.mangleof == "cVar"); static assert(dVar.mangleof == "_D21mixinTemplateMangling8__mixin54dVari"); static assert(cBar.mangleof == "cBar"); static assert(dBar.mangleof == "_D21mixinTemplateMangling8__mixin5Qj4dBarFZv"); struct S { mixin mixinFoo; static assert(cFoo.mangleof == "_D21mixinTemplateMangling1S8__mixin14cFooMUZv"); static assert(cBar.mangleof == "_D21mixinTemplateMangling1S8__mixin18__mixin54cBarMUZv"); static assert(dBar.mangleof == "_D21mixinTemplateMangling1S8__mixin18__mixin54dBarMFZv"); static assert(dFoo.mangleof == "_D21mixinTemplateMangling1S8__mixin14dFooMFZv"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix22362.c0000644000175000017500000000031714141774365023413 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22362 typedef struct Foo { int x, y; } Foo; Foo gfoo = (Foo){0, 1}; int main(int argc, char** argv) { Foo foo1 = (Foo){0}; Foo foo2 = (Foo){0, 1}; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dip22.d0000644000175000017500000000050614141774365023147 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/dip22.d import imports.dip22; class Foo : Base1, Base2 { void test() { static assert(typeof(bar()).sizeof == 2); static assert(baz == 2); static assert(T.sizeof == 2); } } void test() { bar(12); baz(12); 12.bar(); 12.baz(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/warn3882.d0000644000175000017500000000276414141774365023533 0ustar matthiasmatthias// PERMUTE_ARGS: -w -wi -debug @safe pure nothrow void strictVoidReturn(T)(T x) {} @safe pure nothrow void nonstrictVoidReturn(T)(ref T x) {} void test3882() { int x = 3; strictVoidReturn(x); nonstrictVoidReturn(x); } /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=12619 extern (C) @system nothrow pure void* memcpy(void* s1, in void* s2, size_t n); // -> weakly pure void test12619() pure { ubyte[10] a, b; debug memcpy(a.ptr, b.ptr, 5); // memcpy call should have side effect } /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=12760 struct S12760(T) { T i; this(T j) inout {} } struct K12760 { S12760!int nullable; this(int) { nullable = 0; // weak purity } } /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=12909 int f12909(immutable(int[])[int] aa) pure nothrow { //aa[0] = []; // fix for https://issues.dlang.org/show_bug.cgi?id=13701 return 0; } void test12909() { immutable(int[])[int] aa; f12909(aa); // from 12910 const(int[])[int] makeAA() { return null; } // to make r-value makeAA().rehash(); } /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=13899 const struct Foo13899 { int opApply(immutable int delegate(in ref int) pure nothrow dg) pure nothrow { return 1; } } void test13899() { foreach (x; Foo13899()) { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/implicitconv.d0000644000175000017500000000256414141774365024735 0ustar matthiasmatthiasenum __c_wchar_t : wchar; alias wchar_t = __c_wchar_t; immutable(wchar_t)[] a = "somestring"; const(wchar_t)[] b = "somestring"; immutable(wchar_t)* c = "somestring"; const(wchar_t)* d = "somestring"; string foo = "foo"; static assert(!__traits(compiles, { immutable(wchar_t)[] bar = foo; } )); static assert(!__traits(compiles, { const(wchar_t)[] bar = foo; } )); static assert(!__traits(compiles, { immutable(wchar_t)* bar = foo; } )); static assert(!__traits(compiles, { const(wchar_t)* bar = foo; } )); // https://issues.dlang.org/show_bug.cgi?id=17141 static assert(is(typeof(true ? char.init : char.init) == char)); static assert(is(typeof(true ? char.init : wchar.init) == dchar)); static assert(is(typeof(true ? char.init : dchar.init) == dchar)); static assert(is(typeof(true ? wchar.init : wchar.init) == wchar)); static assert(is(typeof(true ? wchar.init : dchar.init) == dchar)); static assert(is(typeof(true ? dchar.init : dchar.init) == dchar)); enum cenum : char { a } enum wenum : wchar{ b } enum denum : dchar{ c } static assert(is(typeof(true ? char.init : cenum.init) == char)); static assert(is(typeof(true ? wchar.init : cenum.init) == dchar)); static assert(is(typeof(true ? char.init : wenum.init) == dchar)); static assert(is(typeof(true ? dchar.init : wenum.init) == dchar)); static assert(is(typeof(true ? cenum.init : wenum.init) == dchar)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/json20742.d0000644000175000017500000000205414141774365023577 0ustar matthiasmatthias/* REQUIRED_ARGS: -Xf- -o- -version=Showme PERMUTE_ARGS: TEST_OUTPUT: ---- [ { "kind" : "module", "file" : "compilable$?:windows=\\|/$json20742.d", "members" : [ { "name" : "X1", "kind" : "struct", "protection" : "private", "line" : 52, "char" : 13, "members" : [] }, { "name" : "Y2", "kind" : "struct", "protection" : "private", "line" : 59, "char" : 13, "members" : [] }, { "name" : "A1", "kind" : "struct", "protection" : "private", "line" : 62, "char" : 13, "members" : [] }, { "name" : "B2", "kind" : "struct", "protection" : "private", "line" : 69, "char" : 13, "members" : [] } ] } ] ---- https://issues.dlang.org/show_bug.cgi?id=20742 */ version(Showme) private struct X1 {} else private struct X2 {} version(Hideme) private struct Y1 {} else private struct Y2 {} static if (true) private struct A1 {} else private struct A2 {} static if (false) private struct B1 {} else private struct B2 {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18951a.d0000644000175000017500000000017114141774365023755 0ustar matthiasmatthiasmodule compilable.test18951a; public class A { package static void foo(Object) {} public static void foo() {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test324.d0000644000175000017500000000062414141774365023440 0ustar matthiasmatthias// DISABLED: LDC /* TEST_OUTPUT: --- compilable/test324.d(17): Deprecation: function `test324.main.doStuff!((i) { return i; } ).doStuff` function requires a dual-context, which is deprecated compilable/test324.d(23): instantiated from here: `doStuff!((i) { return i; } )` --- */ struct Foo { void doStuff(alias fun)() {} } void main() { Foo foo; foo.doStuff!( (i) { return i; })(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17059.d0000644000175000017500000000024614141774365023615 0ustar matthiasmatthiasmixin template impl() { alias T = typeof(this); enum doImplement = is(T : I); static if (doImplement) {} } interface I {} class A : I {mixin impl;} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/mixintype2.d0000644000175000017500000000366714141774365024352 0ustar matthiasmatthias alias fun = mixin("(){}"); void test1() { int x = 1; static immutable c = 2; fun(); foo!(mixin("int"))(); foo!(mixin("long*"))(); foo!(mixin("ST!(int, S.T)"))(); foo!(mixin(ST!(int, S.T)))(); int[mixin("string")] a1; int[mixin("5")] a2; int[mixin("c")] a3; int[] v1 = new int[mixin("3")]; auto v2 = new int[mixin("x")]; mixin(q{__traits(getMember, S, "T")}) ftv; alias T = int*; static assert(__traits(compiles, mixin("int"))); static assert(__traits(compiles, mixin(q{int[mixin("string")]}))); static assert(__traits(compiles, mixin(q{int[mixin("2")]}))); static assert(__traits(compiles, mixin(T))); static assert(__traits(compiles, mixin("int*"))); static assert(__traits(compiles, mixin(typeof(0)))); } struct S { alias T = float*; } struct ST(X,Y) {} void foo(alias t)() {} /**************************************************/ // https://issues.dlang.org/show_bug.cgi?id=21074 alias Byte = ubyte; alias Byte2(A) = ubyte; alias T0 = mixin(q{const(Byte)})*; alias T1 = mixin(q{const(Byte[1])})*; alias T2 = mixin(q{const(Byte2!int)})*; alias T3 = mixin(q{const(mixin(Byte2!int))})*; alias T4 = mixin(q{const(mixin("__traits(getMember, S, \"T\")"))})*; alias T5 = const(mixin(q{Byte}))*; alias T6 = const(mixin(q{immutable(Byte)}))*; alias T7 = const(mixin(q{shared(Byte)}))*; alias T8 = const(mixin(q{Byte*})); // the following tests now work static assert(is(T0 == const(ubyte)*)); static assert(is(T1 == const(ubyte[1])*)); static assert(is(T2 == const(ubyte)*)); static assert(is(T3 == const(ubyte)*)); static assert(is(T4 == const(float*)*)); static assert(is(T5 == const(ubyte)*)); static assert(is(T6 == immutable(ubyte)*)); static assert(is(T7 == const(shared(ubyte))*)); static assert(is(T8 == const(ubyte*))); // this doesn't work but I'll file a new issue /* alias T8 = mixin(q{immutable(__traits(getMember, S, "T"))})*; static assert(is(T8 == immutable(float*)*)); */ ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dip22d.d0000644000175000017500000000030114141774365023304 0ustar matthiasmatthias// REQUIRED_ARGS: // EXTRA_FILES: imports/dip22d.d imports/dip22e.d // https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP22.md import imports.dip22d; import imports.dip22e; Foo foo; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice13088.d0000644000175000017500000000030214141774365023365 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: struct X { void mfoo(this T)() {} } void test() { shared const X scx; scx.mfoo(); } struct Vec { int x; void sc() shared const {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test4364.d0000644000175000017500000000020714141774365023525 0ustar matthiasmatthiasstruct Object{} class Game {} void main() { static assert(is(Object == struct)); static assert(is(object.Object == class)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b20780.d0000644000175000017500000000055014141774365023050 0ustar matthiasmatthiasvoid main() { struct A; struct B { struct CD;} alias V = void; alias I = int; V test0(@A I) {} V test1(@A I p) {} V test2(@A @(B) I) {} V test3(@(B.CD) @B I) {} V test4(@A I, @B @A I) {} V test5(@A I p, @(B.CD) @A I ) {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix22275.c0000644000175000017500000000025214141774365023414 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22275 void test(char *dest) { char buf[1]; if (dest != buf) return; if (test != &test) return; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15785.d0000644000175000017500000000060614141774365023621 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/test15785.d // PERMUTE_ARGS: import imports.test15785; class Derived : Base, IBase2 { override void foo() { super.foo(); bar(); // Base.bar(); // doesn't work yet due to a bug in checkAccess faz(); // IBase2.faz(); // doesn't work yet due to a bug in checkAccess } typeof(super).T t; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21438.d0000644000175000017500000000041614141774365023610 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21438 int genGBPLookup() { static struct Table { int[1] entries; } auto table = new Table; auto x = table.entries[0]; static assert(is(typeof(x) == int)); return 0; } enum x = genGBPLookup; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc7555.d0000644000175000017500000000142114141774365023463 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc7555; /** Dummy doc. $(X0 DelimitedString TokenString) $(X1 DelimitedString TokenString) $(X2 x,HexString) $(X2 x, HexString) $(X3 x,x,HexString) $(X3 x,x, HexString) $(X4 x,x,x,HexString) $(X4 x,x,x, HexString) $(X5 x,x,x,x,HexString) $(X5 x,x,x,x, HexString) $(X6 x,x,x,x,x,HexString) $(X6 x,x,x,x,x, HexString) $(X7 x,x,x,x,x,x,HexString) $(X7 x,x,x,x,x,x, HexString) $(X8 x,x,x,x,x,x,x,HexString) $(X8 x,x,x,x,x,x,x, HexString) $(X9 x,x,x,x,x,x,x,x,HexString) $(X9 x,x,x,x,x,x,x,x, HexString) Macros: X0=$0 X1=$1 X2=$2 X3=$3 X4=$4 X5=$5 X6=$6 X7=$7 X8=$8 X9=$9 */ void dummy(); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix22294.c0000644000175000017500000000020714141774365023415 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22294 enum { A, B, C }; _Static_assert(A == 0 && B == 1 && C == 2, "in"); int array[C]; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test10992.d0000644000175000017500000000026014141774365023610 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -unittest unittest { } unittest { } unittest { } void main() { static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 3); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/json.d0000644000175000017500000001003014141774365023171 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -d -preview=dip1000 -o- -X -Xf- // EXTRA_FILES: imports/jsonimport1.d imports/jsonimport2.d imports/jsonimport3.d imports/jsonimport4.d // TRANSFORM_OUTPUT: sanitize_json // TEST_OUTPUT_FILE: extra-files/json.json module json; shared static this() {} static this() {} shared static ~this() {} static ~this() {} template X(T) { shared static this() {} static this() {} shared static ~this() {} static ~this() {} } alias SSCDX = X!int; class SSCDClass { shared static this() {} static this() {} shared static ~this() {} static ~this() {} } #line 17 alias int myInt; myInt x; // https://issues.dlang.org/show_bug.cgi?id=3404 struct Foo(T) { T t; } class Bar(int T) { int t = T; } interface Baz(T...) { T[0] t() const; } // https://issues.dlang.org/show_bug.cgi?id=3466 template P(alias T) {} class Bar2 : Bar!1, Baz!(int, 2, null) { this() {} ~this() {} // https://issues.dlang.org/show_bug.cgi?id=4178 static foo() {} protected abstract Foo!int baz(); override int t() const { return 0; } } class Bar3 : Bar2 { private int val; this(int i) { val = i; } protected override Foo!int baz() { return Foo!int(val); } } struct Foo2 { Bar2 bar2; union U { struct { short s; int i; } Object o; } } struct Foo3(bool b) { version(D_Ddoc) { /// Doc 1 void method1(); } static if (b) { /// Doc 2 void method2(); } else { /// Doc 3 void method3(); } /// Doc 4 void method4(); } /++ + Documentation test +/ @trusted myInt bar(ref uint blah, Bar2 foo = new Bar3(7)) // https://issues.dlang.org/show_bug.cgi?id=4477 { return -1; } @property int outer() nothrow in { assert(true); } out(result) { assert(result == 18); } do { int x = 8; int inner(void* v) nothrow { int y = 2; assert(true); return x + y; } int z = inner(null); return x + z; } /** Issue 9484 - selective and renamed imports */ import imports.jsonimport1 : target1, target2; import imports.jsonimport2 : alias1 = target1, alias2 = target2; import imports.jsonimport3 : alias3 = target1, alias4 = target2, target3; import imports.jsonimport4; struct S { /** Issue 9480 - Template name should be stripped of parameters */ this(T)(T t) { } } /** Issue 9755 - Protection not emitted properly for Templates. */ private struct S1_9755(T) { } package struct S2_9755(T) { } class C_9755 { protected static class CI_9755(T) { } } /** Issue 10011 - init property is wrong for object initializer. */ const Object c_10011 = new Object(); /// enum Numbers { unspecified1, one = 2, two = 3, FILE_NOT_FOUND = 101, unspecified3, unspecified4, four = 4, } template IncludeConstraint(T) if (T == string) {} static foreach(enum i; 0..3) { mixin("int a" ~ i.stringof ~ " = 1;"); } alias Seq(T...) = T; static foreach(int i, alias a; Seq!(a0, a1, a2)) { mixin("alias b" ~ i.stringof ~ " = a;"); } // return ref, return scope, return ref scope ref int foo(return ref int a) @safe { return a; } int* foo(return scope int* a) @safe { return a; } ref int* foo(scope return ref int* a) @safe { return a; } struct SafeS { @safe: ref SafeS foo() return { return this; } SafeS foo2() return scope { return this; } ref SafeS foo3() return scope { return this; } int* p; } extern int vlinkageDefault; extern(D) int vlinkageD; extern(C) int vlinakgeC; extern(C++) __gshared int vlinkageCpp; extern(Windows) int vlinkageWindows; extern(Objective-C) int vlinkageObjc; extern int flinkageDefault(); extern(D) int flinkageD(); extern(C) int linakgeC(); extern(C++) int flinkageCpp(); extern(Windows) int flinkageWindows(); extern(Objective-C) int flinkageObjc(); mixin template test18211(int n) { static foreach (i; 0 .. n>10 ? 10 : n) { mixin("enum x" ~ cast(char)('0' + i)); } static if (true) {} } alias F = size_t function (size_t a); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/commontype.d0000644000175000017500000005160414141774365024426 0ustar matthiasmatthias// LDC: don't enforce -mcpu // required_args: -mcpu=avx2 import core.simd; version = CondExp; //version = ReturnInfer; T rvalueOf(T)(); version (CondExp) { alias X(T, U) = typeof(0 ? rvalueOf!T : rvalueOf!U); } else version (ReturnInfer) { alias X(T, U) = typeof({ if (0) return rvalueOf!T; else return rvalueOf!U;}()); } else static assert(0); enum Error(T, U) = !__traits(compiles, X!(T, U)); interface I {} class B {} class C : B, I {} class D : B {} class K {} struct SI { I o; alias o this; } struct SC { C o; alias o this; } struct SB { B o; alias o this; } struct SD { D o; alias o this; } struct SK { K o; alias o this; } struct SiC { immutable(C) o; alias o this; } struct S { int a; } struct Si { int a; alias a this; } struct Si2 { int a; alias a this; } struct Sl { long a; alias a this; } /****************************** * Basic types */ static assert(is( X!( byte, byte ) == byte )); static assert(is( X!( ubyte, ubyte ) == ubyte )); static assert(is( X!( byte, ubyte ) == int )); static assert(is( X!( byte, short ) == int )); static assert(is( X!( byte, ushort ) == int )); static assert(is( X!( byte, const(byte) ) == int )); static assert(is( X!( ubyte, const(ubyte) ) == int )); static assert(is( X!( short, short ) == short )); static assert(is( X!( ushort, ushort ) == ushort )); static assert(is( X!( short, ushort ) == int )); static assert(is( X!( short, const(short) ) == int )); static assert(is( X!( ushort, const(ushort) ) == int )); static assert(is( X!( int, int ) == int )); static assert(is( X!( int, uint ) == uint )); static assert(is( X!( uint, uint ) == uint )); static assert(is( X!( int, long ) == long )); static assert(is( X!( int, ulong ) == ulong )); static assert(is( X!( float, float ) == float )); static assert(is( X!( float, int ) == float )); static assert(is( X!( float, uint ) == float )); static assert(is( X!( float, long ) == float )); static assert(is( X!( float, ulong ) == float )); static assert(is( X!( float, double ) == double )); static assert(is( X!( float, real ) == real )); static assert(is( X!( char, char ) == char )); static assert(is( X!( char, byte ) == int )); static assert(is( X!( char, ubyte ) == int )); static assert(is( X!( char, wchar ) == dchar )); static assert(is( X!( char, dchar ) == dchar )); static assert(is( X!( char, const(char) ) == const(char) )); static assert(is( X!( wchar, const(wchar) ) == const(wchar) )); static assert(is( X!( dchar, const(dchar) ) == const(dchar) )); static assert(is( X!( char, immutable(char) ) == const(char) )); static assert(Error!( char, shared(char) )); static assert(is( X!( char, float ) == float )); static assert(is( X!( immutable(int), int ) == int )); static assert(is( X!( const(int), int ) == int )); static assert(is( X!( shared(int), int ) == int )); static assert(is( X!( immutable(int), const(shared(int)) ) == int )); static assert(is( X!( shared(int), const(int) ) == int )); /****************************** * Strings */ static assert(is( X!( string, string ) == string )); static assert(Error!( wstring, string )); static assert(Error!( dstring, string )); static assert(Error!( dstring, wstring )); static assert(is( X!( const(char)[], string ) == const(char)[] )); static assert(is( X!( char[], string ) == const(char)[] )); static assert(is( X!( string, immutable(string) ) == immutable(string) )); // `const` static assert(is( X!( immutable(string), string ) == string )); // not commutative /****************************** * Enums */ enum Ei : int { a, } enum Eb : byte { a, } enum Ec : char { a, } enum Ew : wchar { a, } static assert(is( X!( Ei, Ei ) == Ei )); static assert(is( X!( Ei, const(Ei) ) == const(Ei) )); static assert(is( X!( Ei, immutable(Ei) ) == const(Ei) )); static assert(is( X!( Eb, Eb ) == Eb )); static assert(is( X!( Eb, const(Eb) ) == int )); static assert(is( X!( Eb, immutable(Eb) ) == int )); static assert(is( X!( Ei, Eb ) == int )); static assert(is( X!( Ei, const(Eb) ) == int )); static assert(is( X!( Ei, immutable(Eb) ) == int )); static assert(is( X!( Ec, Ec ) == Ec )); static assert(is( X!( Ec, const(Ec) ) == const(char) )); static assert(is( X!( Ec, immutable(Ec) ) == const(char) )); static assert(is( X!( Ew, Ew ) == Ew )); static assert(is( X!( Ew, const(Ew) ) == const(wchar) )); static assert(is( X!( Ew, immutable(Ew) ) == const(wchar) )); static assert(is( X!( Ew, Ec ) == dchar )); static assert(is( X!( Ew, const(Ec) ) == dchar )); static assert(is( X!( Ew, immutable(Ec) ) == dchar )); /****************************** * Tuple */ alias Tuple(Args...) = Args; static assert(!__traits(compiles ,typeof(0 ? Tuple!1 : Tuple!1))); /****************************** * Pointers */ static assert(is( X!( int*, int* ) == int* )); static assert(is( X!( const(int*), const(int)* ) == const(int*) )); static assert(is( X!( const(int)*, const(int*) ) == const(int)* )); // not commutative static assert(Error!( uint*, int* )); static assert(is( X!( int function(), int function() ) == int function() )); // void pointer static assert(is( X!( void*, int* ) == int* )); static assert(is( X!( int*, void* ) == int* )); static assert(is( X!( const(int)*, void* ) == const(int)* )); static assert(is( X!( const(int*), void* ) == const(int*) )); static assert(is( X!( int*, const(void)* ) == int* )); // `const` static assert(is( X!( int*, const(void*) ) == int* )); // `const` static assert(is( X!( int*, shared(void*) ) == int* )); // should fail static assert(is( X!( int*, shared(void)* ) == int* )); // should fail static assert(Error!( int**, void** )); // should work static assert(is( X!( void*, int function() ) == int function() )); static assert(is( X!( immutable(void*), int function() ) == int function() )); // `const` // implicit conversion static assert(is( X!( int*, const(int*) ) == const(int*) )); static assert(is( X!( int*, const(int)* ) == const(int)* )); static assert(is( X!( int***, const(int)*** ) == const(int**)* )); static assert(is( X!( immutable(int)***, const(int)*** ) == const(int**)* )); static assert(is( X!( immutable(int)***, const(shared(int))*** ) == const(shared(int)**)* )); // common modifier static assert(is( X!( immutable(int)*, int* ) == const(int)* )); static assert(is( X!( immutable(int*), int* ) == const(int)* )); static assert(is( X!( immutable(int)*, shared(int)* ) == shared(const(int))* )); static assert(Error!( shared(int)*, int* )); static assert(is( X!( immutable(int)***, int*** ) == const(int**)* )); // `const(int)***` static assert(is( X!( shared(const(int)***), shared(int***) ) == const(shared(int*)*)* )); // `shared(const(int)***)` static assert(is( X!( shared(const(int)***), shared(int**)* ) == const(shared(int*)*)* )); static assert(Error!( shared(const(int)***), shared(int*)** )); // class pointer static assert(is( X!( C*, B* ) == B* )); static assert(is( X!( const(C)*, B* ) == const(B)* )); static assert(Error!( shared(C)*, B* )); static assert(is( X!( immutable(C)*, B* ) == const(B)* )); static assert(is( X!( immutable(C*), B* ) == const(B)* )); static assert(is( X!( C**, B** ) == const(B*)* )); // `B**` static assert(is( X!( B**, C** ) == const(B*)* )); // `B**` static assert(is( X!( C***, B*** ) == const(B**)* )); // `B***` static assert(is( X!( C*, I* ) == I* )); static assert(is( X!( I*, C* ) == I* )); static assert(Error!( C**, I** )); static assert(Error!( C*, D* )); // should work // function pointer static assert(is( X!( immutable(int function()), int function() ) == immutable(int function()) )); static assert(is( X!( int function(), immutable(int function()) ) == int function() )); // not commutative static assert(is( X!( int function(), shared(int function()) ) == int function() )); static assert(is( X!( int function(), const(int) function() ) == const(int) function() )); static assert(is( X!( int function(), immutable(int) function() ) == immutable(int) function() )); // `const` static assert(is( X!( immutable(int) function(), int function() ) == int function() )); // not commutative static assert(Error!( uint function(), int function() )); static assert(is( X!( C function(), B function() ) == B function() )); static assert(is( X!( B function(), C function() ) == B function() )); static assert(is( X!( C function(), const(B) function() ) == const(B) function() )); static assert(Error!( const(C) function(), B function() )); // should work static assert(Error!( C* function(), B* function() )); // should work static assert(Error!( C function(), I function() )); static assert(Error!( C* function(), I* function() )); static assert(is( X!( C delegate(), B delegate() ) == B delegate() )); static assert(Error!( C delegate(), I delegate() )); static assert(Error!( C function(), D function() )); // should work static assert(Error!( void function(int), void function(const(int)) )); // should work static assert(Error!( void function(C), void function(B) )); static assert(Error!( void function(C*), void function(B*) )); static assert(Error!( void function(const(C)*), void function(B*) )); static assert(is( X!( void function(C*), void function(const(B*)) ) == void function(C*) )); // !? static assert(is( X!( void function(C), void function(const(C)) ) == void function(C) )); static assert(is( X!( void function(C), void function(const(C)) ) == void function(C) )); static assert(is( X!( void function() pure nothrow @nogc @safe, void function() ) == void function() )); static assert(is( X!( void function() pure @safe, void function() @nogc ) == void function() )); static assert(is( X!( void function() pure @trusted, void function() nothrow @safe ) == void function() @trusted )); static assert(is( X!( void function() @trusted, void function() ) == void function())); static assert(is( X!( void function() @trusted, void function() @trusted ) == void function() @trusted )); static assert(is( X!( void function() @safe, void function() @trusted ) == void function() @trusted )); static assert(is( X!( void function() @trusted, void function() @safe ) == void function() @safe )); // not commutative static assert(is( X!( const(int function())*, int function()* ) == const(int function())* )); static assert(is( X!( immutable(int function())*, int function()* ) == const(int function())* )); static assert(Error!( shared(int function())*, int function()* )); static assert(is( X!( shared(int function())*, immutable(int function())* ) == shared(const(int function()))* )); /****************************** * Arrays */ static assert(is( X!( int[4], int[4] ) == int[4] )); static assert(is( X!( int[], int[] ) == int[] )); // static array modifier conversion static assert(is( X!( const(int)[4], int[4] ) == int[4] )); static assert(is( X!( int[4], const(int)[4] ) == const(int)[4] )); // not commutative static assert(is( X!( const(int)[4], immutable(int)[4] ) == immutable(int)[4] )); static assert(is( X!( immutable(int)[4], const(int)[4] ) == const(int)[4] )); // not commutative static assert(is( X!( int[4], immutable(int)[4] ) == immutable(int)[4] )); static assert(is( X!( immutable(int)[4], int[4] ) == int[4] )); // not commutative static assert(Error!( shared(int)[4], int[4] )); // should work static assert(Error!( int[4], shared(int)[4] )); // should work static assert(Error!( shared(int)[4], const(int)[4] )); // should work static assert(Error!( const(int)[4] , shared(int)[4])); // should work static assert(is( X!( shared(const(int))[4], shared(int)[4] ) == shared(int)[4] )); static assert(is( X!( shared(int)[4], shared(const(int))[4] ) == shared(const(int))[4] )); // not commutative static assert(is( X!( shared(const(int))[4], immutable(int)[4] ) == shared(const(int))[4] )); static assert(is( X!( immutable(int)[4], shared(const(int))[4] ) == shared(const(int))[4] )); static assert(is( X!( immutable(int)[4], shared(int)[4] ) == shared(const(int))[] )); // `[4]` static assert(is( X!( shared(int)[4], immutable(int)[4] ) == shared(const(int))[] )); // `[4]` static assert(is( X!( int*[4], const(int)*[4] ) == const(int)*[4])); static assert(is( X!( const(int)*[4], int*[4] ) == const(int)*[4])); static assert(is( X!( immutable(int)*[4], const(int)*[4] ) == const(int)*[4])); static assert(is( X!( const(int)*[4], immutable(int)*[4] ) == const(int)*[4])); static assert(Error!( int*[4], immutable(int)*[4] )); // should work static assert(Error!( immutable(int)*[4], int*[4] )); // should work static assert(Error!( int*[4], shared(int)*[4] )); static assert(Error!( shared(int)*[4], int*[4] )); static assert(Error!( shared(int)*[4], immutable(int)*[4] )); // should work static assert(Error!( immutable(int)*[4], shared(int)*[4] )); // should work static assert(is( X!( shared(const(int))*[4], shared(int)*[4] ) == shared(const(int))*[4] )); static assert(is( X!( shared(int)*[4], shared(const(int))*[4] ) == shared(const(int))*[4] )); static assert(is( X!( C[4], const(C)[4] ) == const(C)[4] )); static assert(is( X!( const(C)[4], C[4] ) == const(C)[4] )); static assert(is( X!( C[4], immutable(C)[4] ) == const(C)[] )); // `[4]` static assert(is( X!( immutable(C)[4], C[4] ) == const(C)[] )); // `[4]` static assert(Error!( shared(C)[4], C[4] )); static assert(Error!( C[4], shared(C)[4] )); static assert(is( X!( shared(C)[4], immutable(C)[4] ) == shared(const(C))[] )); // `[4]` static assert(is( X!( immutable(C)[4], shared(C)[4] ) == shared(const(C))[] )); // `[4]` static assert(is( X!( shared(const(C))[4], shared(C)[4] ) == shared(const(C))[4] )); static assert(is( X!( shared(C)[4], shared(const(C))[4] ) == shared(const(C))[4] )); // base class conversion static assert(is( X!(C[4], B[4]) )); static assert(Error!( C[4], I[4] )); static assert(Error!( C[4], D[4] )); static assert(is( X!( C[4], const(B)[4] ) == const(B)[4] )); static assert(Error!( C[4], const(I)[4] )); static assert(Error!( C[4], const(D)[4] )); static assert(Error!( C*[4], B*[4] )); static assert(Error!( C*[4], I*[4] )); static assert(Error!( C*[4], D*[4] )); static assert(is( X!( C*[4], const(B*)[4] ) == const(B*)[] )); // !? static assert(Error!( C*[4], const(I*)[4] )); static assert(Error!( C*[4], const(D*)[4] )); static assert(Error!( C*[4], B**[4] )); static assert(Error!( C*[4], const(B*)*[4] )); static assert(Error!( C*[4], const(B**)[4] )); // static to dynamic static assert(is( X!( int[4], void[4] ) == void[] )); static assert(is( X!( void[4], int[4] ) == void[] )); static assert(is( X!( int[4], int[3] ) == int[] )); static assert(is( X!( int[4], const(int)[3] ) == const(int)[] )); static assert(is( X!( int[4], int[] ) == int[] )); static assert(is( X!( const(int)[4], int[] ) == const(int)[] )); static assert(is( X!( int[4], const(int)[] ) == const(int)[] )); static assert(is( X!( int[4], void[] ) == void[] )); static assert(is( X!( const(int)[4], void[] ) == const(void)[] )); static assert(Error!( int*[4], void*[4] )); // should work static assert(Error!( int*[4], void*[] )); // should work static assert(is( X!( int*[4], int*[] ) == int*[] )); static assert(is( X!( const(int*)[4], int*[] ) == const(int*)[] )); static assert(is( X!( int*[4], const(int*)[] ) == const(int*)[] )); static assert(Error!( const(int)*[4], int*[] )); // should work static assert(Error!( int*[4], const(int)*[] )); // should work static assert(Error!( int[4], long[] )); static assert(Error!( int[4], uint[] )); static assert(Error!( int[4], short[] )); static assert(Error!( C[4], B[] )); static assert(Error!( C[4], I[] )); static assert(Error!( C[4], D[] )); static assert(Error!( C*[4], B*[] )); static assert(Error!( C*[4], I*[] )); static assert(Error!( C*[4], D*[] )); // dynamic arrays static assert(is( X!( int[], int[] ) == int[] )); static assert(is( X!( int[], const(int)[] ) == const(int)[] )); static assert(is( X!( const(int)[], int[] ) == const(int)[] )); static assert(is( X!( int[], immutable(int)[] ) == const(int)[] )); static assert(is( X!( immutable(int)[], int[] ) == const(int)[] )); static assert(Error!( int[], shared(int)[] )); static assert(Error!( shared(int)[], int[] )); static assert(is( X!( shared(int)[], immutable(int)[] ) == shared(const(int))[] )); static assert(is( X!( immutable(int)[], shared(int)[] ) == shared(const(int))[] )); static assert(Error!( const(int)[], shared(int)[] )); static assert(Error!( shared(int)[], const(int)[] )); static assert(is( X!( int[], void[] ) == void[] )); static assert(is( X!( void[], int[] ) == void[] )); static assert(is( X!( int[], const(void)[] ) == const(void)[] )); static assert(is( X!( const(int)[], void[] ) == const(void)[] )); static assert(is( X!( int*[], const(int*)[] ) == const(int*)[] )); static assert(is( X!( const(int*)[], int*[] ) == const(int*)[] )); static assert(Error!( int*[], const(int)*[] )); // should work static assert(Error!( const(int)*[], int*[] )); // should work static assert(is( X!( C[], const(C)[] ) == const(C)[] )); static assert(is( X!( const(C)[], C[] ) == const(C)[] )); static assert(Error!( int[], long[] )); static assert(Error!( int[], uint[] )); static assert(Error!( int[], short[] )); static assert(Error!( C[], B[] )); static assert(Error!( C[], I[] )); static assert(Error!( C[], D[] )); static assert(Error!( C*[], B*[] )); static assert(Error!( C*[], I*[] )); static assert(Error!( C*[], D*[] )); /****************************** * Associative arrays */ static assert(is( X!( int[int], int[int] ) == int[int] )); static assert(Error!( const(int[int]), int[int] )); // should work static assert(Error!( immutable(int[int]), int[int] )); // should work static assert(Error!( shared(int[int]), int[int] )); /****************************** * Classes */ static assert(Error!( C, void* )); static assert(Error!( void*, C )); static assert(is( X!( C, C ) == C )); static assert(is( X!( C, B ) == B )); static assert(is( X!( C, I ) == I )); static assert(is( X!( C, D ) == B )); static assert(is( X!( C, K ) == Object )); static assert(is( X!( C, SC ) == C )); static assert(is( X!( C, SB ) == B )); static assert(is( X!( C, SI ) == I )); static assert(is( X!( C, SD ) == B )); static assert(is( X!( C, SK ) == Object )); static assert(is( X!( C, immutable(C) ) == const(C) )); static assert(is( X!( C, immutable(I) ) == const(I) )); static assert(is( X!( C, immutable(B) ) == const(B) )); static assert(is( X!( C, immutable(D) ) == const(B) )); static assert(is( X!( C, immutable(K) ) == const(Object) )); static assert(Error!( C, immutable(SC) )); // should work static assert(Error!( C, immutable(SI) )); // should work static assert(Error!( immutable(SI), C )); // should work static assert(Error!( C, immutable(SB) )); // should work static assert(Error!( C, immutable(SD) )); // should work static assert(Error!( C, immutable(SK) )); // should work static assert(is( X!( const(C), C ) == const(C) )); static assert(is( X!( const(C), I ) == const(I) )); static assert(is( X!( const(C), B ) == const(B) )); static assert(is( X!( const(C), D ) == const(B) )); static assert(is( X!( const(C), K ) == const(Object) )); static assert(is( X!( const(C), SC ) == const(C))); static assert(Error!( const(C), SI )); // should work static assert(is( X!( const(SI), const(C) ) == const(I) )); // should work static assert(is( X!( const(C), SB ) == const(B))); static assert(is( X!( const(C), SD ) == const(B))); static assert(is( X!( const(C), SK ) == Object)); // `const` static assert(is( X!( SiC, SC ) == const(C) )); /****************************** * Structs */ static assert(is( X!( S, S ) == S )); static assert(is( X!( S, immutable(S) ) == const(S) )); static assert(Error!( S, shared(S) )); static assert(is( X!( Si, Si ) == Si )); static assert(is( X!( Si, int ) == int )); static assert(is( X!( int, Si ) == int )); static assert(is( X!( Si, Si2 ) == int )); static assert(is( X!( int, Sl ) == long )); static assert(is( X!( Si, Sl ) == long )); /****************************** * Vectors */ static if (__traits(compiles, int4)) { static assert(is( X!( int4, int4 ) == int4)); static assert(is( X!( int4, const(int4) ) == const(int4))); static assert(is( X!( int4, immutable(int4) ) == const(int4))); static assert(is( X!( __vector(const(int)[4]), int4 ) == int4)); static assert(is( X!( int4, __vector(const(int)[4]) ) == int4)); static assert(Error!( int[4], int4 )); static assert(Error!( int4, int[4] )); } static if (__traits(compiles, { byte16 a; void16 b; })) static assert(Error!( byte16, void16 )); static if (__traits(compiles, { int4 a; void16 b; })) static assert(Error!( int4, void16 )); static if (__traits(compiles, { float4 a; void16 b; })) static assert(Error!( float4, void16 )); static if (__traits(compiles, { byte16 a; ubyte16 b; })) static assert(Error!( byte16, ubyte16 )); static if (__traits(compiles, { short8 a; ushort8 b; })) static assert(Error!( short8, ushort8 )); static if (__traits(compiles, { int4 a; uint4 b; })) static assert(Error!( int4, uint4 )); static if (__traits(compiles, { int4 a; float4 b; })) static assert(Error!( int4, float4 )); static if (__traits(compiles, { long4 a; ulong4 b; })) static assert(Error!( long4, ulong4 )); static if (__traits(compiles, { double4 a; float8 b; })) static assert(Error!( double4, float8 )); /****************************** * Null */ static assert(is( X!( typeof(null), int* ) == int*)); static assert(is( X!( typeof(null), int[] ) == int[])); static assert(is( X!( typeof(null), int[int] ) == int[int])); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ctfe_math.d0000644000175000017500000000137214141774365024163 0ustar matthiasmatthias// Test CTFE builtins for std.math functions. import std.math; void main() { static assert(isClose(sin(2.0L), 0.9092974268)); static assert(isClose(cos(2.0), -0.4161468365)); static assert(isClose(tan(2.0f), -2.185040f, 1e-5)); static assert(isClose(sqrt(2.0L), 1.4142135623)); static assert(fabs(-2.0) == 2.0); static assert(ldexp(2.5f, 3) == 20.0f); static assert(isNaN(real.init)); static assert(isNaN(double.nan)); static assert(!isNaN(float.infinity)); static assert(isInfinity(real.infinity)); static assert(isInfinity(-double.infinity)); static assert(!isInfinity(float.nan)); static assert(isFinite(1.0L)); static assert(!isFinite(double.infinity)); static assert(!isFinite(float.nan)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20835.d0000644000175000017500000000234514141774365023613 0ustar matthiasmatthias// EXTRA_FILES: imports/test19344.d // https://issues.dlang.org/show_bug.cgi?id=20835 template T(E) { alias T = __traits(getAttributes, E.a); } void main() { class C {} enum E { @C a } alias b = T!E; } // https://issues.dlang.org/show_bug.cgi?id=19344 import imports.test19344; struct Struct { int value; } enum Enum { @Struct(42) first, } static assert(getUDAs!(Enum.first, Struct)[0] == Struct(42)); static assert(__traits(getAttributes, Enum.first)[0] == Struct(42)); // https://issues.dlang.org/show_bug.cgi?id=21122 void test21122() { enum A; enum E { @A a } static assert(is(getAllUDAs!(E.a)[0] == A)); } alias getAllUDAs(A...) = __traits(getAttributes, A); // https://issues.dlang.org/show_bug.cgi?id=21352 @("aaa") enum Hoge { @("bbb") foo, // tuple("aaa", "bbb") -> should be only tuple("bbb") bar, // tuple() } @("aaa") struct Fuga { @("bbb") int foo; // tuple("bbb") int bar; // tuple() } static assert([__traits(getAttributes, Hoge.foo)] == ["bbb"]); //NG -> fixed static assert([__traits(getAttributes, Hoge.bar)] == []); static assert([__traits(getAttributes, Fuga.foo)] == ["bbb"]); static assert([__traits(getAttributes, Fuga.bar)] == []); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc10325.d0000644000175000017500000000041114141774365023526 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc10325; /** */ template templ(T...) if (someConstraint!T) { } /** */ void foo(T)(T t) if (someConstraint!T) { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16657.d0000644000175000017500000000031714141774365023617 0ustar matthiasmatthiasstruct A { int x; } struct B { A a, b; } static assert(B(A(1), A(1)) != B(A(1), A(2))); // Works struct C { A a, b; alias a this; } static assert(C(A(1), A(1)) != C(A(1), A(2))); // Fails! ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19203.d0000644000175000017500000000103414141774365023602 0ustar matthiasmatthias//https://issues.dlang.org/show_bug.cgi?id=19203 struct BoolWithErr { bool b; string error; alias b this; } struct Foo { int popBack() { return 0; } } struct Bar {} template hasPopBack(T) { static if (!is(typeof(T.init.popBack))) enum hasPopBack = BoolWithErr(false, T.stringof~" does not have popBack"); else enum hasPopBack = BoolWithErr(true,""); } void test() { static assert( hasPopBack!Foo); static assert(!hasPopBack!Bar); static assert( hasPopBack!Foo && !hasPopBack!Bar); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21806.d0000644000175000017500000000110014141774365023576 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21806 void main() { ubyte[16] arr; static assert(is(typeof( fun(arr[])) == char)); static assert(is(typeof(funtp(arr[])) == char)); static assert(is(typeof( bar(arr[])) == char)); } // functions char fun(ubyte[] arr) { return 'X'; } int fun(ubyte[16] arr) { return 123; } // function templates char funtp()(ubyte[] arr) { return 'X'; } int funtp(size_t N)(ubyte[N] arr) { return 123; } // original case with 'in' char bar()(in ubyte[] arr) { return 'X'; } int bar(size_t N)(in ubyte[N] arr) { return 123; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15762.d0000644000175000017500000000052014141774365023607 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=15762 enum Windows1252Char : ubyte { init } void main() @safe { ubyte[] a = [1, 2, 3, 4]; auto aw = cast(Windows1252Char[]) a; auto caw = cast(const(Windows1252Char)[]) a; const(ubyte)[] c = [1, 2, 3, 4]; auto d = cast(const(ubyte)[]) c; auto e = cast(const(Windows1252Char)[]) c; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20795.d0000644000175000017500000000071414141774365023616 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20795 // REQUIRED_ARGS: -preview=dip1000 struct Foo { void opEquals(T)(T rhs) if (T.init.opCast!string) {} } struct Bar { void opEquals()(Bar) { Gun() == Foo(); } } class Baz { void opCast(T)() {} } struct Gun { void[24] buff; auto underlying() { return cast(Baz) buff.ptr; } alias underlying this; void opEquals(R)(R) if (Bar.init == R.init) {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16578a.d0000644000175000017500000000043214141774365023760 0ustar matthiasmatthias// REQUIRED_ARGS: -debug // https://issues.dlang.org/show_bug.cgi?id=16578 string[string] opts; void main() { string arg; switch (arg) { case "-f": opts["fore"] = ""; break; debug { case "-throw": opts["throw"] = ""; break; } default: } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test7569.d0000644000175000017500000000013714141774365023541 0ustar matthiasmatthiastemplate Tuple(T...) { alias T Tuple; } void main() { Tuple!(int, int) tup1 = void; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16635.d0000644000175000017500000000170214141774365023612 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=16635 struct A { alias get this; const(A) get() const { return A(); } } static assert(!__traits(compiles, A() + A())); // Original test (covers another path) struct Vector2 { float x; float y; alias byRef this; ref const(Vector2) byRef() const { static Vector2 v; return v; } Vector2 opBinary(string op : "+")(ref const(Vector2) a) const { return Vector2(x + a.x, y + a.y); } } void test16635_1() { Vector2 a = Vector2(1, 2); Vector2 b = Vector2(3, 4); // this line causes application to run infinitely // Already fixed. It was issue 16621 Vector2 c = a + b; // OK <- this line seg faults without the above line Vector2 d = a + Vector2(5, 6); } void test16635_2() { Vector2 a = Vector2(1, 2); Vector2 b = Vector2(3, 4); // just this line alone Vector2 d = a + Vector2(5, 6); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc12706.d0000644000175000017500000000026614141774365023543 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /// void test()(string[] args) if (args[$]) { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19809.d0000644000175000017500000000037214141774365023622 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19809 mixin template Impl(M...) { int opCmp(Object o) { return 0; } } class C { override { int function(int) fp = ((int x) => x); mixin Impl!("x", "y", ((int x) => x)); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_cpp98_compat.d0000644000175000017500000000463314141774365025560 0ustar matthiasmatthias/* REQUIRED_ARGS: -extern-std=c++98 -HC -c -o- -Icompilable/extra-files PERMUTE_ARGS: EXTRA_FILES: extra-files/dtoh_imports.d extra-files/dtoh_imports2.d TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif class ImportsC { }; struct Null final { void* field; _d_dynamicArray< const char > null_; private: Null(int32_t ); public: Null() : field(NULL), null_() { } Null(void* field, _d_dynamicArray< const char > null_ = _d_dynamicArray< const char >()) : field(field), null_(null_) {} }; extern void* typeof_null; extern void* inferred_null; struct MyString final { _d_dynamicArray< const char > str; MyString() : str() { } MyString(_d_dynamicArray< const char > str) : str(str) {} }; struct Wrapper final { MyString s1; MyString s2; Wrapper() : s1(MyString(_d_dynamicArray< const char >( 5, "Hello" ))), s2(MyString(_d_dynamicArray< const char >())) { } Wrapper(MyString s1, MyString s2 = MyString(_d_dynamicArray< const char >())) : s1(s1), s2(s2) {} }; class UsingBase { public: virtual void foo(); }; class UsingChild : public UsingBase { public: }; --- */ extern (C++) struct Null { void* field = null; string null_ = null; @disable this(int); } extern (C++) __gshared typeof(null) typeof_null = null; extern (C++) __gshared inferred_null = null; extern (C++) struct MyString { string str; } extern (C++) struct Wrapper { MyString s1 = MyString("Hello"); MyString s2 = MyString(null); } extern (C++) class UsingBase { void foo() {} } extern (C++) class UsingChild : UsingBase { alias foo = UsingBase.foo; } public import dtoh_imports : aliasName = ImportsC; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/chkformat.d0000644000175000017500000000067014141774365024207 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20643 // https://issues.dlang.org/show_bug.cgi?id=20644 /* TEST_OUTPUT: ---- compilable/chkformat.d(14): Deprecation: more format specifiers than 0 arguments ---- */ import core.stdc.stdio; void main() { // b20643 printf("%d \n"); // b20644 ubyte b; printf("%hhu \n", b); char c = '-'; printf("%c", c); short s; printf("%hd", s); printf("%hn", &s); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21282.d0000644000175000017500000000034114141774365023602 0ustar matthiasmatthias/* TEST_OUTPUT: --- tuple(func) --- */ // https://issues.dlang.org/show_bug.cgi?id=21282 template I(T...) { alias I = T; } template Bug(T...) { alias Bug = mixin("I!(T[0])"); } void func() {} pragma(msg, Bug!func); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/traits.d0000644000175000017500000002350514141774365023541 0ustar matthiasmatthias// REQUIRED_ARGS: -extern-std=c++98 // EXTRA_FILES: imports/plainpackage/plainmodule.d imports/pkgmodule/package.d imports/pkgmodule/plainmodule.d // This file is intended to contain all compilable traits-related tests in an // effort to keep the number of files in the `compilable` folder to a minimum. // https://issues.dlang.org/show_bug.cgi?id=19152 module traits; class C19152 { int OnExecute() { auto name = __traits(getOverloads, this, "OnExecute").stringof; return 0; } } static assert(is(typeof(__traits(getTargetInfo, "cppRuntimeLibrary")) == string)); version (CppRuntime_Microsoft) { static assert(__traits(getTargetInfo, "cppRuntimeLibrary") == "libcmt" || __traits(getTargetInfo, "cppRuntimeLibrary")[0..6] == "msvcrt"); // includes mingw import libs } version (D_HardFloat) static assert(__traits(getTargetInfo, "floatAbi") == "hard"); version (Win64) static assert(__traits(getTargetInfo, "objectFormat") == "coff"); version (OSX) static assert(__traits(getTargetInfo, "objectFormat") == "macho"); version (linux) static assert(__traits(getTargetInfo, "objectFormat") == "elf"); static assert(__traits(getTargetInfo, "cppStd") == 199711); import imports.plainpackage.plainmodule; import imports.pkgmodule.plainmodule; #line 40 struct MyStruct; alias a = imports.plainpackage; alias b = imports.pkgmodule.plainmodule; static assert(__traits(isPackage, imports.plainpackage)); static assert(__traits(isPackage, a)); static assert(!__traits(isPackage, imports.plainpackage.plainmodule)); static assert(!__traits(isPackage, b)); static assert(__traits(isPackage, imports.pkgmodule)); static assert(!__traits(isPackage, MyStruct)); static assert(!__traits(isModule, imports.plainpackage)); static assert(!__traits(isModule, a)); static assert(__traits(isModule, imports.plainpackage.plainmodule)); static assert(__traits(isModule, b)); // This is supposed to work even though we haven't directly imported imports.pkgmodule. static assert(__traits(isModule, imports.pkgmodule)); static assert(!__traits(isModule, MyStruct)); /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=19942 static assert(!__traits(compiles, { a.init; })); static assert(!__traits(compiles, { import m : a; a.init; })); version(Windows) static assert(__traits(getLocation, MyStruct)[0] == `compilable\traits.d`); else static assert(__traits(getLocation, MyStruct)[0] == "compilable/traits.d"); static assert(__traits(getLocation, MyStruct)[1] == 40); static assert(__traits(getLocation, MyStruct)[2] == 1); int foo(); int foo(int); static assert(__traits(getLocation, __traits(getOverloads, traits, "foo")[1])[1] == 74); mixin("int bar;"); static assert(__traits(getLocation, bar)[1] == 78); struct Outer { struct Nested{} void method() {} } static assert(__traits(getLocation, Outer.Nested)[1] == 83); static assert(__traits(getLocation, Outer.method)[1] == 85); /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=19902 // Define hasElaborateCopyConstructor trait // but done as two independent traits per conversation // in https://github.com/dlang/dmd/pull/10265 struct S { this (ref S rhs) {} } struct OuterS { struct S { this (ref S rhs) {} } S s; } void foo(T)() { struct S(U) { this (ref S rhs) {} } static assert (__traits(hasCopyConstructor, S!int)); } struct U(T) { this (ref U rhs) {} } struct SPostblit { this(this) {} } struct DisabledPostblit { @disable this(this); } struct NoCpCtor { } class C19902 { } static assert(__traits(hasCopyConstructor, S)); static assert(__traits(hasCopyConstructor, OuterS.S)); static assert(__traits(hasCopyConstructor, OuterS)); static assert(__traits(compiles, foo!int)); static assert(__traits(compiles, foo!S)); static assert(__traits(hasCopyConstructor, U!int)); static assert(__traits(hasCopyConstructor, U!S)); static assert(!__traits(hasPostblit, U!S)); static assert(__traits(hasPostblit, SPostblit)); static assert(!__traits(hasCopyConstructor, SPostblit)); static assert(!__traits(hasCopyConstructor, NoCpCtor)); static assert(!__traits(hasCopyConstructor, C19902)); static assert(!__traits(hasCopyConstructor, int)); static assert(!__traits(hasPostblit, NoCpCtor)); static assert(!__traits(hasPostblit, C19902)); static assert(!__traits(hasPostblit, int)); static assert(__traits(isCopyable, int)); static assert(!__traits(isCopyable, DisabledPostblit)); struct S1 {} // Fine. Can be copied struct S2 { this(this) {} } // Fine. Can be copied struct S3 { @disable this(this); } // Not fine. Copying is disabled. struct S4 { S3 s; } // Not fine. A field has copying disabled. class C1 {} static assert( __traits(isCopyable, S1)); static assert( __traits(isCopyable, S2)); static assert(!__traits(isCopyable, S3)); static assert(!__traits(isCopyable, S4)); static assert(__traits(isCopyable, C1)); static assert(__traits(isCopyable, int)); static assert(__traits(isCopyable, int[])); enum E1 : S1 { a = S1(), } enum E2 : S2 { a = S2(), } enum E3 : S3 { a = S3(), } enum E4 : S4 { a = S4(), } static assert(__traits(isCopyable, E1)); static assert(__traits(isCopyable, E2)); static assert(!__traits(isCopyable, E3)); static assert(!__traits(isCopyable, E4)); struct S5 { @disable this(ref S5); } static assert(!__traits(isCopyable, S5)); /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=20884 struct S20884 { int x; } alias T20884 = immutable(S20884); enum m20884 = "x"; static assert(is(typeof(__traits(getMember, T20884, m20884)) == immutable(int))); // OK now static assert(is( typeof(mixin("T20884." ~ m20884)) == immutable(int))); static assert(is( typeof(T20884.x) == immutable(int))); /******************************************/ // https://issues.dlang.org/show_bug.cgi?id=20761 alias Seq(T...) = T; static assert(__traits(isSame, Seq!(1, 2), Seq!(1, 2))); static assert(!__traits(isSame, Seq!(1, 1), Seq!(2, 2))); static assert(!__traits(isSame, Seq!(1, 1, 2), Seq!(1, 1))); static assert(!__traits(isSame, Seq!(1, 1), Seq!(1, 1, 2))); static assert(__traits(isSame, Seq!(string, wstring), Seq!(immutable(char)[], immutable(wchar)[])) ); static assert(__traits(isSame, Seq!(i => i.value, (a, b) => a + b), Seq!(a => a.value, (x, y) => x + y) )); static assert(__traits(isSame, Seq!(float, Seq!(double, Seq!real)), Seq!(Seq!(Seq!float, double), real) )); static assert(!__traits(isSame, Seq!(int, Seq!(a => a + a)), Seq!(int, Seq!(a => a * a)) )); // Do these out of order to ensure there are no forward refencing bugs extern(C++, __traits(getCppNamespaces,GetNamespaceTest1)) struct GetNamespaceTest4 {} static assert (__traits(getCppNamespaces,GetNamespaceTest1) == __traits(getCppNamespaces,GetNamespaceTest4)); extern(C++, "ns") struct GetNamespaceTest1 {} extern(C++, "multiple", "namespaces") struct GetNamespaceTest2 {} extern(C++, mixin("Seq!(`ns`, `nt`)")) struct GetNamespaceTest3 {} static assert(__traits(getCppNamespaces,GetNamespaceTest1)[0] == "ns"); static assert(__traits(getCppNamespaces,GetNamespaceTest2) == Seq!("multiple","namespaces")); static assert(__traits(getCppNamespaces,GetNamespaceTest3) == Seq!("ns", "nt")); extern(C++, __traits(getCppNamespaces,GetNamespaceTest5)) struct GetNamespaceTest8 {} static assert (__traits(getCppNamespaces,GetNamespaceTest5) == __traits(getCppNamespaces,GetNamespaceTest8)); extern(C++, ns) struct GetNamespaceTest5 {} extern(C++, multiple) extern(C++, namespaces) struct GetNamespaceTest6 {} static assert(__traits(getCppNamespaces,GetNamespaceTest5)[0] == "ns"); static assert(__traits(getCppNamespaces,GetNamespaceTest6) == Seq!("multiple","namespaces")); extern(C++, NS) { struct GetNamespaceTest9 {} extern(C++, nested) { struct GetNamespaceTest10 {} extern(C++,"nested2") struct GetNamespaceTest11 {} } extern (C++, "nested3") { extern(C++, nested4) struct GetNamespaceTest12 {} } } static assert (__traits(getCppNamespaces,NS.GetNamespaceTest9)[0] == "NS"); static assert (__traits(getCppNamespaces,NS.GetNamespaceTest10) == Seq!("NS", "nested")); static assert (__traits(getCppNamespaces,NS.GetNamespaceTest11) == Seq!("NS", "nested", "nested2")); static assert (__traits(getCppNamespaces,NS.GetNamespaceTest12) == Seq!("NS", "nested4", "nested3")); extern(C++, `ns`) struct GetNamespaceTestTemplated(T) {} extern(C++, `ns`) template GetNamespaceTestTemplated2(T) { struct GetNamespaceTestTemplated2 {} } template GetNamespaceTestTemplated3(T) { extern(C++, `ns`) struct GetNamespaceTestTemplated3 {} } static assert (__traits(getCppNamespaces,GetNamespaceTestTemplated!int) == Seq!("ns")); static assert (__traits(getCppNamespaces,GetNamespaceTestTemplated2!int) == Seq!("ns")); static assert (__traits(getCppNamespaces,GetNamespaceTestTemplated3!int) == Seq!("ns")); extern(C++, `ns2`) template GetNamespaceTestTemplated4(T) { extern(C++, `ns`) struct GetNamespaceTestTemplated4 { struct GetNamespaceTestTemplated5 {} struct GetNamespaceTestTemplated6(T) {} } } static assert (__traits(getCppNamespaces,GetNamespaceTestTemplated4!int) == Seq!("ns2","ns")); static assert (__traits(getCppNamespaces,GetNamespaceTestTemplated4!int.GetNamespaceTestTemplated5) == Seq!("ns2","ns")); static assert (__traits(getCppNamespaces,GetNamespaceTestTemplated4!int.GetNamespaceTestTemplated6!int) == Seq!("ns2","ns")); // Currently ignored due to https://issues.dlang.org/show_bug.cgi?id=21373 extern(C++, `decl`) mixin template GetNamespaceTestTemplatedMixin() { extern(C++, `f`) void foo() {} } extern(C++, `inst`) mixin GetNamespaceTestTemplatedMixin!() GNTT; static assert (__traits(getCppNamespaces, GNTT.foo) == Seq!(`inst`,/*`decl`,*/ `f`)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/cppmangle2.d0000644000175000017500000000036714141774365024264 0ustar matthiasmatthiasmodule cppmangle2; extern(C++, Namespace18922) { struct Struct18922 { int i; } } extern(C++, std) { struct vector (T); } extern(C++, `Namespace18922`) { struct Struct18922 { int i; } } extern(C++, `std`) { struct vector (T); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20710.d0000644000175000017500000000044014141774365023575 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20710 // with empty array literal immutable A a = A(B([])); immutable B b = a.b; struct A { B b; } struct B { int[] c; } // with empty struct literal immutable C c = C(D()); immutable D d = c.d; struct C { D d; } struct D { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19840.d0000644000175000017500000000033514141774365023614 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=19840 struct G { ubyte[] I; alias I this; } auto M(ubyte[]) { G N; return N; } struct U { int V; } void X() { func((cast(U[])[].M)); } void func(U[]) {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20923.d0000644000175000017500000000022114141774365023600 0ustar matthiasmatthiasversion (D_LP64) { alias size_t = uint; } else { alias size_t = ulong; } struct S { real not_reproduceable_without_this_variable; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ctfesimd.d0000644000175000017500000000717214141774365024033 0ustar matthiasmatthiasversion (D_SIMD) { import core.simd; // https://issues.dlang.org/show_bug.cgi?id=19627 enum int[4] fail19627 = cast(int[4])int4(0); // https://issues.dlang.org/show_bug.cgi?id=19628 enum ice19628a = int4.init[0]; enum ice19628b = int4.init.array[0]; enum ice19628c = (cast(int[4])int4.init.array)[0]; enum ice19628d = (cast(int[4])int4.init)[0]; // https://issues.dlang.org/show_bug.cgi?id=19629 enum fail19629a = int4(0)[0]; enum fail19629b = int4(0).array[0]; enum fail19629c = (cast(int[4])int4(0).array)[0]; enum fail19628d = (cast(int[4])int4(0))[0]; // https://issues.dlang.org/show_bug.cgi?id=19630 enum fail19630a = int4.init[1..2]; enum fail19630b = int4.init.array[1..2]; enum fail19630c = (cast(int[4])int4.init.array)[1..2]; enum fail19630d = int4(0)[1..2]; enum fail19630e = int4(0).array[1..2]; enum fail19630f = (cast(int[4])int4(0).array)[1..2]; enum fail19630g = (cast(int[4])int4.init)[1..2]; enum fail19630h = (cast(int[4])int4(0))[1..2]; // Same tests as above, but use access via enum. enum int4 V1 = int4.init; enum int[4] V2 = int4.init.array; enum int[4] V3 = cast(int[4])int4.init; enum int[4] V4 = cast(int[4])int4.init.array; enum int4 V5 = int4(0); enum int[4] V6 = int4(0).array; enum int[4] V7 = cast(int[4])int4(0); enum int[4] V8 = cast(int[4])int4(0).array; // CTFE index tests enum I1 = V1[0]; static assert(I1 == 0); enum I2 = V2[0]; static assert(I2 == 0); enum I3 = V3[0]; static assert(I3 == 0); enum I4 = V4[0]; static assert(I4 == 0); enum I5 = V5[0]; static assert(I5 == 0); enum I6 = V6[0]; static assert(I6 == 0); enum I7 = V7[0]; static assert(I7 == 0); enum I8 = V8[0]; static assert(I8 == 0); // CTFE slice tests enum S1 = V1[1..2]; static assert(S1 == [0]); enum S2 = V2[1..2]; static assert(S2 == [0]); enum S3 = V3[1..2]; static assert(S3 == [0]); enum S4 = V4[1..2]; static assert(S4 == [0]); enum S5 = V5[1..2]; static assert(S5 == [0]); enum S6 = V6[1..2]; static assert(S6 == [0]); enum S7 = V7[1..2]; static assert(S7 == [0]); enum S8 = V8[1..2]; static assert(S8 == [0]); // Same tests as above, but use access via immutable. //immutable int4 v1 = int4.init; // Cannot cast to immutable at compile time immutable int[4] v2 = int4.init.array; immutable int[4] v3 = cast(int[4])int4.init; immutable int[4] v4 = cast(int[4])int4.init.array; //immutable int4 v5 = int4(0); // Cannot cast to immutable at compile time immutable int[4] v6 = int4(0).array; immutable int[4] v7 = cast(int[4])int4(0); immutable int[4] v8 = cast(int[4])int4(0).array; // CTFE index tests //immutable i1 = v1[0]; static assert(i1 == 0); immutable i2 = v2[0]; static assert(i2 == 0); immutable i3 = v3[0]; static assert(i3 == 0); immutable i4 = v4[0]; static assert(i4 == 0); //immutable i5 = v5[0]; static assert(i5 == 0); immutable i6 = v6[0]; static assert(i6 == 0); immutable i7 = v7[0]; static assert(i7 == 0); immutable i8 = v8[0]; static assert(i8 == 0); // CTFE slice tests //immutable s1 = v1[1..2]; static assert(s1 == [0]); immutable s2 = v2[1..2]; static assert(s2 == [0]); immutable s3 = v3[1..2]; static assert(s3 == [0]); immutable s4 = v4[1..2]; static assert(s4 == [0]); //immutable s5 = v5[1..2]; static assert(s5 == [0]); immutable s6 = v6[1..2]; static assert(s6 == [0]); immutable s7 = v7[1..2]; static assert(s7 == [0]); immutable s8 = v8[1..2]; static assert(s8 == [0]); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test10066.d0000644000175000017500000000224314141774365023603 0ustar matthiasmatthiasvoid main() { alias Zoo = Foo!(1); } struct Foo(size_t N) { string bar() { Appender!(string) w; char[] buf; put(w, buf); return ""; } public bool opEquals(T)(T other) const // Add const, different from bug 10056 { alias Foo!(typeof(this), T, "CMP") P; return false; } } template Foo(T, U, string OP) { static if (T.ISEMPTY && U.ISEMPTY) enum bool S = false; else enum bool S = false; alias Foo = Foo!(0); } /**********************************************/ void put(R, E)(ref R r, E e) { static if (is(typeof(r.put(e)))) { r.put(e); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } struct Appender(A : T[], T) { private template canPutItem(U) { enum bool canPutItem = is(U : T); } private template canPutRange(R) { enum bool canPutRange = is(typeof(Appender.init.put(R.init[0]))); } void put(U)(U item) if (canPutItem!U) { char[T.sizeof == 1 ? 4 : 2] encoded; put(encoded[]); } void put(R)(R items) if (canPutRange!R) { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldmd_response_file.sh0000755000175000017500000000146314141774365026261 0ustar matthiasmatthias#!/usr/bin/env bash # Make sure LDMD forwards a huge command line correctly to LDC. dir=${RESULTS_DIR}/compilable # generate a ~100K response file for LDMD rsp_file=${dir}/ldmd_response_file.rsp echo "-version=FirstLine" > ${rsp_file} for i in {1..1000} do echo "-I=Some/lengthy/string/Some/lengthy/string/Some/lengthy/string/Some/lengthy/string/Some/lengthy/string/" >> ${rsp_file} done echo "-version=LastLine" >> ${rsp_file} # statically assert that both versions are set src_file=${dir}/ldmd_response_file.d echo "version (FirstLine) {" > ${src_file} echo " version (LastLine) {} else static assert(0);" >> ${src_file} echo "} else" >> ${src_file} echo " static assert(0);" >> ${src_file} # LDMD errors if there's no source file. $DMD @${rsp_file} -c -o- ${src_file} if [ $? -ne 0 ]; then exit 1; fi; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/previewin.d0000644000175000017500000000563014141774365024242 0ustar matthiasmatthias/* REQUIRED_ARGS: -preview=dip1000 -preview=in -mcpu=native */ import core.stdc.time; void fun(in int* inParam) @safe; static assert([__traits(getParameterStorageClasses, fun, 0)] == ["in"]); static assert (is(typeof(fun) P == __parameters) && is(P[0] == const int*)); struct Foo { int a; double[100] b; } void fun2(in Foo inParam) @safe; static assert([__traits(getParameterStorageClasses, fun2, 0)] == ["in"]); static assert (is(typeof(fun2) P == __parameters) && is(P[0] == const Foo)); void test() { withDefaultValue(42); withDefaultValue(); withDefaultRef(TimeRef.init); withDefaultRef(); withInitDefaultValue(); withInitDefaultRef(); } struct FooBar { string toString() const { string result; // Type is const this.toString((in char[] buf) { static assert(is(typeof(buf) == const(char[]))); result ~= buf; }); // Type inference works this.toString((in buf) { result ~= buf; }); return result; } void toString(scope void delegate(in char[]) sink) const { sink("Hello world"); } } // Ensure that default parameter works even if non CTFEable void withDefaultValue(in time_t currTime = time(null)) {} struct TimeRef { time_t now; ulong[4] bloat; } void withDefaultRef(in TimeRef currTime = TimeRef(time(null))) {} // Ensure that default parameters work with `.init` void withInitDefaultValue(in size_t defVal = size_t.init) {} void withInitDefaultRef(in TimeRef defVal = TimeRef.init) {} // Ensure that temporary aren't needlessly created // (if they are, it'll trigger the "goto skips declaration" error) void checkNotIdentity(in void* p1, in void* p2) { assert(p1 !is p2); } void checkTemporary() { int* p = new int; if (p is null) goto LError; // Should not generate temporary, pass the pointers by value checkNotIdentity(/*lvalue*/ p, /*rvalue*/ null); checkNotIdentity(new int, null); LError: assert(0); } // Some ABI-specific tests: version (Win64) { void checkReal(in real p) { // ref for x87 real, value for double-precision real static assert(__traits(isRef, p) == (real.sizeof > 8)); } struct RGB { ubyte r, g, b; } void checkNonPowerOf2(in RGB p) { static assert(__traits(isRef, p)); } } else version (X86_64) // Posix x86_64 { struct Empty {} // 1 dummy byte passed on the stack void checkEmptyStruct(in Empty p) { static assert(!__traits(isRef, p)); } static if (is(__vector(double[4]))) { struct AvxVectorWrapper { __vector(double[4]) a; } // 256 bits void checkAvxVector(in AvxVectorWrapper p) { static assert(!__traits(isRef, p)); } } } else version (AArch64) { alias HVA = __vector(float[4])[4]; // can be passed in 4 vector registers void checkHVA(in HVA p) { static assert(!__traits(isRef, p)); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testpostblit.d0000644000175000017500000000021714141774365024766 0ustar matthiasmatthiasstruct Test1a { this(this) { } } struct Test1b { Test1a a; } struct Test1c { const Test1b b; @disable this(this); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test67.d0000644000175000017500000000016514141774365023364 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/test67a.d import imports.test67a; interface I { } interface SubI : I { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test7065.d0000644000175000017500000000230114141774365023523 0ustar matthiasmatthiasvoid main() { align(1) struct X1 { ubyte b; int n; } static assert(X1.sizeof == 8); static assert(X1.b.offsetof == 0); static assert(X1.n.offsetof == 4); //X1 x1; //assert(cast(void*)&x1.b == cast(void*)&x1 + 0); //assert(cast(void*)&x1.n == cast(void*)&x1 + 1); struct Y1 { ubyte b; int n; } static assert(Y1.sizeof == 8); static assert(Y1.b.offsetof == 0); static assert(Y1.n.offsetof == 4); //Y1 y1; //assert(cast(void*)&y1.b == cast(void*)&y1 + 0); //assert(cast(void*)&y1.n == cast(void*)&y1 + 4); int local; align(1) struct X2 { ubyte b; int n; int f(){ return local; } } static assert(X2.sizeof == 8 + (void*).sizeof); static assert(X2.b.offsetof == 0); static assert(X2.n.offsetof == 4); //X2 x2; //assert(cast(void*)&x2.b == cast(void*)&x2 + 0); //assert(cast(void*)&x2.n == cast(void*)&x2 + 1); struct Y2 { ubyte b; int n; int f(){ return local; } } static assert(Y2.sizeof == 8 + (void*).sizeof); static assert(Y2.b.offsetof == 0); static assert(Y2.n.offsetof == 4); //Y2 y2; //assert(cast(void*)&y2.b == cast(void*)&y2 + 0); //assert(cast(void*)&y2.n == cast(void*)&y2 + 4); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18670.d0000644000175000017500000000027714141774365023621 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=dip1000 // https://issues.dlang.org/show_bug.cgi?id=18670 void foo() { new OVERLAPPED; } union OVERLAPPED { uint OffsetHigh; uint Pointer; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_1581.d0000644000175000017500000000075314141774365025015 0ustar matthiasmatthiasstruct OperandFormatDescriptor { string name; } enum OperandFormat { SrcDst = OperandFormatDescriptor("SrcDst"), DstSrc = OperandFormatDescriptor("DstSrc") } struct OpcodeDescriptor { OperandFormat operandFormat; } enum Opcodes { Load = OpcodeDescriptor(OperandFormat.DstSrc), } void main() { assert(OperandFormat.init.name == "SrcDst"); assert(OpcodeDescriptor.init.operandFormat.name == "SrcDst"); assert(Opcodes.Load.operandFormat.name == "DstSrc"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/sw_transition_tls.d0000644000175000017500000000034614141774365026016 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -transition=tls /* TEST_OUTPUT: --- compilable/sw_transition_tls.d(11): `x` is thread local compilable/sw_transition_tls.d(15): `y` is thread local --- */ int x; struct S { static int y; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9692.d0000644000175000017500000000035214141774365023537 0ustar matthiasmatthias// EXTRA_FILES: test9692a.d imports/test9692b.d module test9692; import test9692a; import imports.test9692b; enum x = [__traits(allMembers, imports.test9692b)]; // ok enum y = [__traits(allMembers, test9692a)]; // ng: should work ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fix17145.d0000644000175000017500000000037414141774365023422 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=17145 auto tuple(T...)(T t) { struct Result { T expand; } return Result(t); } void baz() { enum zoo = tuple(1, 2).expand; // Error: value of __tup1847 is not known at compile time } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice10040.d0000644000175000017500000000034414141774365023354 0ustar matthiasmatthiasstruct MsgProc1 { mixin MsgMixin; } struct MsgProc2 { mixin MsgMixin; } struct MsgHeader {} template MsgMixin() { mixin(mixinMembers!(MsgHeader.init)); } string mixinMembers(T ...)() { struct Op {} return null; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18694.d0000644000175000017500000000015614141774365023623 0ustar matthiasmatthiasstruct S { enum int x = 42; } static S dummy; pure int fun(int x) { return dummy.x + x; } void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testclidflags.sh0000755000175000017500000000114414141774365025250 0ustar matthiasmatthias#!/usr/bin/env bash # LDC doesn't print the DFLAGS environment variable as part of -v output # DISABLED: LDC unset DFLAGS # Force DMD to print the -v menu by passing an invalid object file # It will fail with "no object files to link", but print the log # On OSX DMD terminates with a successful exit code, so `|| true` is used. ( "$DMD" -conf= -v foo.d 2> /dev/null || true) | grep -q "DFLAGS (none)" ( DFLAGS="-O -D" "$DMD" -conf= -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O -D" ( DFLAGS="-O '-Ifoo bar' -c" "$DMD" -conf= -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O '-Ifoo bar' -c" ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test4003.d0000644000175000017500000000023714141774365023516 0ustar matthiasmatthias// COMPILED_IMPORTS: imports/test4003a.d // EXTRA_FILES: imports/stdio4003.d imports/typecons4003.d // PERMUTE_ARGS: import imports.stdio4003; void main(){} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test7491.d0000644000175000017500000000261214141774365023533 0ustar matthiasmatthias// EXTRA_FILES: imports/test7491a.d imports/test7491b.d struct Struct { import object; import imports.test7491a; import renamed=imports.test7491b; } struct AliasThis { Struct _struct; alias _struct this; } class Base { import object; import imports.test7491a; import renamed=imports.test7491b; } class Derived : Base { } interface Interface { import object; import imports.test7491a; import renamed=imports.test7491b; } class Impl : Interface { } static assert(__traits(compiles, Struct.object)); static assert(__traits(compiles, Struct.imports)); static assert(__traits(compiles, Struct.renamed)); static assert(__traits(compiles, AliasThis.object)); static assert(__traits(compiles, AliasThis.imports)); static assert(__traits(compiles, AliasThis.renamed)); static assert(__traits(compiles, Base.object)); static assert(__traits(compiles, Base.imports)); static assert(__traits(compiles, Base.renamed)); static assert(__traits(compiles, Derived.object)); static assert(__traits(compiles, Derived.imports)); static assert(__traits(compiles, Derived.renamed)); static assert(__traits(compiles, Interface.object)); static assert(__traits(compiles, Interface.imports)); static assert(__traits(compiles, Interface.renamed)); static assert(__traits(compiles, Impl.object)); static assert(__traits(compiles, Impl.imports)); static assert(__traits(compiles, Impl.renamed)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test11471.d0000644000175000017500000000042514141774365023604 0ustar matthiasmatthias// REQUIRED_ARGS: -profile /* DISABLED: LDC_not_x86 TEST_OUTPUT: --- compilable/test11471.d(10): Deprecation: `asm` statement is assumed to throw - mark it with `nothrow` if it does not --- */ void main() nothrow { asm { nop; } } // Error: asm statements are assumed to throw ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test1238.d0000644000175000017500000000024614141774365023525 0ustar matthiasmatthias// EXTRA_FILES: imports/test1238a.d imports/test1238b.d module test1238; import imports.test1238a; import imports.test1238b; void foo() { int qwert = zuiop; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc10870.d0000644000175000017500000000025714141774365023543 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /// interface I { /// void f(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21050.d0000644000175000017500000000135514141774365023601 0ustar matthiasmatthias/* TEST_OUTPUT: ---- instantiated:long instantiated:int ---- */ struct S { static int foo(T)(int i) { pragma(msg, "instantiated:", T.stringof); return 0; } static int foo(T)(string s) { return 1; } } alias foo0 = __traits(getOverloads, S, "foo", true)[0]; alias bar0 = foo0!long; // prints "instantiated:long" enum x = S.foo!long(0); // should not print "instantiated:long" again. static assert(bar0(3) == 0); alias bar0int = foo0!int; // prints "instantiated:int" enum y = S.foo!int(0); // should not print "instantiated:int" again. static assert(!__traits(compiles, bar0("hi"))); alias foo1 = __traits(getOverloads, S, "foo", true)[1]; alias bar1 = foo1!long; static assert(bar1("hi") == 1); static assert(!__traits(compiles, bar1(3))); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/exception.d0000644000175000017500000000033714141774365024227 0ustar matthiasmatthiasclass E2 : Exception { this() { super(null); } } class E3 : Exception { this() { super(null); } } void main() { try { } catch (E3) { } catch (E2) { } catch (Exception) { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue21614.d0000644000175000017500000000030414141774365023751 0ustar matthiasmatthias// EXTRA_FILES: imports/issue21614a.d // REQUIRED_ARGS: -i // https://issues.dlang.org/show_bug.cgi?id=21614 void logmdigammaInverse(real y) { import imports.issue21614a; findRoot(y); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/fail260.d0000644000175000017500000000121114141774365023364 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -d struct Static(uint width2, uint height2) { immutable width = width2; immutable height = height2; static Static opCall() { Static ret; return ret; } alias float E; template MultReturn(alias M1, alias M2) { alias Static!(M2.width, M1.height) MultReturn; } void opMultVectors(M2)(M2 b) { alias MultReturn!(Static, M2) ret_matrix; } } void test() { alias Static!(4, 1) matrix_stat; static matrix_stat m4 = matrix_stat(); alias Static!(1, 4) matrix_stat2; static m6 = matrix_stat2(); m6.opMultVectors(m4); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_CPPNamespaceDeclaration.d0000644000175000017500000000210114141774365027643 0ustar matthiasmatthias/* REQUIRED_ARGS: -HC -c -o- PERMUTE_ARGS: TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif namespace nameSpace { extern void fn(); namespace nameSpace2 { extern void fn2(); } extern double identity(double _param_0); } --- */ extern(C++, "nameSpace") { void fn() {} extern(C++, nameSpace2) { void fn2() {} } double identity(double) { return _param_0; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/pragmainline2.d0000644000175000017500000000203614141774365024757 0ustar matthiasmatthias/* DISABLED: LDC // FIXME - LLVM complains: `Attributes 'noinline and alwaysinline' are incompatible!` REQUIRED_ARGS: -inline -wi TEST_OUTPUT: --- compilable/pragmainline2.d(14): Warning: cannot inline function `pragmainline2.foo` compilable/pragmainline2.d(22): Warning: cannot inline function `pragmainline2.f1t` compilable/pragmainline2.d(25): Warning: cannot inline function `pragmainline2.f2t` --- */ pragma(inline, true): pragma(inline, false): pragma(inline) void foo() { pragma(inline, false); pragma(inline); pragma(inline, true); // this last one will affect to the 'foo' asm { nop; } } pragma(inline, true) void f1t() { asm { nop; } } // cannot inline pragma(inline, false) void f1f() { asm { nop; } } pragma(inline) void f1d() { asm { nop; } } void f2t() { pragma(inline, true); asm { nop; } } // cannot inline void f2f() { pragma(inline, false); asm { nop; } } void f2d() { pragma(inline); asm { nop; } } void main() { foo(); f1t(); f1f(); f1d(); f2t(); f2f(); f2d(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_791.d0000644000175000017500000000011414141774365024726 0ustar matthiasmatthias// DISABLED: LDC_not_x86 int crash() { asm { naked; ret; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ice11610.d0000644000175000017500000000400014141774365023351 0ustar matthiasmatthias struct Token { TokenType type; } enum TokenType : ushort { invalid } class Parser { bool peekIsOneOf(TokenType[] types...) { canFind(types, tokens[1].type); return true; } Token[] tokens; } /*************************************************/ // std.algorithm R find(alias pred = "a == b", R, E)(R haystack, E needle) { enum isIntegralNeedle = isSomeChar!E/* || isIntegral!E || isBoolean!E*/; return haystack; } bool canFind(alias pred = "a == b", R, E)(R haystack, E needle) if (is(typeof(find!pred(haystack, needle)))) // 1st instantiate of find template with error gagging { return find!pred(haystack, needle).length != 0; // 2nd instantiate of find template without gagging } /*************************************************/ // std.traits template CharTypeOf(T) { inout( char) idx( inout( char) ); inout(wchar) idx( inout(wchar) ); inout(dchar) idx( inout(dchar) ); shared(inout char) idx( shared(inout char) ); shared(inout wchar) idx( shared(inout wchar) ); shared(inout dchar) idx( shared(inout dchar) ); static if (is(T == enum)) { /* This line instantiates CharTypeOf!short and will make error. * But, when CharTypeOf!short is re-instantiated without gagging, * that's for correct error report, its 'members' does not re-created. * so, members' semantic will call FuncDeclaration::overloadInsert of * 'idx' functions, and will make circular linked list of * FuncDeclaration::overnext. Finally, iterating it will cause * infinite recursion and compiler segfault. */ alias .CharTypeOf!(OriginalType!T) CharTypeOf; } else static if (is(typeof(idx(T.init)) X)) { alias X CharTypeOf; } else static assert(0, T.stringof~" is not a character type"); } template isSomeChar(T) { enum isSomeChar = is(CharTypeOf!T); } template OriginalType(T) { alias OriginalType = ushort; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20406.d0000644000175000017500000000026414141774365023603 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=20406 struct S { @disable this(); this(int) {} this(ref S other) {} } void foo(S s) {} void main() { S s = S(3); foo(s); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/noreturn1.d0000644000175000017500000000426314141774365024170 0ustar matthiasmatthias/* REQUIRED_ARGS: -w TEST_OUTPUT: --- noreturn --- Basic properties and usage mentioned in the DIP: https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md */ alias noreturn = typeof(*null); pragma(msg, noreturn); static assert(!is(noreturn == void)); // Fails // static assert(is( typeof([]) == noreturn[] )); // static assert(is( typeof([][0]) == noreturn )); static assert(is( typeof(assert(0)) == noreturn )); // Does not parse yet // static assert(is( typeof(throw new Exception()) == noreturn )); static assert(is(noreturn == noreturn)); static assert(!is(noreturn == const noreturn)); static assert(is(noreturn : const noreturn)); static assert(!is(noreturn == int)); static assert(is(noreturn : int)); // Covariance static assert(is(noreturn[] : int[])); static assert(is(noreturn* : int*)); static assert(is(noreturn function() : int function())); static assert(is(noreturn delegate() : int delegate())); // Reject inverse conversions static assert(!is(int[] : noreturn[])); static assert(!is(int* : noreturn*)); static assert(!is(int function() : noreturn function())); static assert(!is(int delegate() : noreturn delegate())); static assert(noreturn.mangleof == "Nn"); // Changed from b due to conflicts with bool static assert(noreturn.sizeof == 0); static assert(noreturn.alignof == 0); static assert((noreturn*).sizeof == (int*).sizeof); static assert((noreturn[]).sizeof == (int[]).sizeof); version (DigitalMars) noreturn exits(int* p) { *p = 3; assert(false); // *p could be valid } noreturn exit(); noreturn pureexits() @nogc nothrow pure @safe { assert(0); } noreturn callpureexits() { pureexits(); } noreturn returnExits() { return pureexits(); } void alsoExits() { return assert(0); } int thisAlsoExits() { return assert(0); } void cast_() { noreturn n; int i = n; } int test1(int i) { if (exit()) return i + 1; return i - 1; } noreturn tlsNoreturn; __gshared noreturn globalNoreturn; template CreateTLS(A) { A a; } void* useTls() { alias Tnr = CreateTLS!noreturn; void* a1 = &Tnr.a; void* a2 = &tlsNoreturn; void* a3 = &globalNoreturn; return a1 < a2 ? a2 : a3; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15292.d0000644000175000017500000000032514141774365023610 0ustar matthiasmatthiasstruct NullableRef15292(T) { inout(T) get() inout { assert(false); } alias get this; } struct S15292 { NullableRef15292!S15292 n; } void main() { S15292 s; assert(s == s); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19081.d0000644000175000017500000000050514141774365023610 0ustar matthiasmatthiasvoid main() { @(1) enum { A } /// comment @(1) enum X { A } @(2) enum Y; @(1) @(2) enum Z { A } struct Test { int test; } @Test(1) enum W { A } @(1) enum V: int { A } X a; static assert(__traits(getAttributes, X).length == 1); static assert(__traits(getAttributes, X)[0] == 1); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20280.d0000644000175000017500000000025114141774365023577 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -Icompilable/extra-files // EXTRA_FILES: extra-files/test20280a.d module test20280; import test20280a; alias Charlie = Foxtrot!(0); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19778.d0000644000175000017500000000011414141774365023621 0ustar matthiasmatthiasstruct S { int[] data; } immutable X = S([]); enum len = X.data.length; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_escapes.d0000644000175000017500000000071314141774365026545 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_escapes.html // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_escapes.html /++ Backslash Escapes: \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\} But not in code: --- \{\} --- `\{\}` Nor in HTML: Nor before things that aren't punctuation: C:\dlang\dmd +/ module ddoc_markdown_escapes; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/b33.d0000644000175000017500000000021414141774365022612 0ustar matthiasmatthias// COMPILED_IMPORTS: imports/b33a.d // PERMUTE_ARGS: module b33; private import imports.b33a; size_t fn() { return find( "123" ); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_aggregate.d0000644000175000017500000000023614141774365024777 0ustar matthiasmatthias union A { TypeInfo info; void[0] result; } struct B { TypeInfo info; void[0] result; } class C { TypeInfo info; void[0] result; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc9497c.d0000644000175000017500000000036614141774365023644 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc9497c.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** foo function. Args: $(XYZ arg1, arg2) */ void foo() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test314.d0000644000175000017500000000041314141774365023433 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/a314.d imports/c314.d module imports.test314; // package imports import imports.a314; void main() { imports.a314.bug("This should work.\n"); renamed.bug("This should work.\n"); bug("This should work.\n"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16348.d0000644000175000017500000000033614141774365023615 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test16348.d module mypackage.foo; void bug() { // removing the if-else also removes the segfault if (true) {} else { import mypackage.bar; auto b = bar(); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test9766.d0000644000175000017500000000264214141774365023545 0ustar matthiasmatthias// PERMUTE_ARGS: size_t getAlign9766(size_t n) { return n; } struct S9766 { align(getAlign9766(1)): ubyte[5] pad1; ubyte var1; align(getAlign9766(2)): ubyte[5] pad2; ubyte var2; align(getAlign9766(4)): ubyte[5] pad3; ubyte var3; align(getAlign9766(8)): ubyte[5] pad4; ubyte var4; } static assert(S9766.pad1.offsetof == 0); static assert(S9766.var1.offsetof == 5); static assert(S9766.pad2.offsetof == 6); static assert(S9766.var2.offsetof == 12); static assert(S9766.pad3.offsetof == 16); static assert(S9766.var3.offsetof == 24); static assert(S9766.pad4.offsetof == 32); static assert(S9766.var4.offsetof == 40); union U9766 { struct { align(getAlign9766(1)): ubyte[5] pad1; ubyte var1; align(getAlign9766(2)): ubyte[5] pad2; ubyte var2; align(getAlign9766(4)): ubyte[5] pad3; ubyte var3; align(getAlign9766(8)): ubyte[5] pad4; ubyte var4; } } static assert(U9766.pad1.offsetof == 0); static assert(U9766.var1.offsetof == 5); static assert(U9766.pad2.offsetof == 6); static assert(U9766.var2.offsetof == 12); static assert(U9766.pad3.offsetof == 16); static assert(U9766.var3.offsetof == 24); static assert(U9766.pad4.offsetof == 32); static assert(U9766.var4.offsetof == 40); struct TestMaxAlign { align(1u << 15): ubyte a; ubyte b; } static assert(TestMaxAlign.b.offsetof == (1 << 15)); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc18361.d0000644000175000017500000000134014141774365023540 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh // REQUIRED_ARGS: -d // Test notes: 'main' is the symbol being documented (DDOC_AUTO_PSYMBOL), // 'arguments' is a parameter (DDOC_AUTO_PARAM), and 'false' is a keyword // (DDOC_AUTO_KEYWORD). /** * The main thing this program does is nothing, and I do _not want to hear any * false arguments about that! * * Macros: * DDOC_AUTO_PSYMBOL = $0 * DDOC_AUTO_KEYWORD = $0 * DDOC_AUTO_PARAM = $0 * DDOC_AUTO_PSYMBOL_SUPPRESS = HALPIMBEINGSUPPRESSED $0 * * DDOC = $(BODY) * DDOC_DECL = $0 * DDOC_MEMBER_HEADER = * DDOC_MODULE_MEMBERS = $0 * DDOC_MEMBER = $0 */ void main(string[] arguments) { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc9497d.d0000644000175000017500000000036614141774365023645 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc9497d.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh /** foo function. Args: $(XYZ arg1, arg2) */ void foo() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_lists_verbose.d0000644000175000017500000000044314141774365030005 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- -transition=vmarkdown // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_lists_verbose.html // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_lists_verbose.html /++ - list item +/ module ddoc_markdown_lists_verbose; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/riia_ctor.d0000644000175000017500000000115314141774365024201 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=17494 // REQUIRED_ARGS: -revert=dtorfields struct S { ~this() {} } class C { S s; this() nothrow {} } // https://issues.dlang.org/show_bug.cgi?id=17505 struct Array { int[] _payload; ~this() { import core.stdc.stdlib : free; free(_payload.ptr); } } class Scanner { Array arr; this() @safe {} } // https://issues.dlang.org/show_bug.cgi?id=17506 struct TreeMap { this() @disable; this(TTree tree) { this.tree = tree; } TTree tree; } struct TTree { this() @disable; this(int foo) {} ~this() {} } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/shortened_methods.d0000644000175000017500000000142214141774365025743 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=shortenedMethods class A { int _x = 34; // short syntax works in all contexts @property x() => _x; @property x(int v) => _x = v; // including with contracts @property y() in(true) => _x; // or other auto returns auto foo() @safe => assert(0); // or normal method defintions bool isNull() => this is null; } class B : A{ // short syntax also overrides the same as long syntax override bool isNull() => this !is null; } static assert((new A).x == 34); string test() => "hello"; // works at any scope static assert(test() == "hello"); // works normally static assert(is(typeof(&test) == string function())); // same normal type void func() { int a; int nested() => a; // and at nested scopes too } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/minimal.d0000644000175000017500000000064514141774365023661 0ustar matthiasmatthias// DFLAGS: // PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/minimal/verify_symbols.sh // REQUIRED_ARGS: -defaultlib= // EXTRA_SOURCES: extra-files/minimal/object.d // This test ensures an empty main with a struct and enum, built with a minimal // runtime, does not generate ModuleInfo or exception handling code, and does not // require TypeInfo struct S { } enum E { e0 = 0, e1 = 1 } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21227.d0000644000175000017500000000100214141774365023574 0ustar matthiasmatthias// REQUIRED_ARGS: -Jcompilable/imports // EXTRA_FILES: imports/test21227/a..b.txt imports/test21227/a.txt imports/test21227/..foo/a.txt // https://issues.dlang.org/show_bug.cgi?id=21227 void bar(string x) {} void test21227() { import("./test21227/a.txt").bar; import("test21227//a..b.txt").bar; import("test21227/..foo/a.txt").bar; version(Windows) { import(r".\test21227\a.txt").bar; import(r"test21227\\a..b.txt").bar; import(r"test21227\..foo\a.txt").bar; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/minimal3.d0000644000175000017500000000155114141774365023741 0ustar matthiasmatthias// DFLAGS: // REQUIRED_ARGS: -defaultlib= // EXTRA_SOURCES: extra-files/minimal/object.d /**********************************************/ // https://issues.dlang.org/show_bug.cgi?id=19234 void issue19234() { static struct A {} A[10] a; A[10] b; b[] = a[]; } /**********************************************/ // https://issues.dlang.org/show_bug.cgi?id=22005 void issue22005() { enum int[4] foo = [1,2,3,4]; static foreach (i, e; foo) { } } /**********************************************/ // https://issues.dlang.org/show_bug.cgi?id=22006 void issue22006() { alias size_t = typeof(int.sizeof); alias AliasSeq(T...) = T; foreach (size_t i, e; [0, 1, 2, 3]) { } static foreach (size_t i, e; [0, 1, 2, 3]) { } foreach (size_t i, e; AliasSeq!(0, 1, 2, 3)) { } static foreach (size_t i, e; AliasSeq!(0, 1, 2, 3)) { } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testheader12567b.d0000644000175000017500000000062314141774365025126 0ustar matthiasmatthias/* REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/testheader12567b.di PERMUTE_ARGS: OUTPUT_FILES: ${RESULTS_DIR}/compilable/testheader12567b.di TEST_OUTPUT: --- === ${RESULTS_DIR}/compilable/testheader12567b.di // D import file generated from 'compilable/testheader12567b.d' deprecated("message") module header12567b; void main(); --- */ deprecated("message") module header12567b; void main() {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test19540.d0000644000175000017500000000010314141774365023602 0ustar matthiasmatthiasalias inst = templ!(); template templ(T = typeof(new class {})) {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test17908.d0000644000175000017500000000035114141774365023615 0ustar matthiasmatthias// PERMUTE ARGS: @disable void foo() {} void foo(int) {} alias g = foo; // make sure the order of declaration // doesn't change anything void bar(int) {} @disable void bar() {} alias h = bar; void main() { g(10); h(10); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18955.d0000644000175000017500000000133414141774365023622 0ustar matthiasmatthiasversion(Windows) { extern (C++, std) { struct char_traits(Char) { } extern (C++, class) struct basic_string(T, Traits) { } alias test_string = basic_string!(char, char_traits!char); } extern (C++) void test(ref const(std.test_string) str) {} version(D_LP64) static assert(test.mangleof == "?test@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@@std@@@Z"); else { version(CRuntime_DigitalMars) static assert(test.mangleof == "?test@@YAXABV?$basic_string@std@DU?$char_traits@std@D@1@@std@@@Z"); else static assert(test.mangleof == "?test@@YAXABV?$basic_string@DU?$char_traits@D@std@@@std@@@Z"); } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/iasm_labeloperand.d0000644000175000017500000000151114141774365025665 0ustar matthiasmatthias// LLVM mach-o backend: "32-bit absolute addressing is not supported in 64-bit mode" // DISABLED: LDC_not_x86 LDC_osx version (D_InlineAsm_X86) version = TestInlineAsm; else version (D_InlineAsm_X86_64) version = TestInlineAsm; else pragma(msg, "Inline asm not supported, not testing."); version (TestInlineAsm) { void testInlineAsm() { asm { L1: nop; nop; nop; nop; mov EAX, dword ptr L1; // Check back references mov EAX, dword ptr L2; // Check forward references mov EAX, dword ptr DS:L1; // Not really useful in standard use, but who knows. mov EAX, dword ptr FS:L2; // Once again, not really useful, but it is valid. mov EAX, dword ptr CS:L1; // This is what the first test case should implicitly be. L2: nop; nop; nop; nop; } } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue20704.d0000644000175000017500000000076114141774365023757 0ustar matthiasmatthias/* https://issues.dlang.org/show_bug.cgi?id=20704 REQUIRED_ARGS: -preview=rvaluerefparam */ void f1(T)(const auto ref T arg = T.init) {} void f2(T)(const ref T arg = T.init) {} void f3(T)(const auto ref T arg = 0) {} void f4(T)(const ref T arg = 0) {} struct S { int _; } class C { int _; } void main () { int i; f1!int(i); f2!int(i); f3!int(i); f4!int(i); f1!int(); f2!int(); f3!int(); f4!int(); f1!S(); f2!S(); f1!C(); f2!C(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc9.d0000644000175000017500000000111214141774365023223 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh // https://issues.dlang.org/show_bug.cgi?id=273 /// Template Documentation (OK) template Template(T) { } /// Function Documentation (Not included at all by DDoc) void Function(T)(T x) { } /// Class Documentation (OK) class Class(T) { } /// Struct Documentation struct Struct(T) { } /// Union Documentation union Union(T) { } /// Template documentation with anonymous enum template TemplateWithAnonEnum(T) { enum { TemplateWithAnonEnum = 1 } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test10752.d0000644000175000017500000000025214141774365023603 0ustar matthiasmatthias// EXTRA_FILES: imports/test10752.d import imports.test10752; void main() { static assert(!__traits(compiles, priv)); static assert(!__traits(compiles, priv)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20065.d0000644000175000017500000000031614141774365023602 0ustar matthiasmatthiasalias AliasSeq(T...) = T; void main() { enum string[] array1 = [AliasSeq!("foo")]; static assert(array1 == ["foo"]); enum string[] array2 = [AliasSeq!()]; static assert(array2 == []); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16303.d0000644000175000017500000000053614141774365023606 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=16303 void yayf(void function(int*) fp); void yayd(void delegate(int*) dg); void bar() { void function(const(int)* p) fp; yayf(fp); // should be good but produces error void delegate(const(int)* p) dg; yayd(dg); // should be good but produces error } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/mixintype.d0000644000175000017500000000155414141774365024261 0ustar matthiasmatthias alias Int = mixin("int"); alias Lint = mixin("Int"); int test1(mixin("int")* p) { mixin("int")[] a; mixin("int[]") b; mixin("int[] c;"); mixin("*p = c[0];"); *p = mixin("c[0]"); return *p + a[0] + b[0] + c[0]; } /******************************************/ void test2() { auto a = __traits(allMembers, mixin(__MODULE__)); } /*****************************************/ void test3() { char val; int mod; enum b = __traits(compiles, mixin("*cast(int*)&val + mod")); static assert(b == true); } /********************************************/ struct S { int fielda; int fieldb; } template Foo4(alias T) { enum Foo4 = true; } void test4() { S sa; auto a = Foo4!( __traits(getMember,sa,"fielda") ); S sb; enum getStuff = q{ __traits(getMember,sb,"fieldb") }; auto b = Foo4!(mixin(getStuff)); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test20318.d0000644000175000017500000000027514141774365023607 0ustar matthiasmatthias// DISABLED: LDC // no support for -profile=gc yet // https://issues.dlang.org/show_bug.cgi?id=20318 // REQUIRED_ARGS: -dip1008 -profile=gc void main() { throw new Exception("msg"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test22214.d0000644000175000017500000000032114141774365023574 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22214 struct S { struct T { } } void main() { const S s; static if (__traits(compiles, { auto t = s.T; })) { auto t = s.T; } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc7795.d0000644000175000017500000000051614141774365023475 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc7795; struct TimeValue { this(int hour, int minute, int second = 0, int ms = 0) {} } /// struct DateTime { /// this(int x, TimeValue t = TimeValue(0, 0)) {} } void main() { } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_982.d0000644000175000017500000000014214141774365024731 0ustar matthiasmatthiasimport std.datetime.stopwatch; void main() { auto r = cast(Duration[2])benchmark!({},{})(1); }./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/diag20916.d0000644000175000017500000000301014141774365023526 0ustar matthiasmatthias/* TEST_OUTPUT: --- compilable/diag20916.d(32): Deprecation: `alias fb this` is deprecated compilable/diag20916.d(37): instantiated from here: `jump2!(Foo)` compilable/diag20916.d(42): instantiated from here: `jump1!(Foo)` compilable/diag20916.d(32): Deprecation: function `diag20916.FooBar.toString` is deprecated compilable/diag20916.d(37): instantiated from here: `jump2!(Foo)` compilable/diag20916.d(42): instantiated from here: `jump1!(Foo)` compilable/diag20916.d(32): Deprecation: template `diag20916.Bar.toString()()` is deprecated compilable/diag20916.d(37): instantiated from here: `jump2!(Bar)` compilable/diag20916.d(43): instantiated from here: `jump1!(Bar)` compilable/diag20916.d(21): Deprecation: variable `diag20916.Something.something` is deprecated compilable/diag20916.d(24): instantiated from here: `nestedCheck!(Something)` --- */ #line 1 struct FooBar { deprecated string toString() const { return "42"; } int value = 42; } struct Foo { FooBar fb; deprecated alias fb this; } struct Bar { deprecated string toString()() const { return "42"; } int value = 42; } template nestedCheck(T) { enum nestedCheck = T.something.init == 0; } struct Constraint (T) if(nestedCheck!T) { T value; } struct Something { deprecated int something; } void jump2(T) (T value) { assert(value.toString() == "42"); } void jump1(T) (T value) { jump2(value); } void main () { jump1(Foo.init); jump1(Bar.init); Constraint!Something c1; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test313c.d0000644000175000017500000000027714141774365023605 0ustar matthiasmatthias// REQUIRED_ARGS: -de // EXTRA_FILES: imports/pkgmod313/mod.d imports/pkgmod313/package.d import imports.pkgmod313; void test() { imports.pkgmod313.foo(); imports.pkgmod313.bar(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ldc_github_637.d0000644000175000017500000000007614141774365024734 0ustar matthiasmatthiasextern(C): struct Value { this(string) {} string s; }./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test1754.d0000644000175000017500000000023114141774365023522 0ustar matthiasmatthias// EXTRA_FILES: imports/test1754a.d imports/test1754b.d module test1754; import imports.test1754a; import imports.test1754b; void foo() { bar(); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue18097.d0000644000175000017500000000037314141774365023772 0ustar matthiasmatthias// REQUIRED_ARGS: -unittest module issue18097; unittest // this first unittest is needed to trigger the bug { } unittest // second unittest { auto a = &mixin(__traits(identifier, __traits(parent, { }))); auto b = &__traits(parent, { }); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test21861.d0000644000175000017500000000161614141774365023613 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=21861 int f() { @("S") struct S {} @("U") union U {} @("C") class C {} // OK <- CTFE fails on this: @("E") enum E { X } // OK <- CTFE fails on this: @("f") int f(int x) { return x + 2; } // OK <- CTFE fails on this: @(&f) int a; @(1) @(2) int b = 4, c; @(3) extern(C) int d = 3; enum uda1 = __traits(getAttributes, a); enum uda2 = __traits(getAttributes, b); enum uda3 = __traits(getAttributes, c); // These are to trigger a compiler assert if parser is updated in the future static assert(!__traits(compiles, mixin("{ @(1) { int x; int y; } }"))); static assert(!__traits(compiles, mixin("{ @(1): int x; int y; }"))); // 3+2 1 2 4 1 3 return uda1[0](3) + uda2[0] + uda2[1] + b + uda3[0] + d; } static assert(f() == 16); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test18651a.d0000644000175000017500000000035714141774365023760 0ustar matthiasmatthias// REQUIRED_ARGS: -deps=${RESULTS_DIR}/compilable/test18651a.deps // EXTRA_SOURCES: imports/test18651/b.d // EXTRA_FILES: imports/test18651/c.d imports/test18651/algorithm.d imports/test18651/datetime.d import imports.test18651.datetime; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testAliasLookup.d0000644000175000017500000000155714141774365025361 0ustar matthiasmatthias// REQUIRED_ARGS: -preview=fixAliasThis // https://issues.dlang.org/show_bug.cgi?id=16086 struct A { void tail() {} } struct S16086 { struct Inner2 { Inner a; alias a this; } struct Inner { int unique_identifier_name; int tail = 2; } Inner2 inner; alias inner this; auto works() { return unique_identifier_name; } auto fails() { int a = tail; return tail; // Line 22 // The workaround: return this.tail; } } // https://issues.dlang.org/show_bug.cgi?id=16082 struct S16082 { struct Inner { int any_name_but_modulename; int aliasthis = 5; } Inner inner; alias inner this; auto works() { return any_name_but_modulename; } auto fails() { return aliasthis; // Line 20 } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc9727.d0000644000175000017500000000053714141774365023475 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc9727; /** The function foo. */ void foo(int x); /** */ unittest { foo(1); } /** foo can be used like this: */ unittest { foo(2); } /** foo can also be used like this: */ unittest { foo(3); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testcolor.sh0000755000175000017500000000331014141774365024433 0ustar matthiasmatthias#!/usr/bin/env bash set -eo pipefail compare() { local actual="$1" local expected="$2" if [ "$actual" != "$expected" ] ; then printf 'Expected: %q\n' "$expected" printf 'Actual: %q\n' "$actual" hexdump -C <<<"$expected" hexdump -C <<<"$actual" exit 1 fi } normalize() { tr -d "\n\r" ; } check() { local actual expected actual=$(echo "$2" | ("$DMD" -c -o- "$1" - 2>&1 || true) | normalize) compare "$actual" "$3" } expectedWithoutColor=__stdin.d\(2\):\ Error:\ no\ identifier\ for\ declarator\ \`test\` expectedWithColor=$'\033'\[1m__stdin.d\(2\):\ $'\033'\[1\;31mError:\ $'\033'\[mno\ identifier\ for\ declarator\ \`$'\033'\[0\;36m$'\033'\[m$'\033'\[1mtest$'\033'\[0\;36m$'\033'\[m\` check -c "test" "$expectedWithoutColor" check -color=auto "test" "$expectedWithoutColor" check -color=on "test" "$expectedWithColor" check -color=off "test" "$expectedWithoutColor" gooCode="void foo() {} void main() { goo(); }" gooExpectedWithoutColor='__stdin.d(1): Error: undefined identifier `goo`, did you mean function `foo`?' gooExpectedWithColor=$'\033[1m__stdin.d(1): \033[1;31mError: \033[mundefined identifier `\033[0;36m\033[m\033[1mgoo\033[0;36m\033[m`, did you mean function `\033[0;36m\033[m\033[1mfoo\033[0;36m\033[m`?' check -color=on "$gooCode" "$gooExpectedWithColor" check -color=off "$gooCode" "$gooExpectedWithoutColor" if [[ "$(script --version)" == script\ from\ util-linux\ * ]] then actual="$(SHELL="$(command -v bash)" TERM="faketerm" script -q -c "echo test | ( $DMD -c -o- -)" /dev/null | normalize)" || true if [[ "$actual" != '^@^@'* ]] # 'script' weirdness on CircleCI then compare "$actual" "$expectedWithColor" fi fi ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8922b.d0000644000175000017500000000040714141774365023675 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/bug8922.d void test() { import imports.bug8922; static assert(!__traits(compiles, __traits(parent, imports))); enum x = __traits(parent, imports.bug8922).stringof; static assert(x == "package imports"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/cppmangle_abitag.d0000644000175000017500000000430414141774365025504 0ustar matthiasmatthias// DISABLED: win32 win64 // REQUIRED_ARGS: -extern-std=c++11 /* * Test C++ abi-tag name mangling. * https://issues.dlang.org/show_bug.cgi?id=19949 */ import core.attribute; extern(C++): alias Tuple(A...) = A; enum foo_bar = gnuAbiTag("foo", "bar"); @foo_bar struct S { int i; this(int); } @foo_bar extern __gshared int a; static assert(a.mangleof == "_Z1aB3barB3foo"); extern __gshared S b; static assert(b.mangleof == "_Z1bB3barB3foo"); @foo_bar int f(); static assert(f.mangleof == "_Z1fB3barB3foov"); S gs(int); S gss(S, int); static assert(gs.mangleof == "_Z2gsB3barB3fooi"); static assert(gss.mangleof == "_Z3gss1SB3barB3fooi"); @foo_bar S fss(S, int); static assert(gs.mangleof == "_Z2gsB3barB3fooi"); T gt(T)(int); T gtt(T)(T, int); static assert(gt!S.mangleof == "_Z2gtI1SB3barB3fooET_i"); static assert(gtt!S.mangleof == "_Z3gttI1SB3barB3fooET_S1_i"); @foo_bar T ft(T)(int); // matches Clang and GCC <= 6 static assert(ft!S.mangleof == "_Z2ftB3barB3fooI1SB3barB3fooET_i"); @foo_bar T ftt(T)(T, int); // matches Clang and GCC <= 6 static assert(ftt!S.mangleof == "_Z3fttB3barB3fooI1SB3barB3fooET_S1_i"); // GCC >= 6 only @gnuAbiTag("ENN") enum E0 { a = 0xa, } E0 fe(); E0 fei(int i)(); static assert(fe.mangleof == "_Z2feB3ENNv"); static assert(fei!0.mangleof == "_Z3feiILi0EE2E0B3ENNv"); // Linux std::string // https://issues.dlang.org/show_bug.cgi?id=14956#c13 extern(C++, "std") { struct allocator(T); struct char_traits(CharT); extern(C++, "__cxx11") { @gnuAbiTag("cxx11") struct basic_string(CharT, Traits=char_traits!CharT, Allocator=allocator!CharT) { const char* data(); size_t length() const; } } alias string_ = basic_string!char; } string_* toString(const char*); static assert(toString.mangleof == "_Z8toStringB5cxx11PKc"); @gnuAbiTag("A", "B") { void fun0(); static assert(fun0.mangleof == "_Z4fun0B1AB1Bv"); } @gnuAbiTag("C", "D"): void fun1(); static assert(fun1.mangleof == "_Z4fun1B1CB1Dv"); void fun2(); static assert(fun2.mangleof == "_Z4fun2B1CB1Dv"); auto fun3() { @gnuAbiTag("Nested") extern(C++) struct T {} return T(); } static assert(fun3.mangleof == "_Z4fun3B1CB1DB6Nestedv"); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc6491.d0000644000175000017500000000042014141774365023457 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh module ddoc6491; import core.cpuid; enum int c6491 = 4; /// test void bug6491a(int a = ddoc6491.c6491, string b = core.cpuid.vendor); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test16578b.d0000644000175000017500000000033314141774365023761 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=16578 void main() { string[string] opts; switch (2) { case 0: opts["a"] = ""; { case 1: break; } default: } } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc_markdown_tables_verbose.d0000644000175000017500000000054214141774365030121 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- -transition=vmarkdown // TEST_OUTPUT_FILE: extra-files/ddoc_markdown_tables_verbose.html // OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_tables_verbose.html /++ Table: | this | that | | ---- | ---- | | cell | cell | +/ module test.compilable.ddoc_markdown_tables_verbose; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test22292.d0000644000175000017500000000417314141774365023613 0ustar matthiasmatthias// https://issues.dlang.org/show_bug.cgi?id=22292 // Original case class C1 { C1 c1; this () pure { c1 = this; } } immutable x = cast(immutable)r; auto r() { C1 c1 = new C1; return c1; } // Reference stored in another class template Test2() { class C1 { C2 c2; this () pure { C1 a = this; c2 = new C2(a); } } class C2 { C1 c1; this (C1 c) pure { c1 = c; } } immutable x = cast(immutable)r; auto r() { C1 c1 = new C1(); return c1; } } alias test2 = Test2!(); // Ditto but using a struct in the middle template Test3() { class C0 { S1 s1; this() { s1 = S1(this); } } struct S1 { C1 c1; this (C0 c) { c1 = new C1(c); } } class C1 { C0 c0; this(C0 c) { c0 = c; } } immutable x = cast(immutable)r; auto r() { C0 c0 = new C0(); return c0; } } alias test3 = Test3!(); // From https://issues.dlang.org/show_bug.cgi?id=22114 template Test4() { public class Test1(T) { private Test2!T val; this() { val = new Test2!T(this); } private class Test2(T) { private Test1!(T) m_source; this(Test1!T source) { m_source = source; } } } public class Demo { auto val = new Test1!int(); } } alias test4 = Test4!(); // ditto template Test5() { public @nogc class TestA(T) { private TestB!T valA; private TestB!T valB; this() { valB = valA = new TestB!T(this); } private @nogc class TestB(T) { private TestA!(T) m_source; this(TestA!T source) { m_source = source; } } } public class Demo { auto val = new TestA!int(); } } alias test5 = Test5!(); ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/dtoh_VarDeclaration.d0000644000175000017500000000331114141774365026140 0ustar matthiasmatthias/* REQUIRED_ARGS: -HC -c -o- PERMUTE_ARGS: TEST_OUTPUT: --- // Automatically generated by Digital Mars D Compiler #pragma once #include #include #include #include #ifdef CUSTOM_D_ARRAY_TYPE #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE #else /// Represents a D [] array template struct _d_dynamicArray final { size_t length; T *ptr; _d_dynamicArray() : length(0), ptr(NULL) { } _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } T& operator[](const size_t idx) { assert(idx < length); return ptr[idx]; } const T& operator[](const size_t idx) const { assert(idx < length); return ptr[idx]; } }; #endif #if !defined(_d_real) # define _d_real long double #endif extern "C" int32_t z; extern int32_t t; struct S; struct S2; class C2; union U; union U2; extern "C" size_t v; extern nullptr_t typeof_null; extern nullptr_t inferred_null; extern int32_t i; extern _d_real r; extern int32_t si[4$?:32=u|64=LLU$]; extern const _d_dynamicArray< const int32_t > di; extern void* ii; extern const int32_t* const pi; extern int16_t(*func)(float , bool , ...); --- */ int x = 42; extern int y; extern (C) int z; extern (C++) __gshared int t; extern (C) struct S; extern (C++) struct S2; extern (C) class C; extern (C++) class C2; extern (C) union U; extern (C++) union U2; extern (C) size_t v; extern (C++) __gshared typeof(null) typeof_null = null; extern (C++) __gshared inferred_null = null; extern(C++): __gshared { int i; real r; int[4] si; const int[] di; int[int] ii; const int* pi; short function(float, bool, ...) func; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test8922a.d0000644000175000017500000000040314141774365023670 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_FILES: imports/bug8922.d import imports.bug8922; void test() { static assert(!__traits(compiles, __traits(parent, imports))); enum x = __traits(parent, imports.bug8922).stringof; static assert(x == "package imports"); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/test15371.d0000644000175000017500000000041614141774365023607 0ustar matthiasmatthias// EXTRA_FILES: imports/test15371.d import imports.test15371; void main() { A a; static assert(__traits(hasMember, A, "a")); static assert(__traits(getOverloads, A, "fun").length == 3); static assert(__traits(compiles, __traits(getMember, a, "a") )); } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/issue20995.d0000644000175000017500000000023214141774365023764 0ustar matthiasmatthias/* REQUIRED_ARGS: -preview=dip1021 https://issues.dlang.org/show_bug.cgi?id=20995 */ void foo() @live { throw new Exception(""); } void main () {} ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/quadratic.d0000644000175000017500000000143714141774365024210 0ustar matthiasmatthias/* PERMUTE_ARGS: -O * If not careful, this can produce exponential tree traversal times * when compiling the generated opEquals() function. */ struct Param { bool verbose; bool vcg_ast; bool showColumns; bool vtls; bool vtemplates; bool vgc; bool vfield; bool vcomplex; int useDeprecated; bool stackstomp; bool useUnitTests; bool useInline; bool useDIP25; bool noDIP25; bool useDIP1021; bool release; bool a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z; uint debuglevel; void* debugids; uint versionlevel; void* versionids; const(char)[] defaultlibname; const(char)[] debuglibname; const(char) mscrtlib; void* moduleDeps; int messageStyle = 1; } struct Global { Param params; } ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/ddoc14633.d0000644000175000017500000000047114141774365023542 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -w -o- /** Blah Params: T = some type test = something overnext = for testing overloaded functions */ template case1(T) { void case1(R)(R test) { } void case1(R)(R test, string overnext) { } } ///ditto alias case2 = case1!int; ./ldc-1.28.0-src/tests/d2/dmd-testsuite/compilable/testhelp.d0000644000175000017500000000127314141774365024061 0ustar matthiasmatthias/* DISABLED: LDC REQUIRED_ARGS: -conf=compilable/extra-files/empty.conf --help PERMUTE_ARGS: TEST_OUTPUT: ---- $r:DMD(32|64) D Compiler .*$ Copyright (C) 1999-$n$ by The D Language Foundation, All Rights Reserved written by Walter Bright Documentation: https://dlang.org/ Config file: $p:compilable/extra-files/empty.conf$ Usage: dmd [