From a60f532a9132c39e4fbd4000f6c2dc20221c44a8 Mon Sep 17 00:00:00 2001 From: Dario Domizioli Date: Wed, 15 Oct 2014 16:18:20 +0000 Subject: Fix for PR21254 - Assertion in comment parser The size of the ID field in CommandInfo was narrow, leading to potential wrap-around of command IDs, causing misinterpretation later on. The patch does the following: - It extends the ID bitfield from 8 to 20 bits. - It provides a DRY definition of the number of bits for the field to avoid using literal numbers in different files. - It introduces a new assertion that checks for the wrap-around. - It adds the testcase from PR21254. llvm-svn: 219802 --- clang/lib/AST/CommentCommandTraits.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'clang/lib/AST/CommentCommandTraits.cpp') diff --git a/clang/lib/AST/CommentCommandTraits.cpp b/clang/lib/AST/CommentCommandTraits.cpp index a7b07a40c98..7378a7c3ac0 100644 --- a/clang/lib/AST/CommentCommandTraits.cpp +++ b/clang/lib/AST/CommentCommandTraits.cpp @@ -89,6 +89,10 @@ CommandInfo *CommandTraits::createCommandInfoWithName(StringRef CommandName) { // Value-initialize (=zero-initialize in this case) a new CommandInfo. CommandInfo *Info = new (Allocator) CommandInfo(); Info->Name = Name; + // We only have a limited number of bits to encode command IDs in the + // CommandInfo structure, so the ID numbers can potentially wrap around. + assert((NextID < (1 << CommandInfo::NumCommandIDBits)) + && "Too many commands. We have limited bits for the command ID."); Info->ID = NextID++; RegisteredCommands.push_back(Info); -- cgit v1.2.3