Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonblocking/nonallocating attributes: 2nd pass caller/callee analysis #99656

Merged
merged 71 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
8c5f854
nonblocking/nonallocating attributes: 2nd pass caller/callee analysis…
May 5, 2024
95b7a00
- Sema.h: Move function decls to be in the correct per-source-file se…
Jul 20, 2024
21c780a
clang-format
Jul 20, 2024
ff10413
- Detect ObjC @throw and @catch, diagnose identically to their C++ co…
Jul 26, 2024
d472964
FunctionEffect constructors: cast Kind to uint8_t
May 5, 2024
f1142db
New file: EFfectAnalysis.cpp.
Jul 26, 2024
efe1b93
CallableInfo doesn't need to cache the name.
Jul 26, 2024
d4f8dd5
Merge branch 'main' into nonblocking-part2
Jul 26, 2024
7ffdbef
Simpler bitmap implementation of FunctionEffectKindSet
Aug 2, 2024
c39e28e
- function does not permit inference of '%0': include the name of the…
Aug 2, 2024
dec1a61
Merge remote-tracking branch 'llvm-origin/main' into nonblocking-part2
Aug 5, 2024
06ca4c5
Add tests around lambda traversal and contexts like decltype, sizeof,…
Aug 7, 2024
9e45e6f
Inline checks preceding maybeAddDeclWithEffects
Aug 7, 2024
b99f784
Remove dead code in EffectAnalysis.cpp. Add comment about AST travers…
Aug 7, 2024
dbdd8f8
Merge remote-tracking branch 'llvm-origin/main' into nonblocking-part2
Aug 7, 2024
1b9874f
patch what the bot's clang-format wishes clang-format on my system wo…
Aug 7, 2024
b8818a3
Merge branch 'main' into nonblocking-part2
Aug 8, 2024
8390e69
"function cannot be inferred" -> "declaration cannot be inferred"
Aug 8, 2024
7acda8c
No need to override VisitCXXDefaultInitExpr.
Aug 8, 2024
bffacc5
Begin a list of unsafe builtin functions, starting with malloc and fr…
Aug 13, 2024
c718b5a
Apply suggestions from code review
dougsonos Aug 14, 2024
8b225f4
- FunctionEffect and FunctionEffectKindSet are tiny, pass by value wh…
Aug 14, 2024
2cb4539
- Comments begin with capital letters and end with full stops.
Aug 14, 2024
0e07315
Implement FunctionEffectKindSet with std::bitset.
Aug 14, 2024
47dfce8
Merge remote-tracking branch 'llvm-origin/main' into nonblocking-part2
Aug 14, 2024
fddd9d2
- Diagnose __builtin_operator_new and delete
Aug 14, 2024
eb536ab
EffectAnalysis.cpp => SemaFunctionEffects.cpp (minimal first step; mo…
Aug 15, 2024
15b399f
Move most Sema methods involving effects into SemaFunctionEffects.cpp.
Aug 15, 2024
dfebc1a
Move FunctionEffectDiff/Differences into SemaFunctionEffects.cpp.
Aug 16, 2024
82cb07d
Combine the diagnostics for 5 violations into one using %select{}
Aug 16, 2024
a7060ad
Merge branch 'main' into nonblocking-part2
Aug 16, 2024
f93ee01
Violation constructor: use optional instead of pointer.
Aug 16, 2024
6cc0a62
clang-format
Aug 16, 2024
69e1ae6
emitDiagnostics doesn't need to receive another S
Aug 16, 2024
076302e
VisitVarDecl can reuse followTypeDtor().
Aug 16, 2024
7b891c6
Add a test for a delegating initializer.
Aug 16, 2024
d1fcceb
Fix typo in comment for TraverseLambdaExpr.
Aug 16, 2024
abcf022
Fix test broken by rewording of diagnostics.
Aug 17, 2024
47ebf27
Diagnostics are now more specific about where a construct was found, …
Aug 17, 2024
6650c1f
Two fixes for default arguments:
Aug 20, 2024
250b80b
Type.cpp: remove asserts preceding llvm_unreachable().
Aug 20, 2024
e8bcd9f
Fix pre-C++20 compile error.
Aug 22, 2024
ea7f3fc
Review feedback: ViolationSite can use a PointerIntPair. Expand list …
Aug 29, 2024
d1a39e2
Fix: was traversing virtual base class destructors twice, exposed by …
Aug 29, 2024
75365ef
More builtin functions.
Aug 29, 2024
6aadec0
Apply suggestions from code review
dougsonos Sep 4, 2024
9b123a6
Review feedback:
Sep 4, 2024
ba57bfb
Fix: Don't try to follow a deleted destructor. (Happens with a std::o…
Sep 4, 2024
54feb05
Fix test broken by rewording of warnings.
Sep 5, 2024
93cb74e
Fix: need to ignore concept requirements.
Sep 5, 2024
d583c85
clang-format
Sep 5, 2024
cda1a9c
Make the FunctionEffects and PerfConstraintImpliesNoexcept diagnostic…
Sep 7, 2024
9c971c6
Add a release note.
Sep 7, 2024
b23e942
Merge branch 'main' into nonblocking-part2
Sep 8, 2024
9bfbe12
Fix botched format string in warn_func_effect_calls_expr_without_effect
Sep 9, 2024
f06909b
Fix test failures introduced by last commit.
Sep 17, 2024
adcfd14
If a function is noexcept and noreturn, exempt it from effect analysis.
Sep 18, 2024
17320b8
Remove the new diagnostics from `-Wall`. Fix a couple of sentences in…
Sep 23, 2024
909d7ff
Apply suggestions from code review
dougsonos Sep 23, 2024
9367103
Review feedback:
Sep 23, 2024
eb782e0
- Add constraint tests for plain C.
Sep 24, 2024
eccc7cf
-Wperf-constraint-implies-noexcept is part of -Wall again
Sep 24, 2024
220a1bf
Remove FunctionEffect::Kind::None as a sentinel; use optionals instead.
Sep 25, 2024
a8fef93
Ensure that setjmp() is not included in the special treatment of `nor…
Sep 26, 2024
092bc16
Update clang/lib/Sema/SemaFunctionEffects.cpp
dougsonos Sep 26, 2024
ca3f44a
Merge branch 'main' into nonblocking-part2
Sep 26, 2024
424a74b
Builtins with effects don't get the noexcept/noreturn special treatment.
Sep 26, 2024
273871a
warning-wall test was broken a few commits ago; fix it now.
Sep 26, 2024
a77d4e3
- FunctionEffect::Kind: no need to be specific with enum values. Same…
Sep 26, 2024
f8d9189
Tweak release note, fix typo in comment.
Sep 26, 2024
da725c1
Tweak: "function with 'nonblocking' attribute should be declared noex…
Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion clang/lib/Sema/SemaFunctionEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ static FunctionEffectKindSet getBuiltinFunctionEffects(unsigned BuiltinID) {
break;

// These block in some other way than allocating memory.
// longjmp() and friends are presumed unsafe because they are the moral
// equivalent of throwing a C++ exception, which is unsafe.
case Builtin::ID::BIlongjmp:
case Builtin::ID::BI_longjmp:
case Builtin::ID::BIsiglongjmp:
Expand Down Expand Up @@ -1016,17 +1018,22 @@ class Analyzer {
// Check for a call to a builtin function, whose effects are
// handled specially.
if (const auto *FD = dyn_cast<FunctionDecl>(CI.CDecl)) {
bool IgnoreIfNoexceptNoreturn = true;
if (unsigned BuiltinID = FD->getBuiltinID()) {
CI.Effects = getBuiltinFunctionEffects(BuiltinID);
if (CI.Effects.empty()) {
// A builtin with no known effects is assumed safe.
return;
}
// A builtin WITH effects doesn't get any special treatment for
// being noreturn/noexcept, e.g. longjmp().
IgnoreIfNoexceptNoreturn = false;
Sirraide marked this conversation as resolved.
Show resolved Hide resolved
}

// If the callee is both `noreturn` and `noexcept`, it presumably
// terminates. Ignore it for the purposes of effect analysis.
// If not C++, `noreturn` alone is sufficient.
Sirraide marked this conversation as resolved.
Show resolved Hide resolved
if (FD->isNoReturn() &&
if (IgnoreIfNoexceptNoreturn && FD->isNoReturn() &&
(!Outer.S.getLangOpts().CPlusPlus || isNoexcept(FD)))
return;
}
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Headers/Inputs/include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ typedef struct {
int x[42];
} jmp_buf;

__attribute__((noreturn))
void longjmp(jmp_buf, int);

#endif
11 changes: 10 additions & 1 deletion clang/test/Sema/attr-nonblocking-constraints.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -Wfunction-effects %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -Wfunction-effects -internal-isystem %S/../Headers/Inputs/include %s

// Tests for a few cases involving C functions without prototypes.

Expand All @@ -16,3 +16,12 @@ void nb2(void) __attribute__((nonblocking)) {
nb1();
aborts(); // no diagnostic because it's noreturn.
}

#include <setjmp.h>

void nb3(int x, int y) __attribute__((nonblocking)) {
if (x != y) {
jmp_buf jb;
longjmp(jb, 0); // expected-warning {{function with 'nonblocking' attribute must not call non-'nonblocking' function 'longjmp'}}
}
}