This is an archive of the discontinued LLVM Phabricator instance.

Fix static analyzer bugs with null pointer dereferences in CheckSizelessVectorOperands()
AbandonedPublic

Authored by Manna on Jun 5 2023, 1:44 PM.

Details

Summary

This patch adds nullptr checks for LHSBuiltinTy and RHSBuiltinTy before using them to getBuiltinVectorTypeInfo() in clang::​Sema::​CheckSizelessVectorOperands(clang::​ActionResult<clang::​Expr *, true> &, clang::​ActionResult<clang::​Expr *, true> &, clang::​SourceLocation, bool, clang::​Sema::​ArithConvKind).

Diff Detail

Event Timeline

Manna created this revision.Jun 5 2023, 1:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2023, 1:44 PM
Manna requested review of this revision.Jun 5 2023, 1:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2023, 1:44 PM
Manna retitled this revision from [NFC][CLANG] Fix static analyzer bugs with dereference after null check to [NFC][CLANG] Fix static analyzer bugs with null pointer dereferences in CheckSizelessVectorOperands().Jun 5 2023, 1:46 PM
sdesmalen added inline comments.
clang/lib/Sema/SemaExpr.cpp
11119

This doesn't seem like a non-functional change. Here it checks that LHSBuiltinTy is not nullptr before using it, which suggests that it is valid for LHSType/RHSType not to be a builtin type. There is also nothing else guarding that the types are all VLSTBuiltinTypes. Do none of the tests fail?

erichkeane requested changes to this revision.Jun 6 2023, 6:10 AM

The SA tool is incorrect here.

clang/lib/Sema/SemaExpr.cpp
11119

In fact they DO! Pre-commit CI found them.

11149

This is the only other use of htem, but the 1st part of the 'if' checks if these are builtin types.

This revision now requires changes to proceed.Jun 6 2023, 6:10 AM
Manna updated this revision to Diff 529138.Jun 6 2023, 8:06 PM
Manna retitled this revision from [NFC][CLANG] Fix static analyzer bugs with null pointer dereferences in CheckSizelessVectorOperands() to Fix static analyzer bugs with null pointer dereferences in CheckSizelessVectorOperands().
Manna edited the summary of this revision. (Show Details)

Thank you @erichkeane and @sdesmalen for reviews and feedbacks.

Manna set the repository for this revision to rG LLVM Github Monorepo.
Manna marked an inline comment as done.Jun 6 2023, 8:14 PM
Manna added inline comments.
clang/lib/Sema/SemaExpr.cpp
11149

Thanks for the comments. I have added nullptr checks for LHSBuiltinTy and RHSBuiltinTy before using them to getBuiltinVectorTypeInfo() which dereferences.

Manna marked 3 inline comments as done.Jun 6 2023, 8:15 PM
erichkeane added inline comments.Jun 7 2023, 6:44 AM
clang/lib/Sema/SemaExpr.cpp
11148

I think this is unnecessary. isVLSTBuiltinType only returns true if LHSType is a BuiltinType already (or at least, a subset-of). See : https://clang.llvm.org/doxygen/Type_8cpp_source.html#l02409

Manna marked an inline comment as done.Jun 22 2023, 1:06 PM
Manna added inline comments.
clang/lib/Sema/SemaExpr.cpp
11148

This makes sense to me. Thank you for the pointer and explanation!

Manna abandoned this revision.Jun 22 2023, 1:06 PM
Manna marked an inline comment as done.