[clang] e0fa7c7 - Remove empty header file.

2022-12-23 Thread Dani Ferreira Franco Moura via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2022-12-23T11:34:50Z
New Revision: e0fa7c730d01fafd877863a145462cf1e0d5fd5b

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

LOG: Remove empty header file.

Reviewed By: gribozavr2, merrymeerkat

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

Added: 


Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/include/clang/module.modulemap

Removed: 
clang/include/clang/Analysis/AnalysisDiagnostic.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index c7443e7a228dc..3babeeeab03f5 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@ clang/bindings/python/tests/cindex/INPUTS/header3.h
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h

diff  --git a/clang/include/clang/Analysis/AnalysisDiagnostic.h 
b/clang/include/clang/Analysis/AnalysisDiagnostic.h
deleted file mode 100644
index fd5f2ffe6483d..0
--- a/clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- C++ 
-*-===//
-//
-// 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
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif

diff  --git a/clang/include/clang/module.modulemap 
b/clang/include/clang/module.modulemap
index c182da1d830a8..9810add761f81 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -94,10 +94,7 @@ module Clang_Diagnostics {
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis {
-header "Analysis/AnalysisDiagnostic.h" export *
-textual header "Analysis/Analyses/UnsafeBufferUsageGadgets.def"
-  }
+  module Analysis { textual header 
"Analysis/Analyses/UnsafeBufferUsageGadgets.def" }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }



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


[clang] fbee2dd - [clang][nullability] Remove old overload for getNullability()

2022-12-23 Thread Dani Ferreira Franco Moura via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2022-12-23T16:50:58Z
New Revision: fbee2dd9a4ba226590d16546728e436ad9e5ed6c

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

LOG: [clang][nullability] Remove old overload for getNullability()

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 2407400b31315..8f7a4836381ae 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2548,8 +2548,6 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
   Optional getNullability() const;
-  // TODO: Remove overload.
-  Optional getNullability(const ASTContext &) const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 0b551ae9af432..54bfb023237b0 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4157,10 +4157,6 @@ Optional Type::getNullability() const {
   }
   return std::nullopt;
 }
-// TODO: Remove overload.
-Optional Type::getNullability(const ASTContext &) const {
-  return getNullability();
-}
 
 bool Type::canHaveNullability(bool ResultIfUnknown) const {
   QualType type = getCanonicalTypeInternal();



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


[clang] d862f66 - [clang][dataflow] Treat unions as structs.

2023-01-03 Thread Dani Ferreira Franco Moura via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2023-01-03T18:36:24Z
New Revision: d862f66221de1463ee7c92fe2e78445edb30a601

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

LOG: [clang][dataflow] Treat unions as structs.

This is a straightfoward way to handle unions in dataflow analysis. Without 
this change, nullability verification crashes on files that contain unions.

Reviewed By: gribozavr2, ymandel

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h 
b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
index fdfd03129b81e..f7ea7eb174c54 100644
--- a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
+++ b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
@@ -65,6 +65,9 @@ class ScalarStorageLocation final : public StorageLocation {
 /// struct with public members. The child map is flat, so when used for a 
struct
 /// or class type, all accessible members of base struct and class types are
 /// directly accesible as children of this location.
+/// FIXME: Currently, the storage location of unions is modelled the same way 
as
+/// that of structs or classes. Eventually, we need to change this modelling so
+/// that all of the members of a given union have the same storage location.
 class AggregateStorageLocation final : public StorageLocation {
 public:
   explicit AggregateStorageLocation(QualType Type)

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index b8e3e93390602..1a561b31aae9a 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -235,14 +235,12 @@ Environment::Environment(DataflowAnalysisContext &DACtx,
 if (Parent->isLambda())
   MethodDecl = dyn_cast(Parent->getDeclContext());
 
+// FIXME: Initialize the ThisPointeeLoc of lambdas too.
 if (MethodDecl && !MethodDecl->isStatic()) {
   QualType ThisPointeeType = MethodDecl->getThisObjectType();
-  // FIXME: Add support for union types.
-  if (!ThisPointeeType->isUnionType()) {
-ThisPointeeLoc = &createStorageLocation(ThisPointeeType);
-if (Value *ThisPointeeVal = createValue(ThisPointeeType))
-  setValue(*ThisPointeeLoc, *ThisPointeeVal);
-  }
+  ThisPointeeLoc = &createStorageLocation(ThisPointeeType);
+  if (Value *ThisPointeeVal = createValue(ThisPointeeType))
+setValue(*ThisPointeeLoc, *ThisPointeeVal);
 }
   }
 
@@ -570,7 +568,7 @@ void Environment::setValue(const StorageLocation &Loc, 
Value &Val) {
 auto &AggregateLoc = *cast(&Loc);
 
 const QualType Type = AggregateLoc.getType();
-assert(Type->isStructureOrClassType());
+assert(Type->isStructureOrClassType() || Type->isUnionType());
 
 for (const FieldDecl *Field : getObjectFields(Type)) {
   assert(Field != nullptr);
@@ -684,7 +682,7 @@ Value *Environment::createValueUnlessSelfReferential(
 return &takeOwnership(std::make_unique(PointeeLoc));
   }
 
-  if (Type->isStructureOrClassType()) {
+  if (Type->isStructureOrClassType() || Type->isUnionType()) {
 CreatedValuesCount++;
 // FIXME: Initialize only fields that are accessed in the context that is
 // being analyzed.

diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 336de81b06538..32e9d6f12e44e 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -487,10 +487,6 @@ class TransferVisitor : public 
ConstStmtVisitor {
 if (BaseLoc == nullptr)
   return;
 
-// FIXME: Add support for union types.
-if (BaseLoc->getType()->isUnionType())
-  return;
-
 auto &MemberLoc = BaseLoc->getChild(*Member);
 if (MemberLoc.getType()->isReferenceType()) {
   Env.setStorageLocation(*S, MemberLoc);

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index b5e10b24fffb5..a9b1f42f20360 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1518,6 +1518,50 @@ TEST(TransferTest, ClassThisMember) {
   });
 }
 
+TEST(TransferTest, UnionThisMember) {
+  std::string Code = R"(
+union A {
+  int Foo;
+  int Bar;
+
+  void target() {
+(void)0; // [[p]]
+

[clang] 70acb3a - A slightly more concise AST dump :)

2023-02-10 Thread Dani Ferreira Franco Moura via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2023-02-10T19:11:31Z
New Revision: 70acb3aab3a10eea802781f69c8336c21dce6d59

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

LOG: A slightly more concise AST dump :)

If the modifiedType and the minimally desugared type of an AttributedType are 
the same, then we do not need to show both in an AST dump.

Here, we change VisitAttributedType to only visit the modifiedType when it is 
different from the equivalentType (the minimally desugared type), because the 
latter is already visited by default.

Reviewed By: sammccall

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

Added: 
clang/test/AST/ast-dump-attr-type.cpp

Modified: 
clang/include/clang/AST/ASTNodeTraverser.h
clang/test/AST/ast-dump-types-json.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index a2c57aab89ebc..86a896740e910 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -384,7 +384,8 @@ class ASTNodeTraverser
   }
   void VisitAttributedType(const AttributedType *T) {
 // FIXME: AttrKind
-Visit(T->getModifiedType());
+if (T->getModifiedType() != T->getEquivalentType())
+  Visit(T->getModifiedType());
   }
   void VisitBTFTagAttributedType(const BTFTagAttributedType *T) {
 Visit(T->getWrappedType());

diff  --git a/clang/test/AST/ast-dump-attr-type.cpp 
b/clang/test/AST/ast-dump-attr-type.cpp
new file mode 100644
index 0..17e710ff72817
--- /dev/null
+++ b/clang/test/AST/ast-dump-attr-type.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump %s | 
FileCheck %s
+
+int * _Nonnull x;
+using Ty = decltype(x);
+
+// CHECK: TypeAliasDecl 0x{{[^ ]*}}   col:7 Ty 
'decltype(x)':'int *'
+// CHECK-NEXT:  `-DecltypeType 0x{{[^ ]*}} 'decltype(x)' sugar
+// CHECK-NEXT: |-DeclRefExpr 0x{{[^ ]*}}  'int * _Nonnull':'int *' 
lvalue Var 0x{{[^ ]*}} 'x' 'int * _Nonnull':'int *' non_odr_use_unevaluated
+// CHECK-NEXT:`-AttributedType 0x{{[^ ]*}} 'int * _Nonnull' sugar
+// CHECK-NEXT:  `-PointerType 0x{{[^ ]*}} 'int *'
+// CHECK-NEXT:`-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NOT:   `-PointerType
+
+[[clang::address_space(3)]] int *y;
+using Ty1 = decltype(y);
+
+// CHECK: TypeAliasDecl 0x{{[^ ]*}}  col:7 Ty1 
'decltype(y)':'__attribute__((address_space(3))) int *'
+// CHECK-NEXT: `-DecltypeType 0x{{[^ ]*}} 'decltype(y)' sugar
+// CHECK-NEXT:   |-DeclRefExpr 0x{{[^ ]*}}  
'__attribute__((address_space(3))) int *' lvalue Var 0x{{[^ ]*}} 'y' 
'__attribute__((address_space(3))) int *' non_odr_use_unevaluated
+// CHECK-NEXT: `-PointerType 0x{{[^ ]*}} 
'__attribute__((address_space(3))) int *'
+// CHECK-NEXT:   `-AttributedType 0x{{[^ ]*}} 
'__attribute__((address_space(3))) int' sugar
+// CHECK-NEXT  |-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT  `-QualType 0x{{[^ ]*}} 
'__attribute__((address_space(3))) int' __attribute__((address_space(3)))
+// CHECK-NEXT`-BuiltinType 0x{{[^ ]*}} 'int'

diff  --git a/clang/test/AST/ast-dump-types-json.cpp 
b/clang/test/AST/ast-dump-types-json.cpp
index 87cfaa241fbc7..0a92483fb1c7f 100644
--- a/clang/test/AST/ast-dump-types-json.cpp
+++ b/clang/test/AST/ast-dump-types-json.cpp
@@ -203,32 +203,6 @@ using ::TestUsingShadowDeclType;
 // CHECK-NEXT:]
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "ParenType",
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "void ()"
-// CHECK-NEXT:  },
-// CHECK-NEXT:  "inner": [
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "FunctionProtoType",
-// CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": "void ()"
-// CHECK-NEXT:},
-// CHECK-NEXT:"cc": "cdecl",
-// CHECK-NEXT:"inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "BuiltinType",
-// CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "void"
-// CHECK-NEXT:  }
-// CHECK-NEXT: }
-// CHECK-NEXT:]
-// CHECK-NEXT:   }
-// CHECK-NEXT:  ]
 // CHECK-NEXT: }
 // CHECK-NEXT:]
 // CHECK-NEXT:   }



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