llvm-project/clang/lib
Hal Finkel 0e2b975eb6 Don't crash on a self-alias declaration
We were crashing in CodeGen given input like this:

  int self_alias(void) __attribute__((weak, alias("self_alias")));

such a self-alias is invalid, but instead of diagnosing the situation, we'd
proceed to produce IR for both the function declaration and the alias. Because
we already had a function named 'self_alias', the alias could not be named the
same thing, and so LLVM would pick a different name ('self_alias1' for example)
for that value. When we later called CodeGenModule::checkAliases, we'd look up
the IR value corresponding to the alias name, find the function declaration
instead, and then assert in a cast to llvm::GlobalAlias. The easiest way to prevent
this is simply to avoid creating the wrongly-named alias value in the first
place and issue the diagnostic there (instead of in checkAliases). We detect a
related cycle case in CodeGenModule::EmitAliasDefinition already, so this just
adds a second such check.

Even though the other test cases for this 'alias definition is part of a cycle'
diagnostic are in test/Sema/attr-alias-elf.c, I've added a separate regression
test for this case. This is because I can't add this check to
test/Sema/attr-alias-elf.c without disturbing the other test cases in that
file. In order to avoid construction of the bad IR values, this diagnostic
is emitted from within CodeGenModule::EmitAliasDefinition (and the relevant
declaration is not added to the Aliases vector). The other cycle checks are
done within the CodeGenModule::checkAliases function based on the Aliases
vector, called from CodeGenModule::Release.  However, if there have been errors
earlier, HandleTranslationUnit does not call Release, and so checkAliases is
never called, and so none of the other diagnostics would be produced.

Fixes PR23509.

llvm-svn: 246882
2015-09-04 21:49:21 +00:00
..
ARCMigrate Remove and forbid raw_svector_ostream::flush() calls. 2015-08-13 18:12:56 +00:00
AST Increase accuracy of __builtin_object_size. 2015-09-04 21:28:13 +00:00
ASTMatchers Adding an AST matcher for namespaceAliasDecl. 2015-08-28 19:39:21 +00:00
Analysis Thread safety analysis: the NO_THREAD_SAFETY_ANALYSIS attribute will now 2015-09-03 21:14:22 +00:00
Basic [X86-64] Allow additional register names in inline assembler. 2015-09-04 03:42:23 +00:00
CodeGen Don't crash on a self-alias declaration 2015-09-04 21:49:21 +00:00
Driver [WebAssembly] Initial WebAssembly support in clang 2015-09-03 22:51:53 +00:00
Edit [Edit] Use StringRef's copy method. No functional change intended. 2015-08-04 11:18:09 +00:00
Format clang-format: Don't let a leading "template <..>" lead to wrapped initializers. 2015-08-27 11:59:31 +00:00
Frontend Fix crash on invalid if we can't find a suitable PCH file in a specified 2015-09-04 21:44:32 +00:00
FrontendTool Provide a BuryPointer for unique_ptrs. 2014-08-29 16:53:14 +00:00
Headers [X86][SSE] Add _mm_undefined_* intrinsics 2015-08-26 21:17:12 +00:00
Index Remove and forbid raw_svector_ostream::flush() calls. 2015-08-13 18:12:56 +00:00
Lex Add a -gmodules option to the driver and a -dwarf-ext-refs to cc1 2015-08-27 19:46:20 +00:00
Parse [OPENMP 4.1] Parsing/sema analysis for extended format of 'if' clause. 2015-09-03 07:23:48 +00:00
Rewrite Make local function isWhitespaceExceptNL static instead of in anonymous namespace 2015-07-28 04:54:03 +00:00
Sema Don't allow dllexport/import on static local variables 2015-09-04 19:59:39 +00:00
Serialization [OPENMP 4.1] Parsing/sema analysis for extended format of 'if' clause. 2015-09-03 07:23:48 +00:00
StaticAnalyzer [Static Analyzer] Remove sinks from nullability checks. 2015-09-03 23:16:21 +00:00
Tooling [clang-tidy] Make NumOccurrenceFlag for SourcePaths configurable. 2015-08-17 10:01:42 +00:00
CMakeLists.txt Fix build with various feature flag combinations 2014-07-14 22:17:22 +00:00
Makefile Make clang's rewrite engine a core feature 2014-07-16 16:48:33 +00:00