Ignore:
Timestamp:
Jun 6, 2017, 6:20:55 PM (2 years ago)
Author:
cameron
Message:

Restore check-ins from the last several days

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5489 r5493  
    2121#include <unistd.h>
    2222#include <stdio.h>
    23 #ifdef HAS_ADDRESS_SANITIZER
    24 #include <sanitizer/asan_interface.h>
    25 #endif
    26 #ifdef HAS_LIBUNWIND
     23#if defined(HAS_MACH_VM_TYPES)
     24#include <mach/vm_types.h>
     25extern void _thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb, unsigned skip);
     26static_assert(sizeof(vm_address_t) == sizeof(uintptr_t), "");
     27#elif defined(HAS_LIBUNWIND)
    2728#define UNW_LOCAL_ONLY
    2829#include <libunwind.h>
    29 using unw_word_t = unw_word_t;
    30 #elif HAS_EXECINFO
     30static_assert(sizeof(unw_word_t) <= sizeof(uintptr_t), "");
     31#elif defined(HAS_EXECINFO)
    3132#include <execinfo.h>
    32 #include <boost/integer.hpp>
    33 using unw_word_t = boost::uint_t<sizeof(void *) * CHAR_BIT>::exact;
    34 #else
    35 using unw_word_t = uint64_t;
     33static_assert(sizeof(void *) == sizeof(uintptr_t), "");
    3634#endif
    3735
     
    247245    size = CreateZExtOrTrunc(size, sizeTy);
    248246    CallInst * const ptr = CreateCall(f, size);
    249     ptr->setTailCall();
    250247    CreateAssert(ptr, "CreateMalloc: returned null pointer");
    251248    return ptr;
     
    259256    IntegerType * const sizeTy = getSizeTy();
    260257    PointerType * const voidPtrTy = getVoidPtrTy();
    261     #ifdef STDLIB_HAS_ALIGNED_ALLOC
    262     Function * f = m->getFunction("aligned_alloc");
    263     if (LLVM_UNLIKELY(f == nullptr)) {
    264         FunctionType * const fty = FunctionType::get(voidPtrTy, {sizeTy, sizeTy}, false);
    265         f = Function::Create(fty, Function::ExternalLinkage, "aligned_alloc", m);
    266         f->setCallingConv(CallingConv::C);
    267         f->setDoesNotAlias(0);
    268     }
    269     #else
    270     Function * f = m->getFunction("posix_memalign");
    271     if (LLVM_UNLIKELY(f == nullptr)) {
    272         FunctionType * const fty = FunctionType::get(getInt32Ty(), {voidPtrTy->getPointerTo(), sizeTy, sizeTy}, false);
    273         f = Function::Create(fty, Function::ExternalLinkage, "posix_memalign", m);
    274         f->setCallingConv(CallingConv::C);
    275         f->setDoesNotAlias(1);
    276     }
    277     #endif
     258
    278259    size = CreateZExtOrTrunc(size, sizeTy);
    279260    ConstantInt * const align = ConstantInt::get(sizeTy, alignment);
    280261    if (codegen::EnableAsserts) {
    281         CreateAssert(CreateICmpEQ(CreateURem(size, align), ConstantInt::get(sizeTy, 0)),
    282                      "CreateAlignedMalloc: size must be an integral multiple of alignment.");
    283     }
    284     #ifdef STDLIB_HAS_ALIGNED_ALLOC
    285     CallInst * const ptr = CreateCall(f, {align, size});
    286     ptr->setTailCall();
    287     #else
    288     Value * ptr = CreateAlloca(voidPtrTy);
    289     CallInst * success = CreateCall(f, {ptr, align, size});
    290     success->setTailCall();
    291     if (codegen::EnableAsserts) {
    292         CreateAssert(CreateICmpEQ(success, getInt32(0)),
    293                      "CreateAlignedMalloc: posix_memalign reported bad allocation");
    294     }
    295     ptr = CreateLoad(ptr);
    296     #endif
     262        CreateAssertZero(CreateURem(size, align), "CreateAlignedMalloc: size must be an integral multiple of alignment.");
     263    }
     264
     265    Value * ptr = nullptr;
     266    if (hasAlignedAlloc()) {
     267        Function * f = m->getFunction("aligned_alloc");
     268        if (LLVM_UNLIKELY(f == nullptr)) {
     269            FunctionType * const fty = FunctionType::get(voidPtrTy, {sizeTy, sizeTy}, false);
     270            f = Function::Create(fty, Function::ExternalLinkage, "aligned_alloc", m);
     271            f->setCallingConv(CallingConv::C);
     272            f->setDoesNotAlias(0);
     273        }
     274        ptr = CreateCall(f, {align, size});
     275    } else if (hasPosixMemalign()) {
     276        Function * f = m->getFunction("posix_memalign");
     277        if (LLVM_UNLIKELY(f == nullptr)) {
     278            FunctionType * const fty = FunctionType::get(getInt32Ty(), {voidPtrTy->getPointerTo(), sizeTy, sizeTy}, false);
     279            f = Function::Create(fty, Function::ExternalLinkage, "posix_memalign", m);
     280            f->setCallingConv(CallingConv::C);
     281            f->setDoesNotAlias(0);
     282            f->setDoesNotAlias(1);
     283        }
     284        ptr = CreateAlloca(voidPtrTy);
     285        CallInst * success = CreateCall(f, {ptr, align, size});
     286        if (codegen::EnableAsserts) {
     287            CreateAssertZero(success, "CreateAlignedMalloc: posix_memalign reported bad allocation");
     288        }
     289        ptr = CreateLoad(ptr);
     290    } else {
     291        report_fatal_error("stdlib.h does not contain either aligned_alloc or posix_memalign");
     292    }
    297293    CreateAssert(ptr, "CreateAlignedMalloc: returned null pointer.");
    298294    return ptr;
    299295}
    300296
    301 Value * CBuilder::CreateRealloc(Value * const ptr, Value * size) {
     297inline bool CBuilder::hasAlignedAlloc() const {
     298    return mDriver && mDriver->hasExternalFunction("aligned_alloc");
     299}
     300
     301
     302inline bool CBuilder::hasPosixMemalign() const {
     303    return mDriver && mDriver->hasExternalFunction("posix_memalign");
     304}
     305
     306Value * CBuilder::CreateRealloc(Value * const ptr, Value * const size) {
    302307    Module * const m = getModule();
    303308    IntegerType * const sizeTy = getSizeTy();
     
    311316        f->setDoesNotAlias(1);
    312317    }
    313     Value * const addr = CreatePointerCast(ptr, voidPtrTy);
    314     size = CreateZExtOrTrunc(size, sizeTy);
    315     CallInst * const ci = CreateCall(f, {addr, size});
    316     ci->setTailCall();
     318    CallInst * const ci = CreateCall(f, {CreatePointerCast(ptr, voidPtrTy), CreateZExtOrTrunc(size, sizeTy)});
     319
    317320    return CreatePointerCast(ci, ptr->getType());
    318321}
    319322
    320 void CBuilder::CreateFree(Value * ptr) {
     323void CBuilder::CreateFree(Value * const ptr) {
    321324    assert (ptr->getType()->isPointerTy());
    322325    Module * const m = getModule();
     
    328331        f->setCallingConv(CallingConv::C);
    329332    }
    330     ptr = CreatePointerCast(ptr, voidPtrTy);
    331     CreateCall(f, ptr)->setTailCall();
     333    CreateCall(f, CreatePointerCast(ptr, voidPtrTy));
    332334}
    333335
     
    485487        Value * const addrValue = CreatePtrToInt(addr, intPtrTy);
    486488        Value * const pageOffset = CreateURem(addrValue, ConstantInt::get(intPtrTy, getpagesize()));
    487         CreateAssert(CreateICmpEQ(pageOffset, ConstantInt::getNullValue(intPtrTy)), "CreateMUnmap: addr must be a multiple of the page size");
     489        CreateAssertZero(pageOffset, "CreateMUnmap: addr must be a multiple of the page size");
    488490        Value * const boundCheck = CreateICmpULT(addrValue, CreateSub(ConstantInt::getAllOnesValue(intPtrTy), CreateZExtOrTrunc(len, intPtrTy)));
    489491        CreateAssert(boundCheck, "CreateMUnmap: addresses in [addr, addr+len) are outside the valid address space range");
     
    494496
    495497PointerType * CBuilder::getVoidPtrTy() const {
    496     return TypeBuilder<void *, true>::get(getContext());
     498    return TypeBuilder<void *, false>::get(getContext());
    497499}
    498500
     
    641643}
    642644
    643 void __report_failure(const char * msg, const unw_word_t * trace, const uint32_t n) {
     645void __report_failure(const char * msg, const uintptr_t * trace, const uint32_t n) {
    644646    raw_fd_ostream out(STDERR_FILENO, false);
    645     #if defined(HAS_LIBUNWIND) || defined(HAS_EXECINFO)
    646647    if (trace) {
    647648        SmallVector<char, 4096> tmp;
     
    667668        out << trace_string.str();
    668669    }
    669     #endif
    670670    out.changeColor(raw_fd_ostream::WHITE, true);
    671671    out << "Assertion `" << msg << "' failed.\n";
    672672    out.resetColor();
    673673    out.flush();
    674 }
    675 
    676 void CBuilder::CreateAssert(Value * assertion, StringRef failureMessage) {
     674
     675}
     676
     677#if defined(HAS_MACH_VM_TYPES)
     678
     679/*
     680 * Copyright (c) 1999, 2007 Apple Inc. All rights reserved.
     681 *
     682 * @APPLE_LICENSE_HEADER_START@
     683 *
     684 * This file contains Original Code and/or Modifications of Original Code
     685 * as defined in and that are subject to the Apple Public Source License
     686 * Version 2.0 (the 'License'). You may not use this file except in
     687 * compliance with the License. Please obtain a copy of the License at
     688 * http://www.opensource.apple.com/apsl/ and read it before using this
     689 * file.
     690 *
     691 * The Original Code and all software distributed under the License are
     692 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
     693 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
     694 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
     695 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
     696 * Please see the License for the specific language governing rights and
     697 * limitations under the License.
     698 *
     699 * @APPLE_LICENSE_HEADER_END@
     700 */
     701
     702#include <pthread.h>
     703#include <mach/mach.h>
     704#include <mach/vm_statistics.h>
     705#include <stdlib.h>
     706
     707#if defined(__i386__) || defined(__x86_64__)
     708#define FP_LINK_OFFSET 1
     709#elif defined(__ppc__) || defined(__ppc64__)
     710#define FP_LINK_OFFSET 2
     711#else
     712#error  ********** Unimplemented architecture
     713#endif
     714
     715#define INSTACK(a)      ((uintptr_t)(a) >= stackbot && (uintptr_t)(a) <= stacktop)
     716#if defined(__ppc__) || defined(__ppc64__) || defined(__x86_64__)
     717#define ISALIGNED(a)    ((((uintptr_t)(a)) & 0xf) == 0)
     718#elif defined(__i386__)
     719#define ISALIGNED(a)    ((((uintptr_t)(a)) & 0xf) == 8)
     720#endif
     721
     722__private_extern__  __attribute__((noinline))
     723void
     724_thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb, unsigned skip)
     725{
     726    void *frame, *next;
     727    pthread_t self = pthread_self();
     728    uintptr_t stacktop = (uintptr_t)(pthread_get_stackaddr_np(self));
     729    uintptr_t stackbot = stacktop - (uintptr_t)(pthread_get_stacksize_np(self));
     730   
     731    *nb = 0;
     732   
     733    /* make sure return address is never out of bounds */
     734    stacktop -= (FP_LINK_OFFSET + 1) * sizeof(void *);
     735   
     736    /*
     737     * The original implementation called the first_frame_address() function,
     738     * which returned the stack frame pointer.  The problem was that in ppc,
     739     * it was a leaf function, so no new stack frame was set up with
     740     * optimization turned on (while a new stack frame was set up without
     741     * optimization).  We now inline the code to get the stack frame pointer,
     742     * so we are consistent about the stack frame.
     743     */
     744#if defined(__i386__) || defined(__x86_64__)
     745    frame = __builtin_frame_address(0);
     746#elif defined(__ppc__) || defined(__ppc64__)
     747    /* __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421 */
     748    __asm__ volatile("mr %0, r1" : "=r" (frame));
     749#endif
     750    if(!INSTACK(frame) || !ISALIGNED(frame))
     751        return;
     752#if defined(__ppc__) || defined(__ppc64__)
     753    /* back up the stack pointer up over the current stack frame */
     754    next = *(void **)frame;
     755    if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
     756        return;
     757    frame = next;
     758#endif
     759    while (skip--) {
     760        next = *(void **)frame;
     761        if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
     762            return;
     763        frame = next;
     764    }
     765    while (max--) {
     766        buffer[*nb] = *(vm_address_t *)(((void **)frame) + FP_LINK_OFFSET);
     767        (*nb)++;
     768        next = *(void **)frame;
     769        if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
     770            return;
     771        frame = next;
     772    }
     773}
     774#endif
     775
     776void CBuilder::__CreateAssert(Value * const assertion, StringRef failureMessage) {
    677777    if (LLVM_UNLIKELY(codegen::EnableAsserts)) {
    678778        Module * const m = getModule();
     779        if (LLVM_UNLIKELY(isa<ConstantInt>(assertion))) {
     780            if (LLVM_UNLIKELY(cast<ConstantInt>(assertion)->isZero())) {
     781                report_fatal_error(failureMessage);
     782            } else {
     783                return;
     784            }
     785        }
     786        Type * const stackTy = TypeBuilder<uintptr_t, false>::get(getContext());
     787        PointerType * const stackPtrTy = stackTy->getPointerTo();
     788        PointerType * const int8PtrTy = getInt8PtrTy();
    679789        Function * function = m->getFunction("assert");
    680         IntegerType * const int1Ty = getInt1Ty();
    681790        if (LLVM_UNLIKELY(function == nullptr)) {
    682791            auto ip = saveIP();
    683             PointerType * const int8PtrTy = getInt8PtrTy();
    684             IntegerType * const unwWordTy = TypeBuilder<unw_word_t, false>::get(getContext());
    685             PointerType * const unwWordPtrTy = unwWordTy->getPointerTo();
    686             FunctionType * fty = FunctionType::get(getVoidTy(), { int1Ty, int8PtrTy, unwWordPtrTy, getInt32Ty() }, false);
     792            IntegerType * const int1Ty = getInt1Ty();
     793            FunctionType * fty = FunctionType::get(getVoidTy(), { int1Ty, int8PtrTy, stackPtrTy, getInt32Ty() }, false);
    687794            function = Function::Create(fty, Function::PrivateLinkage, "assert", m);
    688795            function->setDoesNotThrow();
     
    710817            restoreIP(ip);
    711818        }
    712         if (assertion->getType() != int1Ty) {
    713             assertion = CreateICmpNE(assertion, Constant::getNullValue(assertion->getType()));
    714         }
    715         SmallVector<unw_word_t, 64> stack;
    716         #ifdef HAS_LIBUNWIND
     819
     820        SmallVector<uint64_t, 64> stack;
     821        #if defined(HAS_MACH_VM_TYPES)
     822        for (;;) {
     823            unsigned int n;
     824            _thread_stack_pcs(reinterpret_cast<vm_address_t *>(stack.data()), stack.capacity(), &n, 1);
     825            if (LLVM_UNLIKELY(n < stack.capacity() || stack[n - 1] == 0)) {
     826                while (n >= 1 && stack[n - 1] == 0) {
     827                    n -= 1;
     828                }
     829                stack.set_size(n);
     830                break;
     831            }
     832            stack.reserve(n * 2);
     833        }
     834        #elif defined(HAS_LIBUNWIND)
    717835        unw_context_t context;
    718836        // Initialize cursor to current frame for local unwinding.
     
    727845                break;
    728846            }
    729             stack.push_back(pc);
     847            stack.push_back(static_cast<uint64_t>(pc));
    730848        }
    731849        #elif defined(HAS_EXECINFO)
     
    739857        }
    740858        #endif
    741         IntegerType * const stackTy = TypeBuilder<unw_word_t, false>::get(getContext());
    742         PointerType * const stackPtrTy = stackTy->getPointerTo();
    743         GlobalVariable * ip_trace = nullptr;
    744         const auto n = stack.size();
    745         for (GlobalVariable & gv : m->getGlobalList()) {
    746             Type * const ty = gv.getValueType();
    747             if (ty->isArrayTy() && ty->getArrayElementType() == stackTy && ty->getArrayNumElements() == n) {
    748                 const ConstantDataArray * const array = cast<ConstantDataArray>(gv.getOperand(0));
    749                 bool found = true;
    750                 for (auto i = n - 1; i != 0; --i) {
    751                     if (LLVM_LIKELY(array->getElementAsInteger(i) != stack[i])) {
    752                         found = false;
     859        Value * trace = nullptr;
     860        ConstantInt * depth = nullptr;
     861        if (stack.empty()) {
     862            trace = ConstantPointerNull::get(stackPtrTy);
     863            depth = getInt32(0);
     864        } else {
     865            const auto n = stack.size() - 1;
     866            for (GlobalVariable & gv : m->getGlobalList()) {
     867                Type * const ty = gv.getValueType();
     868                if (ty->isArrayTy() && ty->getArrayElementType() == stackTy && ty->getArrayNumElements() == n) {
     869                    const ConstantDataArray * const array = cast<ConstantDataArray>(gv.getOperand(0));
     870                    bool found = true;
     871                    for (size_t i = 0; i < n; ++i) {
     872                        if (LLVM_LIKELY(array->getElementAsInteger(i) != stack[i + 1])) {
     873                            found = false;
     874                            break;
     875                        }
     876                    }
     877                    if (LLVM_UNLIKELY(found)) {
     878                        trace = &gv;
    753879                        break;
    754880                    }
    755881                }
    756                 if (LLVM_UNLIKELY(found)) {
    757                     ip_trace = &gv;
    758                     break;
    759                 }
    760882            }
    761         }
    762         if (LLVM_LIKELY(ip_trace == nullptr)) {
    763             Constant * const initializer = ConstantDataArray::get(getContext(), stack);
    764             ip_trace = new GlobalVariable(*m, initializer->getType(), true, GlobalVariable::InternalLinkage, initializer);
    765         }
    766         Value * const trace = CreatePointerCast(ip_trace, stackPtrTy);
    767         IRBuilder<>::CreateCall(function, {assertion, GetString(failureMessage), trace, getInt32(n)});
     883            if (LLVM_LIKELY(trace == nullptr)) {
     884                Constant * const initializer = ConstantDataArray::get(getContext(), ArrayRef<uint64_t>(stack.data() + 1, n));
     885                trace = new GlobalVariable(*m, initializer->getType(), true, GlobalVariable::InternalLinkage, initializer);
     886            }
     887            trace = CreatePointerCast(trace, stackPtrTy);
     888            depth = getInt32(n);
     889        }
     890        IRBuilder<>::CreateCall(function, {assertion, GetString(failureMessage), trace, depth});
    768891    }
    769892}
     
    833956    CreateAssert(value, "CreateCeilLog2: value cannot be zero");
    834957    Value * m = CreateCountReverseZeroes(CreateSub(value, ConstantInt::get(ty, 1)));
    835     return CreateSub(ConstantInt::get(m->getType(), ty->getBitWidth() - 1), m);
     958    return CreateSub(ConstantInt::get(m->getType(), ty->getBitWidth()), m);
    836959}
    837960
     
    860983
    861984#define CHECK_ADDRESS(Ptr) \
    862     if (codegen::EnableAsserts) { \
    863         Function * const isPoisoned = LinkFunction("__asan_region_is_poisoned", __asan_region_is_poisoned); \
    864         auto arg = isPoisoned->arg_begin(); \
    865         Value * const addr = CreatePointerCast(Ptr, arg->getType()); \
    866         Constant * const size = ConstantInt::get((++arg)->getType(), Ptr->getType()->getPointerElementType()->getPrimitiveSizeInBits() / 8); \
     985    if (LLVM_UNLIKELY(hasAddressSanitizer())) { \
     986        Module * const m = getModule(); \
     987        PointerType * const voidPtrTy = getVoidPtrTy(); \
     988        IntegerType * const sizeTy = getSizeTy(); \
     989        Function * isPoisoned = m->getFunction("__asan_region_is_poisoned"); \
     990        if (LLVM_UNLIKELY(isPoisoned == nullptr)) { \
     991            isPoisoned = Function::Create(FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy}, false), Function::ExternalLinkage, "__asan_region_is_poisoned", m); \
     992            isPoisoned->setCallingConv(CallingConv::C); \
     993            isPoisoned->setDoesNotAlias(0); \
     994            isPoisoned->setDoesNotAlias(1); \
     995        } \
     996        Value * const addr = CreatePointerCast(Ptr, voidPtrTy); \
     997        ConstantInt * const size = ConstantInt::get(sizeTy, Ptr->getType()->getPointerElementType()->getPrimitiveSizeInBits() / 8); \
    867998        Value * check = CreateCall(isPoisoned, { addr, size }); \
    868999        check = CreateICmpEQ(check, ConstantPointerNull::get(cast<PointerType>(isPoisoned->getReturnType()))); \
     
    8981029
    8991030#endif
     1031
     1032inline bool CBuilder::hasAddressSanitizer() const {
     1033    return codegen::EnableAsserts && mDriver && mDriver->hasExternalFunction("__asan_region_is_poisoned");
     1034}
     1035
     1036LoadInst * CBuilder::CreateAlignedLoad(Value * Ptr, unsigned Align, const char * Name) {
     1037    if (codegen::EnableAsserts) {
     1038        DataLayout DL(getModule());
     1039        IntegerType * const intPtrTy = cast<IntegerType>(DL.getIntPtrType(Ptr->getType()));
     1040        Value * alignmentOffset = CreateURem(CreatePtrToInt(Ptr, intPtrTy), ConstantInt::get(intPtrTy, Align));
     1041        CreateAssertZero(alignmentOffset, "CreateAlignedLoad: pointer is misaligned");
     1042    }
     1043    LoadInst * LI = CreateLoad(Ptr, Name);
     1044    LI->setAlignment(Align);
     1045    return LI;
     1046}
     1047
     1048LoadInst * CBuilder::CreateAlignedLoad(Value * Ptr, unsigned Align, const Twine & Name) {
     1049    if (codegen::EnableAsserts) {
     1050        DataLayout DL(getModule());
     1051        IntegerType * const intPtrTy = cast<IntegerType>(DL.getIntPtrType(Ptr->getType()));
     1052        Value * alignmentOffset = CreateURem(CreatePtrToInt(Ptr, intPtrTy), ConstantInt::get(intPtrTy, Align));
     1053        CreateAssertZero(alignmentOffset, "CreateAlignedLoad: pointer is misaligned");
     1054    }
     1055    LoadInst * LI = CreateLoad(Ptr, Name);
     1056    LI->setAlignment(Align);
     1057    return LI;
     1058}
     1059
     1060LoadInst * CBuilder::CreateAlignedLoad(Value * Ptr, unsigned Align, bool isVolatile, const Twine & Name) {
     1061    if (codegen::EnableAsserts) {
     1062        DataLayout DL(getModule());
     1063        IntegerType * const intPtrTy = cast<IntegerType>(DL.getIntPtrType(Ptr->getType()));
     1064        Value * alignmentOffset = CreateURem(CreatePtrToInt(Ptr, intPtrTy), ConstantInt::get(intPtrTy, Align));
     1065        CreateAssertZero(alignmentOffset, "CreateAlignedLoad: pointer is misaligned");
     1066    }
     1067    LoadInst * LI = CreateLoad(Ptr, isVolatile, Name);
     1068    LI->setAlignment(Align);
     1069    return LI;
     1070}
     1071
     1072StoreInst * CBuilder::CreateAlignedStore(Value * Val, Value * Ptr, unsigned Align, bool isVolatile) {
     1073    if (codegen::EnableAsserts) {
     1074        DataLayout DL(getModule());
     1075        IntegerType * const intPtrTy = cast<IntegerType>(DL.getIntPtrType(Ptr->getType()));
     1076        Value * alignmentOffset = CreateURem(CreatePtrToInt(Ptr, intPtrTy), ConstantInt::get(intPtrTy, Align));
     1077        CreateAssertZero(alignmentOffset, "CreateAlignedStore: pointer is misaligned");
     1078    }
     1079    StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
     1080    SI->setAlignment(Align);
     1081    return SI;
     1082}
    9001083
    9011084CBuilder::CBuilder(LLVMContext & C)
Note: See TracChangeset for help on using the changeset viewer.