Skip to content
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
2 changes: 1 addition & 1 deletion clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -4699,7 +4699,7 @@ class FunctionEffect {

private:
LLVM_PREFERRED_TYPE(Kind)
unsigned FKind : 3;
uint8_t FKind : 3;

// Expansion: for hypothetical TCB+types, there could be one Kind for TCB,
// then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,7 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", [UnsafeBufferUsageInCon
// Warnings and notes related to the function effects system underlying
// the nonblocking and nonallocating attributes.
def FunctionEffects : DiagGroup<"function-effects">;
def PerfConstraintImpliesNoexcept : DiagGroup<"perf-constraint-implies-noexcept">;

// Warnings and notes InstallAPI verification.
def InstallAPIViolation : DiagGroup<"installapi-violation">;
Expand Down
49 changes: 49 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10928,6 +10928,55 @@ def warn_imp_cast_drops_unaligned : Warning<
InGroup<DiagGroup<"unaligned-qualifier-implicit-cast">>;

// Function effects
def warn_func_effect_allocates : Warning<
"'%0' function must not allocate or deallocate memory">,
InGroup<FunctionEffects>;
def note_func_effect_allocates : Note<
"function cannot be inferred '%0' because it allocates/deallocates memory">;
def warn_func_effect_throws_or_catches : Warning<
"'%0' function must not throw or catch exceptions">,
InGroup<FunctionEffects>;
def note_func_effect_throws_or_catches : Note<
"function cannot be inferred '%0' because it throws or catches exceptions">;
def warn_func_effect_has_static_local : Warning<
"'%0' function must not have static locals">,
InGroup<FunctionEffects>;
def note_func_effect_has_static_local : Note<
"function cannot be inferred '%0' because it has a static local">;
def warn_func_effect_uses_thread_local : Warning<
"'%0' function must not use thread-local variables">,
InGroup<FunctionEffects>;
def note_func_effect_uses_thread_local : Note<
"function cannot be inferred '%0' because it uses a thread-local variable">;
def warn_func_effect_calls_objc : Warning<
"'%0' function must not access an ObjC method or property">,
InGroup<FunctionEffects>;
def note_func_effect_calls_objc : Note<
"function cannot be inferred '%0' because it accesses an ObjC method or property">;
def warn_func_effect_calls_func_without_effect : Warning<
"'%0' function must not call non-'%0' function '%1'">,
InGroup<FunctionEffects>;
def warn_func_effect_calls_expr_without_effect : Warning<
"'%0' function must not call non-'%0' expression">,
InGroup<FunctionEffects>;
def note_func_effect_calls_func_without_effect : Note<
"function cannot be inferred '%0' because it calls non-'%0' function '%1'">;
def note_func_effect_call_extern : Note<
"function cannot be inferred '%0' because it has no definition in this translation unit">;
def note_func_effect_call_disallows_inference : Note<
"function does not permit inference of '%0'">;
def note_func_effect_call_virtual : Note<
"virtual method cannot be inferred '%0'">;
def note_func_effect_call_func_ptr : Note<
"function pointer cannot be inferred '%0'">;
def warn_perf_constraint_implies_noexcept : Warning<
"'%0' function should be declared noexcept">,
InGroup<PerfConstraintImpliesNoexcept>;

// FIXME: It would be nice if we could provide fuller template expansion notes.
def note_func_effect_from_template : Note<
"in template expansion here">;

// spoofing nonblocking/nonallocating
def warn_invalid_add_func_effects : Warning<
"attribute '%0' should not be added via type conversion">,
Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,13 @@ class Sema final : public SemaBase {

// ----- function effects ---

/// All functions/lambdas/blocks which have bodies and which have a non-empty
/// FunctionEffectsRef to be verified.
SmallVector<const Decl *> DeclsWithEffectsToVerify;
/// The union of all effects present on DeclsWithEffectsToVerify. Conditions
/// are all null.
FunctionEffectSet AllEffectsToVerify;

/// Warn when implicitly changing function effects.
void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType,
SourceLocation Loc);
Expand All @@ -891,6 +898,12 @@ class Sema final : public SemaBase {
SourceLocation NewLoc,
SourceLocation OldLoc);

/// Potentially add a FunctionDecl or BlockDecl to DeclsWithEffectsToVerify.
void maybeAddDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);

/// Unconditionally add a Decl to DeclsWithEfffectsToVerify.
void addDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);

/// Try to parse the conditional expression attached to an effect attribute
/// (e.g. 'nonblocking'). (c.f. Sema::ActOnNoexceptSpec). Return an empty
/// optional on error.
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ enum ASTRecordTypes {

/// Record code for \#pragma clang unsafe_buffer_usage begin/end
PP_UNSAFE_BUFFER_USAGE = 69,

/// Record code for Sema's vector of functions/blocks with effects to
/// be verified.
DECLS_WITH_EFFECTS_TO_VERIFY = 70,
};

/// Record types used within a source manager block.
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,9 @@ class ASTReader
/// Sema tracks these to emit deferred diags.
llvm::SmallSetVector<GlobalDeclID, 4> DeclsToCheckForDeferredDiags;

/// The IDs of all decls with function effects to be checked.
SmallVector<GlobalDeclID, 0> DeclsWithEffectsToVerify;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably not include the '0' here. The size of ASTReader isn't concerning/problematic, and the default is usually pretty reasonable. So I'd suggest just removing the , 0 or making this a std::vector.


private:
struct ImportedSubmodule {
serialization::SubmoduleID ID;
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Serialization/ASTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ class ASTWriter : public ASTDeserializationListener,
void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
void WritePackPragmaOptions(Sema &SemaRef);
void WriteFloatControlPragmaOptions(Sema &SemaRef);
void WriteDeclsWithEffectsToVerify(Sema &SemaRef);
void WriteModuleFileExtension(Sema &SemaRef,
ModuleFileExtensionWriter &Writer);

Expand Down
Loading