[clang] 2ce662c - [NFC] Remove needless nullchecks.

2023-07-20 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-20T23:33:33-07:00
New Revision: 2ce662c5d5969255b6779eafe4b309dc57e2d3a6

URL: 
https://github.com/llvm/llvm-project/commit/2ce662c5d5969255b6779eafe4b309dc57e2d3a6
DIFF: 
https://github.com/llvm/llvm-project/commit/2ce662c5d5969255b6779eafe4b309dc57e2d3a6.diff

LOG: [NFC] Remove needless nullchecks.

Differential Revision: https://reviews.llvm.org/D155774

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 2d0d40b1994863..ef49349053b977 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5234,7 +5234,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
   // Is accessible from all the threads within the grid and from the host
   // through the runtime library (cudaGetSymbolAddress() / cudaGetSymbolSize()
   // / cudaMemcpyToSymbol() / cudaMemcpyFromSymbol())."
-  if (GV && LangOpts.CUDA) {
+  if (LangOpts.CUDA) {
 if (LangOpts.CUDAIsDevice) {
   if (Linkage != llvm::GlobalValue::InternalLinkage &&
   (D->hasAttr() || D->hasAttr() ||

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 4f713fe6e4ad41..5a1b0a918caab1 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -2475,7 +2475,7 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind 
LeadingToken,
   bool NeedsFramework = false;
   Map.addUnresolvedHeader(ActiveModule, std::move(Header), NeedsFramework);
 
-  if (NeedsFramework && ActiveModule)
+  if (NeedsFramework)
 Diags.Report(CurrModuleDeclLoc, diag::note_mmap_add_framework_keyword)
   << ActiveModule->getFullModuleName()
   << FixItHint::CreateReplacement(CurrModuleDeclLoc, "framework module");

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 87e0939d56ceb2..2a7ae730a9084f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10926,11 +10926,9 @@ static bool tryGCCVectorConvertAndSplat(Sema &S, 
ExprResult *Scalar,
 return true;
 
   // Adjust scalar if desired.
-  if (Scalar) {
-if (ScalarCast != CK_NoOp)
-  *Scalar = S.ImpCastExprToType(Scalar->get(), VectorEltTy, ScalarCast);
-*Scalar = S.ImpCastExprToType(Scalar->get(), VectorTy, CK_VectorSplat);
-  }
+  if (ScalarCast != CK_NoOp)
+*Scalar = S.ImpCastExprToType(Scalar->get(), VectorEltTy, ScalarCast);
+  *Scalar = S.ImpCastExprToType(Scalar->get(), VectorTy, CK_VectorSplat);
   return false;
 }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8ac137a - [NFC] Add checks for self-assignment.

2023-07-24 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-24T00:38:08-07:00
New Revision: 8ac137acefc01caf636db5f95eb0977c97def1ba

URL: 
https://github.com/llvm/llvm-project/commit/8ac137acefc01caf636db5f95eb0977c97def1ba
DIFF: 
https://github.com/llvm/llvm-project/commit/8ac137acefc01caf636db5f95eb0977c97def1ba.diff

LOG: [NFC] Add checks for self-assignment.

Differential Revision: https://reviews.llvm.org/D155776

Added: 


Modified: 
clang/lib/AST/APValue.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/Interpreter/Value.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 5b0a5e256e411a..7bbde6d065316e 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -390,11 +390,13 @@ APValue &APValue::operator=(const APValue &RHS) {
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != RHS) {
+if (Kind != None && Kind != Indeterminate)
+  DestroyDataAndMakeUninit();
+Kind = RHS.Kind;
+Data = RHS.Data;
+RHS.Kind = None;
+  }
   return *this;
 }
 

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 58ee6dd64c4fc3..5b089f3330c42b 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,10 @@ class ApplyDebugLocation {
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-CGF = Other.CGF;
-Other.CGF = nullptr;
+if (this != Other) {
+  CGF = Other.CGF;
+  Other.CGF = nullptr;
+}
 return *this;
   }
 

diff  --git a/clang/lib/Interpreter/Value.cpp b/clang/lib/Interpreter/Value.cpp
index 6d0eaf1b82e108..68adfc268261af 100644
--- a/clang/lib/Interpreter/Value.cpp
+++ b/clang/lib/Interpreter/Value.cpp
@@ -201,16 +201,17 @@ Value &Value::operator=(const Value &RHS) {
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (IsManuallyAlloc)
-ValueStorage::getFromPayload(getPtr())->Release();
+  if (this != RHS) {
+if (IsManuallyAlloc)
+  ValueStorage::getFromPayload(getPtr())->Release();
 
-  Interp = std::exchange(RHS.Interp, nullptr);
-  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
-
-  Data = RHS.Data;
+Interp = std::exchange(RHS.Interp, nullptr);
+OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
 
+Data = RHS.Data;
+  }
   return *this;
 }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 235390d - [NFC] Avoid potential dereferencing of nullptr.

2023-07-31 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-31T08:33:26-07:00
New Revision: 235390d930be41c32c71f877d90470fc83e2cb89

URL: 
https://github.com/llvm/llvm-project/commit/235390d930be41c32c71f877d90470fc83e2cb89
DIFF: 
https://github.com/llvm/llvm-project/commit/235390d930be41c32c71f877d90470fc83e2cb89.diff

LOG: [NFC] Avoid potential dereferencing of nullptr.

Differential Revision: https://reviews.llvm.org/D156274

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index f08286a0d4baef..16f0d90451f7ad 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1656,6 +1656,7 @@ void CXXNameMangler::mangleUnqualifiedName(
   // Otherwise, use the complete destructor name. This is relevant if a
   // class with a destructor is declared within a destructor.
   mangleCXXDtorType(Dtor_Complete);
+assert(ND);
 writeAbiTags(ND, AdditionalAbiTags);
 break;
 

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index b5d29b2e956c3d..476baad734f70e 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6601,7 +6601,7 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec 
&SS,
   // The "template" keyword can follow "::" in the grammar, but only
   // put it into the grammar if the nested-name-specifier is dependent.
   // FIXME: results is always empty, this appears to be dead.
-  if (!Results.empty() && NNS->isDependent())
+  if (!Results.empty() && NNS && NNS->isDependent())
 Results.AddResult("template");
 
   // If the scope is a concept-constrained type parameter, infer nested



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fd857f7 - [NFC] Initialize pointer fields and remove needless null check.

2023-07-10 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-10T11:32:13-07:00
New Revision: fd857f786f61620c370d132fe9ba1b5608bb4f50

URL: 
https://github.com/llvm/llvm-project/commit/fd857f786f61620c370d132fe9ba1b5608bb4f50
DIFF: 
https://github.com/llvm/llvm-project/commit/fd857f786f61620c370d132fe9ba1b5608bb4f50.diff

LOG: [NFC] Initialize pointer fields and remove needless null check.

Reviewed here: https://reviews.llvm.org/D153589

Added: 


Modified: 
clang/lib/Analysis/CFG.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/lib/Lex/PPExpressions.cpp
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Removed: 




diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index b0f44ec0edcbbb..3f2367fafc88f7 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -4152,7 +4152,7 @@ CFGBlock *CFGBuilder::VisitCXXTypeidExpr(CXXTypeidExpr 
*S, AddStmtChoice asc) {
   //   operand. [...]
   // We add only potentially evaluated statements to the block to avoid
   // CFG generation for unevaluated operands.
-  if (S && !S->isTypeDependent() && S->isPotentiallyEvaluated())
+  if (!S->isTypeDependent() && S->isPotentiallyEvaluated())
 return VisitChildren(S);
 
   // Return block without CFG for unevaluated operands.

diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index c7b193e34ea0a3..09b6c3ac6adf41 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -46,17 +46,13 @@ namespace {
 /// types and the function declaration into a module if they're not used, and
 /// avoids constructing the type more than once if it's used more than once.
 class LazyRuntimeFunction {
-  CodeGenModule *CGM;
-  llvm::FunctionType *FTy;
-  const char *FunctionName;
-  llvm::FunctionCallee Function;
+  CodeGenModule *CGM = nullptr;
+  llvm::FunctionType *FTy = nullptr;
+  const char *FunctionName = nullptr;
+  llvm::FunctionCallee Function = nullptr;
 
 public:
-  /// Constructor leaves this class uninitialized, because it is intended to
-  /// be used as a field in another class and not all of the types that are
-  /// used as arguments will necessarily be available at construction time.
-  LazyRuntimeFunction()
-  : CGM(nullptr), FunctionName(nullptr), Function(nullptr) {}
+  LazyRuntimeFunction() = default;
 
   /// Initialises the lazy function with the name, return type, and the types
   /// of the arguments.

diff  --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 9650ce1a9c1583..311d879b0a0881 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -306,7 +306,7 @@ class UnwrappedLineParser {
   // Since the next token might already be in a new unwrapped line, we need to
   // store the comments belonging to that token.
   SmallVector CommentsBeforeNextToken;
-  FormatToken *FormatTok;
+  FormatToken *FormatTok = nullptr;
   bool MustBreakBeforeNextToken;
 
   // The parsed lines. Only added to through \c CurrentLines.

diff  --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index 6c935148f40726..7c41dd510d2dba 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -44,7 +44,7 @@ namespace {
 /// conditional and the source range covered by it.
 class PPValue {
   SourceRange Range;
-  IdentifierInfo *II;
+  IdentifierInfo *II = nullptr;
 
 public:
   llvm::APSInt Val;

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 1bf6592ee6d8e0..51ae0506466a7d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -84,7 +84,7 @@ class CStringChecker : public Checker< eval::Call,
   mutable std::unique_ptr BT_Null, BT_Bounds, BT_Overlap,
   BT_NotCString, BT_AdditionOverflow, BT_UninitRead;
 
-  mutable const char *CurrentFunctionDescription;
+  mutable const char *CurrentFunctionDescription = nullptr;
 
 public:
   /// The filter is used to filter out the diagnostics which are not enabled by



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5942ae8 - [NFC] Initialize class member pointers to nullptr.

2023-07-10 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-10T11:38:55-07:00
New Revision: 5942ae8681db20822ac3e0b94cf8089d30647a39

URL: 
https://github.com/llvm/llvm-project/commit/5942ae8681db20822ac3e0b94cf8089d30647a39
DIFF: 
https://github.com/llvm/llvm-project/commit/5942ae8681db20822ac3e0b94cf8089d30647a39.diff

LOG: [NFC] Initialize class member pointers to nullptr.

Reviewed here: https://reviews.llvm.org/D153926

Added: 


Modified: 
clang/include/clang/AST/RawCommentList.h
clang/include/clang/AST/Redeclarable.h
clang/include/clang/CodeGen/CodeGenAction.h
clang/include/clang/Sema/HLSLExternalSemaSource.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Format/SortJavaScriptImports.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RawCommentList.h 
b/clang/include/clang/AST/RawCommentList.h
index a293e219e25020..2f44a77d4503d3 100644
--- a/clang/include/clang/AST/RawCommentList.h
+++ b/clang/include/clang/AST/RawCommentList.h
@@ -173,7 +173,7 @@ class RawComment {
   SourceRange Range;
 
   mutable StringRef RawText;
-  mutable const char *BriefText;
+  mutable const char *BriefText = nullptr;
 
   mutable bool RawTextValid : 1;   ///< True if RawText is valid
   mutable bool BriefTextValid : 1; ///< True if BriefText is valid

diff  --git a/clang/include/clang/AST/Redeclarable.h 
b/clang/include/clang/AST/Redeclarable.h
index 58ec07973920cb..091bb886f2d496 100644
--- a/clang/include/clang/AST/Redeclarable.h
+++ b/clang/include/clang/AST/Redeclarable.h
@@ -240,7 +240,7 @@ class Redeclarable {
   class redecl_iterator {
 /// Current - The current declaration.
 decl_type *Current = nullptr;
-decl_type *Starter;
+decl_type *Starter = nullptr;
 bool PassedFirst = false;
 
   public:

diff  --git a/clang/include/clang/CodeGen/CodeGenAction.h 
b/clang/include/clang/CodeGen/CodeGenAction.h
index 821e80919fc849..7ad2988e589eb2 100644
--- a/clang/include/clang/CodeGen/CodeGenAction.h
+++ b/clang/include/clang/CodeGen/CodeGenAction.h
@@ -83,7 +83,7 @@ class CodeGenAction : public ASTFrontendAction {
 
   CodeGenerator *getCodeGenerator() const;
 
-  BackendConsumer *BEConsumer;
+  BackendConsumer *BEConsumer = nullptr;
 };
 
 class EmitAssemblyAction : public CodeGenAction {

diff  --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 8531609bb9e0d6..4b6bc96f72e225 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -23,7 +23,7 @@ class Sema;
 class HLSLExternalSemaSource : public ExternalSemaSource {
   Sema *SemaPtr = nullptr;
   NamespaceDecl *HLSLNamespace = nullptr;
-  CXXRecordDecl *ResourceDecl;
+  CXXRecordDecl *ResourceDecl = nullptr;
 
   using CompletionFunction = std::function;
   llvm::DenseMap Completions;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6f413d1c9a6fa3..dbc071bf5cd838 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -943,7 +943,7 @@ class Sema final {
   class DelayedDiagnostics;
 
   class DelayedDiagnosticsState {
-sema::DelayedDiagnosticPool *SavedPool;
+sema::DelayedDiagnosticPool *SavedPool = nullptr;
 friend class Sema::DelayedDiagnostics;
   };
   typedef DelayedDiagnosticsState ParsingDeclState;

diff  --git a/clang/include/clang/Serialization/ModuleFile.h 
b/clang/include/clang/Serialization/ModuleFile.h
index e96f3ce06c2ceb..b632b4e3e7a7ce 100644
--- a/clang/include/clang/Serialization/ModuleFile.h
+++ b/clang/include/clang/Serialization/ModuleFile.h
@@ -196,7 +196,7 @@ class ModuleFile {
 
   /// The memory buffer that stores the data associated with
   /// this AST file, owned by the InMemoryModuleCache.
-  llvm::MemoryBuffer *Buffer;
+  llvm::MemoryBuffer *Buffer = nullptr;
 
   /// The size of this file, in bits.
   uint64_t SizeInBits = 0;

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index e52f44b61a9464..1debbbf57fe6b9 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -318,10 +318,10 @@ class CodeGenFunction : public CodeGenTypeCache {
 
   /// CurFuncDecl - Holds the Decl for the current outermost
   /// non-closure context.
-  const Decl *CurFuncDecl;
+  const Decl *CurFuncDecl = nullptr;
   /// CurCodeDecl - This is the inner-most code context, which includes blocks.
-  const Decl *CurCodeDecl;
-  const CGFunctionInfo *CurFnInfo;
+  const Decl *CurCodeDecl = nullptr;
+  const CGFunctionInfo *CurFnInfo = nullptr;
   QualType FnRetTy;
   llvm::Function *CurFn = nullptr;
 

[clang] e9877ec - [NFC] Initialize class member pointers to nullptr.

2023-07-12 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-12T11:04:38-07:00
New Revision: e9877eca408e3c266ca7ba8f05f6a907087e9e82

URL: 
https://github.com/llvm/llvm-project/commit/e9877eca408e3c266ca7ba8f05f6a907087e9e82
DIFF: 
https://github.com/llvm/llvm-project/commit/e9877eca408e3c266ca7ba8f05f6a907087e9e82.diff

LOG: [NFC] Initialize class member pointers to nullptr.

Fix clang-format issues in surrounding code.
Differential revision: https://reviews.llvm.org/D153892

Added: 


Modified: 
clang/lib/ARCMigrate/TransProperties.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/Frontend/ASTConsumers.cpp
clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp

Removed: 




diff  --git a/clang/lib/ARCMigrate/TransProperties.cpp 
b/clang/lib/ARCMigrate/TransProperties.cpp
index e5ccf1cf79b13a..6d1d950821a07c 100644
--- a/clang/lib/ARCMigrate/TransProperties.cpp
+++ b/clang/lib/ARCMigrate/TransProperties.cpp
@@ -45,7 +45,7 @@ namespace {
 class PropertiesRewriter {
   MigrationContext &MigrateCtx;
   MigrationPass &Pass;
-  ObjCImplementationDecl *CurImplD;
+  ObjCImplementationDecl *CurImplD = nullptr;
 
   enum PropActionKind {
 PropAction_None,

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 2da4eb772589f9..f0185d016d7163 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -583,7 +583,7 @@ namespace {
 /// LambdaCaptureFields - Mapping from captured variables/this to
 /// corresponding data members in the closure class.
 llvm::DenseMap LambdaCaptureFields;
-FieldDecl *LambdaThisCaptureField;
+FieldDecl *LambdaThisCaptureField = nullptr;
 
 CallStackFrame(EvalInfo &Info, SourceLocation CallLoc,
const FunctionDecl *Callee, const LValue *This,

diff  --git a/clang/lib/Frontend/ASTConsumers.cpp 
b/clang/lib/Frontend/ASTConsumers.cpp
index 96f5926c0d7edb..7b58eaa04df95a 100644
--- a/clang/lib/Frontend/ASTConsumers.cpp
+++ b/clang/lib/Frontend/ASTConsumers.cpp
@@ -183,21 +183,20 @@ std::unique_ptr 
clang::CreateASTDeclNodeLister() {
 /// ASTViewer - AST Visualization
 
 namespace {
-  class ASTViewer : public ASTConsumer {
-ASTContext *Context;
-  public:
-void Initialize(ASTContext &Context) override {
-  this->Context = &Context;
-}
+class ASTViewer : public ASTConsumer {
+  ASTContext *Context = nullptr;
 
-bool HandleTopLevelDecl(DeclGroupRef D) override {
-  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I)
-HandleTopLevelSingleDecl(*I);
-  return true;
-}
+public:
+  void Initialize(ASTContext &Context) override { this->Context = &Context; }
 
-void HandleTopLevelSingleDecl(Decl *D);
-  };
+  bool HandleTopLevelDecl(DeclGroupRef D) override {
+for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I)
+  HandleTopLevelSingleDecl(*I);
+return true;
+  }
+
+  void HandleTopLevelSingleDecl(Decl *D);
+};
 }
 
 void ASTViewer::HandleTopLevelSingleDecl(Decl *D) {

diff  --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index 80fd2e4d219496..abf9914f2ca4ed 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -29,7 +29,7 @@ namespace {
 class StackAddrEscapeChecker
 : public Checker,
  check::EndFunction> {
-  mutable IdentifierInfo *dispatch_semaphore_tII;
+  mutable IdentifierInfo *dispatch_semaphore_tII = nullptr;
   mutable std::unique_ptr BT_stackleak;
   mutable std::unique_ptr BT_returnstack;
   mutable std::unique_ptr BT_capturedstackasync;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 472232a - [NFC] Fix potential dereferencing of nullptr

2023-07-12 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-12T13:26:03-07:00
New Revision: 472232a80d036a00570cb3b0a9a261113859ea93

URL: 
https://github.com/llvm/llvm-project/commit/472232a80d036a00570cb3b0a9a261113859ea93
DIFF: 
https://github.com/llvm/llvm-project/commit/472232a80d036a00570cb3b0a9a261113859ea93.diff

LOG: [NFC] Fix potential dereferencing of nullptr

Differential Revision: https://reviews.llvm.org/D139148

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 89fd56fb660b8b..289643f690da4c 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6336,6 +6336,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
   // We're at the end of the line for C: it's either a write-back conversion
   // or it's a C assignment. There's no need to check anything else.
   if (!S.getLangOpts().CPlusPlus) {
+assert(Initializer && "Initializer must be non-null");
 // If allowed, check whether this is an Objective-C writeback conversion.
 if (allowObjCWritebackConversion &&
 tryObjCWritebackConversion(S, *this, Entity, Initializer)) {
@@ -6362,7 +6363,8 @@ void InitializationSequence::InitializeFrom(Sema &S,
 if (Kind.getKind() == InitializationKind::IK_Direct ||
 (Kind.getKind() == InitializationKind::IK_Copy &&
  (Context.hasSameUnqualifiedType(SourceType, DestType) ||
-  S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType 
{
+  (Initializer && S.IsDerivedFrom(Initializer->getBeginLoc(),
+  SourceType, DestType) {
   TryConstructorInitialization(S, Entity, Kind, Args, DestType, DestType,
*this);
 
@@ -6406,6 +6408,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
   //   function is used) to a derived class thereof are enumerated as
   //   described in 13.3.1.4, and the best one is chosen through
   //   overload resolution (13.3).
+  assert(Initializer && "Initializer must be non-null");
   TryUserDefinedConversion(S, DestType, Kind, Initializer, *this,
TopLevelOfInitList);
 }
@@ -6457,6 +6460,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
   //- Otherwise, if the source type is a (possibly cv-qualified) class
   //  type, conversion functions are considered.
   if (!SourceType.isNull() && SourceType->isRecordType()) {
+assert(Initializer && "Initializer must be non-null");
 // For a conversion to _Atomic(T) from either T or a class type derived
 // from T, initialize the T object then convert to _Atomic type.
 bool NeedAtomicConversion = false;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4ad8913 - [NFC] Add checks for self-assignment.

2023-08-24 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-08-24T09:20:58-07:00
New Revision: 4ad89131e0de9368bc41395d770e1923366deba1

URL: 
https://github.com/llvm/llvm-project/commit/4ad89131e0de9368bc41395d770e1923366deba1
DIFF: 
https://github.com/llvm/llvm-project/commit/4ad89131e0de9368bc41395d770e1923366deba1.diff

LOG: [NFC] Add checks for self-assignment.

Differential Revision: https://reviews.llvm.org/D155776

Added: 


Modified: 
clang/lib/AST/APValue.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/Interpreter/Value.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 5b0a5e256e411a..ef424215182280 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -390,11 +390,13 @@ APValue &APValue::operator=(const APValue &RHS) {
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != &RHS) {
+if (Kind != None && Kind != Indeterminate)
+  DestroyDataAndMakeUninit();
+Kind = RHS.Kind;
+Data = RHS.Data;
+RHS.Kind = None;
+  }
   return *this;
 }
 

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index b47a4934f0b1ba..ae12485850ca77 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -835,8 +835,10 @@ class ApplyDebugLocation {
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-CGF = Other.CGF;
-Other.CGF = nullptr;
+if (this != &Other) {
+  CGF = Other.CGF;
+  Other.CGF = nullptr;
+}
 return *this;
   }
 

diff  --git a/clang/lib/Interpreter/Value.cpp b/clang/lib/Interpreter/Value.cpp
index 6d0eaf1b82e108..1d6b2da087e9fb 100644
--- a/clang/lib/Interpreter/Value.cpp
+++ b/clang/lib/Interpreter/Value.cpp
@@ -201,16 +201,17 @@ Value &Value::operator=(const Value &RHS) {
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (IsManuallyAlloc)
-ValueStorage::getFromPayload(getPtr())->Release();
+  if (this != &RHS) {
+if (IsManuallyAlloc)
+  ValueStorage::getFromPayload(getPtr())->Release();
 
-  Interp = std::exchange(RHS.Interp, nullptr);
-  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
-
-  Data = RHS.Data;
+Interp = std::exchange(RHS.Interp, nullptr);
+OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
 
+Data = RHS.Data;
+  }
   return *this;
 }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bbcc7c5 - [NFC] Initialize member pointer and avoid potential null dereference

2023-08-25 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-08-25T11:35:44-07:00
New Revision: bbcc7c5614cd642c8e71b89a6655b097454d57ea

URL: 
https://github.com/llvm/llvm-project/commit/bbcc7c5614cd642c8e71b89a6655b097454d57ea
DIFF: 
https://github.com/llvm/llvm-project/commit/bbcc7c5614cd642c8e71b89a6655b097454d57ea.diff

LOG: [NFC] Initialize member pointer and avoid potential null dereference

Differential Revision: https://reviews.llvm.org/D158775

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/lib/Analysis/ThreadSafety.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index cfef45d2e8d689..180bd5add2e262 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -201,13 +201,14 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   return false;
   }
 
+  assert(S.Current);
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
   if (!S.checkingPotentialConstantExpression() || S.Current->Caller) {
 // Certain builtin functions are declared as func-name(...), so the
 // parameters are checked in Sema and only available through the CallExpr.
 // The interp::Function we create for them has 0 parameters, so we need to
 // remove them from the stack by checking the CallExpr.
-if (S.Current && S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
+if (S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
   popBuiltinArgs(S, PC);
 else
   S.Current->popArgs();

diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 087994e6ebd702..34260ac8f4e7d6 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1008,7 +1008,7 @@ class ThreadSafetyAnalyzer {
   threadSafety::SExprBuilder SxBuilder;
 
   ThreadSafetyHandler &Handler;
-  const CXXMethodDecl *CurrentMethod;
+  const CXXMethodDecl *CurrentMethod = nullptr;
   LocalVariableMap LocalVarMap;
   FactManager FactMan;
   std::vector BlockInfo;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6f2a865 - [NFC] Fix uninitalized member variable use in ASTReader::ParseTargetOptions()

2023-03-29 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-03-29T09:29:14-07:00
New Revision: 6f2a865d2f6bc426a61939a0a1acfcb25d5c1a18

URL: 
https://github.com/llvm/llvm-project/commit/6f2a865d2f6bc426a61939a0a1acfcb25d5c1a18
DIFF: 
https://github.com/llvm/llvm-project/commit/6f2a865d2f6bc426a61939a0a1acfcb25d5c1a18.diff

LOG: [NFC] Fix uninitalized member variable use in 
ASTReader::ParseTargetOptions()

Added: 


Modified: 
clang/include/clang/Basic/TargetOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetOptions.h 
b/clang/include/clang/Basic/TargetOptions.h
index f9e5cedbafcd1..9197282f3b566 100644
--- a/clang/include/clang/Basic/TargetOptions.h
+++ b/clang/include/clang/Basic/TargetOptions.h
@@ -45,7 +45,7 @@ class TargetOptions {
   std::string ABI;
 
   /// The EABI version to use
-  llvm::EABI EABIVersion;
+  llvm::EABI EABIVersion = llvm::EABI::Default;
 
   /// If given, the version string of the linker in use.
   std::string LinkerVersion;
@@ -88,7 +88,7 @@ class TargetOptions {
 COV_5 = 500,
   };
   /// \brief Code object version for AMDGPU.
-  CodeObjectVersionKind CodeObjectVersion;
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
 
   // The code model to be used as specified by the user. Corresponds to
   // CodeModel::Model enum defined in include/llvm/Support/CodeGen.h, plus



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d2fafa7 - [NFC] Fix potential dereferencing of nullptr.

2023-06-22 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-06-22T09:53:28-07:00
New Revision: d2fafa79ef08f9ef9cd0108a6caa7fc61a31bdeb

URL: 
https://github.com/llvm/llvm-project/commit/d2fafa79ef08f9ef9cd0108a6caa7fc61a31bdeb
DIFF: 
https://github.com/llvm/llvm-project/commit/d2fafa79ef08f9ef9cd0108a6caa7fc61a31bdeb.diff

LOG: [NFC] Fix potential dereferencing of nullptr.

Replace getAs with castAs and add assert if needed.
Differential revision: https://reviews.llvm.org/D153236

Added: 


Modified: 
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index e8984d298a29c..5df830e5bee6d 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2438,6 +2438,9 @@ ExprResult Sema::BuildClassMessageImplicit(QualType 
ReceiverType,
   if (!ReceiverType.isNull())
 receiverTypeInfo = Context.getTrivialTypeSourceInfo(ReceiverType);
 
+  assert(((isSuperReceiver && Loc.isValid()) || receiverTypeInfo) &&
+ "Either the super receiver location needs to be valid or the receiver 
"
+ "needs valid type source information");
   return BuildClassMessage(receiverTypeInfo, ReceiverType,
   /*SuperLoc=*/isSuperReceiver ? Loc : 
SourceLocation(),
Sel, Method, Loc, Loc, Loc, Args,

diff  --git a/clang/lib/Sema/SemaObjCProperty.cpp 
b/clang/lib/Sema/SemaObjCProperty.cpp
index 3317bfce41192..7e5dc3a71cbba 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -1363,10 +1363,9 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
 if (!Context.hasSameType(PropertyIvarType, IvarType)) {
   if (isa(PropertyIvarType)
   && isa(IvarType))
-compat =
-  Context.canAssignObjCInterfaces(
-  
PropertyIvarType->getAs(),
-  IvarType->getAs());
+compat = Context.canAssignObjCInterfaces(
+PropertyIvarType->castAs(),
+IvarType->castAs());
   else {
 compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
  IvarType)

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 77a1ce866d5c7..838ec19fcb3be 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2708,8 +2708,8 @@ QualType Sema::BuildVectorType(QualType CurType, Expr 
*SizeExpr,
 return QualType();
   }
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  if (CurType->isBitIntType()) {
-unsigned NumBits = CurType->getAs()->getNumBits();
+  if (const auto *BIT = CurType->getAs()) {
+unsigned NumBits = BIT->getNumBits();
 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
   Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
   << (NumBits < 8);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0e444c5 - Remove dead conditionals

2023-06-13 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-06-13T09:48:20-07:00
New Revision: 0e444c57c85853c86e4f4c94d9a51fb459fd9922

URL: 
https://github.com/llvm/llvm-project/commit/0e444c57c85853c86e4f4c94d9a51fb459fd9922
DIFF: 
https://github.com/llvm/llvm-project/commit/0e444c57c85853c86e4f4c94d9a51fb459fd9922.diff

LOG: Remove dead conditionals

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/Sema/SemaOverload.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 319d6c52d1900..7fcfff062fda8 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -3809,15 +3809,9 @@ llvm::Constant *CGObjCMac::EmitIvarList(const 
ObjCImplementationDecl *ID,
   ivarList.fillPlaceholderWithInt(countSlot, ObjCTypes.IntTy, count);
 
   llvm::GlobalVariable *GV;
-  if (ForClass)
-GV =
-CreateMetadataVar("OBJC_CLASS_VARIABLES_" + ID->getName(), ivarList,
-  "__OBJC,__class_vars,regular,no_dead_strip",
-  CGM.getPointerAlign(), true);
-  else
-GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), 
ivarList,
-   "__OBJC,__instance_vars,regular,no_dead_strip",
-   CGM.getPointerAlign(), true);
+  GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), ivarList,
+ "__OBJC,__instance_vars,regular,no_dead_strip",
+ CGM.getPointerAlign(), true);
   return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy);
 }
 

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 68a7f81fffa56..108e2cf47437a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10864,8 +10864,8 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   if (FromExpr && isa(FromExpr)) {
 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_list_argument)
 << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc
-<< (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy
-<< ToTy << (unsigned)isObjectArgument << I + 1
+<< FromExpr->getSourceRange() << FromTy << ToTy
+<< (unsigned)isObjectArgument << I + 1
 << (Conv.Bad.Kind == BadConversionSequence::too_few_initializers ? 1
 : Conv.Bad.Kind == BadConversionSequence::too_many_initializers
 ? 2

diff  --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index cc0cab480be43..b4d5c256aa1a7 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2122,8 +2122,7 @@ CanonicalLoopInfo *OpenMPIRBuilder::createCanonicalLoop(
 // Avoid incrementing past stop since it could overflow.
 Value *CountIfTwo = Builder.CreateAdd(
 Builder.CreateUDiv(Builder.CreateSub(Span, One), Incr), One);
-Value *OneCmp = Builder.CreateICmp(
-InclusiveStop ? CmpInst::ICMP_ULT : CmpInst::ICMP_ULE, Span, Incr);
+Value *OneCmp = Builder.CreateICmp(CmpInst::ICMP_ULE, Span, Incr);
 CountIfLooping = Builder.CreateSelect(OneCmp, One, CountIfTwo);
   }
   Value *TripCount = Builder.CreateSelect(ZeroCmp, Zero, CountIfLooping,



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c2888cd - [NFC] Fix potential dereferencing of null return value.

2023-06-16 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-06-16T20:31:08-07:00
New Revision: c2888cddd5d98081fc82c51cb92be241144c6ffa

URL: 
https://github.com/llvm/llvm-project/commit/c2888cddd5d98081fc82c51cb92be241144c6ffa
DIFF: 
https://github.com/llvm/llvm-project/commit/c2888cddd5d98081fc82c51cb92be241144c6ffa.diff

LOG: [NFC] Fix potential dereferencing of null return value.

Replace getAs with castAs and add assert if needed.
Differential Revision: https://reviews.llvm.org/D152977

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d12909aa1edcc..8fb62dd13361f 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4141,8 +4141,8 @@ QualType ASTContext::getExtVectorType(QualType vecType,
   assert(vecType->isBuiltinType() || vecType->isDependentType() ||
  (vecType->isBitIntType() &&
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  llvm::isPowerOf2_32(vecType->getAs()->getNumBits()) &&
-  vecType->getAs()->getNumBits() >= 8));
+  llvm::isPowerOf2_32(vecType->castAs()->getNumBits()) &&
+  vecType->castAs()->getNumBits() >= 8));
 
   // Check if we've already instantiated a vector of this type.
   llvm::FoldingSetNodeID ID;

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index f62a29c02ee13..a6846b9c95207 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -458,6 +458,8 @@ class DefaultTemplateInstCallback : public 
TemplateInstantiationCallback {
   return;
 }
 
+assert(NamedCtx && "NamedCtx cannot be null");
+
 if (const auto *Decl = dyn_cast(NamedTemplate)) {
   OS << "unnamed function parameter " << Decl->getFunctionScopeIndex()
  << " ";

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 32118a370b9b3..77a1ce866d5c7 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2790,7 +2790,7 @@ QualType Sema::BuildExtVectorType(QualType T, Expr 
*ArraySize,
 
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
   if (T->isBitIntType()) {
-unsigned NumBits = T->getAs()->getNumBits();
+unsigned NumBits = T->castAs()->getNumBits();
 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
   Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
   << (NumBits < 8);

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
index 3fcf6f435a436..baf9618baccd4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -321,7 +321,9 @@ 
ObjCDeallocChecker::getInstanceSymbolFromIvarSymbol(SymbolRef IvarSym) const {
   if (!IvarRegion)
 return nullptr;
 
-  return IvarRegion->getSymbolicBase()->getSymbol();
+  const SymbolicRegion *SR = IvarRegion->getSymbolicBase();
+  assert(SR && "Symbolic base should not be nullptr");
+  return SR->getSymbol();
 }
 
 /// If we are in -dealloc or -dealloc is on the stack, handle the call if it is

diff  --git a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
index 929bd6bc3eb39..fa8572cf85edf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -291,6 +291,7 @@ ProgramStateRef 
PthreadLockChecker::resolvePossiblyDestroyedMutex(
   // Existence in DestroyRetVal ensures existence in LockMap.
   // Existence in Destroyed also ensures that the lock state for lockR is 
either
   // UntouchedAndPossiblyDestroyed or UnlockedAndPossiblyDestroyed.
+  assert(lstate);
   assert(lstate->isUntouchedAndPossiblyDestroyed() ||
  lstate->isUnlockedAndPossiblyDestroyed());
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4706a29 - Avoid setting tbaa on the store of return type of call to inline assembler.

2021-12-14 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2021-12-14T17:40:33-08:00
New Revision: 4706a297fb9ebe6af91ee2c92e5eb196dc2785f7

URL: 
https://github.com/llvm/llvm-project/commit/4706a297fb9ebe6af91ee2c92e5eb196dc2785f7
DIFF: 
https://github.com/llvm/llvm-project/commit/4706a297fb9ebe6af91ee2c92e5eb196dc2785f7.diff

LOG: Avoid setting tbaa on the store of return type of call to inline assembler.

In 32bit mode, attaching TBAA metadata to the store following the call
to inline assembler results in describing the wrong type by making a
fake lvalue(i.e., whatever the inline assembler happens to leave in
EAX:EDX.) Even if inline assembler somehow describes the correct type,
setting TBAA information on return type of call to inline assembler is
likely not correct, since TBAA rules need not apply to inline assembler.

Differential Revision: https://reviews.llvm.org/D115320

Added: 
clang/test/CodeGen/avoidTBAAonASMstore.cpp

Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index d399ff919cc39..ef0068cd3b0c9 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2454,7 +2454,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 const ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
 if (RetAI.isDirect() || RetAI.isExtend()) {
   // Make a fake lvalue for the return value slot.
-  LValue ReturnSlot = MakeAddrLValue(ReturnValue, FnRetTy);
+  LValue ReturnSlot = MakeAddrLValueWithoutTBAA(ReturnValue, FnRetTy);
   CGM.getTargetCodeGenInfo().addReturnRegisterOutputs(
   *this, ReturnSlot, Constraints, ResultRegTypes, ResultTruncRegTypes,
   ResultRegDests, AsmString, S.getNumOutputs());

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index ff5b6634da1c2..2fabeb2061937 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -2504,6 +2504,13 @@ class CodeGenFunction : public CodeGenTypeCache {
 BaseInfo, TBAAInfo);
   }
 
+  LValue
+  MakeAddrLValueWithoutTBAA(Address Addr, QualType T,
+AlignmentSource Source = AlignmentSource::Type) {
+return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
+TBAAAccessInfo());
+  }
+
   LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);
 

diff  --git a/clang/test/CodeGen/avoidTBAAonASMstore.cpp 
b/clang/test/CodeGen/avoidTBAAonASMstore.cpp
new file mode 100644
index 0..107963a8710bd
--- /dev/null
+++ b/clang/test/CodeGen/avoidTBAAonASMstore.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -disable-llvm-passes 
-fasm-blocks %s -emit-llvm -o - | FileCheck --check-prefix=STORE-LINE %s
+double foo(double z) {
+  // STORE-LINE-LABEL: define{{.*}} double @_Z3food
+  unsigned short ControlWord;
+  __asm { fnstcw word ptr[ControlWord]}
+  ;
+  // STORE-LINE: store i64 %{{.*}}, i64* %{{.*}},
+  // STORE-LINE-NOT: align 4, !tbaa
+  // STORE-LINE-SAME: align 4
+  return z;
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits