[PATCH] D62961: [AST] Add new Type queries for sizeless types

2020-11-27 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm abandoned this revision.
rsandifo-arm added a comment.

Was superceded by later revisions, but I forgot to close this one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62961/new/

https://reviews.llvm.org/D62961

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


[PATCH] D62961: [AST] Add new Type queries for sizeless types

2020-02-21 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm updated this revision to Diff 245812.
rsandifo-arm added a comment.

Update to latest master.  Defer making sizeless types
incomplete until D62962 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62961/new/

https://reviews.llvm.org/D62961

Files:
  clang/include/clang/AST/CanonicalType.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/SizelessTypesTest.cpp

Index: clang/unittests/AST/SizelessTypesTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/SizelessTypesTest.cpp
@@ -0,0 +1,81 @@
+//===- unittests/AST/SizelessTypesTest.cpp --- Sizeless type tests ===//
+//
+// 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
+//
+//===--===//
+//
+// This file contains tests for clang::Type queries related to sizeless types.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+struct SizelessTypeTester : public ::testing::Test {
+  // Declare an incomplete structure type.
+  std::unique_ptr AST =
+tooling::buildASTFromCodeWithArgs("struct foo;",
+  {"-target", "aarch64-linux-gnu"});
+  ASTContext  = AST->getASTContext();
+  TranslationUnitDecl  = *Ctx.getTranslationUnitDecl();
+  TypeDecl *Foo = cast(TU.lookup(("foo")).front());
+  const Type *FooTy = Foo->getTypeForDecl();
+};
+
+TEST_F(SizelessTypeTester, TestSizeless) {
+  ASSERT_TRUE(Ctx.SveInt8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveUint8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveFloat16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveFloat32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveFloat64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveBoolTy->isSizelessType());
+
+  ASSERT_FALSE(Ctx.VoidTy->isSizelessType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessType());
+  ASSERT_FALSE(FooTy->isSizelessType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
+}
+
+TEST_F(SizelessTypeTester, TestIndefinite) {
+  ASSERT_FALSE(Ctx.SveInt8Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveUint8Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveFloat16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveFloat32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveFloat64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveBoolTy->isIndefiniteType());
+
+  ASSERT_TRUE(Ctx.VoidTy->isIndefiniteType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isIndefiniteType());
+  ASSERT_TRUE(FooTy->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isIndefiniteType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isIndefiniteType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isIndefiniteType());
+}
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -29,6 +29,7 @@
   NamedDeclPrinterTest.cpp
   OMPStructuredBlockTest.cpp
   RecursiveASTVisitorTest.cpp
+  SizelessTypesTest.cpp
   SourceLocationTest.cpp
   StmtPrinterTest.cpp
   StructuralEquivalenceTest.cpp
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2109,10 +2109,10 @@
   return !isa(CanonicalType);
 }
 
-/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
-/// - a type that can describe objects, but which lacks information needed to
-/// determine its size.
-bool Type::isIncompleteType(NamedDecl **Def) const {
+/// isIndefiniteType - Return true if this is an indefinite type - a type that
+/// can describe objects, but lacks information needed to construct them.
+/// For sized types, 

[PATCH] D62961: [AST] Add new Type queries for sizeless types

2019-06-27 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm updated this revision to Diff 206894.
rsandifo-arm added a comment.

- Update for new version of D62960 


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62961/new/

https://reviews.llvm.org/D62961

Files:
  include/clang/AST/CanonicalType.h
  include/clang/AST/Type.h
  lib/AST/Type.cpp
  unittests/AST/CMakeLists.txt
  unittests/AST/SizelessTypesTest.cpp

Index: unittests/AST/SizelessTypesTest.cpp
===
--- /dev/null
+++ unittests/AST/SizelessTypesTest.cpp
@@ -0,0 +1,105 @@
+//===- unittests/AST/SizelessTypesTest.cpp --- Sizeless type tests ===//
+//
+// 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
+//
+//===--===//
+//
+// This file contains tests for clang::Type queries related to sizeless types.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+struct SizelessTypeTester : public ::testing::Test {
+  // Declare an incomplete structure type.
+  std::unique_ptr AST = tooling::buildASTFromCode("struct foo;");
+  ASTContext  = AST->getASTContext();
+  TranslationUnitDecl  = *Ctx.getTranslationUnitDecl();
+  TypeDecl *Foo = cast(TU.lookup(("foo")).front());
+  const Type *FooTy = Foo->getTypeForDecl();
+};
+
+TEST_F(SizelessTypeTester, TestSizeless) {
+  ASSERT_TRUE(Ctx.SveInt8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveUint8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveFloat16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveFloat32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveFloat64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveBoolTy->isSizelessType());
+
+  ASSERT_FALSE(Ctx.VoidTy->isSizelessType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessType());
+  ASSERT_FALSE(FooTy->isSizelessType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
+}
+
+TEST_F(SizelessTypeTester, TestIndefinite) {
+  ASSERT_FALSE(Ctx.SveInt8Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveUint8Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveFloat16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveFloat32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveFloat64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveBoolTy->isIndefiniteType());
+
+  ASSERT_TRUE(Ctx.VoidTy->isIndefiniteType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isIndefiniteType());
+  ASSERT_TRUE(FooTy->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isIndefiniteType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isIndefiniteType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isIndefiniteType());
+}
+
+TEST_F(SizelessTypeTester, TestIncomplete) {
+  ASSERT_TRUE(Ctx.SveInt8Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveInt16Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveInt32Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveInt64Ty->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.SveUint8Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveUint16Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveUint32Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveUint64Ty->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.SveFloat16Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveFloat32Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveFloat64Ty->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.SveBoolTy->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.VoidTy->isIncompleteType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isIncompleteType());
+  ASSERT_TRUE(FooTy->isIncompleteType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isIncompleteType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isIncompleteType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isIncompleteType());
+}
Index: unittests/AST/CMakeLists.txt
===
--- 

[PATCH] D62961: [AST] Add new Type queries for sizeless types

2019-06-06 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

This patch adds new type queries:

- isSizelessType
- isDefiniteType
- isIndefiniteType

following the type classification described in the comments.
The follow-on patch to support sizeless types in C and C++
has more details about the sizeless type extension.


Repository:
  rC Clang

https://reviews.llvm.org/D62961

Files:
  include/clang/AST/CanonicalType.h
  include/clang/AST/Type.h
  lib/AST/Type.cpp
  unittests/AST/CMakeLists.txt
  unittests/AST/SizelessTypesTest.cpp

Index: unittests/AST/SizelessTypesTest.cpp
===
--- /dev/null
+++ unittests/AST/SizelessTypesTest.cpp
@@ -0,0 +1,105 @@
+//===- unittests/AST/SizelessTypesTest.cpp --- Sizeless type tests ===//
+//
+// 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
+//
+//===--===//
+//
+// This file contains tests for clang::Type queries related to sizeless types.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+struct SizelessTypeTester : public ::testing::Test {
+  // Declare an incomplete structure type.
+  std::unique_ptr AST = tooling::buildASTFromCode("struct foo;");
+  ASTContext  = AST->getASTContext();
+  TranslationUnitDecl  = *Ctx.getTranslationUnitDecl();
+  TypeDecl *Foo = cast(TU.lookup(("foo")).front());
+  const Type *FooTy = Foo->getTypeForDecl();
+};
+
+TEST_F(SizelessTypeTester, TestSizeless) {
+  ASSERT_TRUE(Ctx.SveInt8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveUint8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveFloat16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveFloat32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveFloat64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveBoolTy->isSizelessType());
+
+  ASSERT_FALSE(Ctx.VoidTy->isSizelessType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessType());
+  ASSERT_FALSE(FooTy->isSizelessType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
+}
+
+TEST_F(SizelessTypeTester, TestIndefinite) {
+  ASSERT_FALSE(Ctx.SveInt8Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveInt64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveUint8Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveUint64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveFloat16Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveFloat32Ty->isIndefiniteType());
+  ASSERT_FALSE(Ctx.SveFloat64Ty->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.SveBoolTy->isIndefiniteType());
+
+  ASSERT_TRUE(Ctx.VoidTy->isIndefiniteType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isIndefiniteType());
+  ASSERT_TRUE(FooTy->isIndefiniteType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isIndefiniteType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isIndefiniteType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isIndefiniteType());
+}
+
+TEST_F(SizelessTypeTester, TestIncomplete) {
+  ASSERT_TRUE(Ctx.SveInt8Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveInt16Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveInt32Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveInt64Ty->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.SveUint8Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveUint16Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveUint32Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveUint64Ty->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.SveFloat16Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveFloat32Ty->isIncompleteType());
+  ASSERT_TRUE(Ctx.SveFloat64Ty->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.SveBoolTy->isIncompleteType());
+
+  ASSERT_TRUE(Ctx.VoidTy->isIncompleteType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isIncompleteType());
+  ASSERT_TRUE(FooTy->isIncompleteType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isIncompleteType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isIncompleteType());
+