10 Commits

Author SHA1 Message Date
Kazu Hirata
1e3e199ed9
[Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2024-11-27 09:13:28 -08:00
smanna12
4389220549
[Clang] Prevent potential null pointer dereferences (#117176)
This commit addresses several null pointer issues identified by static
analysis by replacing dyn_cast<> with cast<> and getAs<> with castAs<>
in various parts of the Clang codebase. The cast and castAs method is
used to ensure that the type is correctly cast, which helps prevent
potential null pointer dereferences.

Changes:
1. ASTContext.cpp:
Replaced dyn_cast with cast to ensure that the type is correctly cast to
AttributedType.

2. SemaFunctionEffects.cpp:
Replaced getAs with castAs to ensure that the type is correctly cast to
FunctionProtoType.

3. SemaHLSL.cpp:
Replaced getAs with castAs to ensure that the type is correctly cast to
VectorType.
2024-11-22 08:41:20 -06:00
Doug Wyatt
39bdf7a9db
[Clang] SemaFunctionEffects: Fix bug where lambdas produced by template expansion weren't verified. (#116505)
---------

Co-authored-by: Doug Wyatt <dwyatt@apple.com>
2024-11-18 16:04:10 -08:00
Sirraide
dde802b153
[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use DynamicRecursiveASTVisitor (#115144)
This pr refactors all recursive AST visitors in `Sema`, `Analyze`, and
`StaticAnalysis` to inherit from DRAV instead. This is over half of the
visitors that inherit from RAV directly.

See also #115132, #110040, #93462

LLVM Compile-Time Tracker link for this branch:
https://llvm-compile-time-tracker.com/compare.php?from=5adb5c05a2e9f31385fbba8b0436cbc07d91a44d&to=b58e589a86c06ba28d4d90613864d10be29aa5ba&stat=instructions%3Au
2024-11-15 08:04:08 +01:00
Doug Wyatt
3e30b365c1
[Clang] SemaFunctionEffects: When verifying a function, ignore any conditional noexcept expression. (#115342)
---------

Co-authored-by: Doug Wyatt <dwyatt@apple.com>
2024-11-10 17:02:50 -08:00
Doug Wyatt
7f9d348eb2
[Clang] SemaFunctionEffects: When verifying a function, ignore any trailing requires clause. (#114266)
---------

Co-authored-by: Doug Wyatt <dwyatt@apple.com>
2024-11-05 10:51:01 +01:00
Jinsong Ji
19aa4c854a
[NFC] Fix implicit-fallthrough warnings (#112825)
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on.
Built by GCC 11.

Fix warnings:

clang/lib/Sema/SemaFunctionEffects.cpp:1531:5: error: this statement may
fall through [-Werror=implicit-fallthrough=]
 1531 |     switch (DiffKind) {
      |     ^~~~~~
2024-10-18 11:42:57 +02:00
Doug Wyatt
cef66aa04d
[Clang] Diagnose additional ObjC statements as function effect violations (#112148)
Bug fix: `@autoreleasepool`, `@synchronized`, and `@finally` were not
being noticed and treated as function effect violations.

---------

Co-authored-by: Doug Wyatt <dwyatt@apple.com>
2024-10-14 17:49:30 +02:00
Doug Wyatt
4d218caa77
[Clang] [Sema] Effects: Correctly detect (x ? a : b) as nonblocking when a and b are (#111224)
Correctly detect `(x ? a : b)` as nonblocking when `a` and `b` are. Use 
`FunctionEffectsRef::get` to get to the actual effect set instead of trying 
to retrieve it manually via the `FunctionProtoType` as we may have to 
look through function pointers etc. in some cases.

---------

Co-authored-by: Doug Wyatt <dwyatt@apple.com>
2024-10-08 10:20:05 +02:00
Doug Wyatt
7fe43ada28
[Clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (#99656)
- In Sema, when encountering Decls with function effects needing
verification, add them to a vector, DeclsWithEffectsToVerify.
- Update AST serialization to include DeclsWithEffectsToVerify.
- In AnalysisBasedWarnings, use DeclsWithEffectsToVerify as a work
queue, verifying functions with declared effects, and inferring (when
permitted and necessary) whether their callees have effects.

---------

Co-authored-by: Doug Wyatt <dwyatt@apple.com>
Co-authored-by: Sirraide <aeternalmail@gmail.com>
Co-authored-by: Erich Keane <ekeane@nvidia.com>
2024-10-03 02:14:51 +02:00