diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -2695,8 +2695,8 @@ size = varOffset; // Conversely, we might have to prevent LLVM from inserting padding. - } else if (CGM.getDataLayout().getABITypeAlignment(varTy) - > varAlign.getQuantity()) { + } else if (CGM.getDataLayout().getABITypeAlignment(varTy) > + uint64_t(varAlign.getQuantity())) { packed = true; } types.push_back(varTy); diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5021,12 +5021,12 @@ auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType); // Materialize to a temporary. - addr = CreateTempAlloca( - RV.getScalarVal()->getType(), - CharUnits::fromQuantity(std::max( - (unsigned)layout->getAlignment().value(), scalarAlign)), - "tmp", - /*ArraySize=*/nullptr, &AllocaAddr); + addr = + CreateTempAlloca(RV.getScalarVal()->getType(), + CharUnits::fromQuantity(std::max( + layout->getAlignment().value(), scalarAlign)), + "tmp", + /*ArraySize=*/nullptr, &AllocaAddr); tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer()); Builder.CreateStore(RV.getScalarVal(), addr); diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1142,7 +1142,7 @@ GV->setAlignment(Align.getAsAlign()); GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); CacheEntry = GV; - } else if (CacheEntry->getAlignment() < Align.getQuantity()) { + } else if (CacheEntry->getAlignment() < uint64_t(Align.getQuantity())) { CacheEntry->setAlignment(Align.getAsAlign()); } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5386,7 +5386,7 @@ if (!LangOpts.WritableStrings) { Entry = &ConstantStringMap[C]; if (auto GV = *Entry) { - if (Alignment.getQuantity() > GV->getAlignment()) + if (uint64_t(Alignment.getQuantity()) > GV->getAlignment()) GV->setAlignment(Alignment.getAsAlign()); return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV), Alignment); @@ -5449,7 +5449,7 @@ if (!LangOpts.WritableStrings) { Entry = &ConstantStringMap[C]; if (auto GV = *Entry) { - if (Alignment.getQuantity() > GV->getAlignment()) + if (uint64_t(Alignment.getQuantity()) > GV->getAlignment()) GV->setAlignment(Alignment.getAsAlign()); return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV), Alignment); diff --git a/clang/test/CodeGen/builtin-assume-aligned.c b/clang/test/CodeGen/builtin-assume-aligned.c --- a/clang/test/CodeGen/builtin-assume-aligned.c +++ b/clang/test/CodeGen/builtin-assume-aligned.c @@ -117,7 +117,7 @@ // CHECK-NEXT: store i32* [[A]], i32** [[A_ADDR]], align 8 // CHECK-NEXT: [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8 // CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[TMP0]] to i8* -// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[TMP1]], i64 1073741824) ] +// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[TMP1]], i64 4294967296) ] // CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i32* // CHECK-NEXT: store i32* [[TMP2]], i32** [[A_ADDR]], align 8 // CHECK-NEXT: [[TMP3:%.*]] = load i32*, i32** [[A_ADDR]], align 8 diff --git a/clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp b/clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp --- a/clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp +++ b/clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp @@ -7,7 +7,7 @@ // CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}}* @[[CHAR]] } char **passthrough(__attribute__((align_value(0x80000000))) char **x) { - // CHECK-NOSANITIZE: define{{.*}} i8** @{{.*}}(i8** align 1073741824 %[[X:.*]]) + // CHECK-NOSANITIZE: define{{.*}} i8** @{{.*}}(i8** align 2147483648 %[[X:.*]]) // CHECK-SANITIZE: define{{.*}} i8** @{{.*}}(i8** %[[X:.*]]) // CHECK-NEXT: [[entry:.*]]: // CHECK-NEXT: %[[X_ADDR:.*]] = alloca i8**, align 8 diff --git a/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp b/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp --- a/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp +++ b/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp @@ -18,17 +18,17 @@ // CHECK-NEXT: %[[OFFSET_RELOADED:.*]] = load i64, i64* %[[OFFSET_ADDR]], align 8 // CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64 // CHECK-SANITIZE-NEXT: %[[OFFSETPTR:.*]] = sub i64 %[[PTRINT]], %[[OFFSET_RELOADED]] - // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 1073741823 + // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 2147483647 // CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0 // CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize // CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize // CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]: - // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize - // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize + // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize + // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize // CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize // CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize // CHECK-SANITIZE: [[CONT]]: - // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824, i64 %[[OFFSET_RELOADED]]) ] + // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 2147483648, i64 %[[OFFSET_RELOADED]]) ] // CHECK-NEXT: ret i8* %[[BITCAST]] // CHECK-NEXT: } #line 100 diff --git a/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp b/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp --- a/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp +++ b/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp @@ -15,17 +15,17 @@ // CHECK-NEXT: %[[BITCAST:.*]] = bitcast i8** %[[X_RELOADED]] to i8* // CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64 // CHECK-SANITIZE-NEXT: %[[OFFSETPTR:.*]] = sub i64 %[[PTRINT]], 42 - // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 1073741823 + // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 2147483647 // CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0 // CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize // CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize // CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]: - // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 42){{.*}}, !nosanitize - // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 42){{.*}}, !nosanitize + // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 42){{.*}}, !nosanitize + // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 42){{.*}}, !nosanitize // CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize // CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize // CHECK-SANITIZE: [[CONT]]: - // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824, i64 42) ] + // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 2147483648, i64 42) ] // CHECK-NEXT: ret i8* %[[BITCAST]] // CHECK-NEXT: } #line 100 diff --git a/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp b/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp --- a/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp +++ b/clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp @@ -14,17 +14,17 @@ // CHECK-NEXT: %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8 // CHECK-NEXT: %[[BITCAST:.*]] = bitcast i8** %[[X_RELOADED]] to i8* // CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64 - // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 1073741823 + // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 2147483647 // CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0 // CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize // CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize // CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]: - // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize - // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize + // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 0){{.*}}, !nosanitize + // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 0){{.*}}, !nosanitize // CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize // CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize // CHECK-SANITIZE: [[CONT]]: - // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824) ] + // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 2147483648) ] // CHECK-NEXT: ret i8* %[[BITCAST]] // CHECK-NEXT: } #line 100 diff --git a/llvm/include/llvm/Bitcode/BitcodeCommon.h b/llvm/include/llvm/Bitcode/BitcodeCommon.h --- a/llvm/include/llvm/Bitcode/BitcodeCommon.h +++ b/llvm/include/llvm/Bitcode/BitcodeCommon.h @@ -19,10 +19,14 @@ namespace llvm { struct AllocaPackedValues { - using Align = Bitfield::Element; - using UsedWithInAlloca = Bitfield::Element; + // We increased the number of bits needed to represent alignment to be more + // than 5, but to preserve backward compatibility we store the upper bits + // separately. + using AlignLower = Bitfield::Element; + using UsedWithInAlloca = Bitfield::Element; using ExplicitType = Bitfield::Element; using SwiftError = Bitfield::Element; + using AlignUpper = Bitfield::Element; }; } // namespace llvm diff --git a/llvm/include/llvm/IR/Argument.h b/llvm/include/llvm/IR/Argument.h --- a/llvm/include/llvm/IR/Argument.h +++ b/llvm/include/llvm/IR/Argument.h @@ -97,7 +97,7 @@ /// If this is a byval or inalloca argument, return its alignment. /// FIXME: Remove this function once transition to Align is over. /// Use getParamAlign() instead. - unsigned getParamAlignment() const; + uint64_t getParamAlignment() const; /// If this is a byval or inalloca argument, return its alignment. MaybeAlign getParamAlign() const; diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h --- a/llvm/include/llvm/IR/DataLayout.h +++ b/llvm/include/llvm/IR/DataLayout.h @@ -518,7 +518,7 @@ /// Returns the minimum ABI-required alignment for the specified type. /// FIXME: Deprecate this function once migration to Align is over. - unsigned getABITypeAlignment(Type *Ty) const; + uint64_t getABITypeAlignment(Type *Ty) const; /// Returns the minimum ABI-required alignment for the specified type. Align getABITypeAlign(Type *Ty) const; @@ -541,7 +541,7 @@ /// /// This is always at least as good as the ABI alignment. /// FIXME: Deprecate this function once migration to Align is over. - unsigned getPrefTypeAlignment(Type *Ty) const; + uint64_t getPrefTypeAlignment(Type *Ty) const; /// Returns the preferred stack/global alignment for the specified /// type. diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -444,7 +444,7 @@ /// Extract the alignment for a call or parameter (0=unknown). /// FIXME: Remove this function once transition to Align is over. /// Use getParamAlign() instead. - unsigned getParamAlignment(unsigned ArgNo) const { + uint64_t getParamAlignment(unsigned ArgNo) const { if (const auto MA = getParamAlign(ArgNo)) return MA->value(); return 0; diff --git a/llvm/include/llvm/IR/GlobalObject.h b/llvm/include/llvm/IR/GlobalObject.h --- a/llvm/include/llvm/IR/GlobalObject.h +++ b/llvm/include/llvm/IR/GlobalObject.h @@ -51,7 +51,7 @@ Comdat *ObjComdat; enum { - LastAlignmentBit = 4, + LastAlignmentBit = 5, HasSectionHashEntryBit, GlobalObjectBits, @@ -68,7 +68,7 @@ GlobalObject(const GlobalObject &) = delete; /// FIXME: Remove this function once transition to Align is over. - unsigned getAlignment() const { + uint64_t getAlignment() const { MaybeAlign Align = getAlign(); return Align ? Align->value() : 0; } diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -59,11 +59,11 @@ // Template alias so that all Instruction storing alignment use the same // definiton. // Valid alignments are powers of two from 2^0 to 2^MaxAlignmentExponent = - // 2^30. We store them as Log2(Alignment), so we need 5 bits to encode the 31 + // 2^32. We store them as Log2(Alignment), so we need 6 bits to encode the 33 // possible values. template using AlignmentBitfieldElementT = - typename Bitfield::Element; template diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -126,7 +126,7 @@ } // FIXME: Remove this one transition to Align is over. - unsigned getAlignment() const { return getAlign().value(); } + uint64_t getAlignment() const { return getAlign().value(); } /// Return true if this alloca is in the entry block of the function and is a /// constant size. If so, the code generator will fold it into the @@ -217,7 +217,7 @@ /// Return the alignment of the access that is being performed. /// FIXME: Remove this function once transition to Align is over. /// Use getAlign() instead. - unsigned getAlignment() const { return getAlign().value(); } + uint64_t getAlignment() const { return getAlign().value(); } /// Return the alignment of the access that is being performed. Align getAlign() const { @@ -348,7 +348,7 @@ /// Return the alignment of the access that is being performed /// FIXME: Remove this function once transition to Align is over. /// Use getAlign() instead. - unsigned getAlignment() const { return getAlign().value(); } + uint64_t getAlignment() const { return getAlign().value(); } Align getAlign() const { return Align(1ULL << (getSubclassData())); diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h --- a/llvm/include/llvm/IR/Value.h +++ b/llvm/include/llvm/IR/Value.h @@ -785,8 +785,8 @@ /// /// This is the greatest alignment value supported by load, store, and alloca /// instructions, and global values. - static constexpr unsigned MaxAlignmentExponent = 30; - static constexpr unsigned MaximumAlignment = 1u << MaxAlignmentExponent; + static constexpr unsigned MaxAlignmentExponent = 32; + static constexpr uint64_t MaximumAlignment = 1ULL << MaxAlignmentExponent; /// Mutate the type of this Value to be of the specified type. /// diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -3413,7 +3413,7 @@ }; using AAAlignmentStateType = - IncIntegerState; + IncIntegerState; /// An abstract interface for all align attributes. struct AAAlign : public IRAttribute< Attribute::Alignment, @@ -3421,10 +3421,10 @@ AAAlign(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} /// Return assumed alignment. - unsigned getAssumedAlign() const { return getAssumed(); } + uint64_t getAssumedAlign() const { return getAssumed(); } /// Return known alignment. - unsigned getKnownAlign() const { return getKnown(); } + uint64_t getKnownAlign() const { return getKnown(); } /// See AbstractAttribute::getName() const std::string getName() const override { return "AAAlign"; } diff --git a/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h b/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h --- a/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h +++ b/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h @@ -33,7 +33,7 @@ uint64_t Size; // Size of the variable in bytes. size_t LifetimeSize; // Size in bytes to use for lifetime analysis check. // Will be rounded up to Granularity. - size_t Alignment; // Alignment of the variable (power of 2). + uint64_t Alignment; // Alignment of the variable (power of 2). AllocaInst *AI; // The actual AllocaInst. size_t Offset; // Offset from the beginning of the frame; // set by ComputeASanStackFrameLayout. diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1927,7 +1927,7 @@ if (!EatIfPresent(lltok::kw_align)) return false; LocTy AlignLoc = Lex.getLoc(); - uint32_t Value = 0; + uint64_t Value = 0; LocTy ParenLoc = Lex.getLoc(); bool HaveParens = false; @@ -1936,13 +1936,13 @@ HaveParens = true; } - if (parseUInt32(Value)) + if (parseUInt64(Value)) return true; if (HaveParens && !EatIfPresent(lltok::rparen)) return error(ParenLoc, "expected ')'"); - if (!isPowerOf2_32(Value)) + if (!isPowerOf2_64(Value)) return error(AlignLoc, "alignment is not a power of two"); if (Value > Value::MaximumAlignment) return error(AlignLoc, "huge alignments are not supported yet"); diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4930,8 +4930,10 @@ Type *OpTy = getTypeByID(Record[1]); Value *Size = getFnValueByID(Record[2], OpTy); MaybeAlign Align; - if (Error Err = - parseAlignmentValue(Bitfield::get(Rec), Align)) { + uint64_t AlignExp = + Bitfield::get(Rec) | + (Bitfield::get(Rec) << APV::AlignLower::Bits); + if (Error Err = parseAlignmentValue(AlignExp, Align)) { return Err; } if (!Ty || !Size) diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3055,7 +3055,11 @@ Vals.push_back(VE.getValueID(I.getOperand(0))); // size. using APV = AllocaPackedValues; unsigned Record = 0; - Bitfield::set(Record, getEncodedAlign(AI.getAlign())); + unsigned EncodedAlign = getEncodedAlign(AI.getAlign()); + Bitfield::set( + Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1)); + Bitfield::set(Record, + EncodedAlign >> APV::AlignLower::Bits); Bitfield::set(Record, AI.isUsedWithInAlloca()); Bitfield::set(Record, true); Bitfield::set(Record, AI.isSwiftError()); diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -498,7 +498,7 @@ MachineOperand &Dest, Optional &TiedDefIdx); bool parseOffset(int64_t &Offset); - bool parseAlignment(unsigned &Alignment); + bool parseAlignment(uint64_t &Alignment); bool parseAddrspace(unsigned &Addrspace); bool parseSectionID(Optional &SID); bool parseOperandsOffset(MachineOperand &Op); @@ -676,7 +676,7 @@ bool IsLandingPad = false; bool IsEHFuncletEntry = false; Optional SectionID; - unsigned Alignment = 0; + uint64_t Alignment = 0; BasicBlock *BB = nullptr; if (consumeIfPresent(MIToken::lparen)) { do { @@ -2898,16 +2898,16 @@ return false; } -bool MIParser::parseAlignment(unsigned &Alignment) { +bool MIParser::parseAlignment(uint64_t &Alignment) { assert(Token.is(MIToken::kw_align) || Token.is(MIToken::kw_basealign)); lex(); if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned()) return error("expected an integer literal after 'align'"); - if (getUnsigned(Alignment)) + if (getUint64(Alignment)) return true; lex(); - if (!isPowerOf2_32(Alignment)) + if (!isPowerOf2_64(Alignment)) return error("expected a power-of-2 literal after 'align'"); return false; @@ -3261,7 +3261,7 @@ if (parseMachinePointerInfo(Ptr)) return true; } - unsigned BaseAlignment = + uint64_t BaseAlignment = (Size != MemoryLocation::UnknownSize ? PowerOf2Ceil(Size) : 1); AAMDNodes AAInfo; MDNode *Range = nullptr; diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -147,7 +147,7 @@ /// /// 16 seems like a reasonable upper bound on the alignment of objects that we /// might expect to appear on the stack on most common targets. - enum { StackAlignment = 16 }; + static constexpr uint64_t StackAlignment = 16; /// Return the value of the stack canary. Value *getStackGuard(IRBuilder<> &IRB, Function &F); @@ -221,6 +221,8 @@ bool run(); }; +constexpr uint64_t SafeStack::StackAlignment; + uint64_t SafeStack::getStaticAllocaAllocationSize(const AllocaInst* AI) { uint64_t Size = DL.getTypeAllocSize(AI->getAllocatedType()); if (AI->isArrayAllocation()) { @@ -519,7 +521,7 @@ StackLayout SSL(StackAlignment); if (StackGuardSlot) { Type *Ty = StackGuardSlot->getAllocatedType(); - unsigned Align = + uint64_t Align = std::max(DL.getPrefTypeAlignment(Ty), StackGuardSlot->getAlignment()); SSL.addObject(StackGuardSlot, getStaticAllocaAllocationSize(StackGuardSlot), Align, SSC.getFullLiveRange()); @@ -532,8 +534,8 @@ Size = 1; // Don't create zero-sized stack objects. // Ensure the object is properly aligned. - unsigned Align = std::max((unsigned)DL.getPrefTypeAlignment(Ty), - Arg->getParamAlignment()); + uint64_t Align = + std::max(DL.getPrefTypeAlignment(Ty), Arg->getParamAlignment()); SSL.addObject(Arg, Size, Align, SSC.getFullLiveRange()); } @@ -544,21 +546,20 @@ Size = 1; // Don't create zero-sized stack objects. // Ensure the object is properly aligned. - unsigned Align = - std::max((unsigned)DL.getPrefTypeAlignment(Ty), AI->getAlignment()); + uint64_t Align = std::max(DL.getPrefTypeAlignment(Ty), AI->getAlignment()); SSL.addObject(AI, Size, Align, ClColoring ? SSC.getLiveRange(AI) : NoColoringRange); } SSL.computeLayout(); - unsigned FrameAlignment = SSL.getFrameAlignment(); + uint64_t FrameAlignment = SSL.getFrameAlignment(); // FIXME: tell SSL that we start at a less-then-MaxAlignment aligned location // (AlignmentSkew). if (FrameAlignment > StackAlignment) { // Re-align the base pointer according to the max requested alignment. - assert(isPowerOf2_32(FrameAlignment)); + assert(isPowerOf2_64(FrameAlignment)); IRB.SetInsertPoint(BasePointer->getNextNode()); BasePointer = cast(IRB.CreateIntToPtr( IRB.CreateAnd(IRB.CreatePtrToInt(BasePointer, IntPtrTy), @@ -676,9 +677,9 @@ SP = IRB.CreateSub(SP, Size); // Align the SP value to satisfy the AllocaInst, type and stack alignments. - unsigned Align = std::max( - std::max((unsigned)DL.getPrefTypeAlignment(Ty), AI->getAlignment()), - (unsigned)StackAlignment); + uint64_t Align = + std::max(std::max(DL.getPrefTypeAlignment(Ty), AI->getAlignment()), + StackAlignment); assert(isPowerOf2_32(Align)); Value *NewTop = IRB.CreateIntToPtr( diff --git a/llvm/lib/CodeGen/SafeStackLayout.h b/llvm/lib/CodeGen/SafeStackLayout.h --- a/llvm/lib/CodeGen/SafeStackLayout.h +++ b/llvm/lib/CodeGen/SafeStackLayout.h @@ -22,7 +22,7 @@ /// Compute the layout of an unsafe stack frame. class StackLayout { - unsigned MaxAlignment; + uint64_t MaxAlignment; struct StackRegion { unsigned Start; @@ -39,23 +39,24 @@ struct StackObject { const Value *Handle; - unsigned Size, Alignment; + unsigned Size; + uint64_t Alignment; StackLifetime::LiveRange Range; }; SmallVector StackObjects; DenseMap ObjectOffsets; - DenseMap ObjectAlignments; + DenseMap ObjectAlignments; void layoutObject(StackObject &Obj); public: - StackLayout(unsigned StackAlignment) : MaxAlignment(StackAlignment) {} + StackLayout(uint64_t StackAlignment) : MaxAlignment(StackAlignment) {} /// Add an object to the stack frame. Value pointer is opaque and used as a /// handle to retrieve the object's offset in the frame later. - void addObject(const Value *V, unsigned Size, unsigned Alignment, + void addObject(const Value *V, unsigned Size, uint64_t Alignment, const StackLifetime::LiveRange &Range); /// Run the layout computation for all previously added objects. @@ -65,13 +66,13 @@ unsigned getObjectOffset(const Value *V) { return ObjectOffsets[V]; } /// Returns the alignment of the object - unsigned getObjectAlignment(const Value *V) { return ObjectAlignments[V]; } + uint64_t getObjectAlignment(const Value *V) { return ObjectAlignments[V]; } /// Returns the size of the entire frame. unsigned getFrameSize() { return Regions.empty() ? 0 : Regions.back().End; } /// Returns the alignment of the frame. - unsigned getFrameAlignment() { return MaxAlignment; } + uint64_t getFrameAlignment() { return MaxAlignment; } void print(raw_ostream &OS); }; diff --git a/llvm/lib/CodeGen/SafeStackLayout.cpp b/llvm/lib/CodeGen/SafeStackLayout.cpp --- a/llvm/lib/CodeGen/SafeStackLayout.cpp +++ b/llvm/lib/CodeGen/SafeStackLayout.cpp @@ -37,7 +37,7 @@ } } -void StackLayout::addObject(const Value *V, unsigned Size, unsigned Alignment, +void StackLayout::addObject(const Value *V, unsigned Size, uint64_t Alignment, const StackLifetime::LiveRange &Range) { StackObjects.push_back({V, Size, Alignment, Range}); ObjectAlignments[V] = Alignment; @@ -45,7 +45,7 @@ } static unsigned AdjustStackOffset(unsigned Offset, unsigned Size, - unsigned Alignment) { + uint64_t Alignment) { return alignTo(Offset + Size, Alignment) - Size; } diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -819,7 +819,7 @@ } /// TODO: Remove this function once the transition to Align is over. -unsigned DataLayout::getABITypeAlignment(Type *Ty) const { +uint64_t DataLayout::getABITypeAlignment(Type *Ty) const { return getABITypeAlign(Ty).value(); } @@ -828,7 +828,7 @@ } /// TODO: Remove this function once the transition to Align is over. -unsigned DataLayout::getPrefTypeAlignment(Type *Ty) const { +uint64_t DataLayout::getPrefTypeAlignment(Type *Ty) const { return getPrefTypeAlign(Ty).value(); } diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -189,7 +189,7 @@ return getMemoryParamAllocType(ParamAttrs); } -unsigned Argument::getParamAlignment() const { +uint64_t Argument::getParamAlignment() const { assert(getType()->isPointerTy() && "Only pointers have alignments"); return getParent()->getParamAlignment(getArgNo()); } diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -176,7 +176,7 @@ // Accesses sizes are powers of two: 1, 2, 4, 8, 16. static const size_t kNumberOfAccessSizes = 5; -static const unsigned kAllocaRzSize = 32; +static const uint64_t kAllocaRzSize = 32; // ASanAccessInfo implementation constants. constexpr size_t kCompileKernelShift = 0; @@ -3578,7 +3578,7 @@ void FunctionStackPoisoner::handleDynamicAllocaCall(AllocaInst *AI) { IRBuilder<> IRB(AI); - const unsigned Alignment = std::max(kAllocaRzSize, AI->getAlignment()); + const uint64_t Alignment = std::max(kAllocaRzSize, AI->getAlignment()); const uint64_t AllocaRedzoneMask = kAllocaRzSize - 1; Value *Zero = Constant::getNullValue(IntptrTy); diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -356,7 +356,7 @@ bool WithFrameRecord; void init(Triple &TargetTriple, bool InstrumentWithCalls); - unsigned getObjectAlignment() const { return 1U << Scale; } + uint64_t getObjectAlignment() const { return 1ULL << Scale; } }; ShadowMapping Mapping; diff --git a/llvm/test/Assembler/align-inst-alloca.ll b/llvm/test/Assembler/align-inst-alloca.ll --- a/llvm/test/Assembler/align-inst-alloca.ll +++ b/llvm/test/Assembler/align-inst-alloca.ll @@ -1,6 +1,6 @@ ; RUN: not llvm-as %s -o /dev/null 2>/dev/null define void @foo() { - %p = alloca i1, align 2147483648 + %p = alloca i1, align 8589934592 ret void } diff --git a/llvm/test/Assembler/align-inst-load.ll b/llvm/test/Assembler/align-inst-load.ll --- a/llvm/test/Assembler/align-inst-load.ll +++ b/llvm/test/Assembler/align-inst-load.ll @@ -1,6 +1,6 @@ ; RUN: not llvm-as %s -o /dev/null 2>/dev/null define void @foo(i1* %p) { - load i1, i1* %p, align 2147483648 + load i1, i1* %p, align 8589934592 ret void } diff --git a/llvm/test/Assembler/align-inst-store.ll b/llvm/test/Assembler/align-inst-store.ll --- a/llvm/test/Assembler/align-inst-store.ll +++ b/llvm/test/Assembler/align-inst-store.ll @@ -1,6 +1,6 @@ ; RUN: not llvm-as %s -o /dev/null 2>/dev/null define void @foo(i1* %p) { - store i1 false, i1* %p, align 2147483648 + store i1 false, i1* %p, align 8589934592 ret void } diff --git a/llvm/test/Assembler/align-inst.ll b/llvm/test/Assembler/align-inst.ll --- a/llvm/test/Assembler/align-inst.ll +++ b/llvm/test/Assembler/align-inst.ll @@ -1,11 +1,11 @@ ; RUN: llvm-as %s -o /dev/null ; RUN: verify-uselistorder %s -@A = global i1 0, align 1073741824 +@A = global i1 0, align 4294967296 define void @foo() { - %p = alloca i1, align 1073741824 - load i1, i1* %p, align 1073741824 - store i1 false, i1* %p, align 1073741824 + %p = alloca i1, align 4294967296 + load i1, i1* %p, align 4294967296 + store i1 false, i1* %p, align 4294967296 ret void } diff --git a/llvm/test/Bitcode/Inputs/invalid-align.bc b/llvm/test/Bitcode/Inputs/invalid-align.bc index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@setAlignment(Align(1073741824)); - EXPECT_EQ(Dummy0->getAlignment(), 1073741824U); + EXPECT_TRUE(Value::MaximumAlignment == 4294967296ULL); + Dummy0->setAlignment(Align(4294967296ULL)); + EXPECT_EQ(Dummy0->getAlignment(), 4294967296ULL); // Make sure the address space isn't dropped when returning this. Constant *Dummy1 = M->getOrInsertGlobal("dummy", Int32Ty); @@ -101,7 +101,7 @@ Constant::getAllOnesValue(Int32Ty), "var", nullptr, GlobalVariable::NotThreadLocal, 1); - EXPECT_DEATH(Var->setAlignment(Align(2147483648U)), + EXPECT_DEATH(Var->setAlignment(Align(8589934592ULL)), "Alignment is greater than MaximumAlignment"); } #endif