Skip to content

Commit b4e97e5

Browse files
committed
Rename llvm::Bool aliases to standard const case
This avoids the need for `#![allow(non_upper_case_globals)]`.
1 parent 455a67b commit b4e97e5

File tree

10 files changed

+33
-34
lines changed

10 files changed

+33
-34
lines changed

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use smallvec::SmallVec;
1212

1313
use crate::builder::SBuilder;
1414
use crate::declare::declare_simple_fn;
15-
use crate::llvm::{self, False, True, Type, Value};
15+
use crate::llvm::{self, FALSE, TRUE, Type, Value};
1616
use crate::{SimpleCx, attributes, debuginfo, llvm_util};
1717

1818
pub(crate) unsafe fn codegen(
@@ -80,7 +80,7 @@ pub(crate) unsafe fn codegen(
8080
&cx,
8181
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
8282
&i8,
83-
&llvm::LLVMConstInt(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as u64, False),
83+
&llvm::LLVMConstInt(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as u64, FALSE),
8484
);
8585

8686
// __rust_no_alloc_shim_is_unstable_v2
@@ -201,7 +201,7 @@ fn create_wrapper_function(
201201
.map(|(i, _)| llvm::get_param(llfn, i as c_uint))
202202
.collect::<Vec<_>>();
203203
let ret = bx.call(ty, callee, &args, None);
204-
llvm::LLVMSetTailCall(ret, True);
204+
llvm::LLVMSetTailCall(ret, TRUE);
205205
if output.is_some() {
206206
bx.ret(ret);
207207
} else {

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ fn embed_bitcode(
11101110

11111111
llvm::set_section(llglobal, bitcode_section_name(cgcx));
11121112
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
1113-
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
1113+
llvm::LLVMSetGlobalConstant(llglobal, llvm::TRUE);
11141114

11151115
let llconst = common::bytes_in_context(llcx, &[]);
11161116
let llglobal = llvm::add_global(llmod, common::val_ty(llconst), c"rustc.embedded.cmdline");

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::attributes;
3535
use crate::common::Funclet;
3636
use crate::context::{CodegenCx, FullCx, GenericCx, SCx};
3737
use crate::llvm::{
38-
self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, GEPNoWrapFlags, Metadata, ToLlvmBool, True,
38+
self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, GEPNoWrapFlags, Metadata, TRUE, ToLlvmBool,
3939
};
4040
use crate::type_::Type;
4141
use crate::type_of::LayoutLlvmExt;
@@ -493,8 +493,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
493493
unsafe {
494494
let add = llvm::LLVMBuildAdd(self.llbuilder, a, b, UNNAMED);
495495
if llvm::LLVMIsAInstruction(add).is_some() {
496-
llvm::LLVMSetNUW(add, True);
497-
llvm::LLVMSetNSW(add, True);
496+
llvm::LLVMSetNUW(add, TRUE);
497+
llvm::LLVMSetNSW(add, TRUE);
498498
}
499499
add
500500
}
@@ -503,8 +503,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
503503
unsafe {
504504
let sub = llvm::LLVMBuildSub(self.llbuilder, a, b, UNNAMED);
505505
if llvm::LLVMIsAInstruction(sub).is_some() {
506-
llvm::LLVMSetNUW(sub, True);
507-
llvm::LLVMSetNSW(sub, True);
506+
llvm::LLVMSetNUW(sub, TRUE);
507+
llvm::LLVMSetNSW(sub, TRUE);
508508
}
509509
sub
510510
}
@@ -513,8 +513,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
513513
unsafe {
514514
let mul = llvm::LLVMBuildMul(self.llbuilder, a, b, UNNAMED);
515515
if llvm::LLVMIsAInstruction(mul).is_some() {
516-
llvm::LLVMSetNUW(mul, True);
517-
llvm::LLVMSetNSW(mul, True);
516+
llvm::LLVMSetNUW(mul, TRUE);
517+
llvm::LLVMSetNSW(mul, TRUE);
518518
}
519519
mul
520520
}
@@ -528,7 +528,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
528528
// an instruction, so we need to check before setting the flag.
529529
// (See also `LLVMBuildNUWNeg` which also needs a check.)
530530
if llvm::LLVMIsAInstruction(or).is_some() {
531-
llvm::LLVMSetIsDisjoint(or, True);
531+
llvm::LLVMSetIsDisjoint(or, TRUE);
532532
}
533533
or
534534
}
@@ -629,7 +629,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
629629
fn volatile_load(&mut self, ty: &'ll Type, ptr: &'ll Value) -> &'ll Value {
630630
unsafe {
631631
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
632-
llvm::LLVMSetVolatile(load, llvm::True);
632+
llvm::LLVMSetVolatile(load, llvm::TRUE);
633633
load
634634
}
635635
}
@@ -838,7 +838,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
838838
if flags.contains(MemFlags::UNALIGNED) { 1 } else { align.bytes() as c_uint };
839839
llvm::LLVMSetAlignment(store, align);
840840
if flags.contains(MemFlags::VOLATILE) {
841-
llvm::LLVMSetVolatile(store, llvm::True);
841+
llvm::LLVMSetVolatile(store, llvm::TRUE);
842842
}
843843
if flags.contains(MemFlags::NONTEMPORAL) {
844844
// Make sure that the current target architectures supports "sane" non-temporal
@@ -956,7 +956,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
956956
let trunc = self.trunc(val, dest_ty);
957957
unsafe {
958958
if llvm::LLVMIsAInstruction(trunc).is_some() {
959-
llvm::LLVMSetNUW(trunc, True);
959+
llvm::LLVMSetNUW(trunc, TRUE);
960960
}
961961
}
962962
trunc
@@ -968,7 +968,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
968968
let trunc = self.trunc(val, dest_ty);
969969
unsafe {
970970
if llvm::LLVMIsAInstruction(trunc).is_some() {
971-
llvm::LLVMSetNSW(trunc, True);
971+
llvm::LLVMSetNSW(trunc, TRUE);
972972
}
973973
}
974974
trunc
@@ -1223,7 +1223,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12231223
let ty = self.type_struct(&[self.type_ptr(), self.type_i32()], false);
12241224
let landing_pad = self.landing_pad(ty, pers_fn, 0);
12251225
unsafe {
1226-
llvm::LLVMSetCleanup(landing_pad, llvm::True);
1226+
llvm::LLVMSetCleanup(landing_pad, llvm::TRUE);
12271227
}
12281228
(self.extract_value(landing_pad, 0), self.extract_value(landing_pad, 1))
12291229
}
@@ -1319,7 +1319,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13191319
src,
13201320
AtomicOrdering::from_generic(order),
13211321
AtomicOrdering::from_generic(failure_order),
1322-
llvm::False, // SingleThreaded
1322+
llvm::FALSE, // SingleThreaded
13231323
);
13241324
llvm::LLVMSetWeak(value, weak.to_llvm_bool());
13251325
let val = self.extract_value(value, 0);
@@ -1346,7 +1346,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13461346
dst,
13471347
src,
13481348
AtomicOrdering::from_generic(order),
1349-
llvm::False, // SingleThreaded
1349+
llvm::FALSE, // SingleThreaded
13501350
)
13511351
};
13521352
if ret_ptr && self.val_ty(res) != self.type_ptr() {

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::builder::{Builder, PlaceRef, UNNAMED};
1111
use crate::context::SimpleCx;
1212
use crate::declare::declare_simple_fn;
1313
use crate::llvm;
14-
use crate::llvm::{Metadata, True, Type};
14+
use crate::llvm::{Metadata, TRUE, Type};
1515
use crate::value::Value;
1616

1717
pub(crate) fn adjust_activity_to_abi<'tcx>(
@@ -293,7 +293,7 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
293293
// ret double %0
294294
// }
295295
// ```
296-
let enzyme_ty = unsafe { llvm::LLVMFunctionType(ret_ty, ptr::null(), 0, True) };
296+
let enzyme_ty = unsafe { llvm::LLVMFunctionType(ret_ty, ptr::null(), 0, TRUE) };
297297

298298
// FIXME(ZuseZ4): the CC/Addr/Vis values are best effort guesses, we should look at tests and
299299
// think a bit more about what should go here.

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tracing::debug;
2020
use crate::consts::const_alloc_to_llvm;
2121
pub(crate) use crate::context::CodegenCx;
2222
use crate::context::{GenericCx, SCx};
23-
use crate::llvm::{self, BasicBlock, ConstantInt, False, Metadata, ToLlvmBool, True};
23+
use crate::llvm::{self, BasicBlock, ConstantInt, FALSE, Metadata, TRUE, ToLlvmBool};
2424
use crate::type_::Type;
2525
use crate::value::Value;
2626

@@ -158,7 +158,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
158158
self.type_kind(t) == TypeKind::Integer,
159159
"only allows integer types in const_int"
160160
);
161-
unsafe { llvm::LLVMConstInt(t, i as u64, True) }
161+
unsafe { llvm::LLVMConstInt(t, i as u64, TRUE) }
162162
}
163163

164164
fn const_u8(&self, i: u8) -> &'ll Value {
@@ -192,7 +192,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
192192
self.type_kind(t) == TypeKind::Integer,
193193
"only allows integer types in const_uint"
194194
);
195-
unsafe { llvm::LLVMConstInt(t, i, False) }
195+
unsafe { llvm::LLVMConstInt(t, i, FALSE) }
196196
}
197197

198198
fn const_uint_big(&self, t: &'ll Type, u: u128) -> &'ll Value {
@@ -377,7 +377,7 @@ pub(crate) fn val_ty(v: &Value) -> &Type {
377377
pub(crate) fn bytes_in_context<'ll>(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
378378
unsafe {
379379
let ptr = bytes.as_ptr() as *const c_char;
380-
llvm::LLVMConstStringInContext2(llcx, ptr, bytes.len(), True)
380+
llvm::LLVMConstStringInContext2(llcx, ptr, bytes.len(), TRUE)
381381
}
382382
}
383383

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
701701
}
702702

703703
pub(crate) fn get_const_int(&self, ty: &'ll Type, val: u64) -> &'ll Value {
704-
unsafe { llvm::LLVMConstInt(ty, val, llvm::False) }
704+
unsafe { llvm::LLVMConstInt(ty, val, llvm::FALSE) }
705705
}
706706

707707
pub(crate) fn get_const_i64(&self, n: u64) -> &'ll Value {

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
7272
.unwrap_or_else(|| bug!("symbol `{}` is already defined", section_var_name));
7373
llvm::set_section(section_var, c".debug_gdb_scripts");
7474
llvm::set_initializer(section_var, cx.const_bytes(section_contents));
75-
llvm::LLVMSetGlobalConstant(section_var, llvm::True);
75+
llvm::LLVMSetGlobalConstant(section_var, llvm::TRUE);
7676
llvm::set_unnamed_address(section_var, llvm::UnnamedAddr::Global);
7777
llvm::set_linkage(section_var, llvm::Linkage::LinkOnceODRLinkage);
7878
// This should make sure that the whole section is not larger than

compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) fn item_namespace<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'l
3838
parent_scope,
3939
namespace_name_string.as_ptr(),
4040
namespace_name_string.len(),
41-
llvm::False, // ExportSymbols (only relevant for C++ anonymous namespaces)
41+
llvm::FALSE, // ExportSymbols (only relevant for C++ anonymous namespaces)
4242
)
4343
};
4444

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! the need for an extra cast from `*const u8` on the Rust side.
1212
1313
#![allow(non_camel_case_types)]
14-
#![allow(non_upper_case_globals)]
1514

1615
use std::fmt::{self, Debug};
1716
use std::marker::PhantomData;
@@ -42,8 +41,8 @@ pub(crate) struct Bool {
4241
value: c_int,
4342
}
4443

45-
pub(crate) const True: Bool = Bool::TRUE;
46-
pub(crate) const False: Bool = Bool::FALSE;
44+
pub(crate) const TRUE: Bool = Bool::TRUE;
45+
pub(crate) const FALSE: Bool = Bool::FALSE;
4746

4847
impl Bool {
4948
pub(crate) const TRUE: Self = Self { value: 1 };

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_target::callconv::{CastTarget, FnAbi};
1515
use crate::abi::{FnAbiLlvmExt, LlvmType};
1616
use crate::context::{CodegenCx, GenericCx, SCx};
1717
pub(crate) use crate::llvm::Type;
18-
use crate::llvm::{False, Metadata, ToLlvmBool, True};
18+
use crate::llvm::{FALSE, Metadata, TRUE, ToLlvmBool};
1919
use crate::type_of::LayoutLlvmExt;
2020
use crate::value::Value;
2121
use crate::{common, llvm};
@@ -141,7 +141,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
141141
}
142142

143143
pub(crate) fn type_variadic_func(&self, args: &[&'ll Type], ret: &'ll Type) -> &'ll Type {
144-
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, True) }
144+
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, TRUE) }
145145
}
146146

147147
pub(crate) fn type_i1(&self) -> &'ll Type {
@@ -202,7 +202,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BaseTypeCodegenMethods for GenericCx<'ll, CX> {
202202
}
203203

204204
fn type_func(&self, args: &[&'ll Type], ret: &'ll Type) -> &'ll Type {
205-
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, False) }
205+
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, FALSE) }
206206
}
207207

208208
fn type_kind(&self, ty: &'ll Type) -> TypeKind {

0 commit comments

Comments
 (0)