Add more @safe annotations

This commit is contained in:
Dennis Korpel 2024-10-02 12:47:01 +02:00 committed by The Dlang Bot
parent 4ccb01fde5
commit 76d2c08fde
14 changed files with 22 additions and 25 deletions

View file

@ -328,7 +328,6 @@ void WRdefnod(ref GlobalOptimizer go)
} }
} }
@trusted
const(char)* fl_str(FL fl) const(char)* fl_str(FL fl)
{ {
immutable char*[FLMAX] fls = immutable char*[FLMAX] fls =

View file

@ -287,7 +287,6 @@ bool tyvector(tym_t ty) { return tybasic(ty) >= TYfloat4 && tybasic(ty) <= TYull
uint tyshort(tym_t ty) { return tytab[ty & 0xFF] & TYFLshort; } uint tyshort(tym_t ty) { return tytab[ty & 0xFF] & TYFLshort; }
/* Detect TYlong or TYulong */ /* Detect TYlong or TYulong */
@trusted
bool tylong(tym_t ty) { return tybasic(ty) == TYlong || tybasic(ty) == TYulong; } bool tylong(tym_t ty) { return tybasic(ty) == TYlong || tybasic(ty) == TYulong; }
/* Use to detect a pointer type */ /* Use to detect a pointer type */

View file

@ -2384,7 +2384,6 @@ private void loadcse(ref CodeBuilder cdb,elem *e,reg_t reg,regm_t regm)
} }
@trusted
void callcdxxx(ref CGstate cg, ref CodeBuilder cdb, elem *e, ref regm_t pretregs, OPER op) void callcdxxx(ref CGstate cg, ref CodeBuilder cdb, elem *e, ref regm_t pretregs, OPER op)
{ {
(*cdxxx[op])(cg, cdb, e, pretregs); (*cdxxx[op])(cg, cdb, e, pretregs);

View file

@ -51,7 +51,7 @@ import dmd.tokens;
* Returns: * Returns:
* merged storage class * merged storage class
*/ */
StorageClass mergeFuncAttrs(StorageClass s1, const FuncDeclaration f) pure StorageClass mergeFuncAttrs(StorageClass s1, const FuncDeclaration f) pure @safe
{ {
if (!f) if (!f)
return s1; return s1;

View file

@ -247,7 +247,7 @@ struct OutBuffer
/** /**
* Writes a 16 bit value, no reserve check. * Writes a 16 bit value, no reserve check.
*/ */
nothrow nothrow @safe
void write16n(int v) void write16n(int v)
{ {
auto x = cast(ushort) v; auto x = cast(ushort) v;
@ -367,7 +367,7 @@ struct OutBuffer
} }
// Position buffer to accept the specified number of bytes at offset // Position buffer to accept the specified number of bytes at offset
void position(size_t where, size_t nbytes) nothrow void position(size_t where, size_t nbytes) nothrow @safe
{ {
if (where + nbytes > data.length) if (where + nbytes > data.length)
{ {

View file

@ -319,7 +319,7 @@ struct Triple
Initializes Target settings to compile for the same target Initializes Target settings to compile for the same target
as the build compiler. as the build compiler.
*/ */
void setTargetBuildDefaults(ref Target target) void setTargetBuildDefaults(ref Target target) @safe
{ {
target = target.init; target = target.init;
target.os = defaultTargetOS(); target.os = defaultTargetOS();

View file

@ -253,13 +253,13 @@ extern (C++) struct Scope
} }
/// Copy flags from scope `other` /// Copy flags from scope `other`
extern(D) void copyFlagsFrom(Scope* other) extern(D) void copyFlagsFrom(Scope* other) @safe
{ {
this.bitFields = other.bitFields; this.bitFields = other.bitFields;
} }
/// Set all scope flags to their initial value /// Set all scope flags to their initial value
extern(D) void resetAllFlags() extern(D) void resetAllFlags() @safe
{ {
this.bitFields = 0; this.bitFields = 0;
} }

View file

@ -4082,7 +4082,7 @@ private extern(C++) class AddMemberVisitor : Visitor
Scope* sc; Scope* sc;
ScopeDsymbol sds; ScopeDsymbol sds;
this(Scope* sc, ScopeDsymbol sds) this(Scope* sc, ScopeDsymbol sds) @safe
{ {
this.sc = sc; this.sc = sc;
this.sds = sds; this.sds = sds;
@ -6045,7 +6045,7 @@ private extern(C++) class SearchVisitor : Visitor
SearchOptFlags flags; SearchOptFlags flags;
Dsymbol result; Dsymbol result;
this(const ref Loc loc, Identifier ident, SearchOptFlags flags) this(const ref Loc loc, Identifier ident, SearchOptFlags flags) @safe
{ {
this.loc = loc; this.loc = loc;
this.ident = ident; this.ident = ident;
@ -6651,7 +6651,7 @@ private extern(C++) class SetScopeVisitor : Visitor
alias visit = typeof(super).visit; alias visit = typeof(super).visit;
Scope* sc; Scope* sc;
this(Scope* sc) this(Scope* sc) @safe
{ {
this.sc = sc; this.sc = sc;
} }
@ -6794,7 +6794,7 @@ extern(C++) class ImportAllVisitor : Visitor
alias visit = typeof(super).visit; alias visit = typeof(super).visit;
Scope* sc; Scope* sc;
this(Scope* sc) this(Scope* sc) @safe
{ {
this.sc = sc; this.sc = sc;
} }
@ -7037,7 +7037,7 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
FieldState* fieldState; FieldState* fieldState;
bool isunion; bool isunion;
this(AggregateDeclaration ad, FieldState* fieldState, bool isunion) this(AggregateDeclaration ad, FieldState* fieldState, bool isunion) @safe
{ {
this.ad = ad; this.ad = ad;
this.fieldState = fieldState; this.fieldState = fieldState;

View file

@ -1880,7 +1880,7 @@ extern (C++) final class InterpExp : Expression
enum char NoPostfix = 0; enum char NoPostfix = 0;
extern (D) this(const ref Loc loc, InterpolatedSet* set, char postfix = NoPostfix) scope extern (D) this(const ref Loc loc, InterpolatedSet* set, char postfix = NoPostfix) scope @safe
{ {
super(loc, EXP.interpolated); super(loc, EXP.interpolated);
this.interpolatedSet = set; this.interpolatedSet = set;
@ -4575,7 +4575,7 @@ extern (C++) class CatAssignExp : BinAssignExp
{ {
Expression lowering; // lowered druntime hook `_d_arrayappend{cTX,T}` Expression lowering; // lowered druntime hook `_d_arrayappend{cTX,T}`
extern (D) this(const ref Loc loc, Expression e1, Expression e2) extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{ {
super(loc, EXP.concatenateAssign, e1, e2); super(loc, EXP.concatenateAssign, e1, e2);
} }
@ -5286,7 +5286,7 @@ extern (C++) final class ObjcClassReferenceExp : Expression
{ {
ClassDeclaration classDeclaration; ClassDeclaration classDeclaration;
extern (D) this(const ref Loc loc, ClassDeclaration classDeclaration) extern (D) this(const ref Loc loc, ClassDeclaration classDeclaration) @safe
{ {
super(loc, EXP.objcClassReference); super(loc, EXP.objcClassReference);
this.classDeclaration = classDeclaration; this.classDeclaration = classDeclaration;

View file

@ -2802,7 +2802,7 @@ void modifyReturns(FuncLiteralDeclaration fld, Scope* sc, Type tret)
* Returns: `true` if the provided scope is the root * Returns: `true` if the provided scope is the root
* of the traits compiles list of scopes. * of the traits compiles list of scopes.
*/ */
bool isRootTraitsCompilesScope(Scope* sc) bool isRootTraitsCompilesScope(Scope* sc) @safe
{ {
return (sc.traitsCompiles) && !sc.func.skipCodegen; return (sc.traitsCompiles) && !sc.func.skipCodegen;
} }

View file

@ -134,7 +134,7 @@ extern(C++) struct Verbose
uint errorLimit = 20; uint errorLimit = 20;
uint errorSupplementLimit = 6; // Limit the number of supplemental messages for each error (0 means unlimited) uint errorSupplementLimit = 6; // Limit the number of supplemental messages for each error (0 means unlimited)
uint errorSupplementCount() uint errorSupplementCount() @safe
{ {
if (verbose) if (verbose)
return uint.max; return uint.max;
@ -256,7 +256,7 @@ extern (C++) struct Param
const(char)* timeTraceFile; /// File path of output file const(char)* timeTraceFile; /// File path of output file
/// ///
bool parsingUnittestsRequired() bool parsingUnittestsRequired() @safe
{ {
return useUnitTests || ddoc.doOutput || dihdr.doOutput; return useUnitTests || ddoc.doOutput || dihdr.doOutput;
} }

View file

@ -277,7 +277,7 @@ nothrow:
* Returns: * Returns:
* the slice * the slice
*/ */
extern (D) static const(char)[] sansExt(const char[] filename) extern (D) static const(char)[] sansExt(const char[] filename) @safe
{ {
auto e = ext(filename); auto e = ext(filename);
size_t length = e.length; size_t length = e.length;
@ -1101,7 +1101,7 @@ nothrow:
return str.ptr; return str.ptr;
} }
const(char)[] toString() const pure nothrow @nogc @trusted const(char)[] toString() const pure nothrow @nogc @safe
{ {
return str; return str;
} }

View file

@ -433,7 +433,7 @@ Returns:
a `FindSplit` object that casts to `true` iff `needle` was found inside `str`. a `FindSplit` object that casts to `true` iff `needle` was found inside `str`.
In that case, `split[1]` is the needle, and `split[0]`/`split[2]` are before/after the needle. In that case, `split[1]` is the needle, and `split[0]`/`split[2]` are before/after the needle.
*/ */
FindSplit findSplit(return scope const(char)[] str, scope const(char)[] needle) FindSplit findSplit(return scope const(char)[] str, scope const(char)[] needle) @safe
{ {
if (needle.length > str.length) if (needle.length > str.length)
return FindSplit([str, null, null]); return FindSplit([str, null, null]);
@ -469,7 +469,7 @@ Params:
Returns: Returns:
substring of `str` inbetween `l` and `r` substring of `str` inbetween `l` and `r`
*/ */
const(char)[] findBetween(const(char)[] str, const(char)[] l, const(char)[] r) const(char)[] findBetween(const(char)[] str, const(char)[] l, const(char)[] r) @safe
{ {
if (auto s0 = str.findSplit(l)) if (auto s0 = str.findSplit(l))
if (auto s1 = s0[2].findSplit(r)) if (auto s1 = s0[2].findSplit(r))

View file

@ -237,7 +237,7 @@ bool parseDigits(T)(ref T val, const(char)[] p, const T max = T.max)
* size = 1 for ubyte[], 2 for ushort[], 4 for uint[], 8 for ulong[] * size = 1 for ubyte[], 2 for ushort[], 4 for uint[], 8 for ulong[]
* Returns: copy of `data`, with bytes shuffled if compiled for `version(LittleEndian)` * Returns: copy of `data`, with bytes shuffled if compiled for `version(LittleEndian)`
*/ */
ubyte[] arrayCastBigEndian(const ubyte[] data, size_t size) ubyte[] arrayCastBigEndian(const ubyte[] data, size_t size) @safe
{ {
ubyte[] impl(T)() ubyte[] impl(T)()
{ {