Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
71f92bb
[tidy] update documentation from `make check` to `x.py test`
chrissimpkins Mar 1, 2020
8858d71
Put back output-format option for show-coverage
GuillaumeGomez Nov 16, 2019
10492c3
Add support for json output in show-coverage option
GuillaumeGomez Nov 16, 2019
15babed
add tests for rustdoc output-format json
GuillaumeGomez Nov 16, 2019
f1070b1
Replace ToJson with serde
GuillaumeGomez Feb 17, 2020
1c01646
Extend json detection in runtest
GuillaumeGomez Feb 27, 2020
b646627
remove output-format test
GuillaumeGomez Mar 2, 2020
528cbc4
fix memory leak when vec::IntoIter panics during drop
RalfJung Mar 8, 2020
1a9fc18
panic_bounds_check: use caller_location, like PanicFnLangItem
RalfJung Mar 9, 2020
51b60b7
Improve readability
RalfJung Mar 9, 2020
f34e066
remove no-longer needed span from Miri Machine hook
RalfJung Mar 9, 2020
0982c58
update tidy documentation to recommend ./x.py test tidy
chrissimpkins Mar 10, 2020
259b06e
add documentation of x.py tool testing
chrissimpkins Mar 10, 2020
9f734c9
Add documentation of tool testing with x.py script
chrissimpkins Mar 10, 2020
4922b68
remove trailing whitespace (tidy)
chrissimpkins Mar 10, 2020
c60d581
update x.py tidy testing command
chrissimpkins Mar 10, 2020
6f2c01b
Add long error explanation for E0739
Mar 10, 2020
761c8c1
Removed trailing whitespace
Mar 10, 2020
9596dc2
parse_labeled_expr: simplify
Centril Mar 5, 2020
c303c44
use error_block_no_opening_brace more
Centril Mar 5, 2020
883e90d
simplify parse_inner_attributes
Centril Mar 5, 2020
8ee220c
more reuse in block parsing & improve diagnostics.
Centril Mar 5, 2020
055733f
parse: recover on `&'lt $expr` / `'lt $expr`.
Centril Mar 5, 2020
379f318
parse: simplify parse_fn_body
Centril Mar 5, 2020
be86b2d
parse: recover on `fn foo() = expr;`
Centril Mar 5, 2020
addbc5b
unify/improve/simplify attribute parsing
Centril Mar 5, 2020
fe848b4
parse_block_tail: reduce visibility
Centril Mar 5, 2020
e72df7e
parse_labeled_expr: add a suggestion on missing colon.
Centril Mar 6, 2020
83be689
parser/attr: adjust indentation.
Centril Mar 7, 2020
65b7ba5
parser: add note for `'label expr`.
Centril Mar 7, 2020
c01b3e6
block-no-opening-brace: add another statement
Centril Mar 7, 2020
09997e7
error_block_no_opening_brace: handle closures better
Centril Mar 7, 2020
25cd01b
issue 68890: add more minimal repro
Centril Mar 7, 2020
c0b073b
simplify & improve parse_ty_tuple_or_parens
Centril Mar 7, 2020
d1822b3
use check_path more
Centril Mar 7, 2020
ba3ae46
trait-object-lifetime-parens: improve recovery.
Centril Mar 7, 2020
458383d
parse_if_expr: recover on attributes
Centril Mar 7, 2020
0b2329d
also make panic_fmt track_caller
RalfJung Mar 10, 2020
5357f83
[Miri] Use a session variable instead of checking for an env var always
wesleywiser Feb 17, 2020
1106579
librustc_codegen_llvm: Use slices instead of 0-terminated strings
tmiasko Mar 10, 2020
741d4ff
Rollup merge of #66472 - GuillaumeGomez:show-coverage-json, r=ollie27
Centril Mar 11, 2020
dde2484
Rollup merge of #69603 - chrissimpkins:tidy-docs-update, r=petrochenkov
Centril Mar 11, 2020
9674c09
Rollup merge of #69760 - Centril:parse-expr-improve, r=estebank
Centril Mar 11, 2020
080d413
Rollup merge of #69828 - RalfJung:vec-leak, r=kennytm
Centril Mar 11, 2020
3853da7
Rollup merge of #69850 - RalfJung:panic-bounds-check, r=eddyb
Centril Mar 11, 2020
e838383
Rollup merge of #69876 - ayushmishra2005:doc/61137-add-long-error-cod…
Centril Mar 11, 2020
b1471e0
Rollup merge of #69888 - wesleywiser:miri_exception_env_var_to_sessio…
Centril Mar 11, 2020
a77206f
Rollup merge of #69893 - tmiasko:cstr, r=petrochenkov
Centril Mar 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/librustc_codegen_llvm/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ffi::CString;

use crate::attributes;
use libc::c_uint;
use rustc::bug;
Expand Down Expand Up @@ -50,8 +48,8 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
args.len() as c_uint,
False,
);
let name = CString::new(format!("__rust_{}", method.name)).unwrap();
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr(), ty);
let name = format!("__rust_{}", method.name);
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);

if tcx.sess.target.target.options.default_hidden_visibility {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
Expand All @@ -60,8 +58,9 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
attributes::emit_uwtable(llfn, true);
}

let callee = CString::new(kind.fn_name(method.name)).unwrap();
let callee = llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr(), ty);
let callee = kind.fn_name(method.name);
let callee =
llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr().cast(), callee.len(), ty);
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);

let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, "entry\0".as_ptr().cast());
Expand All @@ -73,14 +72,8 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
.enumerate()
.map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint))
.collect::<Vec<_>>();
let ret = llvm::LLVMRustBuildCall(
llbuilder,
callee,
args.as_ptr(),
args.len() as c_uint,
None,
"\0".as_ptr().cast(),
);
let ret =
llvm::LLVMRustBuildCall(llbuilder, callee, args.as_ptr(), args.len() as c_uint, None);
llvm::LLVMSetTailCall(ret, True);
if output.is_some() {
llvm::LLVMBuildRet(llbuilder, ret);
Expand Down
22 changes: 11 additions & 11 deletions src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use rustc_span::Span;

use libc::{c_char, c_uint};
use log::debug;
use std::ffi::{CStr, CString};

impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn codegen_inline_asm(
Expand Down Expand Up @@ -80,12 +79,11 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
_ => self.type_struct(&output_types, false),
};

let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
let constraint_cstr = CString::new(all_constraints).unwrap();
let asm = ia.asm.as_str();
let r = inline_asm_call(
self,
&asm,
&constraint_cstr,
&all_constraints,
&inputs,
output_type,
ia.volatile,
Expand Down Expand Up @@ -125,17 +123,17 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {

impl AsmMethods for CodegenCx<'ll, 'tcx> {
fn codegen_global_asm(&self, ga: &hir::GlobalAsm) {
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
let asm = ga.asm.as_str();
unsafe {
llvm::LLVMRustAppendModuleInlineAsm(self.llmod, asm.as_ptr());
llvm::LLVMRustAppendModuleInlineAsm(self.llmod, asm.as_ptr().cast(), asm.len());
}
}
}

fn inline_asm_call(
bx: &mut Builder<'a, 'll, 'tcx>,
asm: &CStr,
cons: &CStr,
asm: &str,
cons: &str,
inputs: &[&'ll Value],
output: &'ll llvm::Type,
volatile: bool,
Expand All @@ -157,13 +155,15 @@ fn inline_asm_call(
let fty = bx.cx.type_func(&argtys[..], output);
unsafe {
// Ask LLVM to verify that the constraints are well-formed.
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr().cast(), cons.len());
debug!("constraint verification result: {:?}", constraints_ok);
if constraints_ok {
let v = llvm::LLVMRustInlineAsm(
fty,
asm.as_ptr(),
cons.as_ptr(),
asm.as_ptr().cast(),
asm.len(),
cons.as_ptr().cast(),
cons.len(),
volatile,
alignstack,
llvm::AsmDialect::from_generic(dia),
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
args.as_ptr() as *const &llvm::Value,
args.len() as c_uint,
bundle,
UNNAMED,
)
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_codegen_llvm/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::value::Value;
use log::debug;
use rustc::ty::Ty;
use rustc_codegen_ssa::traits::*;
use rustc_data_structures::small_c_str::SmallCStr;

/// Declare a function.
///
Expand All @@ -34,8 +33,9 @@ fn declare_raw_fn(
ty: &'ll Type,
) -> &'ll Value {
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
let namebuf = SmallCStr::new(name);
let llfn = unsafe { llvm::LLVMRustGetOrInsertFunction(cx.llmod, namebuf.as_ptr(), ty) };
let llfn = unsafe {
llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_ptr().cast(), name.len(), ty)
};

llvm::SetFunctionCallConv(llfn, callconv);
// Function addresses in Rust are never significant, allowing functions to
Expand Down Expand Up @@ -83,8 +83,7 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {

fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
debug!("get_declared_value(name={:?})", name);
let namebuf = SmallCStr::new(name);
unsafe { llvm::LLVMRustGetNamedValue(self.llmod, namebuf.as_ptr()) }
unsafe { llvm::LLVMRustGetNamedValue(self.llmod, name.as_ptr().cast(), name.len()) }
}

fn get_defined_value(&self, name: &str) -> Option<&'ll Value> {
Expand Down
18 changes: 14 additions & 4 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ extern "C" {

/// See Module::setModuleInlineAsm.
pub fn LLVMSetModuleInlineAsm(M: &Module, Asm: *const c_char);
pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char);
pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char, AsmLen: size_t);

/// See llvm::LLVMTypeKind::getTypeID.
pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
Expand Down Expand Up @@ -879,13 +879,18 @@ extern "C" {
pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
pub fn LLVMRustGetNamedValue(M: &Module, Name: *const c_char) -> Option<&Value>;
pub fn LLVMRustGetNamedValue(
M: &Module,
Name: *const c_char,
NameLen: size_t,
) -> Option<&Value>;
pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);

// Operations on functions
pub fn LLVMRustGetOrInsertFunction(
M: &'a Module,
Name: *const c_char,
NameLen: size_t,
FunctionTy: &'a Type,
) -> &'a Value;
pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
Expand Down Expand Up @@ -1332,7 +1337,6 @@ extern "C" {
Args: *const &'a Value,
NumArgs: c_uint,
Bundle: Option<&OperandBundleDef<'a>>,
Name: *const c_char,
) -> &'a Value;
pub fn LLVMRustBuildMemCpy(
B: &Builder<'a>,
Expand Down Expand Up @@ -1581,12 +1585,18 @@ extern "C" {
pub fn LLVMRustInlineAsm(
Ty: &Type,
AsmString: *const c_char,
AsmStringLen: size_t,
Constraints: *const c_char,
ConstraintsLen: size_t,
SideEffects: Bool,
AlignStack: Bool,
Dialect: AsmDialect,
) -> &Value;
pub fn LLVMRustInlineAsmVerify(Ty: &Type, Constraints: *const c_char) -> bool;
pub fn LLVMRustInlineAsmVerify(
Ty: &Type,
Constraints: *const c_char,
ConstraintsLen: size_t,
) -> bool;

pub fn LLVMRustDebugMetadataVersion() -> u32;
pub fn LLVMRustVersionMajor() -> u32;
Expand Down
47 changes: 26 additions & 21 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,22 @@ extern "C" void LLVMRustPrintPassTimings() {
TimerGroup::printAll(OS);
}

extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M,
const char *Name) {
return wrap(unwrap(M)->getNamedValue(Name));
extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M, const char *Name,
size_t NameLen) {
return wrap(unwrap(M)->getNamedValue(StringRef(Name, NameLen)));
}

extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
const char *Name,
size_t NameLen,
LLVMTypeRef FunctionTy) {
return wrap(
unwrap(M)->getOrInsertFunction(Name, unwrap<FunctionType>(FunctionTy))
return wrap(unwrap(M)
->getOrInsertFunction(StringRef(Name, NameLen),
unwrap<FunctionType>(FunctionTy))
#if LLVM_VERSION_GE(9, 0)
.getCallee()
.getCallee()
#endif
);
);
}

extern "C" LLVMValueRef
Expand Down Expand Up @@ -395,22 +397,26 @@ static InlineAsm::AsmDialect fromRust(LLVMRustAsmDialect Dialect) {
}
}

extern "C" LLVMValueRef LLVMRustInlineAsm(LLVMTypeRef Ty, char *AsmString,
char *Constraints,
LLVMBool HasSideEffects,
LLVMBool IsAlignStack,
LLVMRustAsmDialect Dialect) {
return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), AsmString, Constraints,
extern "C" LLVMValueRef
LLVMRustInlineAsm(LLVMTypeRef Ty, char *AsmString, size_t AsmStringLen,
char *Constraints, size_t ConstraintsLen,
LLVMBool HasSideEffects, LLVMBool IsAlignStack,
LLVMRustAsmDialect Dialect) {
return wrap(InlineAsm::get(unwrap<FunctionType>(Ty),
StringRef(AsmString, AsmStringLen),
StringRef(Constraints, ConstraintsLen),
HasSideEffects, IsAlignStack, fromRust(Dialect)));
}

extern "C" bool LLVMRustInlineAsmVerify(LLVMTypeRef Ty,
char *Constraints) {
return InlineAsm::Verify(unwrap<FunctionType>(Ty), Constraints);
extern "C" bool LLVMRustInlineAsmVerify(LLVMTypeRef Ty, char *Constraints,
size_t ConstraintsLen) {
return InlineAsm::Verify(unwrap<FunctionType>(Ty),
StringRef(Constraints, ConstraintsLen));
}

extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
unwrap(M)->appendModuleInlineAsm(StringRef(Asm));
extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm,
size_t AsmLen) {
unwrap(M)->appendModuleInlineAsm(StringRef(Asm, AsmLen));
}

typedef DIBuilder *LLVMRustDIBuilderRef;
Expand Down Expand Up @@ -1282,12 +1288,11 @@ extern "C" void LLVMRustFreeOperandBundleDef(OperandBundleDef *Bundle) {

extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
LLVMValueRef *Args, unsigned NumArgs,
OperandBundleDef *Bundle,
const char *Name) {
OperandBundleDef *Bundle) {
unsigned Len = Bundle ? 1 : 0;
ArrayRef<OperandBundleDef> Bundles = makeArrayRef(Bundle, Len);
return wrap(unwrap(B)->CreateCall(
unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Bundles, Name));
unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Bundles));
}

extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B,
Expand Down