Skip to content

No warning when shifting invalid amount #3705

@llvmbot

Description

@llvmbot
Bugzilla Link 3333
Resolution FIXED
Resolved on Mar 12, 2010 00:57
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor

Extended Description

When using operators ">>" or "<<", the valid range for the shift amount is [0, # bits in type).

GCC gives appropriate warnings when the shift amount is an out-of-range constant, such as:

"warning: right shift count is negative"

and

"warning: left shift count >= width of type"

However, clang does not present any warnings on the same code. An example input:

#include <stdio.h>

int main(void)
{
int i = 1;
printf("%d\n", i>>-1);
return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions