~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

Viewing changes to libclamav/c++/bytecode2llvm.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-07-15 01:08:10 UTC
  • mfrom: (0.35.47 sid)
  • Revision ID: package-import@ubuntu.com-20140715010810-ru66ek4fun2iseba
Tags: 0.98.4+dfsg-2~ubuntu13.10.1
No-change backport to saucy (LP: #1341962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#ifndef _WIN32
25
25
#include <sys/time.h>
26
26
#endif
 
27
 
27
28
#include "ClamBCModule.h"
28
29
#include "ClamBCDiagnostics.h"
29
 
#include "llvm/Analysis/DebugInfo.h"
30
30
#include "llvm/ADT/DenseMap.h"
31
31
#include "llvm/ADT/BitVector.h"
32
32
#include "llvm/ADT/PostOrderIterator.h"
39
39
#include "llvm/Analysis/ScalarEvolution.h"
40
40
#include "llvm/Analysis/Verifier.h"
41
41
#include "llvm/AutoUpgrade.h"
42
 
#include "llvm/CallingConv.h"
43
 
#include "llvm/DerivedTypes.h"
44
 
#include "llvm/Function.h"
45
42
#include "llvm/ExecutionEngine/ExecutionEngine.h"
46
43
#include "llvm/ExecutionEngine/JIT.h"
47
44
#include "llvm/ExecutionEngine/JITEventListener.h"
48
 
#include "llvm/LLVMContext.h"
49
 
#include "llvm/Intrinsics.h"
50
 
#include "llvm/Module.h"
51
45
#include "llvm/PassManager.h"
52
46
#include "llvm/Support/Compiler.h"
53
47
#include "llvm/Support/Debug.h"
57
51
#include "llvm/Support/MemoryBuffer.h"
58
52
#include "llvm/Support/raw_ostream.h"
59
53
#include "llvm/Support/SourceMgr.h"
60
 
#include "llvm/Support/IRBuilder.h"
61
54
#include "llvm/Support/PrettyStackTrace.h"
62
55
 
63
56
#ifdef LLVM29
69
62
#include "llvm/Support/Signals.h"
70
63
#include "llvm/Support/Threading.h"
71
64
#include "llvm/Support/ThreadLocal.h"
 
65
#include "llvm/PassRegistry.h"
 
66
#if LLVM_VERSION < 33
72
67
#include "llvm/IntrinsicInst.h"
73
 
#include "llvm/PassRegistry.h"
 
68
#else
 
69
#include "llvm/IR/IntrinsicInst.h"
 
70
#endif
74
71
#else
75
72
#include "llvm/System/DataTypes.h"
76
73
#include "llvm/System/Host.h"
93
90
#else
94
91
#include "llvm/Target/TargetSelect.h"
95
92
#endif
96
 
#include "llvm/Target/TargetData.h"
97
93
#include "llvm/Target/TargetOptions.h"
98
94
#include "llvm/Support/TargetFolder.h"
99
95
#include "llvm/Transforms/Scalar.h"
105
101
#include <cerrno>
106
102
#include <string>
107
103
 
 
104
#if LLVM_VERSION < 32
 
105
#include "llvm/Analysis/DebugInfo.h"
 
106
#else
 
107
#include "llvm/DebugInfo.h"
 
108
#endif
 
109
 
 
110
#if LLVM_VERSION < 32
 
111
#include "llvm/Support/IRBuilder.h"
 
112
#include "llvm/Target/TargetData.h"
 
113
#elif LLVM_VERSION < 33
 
114
#include "llvm/IRBuilder.h"
 
115
#include "llvm/DataLayout.h"
 
116
#else
 
117
#include "llvm/IR/IRBuilder.h"
 
118
#include "llvm/IR/DataLayout.h"
 
119
#endif
 
120
 
 
121
#if LLVM_VERSION < 33
 
122
#include "llvm/CallingConv.h"
 
123
#include "llvm/DerivedTypes.h"
 
124
#include "llvm/Function.h"
 
125
#include "llvm/LLVMContext.h"
 
126
#include "llvm/Intrinsics.h"
 
127
#include "llvm/Module.h"
 
128
#else
 
129
#include "llvm/IR/CallingConv.h"
 
130
#include "llvm/IR/DerivedTypes.h"
 
131
#include "llvm/IR/Function.h"
 
132
#include "llvm/IR/LLVMContext.h"
 
133
#include "llvm/IR/Intrinsics.h"
 
134
#include "llvm/IR/Module.h"
 
135
#endif
 
136
 
 
137
#if LLVM_VERSION >= 34
 
138
#include "llvm/Analysis/CFG.h"
 
139
#endif
 
140
 
108
141
//#define TIMING
109
142
#undef TIMING
110
143
 
111
144
#include "llvm/Config/config.h"
 
145
#ifdef ENABLE_THREADS
112
146
#if !ENABLE_THREADS
113
147
#error "Thread support was explicitly disabled. Cannot continue"
114
148
#endif
 
149
#endif
 
150
 
 
151
#ifdef LLVM_ENABLE_THREADS
 
152
#if !LLVM_ENABLE_THREADS
 
153
#error "Thread support was explicitly disabled. Cannot continue"
 
154
#endif
 
155
#endif
115
156
 
116
157
#ifdef _GLIBCXX_PARALLEL
117
158
#error "libstdc++ parallel mode is not supported for ClamAV. Please remove -D_GLIBCXX_PARALLEL from CXXFLAGS!"
126
167
#undef PACKAGE_URL
127
168
#include "clamav-config.h"
128
169
#endif
 
170
 
 
171
#include <openssl/ssl.h>
 
172
#include <openssl/err.h>
 
173
 
 
174
extern "C" {
 
175
#include "libclamav/crypto.h"
 
176
}
 
177
 
129
178
#include "dconf.h"
130
179
#include "clamav.h"
131
180
#include "clambc.h"
132
181
#include "bytecode.h"
133
182
#include "bytecode_priv.h"
134
183
#include "type_desc.h"
135
 
extern "C" {
136
 
#include "md5.h"
137
 
}
138
184
 
139
185
#define MODULE "libclamav JIT: "
140
186
 
268
314
    jit_exception_handler();
269
315
}
270
316
 
 
317
#if LLVM_VERSION < 33
271
318
void llvm_error_handler(void *user_data, const std::string &reason)
 
319
#else
 
320
void llvm_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag = true)
 
321
#endif
272
322
{
273
323
    // Output it to stderr, it might exceed the 1k/4k limit of cli_errmsg
274
324
    cli_errmsg("[Bytecode JIT]: [LLVM error] %s\n", reason.c_str());
377
427
        if (!cli_debug_flag)
378
428
            return;
379
429
        cli_dbgmsg_internal("[Bytecode JIT]: emitted function %s of %ld bytes at %p\n",
 
430
#if LLVM_VERSION < 31
380
431
                            F.getNameStr().c_str(), (long)Size, Code);
 
432
#else
 
433
                            F.getName().str().c_str(), (long)Size, Code);
 
434
#endif
381
435
    }
382
436
};
383
437
 
670
724
        CallInst* AbrtC = CallInst::Create(func_abort, "", AbrtBB);
671
725
        AbrtC->setCallingConv(CallingConv::C);
672
726
        AbrtC->setTailCall(true);
 
727
#if LLVM_VERSION < 32
673
728
        AbrtC->setDoesNotReturn(true);
674
729
        AbrtC->setDoesNotThrow(true);
 
730
#else
 
731
        AbrtC->setDoesNotReturn();
 
732
        AbrtC->setDoesNotThrow();
 
733
#endif
675
734
        new UnreachableInst(F.getContext(), AbrtBB);
676
735
        IRBuilder<false> Builder(F.getContext());
677
736
 
1021
1080
        : bc(bc), M(M), Context(M->getContext()), EE(EE),
1022
1081
        PM(PM),PMUnsigned(PMUnsigned), TypeMap(), apiFuncs(apiFuncs),apiMap(apiMap),
1023
1082
        compiledFunctions(cFuncs), BytecodeID("bc"+Twine(bc->id)),
 
1083
#if LLVM_VERSION < 32
1024
1084
        Folder(EE->getTargetData()), Builder(Context, Folder), Values(), CF(CF) {
 
1085
#else
 
1086
        Folder(EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) {
 
1087
#endif
1025
1088
 
1026
1089
        for (unsigned i=0;i<cli_apicall_maxglobal - _FIRST_GLOBAL;i++) {
1027
1090
            unsigned id = cli_globals[i].globalid;
1152
1215
            }
1153
1216
            V = SI->getOperand(0);
1154
1217
        }
 
1218
#if LLVM_VERSION < 32
1155
1219
        if (EE->getTargetData()->getPointerSize() == 8) {
 
1220
#else
 
1221
        if (EE->getDataLayout()->getPointerSize() == 8) {
 
1222
#endif
1156
1223
            // eliminate useless trunc, GEP can take i64 too
1157
1224
            if (TruncInst *I = dyn_cast<TruncInst>(V)) {
1158
1225
                Value *Src = I->getOperand(0);
1227
1294
            Functions[j]->setLinkage(GlobalValue::InternalLinkage);
1228
1295
#ifdef C_LINUX
1229
1296
            /* bb #2270, this should really be fixed either by LLVM or GCC.*/
 
1297
#if LLVM_VERSION < 32
1230
1298
            Functions[j]->addFnAttr(Attribute::constructStackAlignmentFromInt(16));
 
1299
#else
 
1300
        // TODO: How does this translate?
 
1301
//          Functions[j]->addFnAttr(Attribute::StackAlignment);
 
1302
#endif
1231
1303
#endif
1232
1304
        }
1233
1305
        constType *I32Ty = Type::getInt32Ty(Context);
1528
1600
                            }
1529
1601
                            CallInst *CI = Builder.CreateCall(DestF, ARRAYREF(Value*, args.begin(), args.end()));
1530
1602
                            CI->setCallingConv(CallingConv::Fast);
 
1603
#if LLVM_VERSION < 32
1531
1604
                            CI->setDoesNotThrow(true);
 
1605
#else
 
1606
                            CI->setDoesNotThrow();
 
1607
#endif
1532
1608
                            if (CI->getType()->getTypeID() != Type::VoidTyID)
1533
1609
                                Store(inst->dest, CI);
1534
1610
                            break;
1549
1625
                                args.push_back(convertOperand(func, DestF->getFunctionType()->getParamType(a+1), op));
1550
1626
                            }
1551
1627
                            CallInst *CI = Builder.CreateCall(DestF, ARRAYREFVECTOR(Value*, args));
 
1628
#if LLVM_VERSION < 32
1552
1629
                            CI->setDoesNotThrow(true);
 
1630
#else
 
1631
                            CI->setDoesNotThrow();
 
1632
#endif
1553
1633
                            Store(inst->dest, CI);
1554
1634
                            }
1555
1635
                            break;
1682
1762
                            Dst = Builder.CreatePointerCast(Dst, PointerType::getUnqual(Type::getInt8Ty(Context)));
1683
1763
                            Value *Src = convertOperand(func, inst, inst->u.three[1]);
1684
1764
                            Src = Builder.CreatePointerCast(Src, PointerType::getUnqual(Type::getInt8Ty(Context)));
 
1765
#if LLVM_VERSION < 32
1685
1766
                            Value *Len = convertOperand(func, EE->getTargetData()->getIntPtrType(Context), inst->u.three[2]);
 
1767
#else
 
1768
                            Value *Len = convertOperand(func, EE->getDataLayout()->getIntPtrType(Context), inst->u.three[2]);
 
1769
#endif
1686
1770
                            CallInst *c = Builder.CreateCall3(CF->FRealmemcmp, Dst, Src, Len);
1687
1771
                            c->setTailCall(true);
1688
1772
                            c->setDoesNotThrow();
1707
1791
                            {
1708
1792
                                CallInst *C = Builder.CreateCall(CF->FBSwap16, convertOperand(func, inst, inst->u.unaryop));
1709
1793
                                C->setTailCall(true);
 
1794
#if LLVM_VERSION < 32
1710
1795
                                C->setDoesNotThrow(true);
 
1796
#else
 
1797
                                C->setDoesNotThrow();
 
1798
#endif
1711
1799
                                Store(inst->dest, C);
1712
1800
                                break;
1713
1801
                            }
1715
1803
                            {
1716
1804
                                CallInst *C = Builder.CreateCall(CF->FBSwap32, convertOperand(func, inst, inst->u.unaryop));
1717
1805
                                C->setTailCall(true);
 
1806
#if LLVM_VERSION < 32
1718
1807
                                C->setDoesNotThrow(true);
 
1808
#else
 
1809
                                C->setDoesNotThrow();
 
1810
#endif
1719
1811
                                Store(inst->dest, C);
1720
1812
                                break;
1721
1813
                            }
1723
1815
                            {
1724
1816
                                CallInst *C = Builder.CreateCall(CF->FBSwap64, convertOperand(func, inst, inst->u.unaryop));
1725
1817
                                C->setTailCall(true);
 
1818
#if LLVM_VERSION < 32
1726
1819
                                C->setDoesNotThrow(true);
 
1820
#else
 
1821
                                C->setDoesNotThrow();
 
1822
#endif
1727
1823
                                Store(inst->dest, C);
1728
1824
                                break;
1729
1825
                            }
1828
1924
        // entrypoint can only be C, emit wrapper
1829
1925
        Function *F = Function::Create(Functions[0]->getFunctionType(),
1830
1926
                                       Function::ExternalLinkage,
 
1927
#if LLVM_VERSION < 33
1831
1928
                                       Functions[0]->getName()+"_wrap", M);
 
1929
#else
 
1930
                                       Functions[0]->getName().str()+"_wrap", M);
 
1931
#endif
1832
1932
        F->setDoesNotThrow();
1833
1933
        BasicBlock *BB = BasicBlock::Create(Context, "", F);
1834
1934
        std::vector<Value*> Args;
1887
1987
                                          "clamjit.fail", M);
1888
1988
    CF->FHandler->setDoesNotReturn();
1889
1989
    CF->FHandler->setDoesNotThrow();
 
1990
#if LLVM_VERSION == 32
 
1991
    CF->FHandler->addFnAttr(Attributes::NoInline);
 
1992
#else
1890
1993
    CF->FHandler->addFnAttr(Attribute::NoInline);
1891
 
 
 
1994
#endif
1892
1995
    EE->addGlobalMapping(CF->FHandler, (void*)(intptr_t)jit_exception_handler);
1893
1996
    EE->InstallLazyFunctionCreator(noUnknownFunctions);
1894
1997
    EE->getPointerToFunction(CF->FHandler);
1911
2014
#endif
1912
2015
                                         M);
1913
2016
    CF->FMemset->setDoesNotThrow();
 
2017
#if LLVM_VERSION < 32
1914
2018
    CF->FMemset->setDoesNotCapture(1, true);
 
2019
#else
 
2020
    CF->FMemset->setDoesNotCapture(1);
 
2021
#endif
1915
2022
 
1916
2023
    args.clear();
1917
2024
    args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));
1931
2038
#endif
1932
2039
                                          M);
1933
2040
    CF->FMemmove->setDoesNotThrow();
 
2041
#if LLVM_VERSION < 32
1934
2042
    CF->FMemmove->setDoesNotCapture(1, true);
 
2043
#else
 
2044
    CF->FMemmove->setDoesNotCapture(1);
 
2045
#endif
1935
2046
 
1936
2047
    CF->FMemcpy = Function::Create(FuncTy_4, GlobalValue::ExternalLinkage,
1937
2048
#ifdef LLVM30
1941
2052
#endif
1942
2053
                                         M);
1943
2054
    CF->FMemcpy->setDoesNotThrow();
 
2055
#if LLVM_VERSION < 32
1944
2056
    CF->FMemcpy->setDoesNotCapture(1, true);
 
2057
#else
 
2058
    CF->FMemcpy->setDoesNotCapture(1);
 
2059
#endif
1945
2060
 
1946
2061
    args.clear();
1947
2062
    args.push_back(Type::getInt16Ty(Context));
1981
2096
    args.clear();
1982
2097
    args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));
1983
2098
    args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));
 
2099
#if LLVM_VERSION < 32
1984
2100
    args.push_back(EE->getTargetData()->getIntPtrType(Context));
 
2101
#else
 
2102
    args.push_back(EE->getDataLayout()->getIntPtrType(Context));
 
2103
#endif
1985
2104
    FuncTy_5 = FunctionType::get(Type::getInt32Ty(Context),
1986
2105
                                 args, false);
1987
2106
    CF->FRealmemcmp = Function::Create(FuncTy_5, GlobalValue::ExternalLinkage, "memcmp", M);
2201
2320
static unsigned char name_salt[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253 };
2202
2321
static void setGuard(unsigned char* guardbuf)
2203
2322
{
2204
 
    cli_md5_ctx ctx;
2205
2323
    char salt[48];
2206
2324
    memcpy(salt, name_salt, 16);
2207
2325
    for(unsigned i = 16; i < 48; i++)
2208
 
        salt[i] = cli_rndnum(255);
 
2326
        salt[i] = cli_rndnum(255);
2209
2327
 
2210
 
    cli_md5_init(&ctx);
2211
 
    cli_md5_update(&ctx, salt, 48);
2212
 
    cli_md5_final(guardbuf, &ctx);
 
2328
    cl_hash_data("md5", salt, 48, guardbuf, NULL);
2213
2329
}
2214
 
 
 
2330
#if LLVM_VERSION < 32
2215
2331
static void addFPasses(FunctionPassManager &FPM, bool trusted, const TargetData *TD)
 
2332
#else
 
2333
static void addFPasses(FunctionPassManager &FPM, bool trusted, const DataLayout *TD)
 
2334
#endif
2216
2335
{
2217
2336
    // Set up the optimizer pipeline.  Start with registering info about how
2218
2337
    // the target lays out data structures.
 
2338
#if LLVM_VERSION < 32
2219
2339
    FPM.add(new TargetData(*TD));
 
2340
#else
 
2341
    FPM.add(new DataLayout(*TD));
 
2342
#endif
2220
2343
    // Promote allocas to registers.
2221
2344
    FPM.add(createPromoteMemoryToRegisterPass());
2222
2345
    FPM.add(new BrSimplifier());
2238
2361
        // Create the JIT.
2239
2362
        std::string ErrorMsg;
2240
2363
        EngineBuilder builder(M);
 
2364
 
 
2365
#if LLVM_VERSION >= 31
 
2366
        TargetOptions Options;
 
2367
#ifdef CL_DEBUG
 
2368
        //disable this for now, it leaks
 
2369
        Options.JITEmitDebugInfo = false;
 
2370
//      Options.JITEmitDebugInfo = true;
 
2371
#else
 
2372
        Options.JITEmitDebugInfo = false;
 
2373
#endif
 
2374
#if LLVM_VERSION < 34
 
2375
        Options.DwarfExceptionHandling = false;
 
2376
#else
 
2377
        // TODO: How to do this now?
 
2378
#endif
 
2379
        builder.setTargetOptions(Options);
 
2380
#endif
 
2381
 
2241
2382
        builder.setErrorStr(&ErrorMsg);
2242
2383
        builder.setEngineKind(EngineKind::JIT);
2243
2384
        builder.setOptLevel(CodeGenOpt::Default);
2262
2403
        addFunctionProtos(&CF, EE, M);
2263
2404
 
2264
2405
        FunctionPassManager OurFPM(M), OurFPMUnsigned(M);
 
2406
#if LLVM_VERSION < 32
2265
2407
        M->setDataLayout(EE->getTargetData()->getStringRepresentation());
 
2408
#else
 
2409
        M->setDataLayout(EE->getDataLayout()->getStringRepresentation());
 
2410
#endif
 
2411
#if LLVM_VERSION < 31
2266
2412
        M->setTargetTriple(sys::getHostTriple());
2267
 
 
 
2413
#else
 
2414
        M->setTargetTriple(sys::getDefaultTargetTriple());
 
2415
#endif
 
2416
#if LLVM_VERSION < 32
2268
2417
        addFPasses(OurFPM, true, EE->getTargetData());
2269
2418
        addFPasses(OurFPMUnsigned, false, EE->getTargetData());
 
2419
#else
 
2420
        addFPasses(OurFPM, true, EE->getDataLayout());
 
2421
        addFPasses(OurFPMUnsigned, false, EE->getDataLayout());
 
2422
#endif
 
2423
 
2270
2424
 
2271
2425
        //TODO: create a wrapper that calls pthread_getspecific
2272
2426
        unsigned maxh = cli_globals[0].offset + sizeof(struct cli_bc_hooks);
2373
2527
            }
2374
2528
        }
2375
2529
        PassManager PM;
 
2530
#if LLVM_VERSION < 32
2376
2531
        PM.add(new TargetData(*EE->getTargetData()));
 
2532
#else
 
2533
        PM.add(new DataLayout(*EE->getDataLayout()));
 
2534
#endif
2377
2535
        // TODO: only run this on the untrusted bytecodes, not all of them...
2378
2536
        if (has_untrusted)
2379
2537
            PM.add(createClamBCRTChecks());
2438
2596
    llvm_install_error_handler(llvm_error_handler);
2439
2597
#ifdef CL_DEBUG
2440
2598
    sys::PrintStackTraceOnErrorSignal();
 
2599
#if LLVM_VERSION >= 34
 
2600
    llvm::EnablePrettyStackTrace();
 
2601
#endif
2441
2602
#else
 
2603
#if LLVM_VERSION < 34
2442
2604
    llvm::DisablePrettyStackTrace = true;
2443
2605
#endif
 
2606
#endif
2444
2607
    atexit(do_shutdown);
2445
2608
 
 
2609
#if LLVM_VERSION < 31
2446
2610
#ifdef CL_DEBUG
2447
2611
    //disable this for now, it leaks
2448
2612
    llvm::JITEmitDebugInfo = false;
2451
2615
    llvm::JITEmitDebugInfo = false;
2452
2616
#endif
2453
2617
    llvm::DwarfExceptionHandling = false;
 
2618
#endif
2454
2619
    llvm_start_multithreaded();
2455
2620
 
2456
2621
    // If we have a native target, initialize it to ensure it is linked in and
2609
2774
void stop(const char *msg, llvm::Function* F, llvm::Instruction* I)
2610
2775
{
2611
2776
    if (F && F->hasName()) {
 
2777
#if LLVM_VERSION < 31
2612
2778
        cli_warnmsg("[Bytecode JIT] in function %s: %s", F->getNameStr().c_str(), msg);
 
2779
#else
 
2780
        cli_warnmsg("[Bytecode JIT] in function %s: %s", F->getName().str().c_str(), msg);
 
2781
#endif
2613
2782
    } else {
2614
2783
        cli_warnmsg("[Bytecode JIT] %s", msg);
2615
2784
    }
2676
2845
static bool getLocationInfo(const Value *V, std::string &DisplayName,
2677
2846
                            std::string &Type, unsigned &LineNo,
2678
2847
                            std::string &File, std::string &Dir) {
 
2848
#if LLVM_VERSION < 33
2679
2849
  DICompileUnit Unit;
 
2850
#else
 
2851
  StringRef G;
 
2852
  StringRef H;
 
2853
#endif
2680
2854
  DIType TypeD;
2681
2855
 
2682
2856
  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
2688
2862
    if (!D.empty())
2689
2863
      DisplayName = D;
2690
2864
    LineNo = Var.getLineNumber();
 
2865
#if LLVM_VERSION < 33
2691
2866
    Unit = Var.getCompileUnit();
 
2867
#else
 
2868
    G = Var.getFilename();
 
2869
    H = Var.getDirectory();
 
2870
#endif
2692
2871
    TypeD = Var.getType();
2693
2872
  } else if (Function *F = dyn_cast<Function>(const_cast<Value*>(V))){
2694
2873
    Value *DIF = findDbgSubprogramDeclare(F);
2699
2878
    if (!D.empty())
2700
2879
      DisplayName = D;
2701
2880
    LineNo = Var.getLineNumber();
 
2881
#if LLVM_VERSION < 33
2702
2882
    Unit = Var.getCompileUnit();
 
2883
#else
 
2884
    G = Var.getFilename();
 
2885
    H = Var.getDirectory();
 
2886
#endif
2703
2887
    TypeD = Var.getType();
2704
2888
  } else {
2705
2889
    const DbgDeclareInst *DDI = findDbgDeclare(V);
2710
2894
    if (!D.empty())
2711
2895
      DisplayName = D;
2712
2896
    LineNo = Var.getLineNumber();
 
2897
#if LLVM_VERSION < 33
2713
2898
    Unit = Var.getCompileUnit();
 
2899
#else
 
2900
    // getFilename and getDirectory are not defined
 
2901
    G = StringRef();
 
2902
    H = StringRef();
 
2903
#endif
2714
2904
    TypeD = Var.getType();
2715
2905
  }
2716
2906
 
2717
2907
  StringRef T = TypeD.getName();
2718
2908
  if (!T.empty())
2719
2909
    Type = T;
2720
 
  StringRef F = Unit.getFilename();
2721
 
  if (!F.empty())
2722
 
    File = F;
2723
 
  StringRef D = Unit.getDirectory();
2724
 
  if (!D.empty())
2725
 
    Dir = D;
 
2910
#if LLVM_VERSION < 33
 
2911
  StringRef G = Unit.getFilename();
 
2912
  StringRef H = Unit.getDirectory();
 
2913
#endif
 
2914
  if (!G.empty())
 
2915
    File = G;
 
2916
  if (!H.empty())
 
2917
    Dir = H;
2726
2918
  return true;
2727
2919
}
2728
2920
#endif