llvm-project/clang/tools/libclang
Alexander Richardson 6d989436d0 Convert clang::LangAS to a strongly typed enum
Summary:
Convert clang::LangAS to a strongly typed enum

Currently both clang AST address spaces and target specific address spaces
are represented as unsigned which can lead to subtle errors if the wrong
type is passed. It is especially confusing in the CodeGen files as it is
not possible to see what kind of address space should be passed to a
function without looking at the implementation.
I originally made this change for our LLVM fork for the CHERI architecture
where we make extensive use of address spaces to differentiate between
capabilities and pointers. When merging the upstream changes I usually
run into some test failures or runtime crashes because the wrong kind of
address space is passed to a function. By converting the LangAS enum to a
C++11 we can catch these errors at compile time. Additionally, it is now
obvious from the function signature which kind of address space it expects.

I found the following errors while writing this patch:

- ItaniumRecordLayoutBuilder::LayoutField was passing a clang AST address
  space to  TargetInfo::getPointer{Width,Align}()
- TypePrinter::printAttributedAfter() prints the numeric value of the
  clang AST address space instead of the target address space.
  However, this code is not used so I kept the current behaviour
- initializeForBlockHeader() in CGBlocks.cpp was passing
  LangAS::opencl_generic to TargetInfo::getPointer{Width,Align}()
- CodeGenFunction::EmitBlockLiteral() was passing a AST address space to
  TargetInfo::getPointerWidth()
- CGOpenMPRuntimeNVPTX::translateParameter() passed a target address space
  to Qualifiers::addAddressSpace()
- CGOpenMPRuntimeNVPTX::getParameterAddress() was using
  llvm::Type::getPointerTo() with a AST address space
- clang_getAddressSpace() returns either a LangAS or a target address
  space. As this is exposed to C I have kept the current behaviour and
  added a comment stating that it is probably not correct.

Other than this the patch should not cause any functional changes.

Reviewers: yaxunl, pcc, bader

Reviewed By: yaxunl, bader

Subscribers: jlebar, jholewinski, nhaehnle, Anastasia, cfe-commits

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

llvm-svn: 315871
2017-10-15 18:48:14 +00:00
..
ARCMigrate.cpp [CMake] Move CLANG_ENABLE_(ARCMT|OBJC_REWRITER|STATIC_ANALYZER) into clang/Config/config.h. 2017-07-18 08:55:03 +00:00
BuildSystem.cpp Replace TimeValue with TimePoint in BuildSystem.cpp. NFC. 2016-11-09 11:19:39 +00:00
CIndex.cpp Dependent Address Space Support 2017-10-02 06:25:51 +00:00
CIndexCXX.cpp [libclang] Remove the 'extern "C"' blocks from the implementation files. 2016-12-17 01:09:40 +00:00
CIndexCodeCompletion.cpp [libclang] Bury dead TemporaryFiles 2017-03-24 09:49:54 +00:00
CIndexDiagnostic.cpp Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"" 2017-06-27 09:50:38 +00:00
CIndexDiagnostic.h Roll-back r250822. 2015-10-20 13:23:58 +00:00
CIndexHigh.cpp [libclang] Revert part of r290025, "Remove the 'extern "C"' blocks from the implementation files." 2016-12-19 16:50:43 +00:00
CIndexInclusionStack.cpp [libclang] Remove the 'extern "C"' blocks from the implementation files. 2016-12-17 01:09:40 +00:00
CIndexUSRs.cpp [libclang] Remove the 'extern "C"' blocks from the implementation files. 2016-12-17 01:09:40 +00:00
CIndexer.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
CIndexer.h [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
CLog.h Replace uses of LLVM_FUNCTION_NAME with __func__, this was macro was removed from llvm/Support in r284681 2016-10-20 02:46:22 +00:00
CMakeLists.txt [CMake][Modules] libclang: Ignore _CINDEX_LIB_ and CLANG_TOOL_EXTRA_BUILD for -fmodules. 2017-07-31 11:45:20 +00:00
CXComment.cpp [libclang] Remove the 'extern "C"' blocks from the implementation files. 2016-12-17 01:09:40 +00:00
CXComment.h [cleanup] Re-sort the #include lines using llvm/utils/sort_includes.py 2015-01-14 11:23:58 +00:00
CXCompilationDatabase.cpp [Tooling][libclang] Remove unused CompilationDatabase::MappedSources 2017-05-23 13:50:43 +00:00
CXCursor.cpp libclang: remove unused variable. 2017-04-27 20:22:40 +00:00
CXCursor.h Revert r240270 ("Fixed/added namespace ending comments using clang-tidy"). 2015-06-22 23:07:51 +00:00
CXIndexDataConsumer.cpp [index] Add indexing for unresolved-using declarations 2017-08-16 23:12:21 +00:00
CXIndexDataConsumer.h [index] When indexing an ObjC method declaration use its base name for the location. 2017-01-26 02:11:50 +00:00
CXLoadedDiagnostic.cpp [libclang] Remove the 'extern "C"' blocks from the implementation files. 2016-12-17 01:09:40 +00:00
CXLoadedDiagnostic.h [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
CXSourceLocation.cpp [libclang] Remove the 'extern "C"' blocks from the implementation files. 2016-12-17 01:09:40 +00:00
CXSourceLocation.h Revert r240270 ("Fixed/added namespace ending comments using clang-tidy"). 2015-06-22 23:07:51 +00:00
CXStoredDiagnostic.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
CXString.cpp [libclang] Remove the 'extern "C"' blocks from the implementation files. 2016-12-17 01:09:40 +00:00
CXString.h libclang: add new StringSet type 2015-11-12 03:57:16 +00:00
CXTranslationUnit.h [libclang] Expose some target information via the C API. 2017-04-28 15:56:39 +00:00
CXType.cpp Convert clang::LangAS to a strongly typed enum 2017-10-15 18:48:14 +00:00
CXType.h
CursorVisitor.h [index] Expose FriendDecl 2016-11-04 06:29:27 +00:00
Index_Internal.h
Indexing.cpp [Lexer] Report more precise skipped regions (PR34166) 2017-09-11 20:47:42 +00:00
libclang.exports [index] Generate class & metaclass manglings for objc 2017-09-22 16:58:57 +00:00