@@ -1875,7 +1875,8 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(LValue lvalue,
1875
1875
SourceLocation Loc) {
1876
1876
return EmitLoadOfScalar (lvalue.getAddress (), lvalue.isVolatile (),
1877
1877
lvalue.getType (), Loc, lvalue.getBaseInfo (),
1878
- lvalue.getTBAAInfo (), lvalue.isNontemporal ());
1878
+ lvalue.getTBAAInfo (), lvalue.isNontemporal (),
1879
+ lvalue.isErrno ());
1879
1880
}
1880
1881
1881
1882
static bool hasBooleanRepresentation (QualType Ty) {
@@ -1910,6 +1911,16 @@ static bool getRangeForType(CodeGenFunction &CGF, QualType Ty,
1910
1911
return true ;
1911
1912
}
1912
1913
1914
+ static bool maybeDereferencingErrno (const Expr *E) {
1915
+ if (auto *CE = dyn_cast<CallExpr>(E))
1916
+ if (auto *ICE = dyn_cast<ImplicitCastExpr>(CE->getCallee ());
1917
+ ICE && ICE->getCastKind () == CK_FunctionToPointerDecay)
1918
+ if (auto *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr ()))
1919
+ if (auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl ()))
1920
+ return FD->getName () == " __errno_location" ;
1921
+ return false ;
1922
+ }
1923
+
1913
1924
llvm::MDNode *CodeGenFunction::getRangeForLoadFromType (QualType Ty) {
1914
1925
llvm::APInt Min, End;
1915
1926
if (!getRangeForType (*this , Ty, Min, End, CGM.getCodeGenOpts ().StrictEnums ,
@@ -1972,11 +1983,11 @@ bool CodeGenFunction::EmitScalarRangeCheck(llvm::Value *Value, QualType Ty,
1972
1983
}
1973
1984
1974
1985
llvm::Value *CodeGenFunction::EmitLoadOfScalar (Address Addr, bool Volatile,
1975
- QualType Ty,
1976
- SourceLocation Loc,
1986
+ QualType Ty, SourceLocation Loc,
1977
1987
LValueBaseInfo BaseInfo,
1978
1988
TBAAAccessInfo TBAAInfo,
1979
- bool isNontemporal) {
1989
+ bool isNontemporal,
1990
+ bool IsErrno) {
1980
1991
if (auto *GV = dyn_cast<llvm::GlobalValue>(Addr.getBasePointer ()))
1981
1992
if (GV->isThreadLocal ())
1982
1993
Addr = Addr.withPointer (Builder.CreateThreadLocalAddress (GV),
@@ -2038,6 +2049,8 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(Address Addr, bool Volatile,
2038
2049
}
2039
2050
2040
2051
CGM.DecorateInstructionWithTBAA (Load, TBAAInfo);
2052
+ if (IsErrno)
2053
+ CGM.DecorateInstructionWithErrnoTBAA (Load);
2041
2054
2042
2055
if (EmitScalarRangeCheck (Load, Ty, Loc)) {
2043
2056
// In order to prevent the optimizer from throwing away the check, don't
@@ -2132,14 +2145,14 @@ static void EmitStoreOfMatrixScalar(llvm::Value *value, LValue lvalue,
2132
2145
value->getType ()->isVectorTy ());
2133
2146
CGF.EmitStoreOfScalar (value, Addr, lvalue.isVolatile (), lvalue.getType (),
2134
2147
lvalue.getBaseInfo (), lvalue.getTBAAInfo (), isInit,
2135
- lvalue.isNontemporal ());
2148
+ lvalue.isNontemporal (), lvalue. isErrno () );
2136
2149
}
2137
2150
2138
2151
void CodeGenFunction::EmitStoreOfScalar (llvm::Value *Value, Address Addr,
2139
2152
bool Volatile, QualType Ty,
2140
2153
LValueBaseInfo BaseInfo,
2141
- TBAAAccessInfo TBAAInfo,
2142
- bool isInit , bool isNontemporal ) {
2154
+ TBAAAccessInfo TBAAInfo, bool isInit,
2155
+ bool isNontemporal , bool IsErrno ) {
2143
2156
if (auto *GV = dyn_cast<llvm::GlobalValue>(Addr.getBasePointer ()))
2144
2157
if (GV->isThreadLocal ())
2145
2158
Addr = Addr.withPointer (Builder.CreateThreadLocalAddress (GV),
@@ -2182,6 +2195,8 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
2182
2195
}
2183
2196
2184
2197
CGM.DecorateInstructionWithTBAA (Store, TBAAInfo);
2198
+ if (IsErrno)
2199
+ CGM.DecorateInstructionWithErrnoTBAA (Store);
2185
2200
}
2186
2201
2187
2202
void CodeGenFunction::EmitStoreOfScalar (llvm::Value *value, LValue lvalue,
@@ -2193,7 +2208,8 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *value, LValue lvalue,
2193
2208
2194
2209
EmitStoreOfScalar (value, lvalue.getAddress (), lvalue.isVolatile (),
2195
2210
lvalue.getType (), lvalue.getBaseInfo (),
2196
- lvalue.getTBAAInfo (), isInit, lvalue.isNontemporal ());
2211
+ lvalue.getTBAAInfo (), isInit, lvalue.isNontemporal (),
2212
+ lvalue.isErrno ());
2197
2213
}
2198
2214
2199
2215
// Emit a load of a LValue of matrix type. This may require casting the pointer
@@ -3245,6 +3261,8 @@ LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) {
3245
3261
&TBAAInfo);
3246
3262
LValue LV = MakeAddrLValue (Addr, T, BaseInfo, TBAAInfo);
3247
3263
LV.getQuals ().setAddressSpace (ExprTy.getAddressSpace ());
3264
+ if (bool IsErrno = maybeDereferencingErrno (E->getSubExpr ()))
3265
+ LV.setErrno (IsErrno);
3248
3266
3249
3267
// We should not generate __weak write barrier on indirect reference
3250
3268
// of a pointer to object; as in void foo (__weak id *param); *param = 0;
0 commit comments