================
@@ -1242,33 +1228,97 @@ void
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
const Expr *ObjArg = TheCall->getArg(NewIndex);
if (std::optional<uint64_t> Result =
- ObjArg->tryEvaluateStrLen(getASTContext())) {
+ ObjArg->tryEvaluateStrLen(S.getASTContext())) {
// Add 1 for null byte.
return llvm::APSInt::getUnsigned(*Result + 1).extOrTrunc(SizeTypeWidth);
}
return std::nullopt;
- };
+ }
+
+ unsigned getSizeTypeWidth() const { return SizeTypeWidth; }
+
+ unsigned getBuiltinID() const {
+ const FunctionDecl *UseDecl = FD;
+ if (DABAttr) {
+ UseDecl = DABAttr->getFunction();
+ assert(UseDecl && "Missing FunctionDecl in DiagnoseAsBuiltin
attribute!");
+ }
+ return UseDecl->getBuiltinID(/*ConsiderWrappers=*/true);
+ }
+
+ /// Return function name after stripping __builtin_ and _chk affixes.
+ std::string getFunctionName() const {
+ unsigned ID = getBuiltinID();
+ if (!ID) {
+ // Use callee name directly if not a builtin.
+ const FunctionDecl *Callee = TheCall->getDirectCallee();
+ assert(Callee && "expected callee");
+ return Callee->getName().str();
+ }
+ std::string Name = S.getASTContext().BuiltinInfo.getName(ID);
+ StringRef Ref = Name;
+ // Strip __builtin___*_chk or __builtin_ prefix.
+ if (!(Ref.consume_front("__builtin___") && Ref.consume_back("_chk")))
+ Ref.consume_front("__builtin_");
+ assert(!Ref.empty() && "expected non-empty function name");
+ return Ref.str();
+ }
+
+ /// Check for source buffer overread in memory functions.
+ void checkSourceOverread(unsigned SrcArgIdx, unsigned SizeArgIdx) {
+ if (S.isConstantEvaluatedContext())
+ return;
+
+ const Expr *SrcArg = TheCall->getArg(SrcArgIdx);
+ const Expr *SizeArg = TheCall->getArg(SizeArgIdx);
+ // Need to check both value-dependence and instantiation-dependence.
----------------
erichkeane wrote:
> Yeah, that's wrong, instantiation dependence means it depends on template
> parameters somehow, so it is a strict superset of value and type dependence.
>
> That's a bug in
> [6b760a5](https://github.com/llvm/llvm-project/commit/6b760a50f52142e401a6380ff71f933cda22a909),
> it should have set `ExprDependence::ValueInstantiation` instead of just
> `ExprDependence::Value`.
Cool, thanks for the confirmation. @jpjepko : Could you just fix that up as
suggested here and see if that fixes the bug/doesn't regress anything?
https://github.com/llvm/llvm-project/pull/208012
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits