[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)
@@ -657,17 +658,22 @@ class TransferVisitor : public ConstStmtVisitor { } void VisitConditionalOperator(const ConditionalOperator *S) { -// FIXME: Revisit this once flow conditions are added to the framework. For -// `a = b ? c : d` we can add `b => a == c && !b => a == d` to the flow -// condition. -// When we do this, we will need to retrieve the values of the operands from -// the environments for the basic blocks they are computed in, in a similar -// way to how this is done for short-circuited logical operators in -// `getLogicOperatorSubExprValue()`. -if (S->isGLValue()) - Env.setStorageLocation(*S, Env.createObject(S->getType())); -else if (!S->getType()->isRecordType()) { - if (Value *Val = Env.createValue(S->getType())) +const Environment *TrueEnv = StmtToEnv.getEnvironment(*S->getTrueExpr()); +const Environment *FalseEnv = StmtToEnv.getEnvironment(*S->getFalseExpr()); + +if (TrueEnv == nullptr || FalseEnv == nullptr) + return; + +if (S->isGLValue()) { + StorageLocation *TrueLoc = TrueEnv->getStorageLocation(*S->getTrueExpr()); + StorageLocation *FalseLoc = + FalseEnv->getStorageLocation(*S->getFalseExpr()); + if (TrueLoc == FalseLoc && TrueLoc != nullptr) +Env.setStorageLocation(*S, *TrueLoc); +} else if (!S->getType()->isRecordType()) { + if (Value *Val = Environment::joinValues( martinboehme wrote: > That being said, I think this is not too bad to explain. I am happy with the > PR now. I wonder if it is worth to extend the comment why the join here is > inherently part of the transfer in case it is possible to do it in a couple > of concise sentences. If that is not the case, I am ok with merging as is. I've added my attempt at this, though it ended up being more than two sentences. I'll merge this as-is, as it's just a comment change, but If you think this explanation is too much, happy to remove it in a followup PR. https://github.com/llvm/llvm-project/pull/89213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)
https://github.com/martinboehme updated https://github.com/llvm/llvm-project/pull/89213 >From e6f729dff29cb74ca0599ba486561d04963c1ac5 Mon Sep 17 00:00:00 2001 From: Martin Braenne Date: Thu, 18 Apr 2024 10:50:40 + Subject: [PATCH 1/4] [clang][dataflow] Model conditional operator correctly. --- .../FlowSensitive/DataflowEnvironment.h | 15 + .../clang/Analysis/FlowSensitive/Transfer.h | 3 +- .../FlowSensitive/DataflowEnvironment.cpp | 46 ++--- clang/lib/Analysis/FlowSensitive/Transfer.cpp | 38 ++- .../TypeErasedDataflowAnalysis.cpp| 4 +- .../Analysis/FlowSensitive/TestingSupport.h | 4 +- .../Analysis/FlowSensitive/TransferTest.cpp | 66 +-- 7 files changed, 130 insertions(+), 46 deletions(-) diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index d50dba35f8264c..cdf89c7def2c91 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -244,6 +244,21 @@ class Environment { Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior); + /// Returns a value that approximates both `Val1` and `Val2`, or null if no + /// such value can be produced. + /// + /// `Env1` and `Env2` can be used to query child values and path condition + /// implications of `Val1` and `Val2` respectively. The joined value will be + /// produced in `JoinedEnv`. + /// + /// Requirements: + /// + /// `Val1` and `Val2` must model values of type `Type`. + static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1, + Value *Val2, const Environment &Env2, + Environment &JoinedEnv, + Environment::ValueModel &Model); + /// Widens the environment point-wise, using `PrevEnv` as needed to inform the /// approximation. /// diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h b/clang/include/clang/Analysis/FlowSensitive/Transfer.h index ed148250d8eb29..940025e02100f9 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h +++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h @@ -53,7 +53,8 @@ class StmtToEnvMap { /// Requirements: /// /// `S` must not be `ParenExpr` or `ExprWithCleanups`. -void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); +void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, + Environment::ValueModel &Model); } // namespace dataflow } // namespace clang diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 05395e07a7a68c..3cb656adcbdc0c 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -237,13 +237,8 @@ joinLocToVal(const llvm::MapVector &LocToVal, continue; assert(It->second != nullptr); -if (areEquivalentValues(*Val, *It->second)) { - Result.insert({Loc, Val}); - continue; -} - -if (Value *JoinedVal = joinDistinctValues( -Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) { +if (Value *JoinedVal = Environment::joinValues( +Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) { Result.insert({Loc, JoinedVal}); } } @@ -775,27 +770,16 @@ Environment Environment::join(const Environment &EnvA, const Environment &EnvB, JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal; JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc; - if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) { -// `ReturnVal` might not always get set -- for example if we have a return -// statement of the form `return some_other_func()` and we decide not to -// analyze `some_other_func()`. -// In this case, we can't say anything about the joined return value -- we -// don't simply want to propagate the return value that we do have, because -// it might not be the correct one. -// This occurs for example in the test `ContextSensitiveMutualRecursion`. + if (EnvA.CallStack.empty()) { JoinedEnv.ReturnVal = nullptr; - } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) { -JoinedEnv.ReturnVal = EnvA.ReturnVal; } else { -assert(!EnvA.CallStack.empty()); // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this // cast. auto *Func = dyn_cast(EnvA.CallStack.back()); assert(Func != nullptr); -if (Value *JoinedVal = -joinDistinctValues(Func->getReturnType(), *EnvA.ReturnVal, EnvA, - *EnvB.ReturnVal, EnvB, JoinedEnv, Model)) - JoinedEnv.ReturnVal = JoinedVal; +JoinedEnv.ReturnVal = +joinVal
[clang] [clang][RISCV] Support RVV bfloat16 C intrinsics (PR #89354)
kito-cheng wrote: > Oh, I forgot to remove them. Or do you think they should be moved to bfloat > folder to make them consistent? Remove files from this PR, that should be a separated NFC PR for moving those files, but I am fine to keep those file in same place :) https://github.com/llvm/llvm-project/pull/89354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)
https://github.com/martinboehme closed https://github.com/llvm/llvm-project/pull/89213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] abb958f - [clang][dataflow] Model conditional operator correctly. (#89213)
Author: martinboehme Date: 2024-04-22T09:23:13+02:00 New Revision: abb958f1610becc0a753ad8f4308a90f85e1338f URL: https://github.com/llvm/llvm-project/commit/abb958f1610becc0a753ad8f4308a90f85e1338f DIFF: https://github.com/llvm/llvm-project/commit/abb958f1610becc0a753ad8f4308a90f85e1338f.diff LOG: [clang][dataflow] Model conditional operator correctly. (#89213) Added: Modified: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h clang/include/clang/Analysis/FlowSensitive/Transfer.h clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp clang/unittests/Analysis/FlowSensitive/TestingSupport.h clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Removed: diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index d50dba35f8264c..cdf89c7def2c91 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -244,6 +244,21 @@ class Environment { Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior); + /// Returns a value that approximates both `Val1` and `Val2`, or null if no + /// such value can be produced. + /// + /// `Env1` and `Env2` can be used to query child values and path condition + /// implications of `Val1` and `Val2` respectively. The joined value will be + /// produced in `JoinedEnv`. + /// + /// Requirements: + /// + /// `Val1` and `Val2` must model values of type `Type`. + static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1, + Value *Val2, const Environment &Env2, + Environment &JoinedEnv, + Environment::ValueModel &Model); + /// Widens the environment point-wise, using `PrevEnv` as needed to inform the /// approximation. /// diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h b/clang/include/clang/Analysis/FlowSensitive/Transfer.h index ed148250d8eb29..940025e02100f9 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h +++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h @@ -53,7 +53,8 @@ class StmtToEnvMap { /// Requirements: /// /// `S` must not be `ParenExpr` or `ExprWithCleanups`. -void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); +void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, + Environment::ValueModel &Model); } // namespace dataflow } // namespace clang diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 05395e07a7a68c..3cb656adcbdc0c 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -237,13 +237,8 @@ joinLocToVal(const llvm::MapVector &LocToVal, continue; assert(It->second != nullptr); -if (areEquivalentValues(*Val, *It->second)) { - Result.insert({Loc, Val}); - continue; -} - -if (Value *JoinedVal = joinDistinctValues( -Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) { +if (Value *JoinedVal = Environment::joinValues( +Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) { Result.insert({Loc, JoinedVal}); } } @@ -775,27 +770,16 @@ Environment Environment::join(const Environment &EnvA, const Environment &EnvB, JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal; JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc; - if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) { -// `ReturnVal` might not always get set -- for example if we have a return -// statement of the form `return some_other_func()` and we decide not to -// analyze `some_other_func()`. -// In this case, we can't say anything about the joined return value -- we -// don't simply want to propagate the return value that we do have, because -// it might not be the correct one. -// This occurs for example in the test `ContextSensitiveMutualRecursion`. + if (EnvA.CallStack.empty()) { JoinedEnv.ReturnVal = nullptr; - } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) { -JoinedEnv.ReturnVal = EnvA.ReturnVal; } else { -assert(!EnvA.CallStack.empty()); // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this // cast. auto *Func = dyn_cast(EnvA.CallStack.back()); assert(Func != nullptr); -if (Value *JoinedVal = -joinDistinctValues(Func->getReturnType(), *EnvA.ReturnVal, EnvA, -
[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)
martinboehme wrote: This is causing buildbot failures. Reverting. https://github.com/llvm/llvm-project/pull/89213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[clang][dataflow] Model conditional operator correctly." (PR #89577)
https://github.com/martinboehme created https://github.com/llvm/llvm-project/pull/89577 Reverts llvm/llvm-project#89213 This is causing buildbot failures. >From b0456501b10a3a83e6e6818a050f3fd691972d79 Mon Sep 17 00:00:00 2001 From: martinboehme Date: Mon, 22 Apr 2024 09:35:06 +0200 Subject: [PATCH] Revert "[clang][dataflow] Model conditional operator correctly. (#89213)" This reverts commit abb958f1610becc0a753ad8f4308a90f85e1338f. --- .../FlowSensitive/DataflowEnvironment.h | 15 - .../clang/Analysis/FlowSensitive/Transfer.h | 3 +- .../FlowSensitive/DataflowEnvironment.cpp | 46 +++-- clang/lib/Analysis/FlowSensitive/Transfer.cpp | 57 +--- .../TypeErasedDataflowAnalysis.cpp| 4 +- .../Analysis/FlowSensitive/TestingSupport.h | 4 +- .../Analysis/FlowSensitive/TransferTest.cpp | 66 ++- 7 files changed, 46 insertions(+), 149 deletions(-) diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index cdf89c7def2c91..d50dba35f8264c 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -244,21 +244,6 @@ class Environment { Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior); - /// Returns a value that approximates both `Val1` and `Val2`, or null if no - /// such value can be produced. - /// - /// `Env1` and `Env2` can be used to query child values and path condition - /// implications of `Val1` and `Val2` respectively. The joined value will be - /// produced in `JoinedEnv`. - /// - /// Requirements: - /// - /// `Val1` and `Val2` must model values of type `Type`. - static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1, - Value *Val2, const Environment &Env2, - Environment &JoinedEnv, - Environment::ValueModel &Model); - /// Widens the environment point-wise, using `PrevEnv` as needed to inform the /// approximation. /// diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h b/clang/include/clang/Analysis/FlowSensitive/Transfer.h index 940025e02100f9..ed148250d8eb29 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h +++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h @@ -53,8 +53,7 @@ class StmtToEnvMap { /// Requirements: /// /// `S` must not be `ParenExpr` or `ExprWithCleanups`. -void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, - Environment::ValueModel &Model); +void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); } // namespace dataflow } // namespace clang diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 3cb656adcbdc0c..05395e07a7a68c 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -237,8 +237,13 @@ joinLocToVal(const llvm::MapVector &LocToVal, continue; assert(It->second != nullptr); -if (Value *JoinedVal = Environment::joinValues( -Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) { +if (areEquivalentValues(*Val, *It->second)) { + Result.insert({Loc, Val}); + continue; +} + +if (Value *JoinedVal = joinDistinctValues( +Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) { Result.insert({Loc, JoinedVal}); } } @@ -770,16 +775,27 @@ Environment Environment::join(const Environment &EnvA, const Environment &EnvB, JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal; JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc; - if (EnvA.CallStack.empty()) { + if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) { +// `ReturnVal` might not always get set -- for example if we have a return +// statement of the form `return some_other_func()` and we decide not to +// analyze `some_other_func()`. +// In this case, we can't say anything about the joined return value -- we +// don't simply want to propagate the return value that we do have, because +// it might not be the correct one. +// This occurs for example in the test `ContextSensitiveMutualRecursion`. JoinedEnv.ReturnVal = nullptr; + } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) { +JoinedEnv.ReturnVal = EnvA.ReturnVal; } else { +assert(!EnvA.CallStack.empty()); // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this // cast. auto *Func = dyn_cast(EnvA.CallStack.back()); assert(Func != nullptr); -JoinedEnv.ReturnVal = -joinValues(Func->getReturnType(), EnvA.ReturnVal, EnvA, EnvB.ReturnVal, -
[clang] Revert "[clang][dataflow] Model conditional operator correctly." (PR #89577)
https://github.com/martinboehme closed https://github.com/llvm/llvm-project/pull/89577 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 8ff6434 - Revert "[clang][dataflow] Model conditional operator correctly." (#89577)
Author: martinboehme Date: 2024-04-22T09:35:29+02:00 New Revision: 8ff6434546bcb4602bd079f4161f746956905c60 URL: https://github.com/llvm/llvm-project/commit/8ff6434546bcb4602bd079f4161f746956905c60 DIFF: https://github.com/llvm/llvm-project/commit/8ff6434546bcb4602bd079f4161f746956905c60.diff LOG: Revert "[clang][dataflow] Model conditional operator correctly." (#89577) Reverts llvm/llvm-project#89213 This is causing buildbot failures. Added: Modified: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h clang/include/clang/Analysis/FlowSensitive/Transfer.h clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp clang/unittests/Analysis/FlowSensitive/TestingSupport.h clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Removed: diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index cdf89c7def2c91..d50dba35f8264c 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -244,21 +244,6 @@ class Environment { Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior); - /// Returns a value that approximates both `Val1` and `Val2`, or null if no - /// such value can be produced. - /// - /// `Env1` and `Env2` can be used to query child values and path condition - /// implications of `Val1` and `Val2` respectively. The joined value will be - /// produced in `JoinedEnv`. - /// - /// Requirements: - /// - /// `Val1` and `Val2` must model values of type `Type`. - static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1, - Value *Val2, const Environment &Env2, - Environment &JoinedEnv, - Environment::ValueModel &Model); - /// Widens the environment point-wise, using `PrevEnv` as needed to inform the /// approximation. /// diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h b/clang/include/clang/Analysis/FlowSensitive/Transfer.h index 940025e02100f9..ed148250d8eb29 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h +++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h @@ -53,8 +53,7 @@ class StmtToEnvMap { /// Requirements: /// /// `S` must not be `ParenExpr` or `ExprWithCleanups`. -void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, - Environment::ValueModel &Model); +void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); } // namespace dataflow } // namespace clang diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 3cb656adcbdc0c..05395e07a7a68c 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -237,8 +237,13 @@ joinLocToVal(const llvm::MapVector &LocToVal, continue; assert(It->second != nullptr); -if (Value *JoinedVal = Environment::joinValues( -Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) { +if (areEquivalentValues(*Val, *It->second)) { + Result.insert({Loc, Val}); + continue; +} + +if (Value *JoinedVal = joinDistinctValues( +Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) { Result.insert({Loc, JoinedVal}); } } @@ -770,16 +775,27 @@ Environment Environment::join(const Environment &EnvA, const Environment &EnvB, JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal; JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc; - if (EnvA.CallStack.empty()) { + if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) { +// `ReturnVal` might not always get set -- for example if we have a return +// statement of the form `return some_other_func()` and we decide not to +// analyze `some_other_func()`. +// In this case, we can't say anything about the joined return value -- we +// don't simply want to propagate the return value that we do have, because +// it might not be the correct one. +// This occurs for example in the test `ContextSensitiveMutualRecursion`. JoinedEnv.ReturnVal = nullptr; + } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) { +JoinedEnv.ReturnVal = EnvA.ReturnVal; } else { +assert(!EnvA.CallStack.empty()); // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this // cast. auto *Func = dyn_cast(EnvA.CallStack.back()); assert(Func != nullptr); -JoinedEnv.ReturnVal = -joinValu
[clang] Revert "[clang][dataflow] Model conditional operator correctly." (PR #89577)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (martinboehme) Changes Reverts llvm/llvm-project#89213 This is causing buildbot failures. --- Full diff: https://github.com/llvm/llvm-project/pull/89577.diff 7 Files Affected: - (modified) clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h (-15) - (modified) clang/include/clang/Analysis/FlowSensitive/Transfer.h (+1-2) - (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+22-24) - (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+15-42) - (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp (+2-2) - (modified) clang/unittests/Analysis/FlowSensitive/TestingSupport.h (+2-2) - (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+4-62) ``diff diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index cdf89c7def2c91..d50dba35f8264c 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -244,21 +244,6 @@ class Environment { Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior); - /// Returns a value that approximates both `Val1` and `Val2`, or null if no - /// such value can be produced. - /// - /// `Env1` and `Env2` can be used to query child values and path condition - /// implications of `Val1` and `Val2` respectively. The joined value will be - /// produced in `JoinedEnv`. - /// - /// Requirements: - /// - /// `Val1` and `Val2` must model values of type `Type`. - static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1, - Value *Val2, const Environment &Env2, - Environment &JoinedEnv, - Environment::ValueModel &Model); - /// Widens the environment point-wise, using `PrevEnv` as needed to inform the /// approximation. /// diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h b/clang/include/clang/Analysis/FlowSensitive/Transfer.h index 940025e02100f9..ed148250d8eb29 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h +++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h @@ -53,8 +53,7 @@ class StmtToEnvMap { /// Requirements: /// /// `S` must not be `ParenExpr` or `ExprWithCleanups`. -void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, - Environment::ValueModel &Model); +void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); } // namespace dataflow } // namespace clang diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 3cb656adcbdc0c..05395e07a7a68c 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -237,8 +237,13 @@ joinLocToVal(const llvm::MapVector &LocToVal, continue; assert(It->second != nullptr); -if (Value *JoinedVal = Environment::joinValues( -Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) { +if (areEquivalentValues(*Val, *It->second)) { + Result.insert({Loc, Val}); + continue; +} + +if (Value *JoinedVal = joinDistinctValues( +Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) { Result.insert({Loc, JoinedVal}); } } @@ -770,16 +775,27 @@ Environment Environment::join(const Environment &EnvA, const Environment &EnvB, JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal; JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc; - if (EnvA.CallStack.empty()) { + if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) { +// `ReturnVal` might not always get set -- for example if we have a return +// statement of the form `return some_other_func()` and we decide not to +// analyze `some_other_func()`. +// In this case, we can't say anything about the joined return value -- we +// don't simply want to propagate the return value that we do have, because +// it might not be the correct one. +// This occurs for example in the test `ContextSensitiveMutualRecursion`. JoinedEnv.ReturnVal = nullptr; + } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) { +JoinedEnv.ReturnVal = EnvA.ReturnVal; } else { +assert(!EnvA.CallStack.empty()); // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this // cast. auto *Func = dyn_cast(EnvA.CallStack.back()); assert(Func != nullptr); -JoinedEnv.ReturnVal = -joinValues(Func->getReturnType(), EnvA.ReturnVal, EnvA, EnvB.ReturnVal, - EnvB, JoinedEnv, Model); +if (Value *JoinedVal = +joinDistinctValues(Func->getReturnType()
[clang] [clang] CTAD: Fix require-clause is not transformed. (PR #89378)
hokein wrote: > This seems to have broken the bot: #89476 (you should have had an email?) > > I reverted in #89476 sorry, and thanks for the revert. I will take a further look. https://github.com/llvm/llvm-project/pull/89378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Default -g to full debug info. (PR #89418)
https://github.com/jeanPerier approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/89418 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
ealcdan wrote: ping :) https://github.com/llvm/llvm-project/pull/85060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)
arsenm wrote: For AMDGPU 64 is probably right https://github.com/llvm/llvm-project/pull/89446 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] eef5798 - [clang][Interp] Create full type info for dummy pointers
Author: Timm Bäder Date: 2024-04-22T10:04:09+02:00 New Revision: eef5798844a6ed489c28b37113f3bcaafd1d6e68 URL: https://github.com/llvm/llvm-project/commit/eef5798844a6ed489c28b37113f3bcaafd1d6e68 DIFF: https://github.com/llvm/llvm-project/commit/eef5798844a6ed489c28b37113f3bcaafd1d6e68.diff LOG: [clang][Interp] Create full type info for dummy pointers Added: Modified: clang/lib/AST/Interp/Descriptor.cpp clang/lib/AST/Interp/Descriptor.h clang/lib/AST/Interp/Interp.h clang/lib/AST/Interp/Pointer.cpp clang/lib/AST/Interp/Program.cpp clang/test/AST/Interp/builtin-align-cxx.cpp clang/test/AST/Interp/c.c Removed: diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index a4ccc0236d292c..670fccdd6a 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -309,14 +309,6 @@ Descriptor::Descriptor(const DeclTy &D) assert(Source && "Missing source"); } -/// Dummy array. -Descriptor::Descriptor(const DeclTy &D, UnknownSize) -: Source(D), ElemSize(1), Size(UnknownSizeMark), MDSize(0), - AllocSize(MDSize), ElemRecord(nullptr), IsConst(true), IsMutable(false), - IsTemporary(false), IsArray(true), IsDummy(true) { - assert(Source && "Missing source"); -} - QualType Descriptor::getType() const { if (auto *E = asExpr()) return E->getType(); diff --git a/clang/lib/AST/Interp/Descriptor.h b/clang/lib/AST/Interp/Descriptor.h index c386fc8ac7b09d..f8a574c9b3a023 100644 --- a/clang/lib/AST/Interp/Descriptor.h +++ b/clang/lib/AST/Interp/Descriptor.h @@ -125,7 +125,7 @@ struct Descriptor final { /// Flag indicating if the block is an array. const bool IsArray = false; /// Flag indicating if this is a dummy descriptor. - const bool IsDummy = false; + bool IsDummy = false; /// Storage management methods. const BlockCtorFn CtorFn = nullptr; @@ -159,8 +159,8 @@ struct Descriptor final { /// Allocates a dummy descriptor. Descriptor(const DeclTy &D); - /// Allocates a dummy array descriptor. - Descriptor(const DeclTy &D, UnknownSize); + /// Make this descriptor a dummy descriptor. + void makeDummy() { IsDummy = true; } QualType getType() const; QualType getElemQualType() const; diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index cebedf59e0593f..813bd02030cbfa 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -823,9 +823,9 @@ inline bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn) { // element in the same array are NOT equal. They have the same Base value, // but a diff erent Offset. This is a pretty rare case, so we fix this here // by comparing pointers to the first elements. -if (!LHS.isZero() && !LHS.isDummy() && LHS.isArrayRoot()) +if (!LHS.isZero() && LHS.isArrayRoot()) VL = LHS.atIndex(0).getByteOffset(); -if (!RHS.isZero() && !RHS.isDummy() && RHS.isArrayRoot()) +if (!RHS.isZero() && RHS.isArrayRoot()) VR = RHS.atIndex(0).getByteOffset(); S.Stk.push(BoolT::from(Fn(Compare(VL, VR; @@ -1241,14 +1241,16 @@ inline bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) { !CheckNull(S, OpPC, Ptr, CSK_Field)) return false; - if (CheckDummy(S, OpPC, Ptr)) { -if (!CheckExtern(S, OpPC, Ptr)) - return false; -if (!CheckRange(S, OpPC, Ptr, CSK_Field)) - return false; -if (!CheckSubobject(S, OpPC, Ptr, CSK_Field)) - return false; - } + if (!CheckExtern(S, OpPC, Ptr)) +return false; + if (!CheckRange(S, OpPC, Ptr, CSK_Field)) +return false; + if (!CheckSubobject(S, OpPC, Ptr, CSK_Field)) +return false; + + if (Ptr.isBlockPointer() && Off > Ptr.block()->getSize()) +return false; + S.Stk.push(Ptr.atField(Off)); return true; } @@ -1992,11 +1994,6 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) { if (!Ptr.isZero()) { if (!CheckArray(S, OpPC, Ptr)) return false; - -if (Ptr.isDummy()) { - S.Stk.push(Ptr); - return true; -} } if (!OffsetHelper(S, OpPC, Offset, Ptr)) @@ -2013,11 +2010,6 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) { if (!Ptr.isZero()) { if (!CheckArray(S, OpPC, Ptr)) return false; - -if (Ptr.isDummy()) { - S.Stk.push(Ptr); - return true; -} } if (!OffsetHelper(S, OpPC, Offset, Ptr)) @@ -2053,12 +2045,12 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index) { inline bool ArrayDecay(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.pop(); - if (Ptr.isZero() || Ptr.isDummy()) { + if (Ptr.isZero()) { S.Stk.push(Ptr); return true; } - if (!Ptr.isUnknownSizeArray()) { + if (!Ptr.isUnknownSizeArray() || Ptr.isDummy()) { S.Stk.push(Ptr.atIndex(0)); return true; } diff --git a/clang/lib
[clang] 57c24eb - Reland "[clang] CTAD: Fix require-clause is not transformed." (#89476)
Author: Haojian Wu Date: 2024-04-22T10:04:55+02:00 New Revision: 57c24eb0a7482ca7f661a2a9cb45249f1553d6d2 URL: https://github.com/llvm/llvm-project/commit/57c24eb0a7482ca7f661a2a9cb45249f1553d6d2 DIFF: https://github.com/llvm/llvm-project/commit/57c24eb0a7482ca7f661a2a9cb45249f1553d6d2.diff LOG: Reland "[clang] CTAD: Fix require-clause is not transformed." (#89476) This relands the c8e65e193d542464421ad4f9a9965d45b302ac0c, which was reverted in b48ea2d394911efcc56880fde58f806282db1e8a due to the breakage of windows builtbot. The reland contains some adjustments in the lit test deduction-gudie.cpp, to make the checking text less strict. Added: Modified: clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateInstantiate.cpp clang/test/SemaCXX/cxx20-ctad-type-alias.cpp clang/test/SemaTemplate/deduction-guide.cpp Removed: diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index d4976f9d0d11d8..4bda31ba67c02d 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2962,19 +2962,6 @@ void DeclareImplicitDeductionGuidesForTypeAlias( Context.getCanonicalTemplateArgument( Context.getInjectedTemplateArg(NewParam)); } -// Substitute new template parameters into requires-clause if present. -Expr *RequiresClause = -transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime); -// FIXME: implement the is_deducible constraint per C++ -// [over.match.class.deduct]p3.3: -//... and a constraint that is satisfied if and only if the arguments -//of A are deducible (see below) from the return type. -auto *FPrimeTemplateParamList = TemplateParameterList::Create( -Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(), -AliasTemplate->getTemplateParameters()->getLAngleLoc(), -FPrimeTemplateParams, -AliasTemplate->getTemplateParameters()->getRAngleLoc(), -/*RequiresClause=*/RequiresClause); // To form a deduction guide f' from f, we leverage clang's instantiation // mechanism, we construct a template argument list where the template @@ -3020,6 +3007,20 @@ void DeclareImplicitDeductionGuidesForTypeAlias( F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(), Sema::CodeSynthesisContext::BuildingDeductionGuides)) { auto *GG = cast(FPrime); + // Substitute new template parameters into requires-clause if present. + Expr *RequiresClause = + transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime); + // FIXME: implement the is_deducible constraint per C++ + // [over.match.class.deduct]p3.3: + //... and a constraint that is satisfied if and only if the arguments + //of A are deducible (see below) from the return type. + auto *FPrimeTemplateParamList = TemplateParameterList::Create( + Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(), + AliasTemplate->getTemplateParameters()->getLAngleLoc(), + FPrimeTemplateParams, + AliasTemplate->getTemplateParameters()->getRAngleLoc(), + /*RequiresClause=*/RequiresClause); + buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList, GG->getCorrespondingConstructor(), GG->getExplicitSpecifier(), GG->getTypeSourceInfo(), diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 3e6676f21c9be0..98d5c7cb3a8a80 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2502,10 +2502,7 @@ TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, assert(Arg.getKind() == TemplateArgument::Type && "unexpected nontype template argument kind in template rewrite"); QualType NewT = Arg.getAsType(); - assert(isa(NewT) && - "type parm not rewritten to type parm"); - auto NewTL = TLB.push(NewT); - NewTL.setNameLoc(TL.getNameLoc()); + TLB.pushTrivial(SemaRef.Context, NewT, TL.getNameLoc()); return NewT; } diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp index 6f04264a655ad5..508a3a5da76a91 100644 --- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp +++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp @@ -289,3 +289,21 @@ using String = Array; // Verify no crash on constructing the aggregate deduction guides. String s("hello"); } // namespace test21 + +// GH89013 +namespace test22 { +class Base {}; +template +class Derived final : public Base {}; + +template +requires __is_base_of(Base, D) +struct Foo { + explicit Foo(D) {} +}; + +template +using AFoo = Foo>; + +AFoo a(Derived{}); +} // namespace test22 diff --gi
[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)
https://github.com/weliveindetail updated https://github.com/llvm/llvm-project/pull/84758 From 7ee5d29f69daf626a4fdc2fced802fe7e881f31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= Date: Sun, 10 Mar 2024 18:17:48 +0100 Subject: [PATCH 1/2] [clang-repl] Set up executor implicitly to account for init PTUs --- clang/lib/Interpreter/Interpreter.cpp | 32 +++ clang/test/Interpreter/execute.cpp| 4 ++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index b20e6efcebfd10..7bd44f8e046c02 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -229,12 +229,30 @@ IncrementalCompilerBuilder::CreateCudaHost() { } Interpreter::Interpreter(std::unique_ptr CI, - llvm::Error &Err) { - llvm::ErrorAsOutParameter EAO(&Err); + llvm::Error &ErrOut) { + llvm::ErrorAsOutParameter EAO(&ErrOut); auto LLVMCtx = std::make_unique(); TSCtx = std::make_unique(std::move(LLVMCtx)); - IncrParser = std::make_unique(*this, std::move(CI), - *TSCtx->getContext(), Err); + IncrParser = std::make_unique( + *this, std::move(CI), *TSCtx->getContext(), ErrOut); + if (ErrOut) +return; + + // Not all frontends support code-generation, e.g. ast-dump actions don't + if (IncrParser->getCodeGen()) { +if (llvm::Error Err = CreateExecutor()) { + ErrOut = joinErrors(std::move(ErrOut), std::move(Err)); + return; +} + +// Process the PTUs that came from initialization. For example -include will +// give us a header that's processed at initialization of the preprocessor. +for (PartialTranslationUnit &PTU : IncrParser->getPTUs()) + if (llvm::Error Err = Execute(PTU)) { +ErrOut = joinErrors(std::move(ErrOut), std::move(Err)); +return; + } + } } Interpreter::~Interpreter() { @@ -395,10 +413,16 @@ llvm::Error Interpreter::CreateExecutor() { return llvm::make_error("Operation failed. " "Execution engine exists", std::error_code()); + if (!IncrParser->getCodeGen()) +return llvm::make_error("Operation failed. " + "No code generator available", + std::error_code()); + llvm::Expected> JB = CreateJITBuilder(*getCompilerInstance()); if (!JB) return JB.takeError(); + llvm::Error Err = llvm::Error::success(); auto Executor = std::make_unique(*TSCtx, **JB, Err); if (!Err) diff --git a/clang/test/Interpreter/execute.cpp b/clang/test/Interpreter/execute.cpp index 6e73ed3927e815..534a54ed94fba2 100644 --- a/clang/test/Interpreter/execute.cpp +++ b/clang/test/Interpreter/execute.cpp @@ -7,6 +7,8 @@ // RUN: cat %s | clang-repl | FileCheck %s // RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s +// RUN: clang-repl -Xcc -include -Xcc %s | FileCheck %s +// RUN: clang-repl -Xcc -fsyntax-only -Xcc -include -Xcc %s extern "C" int printf(const char *, ...); int i = 42; auto r1 = printf("i = %d\n", i); @@ -19,5 +21,3 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast Date: Mon, 11 Mar 2024 14:10:58 +0100 Subject: [PATCH 2/2] [tmp] Add crash note --- clang/test/Interpreter/inline-virtual.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Interpreter/inline-virtual.cpp b/clang/test/Interpreter/inline-virtual.cpp index 79ab8ed337ffea..d862b3354f61fe 100644 --- a/clang/test/Interpreter/inline-virtual.cpp +++ b/clang/test/Interpreter/inline-virtual.cpp @@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); }; // PartialTranslationUnit. inline A::~A() { printf("~A(%d)\n", a); } -// Create one instance with new and delete it. +// Create one instance with new and delete it. We crash here now: A *a1 = new A(1); delete a1; // CHECK: ~A(1) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)
https://github.com/balazske updated https://github.com/llvm/llvm-project/pull/89247 From 7138f026e845ebb4f1a3e6a86bdeb534d666ae7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= Date: Thu, 18 Apr 2024 16:40:03 +0200 Subject: [PATCH 1/4] [clang][analyzer] Move StreamChecker out of the alpha package. --- clang/docs/analyzer/checkers.rst | 186 +- .../clang/StaticAnalyzer/Checkers/Checkers.td | 31 +-- clang/test/Analysis/analyzer-config.c | 2 +- .../test/Analysis/analyzer-enabled-checkers.c | 1 + ...c-library-functions-arg-enabled-checkers.c | 6 +- .../std-c-library-functions-arg-weakdeps.c| 4 +- ...td-c-library-functions-vs-stream-checker.c | 8 +- clang/test/Analysis/stream-errno-note.c | 4 +- clang/test/Analysis/stream-errno.c| 4 +- clang/test/Analysis/stream-error.c| 4 +- clang/test/Analysis/stream-invalidate.c | 2 +- .../test/Analysis/stream-non-posix-function.c | 2 +- clang/test/Analysis/stream-noopen.c | 2 +- clang/test/Analysis/stream-note.c | 8 +- clang/test/Analysis/stream-pedantic.c | 8 +- .../Analysis/stream-stdlibraryfunctionargs.c | 10 +- clang/test/Analysis/stream.c | 16 +- clang/test/Analysis/stream.cpp| 2 +- clang/www/analyzer/alpha_checks.html | 4 +- clang/www/analyzer/open_projects.html | 2 +- 20 files changed, 154 insertions(+), 152 deletions(-) diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst index fb748d23a53d01..32c2a312962754 100644 --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -1462,6 +1462,99 @@ checker). Default value of the option is ``true``. +.. _unix-Stream: + +unix.Stream (C) +" +Check C stream handling functions: +``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``. + +The checker maintains information about the C stream objects (``FILE *``) and +can detect error conditions related to use of streams. The following conditions +are detected: + +* The ``FILE *`` pointer passed to the function is NULL (the single exception is + ``fflush`` where NULL is allowed). +* Use of stream after close. +* Opened stream is not closed. +* Read from a stream after end-of-file. (This is not a fatal error but reported + by the checker. Stream remains in EOF state and the read operation fails.) +* Use of stream when the file position is indeterminate after a previous failed + operation. Some functions (like ``ferror``, ``clearerr``, ``fseek``) are + allowed in this state. +* Invalid 3rd ("``whence``") argument to ``fseek``. + +The stream operations are by this checker usually split into two cases, a success +and a failure case. However, in the case of write operations (like ``fwrite``, +``fprintf`` and even ``fsetpos``) this behavior could produce a large amount of +unwanted reports on projects that don't have error checks around the write +operations, so by default the checker assumes that write operations always succeed. +This behavior can be controlled by the ``Pedantic`` flag: With +``-analyzer-config unix.Stream:Pedantic=true`` the checker will model the +cases where a write operation fails and report situations where this leads to +erroneous behavior. (The default is ``Pedantic=false``, where write operations +are assumed to succeed.) + +.. code-block:: c + + void test1() { + FILE *p = fopen("foo", "r"); + } // warn: opened file is never closed + + void test2() { + FILE *p = fopen("foo", "r"); + fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL + fclose(p); + } + + void test3() { + FILE *p = fopen("foo", "r"); + if (p) { + fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR + fclose(p); + } + } + + void test4() { + FILE *p = fopen("foo", "r"); + if (!p) + return; + + fclose(p); + fclose(p); // warn: stream already closed + } + + void test5() { + FILE *p = fopen("foo", "r"); + if (!p) + return; + + fgetc(p); + if (!ferror(p)) + fgetc(p); // warn: possible read after end-of-file + + fclose(p); + } + + void test6() { + FILE *p = fopen("foo", "r"); + if (!p) + return; + + fgetc(p); + if (!feof(p)) + fgetc(p); // warn: file position may be indeterminate after I/O error + + fclose(p); + } + +**Limitations** + +The checker does not track the correspondence between integer file descriptors +and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not +treated specially and are therefore often not recognized (because these streams +are usually not opened explicitly by the program, and are global variables). + .. _osx-checkers: osx @@ -3116,99 +3209,6 @@ Check for misuse
[clang] Revert "[clang][dataflow] Model conditional operator correctly." (PR #89577)
martinboehme wrote: Postmortem reveals that I inadvertently had my build configured with `-DCMAKE_BUILD_TYPE=Release`. https://github.com/llvm/llvm-project/pull/89577 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang] Compute the right spelling location (PR #72400)
https://github.com/sebastianpoeplau updated https://github.com/llvm/llvm-project/pull/72400 >From cc15f9bb8b37fb1b68bd33241ab37e98d57d274c Mon Sep 17 00:00:00 2001 From: Matthieu Eyraud Date: Mon, 11 Apr 2022 16:53:24 +0200 Subject: [PATCH] [libclang] Compute the right spelling location Locations inside macro expansions have different spelling/expansion locations. Apply a FIXME to make the libclang function clang_getSpellingLocation return the right spelling location, and adapt the testsuite driver code to use the file location rather than the spelling location to compute source ranges. --- clang/docs/ReleaseNotes.rst | 3 ++ clang/tools/c-index-test/c-index-test.c | 54 +++ clang/tools/libclang/CXSourceLocation.cpp | 3 +- clang/unittests/libclang/LibclangTest.cpp | 31 + 4 files changed, 61 insertions(+), 30 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3fe15934323c53..6fdc285da6ecd3 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -678,6 +678,9 @@ clang-format libclang +- ``clang_getSpellingLocation`` now correctly resolves macro expansions; that + is, it returns the spelling location instead of the expansion location. + Static Analyzer --- diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 21619888cfa5f3..e078e9bdce027a 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -464,10 +464,10 @@ static void PrintRange(CXSourceRange R, const char *str) { CXFile begin_file, end_file; unsigned begin_line, begin_column, end_line, end_column; - clang_getSpellingLocation(clang_getRangeStart(R), -&begin_file, &begin_line, &begin_column, 0); - clang_getSpellingLocation(clang_getRangeEnd(R), -&end_file, &end_line, &end_column, 0); + clang_getFileLocation(clang_getRangeStart(R), &begin_file, &begin_line, +&begin_column, 0); + clang_getFileLocation(clang_getRangeEnd(R), &end_file, &end_line, &end_column, +0); if (!begin_file || !end_file) return; @@ -849,13 +849,13 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { printf(", "); Loc = clang_getCursorLocation(Ovl); - clang_getSpellingLocation(Loc, 0, &line, &column, 0); + clang_getFileLocation(Loc, 0, &line, &column, 0); printf("%d:%d", line, column); } printf("]"); } else { CXSourceLocation Loc = clang_getCursorLocation(Referenced); -clang_getSpellingLocation(Loc, 0, &line, &column, 0); +clang_getFileLocation(Loc, 0, &line, &column, 0); printf(":%d:%d", line, column); } @@ -1047,7 +1047,7 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { if (!clang_equalCursors(SpecializationOf, clang_getNullCursor())) { CXSourceLocation Loc = clang_getCursorLocation(SpecializationOf); CXString Name = clang_getCursorSpelling(SpecializationOf); - clang_getSpellingLocation(Loc, 0, &line, &column, 0); + clang_getFileLocation(Loc, 0, &line, &column, 0); printf(" [Specialization of %s:%d:%d]", clang_getCString(Name), line, column); clang_disposeString(Name); @@ -1094,7 +1094,7 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { printf(" [Overrides "); for (I = 0; I != num_overridden; ++I) { CXSourceLocation Loc = clang_getCursorLocation(overridden[I]); -clang_getSpellingLocation(Loc, 0, &line, &column, 0); +clang_getFileLocation(Loc, 0, &line, &column, 0); lineCols[I].line = line; lineCols[I].col = column; } @@ -1257,8 +1257,8 @@ void PrintDiagnostic(CXDiagnostic Diagnostic) { fprintf(stderr, "%s\n", clang_getCString(Msg)); clang_disposeString(Msg); - clang_getSpellingLocation(clang_getDiagnosticLocation(Diagnostic), -&file, 0, 0, 0); + clang_getFileLocation(clang_getDiagnosticLocation(Diagnostic), &file, 0, 0, +0); if (!file) return; @@ -1271,9 +1271,8 @@ void PrintDiagnostic(CXDiagnostic Diagnostic) { CXSourceLocation end = clang_getRangeEnd(range); unsigned start_line, start_column, end_line, end_column; CXFile start_file, end_file; -clang_getSpellingLocation(start, &start_file, &start_line, - &start_column, 0); -clang_getSpellingLocation(end, &end_file, &end_line, &end_column, 0); +clang_getFileLocation(start, &start_file, &start_line, &start_column, 0); +clang_getFileLocation(end, &end_file, &end_line, &end_column, 0); if (clang_equalLocations(start, end)) { /* Insertion. */ if (start_file == file) @@ -1356,7 +1355,7 @
[clang] [libclang] Compute the right spelling location (PR #72400)
@@ -1292,6 +1292,31 @@ void func() {} EXPECT_EQ(attrCount, 1); } +TEST_F(LibclangParseTest, clang_getSpellingLocation) { + std::string fileName = "main.c"; + WriteFile(fileName, "#define X(value) int x = value;\nX(42)\n"); + + ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), nullptr, 0, + nullptr, 0, TUFlags); + + Traverse([](CXCursor cursor, CXCursor parent) -> CXChildVisitResult { +if (cursor.kind == CXCursor_VarDecl) { + CXSourceLocation cxl = clang_getCursorLocation(cursor); + unsigned line; + + // We expect clang_getFileLocation to return the expansion location, + // whereas clang_getSpellingLocation should resolve the macro expansion + // and return the location of the macro definition. + clang_getFileLocation(cxl, nullptr, &line, nullptr, nullptr); + EXPECT_EQ(line, 2U); + clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr); + EXPECT_EQ(line, 1U); +} + +return CXChildVisit_Recurse; + }); +} sebastianpoeplau wrote: Good point, I've updated the test. https://github.com/llvm/llvm-project/pull/72400 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)
Khao7342 wrote: > Has KunMingHu's RTL been finalized (IIRC, we have vector unit under > development)? And can we have different doc for different generations of > XiangShan? Thanks for your attention to Xiangshan. KunMingHu's RTL has not been finalized yet. The development work on vectors is in the final stages of testing and performance optimization. And there won't be too many changes on the RTL. https://github.com/llvm/llvm-project/pull/89359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)
Khao7342 wrote: > Has the target architecture been finalized? (As in what it should be, not > necessarily the rtl) > > Just yesterday, there was a significant change in vector execution units: > > [before](https://github.com/OpenXiangShan/XiangShan/blob/e25e4d90505c592524b410b127fe611ac49a3adf/src/main/scala/xiangshan/Parameters.scala#L355): > > ``` > VFEX0: VfaluCfg, VfmaCfg, VialuCfg, VimacCfg > VFEX1: VipuCfg, VppuCfg, VfcvtCfg, F2vCfg, F2fCfg, F2iCfg, VSetRvfWvfCfg > VFEX2: VfaluCfg, VfmaCfg, VialuCfg > VFEX3: VfdivCfg, VidivCfg > ``` > > [after](https://github.com/OpenXiangShan/XiangShan/blob/2e61107/src/main/scala/xiangshan/Parameters.scala#L357): > > ``` > VFEX0: VfmaCfg, VialuCfg, VimacCfg, VppuCfg > VFEX1: VfaluCfg, VfcvtCfg, VipuCfg, VSetRvfWvfCfg > VFEX2: VfmaCfg, VialuCfg, F2vCfg > VFEX3: VfaluCfg, VfcvtCfg > VFEX4: VfdivCfg, VidivCfg > VFEX5: VfdivCfg, VidivCfg > ``` Thanks for your attention to Xiangshan. KunMingHu's RTL has not been finalized yet. The development work on vectors is in the final stages of testing and performance optimization. And there won't be too many changes on the RTL. https://github.com/llvm/llvm-project/pull/89359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6195e22 - Revert "[clang][Interp] Create full type info for dummy pointers"
Author: Timm Bäder Date: 2024-04-22T10:32:31+02:00 New Revision: 6195e228eb2a7085fac53603f534d2401ab1ac39 URL: https://github.com/llvm/llvm-project/commit/6195e228eb2a7085fac53603f534d2401ab1ac39 DIFF: https://github.com/llvm/llvm-project/commit/6195e228eb2a7085fac53603f534d2401ab1ac39.diff LOG: Revert "[clang][Interp] Create full type info for dummy pointers" This reverts commit eef5798844a6ed489c28b37113f3bcaafd1d6e68. This breaks two tests on an arm builder: https://lab.llvm.org/buildbot/#/builders/245/builds/23496 Added: Modified: clang/lib/AST/Interp/Descriptor.cpp clang/lib/AST/Interp/Descriptor.h clang/lib/AST/Interp/Interp.h clang/lib/AST/Interp/Pointer.cpp clang/lib/AST/Interp/Program.cpp clang/test/AST/Interp/builtin-align-cxx.cpp clang/test/AST/Interp/c.c Removed: diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index 670fccdd6a..a4ccc0236d292c 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -309,6 +309,14 @@ Descriptor::Descriptor(const DeclTy &D) assert(Source && "Missing source"); } +/// Dummy array. +Descriptor::Descriptor(const DeclTy &D, UnknownSize) +: Source(D), ElemSize(1), Size(UnknownSizeMark), MDSize(0), + AllocSize(MDSize), ElemRecord(nullptr), IsConst(true), IsMutable(false), + IsTemporary(false), IsArray(true), IsDummy(true) { + assert(Source && "Missing source"); +} + QualType Descriptor::getType() const { if (auto *E = asExpr()) return E->getType(); diff --git a/clang/lib/AST/Interp/Descriptor.h b/clang/lib/AST/Interp/Descriptor.h index f8a574c9b3a023..c386fc8ac7b09d 100644 --- a/clang/lib/AST/Interp/Descriptor.h +++ b/clang/lib/AST/Interp/Descriptor.h @@ -125,7 +125,7 @@ struct Descriptor final { /// Flag indicating if the block is an array. const bool IsArray = false; /// Flag indicating if this is a dummy descriptor. - bool IsDummy = false; + const bool IsDummy = false; /// Storage management methods. const BlockCtorFn CtorFn = nullptr; @@ -159,8 +159,8 @@ struct Descriptor final { /// Allocates a dummy descriptor. Descriptor(const DeclTy &D); - /// Make this descriptor a dummy descriptor. - void makeDummy() { IsDummy = true; } + /// Allocates a dummy array descriptor. + Descriptor(const DeclTy &D, UnknownSize); QualType getType() const; QualType getElemQualType() const; diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 813bd02030cbfa..cebedf59e0593f 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -823,9 +823,9 @@ inline bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn) { // element in the same array are NOT equal. They have the same Base value, // but a diff erent Offset. This is a pretty rare case, so we fix this here // by comparing pointers to the first elements. -if (!LHS.isZero() && LHS.isArrayRoot()) +if (!LHS.isZero() && !LHS.isDummy() && LHS.isArrayRoot()) VL = LHS.atIndex(0).getByteOffset(); -if (!RHS.isZero() && RHS.isArrayRoot()) +if (!RHS.isZero() && !RHS.isDummy() && RHS.isArrayRoot()) VR = RHS.atIndex(0).getByteOffset(); S.Stk.push(BoolT::from(Fn(Compare(VL, VR; @@ -1241,16 +1241,14 @@ inline bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) { !CheckNull(S, OpPC, Ptr, CSK_Field)) return false; - if (!CheckExtern(S, OpPC, Ptr)) -return false; - if (!CheckRange(S, OpPC, Ptr, CSK_Field)) -return false; - if (!CheckSubobject(S, OpPC, Ptr, CSK_Field)) -return false; - - if (Ptr.isBlockPointer() && Off > Ptr.block()->getSize()) -return false; - + if (CheckDummy(S, OpPC, Ptr)) { +if (!CheckExtern(S, OpPC, Ptr)) + return false; +if (!CheckRange(S, OpPC, Ptr, CSK_Field)) + return false; +if (!CheckSubobject(S, OpPC, Ptr, CSK_Field)) + return false; + } S.Stk.push(Ptr.atField(Off)); return true; } @@ -1994,6 +1992,11 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) { if (!Ptr.isZero()) { if (!CheckArray(S, OpPC, Ptr)) return false; + +if (Ptr.isDummy()) { + S.Stk.push(Ptr); + return true; +} } if (!OffsetHelper(S, OpPC, Offset, Ptr)) @@ -2010,6 +2013,11 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) { if (!Ptr.isZero()) { if (!CheckArray(S, OpPC, Ptr)) return false; + +if (Ptr.isDummy()) { + S.Stk.push(Ptr); + return true; +} } if (!OffsetHelper(S, OpPC, Offset, Ptr)) @@ -2045,12 +2053,12 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index) { inline bool ArrayDecay(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.pop(); - if (Ptr.isZero()) { + if (Ptr.isZero() || Ptr.isDummy()) { S.Stk.push(Ptr); return true; }
[clang] 0ff992e - [clang][Interp][NFC] Get ComplexType directly
Author: Timm Bäder Date: 2024-04-22T10:34:43+02:00 New Revision: 0ff992e5f210fdcbfdd1dcc3687c9aeabde318c3 URL: https://github.com/llvm/llvm-project/commit/0ff992e5f210fdcbfdd1dcc3687c9aeabde318c3 DIFF: https://github.com/llvm/llvm-project/commit/0ff992e5f210fdcbfdd1dcc3687c9aeabde318c3.diff LOG: [clang][Interp][NFC] Get ComplexType directly Instead of doing a isa<> + getAs<> Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index f317f506d24f4b..486ad9db625ddb 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -922,9 +922,9 @@ bool ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueIni return true; } - if (QT->isAnyComplexType()) { + if (const auto *ComplexTy = E->getType()->getAs()) { assert(Initializing); -QualType ElemQT = QT->getAs()->getElementType(); +QualType ElemQT = ComplexTy->getElementType(); PrimType ElemT = classifyPrim(ElemQT); for (unsigned I = 0; I < 2; ++I) { if (!this->visitZeroInitializer(ElemT, ElemQT, E)) @@ -1098,13 +1098,13 @@ bool ByteCodeExprGen::VisitInitListExpr(const InitListExpr *E) { return true; } - if (T->isAnyComplexType()) { + if (const auto *ComplexTy = E->getType()->getAs()) { unsigned NumInits = E->getNumInits(); if (NumInits == 1) return this->delegate(E->inits()[0]); -QualType ElemQT = E->getType()->getAs()->getElementType(); +QualType ElemQT = ComplexTy->getElementType(); PrimType ElemT = classifyPrim(ElemQT); if (NumInits == 0) { // Zero-initialize both elements. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)
@@ -378,3 +378,30 @@ def XIANGSHAN_NANHU : RISCVProcessorModel<"xiangshan-nanhu", TuneZExtHFusion, TuneZExtWFusion, TuneShiftedZExtWFusion]>; +def XIANGSHAN_KUNMINGHU : RISCVProcessorModel<"xiangshan-kunminghu", + NoSchedModel, + [Feature64Bit, + FeatureStdExtI, + FeatureStdExtZicsr, + FeatureStdExtZifencei, + FeatureStdExtM, + FeatureStdExtA, + FeatureStdExtF, + FeatureStdExtD, + FeatureStdExtC, + FeatureStdExtZba, + FeatureStdExtZbb, + FeatureStdExtZbc, + FeatureStdExtZbs, + FeatureStdExtZkn, + FeatureStdExtZksed, + FeatureStdExtZksh, + FeatureStdExtSvinval, + FeatureStdExtZicbom, + FeatureStdExtZicboz, + FeatureStdExtV, + FeatureStdExtZvl128b], + [TuneNoDefaultUnroll, dtcxzyw wrote: Can you provide some performance data about these options? IIRC KunMingHu core supports the `lui + addi` fusion. https://github.com/llvm/llvm-project/pull/89359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6b6c7e4 - [clang][Interp][NFC] Test out-of-bounds access on vectors
Author: Timm Bäder Date: 2024-04-22T10:35:45+02:00 New Revision: 6b6c7e46cc1e97b678e969bad78825dd02c11ff9 URL: https://github.com/llvm/llvm-project/commit/6b6c7e46cc1e97b678e969bad78825dd02c11ff9 DIFF: https://github.com/llvm/llvm-project/commit/6b6c7e46cc1e97b678e969bad78825dd02c11ff9.diff LOG: [clang][Interp][NFC] Test out-of-bounds access on vectors Added: Modified: clang/test/AST/Interp/vectors.cpp Removed: diff --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp index 5c4694f122d812..cb8bcd4fdda768 100644 --- a/clang/test/AST/Interp/vectors.cpp +++ b/clang/test/AST/Interp/vectors.cpp @@ -8,6 +8,13 @@ static_assert(A[1] == 2, ""); // ref-error {{not an integral constant expression static_assert(A[2] == 3, ""); // ref-error {{not an integral constant expression}} static_assert(A[3] == 4, ""); // ref-error {{not an integral constant expression}} + +/// FIXME: It would be nice if the note said 'vector' instead of 'array'. +static_assert(A[12] == 4, ""); // ref-error {{not an integral constant expression}} \ + // expected-error {{not an integral constant expression}} \ + // expected-note {{cannot refer to element 12 of array of 4 elements in a constant expression}} + + /// VectorSplat casts typedef __attribute__(( ext_vector_type(4) )) float float4; constexpr float4 vec4_0 = (float4)0.5f; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Don't wrap immediate invocations in ConstantExprs within constexpr initializers (PR #89565)
cor3ntin wrote: I think the change makes sense. Can you add a release note? https://github.com/llvm/llvm-project/pull/89565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)
vvd170501 wrote: Ping. @PiotrZSL, I've added the changes you requested (except `matchesAnyListedName`), waiting for your feedback https://github.com/llvm/llvm-project/pull/88636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] e614e03 - [libclc] Fix build with Unix Makefiles (#89147)
Author: Fraser Cormack Date: 2024-04-22T09:50:39+01:00 New Revision: e614e037f371e92499e19ada730f61e77d640780 URL: https://github.com/llvm/llvm-project/commit/e614e037f371e92499e19ada730f61e77d640780 DIFF: https://github.com/llvm/llvm-project/commit/e614e037f371e92499e19ada730f61e77d640780.diff LOG: [libclc] Fix build with Unix Makefiles (#89147) Commit #87622 broke the build. Ninja was happy with creating the output directories as necessary, but Unix Makefiles isn't. Ensure they are always created. Fixes #88626. Added: Modified: libclc/cmake/modules/AddLibclc.cmake Removed: diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 5e09cde8035c27..bbedc244a72899 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -39,6 +39,10 @@ function(compile_to_bc) set( TARGET_ARG "-target" ${ARG_TRIPLE} ) endif() + # Ensure the directory we are told to output to exists + get_filename_component( ARG_OUTPUT_DIR ${ARG_OUTPUT} DIRECTORY ) + file( MAKE_DIRECTORY ${ARG_OUTPUT_DIR} ) + add_custom_command( OUTPUT ${ARG_OUTPUT}${TMP_SUFFIX} COMMAND libclc::clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix build with Unix Makefiles (PR #89147)
https://github.com/frasercrmck closed https://github.com/llvm/llvm-project/pull/89147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix build with Unix Makefiles (PR #89147)
@@ -39,6 +39,10 @@ function(compile_to_bc) set( TARGET_ARG "-target" ${ARG_TRIPLE} ) endif() + # Ensure the directory we are told to output to exists + get_filename_component( ARG_OUTPUT_DIR ${ARG_OUTPUT} DIRECTORY ) frasercrmck wrote: Yeah, there very well may be. I couldn't find anything obvious, but I'm sure I'll keep iterating on the build system over time so I'll keep an eye out. https://github.com/llvm/llvm-project/pull/89147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix half && bfloat16 convert node expr codegen (PR #89051)
@@ -0,0 +1,194 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +fullbf16 -S -emit-llvm %s -o - | FileCheck %s +// CHECK-LABEL: define dso_local half @test_convert_from_bf16_to_fp16( +// CHECK-SAME: bfloat noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2 +// CHECK-NEXT:store bfloat [[A]], ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[CONV:%.*]] = fpext bfloat [[TMP0]] to float +// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to half +// CHECK-NEXT:ret half [[CONV1]] +// +_Float16 test_convert_from_bf16_to_fp16(__bf16 a) { +return (_Float16)a; +} + +// CHECK-LABEL: define dso_local bfloat @test_convert_from_fp16_to_bf16( +// CHECK-SAME: half noundef [[A:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca half, align 2 +// CHECK-NEXT:store half [[A]], ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load half, ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[CONV:%.*]] = fpext half [[TMP0]] to float +// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to bfloat +// CHECK-NEXT:ret bfloat [[CONV1]] +// +__bf16 test_convert_from_fp16_to_bf16(_Float16 a) { +return (__bf16)a; +} + +typedef _Float16 half2 __attribute__((ext_vector_type(2))); +typedef _Float16 half4 __attribute__((ext_vector_type(4))); + +typedef __bf16 bfloat2 __attribute__((ext_vector_type(2))); +typedef __bf16 bfloat4 __attribute__((ext_vector_type(4))); + +// CHECK-LABEL: define dso_local i32 @test_cast_from_fp162_to_bf162( +// CHECK-SAME: i32 noundef [[IN_COERCE:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x bfloat>, align 4 +// CHECK-NEXT:[[IN:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:store i32 [[IN_COERCE]], ptr [[IN]], align 4 +// CHECK-NEXT:[[IN1:%.*]] = load <2 x half>, ptr [[IN]], align 4 +// CHECK-NEXT:store <2 x half> [[IN1]], ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP0:%.*]] = load <2 x half>, ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x half> [[TMP0]] to <2 x bfloat> arsenm wrote: The vector case is still emitting the incorrect bitcast https://github.com/llvm/llvm-project/pull/89051 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix half && bfloat16 convert node expr codegen (PR #89051)
@@ -0,0 +1,194 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +fullbf16 -S -emit-llvm %s -o - | FileCheck %s +// CHECK-LABEL: define dso_local half @test_convert_from_bf16_to_fp16( +// CHECK-SAME: bfloat noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2 +// CHECK-NEXT:store bfloat [[A]], ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[CONV:%.*]] = fpext bfloat [[TMP0]] to float +// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to half +// CHECK-NEXT:ret half [[CONV1]] +// +_Float16 test_convert_from_bf16_to_fp16(__bf16 a) { +return (_Float16)a; +} + +// CHECK-LABEL: define dso_local bfloat @test_convert_from_fp16_to_bf16( +// CHECK-SAME: half noundef [[A:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca half, align 2 +// CHECK-NEXT:store half [[A]], ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load half, ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[CONV:%.*]] = fpext half [[TMP0]] to float +// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to bfloat +// CHECK-NEXT:ret bfloat [[CONV1]] +// +__bf16 test_convert_from_fp16_to_bf16(_Float16 a) { +return (__bf16)a; +} + +typedef _Float16 half2 __attribute__((ext_vector_type(2))); +typedef _Float16 half4 __attribute__((ext_vector_type(4))); + +typedef __bf16 bfloat2 __attribute__((ext_vector_type(2))); +typedef __bf16 bfloat4 __attribute__((ext_vector_type(4))); + +// CHECK-LABEL: define dso_local i32 @test_cast_from_fp162_to_bf162( +// CHECK-SAME: i32 noundef [[IN_COERCE:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x bfloat>, align 4 +// CHECK-NEXT:[[IN:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:store i32 [[IN_COERCE]], ptr [[IN]], align 4 +// CHECK-NEXT:[[IN1:%.*]] = load <2 x half>, ptr [[IN]], align 4 +// CHECK-NEXT:store <2 x half> [[IN1]], ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP0:%.*]] = load <2 x half>, ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x half> [[TMP0]] to <2 x bfloat> +// CHECK-NEXT:store <2 x bfloat> [[TMP1]], ptr [[RETVAL]], align 4 +// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[RETVAL]], align 4 +// CHECK-NEXT:ret i32 [[TMP2]] +// +bfloat2 test_cast_from_fp162_to_bf162(half2 in) { + return (bfloat2)in; +} + + +// CHECK-LABEL: define dso_local double @test_cast_from_fp164_to_bf164( +// CHECK-SAME: double noundef [[IN_COERCE:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[RETVAL:%.*]] = alloca <4 x bfloat>, align 8 +// CHECK-NEXT:[[IN:%.*]] = alloca <4 x half>, align 8 +// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <4 x half>, align 8 +// CHECK-NEXT:store double [[IN_COERCE]], ptr [[IN]], align 8 +// CHECK-NEXT:[[IN1:%.*]] = load <4 x half>, ptr [[IN]], align 8 +// CHECK-NEXT:store <4 x half> [[IN1]], ptr [[IN_ADDR]], align 8 +// CHECK-NEXT:[[TMP0:%.*]] = load <4 x half>, ptr [[IN_ADDR]], align 8 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast <4 x half> [[TMP0]] to <4 x bfloat> +// CHECK-NEXT:store <4 x bfloat> [[TMP1]], ptr [[RETVAL]], align 8 +// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[RETVAL]], align 8 +// CHECK-NEXT:ret double [[TMP2]] +// +bfloat4 test_cast_from_fp164_to_bf164(half4 in) { + return (bfloat4)in; +} + +// CHECK-LABEL: define dso_local i32 @test_cast_from_bf162_to_fp162( +// CHECK-SAME: i32 noundef [[IN_COERCE:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:[[IN:%.*]] = alloca <2 x bfloat>, align 4 +// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <2 x bfloat>, align 4 +// CHECK-NEXT:store i32 [[IN_COERCE]], ptr [[IN]], align 4 +// CHECK-NEXT:[[IN1:%.*]] = load <2 x bfloat>, ptr [[IN]], align 4 +// CHECK-NEXT:store <2 x bfloat> [[IN1]], ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP0:%.*]] = load <2 x bfloat>, ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x bfloat> [[TMP0]] to <2 x half> arsenm wrote: This bitcast also doesn't look right. I'm shocked that the vector cast behavior seems to treat FP-to-int vectors as bitcast, radically different from the scalar case (which OpenCL doesn't even allow). The comment says it's allowing bitcast between fp/int of the same size, but that's not really what the cast is here. https://github.com/llvm/llvm-project/pull/89051 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix half && bfloat16 convert node expr codegen (PR #89051)
@@ -0,0 +1,194 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +fullbf16 -S -emit-llvm %s -o - | FileCheck %s +// CHECK-LABEL: define dso_local half @test_convert_from_bf16_to_fp16( +// CHECK-SAME: bfloat noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2 +// CHECK-NEXT:store bfloat [[A]], ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[CONV:%.*]] = fpext bfloat [[TMP0]] to float +// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to half +// CHECK-NEXT:ret half [[CONV1]] +// +_Float16 test_convert_from_bf16_to_fp16(__bf16 a) { +return (_Float16)a; +} + +// CHECK-LABEL: define dso_local bfloat @test_convert_from_fp16_to_bf16( +// CHECK-SAME: half noundef [[A:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[A_ADDR:%.*]] = alloca half, align 2 +// CHECK-NEXT:store half [[A]], ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[TMP0:%.*]] = load half, ptr [[A_ADDR]], align 2 +// CHECK-NEXT:[[CONV:%.*]] = fpext half [[TMP0]] to float +// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to bfloat +// CHECK-NEXT:ret bfloat [[CONV1]] +// +__bf16 test_convert_from_fp16_to_bf16(_Float16 a) { +return (__bf16)a; +} + +typedef _Float16 half2 __attribute__((ext_vector_type(2))); +typedef _Float16 half4 __attribute__((ext_vector_type(4))); + +typedef __bf16 bfloat2 __attribute__((ext_vector_type(2))); +typedef __bf16 bfloat4 __attribute__((ext_vector_type(4))); + +// CHECK-LABEL: define dso_local i32 @test_cast_from_fp162_to_bf162( +// CHECK-SAME: i32 noundef [[IN_COERCE:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x bfloat>, align 4 +// CHECK-NEXT:[[IN:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:store i32 [[IN_COERCE]], ptr [[IN]], align 4 +// CHECK-NEXT:[[IN1:%.*]] = load <2 x half>, ptr [[IN]], align 4 +// CHECK-NEXT:store <2 x half> [[IN1]], ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP0:%.*]] = load <2 x half>, ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x half> [[TMP0]] to <2 x bfloat> +// CHECK-NEXT:store <2 x bfloat> [[TMP1]], ptr [[RETVAL]], align 4 +// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[RETVAL]], align 4 +// CHECK-NEXT:ret i32 [[TMP2]] +// +bfloat2 test_cast_from_fp162_to_bf162(half2 in) { + return (bfloat2)in; +} + + +// CHECK-LABEL: define dso_local double @test_cast_from_fp164_to_bf164( +// CHECK-SAME: double noundef [[IN_COERCE:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[RETVAL:%.*]] = alloca <4 x bfloat>, align 8 +// CHECK-NEXT:[[IN:%.*]] = alloca <4 x half>, align 8 +// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <4 x half>, align 8 +// CHECK-NEXT:store double [[IN_COERCE]], ptr [[IN]], align 8 +// CHECK-NEXT:[[IN1:%.*]] = load <4 x half>, ptr [[IN]], align 8 +// CHECK-NEXT:store <4 x half> [[IN1]], ptr [[IN_ADDR]], align 8 +// CHECK-NEXT:[[TMP0:%.*]] = load <4 x half>, ptr [[IN_ADDR]], align 8 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast <4 x half> [[TMP0]] to <4 x bfloat> +// CHECK-NEXT:store <4 x bfloat> [[TMP1]], ptr [[RETVAL]], align 8 +// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[RETVAL]], align 8 +// CHECK-NEXT:ret double [[TMP2]] +// +bfloat4 test_cast_from_fp164_to_bf164(half4 in) { + return (bfloat4)in; +} + +// CHECK-LABEL: define dso_local i32 @test_cast_from_bf162_to_fp162( +// CHECK-SAME: i32 noundef [[IN_COERCE:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x half>, align 4 +// CHECK-NEXT:[[IN:%.*]] = alloca <2 x bfloat>, align 4 +// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <2 x bfloat>, align 4 +// CHECK-NEXT:store i32 [[IN_COERCE]], ptr [[IN]], align 4 +// CHECK-NEXT:[[IN1:%.*]] = load <2 x bfloat>, ptr [[IN]], align 4 +// CHECK-NEXT:store <2 x bfloat> [[IN1]], ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP0:%.*]] = load <2 x bfloat>, ptr [[IN_ADDR]], align 4 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x bfloat> [[TMP0]] to <2 x half> +// CHECK-NEXT:store <2 x half> [[TMP1]], ptr [[RETVAL]], align 4 +// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[RETVAL]], align 4 +// CHECK-NEXT:ret i32 [[TMP2]] +// +half2 test_cast_from_bf162_to_fp162(bfloat2 in) { arsenm wrote: Rename test to match the new typedef name https://github.com/llvm/llvm-project/pull/89051 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c2d665b - [clang][Interp] Support ImplicitArrayInitExpr for vectors
Author: Timm Bäder Date: 2024-04-22T10:58:55+02:00 New Revision: c2d665b7aeb68f3e8e643ee9dfe5bb7dd31137e5 URL: https://github.com/llvm/llvm-project/commit/c2d665b7aeb68f3e8e643ee9dfe5bb7dd31137e5 DIFF: https://github.com/llvm/llvm-project/commit/c2d665b7aeb68f3e8e643ee9dfe5bb7dd31137e5.diff LOG: [clang][Interp] Support ImplicitArrayInitExpr for vectors Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/vectors.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 486ad9db625ddb..5b9ef9980c9cd0 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -935,6 +935,20 @@ bool ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueIni return true; } + if (const auto *VecT = E->getType()->getAs()) { +unsigned NumVecElements = VecT->getNumElements(); +QualType ElemQT = VecT->getElementType(); +PrimType ElemT = classifyPrim(ElemQT); + +for (unsigned I = 0; I < NumVecElements; ++I) { + if (!this->visitZeroInitializer(ElemT, ElemQT, E)) +return false; + if (!this->emitInitElem(ElemT, I, E)) +return false; +} +return true; + } + return false; } diff --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp index cb8bcd4fdda768..49dae14fcf646f 100644 --- a/clang/test/AST/Interp/vectors.cpp +++ b/clang/test/AST/Interp/vectors.cpp @@ -25,6 +25,19 @@ static_assert(vec4_0[3] == 0.5, ""); // ref-error {{not an integral constant exp constexpr int vec4_0_discarded = ((float4)12.0f, 0); +/// ImplicitValueInitExpr of vector type +constexpr float4 arr4[2] = { + {1,2,3,4}, +}; +static_assert(arr4[0][0] == 1, ""); // ref-error {{not an integral constant expression}} +static_assert(arr4[0][1] == 2, ""); // ref-error {{not an integral constant expression}} +static_assert(arr4[0][2] == 3, ""); // ref-error {{not an integral constant expression}} +static_assert(arr4[0][3] == 4, ""); // ref-error {{not an integral constant expression}} +static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}} +static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}} +static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}} +static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}} + /// From constant-expression-cxx11.cpp namespace Vector { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [driver] Do not warn about unused plugin flags. (PR #88948)
https://github.com/Meinersbur ready_for_review https://github.com/llvm/llvm-project/pull/88948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [driver] Do not warn about unused plugin flags. (PR #88948)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Michael Kruse (Meinersbur) Changes Plugins are not loaded without the -cc1 phase. Do not report them when running on an assembly file or when linking. Many build tools add these options to all driver invocations, including LLVM's build system. Fixes #88173 --- Full diff: https://github.com/llvm/llvm-project/pull/88948.diff 2 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+3-3) - (added) clang/test/Driver/clang-s-plugin.s (+5) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..c1d85c527d437b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3630,14 +3630,14 @@ defm rwpi : BoolFOption<"rwpi", "Generate read-write position independent code (ARM only)">, NegFlag>; def fplugin_EQ : Joined<["-"], "fplugin=">, Group, - Flags<[NoXarchOption]>, MetaVarName<"">, + Flags<[NoXarchOption, NoArgumentUnused]>, MetaVarName<"">, HelpText<"Load the named plugin (dynamic shared object)">; def fplugin_arg : Joined<["-"], "fplugin-arg-">, - MetaVarName<"-">, + MetaVarName<"-">, Flags<[NoArgumentUnused]>, HelpText<"Pass to plugin ">; def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">, Group, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, - MetaVarName<"">, + MetaVarName<"">, Flags<[NoArgumentUnused]>, HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">, MarshallingInfoStringVector>; defm tocdata : BoolOption<"m","tocdata", diff --git a/clang/test/Driver/clang-s-plugin.s b/clang/test/Driver/clang-s-plugin.s new file mode 100644 index 00..81169b7bc5bbc8 --- /dev/null +++ b/clang/test/Driver/clang-s-plugin.s @@ -0,0 +1,5 @@ +// RUN: %clang -### -c -fpass-plugin=bar.so -fplugin=bar.so -fplugin-arg-bar-option -Werror %s 2>&1 | FileCheck %s + +// Plugins are only relevant for the -cc1 phase. No warning should be raised +// when applied to assembly files. See GH #88173. +// CHECK-NOT: argument unused during compilation `` https://github.com/llvm/llvm-project/pull/88948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [driver] Do not warn about unused plugin flags. (PR #88948)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Michael Kruse (Meinersbur) Changes Plugins are not loaded without the -cc1 phase. Do not report them when running on an assembly file or when linking. Many build tools add these options to all driver invocations, including LLVM's build system. Fixes #88173 --- Full diff: https://github.com/llvm/llvm-project/pull/88948.diff 2 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+3-3) - (added) clang/test/Driver/clang-s-plugin.s (+5) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..c1d85c527d437b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3630,14 +3630,14 @@ defm rwpi : BoolFOption<"rwpi", "Generate read-write position independent code (ARM only)">, NegFlag>; def fplugin_EQ : Joined<["-"], "fplugin=">, Group, - Flags<[NoXarchOption]>, MetaVarName<"">, + Flags<[NoXarchOption, NoArgumentUnused]>, MetaVarName<"">, HelpText<"Load the named plugin (dynamic shared object)">; def fplugin_arg : Joined<["-"], "fplugin-arg-">, - MetaVarName<"-">, + MetaVarName<"-">, Flags<[NoArgumentUnused]>, HelpText<"Pass to plugin ">; def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">, Group, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, - MetaVarName<"">, + MetaVarName<"">, Flags<[NoArgumentUnused]>, HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">, MarshallingInfoStringVector>; defm tocdata : BoolOption<"m","tocdata", diff --git a/clang/test/Driver/clang-s-plugin.s b/clang/test/Driver/clang-s-plugin.s new file mode 100644 index 00..81169b7bc5bbc8 --- /dev/null +++ b/clang/test/Driver/clang-s-plugin.s @@ -0,0 +1,5 @@ +// RUN: %clang -### -c -fpass-plugin=bar.so -fplugin=bar.so -fplugin-arg-bar-option -Werror %s 2>&1 | FileCheck %s + +// Plugins are only relevant for the -cc1 phase. No warning should be raised +// when applied to assembly files. See GH #88173. +// CHECK-NOT: argument unused during compilation `` https://github.com/llvm/llvm-project/pull/88948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] bd84f5d - clang: Remove unnecessary pointer bitcast
Author: Matt Arsenault Date: 2024-04-22T11:35:09+02:00 New Revision: bd84f5d5d71ee26d9552a9cd96ef058cfb8a39fc URL: https://github.com/llvm/llvm-project/commit/bd84f5d5d71ee26d9552a9cd96ef058cfb8a39fc DIFF: https://github.com/llvm/llvm-project/commit/bd84f5d5d71ee26d9552a9cd96ef058cfb8a39fc.diff LOG: clang: Remove unnecessary pointer bitcast Added: Modified: clang/lib/CodeGen/CGExprScalar.cpp Removed: diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index c76052ff6280f9..40a5cd20c3d715 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1540,7 +1540,7 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, if (auto DstPT = dyn_cast(DstTy)) { // The source value may be an integer, or a pointer. if (isa(SrcTy)) - return Builder.CreateBitCast(Src, DstTy, "conv"); + return Src; assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?"); // First, convert to the correct width so that we control the kind of ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][driver] Avoid mentions of Clang in Flang's command line reference. (PR #88932)
Meinersbur wrote: > IIRC it was unnecessary for the documentation because it gets built multiple > times, for the driver it's built once so it has to include all possible > variants the first time. > > I have no preference for how it's done, if the `%Program` thing works then > fine. We only need a `ForVariants` if it's something people see when > interacting with Flang itself I think. I didn't know this and experimented a bit. Indeed `%Program` in `HelpText` gets emitted as "Clang" in `flang-new --help`. `DocBrief` and `HelpText` are "Flang" for `FlangCommandLineReference.rst`. So `DocBriefForVariant` would not add new functionality, but might be useful so `DocBrief[ForVariant]` and `HelpText[ForVariant]` can use the same syntax and avoid confusion. I will merge this patch and work on `DocBriefForVariant` after that. https://github.com/llvm/llvm-project/pull/88932 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fdc8c54 - [flang][driver] Avoid mentions of Clang in Flang's command line reference. (#88932)
Author: Michael Kruse Date: 2024-04-22T11:56:19+02:00 New Revision: fdc8c5440041ac53726d0b3587762ceeb8cbbb4f URL: https://github.com/llvm/llvm-project/commit/fdc8c5440041ac53726d0b3587762ceeb8cbbb4f DIFF: https://github.com/llvm/llvm-project/commit/fdc8c5440041ac53726d0b3587762ceeb8cbbb4f.diff LOG: [flang][driver] Avoid mentions of Clang in Flang's command line reference. (#88932) The help text was not updated in #87360. Clang is also mentioned for the diagnostic warnings reference, which mostly applies to C/C++/Obj-C, not Fortran. #81726 already tried to fix this, and I don't know a better solution. Added: Modified: clang/include/clang/Driver/Options.td flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90 Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 52d161703f965e..9f86808145d9ab 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -807,8 +807,12 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">, "Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation">; def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, FlangOption]>, - HelpText<"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " - "Clang will use the GCC installation with the largest version">; + HelpText< +"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " +"Clang will use the GCC installation with the largest version">, + HelpTextForVariants<[FlangOption], +"Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. " +"Flang will use the GCC installation with the largest version">; def gcc_triple_EQ : Joined<["--"], "gcc-triple=">, HelpText<"Search for the GCC installation with the specified triple.">; def CC : Flag<["-"], "CC">, Visibility<[ClangOption, CC1Option]>, diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 index de2fe3048f993c..b5bb0f1c1b2560 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -109,7 +109,7 @@ ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! CHECK-NEXT: --gcc-install-dir= ! CHECK-NEXT: Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation -! CHECK-NEXT: --gcc-toolchain= Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version +! CHECK-NEXT: --gcc-toolchain= Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Flang will use the GCC installation with the largest version ! CHECK-NEXT: -gline-directives-only Emit debug line info directives only ! CHECK-NEXT: -gline-tables-only Emit debug line number tables only ! CHECK-NEXT: -gpulibcLink the LLVM C Library for GPUs diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 index b258eb59c18629..0b0a493baf07f7 100644 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -97,7 +97,7 @@ ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! HELP-NEXT: --gcc-install-dir= ! HELP-NEXT: Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation -! HELP-NEXT: --gcc-toolchain= Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version +! HELP-NEXT: --gcc-toolchain= Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Flang will use the GCC installation with the largest version ! HELP-NEXT: -gline-directives-only Emit debug line info directives only ! HELP-NEXT: -gline-tables-only Emit debug line number tables only ! HELP-NEXT: -gpulibcLink the LLVM C Library for GPUs ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][driver] Avoid mentions of Clang in Flang's command line reference. (PR #88932)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/88932 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
https://github.com/PiotrZSL approved this pull request. - One code duplication that could be avoided. - Add entry in release notes, about fixing issue with big unsigned config option values printed as negative numbers in --dump-config Overall, fine. As for misc-throw-by-value-catch-by-reference check, we may need to use optional in future for this and fix documentation. https://github.com/llvm/llvm-project/pull/85060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
https://github.com/PiotrZSL edited https://github.com/llvm/llvm-project/pull/85060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
@@ -422,7 +425,10 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, std::optional Value) const { if (Value) -storeInt(Options, LocalName, *Value); +if constexpr (std::is_signed_v) + storeInt(Options, LocalName, *Value); +else + storeUnsigned(Options, LocalName, *Value); PiotrZSL wrote: you could just call: `store(Options, LocalName, *Value)` And this way could avoid duplicates. https://github.com/llvm/llvm-project/pull/85060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)
https://github.com/PiotrZSL approved this pull request. Looks fine for me. https://github.com/llvm/llvm-project/pull/88636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)
@@ -7,42 +7,70 @@ //===--===// #include "StringCompareCheck.h" -#include "../utils/FixItHintUtils.h" +#include "../utils/OptionsUtils.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Tooling/FixIt.h" +#include "llvm/ADT/StringRef.h" +#include using namespace clang::ast_matchers; +namespace optutils = clang::tidy::utils::options; namespace clang::tidy::readability { static const StringRef CompareMessage = "do not use 'compare' to test equality " "of strings; use the string equality " "operator instead"; +static const std::vector StringClasses = { +"::std::basic_string", "::std::basic_string_view"}; + +StringCompareCheck::StringCompareCheck(StringRef Name, + ClangTidyContext *Context) +: ClangTidyCheck(Name, Context), + StringLikeClasses( + optutils::parseStringList(Options.get("StringLikeClasses", ""))) {} + void StringCompareCheck::registerMatchers(MatchFinder *Finder) { - const auto StrCompare = cxxMemberCallExpr( - callee(cxxMethodDecl(hasName("compare"), - ofClass(classTemplateSpecializationDecl( - hasName("::std::basic_string"), - hasArgument(0, expr().bind("str2")), argumentCountIs(1), - callee(memberExpr().bind("str1"))); - - // First and second case: cast str.compare(str) to boolean. - Finder->addMatcher( - traverse(TK_AsIs, - implicitCastExpr(hasImplicitDestinationType(booleanType()), -has(StrCompare)) - .bind("match1")), - this); - - // Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0. - Finder->addMatcher( - binaryOperator(hasAnyOperatorName("==", "!="), - hasOperands(StrCompare.bind("compare"), - integerLiteral(equals(0)).bind("zero"))) - .bind("match2"), - this); + const auto RegisterForClasses = [&, this](const auto &StringClassMatcher) { +const auto StrCompare = cxxMemberCallExpr( +callee(cxxMethodDecl(hasName("compare"), ofClass(StringClassMatcher))), +hasArgument(0, expr().bind("str2")), argumentCountIs(1), +callee(memberExpr().bind("str1"))); + +// First and second case: cast str.compare(str) to boolean. +Finder->addMatcher( +traverse(TK_AsIs, + implicitCastExpr(hasImplicitDestinationType(booleanType()), + has(StrCompare)) + .bind("match1")), +this); + +// Third and fourth case: str.compare(str) == 0 +// and str.compare(str) != 0. +Finder->addMatcher( +binaryOperator(hasAnyOperatorName("==", "!="), + hasOperands(StrCompare.bind("compare"), + integerLiteral(equals(0)).bind("zero"))) +.bind("match2"), +this); + }; + if (StringLikeClasses.empty()) { +RegisterForClasses( +classTemplateSpecializationDecl(hasAnyName(StringClasses))); + } else { +// StringLikeClasses may or may not be templates, so we need to match both +// template and non-template classes. +std::vector PossiblyTemplateClasses = StringClasses; +PossiblyTemplateClasses.insert(PossiblyTemplateClasses.end(), + StringLikeClasses.begin(), + StringLikeClasses.end()); +RegisterForClasses(anyOf( +classTemplateSpecializationDecl(hasAnyName(PossiblyTemplateClasses)), +cxxRecordDecl(hasAnyName(StringLikeClasses; PiotrZSL wrote: OK, personally I would prefer regexp, but for now can be like this. https://github.com/llvm/llvm-project/pull/88636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
https://github.com/ealcdan updated https://github.com/llvm/llvm-project/pull/85060 >From 20f7b3172c6735e8dbdda24ffde7ee8ecd7c7404 Mon Sep 17 00:00:00 2001 From: Daniel Alcaide Nombela Date: Wed, 13 Mar 2024 11:28:34 +0100 Subject: [PATCH] [clang-tidy] Avoid overflow when dumping unsigned integer values Some options take the maximum unsigned integer value as default, but they are being dumped to a string as integers. This makes -dump-config write invalid '-1' values for these options. This change fixes this issue by using utostr if the option is unsigned. Change-Id: I551e6bc616071cf7aa10a8c0220d2076ed3d40e6 --- clang-tools-extra/clang-tidy/ClangTidyCheck.cpp | 6 ++ clang-tools-extra/clang-tidy/ClangTidyCheck.h| 9 +++-- .../infrastructure/Inputs/config-files/5/.clang-tidy | 4 .../test/clang-tidy/infrastructure/config-files.cpp | 8 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp index 3e926236adb451..710b361e16c0a7 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -139,6 +139,12 @@ void ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options, store(Options, LocalName, llvm::itostr(Value)); } +void ClangTidyCheck::OptionsView::storeUnsigned( +ClangTidyOptions::OptionMap &Options, StringRef LocalName, +uint64_t Value) const { + store(Options, LocalName, llvm::utostr(Value)); +} + template <> void ClangTidyCheck::OptionsView::store( ClangTidyOptions::OptionMap &Options, StringRef LocalName, diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h index 656a2f008f6e0e..7427aa9bf48f89 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h @@ -411,7 +411,10 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { std::enable_if_t> store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value) const { - storeInt(Options, LocalName, Value); + if constexpr (std::is_signed_v) +storeInt(Options, LocalName, Value); + else +storeUnsigned(Options, LocalName, Value); } /// Stores an option with the check-local name \p LocalName with @@ -422,7 +425,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, std::optional Value) const { if (Value) -storeInt(Options, LocalName, *Value); +store(Options, LocalName, *Value); else store(Options, LocalName, "none"); } @@ -470,6 +473,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName, int64_t Value) const; +void storeUnsigned(ClangTidyOptions::OptionMap &Options, + StringRef LocalName, uint64_t Value) const; std::string NamePrefix; const ClangTidyOptions::OptionMap &CheckOptions; diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy new file mode 100644 index 00..e33f0f8bb33218 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy @@ -0,0 +1,4 @@ +InheritParentConfig: true +Checks: 'misc-throw-by-value-catch-by-reference' +CheckOptions: + misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976' diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp index ab4f3becb7a9fc..cb0f0bc4d13308 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp @@ -64,3 +64,11 @@ // Validate that check options are printed in alphabetical order: // RUN: clang-tidy --checks="-*,readability-identifier-naming" --dump-config %S/Inputs/config-files/- -- | grep "readability-identifier-naming\." | sort --check + +// Dumped config does not overflow for unsigned options +// RUN: clang-tidy --dump-config \ +// RUN: --checks="-*,misc-throw-by-value-catch-by-reference" \ +// RUN: -- | grep -v -q "misc-throw-by-value-catch-by-reference.MaxSize: '-1'" + +// RUN: clang-tidy --dump-config %S/Inputs/config-files/5/- \ +// RUN: -- | grep -q "misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976'" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mai
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
https://github.com/ealcdan updated https://github.com/llvm/llvm-project/pull/85060 >From afe6658e869646730a18c52e18f5cb4675d67a6b Mon Sep 17 00:00:00 2001 From: Daniel Alcaide Nombela Date: Wed, 13 Mar 2024 11:28:34 +0100 Subject: [PATCH] [clang-tidy] Avoid overflow when dumping unsigned integer values Some options take the maximum unsigned integer value as default, but they are being dumped to a string as integers. This makes -dump-config write invalid '-1' values for these options. This change fixes this issue by using utostr if the option is unsigned. Change-Id: I551e6bc616071cf7aa10a8c0220d2076ed3d40e6 --- clang-tools-extra/clang-tidy/ClangTidyCheck.cpp | 6 ++ clang-tools-extra/clang-tidy/ClangTidyCheck.h| 9 +++-- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ .../infrastructure/Inputs/config-files/5/.clang-tidy | 4 .../test/clang-tidy/infrastructure/config-files.cpp | 8 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp index 3e926236adb451..710b361e16c0a7 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -139,6 +139,12 @@ void ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options, store(Options, LocalName, llvm::itostr(Value)); } +void ClangTidyCheck::OptionsView::storeUnsigned( +ClangTidyOptions::OptionMap &Options, StringRef LocalName, +uint64_t Value) const { + store(Options, LocalName, llvm::utostr(Value)); +} + template <> void ClangTidyCheck::OptionsView::store( ClangTidyOptions::OptionMap &Options, StringRef LocalName, diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h index 656a2f008f6e0e..7427aa9bf48f89 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h @@ -411,7 +411,10 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { std::enable_if_t> store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value) const { - storeInt(Options, LocalName, Value); + if constexpr (std::is_signed_v) +storeInt(Options, LocalName, Value); + else +storeUnsigned(Options, LocalName, Value); } /// Stores an option with the check-local name \p LocalName with @@ -422,7 +425,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, std::optional Value) const { if (Value) -storeInt(Options, LocalName, *Value); +store(Options, LocalName, *Value); else store(Options, LocalName, "none"); } @@ -470,6 +473,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName, int64_t Value) const; +void storeUnsigned(ClangTidyOptions::OptionMap &Options, + StringRef LocalName, uint64_t Value) const; std::string NamePrefix; const ClangTidyOptions::OptionMap &CheckOptions; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 44680f79de6f54..af1cf03bea0e48 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -251,6 +251,9 @@ Miscellaneous option is specified. Now ``clang-apply-replacements`` applies formatting only with the option. +- Fixed bug where big values for unsigned check options overflowed into negative values + when being printed with ``--dump-config``. + Improvements to include-fixer - diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy new file mode 100644 index 00..e33f0f8bb33218 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy @@ -0,0 +1,4 @@ +InheritParentConfig: true +Checks: 'misc-throw-by-value-catch-by-reference' +CheckOptions: + misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976' diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp index ab4f3becb7a9fc..cb0f0bc4d13308 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp @@ -64,3 +64,11 @@ // Validate that check options are printed in alphabetical order: // RUN: clang-tidy --checks="-*,readability-identifier-nami
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
ealcdan wrote: Great, both points have been addressed in the new patches, hope the release notes entry is clear enough. https://github.com/llvm/llvm-project/pull/85060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix a crash introduced in PR#88666 (PR #89567)
https://github.com/yronglin approved this pull request. https://github.com/llvm/llvm-project/pull/89567 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)
alexfh wrote: Thanks for the prompt fix! https://github.com/llvm/llvm-project/pull/88666 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix __is_trivially_equaltiy_comparable documentation (PR #88528)
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/88528 >From 0c9372749f4b2d52deddea82be4e77524a66a348 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Fri, 12 Apr 2024 17:36:53 +0200 Subject: [PATCH] [Clang] Fix __is_trivially_equaltiy_comparable documentation --- clang/docs/LanguageExtensions.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 7b23e4d1c2f30c..40ff2d074e1648 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1640,7 +1640,8 @@ The following type trait primitives are supported by Clang. Those traits marked were made trivially relocatable via the ``clang::trivial_abi`` attribute. * ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two objects of the provided type is known to be equivalent to comparing their - value representations. + object representations. Note that types containing padding bytes are never + trivially equality comparable. * ``__is_unbounded_array`` (C++, GNU, Microsoft, Embarcadero) * ``__is_union`` (C++, GNU, Microsoft, Embarcadero) * ``__is_unsigned`` (C++, Embarcadero): ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)
yronglin wrote: Friendly ping! @zygoloid @hubert-reinterpretcast https://github.com/llvm/llvm-project/pull/87933 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)
yronglin wrote: Friendly ping~ https://github.com/llvm/llvm-project/pull/88602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Default -g to full debug info. (PR #89418)
abidh wrote: I am going to merge this. There is bot failure (trailing whitespace in clang/lib/Serialization/ASTWriter.cpp) which seems unrelated to this PR. https://github.com/llvm/llvm-project/pull/89418 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 087b33b - [flang] Default -g to full debug info. (#89418)
Author: abidh Date: 2024-04-22T11:19:05+01:00 New Revision: 087b33bbff1ab966656a81f9dd8e136fbd966f58 URL: https://github.com/llvm/llvm-project/commit/087b33bbff1ab966656a81f9dd8e136fbd966f58 DIFF: https://github.com/llvm/llvm-project/commit/087b33bbff1ab966656a81f9dd8e136fbd966f58.diff LOG: [flang] Default -g to full debug info. (#89418) Currently, -g defaults to line tables only. This PR changes that to full debug information. This will allow us to test/use the upcoming debug info changes. Added: flang/test/Driver/debug-level.f90 Modified: clang/lib/Driver/ToolChains/Flang.cpp flang/lib/Frontend/CompilerInvocation.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index b46bac24503ce1..abe0b931676005 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -118,7 +118,7 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { Arg *gNArg = Args.getLastArg(options::OPT_gN_Group); DebugInfoKind = debugLevelToInfoKind(*gNArg); } else if (Args.hasArg(options::OPT_g_Flag)) { -DebugInfoKind = llvm::codegenoptions::DebugLineTablesOnly; +DebugInfoKind = llvm::codegenoptions::FullDebugInfo; } else { DebugInfoKind = llvm::codegenoptions::NoDebugInfo; } diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index e432c5a302754c..f1b7b53975398e 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -145,6 +145,7 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts, } opts.setDebugInfo(val.value()); if (val != llvm::codegenoptions::DebugLineTablesOnly && +val != llvm::codegenoptions::FullDebugInfo && val != llvm::codegenoptions::NoDebugInfo) { const auto debugWarning = diags.getCustomDiagID( clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0"); diff --git a/flang/test/Driver/debug-level.f90 b/flang/test/Driver/debug-level.f90 new file mode 100644 index 00..bc0aee166e6a37 --- /dev/null +++ b/flang/test/Driver/debug-level.f90 @@ -0,0 +1,7 @@ +! RUN: %flang %s -g -c -### 2>&1 | FileCheck %s --check-prefix=FULL +! RUN: %flang %s -g1 -c -### 2>&1 | FileCheck %s --check-prefix=LINE +! RUN: %flang %s -gline-tables-only -c -### 2>&1 | FileCheck %s --check-prefix=LINE + +! LINE: -debug-info-kind=line-tables-only +! FULL: -debug-info-kind=standalone + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Default -g to full debug info. (PR #89418)
https://github.com/abidh closed https://github.com/llvm/llvm-project/pull/89418 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)
@@ -0,0 +1,34 @@ +//===--- ReturnConstRefFromParameterCheck.cpp - clang-tidy ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ReturnConstRefFromParameterCheck.h" +#include "../utils/Matchers.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType( + hasCanonicalType(matchers::isReferenceToConst( + .bind("ret"), + this); HerrCai0907 wrote: clang will create `CXXConstructExpr` for object and `ImplicitCastExpr` for builtin type. just like ``` `-FunctionDecl 0x13d8cf548 col:9 fn 'const S (const S &)' |-ParmVarDecl 0x13d8cf450 col:21 used a 'const S &' `-CompoundStmt 0x13d8ee1a0 `-ReturnStmt 0x13d8ee190 `-CXXConstructExpr 0x13d8ee160 'const S':'const S' 'void (const S &) noexcept' `-DeclRefExpr 0x13d8cf640 'const S':'const S' lvalue ParmVar 0x13d8cf450 'a' 'const S &' ``` and ``` `-FunctionDecl 0x1410d9ac0 col:11 fn 'const int (const int &)' |-ParmVarDecl 0x1410d99f0 col:25 used a 'const int &' `-CompoundStmt 0x1410d9c00 `-ReturnStmt 0x1410d9bf0 `-ImplicitCastExpr 0x1410d9bd8 'int' `-DeclRefExpr 0x1410d9bb8 'const int' lvalue ParmVar 0x1410d99f0 'a' 'const int &' ``` https://github.com/llvm/llvm-project/pull/89497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/89497 >From 91915f68902ade86c0bf8eba643428017ae8bb3c Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sat, 20 Apr 2024 17:58:19 +0800 Subject: [PATCH 1/5] [tidy] add new check bugprone-return-const-ref-from-parameter Detects the function which returns the const reference from parameter which causes potential use after free if the caller uses xvalue as argument. In c++, const reference parameter can accept xvalue which will be destructed after the call. When the function returns this parameter also as const reference, then the returned reference can be used after the object it refers to has been destroyed. Fixes: #85253 --- .../bugprone/BugproneTidyModule.cpp | 3 ++ .../clang-tidy/bugprone/CMakeLists.txt| 1 + .../ReturnConstRefFromParameterCheck.cpp | 41 +++ .../ReturnConstRefFromParameterCheck.h| 35 clang-tools-extra/docs/ReleaseNotes.rst | 6 +++ .../return-const-ref-from-parameter.rst | 30 ++ .../docs/clang-tidy/checks/list.rst | 9 ++-- .../return-const-ref-from-parameter.cpp | 31 ++ 8 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index 2931325d8b5798..1b92d2e60cc173 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -54,6 +54,7 @@ #include "PosixReturnCheck.h" #include "RedundantBranchConditionCheck.h" #include "ReservedIdentifierCheck.h" +#include "ReturnConstRefFromParameterCheck.h" #include "SharedPtrArrayMismatchCheck.h" #include "SignalHandlerCheck.h" #include "SignedCharMisuseCheck.h" @@ -137,6 +138,8 @@ class BugproneModule : public ClangTidyModule { "bugprone-inaccurate-erase"); CheckFactories.registerCheck( "bugprone-incorrect-enable-if"); +CheckFactories.registerCheck( +"bugprone-return-const-ref-from-parameter"); CheckFactories.registerCheck( "bugprone-switch-missing-default-case"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index 081ba67efe1538..2d303191f88650 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule ImplicitWideningOfMultiplicationResultCheck.cpp InaccurateEraseCheck.cpp IncorrectEnableIfCheck.cpp + ReturnConstRefFromParameterCheck.cpp SuspiciousStringviewDataUsageCheck.cpp SwitchMissingDefaultCaseCheck.cpp IncDecInConditionsCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp new file mode 100644 index 00..87fc663231496e --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -0,0 +1,41 @@ +//===--- ReturnConstRefFromParameterCheck.cpp - clang-tidy ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ReturnConstRefFromParameterCheck.h" +#include "../utils/Matchers.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +std::optional +ReturnConstRefFromParameterCheck::getCheckTraversalKind() const { + // Use 'AsIs' to make sure the return type is exactly the same as the + // parameter type. + return TK_AsIs; +} + +void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType( + hasCanonicalType(matchers::isReferenceToConst( + .bind("ret"), + this); +} + +void ReturnConstRefFromParameterCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *R = Result.Nodes.getNodeAs("ret"); + diag(R->getRetValue()->getBeginLoc(), + "return const reference parameter cause potential use-after-free " +
[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)
@@ -0,0 +1,34 @@ +//===--- ReturnConstRefFromParameterCheck.cpp - clang-tidy ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ReturnConstRefFromParameterCheck.h" +#include "../utils/Matchers.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType( + hasCanonicalType(matchers::isReferenceToConst( + .bind("ret"), + this); HerrCai0907 wrote: stack variable leak can be detected by clang diagnose directly, no need to use clang-tidy. https://github.com/llvm/llvm-project/pull/89497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)
https://github.com/HerrCai0907 edited https://github.com/llvm/llvm-project/pull/89497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)
martinboehme wrote: Needed to revert this because it turns out that, embarrassingly, I was locally running my tests in `Release` mode, i.e. with `assert()` disabled. I'm working on a PR to re-land this that fixes the assertion failures that were occurring. https://github.com/llvm/llvm-project/pull/89213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
@@ -251,6 +251,9 @@ Miscellaneous option is specified. Now ``clang-apply-replacements`` applies formatting only with the option. +- Fixed bug where big values for unsigned check options overflowed into negative values + when being printed with ``--dump-config``. PiotrZSL wrote: should be in line 103, and rebase your changes https://github.com/llvm/llvm-project/pull/85060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
https://github.com/PiotrZSL approved this pull request. https://github.com/llvm/llvm-project/pull/85060 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)
https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/89358 >From 9583811bfa66ff058f5e33012cd77501ce3e5e23 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 19 Apr 2024 10:54:12 +0200 Subject: [PATCH 1/2] [clang] CTAD: implement the missing IsDeducible constraint for alias templates. Fixes https://github.com/llvm/llvm-project/issues/85192 Fixes https://github.com/llvm/llvm-project/issues/84492 --- clang/include/clang/Basic/TokenKinds.def | 1 + clang/include/clang/Sema/Sema.h | 9 ++ clang/lib/Parse/ParseExprCXX.cpp | 16 ++-- clang/lib/Sema/SemaExprCXX.cpp| 11 +++ clang/lib/Sema/SemaTemplate.cpp | 70 --- clang/lib/Sema/SemaTemplateDeduction.cpp | 87 +++ clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 26 -- .../test/SemaCXX/type-traits-is-deducible.cpp | 47 ++ clang/www/cxx_status.html | 8 +- 9 files changed, 243 insertions(+), 32 deletions(-) create mode 100644 clang/test/SemaCXX/type-traits-is-deducible.cpp diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index a27fbed358a60c..74102f40539681 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -537,6 +537,7 @@ TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX) TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX) TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX) TYPE_TRAIT_2(__reference_constructs_from_temporary, ReferenceConstructsFromTemporary, KEYCXX) +TYPE_TRAIT_2(__is_deducible, IsDeducible, KEYCXX) // Embarcadero Expression Traits EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index ffc58c681cdcd5..a4470ef0aab280 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9591,6 +9591,15 @@ class Sema final : public SemaBase { ArrayRef TemplateArgs, sema::TemplateDeductionInfo &Info); + /// Deduce the template arguments of the given template from \p FromType. + /// Used to implement the IsDeducible constraint for alias CTAD per C++ + /// [over.match.class.deduct]p4. + /// + /// It only supports class or type alias templates. + TemplateDeductionResult + DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType, + sema::TemplateDeductionInfo &Info); + TemplateDeductionResult DeduceTemplateArguments( TemplateParameterList *TemplateParams, ArrayRef Ps, ArrayRef As, sema::TemplateDeductionInfo &Info, diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 0d2ad980696fcc..af4e205eeff803 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -3906,14 +3906,18 @@ ExprResult Parser::ParseTypeTrait() { BalancedDelimiterTracker Parens(*this, tok::l_paren); if (Parens.expectAndConsume()) return ExprError(); - + TypeTrait TTKind = TypeTraitFromTokKind(Kind); SmallVector Args; do { // Parse the next type. -TypeResult Ty = ParseTypeName(/*SourceRange=*/nullptr, - getLangOpts().CPlusPlus - ? DeclaratorContext::TemplateTypeArg - : DeclaratorContext::TypeName); +TypeResult Ty = ParseTypeName( +/*SourceRange=*/nullptr, +getLangOpts().CPlusPlus +// For __is_deducible type trait, the first argument is a template +// specification type without template argument lists. +? (TTKind == BTT_IsDeducible ? DeclaratorContext::TemplateArg + : DeclaratorContext::TemplateTypeArg) +: DeclaratorContext::TypeName); if (Ty.isInvalid()) { Parens.skipToEnd(); return ExprError(); @@ -3937,7 +3941,7 @@ ExprResult Parser::ParseTypeTrait() { SourceLocation EndLoc = Parens.getCloseLocation(); - return Actions.ActOnTypeTrait(TypeTraitFromTokKind(Kind), Loc, Args, EndLoc); + return Actions.ActOnTypeTrait(TTKind, Loc, Args, EndLoc); } /// ParseArrayTypeTrait - Parse the built-in array type-trait diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 7582cbd75fec05..0833a985b48b88 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -6100,6 +6100,17 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI tok::kw___is_pointer_interconvertible_base_of); return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs); + } + case BTT_IsDeducible: { +if (const auto *TSTToBeDeduced = +LhsT->getAs()) { + sema::TemplateDeductionInfo Info(KeyLoc); + return Self.DeduceTemplateArgumentsFr
[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)
@@ -3207,6 +3241,59 @@ Sema::DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, return ::DeduceTemplateArguments(*this, Partial, TemplateArgs, Info); } +TemplateDeductionResult +Sema::DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType, + sema::TemplateDeductionInfo &Info) { + if (TD->isInvalidDecl()) +return TemplateDeductionResult::Invalid; + + QualType PType; + if (const auto *CTD = dyn_cast(TD)) { +// Use the InjectedClassNameType. +PType = Context.getTypeDeclType(CTD->getTemplatedDecl()); + } else if (const auto *AliasTemplate = dyn_cast(TD)) { +PType = AliasTemplate->getTemplatedDecl() +->getUnderlyingType() +.getCanonicalType(); + } else { +// FIXME: emit a diagnostic, we only only support alias and class templates. hokein wrote: It turns out we will never hit other cases in this code path (we will reject the var/function templates when parsing the type trait expr). I changed it to `assert`. https://github.com/llvm/llvm-project/pull/89358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)
@@ -6100,6 +6100,17 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI tok::kw___is_pointer_interconvertible_base_of); return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs); + } + case BTT_IsDeducible: { +if (const auto *TSTToBeDeduced = +LhsT->getAs()) { + sema::TemplateDeductionInfo Info(KeyLoc); + return Self.DeduceTemplateArgumentsFromType( + TSTToBeDeduced->getTemplateName().getAsTemplateDecl(), RhsT, + Info) == TemplateDeductionResult::Success; +} +// FIXME: emit a diagnostic. hokein wrote: implemented a new diagnostic for bad argument types for the builtin. https://github.com/llvm/llvm-project/pull/89358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)
hokein wrote: > Needs a release note, and I think we actually DO have to do those diagnostics > here. Added a release note for the new builtin. https://github.com/llvm/llvm-project/pull/89358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix template alias default DWARF version (PR #89594)
https://github.com/OCHyams created https://github.com/llvm/llvm-project/pull/89594 DW_TAG_template_alias DIEs were added in DWARFv4, not DWARFv5 >From 95c86b499e1eebb15dbd61f839f5fefa83dc910d Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 22 Apr 2024 11:48:19 +0100 Subject: [PATCH 1/2] [Clang] Fix template alias default DWARF versiion DW_TAG_template_alias DIEs were added in DWARFv4, not DWARFv5 --- clang/lib/Driver/ToolChains/Clang.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 97b4aa1c9b1d0a..f8a81ee8ab56bc 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4634,7 +4634,7 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, // Emit DW_TAG_template_alias for template aliases? True by default for SCE. bool UseDebugTemplateAlias = - DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 5; + DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4; if (const auto *DebugTemplateAlias = Args.getLastArg( options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) { // DW_TAG_template_alias is only supported from DWARFv5 but if a user >From 90235c8e9d953975479f18a2cb8aa05a3d3456b7 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 22 Apr 2024 11:55:32 +0100 Subject: [PATCH 2/2] update test --- clang/test/Driver/debug-options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c index b209c911d1ca2b..7d061410a229f0 100644 --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -456,9 +456,9 @@ // RUN: %clang -### -target x86_64 -c -g %s 2>&1 | FileCheck --check-prefix=FULL_TEMP_NAMES --implicit-check-not=debug-forward-template-params %s // FULL_TEMP_NAMES-NOT: -gsimple-template-names - Test -g[no-]template-alias (enabled by default with SCE debugger tuning and DWARFv5). + Test -g[no-]template-alias (enabled by default with SCE debugger tuning and DWARF version >= 4). // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS -// RUN: %clang -### -target x86_64 -c -gdwarf-4 -gsce %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS +// RUN: %clang -### -target x86_64 -c -gdwarf-3 -gsce %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce -gtemplate-alias %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce -gno-template-alias %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gtemplate-alias %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix template alias default DWARF version (PR #89594)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Orlando Cazalet-Hyams (OCHyams) Changes DW_TAG_template_alias DIEs were added in DWARFv4, not DWARFv5 --- Full diff: https://github.com/llvm/llvm-project/pull/89594.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) - (modified) clang/test/Driver/debug-options.c (+2-2) ``diff diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 97b4aa1c9b1d0a..f8a81ee8ab56bc 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4634,7 +4634,7 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, // Emit DW_TAG_template_alias for template aliases? True by default for SCE. bool UseDebugTemplateAlias = - DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 5; + DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4; if (const auto *DebugTemplateAlias = Args.getLastArg( options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) { // DW_TAG_template_alias is only supported from DWARFv5 but if a user diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c index b209c911d1ca2b..7d061410a229f0 100644 --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -456,9 +456,9 @@ // RUN: %clang -### -target x86_64 -c -g %s 2>&1 | FileCheck --check-prefix=FULL_TEMP_NAMES --implicit-check-not=debug-forward-template-params %s // FULL_TEMP_NAMES-NOT: -gsimple-template-names - Test -g[no-]template-alias (enabled by default with SCE debugger tuning and DWARFv5). + Test -g[no-]template-alias (enabled by default with SCE debugger tuning and DWARF version >= 4). // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS -// RUN: %clang -### -target x86_64 -c -gdwarf-4 -gsce %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS +// RUN: %clang -### -target x86_64 -c -gdwarf-3 -gsce %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce -gtemplate-alias %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce -gno-template-alias %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gtemplate-alias %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS `` https://github.com/llvm/llvm-project/pull/89594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)
https://github.com/ealcdan updated https://github.com/llvm/llvm-project/pull/85060 >From 07248879092c0e752811b4c33b98c50d42230d14 Mon Sep 17 00:00:00 2001 From: Daniel Alcaide Nombela Date: Wed, 13 Mar 2024 11:28:34 +0100 Subject: [PATCH] [clang-tidy] Avoid overflow when dumping unsigned integer values Some options take the maximum unsigned integer value as default, but they are being dumped to a string as integers. This makes -dump-config write invalid '-1' values for these options. This change fixes this issue by using utostr if the option is unsigned. Change-Id: I551e6bc616071cf7aa10a8c0220d2076ed3d40e6 --- clang-tools-extra/clang-tidy/ClangTidyCheck.cpp | 6 ++ clang-tools-extra/clang-tidy/ClangTidyCheck.h| 9 +++-- clang-tools-extra/docs/ReleaseNotes.rst | 2 ++ .../infrastructure/Inputs/config-files/5/.clang-tidy | 4 .../test/clang-tidy/infrastructure/config-files.cpp | 8 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp index 3e926236adb451..710b361e16c0a7 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -139,6 +139,12 @@ void ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options, store(Options, LocalName, llvm::itostr(Value)); } +void ClangTidyCheck::OptionsView::storeUnsigned( +ClangTidyOptions::OptionMap &Options, StringRef LocalName, +uint64_t Value) const { + store(Options, LocalName, llvm::utostr(Value)); +} + template <> void ClangTidyCheck::OptionsView::store( ClangTidyOptions::OptionMap &Options, StringRef LocalName, diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h index 656a2f008f6e0e..7427aa9bf48f89 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h @@ -411,7 +411,10 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { std::enable_if_t> store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value) const { - storeInt(Options, LocalName, Value); + if constexpr (std::is_signed_v) +storeInt(Options, LocalName, Value); + else +storeUnsigned(Options, LocalName, Value); } /// Stores an option with the check-local name \p LocalName with @@ -422,7 +425,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, std::optional Value) const { if (Value) -storeInt(Options, LocalName, *Value); +store(Options, LocalName, *Value); else store(Options, LocalName, "none"); } @@ -470,6 +473,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName, int64_t Value) const; +void storeUnsigned(ClangTidyOptions::OptionMap &Options, + StringRef LocalName, uint64_t Value) const; std::string NamePrefix; const ClangTidyOptions::OptionMap &CheckOptions; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 9ef1d38d3c4560..27dabc0ed42f95 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -102,6 +102,8 @@ Improvements to clang-tidy similar fashion to what `-header-filter` does for header files. - Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes` to aid in clang-tidy and test development. +- Fixed bug where big values for unsigned check options overflowed into negative values + when being printed with ``--dump-config``. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy new file mode 100644 index 00..e33f0f8bb33218 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy @@ -0,0 +1,4 @@ +InheritParentConfig: true +Checks: 'misc-throw-by-value-catch-by-reference' +CheckOptions: + misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976' diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp index ab4f3becb7a9fc..cb0f0bc4d13308 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp @@ -64,3 +64,11 @@ // Validate that check options are printed in alphabetical ord
[clang] [Clang] Fix template alias default DWARF version (PR #89594)
https://github.com/Michael137 approved this pull request. https://github.com/llvm/llvm-project/pull/89594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] Stop eagerly reading files with diagnostic pragmas (PR #87442)
alexfh wrote: Hi Jan, we started seeing a compilation error in a (quite unusual, frankly speaking) code: ``` pigweed/pw_rpc/public/pw_rpc/internal/channel_list.h:24:10: fatal error: 'vector' file not found 24 | #include PW_RPC_DYNAMIC_CONTAINER_INCLUDE | ^~~~ pigweed/pw_rpc/public/pw_rpc/internal/config.h:207:42: note: expanded from macro 'PW_RPC_DYNAMIC_CONTAINER_INCLUDE' 207 | #define PW_RPC_DYNAMIC_CONTAINER_INCLUDE | ^~~~ :73:1: note: expanded from here 73 | | ^~~~ ``` The code is coming from here: https://pigweed.googlesource.com/pigweed/pigweed/+/refs/heads/main/pw_rpc/public/pw_rpc/internal/channel_list.h#24 This error only reproduces in our modules build. https://github.com/llvm/llvm-project/pull/87442 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 093171b - [Clang] Fix template alias default DWARF version (#89594)
Author: Orlando Cazalet-Hyams Date: 2024-04-22T12:01:21+01:00 New Revision: 093171b053838020a30c7710015c56c88d51c7ef URL: https://github.com/llvm/llvm-project/commit/093171b053838020a30c7710015c56c88d51c7ef DIFF: https://github.com/llvm/llvm-project/commit/093171b053838020a30c7710015c56c88d51c7ef.diff LOG: [Clang] Fix template alias default DWARF version (#89594) DW_TAG_template_alias DIEs were added in DWARFv4, not DWARFv5 Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/debug-options.c Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 97b4aa1c9b1d0a..f8a81ee8ab56bc 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4634,7 +4634,7 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, // Emit DW_TAG_template_alias for template aliases? True by default for SCE. bool UseDebugTemplateAlias = - DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 5; + DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4; if (const auto *DebugTemplateAlias = Args.getLastArg( options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) { // DW_TAG_template_alias is only supported from DWARFv5 but if a user diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c index b209c911d1ca2b..7d061410a229f0 100644 --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -456,9 +456,9 @@ // RUN: %clang -### -target x86_64 -c -g %s 2>&1 | FileCheck --check-prefix=FULL_TEMP_NAMES --implicit-check-not=debug-forward-template-params %s // FULL_TEMP_NAMES-NOT: -gsimple-template-names - Test -g[no-]template-alias (enabled by default with SCE debugger tuning and DWARFv5). + Test -g[no-]template-alias (enabled by default with SCE debugger tuning and DWARF version >= 4). // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS -// RUN: %clang -### -target x86_64 -c -gdwarf-4 -gsce %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS +// RUN: %clang -### -target x86_64 -c -gdwarf-3 -gsce %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce -gtemplate-alias %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gsce -gno-template-alias %s 2>&1 | FileCheck %s --check-prefixes=NO-TEMPLATE-ALIAS // RUN: %clang -### -target x86_64 -c -gdwarf-5 -gtemplate-alias %s 2>&1 | FileCheck %s --check-prefixes=TEMPLATE-ALIAS ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix template alias default DWARF version (PR #89594)
https://github.com/OCHyams closed https://github.com/llvm/llvm-project/pull/89594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] reland conditional operator (PR #89596)
https://github.com/martinboehme created https://github.com/llvm/llvm-project/pull/89596 - **Reapply "[clang][dataflow] Model conditional operator correctly." (#89577)** - **Fix failing tests for `TransferVisitor::VisitConditionalOperator().`** >From db32339492774cad8a6ceeb86ca8e13e6fef8c2a Mon Sep 17 00:00:00 2001 From: Martin Braenne Date: Mon, 22 Apr 2024 08:53:48 + Subject: [PATCH 1/2] Reapply "[clang][dataflow] Model conditional operator correctly." (#89577) This reverts commit 8ff6434546bcb4602bd079f4161f746956905c60. --- .../FlowSensitive/DataflowEnvironment.h | 15 + .../clang/Analysis/FlowSensitive/Transfer.h | 3 +- .../FlowSensitive/DataflowEnvironment.cpp | 46 ++--- clang/lib/Analysis/FlowSensitive/Transfer.cpp | 57 +++- .../TypeErasedDataflowAnalysis.cpp| 4 +- .../Analysis/FlowSensitive/TestingSupport.h | 4 +- .../Analysis/FlowSensitive/TransferTest.cpp | 66 +-- 7 files changed, 149 insertions(+), 46 deletions(-) diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index d50dba35f8264c..cdf89c7def2c91 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -244,6 +244,21 @@ class Environment { Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior); + /// Returns a value that approximates both `Val1` and `Val2`, or null if no + /// such value can be produced. + /// + /// `Env1` and `Env2` can be used to query child values and path condition + /// implications of `Val1` and `Val2` respectively. The joined value will be + /// produced in `JoinedEnv`. + /// + /// Requirements: + /// + /// `Val1` and `Val2` must model values of type `Type`. + static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1, + Value *Val2, const Environment &Env2, + Environment &JoinedEnv, + Environment::ValueModel &Model); + /// Widens the environment point-wise, using `PrevEnv` as needed to inform the /// approximation. /// diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h b/clang/include/clang/Analysis/FlowSensitive/Transfer.h index ed148250d8eb29..940025e02100f9 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h +++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h @@ -53,7 +53,8 @@ class StmtToEnvMap { /// Requirements: /// /// `S` must not be `ParenExpr` or `ExprWithCleanups`. -void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); +void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, + Environment::ValueModel &Model); } // namespace dataflow } // namespace clang diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 05395e07a7a68c..3cb656adcbdc0c 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -237,13 +237,8 @@ joinLocToVal(const llvm::MapVector &LocToVal, continue; assert(It->second != nullptr); -if (areEquivalentValues(*Val, *It->second)) { - Result.insert({Loc, Val}); - continue; -} - -if (Value *JoinedVal = joinDistinctValues( -Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) { +if (Value *JoinedVal = Environment::joinValues( +Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) { Result.insert({Loc, JoinedVal}); } } @@ -775,27 +770,16 @@ Environment Environment::join(const Environment &EnvA, const Environment &EnvB, JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal; JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc; - if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) { -// `ReturnVal` might not always get set -- for example if we have a return -// statement of the form `return some_other_func()` and we decide not to -// analyze `some_other_func()`. -// In this case, we can't say anything about the joined return value -- we -// don't simply want to propagate the return value that we do have, because -// it might not be the correct one. -// This occurs for example in the test `ContextSensitiveMutualRecursion`. + if (EnvA.CallStack.empty()) { JoinedEnv.ReturnVal = nullptr; - } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) { -JoinedEnv.ReturnVal = EnvA.ReturnVal; } else { -assert(!EnvA.CallStack.empty()); // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this // cast. auto *Func = dyn_cast(EnvA.CallStack.back()); assert(Func != nullptr); -if (Value *Jo
[clang] reland conditional operator (PR #89596)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (martinboehme) Changes - **Reapply "[clang][dataflow] Model conditional operator correctly." (#89577)** - **Fix failing tests for `TransferVisitor::VisitConditionalOperator().`** --- Full diff: https://github.com/llvm/llvm-project/pull/89596.diff 7 Files Affected: - (modified) clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h (+15) - (modified) clang/include/clang/Analysis/FlowSensitive/Transfer.h (+2-1) - (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+24-22) - (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+43-15) - (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp (+2-2) - (modified) clang/unittests/Analysis/FlowSensitive/TestingSupport.h (+2-2) - (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+63-5) ``diff diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index d50dba35f8264c..cdf89c7def2c91 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -244,6 +244,21 @@ class Environment { Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior); + /// Returns a value that approximates both `Val1` and `Val2`, or null if no + /// such value can be produced. + /// + /// `Env1` and `Env2` can be used to query child values and path condition + /// implications of `Val1` and `Val2` respectively. The joined value will be + /// produced in `JoinedEnv`. + /// + /// Requirements: + /// + /// `Val1` and `Val2` must model values of type `Type`. + static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1, + Value *Val2, const Environment &Env2, + Environment &JoinedEnv, + Environment::ValueModel &Model); + /// Widens the environment point-wise, using `PrevEnv` as needed to inform the /// approximation. /// diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h b/clang/include/clang/Analysis/FlowSensitive/Transfer.h index ed148250d8eb29..940025e02100f9 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h +++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h @@ -53,7 +53,8 @@ class StmtToEnvMap { /// Requirements: /// /// `S` must not be `ParenExpr` or `ExprWithCleanups`. -void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); +void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, + Environment::ValueModel &Model); } // namespace dataflow } // namespace clang diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 05395e07a7a68c..3cb656adcbdc0c 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -237,13 +237,8 @@ joinLocToVal(const llvm::MapVector &LocToVal, continue; assert(It->second != nullptr); -if (areEquivalentValues(*Val, *It->second)) { - Result.insert({Loc, Val}); - continue; -} - -if (Value *JoinedVal = joinDistinctValues( -Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) { +if (Value *JoinedVal = Environment::joinValues( +Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) { Result.insert({Loc, JoinedVal}); } } @@ -775,27 +770,16 @@ Environment Environment::join(const Environment &EnvA, const Environment &EnvB, JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal; JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc; - if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) { -// `ReturnVal` might not always get set -- for example if we have a return -// statement of the form `return some_other_func()` and we decide not to -// analyze `some_other_func()`. -// In this case, we can't say anything about the joined return value -- we -// don't simply want to propagate the return value that we do have, because -// it might not be the correct one. -// This occurs for example in the test `ContextSensitiveMutualRecursion`. + if (EnvA.CallStack.empty()) { JoinedEnv.ReturnVal = nullptr; - } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) { -JoinedEnv.ReturnVal = EnvA.ReturnVal; } else { -assert(!EnvA.CallStack.empty()); // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this // cast. auto *Func = dyn_cast(EnvA.CallStack.back()); assert(Func != nullptr); -if (Value *JoinedVal = -joinDistinctValues(Func->getReturnType(), *EnvA.ReturnVal, EnvA, - *EnvB.R
[clang] Reapply "[clang][dataflow] Model conditional operator correctly." with fixes (PR #89596)
https://github.com/martinboehme edited https://github.com/llvm/llvm-project/pull/89596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[clang][dataflow] Model conditional operator correctly." with fixes (PR #89596)
martinboehme wrote: I reverted https://github.com/llvm/llvm-project/pull/89213 beause it was causing buildbots to fail with assertion failures. Embarrassingly, it turns out I had been running tests locally in `Release` mode, i.e. with `assert()` compiled away. This PR re-lands #89213 with fixes for the failing assertions. https://github.com/llvm/llvm-project/pull/89596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[clang][dataflow] Model conditional operator correctly." with fixes (PR #89596)
https://github.com/martinboehme edited https://github.com/llvm/llvm-project/pull/89596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Don't wrap immediate invocations in ConstantExprs within constexpr initializers (PR #89565)
@@ -2554,16 +2554,26 @@ Decl *Parser::ParseDeclarationAfterDeclarator( return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo); } +static bool isConstexprVariable(const Decl *D) { + if (const VarDecl *Var = dyn_cast_or_null(D)) +return Var->isConstexpr(); + + return false; +} + Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( Declarator &D, const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) { // RAII type used to track whether we're inside an initializer. struct InitializerScopeRAII { Parser &P; Declarator &D; Decl *ThisDecl; +llvm::SaveAndRestore ConstantContext; InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl) -: P(P), D(D), ThisDecl(ThisDecl) { +: P(P), D(D), ThisDecl(ThisDecl), + ConstantContext(P.Actions.isConstantEvaluatedOverride, + isConstexprVariable(ThisDecl)) { cor3ntin wrote: I think we would be better of pushing an actual ExpressionEvaluationContextRecord here https://github.com/llvm/llvm-project/pull/89565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Don't wrap immediate invocations in ConstantExprs within constexpr initializers (PR #89565)
@@ -2554,16 +2554,26 @@ Decl *Parser::ParseDeclarationAfterDeclarator( return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo); } +static bool isConstexprVariable(const Decl *D) { + if (const VarDecl *Var = dyn_cast_or_null(D)) cor3ntin wrote: ```suggestion if (const VarDecl *Var = dyn_cast(D)) ``` `D` can never be null here, right? Beside I think the recommended practice would be to use `if_present` rather than `or_null`, the later being deprecated https://github.com/llvm/llvm-project/pull/89565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Don't wrap immediate invocations in ConstantExprs within constexpr initializers (PR #89565)
@@ -1032,17 +1043,15 @@ int f() { namespace GH57682 { void test() { - constexpr auto l1 = []() consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \ - // expected-note 2{{declared here}} + constexpr auto l1 = []() consteval { // expected-note {{declared here}} return 3; }; constexpr int (*f1)(void) = l1; // expected-error {{constexpr variable 'f1' must be initialized by a constant expression}} \ // expected-note {{pointer to a consteval declaration is not a constant expression}} - constexpr auto lstatic = []() static consteval { // expected-error {{cannot take address of consteval call operator of '(lambda at}} \ - // expected-note 2{{declared here}} \ - // expected-warning {{extension}} + constexpr auto lstatic = []() static consteval { // expected-note {{declared here}} \ + // expected-warning {{extension}} cor3ntin wrote: Do we have existing tests for assigning the address of a lambda to a non constexpr variable? https://github.com/llvm/llvm-project/pull/89565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OpenMP] Migrate GPU Reductions CodeGen from Clang to OMPIRBuilder (PR #80343)
TIFitis wrote: > This patch is huge, and just skimming over it shows various places that could > be split off, and others that should not make it to the review stage > (commented out code). Please update. Hi, thanks for talking the time out to review the patch. I've addressed the comments you made and also fixed the build issues. It now builds cleanly again and passes all checks. I'm not sure however on how to split the patch, as we definitely need all the pieces to pass the CI tests. I hope it isn't too much of a burden to review the patch. Thanks. https://github.com/llvm/llvm-project/pull/80343 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)
cor3ntin wrote: > Regarding the __is_deducible type trait, GCC also provides one, but it was > hidden from users and only used for internal CTAD implementation. I'm not > sure if we should follow the same strategy in clang, ideas? I have mixed feeling. What do you think @AaronBallman ? https://github.com/llvm/llvm-project/pull/89358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)
@@ -5,13 +5,18 @@ // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -S -emit-llvm -o - -mbranch-protection=pac-ret+b-key %s | FileCheck %s --check-prefix=CHECK --check-prefix=PART // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -S -emit-llvm -o - -mbranch-protection=bti %s | FileCheck %s --check-prefix=CHECK --check-prefix=BTE -// Check there are no branch protection function attributes +// Check there is branch protection function attributes tmatheson-arm wrote: ```suggestion // Check there are branch protection function attributes ``` https://github.com/llvm/llvm-project/pull/82819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang]MveEmitter: Pass Args as a const reference (PR #89551)
https://github.com/aniplcc ready_for_review https://github.com/llvm/llvm-project/pull/89551 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang]MveEmitter: Pass Args as a const reference (PR #89551)
llvmbot wrote: @llvm/pr-subscribers-clang Author: aniplcc (aniplcc) Changes Closes #89192. Also updated with review patches. In continuation of: `https://github.com/llvm/llvm-project/pull/89202` [Closed due to a bad rebase] --- Full diff: https://github.com/llvm/llvm-project/pull/89551.diff 1 Files Affected: - (modified) clang/utils/TableGen/MveEmitter.cpp (+6-5) ``diff diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp index 88e7b6e8546595..c455071ed9da7c 100644 --- a/clang/utils/TableGen/MveEmitter.cpp +++ b/clang/utils/TableGen/MveEmitter.cpp @@ -658,9 +658,9 @@ class IRBuilderResult : public Result { std::vector Args; std::set AddressArgs; std::map IntegerArgs; - IRBuilderResult(StringRef CallPrefix, std::vector Args, - std::set AddressArgs, - std::map IntegerArgs) + IRBuilderResult(StringRef CallPrefix, const std::vector &Args, + const std::set &AddressArgs, + const std::map &IntegerArgs) : CallPrefix(CallPrefix), Args(Args), AddressArgs(AddressArgs), IntegerArgs(IntegerArgs) {} void genCode(raw_ostream &OS, @@ -727,8 +727,9 @@ class IRIntrinsicResult : public Result { std::string IntrinsicID; std::vector ParamTypes; std::vector Args; - IRIntrinsicResult(StringRef IntrinsicID, std::vector ParamTypes, -std::vector Args) + IRIntrinsicResult(StringRef IntrinsicID, +const std::vector &ParamTypes, +const std::vector &Args) : IntrinsicID(std::string(IntrinsicID)), ParamTypes(ParamTypes), Args(Args) {} void genCode(raw_ostream &OS, `` https://github.com/llvm/llvm-project/pull/89551 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU][WIP] Add support for i64/f64 readlane, writelane and readfirstlane operations. (PR #89217)
@@ -4822,6 +4822,111 @@ static MachineBasicBlock *lowerWaveReduce(MachineInstr &MI, return RetBB; } +static MachineBasicBlock *lowerPseudoLaneOp(MachineInstr &MI, vikramRH wrote: @arsenm, would "PreISelIntrinsicLowering" be a proper place for this ? https://github.com/llvm/llvm-project/pull/89217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)
AaronBallman wrote: > @AaronBallman Did you read > https://discourse.llvm.org/t/rfc-c-17-hardware-constructive-destructive-interference-size/48674/42 > ? I want to make sure we do abide by it and it's unclear a consensus was > ever formed or called Yes, I looked at the thread and while there are very valid criticisms of what was standardized, the end result is still that we need this support 1) for Clang to support libc++ implementing a C++17 feature for conformance reasons and 2) for GCC compatibility (re: the macros that are exposed). We can either let libc++ solve this problem entirely on their own and not aim for GCC compatibility here, or we can bite the bullet and do our best. Given that GCC exposes these macros, I think it makes more sense for Clang to predefine them than for libc++ to try to do this from their end. https://github.com/llvm/llvm-project/pull/89446 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)
AaronBallman wrote: > Sorry, I know nothing about it. But it looks to me it's to match with GCC, > why don't borrow the value from GCC as a beginning? Because the values depend on the target and the compiler options picked. I don't have that information myself, and given how many targets and options we support, I am hoping target owners can help rather than having to guess. https://github.com/llvm/llvm-project/pull/89446 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541, #88311)" (PR #88731)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/88731 >From 9b54d77ef690a69b94ab2985f62fa1a281259796 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Mon, 15 Apr 2024 09:17:39 -0400 Subject: [PATCH 1/5] Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541, #88311)" Reapplies #87541 and #88311 addressing the bug which caused expressions naming overload sets to be incorrectly rebuilt, as well as the bug which caused base class members to always be treated as overload sets. --- clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/AST/ExprCXX.h | 3 +- clang/include/clang/Sema/Sema.h | 16 +- clang/lib/AST/ASTImporter.cpp | 2 +- clang/lib/AST/ExprCXX.cpp | 9 +- clang/lib/Sema/SemaCoroutine.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/lib/Sema/SemaExpr.cpp | 38 +--- clang/lib/Sema/SemaExprCXX.cpp| 61 +++--- clang/lib/Sema/SemaExprMember.cpp | 63 -- clang/lib/Sema/SemaOpenMP.cpp | 6 +- clang/lib/Sema/SemaOverload.cpp | 3 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 8 + clang/lib/Sema/TreeTransform.h| 82 --- .../SemaTemplate/instantiate-using-decl.cpp | 2 +- ...ms-function-specialization-class-scope.cpp | 201 +- 16 files changed, 376 insertions(+), 124 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c44f238e33846b..db5830a6371583 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -538,6 +538,8 @@ Bug Fixes to C++ Support - Fix an issue caused by not handling invalid cases when substituting into the parameter mapping of a constraint. Fixes (#GH86757). - Fixed a bug that prevented member function templates of class templates declared with a deduced return type from being explicitly specialized for a given implicit instantiation of the class template. +- Fixed a crash when ``this`` is used in a dependent class scope function template specialization + that instantiates to a static member function. - Fix crash when inheriting from a cv-qualified type. Fixes #GH35603 - Fix a crash when the using enum declaration uses an anonymous enumeration. Fixes (#GH86790). diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index d28e5c3a78ee4b..4d5293566580ae 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -3219,7 +3219,8 @@ class UnresolvedLookupExpr final Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, - UnresolvedSetIterator Begin, UnresolvedSetIterator End); + UnresolvedSetIterator Begin, UnresolvedSetIterator End, + bool KnownDependent); // After canonicalization, there may be dependent template arguments in // CanonicalConverted But none of Args is dependent. When any of diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index ffc58c681cdcd5..452af06dff9905 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -5429,7 +5429,8 @@ class Sema final : public SemaBase { ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, - bool AcceptInvalidDecl = false); + bool AcceptInvalidDecl = false, + bool NeedUnresolved = false); ExprResult BuildDeclarationNameExpr( const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, NamedDecl *FoundD = nullptr, @@ -6527,7 +6528,10 @@ class Sema final : public SemaBase { SourceLocation RParenLoc); ActOnCXXThis - Parse 'this' pointer. - ExprResult ActOnCXXThis(SourceLocation loc); + ExprResult ActOnCXXThis(SourceLocation Loc); + + /// Check whether the type of 'this' is valid in the current context. + bool CheckCXXThisType(SourceLocation Loc, QualType Type); /// Build a CXXThisExpr and mark it referenced in the current context. Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); @@ -6949,10 +6953,14 @@ class Sema final : public SemaBase { ///@{ public: + /// Check whether an expression might be an implicit class member access. + bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R, + bool IsAddressOfOperand); + ExprResult BuildPossibleImplicitMemberExpr( const CXXScopeSpec &SS, SourceLocation Temp
[clang] [AST] Dump argument types for TypeTraitExpr. (PR #89370)
hokein wrote: > It seems to me that exposing these as children is the better option here, > right? That way it would better model a CallExpr or template type-trait, and > would work in our StmtProfiler et-al. Agree that exposing them as children is better. However, we encounter an implementation limitation. For `Expr` subclasses, their children must be a `Stmt`. The `TypeTraitExpr` doesn't meet this requirement because its arguments are types `TypeSourceInfo`. https://github.com/llvm/llvm-project/pull/89370 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)
AaronBallman wrote: > For SystemZ the correct value is 256. Thanks! Double-checking: for both constructive and destructive? > In general I agree it makes sense to look at the GCC implementation as a > source of reasonable values. Also, I think there probably should be no > generic default value at all - it there is no platform-specific value known, > it seems better to not define those values rather than define them to some > incorrect value ... On the one hand, I agree. But then libc++ will still have to pick default values to expose (these are `constexpr size_t` variables in libc++ rather than macros or `std::optional` values), so that just moves the problem elsewhere. Also, as best I can tell, that doesn't seem to be how GCC behaves (at least, from trying various GCC flavors on Compiler Explorer). https://github.com/llvm/llvm-project/pull/89446 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang]MveEmitter: Pass Args as a const reference (PR #89551)
https://github.com/RKSimon approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/89551 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Refactor `PropagateResultObject()` with a switch statement. (PR #88865)
martinboehme wrote: First of all, a followup: I should of course have noticed the failling CI tests, but a contributing factor was that I was locally running tests in `Release` mode, i.e. with `assert()` compiled out. I've now looked at why tests fail, and it is because when using `E->getStmtClass()`, we need to enumerate all possible sub-classes that we're interested in, whereas when using `isa` / `dyn_cast`, it's enough to switch on the base class. In practical terms, this means that to get complete coverage for what used to be covered by `isa(E)`, we need to check not only for `CXXConstructExprClass` but also `CXXTemporaryObjectExprClass`. To get coverage for what used to be covered by `isa(E)`, we need to check not only for `CallExprClass` but also for `CXXMemberCallExprClass` and `CXXOperatorCallExprClass`. In my mind, this shifts the tradeoff: Having to enumerate all possible sub-classes adds verbosity and carries the risk of forgetting a subclass, particularly if subclasses are added in the future. I would therefore propose to stay with the existing implementation as I'm no longer convinced that the switch statement is the better option. https://github.com/llvm/llvm-project/pull/88865 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)
=?utf-8?q?Balázs_Kéri?= , =?utf-8?q?Balázs_Kéri?= , =?utf-8?q?Balázs_Kéri?= Message-ID: In-Reply-To: https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/89247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)
=?utf-8?q?Balázs_Kéri?= , =?utf-8?q?Balázs_Kéri?= , =?utf-8?q?Balázs_Kéri?= Message-ID: In-Reply-To: https://github.com/NagyDonat approved this pull request. LGTM, the diff is clean and the results on open source projects are good enough for a non-alpha checker. Note that the direct codechecker links show the pedantic-only results which are... well, pedantic. Turning off the comparison and filtering for "alpha.unix.Stream" shows the default behavior of the checker, which is reasonable. On `vim` even non-pedantic mode produces dozens of reports, but that's because the code assumes that the input files are well-formed (no EOF in the middle of a record) -- and this checker should definitely report that kind of assumption. (If the developers don't want to see this kind of warning, they can disable this checker.) I think that this PR can be merged as it is now, but let's wait a week and see whether @haoNoQ or @Xazax-hun have any suggestions or objections. https://github.com/llvm/llvm-project/pull/89247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits