[PATCH] D45679: [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 4 01:23:17 PDT 2018


JonasToth added inline comments.


================
Comment at: clang-tidy/utils/ExprMutationAnalyzer.cpp:88
+
+const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) {
+  // LHS of any assignment operators.
----------------
shuaiwang wrote:
> aaron.ballman wrote:
> > Should this also consider a DeclRefExpr to a volatile-qualified variable as a direct mutation?
> > 
> > What about using `Expr::HasSideEffect()`?
> Good catch about DeclRefExpr to volatile.
> 
> `HasSideEffects` means something different. Here find*Mutation means find a Stmt **in ancestors** that mutates the given Expr. `HasSideEffects` IIUC means whether anything is mutated by the Expr but doesn't care about what exactly is mutated.
May I ask the exact semantics for `volatile`? I would add the test to my check, too.

It is possible to write `const volatile int m = 42;`, but if i understand correctly `m` could still change by hardware, or would this be UB?
If the `const` is missing, one must always assume external modification, right?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679





More information about the cfe-commits mailing list